HardhatDeFi
15,000 USDC
View results
Submission Details
Severity: medium
Invalid

Yield Calculation Error Due to Misaligned aToken and wToken Accounting

Bug Description

The _getAccruedYieldPrivate function incorrectly calculates the accrued yield by subtracting the total supply of wTokens from the aToken balance. This logic is flawed because aTokens represent both the principal (collateral tokens supplied by users) and the accrued yield. The current implementation assumes that the difference between the aToken balance and the wToken supply is the yield, but this is incorrect because the wToken supply only represents the principal. As a result, the function overestimates the yield by including the principal in the aToken balance.
code snippet:

function _getAccruedYieldPrivate(address _collateralToken) private view returns (uint256) {
uint256 aTokenBalance = IERC20Metadata(IAave(_aaveV3Pool).getReserveData(_collateralToken).aTokenAddress)
.balanceOf(address(this));
uint256 wTokenSupply = IERC20Metadata(_collateralTokenToWToken[_collateralToken]).totalSupply();
// Handle case where the aToken balance might be smaller than the wToken supply (e.g., due to rounding).
// In that case, the owner should just wait until yield accrues.
return aTokenBalance > wTokenSupply ? aTokenBalance - wTokenSupply : 0;
}

This logic fails to isolate the yield because it does not account for the fact that the aToken balance includes both the principal and the yield. Consequently, the function returns an inflated yield amount, which could lead to the contract owner claiming more tokens than the actual yield.

Impact

If the owner claims the incorrect yield amount, the contract may not have enough aTokens to cover user redemptions, leading to a situation where users cannot withdraw their collateral tokens.

Mitigation

Track the total principal supplied to Aave separately and calculate the yield as the difference between the current aToken balance and the tracked principal.

Updates

Lead Judging Commences

bube Lead Judge 6 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.