---
eip: 8030
label: EIP-8030
title: P256 algorithm support
status: Draft
type: Standards Track
category: Core
created: 2025-09-20
requires: 7932, 7951
official: https://eips.ethereum.org/EIPS/eip-8030
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-8030.md
canonical: https://eips.huatuo.xyz/zh/eip-8030/
lang: zh
tldr: 在 EIP-7932 框架下将 P256（secp256r1）注册为签名算法类型 0x01，复用每个客户端因 EIP-7951 预编译而已经实现的 P256 验证逻辑。
tags: [signatures, p256, secp256r1, cryptography, core]
---

# EIP-8030: P256 algorithm support

> Adds an EIP-7932 algorithm type for P256 support of type `0x01`

**TL;DR:** 在 EIP-7932 框架下将 P256（secp256r1）注册为签名算法类型 0x01，复用每个客户端因 EIP-7951 预编译而已经实现的 P256 验证逻辑。

## 它解决什么问题？

以太坊账户使用 secp256k1 签名。[EIP-7932](/eip-7932/) 提出了一个**次级签名算法**框架，每种算法由一个字节的类型标识，这样交易和其他对象就可以用别的算法签名。一个框架需要第一个具体的算法来进行定义和测试。

P256（也称 secp256r1）是一条被广泛使用的 NIST 曲线，通行密钥（passkey）和许多安全硬件芯片都使用它。由于 [EIP-7951](/eip-7951/) 中的 P256 验证预编译，每个执行客户端也已经实现了它。这使它成为一个低风险的首个算法。EIP-8030 精确定义了 P256 如何接入 EIP-7932。

## 它如何运作

该算法以如下参数注册：

| 常量 | 值 |
| --- | --- |
| `ALG_TYPE` | `0x01` |
| `SIZE` | `129` 字节 |

签名格式为 `alg_type (1) || r (32) || s (32) || x (32) || y (32)`：类型字节、签名，然后是未压缩的公钥。

EIP-7932 要求的函数：

- **`verify(signature, signing_data)`**：如果 `signing_data` 不是恰好 32 字节，则先用 keccak256 对其哈希。去掉类型字节，`s` 必须不大于 `N/2`（low-s，用于防止可塑性，secp256k1 自 [EIP-2](/eip-2/) 起也是如此），并且 EIP-7951 的 `P256Verify` 逻辑必须通过。它返回 64 字节的公钥 `x || y`。
- **`gas_cost(signing_data)`**：基础值为 3,900 gas，定义为 EIP-7951 预编译的成本减去 3,000（secp256k1 `ecrecover` 预编译的成本）。非 32 字节的数据会加上 keccak 的成本：`30 + 6 * words`。
- **`validate`**：空操作。
- **`merge_detached_signature`**：将 `r || s` 与 `x || y` 拼接起来。

与 secp256k1 不同，P256 无法仅凭签名恢复公钥，这就是公钥要包含在这 129 字节中的原因。

## 示例代码

用 TypeScript 和 `@noble/curves` 构造 129 字节的签名：

```ts
import { p256 } from "@noble/curves/p256";
import { keccak_256 } from "@noble/hashes/sha3";
import { concatBytes } from "@noble/hashes/utils";

const priv = p256.utils.randomPrivateKey();
const pubUncompressed = p256.getPublicKey(priv, false); // 0x04 || x || y

const digest = keccak_256(message);                      // 32-byte signing data
const sig = p256.sign(digest, priv, { lowS: true });     // enforce s <= N/2

const encoded = concatBytes(
  new Uint8Array([0x01]),                                // ALG_TYPE
  sig.toCompactRawBytes(),                               // r || s (64 bytes)
  pubUncompressed.slice(1),                              // x || y (64 bytes)
);
console.log(encoded.length); // 129
```

## 需要注意

- **状态：Draft**，并且依赖同样处于 Draft 的 [EIP-7932](/eip-7932/)。在两者都被采纳之前，这里的任何内容都无法在主网上使用。
- 这里复用的 [EIP-7951](/eip-7951/) 预编译是另一回事：它让合约今天就能验证 P256 签名。EIP-8030 讨论的是 P256 作为协议层面的签名类型。
- 规范指出，其主要目的是为 EIP-7932 提供一个已知安全的算法用于测试用例。
- 签名必须使用 low-s 形式；许多 P256 库默认不会规范化 `s`。
- 安全考量仍标记为"Needs discussion"。


---

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