fix(settlement): checked arithmetic for credited balances#222
Merged
greatest0fallt1me merged 4 commits intoCalloraOrg:mainfrom Mar 31, 2026
Merged
Conversation
|
@Agbasimere 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! 🚀 |
9b451e1 to
efe5e1a
Compare
efe5e1a to
13f601e
Compare
…ked-math # Conflicts: # Cargo.toml # SECURITY.md # contracts/settlement/Cargo.toml # contracts/settlement/src/lib.rs # contracts/settlement/src/test.rs # contracts/settlement/src/test_balance.rs # contracts/vault/src/lib.rs # contracts/vault/src/test.rs
Contributor
Author
|
@greatest0fallt1me Kindly review. |
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: #134
Summary
This pull request replaces naive
i128balance updates (using+=and-=) with checked arithmetic in both thecallora-vaultand the newly renamedcallora-settlementcontract (formerlyrevenue_pool). This ensures any overflow or underflow results in an immediate panic and transaction revert, preventing silent state corruption.Key Changes
contracts/revenue_pooltocontracts/settlementand updated the crate name tocallora-settlement.meta.balance += amountinvault/src/lib.rswithchecked_add().expect("balance overflow").meta.balance -= amountinvault/src/lib.rswithchecked_sub().expect("balance underflow").total_amount += amountinsettlement/src/lib.rswithchecked_add().expect("total amount overflow").vault/src/test.rsandsettlement/src/test.rsto verify panic behavior.SECURITY.mddocumenting the checked arithmetic policy.README.md,INVARIANTS.md, and.github/workflows/ci.ymlfor the contract rename.overflow-checks = trueis explicitly documented and enforced for bothdevandreleaseprofiles in rootCargo.toml.Security Notes
All balance mutations now utilize explicit checked arithmetic (
checked_add/checked_sub). In the event of an overflow, the contract will panic with a descriptive message, providing an additional layer of security beyond the default workspace policy.Test Results
cargo fmt: Passed.cargo clippy: Passed with zero warnings.cargo test: Addeddeposit_overflow_panicsandbatch_distribute_overflow_panicstests; all related tests passing.