Skip to content

feat(BACK-12243): generate calldata descriptors for ERC-7730 v2 EIP-712 messages - #332

Open
fsamier wants to merge 9 commits into
mainfrom
feat/BACK-12243-eip712-calldata
Open

fsamier wants to merge 9 commits into
mainfrom
feat/BACK-12243-eip712-calldata

Conversation

@fsamier

@fsamier fsamier commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Generate calldata (generic parser) descriptors for ERC-7730 v2 EIP-712 messages, following the EIP-712 V2 spec.

Specs

What this does

  • Converts v2 EIP-712 descriptors into calldata descriptors: message info, struct/field schema, fields, enums and maps.
  • Addressing: message info, enums and map entries are addressed by DOMAIN_SEPARATOR + PRIMARY_TYPE_HASH (no more CONTRACT_ADDR/CHAIN_ID/SELECTOR).
  • Domain separator: computed per EIP-712 from the domain and deployment (checked against the spec's Ether Mail vector), or given by the descriptor. A given one has to be the one of the declared domain: the converter rejects the descriptor otherwise, and the lint rule ValidateEIP712DomainSeparatorLinter reports it. A domain declaring a chain id or verifying contract that conflicts with the deployment is rejected.
  • Paths: EIP-712 path encoding, including EIP712_LEAF_SLICE and the 17-element limit. ARRAY_DIM is encoded minimally.
  • Maps supported for EIP-712, with key encoding and validation. Visibility constraints are normalized to the leaf encoding.
  • Contract-less descriptors: network, chain_id and address are optional on EIP-712 calldata descriptors (still required for transactions, and for enums/maps using a selector). Chain and contract come from the domain (chainId, verifyingContract) when present.
  • TLV tag/length encoded as multi-byte DER to support payloads over 255 bytes.

Decisions / out of scope

  • PARAM_GROUP nesting is still flattened (as in v1).
  • @.value is rejected for EIP-712; GATING_DESCRIPTOR and PROXY_INFO are not handled.
  • domainSeparator or deployments is still required in the input model.

Tests

  • Unit tests for EIP-712 conversion, maps, contract-less descriptors and the new lint rule.
  • Integration test (--run-integration) converting every registry EIP-712 descriptor. 9 files that hit existing converter gaps (e.g. visibility conditions on non-raw formats from feat(v2): update spec and add support for visibility rules and constraints #335) are listed as expected failures in tests/files.py.

@fsamier
fsamier force-pushed the feat/BACK-12243-eip712-calldata branch from 044b7d8 to 086588d Compare August 20, 2026 12:39
@fsamier fsamier added the integration Also run integration tests in CI label Aug 20, 2026
@fsamier
fsamier force-pushed the feat/BACK-12243-eip712-calldata branch 2 times, most recently from 9e38dd7 to 182ed1f Compare August 20, 2026 15:24
@fsamier
fsamier force-pushed the feat/BACK-12243-eip712-calldata branch from 182ed1f to 3e0453d Compare September 11, 2026 10:48
@fsamier
fsamier force-pushed the feat/BACK-12243-eip712-calldata branch from 3e0453d to c9834e4 Compare November 12, 2026 11:07
@fsamier
fsamier marked this pull request as ready for review November 12, 2026 14:52
@fsamier
fsamier requested a review from a team as a code owner November 12, 2026 14:52
@fsamier
fsamier requested a max review from Copilot November 12, 2026 14:52

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.

🟡 Changes recommended

Unresolved EIP-712 defects can produce incorrect type hashes, emit incomplete domain schemas, and bind domain separators to values that conflict with explicit inputs.

13 open issues
What changed in this PR

Extends ERC-7730 v2 conversion to generate generic-parser clear-signing descriptors for EIP-712 messages alongside existing transaction calldata descriptors.

Changes:

  • Adds EIP-712 schema reconstruction, message paths, domain/type-hash binding, and optional deployment metadata.
  • Extends enum/map encoding and supports multi-byte DER tags and lengths.
  • Adds domain-separator linting, conversion tests, and registry integration coverage.
File Description
tests/​v2/​lint/​test_lint_validate_eip712_domain_separator.py Tests separator validation and deployment matching.
tests/​v2/​convert/​calldata/​test_convert_maps.py Keeps existing map tests focused on transaction descriptors.
tests/​v2/​convert/​calldata/​test_convert_eip712.py Tests message conversion, paths, schemas, and serialization.
tests/​files.py Updates registry fixtures and tracks expected conversion failures.
tests/​convert/​calldata/​test_convert_registry_files.py Adds EIP-712 registry conversion integration tests.
tests/​common/​test_binary.py Expands DER and fixed-width encoding tests.
src/​erc7730/​model/​calldata/​v1/​value.py Adds EIP-712 path elements and validation.
src/​erc7730/​model/​calldata/​v1/​instruction.py Adds message information and operation-specific enum/map bindings.
src/​erc7730/​model/​calldata/​v1/​eip712.py Defines EIP-712 schema, struct, and field models.
src/​erc7730/​model/​calldata/​v1/​descriptor.py Adds EIP-712 descriptors with optional deployment metadata.
src/​erc7730/​model/​calldata/​descriptor.py Discriminates transaction and message descriptors by type.
src/​erc7730/​model/​calldata/​__init__.py Generalizes the shared descriptor base.
src/​erc7730/​lint/​v2/​lint.py Registers domain-separator validation.
src/​erc7730/​lint/​v2/​lint_validate_map_keys.py Adapts map validation to path-converter callbacks.
src/​erc7730/​lint/​v2/​lint_validate_eip712_domain_separator.py Checks declared separators against computed domain hashes.
src/​erc7730/​convert/​calldata/​v1/​tlv.py Serializes EIP-712 schemas, paths, and operation bindings.
src/​erc7730/​convert/​calldata/​v1/​selector.py Updates transaction enum conversion calls.
src/​erc7730/​convert/​calldata/​v1/​path.py Introduces the shared path-converter interface.
src/​erc7730/​convert/​calldata/​v1/​map.py Adds EIP-712 map-key encoding and message bindings.
src/​erc7730/​convert/​calldata/​v1/​enum.py Supports enums bound to typed messages.
src/​erc7730/​convert/​calldata/​v1/​eip712_schema.py Reconstructs schemas and computes domain/type hashes.
src/​erc7730/​convert/​calldata/​v1/​eip712_path.py Converts message paths into EIP-712 binary paths.
src/​erc7730/​convert/​calldata/​convert_erc7730_v2_input_to_calldata.py Integrates message conversion and constraint normalization.
src/​erc7730/​common/​binary.py Extends DER encoding and adds binary encoding helpers.
src/​erc7730/​common/​abi.py Adds canonical encodeType serialization.

Review effort: Max

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.

🟡 Changes recommended

Unresolved conversion defects can emit invalid EIP-712 schemas, reject valid inputs, or discard converted formats, while existing registry tests can miss partial failures.

1 open issue
8 previously missed issues

In code that hasn't changed since last review

Medium severity Use the legal name for CREATOR_LEGAL_NAME

src/​erc7730/​convert/​calldata/​convert_erc7730_v2_input_to_calldata.py:1207

This copies the display name into CREATOR_LEGAL_NAME instead of using info.legalName, so generated message metadata contains the wrong legal name whenever the two differ. Use descriptor.metadata.info.legalName, leaving the optional tag unset when that field is absent.

Medium severity Report unrepresentable path bounds instead of raising

src/​erc7730/​convert/​calldata/​v1/​eip712_path.py:100

The source path model accepts index 32767, but translating values.[32767] on a dynamic array produces an exclusive end of 32768, which violates the new slice model's signed-16-bit limit. Its validation exception escapes this function and the outer converter discards all previously converted formats; the map-key linter can likewise abort. Check representability and report the unsupported path through out instead; apply the same check to explicit slice bounds.

Medium severity Report unsupported struct field indices

src/​erc7730/​convert/​calldata/​v1/​eip712_path.py:131

Selecting field index 256 of a 257-member struct raises here instead of reporting an unsupported path. The exception reaches the descriptor-wide handler and drops formats already converted; the map-key linter can also abort. Check the index against the device limit and report it through out before constructing the element.

Medium severity Reject statically empty fixed-size leaf slices

src/​erc7730/​convert/​calldata/​v1/​eip712_path.py:175

For a fixed bytes32 leaf, key.[32:40] (or key.[-1:0]) is statically empty, but _leaf_slice_width returns None, which is treated as an unknown width. Conversion therefore succeeds, and an EIP-712 map using this path even accepts nonempty keys although none can ever match. Reject statically empty fixed-size leaf slices before emitting the path.

Medium severity Reject invalid integer widths before schema conversion

src/​erc7730/​convert/​calldata/​v1/​eip712_schema.py:117

For Msg(uint9 value), dividing the width by eight produces a one-byte UINT schema while primary_type_hash still hashes uint9, so the emitted schema and addressing hash disagree. Conversion does not run the key linter that rejects invalid integer types. Reject aliases and noncanonical or out-of-range widths before converting them to bytes.

Medium severity Reuse matching EIP712Domain definitions

src/​erc7730/​convert/​calldata/​v1/​eip712_schema.py:223

When a message references EIP712Domain, such as Msg(EIP712Domain d)EIP712Domain(string name), these lines append that struct twice even if it matches the declared domain. The duplicate-struct validation then aborts conversion and discards other formats. Reuse a matching definition and report an error only when the domain definitions disagree.

Medium severity Reject schemas with undefined referenced structs

src/​erc7730/​convert/​calldata/​v1/​eip712_schema.py:230

Msg(uint256 value,Missing other) can emit a schema referencing an undefined Missing struct when only value is displayed. The device cannot resolve that schema, and conversion does not run the key linter that would reject it. Check that every referenced struct is defined before returning the schema.

Medium severity Fail tests when conversion returns partial results

tests/​convert/​calldata/​test_convert_registry_files.py:25

The converter returns partial results when a format or deployment fails, so assert descriptors can pass while some messages are omitted and conversion errors remain. Collect diagnostics with a ListOutputAdder and assert that it has no errors, so the existing expected-failure markers also detect partial failures.

13 resolved since last review

Review effort: Max

fsamier and others added 9 commits November 25, 2026 16:13
- bind EIP712_MESSAGE_INFO, ENUM_VALUE and MAP_ENTRY with DOMAIN_SEPARATOR and PRIMARY_TYPE_HASH
- compute the domain separator per deployment (or use the given one)
- struct/field versions set to 1, add EIP712_LEAF_SLICE and 17 elements path limit
- support map lookups and key encoding for EIP-712
- validate EIP-712 schema, normalize constraints, reject @.value
- fix map keys linter path converter
- add tests

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
An EIP-712 descriptor is addressed by its domain separator and primary type hash: the verifying contract is optional.

- chain id, address and network are optional for EIP-712 descriptors, message info, enums and map entries
- emit a descriptor when no deployment is declared, taking the chain and contract from the domain if it has them
- compute the domain separator from the domain fields only, and check the separator given by the descriptor
- add domain separator tests (salt, no verifying contract)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The converter uses a domainSeparator given by the descriptor as is, as the declared domain may be partial. A new linter recomputes the separator from the domain and deployments, and warns when none matches.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Restore the resolution registry test and mark the EIP-712 files the converter does not support yet as expected failures.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…rsion

- bind the domain chain id and verifying contract to the deployment once, reject conflicts, and carry them
  independently to maps, enums and token checks
- reject a given domain separator that is not the one of the declared domain
- keep descriptors on networks unknown to Ledger, and isolate schema errors to the failing format
- check fixed array indexes, keep the width of a sliced bytesN leaf, pad int constraints only when negative
- lint EIP-712 map keys, require 32 bytes hashes, accept $ in struct names

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- filter deployments by the requested chain before binding them to the domain
- report path bounds, struct field indices and statically empty leaf slices the device cannot represent
- reject non canonical integer and bytesN widths, undefined referenced structs and conflicting EIP712Domain
- use the legal name of the owner info when set
- fail the registry test on any conversion error, not only on empty output

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@fsamier
fsamier force-pushed the feat/BACK-12243-eip712-calldata branch from 9624601 to 8bba315 Compare November 25, 2026 15:22

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration Also run integration tests in CI sources

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants