Skip to content
Smart contracts Audit finding Intermediate

First ERC4626 deposit can break share calculation

The first depositor of an ERC4626 vault can deposit a tiny amount and then donate assets directly to the vault, inflating the share price. A later depositor then receives zero shares due to rounding down, losing their deposited funds.

ak1 Follow with 0xNazgul, joestakey and 6 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-10-astaria-judging/issues/143

Found by

ak1, 0xNazgul, joestakey, rvierdiiev, neila, pashov, Jeiwan, ctf_sec, __141345__

Summary

The first depositor of an ERC4626 vault can maliciously manipulate the share price by depositing the lowest possible amount (1 wei) of liquidity and then artificially inflating ERC4626.totalAssets.

This can inflate the base share price as high as 1:1e18 early on, which force all subsequence deposit to use this share price as a base and worst case, due to rounding down, if this malicious initial deposit front-run someone else depositing, this depositor will receive 0 shares and lost his deposited assets.

Vulnerability Detail

Given a vault with DAI as the underlying asset:

Alice (attacker) deposits initial liquidity of 1 wei DAI via deposit() Alice receives 1e18 (1 wei) vault shares Alice transfers 1 ether of DAI via transfer() to the vault to artificially inflate the asset balance without minting new shares. The asset balance is now 1 ether + 1 wei DAI -> vault share price is now very high (= 1000000000000000000001 wei ~ 1000 * 1e18) Bob (victim) deposits 100 ether DAI Bob receives 0 shares Bob receives 0 shares due to a precision issue. His deposited funds are lost.

The shares are calculated as following return supply == 0 ? assets : assets.mulDivDown(supply, totalAssets()); In case of a very high share price, due to totalAssets() > assets * supply, shares will be 0.

Impact

ERC4626 vault share price can be maliciously inflated on the initial deposit, leading to the next depositor losing assets due to precision issues.

Code Snippet

https://github.com/sherlock-audit/2022-10-astaria/blob/main/lib/astaria-gpl/src/ERC4626-Cloned.sol#L392

Tool used

Manual Review

Recommendation

This is a well-known issue, Uniswap and other protocols had similar issues when supply == 0.

For the first deposit, mint a fixed amount of shares, e.g. 10**decimals()

JSX
if (supply == 0) {
    return 10**decimals; 
} else {
    return assets.mulDivDown(supply, totalAssets());
}

The original report as published on Sherlock, by ak1. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The share calculation uses the current asset balance, which can be inflated by direct transfers, and rounds down, so a very high share price causes new deposits to mint zero shares.

Impact

The next depositor can lose their entire deposit because they receive zero shares, and the attacker may profit from the inflated share price.

What the attacker needed

Attacker is first depositor; victim deposits after inflation

The fix

For the first deposit, mint a fixed number of shares (e.g., 10**decimals) instead of using the asset amount, to prevent share price inflation.

How it was found

  1. Attacker deposits 1 wei of the underlying asset and receives 1 wei of vault shares.
  2. Attacker transfers a large amount of the asset directly to the vault, inflating totalAssets without minting new shares.
  3. Victim deposits a normal amount of the asset.
  4. Victim receives zero shares because the share price is extremely high and the calculation rounds down.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A vault lets people put in tokens and get shares representing their portion. The first person to deposit can put in a tiny amount, then send extra tokens directly to the vault without getting shares, making each share seem very valuable. When someone else deposits, the maths rounds down and they may get zero shares, so their tokens are effectively stolen.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by ak1

View all

6 more disclosed reports, best first.

More from Astaria

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.