Platform: Code4rena
Start Date: 20/01/2022
Pot Size: $80,000 USDC
Total HM: 5
Participants: 37
Period: 7 days
Judge: Jack the Pug
Total Solo HM: 1
Id: 76
League: ETH
Rank: 3/37
Findings: 1
Award: $10,957.14
🌟 Selected for report: 1
🚀 Solo Findings: 0
10957.1383 USDC - $10,957.14
egjlmn1
A user who joins the systems first (stakes first) can steal everybody's tokens by sending tokens to the system externally. This attack is possible because you enable staking a small amount of tokens.
See the following attack:
ERC20.transfer
shares = (_amount * totalStakeShares_) / (totalTokenBalanceStakers() - _amount);
shares = (X * 1) / (X + 1 + X - X) = X/(X+1) = 0
meaning all the tokens he staked got him no shares, and those tokens are now a part of the single share that user A holdsERC20.transfer
to the system because all the money in the system is in a single share that user A holds.In general, since there is only a single share, for any user who is going to stake X tokens, if the system has X+1 tokens in its balance, the user won't get any shares and all the money will go to the attacker.
Manual code review
Force users to stake at least some amount in the system (Uniswap forces users to pay at least 1e18
)
That way the amount the attacker will need to ERC20.transfer to the system will be at least X*1e18
instead of X
which is unrealistic
#0 - Evert0x
2022-02-03T21:56:04Z
Thanks. I agree it's an issue than could theoretically affect all deposits.