Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit bcdb108

Browse files
committed
add confidential burn proof extraction
1 parent 07ec5b8 commit bcdb108

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
}

token/confidential-transfer/proof-extraction/src/encryption.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,7 @@ impl PodFeeCiphertext {
4646
.map_err(|_| TokenProofExtractionError::CiphertextExtraction)
4747
}
4848
}
49+
50+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
51+
#[repr(C)]
52+
pub struct PodBurnAmountCiphertext(pub(crate) PodGroupedElGamalCiphertext2Handles);

token/confidential-transfer/proof-extraction/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub mod burn;
12
pub mod encryption;
23
pub mod errors;
34
pub mod transfer;

0 commit comments

Comments
 (0)