The ReserveLibrary's deposit function incorrectly interprets the return values from RToken's mint function, leading to wrong amounts being emitted in Deposit events. This occurs because the ReserveLibrary assumes the second return parameter from mint is the scaled amount, while RToken actually returns the scaled amount as the fourth parameter.
The issue stems from a parameter order mismatch between what ReserveLibrary expects and what RToken returns. Let's analyze the flow:
In ReserveLibrary's deposit function:
From analyzing the code in deposit function above, in the Deposit event amount and amountMinted will always have the same value (since amountMinted is just the same variable as amount - has essentially just been recycled through the RToken contract)
In IRToken interface,
Notice that in the IRToken mint natspec comments, the 2nd return value The amount of scaled tokens minted and the 4th uint256: The amount of underlying tokens mintedHowever, The RToken's mint function returns values in this interchanged order:
ReserveLibrary assigns the second return value (amountToMint) to amountMinted, believing it to be the scaled amount. However, amountToMint is the raw amount, while the actual scaled amount is the fourth parameter.
This matters because:
The scaled amount represents the token amount adjusted by the liquidity index
The raw amount is the direct deposit amount without scaling
Using the wrong value leads to incorrect event emissions and potentially misleading off-chain monitoring systems
Incorrect event emissions leading to wrong historical data
Off-chain systems monitoring deposit amounts will record incorrect scaled values
Potential confusion in accounting systems tracking scaled vs. unscaled amounts
Manual review
You have 2 options;
a) Modify the RToken contract to return the correct order as in IRToken interface:
b) Or alternatively modify ReserveLibrary's deposit function to use the correct return parameter:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.