# Potential stake() DoS if sole safETH holder (ie: first depositor) unstakes totalSupply - 1

Sole safETH holder unstakes totalSupply-1, leaving 1 wei and zero underlyingValue, causing divide-by-zero DoS in stake().

- Payout: Contest reward
- Severity: medium
- Program: Asymmetry Finance
- Credited: whoismatthewmc1
- Disclosed: 2023-07-28
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2023-03-asymmetry-findings/issues/1016
- Library page: https://bugbountylibrary.com/r/c4%3A2023-03-asymmetry%3AM-03
- Tags: domain:web3 impact:dos kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:dos vuln:oracle-manipulation

**Target:** SafEth.sol stake()/unstake() share pricing
**Root cause:** preDepositPrice = (1e18 * underlyingValue) / totalSupply divides by totalSupply=1 wei; if underlyingValue rounds to 0 (derivative price <1 ETH), preDepositPrice=0 and mintAmount division reverts.
**Steps:**
1. Be first depositor, hold 100% of safETH totalSupply.
2. Unstake totalSupply - 1, leaving 1 wei safETH and ~1 wei derivative balance.
3. Manipulate derivative AMM price so ethPerDerivative < 1e18 (e.g. 1 rETH = 9.99e17 ETH).
4. underlyingValue = (9.99e17 * 1)/1e18 = 0.
5. Call stake(): preDepositPrice = (1e18*0)/1 = 0, then `mintAmount = (totalStakeValueEth * 1e18) / 0` reverts.
**How found:** Code reading of stake() pricing: noticed preDepositPrice divides by totalSupply and that totalSupply can be driven to 1 wei by the sole holder, then traced underlyingValue rounding to zero.
**Exploitation:** Attacker (first/last holder) burns nearly all supply and manipulates the derivative's AMM price so underlyingValue rounds to zero, permanently reverting stake() until owner redeploys or manually seeds safETH.
**Insight:** Share-price math that divides by totalSupply is fragile at tiny supplies; check whether a sole holder can burn down to 1 wei and whether underlyingValue can round to 0 via oracle/AMM price, yielding divide-by-zero.
