
Briefing
The Yearn Finance yETH Stableswap pool was subjected to a critical logic exploit resulting in the theft of approximately $9 million in underlying assets. The attack vector leveraged a flaw in the contract’s internal accounting, specifically the state management of cached virtual balances, which permitted the attacker to mint an astronomical number of pool tokens. This was achieved with an initial deposit of only 16 wei, demonstrating one of the most capital-efficient exploits in decentralized finance history.

Context
The prevailing risk in complex DeFi protocols often resides in non-standard or legacy contract implementations that attempt to optimize for gas efficiency. In this instance, the pool utilized a custom stableswap logic, distinct from other protocol products, that employed cached storage variables to reduce transaction costs. This architectural choice introduced a critical, non-obvious attack surface where the system’s external state could diverge from its internal, cached state.

Analysis
The attack was executed by first manipulating the pool’s internal state through a series of flash-loaned deposit and withdrawal cycles, deliberately accumulating phantom balances in the packed_vbs cached storage array. The attacker then drained all remaining liquidity, which correctly reset the main token supply to zero but critically failed to clear the accumulated values in the cached storage. This “zero supply” condition triggered the contract’s logic for the “first-ever deposit” upon the attacker’s final 16 wei transaction. The contract then calculated the value of this minimal deposit by referencing the uncleared, highly inflated phantom balances in the cached storage, leading to the minting of 235 septillion yETH tokens that were subsequently redeemed for the underlying assets.

Parameters
- Key Metric → $9 Million → The total estimated value of underlying assets drained from the yETH Stableswap pool.
- Attack Cost → 16 wei → The minimal amount of cryptocurrency deposited to trigger the infinite token minting exploit.
- Vulnerability Type → Cached Storage Flaw → A logic error where internal state variables ( packed_vbs ) were not reset upon a full withdrawal.
- Minted Tokens → 235 Septillion yETH → The astronomical number of tokens minted due to the arithmetic overvaluation.

Outlook
Immediate mitigation requires all protocols utilizing custom stableswap or gas-optimized logic with cached state variables to undergo an emergency review and formal verification for state transition completeness. The incident underscores the systemic risk of complex, non-standard arithmetic in liquidity pools, especially concerning edge cases like zero-supply conditions. New security best practices will likely mandate explicit, mandatory storage clearing functions or formal proofs for all state-dependent variables, reinforcing the need for rigorous handling of non-happy-path execution flows.

Verdict
This exploit serves as a definitive case study on the catastrophic risk posed by subtle state management flaws in gas-optimized smart contract logic, proving that arithmetic edge cases remain a primary vector for total asset loss.
