I'm reading mastering ethereum and in section "Race Conditions/Front Running", quote:

As with most blockchains, Ethereum nodes pool transactions and form them into blocks. The transactions are only considered valid once a miner has solved a consensus mechanism (currently Ethash PoW for Ethereum). The miner who solves the block also chooses which transactions from the pool will be included in the block, typically ordered by the gasPrice of each transaction. Here is a potential attack vector. An attacker can watch the transaction pool for transactions that may contain solutions to problems, and modify or revoke the solver’s permissions or change state in a contract detrimentally to the solver. The attacker can then get the data from this transaction and create a transaction of their own with a higher gasPrice so their transaction is included in a block before the original.

I don't quite understand it. When the attacker see the transaction, it might already be broadcasted and included in the transaction pool.

If the attacker submit the same transaction with higher gasPrice again, what would happen to miners that already included the old transaction? Will they remove the old one and include the new one?

1 Answer 1


The attacker would see the transaction in the mempool and would issue another transaction with a higher gas price, which the first transaction is still not minted. The miners get to decide what goes in a block and would choose the transaction with the higher gas price (the one by the attacker). This is called frontrunning and is usually implemented by bots. These bots look for transactions as they are announced to the mempool and issue new ones with a higher gas price.

  • Thanks pbsh. Will the first transaction be mined later?
    – daisy
    Jan 20, 2022 at 12:10
  • That depends. If the first transaction can be executed after the attacker's transaction, then it will be. But let's say the transaction was to buy an NFT and if the attacker's high gas price transaction bought it before the original, then the first transaction will revert. You can learn more about front running and its types here.
    – pbsh
    Jan 20, 2022 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.