Christmas Dinner

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

Ineffective Reentrancy Guard Due to Missing Lock State Causes Reentrancy in functions where it is used

Summary

The nonReentrant modifier in the ChristmasDinner contract fails to properly implement reentrancy protection because it never sets the locked state to true, allowing potential reentrant calls.

Vulnerability Details

modifier nonReentrant() {
require(!locked, "No re-entrancy");
_;
locked = false;
}

The modifier checks if locked is false but never sets it to true before executing the function body. This means that during the execution of the protected function, the locked state remains false, allowing another call to enter the same function.

A proper reentrancy guard should:

  1. Check if the contract is locked

  2. Set the lock before executing the function

  3. Release the lock after execution

Impact

High severity. This vulnerability could allow malicious actors to perform reentrant calls on functions meant to be protected, particularly the refund() function which handles both ERC20 and ETH transfers. This could potentially lead to:

  • Multiple refunds being processed simultaneously

  • Draining of contract funds beyond user entitlements

  • Race conditions in state updates

Tools Used

Manual review

Recommendations

Modify the nonReentrant modifier to properly implement the locking mechanism

modifier nonReentrant() {
require(!locked, "No re-entrancy");
locked = true;
;
locked = false;
}

Consider using OpenZeppelin's ReentrancyGuard contract instead of implementing a custom solution:

import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
contract ChristmasDinner is ReentrancyGuard {
// ... existing code ...
}
Updates

Lead Judging Commences

0xtimefliez Lead Judge 10 months ago
Submission Judgement Published
Validated
Assigned finding tags:

mutex lock incomplete

Support

FAQs

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