Description
The player can make prediction without pay prediction fee on ScoreBoard::setPrediction
.
Impact
The protocol will miss the prediction fee from player.
Proof Of Concept
Add the following code to the test/ThePredicter.test.sol
:
function test_PlayerCanNotEditPredictionWithoutPayPredictionFee() public {
vm.deal(stranger, 1 ether);
vm.startPrank(stranger);
thePredicter.register{value: 0.04 ether}();
vm.stopPrank();
vm.startPrank(organizer);
thePredicter.approvePlayer(stranger);
vm.stopPrank();
vm.startPrank(stranger);
vm.expectRevert();
scoreBoard.setPrediction(msg.sender, 0, ScoreBoard.Result.Second);
vm.stopPrank();
}
Run with: forge test --match-test test_PlayerCanEditPredictionWithoutPayFeeIfAlreadyPaid -vvv
Recommended Mitigation
In the src/ScoreBoard.sol
:
error ScoreBoard__UnauthorizedAccess();
+ error ScoreBoard__PredictionFeeShouldBePaid();
function setPrediction(
address player,
uint256 matchNumber,
Result result
) public {
+ if(playersPredictions[player].isPaid[matchNumber] == false) {
+ revert ScoreBoard__PredictionFeeShouldBePaid();
+ }
if (block.timestamp <= START_TIME + matchNumber * 68400 - 68400)
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;
}
}