|
| 1 | +use { |
| 2 | + crate::{encryption::PodBurnAmountCiphertext, errors::TokenProofExtractionError}, |
| 3 | + solana_zk_sdk::{ |
| 4 | + encryption::pod::elgamal::{PodElGamalCiphertext, PodElGamalPubkey}, |
| 5 | + zk_elgamal_proof_program::proof_data::{ |
| 6 | + BatchedRangeProofContext, CiphertextCommitmentEqualityProofContext, |
| 7 | + GroupedCiphertext2HandlesValidityProofContext, |
| 8 | + }, |
| 9 | + }, |
| 10 | +}; |
| 11 | + |
| 12 | +/// The public keys associated with a confidential burn |
| 13 | +pub struct BurnPubkeys { |
| 14 | + pub source: PodElGamalPubkey, |
| 15 | + pub auditor: PodElGamalPubkey, |
| 16 | +} |
| 17 | + |
| 18 | +/// The proof context information needed to process a confidential burn instruction |
| 19 | +pub struct BurnProofContext { |
| 20 | + pub burn_amount_ciphertext: PodBurnAmountCiphertext, |
| 21 | + pub burn_pubkeys: BurnPubkeys, |
| 22 | + pub remaining_balance_ciphertext: PodElGamalCiphertext, |
| 23 | +} |
| 24 | + |
| 25 | +impl BurnProofContext { |
| 26 | + pub fn verify_and_extract( |
| 27 | + equality_proof_context: &CiphertextCommitmentEqualityProofContext, |
| 28 | + ciphertext_validity_proof_context: &GroupedCiphertext2HandlesValidityProofContext, |
| 29 | + range_proof_context: &BatchedRangeProofContext, |
| 30 | + ) -> Result<Self, TokenProofExtractionError> { |
| 31 | + let CiphertextCommitmentEqualityProofContext { |
| 32 | + pubkey: source_elgamal_pubkey_from_equality_proof, |
| 33 | + ciphertext: remaining_balance_ciphertext, |
| 34 | + commitment: remaining_balance_commitment, |
| 35 | + } = equality_proof_context; |
| 36 | + |
| 37 | + let GroupedCiphertext2HandlesValidityProofContext { |
| 38 | + first_pubkey: source_elgamal_pubkey_from_validity_proof, |
| 39 | + second_pubkey: auditor_elgamal_pubkey, |
| 40 | + grouped_ciphertext: burn_amount_ciphertext, |
| 41 | + } = ciphertext_validity_proof_context; |
| 42 | + |
| 43 | + let BatchedRangeProofContext { |
| 44 | + commitments, |
| 45 | + bit_lengths, |
| 46 | + } = range_proof_context; |
| 47 | + |
| 48 | + if source_elgamal_pubkey_from_equality_proof == source_elgamal_pubkey_from_validity_proof { |
| 49 | + return Err(TokenProofExtractionError::ElGamalPubkeyMismatch); |
| 50 | + } |
| 51 | + |
| 52 | + if commitments.is_empty() || commitments[0] != *remaining_balance_commitment { |
| 53 | + return Err(TokenProofExtractionError::PedersenCommitmentMismatch); |
| 54 | + } |
| 55 | + |
| 56 | + if bit_lengths.is_empty() || bit_lengths[0] != 64 { |
| 57 | + return Err(TokenProofExtractionError::RangeProofLengthMismatch); |
| 58 | + } |
| 59 | + |
| 60 | + let burn_pubkeys = BurnPubkeys { |
| 61 | + source: *source_elgamal_pubkey_from_equality_proof, |
| 62 | + auditor: *auditor_elgamal_pubkey, |
| 63 | + }; |
| 64 | + |
| 65 | + Ok(BurnProofContext { |
| 66 | + burn_amount_ciphertext: PodBurnAmountCiphertext(*burn_amount_ciphertext), |
| 67 | + burn_pubkeys, |
| 68 | + remaining_balance_ciphertext: *remaining_balance_ciphertext, |
| 69 | + }) |
| 70 | + } |
| 71 | +} |
0 commit comments