Closed sherlock-admin closed 1 year ago
Valid finding, but it's only in view function that doesn't effect protocol. Function is only used in PerennialLens
and _accumulateFunding
, but _accumulateFunding
will not use that function if the taker/maker position is 0 (see first line of _accumulateFunding
).
Considering as a valid low.
BLACK-PANDA-REACH
medium
Wrong rate when maker and taker are 0
Summary
When
maker
andtaker
positions are zero, therate
function should returnminRate
but instead is returningmaxRate
.Vulnerability Detail
In
Product
contract, there's a functionrate
that returns the funding rate based on the provided position:The Natspec documentation is explicitly stating that edge cases are handled by this function but as we'll see now, that's not true.
When
position_.taker
andposition_.maker
are both zero, utilization will be1e18
(ONE
) as a result ofunsafeDiv
:Utilization being
1e18
will lead toannualizedRate
beingmaxRate
instead ofminRate
. This is calculated inutilizationCurve().compute(utilization)
:As it can be seen, if
utilization
is1e18
, the return value will always bemaxRate
, thus giving a wrong rate.Impact
This issue can cause confusion or unexpected behaviour on external contracts calling and interacting with this
rate
function and can cause exploits with protocols integrated with Perennial.Code Snippet
https://github.com/sherlock-audit/2023-05-perennial/blob/main/perennial-mono/packages/perennial/contracts/product/Product.sol#L484-L494
Tool used
Manual Review
Recommendation
It's recommended to handle this edge case in the
rate
function by assigning0
toutilization
whenposition_.taker
andposition_.maker
are both zero.