Skip to main content

solana_zk_elgamal_proof_interface/proof_data/
zero_ciphertext.rs

1//! The zero-ciphertext proof instruction.
2//!
3//! A zero-ciphertext proof is defined with respect to a twisted ElGamal ciphertext. The proof
4//! certifies that a given ciphertext encrypts the message 0 in the field (`Scalar::zero()`). To
5//! generate the proof, a prover must provide the decryption key for the ciphertext.
6
7use {
8    crate::proof_data::{ProofType, ZkProofData},
9    bytemuck_derive::{Pod, Zeroable},
10    solana_zk_sdk_pod::{
11        encryption::elgamal::{PodElGamalCiphertext, PodElGamalPubkey},
12        sigma_proofs::PodZeroCiphertextProof,
13    },
14};
15
16/// The instruction data that is needed for the `ProofInstruction::VerifyZeroCiphertext` instruction.
17///
18/// It includes the cryptographic proof as well as the context data information needed to verify
19/// the proof.
20#[derive(Clone, Copy, Pod, Zeroable, Debug, PartialEq, Eq)]
21#[repr(C)]
22pub struct ZeroCiphertextProofData {
23    /// The context data for the zero-ciphertext proof
24    pub context: ZeroCiphertextProofContext, // 96 bytes
25
26    /// Proof that the ciphertext is zero
27    pub proof: PodZeroCiphertextProof, // 96 bytes
28}
29
30/// The context data needed to verify a zero-ciphertext proof.
31#[derive(Clone, Copy, Pod, Zeroable, Debug, PartialEq, Eq)]
32#[repr(C)]
33pub struct ZeroCiphertextProofContext {
34    /// The ElGamal pubkey associated with the ElGamal ciphertext
35    pub pubkey: PodElGamalPubkey, // 32 bytes
36
37    /// The ElGamal ciphertext that encrypts zero
38    pub ciphertext: PodElGamalCiphertext, // 64 bytes
39}
40
41impl ZkProofData<ZeroCiphertextProofContext> for ZeroCiphertextProofData {
42    const PROOF_TYPE: ProofType = ProofType::ZeroCiphertext;
43
44    fn context_data(&self) -> &ZeroCiphertextProofContext {
45        &self.context
46    }
47}