fix(pool): enforce amount validation in recover_stake_ok and state guard in recover_stake - #2509
Open
getasewtilahun wants to merge 1 commit into
Conversation
…ard in recover_stake
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.
Overview
This PR fixes a state tracking issue in
pool.fcwhere the contract's internal accounting can desynchronize from the Elector's state during stake recovery.Problem Statement
In
pool.fc,op::recover_stake_ok()unconditionally resets contract state (state = 0,stake_amount_sent = 0) upon receiving anyop::recover_stake_okmessage from the Elector.However, the Elector maintains
credits(which include surplus stake returns and complaint rewards) separately frompast_elections(frozen stake). Ifrecover_stakeis processed when the Elector holds a pre-unfreeze credit balance while principal remains frozen inpast_elections, the pool receives arecover_stake_okmessage carrying only the partial credit.Because
pool.fccurrently lacks an amount check onmsg_value, processing this partial response prematurely zerosstake_amount_sentand resetsstate = 0. The subsequent legitimate return of the main stake is then misclassified as validation yield rather than principal return, corrupting reward distribution logic.Summary of Changes
op::recover_stake_okAmount Verification:if (msg_value >= stake_amount_sent)before clearingstake_amount_sentand resettingstate = 0.msg_value < stake_amount_sent, the incoming coins (partial credit) are accepted into pool balance, butstateandstake_amount_sentremain active until the full stake is recovered.op::recover_stakeState Guard:throw_unless(77, state == 0)toop::recover_staketo ensure recovery requests can only be forwarded to the Elector when the pool is in an idle state.Impact & Severity
stake_amount_sentaccurately tracks outstanding frozen principal at all times.