feat(core/vm,params,crypto): add the EIP-7951 P256VERIFY precompile #31991, part of #2690 - #2694
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
75e2d16 to
aba445a
Compare
575ab42 to
1a0c614
Compare
28534e9 to
02391d8
Compare
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Exact-length rejection lacks coverage, and unrelated literal rewrites should be removed.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Adds EIP-7951 P256VERIFY support to the Osaka precompile set.
Changes:
- Implements secp256r1 signature verification at
0x100. - Adds the fixed 6900 gas cost.
- Adds registration checks, benchmarks, and 782 vectors.
| File | Description |
|---|---|
params/protocol_params.go |
Defines P256 verification gas. |
crypto/secp256r1/verifier.go |
Implements P-256 verification. |
core/vm/contracts.go |
Registers and executes the precompile. |
core/vm/contracts_test.go |
Adds tests and benchmark coverage. |
core/vm/testdata/precompiles/p256Verify.json |
Provides verification vectors. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
02391d8 to
f11060e
Compare
d8e6025 to
b8609c1
Compare
…thereum#31991, part of XinFinOrg#2690 The Osaka precompile set had no secp256r1 verifier, so contracts relying on WebAuthn or passkey style verification could not be deployed once Osaka gets scheduled. EIP-7951 places it at 0x100. Ported from geth b3131f0 (ethereum#31991). The verifier only uses crypto/ecdsa and crypto/elliptic, so no dependency is added. The precompile is registered at 0x100 in PrecompiledContractsOsaka and the 782 official test vectors are included. geth's Cacheable and NormalizeInput methods and the exported PrecompiledContractsP256Verify set are left out: this fork's PrecompiledContract interface has no caller for them. The p256Verify block itself - its doc comments, the package-level input length constant and Name - is kept verbatim from upstream master, which normalized it in 98a0080 (ethereum#35473); the precompile caching that same commit introduced is the part left out above. Part of XinFinOrg#2690
b8609c1 to
66d497c
Compare


Proposed changes
The Osaka precompile set has no secp256r1 verifier, so once Osaka is scheduled a call to
0x100falls through to "call an empty account" and returns success with empty output; contracts doing WebAuthn or passkey style signature checks would silently get a zero result instead of a verification. EIP-7951 places the precompile at0x100.This adds the precompile at
0x100inPrecompiledContractsOsaka, theP256VerifyGasconstant (6900) andcrypto/secp256r1, which holds the signature verifier. Ported from geth ethereum#31991. The verifier uses onlycrypto/ecdsaandcrypto/elliptic, so no dependency is added. geth'sCacheableandNormalizeInputmethods and the exportedPrecompiledContractsP256Verifyset are not ported, because this fork'sPrecompiledContractinterface does not declare them and nothing calls them.The 782 official test vectors are included and run through
testJson.Vector state: the vectors assert for real because of the JSON vector plumbing from #2664, which is merged into
dev-upgradeand therefore in the base of this branch. On the current head all 782 cases pass with the vector-derived names and gas, and flipping oneExpectedvalue in the vector file makes the test fail. The test also asserts that0x100is registered inPrecompiledContractsOsaka, andTestPrecompileSetsByForkpins it as an Osaka-only entry: presence,Name(), and theActivePrecompileslisting.Activation status: the five real network configs (XDCMainnet, Mainnet, Testnet, Devnet, Localnet) keep
OsakaBlockat nil, so the Osaka set is not selected on any of them and this change has no effect there yet. The six in-tree test configs (AllEthashProtocolChanges,AllDevChainProtocolChanges,AllCliqueProtocolChanges,TestXDPoSMockChainConfig,TestChainConfig,MergedTestChainConfig) haveOsakaBlockset to 0, so on those the precompile is selected from genesis: a call to0x100changes from "call an empty account" (success with empty output) to real verification, andActivePrecompilesnow lists the address. That is the intended behaviour and the reason the vectors can run under the Osaka rules; no existing test relied on the empty-account behaviour.Interaction with the EIP-2537 work: the Osaka set is now
0x01–0x09plus the0x0astub (#2666) plus0x0b–0x11(EIP-2537, #2668, already merged) plus0x100(this PR). This branch is rebased onto #2668, andTestPrecompileSetsByForkpins0x100so a later bucket edit cannot drop it silently.Part of #2690
Types of changes
What types of changes does your code introduce to XDC network?
Impacted Components
Which parts of the codebase does this PR touch?
Checklist
Notes on the unchecked items: the precompile is unreachable until
OsakaBlockis scheduled, so there is nothing to exercise on a private network, no behaviour to be backwards compatible with, and no user facing change to document yet. The gas constant, the 160 byte input layout and the 782 official vectors (including their expected gas) are covered by unit tests.Note on the diff: #2664 and #2668 are merged into
dev-upgradeand this branch is rebased onto it, so the diff contains only the six files of this change (crypto/secp256r1/verifier.go,params/protocol_params.go,core/vm/contracts.go,core/vm/contracts_test.go,core/vm/precompile_sets_test.go,core/vm/testdata/precompiles/p256Verify.json).