Skip to content

fix(escrow): overflow-safe NextContractId allocation#372

Open
Vvictor-commits wants to merge 2 commits into
Talenttrust:mainfrom
Vvictor-commits:fix/escrow-contract-id-overflow-ci
Open

fix(escrow): overflow-safe NextContractId allocation#372
Vvictor-commits wants to merge 2 commits into
Talenttrust:mainfrom
Vvictor-commits:fix/escrow-contract-id-overflow-ci

Conversation

@Vvictor-commits
Copy link
Copy Markdown

@Vvictor-commits Vvictor-commits commented May 28, 2026

Closes #333


Summary

  • Allocate contract IDs with checked_add(1) on NextContractId; panic with ContractIdOverflow at u32::MAX instead of wrapping.
  • Reject allocation when Contract(id) is already set (ContractIdCollision) before persisting a new escrow.
  • Repair CI: remove the conflicting test.rs / test/mod.rs module pair, consolidate tests under test/mod.rs, and fix compile/clippy issues so cargo fmt, cargo clippy, and cargo test pass.

Security notes

Risk Mitigation
u32 wrap near MAX reusing an active id checked_add; counter never wraps
Corrupt / rewound NextContractId Pre-write slot occupancy check
Silent overwrite of live escrow Fails closed before Contract(id) is written

Contract IDs remain strictly monotonic; allocation fails closed at the id-space boundary.

Test plan

  • cargo fmt --all -- --check
  • cargo clippy -p escrow --all-targets -- -D warnings
  • cargo test -p escrow (9 tests, including next_contract_id_overflow_at_u32_max and next_contract_id_rejects_occupied_slot)
test result: ok. 9 passed; 0 failed; 0 ignored; 0 measured

michaelvic123 and others added 2 commits May 28, 2026 16:36
Use checked u32 addition when advancing NextContractId, panic with
ContractIdOverflow at the id-space boundary, and reject allocation when
Contract(id) is already occupied.

Co-authored-by: Cursor <cursoragent@cursor.com>
Use checked u32 increment for NextContractId with ContractIdOverflow at
u32::MAX, reject occupied Contract(id) slots with ContractIdCollision, and
resolve the duplicate test module conflict so fmt/clippy/test pass in CI.

Co-authored-by: Cursor <cursoragent@cursor.com>
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 28, 2026

@Vvictor-commits 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

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.

Guard NextContractId allocation against overflow and reuse

2 participants