The TokenManager
contract contains a critical issue in the _transfer
function. This issue will block the withdrawal logic for WETH, leading to users' funds being locked permanently.
The TokenManager::withdraw
function is designed to handle withdrawals for WETH and other ERC20 tokens. The logic for WETH differs from that of other ERC20 tokens. For other ERC20 tokens, the function directly calls Rescuable::_safe_transfer_from
to transfer the tokens from the capital pool to the msg.sender
. However, for WETH, the function uses the internal TokenManager::_transfer
function.
However, the _transfer
function contains a critical issue that blocks withdrawals. Here’s how this issue arises:
In case users want to withdraw their WETH in the _transfer
function, the _from
address == capitalPool
, which means that we will enter the if statement intended to give approval from CapitalPool
to TokenManager
. This approval is necessary for TokenManager
to call _safe_transfer_from
and complete the transfer. However, the function incorrectly passes address(this)
instead of the _token
(WETH address) to the CapitalPool
's approve
function. As a result, it attempts to call the approve
function on TokenManager
, which does not exist. Consequently, the transaction reverts because the if (!success)
check in the CapitalPool::approve
function evaluates to true.
The following PoC demonstrates this issue.
Note that I modified the createOffer
function to return the stock and offer addresses, which are used for closing the offer and enabling the withdrawal of the deposited amount. The updated function is as follows:
CMD to run the test: forge test --mt test_PermanentWithdrawalDoSForWeth --via-ir -vv
Console output:
Users won't be able to withdraw their funds, and they will be permanently locked within the contract.
VSCode, Foundry
The approve
function should be called with the actual token address. Update the _transfer
function to correctly pass the token address.
If we consider the correct permissioned implementation for the `approve()` function within `CapitalPool.sol`, this would be a critical severity issue, because the withdrawal of funds will be permanently blocked and must be rescued by the admin via the `Rescuable.sol` contract, given it will always revert [here](https://github.com/Cyfrin/2024-08-tadle/blob/04fd8634701697184a3f3a5558b41c109866e5f8/src/core/CapitalPool.sol#L36-L38) when attempting to call a non-existent function selector `approve` within the TokenManager contract. The argument up in the air is since the approval function `approve` was made permisionless, the `if` block within the internal `_transfer()` function will never be invoked if somebody beforehand calls approval for the TokenManager for the required token, so the transfer will infact not revert when a withdrawal is invoked. I will leave open for escalation discussions, but based on my first point, I believe high severity is appropriate.
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.