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
- Flash loan. Borrow 180,000 USDC from Morpho and supply it to Edel as honest collateral.
- Corner the shares. Loop many times: borrow Edel’s
wGOOGLxreserve, move it to a helper contract and supply it back as collateral. The attacker ends up controlling almost all of the wrapper’s shares. - Donate. Redeem the last borrowed tranche for raw
GOOGLx, thentransfer()it straight into thewGOOGLxvault. The share price jumps sharply. - 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. - Exit. Repay the flash loan and keep about $204K plus the drained wrappers.
Why it worked: three facts
- Raw custody read.
balanceOfmixes real deposits with gifts. There’s no internal ledger of deposited assets. - Permissionless inflow. Anyone can raise the vault’s balance in the same transaction without receiving shares.
- 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
- Trace every cash term to storage. For each per-share rate, find where its numerator comes from: a live balance or an accounted variable.
bash grep -rnE "totalAssets\(|convertToAssets|pricePerShare|getCashPrior|exchangeRate" src/ - Find the inflow path. Can an unsolicited transfer raise that exact variable? Watch for indirect ones too, such as
stake(amount, recipient)crediting an arbitrary address. - Ask who gains. When the rate jumps, who benefits: holders’ borrowing power, redemption value, or liquidators?
- Look for dampeners. Is there a per-block cap on rate changes, a deviation breaker, a TWAP or an EMA on the rate that gets consumed?
- Name the monetization call. Through which exact function does the inflated accounting become real tokens out? Sketch it: donate, observe the multiplier, extract.
Lookalikes that are safe, and why
- An internal asset ledger. Only
mint,redeemandrepayupdate accounted cash. A donation just sits there as untracked dust. Always trace the cash term to storage first. - Inflation that only helps others. If the donor holds all the shares and there’s no way to spend someone else’s collateral, donating and redeeming yourself is roughly neutral: you get back what you gave, minus fees. Theft needs a victim’s shares or a shared lending pool on the other side.
- Time-averaged or clamped rates. A TWAP, EMA or per-block cap on the consumed rate can’t be moved much by a single-block donation.
- Donations that land somewhere unpriced. If inflows go to an escrow, fee collector or reward bucket that the price formula never reads, there’s no bug.
Fixes that work
- Keep internal cash accounting. Track a
totalCashvariable updated only by deposits, withdrawals and borrows. MakebalanceOfdisplay-only. It fails when a legacy view such as Compound’sgetCashPriorstill reads the raw balance and feeds a credit calculation. - Never price credit from live
convertToAssets(). Use attested prices, averages or capped rates. It fails when an oracle adapter one hop away reintroduces the live rate. - Bound the payout. Set per-account borrow caps and global exposure limits, and be careful with delegated borrowing such as
borrowBehalf. Even a 10x rate jump then has a bounded payoff. - Sweep stray inflows. A keeper can move untracked balances to a reserve. This weakens the attack but doesn’t stop it, because an atomic attack finishes before any keeper runs.
The same bug in other clothes
- Venus vTHE (BNB Chain). Venus read raw THE balance through
getCashPrior(). A large THE transfer lifted pool cash more than fourfold. The attacker didn’t even deposit. They revalued an innocent user’s fixed vTHE collateral, then calledborrowBehalf(victim, ...), which sent the borrowed tokens to the caller. You don’t need your own collateral if someone else’s can be borrowed against. - Summer.fi (Ethereum, July 2026, about $6M). Fleet NAV summed sub-vault values without handling sub-vaults that had no deposits. The attacker took a dominant position at honest NAV, donated cheap tokens into an empty sub-vault, where any inflow meant a huge multiplier, and redeemed for other LPs’ real USDC. In multi-vault pricing, empty sub-vaults are donation amplifiers.
- Venus on zkSync (February 2025, about 86.7 WETH). wUSDM’s raw-balance
totalAssetsfed an oracle adapter that usedconvertToAssets()as its price. The attacker donated, borrowed, then liquidated themselves dozens of times to farm the liquidation bonus. When an oracle feeds on a vault’s live rate, the bug lives in the oracle consumer. Always look at both sides of the hop.
Test yourself
- 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.
- 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.
- 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.
- 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’stotalAssetssource and every contract that uses the oracle. - 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
- Live balances lie. A share price from live custody can’t tell deposits from gifts.
- Raw-balance rate, permissionless inflow and same-transaction credit use: break any one to stop the attack.
- Theft needs a counterparty, meaning someone else’s shares or a shared lending pool.
- Watch the hop: vault rate, then oracle adapter, then lending market. Find every consumer.
- The reflex: trace every cash term from the formula to the storage slot it actually reads.