Christmas Dinner

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

Missing Initial Deadline Initialization in Constructor.

Summary

The ChristmasDinner contract includes a setDeadline function to enforce a deadline for deposits and participant sign-ups. However, the contract does not set an initial value for the deadline in the constructor, and the setDeadline function must be explicitly called by the host to define the deadline. If the host forgets to set the deadline, the beforeDeadline modifier will never revert, allowing deposits indefinitely.

Vulnerability Details

The issue arises in the setDeadline function and its interaction with the beforeDeadline modifier

function setDeadline(uint256 _days) external onlyHost {
if (deadlineSet) {
revert DeadlineAlreadySet();
} else {
deadline = block.timestamp + _days * 1 days;
emit DeadlineSet(deadline);
}
}

Modifier Definition

modifier beforeDeadline() {
if (block.timestamp > deadline) {
revert BeyondDeadline();
}
_;
}


The deadline variable is initialized to 0 in the constructor and remains unset until the host explicitly calls setDeadline.

Without setting the deadline, the beforeDeadline modifier checks block.timestamp > deadline, which will always evaluate to false when deadline is 0.

This effectively disables the deadline enforcement, allowing users to deposit funds at any time.

Impact

Users can bypass the intended deadline restriction and deposit tokens indefinitely, which undermines the contract’s logic.

Tools Used

Manual

Recommendations

1. Initialize a Default Deadline in the Constructor

Set a reasonable default deadline during contract deployment to ensure the beforeDeadline modifier functions correctly even if the host forgets to call setDeadline.

constructor(address _WBTC, address _WETH, address _USDC) {
host = msg.sender;
i_WBTC = IERC20(_WBTC);
whitelisted[_WBTC] = true;
i_WETH = IERC20(_WETH);
whitelisted[_WETH] = true;
i_USDC = IERC20(_USDC);
whitelisted[_USDC] = true;
// Set a default deadline to 30 days from deployment
deadline = block.timestamp + 30 days;
}
Updates

Lead Judging Commences

0xtimefliez Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

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

Give us feedback!