<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kestrova</title>
    <description>The latest articles on DEV Community by Kestrova (@kestrova).</description>
    <link>https://dev.to/kestrova</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4255989%2Fd008ed52-4ebe-435c-b97f-b3b008009aa6.png</url>
      <title>DEV Community: Kestrova</title>
      <link>https://dev.to/kestrova</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kestrova"/>
    <language>en</language>
    <item>
      <title>Let your coding agent catch reentrancy before it deploys a Solidity contract</title>
      <dc:creator>Kestrova</dc:creator>
      <pubDate>Fri, 20 Nov 2026 15:50:01 +0000</pubDate>
      <link>https://dev.to/kestrova/let-your-coding-agent-catch-reentrancy-before-it-deploys-a-solidity-contract-5296</link>
      <guid>https://dev.to/kestrova/let-your-coding-agent-catch-reentrancy-before-it-deploys-a-solidity-contract-5296</guid>
      <description>&lt;p&gt;AI coding agents write Solidity fast. They also write this, more often than you'd like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract Vault {
    mapping(address =&amp;gt; uint256) public balances;

    function deposit() external payable {
        balances[msg.sender] += msg.value;
    }

    function withdraw() external {
        uint256 amount = balances[msg.sender];
        require(amount &amp;gt; 0, "nothing to withdraw");
        (bool ok, ) = msg.sender.call{value: amount}("");
        require(ok, "transfer failed");
        balances[msg.sender] = 0;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It compiles and the happy-path tests pass. But &lt;code&gt;withdraw&lt;/code&gt; sends ETH before it zeroes the balance. A contract that receives that ETH can call &lt;code&gt;withdraw&lt;/code&gt; again from its &lt;code&gt;receive()&lt;/code&gt; 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.&lt;/p&gt;

&lt;p&gt;The cheapest place to catch it is before &lt;code&gt;forge script&lt;/code&gt; or &lt;code&gt;hardhat deploy&lt;/code&gt; 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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: give the agent a scanner
&lt;/h2&gt;

&lt;p&gt;Kestrova is a hosted Slither scan exposed as a remote MCP server. There's no API key, no account and no local &lt;code&gt;solc&lt;/code&gt; install. Add it to Claude Code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;claude mcp add --transport http kestrova https://kestrova-api.onrender.com/mcp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For Cursor or VS Code there are one-click install links on the &lt;a href="https://kestrova-api.onrender.com/developers" rel="noopener noreferrer"&gt;developers page&lt;/a&gt;, and in Claude.ai or ChatGPT you can add the same URL as a custom connector.&lt;/p&gt;

&lt;p&gt;The agent now has a free tool, &lt;code&gt;scan_solidity_preview&lt;/code&gt;. A good instruction to add to your &lt;code&gt;CLAUDE.md&lt;/code&gt; or rules file:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;After writing or changing a Solidity contract, and before any deploy step, run &lt;code&gt;scan_solidity_preview&lt;/code&gt; on the contract and its imports. If it reports High or Medium findings, fix them and scan again.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Step 2: what the free check returns
&lt;/h2&gt;

&lt;p&gt;Here is the real preview for the &lt;code&gt;Vault&lt;/code&gt; above (trimmed):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"counts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"High"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"Informational"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"detectors"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"reentrancy-eth"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"sample_finding"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"detector"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"reentrancy-eth"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"impact"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"High"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Possible reentrancy (ETH can be withdrawn repeatedly)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"explanation"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"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."&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;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:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function withdraw() external {
    uint256 amount = balances[msg.sender];
    require(amount &amp;gt; 0, "nothing to withdraw");
    balances[msg.sender] = 0;                          // effect first
    (bool ok, ) = msg.sender.call{value: amount}("");  // interaction last
    require(ok, "transfer failed");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;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 &lt;code&gt;ReentrancyGuard&lt;/code&gt; as well.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: when the agent needs exact lines
&lt;/h2&gt;

&lt;p&gt;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 &lt;a href="https://x402.org" rel="noopener noreferrer"&gt;x402&lt;/a&gt;: the HTTP 402 payment standard for agents.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;scan_solidity_findings&lt;/code&gt; (or &lt;code&gt;POST /scan/findings&lt;/code&gt;): every finding with file and line, as JSON. 0.25 USDC.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;scan_solidity_full&lt;/code&gt; (or &lt;code&gt;POST /scan&lt;/code&gt;): 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.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Payment is USDC on Base or Solana mainnet. The flow is the standard x402 one: the first request returns &lt;code&gt;402&lt;/code&gt; with the terms in a &lt;code&gt;PAYMENT-REQUIRED&lt;/code&gt; header, the agent's wallet signs exactly that amount, and the same request is repeated with a &lt;code&gt;PAYMENT-SIGNATURE&lt;/code&gt; header. The facilitator pays the network fee, so the wallet only needs USDC. You're charged only if the scan succeeds.&lt;/p&gt;

&lt;p&gt;A single finding from the 0.25 tier looks like this (from a different test contract):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"detector"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"arbitrary-send-eth"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"impact"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"High"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"confidence"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Medium"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Vault.sweep(address) (Vault.sol#20-23) sends eth to arbitrary user ..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"locations"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"file"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Vault.sol"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"lines"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"scope"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"application"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two rules are worth putting in your agent's instructions if you let it pay:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Ask the user first&lt;/strong&gt; and show the price. The server's &lt;code&gt;payment_terms&lt;/code&gt; tool returns it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Never pay twice.&lt;/strong&gt; If a paid call times out or comes back &lt;code&gt;202 pending&lt;/code&gt;, the agent shouldn't retry with a new payment. It should recover the result with &lt;code&gt;POST /scan/recover&lt;/code&gt;, a free wallet-signed challenge. The step-by-step is in the &lt;a href="https://kestrova-api.onrender.com/developers#agent-payment" rel="noopener noreferrer"&gt;agent payment guide&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What this is and isn't
&lt;/h2&gt;

&lt;p&gt;This is automated pattern detection with Slither: reentrancy, unchecked low-level calls, &lt;code&gt;tx.origin&lt;/code&gt; 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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;If you want to see a complete paid report before you wire anything up, there's a &lt;a href="https://kestrova-api.onrender.com/sample-report" rel="noopener noreferrer"&gt;sample report&lt;/a&gt; on a fictional contract.&lt;/p&gt;

</description>
      <category>solidity</category>
      <category>security</category>
      <category>ai</category>
      <category>web3</category>
    </item>
  </channel>
</rss>
