Skip to content

Fix/escrow approval race condition#403

Merged
Xhristin3 merged 2 commits intorinafcode:mainfrom
Chrisland58:fix/escrow-approval-race-condition
Apr 28, 2026
Merged

Fix/escrow approval race condition#403
Xhristin3 merged 2 commits intorinafcode:mainfrom
Chrisland58:fix/escrow-approval-race-condition

Conversation

@Chrisland58
Copy link
Copy Markdown
Contributor

Fix escrow approval race condition

Addresses a critical data integrity issue where concurrent approvals could produce inconsistent
state:

  • Reentrancy guard: Added ESCROW_GUARD storage symbol and wrapped the full
    check-record-increment sequence in reentrancy::with_guard, making approval atomic.
  • Duplicate approval prevention: approve_with_guard checks has_approved before recording —
    concurrent calls by the same signer are rejected with SignerAlreadyApproved.
  • Unguarded read-modify-write: increment_approval_count is now only reachable through the
    guard, preventing double-counting of approval_count.

Files changed:

  • contracts/teachlink/src/repository/escrow_repository.rs
  • contracts/teachlink/src/storage.rs

Tests added:

- Add ESCROW_GUARD symbol to storage.rs
- Add approve_with_guard: atomically checks has_approved, records approval,
  and increments count under ESCROW_GUARD reentrancy lock
- Prevents duplicate approvals and concurrent read-modify-write on approval_count
- Add 3 concurrency tests: duplicate rejection, multi-signer increment,
  guard-active rejection
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Apr 23, 2026

@Chrisland58 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Xhristin3 Xhristin3 merged commit 1734b7a into rinafcode:main Apr 28, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix race condition in concurrent approval scenarios

2 participants