Submitted by Aymen0909, also found by KupiaSec, wangxx2026 (1, 2), and 0xWaitress
In the liquidate function from the Vault contract, the input argument _amountOut is used as if it was representing a value of asset amounts and share amounts at the same time; which is impossible as there is a conversion rate between them. This error will make the liquidate function behave in an expected manner, not the one that was intended.
The issue is occurring in the liquidate function below:
As you can see from the code above, the value of the argument _amountOut is used multiple times in the function logic and each time is representing either an asset amount or a share amount; which is impossible as there is a conversion formula used to transform the asset amount into the share amount (and inversely) with the function _convertToShares (or _convertToAssets).
From the function comments, I couldnt figure out what the value of _amountOut actually represents, but because there is also another argument given to the liquidate function, which is _tokenOut == address(this), Im supposing that _amountOut is representing as a share amount; which will mean that all the instances highlighted in the code above, when _amountOut is considered as an asset amount, are wrong.
And before comparing _amountOut to the asset amount values of _vaultAssets and _liquidableYield, its value should be converted to an asset amount with the function _convertToAssets.
This issue will cause problems for the protocol working, as the liquidate function logic will not behave as expected, because its comparing values that represent different things.
Note: If _amountOut is actually representing an asset amount (not a share amount as I supposed), the issue is still valid because _amountOut is also used as being a share amount inside the liquidate function. In that case, it should first be converted to a share amount with _convertToShares in order to get the correct behavior of the liquidate function.
To solve this issue, I recommend to first convert the value of _amountOut in the liquidate function to an asset amount and store it in a local variable, _amountOutToAsset. In the function logic, use the correct variable, either _amountOut or _amountOutToAsset, when interacting with a share amount or an asset amount.
Error
asselstine (PoolTogether) confirmed
PoolTogether mitigated:
Status: Mitigation confirmed. Full details in reports from dirk_y, rvierdiiev and 0xStalin.
