Skip to content

Add proptest fuzz harness for swap invariants#116

Merged
ameeribro4-sudo merged 1 commit into
OpenPeerX:mainfrom
Kandexa:fix/issue-44-proptest-fuzz-harness
Jul 21, 2026
Merged

Add proptest fuzz harness for swap invariants#116
ameeribro4-sudo merged 1 commit into
OpenPeerX:mainfrom
Kandexa:fix/issue-44-proptest-fuzz-harness

Conversation

@Kandexa

@Kandexa Kandexa commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Added a proptest-based fuzz harness for swap operations to verify contract invariants under adversarial random inputs.

Changes

  • src/fuzz.rs: New proptest strategy module with 5 strategy variables (amount, fee_bps, oracle_staleness, slippage, user_balance) plus pool_reserves and dust_amount for edge cases
  • src/lib.rs: Added #[cfg(test)] mod fuzz; declaration
  • 7 fuzz targets covering: AMM constant-product invariant, positive output guarantee, fee bounds, slippage consistency, balance non-negativity, output bounds, and dust-swap safety
  • 30 random sequences per target (proptest Config::with_cases(30))
  • All targets verify core contract invariants under random adversarial inputs
  • Verified formatting
  • No unrelated changes introduced

Closes #44

Add property-based fuzz testing with proptest to verify swap invariants
under adversarial random inputs including dust amounts, exact-1.0 ratios,
and large values.

- New src/fuzz.rs with proptest strategy module
- 5 strategy variables: amount, fee_bps, oracle_staleness, slippage,
  user_balance (plus pool_reserves and dust_amount for edge cases)
- 7 fuzz targets covering AMM invariant, positive output, fee bounds,
  slippage consistency, balance non-negativity, output bounds, and
  dust-swap safety
- 30 random sequences per target (proptest Config::with_cases(30))
- All fuzz targets verify core contract invariants

Closes OpenPeerX#44

@ameeribro4-sudo ameeribro4-sudo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ameeribro4-sudo
ameeribro4-sudo merged commit c1ea98d into OpenPeerX:main Jul 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[PeerX Backlog # 44] Add fuzz harness for swap with proptest

2 participants