The withdraw function in the given contract is vulnerable to a reentrancy attack. This vulnerability allows an attacker to recursively call the withdraw function before the initial function execution completes, potentially draining the contract of its funds.
A reentrancy attack occurs when a contract calls an external contract before it updates its state. This allows the external contract to make a recursive call back to the original function, potentially exploiting the contract's state before it is updated.
Affected Function
The withdraw function is susceptible to this vulnerability due to the order of operations:
An attacker can drain the contract’s funds by repeatedly calling the withdraw function before the state is updated, leading to significant financial loss.
Manual
Update State Before External Call: Change the order of operations to update the state before making the external call.
Use Mutex/Guard: Implement a guard to prevent reentrancy.
The `withdraw` function sends the given amount to Ram. If the attacker calls the `withdraw` function again before the state variable is changed, the function will revert because there are no more funds in the contract. This reentrancy has no impact for the protocol. It is recommended to follow the CEI pattern, but this is informational.
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.