feat(evm): add RIP-7212 P256VERIFY (secp256r1) precompile at 0x100 - #392
Open
sfffaaa wants to merge 1 commit into
Open
feat(evm): add RIP-7212 P256VERIFY (secp256r1) precompile at 0x100#392sfffaaa wants to merge 1 commit into
sfffaaa wants to merge 1 commit into
Conversation
|
The preview deployment for peaqnetwork/peaq-network-node:ci/012453_add-auto-upgrade-on-preview-environment-iswg08ckww0c4k48oggoo400 is ready. 🟢 Open Preview | Open Build Logs Last updated at: 2026-08-18 14:02:08 CET |
sfffaaa
force-pushed
the
feature/blk-1007-precompile-p256
branch
from
August 18, 2026 11:03
d802023 to
2ecf8ad
Compare
On-chain secp256r1 (P-256 / NIST P-256) ECDSA verification in the EVM, enabling passkey/WebAuthn/secure-enclave signatures and P-256 account abstraction. secp256k1 (ecrecover at 0x01) cannot verify P-256 -- it is a different curve. - New crate pallet-evm-precompile-p256verify, ported from Moonbeam's implementation (p256 0.13.2, ecdsa, no_std); passes the official RIP-7212 test vectors (2 valid + 3 invalid). - Registered at address 0x100 with 3450 gas (RIP-7212 spec value) on the peaq, peaq-dev and krest runtimes. - The block-weight DoS meter is charged the real ~1.6 ms verify cost via record_external_cost (mirroring Moonbeam's benchmark), so the 3450 gas cannot be used to under-price the operation and grief block production. Additive only: new precompile at a previously-unused address; no storage migration and no change to existing precompiles. spec_version is left for the release process to bump.
sfffaaa
force-pushed
the
feature/blk-1007-precompile-p256
branch
from
August 18, 2026 14:01
2ecf8ad to
cc4d135
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a native EVM precompile for P-256 (secp256r1) signature verification at address
0x100, interface-compatible with Ethereum RIP-7212.The EVM's built-in
ecrecover(0x01) verifies secp256k1 only. P-256 — the curve used by passkeys/WebAuthn, Apple Secure Enclave, Android Keystore and HSMs — currently requires a pure-Solidity verifier at roughly 200k–330k gas per verification. This precompile does the same work for 3,450 gas, and contracts written against OpenZeppelin'sP256library (which probes0x100and falls back to Solidity) switch to the cheap path automatically once this activates, with no code change.Interface (exact RIP-7212)
0x0000000000000000000000000000000000000100(RIP-7212 standard)msgHash(32) ‖ r(32) ‖ s(32) ‖ pubX(32) ‖ pubY(32)1if valid; empty if invalid/malformed; never revertsDenial-of-service pricing (reviewer attention)
3,450 gas is the RIP-7212 constant, far below the real cost of the elliptic-curve work, so the block-weight meter is separately charged the actual verification cost via
record_external_cost(P256VerifyWeight). Pricing the meter by gas alone would let a caller fill blocks with underpriced verification.That weight is now measured rather than borrowed. The same
p256verify path was compiled to wasm32 and executed under Cranelift — the runtime's own execution mode:parachain_staking::payout_collatorbenchmark on both)2_500_000_000ps)This is ~1.4x higher than the figure published for the same crate elsewhere, which an earlier revision of this branch used; on these measurements that figure under-charges the meter. A benchmark generated on peaq reference hardware is still preferable and the constant should be replaced when one exists — the code comment says so.
Capacity impact is negligible: at 2.5 ms a block still admits roughly 800 verifications, far beyond any legitimate load, so the more conservative value costs nothing in practice.
Changes
New crate
precompiles/p256verify(p2560.13.2,no_std), wired into the peaq, peaq-dev and krest runtimes with the standard Ethereum precompile checks. Nospec_versionbump (release process owns it).Testing
0x…01; corrupted hash and wrong-length input → empty, no revert). Test suite lives in peaq-bc-test branchfeature/sig-precompile-tests.Interim availability note
Until this activates, P-256 verification is already possible via the audited Daimo verifier deployed at the canonical cross-chain address
0xc2b78104907F722DABAc4C69f826a522B2754De4on peaq mainnet and agung (~330k gas).