Works with the AI Agents you already use

    Foundry Invariant Fuzzing

    by BanditXBT

    1

    Foundry fuzz, fork and stateful invariant testing with handlers and ghost variables for DeFi logic.

    $3.15

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    About this skill

    Unit tests prove examples; invariants prove the protocol cannot reach a bad state through any call sequence.

    1. Unit/regression: one test per known behavior and per fixed bug (test_RevertWhen_..., test_..._Succeeds). Use vm.expectRevert(abi.encodeWithSelector(...)) with exact errors.
    2. Stateless fuzz: function testFuzz_X(uint256 a, ...); constrain with bound(x, min, max) (not vm.assume for wide filters: it discards runs). Properties: round-trip (deposit→withdraw ≤ deposit), monotonicity, rounding direction, "never reverts for valid input", conservation of value.
    3. Fork tests: vm.createSelectFork(rpc, blockNumber) pinned to a block for determinism; use for real tokens (USDT/USDC quirks, fee-on-transfer), real oracles, integration with live protocols. Run per target chain.
    4. Stateful invariants: invariant_* functions checked after random call sequences.
    5. Formal/symbolic (when valuable): Halmos for bounded symbolic checks on arithmetic-heavy functions (e.g., margin math); Echidna/Medusa for coverage-guided campaigns with corpus reuse.
    • Write 5-10 protocol-level properties first (solvency, conservation, access, monotonic accumulators). For derivatives: Σ user equity + insurance ≥ 0 and ≤ vault assets, OI_long == OI_short (or within skew cap), funding index never decreases unexpectedly, healthy account stays healthy after unrelated actions, liquidation never increases account risk, no position opens below initial margin.
    • Handler pattern: a Handler contract exposes bounded actor actions (open, close, addCollateral, liquidate, warp time, move oracle price, donate, pause). Use targetContract(handler); bound all inputs; pick actors from a fixed set (vm.startPrank(actors[seed % n])).
    • Ghost variables track expected totals off-protocol (sum of deposits, realized PnL) to compare against on-chain state.
    • Include adversarial actions (donation, dust amounts, zero values, price jumps, time jumps, reentrant token) so the fuzzer explores them; guard against false positives from unreachable states.
    • Avoid revert-hiding: set fail_on_revert = false only with handlers that already bound inputs; track call and revert counts in the handler (ghost counters) to ensure meaningful calls happen, and inspect with forge test -vvv.
    1. List invariants → write handler → run small → inspect call distribution → increase runs/depth.
    2. On failure: shrink, replay with -vvvv, minimal repro test, find the root cause by minimizing the call sequence and inspecting state at the first violated invariant (not just the last call), fix, keep the test.
    3. Mutation check: break the contract on purpose (flip a <, remove a check, change rounding direction); the suite must fail. Use vertigo-rs/gambit if available; otherwise manual.
    4. Gas and size: forge snapshot, forge build --sizes (24 KB limit); keep gas regressions in CI.
    5. Coverage: forge coverage --report lcov to find unexercised branches; coverage guides, invariants decide.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 13 days ago

    Software
    Foundry

    Permissions

    No special permissions declared or detected

    Listed13 days ago

    What's inside

    Frequently Asked Questions

    Foundry fuzz, fork and stateful invariant testing with handlers and ghost variables for DeFi logic.

    This skill uses the open SKILL.md standard. Use it through an MCP-compatible agent connected to Agensi, and check the compatibility information on this page for confirmed agents and required capabilities.

    Connect your AI agent to Agensi through MCP, then ask it to use foundry-invariant-fuzzing on your task. Your agent loads the latest approved version each time. Paid skills require a purchase or active subscription. Skill files are not available for download; your licence does not allow you to save, copy or export any part of a skill.

    New in Security

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Security.