Skip to content

Implement set-code transactions (EIP-7702) #80

@mw2000

Description

@mw2000

Summary

Implement EIP-7702 set-code transactions (type 0x04), introduced in Prague. This allows EOAs to temporarily delegate their execution to contract code by setting a delegation indicator 0xef0100 ++ target_address as their code.

Specification

Transaction Type 0x04

New fields beyond EIP-1559:

  • authorization_list: list of (chain_id, address, nonce, y_parity, r, s) tuples
  • Each authorization allows setting the signer's code to a delegation designator

Delegation Designator

  • Code: 0xef0100 ++ 20-byte-address (23 bytes total)
  • When any CALL-family opcode targets an address with this designator, execution follows the pointer and runs the target contract's code in the EOA's context

Gas

  • PER_AUTH_BASE_COST = 2500 gas per authorization tuple in the list
  • Authorizations are processed before execution begins
  • Invalid authorizations are skipped (not failure)

Authorization Processing

For each (chain_id, address, nonce, y_parity, r, s):

  1. Recover signer from signature
  2. Verify chain_id matches (or is 0 for any chain)
  3. Verify nonce matches signer's current nonce
  4. Set signer's code to 0xef0100 ++ address
  5. Increment signer's nonce

CALL Dispatch Change

When CALL/CALLCODE/DELEGATECALL/STATICCALL targets an address whose code starts with 0xef0100:

  • Read the 20-byte target address from bytes 3–22
  • Load code from that target address
  • Execute in the context of the original (delegating) address

Implementation Guide

  1. Add EEVM.Transaction.SetCode struct for type 0x04 with authorization_list field
  2. Update EEVM.Transaction.Envelope to encode/decode type 0x04
  3. Update EEVM.Transaction.Signer for type 0x04 signing hash
  4. Add authorization processing — new module EEVM.Transaction.Authorization
  5. Update CALL dispatch in calls.ex — detect 0xef0100 prefix and follow delegation
  6. Update EXTCODESIZE/EXTCODECOPY/EXTCODEHASH for delegated accounts
  7. Tests: authorization processing, CALL delegation, gas costs, invalid auth skipping

Acceptance Criteria

  • Type 0x04 transaction struct, encoding, and signing
  • Authorization list processing with signature recovery
  • Code delegation designator set correctly
  • CALL-family opcodes follow delegation pointer
  • Invalid authorizations skipped without tx failure
  • Gas: 2500 per authorization tuple
  • EXTCODE* opcodes handle delegated accounts
  • Tests pass

Reference

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreCore EVM functionalityeipEIP specification implementationpraguePrague/Pectra hardfork features

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions