ERC-1271
ERC-1271: Contract Signature Verification Standard¶
ERC-1271 is an Ethereum standard that defines how smart contracts can verify signatures.
Problem Addressed¶
In Ethereum, Externally Owned Accounts (EOAs) can sign messages using their private keys (e.g., using the ECDSA algorithm), and anyone can verify the signature using the public key. However, smart contracts do not have private keys and therefore cannot generate traditional signatures like EOAs. With the rise of smart contract wallets (such as Safe, Argent) and Account Abstraction, we need a standard method for contracts to "sign" messages and for third parties (such as DApps, exchanges) to verify whether these signatures are valid.
Mechanism and Principles¶
ERC-1271 defines a single function interface:
* _hash: The hash of the data to be verified. * _signature: The signature data (format defined by the specific contract implementation). * Return value: If the signature is valid, must return the magic value0x1626ba7e (i.e., bytes4(keccak256("isValidSignature(bytes32,bytes)"))); otherwise return any other value. Verification Flow: 1. A user (or contract owner) generates a signature (typically an EOA signature). 2. The verifier (e.g., OpenSea or Uniswap contract) calls the wallet contract's isValidSignature function, passing the message hash and signature. 3. The wallet contract internally executes custom verification logic (e.g., checking if the signer is the contract owner, or if the multisig threshold is met). 4. If verification passes, the function returns the magic value, and the verifier confirms the signature is valid.
Key Features¶
- Flexibility: Allows arbitrary verification logic (single-sig, multisig, BLS signatures, social recovery, etc.).
- Interoperability: Enables DApps to support smart contract wallet login and interaction just like regular EOAs.
- Off-chain signing, on-chain verification: Supports EIP-712 structured data signing.
Common Use Cases¶
- Smart contract wallet login (SIWE): Allows users to log into Web3 applications via contract wallets.
- NFT marketplace listings: Smart contract wallets can place gasless listings on marketplaces like OpenSea.
- Decentralized exchanges (DEX): Supports contract wallets signing Limit Orders.