code-423n4 / 2024-07-reserve-validation

0 stars 0 forks source link

Lack of Balance Check In RToken's melt() Enables Over-Burning #101

Closed c4-bot-7 closed 1 month ago

c4-bot-7 commented 2 months ago

Lines of code

https://github.com/code-423n4/2024-07-reserve/blob/3f133997e186465f4904553b0f8e86ecb7bbacbf/contracts/p1/RToken.sol#L370-L375

Vulnerability details

The protocol aims to maintain the stability and value of RToken through various mechanisms, including the ability to mint and burn tokens. The RToken contract in RToken.sol defines the core functionality of RToken, including the melt() function, which allows the furnace contract to burn a specified amount of RTokens from the caller's account balance.

However, The function lacks check to ensure that the caller has a sufficient balance to perform the melting operation. This oversight allows a caller to burn more RTokens than they actually own, leading to an incorrect reduction in the total supply and an inconsistent state of the system.

Impact

Proof of Concept

RToken.sol:370-375 shows the vulnerable melt() function

function melt(uint256 amtRToken) external {
    address caller = _msgSender();
    require(caller == address(furnace), "furnace only");
    _burn(caller, amtRToken);
    emit Melted(amtRToken);
}

As evident from the code, there is no check to ensure that the caller's balance (balanceOf(caller)) is greater than or equal to the amtRToken being melted.

Tools Used

Manual review

Recommended Mitigation Steps

Add a balance check in the melt() function to ensure that the caller has a sufficient balance to perform the melting operation.

function melt(uint256 amtRToken) external {
    address caller = _msgSender();
    require(caller == address(furnace), "furnace only");
+   require(balanceOf(caller) >= amtRToken, "insufficient balance");
    _burn(caller, amtRToken);
    emit Melted(amtRToken);
}

Assessed type

Invalid Validation