Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article explores EIP7951.

The proposal introduces ECDSA signature verification on the secp256r1 (P-256) elliptic curve as an Ethereum precompile costing 6900 gas, enabling integration with Apple Secure Enclave and passkeys.

Overview

EIP7951 adds a precompile at address 0x100 called P256VERIFY. It verifies ECDSA signatures on the secp256r1 elliptic curve, also known as P-256 or prime256v1, for 6900 gas.

The original diagrams and pseudocode labels are retained in Japanese.

P256VERIFY precompile overview

Item Details
Precompile address 0x100
Operation name P256VERIFY
Gas cost 6900 gas
Input size 160 bytes
Output size 32 bytes (success) / 0 bytes (failure)
Target curve secp256r1 (P-256 / prime256v1)

The difference between secp256r1 and secp256k1

Ethereum's existing signature verification mechanism (ecrecover) uses the secp256k1 curve. By contrast, secp256r1 (P-256) is a different elliptic curve standardized by NIST and widely adopted in secure hardware and authentication systems such as Apple Secure Enclave, Android Keystore, and FIDO2/WebAuthn. The two curves are incompatible, and historically Ethereum could not efficiently verify secp256r1 signatures on-chain.

EIP7951 specifies a version for Ethereum mainnet that retains the interface of RIP7212, previously implemented on Layer 2 networks, while addressing two security issues in RIP7212.

Motivation

Integration with secure hardware

Secure hardware built into modern smartphones and security keys manages private keys using secp256r1. Typical examples include the following.

Device / technology Use case
Apple Secure Enclave Signing using Face ID / Touch ID
Android Keystore Signing using fingerprint or facial authentication
HSM (hardware security module) Enterprise key management
TEE (trusted execution environment) Secure computing environment
FIDO2 / WebAuthn Passkey authentication

These devices generate signatures using secp256r1. With the P256VERIFY precompile, Ethereum transaction approval can be integrated with an iPhone's Face ID or passkeys. Built-in device authentication can be used for wallet signing without installing a dedicated wallet app, substantially lowering the barrier to entry for everyday users.

Earlier Layer 2 implementations and the transition to an EIP

Improvements from RIP7212 to EIP7951

A secp256r1 precompile had already been implemented and deployed on Layer 2 networks as RIP7212. However, two significant security flaws were discovered in RIP7212. EIP7951 proposes bringing the precompile to Ethereum mainnet while retaining the RIP7212 interface and fixing these vulnerabilities.

Vulnerabilities in RIP7212

RIP7212 had the following two issues.

The first was a missing check for the point at infinity. The specification did not check whether the point R' reconstructed during signature verification was the point at infinity, the identity element of elliptic curve addition. This could lead to nondeterministic behavior across implementations and potentially cause consensus failures.

Vulnerability 1: Missing point-at-infinity check

The second was an incorrect modular comparison. When comparing the x-coordinate r' of the reconstructed R' with the signature component r, the specification used the simple equality test r' == r. However, when the x-coordinate exceeds the curve order n, a modular comparison, r' ≡ r (mod n), is required. This error could produce results that differ from mathematically correct ECDSA verification.

Vulnerability 2: Incorrect modular comparison

What is the point at infinity?

It is a special point in elliptic curve addition that plays the same role as zero in ordinary integer arithmetic. Adding a point P to its inverse -P produces the point at infinity. ECDSA verification must fail if the reconstructed point R' is the point at infinity, but RIP7212 omitted this check.

Specification

Precompile address and gas cost

P256VERIFY is located at address 0x100 and costs 6900 gas. Benchmarks against the existing ECRECOVER precompile (3000 gas) showed that secp256r1 verification is more computationally expensive, leading to the 6900-gas price.

Errors and verification failures also consume 6900 gas. The precompile never reverts under any circumstances.

secp256r1 curve parameters

secp256r1 is an elliptic curve standardized by NIST in SP 800-186 and fully defined by the following parameters.

Parameter Value
Base field modulus p 0xffffffff00000001...ffffffff
Curve coefficient a 0xffffffff00000001...fffffffc
Curve coefficient b 0x5ac635d8aa3a93e7...2604b
x-coordinate of generator G 0x6b17d1f2e12c4247...8c296
y-coordinate of generator G 0x4fe342e2fe1a7f9b...51f5
Subgroup order n 0xffffffff00000000...632551
Cofactor h 0x1

The curve equation is y² = x³ + ax + b (mod p).

Encoding

The data supplied to P256VERIFY is encoded differently depending on its type.

Scalar encoding

Scalars (signature components r and s, and the message hash h) are represented as 32-byte big-endian unsigned integers. Unlike field elements, their integer values do not have to be at most the subgroup order n at the encoding stage.

Field element encoding

Elements of the finite field Fp (field elements) are represented as 32-byte big-endian unsigned integers. The encoded integer must be less than the modulus p. Values greater than or equal to p are invalid inputs.

Point encoding

A point on secp256r1 is represented by 64 bytes: its x-coordinate and y-coordinate, each encoded as 32 bytes and concatenated.

Point-at-infinity encoding

Because the coordinates (0, 0) do not represent a valid point over Fp on secp256r1 (they do not satisfy the curve equation), a sequence of 64 zero bytes is used to represent the point at infinity.

In summary, h is a scalar, r and s are scalars, and qx and qy are field elements (values in Fp). Scalars do not have to be less than the order n at the encoding stage (this is checked during validation), whereas field elements must be less than the modulus p (check 3).

P256VERIFY input and output

Input format

P256VERIFY accepts 160 bytes of input. The input is a byte sequence formed by concatenating the following fields in order.

P256VERIFY input byte layout

Field Size Description
Message hash h 32 bytes Hash to be verified
Signature component r 32 bytes r component of the ECDSA signature
Signature component s 32 bytes s component of the ECDSA signature
Public key x-coordinate qx 32 bytes x-coordinate of the secp256r1 public key
Public key y-coordinate qy 32 bytes y-coordinate of the secp256r1 public key
Output format

The precompile returns different byte sequences depending on whether signature verification succeeds.

Result Output
Verification succeeds 0x0000...0001 (32 bytes)
Verification fails / invalid input Empty byte sequence (0 bytes)
Input validation

The precompile performs the following five checks in order. If any check fails, it skips the remaining checks and returns an empty byte sequence.

P256VERIFY input validation flow

  1. Input length check

    • Condition: The input is exactly 160 bytes long.
    • Purpose: Verify that all five fields (32 bytes each) are present.
  2. Signature component range check

    • Condition: 0 < r < n and 0 < s < n
    • Purpose: Verify that r and s fall within the range determined by the curve order n. Zero and values greater than or equal to n are invalid.
  3. Public key coordinate range check

    • Condition: 0 ≤ qx < p and 0 ≤ qy < p
    • Purpose: Verify that the public key coordinates lie within the finite field Fp. Values greater than or equal to p are not field elements.
  4. On-curve point check

    • Condition: qy² ≡ qx³ + a·qx + b (mod p)
    • Purpose: Verify that the public key (qx, qy) satisfies the secp256r1 curve equation. A point outside the curve is not a valid public key.
  5. Point-at-infinity check

    • Condition: (qx, qy) ≠ (0, 0)
    • Purpose: Verify that the public key is not the point at infinity, which cannot be used as a public key.

Verification algorithm

After input validation succeeds, the signature is verified using the following steps.

P256VERIFY signature verification algorithm

Step 1: Compute the inverse of s

text
s1 = s^(-1) (mod n)

Compute the modular inverse used in reconstructing the signing point associated with the random signing value k: calculate s1 modulo n.

Step 2: Reconstruct the signing point R'

text
R' = (h * s1) * G + (r * s1) * (qx, qy)

Combine the message hash h, the inverse s1, the public key (qx, qy), and the generator G to reconstruct the random point R' used during signing.

G is the generator point of the curve, fixed by the secp256r1 parameters. In elliptic curve cryptography, the relationship is given by 公開鍵 = 秘密鍵 × G (public key = private key × G).

Step 3: Check for the point at infinity (RIP7212 fix)

text
if R' == 無限遠点:
    return(失敗)

If the reconstructed R' is the point at infinity, verification fails. RIP7212 omitted this check, potentially resulting in nondeterministic behavior.

Step 4: Compare the x-coordinate modulo the curve order (RIP7212 fix)

text
r' = R'.x

if r' ≡ r (mod n):
    return 0x0000...0001(成功)
else:
    return(失敗)

Extract the x-coordinate r' of R' and compare it modulo the curve order with the signature component r. RIP7212 used the simple equality check r' == r, which could produce incorrect results in edge cases where the x-coordinate exceeds the order n.

Additional considerations

Why verification rather than recovery?

Ethereum's existing ECRECOVER precompile (for secp256k1) is designed to recover an address from a signature. In contrast, P256VERIFY verifies whether a signature is valid for an already known public key.

There are several reasons for this design choice.

Most secure hardware is designed to prevent private keys from leaving the device and provides a signature verification interface. NIST's FIPS 186-5 standard specifies verification but does not define recovery. Moreover, verification is more efficient than recovery for secp256r1.

Compatibility with RIP7212

EIP7951 maintains the following compatibility with RIP7212.

Item RIP7212 EIP7951
Precompile address 0x100 0x100
Input format 160 bytes 160 bytes
Output format 32 bytes / 0 bytes 32 bytes / 0 bytes
Gas cost 3450 gas 6900 gas
Point-at-infinity check No Yes
Modular comparison No Yes

Contract code written for RIP7212 works without modification, apart from the difference in gas cost. The security fixes are transparent to correctly implemented callers. They affect only edge cases that should have failed in the first place.

The 6900-gas cost is based on benchmarking against ECRECOVER (3000 gas), prioritizing the accuracy of implementation benchmarks. Gas-cost compatibility with the 3450-gas price of RIP7212 is therefore intentionally not preserved.

Security considerations

Signature malleability

EIP2 requires non-malleable secp256k1 transaction signatures, whereas the NIST FIPS 186-5 standard does not require non-malleability for secp256r1.

EIP2 is an early Ethereum protocol improvement proposal. It restricts the range of the s value in secp256k1 signatures to prevent signature malleability.

What is signature malleability?

It is the property that allows another valid signature with a different byte representation to exist for the same message and private key. In the early days of Bitcoin and Ethereum, abuse of this property to alter transaction IDs was a problem. Ethereum mitigates this by imposing an upper bound on the secp256k1 signature component s.

For secp256r1, multiple valid signatures may exist for the same message. Applications that require non-malleability (for example, when using signatures as identifiers) should implement additional checks at the application layer.

Constant-time algorithms are not required

EIP7951 does not require precompile implementations to use constant-time algorithms. Resistance to side-channel attacks (attacks that infer a private key from differences in processing time) is not guaranteed at the precompile level. The device's secure hardware is expected to protect the private key.

Cryptographic strength

secp256r1 provides approximately 128 bits of security. This is comparable to secp256k1, which Ethereum already uses, and its curve parameters are standardized in NIST SP 800-186. It has also undergone extensive cryptographic analysis, with practical deployment experience on L2 networks through RIP7212.

Compatibility

Activating EIP7951 does not affect existing contracts. Contracts deployed at address 0x100 are not a realistic occurrence, so no compatibility issues are expected.

Contracts developed using RIP7212 on Layer 2 networks continue to work apart from the gas cost increase from 3450 to 6900 gas.

Reference implementation

Because secp256r1 is widely adopted in hardware security devices and standard libraries, EIP7951 does not provide a dedicated reference implementation. For implementation guidance, consult NIST FIPS 186-5 (Digital Signature Standard).

References

Conclusion

I hope this explanation was helpful.

This article covered EIP7951.

EIP7951 proposes adding signature verification on the secp256r1 elliptic curve used by Apple Secure Enclave, passkeys, and FIDO2 devices to Ethereum as a precompile costing 6900 gas. It fixes two security problems in RIP7212, previously implemented on Layer 2 networks (the missing point-at-infinity check and incorrect modular comparison), while retaining full interface compatibility with existing implementations. The precompile makes account abstraction patterns that integrate biometric authentication on iPhones and Android devices with Ethereum signing economically practical, potentially lowering the barrier to entry for everyday users.

I also write articles elsewhere; feel free to explore them.

If you notice any mistakes, I would appreciate a comment or a direct message on Twitter. I will continue sharing what I learn in future articles, so feel free to follow along.