-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Battery discharge mechanism doesn't work correctly for first redemption #452
Comments
0xean marked the issue as unsatisfactory: |
0xean marked the issue as satisfactory |
The first redemption is not constrained by the battery properly from what I can tell in the code base. I don't see sufficient evidence that this would lead to a direct loss of user funds however. I will leave open for sponsor review, but think either M severity or below is appropriate without a better statement of impact from the warden. |
0xean changed the severity to 2 (Med Risk) |
tbrent marked the issue as sponsor confirmed |
This can't lead to loss of user funds, but I think it is indeed Medium severity |
Fixed here: reserve-protocol/protocol#584 |
Lines of code
https://github.com/reserve-protocol/protocol/blob/df7ecadc2bae74244ace5e8b39e94bc992903158/contracts/libraries/RedemptionBattery.sol#L59-L70
Vulnerability details
Impact
The
RTokenP1
contract implements a throttling mechanism using theRedemptionBatteryLib
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 byuint48 blocks = uint48(block.number) - battery.lastBlock;
.The bug here is that the
lastBlock
value is never initialized by theRTokenP1
contract so its value defaults to0
. This results in incorrect delta blocks value as the delta blocks comes out to be an incorrectly large valueDue do this issue, the
currentCharge
value comes out to be way larger than the actual intended value for the first RToken redemption. ThemaxCharge
cap at the end ofcurrentCharge
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.Proof of Concept
The following test case was added to
test/RToken.test.ts
file and was ran using commandPROTO_IMPL=1 npx hardhat test ./test/RToken.test.ts
.Tools Used
Hardhat
Recommended Mitigation Steps
The
battery.lastBlock
value must be initialized in theinit
function ofRTokenP1
The text was updated successfully, but these errors were encountered: