Skip to content

Centralize amount validation by wiring amount_validation into create_contract and deposit_funds #335

@mikewheeleer

Description

@mikewheeleer

Description

contracts/escrow/src/amount_validation.rs provides validate_milestone_amounts, validate_deposit_amount, and stroop-precision helpers, but create_contract and deposit_funds in lib.rs re-implement their own ad-hoc loops with safe_add_amounts. Consolidate to a single validation path to remove drift between the two checks.

Requirements and context

  • Scoped to TalentTrust escrow Soroban contract (contracts/escrow).
  • Route create_contract milestone validation through validate_milestone_amounts and deposit_funds through validate_deposit_amount, mapping AmountValidationError variants to the corresponding EscrowError codes.
  • Preserve existing error semantics (InvalidMilestoneAmount, PotentialOverflow, DepositWouldExceedTotal).
  • Invariant: validation behavior is identical before and after, with one source of truth.
  • Must be secure, tested, and documented.

Suggested execution

  • Fork the repo and create a branch:
    • git checkout -b enhancement/centralize-amount-validation
  • Implement changes:
    • contracts/escrow/src/lib.rs
    • Tests: contracts/escrow/src/test/input_sanitization_amounts.rs
    • Docs: docs/escrow/milestone-validation.md
    • Include rustdoc/NatSpec-style doc comments on public functions
    • Validate security assumptions (auth, overflow, fail-closed state machine, storage TTL, fee accounting)

Test and commit

  • Run tests: cargo test
  • Cover edge cases (unauthorized callers, double release/refund, expired approvals, fee rounding, paused state)
  • Include test output and security notes in the PR

Example commit message

refactor(escrow): route amounts through amount_validation

Guidelines

  • Minimum 95% test coverage on new/changed code
  • Clear documentation
  • Timeframe: 96 hours from assignment

Metadata

Metadata

Assignees

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions