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

Commit 045e286

Browse files
committed
add withdraw proof extraction
1 parent 49c9642 commit 045e286

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub mod encryption;
22
pub mod errors;
33
pub mod transfer;
4+
pub mod withdraw;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
use {
2+
crate::errors::TokenProofExtractionError,
3+
solana_zk_sdk::{
4+
encryption::pod::elgamal::{PodElGamalCiphertext, PodElGamalPubkey},
5+
zk_elgamal_proof_program::proof_data::{
6+
BatchedRangeProofContext, CiphertextCommitmentEqualityProofContext,
7+
},
8+
},
9+
};
10+
11+
const REMAINING_BALANCE_BIT_LENGTH: u8 = 64;
12+
13+
pub struct WithdrawProofContext {
14+
pub source_pubkey: PodElGamalPubkey,
15+
pub remaining_balance_ciphertext: PodElGamalCiphertext,
16+
}
17+
18+
impl WithdrawProofContext {
19+
pub fn verify_and_extract(
20+
equality_proof_context: &CiphertextCommitmentEqualityProofContext,
21+
range_proof_context: &BatchedRangeProofContext,
22+
) -> Result<Self, TokenProofExtractionError> {
23+
let CiphertextCommitmentEqualityProofContext {
24+
pubkey: source_pubkey,
25+
ciphertext: remaining_balance_ciphertext,
26+
commitment: remaining_balance_commitment,
27+
} = equality_proof_context;
28+
29+
let BatchedRangeProofContext {
30+
commitments: range_proof_commitments,
31+
bit_lengths: range_proof_bit_lengths,
32+
} = range_proof_context;
33+
34+
if range_proof_commitments.is_empty()
35+
|| range_proof_commitments[0] != *remaining_balance_commitment
36+
{
37+
return Err(TokenProofExtractionError::PedersenCommitmentMismatch);
38+
}
39+
40+
if range_proof_bit_lengths.is_empty()
41+
|| range_proof_bit_lengths[0] != REMAINING_BALANCE_BIT_LENGTH
42+
{
43+
return Err(TokenProofExtractionError::RangeProofLengthMismatch);
44+
}
45+
46+
let context_info = WithdrawProofContext {
47+
source_pubkey: *source_pubkey,
48+
remaining_balance_ciphertext: *remaining_balance_ciphertext,
49+
};
50+
51+
Ok(context_info)
52+
}
53+
}

0 commit comments

Comments
 (0)