Description
In CalloraVault::deposit (contracts/vault/src/lib.rs), the USDC token::transfer happens before the tracked meta.balance is updated and persisted. While Soroban's host model limits classic reentrancy, ordering state effects after an external token call is a reentrancy-equivalent footgun if the configured token is a malicious/custom SAC. Apply a strict checks-effects-interactions ordering and document the assumption.
Requirements and Context
- Compute and validate the new balance, write
MetaKey to storage, then perform the external transfer.
- If the transfer can fail, ensure the state write is not left committed on a panicking transfer (Soroban reverts the whole tx on panic — document this guarantee).
- Add a code comment referencing the CEI ordering decision.
- Must be secure, tested, and documented
- Should be efficient and easy to review
Suggested Execution
- Fork the repo and create a branch
git checkout -b bug/vault-deposit-cei-ordering
- Implement changes
contracts/vault/src/lib.rs — reorder effects vs interaction in deposit
- Add
/// note on the reentrancy-equivalent assumption
- Test and commit
cargo test -p callora-vault
- Add a test with a token mock asserting balance and on-ledger state stay consistent on transfer failure
- Include test output and notes in the PR
Example commit message
fix: enforce checks-effects-interactions ordering in vault deposit
Acceptance Criteria
Guidelines
.rs under contracts/vault/src/, cargo test, /// docs, minimum 95% line coverage, no unwrap() in prod paths
- Clear documentation and inline comments
- Timeframe: 96 hours
Description
In
CalloraVault::deposit(contracts/vault/src/lib.rs), the USDCtoken::transferhappens before the trackedmeta.balanceis updated and persisted. While Soroban's host model limits classic reentrancy, ordering state effects after an external token call is a reentrancy-equivalent footgun if the configured token is a malicious/custom SAC. Apply a strict checks-effects-interactions ordering and document the assumption.Requirements and Context
MetaKeyto storage, then perform the externaltransfer.Suggested Execution
contracts/vault/src/lib.rs— reorder effects vs interaction indeposit///note on the reentrancy-equivalent assumptioncargo test -p callora-vaultExample commit message
Acceptance Criteria
depositretains correct event payload(amount, new_balance)Guidelines
.rsundercontracts/vault/src/,cargo test,///docs, minimum 95% line coverage, nounwrap()in prod paths