Instruction Types
The SDK provides two levels of instruction builders:- Action Functions - High-level helpers that handle account creation and setup
- Generic Instructions - Low-level instruction builders for fine-grained control
Action Functions
Action functions provide the easiest way to interact with the ZK ElGamal Proof program. They handle rent calculation, account creation, and instruction building automatically.verifyZeroCiphertext
Verifies that an ElGamal ciphertext encrypts zero. Type Signature:rpc- Solana RPC client with rent exemption APIpayer- Transaction fee payer and account creatorproofData- Either raw proof bytes (Uint8Array) or reference to record accountcontextState(optional) - If provided, creates an account to store the verified proofprogramId(optional) - Custom program address (defaults toZkE1Gama1Proof11111111111111111111111111111)
verifyPubkeyValidity
Verifies that an ElGamal public key is valid (i.e., the prover knows the corresponding secret key). Type Signature:verifyZeroCiphertext
Returns: Array of instructions to execute
Example:
Other Action Functions
The SDK exports action functions for all proof types:verifyZeroCiphertextverifyPubkeyValidityverifyPercentageWithCapverifyBatchedRangeProofU64verifyBatchedRangeProofU128verifyBatchedRangeProofU256verifyCiphertextCiphertextEqualityverifyCiphertextCommitmentEqualityverifyGroupedCiphertext2HandlesValidityverifyGroupedCiphertext3HandlesValidityverifyBatchedGroupedCiphertext2HandlesValidityverifyBatchedGroupedCiphertext3HandlesValidity
Generic Instructions
For advanced use cases, you can use the low-level instruction builders directly.getVerifyProofInstruction
Universal instruction builder for all proof verification types. Type Signature:discriminator- Instruction discriminator (useZkElGamalProofInstructionenum)proofAccount(optional) - Account containing proof datacontextState(optional) - Account to store verified proofcontextStateAuthority(optional) - Authority for the context state accountoffset(optional) - Byte offset in proof account (default: 0)proofData(optional) - Raw proof bytes (mutually exclusive withproofAccount)
getCloseContextStateInstruction
Closes a context state account and returns rent to the destination account. Type Signature:contextState- Address of the context state account to closedestination- Address to receive the rent lamportsauthority- Authority that owns the context state account (must sign)
Type Definitions
ProofDataInput
Union type for specifying where proof data comes from.ContextStateArgs
Arguments for creating a context state account.ZkElGamalProofInstruction
Enum of all instruction discriminators.Constants
Context Account Sizes
Predefined sizes for context state accounts:Program Address
Advanced Usage
Encoding and Decoding Instruction Data
For custom use cases, you can manually encode/decode instruction data:Parsing Instructions
You can parse instruction data from transactions:Error Handling
Instructions will throw errors if:- Required parameters are missing
- Proof data is invalid
- Accounts don’t have sufficient rent
- Transaction fails on-chain