The nonReentrant modifier in the ChristmasDinner contract is improperly implemented, making it vulnerable to reentrancy attacks. Specifically, the locked = false; statement is executed after the function logic (represented by _) in the modifier. This allows an attacker to exploit the refund function, which relies on this modifier, to repeatedly call the _refundERC20 and _refundETH functions and drain the contract's funds.
The refund function is the most critical function in the contract, as it allows users to withdraw their contributions. By exploiting this vulnerability, an attacker can reenter the refund function and repeatedly call the _refundERC20 and _refundETH functions, withdrawing more than their entitled balance.
The nonReentrant modifier sets locked = false after the function body executes, leaving the contract vulnerable to reentrancy attacks during external calls.
The refund function, which utilizes this modifier, calls both _refundERC20 and _refundETH. These functions perform external calls (e.g., safeTransfer for ERC20 tokens and transfer for Ether), which can be exploited for reentry.
refund()
Internal calls to _refundERC20() and _refundETH().
The nonReentrant modifier fails to set locked = true before the function body executes. This allows an attacker to reenter the contract while locked remains false.
An attacker can exploit the reentrancy vulnerability to:
Call the refund function repeatedly before the balance is updated, draining all the ERC20 tokens and Ether from the contract.
Result in significant financial losses for the participants and the host of the event.
Manual code review.
set the locked variable to true:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.