Conversation
Contributor
There was a problem hiding this comment.
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.Eip7702plus authorization structs (Ethers.Authorization,Ethers.Authorization.Signed) and signing support via the signer behaviour. - Extends
Ethers.TransactionRPC mapping to includeauthorizationListand adds a publicEthers.sign_authorization/2API. - 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/1parsesr/sviahex_to_integer!/1and then:binary.encode_unsigned/1, which loses any leading zeros and can change the byte representation. It also crashes ifr/sare missing (becauseencode_unsigned(nil)raises). Using the existingfrom_map_value_bin/2keepsr/sas raw bytes (consistent with how transactionr/sare 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/1decodestoasnilwhen empty; after guarding against emptytothis can be simplified to always decode the address. This avoids propagating an impossibleniltofor 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://eips.ethereum.org/EIPS/eip-7702