AI coding agents write Solidity fast. They also write this, more often than you'd like:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract Vault {
mapping(address => uint256) public balances;
function deposit() external payable {
balances[msg.sender] += msg.value;
}
function withdraw() external {
uint256 amount = balances[msg.sender];
require(amount > 0, "nothing to withdraw");
(bool ok, ) = msg.sender.call{value: amount}("");
require(ok, "transfer failed");
balances[msg.sender] = 0;
}
}
It compiles and the happy-path tests pass. But withdraw sends ETH before it zeroes the balance. A contract that receives that ETH can call withdraw again from its receive() function, and keep doing it until the vault is empty. This is the classic reentrancy pattern, and it is still one of the most common findings in contracts that never got a review.
The cheapest place to catch it is before forge script or hardhat deploy runs, inside the agent's own loop. This post shows one way to do that with an MCP tool, so the agent checks its own contract the same way it runs tests.
Step 1: give the agent a scanner
Kestrova is a hosted Slither scan exposed as a remote MCP server. There's no API key, no account and no local solc install. Add it to Claude Code:
claude mcp add --transport http kestrova https://kestrova-api.onrender.com/mcp
For Cursor or VS Code there are one-click install links on the developers page, and in Claude.ai or ChatGPT you can add the same URL as a custom connector.
The agent now has a free tool, scan_solidity_preview. A good instruction to add to your CLAUDE.md or rules file:
After writing or changing a Solidity contract, and before any deploy step, run
scan_solidity_previewon the contract and its imports. If it reports High or Medium findings, fix them and scan again.
Step 2: what the free check returns
Here is the real preview for the Vault above (trimmed):
{
"counts": { "High": 1, "Informational": 2 },
"detectors": ["reentrancy-eth"],
"sample_finding": {
"detector": "reentrancy-eth",
"impact": "High",
"title": "Possible reentrancy (ETH can be withdrawn repeatedly)",
"explanation": "A function sends ETH or calls another contract before it finishes updating its own balances. A malicious contract can call back in during that call and repeat the withdrawal."
}
}
For a contract this small that's enough for the agent to fix it. It applies checks-effects-interactions, so the state change comes before the external call:
function withdraw() external {
uint256 amount = balances[msg.sender];
require(amount > 0, "nothing to withdraw");
balances[msg.sender] = 0; // effect first
(bool ok, ) = msg.sender.call{value: amount}(""); // interaction last
require(ok, "transfer failed");
}
It then scans again. On the fixed version the High finding is gone, and only the two informational notes remain. In a real project you'd usually add OpenZeppelin's ReentrancyGuard as well.
The free preview covers files up to 15 KB, 10 files per call. OpenZeppelin imports are resolved when you submit the package files under their usual paths.
Step 3: when the agent needs exact lines
On a real codebase, "1 High, 4 Medium" isn't enough. The agent needs to know where each finding is. That part is paid, per call, using x402: the HTTP 402 payment standard for agents.
-
scan_solidity_findings(orPOST /scan/findings): every finding with file and line, as JSON. 0.25 USDC. -
scan_solidity_full(orPOST /scan): the same, plus a plain-English explanation and fix per finding, and PDF and SARIF files you can upload to GitHub code scanning. 1 USDC.
Payment is USDC on Base or Solana mainnet. The flow is the standard x402 one: the first request returns 402 with the terms in a PAYMENT-REQUIRED header, the agent's wallet signs exactly that amount, and the same request is repeated with a PAYMENT-SIGNATURE header. The facilitator pays the network fee, so the wallet only needs USDC. You're charged only if the scan succeeds.
A single finding from the 0.25 tier looks like this (from a different test contract):
{
"detector": "arbitrary-send-eth",
"impact": "High",
"confidence": "Medium",
"description": "Vault.sweep(address) (Vault.sol#20-23) sends eth to arbitrary user ...",
"locations": [{ "file": "Vault.sol", "lines": [20, 23] }],
"scope": "application"
}
Two rules are worth putting in your agent's instructions if you let it pay:
-
Ask the user first and show the price. The server's
payment_termstool returns it. -
Never pay twice. If a paid call times out or comes back
202 pending, the agent shouldn't retry with a new payment. It should recover the result withPOST /scan/recover, a free wallet-signed challenge. The step-by-step is in the agent payment guide.
What this is and isn't
This is automated pattern detection with Slither: reentrancy, unchecked low-level calls, tx.origin authorization, arbitrary ETH sends, shadowing and the rest of Slither's detector set. It doesn't understand your business logic, economic or oracle attacks, or upgrade and admin-key risk. Zero findings doesn't mean a contract is safe, and it's not an audit.
It does make a coding agent noticeably harder to embarrass. The bug above is the kind that slips through when nobody reads the code before it goes on-chain.
If you want to see a complete paid report before you wire anything up, there's a sample report on a fictional contract.
Top comments (0)