Relevant GitHub Link
https://github.com/Cyfrin/2024-07-the-predicter/blob/839bfa56fe0066e7f5610197a6b670c26a4c0879/src/ThePredicter.sol#L93
https://github.com/Cyfrin/2024-07-the-predicter/blob/839bfa56fe0066e7f5610197a6b670c26a4c0879/src/ScoreBoard.sol#L66
Summary
The current implementation of the makePrediction function restricts predictions to a 19-hour window, contrary to the specified 24-hour interval for making predictions. This discrepancy affects the fairness and functionality of the protocol.
PoC
function test_after19Hours() public {
uint256 START_TIME = 1723752000;
address player1 = makeAddr("player1");
vm.startPrank(player1);
vm.deal(player1, 1 ether);
thePredicter.makePrediction{value: 0.0001 ether}(
0,
ScoreBoard.Result.First
);
vm.stopPrank();
vm.warp(START_TIME + 68400);
address player2 = makeAddr("player2");
vm.startPrank(player2);
vm.deal(player2, 1 ether);
vm.expectRevert(abi.encodeWithSelector(ThePredicter__PredictionsAreClosed.selector));
thePredicter.makePrediction{value: 0.0001 ether}(
0,
ScoreBoard.Result.First
);
vm.stopPrank();
}
Tools Used
Manual Reading and Foundry
Recommendations
Change the 19 hour window to 24.
- if (block.timestamp > START_TIME + matchNumber * 68400 - 68400)
+ if (block.timestamp >= START_TIME + matchNumber * 86400 - 3600) {
revert ThePredicter__PredictionsAreClosed();
}
-if (block.timestamp <= START_TIME + matchNumber * 68400 - 68400)
+if (block.timestamp < START_TIME + matchNumber * 86400 - 3600)