Skip to content

Reject a zero MaxFeeAbsolute cap that silently makes every route free #129

Description

@mikewheeleer

Guard set_max_fee_absolute against a zero cap that zeroes all protocol fees

Description

set_max_fee_absolute in src/lib.rs rejects negative caps but explicitly allows 0, and its own doc comment admits "a cap of 0 makes every route effectively free." Because apply_fee_cap computes min(computed_fee, max_fee_absolute), a single admin call with 0 silently drives every pair's fee to zero regardless of its fee_bps — a catastrophic, easy-to-make fat-finger that drains all protocol revenue with no warning. This issue rejects a zero cap with a typed error (admins who truly want free routing can set per-pair fee_bps to 0 deliberately) and emits a clearer signal when the cap is changed.

Requirements and context

  • Repository scope: StableRoute-Org/Stableroute-contracts only.
  • Reject max_fee == 0 in set_max_fee_absolute with a new append-only RouterError::FeeCapTooLow = 19 (or reuse AmountMustBePositive if preferred — document the choice).
  • Keep the existing negative-cap rejection and the maxfee event.
  • This is distinct from the issues-4 "downgrade guard so the cap cannot silently widen" item — that prevents loosening a cap; this prevents a footgun zero cap.
  • Document that removing the cap entirely is the separate clear_max_fee_absolute path (issues-4), not setting it to 0.

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b security/contracts-reject-zero-fee-cap
  • Implement changes
    • Write code in: src/lib.rs — add the zero-cap guard and the error variant.
    • Write comprehensive tests in: src/lib.rs (inline #[cfg(test)] mod test, alongside mod test_i41_fee_cap) — assert a zero cap panics, a positive cap still clamps fees, and compute_route_fee keeps charging the bps fee under a sane cap.
    • Add documentation: update the fee-cap section in README.md and the error table in docs/abi.md.
    • Include NatSpec-style doc comments (///) on the updated entrypoint, matching the existing style in lib.rs.
    • Validate security assumptions: no path can zero all fees with a single accidental write; revenue invariant preserved.
  • Test and commit

Test and commit

  • Run cargo fmt --all -- --check, cargo build, and cargo test.
  • Cover edge cases: zero cap rejected, negative cap rejected, smallest valid positive cap, and cap above the bps fee (no clamp).
  • Include the full cargo test output and a short security notes section in the PR description.

Example commit message

security: reject a zero MaxFeeAbsolute cap that would zero all protocol fees

Guidelines

  • Minimum 95 percent test coverage for impacted modules.
  • Clear, reviewer-focused documentation.
  • Timeframe: 96 hours.

Community & contribution rewards

  • 💬 Join the StableRoute community on Discord for questions, reviews, and faster merges: https://discord.gg/37aCpusvx
  • ⭐ This is a GrantFox OSS / Official Campaign task and may be rewarded. When your PR is merged you'll be prompted to rate the project — if this issue and the maintainers helped you ship, we'd be grateful for a 5-star rating. Clear questions in Discord and tidy, well-tested PRs are the fastest path to a merge and a reward.

Metadata

Metadata

Assignees

No one assigned

    Fields

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions