fix(F-9): add reentrancy locks to the v3 successor pools (Option B) - #88
Open
unixwhisperer wants to merge 1 commit into
Open
unixwhisperer wants to merge 1 commit into
unixwhisperer wants to merge 1 commit into
Conversation
flashstack-stx-pool-v3 and flashstack-sbtc-pool-v3 shipped without the reentrancy guard (PR #84), so a flash-loan receiver could still "repay" by calling deposit mid-callback and mint shares at the loan-depressed price. Port pool-v3's pv3-F1 guard as one `reentrancy-locked` bool per pool, shared by deposit, withdraw and flash-loan (Option B, Matt 2026-10-05), returning ERR-REENTRANT (u411 STX / u712 sBTC). Deposit now records shares before the transfer, matching pool-v3; a failed transfer still reverts the whole call. The flash-loan repayment check is unchanged. contracts/test/ copies regenerated from the canonical sources (principal rewrites only). New test receivers drive honest, deposit-reentry, withdraw-reentry, under-repay and nested-loan callbacks against each pool; registered in Clarinet.toml and mainnet-plan-guard's known set. Both pools remain undeployed: this is a repository fix, not a remediation of any deployed contract.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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
Implements
Flashstack-ajv.4.9per your Option B decision (email, 2026-10-05).flashstack-stx-pool-v3andflashstack-sbtc-pool-v3get pool-v3's pv3-F1 guard as onereentrancy-lockedbool per pool, shared by deposit, withdraw and flash-loan. Each entry point checks and sets it first and clears it just before its(ok ...). A blocked call returns the newERR-REENTRANT(u411STX /u712sBTC), which is unique within each contract.new-sharesandcurrent-sharesare bound in theletbefore either order, so the values written are identical. A failed transfer makes the public function returnerr, which rolls back every write in the call, the lock included. The lock blocks reentry either way.reserve-after >= reserve-before + fee), fee logic, pause gating, admin and receiver approval are all untouched. The only removed lines in the diff are deposit's two moved statements.contracts/test/copies were regenerated from the canonical sources and differ only in principal rewrites.test-{stx,sbtc}-pool-v3-receiver-reentrant, with five callback modes: honest repay, reenter deposit, reenter withdraw, under-repay, nested flash-loan.FINDINGS_REGISTER.mdis updated.Verification
All of this ran in a clean
git worktreeatorigin/maine0367e006c45(freshnpm ci, clarinet 3.23.2 as in CI). The commit's tree hash (1c9db567) is identical to the verified tree.origin/mainclarinet checkCLARINET_BIN=… npx vitest run)tests/v3-pools-reentrancy-lock.test.tsmain(1 STX, 13 sBTC)Per pool, the suite covers:
The negative cases assert the exact
ERR-REENTRANTcode, which nothing else on that path produces. The withdraw case first asserts that the receiver really holds shares, so it can't pass on a zero-amount error.One finding from writing the tests: a nested
flash-loanon the same pool never reaches the lock. The Clarity VM aborts it asRuntimeCheck(CircularReference), with or without this fix. The test pins that behaviour rather than crediting it to the lock.Security notes
add-approved-receiver:Flashstack-ajv.6.8Flashstack-ajv.6.9Flashstack-ajv.4.4clarinet deployments apply --mainnetwould compute. That takes the knowncontracts/test/publishes from 28 to 30, the same precedent as CRITICAL FINDING (F-9): deposit-as-repayment reentrancy on live v2 pools #83 and fix(F-9): independently prove the sbtc-pool-v2 deposit-reentrancy variant #86. The guard pins the exact set, and thedeployments/README.md"never apply --mainnet from the repo" rule still applies. (That README still says 26; it was already stale at 28 before this PR.)FINDINGS_REGISTER.md. This PR edits the F-9 row, and docs+fix(security): resolve web/ decode-uri-component chain, document braces/elliptic as accepted risk #87 inserts DEP-1/DEP-2 directly after it. The changes don't contradict each other; resolve by keeping both.🤖 Generated with Claude Code