Core Contracts

Regnum Aurum Acquisition Corp
HardhatReal World AssetsNFT
77,280 USDC
View results
Submission Details
Severity: medium
Valid

Untracked Curve vault yield causes underflow when withdraw and breaks the RToken interest mechanism

Summary

The LendingPool contract's totalVaultDeposits tracking mechanism can underflow when withdrawing funds that include accrued yield. This occurs because the protocol subtracts the full withdrawal amount from totalVaultDeposits without accounting for the portion that represents yield, potentially leading to underflow.

The second issue is the curveVault yield is excluded from reserves, creating a mismatch between the actual LendingPool liquidityIndex and the correct value(deposits + yield). This results in RTokens earning less interest than intended.

Vulnerability Details

**Underflow issue: **the LendingPool contract, when withdrawing from the vault:

function _withdrawFromVault(uint256 amount) internal {
curveVault.withdraw(amount, address(this), msg.sender, 0, new address[](0));
totalVaultDeposits -= amount; // @audit-issue potential underflow
}

PoC

Initial state:

totalVaultDeposits = 1000 crvUSD // Original deposits in vault
liquidityBufferRatio = 20% // Protocol wants to keep 20% in buffer

Over time, the Curve vault has generated 10% yield:

Actual vault balance = 1100 crvUSD // 1000 original + 100 yield
totalVaultDeposits still = 1000 crvUSD // This only tracks original deposits

Now a large withdrawal happens, let's say someone wants to withdraw 900 crvUSD:

reserve.totalLiquidity = 1100 crvUSD
desiredBuffer = 1100 * 20% = 220 crvUSD // Protocol wants this much in buffer
currentBuffer = 100 crvUSD // Amount currently in RToken

To maintain the desired buffer ratio after this large withdrawal, _rebalanceLiquidity() will be called:

shortage = desiredBuffer - currentBuffer
shortage = 220 - 100 = 120 crvUSD

_withdrawFromVault(120) is called to cover this shortage:

curveVault.withdraw(120, address(this), address(this));
totalVaultDeposits -= 120; // 1000 - 120 = 880

The issue is that totalVaultDeposits only tracks original deposits (1000), but the protocol needs to withdraw both original deposits AND yield (120) to maintain its buffer ratio. Over time, as more yield accumulates and large withdrawals happen, the protocol will need to withdraw more and more of the yield, eventually leading to withdrawing more than what totalVaultDeposits tracks.

The untracked yield issue: even if the yield is properly withdrawn from the curveVault to meet the liquidity buffer ratio, this yield is not accounted in the reserves. This will cause the interest rates to be calculated based on incorrect liquidity data(value deposited, not value deposited + yield).

Impact

For the underflow:

  • DoS - Users will be prevented from withdrawing their funds.

  • Every function that relies on _rebalanceLiquidity can suffer DoS: deposit, withdraw, and borrow.

For the not accounted yield:

  • Users receive suboptimal interest rates for their RToken.

  • Interest rates are calculated based on incomplete liquidity data

  • The discrepancy grows larger as more yield accrues in the vault

Tools Used

Manual Review

Recommendations

To fix the underflow: Modify totalVaultDeposits to track the total value in the vault including yield, not just the original deposits. When yield is earned, increment totalVaultDeposits accordingly. This ensures withdrawals (including yield) won't cause underflows.

To fix the yield in the reserves: whenever withdrawing yield from the curveVaultupdate the ReserveLibrary.updateInterestRatesAndLiquidity() passing the yield as the amount added. i.e:

// Update reserves with the yield amount
ReserveLibrary.updateInterestRatesAndLiquidity(
reserve,
rateData,
yield,
0
);
Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 month ago
Submission Judgement Published
Validated
Assigned finding tags:

LendingPool::totalVaultDeposits can underflow when withdrawing yield-inclusive amounts and vault yield isn't factored into interest rate calculations

inallhonesty Lead Judge about 1 month ago
Submission Judgement Published
Validated
Assigned finding tags:

LendingPool::totalVaultDeposits can underflow when withdrawing yield-inclusive amounts and vault yield isn't factored into interest rate calculations

Support

FAQs

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