ERC-6327 Elastic Signature (password-based signature) (Elastic Signature)

Draft · Signatures & auth · created 2023-01-13

A standard for signing data with a human-memorable password instead of a private key, and verifying it on-chain with a zero-knowledge proof. The password is never stored anywhere and can be changed as often as desired, with no length restriction.

Why it is needed

On Ethereum, approving anything requires signing with a private key. A private key is a long, random value that cannot be memorized, and there is no way to change it once it has leaked. This is a significant barrier to entry, especially for users with little technical experience. Custodial services that hold private keys on a user's behalf are convenient but create dependence on a specific provider and run counter to decentralization. This standard uses the familiar concept of a password as a signing method. The user only needs to generate a zero-knowledge proof that they know the password and submit it; a smart contract verifies that proof on-chain. The password itself is never stored or transmitted anywhere and can be changed whenever needed. Rather than replacing the private key, it is an additional signing method layered on top of it, so even if the private key leaks, the password provides an extra layer of protection.

What to implement

In depth

Five core values

The spec defines five values. pwdhash is the hash of the secret (password), datahash is the hash of the intended transaction data, fullhash is the hash of datahash together with all well-known variables, expiration is the timestamp at which the intended transaction expires, and allhash is the hash of fullhash and pwdhash together. The public statement must each include an item reflecting pwdhash, fullhash, and allhash, and the method of computing fullhash must be agreed upon between the verifier and the prover.

Roles of the three participants

The Verifier computes fullhash from the datahash given by the requester, looks up pwdhash from the address (an EOA or smart contract wallet), and verifies the proof together with the submitted allhash. The Requester creates datahash and sets expiration, then requests verification from the verifier using the proof and allhash given by the prover, along with datahash and expiration. The Prover generates proof and allhash using the datahash and expiration agreed with the requester, plus shared variables such as nonce.

Shared variables and replay prevention

Shared variables must be knowable to all participants, must include nonce and chainid, and may additionally include verifier-specific variables. Because nonce is included in the fullhash computation, the same proof cannot be used twice, and because chainid is included, a proof cannot be reused on a different chain. The reference implementation increments nonceOf[user] by 1 and emits a Verified event each time verification succeeds.

Behavior of the verify function

verify is designed to be called by other contracts, with the calling contract creating and passing in the datahash. The function must verify whether allhash was correctly and honestly computed from the password. The reference implementation, ZKPass, checks that block.timestamp < expiration and that pwdhash is nonzero (the user exists), then computes fullhash as keccak256(abi.encodePacked(expiration, block.chainid, nonce, datahash)) divided by 8 (reducing 256 bits to 254 bits), and passes proof, pwdhash, fullhash, and allhash to a verifier generated by snarkjs for verification.

resetPassword and initial setup

resetPassword takes a proof for the old password (proof1, expiration1, allhash1) and a proof for the new password (proof2, pwdhash2, expiration2, allhash2). In the reference implementation, if nonce is 0 this is treated as the initial setup: the new pwdhash is stored and only the new password proof is verified. If nonce is not 0, the old password proof is verified first, then the new pwdhash is stored and the new password proof is verified. A SetPassword event is emitted when this completes.

Structure of the zero-knowledge circuit

The circuit (circom) consists of two Poseidon hashes. The first Poseidon takes the password (pwd) and address as input to produce pwdhash. The second Poseidon takes that pwdhash and fullhash as input to produce allhash. The circuit's public outputs are the three values pwdhash, fullhash, and allhash. The verifier contract (verifier.sol) is automatically generated using snarkjs.

An additional method, not a replacement for the private key

ES is not an either-or choice between private key and password; it is designed as an additional signing method layered on top of private key signatures. If a DeFi app requires password entry during the fund transfer process, it provides extra protection even if the private key leaks, and if used as a plugin for account abstraction wallets such as ERC-4337, it can make onboarding new users easier. This method applies only to password-based signing, not to EOA signing, so it remains backward compatible with existing signature verification standards.

Proposal status

This ERC is in Draft status, created in January 2023. The content may change or progress may stall, so it is best to check the latest status before implementing.

Things to watch out for

Original ERC · ← ERCs