Users solvency validation are being erroneously executed since they are done on the basis of wrong tick data #26
Labels
3rd place
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
edited-by-warden
grade-b
primary issue
Highest quality submission among a set of duplicates
Q-03
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
🤖_primary
AI based primary recommendation
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-06-panoptic/blob/153f0d82440b7e63075d55b0659706531431145f/contracts/PanopticPool.sol#L852-L896
Vulnerability details
Proof of Concept
Take a look at https://github.com/code-423n4/2024-06-panoptic/blob/153f0d82440b7e63075d55b0659706531431145f/contracts/PanopticPool.sol#L852-L896
We can see that to get the ticks, the
PanopticMath.computeMedianObservedPrice()
is queried.However the
PanopticMath.computeMedianObservedPrice()
expects the cardinality to be odd to get the right data, see https://github.com/code-423n4/2024-06-panoptic/blob/153f0d82440b7e63075d55b0659706531431145f/contracts/libraries/PanopticMath.sol#L160-L193Evidently, this function expects the cardinality to be odd, which has also been clearly documented here https://github.com/code-423n4/2024-06-panoptic/blob/153f0d82440b7e63075d55b0659706531431145f/contracts/libraries/PanopticMath.sol#L157
/// @param cardinality The number of `periods` to in the median price array, should be odd
Where as this was ensured previously, the current scope does not do this, this is because as can be seen by the snippet below the
SLOW_ORACLE_CARDINALITY
has been changed from 7 in the previous scope, to8
in the current scope.This then makes the attempt to get the ticks via to return the wrong tick data since
Math.sort()
is being queried on false pretence, (assumption that it's odd whereas it's even).Note that from Math.sol's implementation of sort() & quicksort(), we can see how the cardinality is expected to be odd from which the
cardinality / 2
fromint24(Math.sort(ticks)[cardinality / 2])
incomputeMedianObservedPrice()
would return the right median price.Impact
Pricing integration are done in the wrong pretence which not only goes against the docs but also means that the wrong tick data is used to validate the solvency of a user via
validateSolvency()
duringSLOW_ORACLE_UNISWAP_MODE
, this is because the internal median being calculated via PanopticMath.computeMedianObservedPrice() is also going to be inaccurate, considering theMath.sort()
getting called expects an odd cardinality, but instead it's being given an even one.Recommended Mitigation Steps
If the intention is to increase the cardinality of the slow oracle mode, then consider increasing it to another
odd
value, say 9 rather than 8, i.e apply these fixes:Assessed type
Context
The text was updated successfully, but these errors were encountered: