Alert Source Discuss
⚠️ Draft Standards Track: Core

EIP-7793: ASSERTTXINDEX opcode

Opcode that only executes at a specific index within a block

Authors Marc Harvey-Hill (@Marchhill), Ahmad Bitar (@smartprogrammer93)
Created 2024-10-17
Discussion Link https://ethereum-magicians.org/t/eip-7793-asserttxindex-opcode/21513

Abstract

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.

Backwards Compatibility

No backward compatibility issues found.

Test Cases

N/A

Security Considerations

None.

Copyright and related rights waived via CC0.

Citation

Please cite this document as:

Marc Harvey-Hill (@Marchhill), Ahmad Bitar (@smartprogrammer93), "EIP-7793: ASSERTTXINDEX opcode [DRAFT]," Ethereum Improvement Proposals, no. 7793, October 2024. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7793.