Shaggy Lava Mustang - Market may not increase total reserves during times of high volume/frequent transactions #44
Labels
Sponsor Confirmed
The sponsor acknowledged this issue is valid
Won't Fix
The sponsor confirmed this issue will not be fixed
Shaggy Lava Mustang
Medium
Market may not increase total reserves during times of high volume/frequent transactions
Summary
The issue arises from the fact that rate variables are set on a per-second basis, and the
accrualBlockTimestamp
variable is updated (i.e., the interest accrual window moves forward) even if no interest is added due to precision loss.Vulnerability Detail
In the
BaseJumpRateModelV2.sol
,multiplierPerTimestamp
is divided bytimestampsPerYear
to calculate the multiplier per second. Considering thatbaseRatePerYear
is likely to have the same or similar values as in the Compound v2 protocol, this timestamp-based calculation results in values approximately 15 times lower compared to the original "block-per-year" formula.These lower values, combined with the fact that the Sonic network produces at least 1 block per second, make the Machi protocol more prone to precision loss. This issue is particularly significant during high-frequency interactions with the protocol, as these trigger
CToken.accrueInterest
calculations each time.Particularly in
CToken.accrueInterest()
, the value to add to reserves is calculated as the interest accumulated multiplied by the reserve factor. The reserve factor is expected to have a value less than 1e18, as it represents the percentage of interest that must be allocated to reserves.This can lead to truncation and result in zero if the interest accumulated between subsequent calls to
accrueInterest
is too low, resulting in just a few wei.For example, the reserve factor for cWBTC in the Compound v2 protocol is 0.3 (link). This means that if the interest accumulated is less than 4 wei, the result will be zero due to truncation:
3 wei * 0.3 = 0.9 => 0
.PoC
Consider the cWBTC market with the following parameters:
1 SONIC = 1 USD
1 WBTC = 100,000 USD
totalCash: 100 WBTC (or 10,000,000 USD)
reserveFactor: 0.3
multiplierPerYear: 0.25e18
utilizationRate: 5%
Total borrows: 5 WBTC.
Insert this test into
CToken.t.sol
:Output when test is run with the
accrueInterest
called once per 10 seconds for 1 day:As can be seen, reserves were not increased and stayed at 0.
At the same time, a real
totalReserves
increase must be21404 * 0.3 = 6421
.Impact
Market (CToken) may not accrue total reserves.
Preconditions:
Code Snippet
https://github.com/sherlock-audit/2024-12-mach-finance/blob/main/contracts/src/BaseJumpRateModelV2.sol#L155
https://github.com/sherlock-audit/2024-12-mach-finance/blob/main/contracts/src/CToken.sol#L359-L360
Recommendation
Do not update
accrualBlockTimestamp
if calculations result in zero.The text was updated successfully, but these errors were encountered: