In-Depth Analysis of the Balancer V2 Exploit: How Precision Error Toppled a DeFi Giant
In decentralized finance, the difference between rounding 8.918 down versus up can mean millions of dollars. What most developers dismiss as trivial precision loss, sophisticated attackers treat as a precision weapon. The recent Balancer exploit revealed an uncomfortable truth: in financial protocols, every rounding decision matters, and the smallest inconsistency can be turned into profit at scale.
Stable pools in DeFi, designed for assets that trade near parity such as USDC/DAI or wstETH/WETH, rely on mathematical invariants to enable large swaps with minimal price impact. These pools use StableSwap-based formulas, where an invariant D represents the pool’s virtual total value. Each pool issues its own liquidity token (Balancer’s version is the BPT), representing proportional ownership. The design is mathematically elegant, but that same math becomes an attack surface when rounding rules aren’t consistent.
This analysis explores how rounding vulnerabilities can compromise stable pool security, the technical approach attackers use, and the lessons developers should take from the $120 million Balancer incident. The takeaway is clear: precision loss is not an implementation detail, it is an economic vulnerability.
How Stable Pools Work
Stable pools are optimized for capital efficiency between like-kind assets. Unlike constant-product AMMs (x × y = k), which suffer high slippage during large trades, StableSwap math maintains an invariant D that keeps trades near 1:1 with minimal impact on price.
The invariant solver in Balancer’s Composable Stable Pools shifts smoothly between constant-sum behavior near equilibrium and constant-product behavior at extremes. This invariant must remain consistent during swaps, and any manipulation of D without corresponding liquidity changes breaks the core assumption of the model.
Balancer pool tokens (BPTs) represent shares of liquidity, priced through join and exit functions that use amplification parameters and fee factors. Because these formulas depend on consistent rounding, even small systematic mispricing in these calculations can be exploited.
Swap Mechanics: GIVEN_IN vs GIVEN_OUT
Stable pools support two primary swap types:
-
GIVEN_IN: The user specifies how much to deposit, and the protocol calculates the output.
-
GIVEN_OUT: The user specifies how much to withdraw, and the protocol calculates the required input.
The GIVEN_OUT path is mathematically more complex, as it must solve backward for the required input. This is also where rounding vulnerabilities often appear.
In the Balancer exploit, the attacker used the GIVEN_OUT path. During scaling of the requested output, the system used mulDown, which rounded the internal value down. The result was that the pool accepted slightly less input than it should have for the desired output. Each individual undercharge was microscopic, but repeated many times, it became economically significant.
Batch swaps, multi-hop exchanges executed in one transaction, amplified the effect. This mechanism, designed for efficiency, also allowed the attacker to stack small precision gaps across dozens of operations.
Scaling and Decimal Precision
Ethereum tokens use varying decimal precisions. USDC uses 6 decimals, WETH uses 18. Stable pools normalize these values to a common internal precision (typically 18 decimals) through scaling operations.
-
Upscaling: Multiply token amount by a scaling factor to reach internal precision
-
Downscaling: Divide internal value by the same factor to revert to native precision
Each multiplication and division introduces a rounding decision: up or down. Inconsistencies between upscaling and downscaling create exploitable discrepancies.
In the Balancer incident, the critical loss wasn’t from 6-decimal tokens like USDC but from rate scaling of osETH, an 18-decimal token with an exchange rate wrapper. The precision error in that rate calculation provided the entry point for the exploit.
The Rounding Paradox
Smart contracts rely on fixed-point arithmetic. Every multiplication and division must either truncate or round. The guiding principle in financial code is simple: rounding must always favor the protocol.
If a function calculates how much a user must pay, it should round up. If it calculates how much a user receives, it should round down. Breaking that rule introduces silent value leakage that attackers can aggregate into real profit.
The Vulnerability Pattern
In Balancer’s case, two functions intended to handle the same logic rounded in opposite directions. The upscaling process used mulDown, truncating small fractions of the requested output. The invariant solver then calculated the input needed to achieve that slightly smaller value, resulting in the protocol charging too little.
The discrepancy was typically one wei, one quintillionth of a token, but across dozens of carefully engineered swaps, that error compounded. Each iteration extracted an infinitesimal gain. Collectively, the result was millions in value loss.
From Wei to Millions
On November 3, 2025, Balancer’s Composable Stable Pools were exploited across multiple chains, with losses estimated between $116 million and $129 million, most analyses converging near $120 million.
The attacker executed a series of micro-swaps fine-tuned to the smallest rounding boundaries. SlowMist’s analysis identified a 17-wei rounding cliff on osETH, which was repeatedly targeted. Profits were stored as internal balances and withdrawn in a separate transaction, a method likely intended to delay detection.
The combination of repeated micro-swaps, large pool liquidity, and precise rounding exploitation transformed sub-atomic losses into large-scale economic extraction.
How the Attack Worked
Stage 1: Reconnaissance and Optimization
The attacker began by deploying simulation contracts mirroring Balancer’s math. These contracts pulled live on-chain parameters including token balances, scaling factors, amplification coefficients, and fee data.
They then searched for the “trick amount,” a swap value that landed directly on a rounding boundary after upscaling. This is where the mulDown operation would truncate the most significant fraction. By repeatedly testing and optimizing this input, the attacker identified the sequence that maximized cumulative rounding loss without causing solver instability.
Stage 2: Execution
The attacker adjusted pool balances through preliminary swaps to position the system at the precise rounding cliffs.
Next, they executed a series of GIVEN_OUT swaps using the optimized parameters to trigger undercharging.
Finally, they reversed the operations to realize profit and withdrew the accumulated balances via the manageUserBalance function.
The entire process was divided across multiple transactions to avoid immediate detection by automated monitors.
Lessons for DeFi
1. Paranoid Rounding is Non-Negotiable
Every arithmetic operation in a financial protocol must be reviewed for directionality. If it’s unclear whether a rounding favors the protocol or the user, it’s a vulnerability waiting to happen.
Best practices:
-
Use arithmetic libraries with explicit rounding semantics.
-
Enforce “protocol-favoring” rounding in all user-facing paths.
-
Include property-based tests ensuring invariants do not decrease except by fees.
-
Formally verify rounding logic in critical functions.
-
Document rounding rules with a clear security rationale.
2. Attackers Are Getting Smarter
This exploit wasn’t a simple reentrancy or oracle trick. It was a mathematical precision attack executed through simulation, optimization, and iteration.
Modern adversaries test your contracts under laboratory conditions before going on-chain. Defense-in-depth is no longer optional.
Recommended mitigations:
-
Run red-team simulations targeting rounding boundaries.
-
Monitor for repeating micro-swap patterns and invariant “velocity” changes.
-
Implement per-block swap limits and circuit breakers for abnormal activity.
3. Operational Security Matters as Much as Code
Even perfect math is useless if a protocol cannot respond fast enough when under attack.
Operational safeguards:
-
Tiered pause authority for rapid containment.
-
Real-time invariant monitoring dashboards.
-
Automatic circuit breakers triggered by unusual state changes.
-
Predefined communication and response playbooks.
4. Audits Aren’t Enough
Traditional audits often prioritize obvious risks like reentrancy, access control, oracles, while overlooking micro-precision economics. The Balancer incident shows that microscopic arithmetic inconsistencies can yield catastrophic outcomes.
Evolving the audit model:
-
Include rounding-safety and precision-loss reviews in every engagement.
-
Use formal verification tools to check invariant monotonicity.
-
Fuzz test with rounding-boundary inputs.
-
Simulate economic impact under adversarial conditions.
-
Budget for continuous post-deployment monitoring.
Implications for Stakeholders
Liquidity Providers
Audited does not mean safe. Diversify across pools, monitor deviations between BPT price and underlying asset values, and be alert to repeated micro-swaps or invariant anomalies. Understand how and when a protocol can pause trading.
Developers
Raise the baseline. Formal verification, boundary-case fuzzing, live monitoring, tiered pause mechanisms, and robust incident response plans should be standard, not aspirational.
The DeFi Community
Security is collective. Share vulnerability research responsibly, standardize rounding-safety testing, and develop open-source invariant monitors. As adversaries evolve, collaboration is the only sustainable defense.
Conclusion
The Balancer exploit demonstrated that even a single rounding decision can cascade into systemic loss. In DeFi, the smallest arithmetic inconsistency can become an economic vulnerability when adversaries understand the math better than the builders.
Protocols that survive the next generation of exploits will be those that treat every calculation as a potential attack surface. Every rounding operation is a security choice, and every decimal place has value.
In decentralized finance, the danger isn’t hidden in the details, it’s hidden in the rounding.
Related Articles

dbook Smart Contract Audit
dbook is a fully on-chain EVM orderbook exchange designed to deliver decentralized trading with high performance, gas efficiency, and self-custody. The protocol...

Aegis JUSD Smart Contract Audit
Aegis is a multichain stablecoin protocol powering JUSD and YUSD, featuring minting, redemption, staking vaults, rewards distribution, and cross-chain bridging ...

The Moats V3 Smart Contract Audit
The Moats are a flexible staking and rewards protocol enabling project teams to configure easy governance participation, time-weighted incentives, and multi-tok...
Ready to secure your project?
Get in touch with our security experts for a comprehensive audit.
Contact Us