---
eip: 7951
label: EIP-7951
title: Precompile for secp256r1 Curve Support
status: Final
type: Standards Track
category: Core
created: 2025-05-27
official: https://eips.ethereum.org/EIPS/eip-7951
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7951.md
canonical: https://eips.huatuo.xyz/zh/eip-7951/
lang: zh
tldr: 在 0x100 新增 P256VERIFY 预编译，以 6900 gas 验证 secp256r1（P-256）ECDSA 签名，使智能账户可以在以太坊 L1 上直接使用通行密钥（passkey）、Secure Enclave 和 WebAuthn 密钥。
tags: [precompile, secp256r1, passkeys, webauthn, account-abstraction]
---

# EIP-7951: Precompile for secp256r1 Curve Support

> Add precompiled contract for secp256r1 ECDSA signature verification with proper security checks

**TL;DR:** 在 0x100 新增 P256VERIFY 预编译，以 6900 gas 验证 secp256r1（P-256）ECDSA 签名，使智能账户可以在以太坊 L1 上直接使用通行密钥（passkey）、Secure Enclave 和 WebAuthn 密钥。

## 它解决什么问题？

以太坊账户使用 secp256k1 签名，但手机和笔记本电脑中的安全硬件（Apple Secure Enclave、Android Keystore、FIDO2/WebAuthn 通行密钥、许多 HSM）使用另一条曲线：secp256r1，也称 P-256。在 Solidity 中验证 P-256 签名是可行的，但要花费数十万 gas，这使得"用 Face ID 签名"这类智能钱包在 L1 上很昂贵。

许多 L2 已经在 RIP-7212 之下上线了相应的预编译。EIP-7951 把同样的接口带到 L1，并修复了先前那份规范中发现的两个边缘情况漏洞。

## 它如何运作

- **地址：** `0x100`。**Gas：** 6900，无论验证成功与否都会收取。
- **输入：** 恰好 160 字节：`hash (32) | r (32) | s (32) | qx (32) | qy (32)`。
- **输出：** 签名有效时输出 32 字节的 `0x…01`；签名无效或任何格式错误的输入则输出为空。该预编译从不 revert。
- 它会检查 `0 < r, s < n`，公钥坐标小于 `p`，该点在曲线上且不是无穷远点。
- 与 RIP-7212 相比，它增加了对计算得到的点 `R'` 不是无穷远点的检查，并以 `R'.x ≡ r (mod n)` 取代简单的相等比较。

它执行的是*验证*，而不是像 `ECRECOVER` 那样恢复公钥，因为 P-256 硬件和 NIST 标准提供的就是验证。它已被纳入 Fusaka 升级（[EIP-7607](/eip-7607/)）。

## 示例代码

在合约中验证通行密钥签名：

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

library P256 {
    address internal constant VERIFIER = address(0x100);

    function verify(bytes32 hash, bytes32 r, bytes32 s, bytes32 qx, bytes32 qy)
        internal view returns (bool)
    {
        (bool ok, bytes memory out) =
            VERIFIER.staticcall(abi.encodePacked(hash, r, s, qx, qy));
        // Empty output means "invalid"; a chain without the precompile also returns empty.
        return ok && out.length == 32 && abi.decode(out, (uint256)) == 1;
    }
}
```

## 需要注意

- 状态为 **Final**。
- 地址、输入和输出都与 RIP-7212 相同，因此为 L2 编写的合约无需修改即可使用；只有 gas 成本不同（L1 上为 6900，RIP-7212 中为 3450）。
- 空返回值是有歧义的：如果该链上不存在该预编译，也会出现这种情况。依赖它之前，请确认该链支持它。
- P-256 签名是可延展的（`s` 和 `n - s` 都能通过验证）。如果你的应用把签名当作唯一标识符，请自行强制要求 low-`s`。
- WebAuthn 会把被签名的挑战包裹在 `authenticatorData` 和 `clientDataJSON` 中；你的钱包合约必须在调用预编译之前重建该哈希。它与 [ERC-4337](/eip-4337/) 账户以及经 [EIP-7702](/eip-7702/) 委托的 EOA 天然契合。


---

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