-
Notifications
You must be signed in to change notification settings - Fork 529
feat: add cryptography examples for bn254 and bls12-381 syscalls #662
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8da1488
feat(cryptography): add crypto syscall examples ported from crypto-pr…
dev-jodee 9bd1f0d
docs(cryptography): call out deliberate lack of access control in sta…
dev-jodee a5bb894
refactor(cryptography): one stateless program per curve
dev-jodee 48a0bb6
docs(cryptography): document size, op-code, and curve-id constants
dev-jodee 68e1cd3
docs(cryptography): annotate test discriminator and error-code constants
dev-jodee 93b105c
docs(cryptography): reviewer-suggested README intros and kit codecs i…
dev-jodee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # BLS12-381 curve operations (Pinocchio) | ||
|
|
||
| BLS12-381 is a modern elliptic curve designed for _pairings_ — a special operation that powers short aggregate signatures (many signers, one small signature to check) and zero-knowledge proofs, and it's the curve Ethereum and Solana's upcoming consensus both rely on. The underlying point math (adding two points, subtracting, or multiplying a point by a number) is far too expensive to run in ordinary program code without exhausting Solana's compute budget, so the runtime exposes it as a native building block: the `sol_curve_group_op` syscall. This example is a thin, stateless wrapper over that syscall — you pass in points and scalars, it returns the result as transaction return data — so you can see the raw curve operations by themselves before combining them into something like signature verification. | ||
|
|
||
| Learn more: [Solana's BLS12-381 syscall spec (SIMD-0388)](https://github.com/solana-foundation/solana-improvement-documents/blob/main/proposals/0388-bls12-381-syscalls.md) · [BLS12-381 for the rest of us (a beginner-friendly explainer)](https://hackmd.io/@benjaminion/bls12-381) | ||
|
|
||
| Points are big-endian: G1 = 96 bytes, G2 = 192 bytes; scalars are 32 bytes big-endian and go first in the instruction data. | ||
|
|
||
| | Discriminator | Instruction | Input | | ||
| | ------------- | ----------- | -------------- | | ||
| | 0 | G1 add | point ‖ point | | ||
| | 1 | G1 sub | point ‖ point | | ||
| | 2 | G1 mul | scalar ‖ point | | ||
| | 3 | G2 add | point ‖ point | | ||
| | 4 | G2 sub | point ‖ point | | ||
| | 5 | G2 mul | scalar ‖ point | | ||
|
|
||
| The syscall runs in LiteSVM today but only works on public clusters once the `enable_bls12_381_syscall` feature gate activates. | ||
|
|
||
| ## Test | ||
|
|
||
| ```sh | ||
| pnpm install | ||
| pnpm build-and-test # TypeScript tests (mocha + LiteSVM) | ||
| cargo test --manifest-path=./program/Cargo.toml # Rust tests (litesvm), after build-and-test | ||
| ``` |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "name": "bls12-381-pinocchio", | ||
| "version": "0.1.0", | ||
| "type": "module", | ||
| "scripts": { | ||
| "test": "mocha --import=tsx -t 1000000 ./tests/bls12-381.test.ts", | ||
| "build-and-test": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./tests/fixtures && pnpm test", | ||
| "build": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so", | ||
| "deploy": "solana program deploy ./program/target/so/bls12_381_pinocchio_program.so" | ||
| }, | ||
| "dependencies": { | ||
| "@solana/kit": "^7.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/chai": "^5.2.3", | ||
| "@types/mocha": "^10.0.10", | ||
| "@types/node": "^26.1.0", | ||
| "chai": "^6.2.2", | ||
| "litesvm": "^1.3.0", | ||
| "mocha": "^11.7.5", | ||
| "tsx": "^4.19.2", | ||
| "typescript": "^5.9.3" | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.