Skip to content

feat: add cryptography examples for bn254 and bls12-381 syscalls - #662

Merged
dev-jodee merged 6 commits into
mainfrom
feat/cryptography-examples
Aug 3, 2026
Merged

feat: add cryptography examples for bn254 and bls12-381 syscalls#662
dev-jodee merged 6 commits into
mainfrom
feat/cryptography-examples

Conversation

@dev-jodee

@dev-jodee dev-jodee commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • New 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)
  • Results return as transaction return data; every instruction is exercised with known-answer vectors (generator multiples, aggregate BLS signatures) in both mocha+@solana/kit+litesvm TypeScript tests and Rust litesvm integration tests
  • Applied examples (multisig, key registry, encrypted ballot) were deliberately left out to keep the category to simple syscall demos — they remain in the upstream crypto-primitives-examples repo, linked from the category README
  • Rust tests pin litesvm = "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 rejoin litesvm.workspace = true
  • Cargo.lock additions are pinned to match litesvm's own lockfile so the solana crate family stays on one wincode line; letting them float to newest breaks solana-instruction/solana-message compilation

Test Plan

  • pnpm build-and-test in each cryptography/*/pinocchio (TS, LiteSVM)
  • cargo test --manifest-path=cryptography/<name>/pinocchio/program/Cargo.toml (Rust, litesvm 0.15)
  • cargo clippy --all-targets -- -D warnings on both crates; cargo check --workspace; tsc --noEmit per project
  • Verified tests fail loudly by corrupting a known-answer vector once on each layer

Notes

  • The new syscalls are feature-gated on public clusters (enable_alt_bn128_g2_syscalls, enable_bls12_381_syscall); READMEs call this out. LiteSVM has them enabled by default.

…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-apps

greptile-apps Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds stateless Pinocchio syscall demonstrations for the BN254 and BLS12-381 curves.

  • Implements BN254 G2 addition, multiplication, and aggregate verification through pairing.
  • Implements BLS12-381 G1/G2 addition, subtraction, and multiplication.
  • Returns syscall results through transaction return data and adds TypeScript and Rust known-answer tests.
  • Removes the previously reviewed stateful multisig and key-registry examples, eliminating their unauthenticated mutation paths.
  • Adds project documentation and pins LiteSVM 0.15 for syscall support.

Confidence Score: 5/5

The 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

Filename Overview
cryptography/bn254/pinocchio/program/src/lib.rs Adds a stateless dispatcher for BN254 G2 arithmetic and pairing-based aggregate verification, with no account mutation.
cryptography/bls12-381/pinocchio/program/src/lib.rs Adds stateless wrappers for BLS12-381 G1/G2 arithmetic syscalls and returns their results as transaction data.
cryptography/bn254/pinocchio/program/tests/test.rs Exercises the BN254 syscall wrappers with LiteSVM known-answer vectors.
cryptography/bls12-381/pinocchio/program/tests/test.rs Exercises the BLS12-381 syscall wrappers with LiteSVM known-answer vectors.
Cargo.lock Locks LiteSVM 0.15 and its Agave/Solana dependency family alongside the existing workspace dependency versions.

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
Loading

Reviews (6): Last reviewed commit: "docs(cryptography): reviewer-suggested R..." | Re-trigger Greptile

Comment thread cryptography/bls-key-registry/pinocchio/program/src/lib.rs Outdated
Comment thread cryptography/bls-multisig/pinocchio/program/src/lib.rs Outdated
…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.
@dev-jodee dev-jodee changed the title feat: add cryptography examples for bn254 G2, bls12-381, and ristretto syscalls feat: add cryptography examples for bn254 and bls12-381 syscalls Aug 3, 2026
@dev-jodee

Copy link
Copy Markdown
Collaborator Author

Restructured in a5bb894: the category is now one stateless raw-syscall program per primitive — bn254 (G2 ops + aggregate BLS verify, so the pairing op stays covered) and bls12-381 (group ops). The stateful application examples (bls-multisig, bls-key-registry, encrypted-ballot) were removed to keep the category to simple syscall demos; they remain available in crypto-primitives-examples. This also makes both earlier security comments moot — the flagged code no longer exists.

@dev-jodee
dev-jodee requested a review from amilz August 3, 2026 18:15
amilz
amilz previously approved these changes Aug 3, 2026

@amilz amilz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good.

  • a couple of TS codec suggestions
  • a couple of thoughts on more detail for readme

Comment thread cryptography/bn254/pinocchio/tests/bn254.test.ts Outdated
Comment thread cryptography/bls12-381/pinocchio/tests/bls12-381.test.ts Outdated
Comment thread cryptography/bls12-381/pinocchio/program/Cargo.toml
Comment thread cryptography/bn254/pinocchio/README.md
Comment thread cryptography/bls12-381/pinocchio/README.md
…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.
@dev-jodee
dev-jodee merged commit e2b17c4 into main Aug 3, 2026
29 checks passed
@dev-jodee
dev-jodee deleted the feat/cryptography-examples branch August 3, 2026 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants