Skip to content
Business logic Audit finding Intermediate

getOracleData() maxExternalDeposit not accurate

The getOracleData() function calculates maxExternalDeposit without accounting for AAVE's accruedToTreasury, making the value too large. This can cause Treasury.rebalance() to fail when it attempts a deposit that exceeds the actual supply cap.

bin2chen Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-12-notional-update-5-judging/issues/49

Found by

bin2chen

Summary

in getOracleData() The calculation of maxExternalDeposit lacks consideration for reserve.accruedToTreasury. This leads to maxExternalDeposit being too large, causing Treasury.rebalance() to fail.

Vulnerability Detail

in getOracleData()

Solidity
    function getOracleData() external view override returns (OracleData memory oracleData) {
...
        (/* */, uint256 supplyCap) = IPoolDataProvider(POOL_DATA_PROVIDER).getReserveCaps(underlying);
        // Supply caps are returned as whole token values
        supplyCap = supplyCap * UNDERLYING_PRECISION;
        uint256 aTokenSupply = IPoolDataProvider(POOL_DATA_PROVIDER).getATokenTotalSupply(underlying);

        // If supply cap is zero, that means there is no cap on the pool
        if (supplyCap == 0) {
            oracleData.maxExternalDeposit = type(uint256).max;
        } else if (supplyCap <= aTokenSupply) {
            oracleData.maxExternalDeposit = 0;
        } else {
            // underflow checked as consequence of if / else statement
@>          oracleData.maxExternalDeposit = supplyCap - aTokenSupply;
        }

However, AAVE's restrictions are as follows: ValidationLogic.sol#L81-L88

Solidity
    require(
      supplyCap == 0 ||
        ((IAToken(reserveCache.aTokenAddress).scaledTotalSupply() +
          uint256(reserve.accruedToTreasury)).rayMul(reserveCache.nextLiquidityIndex) + amount) <=
        supplyCap * (10 ** reserveCache.reserveConfiguration.getDecimals()),
      Errors.SUPPLY_CAP_EXCEEDED
    );
  }

The current implementation lacks subtraction of uint256(reserve.accruedToTreasury)).rayMul(reserveCache.nextLiquidityIndex).

Impact

An overly large maxExternalDeposit may cause rebalance() to be unable to execute.

Code Snippet

https://github.com/sherlock-audit/2023-12-notional-update-5/blob/main/contracts-v3/contracts/external/pCash/AaveV3HoldingsOracle.sol#L160

Tool used

Manual Review

Recommendation

subtract uint256(reserve.accruedToTreasury)).rayMul(reserveCache.nextLiquidityIndex)

Discussion

sherlock-admin2

1 comment(s) were left on this issue during the judging contest.

takarez commented:

valid because { valid }

sherlock-admin

The protocol team fixed this issue in PR/commit https://github.com/notional-finance/contracts-v3/pull/31.

sherlock-admin

The Lead Senior Watson signed-off on the fix.

The original report as published on Sherlock, by bin2chen. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the calculation of maxExternalDeposit did not subtract the accruedToTreasury amount that AAVE includes in its supply cap check.

Impact

An overly large maxExternalDeposit may cause rebalance() to be unable to execute.

What the attacker needed

None

The fix

The issue was fixed by subtracting the accruedToTreasury amount from the supply cap calculation.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

This report is about a smart contract that calculates how many tokens can be deposited into a lending pool. The calculation missed a small portion of tokens that the pool keeps for itself, so the contract thought more tokens could be deposited than actually allowed. When the contract tried to deposit that larger amount, the transaction failed.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by bin2chen

View all

139 more disclosed reports, best first.

More from Notional Update #5

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.