Overview
TheverifyPercentageWithCap function creates instructions to verify a percentage-with-cap proof. This proof certifies that a transfer amount is within a certain percentage of a base amount, capped at a maximum value. This is useful for implementing fee structures or transfer limits in confidential transactions.
Function Signature
Parameters
Solana RPC client with rent exemption API support
Transaction signer that will pay for the account creation fees
The percentage-with-cap proof data. Can be either:
Uint8Array- Raw proof bytes for ephemeral verification{ account: Address; offset: number }- Reference to proof data stored in a record account
Optional context state configuration for storing the verified proof on-chain:
contextAccount: KeyPairSigner- New account to store the proofauthority: Address- Authority that can close the context account
ZK ElGamal Proof program address. Defaults to
ZK_ELGAMAL_PROOF_PROGRAM_ADDRESSReturns
Promise<Instruction[]> - Array of instructions to execute:
- Create context account instruction (if
contextStateis provided) - Verify percentage-with-cap proof instruction
Usage Examples
Basic Ephemeral Verification
Verify that a fee is within an allowed percentage with a cap:With Context State Storage
Store the verified proof on-chain for later use:Fee Calculation with Cap
Verify a transaction fee structure:Notes
Fee Rate FormatThe fee rate is expressed in basis points (1/10000). For example:
- 1% = 100 basis points
- 2.5% = 250 basis points
- 10% = 1000 basis points
Proof RequirementsThe proof demonstrates that:
- The fee amount ≤ min(transfer_amount × rate, max_fee)
- The prover knows the openings for both commitments
- The committed values match the claimed amounts
Use Cases
- Implementing confidential transaction fees with percentage-based caps
- Proving fee calculations are correct without revealing amounts
- Enforcing transfer limits in confidential token transfers
- Creating tiered fee structures with maximum caps
Related Functions
verifyGroupedCiphertext2HandlesValidity- Verify grouped ciphertext validityverifyRangeProofs- Verify range proofscloseContextStateProof- Close a context state account