An introduction to EIP-1271

What is EIP-1271?

EIP-1271 is an Ethereum Improvement Proposal that specifies a standard interface for contracts that can verify whether a given message or transaction is valid or not. This interface can be used to implement a kind of signature verification for smart contracts, where the contract can check if a signature is valid before executing a certain action.
To use EIP-1271 with a smart contract, you need to implement the interface defined in the proposal. The interface consists of a single function, called isValidSignature, which takes two arguments:
function isValidSignature( bytes32 _messageHash, bytes memory _signature )
public view returns (bytes4);
The _messageHash argument is the hash of the message or transaction that you want to verify. The _signature argument is the signature itself, which is usually a combination of the signer's public key and some cryptographic information. The function returns a four-byte code that indicates whether the signature is valid or not.
The four-byte code is defined as follows:
  • 0x00000000 if the signature is invalid.
  • 0x20c13b0b if the signature is valid and was produced using the eth_sign method.
  • 0x1626ba7e if the signature is valid and was produced using the personal_sign method.
  • 0x01ffc9a7 if the signature is valid and was produced using the eth_signTypedData method.
To implement the interface, you need to write a function that takes the _messageHash and _signature arguments and returns one of the four-byte codes described above. The function should use cryptographic functions to verify the signature and return the appropriate code.
Once you have implemented the interface, you can use the isValidSignature function in your smart contract to check whether a given signature is valid or not. For example, you could use it to verify that a user has signed a message before allowing them to perform a certain action in your contract.
Overall, EIP-1271 provides a standard way for smart contracts to verify signatures and ensure that only authorized parties can perform certain actions. By implementing the interface, you can add an extra layer of security to your smart contract and prevent unauthorized access or malicious behavior.

Why is EIP-1271 important for the future of Ethereum?

Smart contracts cannot directly sign messages, so EIP-1271 serves as a guide to implement isValidSignature(hash, signature) on the signing contract that can be called to validate a signature.
With the rise of smart contract wallets and DAOs controlled by multi-sigs these parties require the means to use signed messages to demonstrate the right to move assets, vote, or for other purposes. EIP-1271 is, additionally, the foundation for account abstraction which enables the evolution of the Ethereum ecosystem.

What kind of dApps is EIP-1271 important for?

Any dApp which would like to implement AA features that simplify UX and boost its capabilities should implement EIP-1271.

How do I implement EIP-1271 on my smart contract?

You can use our npm package that makes it easy for dapps to add support for EIP 1271.
npm install @etherspot/eip1271-verification-util You can also take a look at example code in this repo.