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 أو _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 يكون 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 ، لكن _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. لخص
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. هذا المقال مصدره من الانترنت: 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… تحليل #تبادل #رمز #© 版权声明المصفوفة 上一篇 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 相关文章 Tiger Research: We maintain our $200,000 price target amid heightened market volatility. 6086cf14eb90bc67ca4fc62b 17٬445 A Look Ahead at the New Fed Chair: Hassett, Coinbase Holdings, and Trump’s “Loyal Doves” 6086cf14eb90bc67ca4fc62b 18٬219 2 Messari’s 2026 Cryptocurrency Thesis: Power Struggles, Stablecoins, and Skepticism (Part Two) 6086cf14eb90bc67ca4fc62b 16٬328 1 The story of Brother Machi’s “zeroing out”: His account peaked at nearly $60 million, vanishing in 47 days. 6086cf14eb90bc67ca4fc62b 20٬078 Cryptocurrency and Stock Market Indicators | Strategy’s total BTC holdings have risen to over 670,000, with an annualize 6086cf14eb90bc67ca4fc62b 17٬570 BNB Chain’s journey to immortality, with both high market capitalization and on-chain popularity 6086cf14eb90bc67ca4fc62b 19٬678 بدون تعليقات يجب عليك تسجيل الدخول لتترك تعليق! تسجيل الدخول على الفور بدون تعليقات... Bee.com أكبر بوابة Web3 في العالم الشركاء كوين كارب بينانس CoinMarketCap كوين جيكو كوين لايف الدروع قم بتنزيل تطبيق Bee Network وابدأ رحلة web3 ورق ابيض الأدوار التعليمات © 2021-2026. جميع الحقوق محفوظة. سياسة الخصوصية | شروط الخدمة تحميل تطبيق Bee Network وابدأ رحلة web3 أكبر بوابة Web3 في العالم الشركاء CoinCarp Binance CoinMarketCap CoinGecko Coinlive Armors ورق ابيض الأدوار التعليمات © 2021-2026. جميع الحقوق محفوظة. سياسة الخصوصية | شروط الخدمة يبحث يبحثفي الموقععلى تشيناجتماعيأخبار العنوان: صيادو الإنزال الجوي تحليل البيانات مشاهير التشفير كاشف الفخ العربية English 繁體中文 简体中文 日本語 Tiếng Việt 한국어 Bahasa Indonesia हिन्दी اردو Русский العربية
智能索引记录
-
2026-03-02 12:59:06
视频影音
成功
标题:18岁太奶在线训孙第65集河马短剧_在线播放[高清流畅]_爽文短剧
简介:爽文短剧_18岁太奶在线训孙剧情介绍:18岁太奶在线训孙是由内详执导,内详等人主演的,于2025年上映,该都市讲述的是暂
-
2026-03-02 12:01:16
综合导航
成功
标题:JAE will exhibit its innovative EV charging solutions at EVS35, Oslo Norway from June 11-15, 2022 Connectors - JAE Japan Aviation Electronics Industry, Ltd.
简介:Browse JAE will exhibit its innovative EV charging solutions
-
2026-03-02 16:28:35
电商商城
成功
标题:时尚松糕男鞋怎么样 - 京东
简介:京东是专业的时尚松糕男鞋网上购物商城,为您提供时尚松糕男鞋价格图片信息、时尚松糕男鞋怎么样的用户评论、时尚松糕男鞋精选导
-
2026-03-02 10:54:42
游戏娱乐
成功
标题:变形金刚4拼图,变形金刚4拼图小游戏,4399小游戏 www.4399.com
简介:变形金刚4拼图在线玩,变形金刚4拼图下载, 变形金刚4拼图攻略秘籍.更多变形金刚4拼图游戏尽在4399小游戏,好玩记得告
-
2026-03-02 14:04:17
教育培训
成功
标题:小学三年级写景作文(集合)
简介:在日常学习、工作抑或是生活中,大家都跟作文打过交道吧,作文是人们以书面形式表情达意的言语活动。为了让您在写作文时更加简单
-
2026-03-02 13:47:58
综合导航
成功
标题:1800-01220 Change over unit cock - VTE-FILTER GmbH
简介:Hersteller: Alfa Laval Moatti OEM Nr.: Alfa Laval Moatti 180
-
2026-03-02 06:36:59
综合导航
成功
标题:倾心欲·寒昭·昔友_50字_作文网
简介:时如江,而江也东去萌芽初当春 绿叶亦炎夏 枯花凋零秋 同窗数年冬 欲君重来过 依稀又一夕 以其长醉街 泣亡断心肠 沙场六
-
2026-03-02 12:56:06
教育培训
成功
标题:有你真好作文
简介:在平凡的学习、工作、生活中,大家总少不了接触作文吧,作文是人们把记忆中所存储的有关知识、经验和思想用书面形式表达出来的记
-
2026-03-02 14:57:58
综合导航
成功
标题:二年级家乡作文优选(5篇)
简介:无论是在学校还是在社会中,大家都经常接触到作文吧,通过作文可以把我们那些零零散散的思想,聚集在一块。那要怎么写好作文呢?
-
2026-03-02 10:42:21
教育培训
成功
标题:小学游记作文15篇(必备)
简介:在平凡的学习、工作、生活中,大家总少不了接触作文吧,作文要求篇章结构完整,一定要避免无结尾作文的出现。相信很多朋友都对写
-
2026-03-02 13:03:25
教育培训
成功
标题:(精华)一件有趣的事作文
简介:在生活、工作和学习中,许多人都写过作文吧,作文是从内部言语向外部言语的过渡,即从经过压缩的简要的、自己能明白的语言,向开
-
2026-03-02 13:06:22
综合导航
成功
标题:AI Agent becomes the main theme of the market, 22 crypto projects collectively enter the market Bee Network
简介:Original author: Nancy, PANews AI Agent is undoubtedly the
-
2026-03-02 10:51:02
实用工具
成功
标题:[精品]实用的春节英语作文6篇
简介:无论是在学校还是在社会中,大家都不可避免地会接触到作文吧,通过作文可以把我们那些零零散散的思想,聚集在一块。那么一般作文
-
2026-03-02 13:45:27
游戏娱乐
成功
标题:王者荣耀血王宫的回忆怎么满星过 大师难度如何三星过_欢乐园游戏
简介:王者荣耀血王宫的回忆怎么满星过?大师难度如何三星过?小编今日简单分享通关攻略,希望对卡关卡的小伙伴有所帮助!在王者荣耀中
-
2026-03-02 13:59:14
综合导航
成功
标题:Tetris Fun - Play The Free Game Online
简介:Tetris Fun - click to play online. In Tetris Fun, players mu
-
2026-03-02 14:05:59
教育培训
成功
标题:【精选】写云的作文300字
简介:在平日的学习、工作和生活里,大家总少不了接触作文吧,写作文可以锻炼我们的独处习惯,让自己的心静下来,思考自己未来的方向。
-
2026-03-02 16:28:35
综合导航
成功
标题:On-Demand Fueling Service Adds Cleveland and St. Louis Markets
简介:Yoshi continues to expand on heels of ExxonMobil investment
-
2026-03-02 14:54:06
综合导航
成功
标题:明末庶子洗脚时跪爬最新章节_明末庶子洗脚时跪爬全文免费阅读_恋上你看书网
简介:明朝末年吏治败坏,山西、陕西、河南等地重大自然灾害不断,民大饥不能活,关外女真崛起,多次入关劫掠。大明境内狼烟四起,明失
-
2026-03-02 16:28:22
综合导航
成功
标题:æé¢çæ¼é³_æé¢çææ_æé¢çç¹ä½_è¯ç»ç½
简介:è¯ç»ç½æé¢é¢é,ä»ç»æé¢,æé¢çæ¼é³,æé¢æ¯
-
2026-03-02 16:27:57
实用工具
成功
标题:免费起名打分测试方法,免费起名打分测试结果-免费起名_免费取名_宝宝起名_起名软件_名字测试打分解名(缇帕电子科技)-起点起名网
简介:免费起名打分,很多爸爸妈妈为宝宝起了N多的名字方案,但不知道到底哪个名字好哪个名字好坏,易名轩起名网经过起名专家数年的周
-
2026-03-02 13:55:36
综合导航
成功
标题:Fantasy Football 2025: WR DeAndre Hopkins player profile
简介:Nathan Jahnke breaks down Baltimore Ravens wide receiver DeA
-
2026-03-02 12:37:57
教育培训
成功
标题:(推荐)校园即景作文
简介:在平凡的学习、工作、生活中,大家或多或少都会接触过作文吧,借助作文人们可以反映客观事物、表达思想感情、传递知识信息。那么
-
2026-03-02 14:51:05
游戏娱乐
成功
标题:坦克竞技场,坦克竞技场小游戏,4399小游戏 www.4399.com
简介:坦克竞技场在线玩,坦克竞技场下载, 坦克竞技场攻略秘籍.更多坦克竞技场游戏尽在4399小游戏,好玩记得告诉你的朋友哦!
-
2026-03-02 12:31:49
综合导航
成功
标题:巨跖的拼音_巨跖的意思_巨跖的繁体_词组网
简介:词组网巨跖频道,介绍巨跖,巨跖的拼音,巨跖是什么意思,巨跖的意思,巨跖的繁体,巨跖怎么读,巨跖的近义词,巨跖的反义词。
-
2026-03-02 16:28:31
电商商城
成功
标题:番茄派乳液怎么样 - 京东
简介:京东是专业的番茄派乳液网上购物商城,为您提供番茄派乳液价格图片信息、番茄派乳液怎么样的用户评论、番茄派乳液精选导购、更多
-
2026-03-02 14:03:11
综合导航
成功
标题:Shadow - Play The Free Game Online
简介:Shadow - click to play online. Touch any screen to move the
-
2026-03-02 12:10:17
综合导航
成功
标题:Play Free No sound games on PC, Mobile & Tablet - yad.com
简介:No Sound Games are a special type of game. They are characte
-
2026-03-02 14:06:43
综合导航
成功
标题:亲情的作文(优秀6篇)
简介:在我们平凡的日常里,大家总免不了要接触或使用作文吧,根据写作命题的特点,作文可以分为命题作文和非命题作文。那么你有了解过
-
2026-03-02 14:17:29
综合导航
成功
标题:GMW ASSOCIATES Calibration Services Tektronix
简介:Tektronix can manage 100% of your calibration needs.Tektroni
-
2026-03-02 14:34:18
综合导航
成功
标题:MSO5000/DPO5000 Tektronix
简介:MSO/DPO5000B 시리즈 오실로스코프의 공급은 제한되어 있습니다. 새로운 5시리즈 B MSO 오실로스코