Skip to content

Commit 04247d5

Browse files
author
tilo-14
committed
feat: add ZK examples (zk-id, zk-nullifier, zk-merkle-proof)
- Move zk-id from root to zk/ folder - Add zk-nullifier: single and batch (4x) nullifier creation with Groth16 - Add zk-merkle-proof: merkle proof verification with compressed accounts - Update CI to test zk/zk-id, zk/zk-nullifier, zk/zk-merkle-proof
1 parent fa91f4f commit 04247d5

65 files changed

Lines changed: 28419 additions & 61 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/rust-tests.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ jobs:
2929
- counter/native
3030
- counter/pinocchio
3131
- account-comparison
32-
- zk-id
32+
- zk/zk-id
33+
- zk/zk-nullifier
34+
- zk/zk-merkle-proof
3335
- airdrop-implementations/simple-claim/program
3436
include:
3537
- example: basic-operations/native
@@ -51,10 +53,10 @@ jobs:
5153
example: ${{ matrix.example }}
5254
solana-cli-version: ${{ env.SOLANA_CLI_VERSION }}
5355
rust-toolchain: ${{ env.RUST_TOOLCHAIN }}
54-
install-circom: ${{ matrix.example == 'zk-id' }}
56+
install-circom: ${{ startsWith(matrix.example, 'zk/') || startsWith(matrix.example, 'zk/') }}
5557

5658
- name: Setup ZK circuits
57-
if: matrix.example == 'zk-id'
59+
if: startsWith(matrix.example, 'zk/') || startsWith(matrix.example, 'zk/')
5860
working-directory: ${{ matrix.example }}
5961
run: ./scripts/setup.sh
6062

README.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@
1212
For simple client side distribution visit [this example](https://github.com/Lightprotocol/example-token-distribution).
1313

1414
### Basic Operations
15-
- **[create-nullifier](./basic-operations/anchor/create-nullifier)** - Basic Anchor example to create nullifiers.
16-
- **[basic-operations/anchor](./basic-operations/anchor/)** - Anchor program with Rust and TypeScript tests
17-
- **[basic-operations/native-rust](./basic-operations/native-rust/)** - Native Solana program with light-sdk and Rust tests.
1815

19-
Basic Operations include:
20-
- **create** - Initialize a new compressed account.
21-
- **update** - Modify data in an existing compressed account.
22-
- **close** - Clear account data and preserve its address.
23-
- **reinit** - Reinitialize a closed account with the same address.
24-
- **burn** - Permanently delete a compressed account.
16+
- **[create-nullifier](./basic-operations/anchor/create-nullifier)** - Basic Anchor example to create nullifiers for payments.
17+
- **create** - Initialize a new compressed account
18+
- [Anchor](./basic-operations/anchor/create) | [Native](./basic-operations/native/programs/create)
19+
- **update** - Modify data in an existing compressed account
20+
- [Anchor](./basic-operations/anchor/update) | [Native](./basic-operations/native/programs/update)
21+
- **close** - Clear account data and preserve its address
22+
- [Anchor](./basic-operations/anchor/close) | [Native](./basic-operations/native/programs/close)
23+
- **reinit** - Reinitialize a closed account with the same address
24+
- [Anchor](./basic-operations/anchor/reinit) | [Native](./basic-operations/native/programs/reinit)
25+
- **burn** - Permanently delete a compressed account
26+
- [Anchor](./basic-operations/anchor/burn) | [Native](./basic-operations/native/programs/burn)
2527

2628
### Counter Program
2729

@@ -45,9 +47,17 @@ Full compressed account lifecycle (create, increment, decrement, reset, close):
4547

4648
- **[account-comparison](./account-comparison/)** - Compare compressed vs regular Solana accounts.
4749

48-
### zk-id Program
50+
### ZK Programs
4951

50-
- **[zk-id](./zk-id)** - A minimal zk id Solana program that uses zero-knowledge proofs for identity verification with compressed accounts.
52+
**Full Examples:**
53+
54+
- **[zk-id](./zk/zk-id)** - Identity verification using Groth16 proofs. Issuers create credentials; users prove ownership without revealing the credential.
55+
- **[shielded-pool](./zk/shielded-pool)** - Privacy-preserving deposit/withdrawal .
56+
57+
**Basic Examples:**
58+
59+
- **[zk-nullifier](./zk/zk-nullifier)** - Creates one or four nullifiers. Uses Groth16 proofs and compressed accounts.
60+
- **[zk-merkle-proof](./zk/zk-merkle-proof)** - Creates compressed accounts and verifies with Groth16 proofs (without nullifier).
5161

5262

5363
## Light Protocol dependencies

zk/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# ZK Examples
2+
3+
Building a private Solana program requires a Merkle tree to store state, a way to track nullifiers, and an indexer to serve Merkle proofs.
4+
5+
You can use Light to:
6+
- Track and store nullifiers rent-free in indexed address Merkle trees
7+
- Store state rent-free in indexed state Merkle trees as compressed accounts
8+
9+
[Learn more in the documentation](https://www.zkcompression.com/zk/overview)
10+
11+
## Examples
12+
13+
**Full Examples:**
14+
15+
- **[zk-id](./zk/zk-id)** - Identity verification using Groth16 proofs. Issuers create credentials; users prove ownership without revealing the credential.
16+
- **[shielded-pool](./zk/shielded-pool)** - Privacy-preserving deposit/withdrawal .
17+
18+
**Basic Examples:**
19+
20+
- **[zk-nullifier](./zk/zk-nullifier)** - Creates one or four nullifiers. Uses Groth16 proofs and compressed accounts.
21+
- **[zk-merkle-proof](./zk/zk-merkle-proof)** - Creates compressed accounts and verifies with Groth16 proofs (without nullifier).
File renamed without changes.

zk/zk-id/Anchor.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[toolchain]
2+
anchor_version = "0.31.1"
3+
4+
[features]
5+
resolution = true
6+
skip-lint = false
7+
8+
[workspace]
9+
members = ["."]
10+
11+
[programs.localnet]
12+
zk_id = "HNqStLMpNuNJqhBF1FbGTKHEFbBLJmq8RdJJmZKWz6jH"
13+
14+
[registry]
15+
url = "https://api.apr.dev"
16+
17+
[provider]
18+
cluster = "localnet"
19+
wallet = "~/.config/solana/id.json"
20+
21+
[scripts]
22+
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
23+
File renamed without changes.
File renamed without changes.

zk-id/Cargo.toml renamed to zk/zk-id/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ groth16-solana = { git = "https://github.com/Lightprotocol/groth16-solana", feat
3737
[target.'cfg(not(target_os = "solana"))'.build-dependencies]
3838
rust-witness = "0.1"
3939
groth16-solana = { git = "https://github.com/Lightprotocol/groth16-solana", features = ["vk"], rev = "66c0dc87d0808c4d2aadb53c61435b6edb8ddfd9" }
40+
41+
[profile.release]
42+
overflow-checks = true

zk-id/README.md renamed to zk/zk-id/README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,22 @@ This script will:
6767

6868
## Build and Test
6969

70+
**Build:**
7071
```bash
71-
# Build the program
7272
cargo build-sbf
73+
```
7374

74-
# Run tests and see tx
75+
**Rust tests** (full ZK verification flow):
76+
```bash
7577
RUST_BACKTRACE=1 cargo test-sbf -- --nocapture
7678
```
7779

80+
**TypeScript tests** (requires local validator with Light Protocol):
81+
```bash
82+
npm install
83+
npm test
84+
```
85+
7886
## Structure
7987

8088
```
@@ -89,7 +97,8 @@ zk-id/
8997
├── src/
9098
│ └── lib.rs # Solana program implementation
9199
└── tests/
92-
└── test.rs # Integration tests
100+
├── test.rs # Rust integration tests
101+
└── zk-id.ts # TypeScript integration tests
93102
```
94103

95104
## Cleaning Build Artifacts
File renamed without changes.

0 commit comments

Comments
 (0)