Skip to content

Extend the Cross-Contract Invariant Fuzzer Into the Untouched Snapshot Subsystem #1830

Description

@Emmyt24

Description

contracts/token-factory/fuzz/fuzz_targets/cross_contract_invariants.rs (documented in contracts/token-factory/docs/CROSS_CONTRACT_INVARIANT_FUZZING.txt) fuzzes an Action enum of Mint, Burn, Delegate, Undelegate, Vote against the invariant sum(governance.get_vote_power) <= token_factory.total_supply, asserted after every single action. governance's public surface also includes take_snapshot/get_snapshot_power (used by real proposals to fix vote power at a point in time per delegation.rs's doc comment), but the fuzz harness never calls either — the snapshot subsystem is completely unexercised by the one place this repo does adversarial cross-contract testing of governance's bookkeeping.

Requirements and Context

  • Must not change the existing Action variants' behavior or the invariant assertion's semantics for the current five actions — purely additive.
  • Per contracts/token-factory/fuzz/Cargo.toml's comment, this crate must remain detached from the parent workspace and keep using the pre-built governance.wasm via contractimport! rather than a direct crate dependency.

Suggested Execution

Branch: test/fuzz-cross-contract-snapshot-actions

Implement Changes

  • Add a TakeSnapshot { holder_idx: u8 } variant to the Action enum in contracts/token-factory/fuzz/fuzz_targets/cross_contract_invariants.rs, dispatching to gov.try_take_snapshot(holder).
  • In assert_invariant (or a new sibling assertion function), after a snapshot is taken, verify gov.get_snapshot_power(holder, current_ledger) matches the holder's live get_vote_power at the moment the snapshot was recorded, and that the snapshotted value itself never exceeds total_supply.
  • Update contracts/token-factory/docs/CROSS_CONTRACT_INVARIANT_FUZZING.txt's Action list and harness description to mention the new variant.

Test and Commit

Run cargo test --lib (and cargo test for proptest/fuzz targets where relevant) in the appropriate contracts/<governance|token-factory> directory, confirming the new coverage passes and cargo build --target wasm32v1-none --release --lib still succeeds. For this fuzz target specifically, also confirm cargo build -p governance --release --target wasm32-unknown-unknown followed by cargo fuzz run cross_contract_invariants -- -max_total_time=60 (from contracts/token-factory/fuzz/) runs cleanly with the new action included.

Example Commit Message

test(contract): add snapshot actions to cross-contract invariant fuzz target

Closes #<issue>

Guidelines

  • Branch from main, open a PR back to main
  • All new code must have corresponding tests
  • Run cargo fmt --check, cargo clippy, and cargo test --lib before pushing
  • Follow existing naming conventions and file structure
  • PR description must reference this issue number (e.g., Closes #<issue>)
  • Keep commits atomic and use conventional commit format

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programcontractSoroban smart contract worktestingTesting-focused contribution

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions