fix: make late-fee arithmetic overflow-safe (Closes #1126) - #1213
Draft
s6pa1rta3n-lab wants to merge 1 commit into
Draft
s6pa1rta3n-lab wants to merge 1 commit into
s6pa1rta3n-lab wants to merge 1 commit into
Conversation
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.
Summary
Closes #1126
Makes late-fee arithmetic overflow-safe across all fee modes, installment boundaries, and configuration states. Ensures deterministic execution at maximum amount and installment limits, defines floor rounding for delinquency surcharge calculations, and guarantees neutral protocol behavior when configuration is cleared.
Acceptance Criteria Checklist
Uint128::checked_mulandcrate::accrual::accrued_interest, returningContractError::Overflowbefore any state transition or storage write can occur. Verified incontracts/creditra-credit/tests/late_fee_overflow.rs::overflow_protection.Uint128::MAX, maxu64::MAXinstallments at unit amount, maximum safe product and single-step overflow boundary, and surcharge bps bounds (0,10_000,10_001,u32::MAX). Verified incontracts/creditra-credit/tests/late_fee_overflow.rs::boundary_conditionsand unit tests incontracts/creditra-credit/src/penalties.rs.None->Flat->AprBased->None->Flat->AprBased->None) and verified raw storage keyb"lfc"isolation across mode switches. Verified incontracts/creditra-credit/tests/late_fee_overflow.rs::state_transition_and_clearing.Flatvariants,AprBasedvariants with floor rounding, cleared (None) variant, and extreme boundary vectors. Verified incontracts/creditra-credit/tests/late_fee_overflow.rs::golden_tests.Implementation Details & Code/Test Mapping
compute_late_fee,compute_apr_late_feelate_fee_overflow.rs::overflow_protectionvalidate_late_fee_config,compute_late_feelate_fee_overflow.rs::boundary_conditionsexecute_set_late_fee_config,compute_late_fee_optionallate_fee_overflow.rs::state_transition_and_clearingLateFeeConfiglate_fee_overflow.rs::golden_testsexecute_set_late_fee_configlate_fee_overflow.rs::authorization_boundariesSecurity & Failure-Mode Considerations
checked_mul,checked_div). Any calculation that would exceedUint128::MAXimmediately yieldsContractError::Overflow, halting execution before any state or balance modification takes effect.None),compute_late_fee_optionalevaluates to zero, ensuring no penalty is charged and preventing stale parameters from affecting subsequent contract interactions.ContractError::Unauthorized.Verification
cargo fmt -- --check: PASSEDcargo clippy --all-targets -- -D warnings: PASSEDcargo test --no-fail-fast: PASSED (all unit, integration, and property tests)cargo build --release: PASSEDcargo build --release --lib --target wasm32-unknown-unknown: PASSED (373 KB WASM, within 614,400-byte budget)scripts/validate_schemas.sh: PASSED (schemas up to date)Payout Routing
0xF46C9F6d70C50BF81ef3588AB523a90a594a2F89GCL6OXAMLD75BMTINA6EMRUDWK5THQUSHMYNLSNBCJAPZJHNYJTUNIBC