feat: add cryptography examples for bn254 and bls12-381 syscalls - #662
Conversation
…imitives Five standalone Pinocchio examples in a new cryptography/ category: alt-bn128-g2 (SIMD-0302 G2 add/mul), bls12-381 (G1/G2 group ops), bls-multisig (aggregate BLS verify over BN254, stateless + stateful), bls-key-registry (running aggregate G2 key), and encrypted-ballot (twisted ElGamal tally on ristretto255). Each example carries mocha+kit+litesvm TypeScript tests and Rust integration tests on litesvm 0.15, pinned inline because the workspace litesvm 0.11 predates the alt_bn128 G2 and bls12-381 syscalls. The Cargo.lock additions are aligned to litesvm's own lockfile to keep the solana crate family on one wincode line.
Greptile SummaryAdds stateless Pinocchio syscall demonstrations for the BN254 and BLS12-381 curves.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; both previously reported unauthenticated mutation paths were removed with their stateful examples, and the replacement programs do not access or mutate accounts. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart LR
I[Instruction data] --> D{Primitive discriminator}
D -->|BN254| BN[BN254 syscall]
D -->|BLS12-381| BLS[BLS12-381 syscall]
BN --> R[Transaction return data]
BLS --> R
Reviews (6): Last reviewed commit: "docs(cryptography): reviewer-suggested R..." | Re-trigger Greptile |
…teful examples The bls-multisig and bls-key-registry examples focus on the pairing and curve syscalls; access control is out of scope. Say so explicitly in the doc comments and READMEs so nobody ships the pattern as-is. Addresses review feedback on the unauthenticated mutation paths.
Cut the category down to raw syscall demos: bn254 (G2 add/mul plus aggregate BLS verify, keeping the pairing op covered) and bls12-381 (G1/G2 group ops). The stateful application examples (multisig, key registry, encrypted ballot) added account plumbing without teaching anything new about the syscalls; they stay available in the upstream crypto-primitives-examples repo, now linked from the category README. Renames alt-bn128-g2 to bn254 to match the primitive naming.
|
Restructured in a5bb894: the category is now one stateless raw-syscall program per primitive — |
amilz
left a comment
There was a problem hiding this comment.
Looks good.
- a couple of TS codec suggestions
- a couple of thoughts on more detail for readme
…n tests Adopt amilz's beginner-friendly curve intros with links to the merged SIMD-0302/0388 specs and EIP-197, and switch the TypeScript tests to kit codecs: getBase16Codec for hex vectors and a struct codec spelling out the aggregate-verify wire layout.
Summary
cryptography/category: one stateless Pinocchio program per crypto primitive, wrapping the raw syscalls — bn254 (SIMD-0302 G2 add/mul + aggregate BLS verification via the pairing op) and bls12-381 (G1/G2 add/sub/mul)@solana/kit+litesvm TypeScript tests and Rust litesvm integration testslitesvm = "0.15"inline instead of the workspace ref: workspace litesvm 0.11 sits on agave 3.1, which predates these syscalls. Follow-up: bump the workspace to 0.15 and rejoinlitesvm.workspace = truesolana-instruction/solana-messagecompilationTest Plan
pnpm build-and-testin eachcryptography/*/pinocchio(TS, LiteSVM)cargo test --manifest-path=cryptography/<name>/pinocchio/program/Cargo.toml(Rust, litesvm 0.15)cargo clippy --all-targets -- -D warningson both crates;cargo check --workspace;tsc --noEmitper projectNotes
enable_alt_bn128_g2_syscalls,enable_bls12_381_syscall); READMEs call this out. LiteSVM has them enabled by default.