Account for the mainchain fee in withdrawal value to keep the peg solvent#86
Open
1440000bytes wants to merge 2 commits into
Open
Account for the mainchain fee in withdrawal value to keep the peg solvent#861440000bytes wants to merge 2 commits into
1440000bytes wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
get_valuefor a withdrawal output returned onlyvalue, ignoringmain_fee. But the enforcer pays both out of the treasury when it builds the M6:BlindedM6::into_m6setstreasury_out = treasury - payout - fee, wherepayoutis the sum of the bundle payout amounts (value) andfeeis the bundle's encoded mainchain fee (main_fee).So each withdrawal removed
value + main_feefrom the treasury while the sidechain destroyed onlyvalue. Every withdrawal eroded the peg's backing bymain_feeand since nothing boundsmain_fee, an attacker could withdraw a tinyvaluewith a largemain_feeand drain the treasury at near-zero sidechain cost, eventually making the peg insolvent (late withdrawals hit thechecked_subunderflow and fail).The wallet reinforced this:
create_withdrawalselected coins forvalue + fee + main_feebut computedchange = total - value - fee, refundingmain_feeback to the withdrawer.Fix
get_valuefor a withdrawal returnsvalue + main_fee, so the sidechain destroys exactly what leaves the treasury. Useschecked_addsaturating atAmount::MAXto avoid a panic on a crafted overflowing output (such an output can never be funded, so it is rejected rather than crashing).create_withdrawalsubtractsmain_feefrom the change as well, so wallet built withdrawals stay valid under the corrected accounting.Test
Added a unit test asserting a withdrawal output's value is
value + main_fee, that inputs covering onlyvaluefail fee computation, and that inputs coveringvalue + main_feeleave exactly zero fee. It fails on the old code and passes with the fix.