Skip to content

Return EIP-55 checksummed addresses everywhere - #312

Merged
alisinabh merged 4 commits into
mainfrom
feat/checksummed-addresses
Nov 15, 2026
Merged

alisinabh merged 4 commits into
mainfrom
feat/checksummed-addresses

Conversation

@alisinabh

Copy link
Copy Markdown
Member

Every address the library returns is now EIP-55 checksummed. Some return values used to keep the node's casing (usually lowercase) or the casing they were configured with, so the same address could compare unequal depending on where it came from:

{:ok, contract_address} = Ethers.deployed_address(tx_hash)
[event] = Ethers.get_logs!(filter, address: contract_address)

contract_address == event.address
#=> true now (both checksummed); false before when the node returned lowercase

Inputs still accept any casing.

This PR also fixes two small things in the same area:

  • :deployed_address in Ethers.batch/2 was not mapped to an RPC method, so the node received an unknown deployed_address method and answered -32601 "Method not found". It now maps to eth_getTransactionReceipt, like the direct call.
  • Sending or signing with the transaction from in one casing and signer_opts[:from] in another raised ArgumentError ("different from address"), although both name the same account. The two are now compared as decoded bytes.

Breaking change

These return values are now EIP-55 checksummed strings. Before, they kept the node's casing or the configured casing:

  • address of Ethers.Event, everywhere it is produced: Ethers.get_logs/2, get_logs!/2, :get_logs in Ethers.batch/2, Ethers.Event.decode/2, Ethers.Event.find_and_decode/2 and Ethers.CombinedEventFilter.decode_logs/2
  • Ethers.deployed_address/2, and :deployed_address in Ethers.batch/2
  • accounts/1 of Ethers.Signer.JsonRPC (the result of eth_accounts)
  • The default_address of contract modules: __default_address__/0, and the default_address of the Ethers.TxData, Ethers.EventFilter and Ethers.CombinedEventFilter structs those modules build. This also changes the default to address returned by Ethers.Multicall.aggregate2_encode_data/1 and aggregate3_encode_data/1.

Code that compares these values against lowercase string literals breaks. guides/upgrading.md has a Before (0.8.x) / After (1.0.0) entry that shows how to compare safely, with Ethers.Utils.to_checksum_address/1 or Ethers.Utils.decode_address!/1.

Audit of returned addresses

"Node casing" means whatever the node sent, usually lowercase.

Return value Source Casing before Change
Ethers.Event address (Event.decode/2, find_and_decode/2) log["address"] from the node node casing checksummed; malformed values pass through unchanged
get_logs/2, get_logs!/2, batch :get_logs, CombinedEventFilter.decode_logs/2 built on Event.decode/2 node casing checksummed, through Event.decode/2
Event topics / data address values Utils.human_arg/2 already checksummed none. topics_raw / data_raw stay raw by design
Ethers.deployed_address/2 receipt contractAddress node casing checksummed; malformed values pass through
batch :deployed_address not mapped to an RPC method broken (-32601) fixed: mapped to eth_getTransactionReceipt, result checksummed
get_transaction/2, Transaction.from_rpc_map/1: to goes through new/1 validation already checksummed none
same: from dropped by the transaction structs not exposed none
same: access_list addresses 20-byte binaries n/a none
same: EIP-7702 authorization address to_checksum_address/1 checksummed, but nil raised and malformed values were mangled tolerant helper: a malformed value now returns the Ethers.Authorization validation error (:missing_address, :invalid_address_length or :invalid_address)
Transaction.Signed.from_address/1, Transaction.decode/1 (to, authorizations) key recovery / encode_address already checksummed none
Signer.Local.accounts/1 public_key_to_address/2 already checksummed none
Signer.JsonRPC.accounts/1 raw eth_accounts (anvil returns lowercase) node casing checksummed; malformed values pass through; RPC errors untouched
create_access_list/2 20-byte binaries n/a none
NameService.resolve/2, resolve!/2 ABI-decoded through human_arg/2 already checksummed docs only (the examples showed lowercase)
NameService.reverse_resolve/2 returns a name n/a none (its forward-resolution check was already case-insensitive)
Multicall decode functions human_arg/2 already checksummed none
Multicall.aggregate2_encode_data/1, aggregate3_encode_data/1 the to: input or default_address as configured the default address is now checksummed; an explicit to: passes through as given
Ethers.call/2 ABI-decoded / raw hex checksummed / raw none
Siwe.new/1 user input normalised to checksum none
Siwe.parse/1, verify/3 message text EIP-55 required kept: EIP-4361 requires the checksummed form, so a non-checksummed address is rejected with :invalid_address
Siwe.validate/2 none (already compares decoded bytes)
Signature.verify_* booleans n/a none
TypedData.recover_signer/2, to_eip712_json/1 key recovery / encode_address! checksummed none. Domain.verifying_contract is user input echoed back and is left alone
PersonalMessage.recover/2, recover!/2 key recovery checksummed none
Authorization.new/1, clear/1, Authorization.Signed.recover_authority/1 checksummed none
ForkConfig precompiles / system contracts to_checksum_address/1 checksummed, but malformed values raised or were mangled tolerant helper (malformed values pass through)
Utils.public_key_to_address/2 checksummed unless the flag opts out none (the explicit opt-out is kept)
Utils.encode_address/1, Utils.human_arg/2 checksummed none
Contract __default_address__/0, and default_address of the TxData / EventFilter / CombinedEventFilter structs a contract module builds the use Ethers.Contract, default_address: option as configured checksummed at compile time (well-formed values only)
default_address set by hand on a struct user input as given none
Inspect for TxData, EventFilter, CombinedEventFilter the stored default_address; topics through human_arg/2 as stored none (generated defaults now print checksummed)
Inspect for errors human_arg/2 checksummed none
Address fields of contract error structs raw ABI decode 20-byte binaries none
CCIP-Read {sender} placeholder not a return value lowercase, as EIP-3668 requires none
get_transaction_receipt/2 raw map raw none (raw passthrough by design)

Places where the library compares addresses internally:

  • The only case-sensitive comparison was between the transaction from and signer_opts[:from]. It is fixed in this PR and covered by a test.
  • Combining event filters already deduplicated default addresses case-insensitively. A mixed-case test now covers it.
  • The local signer's key check, PersonalMessage.verify/3, TypedData.valid_signature?/3, Siwe.validate/2, Signature and the NameService forward-resolution check already compared case-insensitively.

Design decisions

  • One helper, one rule for malformed node values. The new Ethers.Utils.maybe_checksum_address/1 (@doc false) calls the existing to_checksum_address/1. It checksums only a 0x/0X prefix followed by 40 hex characters, and returns anything else unchanged (nil, wrong length, non-hex).
    • It is applied to every address string decoded from the node: the event address, deployed_address, JSON-RPC signer accounts, EIP-7702 authorization addresses and fork configs.
    • Why pass-through: these sites returned the node's value before (or raised). Passing malformed values through means log scanning and batch requests gain no new failure modes. Where the library already validates (EIP-7702 new/1), the error now comes back as {:error, reason} instead of a FunctionClauseError.
  • default_address is normalised at compile time, in Ethers.Contract.__before_compile__. __default_address__/0 is a value the library returns. Without this, MyContract.__default_address__() == event.address would be false whenever the address is configured in lowercase.
    • Side effect: keccak now runs while a user's contract modules compile. The default ExKeccak works. A custom :keccak_module must be loadable when those modules compile.
  • Left alone on purpose:
    • User input echoed back: Domain.verifying_contract, a hand-built Siwe.Message, a hand-set default_address, the multicall to: option. Combining filters keeps the first default address as given.
    • Binaries: error struct fields and access lists.
    • Raw passthrough data: topics_raw, data_raw, receipt maps.
    • Casing required by a spec: Siwe parsing (EIP-4361) and the CCIP {sender} (EIP-3668).
    • Plain EIP-55 is used; there are no EIP-1191 chain-specific checksums.

Overlaps with open PRs

  • Add a decoded Ethers.Receipt struct for transaction receipts #310 (receipt struct):
    • Expect conflicts in CHANGELOG.md and guides/upgrading.md only. Both PRs add an entry to the batch RPC action map, and that merges cleanly.
    • With this PR, deployed_address/2 and Event.address are checksummed, matching the addresses of Ethers.Receipt.
    • Ethers.Receipt returns an error for a malformed address member, while this PR passes such values through. Both are reasonable: one is a schema decoder, the other covers passthrough sites.
  • Document EIP-7708 ETH transfer logs and add helpers to identify them #309 (Glamsterdam readiness):
    • Merges cleanly at the text level, but needs a follow-up once both are merged. Event.decode/2 now returns the emitter checksummed, so:
      • Ethers.Event.system_address/0 should return "0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE".
      • Its doctest should show that checksummed form.
      • The test "decode/2 decodes an ETH transfer log as an ERC-20 Transfer event", which asserts address: "0xfffffffffffffffffffffffffffffffffffffffe", must use the checksummed form.
    • eth_transfer_log?/1 compares case-insensitively, so it keeps working.
  • Return Ethers.Transaction.Unknown for unregistered transaction types #308 (unknown transaction types):
    • Expect a CHANGELOG conflict only.
    • Ethers.Transaction.Unknown already checksums from and to. It turns invalid values into nil, a different malformed-value rule; it could adopt maybe_checksum_address/1 later.
  • Add Ethers.get_code/2 and EIP-7702 delegation helpers #305 (get_code and delegation):

Out of scope, found during the audit

  • Ethers.NameService.resolve/2 returns a bare :error, not a tuple, when no resolver exists all the way up to the top-level domain. This contradicts its spec.
  • The generated typespecs of contract error structs declare Ethers.Types.t_address() for address fields, but the decoded values are 20-byte binaries.
  • Ethers.TypedData.recover_signer/2 returns a bare address instead of {:ok, address}.

Testing

  • Full suite against a local anvil 1.6.0-nightly: 637/638 (79 doctests, 558/559 tests). The one failure is the existing create_access_list/2 revert test, which needs a newer anvil than the local one.
  • Tests catch the change: run against the previous code with the new tests, 17 of the new or updated tests fail.
  • Static checks: mix format --check-formatted, mix credo --strict and mix dialyzer pass. mix docs adds no new warnings.

Not verified

  • CI on anvil 1.9.0: pending on this PR.
  • Commit 018ce7b was not run on its own; the full suite ran on the branch tip.

Closes #311

🤖 Generated with Claude Code

https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6

alisinabh and others added 4 commits November 15, 2026 16:47
The action was not mapped to an RPC method, so batch requests sent an
unknown `deployed_address` method to the node. Map it to
`eth_getTransactionReceipt` like the direct call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
Sending or signing with `from` in one casing and `signer_opts[:from]` in
another raised "different from address" although both name the same
account. Compare the decoded addresses instead of the strings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
Some return values passed the node's casing (usually lowercase) or the
configured casing through, so the same address compared unequal
depending on where it came from. Checksum them like the rest of the
library already does:

- `Ethers.Event` `address` (get_logs, batch get_logs, decode,
  find_and_decode, CombinedEventFilter.decode_logs)
- `Ethers.deployed_address/2` and its batch action
- `Ethers.Signer.JsonRPC.accounts/1`
- contract `default_address` (normalised at compile time)

Values from the node that are not a well-formed address are returned
unchanged instead of raising, so log scanning gains no new failure
modes. Inputs keep accepting any casing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
Fetched EIP-7702 authorization addresses and `eth_config` addresses were
passed straight to `to_checksum_address/1`, which raises on `nil` and
mangles other malformed values. Use the tolerant helper so a fetched
transaction with a malformed authorization address returns the
`Ethers.Authorization` validation error and fork configs keep the
node's value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
@alisinabh
alisinabh merged commit b5572ba into main Nov 15, 2026
5 checks passed
@alisinabh
alisinabh deleted the feat/checksummed-addresses branch November 15, 2026 23:12
alisinabh added a commit that referenced this pull request Nov 15, 2026
Since #312, `Ethers.Event.address` and `Ethers.deployed_address/2` are
checksummed, so the receipt tests compare them with the receipt's
addresses directly. The default address case uses a lowercase address to
keep covering case-insensitive matching in `decode_logs/2`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
alisinabh added a commit that referenced this pull request Nov 16, 2026
Decoded events carry an EIP-55 checksummed `address` since #312, so
system_address/0 returns the checksummed form too and compares equal to
the `address` of an ETH transfer log. eth_transfer_log?/1 still compares
case-insensitively.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
alisinabh added a commit that referenced this pull request Nov 16, 2026
* Return an Ethers.Receipt struct from get_transaction_receipt/2

`Ethers.get_transaction_receipt/2` returned the node's JSON untouched: a
string-keyed map with hex quantities. It now returns an `Ethers.Receipt`
struct decoded after the execution-apis `ReceiptInfo` schema:

- quantities (including `type`, the EIP-2718 type id, also for types
  the library has no module for) are integers
- `status` is `:success | :failure`, `nil` for pre-Byzantium receipts,
  which carry `root` instead
- addresses are checksummed, hashes stay `0x` hex strings, `logs_bloom`
  is a binary and `logs` are kept as returned by the node
- omitted members are `nil`, unknown members are ignored and the node's
  map is kept in `raw` for chain specific members (OP Stack L1 fees...)
- a member not matching the schema returns
  `{:error, {:invalid_receipt_member, member}}` instead of raising

The `:get_transaction_receipt` batch action now works and returns the
same struct: it was not mapped to `eth_getTransactionReceipt`, so the
node answered "Method not found".

This is a breaking change for 1.0.0.

Issue: #294

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6

* Add Ethers.Receipt.decode_logs/2

A receipt holds the logs of every contract the transaction called, so
its logs are kept as returned by the node. `decode_logs/2` decodes the
ones matching an event filter, a combined event filter or a contract's
EventFilters module into `%Ethers.Event{}` structs, in emission order.

A log matches like with `eth_getLogs` (topic_0, indexed argument values
with `nil` as a wildcard, the filter's default address compared case
insensitively) plus two checks receipts need: the topic count must equal
1 + the number of indexed arguments, so ERC-20 and ERC-721 `Transfer`
logs are not decoded as each other, and logs whose data does not ABI
decode as the event are skipped instead of raising. Logs matching none
of the events are skipped.

Also note in the typedoc that some nodes (anvil) return `blobGasPrice`
for non-blob transactions.

Issue: #294

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6

* Add changelog and upgrade guide entries for Ethers.Receipt

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6

* Replace Ethers.Receipt raw with extra

`raw` duplicated the whole node map, including every member the struct
already decodes. It is replaced by `extra`, which holds only the members
this version of the library does not decode (the receipt map minus every
member of the decoder table, present or not): chain specific members such
as the OP Stack L1 fee fields, and node extras such as anvil's
`blockTimestamp`. Keys and values stay as returned by the node, and it is
`%{}` when there are none. A member can move from `extra` to a struct
field in a later release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6

* Expect checksummed event and deployed addresses in receipt tests

Since #312, `Ethers.Event.address` and `Ethers.deployed_address/2` are
checksummed, so the receipt tests compare them with the receipt's
addresses directly. The default address case uses a lowercase address to
keep covering case-insensitive matching in `decode_logs/2`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
alisinabh added a commit that referenced this pull request Nov 16, 2026
…309)

* Add helpers to identify EIP-7708 ETH transfer logs

Under EIP-7708 (Glamsterdam) every non-zero ETH transfer emits a
Transfer(address,address,uint256) log from SYSTEM_ADDRESS
(0xff...fe), which ERC-20 Transfer filters decode as a token transfer.

Ethers.Event.system_address/0 returns that emitter and
Ethers.Event.eth_transfer_log?/1 tells such events apart (emitter and
Transfer topic, case-insensitive). get_logs/2 is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6

* Document that Transfer event filters match EIP-7708 ETH transfer logs

Without an address, a Transfer(address,address,uint256) filter (ERC-20,
ERC-777, or a combined filter including it) also returns native ETH
transfers on networks with EIP-7708 active. Warn about it on
Ethers.get_logs/2, Ethers.EventFilter, Ethers.CombinedEventFilter, the
README and in the generated docs of event filters with that signature.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6

* Return the checksummed system address from Ethers.Event.system_address/0

Decoded events carry an EIP-55 checksummed `address` since #312, so
system_address/0 returns the checksummed form too and compares equal to
the `address` of an ETH transfer log. eth_transfer_log?/1 still compares
case-insensitively.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

Return checksummed addresses everywhere

1 participant