The function _updateOracleAndStartingShort
updates the startingShortId
, so matching algorithm knows where to start the matching iteration in Shorts Orderbook. A parameter of this method is shortHintArray
, which is a array of hints of where the startingShortId
should be. The docs say that a hint can have a price 1% higher than the actual startingShortId
and when this happens the logic should go back until it finds the real startingShortId
. However, the function doesn't search the real startingShortId
, but simply sets startingShortId
to be the first value which is in 1% price range.
In LibOrders.sol
, this is _updateOracleAndStartingShort
:
The important snippet is:
As you can see, if the shortHint is true in startingShortWithinOracleRange
, which is the 1% price range, the logic sets the startingShortId
of this stable coin as shortHint
and return, exiting the function. This is not what was intended.
Severity: Medium.
Probability: Medium.
Impact: Medium.
Finding the exact startingShortId
can be hard for a user. So, users will often input a shortHint
in 1% price range and the actual best prices can take longer than expected to match. This is has three problems:
When shorts and asks have the same price, ask is chosen. However, as startingShortId
may target a short with a higher price than it should, sometimes even if ask has the best market price, short can be matched instead of the ask.
Shorts with best price may take longer to get matched, which is unfair and can be seen as a denial of service for users with the best shorts.
Not what was expected in the docs: "If startingShortId is valid within that range but is not exact, the orderbook will match downwards until it hits the true startingShortId. Once it hits that, the system will match back upwards and will behave like a normal orderbook again. This is to allow the next order to set the new oracle price within some reasonable range of values when the oracle price needs to change (freshness)."
Manual Review
Implement the logic that was expected by the docs "the orderbook will match downwards until it hits the true ".
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.