fix(dvm2.0): guard VotingV2 effective-stake subtraction against underflow#4955
Open
tcoatswo wants to merge 3 commits into
Open
fix(dvm2.0): guard VotingV2 effective-stake subtraction against underflow#4955tcoatswo wants to merge 3 commits into
tcoatswo wants to merge 3 commits into
Conversation
Signed-off-by: Tyler Coatsworth <tyler@coatsworth.me>
…flow The two effectiveStake computations in VotingV2 (revealVote and _updateAccountSlashingTrackers) subtract a per-round pendingStakes memo from a voter's current stake. pendingStakes is only ever incremented and never cleared, so the subtraction's non-negativity is guaranteed only by a non-local invariant (update-before-mutate ordering + monotonic resolved-request traversal). Relying on a downstream/global assumption to keep a critical subtraction safe is the CVE-2018-17144 anti-pattern: if a future change breaks that invariant the checked subtraction reverts inside _updateTrackers, which is reached by every state-changing entry point for the voter, permanently locking their staked principal. Enforce the property locally with a saturating _effectiveStake helper. The result is identical to the prior subtraction on every reachable state today, is always <= stake (so it can never inflate vote weight or the slash/reward base), and fails closed to 0 (the correct effective participation) instead of reverting. Adds VotingV2.EffectiveStakeGuard.t.sol asserting normal-path equality, saturation-instead-of-revert on the broken-invariant path, and the result <= stake anti-inflation bound. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
The two
effectiveStakecomputations inVotingV2— inrevealVoteand in_updateAccountSlashingTrackers— subtract a per-roundpendingStakesmemo from a voter's currentstake:pendingStakes[roundId]is only ever incremented (Staker._incrementPendingStake) and is never cleared. The subtraction stays non-negative today only because of a non-local invariant spread across staking, slashing, and resolved-request ordering (update-before-mutate in every stake mutation + the monotonicnextIndexToProcesstraversal).Relying on a downstream/global assumption to keep a critical subtraction from underflowing is the same class of mistake as CVE-2018-17144 (the duplicate-input check removed from
CheckTransactionbecause a downstream layer was assumed to make it redundant). If a future change to slashing order, request rolling/deletion, batched processing, or the staking lifecycle ever letspendingStakes[R]exceed a slashed-downstakewhile a round-Rrequest is still pending processing, the checked subtraction reverts inside_updateAccountSlashingTrackers. That path is reached by every state-changing entry point for the voter (commitVote,revealVote,updateTrackers,stake,requestUnstake,withdrawRewards), permanently locking their staked principal.Change
Enforce the safety property locally with a saturating
_effectiveStakehelper used at both sites:stake >= pendingStake(always true today) the result is identical to the previous subtraction.<= stake, so the weight fed into vote tallying and the slash/reward base can never exceed the voter's actual stake.0(the voter genuinely had no active stake for that round) instead of reverting and locking funds.Test
Adds
packages/core/test/foundry/data-verification-mechanism/VotingV2.EffectiveStakeGuard.t.sol, asserting:effectiveStake <= stakeover a fuzzed input space (anti-inflation bound).Severity
Low / defense-in-depth. No reachable exploit exists at the current HEAD; this hardens a critical subtraction so its safety no longer depends on a non-local invariant.
🤖 Generated with Claude Code