Skip to content

Add EIP-7702 (type 4) transaction support - #269

Merged
alisinabh merged 2 commits into
mainfrom
eip-7702
Jul 29, 2026
Merged

Add EIP-7702 (type 4) transaction support#269
alisinabh merged 2 commits into
mainfrom
eip-7702

Conversation

@alisinabh

Copy link
Copy Markdown
Member

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for Ethereum EIP-7702 “set-code” (type 4) transactions to the Ethers Elixir library, including authorization hashing/signing, JSON-RPC (de)serialization, and end-to-end test coverage.

Changes:

  • Introduces Ethers.Transaction.Eip7702 plus authorization structs (Ethers.Authorization, Ethers.Authorization.Signed) and signing support via the signer behaviour.
  • Extends Ethers.Transaction RPC mapping to include authorizationList and adds a public Ethers.sign_authorization/2 API.
  • Adds comprehensive tests for decoding/encoding type-4 transactions and for signing/recovering authorizations.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/ethers/transaction_test.exs Adds EIP-7702 transaction decode/encode and RPC map round-trip tests.
test/ethers/signer/local_test.exs Adds deterministic fixtures for Signer.Local.sign_authorization/2.
test/ethers/authorization_test.exs New unit tests for authorization creation, hashing, RLP, and authority recovery.
test/ethers_test.exs Adds integration tests for Ethers.sign_authorization/2 and an EIP-7702 delegation lifecycle.
lib/ethers/transaction/eip7702.ex New transaction type module implementing EIP-7702 fields and RLP encoding/decoding.
lib/ethers/transaction.ex Adds authorization_list <-> authorizationList mapping and encoding/decoding helpers.
lib/ethers/signer/local.ex Implements sign_authorization/2 for the local signer (when secp256k1 is available).
lib/ethers/signer/json_rpc.ex Explicitly returns {:error, :not_supported} for authorization signing.
lib/ethers/signer.ex Extends signer behaviour docs/callbacks to include sign_authorization/2.
lib/ethers/authorization/signed.ex New signed-authorization struct with RLP conversion and authority recovery.
lib/ethers/authorization.ex New authorization struct with validation and EIP-7702 hash computation.
lib/ethers.ex Adds public sign_authorization/2 and sign_authorization!/2 helpers.
CHANGELOG.md Notes the new EIP-7702 support in Unreleased enhancements.
Comments suppressed due to low confidence (2)

lib/ethers/transaction.ex:456

  • from_rpc_authorization_list/1 parses r/s via hex_to_integer!/1 and then :binary.encode_unsigned/1, which loses any leading zeros and can change the byte representation. It also crashes if r/s are missing (because encode_unsigned(nil) raises). Using the existing from_map_value_bin/2 keeps r/s as raw bytes (consistent with how transaction r/s are decoded at lines 282–283) and avoids the nil crash.
  defp from_rpc_authorization_list(authorization_list) when is_list(authorization_list) do
    Enum.map(authorization_list, fn authorization ->
      %Authorization.Signed{
        authorization: %Authorization{
          chain_id: from_map_value_int(authorization, :chainId),
          address: authorization |> from_map_value(:address) |> Utils.to_checksum_address(),
          nonce: from_map_value_int(authorization, :nonce)
        },
        signature_y_parity: from_map_value_int(authorization, :yParity),
        signature_r: authorization |> from_map_value_int(:r) |> :binary.encode_unsigned(),
        signature_s: authorization |> from_map_value_int(:s) |> :binary.encode_unsigned()
      }

lib/ethers/transaction/eip7702.ex:127

  • from_rlp_list/1 decodes to as nil when empty; after guarding against empty to this can be simplified to always decode the address. This avoids propagating an impossible nil to for type-4 transactions.
         max_fee_per_gas: :binary.decode_unsigned(max_fee_per_gas),
         gas: :binary.decode_unsigned(gas),
         to: (to != "" && Utils.encode_address!(to)) || nil,
         value: :binary.decode_unsigned(value),

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/ethers/transaction/eip7702.ex
Comment thread lib/ethers/transaction.ex
Comment thread test/ethers/transaction_test.exs Outdated
@alisinabh
alisinabh merged commit f0d7a96 into main Jul 29, 2026
5 checks passed
@alisinabh
alisinabh deleted the eip-7702 branch July 29, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants