Add reentrancy-safe state updates before token transfers in slash_on_miss and claim in accountability_vault
Description
In contracts/accountability_vault/src/lib.rs, slash_on_miss and claim transfer the SEP-41 token before persisting the updated Vault status. Reorder to a checks-effects-interactions pattern so the vault is marked Failed/Completed and staked zeroed in storage before the external token::Client::transfer call. Add tests in contracts/accountability_vault/src/test.rs proving the terminal state is committed even under a failing transfer.
Requirements and context
- Must be secure, tested, and documented
- Should be efficient and easy to review
- Apply checks-effects-interactions in
slash_on_miss and claim in contracts/accountability_vault/src/lib.rs
- Zero
staked and set status before token::Client::transfer
- Add a re-entrancy/ordering test in
contracts/accountability_vault/src/test.rs
- Document the invariant in
contracts/README.md
Suggested execution
- Fork the repo and create a branch
git checkout -b feat/cei-ordering
- Implement changes
- Modify
contracts/accountability_vault/src/lib.rs
- Add test cases to
contracts/accountability_vault/src/test.rs
- Update
contracts/README.md
- Add inline safety comments
- Test and commit
- Run tests, cover edge cases
- Include test output and notes
Example commit message
feat: apply checks-effects-interactions to vault payouts
Guidelines
- Minimum 95 percent test coverage
- Clear documentation
- Timeframe: 96 hours
Add reentrancy-safe state updates before token transfers in slash_on_miss and claim in accountability_vault
Description
In
contracts/accountability_vault/src/lib.rs,slash_on_missandclaimtransfer the SEP-41 token before persisting the updatedVaultstatus. Reorder to a checks-effects-interactions pattern so the vault is markedFailed/Completedandstakedzeroed in storage before the externaltoken::Client::transfercall. Add tests incontracts/accountability_vault/src/test.rsproving the terminal state is committed even under a failing transfer.Requirements and context
slash_on_missandclaimincontracts/accountability_vault/src/lib.rsstakedand set status beforetoken::Client::transfercontracts/accountability_vault/src/test.rscontracts/README.mdSuggested execution
git checkout -b feat/cei-orderingcontracts/accountability_vault/src/lib.rscontracts/accountability_vault/src/test.rscontracts/README.mdExample commit message
feat: apply checks-effects-interactions to vault payoutsGuidelines