The function fillOffchainOrders
has wrong check to ensure a maximum or minimum target price
The function fillOffchainOrders
is used by the keepers to execute orders without creating a market order on chain in order to save gas. This is done by users that sign a bunch of data to ensure the trade and then keepers will automatically execute it onchain. This data is the following:
From these data, the targetPrice
is used in order to ensure a minimum price when selling and a maximum price when buying. However, if we look into the code implementation, we can notice the following:
Reading the comments it makes sense because it tells that when the user is buying, the price MUST be less than or equal to the target price because it is the maximum price the user is willing to accept. For the counterpart, when the user is selling the price MUST be greater than or equal to the target price because is the minimum price which the user would accept to sell his position.
But looking into the code, the variable ctx.isFillPriceValid
gets true when:
Is a buy order AND the targetPrice is less than or equal to the fillPrice
Is a sell order AND the target price is greater than or equal to the fillPrice
As we can see the conditional is wrong for both situations, when it is a buy order the target price should be greater than or equal to the fill price because it is the maximum acceptable price by the user. And when it is a sell order the target price should be less than or equal to the fill price because is the minimum acceptable price set by the user.
High, the user will only get his order executed as he expected if the fill price matches exactly with the target price he set. However, if the price is within the acceptable threshold set by the user it will just not execute because of this:
And if the price is out of the acceptable threshold set by the user it will be executed and the user can lose funds that he did not expect.
Manual review
Correct the conditionals:
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.