Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,577 changes: 1,264 additions & 313 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ members = [
"basics/transfer-sol/anchor/programs/*",
"basics/transfer-sol/asm",

# cryptography
"cryptography/bls12-381/pinocchio/program",
"cryptography/bn254/pinocchio/program",

# tokens
"tokens/create-token/native/program",
"tokens/create-token/pinocchio/program",
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,22 @@ Work with Metaplex compressed NFTs.

[anchor](./compression/cutils/anchor)

## Cryptography

One stateless program per curve, wrapping the raw cryptographic syscalls. These run in LiteSVM today but only work on public clusters once their feature gates activate. Applied examples (multisig, key registry, encrypted ballot) live in the [crypto-primitives-examples](https://github.com/solana-foundation/crypto-primitives-examples) reference repo.

### BN254 (alt_bn128) operations

Add and scalar-multiply G2 points (SIMD-0302) and verify aggregate BLS signatures with a single pairing check, via the `sol_alt_bn128_group_op` syscall.

[pinocchio](./cryptography/bn254/pinocchio)

### BLS12-381 curve operations

Add, subtract, and scalar-multiply BLS12-381 G1 and G2 points with the `sol_curve_group_op` syscall.

[pinocchio](./cryptography/bls12-381/pinocchio)

## Oracles

### pyth
Expand Down
26 changes: 26 additions & 0 deletions cryptography/bls12-381/pinocchio/README.md
Comment thread
dev-jodee marked this conversation as resolved.
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
```
24 changes: 24 additions & 0 deletions cryptography/bls12-381/pinocchio/package.json
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"
}
}
Loading
Loading