TokenManager::_transfer Will Always Revert Due to Incorrect Approval CallThe _transfer function within the TokenManager contract is responsible for transferring funds from the CapitalPool contract to users. For ERC20 tokens, an approval step is necessary before any transfer can occur. However, the current implementation incorrectly calls the approve function on the CapitalPool contract, passing address(this) instead of the correct ERC20 token address. This mistake results in all funds remaining stuck in the CapitalPool, effectively rendering them inaccessible to users.
The _transfer function attempts to approve itself to transfer ERC20 tokens on behalf of the CapitalPool contract. However, it mistakenly uses address(this) as the parameter for the approve function call, instead of the actual ERC20 token address. This incorrect usage prevents the approval from being correctly established, leading to failed transfers.
The correct approve function signature expects the ERC20 token address as its parameter, not the TokenManager address.
While the CapitalPool contract is designed to be rescuable, the inability for users to withdraw any tokens due to this bug effectively means the funds are stuck. This situation undermines the trustworthiness of the system and negatively affects user experience.
Adding the following test to the existing test suite demonstrates the failure mode:
Manual Review
To resolve this issue, the _transfer function should be corrected to pass the ERC20 token address to the approve function call, rather than address(this). This adjustment ensures that the approval is correctly established, allowing for successful transfers of ERC20 tokens.
This correction ensures that the approve function is called with the correct parameters, allowing for successful ERC20 token transfers and resolving the reported vulnerability.
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.