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

Commit cfaa453

Browse files
[confidential-transfer] Organize transfer proof data using structs (#7021)
* organize transfer proof data using structs * update tests * cargo fmt
1 parent 31931a7 commit cfaa453

File tree

3 files changed

+36
-29
lines changed

3 files changed

+36
-29
lines changed

token/confidential-transfer/proof-generation/src/transfer.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ use {
2121
/// token transfer
2222
const RANGE_PROOF_PADDING_BIT_LENGTH: usize = 16;
2323

24+
/// The proof data required for a confidential transfer instruction when the
25+
/// mint is not extended for fees
26+
pub struct TransferProofData {
27+
pub equality_proof_data: CiphertextCommitmentEqualityProofData,
28+
pub ciphertext_validity_proof_data: BatchedGroupedCiphertext3HandlesValidityProofData,
29+
pub range_proof_data: BatchedRangeProofU128Data,
30+
}
31+
2432
pub fn transfer_split_proof_data(
2533
current_available_balance: &ElGamalCiphertext,
2634
current_decryptable_available_balance: &AeCiphertext,
@@ -29,14 +37,7 @@ pub fn transfer_split_proof_data(
2937
aes_key: &AeKey,
3038
destination_elgamal_pubkey: &ElGamalPubkey,
3139
auditor_elgamal_pubkey: Option<&ElGamalPubkey>,
32-
) -> Result<
33-
(
34-
CiphertextCommitmentEqualityProofData,
35-
BatchedGroupedCiphertext3HandlesValidityProofData,
36-
BatchedRangeProofU128Data,
37-
),
38-
TokenProofGenerationError,
39-
> {
40+
) -> Result<TransferProofData, TokenProofGenerationError> {
4041
let default_auditor_pubkey = ElGamalPubkey::default();
4142
let auditor_elgamal_pubkey = auditor_elgamal_pubkey.unwrap_or(&default_auditor_pubkey);
4243

@@ -149,9 +150,9 @@ pub fn transfer_split_proof_data(
149150
)
150151
.map_err(TokenProofGenerationError::from)?;
151152

152-
Ok((
153+
Ok(TransferProofData {
153154
equality_proof_data,
154155
ciphertext_validity_proof_data,
155156
range_proof_data,
156-
))
157+
})
157158
}

token/confidential-transfer/proof-generation/src/transfer_with_fee.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ const FEE_AMOUNT_HI_BITS: usize = 32;
3030
const REMAINING_BALANCE_BIT_LENGTH: usize = 64;
3131
const DELTA_BIT_LENGTH: usize = 48;
3232

33+
/// The proof data required for a confidential transfer instruction when the
34+
/// mint is extended for fees
35+
pub struct TransferWithFeeProofData {
36+
pub equality_proof_data: CiphertextCommitmentEqualityProofData,
37+
pub transfer_amount_ciphertext_validity_proof_data:
38+
BatchedGroupedCiphertext3HandlesValidityProofData,
39+
pub percentage_with_cap_proof_data: PercentageWithCapProofData,
40+
pub fee_ciphertext_validity_proof_data: BatchedGroupedCiphertext2HandlesValidityProofData,
41+
pub range_proof_data: BatchedRangeProofU256Data,
42+
}
43+
3344
#[allow(clippy::too_many_arguments)]
3445
pub fn transfer_with_fee_split_proof_data(
3546
current_available_balance: &ElGamalCiphertext,
@@ -42,16 +53,7 @@ pub fn transfer_with_fee_split_proof_data(
4253
withdraw_withheld_authority_elgamal_pubkey: &ElGamalPubkey,
4354
fee_rate_basis_points: u16,
4455
maximum_fee: u64,
45-
) -> Result<
46-
(
47-
CiphertextCommitmentEqualityProofData,
48-
BatchedGroupedCiphertext3HandlesValidityProofData,
49-
PercentageWithCapProofData,
50-
BatchedGroupedCiphertext2HandlesValidityProofData,
51-
BatchedRangeProofU256Data,
52-
),
53-
TokenProofGenerationError,
54-
> {
56+
) -> Result<TransferWithFeeProofData, TokenProofGenerationError> {
5557
let default_auditor_pubkey = ElGamalPubkey::default();
5658
let auditor_elgamal_pubkey = auditor_elgamal_pubkey.unwrap_or(&default_auditor_pubkey);
5759

@@ -294,13 +296,13 @@ pub fn transfer_with_fee_split_proof_data(
294296
)
295297
.map_err(TokenProofGenerationError::from)?;
296298

297-
Ok((
299+
Ok(TransferWithFeeProofData {
298300
equality_proof_data,
299301
transfer_amount_ciphertext_validity_proof_data,
300302
percentage_with_cap_proof_data,
301303
fee_ciphertext_validity_proof_data,
302304
range_proof_data,
303-
))
305+
})
304306
}
305307

306308
fn calculate_fee(transfer_amount: u64, fee_rate_basis_points: u16) -> Option<(u64, u64)> {

token/confidential-transfer/proof-tests/tests/proof_test.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use {
88
withdraw::WithdrawProofContext,
99
},
1010
spl_token_confidential_transfer_proof_generation::{
11-
transfer::transfer_split_proof_data,
12-
transfer_with_fee::transfer_with_fee_split_proof_data,
11+
transfer::{transfer_split_proof_data, TransferProofData},
12+
transfer_with_fee::{transfer_with_fee_split_proof_data, TransferWithFeeProofData},
1313
withdraw::{withdraw_proof_data, WithdrawProofData},
1414
},
1515
};
@@ -38,7 +38,11 @@ fn test_transfer_proof_validity(spendable_balance: u64, transfer_amount: u64) {
3838
let spendable_ciphertext = source_keypair.pubkey().encrypt(spendable_balance);
3939
let decryptable_balance = aes_key.encrypt(spendable_balance);
4040

41-
let (equality_proof_data, validity_proof_data, range_proof_data) = transfer_split_proof_data(
41+
let TransferProofData {
42+
equality_proof_data,
43+
ciphertext_validity_proof_data,
44+
range_proof_data,
45+
} = transfer_split_proof_data(
4246
&spendable_ciphertext,
4347
&decryptable_balance,
4448
transfer_amount,
@@ -50,12 +54,12 @@ fn test_transfer_proof_validity(spendable_balance: u64, transfer_amount: u64) {
5054
.unwrap();
5155

5256
equality_proof_data.verify_proof().unwrap();
53-
validity_proof_data.verify_proof().unwrap();
57+
ciphertext_validity_proof_data.verify_proof().unwrap();
5458
range_proof_data.verify_proof().unwrap();
5559

5660
TransferProofContext::verify_and_extract(
5761
equality_proof_data.context_data(),
58-
validity_proof_data.context_data(),
62+
ciphertext_validity_proof_data.context_data(),
5963
range_proof_data.context_data(),
6064
)
6165
.unwrap();
@@ -104,13 +108,13 @@ fn test_transfer_with_fee_proof_validity(
104108
let spendable_ciphertext = source_keypair.pubkey().encrypt(spendable_balance);
105109
let decryptable_balance = aes_key.encrypt(spendable_balance);
106110

107-
let (
111+
let TransferWithFeeProofData {
108112
equality_proof_data,
109113
transfer_amount_ciphertext_validity_proof_data,
110114
percentage_with_cap_proof_data,
111115
fee_ciphertext_validity_proof_data,
112116
range_proof_data,
113-
) = transfer_with_fee_split_proof_data(
117+
} = transfer_with_fee_split_proof_data(
114118
&spendable_ciphertext,
115119
&decryptable_balance,
116120
transfer_amount,

0 commit comments

Comments
 (0)