#38137 [SC-Low] `RateLimits` library incorrectly reset the consumed amount when the limit is updated
Submitted on Dec 25th 2024 at 19:00:34 UTC by @OxAlix2 for Audit Comp | Lombard
Report ID: #38137
Report Type: Smart Contract
Report severity: Low
Target: https://github.com/lombard-finance/evm-smart-contracts/blob/main/contracts/libs/RateLimits.sol
Impacts:
Contract fails to deliver promised returns, but doesn't lose value
Description
Brief/Intro
RateLimits
allows the protocol to limit the amount of withdrawn LBTC for a certain period, something like only 10 LBTC could be withdrawn in 10 minutes. This is done by keeping track of the amount in flight, i.e. the amount used in this period/window. However, it incorrectly handles an edge case just after the limit is increased.
Vulnerability Details
To fetch the amount that could be used/withdrawn at a specific time availableAmountToSend
is used, which calculates the decay and compares it to the amount in flight (already used in this window):
All is good, until _amountInFlight
is less than decay
, this could happen if the limit is increased in some window, where _amountInFlight
is > 0. In that case, the amount in flight will be reset, and the window usage will reset.
Let's take the following example, at the end of window X we have _amountInFlight
as 9e8, and the window limit is 10e8. If the limit is increased to 20e8, the _amountInFlight
will be reset to 0, and users will be able to use/deposit 20e8 this window, knowing that they've already used/deposited 9e8; leaving the window with 29e8 limit.
This breaks the rate limit functionality.
Impact Details
Rate limit functionality will be bypassed/broken and users will be able to deposit a wrong exaggerated value of LBTC.
References
https://github.com/lombard-finance/evm-smart-contracts/blob/main/contracts/libs/RateLimits.sol#L91
Mitigation
Proof of Concept
Proof of Concept
Was this helpful?