The withdraw
function in the WithdrawalPool
contract performs an external call (token transfer) before updating the contract's state, potentially allowing for a reentrancy attack. While the use of SafeERC20
mitigates some risks, it doesn't completely eliminate the possibility of reentrancy with non-standard or malicious token implementations.
The withdraw
function in the WithdrawalPool
contract follows this general structure:
Perform some checks
Calculate the amount to withdraw
Transfer tokens to the user using token.safeTransfer
Update the contract's state (e.g., reduce the user's balance)
This order of operations violates the checks-effects-interactions
pattern, which is a best practice to prevent reentrancy attacks
. The external call (token transfer) is made before the contract's state is updated, potentially allowing a malicious token contract to reenter the withdraw
function and manipulate the contract's state.
While the use of SafeERC20's
safeTransfer function provides some protection against reentrancy for standard ERC20
tokens, it doesn't guarantee protection against all possible token implementations, especially non-standard or malicious ones.
this vulnerability could allow an attacker to Withdraw
more funds than they're entitled to, Manipulate the contract's state in unexpected ways and Potentially drain the contract of funds.
manual code review
Implement the checks-effects-interactions pattern in the withdraw function:
Perform all necessary checks
Update the contract's state (e.g., reduce the user's balance)
Perform the token transfer last
Consider implementing a reentrancy guard using OpenZeppelin's ReentrancyGuard contract as an additional layer of protection.
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.