Repository navigation
feat(security): add cross-contract reentrancy and CEI guards across pool, backstop, treasury, and grants (#241) - #503
Open
umpireboulianne-design wants to merge 1 commit into
Conversation
…ool, backstop, treasury, and grants (Refract-Protocol#241) Closes Refract-Protocol#241
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
Enforces strict Checks-Effects-Interactions (CEI) ordering and temporary-storage reentrancy locks (
DataKey::ReentrancyLock) acrossRefractPool,RefractBackstop,RefractTreasury, andRefractGrantsto prevent cross-contract reentrancy and hostile token callback exploits.Closes #241
Changes
pool/src/lib.rs):DataKey::ReentrancyLockandPoolError::ReentrancyDetected = 16.provide_capitalandbuy_policyto commit all pool accounting, share, and policy state before invokingtoken.transferorRefractPolicyRegistry::register_policy.provide_capital,withdraw_capital,buy_policy,process_claim, andexpire_policywithacquire_reentrancy_guard/release_reentrancy_guard.backstop/src/lib.rs,backstop/src/test.rs):DataKey::ReentrancyLockandBackstopError::ReentrancyDetected = 13.deposit_trancheandabsorb_lossso all share, asset, lot, andPendingLossstate mutations are persisted beforetoken.transfer.deposit_tranche,withdraw_tranche,cover_shortfall,absorb_loss,receive_premium, andrescuewithacquire_reentrancy_guard/release_reentrancy_guard.pool -> backstopnested invocation tests inbackstop/src/test.rs.treasury/src/lib.rs,treasury/src/payments.rs,treasury/src/payments_test.rs):DataKey::ReentrancyLockandTreasuryError::ReentrancyDetected = 7.execute_payment_requestsorequest.status = PaymentStatus::Executedis persisted beforetoken.transfer.reentrant_payment_execution_during_token_transfer_is_rejectedintreasury/src/payments_test.rs.grants/src/lib.rs,grants/src/contract.rs):DataKey::ReentrancyLockandGrantsError::ReentrancyDetected = 20.claimandsweep_feessogrant.claimable, milestoneclaimedflags, andAccruedFeesare updated beforetoken.transfer.reentrant_grant_claim_during_token_transfer_is_rejectedingrants/src/contract.rs.Checklist
unwrap(),expect(), orpanic!()calls in non-test contract code