Overview
Thelight-compressed-account crate provides the core compressed account struct and utility types for Light Protocol. It defines the fundamental data structures used throughout the protocol for state compression.
Crate: light-compressed-accountLocation:
program-libs/compressed-account/Error Codes: 12001-12025
Key Types
CompressedAccount
Core struct representing compressed state
Address
Deterministic address derivation
Nullifier
Spend tracking for compressed accounts
Instruction Data
ZK proof structures and CPI contexts
CompressedAccount
Structure
Fields
Program that owns this compressed account (similar to Solana account owner)
Lamport balance stored in this account
Optional deterministic address. Required for accounts with data. Derived from seeds using
derive_address().Optional account data:
discriminator: 8-byte type identifierdata: Raw account data (variable length)data_hash: Poseidon hash ofdiscriminator || data
Hashing
Compressed accounts are hashed before insertion into Merkle trees:- Owner (32 bytes)
- Lamports (8 bytes, little-endian)
- Address or zero (32 bytes)
- Data hash or zero (32 bytes)
Address Derivation
derive_address
Deterministically derive address from seeds:Address Seeds
Structured seed representation:Nullifier Computation
Nullifiers prevent double-spending of compressed accounts:- Compressed account hash
- Leaf index (8 bytes, little-endian)
- Merkle tree pubkey
Instruction Data
CompressedProof
Gro th16 ZK proof (128 bytes):PackedCompressedAccountWithMerkleContext
Compressed account with proof data:NewAddressParams
Parameters for creating new addresses:CpiContext
Cross-program invocation context:Queue Types
Enum for queue variants:Tree Types
Enum for Merkle tree variants:Error Codes
| Code | Error | Description |
|---|---|---|
| 12001 | InputTooLarge | Input exceeds maximum size |
| 12002 | InvalidChunkSize | Chunk size validation failed |
| 12003 | InvalidSeeds | Invalid seeds for address derivation |
| 12004 | InvalidRolloverThreshold | Invalid tree rollover threshold |
| 12005 | InvalidInputLength | Input length doesn’t match expected |
| 12010 | InvalidAccountSize | Account size mismatch |
| 12011 | AccountMutable | Account mutability error |
| 12012 | AlreadyInitialized | Account already initialized |
| 12013 | InvalidAccountBalance | Invalid lamport balance |
| 12014 | FailedBorrowRentSysvar | Failed to access rent sysvar |
| 12015 | DeriveAddressError | Address derivation failed |
| 12016 | InvalidArgument | Invalid function argument |
| 12017 | ZeroCopyExpectedAddress | Expected address in zero-copy data |
| 12018 | InstructionDataExpectedAddress | Expected address in instruction |
| 12019 | CompressedAccountDataNotInitialized | Account data not initialized |
| 12020 | ExpectedDiscriminator | Missing discriminator |
| 12021 | InstructionDataExpectedProof | Missing proof in instruction |
| 12022 | ZeroCopyExpectedProof | Expected proof in zero-copy data |
| 12023 | ExpectedDataHash | Missing data hash |
| 12024 | InvalidCpiContext | Invalid CPI context configuration |
| 12025 | InvalidProofSize | Proof size != 128 bytes |
Usage Examples
Creating Compressed Accounts
Computing Nullifiers
Validating Proofs
Constants
Program IDs and discriminators:Zero-Copy Types
For efficient on-chain processing:Best Practices
Always Derive Addresses for Data Accounts
Always Derive Addresses for Data Accounts
Accounts with data MUST have deterministic addresses. This ensures uniqueness and enables lookups.
Hash Data Consistently
Hash Data Consistently
Always use
discriminator || data when computing data hashes. The discriminator must be included.Validate Proofs Before State Changes
Validate Proofs Before State Changes
Always verify ZK proofs before modifying any state or transferring lamports.
Track Nullifiers
Track Nullifiers
Store and check nullifiers to prevent double-spending of compressed accounts.
Feature Flags
Enables standard library features
Enables Anchor framework integration
Enables Solana SDK integration
Enables Pinocchio SDK integration
Enables allocation without std
Resources
Source Code
View on GitHub
API Docs
Rust documentation
System Program
System program using compressed accounts
Light Protocol Paper
Technical whitepaper