Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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
11 changes: 9 additions & 2 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ runs:

- name: Cache AVM and Anchor
if: inputs.node-version != ''
id: cache-avm
uses: actions/cache@v4
with:
path: |
Expand All @@ -78,6 +79,7 @@ runs:

- name: Cache Photon indexer
if: inputs.photon-indexer == 'true'
id: cache-photon
uses: actions/cache@v4
with:
path: ~/.cargo/bin/photon
Expand All @@ -97,13 +99,18 @@ runs:
fi

- name: Install Anchor CLI
if: inputs.node-version != ''
if: inputs.node-version != '' && steps.cache-avm.outputs.cache-hit != 'true'
shell: bash
run: |
cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
avm install ${{ inputs.anchor-version }}
avm use ${{ inputs.anchor-version }}

- name: Set Anchor version
if: inputs.node-version != '' && steps.cache-avm.outputs.cache-hit == 'true'
shell: bash
run: avm use ${{ inputs.anchor-version }}

- name: Install Light CLI
shell: bash
run: npm install -g @lightprotocol/zk-compression-cli@0.27.1-alpha.2
Expand Down Expand Up @@ -137,7 +144,7 @@ runs:
run: npm install -g snarkjs

- name: Install Photon indexer
if: inputs.photon-indexer == 'true'
if: inputs.photon-indexer == 'true' && steps.cache-photon.outputs.cache-hit != 'true'
shell: bash
env:
RUSTFLAGS: "-A dead-code"
Expand Down
7 changes: 0 additions & 7 deletions .github/workflows/rust-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ jobs:
- counter/native
- counter/pinocchio
- account-comparison
- zk-id
- airdrop-implementations/simple-claim/program
include:
- example: basic-operations/native
Expand All @@ -51,12 +50,6 @@ jobs:
example: ${{ matrix.example }}
solana-cli-version: ${{ env.SOLANA_CLI_VERSION }}
rust-toolchain: ${{ env.RUST_TOOLCHAIN }}
install-circom: ${{ matrix.example == 'zk-id' }}

- name: Setup ZK circuits
if: matrix.example == 'zk-id'
working-directory: ${{ matrix.example }}
run: ./scripts/setup.sh

- name: Build and test
working-directory: ${{ matrix.example }}
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/typescript-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:
- basic-operations/anchor/update
- basic-operations/anchor/close
- basic-operations/anchor/reinit
- zk/zk-id
- zk/nullifier
steps:
- uses: actions/checkout@v4

Expand All @@ -45,6 +47,12 @@ jobs:
solana-cli-version: ${{ env.SOLANA_CLI_VERSION }}
rust-toolchain: ${{ env.RUST_TOOLCHAIN }}
photon-indexer: "true"
install-circom: ${{ matrix.example == 'zk/zk-id' }}

- name: Setup ZK circuits
if: matrix.example == 'zk/zk-id'
working-directory: ${{ matrix.example }}
run: ./scripts/setup.sh

- name: Install dependencies
working-directory: ${{ matrix.example }}
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ test-ledger
.claude
build
pot

# ZK examples - not ready
zk/mixer/
zk/shielded-pool/
zk/zk-merkle-proof/
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@
For simple client side distribution visit [this example](https://github.com/Lightprotocol/example-token-distribution).

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

Basic Operations include:
- **create** - Initialize a new compressed account.
- **update** - Modify data in an existing compressed account.
- **close** - Clear account data and preserve its address.
- **reinit** - Reinitialize a closed account with the same address.
- **burn** - Permanently delete a compressed account.
- **[create-nullifier](./basic-operations/anchor/create-nullifier)** - Basic Anchor example to create nullifiers for payments.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
- **create** - Initialize a new compressed account
- [Anchor](./basic-operations/anchor/create) | [Native](./basic-operations/native/programs/create)
- **update** - Modify data in an existing compressed account
- [Anchor](./basic-operations/anchor/update) | [Native](./basic-operations/native/programs/update)
- **close** - Clear account data and preserve its address
- [Anchor](./basic-operations/anchor/close) | [Native](./basic-operations/native/programs/close)
Comment on lines +21 to +22
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Enhance the close operation description to mention rent reclamation.

The description should highlight that close operations reclaim rent, which is a key benefit of this operation compared to burn.

Based on learnings, close operations preserve the account address for potential reinitialization while reclaiming rent.

📝 Suggested enhancement
-- **close** - Clear account data and preserve its address
+- **close** - Reclaim rent and preserve the account address for reinitialization
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- **close** - Clear account data and preserve its address
- [Anchor](./basic-operations/anchor/close) | [Native](./basic-operations/native/programs/close)
- **close** - Reclaim rent and preserve the account address for reinitialization
- [Anchor](./basic-operations/anchor/close) | [Native](./basic-operations/native/programs/close)
🤖 Prompt for AI Agents
In @README.md around lines 21 - 22, Update the README entry for the "close"
operation to state that it not only clears account data and preserves the
account address but also reclaims the account's rent (freeing lamports) —
highlight that this distinguishes close from burn and that the preserved address
can be reused for reinitialization; change the line starting with "**close** -
Clear account data and preserve its address" to include "reclaims rent" and a
short contrast to "burn" while leaving the Anchor and Native links intact.

- **reinit** - Reinitialize a closed account with the same address
- [Anchor](./basic-operations/anchor/reinit) | [Native](./basic-operations/native/programs/reinit)
- **burn** - Permanently delete a compressed account
- [Anchor](./basic-operations/anchor/burn) | [Native](./basic-operations/native/programs/burn)
Comment on lines +25 to +26
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Clarify that burn prevents address reuse.

The description should explicitly state that burned accounts cannot have their addresses reused, which is the critical distinction from close operations.

Based on learnings, burn operations permanently delete accounts so addresses cannot be reused, unlike close operations which preserve addresses for reinitialization.

📝 Suggested enhancement
-- **burn** - Permanently delete a compressed account
+- **burn** - Permanently delete a compressed account (address cannot be reused)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- **burn** - Permanently delete a compressed account
- [Anchor](./basic-operations/anchor/burn) | [Native](./basic-operations/native/programs/burn)
- **burn** - Permanently delete a compressed account (address cannot be reused)
- [Anchor](./basic-operations/anchor/burn) | [Native](./basic-operations/native/programs/burn)
🤖 Prompt for AI Agents
In @README.md around lines 25 - 26, Update the README entry for the "burn"
operation to explicitly state that burning permanently deletes a compressed
account and prevents the account address from being reused; reference the "burn"
operation name (and its links "Anchor" and "Native") and add a short contrasting
clause noting that this differs from "close" operations which allow address
reinitialization.


### Counter Program

Expand All @@ -45,9 +47,12 @@ Full compressed account lifecycle (create, increment, decrement, reset, close):

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

### zk-id Program
### ZK Programs


- **[zk-id](./zk/zk-id)** - Identity verification using Groth16 proofs. Issuers create credentials; users prove ownership without revealing the credential.
- **[nullifier](./zk/nullifier)** - Simple Program to Create Nullifiers. Requires no custom circuit.

- **[zk-id](./zk-id)** - A minimal zk id Solana program that uses zero-knowledge proofs for identity verification with compressed accounts.


## Light Protocol dependencies
Expand Down
22 changes: 22 additions & 0 deletions scripts/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ cargo +nightly fmt --manifest-path counter/anchor/Cargo.toml
cargo +nightly fmt --manifest-path counter/native/Cargo.toml
cargo +nightly fmt --manifest-path counter/pinocchio/Cargo.toml
cargo +nightly fmt --manifest-path account-comparison/Cargo.toml
cargo +nightly fmt --manifest-path zk/nullifier/Cargo.toml
cargo +nightly fmt --manifest-path zk/zk-id/Cargo.toml

# Run clippy on each project individually
cargo clippy --manifest-path create-and-update/Cargo.toml \
Expand Down Expand Up @@ -59,3 +61,23 @@ cargo clippy --manifest-path account-comparison/Cargo.toml \
-A unexpected-cfgs \
-A clippy::doc_lazy_continuation \
-D warnings

cargo clippy --manifest-path zk/nullifier/Cargo.toml \
--no-deps \
--all-features \
-- -A clippy::result_large_err \
-A clippy::empty-docs \
-A clippy::to-string-trait-impl \
-A unexpected-cfgs \
-A clippy::doc_lazy_continuation \
-D warnings

cargo clippy --manifest-path zk/zk-id/Cargo.toml \
--no-deps \
--all-features \
-- -A clippy::result_large_err \
-A clippy::empty-docs \
-A clippy::to-string-trait-impl \
-A unexpected-cfgs \
-A clippy::doc_lazy_continuation \
-D warnings
12 changes: 12 additions & 0 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ cd counter/pinocchio && cargo fmt --check && cd ../..
echo "Checking account-comparison..."
cd account-comparison && cargo fmt --check && cd ..

echo "Checking zk/nullifier..."
cd zk/nullifier && cargo fmt --check && cd ../..

echo "Checking zk/zk-id..."
cd zk/zk-id && cargo fmt --check && cd ../..

echo "Running clippy..."

# Run clippy for each crate
Expand All @@ -38,4 +44,10 @@ cargo clippy --manifest-path counter/pinocchio/Cargo.toml --all-targets --all-fe
echo "Running clippy on account-comparison..."
cargo clippy --manifest-path account-comparison/Cargo.toml --all-targets --all-features -- -D warnings

echo "Running clippy on zk/nullifier..."
cargo clippy --manifest-path zk/nullifier/Cargo.toml --all-targets --all-features -- -D warnings

echo "Running clippy on zk/zk-id..."
cargo clippy --manifest-path zk/zk-id/Cargo.toml --all-targets --all-features -- -D warnings

echo "Lint checks completed successfully!"
25 changes: 0 additions & 25 deletions zk-id/src/verifying_key.rs

This file was deleted.

144 changes: 144 additions & 0 deletions zk/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Makefile for building and testing all ZK examples
# Usage:
# make all - Build and test all examples
# make build - Build all Solana programs
# make test-rust - Run all Rust tests
# make test-ts - Run all TypeScript tests
# make clean - Clean all build artifacts

SHELL := /bin/bash

# ZK example directories
ZK_EXAMPLES := nullifier zk-id

.PHONY: all build deploy test-rust test-ts clean setup help $(ZK_EXAMPLES)

help:
@echo "ZK Examples Makefile"
@echo ""
@echo "Usage:"
@echo " make all - Build and test all examples (Rust + TypeScript)"
@echo " make build - Build all Solana programs"
@echo " make deploy - Deploy all programs to validator (builds first)"
@echo " make test-rust - Run all Rust tests (cargo test-sbf)"
@echo " make test-ts - Run all TypeScript tests (deploys first)"
@echo " make setup - Setup circuits for all examples"
@echo " make clean - Clean all build artifacts"
@echo ""
@echo "Individual examples:"
@echo " make nullifier - Build and test nullifier"
@echo " make zk-id - Build and test zk-id"

all: build test-rust test-ts
@echo "All examples built and tested successfully!"

build:
@echo "Building all ZK examples..."
@for dir in $(ZK_EXAMPLES); do \
echo "Building $$dir..."; \
cd $$dir && cargo build-sbf && cd ..; \
if [ $$? -ne 0 ]; then \
echo "Failed to build $$dir"; \
exit 1; \
fi; \
echo "$$dir built successfully"; \
done
@echo "All programs built successfully!"

deploy: build
@echo "Deploying all ZK programs..."
@for dir in $(ZK_EXAMPLES); do \
echo "Deploying $$dir..."; \
if [ -f "$$dir/target/deploy/"*.so ]; then \
solana program deploy $$dir/target/deploy/*.so; \
if [ $$? -ne 0 ]; then \
echo "Failed to deploy $$dir"; \
exit 1; \
fi; \
echo "$$dir deployed successfully"; \
else \
echo "No .so file found for $$dir, skipping deploy"; \
fi; \
done
@echo "All programs deployed!"

test-rust:
@echo "Running Rust tests for all ZK examples..."
@for dir in $(ZK_EXAMPLES); do \
echo "Testing $$dir (Rust)..."; \
cd $$dir && cargo test-sbf && cd ..; \
if [ $$? -ne 0 ]; then \
echo "Rust tests failed for $$dir"; \
exit 1; \
fi; \
echo "$$dir Rust tests passed"; \
done
@echo "All Rust tests passed!"

test-ts: deploy
@echo "Running TypeScript tests for all ZK examples..."
@for dir in $(ZK_EXAMPLES); do \
echo "Testing $$dir (TypeScript)..."; \
if [ -f "$$dir/package.json" ]; then \
cd $$dir && npm run test:ts && cd ..; \
if [ $$? -ne 0 ]; then \
echo "TypeScript tests failed for $$dir"; \
exit 1; \
fi; \
echo "$$dir TypeScript tests passed"; \
else \
echo "No package.json found in $$dir, skipping TS tests"; \
fi; \
done
@echo "All TypeScript tests passed!"

setup:
@echo "Setting up circuits for all ZK examples..."
@for dir in $(ZK_EXAMPLES); do \
echo "Setting up $$dir..."; \
if [ -f "$$dir/scripts/setup.sh" ]; then \
cd $$dir && ./scripts/setup.sh && cd ..; \
if [ $$? -ne 0 ]; then \
echo "Setup failed for $$dir"; \
exit 1; \
fi; \
echo "$$dir setup completed"; \
else \
echo "No setup script found in $$dir"; \
fi; \
done
@echo "All setups completed!"

clean:
@echo "Cleaning all ZK examples..."
@for dir in $(ZK_EXAMPLES); do \
echo "Cleaning $$dir..."; \
cd $$dir && cargo clean && cd ..; \
if [ -d "$$dir/build" ]; then \
rm -rf $$dir/build; \
fi; \
if [ -d "$$dir/node_modules" ]; then \
rm -rf $$dir/node_modules; \
fi; \
done
@echo "All examples cleaned!"

# Individual example targets
nullifier:
@echo "Building, deploying, and testing nullifier..."
@cd nullifier && cargo build-sbf && cargo test-sbf
@solana program deploy nullifier/target/deploy/nullifier.so
@if [ -f "nullifier/package.json" ]; then \
cd nullifier && npm run test:ts; \
fi
@echo "nullifier completed!"

zk-id:
@echo "Building, deploying, and testing zk-id..."
@cd zk-id && cargo build-sbf && cargo test-sbf
@solana program deploy zk-id/target/deploy/zk_id.so
@if [ -f "zk-id/package.json" ]; then \
cd zk-id && npm run test:ts; \
fi
@echo "zk-id completed!"

Loading
Loading