You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: zk-compression-blog.md
+37-30Lines changed: 37 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,59 +24,47 @@ For example, in a private KYC program, the private input is your credential, the
24
24
25
25
### Poseidon Merkle Tree
26
26
27
-
A Poseidon Merkle tree is a binary tree where each node is the hash of its children.
27
+
Merkle trees store zk application state.
28
+
Specifically, a Poseidon Merkle tree is a binary tree where each node is the hash of its children.
28
29
Poseidon is designed for ZK circuits - it uses fewer constraints (TODO: add reference) than SHA256, making proofs faster and cheaper to generate.
29
30
30
-
**Merkle tree: custom vs state trees**
31
+
**Merkle trees on Solana:**
31
32
32
-
A custom sparse Merkle tree gives you full control. You design the leaf structure and proof format to match your circuit exactly. The tradeoff: you build and run your own indexer to track the tree and serve Merkle proofs.
33
+
A **custom sparse Merkle tree** gives you full control. You design the leaf structure and proof format to match your circuit exactly. Create Solana accounts with your program to store a sparse Merkle tree and its roots.
34
+
The tradeoff: you build and run your own indexer to track the tree and serve Merkle proofs.
33
35
34
-
State trees handle indexing for you. Standard Solana RPCs serve Merkle proofs. The tradeoff: your circuit must prove inclusion of your data inside the compressed account (accounts stored in Poseidon Merkle trees with Solana RPC support) structure. This adds constraints to your circuit but eliminates infrastructure overhead.
The `data_hash` is entirely yours. Hash whatever structure your application needs. The outer fields are protocol overhead, but they don't limit what you store inside.
36
+
**Zk compression state Merkle trees** Solana RPCs handle indexing for you and serve Merkle proofs. The Light Protocol programs create and maintain Poseidon state Merkle trees for you in Solana accounts. Once a state Merkle tree fills up the protocol creates a new one.
37
+
The tradeoff: your circuit must prove inclusion of your data inside the compressed account structure. Compressed accounts are stored as hashes in Poseidon Merkle trees with Solana RPC support. This adds constraints to your circuit but RPCs index the Merkle tree for you.
51
38
52
39
Note, for offchain privacy a user client should fetch a complete (sub)tree not Merkle proof from an indexer. If only onchain privacy is sufficient fetching Merkle proofs from an indexer is more efficient.
53
40
54
41
55
42
### Nullifier
56
-
A nullifier is a hash derived from your secret and the leaf the transaction is using.
43
+
Nullifiers prevent double spending.
44
+
In detail, a nullifier is a hash derived from your secret and the leaf the transaction is using.
57
45
When you use private state (stored in a Merkle tree leaf), you publish the nullifier. The program stores it in a set.
58
46
If anyone tries to spend the same leaf again, the nullifier would match one already stored, so the transaction fails.
59
47
The nullifier reveals nothing about which leaf was spent.
60
48
Different state produces different nullifiers, so observers can't link a nullifier back to its source leaf.
61
49
62
-
**Nullifier storage: PDAs vs compressed addresses**
50
+
**Nullifiers on Solana:**
63
51
64
-
PDAs are the straightforward choice. Derive an address from the nullifier hash, create an account there. If the account exists, the nullifier was used. The cost is ~899k lamports per nullifier for rent exemption.
52
+
**PDAs** are a straightforward choice. Derive an address from the nullifier hash, create an account there. If the account exists, the nullifier was used. The cost is ~899k lamports per nullifier for rent exemption.
65
53
66
-
Compressed addresses work the same way but cost ~10k lamports. The tradeoff: you need an additional ZK proof to create the account and a CPI to the Light system program. If you're already generating a ZK proof for your application logic, the marginal cost of the extra proof is low. If not, PDAs are simpler.
54
+
**Compressed addresses** work the same way but cost ~10k lamports. The tradeoff: you need an additional ZK proof to create the account and a CPI to the Light system program. If you're already generating a ZK proof for your application logic, the marginal cost of the extra proof is low. If not, PDAs are simpler.
67
55
68
56
69
57
## Zk Id example
70
58
71
-
zk-id is a proof of concept credential system built with zk compression and the following tools:
59
+
[zk-id](https://github.com/Lightprotocol/program-examples/tree/main/zk-id) is a proof of concept credential system built with zk compression and the following tools:
The `data_hash` is entirely yours. Hash whatever structure your application needs. The outer fields are protocol overhead, but they don't limit what you store inside.
0 commit comments