pancake闪电贷攻击学习
合约地址:
BunnyMinterV2:https://bscscan.com/address/0x819eea71d3f93bb604816f1797d4828c90219b5d#code
VaultFlipToFlip:https://bscscan.com/address/0xd415e6caa8af7cc17b7abd872a42d5f2c90838ea#code
MasterChefh:https://bscscan.com/address/0x73feaa1ee314f8c655e354234017be2193c9e24e#code
pancakePair:https://bscscan.com/address/0x16b9a82891338f9ba80e2d6970fdda79d1eb0dae#code
PancakeRouter:https://bscscan.com/address/0x10ED43C718714eb63d5aA57B78B54704E256024E#code
攻击交易:
一:https://bscscan.com/tx/0x88fcffc3256faac76cde4bbd0df6ea3603b1438a5a0409b2e2b91e7c2ba3371a
二:https://bscscan.com/tx/0x897c2de73dd55d7701e1b69ffb3a17b0f4801ced88b0c75fe1551c5fcce6a979
参考文章:
PancakeBunny攻击事件复盘分析 | 零时科技:http://www.xilian.link/depth/75435.html
慢雾:PancakeBunny 黑客分析:
https://slowmist.medium.com/slowmist-pancakebunny-hack-analysis-4a708e284693
合约BunnyMinterv2中函数mintForV2通过performanceFee与valueInBNB 计算mint生成的数量。
uint performanceFee = canMint() ? _minter.performanceFee(amount) : 0; if (performanceFee > DUST) {_minter.mintForV2(address(_stakingToken), 0, performanceFee, msg.sender, depositTimestamp);amount = amount.sub(performanceFee);}
function mintForV2(address asset, uint _withdrawalFee, uint _performanceFee, address to, uint) external payable override onlyMinter {uint feeSum = _performanceFee.add(_withdrawalFee); _transferAsset(asset, feeSum);if (asset == BUNNY) {IBEP20(BUNNY).safeTransfer(DEAD, feeSum);return;}uint bunnyBNBAmount = _zapAssetsToBunnyBNB(asset, feeSum, true);if (bunnyBNBAmount == 0) return;IBEP20(BUNNY_BNB).safeTransfer(BUNNY_POOL, bunnyBNBAmount);IStakingRewards(BUNNY_POOL).notifyRewardAmount(bunnyBNBAmount);(uint valueInBNB,) = priceCalculator.valueOfAsset(BUNNY_BNB, bunnyBNBAmount);uint contribution = valueInBNB.mul(_performanceFee).div(feeSum);uint mintBunny = amountBunnyToMint(contribution);if (mintBunny == 0) return;_mint(mintBunny, to);}
但在函数_zapAssetsToBunnyBNB
返回的bunnyBNBAmount数量是由IBEP20(BUNNY_BNB).balanceOf(address(this)).sub(_initBunnyBNBAmount)
操作后减操作前的balance计算出来的。
同时中间有removeLiquidity
操作。
再看removeLiquidity代码:
function removeLiquidity()
......
address pair = PancakeLibrary.pairFor(factory, tokenA, tokenB);IPancakePair(pair).transferFrom(msg.sender, pair, liquidity); // send liquidity to pair(uint amount0, uint amount1) = IPancakePair(pair).burn(to);
.............------------
function burn(address to) external lock returns (uint amount0, uint amount1) {(uint112 _reserve0, uint112 _reserve1,) = getReserves(); // gas savingsaddress _token0 = token0; // gas savingsaddress _token1 = token1; // gas savingsuint balance0 = IERC20(_token0).balanceOf(address(this));uint balance1 = IERC20(_token1).balanceOf(address(this));uint liquidity = balanceOf[address(this)];bool feeOn = _mintFee(_reserve0, _reserve1);uint _totalSupply = totalSupply; amount0 = liquidity.mul(balance0) / _totalSupply; // using balances ensures pro-rata distributionamount1 = liquidity.mul(balance1) / _totalSupply; // using balances ensures pro-rata distribution_burn(address(this), liquidity);_safeTransfer(_token0, to, amount0);_safeTransfer(_token1, to, amount1);
再调用burn时会将当前pair中的lptoken全部燃烧并发送相应的token到目标地址。
如果将lptoken提前存入pair中,那么在调用函数_zapAssetsToBunnyBNB
时因为removeLiquidity的操作,会将提前存入的lptoken也一并转换为token并发送回合约,大量bnb与usdt 来到合约后。
zapInToken又将这些token转换为bnb后再(转换一半数量为bunny。一半bnb)1:1存入bunny:bnb池子,增加池子中bnb数量(影响bunny价格),_zapAssetsToBunnyBNB
返回时因为提前存入lp导致返回的 bunnyBNBAmount 数量也异常的大。
在(uint valueInBNB,) = priceCalculator.valueOfAsset(BUNNY_BNB, bunnyBNBAmount);
时因为zapInToken的操作,导致计算的valueInBNB结果也变得非常高。
最终生成了大量bunnytoken。
pancake闪电贷攻击学习相关推荐
- Belt闪电贷攻击后续:总损失金额5000万美元,48小时内发布补偿计划
注:5月,DeFi安全事故频发,据统计,约有15个项目遭到黑客攻击,包括Belt Finance.BurgerSwap.Julswap.Merlin.AutoShark Finance.Bogged ...
- 曾遭闪电贷攻击的Origin将重新推出稳定币OUSD
在遭遇闪电贷攻击后,Origin正准备重新推出稳定币OUSD,从现在开始,用户可以再次将USDC.USDT和DAI交换为OUSD. 据此前报道, Origin Protocol稳定币OUSD遭闪电贷攻 ...
- 闪电贷攻击的深层原因:价格预言机操纵攻击
作者:Samczsun 编译:Savage 进入11月以来,连着有两起闪电贷攻击被报道,Value DeFi 协议和BSC上的CHEESE项目方都遭遇了类似攻击,损失了数百万美元.随着时间的增加,可以 ...
- BSC 再现闪电贷攻击 BUNNY 闪崩
北京时间 5 月 20 日,BSC 链上的 DeFi 收益聚合器 PancakeBunny 遭到闪电贷攻击. PeckShield 「派盾」通过追踪和分析发现, 此次攻击源于攻击者利用 Pancake ...
- 闪电贷攻击又背锅? “幕后元凶”竟是它!
来源 | 成都链安 责编 | 晋兆雨 头图 | 付费下载于视觉中国 近日,DeFi市场经历了一场严峻的考验,多起攻击事件接连发生,造成了巨大的资产损失.在多数安全事件中,闪电贷攻击的"冠名& ...
- 知道创宇区块链安全实验室 | OneRing Finance 闪电贷攻击事件分析
前言 北京时间 2022 年 3 月 22 日,知道创宇区块链安全实验室 监测到 Fantom 生态稳定币收益优化器 OneRing Finance 遭到闪电贷攻击,黑客窃取逾 145万 美元. 分析 ...
- Belt Finance 遭闪电贷攻击,Fork Curve 的潘多拉魔盒已打开?
北京时间 5 月 30 日,PeckShield 「派盾」预警显示,BSC 链上结合多策略收益优化的 AMM 协议 Belt Finance 遭到闪电贷攻击. PeckShield 「派盾」通过追踪和 ...
- 零时科技 | Discover 闪电贷攻击事件分析
0x1 事件背景 零时科技区块链安全情报平台监控到消息,北京时间 2022年6月6日 Binance 链上 Discover 智能合约遭到闪电贷攻击.零时科技安全团队及时对此安全事件进行分析. 0x2 ...
- 闪电贷攻击攻击屡试不爽,DeFi一周被盗超1600万美元
黑客利用闪电贷,从DeFi项目Akropolis.Value DeFi Protocol和Origin Protocol中获取了1640万美元的ETH和Dai. Value DeFi的攻击者用通过闪电 ...
最新文章
- 【转】sed 简明教程
- Java LinkedList指南
- Android通过Geth RPC接口实现接入以太坊私有链
- java byte char io流_吃透Java IO:字节流、字符流、缓冲流
- OpenCV形态学变换函数morphologyEx()开运算的使用
- ajax 与route的区别,浅析vue-router jquery和params传参(接收参数)$router $route的区别
- 通过gdb调试分析Linux内核的启动过程
- DHTML【10】--Javascript
- C语言中使输入的字符串反序输出,C语言: 写一函数,使输入的一个字符串按反序存放,在主函数中输入和输出字符串。...
- 线性四叉树十进制Morton码计算示例
- MySQL中以日期为查询条件的方法
- PC_溢出概念+判断方法+示例
- CVPR 2019 论文汇总(按方向划分,0514 更新中)-转载
- 在BUF和BUF+1、BUF+2单元分别放有一个无符号字节型数,编程序将其中最大数存入MAX单元,并在屏幕上显示
- 重写equals()方法
- JS 逆向之 Hook
- 【Unity连载】斗兽棋—棋类游戏开发演示(1)
- 优维科技出席GOPS大会, EASYOPS企业版等你来
- 找工作:java开发三年工作经验
- 神武手游宠物加点方法及属性参考