Skip to content

get_fee_config()'s checked_mul overflow fallback silently defaults to 2000 bps instead of surfacing a genuine inconsistency #259

Description

@SYLVIANNORUKA

Description
get_fee_config()'s fallback path computes fee_bps: default_pct.checked_mul(100).unwrap_or(2000) when no per-token FeeConfig override exists. Since default_pct is a u32 percentage that is validated elsewhere to be at most 100, default_pct * 100 can never exceed 10_000 and this overflow branch can never actually execute -- but if that invariant is ever violated by a future change (e.g. a validation bug elsewhere lets DefaultFee exceed 100), the function would silently return a plausible-looking 2000 bps (20%) instead of surfacing the inconsistency, masking exactly the kind of bug this fallback should catch.

Affected modules: contracts/hamplard/src/lib.rs

An overflow fallback that can currently never trigger would, if it ever did, silently substitute a made-up fee value instead of failing loudly.

Expected Behavior
If DefaultFee is ever found to be out of its expected 0-100 range, get_fee_config() should panic with a clear error rather than silently substituting a default basis-points value.

Tasks

Replace .unwrap_or(2000) with an explicit panic (or expect with a descriptive message) in get_fee_config().

Add a regression test (e.g. via a test-only storage write) confirming an out-of-range DefaultFee is surfaced rather than silently masked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions