Christmas Dinner

First Flight #31
Beginner FriendlyFoundrySolidity
100 EXP
View results
Submission Details
Severity: medium
Valid

`christmasDinner::setDeadline` will never revert

Summary

The christmasDinner::setDeadline function is intended to revert if the deadline has already been set. However, due to a flaw in the current implementation, the revert statement will never be executed.
https://github.com/Cyfrin/2024-12-christmas-dinner/blob/9682dcc306db935a2511e1eb8280d17ef01e9004/src/ChristmasDinner.sol#L182
https://github.com/Cyfrin/2024-12-christmas-dinner/blob/9682dcc306db935a2511e1eb8280d17ef01e9004/src/ChristmasDinner.sol#L42

Vulnerability Details

The christmasDinner::setDeadline function uses a boolean variable, deadlineSet, to determine whether the deadline has already been set. If it is set, the function is supposed to revert. Otherwise, it sets the deadline to block.timestamp + _days * 1 days. However, since the deadlineSet variable is never updated to true after setting the deadline, the function does not revert and allows the deadline to be reset multiple times.

Impact

  • The host can set the event deadline multiple times, potentially causing inconsistencies in the event scheduling.

PoC

  • use this test in christmasDinnerTest.t.sol`

function testUserCanSetDeadLineMultipleTimes() public {
vm.startPrank(deployer);
cd.setDeadline(8 days);
cd.setDeadline(8 days);
vm.stopPrank();
}

Tools Used

  • IDE

  • Manual Review

Recommendations

  • Update the function to set the deadlineSet boolean to true immediately after the deadline is assigned.

function setDeadline(uint256 _days) external onlyHost {
//@audit medium deadlineSet bool is never set to true
if (deadlineSet) {
revert DeadlineAlreadySet();
} else {
deadline = block.timestamp + _days * 1 days;
emit DeadlineSet(deadline);
}
+ deadlineSet = true;
}
Updates

Lead Judging Commences

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

deadline is never set to true

Support

FAQs

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

Give us feedback!