Incorrect calculations for owed premia may potentially disrupt protocols that rely on SFPM. #295
Labels
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
duplicate-211
edited-by-warden
grade-a
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
sponsor disputed
Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
Lines of code
https://github.com/code-423n4/2023-11-panoptic/blob/f4b61b57bdd539f827f3ef7c335c5bde2d5c62a2/contracts/SemiFungiblePositionManager.sol#L1275-L1306
Vulnerability details
Impact
There are two types of liquidity: one remains in
Uniswap
, and the other is transferred fromUniswap
by users.SFPM
tracks owed fees for the liquidity moved fromUniswap
as if it were still inUniswap
.This is crucial because protocols utilizing
SFPM
can access these owed fees and request fees from users moving liquidity fromUniswap
.However, an inaccurate calculation of
owed premia
can disrupt the expectations of protocols relying onSFPM
for precise values.Some protocols may design their functionality based on these values, and if they are incorrect, it has the potential to disrupt the intended behavior of those protocols.
For instance, protocols may determine the
fees
received from theUniswap
pool by calculating the difference betweengross
andowed
amounts, updating their strategy accordingly.However, if this difference is inaccurate due to incorrect calculations, it can lead to the adoption of a flawed strategy.
The incorrect calculations occur consistently.
The process, in which removed liquidity fluctuates between values larger than
0
and0
, repeatsthroughout the
lifecycle
.Consequently, the calculated
owed
premia value becomes unreliable and should not be relied upon.Proof of Concept
There are specific equations used to calculate the
owed
premia.Based on the above information, we derive the final equation for
owed
premia perliquidity
as follows:I'd like to bring to your attention that the above equation is incorrect when
R
is0
.In this scenario,
owed_feesCollectedX128
would be0
according to Equation1
.However, when we divide this by
R
in subsequent steps, we end up with a non-zero value as theowed
growth perliquidity
.In reality, it's not feasible to calculate
0 / 0
, and this aspect needs to be addressed in the equation.As a consequence, the obtained amount is incorrect in this scenario.
It's essential to account for scenarios where the removed liquidity is
0
.The PoC for this is as below:
Tools Used
Manual
Recommended Mitigation Steps
Please modify
_getPremiaDeltas
function as below:Assessed type
Math
The text was updated successfully, but these errors were encountered: