if the orderbook of any market reach 65,000 dao can call the function cancelOrderFarFromOracle multiple times to cancel many orders up to 1000 order in each transaction ,or anyone can cancle the last order in one call.the users who issued the canclled orders will lost thier deposits.and the canclled process is not limited to a certain orders numbers.
source : contracts/facets/OrderFacet.sol
Function : cancelOrderFarFromOracle
when ever a user create a limit order (short limit,bid limit,ask limit), if the order did not match it get added to the orderbook, and the assets amount
or eth amount
uses to create this order is taken from the Virtual balance of the user in the system . userVault(in case of bids and shorts) or userAsset(in case of asks) we can see that here :
also if there is no id's Recycled behind the Head the id for this orders gonna be the current id in s.asset[asset].orderId
,and the s.asset[asset].orderId
get increamented by one . this is true for all three types of orders. (shorts,asks,bids).
now in case this ordersId reach 65k for a specific market, the DAO are able to cancle the last 1000 order, and any one can cancle last order in one call. since it's only checks for the ordersId > 65000.and by the last order i mean the last order of any time of limit orders (asks
,shorts
,bids
).
as we said the user balance get decreaced by the value
of it's order he created. but since the order is set to cancelled the user never gonna be able to recieve thier amount back.cause cancelled orders can't be matched Neither cancelled again.
Ex:
a user create a limit bid as follow : {price: 0.0001 ether
, amount: 10000 ether
}.
when this order get cancelled : the user will loose : 0.0001 * 10000 = 1 ether
ZETH (or ETH)
the shorters will lose more then others since thier balance get decreaced by : PRICE * AMOUNT * MARGIN.
The second issue is there is no limit for how many orders can be cancelled. you can cancel the whole orders in a market that reaches 65K orderId. limits shorts
,limits asks
or limit bids
.starting from the last one.since the only Conditionto be able to cancel orders is the asset order ID reached this number. and if it reachs it. it never decrease .even if there is alot of orders behind head(non active) to be reused.
a malicious actor Can targeted this vulnerability by creating numerous tiny limit asks
pushing the orderId
to be too high .and he can do so by creating ask
with a very high price and very small amount so he can pass the MinEth
amount check, he can just with less then 1 cusd
(in case of cusd market) create a bunsh of limit asks
orders .
using the the main repo setup for testing , here a poc shows how a malicious user can fill the orderbook with bunsh of tiny limit asks
with little cost. and how you can cancle all orders in case the orderId reachs 65k. also that there is no refund for the users that created this orders.
console after running test :
for creating bunsh of tiny asks :
users will lose thier zeth
or Erc
pagged asset dependens on the order type .
any type of orders in this market (shorts
,asks
,bids
) can be effected and cancelled even if there is a lot of non active ids to be reused.
the whole orders in a market can be canncelled without refunding the orders creators.
manual review
before cancling the orders , check that there is no orders to be reuse or the diffrence between the current orderId (s.asset[asset].orderId
) , and the orders to be reused (behind the Head) of this market are Greater then 65000.
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.