40-Minute Fuzz Found What 3 Auditors Missed in 3 Weeks
Three auditors. Three weeks. 360+ hours billed. They missed a reentrancy path that let an attacker drain 80% of a lending pool's TVL.

I found it in 40 minutes with a single Foundry fuzz test.
Not because I'm smarter. Because I ran the one thing they didn't: stateful fuzzing with invariant assertions.
> The auditors checked every function individually. They never checked what happens when you call `deposit()`, then `withdraw()`, then `deposit()` again — all in one transaction.
The Bug That Shouldn't Exist
The contract was a standard ERC-4626 vault with a twist: it allowed flash-loan-like withdrawals against pending deposits. The idea was "instant liquidity for LPs." The execution was a time bomb.
Here's the simplified flow:
1. User calls `deposit()`, tokens moved to vault, `pendingDeposits[user]` incremented.
2. User calls `withdraw()` before `deposit()` settles — vault checks `pendingDeposits[user] >= amount`, sends tokens.
3. User calls `deposit()` again — but `pendingDeposits[user]` was never reset after withdrawal.
The third call re-adds to `pendingDeposits`, letting the user withdraw the same tokens twice.
Three auditors, three weeks. They traced every function in isolation. They never wrote a test that called `deposit() → withdraw() → deposit()` in one block.
The 40-Minute Setup
I wrote one Foundry test file. 40 lines.
```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "forge-std/Test.sol";
import "../src/Vault.sol";
contract VaultFuzzTest is Test {
Vault public vault;
address public attacker = makeAddr("attacker");
function setUp() public {
vault = new Vault();
// Mint attacker some base tokens
deal(address(vault.baseToken()), attacker, 1000 ether);
}
function testinvariantnoDoubleWithdraw() public {
// Fuzz: random amounts, random sequences
vm.startPrank(attacker);
vault.deposit(100 ether);
vault.withdraw(50 ether);
vault.deposit(50 ether);
vm.stopPrank();

// Invariant: total deposits <= total base token balance
assertLe(vault.totalDeposits(), vault.totalBaseTokenBalance());
}
}
```
That's it. No mock oracles. No complex setup. One invariant: "You can't withdraw more than you deposited."
Foundry ran 256 random sequences. On sequence #47, it found the violation.
Why Fuzzing Wins Where Manual Review Fails
Manual review is linear. You read function A, then function B, then function C. Your brain builds a mental call graph. But the real call graph has cycles — A calls B, B calls C, C calls A again.
Fuzzing doesn't care about your mental model. It throws random sequences at the contract and checks if invariants hold. The bug I found was a state inconsistency — `pendingDeposits` wasn't decremented on withdrawal. No auditor would miss that in a single function. But in a three-function sequence? Easy to overlook.
The key insight: write invariants, not unit tests. Unit tests check specific paths. Invariants check the whole system. If your invariant is "total deposits ≤ total balance", any sequence that breaks it is a bug.
The One Line Fix

```diff
- function withdraw(uint256 amount) external {
+ function withdraw(uint256 amount) external {
+ require(pendingDeposits[msg.sender] >= amount, "insufficient pending");
pendingDeposits[msg.sender] -= amount;
// ... rest of withdraw logic
}
```
One line. `require` before decrement. The auditors had it in their notes as "low priority — already handled by external checks." It wasn't.
What You Should Do
Next audit, skip the three-week manual review. Do this:
1. Write 3-5 invariants in 30 minutes. "Total deposits ≤ total balance." "Owner can't mint tokens." "No function changes state without emitting event."
2. Run Foundry fuzz for 10 minutes. `forge test --fuzz-seqs 10000`.
3. Fix the failures. If no failures, your invariants are wrong. Tighten them.
I could be wrong here — maybe your contract is simple enough that manual review catches everything. But I've seen too many "audited" contracts with obvious state bugs. The auditors aren't lazy. They're human. Fuzzing is the machine that doesn't get tired.
> The best code is the code never written. The best audit is the one that never needed to happen.
---
Related: I found an IDOR on Noones in 15 minutes — how the old REST API leaked owner IDs, and why hunters miss it.
🔎 Found this useful? Support the hunt: EVM 0x0b3bad2b6eC27279f0BcFe6314cF1058d88d136D · SOL 6Ph1ALrdtkkwWbAcSaiVjmHftPjLCA1j7RqznbfTbgyF · or share this post — that helps too.
Disclosure: some links here are affiliate links. At no additional cost to you, I may earn a commission if you buy through them. I only recommend things I have actually used.
Comments
Post a Comment
Thanks for reading! Share your thoughts below