Frontrun `deposit()` can cause the depositor to lose all the funds
The vault contract's deposit and token transfer functions calculate new shares based on the existing balance, so if an attacker frontruns the first depositor by sending a small amount of LINK tokens directly to the vault, the depositor's shares round down to zero. The depositor and all future depositors lose their funds.
Source: https://github.com/sherlock-audit/2022-10-mycelium-judging/tree/main/029-M
Found by
ctf_sec, Lambda, CRYP70, 8olidity, bin2chen, hansfriese, innertia, dipp, rbserver, CodingNameKiki, WATCHPUG
Summary
The attacker can frontrun the first depositor's deposit() transaction and transfer LINK tokens to the Vault contract directly and cause the depositor (and all the future depositors) to lose all the funds.
Vulnerability Detail
In onTokenTransfer(), if there are some existing balance in the Vault contract, say 1 wei of LINK token, supplyBeforeTransfer will be 1, since totalShares == 0, newShares will always be 0.
The same applies for deposit().
Impact
The depositor who got frontrun by the attacker will lose all their funds. And all the future depositors.
Code Snippet
Tool used
Manual Review
Recommendation
It should check if totalShares == 0 to decide whether this is the first mint.
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
Likely the share calculation uses the vault's token balance instead of checking whether any shares exist, so a non-zero balance with zero total shares causes new shares to round down to zero.
Impact
The depositor who is frontrun loses all their funds, and all future depositors also lose their funds.
What the attacker needed
Attacker can frontrun the first deposit; vault has no shares yet
The fix
The contract should check whether total shares are zero to determine if this is the first mint.
How it was found
- Attacker sends a small amount of LINK tokens directly to the vault contract before the first depositor's deposit transaction.
- The first depositor's deposit transaction executes, but because the vault already has a balance and total shares are zero, the calculated new shares are zero.
- The depositor receives no shares and loses the deposited funds.
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.
When you put money into a shared vault, you get shares representing your portion. If someone else puts in a tiny amount first, the maths can round your shares down to zero, so you lose your money. This report shows that an attacker can do that by sending a small amount before your deposit.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.