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
Description
contracts/escrow/src/amount_validation.rsprovidesvalidate_milestone_amounts,validate_deposit_amount, and stroop-precision helpers, butcreate_contractanddeposit_fundsinlib.rsre-implement their own ad-hoc loops withsafe_add_amounts. Consolidate to a single validation path to remove drift between the two checks.Requirements and context
escrowSoroban contract (contracts/escrow).create_contractmilestone validation throughvalidate_milestone_amountsanddeposit_fundsthroughvalidate_deposit_amount, mappingAmountValidationErrorvariants to the correspondingEscrowErrorcodes.InvalidMilestoneAmount,PotentialOverflow,DepositWouldExceedTotal).Suggested execution
git checkout -b enhancement/centralize-amount-validationcontracts/escrow/src/lib.rscontracts/escrow/src/test/input_sanitization_amounts.rsdocs/escrow/milestone-validation.mdTest and commit
cargo testExample commit message
Guidelines