# ERC-1271 Smart Wallet Signatures & Safe Replay Defense

> Audit ERC-1271 isValidSignature(bytes32,bytes) magic value 0x1626ba7e checks, Safe multi-chain CREATE2 replay traps, and EIP-6492 counterfactual validation.

Canonical: https://nftvenueledger.com/protocols/erc-1271-smart-contract-wallet-signature-replay-across-safes
Last updated: 2026-11-14T19:55:15.589Z

**Publication:** NFTVenue Ledger
**Category:** Erc721 Erc1155 Eip712 Permit Security
**Published:** 2026-11-13T21:30:25.915Z
**Author:** Dr. Devon Kurosawa, PhD (PhD in Distributed Systems & Cryptographic Protocol Verification)
**Reviewer:** Not recorded

## Answer-first summary

When a user owns multiple Safe or ERC-4337 smart accounts controlled by the same EOA signer set, naive ERC-1271 implementations permit catastrophic cross-account and cross-chain replay.

## Key takeaways

- Smart-contract wallets MUST wrap incoming ERC-1271 hashes inside their own (chainId, address(this)) EIP-712 domain before checking owner keys—otherwise protocols like Permit2 PermitSingle allow cross-vault replay.
- Protocol verifiers must invoke isValidSignature via STATICCALL and verify both returndatasize >= 32 and exact equality to 0x1626ba7e.
- EIP-7739 preserves human-readable typed struct display on hardware wallets while enforcing replay-proof smart-account domain binding.
- EIP-6492 enables gasless off-chain order signing for undeployed counterfactual ERC-4337 smart accounts via a standardized CREATE2 factory suffix.

## Related financial entities

- **CoW Protocol Batch Auction Settlement Engine** (COW-SETTLE) — product: Decentralized trading protocol utilizing off-chain batch auctions to find Coincidence of Wants (CoW) and protect users from MEV sandwich attacks.
- **EIP-712 Typed Structured Data Standard** (EIP-712) — product: Standard for hashing and signing of typed structured data as opposed to just arbitrary byte strings, providing human-readable authorization.
- **Seaport Marketplace Protocol Standard** (SEAPORT) — product: Open-source, highly optimized marketplace contract suite for efficiently buying and selling fungible and non-fungible tokens.

## Analysis

Externally Owned Accounts (`EOAs`) hold private keys, whereas smart-contract wallets (`Safe`, `Coinbase Smart Wallet`, `Kernel`, `Argent`) hold zero private keys and therefore cannot produce raw secp256k1 `ecrecover` signatures directly. **ERC-1271** bridges off-chain order books—such as the [Seaport marketplace protocol](/tokens/seaport-marketplace-protocol) and [CoW Protocol batch auctions](/tokens/cow-protocol-batch-auction)—to smart accounts via a single view interface: `isValidSignature(bytes32 hash, bytes calldata signature) external view returns (bytes4 magicValue)`, returning `0x1626ba7e` on success.

Anchored in our [EIP-712, Permit2 & proxy security master guide](/protocols/eip712-permit2-erc721-royalty-proxy-timelock-security-2026), dozens of custom smart accounts and modular validators introduced critical **Cross-Account** and **Cross-Chain ERC-1271 Replay Vulnerabilities** by validating raw `hash` against `owner` without re-wrapping the digest inside the wallet's own [EIP-712](/tokens/eip-712-typed-signature-standard) domain!

## Anatomy of the Cross-Account ERC-1271 Replay Vulnerability!

Watch how a seemingly innocent 5-line `isValidSignature(bytes32 appDigest, bytes sig)` implementation drains institutional treasuries:
- Suppose Treasury Manager Alice (`0xAlice`) is the 1-of-1 (or 2-of-2) signer on **two separate smart-contract wallets**: `Vault_A` (a testing wallet holding `500 USDC`) and `Vault_B` (the main treasury holding `10,000,000 USDC`).
- Suppose a naive smart wallet implements: `if (ECDSA.recover(appDigest, sig) == owner) return 0x1626ba7e;`!
- Now suppose a protocol (`like Permit2 or a DEX Router`) constructs `appDigest` **without** hashing the wallet's address inside the inner struct—or suppose `Vault_A` and `Vault_B` are deployed via `CREATE2` at the **exact same address** on Polygon and Ethereum Mainnet while an omnichain app omits `chainId`!
- Inspect `Permit2`'s `PermitSingle` EIP-712 struct definition: `PermitSingle(PermitDetails details,address spender,uint256 sigDeadline)`—**`owner` is NOT inside `PermitSingle`'s EIP-712 hashed struct** (`owner is passed separately in calldata to permit(address owner, PermitSingle, bytes sig)!`)!
- Read that again! Because `PermitSingle` does **NOT** include `owner` in `hashStruct`, `appDigest` for `Vault_A` and `Vault_B` on the same chain is **100% byte-for-byte IDENTICAL**! If `Vault_A` and `Vault_B` merely check `ECDSA.recover(appDigest, sig) == 0xAlice`, Alice's signature authorizing `500 USDC` on `Vault_A` replays verbatim against `Vault_B` to drain `$10M`!

![Defensive Nested EIP-712 PersonalSign wrapper inside Safe and Coinbase Smart Wallet ERC-1271 validation](/api/figure?type=flow&title=Safe%20%2F%20ERC-1271%20Defensive%20Nested%20Digest%20Wrapping&subtitle=Binding%20every%20external%20dApp%20hash%20to%20the%20specific%20smart-wallet%20address%20and%20chainId%20before%20ECDSA%20check&steps=1.%20dApp%20Digest%20%28h%29%3A%3APermit2%20%2F%20Seaport%20passes%2032-byte%20appDigest%20%28may%20omit%20wallet%20addr!%29%7C2.%20Wallet%20Re-Wrap%3A%3AWallet%20hashes%20SafeMessage%28h%29%20with%20its%20OWN%20%28chainId%2C%20address%28this%29%29%7C3.%20M-of-N%20Verify%3A%3AVerify%20owner%20threshold%20signatures%20or%20Passkey%20WebAuthn%20over%20wrappedHash%7C4.%20Magic%20Return%3A%3AReturn%200x1626ba7e%20via%20STATICCALL%20%280xffffffff%20on%20any%20mismatch%29&metrics=MAGIC%20VALUE%3A%3A0x1626ba7e%3A%3Abytes4%28keccak256%28%22isValidSignature...%22%29%29%7CCALL%20OPCODE%3A%3ASTATICCALL%3A%3AEnforces%20read-only%20state%20invariance%7CPRE-DEPLOY%20SPEC%3A%3AEIP-6492%3A%3AValidates%20undeployed%20counterfactual%20wallets%7CREPLAY%20IMMUNITY%3A%3A100%25%20Isolated%3A%3ABlocks%20PermitSingle%20cross-vault%20replay)

## Safe `CompatibilityFallbackHandler`, EIP-6492 & EIP-7739 Defensive Rehashing

Safe's audited `CompatibilityFallbackHandler` and **EIP-7739 (`Readable Typed Signatures for Smart Accounts`)** defeat cross-vault replay by wrapping incoming `appDigest` inside `encodeMessageDataForSafe(safeAddress, chainId, appDigest)`. Meanwhile, **EIP-6492** solves a major onboarding friction across marketplaces in our [marketplaces directory](/marketplaces) (like [Basepaint](/marketplaces/basepaint), [Azuki](/marketplaces/azuki), and [Beethoven X](/marketplaces/beethoven-x)): validating signatures from **counterfactual ERC-4337 wallets before their first on-chain deployment transaction** by appending a magic suffix `0x64926492...` containing `(create2Factory, factoryCalldata, innerSig)`!

## Smart-Account Signature Standard Security Matrix

| Signature Standard / Extension | Primary Capability | Critical Replay / Griefing Trap | Audited Defense Requirement |
| :--- | :--- | :--- | :--- |
| Base **ERC-1271** (`0x1626ba7e`) | Deployed contract signature check | Cross-Safe replay when dApp omits `owner` in struct | Wallet **must** wrap `hash` in wallet's own EIP-712 domain! |
| **EIP-7739** Typed Rehashing | Preserves hardware-wallet readability | Naive nested hashing blinds user to inner dApp fields | Merges dApp typed struct + Smart Account domain cleanly |
| **EIP-6492** Counterfactual Verify | Gasless login/orders pre-deployment | Side-effect execution in universal validator deploy | Run inside ephemeral reverted eth_call or off-chain verifier |
| Safe **`SignMessageLib`** On-Chain | `signedMessages[msgHash] = 1` | Reverts if `STATICCALL` gas cap set too low (`<20k`) | Callers must forward sufficient gas (never hardcode `5,000g`) |

![EVM gas consumption of ERC-1271 signature verification across 1-of-1 ECDSA, 3-of-5 Safe, and P-256 Passkey](/api/figure?type=bars&title=On-Chain%20ERC-1271%20Verification%20Gas%20Profiles&subtitle=STATICCALL%20gas%20required%20by%20DEX%20routers%20and%20Seaport%20when%20verifying%20smart-account%20orders&steps=Safe%20On-Chain%20Pre-Sign%3A%3A~6%2C800%20gas%20%281%20warm%2Fcold%20SLOAD%20on%20signedMessages%5Bhash%5D%29%7C1-of-1%20Nested%20ECDSA%3A%3A~8%2C400%20gas%20%28domain%20re-wrap%20%2B%201%20ecrecover%20precompile%29%7C4-of-7%20Safe%20Multisig%3A%3A~21%2C900%20gas%20%284%20sorted%20owner%20ecrecover%20checks%20%2B%20threshold%20SLOAD%29%7CRIP-7212%20WebAuthn%20Passkey%3A%3A~9%2C200%20gas%20on%20L2s%20with%20RIP-7212%20%28vs%20~310k%20gas%20in%20Solidity!%29&metrics=RETURN%20LENGTH%3A%3A%3E%3D%2032%20Bytes%3A%3AABI-padded%200x1626ba7e0000...0000%7CSTATICCALL%20MANDATE%3A%3ARead-Only%3A%3ABlocks%20state-mutating%20malicious%20wallets%7CPASSKEY%20PRECOMPILE%3A%3A0x0100%20%28RIP-7212%29%3A%3Asecp256r1%20%2F%20P-256%20native%20L2%20verify%7CLEGACY%20BUG%3A%3A0xffffffff%20Trap%3A%3ACheck%20exact%20%3D%3D%200x1626ba7e%2C%20never%20!%3D%200!)

## Nested Domain-Bound ERC-1271 Digest Construction Math

Both wallet developers and protocol callers must verify exact ABI return length (`returndata.length == 32`) and exact 4-byte selector equality:

```formula
Defensive Smart-Account Wrapped Digest (Blocks Cross-Vault & Cross-Chain Replay):
 Given external dApp EIP-712 digest h_app (e.g., Permit2 PermitSingle where owner is unhashed):
 Wallet_Domain = keccak256(abi.encode(DOMAIN_TYPEHASH, block.chainid, address(this)))
 Wrapped_Hash = keccak256(concat(0x1901, Wallet_Domain, keccak256(abi.encode(SAFE_MSG_TYPEHASH, h_app))))

 Caller-Side Safe Verification Invariant (Solidity Assembly):
 bool ok = staticcall(gas, signerContract, abi.encodeWithSelector(0x1626ba7e, h_app, sig))
 valid = ok && (returndatasize >= 32) && (mload(returndata) == 0x1626ba7e00000000000000000000000000000000000000000000000000000000)

Worked Permit2 Replay Prevention Test:
 User controls Vault_1 (0x11..11) & Vault_2 (0x22..22) on Ethereum (chainId = 1) with same Passkey K:
 h_app(PermitSingle 100k USDC) = 0x77aa...99 (IDENTICAL for both vaults!)
 Wrapped_Hash(Vault_1) = 0x3c18...f2 != Wrapped_Hash(Vault_2) = 0x9e40...b1 -> Cross-vault replay reverts 100%!
```

## Interfacing ERC-1271 With ERC-4337 Bundlers & EIP-712 Callers

Protocol routers calling `SignatureChecker.isValidSignatureNow` automatically branch on `signer.code.length > 0` (barring an edge case introduced by EIP-7702!). Explore account-abstraction execution next in [ERC-4337 EntryPoint & Paymaster validation griefing](/protocols/erc-4337-entrypoint-paymaster-userop-validation-griefing) and [EIP-7702 EOA code delegation security](/protocols/eip-7702-eoa-code-delegation-sweeper-phishing-mitigation) inside our [EIP-712, Permit2 & Proxy Security hub](/topics/erc721-erc1155-eip712-permit-security).

## Frequently asked questions

### How can an ERC-1271 signature for Vault A replay on Vault B if EIP-712 already hashes verifyingContract?

verifyingContract in the dApp digest is the dApp contract (e.g., Permit2), NOT the user smart wallet! When dApps like Permit2 PermitSingle omit the user wallet address from the signed struct, two wallets sharing an EOA owner produce identical dApp digests unless the wallet re-wraps the hash.

### Why must callers use STATICCALL when invoking ERC-1271 isValidSignature?

If a marketplace or router used regular CALL instead of STATICCALL, a malicious smart-contract wallet could mutate external state or reenter the marketplace mid-settlement during signature verification.

### What is the exact magic value returned by a valid ERC-1271 signature check?

isValidSignature(bytes32,bytes) must return 0x1626ba7e (padded to 32 bytes in ABI encoding), which equals the 4-byte function selector of isValidSignature(bytes32,bytes) itself.

### How does EIP-6492 verify signatures before a smart wallet is deployed on-chain?

EIP-6492 wraps the signature with the wallet CREATE2 factory address, deployment calldata, and magic suffix 0x6492... so verifiers can simulate counterfactual deployment inside eth_call and run ERC-1271.


## Source URLs

- https://eips.ethereum.org/EIPS/eip-1271
- https://eips.ethereum.org/EIPS/eip-6492
- https://eips.ethereum.org/EIPS/eip-7739

## Citation

- APA: Dr. Devon Kurosawa, PhD. (2026). ERC-1271 Smart-Contract Wallet Signatures: Cross-Safe & Cross-Chain Replay Defense. NFTVenue Ledger. https://nftvenueledger.com/protocols/erc-1271-smart-contract-wallet-signature-replay-across-safes
- Canonical article: [ERC-1271 Smart-Contract Wallet Signatures: Cross-Safe & Cross-Chain Replay Defense](https://nftvenueledger.com/protocols/erc-1271-smart-contract-wallet-signature-replay-across-safes)
- Site research index: [NFTVenue Ledger](https://nftvenueledger.com/llms-full.txt)
