Skip to content

[profit] No overflow boundary tests — arithmetic_side_effects deny lint requires u64 boundary coverage #156

@obchain

Description

@obchain

Refs #40

File: crates/charon-core/src/profit.rs (tests module)

PR branch: feat/15-profit-calc-and-queue

Problem:
The workspace deny(arithmetic_side_effects, cast_possible_truncation) lints require all arithmetic to be explicitly checked. The PR claims checked_mul is used, satisfying the lint. However the 5 unit tests use small, well-behaved values and do not exercise:

  • repay_amount_cents near u64::MAX (checked_mul returns None — verify error path)
  • liquidation_bonus_bps == 10_000 (max valid; gross == 2x repay — borderline overflow check)
  • liquidation_bonus_bps == 10_001 (invalid — verify rejection fires correctly)
  • flash_fee + gas + slippage > gross (net goes negative in signed arithmetic or wraps in unsigned — verify the error variant is Overflow not BelowMinThreshold)
  • All costs == gross exactly (net == 0 — boundary between rejection and acceptance)
  • min_profit_usd_cents == 0 (should every positive net profit pass?)

These cases are especially important because calculate_profit is a safety gate. A test suite that passes on happy-path values gives false confidence.

Fix: Add proptest or table-driven tests covering the above boundary values. For the negative-net case verify the exact error variant returned. For u64::MAX repay verify checked_mul returns Overflow not a panic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    layer:rustRust crates (core / scanner / protocols / executor / cli)pr-reviewFindings from PR review processpriority:p2-polishNice-to-have / polishstatus:readyScoped and ready to pick uptype:testTests, fuzz, fork, integration

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions