orderId
Enables Order ImpersonationThe protocol generates orderId
s using a simple, sequential counter (_nextOrderId
). This makes the ID of the next order to be created completely predictable.
A malicious actor can exploit this predictability to conduct an "Order ID Preemption" or "Order Impersonation" attack. By front-running a legitimate seller's createSellOrder
transaction, an attacker can claim an anticipated orderId
for their own malicious order, tricking a buyer into executing a trade with the wrong party under unfavorable terms.
Likelihood:
The vulnerability stems from the _nextOrderId++
logic in the createSellOrder
function. Because the next ID is public knowledge, a sophisticated attacker can execute the following attack:
An attacker observes the mempool and sees two transactions submitted: one from a legitimate Seller
calling createSellOrder
, and another from a Buyer
calling buyOrder
with the predicted, upcoming orderId
. This scenario is most likely when the buyer and seller are coordinating off-chain or in bot-driven activity.
The attacker submits their own createSellOrder
transaction with a higher gas fee. They can set malicious terms for this order (e.g., a very high price or low amount).
The miner includes the attacker's transaction first. The attacker's order is created and assigned the predicted orderId
.
The legitimate Seller
's transaction is included next. It is now assigned the next orderId
.
The Buyer
's buyOrder
transaction is included last. It executes against the orderId
it specified, which now points to the attacker's malicious order, not the legitimate seller's order.
Impact:
This attack undermines the integrity of the entire order book, as buyers can no longer be certain who they are trading with.
The following scenario demonstrates an attacker (Bob) preempting an orderId
that a buyer (Dan) intended to fill from a legitimate seller (Alice).
Let the orderId
be non-sequential and unpredictable. The best practice is to derive the orderId
from a hash of order-specific details that are unique to the seller. This can be achieved by hashing the seller's address with a personal, incrementing nonce.
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.