Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: medium
Valid

The time calculations in `ThePredicter.sol::makePrediction` and `ScoreBoard.sol::setPrediction` for making a prediction are incorrect

Summary

The time calculations in ThePredicter.sol::makePrediction and ScoreBoard.sol::setPrediction for making a prediction are incorrect. As per the documentation, matches occur each day at 20:00:00 UTC, and predictions can be placed until 19:00:00 UTC of that day.

Vulnerability Details

The start time for to protocol is 1723752000 or Thu Aug 15 2024 20:00:00 GMT+0000

Below is the calculations used to see if a prediction can be placed

if (block.timestamp > START_TIME + matchNumber * 68400 - 68400) {
revert ThePredicter__PredictionsAreClosed();
}

If it is matchNumber 1, then this would be the equation:

START_TIME + matchNumber * 68400 - 68400

1723752000 + (1 * 68400) - 68400 = 1723752000

This is correct for the first match. However, the true "first" match should be match 0, otherwise the protocol will only have 8 matches.

This is the equation if matchNumber is zero

1723752000 + (0 * 68400) - 68400 = 1723683600 or Thursday, August 15, 2024 1:00:00 AM

This is an incorrect time because predictions should be able to be placed until 19:00:00 UTC

This is the equation if matchNumber is two

1723752000 + (2 * 68400) - 68400 = 1723810400 or Friday, August 16, 2024 12:13:20 PM

Again this is an incorrect time.

68400 is equal to 19 hours, this is why these time calculations are incorrect, it is allowing predictions for each match in increments of 19 hours after the start time.

Impact

This test fails showing that you cannot make a bet at 18:59:59 UTC August 17, 2024 6:59:59 PM before the second match (matchNumber is two).

function test_correctTime() public {
//1723921200 //August 17, 2024 7:00:00 PM (19:00:00)
vm.startPrank(stranger);
vm.warp(1);
vm.deal(stranger, 1 ether);
thePredicter.register{value: 0.04 ether}();
vm.stopPrank();
vm.startPrank(organizer);
vm.warp(2);
thePredicter.approvePlayer(stranger);
vm.stopPrank();
vm.warp(1723921199); //August 17, 2024 6:59:59 PM (18:59:59)
vm.expectRevert(abi.encodeWithSelector(ThePredicter__PredictionsAreClosed.selector));
vm.startPrank(stranger);
thePredicter.makePrediction{value: 0.0001 ether}(2, ScoreBoard.Result.Draw);
vm.stopPrank();
}

Tools Used

--Foundry

Recommendations

It is recommended to change the time calculations to ensure that predictions can be placed up to 19:00:00 UTC of the day of the match.

function makePrediction(uint256 matchNumber, ScoreBoard.Result prediction) public payable {
if (msg.value != predictionFee) {
revert ThePredicter__IncorrectPredictionFee();
}
- if (block.timestamp > START_TIME + matchNumber * 68400 - 68400) {
+ if (block.timestamp > START_TIME + matchNumber * 86400 - 3600) {
revert ThePredicter__PredictionsAreClosed();
}
scoreBoard.confirmPredictionPayment(msg.sender, matchNumber);
scoreBoard.setPrediction(msg.sender, matchNumber, prediction);
}
function setPrediction(
address player,
uint256 matchNumber,
Result result
) public {
- if (block.timestamp <= START_TIME + matchNumber * 68400 - 68400)
+ if (block.timestamp > START_TIME + matchNumber * 86400 - 3600) {
playersPredictions[player].predictions[matchNumber] = result;
playersPredictions[player].predictionsCount = 0;
for (uint256 i = 0; i < NUM_MATCHES; ++i) {
if (
playersPredictions[player].predictions[i] != Result.Pending &&
playersPredictions[player].isPaid[i]
) ++playersPredictions[player].predictionsCount;
}
}
Updates

Lead Judging Commences

NightHawK Lead Judge about 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

Match timestamps are incorrect

In both contracts there is a similar error in the computation of the timestamps of the matches.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.