This EIP proposes to add a new opcode ASSERTTXINDEX (0xfb), that reverts if the index of the current transaction within the block does not match the expected value. This allows for transactions that can only be executed at a certain index within a block.
Motivation
The new opcode aims to improve support for encrypted mempools. Transactions in an encrypted mempool are ordered while the transactions are encrypted, before being decrypted and included onchain at the top of the block. If the builder does not respect the order when including the decrypted transactions then they could frontrun decrypted transactions. The new opcode can be used to make this impossible; if a decrypted transaction is not included at the correct index, it will revert.
Specification
A new opcode ASSERTTXINDEX is introduced at 0xfb. It takes as an argument the expected transaction index as an offset into calldata.
Input
The opcode takes a single input from the stack, an offset into calldata. From the provided byte offset, a 32 byte word (the expected transaction index) is retrieved from calldata, matching the semantics of CALLDATALOAD.
Behaviour
The ASSERTTXINDEX instruction will revert under the following conditions:
The current transaction index does not match the expected value loaded from calldata.
If gasUsed > 3 (to allow a PUSH* or similar instruction before to provide an argument).
There is not enough gas remaining or enough items on the stack.
Otherwise it will have no effect.
Gas Cost
The gas cost for ASSERTTXINDEX is a fixed fee of 3.
Rationale
Assertion
An alternative design could simply return the current transaction index. The assertion approach is favoured as it means that the expected transaction index can be determined statically, rather than allowing dynamic behaviour based on the returned transaction index. This prevents complex constraints being imposed that makes it difficult to build a block.
Furthermore the instruction must execute at the start of a transaction (with a PUSH* before to provide an argument) and read its input from calldata, so that one can statically evaluate what the expected transaction index is.
Gas Price
The opcode is priced to match CALLDATALOAD, in the W_verylow set.