Frontrunning Vulnerability in submitTransaction
The submitTransaction
function directly pushes a new transaction into the transactions
array, and its index (txId
) is deterministically assigned as transactions.length - 1
. This makes transaction IDs predictable, allowing an attacker monitoring the mempool to frontrun the submission and manipulate transaction approvals or execution in their favor.
For example, a malicious owner could submit a competing transaction with a slightly higher gas fee, ensuring their transaction is mined first. This could lead to unexpected approvals or block the intended transaction.
Transaction Manipulation: Malicious owners can front-run legitimate transactions, affecting execution order and approvals.
Denial of Service (DoS): Attackers can spam transactions, making it difficult to execute an intended transaction.
Potential Exploits: If a transaction involves time-sensitive operations (e.g., arbitrage, flash loans), an attacker could use frontrunning to gain an unfair advantage.
Owner1 submits a transaction:
The transaction's ID is deterministically set as transactions.length - 1
(e.g., txId = 5
).
Malicious Owner2 monitors the mempool and submits a transaction with slightly higher gas:
If Owner2’s transaction gets mined first, it will take txId = 5
, while Owner1’s original transaction is now txId = 6
, altering execution expectations.
Instead of using the array index as an identifier, assign transactions a unique hash based on sender, recipient, and value.
Introduce a mapping for transactions:
Modify submitTransaction
to generate a unique transaction ID:
Update approveTransaction
and executeTransaction
to use txId
:
Submit a hashed transaction request first:
Require the sender to later reveal the details in a second step.
Prevents mempool frontrunning since the full details are not visible.
The hash-based unique transaction ID approach is the simplest and most efficient solution to mitigate frontrunning while maintaining contract usability. If stronger protection is needed, a commit-reveal scheme can be implemented for added security.
Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelyhood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.
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.