Skip to content

feat: support optional domain fields (nil verifying_contract)#2

Open
mdon wants to merge 1 commit into
stocks29:masterfrom
mdon:fix/optional-domain-fields
Open

feat: support optional domain fields (nil verifying_contract)#2
mdon wants to merge 1 commit into
stocks29:masterfrom
mdon:fix/optional-domain-fields

Conversation

@mdon

@mdon mdon commented Mar 23, 2026

Copy link
Copy Markdown

Problem

Passing nil for verifying_contract in the Domain struct crashes with FunctionClauseError in EIP712.Util.pad/2:

%EIP712.Typed{
  domain: %EIP712.Typed.Domain{
    chain_id: 137,
    name: "ClobAuthDomain",
    version: "1"
    # verifying_contract defaults to nil
  },
  ...
}
|> EIP712.Typed.encode()
# ** (FunctionClauseError) no function clause matching in EIP712.Util.pad/2

Per the EIP-712 spec, domain fields like verifyingContract and salt are optional — protocols should be able to omit them from the domain type hash entirely.

This is needed for protocols like Polymarket whose ClobAuth domain only has 3 fields (name, version, chainId) without verifyingContract.

Changes

  • domain_type/1 now accepts a Domain struct and only includes non-nil fields in the type definition (used for the type hash)
  • serialize_keys/1 filters out nil-valued fields instead of including them
  • domain_seperator/1 passes the domain struct to domain_type/1
  • domain_type/0 (no args) still returns all fields for backwards compatibility

Verification

  • All 75 existing doctests pass unchanged
  • Tested with Polymarket's ClobAuth domain (3-field, no verifyingContract) — domain separator matches the Python py-clob-client reference implementation

Per the EIP-712 spec, domain fields like `verifyingContract` and `salt`
are optional. Previously, passing `nil` for `verifying_contract` in the
Domain struct would crash with `FunctionClauseError` in `EIP712.Util.pad/2`
because `nil` is not a binary.

This change:
- Makes `domain_type/1` accept a Domain struct and only include non-nil
  fields in the type hash (matching the EIP-712 spec behavior)
- Updates `serialize_keys/1` to filter out nil-valued fields
- Updates `domain_seperator/1` to pass the domain to `domain_type/1`
- Keeps backwards compatibility: `domain_type/0` (no args) still returns
  all fields

This is needed for protocols like Polymarket whose ClobAuth domain only
has 3 fields (name, version, chainId) without verifyingContract.

All existing doctests pass unchanged.
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.

1 participant