https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/TokenManager.sol
The withdraw
function in the TokenManager
contract is susceptible to reentrancy attacks, particularly when handling wrapped native tokens. This vulnerability arises due to the sequence of operations involved in transferring and unwrapping tokens, which can potentially be exploited by malicious contracts that can re-enter the withdraw
function.
Vulnerable Code
The withdraw
function performs the following operations:
For Wrapped Native Tokens:
Transfers wrapped native tokens from the capital pool to the TokenManager
contract.
Unwraps the tokens using IWrappedNativeToken(wrappedNativeToken).withdraw(claimAbleAmount)
.
Transfers the resulting native tokens to the user with payable(msg.sender).transfer(claimAbleAmount)
.
For ERC20 Tokens:
Transfers ERC20 tokens directly to the user using _safe_transfer_from
.
Reentrancy Issue:
When the function transfers native tokens to msg.sender
, if msg.sender
is a contract with a fallback or receive function, it can re-enter the withdraw
function. This could allow the attacker to withdraw more tokens than they are entitled to before the initial withdrawal completes.
Potential Loss: The attacker could withdraw more than their allowed share, potentially draining the contract of wrapped native tokens.
Financial Loss: Excessive withdrawals could lead to significant financial loss for users and the contract owner.
Contract Instability: Exploitation could destabilize the contract and impact overall system integrity.
Manual Review
Implement Reentrancy Guard:
Use OpenZeppelin’s ReentrancyGuard
to prevent reentrant calls.
Example Implementation.
Implementatio
Review External Contract Interactions:
Ensure that interactions with IWrappedNativeToken
and other external contracts are secure and handle potential errors properly.
Conduct Comprehensive Testing:
Perform thorough testing and security audits to verify that the reentrancy guard is effective and to identify any additional vulnerabilities.
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.