The unstake
function uses the send
function to transfer ETH to the specified address, without properly handling the return value. This can lead to a reentrancy attack, where an attacker can repeatedly call the unstake
function and drain the contract's ETH balance.
The reentrancy vulnerability can allow an attacker to steal all the ETH from the contract, causing significant financial losses for the contract's users.
An attacker calls the unstake
function to withdraw a small amount of ETH.
Before the contract can update the user's staked amount, the attacker repeatedly calls the unstake
function, causing the contract to send more ETH to the attacker's address.
The attacker can continue this process until the contract's ETH balance is depleted.
Manual code review, Visual Studio Code.
Implement the "Checks-Effects-Interactions" pattern in the unstake
function:
Perform all necessary checks (e.g. staking period ended, amount to be withdrawn is valid).
Update the state variables(e.g. user's staked amount, total amount staked),
Interact with external contracts or addresses (i.e. trasnfer the ETH to the specified address).
Here's an example of the modified unstake
Use the low-level call
function to transfer the ETH, and handle the return value to ensure the transfer is successful.
Implement a mutex or a re-entrancy guard to prevent multiple concurrent calls to the unstake
function.
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.