The logic for the function modifier nonRentrant
in ChrismasDinner.sol needs adjusting as the mutex is set up incorrectly. The lock should be set to true before code execution and then set to false after code execution. In the current implementation there no lock before the code execution. This vulnerbility can cause loss of funds through reentrancy attacks.
Currently the code is implemented as above where the require statement will always have locked = false
as it is never set to true
during code execution. This leaves the functions implementing this function modifier vulnerable to rentrancy attacks.
Attack Vector:
Attacker calls vulnerable function (e.g., refund()
)
During execution, the contract makes external call
Attacker contract re-enters the function
Since locked
is never set to true, the require check passes
This cycle can repeat until funds are drained
The impact of this could leave to total loss of funds in the protocol due to the faulty implementation of the reentracy gaurd. The refund()
would be the one vulnerable in this function and downstream this refundERC20()
and refundETH()
would be effects as well too.
Adjust the function modifer to have proper mutex workflow by setting the locked
varibable to true before the code execution.
This execution flow will allow functions that use this modifer would lock the contract as they execute it so no other executions that use this modifer would be allowed until this code gets executed and then return the locked varible to false.
Alternatively, you can use an opensource library such as OpenZeppelin that provide this functionality to protect from reentrancy attacks: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/ReentrancyGuard.sol
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.