Since the allowance from CapitalPool
to TokenManager
is zero, during the withdrawal of WETH, this allowance should be increased. But, due to wrong implementation, it will revert.
This clearly leads to stuck of funds in the protocol.
During withdrawing, if the token address is WETH, then the function _transfer
is called to transfer required WETH from the CapitalPool
to the caller.
https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/TokenManager.sol#L160
In this function, if allowance of CapitalPool
to the TokenManager
is zero, then the function approve
in CapitalPool
is called to give allowance to TokenManager
.
https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/TokenManager.sol#L247
https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/CapitalPool.sol#L24
The issue is that the parameter of the function approve
should be the address of the token WETH, but the protocol by mistake inserted address(this)
as parameter.
https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/TokenManager.sol#L247
This leads to revert, because in CapitalPool
, it is expecting the token address is forwarded as the parameter. So, the low-level call would be unsuccessful, and it reverts by ApproveFailed
.
https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/CapitalPool.sol#L28
In the following test, a maker creates an ask offer with WETH as collateral, and later he closes it. Later the maker intends to withdraw his collateral. By, calling the function withdraw
, it will revert, and he will not be able to withdraw.
Stuck of fund in the protocol.
Users who deposits WETH as collateral, will not be able to withdraw them.
Following modification is recommended:
https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/TokenManager.sol#L247
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.