---
eip: 6327
label: ERC-6327
title: Elastic Signature
status: Draft
type: Standards Track
category: ERC
created: 2023-01-13
official: https://eips.ethereum.org/EIPS/eip-6327
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-6327.md
canonical: https://eips.huatuo.xyz/zh/eip-6327/
lang: zh
tldr: "一个基于密码的\"弹性签名\"草案接口：用户用零知识证明来证明自己知道一个可更改的秘密，由合约验证，作为私钥之上的额外签名因素。"
tags: [signatures, zero-knowledge, password, wallets, draft]
---

# ERC-6327: Elastic Signature

> Use password to sign data as private key

**TL;DR:** 一个基于密码的"弹性签名"草案接口：用户用零知识证明来证明自己知道一个可更改的秘密，由合约验证，作为私钥之上的额外签名因素。

## 它解决什么问题？

私钥对非技术用户很难：它不能更改，记不住，丢了就等于失去一切。托管式密钥服务让入门更容易，但要依赖供应商。

ERC-6327 提议一种**弹性签名（ES）**：用一个对人友好的秘密（比如密码）来授权某项操作，用户可以随时更改这个秘密。密码从不被存储或泄露。用户生成的是一份证明自己知道它的零知识证明，由验证者合约在链上检查该证明。

规范把 ES 定位为*额外的*因素，而不是对密钥的替代：例如，即使钱包密钥被攻破，DeFi 应用也要求输入密码才能提款，或是用作 [ERC-4337](/eip-4337/) 智能账户的密码插件。

## 它如何运作

三个角色和几个哈希：

- `pwdhash` = 密码的哈希（与用户地址绑定）；由验证者存储在链上。
- `datahash` = 被授权操作的哈希，由**请求者**合约生成。
- `fullhash` = `datahash` 加上若干已知值的哈希，其中应包含每个用户的 `nonce` 和 `chainid`（参考实现还混入了 `expiration`）。
- `allhash` = `pwdhash` 和 `fullhash` 的哈希。

流程：

1. **证明者**（用户的客户端）根据密码、地址和 `fullhash` 计算 `allhash` 和 zk-SNARK 的 `proof`。
2. **请求者**合约在**验证者**上调用 `verify(user, proof, datahash, expiration, allhash)`。
3. 验证者重新计算 `fullhash`，查出 `pwdhash`，针对公开值 `[pwdhash, fullhash, allhash]` 检查证明，然后递增用户的 nonce 并触发 `Verified`。

`resetPassword` 通过要求同时提供旧秘密和新秘密的证明来更改密码。参考电路使用 Poseidon 哈希（circom/snarkjs）。

## 示例代码

一个以弹性签名控制提款的请求者合约：

```solidity
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;

interface IElasticSignature {
    event SetPassword(address indexed user, uint indexed pwdhash);
    event Verified(address indexed user, uint indexed nonce);
    function pwdhashOf(address user) external view returns (uint);
    function verify(address user, uint[8] memory proof, uint datahash,
                    uint expiration, uint allhash) external;
}

contract PasswordVault {
    IElasticSignature public immutable es;
    mapping(address => uint256) public balance;

    constructor(IElasticSignature _es) { es = _es; }

    function withdraw(uint256 amount, uint[8] calldata proof,
                      uint expiration, uint allhash) external {
        // datahash binds the proof to this exact action
        uint datahash = uint(keccak256(abi.encode(address(this), msg.sender, amount)));
        es.verify(msg.sender, proof, datahash, expiration, allhash); // reverts if invalid
        balance[msg.sender] -= amount;
        payable(msg.sender).transfer(amount);
    }
}
```

## 需要注意

- 状态为 **Draft**；接口和哈希构造仍可能变化。
- `pwdhash` 是公开的，所以密码可以被离线暴力破解。规范自己的估算显示，短密码在 GPU 上很快就会被破解；只有非常长、高熵的秘密才接近私钥的强度。
- nonce 防止证明被重放；`fullhash` 中的链 ID 防止跨链重用。证明者和验证者必须就 `fullhash` 和 `datahash` 的构造方式完全一致。
- 证明生成在客户端进行，需要电路产物；链上验证者由该电路生成，所以两者必须匹配。


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-6327
