The createOffer
function in the PreMarktes
contract is susceptible to a front-running attack due to the delayed increment of the offerId
. This vulnerability can allow an attacker to gain an unfair advantage in the marketplace by observing pending transactions and creating their own offer with a higher offerId
.
The createOffer
function performs the following sequence of operations:
It performs various checks and calculations.
It generates addresses for the maker, offer, and stock using the current offerId
.
It transfers tokens to the capital pool.
It updates the state variables makerInfoMap
, offerInfoMap
, and stockInfoMap
.
It increments the offerId
.
The vulnerability lies in the fact that offerId
is incremented only after generating addresses and transferring tokens. This creates a window of opportunity for an attacker to observe the pending transaction, extract the offerId
used, and quickly submit their own transaction with a slightly higher offerId
and a higher gas price.
the marketplace uses offerId
to determine priority or order in auctions or queues, an attacker could consistently outbid or jump ahead of other users.
Manual review
Move the offerId
increment to the beginning of the createOffer
function, before any other operations. This ensures that the offerId
used for address generation and subsequent actions is already the next available one, preventing front-running based on predictable IDs.
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.