Core Contracts

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

Incorrect Return Order in `mint()` Function of RToken Contract Causes Misalignment in Lending Pool's ReserveLibrary

Summary

The mint() function in the RToken contract returns a tuple containing (isFirstMint, amountToMint, totalSupply(), amountScaled). However, the ReserveLibrary of the lending pool expects the return values in the order of (isFirstMint, amountScaled, newTotalSupply, amountUnderlying). This discrepancy misaligns the expected values, causing incorrect handling of deposit amounts.

Vulnerability Details

Inside the `ReserveLibrary.deposit()`, RToken is minted for the depositor. The problem here is the return value order of this function:

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

https://github.com/Cyfrin/2025-02-raac/blob/main/contracts/libraries/pools/ReserveLibrary.sol#L337-L342

However, the RToken mint() function returns the amountUnderlying and amountScaled in wrong order:

return (isFirstMint, amountToMint, totalSupply(), amountScaled);

https://github.com/Cyfrin/2025-02-raac/blob/main/contracts/core/tokens/RToken.sol#L140

  1. User A deposits 1,000 tokens into the lending pool.

  2. The mint() function computes:

amountToMint = 1000
amountScaled = amountToMint.rayDiv(usageIndex)

Suppose usageIndex = 1.1e27, then:

amountScaled = 1000.rayDiv(1.1e27) ≈ 909
  1. The function mint() returns:

(true, 1000, 1_000_000, 909)

  1. But ReserveLibrary expects the following order:

(true, 909, 1_000_000, 1000)

  1. Due to the swapped values, the system mistakenly treats 909 as amountUnderlying instead of amountScaled, leading to minting incorrect amounts of Rtokens.

Impact

Since amountScaled and amountUnderlying are displaced, deposited amounts may be incorrectly recorded in the lending pool.

Tools Used

Manual

Recommendations

Consider modifying the RToken minting mechanism and return values which are used inside the ReserveLibrary contract.

Updates

Lead Judging Commences

inallhonesty Lead Judge 4 months ago
Submission Judgement Published
Validated
Assigned finding tags:

RToken::mint returns 0 instead of actual totalSupply() when amountToMint is 0, causing incorrect data for off-chain systems relying on return values

inallhonesty Lead Judge 4 months ago
Submission Judgement Published
Validated
Assigned finding tags:

RToken::mint returns 0 instead of actual totalSupply() when amountToMint is 0, causing incorrect data for off-chain systems relying on return values

Support

FAQs

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