first user can steal everyone else’s tokens
The staking contract calculates shares using a formula that can round down to zero when a large donation is made before a victim stakes. An attacker can front-run a victim's stake with a direct token transfer, causing the victim to receive no shares while the attacker redeems all funds.
Submitted by egjlmn1, also found by OriDabush
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.
Proof of Concept
See the following attack:
- the first user (user A) who enters the system stake 1 token
- another user (user B) is about to stake X tokens
- user A frontrun and transfer X tokens to the system via
ERC20.transfer - user B stakes X tokens, and the shares he receives is:
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 holds 5. user A can now redeem his shares and get the 1 token he staked, the X tokens user B staked, and the X tokens he ERC20.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.
Recommended Mitigation Steps
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
Evert0x (Sherlock) confirmed and commented:
Thanks. I agree it’s an issue that could theoretically affect all deposits.
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 integer division that rounds down to zero when the total balance is inflated by a direct transfer, and there is no minimum stake to prevent this.
Impact
An attacker could steal all tokens deposited by subsequent users, as confirmed by the protocol team.
What the attacker needed
Attacker is first staker; attacker can front-run victim's stake; victim stakes a larger amount
The fix
The report recommends forcing users to stake at least a minimum amount (e.g., 1e18) to make the attack economically unrealistic.
How it was found
- The first user stakes a very small amount (1 token).
- A second user is about to stake a larger amount (X tokens).
- The first user front-runs by transferring X tokens directly to the contract.
- The second user stakes X tokens but receives zero shares due to rounding.
- The first user redeems their single share and receives all tokens in the contract.
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 pool, you get 'shares' that represent your portion. The pool's maths can round your shares down to zero if someone else adds a large amount just before you. That other person can then take out more than they put in, including your money.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.