Description
The codebase mixes raw arithmetic and checked_* patterns. Introduce a safe_math module exposing s_add, s_sub, s_mul, s_div returning Result<i128, RevoraError> and refactor hot paths (compute_share, accrual updates, reconcile_audit_summary) to use it.
Requirements and context
- Must be secure, tested, and documented
- Should be efficient and easy to review
- Relevant code:
Revora-Contracts/src/lib.rs, Revora-Contracts/src/security_assertions.rs
- Clippy lint
arithmetic_side_effects must be denied in the refactor scope
Suggested execution
- Fork the repo and create a branch
git checkout -b refactor/safe-math-module
- Implement changes
- Add
safe_math.rs with helpers and unit tests
- Replace raw ops in compute_share with safe_math
- Enable
#![deny(clippy::arithmetic_side_effects)] on touched modules
- Validate security and correctness assumptions
Test and commit
- Run tests
- Cover edge cases
- i128::MAX overflow attempts must surface
ArithmeticOverflow via Result
- Include test output and security notes
Example commit message
refactor: route i128 hot paths through safe_math wrappers
Guidelines
- Minimum 95 percent test coverage
- Clear documentation
- Timeframe: 96 hours
Description
The codebase mixes raw arithmetic and
checked_*patterns. Introduce asafe_mathmodule exposings_add,s_sub,s_mul,s_divreturningResult<i128, RevoraError>and refactor hot paths (compute_share, accrual updates, reconcile_audit_summary) to use it.Requirements and context
Revora-Contracts/src/lib.rs,Revora-Contracts/src/security_assertions.rsarithmetic_side_effectsmust be denied in the refactor scopeSuggested execution
git checkout -b refactor/safe-math-modulesafe_math.rswith helpers and unit tests#![deny(clippy::arithmetic_side_effects)]on touched modulesTest and commit
cargo test --allArithmeticOverflowvia ResultExample commit message
refactor: route i128 hot paths through safe_math wrappersGuidelines