The net issuance or net redemption may exceeds the per hour limit. #153
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
🤖_52_group
AI based duplicate group recommendation
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-07-reserve/blob/main/contracts/libraries/Throttle.sol#L69-L77
Vulnerability details
Impact
When calculating the current available amount of RToken in
ThrottleLib.currentlyAvailable
, the last available amount (i.e.throttle.lastAvailable
in L75) is also included, which may exceed the hourly limit in some cases.https://github.com/code-423n4/2024-07-reserve/blob/main/contracts/libraries/Throttle.sol#L69-L77
Proof of Concept
We assume that the max hourly limit of net issuance or net redemption for an RToken is
3600 units
. At any time, the value ofthrottle.lastAvailable
may range from 0 to 3600 units.T - 300 seconds
, some user issues some RTokens, and the resultedthrottle.lastAvailable
is200 units
.T + 3000 seconds
, some user issues3500 units
of RToken. The elapsed time since the last issuance is3300 seconds
. So currently available amount isthrottle.lastAvailable + (limit * delta) / ONE_HOUR = 200 + (3600 * 3300 / ONE_HOUR) = 3500 units
, and the newthrottle.lastAvailable
is0
after the issuance.T + 3600 seconds
, someone issues600 units
of RToken. The elapsed time since the last issuance is600 seconds
. So currently available amount isthrottle.lastAvailable + (limit * delta) / ONE_HOUR = 0 + (3600 * 600 / ONE_HOUR) = 600 units
, and the newthrottle.lastAvailable
is0
after the issuance.We can see that within the hour from
T
toT + 3600 seconds
, the total number of units issued is3500 + 600 = 4100 units
, which exceeds the maximum limit of3600 units
per hour.Tools Used
VS Code
Recommended Mitigation Steps
Record
lastUsed
instruct Throttle
, and subtract thelastUsed
when calculating the currently available amount.Assessed type
Math
The text was updated successfully, but these errors were encountered: