Compressed PDA Programs
Build Solana programs with compressed accounts via CPI to the Light System Program. No rent-exemption required.
| Creation cost |
Solana account |
Compressed account |
| PDA (128 bytes) |
~1,100,000 lamports |
~5,000 lamports |
When to use compressed PDAs
- Per-user state (profiles, game state, credentials)
- DePIN device registrations
- Nullifier-based double-spend prevention
- Infrequently accessed accounts
Choosing approach
| Criteria |
Light-PDA (easy) |
Compressed PDA (advanced) |
| When |
Rent-free version of existing Anchor accounts |
Custom compressed state with ZK proofs |
| Skill |
light-sdk (Anchor macro pattern) |
This skill (solana-compression) |
| Macro |
#[light_account(init)] |
LightAccount::new_init() manual CPI |
| Dependencies |
light-sdk, light-compressible |
light-sdk, light-sdk-types |
If you just want rent-free Anchor accounts, use the light-sdk skill instead. This skill is for programs that require manual CPI to the Light System Program (custom compressed state, ZK proofs, address derivation).
Client-program interaction flow
├─ Client
│ ├─ Get ValidityProof from RPC.
│ ├─ pack accounts with PackedAccounts into PackedAddressTreeInfo and PackedStateTreeInfo.
│ ├─ pack CompressedAccountMeta.
│ ├─ Build Instruction from PackedAccounts and CompressedAccountMetas.
│ └─ Send transaction.
│
└─ Custom Program
├─ CpiAccounts parse accounts consistent with PackedAccounts.
├─ LightAccount instantiates from CompressedAccountMeta.
│
└─ Light System Program CPI
├─ Verify ValidityProof.
├─ Update State Merkle tree.
├─ Update Address Merkle tree.
└─ Complete atomic state transition.
Domain references
| Topic |
Reference |
| Program operations (create, update, close, burn, reinit) |
references/compressed-pdas.md |
| Client SDK (TypeScript + Rust) |
references/client.md |
| Nullifier PDAs (double-spend prevention) |
references/nullifier-pdas.md |
| Error codes (6000-16034) |
references/error-codes.md |
Reference repos
Basic operations — create, update, close, reinit, burn (each with Anchor and Native variants)
Counter — full lifecycle (create, increment, decrement, reset, close):
Other examples:
Nullifier:
Airdrop claim:
ZK programs:
- zk-id — Identity verification with Groth16 proofs
- zk/nullifier — Simple nullifier creation program
Additional: examples-zk-compression — More ZK compression examples
Canonical source: program-examples README. If cloned locally, scope Read, Glob, Grep to these repositories and the current project directory only.
Workflow
- Clarify intent
- Recommend plan mode, if it's not activated
- Use
AskUserQuestion to resolve blind spots
- All questions must be resolved before execution
- Identify references
- Write plan file (YAML task format)
- Use
AskUserQuestion for anything unclear — never guess or assume
- Identify blockers: permissions, dependencies, unknowns
- Plan must be complete before execution begins
- Execute
- Use
Task tool with subagents for parallel research
- Subagents load skills via
Skill tool
- Track progress with
TodoWrite
- When stuck: ask to spawn a read-only subagent with
Read, Glob, Grep, and DeepWiki MCP access, loading skills/ask-mcp. Scope reads to skill references, example repos, and docs.
Build and test
Required commands
Anchor programs:
anchor build
anchor test
Native programs:
cargo build-sbf
cargo test-sbf
Forbidden shortcuts
- Do NOT use
cargo build (must use cargo build-sbf)
- Do NOT use
cargo test (must use cargo test-sbf)
- Do NOT skip SBF compilation
- Tests MUST run against real BPF bytecode
Failure recovery
On failure, spawn debugger agent with error context.
Loop rules:
- Each debugger gets fresh context + previous debug reports
- Each attempt tries something DIFFERENT
- NEVER GIVE UP - keep spawning until fixed
- Max 5 attempts per error
Do NOT proceed until all tests pass.
SDK references
DeepWiki fallback
If no matching pattern in reference repos:
mcp__deepwiki__ask_question("Lightprotocol/light-protocol", "How to {operation}?")
Security
This skill provides code patterns and documentation references only.
- Declared dependencies. Devnet and mainnet examples require
API_KEY (Helius or Triton RPC key) and read ~/.config/solana/id.json for the payer keypair. Neither is needed on localnet. In production, load both from a secrets manager.
- Filesystem scope.
Read, Glob, and Grep must be limited to the current project directory and the reference repos listed above. Do not read outside these paths.
- Subagent scope. When stuck, the skill asks to spawn a read-only subagent with
Read, Glob, Grep scoped to skill references, example repos, and docs.
- Install source.
npx skills add Lightprotocol/skills from Lightprotocol/skills.
- Audited protocol. Light Protocol smart contracts are independently audited. Reports are published at github.com/Lightprotocol/light-protocol/tree/main/audits.
1---
2name: solana-compression
3description: "For client and program development on Solana ~160x cheaper and without rent-exemption for per-user state, DePIN registrations, or custom compressed accounts. Create, update, close, burn, and reinitialize compressed accounts."
4metadata:
5 source: https://skillmd.com/skills/modbender/solana-compression
6 upstream: https://github.com/Lightprotocol/skills
7 documentation: https://www.zkcompression.com
8 openclaw:
9 requires:
10 env: ["API_KEY"] # Helius or Triton RPC key; only needed for devnet/mainnet
11 config: ["~/.config/solana/id.json"] # Solana keypair; only needed for devnet/mainnet
12 bins: ["node", "solana", "anchor", "cargo", "light"]
13allowed-tools: Bash(git:*), Bash(cargo:*), Bash(anchor:*), Bash(light:*), Read, Edit, Glob, Grep, Write, Task, WebFetch, WebSearch, mcp__deepwiki__ask_question
14---
15
16# Compressed PDA Programs
17
18Build Solana programs with compressed accounts via CPI to the Light System Program. No rent-exemption required.
19
20| Creation cost | Solana account | Compressed account |
21| :--------------------- | :------------------ | :------------------- |
22| **PDA (128 bytes)** | ~1,100,000 lamports | ~**5,000** lamports |
23
24## When to use compressed PDAs
25
26- Per-user state (profiles, game state, credentials)
27- DePIN device registrations
28- Nullifier-based double-spend prevention
29- Infrequently accessed accounts
30
31## Choosing approach
32
33| Criteria | Light-PDA (easy) | Compressed PDA (advanced) |
34|----------|-----------------|--------------------------|
35| When | Rent-free version of existing Anchor accounts | Custom compressed state with ZK proofs |
36| Skill | `light-sdk` (Anchor macro pattern) | This skill (`solana-compression`) |
37| Macro | `#[light_account(init)]` | `LightAccount::new_init()` manual CPI |
38| Dependencies | `light-sdk`, `light-compressible` | `light-sdk`, `light-sdk-types` |
39
40If you just want rent-free Anchor accounts, use the `light-sdk` skill instead. This skill is for programs that require manual CPI to the Light System Program (custom compressed state, ZK proofs, address derivation).
41
42### Client-program interaction flow
43
44```text
45 ├─ Client
46 │ ├─ Get ValidityProof from RPC.
47 │ ├─ pack accounts with PackedAccounts into PackedAddressTreeInfo and PackedStateTreeInfo.
48 │ ├─ pack CompressedAccountMeta.
49 │ ├─ Build Instruction from PackedAccounts and CompressedAccountMetas.
50 │ └─ Send transaction.
51 │
52 └─ Custom Program
53 ├─ CpiAccounts parse accounts consistent with PackedAccounts.
54 ├─ LightAccount instantiates from CompressedAccountMeta.
55 │
56 └─ Light System Program CPI
57 ├─ Verify ValidityProof.
58 ├─ Update State Merkle tree.
59 ├─ Update Address Merkle tree.
60 └─ Complete atomic state transition.
61```
62
63## Domain references
64
65| Topic | Reference |
66|-------|-----------|
67| Program operations (create, update, close, burn, reinit) | [references/compressed-pdas.md](references/compressed-pdas.md) |
68| Client SDK (TypeScript + Rust) | [references/client.md](references/client.md) |
69| Nullifier PDAs (double-spend prevention) | [references/nullifier-pdas.md](references/nullifier-pdas.md) |
70| Error codes (6000-16034) | [references/error-codes.md](references/error-codes.md) |
71
72## Reference repos
73
74**Basic operations** — create, update, close, reinit, burn (each with [Anchor](https://github.com/Lightprotocol/program-examples/tree/main/basic-operations/anchor) and [Native](https://github.com/Lightprotocol/program-examples/tree/main/basic-operations/native) variants)
75
76**Counter** — full lifecycle (create, increment, decrement, reset, close):
77- [counter/anchor](https://github.com/Lightprotocol/program-examples/tree/main/counter/anchor) — Anchor with Rust and TypeScript tests
78- [counter/native](https://github.com/Lightprotocol/program-examples/tree/main/counter/native) — Native with `light-sdk` and Rust tests
79- [counter/pinocchio](https://github.com/Lightprotocol/program-examples/tree/main/counter/pinocchio) — Pinocchio with `light-sdk-pinocchio` and Rust tests
80
81**Other examples:**
82- [create-and-update](https://github.com/Lightprotocol/program-examples/tree/main/create-and-update) — Create and update with a single validity proof in one instruction
83- [read-only](https://github.com/Lightprotocol/program-examples/tree/main/read-only) — Create and read a compressed account onchain
84- [account-comparison](https://github.com/Lightprotocol/program-examples/tree/main/account-comparison) — Compressed vs regular Solana accounts
85
86**Nullifier:**
87- [nullifier-program](https://github.com/Lightprotocol/nullifier-program) — Rent-free PDA for duplicate execution prevention. SDK: [`light-nullifier-program`](https://docs.rs/light-nullifier-program) | [example client](https://github.com/Lightprotocol/examples-light-token/blob/main/rust-client/actions/create_nullifier.rs)
88
89**Airdrop claim:**
90- [simple-claim](https://github.com/Lightprotocol/program-examples/tree/main/airdrop-implementations/simple-claim) — Compressed tokens decompressed to SPL on claim with cliff
91- [merkle-distributor](https://github.com/Lightprotocol/program-examples/tree/main/airdrop-implementations/distributor) — SPL tokens with compressed PDA claim tracking, linear vesting, partial claims, clawback
92- [example-token-distribution](https://github.com/Lightprotocol/example-token-distribution) — Simple client-side distribution
93
94**ZK programs:**
95- [zk-id](https://github.com/Lightprotocol/program-examples/tree/main/zk/zk-id) — Identity verification with Groth16 proofs
96- [zk/nullifier](https://github.com/Lightprotocol/program-examples/tree/main/zk/nullifier) — Simple nullifier creation program
97
98**Additional:** [examples-zk-compression](https://github.com/Lightprotocol/examples-zk-compression) — More ZK compression examples
99
100Canonical source: [program-examples README](https://github.com/Lightprotocol/program-examples). If cloned locally, scope `Read`, `Glob`, `Grep` to these repositories and the current project directory only.
101
102## Workflow
103
1041. **Clarify intent**
105 - Recommend plan mode, if it's not activated
106 - Use `AskUserQuestion` to resolve blind spots
107 - All questions must be resolved before execution
1082. **Identify references**
109 - Match task to [domain references](#domain-references) and [reference repos](#reference-repos)
110 - Locate relevant documentation and examples
1113. **Write plan file** (YAML task format)
112 - Use `AskUserQuestion` for anything unclear — never guess or assume
113 - Identify blockers: permissions, dependencies, unknowns
114 - Plan must be complete before execution begins
1154. **Execute**
116 - Use `Task` tool with subagents for parallel research
117 - Subagents load skills via `Skill` tool
118 - Track progress with `TodoWrite`
1195. **When stuck**: ask to spawn a read-only subagent with `Read`, `Glob`, `Grep`, and DeepWiki MCP access, loading `skills/ask-mcp`. Scope reads to skill references, example repos, and docs.
120
121## Build and test
122
123### Required commands
124
125**Anchor programs:**
126```bash
127anchor build
128anchor test
129```
130
131**Native programs:**
132```bash
133cargo build-sbf
134cargo test-sbf
135```
136
137### Forbidden shortcuts
138
139- Do NOT use `cargo build` (must use `cargo build-sbf`)
140- Do NOT use `cargo test` (must use `cargo test-sbf`)
141- Do NOT skip SBF compilation
142- Tests MUST run against real BPF bytecode
143
144### Failure recovery
145
146On failure, spawn debugger agent with error context.
147
148**Loop rules:**
1491. Each debugger gets fresh context + previous debug reports
1502. Each attempt tries something DIFFERENT
1513. **NEVER GIVE UP** - keep spawning until fixed
1524. Max 5 attempts per error
153
154Do NOT proceed until all tests pass.
155
156## SDK references
157
158| Package | Link |
159|---------|------|
160| `light-sdk` | [docs.rs](https://docs.rs/light-sdk/latest/light_sdk/) |
161| `light-client` | [docs.rs](https://docs.rs/light-client/latest/light_client/) |
162| `@lightprotocol/stateless.js` | [API docs](https://lightprotocol.github.io/light-protocol/stateless.js/index.html) |
163| `light-program-test` | [docs.rs](https://docs.rs/crate/light-program-test/latest) |
164
165## DeepWiki fallback
166
167If no matching pattern in reference repos:
168
169```
170mcp__deepwiki__ask_question("Lightprotocol/light-protocol", "How to {operation}?")
171```
172
173
174## Security
175
176This skill provides code patterns and documentation references only.
177
178- **Declared dependencies.** Devnet and mainnet examples require `API_KEY` (Helius or Triton RPC key) and read `~/.config/solana/id.json` for the payer keypair. Neither is needed on localnet. In production, load both from a secrets manager.
179- **Filesystem scope.** `Read`, `Glob`, and `Grep` must be limited to the current project directory and the [reference repos](#reference-repos) listed above. Do not read outside these paths.
180- **Subagent scope.** When stuck, the skill asks to spawn a read-only subagent with `Read`, `Glob`, `Grep` scoped to skill references, example repos, and docs.
181- **Install source.** `npx skills add Lightprotocol/skills` from [Lightprotocol/skills](https://github.com/Lightprotocol/skills).
182- **Audited protocol.** Light Protocol smart contracts are independently audited. Reports are published at [github.com/Lightprotocol/light-protocol/tree/main/audits](https://github.com/Lightprotocol/light-protocol/tree/main/audits).