Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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,644 changes: 1,320 additions & 324 deletions Cargo.lock

Large diffs are not rendered by default.

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

# cryptography
"cryptography/alt-bn128-g2/pinocchio/program",
"cryptography/bls-key-registry/pinocchio/program",
"cryptography/bls-multisig/pinocchio/program",
"cryptography/bls12-381/pinocchio/program",
"cryptography/encrypted-ballot/pinocchio/program",

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

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

## Cryptography

Each example wraps a cryptographic syscall in a small Pinocchio program. The alt_bn128 G2 (SIMD-0302) and BLS12-381 syscalls run in LiteSVM today but only work on public clusters once their feature gates activate.

### Alt-bn128 G2 operations

Add and scalar-multiply BN254 G2 points with the `sol_alt_bn128_group_op` syscall.

[pinocchio](./cryptography/alt-bn128-g2/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)

### BLS multisig

Verify aggregate BLS signatures over BN254 with a single pairing check — stateless, or against signers stored in a multisig account.

[pinocchio](./cryptography/bls-multisig/pinocchio)

### BLS key registry

Maintain a running aggregate BLS12-381 G2 public key on-chain, adding and removing members with curve syscalls.

[pinocchio](./cryptography/bls-key-registry/pinocchio)

### Encrypted ballot

Fold twisted ElGamal ballot ciphertexts into an encrypted running tally with ristretto255 additions.

[pinocchio](./cryptography/encrypted-ballot/pinocchio)

## Oracles

### pyth
Expand Down
18 changes: 18 additions & 0 deletions cryptography/alt-bn128-g2/pinocchio/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Alt-bn128 G2 operations (Pinocchio)

A stateless program that wraps the BN254 (alt_bn128) G2 group operations added by [SIMD-0302](https://github.com/solana-foundation/solana-improvement-documents/pull/302), via the `sol_alt_bn128_group_op` syscall. Results come back as transaction return data.

| Discriminator | Instruction | Input |
| ------------- | ----------- | --------------------------------------------------- |
| 0 | G2 add | two big-endian G2 points (128 bytes each) |
| 1 | G2 mul | one big-endian G2 point ‖ 32-byte big-endian scalar |

The syscall runs in LiteSVM today but only works on public clusters once the `enable_alt_bn128_g2_syscalls` 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/alt-bn128-g2/pinocchio/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "alt-bn128-g2-pinocchio",
"version": "0.1.0",
"type": "module",
"scripts": {
"test": "mocha --import=tsx -t 1000000 ./tests/alt-bn128-g2.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/alt_bn128_g2_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