Skip to content

Vault: reorder deposit to checks-effects-interactions before token transfer #328

@greatest0fallt1me

Description

@greatest0fallt1me

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

  1. Fork the repo and create a branch
    git checkout -b bug/vault-deposit-cei-ordering
  2. Implement changes
    • contracts/vault/src/lib.rs — reorder effects vs interaction in deposit
    • Add /// note on the reentrancy-equivalent assumption
  3. 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

  • State validated and ordering documented before external transfer
  • Transfer-failure test confirms no inconsistent state
  • deposit retains correct event payload (amount, new_balance)
  • No regression in existing deposit tests

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

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programauditSecurity audit/reviewrustRust implementationsecuritySecurity hardeningsmart-contractSoroban smart-contract work

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions