The TokenManager::withdraw
function contains a critical vulnerability that allows users to repeatedly withdraw funds without updating their balance. This oversight allows any user with a positive balance to drain all funds in the protocol by repeatedly calling the withdraw function.
The TokenManager::withdraw
function is designed to allow users to withdraw their balances from the protocol. The function reads the user’s balance from the internal accounting mapping and sends the corresponding amount to the user. However, it fails to update the user’s balance after the withdrawal, enabling users to withdraw their balance multiple times.
The issue arises because the function does not set the user’s balance to zero or otherwise reduce it after a withdrawal. This enables an attacker to:
Call the withdraw function to withdraw their balance.
Call the withdraw function again, as their balance remains unchanged, allowing them to withdraw the same amount repeatedly.
Continue this process until the protocol’s funds are completely drained.
This vulnerability allows any user with a positive balance to repeatedly withdraw funds from the protocol without limit, leading to the complete depletion of the protocol’s funds. The issue can result in the total loss of funds for all users of the protocol.
The following test case, which can be included in TokenManager.t.sol, demonstrates the exploit:
Manual code review.
To address this vulnerability, the TokenManager::withdraw function must update the user’s balance after a withdrawal is made. The following code modification ensures that the balance is properly adjusted:
This change ensures that users cannot withdraw more than their actual balance, preventing them from draining the protocol’s funds.
Valid critical severity finding, the lack of clearance of the `userTokenBalanceMap` mapping allows complete draining of the CapitalPool contract. Note: This would require the approval issues highlighted in other issues to be fixed first (i.e. wrong approval address within `_transfer` and lack of approvals within `_safe_transfer_from` during ERC20 withdrawals)
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.