Extend reentrancy regression coverage to stake, unstake, unlock_assets, emergency_withdraw - #137
Merged
prodbycorne merged 4 commits intoAug 18, 2026
Conversation
✅ Deploy Preview for sdcontracts ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
miraclesonly
force-pushed
the
test/reentrancy-coverage-128
branch
from
August 18, 2026 20:05
eacaa27 to
bf5e9d5
Compare
Contributor
|
good |
3 tasks
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
MockReentrantToken/MockNaiveReentrantTokenwere only ever wired up againstlock_assets, despitestake,unstake,unlock_assets, andemergency_withdrawsharing the identical threat model (an admin-supplied, not-necessarily-trustedstake_tokenwhosetransferis a synchronous cross-contract call). These are also exactly the four functions #70/#71/#72 flag for transfer-before-state-update ordering, so this coverage doubles as their eventual regression suite.configure_reentrant_call(function, args), an optional override for which functiontransferreenters with — defaults to the existingget_user_position(reentrant_user)behavior when unset, solock_assets's existing two tests are completely untouched. Used to make each new function's probe reenter the same state-mutating function currently executing (e.g.unlock_assetsreenteringunlock_assets), per the acceptance criteria's callout that this is a stronger, more realistic proof than only targeting a read-only getter.stake(top-up branch specifically),unstake,unlock_assets, andemergency_withdraw— each with a graceful-rejection (MockReentrantToken) and naive-full-revert (MockNaiveReentrantToken) variant, mirroringlock_assets's existing two tests' structure and assertions (reentry rejection + exact final-state correctness, not just "didn't panic").emergency_withdrawgets two graceful tests instead of one, since it makes two separate transfers in sequence — one covering reentry during the Position-only payout, one covering reentry during the second (UserStake) payout when both exist for a user.Position/UserStakestate some tests need is seeded directly viaset_position/set_user_stakeunderenv.as_contract, not by callinglock_assets/stakefirst:stake_tokenis fixed atinitializewith no setter, so a token already configured to reenter would also reenter during that setup call — harmless for the graceful mock, but fatal for the naive one (the setup call itself would trap).Test plan
reentry_was_rejected()— i.e. that the host actually blocked the reentrant call, not just that final state happens to look rightcargo test --workspace(mirroring CI's own steps exactly) — 182/182 passing acrossfactory,farming-pool,vesting-walletcargo build --workspace --target wasm32v1-none --release— succeedscargo fmt --all -- --check— cleancargo clippy --workspace --all-targets -- -D warnings— cleanCloses #128