fix(v2): enter reentrancy guard at start of entrypoints (#132) - #151
Conversation
collinsezedike
left a comment
There was a problem hiding this comment.
enter_reentrancy_guard's doc comment (contracts/tholos-v2/src/lib.rs:856) still says every guarded function calls it immediately before the transfer, after writing state. That's no longer true after this PR: assert_outcome, dispute, register, and withdraw all call it at the top of the function, right after require_auth, before any validation or state writes. This line isn't part of the diff so I can't anchor a comment to it directly, please update it to describe the new ordering, otherwise a future contributor adding a token-moving entrypoint will copy the stale pattern and reintroduce the exact fragility this issue fixed.
ca9ca5a to
e4544b2
Compare
|
Thanks for the review. I've addressed the requested changes, including updating the reentrancy guard documentation and improving the regression test coverage. The changes have been pushed to this PR for review. |
collinsezedike
left a comment
There was a problem hiding this comment.
@xtep103 thank you for the contribution. This looks good, there is nothing to flag.
Overview
Hoists
enter_reentrancy_guardto the start ofassert_outcome,dispute,register, andwithdrawimmediately afterrequire_auth(), closing potential reentrancy windows during early validation and id/state setup.Related Issue
Closes #132
Changes
Contracts (tholos-v2)
contracts/tholos-v2/src/lib.rsenter_reentrancy_guardto the entry ofassert_outcome,dispute, andregisterimmediately afterrequire_auth().withdraw, replacecheck_reentrancy_guardwithenter_reentrancy_guardat entry.enter_reentrancy_guardinvocations before token transfers.contracts/tholos-v2/src/test.rstest_reentrancy_guard_blocks_calls_while_held.test_reentrancy_guard_blocks_calls_before_validationverifyingReentrancyGuardActiveis returned even when arguments would otherwise fail later validation.contracts/tholos-v2/test_snapshots/test/test_reentrancy_guard_blocks_calls_before_validation.1.jsonVerification Results
require_auth()inassert_outcome,dispute,register, andwithdrawtest_reentrancy_guard_blocks_calls_before_validationcargo fmt --checkandcargo clippypassed