Skip to content

NEP-635: P256 host function#635

Merged
gagdiez merged 6 commits intomasterfrom
p256
Apr 7, 2026
Merged

NEP-635: P256 host function#635
gagdiez merged 6 commits intomasterfrom
p256

Conversation

@bowenwang1996
Copy link
Copy Markdown
Collaborator

@bowenwang1996 bowenwang1996 commented Jan 25, 2026

Proposal to add ECDSA P256 signature verification as a host function in the runtime. Implementation in near/nearcore#14927

@bowenwang1996 bowenwang1996 requested a review from a team as a code owner January 25, 2026 16:50
@github-project-automation github-project-automation bot moved this to NEW in NEPs Jan 25, 2026
@github-project-automation github-project-automation bot moved this to NEW❗ in DevRel Jan 25, 2026
Copy link
Copy Markdown
Contributor

@mitinarseny mitinarseny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @bowenwang1996, thank you for this proposal!

We (Near Intents team) are super-excited to have it on mainnet soon, as it would drastically reduce gas costs of verifying p256 signatures in WASM, while leaving more gas for other operations.

I left a couple of comments, would appreciate your feedback.

neps/nep-0635.md Outdated
///
/// - `signature` MUST be 64 bytes encoded as `r || s` (32 bytes each, big-endian).
/// - `public_key` MUST be a 33-byte compressed SEC1 encoding.
/// - `message` is the exact byte sequence to verify (no hashing is performed).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, all ECDCA signatures MUST be calculated over a digest of cryptographic hash function, while it's up to signing standard which hash function to use: e.g. webauthn uses SHA-256. Do you think it's worth to mention it here?

Copy link
Copy Markdown
Contributor

@mitinarseny mitinarseny Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I checked: the value will be truncated or padded with zeros inside of <VerifyingKey<C> as PrehashVerifier<Signature<C>>>::verify_prehash if the length is not equal to <C as Curve>::FieldBytesSize, which is 32 bytes for NistP256

@gagdiez gagdiez added WG-protocol Protocol Standards Work Group should be accountable A-NEP A NEAR Enhancement Proposal (NEP). labels Jan 29, 2026
@gagdiez
Copy link
Copy Markdown
Contributor

gagdiez commented Jan 29, 2026

Thank you @bowenwang1996 for submitting this NEP. I would now request @near/wg-protocol to assign two reviewers

т(see expectations below).

Just for clarity, Technical Reviewers play a crucial role in scaling the NEAR ecosystem as they provide their in-depth expertise in the niche topic while work group members can stay on guard of the NEAR ecosystem. The discussions may get too deep and it would be inefficient for each WG member to dive into every single comment, so NEAR Developer Governance designed this process that includes subject matter experts helping us to scale by writing a summary with the raised concerns and how they were addressed.

Technical Review Guidelines
  • First, review the proposal within one week. If you have any suggestions that could be fixed, leave them as comments to the author. It may take a couple of iterations to resolve any open comments.
  • Second, once all the suggestions are addressed, produce a Technical Summary, which helps the working group members make a weighted decision faster. Without the summary, the working group will have to read the whole discussion and potentially miss some details.
    Technical Summary guidelines:
  • A recommendation for the working group if the NEP is ready for voting (it could be approving or rejecting recommendation). Please note that this is the reviewer's personal recommendation.
  • A summary of benefits that surfaced in previous discussions. This should include a concise list of all the benefits that others raised, not just the ones that the reviewer personally agrees with.
  • A summary of concerns or blockers, along with their current status and resolution. Again, this should reflect the collective view of all commenters, not just the reviewer's perspective.

Here is a nice example and a template for your convenience:

### Recommendation
Add recommendation
### Benefits
* Benefit
* Benefit
### Concerns
| # | Concern | Resolution | Status |
| - | - | - | - |
| 1 | Concern | Resolution | Status |
| 2 | Concern | Resolution | Status |

Please tag the @near/nep-moderators once you are done, so we can move this NEP to the voting stage. Thanks again.

@gagdiez gagdiez added the S-review/needs-wg-to-assign-sme A NEP that needs working group to assign two SMEs. label Jan 29, 2026
neps/nep-0635.md Outdated

The reference implementation in `nearcore`:

- Uses the RustCrypto `p256` crate to parse `Signature::from_slice` and `VerifyingKey::from_sec1_bytes`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the reviewer of this NEP, I think it would be nice to mention that this crate was audited recently: https://reports.zksecurity.xyz/reports/near-p256/

Particularly since the maintainers of this crate still claim this crate has never been independently audited: https://github.com/RustCrypto/elliptic-curves/tree/master/p256#%EF%B8%8F-security-warning

even though they have added the suggested changes from the audit: RustCrypto/elliptic-curves#1155

Copy link
Copy Markdown
Contributor

@gagdiez gagdiez Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this would also be relevant for future readers, I will go ahead and add a small comment on the NEP itself

@gagdiez
Copy link
Copy Markdown
Contributor

gagdiez commented Mar 5, 2026

@near/wg-protocol sorry to ping again, still waiting on two SME reviewers (cc @walnut-the-cat)

Copy link
Copy Markdown
Contributor

@birchmd birchmd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gagdiez we had a discussion about this NEP at our monthly Protocol Working Group review call. We decided that it is ok to skip the separate SME review for this proposal and move straight to voting. This because it is using a commonly used and well-specified signature algorithm while also making use of a library that has been audited. Essentially, we fell the SME review has implicitly already taken place in the form of the popularity of this algorithm (e.g. in passkeys) and in the audit of the crate.

To that end, as my role as a WG member, I vote to approve this proposal. My only minor comment is that we should accept @mitinarseny 's comments about making clear the msg passed to the verify function should come from some cryptographically secure hash function (the exact one chosen is dependent on the signature scheme), and enforcing input lengths at the SDK level.

@gagdiez gagdiez added S-voting/needs-wg-voting-indication A NEP in the VOTING stage that needs the working group voting indication. and removed S-review/needs-wg-to-assign-sme A NEP that needs working group to assign two SMEs. labels Mar 13, 2026
@gagdiez
Copy link
Copy Markdown
Contributor

gagdiez commented Mar 13, 2026

@birchmd completely understandable, I think it would still be quite nice if we could get another member from the @near/wg-protocol to state their vote, as @bowenwang1996 is already the one proposing the NEP maybe @mfornet could give their thumbs up?

Co-authored-by: Arseny Mitin <mitinarseny@gmail.com>
Co-authored-by: r-near <163825889+r-near@users.noreply.github.com>
@graphite
Copy link
Copy Markdown
Contributor

graphite commented Apr 2, 2026

Giving my thumbs up here as well. I incorporated the suggestions from @mitinarseny and @r-near as @birchmd suggested. I believe in the current state this NEP should be accepted.

as Iker pointed out, the creators of the `p256` crate claim that their crate was never audited

However NEAR recently requested an independent review from zksecurity, which reported "No major issues were found and the codebase was found to be thoroughly tested and well-architected."
@gagdiez
Copy link
Copy Markdown
Contributor

gagdiez commented Apr 7, 2026

Both @birchmd [1] and @graphite [2] who are members of the @near/wg-protocol gave their approval, which means we have reached enough quorum for it to be accepted as a Protocol NEP

For anyone reading this in the future, we did skip the protocol meeting to vote, as this NEP proposes to add a well-known cryptographical operation using audited crates, which means that it has been implicitly reviewed by multiple subject matter experts

@gagdiez gagdiez changed the title P256 host function NEP-635: P256 host function Apr 7, 2026
@gagdiez gagdiez merged commit 801dd8b into master Apr 7, 2026
2 of 3 checks passed
@github-project-automation github-project-automation bot moved this from NEW❗ to Shipped 🚀 in DevRel Apr 7, 2026
@gagdiez gagdiez deleted the p256 branch April 7, 2026 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-NEP A NEAR Enhancement Proposal (NEP). S-voting/needs-wg-voting-indication A NEP in the VOTING stage that needs the working group voting indication. WG-protocol Protocol Standards Work Group should be accountable

Projects

Status: Shipped 🚀
Status: NEW

Development

Successfully merging this pull request may close these issues.

8 participants