Attack entry point
The attack entry point is the Balancer: Vault contract, and the corresponding entry function is the batchSwap function, which internally calls onSwap to perform token swaps. function onSwap( SwapRequest memory swapRequest, uint256[] memory balances, uint256 indexIn, uint256 indexOut ) external override onlyVault(swapRequest.poolId) returns (uint256) { _beforeSwapJoinExit(); _validateIndexes(indexIn, indexOut, _getTotalTokens()); uint256[] memory scalingFactors = _scalingFactors(); return swapRequest.kind == IVault.SwapKind.GIVEN_IN ? _swapGivenIn(swapRequest, balances, indexIn, indexOut, scalingFactors) : _swapGivenOut(swapRequest, balances, indexIn, indexOut, scalingFactors); } From the function parameters and restrictions, we can obtain several pieces of information: Attackers need to call this function through Vault; they cannot call it directly. The function internally calls _scalingFactors() to obtain scaling factors for scaling operations. Scaling operations are handled in either _swapGivenIn atau _swapGivenOut . Attack Pattern Analysis
BPT Price Calculation Method In Balancer’s stable pool model, the price of BPT is an important reference point, which determines how many BPTs a user receives and how many assets are received per BPT. BPT Price = D / totalSupply Where D = invariant, from Curve's StableSwap model. In the pool exchange calculation: // StableMath._calcOutGivenIn function _calcOutGivenIn( uint256 amplificationParameter, uint256[] memory balances, uint256 tokenIndexIn, uint256 tokenIndexOut, uint256 tokenAmountIn, uint256 invariant ) internal pure returns (uint256) { /********************************************************************************************************** // outGivenIn token x for y - polynomial equation to solve // // ay = amount out to calculate // // by = balance token out // // y = by - ay (finalBalanceOut) // // D = invariant DD^(n+1) // // A = amplification coefficient y^2 + ( S + ---------- - D) * y - ------------- = 0 // // n = number of tokens (A * n^n) A * n^2n * P // // S = sum of final balances but y // // P = product of final balances but y // **************************************************************************************************************/ // Amount out, so we round down overall. balances[tokenIndexIn] = balances[tokenIndexIn].add(tokenAmountIn); uint256 finalBalanceOut = _getTokenBalanceGivenInvariantAndAllOtherBalances( amplificationParameter, balances invariant, // using the old D tokenIndexOut ); // No need to use checked arithmetic since `tokenAmountIn` was actually added to the same balance right before // calling `_getTokenBalanceGivenInvariantAndAllOtherBalances` which doesn't alter the balances array. balances[tokenIndexIn] = balances[tokenIndexIn] - tokenAmountIn; return balances[tokenIndexOut].sub(finalBalanceOut).sub(1); } The portion that serves as the benchmark for BPT prices adalah a constant value D ; that is, manipulating BPT prices requires manipulating D. Let’s analyze the calculation process of D: // StableMath._calculateInvariant function _calculateInvariant(uint256 amplificationParameter, uint256[] memory balances) internal pure returns (uint256) { /********************************************************************************************** // invariant // // D = invariant D^(n+1) // // A = amplification coefficient A n^n S + D = AD n^n + ----------- // // S = sum of balances n^n P // // P = product of balances // // n = number of tokens // **********************************************************************************************/ // Always round down, to match Vyper's arithmetic (which always truncates). uint256 sum = 0; // S in the Curve version uint256 numTokens = balances.length; for (uint256 i = 0; i prevInvariant) { if (invariant - prevInvariant In the code above, the calculation of D depends on the scaled balances array . This means that an operation is needed to change the precision of these balances, leading to an error in the calculation of D. The root cause of accuracy loss // BaseGeneralPool._swapGivenIn function _swapGivenIn( SwapRequest memory swapRequest, uint256[] memory balances, uint256 indexIn, uint256 indexOut, uint256[] memory scalingFactors ) internal virtual returns (uint256) { // Fees are subtracted before scaling, to reduce the complexity of the rounding direction analysis. swapRequest.amount = _subtractSwapFeeAmount(swapRequest.amount); _upscaleArray(balances, scalingFactors); // Key: Upscale the balance swapRequest.amount = _upscale(swapRequest.amount, scalingFactors[indexIn]); uint256 amountOut = _onSwapGivenIn(swapRequest, balances, indexIn, indexOut); // amountOut tokens are exiting the Pool, so we round down. return _downscaleDown(amountOut, scalingFactors[indexOut]); } Scaling operation: // ScalingHelpers.sol function _upscaleArray(uint256[] memory amounts, uint256[] memory scalingFactors) pure { uint256 length = amounts.length; InputHelpers.ensureInputLengthMatch(length, scalingFactors.length); for (uint256 i = 0; i As shown above, when using _upscaleArray , if the balance is very small (e.g., 8-9 wei), the down-rounding of mulDown will result in a significant loss of precision. Attack process details Phase 1: Adjust to rounding boundary Attacker: BPT → cbETH Objective: To adjust the cbETH balance to the rounding boundary (e.g., ending in 9). Assume the initial state: cbETH Balance (Original): ...00000000009 wei (last digit is 9) Phase 2: Triggering Precision Loss (Core Vulnerability) Attacker: wstETH (8 wei) → cbETH Before scaling: cbETH Balance: ...000000000009 wei wstETH input: 8 wei Execute _upscaleArray: // cbETH scaling: 9 * 1e18 / 1e18 = 9 // But if the actual value is 9.5, it becomes 9 due to rounding down. scaled_cbETH = floor(9.5) = 9 Accuracy loss: 0.5 / 9.5 = 5.3% relative error calculation exchange: Input (wstETH): 8 wei (scaled) Balance (cbETH): 9 (Incorrect, it should be 9.5) Because cbETH is undervalued, the calculated new balance will also be undervalued, leading to an error in the D calculation. D_original = f(9.5, ...) D_new = f(9, ...) Phase 3: Profiting from the depressed BPT price Attacker: Underlying asset → BPT at this time: D_new = D_original - ΔD BPT price = D_new / totalSupply The attacker above used Batch Swap to perform multiple swaps within a single transaction: First exchange: BPT → cbETH (adjust balance) Second swap: wstETH (8) → cbETH (triggers precision loss) Third exchange: Underlying assets → BPT (profit) These swaps are all within the same batch swap transaction and share the same balance state , but _upscaleArray is called to modify the balances array for each swap. The lack of a callback mechanism The main process is started by Vault, so how does this lead to the accumulation of precision loss? The answer lies in the passing mechanism of the balances array . // The logic function when Vault calls onSwap: _processGeneralPoolSwapRequest(IPoolSwapStructs.SwapRequest memory request, IGeneralPool pool) private returns (uint256 amountCalculated) { bytes32 tokenInBalance; bytes32 tokenOutBalance; // We access both token indexes without checking existence, because we will do it manually immediately after. EnumerableMap.IERC20ToBytes32Map storage poolBalances = _generalPoolsBalances[request.poolId]; uint256 indexIn = poolBalances.unchecked_indexOf(request.tokenIn); uint256 indexOut = poolBalances.unchecked_indexOf(request.tokenOut); if (indexIn == 0 || indexOut == 0) { // The tokens might not be registered because the Pool itself is not registered. We check this to provide a // more accurate revert reason. _ensureRegisteredPool(request.poolId); _revert(Errors.TOKEN_NOT_REGISTERED); } // EnumerableMap stores indices *plus one* to use the zero index as a sentinel value - because these are valid, We can undo this. indexIn -= 1; indexOut -= 1; uint256 tokenAmount = poolBalances.length(); uint256[] memory currentBalances = new uint256[](tokenAmount); request.lastChangeBlock = 0; for (uint256 i = 0; i Analyzing the code above, although Vault creates a new currentBalances array every time onSwap is called, in Batch Swap : After the first exchange, the balance is updated (but the updated value may be inaccurate due to loss of precision). The second swap continues the calculation based on the result of the first swap. Accumulated loss of precision eventually leads to a significant decrease in the invariant value D. Key issues: // BaseGeneralPool._swapGivenIn function _swapGivenIn( SwapRequest memory swapRequest, uint256[] memory balances, uint256 indexIn, uint256 indexOut, uint256[] memory scalingFactors ) internal virtual returns (uint256) { // Fees are subtracted before scaling, to reduce the complexity of the rounding direction analysis. swapRequest.amount = _subtractSwapFeeAmount(swapRequest.amount); _upscaleArray(balances, scalingFactors); // Modify the array in place. swapRequest.amount = _upscale(swapRequest.amount, scalingFactors[indexIn]); uint256 amountOut = _onSwapGivenIn(swapRequest, balances, indexIn, indexOut); // amountOut tokens are exiting the Pool, so we round down. return _downscaleDown(amountOut, scalingFactors[indexOut]); } // Although Vault passes in a new array each time, but: // 1. If the balance is very small (8-9 wei), the precision loss during scaling is significant. // 2. In Batch Swap, subsequent swaps continue calculations based on the balance that has already lost precision. // 3. It was not verified whether the change in the invariant value D was within a reasonable range. Meringkaskan
The reasons for Balancer's attack can be summarized as follows: 1. Scaling function uses rounding down : _upscaleArray uses mulDown for scaling, which will produce a significant loss of relative precision when the balance is very small (such as 8-9 wei). 2. Invariant value calculation is sensitive to precision : The calculation of the invariant value D depends on the scaled balances array, and the precision loss will be directly passed to the calculation of D, making D smaller. 3. Lack of verification of changes in invariant values : During the exchange process, it was not verified whether the changes in the invariant value D were within a reasonable range, which allowed attackers to repeatedly exploit the loss of precision to lower the price of BPT. 4. Accumulated precision loss in batch swap : In the same batch swap, the precision loss from multiple swaps will accumulate and eventually amplify into huge financial losses. These two issues—precision loss and lack of validation—combined with the attacker's careful design of boundary conditions, resulted in this loss. Artikel ini bersumber dari internet: Balancer hacked, vulnerability analysisRecommended Articles Related: BitMart Launches Pre-Market Trading, with Monad (MON) as the First Project Launched To further enrich its trading product portfolio and enhance user engagement and asset allocation flexibility, BitMart has officially launched a new feature: pre-market trading . This innovative mechanism provides users with the opportunity to invest in projects before their official launch, helping them capture early value more efficiently and gain direct access to high-quality assets. Pre-market trading: an innovative pre-release token trading mechanism Pre-market trading is an innovative financial tool launched by BitMart based on a staking mechanism. Users can mint PreTokens by staking USDT and trade them freely in a dedicated pre-market spot market. The core logic of this model is that before the project token is officially launched, PreToken provides users with a channel for early participation, thereby achieving pre-positioning and price discovery of potential assets. Key features… Analisis #Pertukaran ## Tanda© 版权声明Array 上一篇 The market has crashed, but you still have a chance to win it back. 下一篇 Tracing the Decoupling of $XUSD: Balancer Vulnerability and the Butterfly Effect of DeFi Leverage 相关文章 New security module Umbrella is launched, how will Aave staking security change? 6086cf14eb90bc67ca4fc62b 27,109 1 Circle Launches Arc Public Blockchain: Integrating Libra, Monero, and Consortium ChainsRecommended Articles 6086cf14eb90bc67ca4fc62b 21,884 1 Wintermute: The “Dinosaur Coin” rally has completely dissipated, and the market has entered a “quiet accumulation period 6086cf14eb90bc67ca4fc62b 16,800 Resupply incident review: Hackers at large, users forced to fill holes, security incident turns into racial discriminati 6086cf14eb90bc67ca4fc62b 25,988 2 Bitwise: Mengapa investor tradisional harus memperhatikan stablecoin? 6086cf14eb90bc67ca4fc62b 40,778 Popular Interactions | Perle Labs Beta Whitelist Application; IOPn Testnet Event Launched (October 31) 6086cf14eb90bc67ca4fc62b 17,090 Tidak ada komentar Anda harus login untuk meninggalkan komentar! Segera masuk Tidak ada komentar... artikel Terbaru Did Jane Street “Manipulate” BTC? Decoding the AP System, Understanding the Power Struggle Behind ETF Creation and Redemption Pricing 21 jam yang lalu 653 Stop Comparing Bitcoin to Gold—It’s Now a High-Volatility Software Stock 21 jam yang lalu 709 Matrixport Research: $25 Billion Gamma Unwinding Imminent, Liquidity Yet to Return Behind the Rebound 21 jam yang lalu 656 ERC-5564: Ethereum’s Stealth Era Has Arrived, Receiving Addresses No Longer ‘Exposed’ 21 jam yang lalu 545 Hong Kong Regulatory Green Light: Asseto Enables DL Holdings to Achieve Compliance for Two RWA Business Implementations 21 jam yang lalu 621 Situs Web PopulerTempoLighterGAIBGliderPlanckRaylsBCPokerVooi Bee.com Portal Web3 terbesar di dunia Mitra KoinCarp binance KoinMarketCap KoinGecko hidup koin Armor Unduh Aplikasi Bee Network dan mulai perjalanan web3 Kertas putih Peran Pertanyaan Umum © 2021-2026. Semua Hak Cipta Dilindungi Undang-Undang. Kebijakan pribadi | Ketentuan Layanan Unduh Aplikasi Jaringan Lebah dan memulai perjalanan web3 Portal Web3 terbesar di dunia Mitra CoinCarp Binance CoinMarketCap CoinGecko Coinlive Armors Kertas putih Peran Pertanyaan Umum © 2021-2026. Semua Hak Cipta Dilindungi Undang-Undang. Kebijakan pribadi | Ketentuan Layanan Mencari MencariDi dalam SitusDi RantaiSosialBerita 热门推荐: Pemburu Airdrop Analisis data Selebriti Kripto Detektor Perangkap Bahasa Indonesia English 繁體中文 简体中文 日本語 Tiếng Việt العربية 한국어 हिन्दी اردو Русский Bahasa Indonesia
智能索引记录
-
2026-03-02 18:25:04
综合导航
成功
标题:Mi Casa Resource Center Contact Information - PR.com
简介:View Mi Casa Resource Center's contact information in t
-
2026-03-02 21:49:48
综合导航
成功
标题:Deciphering Monad’s 18-page sales document: How does the 0.16% market-making stake support a $2.5 billion FDV? Bee Network
简介:With the countdown to the Monad (MON) token
-
2026-03-02 22:00:38
综合导航
成功
标题:UID I UX-Agentur für Innovation, Design & Strategie - UID
简介:UID ist eure UX-Agentur für die gesamte Produktentwicklung:
-
2026-03-02 17:53:53
综合导航
成功
标题:Helicopter Escape 3D - Shooting 3D Game
简介:Helicopter Escape 3D is a third-person shooter game. Shoot t
-
2026-03-02 17:54:36
综合导航
成功
标题:Tiger Research: Will Bitcoin be hacked by quantum computers? Bee Network
简介:Key points The Q-Day scenario, in which quantum computers
-
2026-03-02 22:13:24
综合导航
成功
标题:10 big-name cut candidates this offseason
简介:PFF
-
2026-03-02 10:30:47
综合导航
成功
标题:ä¼å°çæ¼é³_ä¼å°çææ_ä¼å°çç¹ä½_è¯ç»ç½
简介:è¯ç»ç½ä¼å°é¢é,ä»ç»ä¼å°,ä¼å°çæ¼é³,ä¼å°æ¯
-
2026-03-02 21:50:51
游戏娱乐
成功
标题:尤达寿司大厨,尤达寿司大厨小游戏,4399小游戏 www.4399.com
简介:尤达寿司大厨在线玩,尤达寿司大厨下载, 尤达寿司大厨攻略秘籍.更多尤达寿司大厨游戏尽在4399小游戏,好玩记得告诉你的朋
-
2026-03-02 22:11:35
综合导航
成功
标题:妖怪医生最新章节_062 美少年第1页_妖怪医生免费章节_恋上你看书网
简介:062 美少年第1页_妖怪医生_甜甜T_恋上你看书网
-
2026-03-02 10:29:33
综合导航
成功
标题:九州之王赵景山宁滢最新章节_九州之王赵景山宁滢全文免费阅读_恋上你看书网
简介:九州之王赵景山宁滢是由作者:风起所著,恋上你看书网免费提供九州之王赵景山宁滢全文在线阅读。<br />三秒记住本站:恋上
-
2026-03-02 18:15:04
实用工具
成功
标题:工作内容调查日报表-果果圈模板
简介:工作内容调查日报表,日报表简单实用,条理清晰,下载即可直接使用,欢迎大家下载。
-
2026-03-02 18:15:27
职场办公
成功
标题:非经济学专业学生考cfa有用吗?-高顿
简介:报考CFA考试实现就业的同学不在少数。事实上,无论是职场人士还是大学生报考CFA,很多人都是奔着就业去的,希望在提升专业
-
2026-03-02 21:54:48
综合导航
成功
标题:turbonetics TO-4 with With manifold & external wastegate. [Archive] - Toyota MR2 Message Board
简介:Hey everyone I have for sale A brand new turbonetics turboch
-
2026-03-02 18:12:49
综合导航
成功
标题:恋上你看书网_书友最值得收藏的网络小说阅读网
简介:恋上你看书网
-
2026-03-02 10:24:54
综合导航
成功
标题:KrisFlyer - Donate Miles Singapore Airlines
简介:KrisFlyer teamed up with Make-A-Wish Singapore to help child
-
2026-03-02 11:52:49
综合导航
成功
标题:Malaysian Chinese, the invisible protagonists of the crypto worldRecommended Articles Bee Network
简介:When people talk about the protagonists of the crypto world,
-
2026-03-02 22:17:49
综合导航
成功
标题:é±¼è çæ¼é³_é±¼è çææ_é±¼è çç¹ä½_è¯ç»ç½
简介:è¯ç»ç½é±¼è é¢é,ä»ç»é±¼è ,é±¼è çæ¼é³,é±¼è æ¯
-
2026-03-02 17:59:53
综合导航
成功
标题:å¸å¶çæ¼é³_å¸å¶çææ_å¸å¶çç¹ä½_è¯ç»ç½
简介:è¯ç»ç½å¸å¶é¢é,ä»ç»å¸å¶,å¸å¶çæ¼é³,å¸å¶æ¯
-
2026-03-02 22:09:48
新闻资讯
成功
标题:PageRank、最小生成树:ML开发者应该了解的五种图算法, 站长资讯平台
简介:作为数据科学家,我们已经对 Pandas 或 SQL 等关系数据库非常熟悉了。我们习惯于将用户属性以列的形式展示在行中。
-
2026-03-02 22:05:05
综合导航
成功
标题:Solitaire Tripeaks Garden - Play The Free Mobile Game Online
简介:Solitaire Tripeaks Garden - click to play online. Solitaire
-
2026-03-02 17:42:51
综合导航
成功
标题:èå¿çæ¼é³_èå¿çææ_èå¿çç¹ä½_è¯ç»ç½
简介:è¯ç»ç½èå¿é¢é,ä»ç»èå¿,èå¿çæ¼é³,èå¿æ¯
-
2026-03-02 18:42:06
综合导航
成功
标题:风光大嫁傅先生疼她入骨最新章节_风光大嫁傅先生疼她入骨全文免费阅读_恋上你看书网
简介:三年后再遇,他捏着她的下颌说:“我们睡过那么多次,聂掌珠,你就是化成灰,我也认得出你。”*一场商业阴谋,父死母疯,那一年
-
2026-03-02 21:51:12
电商商城
成功
标题:科漫摄像机脚架碳纤维 - 京东
简介:京东是国内专业的科漫摄像机脚架碳纤维网上购物商城,本频道提供科漫摄像机脚架碳纤维商品图片,科漫摄像机脚架碳纤维价格,科漫
-
2026-03-02 22:15:52
综合导航
成功
标题:第七章 再见元王第1页_镇国长公主李承苏清烟_笔趣阁
简介:第七章 再见元王第1页_镇国长公主李承苏清烟_梅子好酸_笔趣阁
-
2026-03-02 17:54:12
综合导航
成功
标题:1800-08036 Intermediate shaft - VTE-FILTER GmbH
简介:Fabricant: Alfa Laval Moatti Numéro OEM : Alfa Laval Moatti
-
2026-03-02 21:53:48
综合导航
成功
标题:示ç¥çæ¼é³_示ç¥çææ_示ç¥çç¹ä½_è¯ç»ç½
简介:è¯ç»ç½ç¤ºç¥é¢é,ä»ç»ç¤ºç¥,示ç¥çæ¼é³,ç¤ºç¥æ¯
-
2026-03-02 17:11:10
综合导航
成功
标题:Le Seigneur des anneaux : les deux tours
简介:Le Seigneur des anneaux : les deux tours est un film réalisé
-
2026-03-02 12:24:02
综合导航
成功
标题:d币价格(zcd币价格)_火必 Huobi交易所
简介:本篇文章给大家谈谈d币价格,以及zcd币价格对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。 本文目录一览: 1、
-
2026-03-02 21:54:06
综合导航
成功
标题:å¿æ¯çæ¼é³_å¿æ¯çææ_å¿æ¯çç¹ä½_è¯ç»ç½
简介:è¯ç»ç½å¿æ¯é¢é,ä»ç»å¿æ¯,å¿æ¯çæ¼é³,å¿æ¯æ¯
-
2026-03-02 17:41:01
教育培训
成功
标题:执业药师考试技巧-学习方法-经验分享-233网校
简介:提供执业药师技巧心得、考试技巧、经验分享、复习方法、学习技巧、执业药师网校等内容。