Vulnerability Details
The RToken.sol
implements an interest-bearing token where users' balances increase over time as they accrue interest.
rebase mechanism:
function balanceOf(address account) public view override(ERC20, IERC20) returns (uint256) {
uint256 scaledBalance = super.balanceOf(account);
return scaledBalance.rayMul(ILendingPool(_reservePool).getNormalizedIncome());
}
The amount of tokens to mint should be determined based on the following calculation formula, rather than directly using amountToMint
to mint tokens. In this way, interest can be accumulated by updating the index.
formula:
function mint(
address caller,
address onBehalfOf,
uint256 amountToMint,
uint256 index
) external override onlyReservePool returns (bool, uint256, uint256, uint256) {
uint256 amountScaled = amountToMint.rayDiv(index);
_mint(onBehalfOf, amountToMint.toUint128());
}
Impact
Due to incorrect input, the #mint
function will mint an excessive amount of tokens.
Recommendations
contract RToken is ERC20, ERC20Permit, IRToken, Ownable {
function _accrueIndex() internal {
_liquidityIndex = ILendingPool(_reservePool).getNormalizedIncome();
}
function mint(
address caller,
address onBehalfOf,
uint256 amountToMint,
uint256 index
) external override onlyReservePool returns (bool, uint256, uint256, uint256) {
_accrueIndex();
uint256 amountScaled = amountToMint.rayDiv(index);
_mint(onBehalfOf, amountScaled);
}
}