Submitted by AkshaySrivastav
The RTokenP1 contract implements a throttling mechanism using the RedemptionBatteryLib library. The library models a battery which recharges linearly block by block, over roughly 1 hour.
RToken.sol
RedemptionBatteryLib.sol
The linear redemption limit is calculated in the currentCharge function. This function calculates the delta blocks by uint48 blocks = uint48(block.number) - battery.lastBlock;.
The bug here is that the lastBlock value is never initialized by the RTokenP1 contract so its value defaults to 0. This results in incorrect delta blocks value as the delta blocks comes out to be an incorrectly large value
Due do this issue, the currentCharge value comes out to be way larger than the actual intended value for the first RToken redemption. The maxCharge cap at the end of currentCharge function caps the result to the current total supply of RToken.
The issue results in an instant first RToken redemption for the full totalSupply of the RToken. The battery discharging mechanism is completely neglected.
It should be noted that the issue only exists for the first ever redemption as during the first redemption the lastBlock value gets updated with current block number.
The following test case was added to test/RToken.test.ts file and was ran using command PROTO_IMPL=1 npx hardhat test ./test/RToken.test.ts.
Hardhat
The battery.lastBlock value must be initialized in the init function of RTokenP1
0xean (judge) decreased severity to Medium and commented:
tbrent (Reserve) confirmed and commented:
tbrent (Reserve) commented:
Status: Mitigation confirmed. Full details in reports from 0xA5DF, HollaDieWaldfee, and AkshaySrivastav.
