Description
get_total_unpaid(owner) and get_total_unpaid_by_currency(owner, currency) sum the amount of unpaid bills into an i128. With many large-amount bills these sums can overflow; under overflow-checks = true that aborts the read. We need to make the aggregation overflow-aware (saturating or checked with a defined error) and add tests with near-i128::MAX totals and many bills, plus confirm currency filtering only sums matching currency codes.
Requirements and context
- Secure: Aggregation must not panic-abort on overflow; define saturating or checked behavior consistently.
- Tested: near-max totals, mixed-currency filtering, empty owner returns 0.
- Documented: Document aggregation overflow policy in
docs/.
- Reference real symbols:
get_total_unpaid, get_total_unpaid_by_currency, Bill { amount, currency, paid }, get_bills_by_currency.
Suggested execution
- Branch
feature/bp-total-unpaid-overflow.
- Apply checked/saturating sums in
bill_payments/src/lib.rs; add tests in bill_payments/tests/stress_test_large_amounts.rs.
- Add docs
docs/bill-payments-aggregation.md.
- Add
/// comments documenting overflow policy.
- Validate security assumptions: bounded read behavior.
Test and commit
- Run
cargo test -p bill_payments.
- Cover edge cases: near-max totals, currency mismatch, no bills.
- Include test output and an aggregation-overflow note.
Example commit message
fix: make unpaid-total aggregations overflow-safe and add large-amount tests
Guidelines
- Minimum 95% test coverage
- Clear documentation in
docs/ and inline /// comments
- Timeframe: 96 hours
Description
get_total_unpaid(owner)andget_total_unpaid_by_currency(owner, currency)sum theamountof unpaid bills into ani128. With many large-amount bills these sums can overflow; underoverflow-checks = truethat aborts the read. We need to make the aggregation overflow-aware (saturating or checked with a defined error) and add tests with near-i128::MAXtotals and many bills, plus confirm currency filtering only sums matchingcurrencycodes.Requirements and context
docs/.get_total_unpaid,get_total_unpaid_by_currency,Bill { amount, currency, paid },get_bills_by_currency.Suggested execution
feature/bp-total-unpaid-overflow.bill_payments/src/lib.rs; add tests inbill_payments/tests/stress_test_large_amounts.rs.docs/bill-payments-aggregation.md.///comments documenting overflow policy.Test and commit
cargo test -p bill_payments.Example commit message
fix: make unpaid-total aggregations overflow-safe and add large-amount testsGuidelines
docs/and inline///comments