Skip to main content
Scenario: Your app lets users approve USDC spending without paying gas. The user signs an off-chain “Permit” approval, sends the signature to your relayer over HTTP, and your relayer submits permit(...) on-chain.

Spot the Replay Bug

Suppose you ask the user to sign a plain string with EIP-191 (personal_sign):
What goes wrong?
  1. Cross-chain replay: An attacker takes the exact same signature and replays it on Arbitrum, Optimism, and Base where the user also holds USDC.
  2. Cross-contract replay: If two tokens share the same message format, a signature meant for a testnet token works on mainnet.
  3. Opaque wallet UX: Wallets show raw hex or unstructured text, so users cannot verify what they are signing.

How EIP-712 Fixes All Three

EIP-712 binds every signature to a domain separator (name, version, chainId, verifyingContract) and a typed struct hash, joined under the \x19\x01 prefix: Why 0x19 0x01? EIP-191 reserves 0x19 as a leading byte that can never be valid RLP (an RLP transaction list starts at 0xc0–0xff, and typed EIP-2718 envelopes use 0x01–0x04). That guarantees an EIP-712 digest can never collide with a valid Ethereum transaction!
Always check signature normalization (low-s, EIP-2). Because secp256k1 is symmetric across the x-axis, (r, s, v) and (r, n - s, v ^ 1) recover the same key unless the verifier rejects high-s values. Voltaire’s Secp256k1.sign always produces canonical low-s signatures.

Step-by-Step: Sign, Transmit, and Verify a Permit

1

Define the EIP-712 typed data payload

2

Compute the digest and sign on the client

3

Verify on the relayer before paying gas

Your relayer must verify the signature offline before submitting it on-chain so attackers cannot drain your relayer’s ETH with invalid permits:
4

Prove cross-chain replay fails

Flip chainId from 1n (Ethereum) to 42161n (Arbitrum) and try verifying the exact same signature:
Voltaire follows a consistent data-first convention: the object being inspected (signature) comes first, followed by the context it operates against (digest). When in doubt, TypeScript’s branded types (SignatureType vs HashType) catch reversed arguments at compile time.

What You Built

  • Bound an ERC-20 Permit signature to chainId and verifyingContract via EIP-712.
  • Signed and recovered the signer offline using EIP712 and Secp256k1.
  • Proved that replaying the signature on another chain fails verification immediately.
Next tutorial: Tutorial 4: Anatomy of an EIP-1559 Transaction