# Early user can break minting

First depositor mints then withdraws all but 1 wei, leaving factor()=0 so later deposits mint zero tokens and accrue value to attacker.

- Payout: Audit contest
- Severity: medium
- Program: Gro Protocol
- Found by: cmichel
- Disclosed: 2021-08-30
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2021-06-gro-findings/issues/107
- Library page: https://bugbountylibrary.com/r/c4%3A2021-06-gro%3AM-06
- Tags: area:web3 domain:web3 impact:dos impact:funds-loss kind:contest platform:code4rena sev:medium technique:source-review vuln:accounting-error vuln:business-logic vuln:share-inflation

**Target:** GToken mint/burn exchange-rate factor (DepositHandler/WithdrawHandler)
**Root cause:** factor() = totalSupplyBase*BASE/totalAssets; withdrawal fee only reduces totalAssets by post-fee amount, so burning to 1 wei leaves tiny supply over nonzero assets, truncating factor to 0.
**Steps:**
1. Attacker deposits 100 DAI via `DepositHandler.depositGToken` with `dollarAmount = 100 * 1e18`, calling `ctrl.mintGToken(pwrd, msg.sender, 1e18)`; as first minter `gt.factor()` returns `getInitialBase() = 1e18`, minting `1e18`.
2. `ctrl.mintGToken` increases total assets via `pnl.increaseGTokenLastAmount(...)`.
3. Attacker withdraws all but 1 wei via WithdrawHandler: `IPnL(pnl).decreaseGTokenLastAmount(pwrd, amount=userBalance - 1, bonus=fee)`; with 2% fee total assets only drop to ~2e18.
4. factor() = `1 * 1e18 / (2 * 1e18) = 0`, so subsequent `depositGToken` mints 0 base tokens to depositors.
**How found:** Reading GToken.factor() exchange-rate math and noticing integer truncation combined with withdrawal-fee accounting that leaves totalAssets nonzero while supply is 1 wei.
**Exploitation:** Attacker becomes first minter, deposits, then burns down to 1 wei so factor truncates to 0; all future depositors mint nothing while attacker holds the only base tokens, capturing all deposits and value. Can front-run the first minter to steal their deposit.
**Insight:** On rebase/share-token designs, check whether the exchange rate can be truncated to 0 by leaving minimal supply; withdrawal fees that only reduce assets by post-fee amount enable this.

