You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The struct MethodologySettings has a field called recenteringSpeedwhich states that it is used as a value to go back to the targetLeverageRatio and it is used in _calculateNewLeverageRatio().
The issue stems from that the calculation doesn't make the _currentLeverageRatio go to the targetLeverageRatio,
just as a percentage of recenteringSpeed
Root Cause
The problem stems from the following:
Let's say we have a minLeverageRatio of 2, maxLeverageRatio of 3, targetLeverageRatio of 2.5, _currentLeverageRatio of 2.25 and recenteringSpeed being equal to a value corresponding to 15%.
(I will use floating numbers for simplicity, we all know Solidity works with whole numbers only)
a will be -> 2.5 * 1.15 = 2.875 b will be -> 0.85 * 2.25 = 1.9125 c will be -> a + b = 4.7875 d will take the minimum value between c and maxLeverageRatio, which will be later in our example -> 3
and the return statement will take the max value between minLeverageRatio and d which will be again the latter of -> 3
We started with a _currentLeverageRatio of 2.25 and right now we are at maxLeverageRatio of 3 after the calculation which is against the specified comment and is a lot more volatile than anticipated, given the 15% of recenteringSpeed.
Internal pre-conditions
No response
External pre-conditions
No response
Attack Path
Keeper bot sees that it can call rebalance() and calls it
Inside it, we execute _calculateNewLeverageRatio() to calculate the new leverage ratio
The calculation is a lot more volatile than expected and results in unexpected behaviour
Impact
The impact is an incorrect leverage calculation, resulting in a potentially lost funds
PoC
No response
Mitigation
Rewrite the _calculateNewLeverageRatio() with a logic changing the _currentLeverageRatio correctly given the recenteringSpeed, so it works as expected
The text was updated successfully, but these errors were encountered:
sherlock-admin2
changed the title
Polished Walnut Capybara - Calculation of leverage ratio is not as intended
onthehunt - Calculation of leverage ratio is not as intended
Oct 28, 2024
onthehunt
Medium
Calculation of leverage ratio is not as intended
Summary
The struct
MethodologySettings
has a field calledrecenteringSpeed
which states that it is used as a value to go back to thetargetLeverageRatio
and it is used in_calculateNewLeverageRatio()
.The issue stems from that the calculation doesn't make the
_currentLeverageRatio
go to thetargetLeverageRatio
,just as a percentage of
recenteringSpeed
Root Cause
The problem stems from the following:
Let's say we have a
minLeverageRatio
of 2,maxLeverageRatio
of 3,targetLeverageRatio
of 2.5,_currentLeverageRatio
of 2.25 andrecenteringSpeed
being equal to a value corresponding to15%
.(I will use floating numbers for simplicity, we all know Solidity works with whole numbers only)
a
will be -> 2.5 * 1.15 = 2.875b
will be -> 0.85 * 2.25 = 1.9125c
will be -> a + b = 4.7875d
will take the minimum value betweenc
andmaxLeverageRatio
, which will be later in our example -> 3and the return statement will take the max value between
minLeverageRatio
andd
which will be again the latter of -> 3We started with a
_currentLeverageRatio
of 2.25 and right now we are atmaxLeverageRatio
of 3 after the calculation which is against the specified comment and is a lot more volatile than anticipated, given the 15% ofrecenteringSpeed
.Internal pre-conditions
No response
External pre-conditions
No response
Attack Path
rebalance()
and calls it_calculateNewLeverageRatio()
to calculate the new leverage ratioImpact
The impact is an incorrect leverage calculation, resulting in a potentially lost funds
PoC
No response
Mitigation
Rewrite the
_calculateNewLeverageRatio()
with a logic changing the_currentLeverageRatio
correctly given therecenteringSpeed
, so it works as expectedThe text was updated successfully, but these errors were encountered: