Don't Get Rekt

Smart contract bugs / Is the math and the design right?

Rounding, precision and share inflation

Share, interest or fee math rounds in the wrong direction or loses precision. The attacker repeats a small gain many times, or inflates the share price of an empty vault.

OWASP SC07:2026 · 39 real exploits · $305.5M lost

How the attack works

  1. A vault mints shares as assets * totalSupply / totalAssets. Solidity division rounds down.
  2. In an empty vault, the attacker deposits 1 wei and gets 1 share. Then the attacker sends a large donation directly to the vault.
  3. The next depositor's shares round down to zero. The attacker redeems the 1 share and takes both deposits.
  4. Variants: rounding in favour of the user on withdraw, division before multiplication, wrong decimals (6 vs 18), many tiny actions that each round in the attacker's favour.

Vulnerable and fixed code

Vulnerable
function deposit(uint256 assets) external returns (uint256 shares) {
    shares = totalSupply == 0
        ? assets
        : assets * totalSupply / token.balanceOf(address(this)); // donation moves this
    _mint(msg.sender, shares);                                  // can be 0
    token.transferFrom(msg.sender, address(this), assets);
}
Fixed
// OpenZeppelin ERC4626 (v4.9+) adds virtual shares and assets (decimals offset),
// so a donation cannot make the next deposit round to zero.
contract Vault is ERC4626 {
    constructor(IERC20 a) ERC4626(a) ERC20("vShare", "vS") {}
    function _decimalsOffset() internal pure override returns (uint8) { return 6; }
}
// In your own math: multiply before you divide, round against the user
// (Math.mulDiv with Rounding.Ceil on withdraw), and revert when shares == 0.

Review checklist

  • Round in favour of the protocol: down when you give shares or assets, up when you take them.
  • Multiply before you divide. Use Math.mulDiv for large numbers.
  • Use internal accounting for total assets, not balanceOf(address(this)), so donations do not change the rate.
  • Protect empty vaults: virtual shares, a dead-shares deposit at deploy, or a minimum first deposit.
  • Check decimals of every token. Do not assume 18.

How to test for it

  • Fuzz deposit and withdraw with amounts from 1 wei to large values. Check that redeem(deposit(x)) <= x.
  • Test the first deposit after a donation to an empty vault.

Real exploits (39)

  • Nov 3, 2025Ethereum$128.0MAudited, bug out of scope

    Balancer V2 (Composable Stable Pools): Balancer V2 Composable Stable Pools lost about $128M across several chains because _upscale() always rounded down, which let an attacker shrink the pool invariant through repeated micro-swaps.

    Root cause and fix

    Vulnerable code: BaseGeneralPool.sol / ComposableStablePool · _upscale()

    The _upscale() scaling function always used mulDown, so token amounts were rounded down no matter the swap direction. The developers had commented that the impact was "expected to be minimal". The attacker used batchSwap with the Vault's deferred settlement and internal balances to obtain BPT temporarily. They pushed pool balances to very low levels and ran about 65 micro-swaps in one transaction, so the rounding error compounded and the invariant and BPT price were distorted. In a second transaction they called manageUserBalance(WITHDRAW_INTERNAL) to take out the real tokens.

    What would have stopped it: Round in the direction that favors the pool for each operation: down for amounts received, up for amounts paid out. Add fuzz and formal-verification properties such as roundtrip swap invariance (A→B→A never returns more than the input) and "BPT share value must not decrease", and test them at low-liquidity edge cases. Make sure audits cover every pool variant that overrides the scaling factors.

    rekt.news article ↗Run the exploit (Foundry PoC) ↗

  • Nov 22, 2023Arbitrum$48.0MFlash loanAudited

    KyberSwap Elastic: KyberSwap Elastic lost over $48M across six chains when an attacker used flash loans and precisely sized swaps to exploit a precision error that double-counted liquidity in its concentrated liquidity pools.

    Root cause and fix

    Vulnerable code: KyberSwap Elastic pool (KS2-RT frxETH/WETH pool 0xFd7B111AA83b9b6F547E617C7601EfD997F64703) · swap()

    The article says the attacker used flash loans to push pool prices into a range with no liquidity. They then made extremely precise swaps there, and a precision error let them get past a check that failed by less than 0.00000000001%. BlockSec describes the root cause as tick manipulation and double liquidity counting: repeated swap steps and cross-tick operations counted liquidity twice, so the pools could be drained. The article does not name the vulnerable function or contract.

    What would have stopped it: Make tick-crossing and swap-step math consistent at price boundaries, with explicit rounding directions. Add invariant and fuzz tests that check liquidity is never counted twice when swaps end at or near tick boundaries, including in empty liquidity ranges.

    rekt.news article ↗Run the exploit (Foundry PoC) ↗

  • Feb 13, 2021Ethereum$37.5MFlash loan

    Alpha Homora V2 (Alpha Finance): Alpha Homora V2 lost about $37.5M when an attacker abused a rounding error in borrow share math plus a publicly callable resolveReserve to borrow sUSD with zero debt shares.

    Root cause and fix

    Vulnerable code: HomoraBankV2 · resolveReserve

    In HomoraBankV2 the borrow calculation rounded debt shares down, so when the attacker was the sole borrower of an empty sUSD pool, a borrow of totalDebt-1 gave 0 shares and counted as no debt. The attacker left 1 share of debt by repaying slightly less than owed, then called resolveReserve (callable by anyone), which raised totalDebt without raising totalShare. Each borrow of totalDebt-1 then doubled totalDebt at no cost in shares. A custom spell passed the collateral > borrow check. The attacker then deposited the sUSD into Cream's Iron Bank, used Aave flash loans for liquidity, and borrowed other assets against it.

    What would have stopped it: Round debt shares up when borrowing and revert if a nonzero borrow mints zero shares. Restrict resolveReserve to a trusted role, or make it update shares consistently. Fuzz test the debt and share invariants with a single borrower and an empty pool, and don't leave unreleased pools live on mainnet.

    rekt.news article ↗

  • May 14, 2024Optimism$20.0MFlash loanFork of Compound V2Audited

    Sonne Finance: Sonne Finance, a Compound V2 fork on Optimism, lost about $20M to the known donation (empty-market share inflation) attack on a newly added VELO market, made possible by a non-atomic governance rollout.

    Root cause and fix

    Vulnerable code: soVELO · mint() / redeemUnderlying()

    Compound V2 forks are exposed to a donation attack on empty markets, where the exchange rate can be inflated. Sonne had avoided it before by raising collateral factors slowly. For the new VELO market, the team created the market and queued a governance proposal to set its collateral factor as separate steps. The timelock-queued proposal could be executed by anyone, and the attacker executed it in the same transaction as their attack. This set the collateral factor to 35% on the empty soVELO market, and the attacker used a flash loan and a donation to inflate the exchange rate. They then borrowed and drained WETH, USDC and VELO from other markets.

    What would have stopped it: Seed a new market with a real deposit and burn the initial shares before any collateral factor is set. Bundle market creation, the initial mint and the collateral factor change into one atomic governance action, so nobody can pick and choose steps. Also restrict who can execute queued timelock actions.

    rekt.news article ↗Run the exploit (Foundry PoC) ↗

  • Jun 25, 2025Ethereum$9.8MFlash loanAudited

    ResupplyFi: ResupplyFi lost about $9.8M when an attacker used an ERC4626 donation attack on a freshly deployed, empty vault to make the exchange rate round to zero and borrow reUSD against 1 wei of collateral.

    Root cause and fix

    Vulnerable code: cvcrvUSD vault / ResupplyPair (wstUSR market) · borrow()

    The market computed its exchange rate as 1e36 / oracle.getPrices(). On a brand-new vault with almost no collateral, the attacker donated 2,000 crvUSD directly to the vault controller and minted 1 wei of shares. That pushed the share price to about 2*10^36, so the floor division returned zero. With an exchange rate of zero, the loan-to-value check passed for any loan. The attacker deposited 1 wei of cvcrvUSD as collateral and borrowed about $10M reUSD, using a small flash loan from Morpho to fund the donation.

    What would have stopped it: Seed new ERC4626 vaults and markets with meaningful collateral at deployment, or use virtual shares/assets offsets to block share-price inflation. Also revert when the computed exchange rate is zero, and add tests for empty-market deployments.

    rekt.news article ↗Run the exploit (Foundry PoC) ↗

  • Feb 11, 2025StarknetCairo$9.6MFlash loanAudited

    zkLend: zkLend on Starknet lost about $9.57M when an attacker used flash loans to inflate the lending_accumulator in an empty market and exploited withdrawal rounding.

    Root cause and fix

    Vulnerable code: zkLend Market

    The lending_accumulator math lost precision and rounded in the user's favor on withdrawal. The attacker started with a 1 wei deposit into an empty market. They then used flash loans, with donations accepted, to push the accumulator from 1.0 to about 4.069297906051644020. At that value, a deposit of 4.069...021 wstETH minted only 2 wei of shares, but those shares could withdraw 6.10... wstETH. The post-mortem calls the cause three individually harmless design details that were lethal together: empty-market deposits, accepted donations, and withdrawal rounding.

    What would have stopped it: Round against the user on withdrawals (round shares burned up), and avoid first-depositor or empty-market states, for example with minimum liquidity or dead shares. Also guard against accumulator inflation through donations and flash-loan repayments, and fuzz-test deposit and withdraw round trips at extreme accumulator values.

    rekt.news article ↗

  • Sep 1, 2025Ethereum$8.4MAudited

    Bunni: Bunni lost $8.4M across Ethereum (USDC/USDT) and Unichain (ETH/weETH) pools because rounding errors in its custom Liquidity Distribution Function rebalancing and withdrawal math could be exploited.

    Root cause and fix

    Bunni's rebalancing and withdrawal math rounded in ways that looked fine alone but became harmful when chained. The attacker used carefully sized trades and tiny withdrawals to push a pool's active balance down to a few wei (USDC from 28 wei to 4 wei, an 85.7% drop, for a much smaller burn of liquidity shares). With the balance that small, the per-share value was calculated wrongly. The attacker repeated this to withdraw more tokens than they were owed, and each round made the error larger. Bunni's tests did not cover this case.

    What would have stopped it: Round in the protocol's favor everywhere, and enforce an invariant that withdrawals cannot reduce the active balance by more than the share of liquidity burned. Add stateful fuzz and invariant tests that chain small swaps and withdrawals, including near-zero balances, as Trail of Bits and Cyfrin recommended.

    rekt.news article ↗

  • Apr 15, 2023Optimism$7.4MFlash loanFork of Compound V2Audited

    Hundred Finance: Hundred Finance lost $7.4M on Optimism when an attacker donated flash-loaned WBTC to an empty hWBTC market, inflating its exchange rate and exploiting a rounding error in redeemUnderlying.

    Root cause and fix

    Vulnerable code: hWBTC · redeemUnderlying

    The hWBTC exchange rate depends on the WBTC balance held by the contract, so a direct donation can inflate it. The market was empty, which made this easy. The redeemUnderlying function also had a rounding error. The attacker flash-loaned WBTC from Aave and minted hWBTC. They redeemed the underlying WBTC with fewer hWBTC than they should have needed, which left them a tiny hWBTC balance. They then donated about 500 WBTC to inflate the rate and borrowed about 1,021 ETH and other assets against 2 wei of hWBTC. Finally they withdrew the donated WBTC.

    What would have stopped it: Round redeem and share calculations in the protocol's favor, so that redeeming burns at least the shares it should. Guard against empty-market donation attacks by minting dead shares at market launch, or by tracking internal cash instead of balanceOf. Do not leave empty duplicate markets live.

    rekt.news article ↗Run the exploit (Foundry PoC) ↗

  • Jan 30, 2024Ethereum$6.5MFlash loan

    Abracadabra: Abracadabra lost $6.5M on Ethereum when an attacker exploited a rounding error in CauldronV4's borrow debt-share calculation, draining MIM from two cauldrons and depegging MIM.

    Root cause and fix

    Vulnerable code: CauldronV4 · borrow

    The borrow function in CauldronV4 computes the user's debt share (the part value) with rounding that can be manipulated. The attacker flash-loaned MIM from Degenbox and donated it to BentoBox. They called repayForAll() and manually repaid other borrowers until the borrow elastic was near zero, which is below the 1000 * 1e18 threshold. They then borrowed and repaid repeatedly to inflate the share price, as in an ERC-4626 first-depositor attack. Finally they added collateral, borrowed a large amount of MIM, repaid the flash loan and kept the profit.

    What would have stopped it: Round debt shares up when borrowing, and enforce a minimum total debt or minimum share size so the debt-to-share ratio can't be driven to an extreme. Add invariant and fuzz tests for repeated borrow/repay loops and for near-zero total elastic.

    rekt.news article ↗

  • Jan 30, 2024Ethereum$6.5MFlash loan

    MIM Spell (Abracadabra) CauldronV4: MIM Spell's CauldronV4 lost about $6.5M because repayForAll() and the borrow accounting broke the elastic/base ratio through precision loss, which let the attacker borrow MIM against almost no debt.

    Root cause and fix

    Vulnerable code: CauldronV4 (0x7259e152103756e1616A77Ae982353c3751A6a90) · repayForAll()

    The article says only "Precision Loss". The PoC suggests the rest. The attacker flash-loans MIM from DegenBox and calls CauldronV4.repayForAll() to reduce totalBorrow.elastic while totalBorrow.base stays the same. The PoC repays the debt of 15 listed users with repay(), which pushes the base down to almost nothing. With a tiny base and a large elastic, the elastic-to-base ratio is extremely skewed, so rounding in the borrow-part math lets a later borrow() mint huge MIM for almost no debt. The attacker then swaps the MIM for USDT, USDC and WETH. These details come from the PoC steps and are partly inferred.

    What would have stopped it: Do not let repayForAll() change the elastic/base ratio freely. Enforce a minimum base, or reject the call when base is very small. Round debt up when borrowing, and add invariant and fuzz tests on extreme elastic/base ratios.

    Run the exploit (Foundry PoC) ↗

29 more examples in the full guide.

References

Send a new scam

Describe what happened, or paste a link to the post. Do not include seed phrases, keys or passwords.

Open the post ↗