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

0 stars 0 forks source link

Unprotected Multiple Issuances in RTokenP1 Contract Allows Incorrect Balance Increase #81

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#L145-L146 https://github.com/code-423n4/2024-07-reserve/blob/3f133997e186465f4904553b0f8e86ecb7bbacbf/contracts/p1/RToken.sol#L105-L155

Vulnerability details

The issueTo() function in the RTokenP1 contract (RToken.sol:105-155) does not prevent multiple issuances with the same parameters within a single transaction or block. This can lead to an incorrect increase in the recipient's balance.

Impact

If the issueTo() function is called multiple times with the same parameters within a single transaction or block, the recipient's balance will be incorrectly increased by the issued amount multiple times. The recipient's balance should only be increased by the issued amount once.

Proof of Concept

Tools Used

Manual review

Recommended Mitigation Steps

Modify the issueTo() function to be idempotent, meaning that multiple calls with the same parameters would have the same effect as a single call. This can be achieved by using a mapping to track the issuances and their corresponding parameters, and only performing the issuance if it hasn't been done before.

+ mapping(address => mapping(uint256 => bool)) private _issuedAmounts;

function issueTo(address recipient, uint256 amount) public notIssuancePausedOrFrozen {
    // ...
+   if (!_issuedAmounts[recipient][amount]) {
+       _issuedAmounts[recipient][amount] = true;
        _scaleUp(recipient, amtBaskets, supply);
+   }
    // ...
}

Assessed type

Reentrancy