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

Yield Claim Rounding Errors

Summary

The function _getAccruedYieldPrivate() calculates accrued yield by subtracting wTokenSupply from aTokenBalance. However, rounding issues may cause wTokenSupply> aTokenBalance, resulting in an incorrect 0 return

Vulnerability Details

.Aave's interest model results in small discrepancies between aToken balance and wToken supply.

. If wTokenSupply is slightly larger due to rounding, _getAccruedYieldPrivate() returns 0 even when yield exists.

.Setup

.Alice deposits 1000 USDC and receives 1000 aUSDC and 1000 wUSDC.

. Overtime, 1 USDC yield accrues, so aUSDC balance = 1001, but wUSDC supply = 1002 due to rounding

.Exploit

. _getAccruedYieldPrivate() computes 1001 - 1002 = 0, meaning Alice gets zero yield

Consequences

Alice's accrued yield is permanently lost

Code location Concern

https://github.com/Cyfrin/2025-01-diva/blob/1b6543768c341c2334cdff87b6dd627ee2f62c89/contracts/src/AaveDIVAWrapperCore.sol#L482

https://github.com/Cyfrin/2025-01-diva/blob/1b6543768c341c2334cdff87b6dd627ee2f62c89/contracts/src/AaveDIVAWrapperCore.sol#L483

https://github.com/Cyfrin/2025-01-diva/blob/1b6543768c341c2334cdff87b6dd627ee2f62c89/contracts/src/AaveDIVAWrapperCore.sol#L484

https://github.com/Cyfrin/2025-01-diva/blob/1b6543768c341c2334cdff87b6dd627ee2f62c89/contracts/src/AaveDIVAWrapperCore.sol#L488

https://github.com/Cyfrin/2025-01-diva/blob/1b6543768c341c2334cdff87b6dd627ee2f62c89/contracts/src/AaveDIVAWrapperCore.sol#L344

https://github.com/Cyfrin/2025-01-diva/blob/1b6543768c341c2334cdff87b6dd627ee2f62c89/contracts/src/AaveDIVAWrapperCore.sol#L345

https://github.com/Cyfrin/2025-01-diva/blob/1b6543768c341c2334cdff87b6dd627ee2f62c89/contracts/src/AaveDIVAWrapperCore.sol#L346

https://github.com/Cyfrin/2025-01-diva/blob/1b6543768c341c2334cdff87b6dd627ee2f62c89/contracts/src/AaveDIVAWrapperCore.sol#L347

Impact

. If rounding favours aTokens, users may over claim yield, potentially causing fund shortages in the protocol

. If rounding favours wTokens, users may over claim yield, potentially causing fund shortages in the protocol

. Small differences in balance calculations may accumulate over time, leading to unexpected errors when redeeming yield.

Tools Used

Manual review

Recommendations

return aTokenBalance > wTokenSupply ? aTokenBalance - wTokenSupply : 0;

Fix

This ensures at least 1 wei is returned, avoiding unnecessary loss due to rounding errors

return aTokenBalance > wTokenSupply ? aTokenBalance - wTokenSupply : 1;
Updates

Lead Judging Commences

bube Lead Judge 5 months ago
Submission Judgement Published
Invalidated
Reason: Known issue

Support

FAQs

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