Skip to content

Add safe-math wrapper module enforcing checked arithmetic across all i128 operations #484

Description

@thlpkee20-wq

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
    • cargo test --all
  • 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

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions