Description
FamilyWallet performs i128 arithmetic across check_spending_limit, validate_precision_spending, update_spending_limit, and the SPND_TRK tracker accumulation. Although the release profile sets overflow-checks = true, panics on overflow are a denial-of-service vector and silently saturating logic could mis-account spending. Every add/subtract on amounts and accumulated spend must use checked_* operations with explicit Error returns rather than relying on panic-abort.
Requirements and context
- Secure: Replace raw
+/- on amounts with checked_add/checked_sub returning a defined Error variant.
- Tested: Tests pushing values near
i128::MAX and asserting graceful error rather than panic.
- Documented: Add an overflow-safety note in
docs/fw-overflow-safety.md.
- Reference
SpendingTracker, PrecisionSpendingLimit, SPND_TRK, PREC_LIM, check_spending_limit, validate_precision_spending.
Suggested execution
Create branch feature/fw-overflow-safety.
- Modify arithmetic in
family_wallet/src/lib.rs to use checked operations.
- Write tests in
family_wallet/src/test.rs for near-max amounts.
- Add docs
docs/fw-overflow-safety.md.
- Add
/// comments on checked helpers.
- Validate no arithmetic panics on hostile inputs.
Test and commit
- Run
cargo test -p family_wallet.
- Cover edge cases: amount overflow, accumulated-spend overflow, negative amount.
- Include test output and security notes.
Example commit message
feat: use checked i128 arithmetic across family wallet spending paths
Guidelines
- Minimum 95% test coverage
- Clear documentation
- Timeframe: 96 hours
Description
FamilyWalletperformsi128arithmetic acrosscheck_spending_limit,validate_precision_spending,update_spending_limit, and theSPND_TRKtracker accumulation. Although the release profile setsoverflow-checks = true, panics on overflow are a denial-of-service vector and silently saturating logic could mis-account spending. Every add/subtract on amounts and accumulated spend must usechecked_*operations with explicitErrorreturns rather than relying on panic-abort.Requirements and context
+/-on amounts withchecked_add/checked_subreturning a definedErrorvariant.i128::MAXand asserting graceful error rather than panic.docs/fw-overflow-safety.md.SpendingTracker,PrecisionSpendingLimit,SPND_TRK,PREC_LIM,check_spending_limit,validate_precision_spending.Suggested execution
Create branch
feature/fw-overflow-safety.family_wallet/src/lib.rsto use checked operations.family_wallet/src/test.rsfor near-max amounts.docs/fw-overflow-safety.md.///comments on checked helpers.Test and commit
cargo test -p family_wallet.Example commit message
feat: use checked i128 arithmetic across family wallet spending pathsGuidelines