Skip to content

Contracts: Add fuzz target for campaign contract registration logic #282

@joelpeace48-cell

Description

@joelpeace48-cell

Summary

The rewards contract has a fuzz target at contracts/rewards/fuzz/fuzz_targets/fuzz_balance.rs that randomizes credit/claim sequences. The campaign contract has no fuzz coverage, leaving participant registration, Merkle proof verification, cap enforcement, and time window logic untested by property-based randomization.

Problem

Campaign contract logic involves multiple interacting invariants:

  • Registration is idempotent (double register returns false, count does not increase)
  • Cap is never exceeded (participant_count ≤ max_cap when max_cap > 0)
  • Time window is enforced (no registration outside [start, end])
  • Merkle proof rejection (invalid proof must never register participant)

These invariants can be broken by edge cases that unit tests miss. Fuzzing catches them systematically.

Acceptance Criteria

  • Create contracts/campaign/fuzz/ directory structure mirroring contracts/rewards/fuzz/
  • Add fuzz_targets/fuzz_register.rs that:
    • Generates random (participant, cap, start, end, current_ledger, merkle_root_set) inputs
    • Calls register with valid/invalid parameters
    • Asserts: participant_count <= max_cap always
    • Asserts: if participant was successfully registered twice, count only incremented once
    • Asserts: if outside time window, Error::OutsideTimeWindow is returned
  • Add Cargo.toml and Cargo.lock for the fuzz workspace
  • Document how to run the fuzz target in contracts/campaign/README.md or a new FUZZING.md
  • Wire the fuzz build into contracts-ci.yml as an optional cargo fuzz build step

References

  • contracts/rewards/fuzz/fuzz_targets/fuzz_balance.rs — existing fuzz target to mirror
  • contracts/campaign/src/lib.rs — target logic
  • .github/workflows/contracts-ci.yml

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions