Create a Program with Compressed PDAs

Overview to compressed PDA core features and guide for program development.

Compressed PDAs provide full functionality of accounts at PDAs, without per-account rent cost.

Creation
Regular PDA Account
Compressed PDA
Cost Reduction

100-byte PDA

~ 0.0016 SOL

~ 0.00001 SOL

160x

Compressed PDAs are derived using a specific program address and seed, like regular PDAs. Custom programs invoke the to create and update accounts, instead of the System program.

Compressed PDAs at a Glance

Rent free PDAs

Create accounts at program-derived addresses without upfront rent exempt balance.

Full PDA Functionality

Deterministic seed generation and program ownership.

Composable

CPI support between compressed and regular PDAs.

Start Building

Developing with compressed PDAs works similar to regular PDAs and involves minimal setup:

required versions

Make sure you have the required versions installed and available in PATH:

  • Rust: 1.86.0 or later

  • Solana CLI: 2.2.15

  • Anchor CLI: 0.31.1

  • Node.js: 23.5.0 or later

  • Zk compression CLI: 0.27.0 or later

1

Prerequisite Setup

Make sure you installed Rust, the Solana CLI, and Anchor. Refer to this setup guide for more help.

Install the Light CLI:

npm -g i @lightprotocol/zk-compression-cli
### verify installation
light --version
2

Initialize Your Program

light init testprogram

The light init command creates only Anchor-based projects . For Pinocchio programs, manually configure dependencies using light-sdk-pinocchio.

This initializes an anchor program with a basic counter program template using compressed accounts with all required dependencies.

3

Build and Test

Now cd testprogram and run:

anchor build
# Success: Finished `release` profile [optimized] target(s), after compiling.
# Note: Stack offset warnings are expected and don't prevent compilation
cargo test-sbf

# Success: test result: ok. 1 passed; 0 failed; 0 ignored
Light Protocol Libraries Used

Rust Crates

  • light-sdk - Core SDK for compressed accounts in native and anchor programs

  • light-sdk-pinocchio Core SDK for compressed accounts in pinocchio programs

  • light-hasher - Hashing utilities for ZK compression

  • light-client - RPC client and indexer for interacting with compressed accounts

  • light-program-test - Testing utilities for compressed programs.

TypeScript/JavaScript Packages

  • @lightprotocol/stateless.js - Client library for interacting with compressed accounts

  • @lightprotocol/zk-compression-cli - Command-line tools for ZK compression development

Common Errors

'assert.h' file not found - during compilation.
Fix: 
In your terminal, run:
1. export CC=$(xcrun -find clang)
2. export SDKROOT=$(xcrun --show-sdk-path)
3. cargo clean
4. anchor build


Example log:
The following warnings were emitted during compilation:

warning: [email protected]: In file included from c/blake3_neon.c:1:
warning: [email protected]: c/blake3_impl.h:4:10: fatal error: 'assert.h' file not found
warning: [email protected]:     4 | #include <assert.h>
warning: [email protected]:       |          ^~~~~~~~~~
warning: [email protected]: 1 error generated.

error: failed to run custom build command for `blake3 v1.5.1`

Caused by:
  process didn't exit successfully: `/Users/you/testprogram/target/release/build/blake3-ac41d29c2eabe052/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=CARGO_FEATURE_PURE
  cargo:rerun-if-env-changed=CARGO_FEATURE_NO_NEON
  cargo:rerun-if-env-changed=CARGO_FEATURE_NEON
  cargo:rerun-if-env-changed=CARGO_FEATURE_NEON
  cargo:rerun-if-env-changed=CARGO_FEATURE_NO_NEON
  cargo:rerun-if-env-changed=CARGO_FEATURE_PURE
  cargo:rustc-cfg=blake3_neon
  OUT_DIR = Some(/Users/you/testprogram/target/release/build/blake3-735a4c71d985df30/out)
  TARGET = Some(aarch64-apple-darwin)
  OPT_LEVEL = Some(3)
  HOST = Some(aarch64-apple-darwin)
  cargo:rerun-if-env-changed=CC_aarch64-apple-darwin
  CC_aarch64-apple-darwin = None
  cargo:rerun-if-env-changed=CC_aarch64_apple_darwin
  CC_aarch64_apple_darwin = None
  cargo:rerun-if-env-changed=HOST_CC
  HOST_CC = None
  cargo:rerun-if-env-changed=CC
  CC = Some(/Users/you/.local/share/solana/install/releases/1.18.22/solana-release/bin/sdk/sbf/dependencies/platform-tools/llvm/bin/clang)
  RUSTC_WRAPPER = None
  cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some(false)
  cargo:rerun-if-env-changed=MACOSX_DEPLOYMENT_TARGET
  MACOSX_DEPLOYMENT_TARGET = None
  cargo:rerun-if-env-changed=CFLAGS_aarch64-apple-darwin
  CFLAGS_aarch64-apple-darwin = None
  cargo:rerun-if-env-changed=CFLAGS_aarch64_apple_darwin
  CFLAGS_aarch64_apple_darwin = None
  cargo:rerun-if-env-changed=HOST_CFLAGS
  HOST_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  cargo:warning=In file included from c/blake3_neon.c:1:
  cargo:warning=c/blake3_impl.h:4:10: fatal error: 'assert.h' file not found
  cargo:warning=    4 | #include <assert.h>
  cargo:warning=      |          ^~~~~~~~~~
  cargo:warning=1 error generated.

  --- stderr


  error occurred: Command env -u IPHONEOS_DEPLOYMENT_TARGET "/Users/you/.local/share/solana/install/releases/1.18.22/solana-release/bin/sdk/sbf/dependencies/platform-tools/llvm/bin/clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=arm64-apple-darwin" "-mmacosx-version-min=14.4" "-Wall" "-Wextra" "-std=c11" "-o" "/Users/you/testprogram/target/release/build/blake3-735a4c71d985df30/out/db3b6bfb95261072-blake3_neon.o" "-c" "c/blake3_neon.c" with args clang did not execute successfully (status code exit status: 1).

More Examples

Counter Program

The counter program implements a compressed account lifecycle (create, increment, decrement, reset, close):

Create and Update Program

  • create-and-update - Create a new compressed account and update an existing compressed account with a single validity proof in one instruction.

Solana vs compressed accounts comparison Program


Next Steps

Get an overview of the SDKs for program development with ZK Compression.

Program Development

Last updated