Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIMD-0075: Precompile for Secp256r1 #3152

Merged
merged 75 commits into from
Nov 15, 2024

Conversation

0xRigel
Copy link

@0xRigel 0xRigel commented Oct 13, 2024

Problem

There currently isn't support for signature verification of signatures on the NIST-P256 curve (primary curve used by Passkeys). Motivation and details can be found in SIMD-0075

Summary of Changes

  • Adds a precompile for secp256r1 signature verification that implements the structure defined in SIMD-0075 and that abides by the rules set forth in SIMD-0152
  • Adds a separate secp256r1 crate to avoid further bloat of solana_sdk
  • Adds tests to check functionality of the precompile, as well as the computed curve order values

@mergify mergify bot requested a review from a team October 13, 2024 16:26
@0xRigel 0xRigel force-pushed the secp256r1-precompile branch 2 times, most recently from 0f4876e to 8f18340 Compare October 13, 2024 17:29
@0xRigel 0xRigel force-pushed the secp256r1-precompile branch from 8f18340 to 4c753ff Compare October 13, 2024 17:29
@kevinheavey kevinheavey added the CI Pull Request is ready to enter CI label Oct 15, 2024
@anza-team anza-team removed the CI Pull Request is ready to enter CI label Oct 15, 2024
@samkim-crypto samkim-crypto self-requested a review October 16, 2024 08:20
@0xRigel 0xRigel marked this pull request as ready for review October 16, 2024 17:28
Copy link

@buffalojoec buffalojoec left a comment

Choose a reason for hiding this comment

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

I think I looked at just about everything except the actual cryptography. I saw @samkim-crypto self-requested review.

I spotted a handful of small nits, mostly around naming and semantics. Let me know what you think. Other than that nice work!

@samkim-crypto samkim-crypto added the CI Pull Request is ready to enter CI label Oct 22, 2024
@0xRigel
Copy link
Author

0xRigel commented Nov 15, 2024

Massive thank you @joncinque for the in depth review ❤️
I think I've addressed everything except the lock file changes in programs/sbf/Cargo.lock. Not sure why exactly the CI yells at me if i leave it unchanged.

Let me know if I missed anything 🫶

@jordaaash jordaaash added the CI Pull Request is ready to enter CI label Nov 15, 2024
@anza-team anza-team removed the CI Pull Request is ready to enter CI label Nov 15, 2024
@jordaaash jordaaash added the CI Pull Request is ready to enter CI label Nov 15, 2024
@anza-team anza-team removed the CI Pull Request is ready to enter CI label Nov 15, 2024
@jordaaash jordaaash added the CI Pull Request is ready to enter CI label Nov 15, 2024
@anza-team anza-team removed the CI Pull Request is ready to enter CI label Nov 15, 2024
Copy link

@samkim-crypto samkim-crypto left a comment

Choose a reason for hiding this comment

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

Looks good to me! I asked @yihau to help out with the crate publishing. In the meanwhile, @buffalojoec, @kevinheavey, @0x0ece, @joncinque, if you have any last comments please let us know. Otherwise, I'll go ahead and merge it once the crate is published.

@samkim-crypto samkim-crypto merged commit da4f55e into anza-xyz:master Nov 15, 2024
54 checks passed
@samkim-crypto samkim-crypto added the v2.1 Backport to v2.1 branch label Nov 15, 2024
Copy link

mergify bot commented Nov 15, 2024

Backports to the beta branch are to be avoided unless absolutely necessary for fixing bugs, security issues, and perf regressions. Changes intended for backport should be structured such that a minimum effective diff can be committed separately from any refactoring, plumbing, cleanup, etc that are not strictly necessary to achieve the goal. Any of the latter should go only into master and ride the normal stabilization schedule. Exceptions include CI/metrics changes, CLI improvements and documentation updates on a case by case basis.

mergify bot pushed a commit that referenced this pull request Nov 15, 2024
* feat: secp256r1 precompile

* add: num_signatures == 0 check from SIMD-0152

* rm: unnecessary comment

* fix: legacy numeric constant

* CI/fix: compilation for wasm32 target

* Extract secp256r1 crate

* rm: unnecessary import

* update: sbf/Cargo.lock

* rm: unnecesary re-exports

* add: secp256r1 precompile to docs

* add: docs/description to sdk/program/src/lib.rs

* fix: alpha sort deps

* fixes

* docs fixes

* add: solana-instruction std feature to deps

* fix: lockfile from rebase

* fix: target architecture

* fix: workflow for client_target android

* add: sudo to workflow perl install

* fix: Cargo toml workspace member

* modify: ranlib path in client-targets.yaml

* fix: secp256r1/Cargo.toml formatting

* add: openssl feature

* fixes

* add: precompile signature range error

* more adjustments

* change: feature id

* fix: cargo format

* Revert "add: precompile signature range error"

This reverts commit fdf7673.

* fix: cargo sanity

* fix: client target openssl dep

* fix: 31 byte r,s support in new_secp256r1_instruction

* update: Cargo.lock

* fix: unchecked math in new_secp256r1_instruction

* fixes & increased test coverage

* add: solana-sdk/openssl to all release binaries

* update: comment to make openssl feature more clear

* add: solana-sdk/openssl feature to dependencies

* add: solana-sdk/openssl feature to dependencies

* merge: master into secp256r1-precompile

* fix: test-validator formatting

* Revert "add: solana-sdk/openssl to all release binaries"

This reverts commit 5c66b50.

* add: reserved key for secp256r1 program

* modify: client-targets.yaml

* modify: client/Cargo.toml solana-sdk dep

* modify: ledger-tool/Cargo.toml solana-sdk

* modify: test-validator/Cargo.toml solana-sdk dep

* modify: validator/Cargo.toml solana-sdk dep

* change: openssl feature to openssl-vendored

* remove: solana-sdk dep from sdk/program

* refactor: secp256r1 directory name

* fmt

* cargo.lock files

* revert: rustc-demangle bump

* cargo lock sanity

* fix: faulty feature-set merge

* fix: reserved keys pending feature id

---------

Co-authored-by: Iceomatic <89707822+iceomatic@users.noreply.github.com>
(cherry picked from commit da4f55e)

# Conflicts:
#	Cargo.lock
#	Cargo.toml
#	ledger-tool/Cargo.toml
#	programs/sbf/Cargo.lock
#	sdk/Cargo.toml
#	sdk/feature-set/src/lib.rs
#	sdk/reserved-account-keys/Cargo.toml
#	sdk/src/reserved_account_keys.rs
@kevinheavey
Copy link

8 hours wasn't really enough notice, this still needed changes

@@ -20,6 +20,7 @@ solana-frozen-abi-macro = { workspace = true, optional = true, features = [
] }
solana-pubkey = { workspace = true, default-features = false }
solana-sdk-ids = { workspace = true }
solana-secp256r1-program = { workspace = true }

Choose a reason for hiding this comment

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

I would have asked you to put the secp256r1 program ID in solana-sdk-ids so solana-reserved-account-keys wouldn't end up with a solana-secp256r1-program dependency

Copy link
Author

Choose a reason for hiding this comment

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

Will coordinate with sam to make sure #3663 is backported together with this 👍

Choose a reason for hiding this comment

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

Looks like we don't have to backport since the sdk-ids split isn't in 2.1. Will just get this merged into master 🫡

@kevinheavey
Copy link

#3663

samkim-crypto pushed a commit that referenced this pull request Nov 15, 2024
* SIMD-0075: Precompile for Secp256r1 (#3152)

* feat: secp256r1 precompile

* add: num_signatures == 0 check from SIMD-0152

* rm: unnecessary comment

* fix: legacy numeric constant

* CI/fix: compilation for wasm32 target

* Extract secp256r1 crate

* rm: unnecessary import

* update: sbf/Cargo.lock

* rm: unnecesary re-exports

* add: secp256r1 precompile to docs

* add: docs/description to sdk/program/src/lib.rs

* fix: alpha sort deps

* fixes

* docs fixes

* add: solana-instruction std feature to deps

* fix: lockfile from rebase

* fix: target architecture

* fix: workflow for client_target android

* add: sudo to workflow perl install

* fix: Cargo toml workspace member

* modify: ranlib path in client-targets.yaml

* fix: secp256r1/Cargo.toml formatting

* add: openssl feature

* fixes

* add: precompile signature range error

* more adjustments

* change: feature id

* fix: cargo format

* Revert "add: precompile signature range error"

This reverts commit fdf7673.

* fix: cargo sanity

* fix: client target openssl dep

* fix: 31 byte r,s support in new_secp256r1_instruction

* update: Cargo.lock

* fix: unchecked math in new_secp256r1_instruction

* fixes & increased test coverage

* add: solana-sdk/openssl to all release binaries

* update: comment to make openssl feature more clear

* add: solana-sdk/openssl feature to dependencies

* add: solana-sdk/openssl feature to dependencies

* merge: master into secp256r1-precompile

* fix: test-validator formatting

* Revert "add: solana-sdk/openssl to all release binaries"

This reverts commit 5c66b50.

* add: reserved key for secp256r1 program

* modify: client-targets.yaml

* modify: client/Cargo.toml solana-sdk dep

* modify: ledger-tool/Cargo.toml solana-sdk

* modify: test-validator/Cargo.toml solana-sdk dep

* modify: validator/Cargo.toml solana-sdk dep

* change: openssl feature to openssl-vendored

* remove: solana-sdk dep from sdk/program

* refactor: secp256r1 directory name

* fmt

* cargo.lock files

* revert: rustc-demangle bump

* cargo lock sanity

* fix: faulty feature-set merge

* fix: reserved keys pending feature id

---------

Co-authored-by: Iceomatic <89707822+iceomatic@users.noreply.github.com>
(cherry picked from commit da4f55e)

# Conflicts:
#	Cargo.lock
#	Cargo.toml
#	ledger-tool/Cargo.toml
#	programs/sbf/Cargo.lock
#	sdk/Cargo.toml
#	sdk/feature-set/src/lib.rs
#	sdk/reserved-account-keys/Cargo.toml
#	sdk/src/reserved_account_keys.rs

* Fix merge conflicts

---------

Co-authored-by: Orion <89707822+0xRigel@users.noreply.github.com>
Co-authored-by: Jon C <me@jonc.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants