-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
00adcd1
commit 082711d
Showing
3 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "./WBC.sol"; | ||
import {console} from "forge-std/Test.sol"; | ||
|
||
contract Ans { | ||
WBC public immutable wbc; | ||
|
||
constructor(address wbc_) { | ||
wbc = WBC(wbc_); | ||
wbc.bodyCheck(); | ||
} | ||
|
||
function win() external { | ||
wbc.ready(); | ||
} | ||
|
||
function judge() external view returns (address) { | ||
return block.coinbase; | ||
} | ||
|
||
function steal() external pure returns (uint160) { | ||
return 507778882907781185490817896798523593512684789769; | ||
} | ||
|
||
function execute() external pure returns (bytes32) { | ||
string memory ans = "HitAndRun"; | ||
return bytes32(uint256(uint80(bytes10(abi.encodePacked(uint8(bytes(ans).length), ans))))); | ||
} | ||
|
||
function shout() external view returns (string memory) { | ||
if (gasleft() % 3 == 2) { | ||
return "I'm the best"; | ||
} else { | ||
return "We are the champion!"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import {console2} from "forge-std/console2.sol"; | ||
import {Test} from "forge-std/Test.sol"; | ||
import {WBC, WBCBase} from "src/WBC/WBC.sol"; | ||
import {Ans} from "src/WBC/Ans.sol"; | ||
|
||
contract WBCTest is Test { | ||
WBCBase public base; | ||
WBC public wbc; | ||
Ans public ans; | ||
|
||
uint256 count; | ||
|
||
function setUp() external { | ||
uint256 startTime = block.timestamp + 60; | ||
uint256 endTime = startTime + 60; | ||
uint256 fullScore = 100; | ||
base = new WBCBase(startTime, endTime, fullScore); | ||
base.setup(); | ||
wbc = base.wbc(); | ||
} | ||
|
||
function testExploit() external { | ||
for (uint256 i = 0; i < 1000; ++i) { | ||
try new Ans{salt: bytes32(i)}(address(wbc)) returns (Ans _ans) { | ||
ans = _ans; | ||
break; | ||
} catch {} | ||
} | ||
ans.win(); | ||
base.solve(); | ||
assertTrue(base.isSolved()); | ||
} | ||
|
||
function testCannotHomeRunEasily() external { | ||
vm.expectRevert("try again"); | ||
wbc.homerun(); | ||
vm.expectRevert(); | ||
base.solve(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters