fix(escrow): overflow-safe NextContractId allocation#372
Open
Vvictor-commits wants to merge 2 commits into
Open
fix(escrow): overflow-safe NextContractId allocation#372Vvictor-commits wants to merge 2 commits into
Vvictor-commits wants to merge 2 commits into
Conversation
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>
|
@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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #333
Summary
checked_add(1)onNextContractId; panic withContractIdOverflowatu32::MAXinstead of wrapping.Contract(id)is already set (ContractIdCollision) before persisting a new escrow.test.rs/test/mod.rsmodule pair, consolidate tests undertest/mod.rs, and fix compile/clippy issues socargo fmt,cargo clippy, andcargo testpass.Security notes
u32wrap nearMAXreusing an active idchecked_add; counter never wrapsNextContractIdContract(id)is writtenContract IDs remain strictly monotonic; allocation fails closed at the id-space boundary.
Test plan
cargo fmt --all -- --checkcargo clippy -p escrow --all-targets -- -D warningscargo test -p escrow(9 tests, includingnext_contract_id_overflow_at_u32_maxandnext_contract_id_rejects_occupied_slot)