This contract uses aToken.balanceOf(address(this)) to measure the amount of collateral held in Aave V3 and compares it to the total supply of the associated wToken to account for the accrued interest. Specifically, _getAccruedYieldPrivate calculates yield as aTokenBalance - wTokenSupply. However, aTokens are rebalancing tokens in Aave V3 and can deviate from a strict 1:1 relationship with the underlying asset. This means aToken.balanceOf may exceed the actual underlying tokens causing overstated yield calculations and potentially leading to stuck yields.
The code assumes aTokenBalance - wTokenSupply accurately represents the interest part.
In most cases aTokenBalance is same as asset balance. However, this ratio can be broken for a number of reasons.
For example, aUSDC is worth less than USDC.
https://etherscan.io/tx/0xfc0c25219c04f1398b68a9e6880d9282f63ff8508e96527a0cd8e708749e107a
In the above transaction, 20001.9 aUSDC were minted for 20000 USDC.
The function _claimYield calls:
This withdraws the underlying asset in an amount equal to _getAccruedYieldPrivate. This amount still represents the quantity of aTokens left. Whereas aaveV3 withdraw requires the quantity of assets to be withdrawn, not the quantity of aTokens: https://aave.com/docs/developers/smart-contracts/pool#write-methods-withdraw
asset : The address of the underlying asset to withdraw, not the aToken
If _getAccruedYieldPrivate is inflated and users have withdrawed all their tokens, a revert occurs in IAave(_aaveV3Pool).withdraw because the aToken is more than the actual asset supplied. Which will cause the funds to be stuck until more funds are supplied by users.
If users have not withdrawed all the tokens, and claimYield is called before, it will leave less tokens for the users. This will thus block the users from withdrawing their full amounts.
Manual code review
Use Scaled Balances and Liquidity Index to account for the correct max withdrawable amount (must update the Liquidity index before the calculation):
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.