# first user can steal everyone else's tokens

First staker in Sherlock's share-based staking can donate tokens to inflate share price, causing the next depositor to receive zero shares and lose their stake.

- Payout: Audit contest
- Severity: high
- Program: Sherlock
- Found by: egjlmn1
- Disclosed: 2022-05-17
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2022-01-sherlock-findings/issues/39
- Library page: https://bugbountylibrary.com/r/c4%3A2022-01-sherlock%3AH-01
- Tags: domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:share-inflation

**Target:** ERC20 staking/share accounting contract
**Root cause:** Share minting formula divides by (totalTokenBalanceStakers() - _amount), so an externally donated balance can make the denominator exceed the deposit, rounding shares to zero.
**Steps:**
1. User A stakes 1 token, becoming sole share holder
2. User B submits a stake of X tokens
3. User A frontruns with `ERC20.transfer(X)` to the contract, raising totalTokenBalanceStakers()
4. User B's stake executes: `shares = (X * 1) / (X + 1 + X - X) = X/(X+1) = 0`
5. User A redeems the single share, capturing B's X tokens plus the donated X
**How found:** Reading the share calculation formula and noticing the denominator includes externally donated balance, so a donation can push shares to zero for the next depositor.
**Exploitation:** Attacker stakes minimal 1 token first, then frontruns each victim deposit with an equal external transfer so the victim mints zero shares; attacker redeems the sole share to sweep all contract balance.
**Insight:** In share-based vaults, check whether the mint formula's denominator can be inflated by direct token transfers; if the first depositor holds one share, any donation-based inflation zeroes out subsequent depositors' shares.
