Christmas Dinner

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

Reentrancy Vulnerability in `refund()`

Summary

The refund() function implements a mutex lock to prevent reentrancy. However, the lock implementation is incorrect, allowing the function to be exploited.

Vulnerability Details

  • The locked variable is set to false after the function execution, rather than before. This enables malicious contracts to re-enter the function.

    Steps To Reproduce

  • Write a malicious contract that calls the refund() function recursively.

  • Deploy the ChristmasDinner contract.

  • Deploy the malicious contract and deposit funds into ChristmasDinner.

  • Execute the reentrancy attack by calling the malicious contract.

Impact

An attacker can drain funds from the contract by repeatedly calling refund() before the locked variable is reset.

Tools Used

Foundry

Recommendations

  • Set locked to true at the start of the refund() function and reset it to false after execution.

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

Lead Judging Commences

0xtimefliez Lead Judge about 1 year 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.

Give us feedback!