When removing liquidity or redeeming position the `_amountReturned` from AAVE may not be the full amount the user requested. This will lead to funds being lost for the user since all of his wTokens are being burned, leaving him with no wTokens to get his remaining collateral from AAVE.
When a user decides to removing liquidity or redeeming position he calls the corresponding function in the AaveDIVAWrapper/Core contract. The correspongin function calls '_redeemTokenPrivate' function. Let's take a look at that function:
So the function calls the `withdraw` function from AAVE. Let's take a look at the documentation from AAVE:
https://aave.com/docs/developers/smart-contracts/pool
For the withdraw function we have this important message:
`If user has any existing debt backed by the underlying token, then the maximum amount available to withdraw is the amount that will not leave user's health factor < 1 after withdrawal.`
Meaning if a user has used this collateral in a debt backing he will return only the part that will not harm his debt.
But as we previously see in the function ,if a user withdraws all of his wToken the user will have his whole wToken balance burned but may NOT receive the whole amount returned from AAVE.
Leaving him with no wToken and only a portion of his collateral back , in a case where he decided to withdraw all of his collateral.
There is no checking for the _amountReturned to be equal to the _wTokenAmount.
High as funds from the user will be lost.
Manual review
Compare the _amountReturned with the _wTokenAmount in the _redeemTokenPrivate function.
Or another approach is to keep the eligible tokens to withdraw in a separate mapping and make the withdrawal in a separate function.
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.