Core Contracts

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

Non-1:1 Minting of `RTokens` Leading to Incorrect Withdrawal Amounts

Summary

The deposit function in the ReserveLibrary mints RTokens based on the reserve.liquidityIndex, which is not a 1:1 ratio with the underlying asset. This design flaw causes users to withdraw more or less of the underlying asset than they initially deposited, depending on the state of the liquidityIndex. This issue undermines the fairness and predictability of the protocol, potentially leading to financial losses for users.

Vulnerability Details

The deposit function in the ReserveLibrary mints RTokens to users based on the reserve.liquidityIndex, which is updated over time to reflect accrued interest.

(bool isFirstMint, uint256 amountScaled, uint256 newTotalSupply, uint256 amountUnderlying) = IRToken(reserve.reserveRTokenAddress).mint(
address(this), // caller
depositor, // onBehalfOf
amount, // amount
reserve.liquidityIndex // index
);

RToken contract _update function

function _update(address from, address to, uint256 amount) internal override {
// Scale amount by normalized income for all operations (mint, burn, transfer)
uint256 scaledAmount = amount.rayDiv(ILendingPool(_reservePool).getNormalizedIncome());
super._update(from, to, scaledAmount);
}

The amountScaled (minted RTokens) is calculated using the reserve.liquidityIndex, which increases over time as interest accrues. This means that the same amount of underlying assets deposited at different times will result in different amounts of RTokens being minted. When users withdraw their funds, the amount of underlying assets they receive is determined by the current liquidityIndex, which may not match the index at the time of deposit.

This creates a discrepancy between the deposited and withdrawn amounts, leading to unfair outcomes for users. For example:

  • If the liquidityIndex increases significantly after a deposit, users may receive more underlying assets than they deposited, potentially at the expense of other users.

  • If the liquidityIndex decreases, users may receive fewer underlying assets than they deposited, resulting in financial losses.

Proof of Concept (POC)

  1. Initial State:

    • reserve.liquidityIndex = 1e27 (RAY, representing 1.0)

    • User A deposits 100 crvUSD.

  2. Minting RTokens:

    • The mint function calculates amountScaled as amount / liquidityIndex.

    • amountScaled = 100e18 / 1e27 = 1e11 RTokens are minted to User A.

  3. Interest Accrual:

    • Over time, the liquidityIndex increases to 1.1e27 due to accrued interest.

  4. User A Withdraws:

    • User A attempts to withdraw their 1e11 RTokens.

    • The burn function calculates the underlying amount as amountScaled * liquidityIndex.

    • amountUnderlying = 1e11 * 1.1e27 = 110e18 crvUSD.

Result:

  • User A deposited 100 crvUSD but withdrew 110 crvUSD, receiving 10% more than they deposited. This excess comes from the protocol's reserves, potentially disadvantaging other users.

// Initial state
reserve.liquidityIndex = 1e27; // 1.0 in RAY
// User A deposits 100 crvUSD
uint256 amount = 100e18;
(uint256 amountScaled, , , ) = IRToken(reserve.reserveRTokenAddress).mint(
address(this),
depositor,
amount,
reserve.liquidityIndex
);
// amountScaled = 100e18 / 1e27 = 1e11 RTokens
// Interest accrues, liquidityIndex increases to 1.1e27
reserve.liquidityIndex = 1.1e27;
// User A withdraws 1e11 RTokens
(uint256 amountUnderlying, , ) = IRToken(reserve.reserveRTokenAddress).burn(
depositor,
depositor,
amountScaled,
reserve.liquidityIndex
);
// amountUnderlying = 1e11 * 1.1e27 = 110e18 crvUSD

Impact

  • Users may receive fewer underlying assets than they deposited if the liquidityIndex decreases.

  • Users may receive more underlying assets than they deposited if the liquidityIndex increases, potentially at the expense of other users.

Tools Used

Manual Review

Recommendations

Modify the mint and burn functions to ensure a 1:1 ratio between deposited underlying assets and minted RTokens.

Updates

Lead Judging Commences

inallhonesty Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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

Give us feedback!