Enforce EIP-712 domain separation
The EIP-712 domain is what binds a signature to one contract on one chain; an omitted field widens the set of places a signature is valid. This skill checks each domain field against the target and refuses signatures whose domain is incomplete.
Procedure
- Read the actual domain separator from the contract and compare it to the one you hashed:
cast call $CONTRACT "DOMAIN_SEPARATOR()(bytes32)" --rpc-url $RPC - Verify the five declared fields of the domain:
name— matches the contract'sname()(or the exact string it uses),version— e.g."1"; a version bump changes every signature,chainId— must be present and equal the live chain (cast chain-id --rpc-url $RPC),verifyingContract— must equal the address actually verifying,salt— required only whenverifyingContractis absent; not both, not neither.
- Recompute the domain hash locally and compare to step 1:
import { hashDomain } from 'viem'; const domain = { name: 'MyToken', version: '1', chainId: 1, verifyingContract: token }; console.log(hashDomain({ domain })); - For typed data, print the full message struct and confirm the wallet displays the same fields you signed. If the wallet shows a raw hash instead of the struct, do not sign.
- Reject any domain missing
chainIdorverifyingContract, or using a wildcard.
Pitfalls
- Two contracts deployed at the same address on two chains with identical domains accept each other's signatures; the
chainIdfield is the only separator. - An uninitialized
DOMAIN_SEPARATORcache can return a stale value after a chain fork; re-read it on the new chain. saltandverifyingContracttogether are redundant and some verifiers reject it; use exactly one.- A wallet that renders the struct but hashes a different domain is indistinguishable to the user — always compare the domain hash you computed to the contract's.
Verification
cast call $CONTRACT "DOMAIN_SEPARATOR()(bytes32)" --rpc-url $RPC
# expect it to equal the locally computed hashDomain() for the intended domain
Report the contract's domain separator, the locally computed hash, and whether they match, quoting the commands.