/auditsentry:invariant <contract-or-file>from auditsentry
Generates Foundry invariant tests for property-based fuzzing. Reads a Solidity contract, identifies protocol-specific invariants (token, vault, AMM, lending, governance), produces a harness with Handler contract, and runs fuzz tests via forge-runner.
Ships in auditsentry. Installing the plugin adds it to Claude Code.
Property-based testing in Foundry. The single highest-leverage test artifact you can produce — invariants catch bugs no example-based test does.
Dispatch invariant-writer subagent. It reads the contract and proposes invariants based on protocol type:
Token / ERC-20:
totalSupply() == sum(balanceOf(a) for a in all_addrs)Vault / ERC-4626:
totalAssets() >= sum(convertToAssets(balanceOf(a)) for a in all_holders)previewDeposit + previewWithdraw round-trip ≤ initial valuetotalSupply == 0 ⇒ totalAssets == 0deposit/mint, only burnable via withdraw/redeemAMM:
K = reserve0 * reserve1 non-decreasing after fee-paying swapsLending:
sumDebt <= sumCollateralValue * MAX_LTV (modulo bad debt)Governance:
contract VaultInvariants is Test {
Vault vault;
Handler handler; // ← actor that calls arbitrary fns with bounded random inputs
function setUp() public {
vault = new Vault();
handler = new Handler(vault);
targetContract(address(handler));
}
function invariant_TotalAssetsCoversShares() public {
uint256 sum;
address[] memory users = handler.getActors();
for (uint i; i < users.length; ++i) {
sum += vault.convertToAssets(vault.balanceOf(users[i]));
}
assertGe(vault.totalAssets(), sum, "vault would be insolvent");
}
}
Plus a Handler contract that has deposit, withdraw, transfer, etc. — each bounded to realistic random inputs.
Use forge-runner MCP:
mcp__forge-runner__test(test="invariant", flags="--fuzz-runs 5000")
If an invariant breaks, that's a finding. Reduce the failing seed to a minimal counter-example and surface as a finding.
Invariants generated for Vault:
✓ invariant_TotalAssetsCoversShares 5000/5000 runs
✓ invariant_DepositReducesAssetsBalance 5000/5000 runs
✗ invariant_PreviewWithdrawIsExact 4982/5000 runs
Counter-example for invariant_PreviewWithdrawIsExact:
seed: 0xabc...
calls: deposit(85), deposit(1), withdraw(86)
actual: previewWithdraw mismatched by 1 wei (rounding)
The counter-example becomes a finding.
Handler is the key — bad handlers find no bugs. Make sure the handler covers all realistic state transitions./symbolic (Halmos) for invariants that fuzzing can't reach.What the command file sets; muted values are Claude Code's defaults
foundry, invariant-testing, property-based-testing, fuzzing, solidity
7-day visitors to each command page
npx claudepluginhub iktok90-design/ai-smart-contract-auditor --plugin auditsentry45 commands in this plugin
/audit/audit — full security auditFull security audit of a Solidity/Vyper/Rust contract or directory. Runs the entire vuln-skills library and dispatches DeFi specialist subagents based on detected protocol type./audit-changes/audit-changes — audit only what changedAudit only the git diff vs main (or specified base). Optimized for PR review./audit-deep/audit-deep — multi-pass adversarial auditDeep audit — same as /audit but spawns more parallel subagents, runs multi-pass review, and chases exploit chains across files./audit-deps/audit-deps — vet the libraries you importAudit third-party dependencies — resolve installed versions, cross-reference known-vulnerable releases, and flag vendored code that has diverged from upstream./audit-diff/audit-diff — regression diff between two auditsDiff two AuditSentry audit reports (before vs after) to track regressions — what's new, what's fixed, and whether the grade moved./audit-history/audit-history — what's been found beforePull past public audits (Code4rena, Sherlock, Spearbit, etc.) for a deployed contract or known protocol.Other plugins' commands for the same job