Killua
← All parts Bug Hunting Field Guide · Part 3 of 8

Donation-rate inflation: minting value from thin air

Killua · 6 min read

A share price computed from a live balance can’t tell deposits from gifts. A gift moves the price, and a lending market turns the moved price into debt that someone else’s money pays for.

This guide covers one of the cleanest bugs in DeFi. There’s no reentrancy, no clever math and no oracle manipulation, just a plain token transfer and a protocol that believes its own balance.

The bug in one sentence

A vault prices its shares from its live token balance, so anyone can raise the share price by transferring tokens straight to the vault, and a protocol that accepts those shares as collateral lends against the inflated value.

ERC-20 transfers are permissionless. You can’t stop someone from sending tokens to your contract. If the vault’s price formula uses balanceOf(address(this)), every unsolicited transfer raises the value of every existing share, without minting anything new.

A real case: Edel xStock (Ethereum, July 2026, about $204K plus five wrapped stocks)

Edel ran an Aave-style lending pool that accepted wrapped stock tokens as collateral, including wGOOGLx, a standard OpenZeppelin ERC4626 vault. The pool valued that collateral with the wrapper’s live convertToAssets().

The problem is two lines of stock OpenZeppelin ERC4626 code:

function totalAssets() public view virtual override returns (uint256) {
    return _asset.balanceOf(address(this)); // includes any tokens sent directly
}

function _convertToAssets(uint256 shares, Rounding r) internal view returns (uint256) {
    return shares.mulDiv(totalAssets() + 1, totalSupply() + 10 ** _decimalsOffset(), r);
}

This is correct for a standalone vault. It becomes dangerous the moment another protocol treats convertToAssets() as a price.

The math

Let A be the assets in custody, S the share supply, and D a direct donation:

rate before = A / S
rate after  = (A + D) / S
multiplier  = 1 + D / A

A vault holding a given amount that receives an equal donation doubles its share price instantly, with no new shares minted.

A note on virtual shares. OpenZeppelin added virtual shares and a decimals offset to stop the classic first-depositor attack on empty vaults. That works for bootstrapping. It does nothing once the vault holds real capital. A vault with $1M that receives a $1M gift still doubles its share price.

The attack, step by step

  1. Flash loan. Borrow 180,000 USDC from Morpho and supply it to Edel as honest collateral.
  2. Corner the shares. Loop many times: borrow Edel’s wGOOGLx reserve, move it to a helper contract and supply it back as collateral. The attacker ends up controlling almost all of the wrapper’s shares.
  3. Donate. Redeem the last borrowed tranche for raw GOOGLx, then transfer() it straight into the wGOOGLx vault. The share price jumps sharply.
  4. Drain. Edel re-prices the helper’s collateral through convertToAssets(). Its borrowing power surges, and the attacker borrows all the remaining USDC plus five other wrapped stocks.
  5. Exit. Repay the flash loan and keep about $204K plus the drained wrappers.

Why it worked: three facts

  1. Raw custody read. balanceOf mixes real deposits with gifts. There’s no internal ledger of deposited assets.
  2. Permissionless inflow. Anyone can raise the vault’s balance in the same transaction without receiving shares.
  3. Credit consumption. Some protocol uses the inflated rate for borrowing, redemptions or liquidations. An inflated rate that nothing uses is harmless.

Break any one and the exploit collapses.

How to hunt for it

Lookalikes that are safe, and why

Fixes that work

The same bug in other clothes

Test yourself

  1. The vault has an internal ledger, but one legacy view returns a raw-balance price that nothing uses. Finding? No, because nothing consumes it. Prove that with a grep, and leave an informational note for future integrators.
  2. A donation triples the rate, but the only way to spend it is the donor’s own redemption. Finding? No. Self-donation and self-redemption is roughly neutral. Theft needs a counterparty.
  3. Raw-balance rate, but a $1K per-account borrow cap against a $10M pool. Severity? Low and bounded. The cap holds, unless an attacker can spread the borrowing across many accounts profitably.
  4. A market prices collateral through an oracle that returns a vault’s live convertToAssets(). Where do you look? Both sides of the hop: the vault’s totalAssets source and every contract that uses the oracle.
  5. A donation jumps the rate 5x, but borrowing currently reverts on a utilization cap. Report? Yes. The core flaw is live, and it becomes exploitable as soon as utilization drops. Explain the condition in the report.

Recap