Skip to content

Commit

Permalink
Use Signers in transfer_with_fee_and_split_proofs_in_parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
joncinque committed Oct 25, 2023
1 parent d5d8106 commit 1dee02f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 66 deletions.
74 changes: 18 additions & 56 deletions token/client/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2725,7 +2725,9 @@ where
/// This function internally generates the ZK Token proof instructions to create the necessary
/// proof context states.
#[allow(clippy::too_many_arguments)]
pub async fn confidential_transfer_transfer_with_fee_and_split_proofs_in_parallel<S: Signer>(
pub async fn confidential_transfer_transfer_with_fee_and_split_proofs_in_parallel<
S: Signers,
>(
&self,
source_account: &Pubkey,
destination_account: &Pubkey,
Expand All @@ -2740,13 +2742,9 @@ where
withdraw_withheld_authority_elgamal_pubkey: &ElGamalPubkey,
fee_rate_basis_points: u16,
maximum_fee: u64,
source_authority_keypair: &S,
equality_proof_account_keypair: &S,
transfer_amount_ciphertext_validity_proof_account_keypair: &S,
fee_sigma_proof_account_keypair: &S,
fee_ciphertext_validity_proof_account_keypair: &S,
range_proof_account_keypair: &S,
context_state_authority_keypair: Option<&S>,
equality_and_ciphertext_validity_proof_signers: &S,
fee_sigma_signers: &S,
range_proof_signers: &S,
) -> TokenResult<(T::Output, T::Output, T::Output)> {
let account_info = if let Some(account_info) = account_info {
account_info
Expand Down Expand Up @@ -2807,48 +2805,30 @@ where
&source_decrypt_handles,
)?;

let mut equality_and_ciphertext_signers = vec![
&source_authority_keypair,
&equality_proof_account_keypair,
&transfer_amount_ciphertext_validity_proof_account_keypair,
];
if let Some(context_state_authority_keypair) = &context_state_authority_keypair {
equality_and_ciphertext_signers.push(context_state_authority_keypair);
}
let transfer_with_equality_and_ciphertext_valdity = self
.create_equality_and_ciphertext_validity_proof_context_states_for_transfer_with_fee_parallel(
context_state_accounts,
&equality_proof_data,
&transfer_amount_ciphertext_validity_proof_data,
&transfer_instruction,
&equality_and_ciphertext_signers,
equality_and_ciphertext_validity_proof_signers
);

let mut fee_sigma_signers = vec![
&source_authority_keypair,
&fee_sigma_proof_account_keypair,
&fee_ciphertext_validity_proof_account_keypair,
];
if let Some(context_state_authority_keypair) = &context_state_authority_keypair {
fee_sigma_signers.push(context_state_authority_keypair);
}
let transfer_with_fee_sigma_and_ciphertext_validity = self
.create_fee_sigma_and_ciphertext_validity_proof_context_states_for_transfer_with_fee_parallel(
context_state_accounts,
&fee_sigma_proof_data,
&fee_ciphertext_validity_proof_data,
&transfer_instruction,
&fee_sigma_signers,
fee_sigma_signers,
);

let transfer_with_range_proof = self
.create_range_proof_context_state_for_transfer_with_fee_parallel(
context_state_accounts,
&range_proof_data,
&transfer_instruction,
Some(source_authority_keypair),
range_proof_account_keypair,
context_state_authority_keypair,
range_proof_signers,
);

try_join!(
Expand Down Expand Up @@ -3104,65 +3084,47 @@ where

/// Create range proof context state account for a confidential transfer with fee.
#[allow(clippy::too_many_arguments)]
pub async fn create_range_proof_context_state_for_transfer_with_fee<S: Signer>(
pub async fn create_range_proof_context_state_for_transfer_with_fee<S: Signers>(
&self,
context_state_accounts: TransferWithFeeSplitContextStateAccounts<'_>,
range_proof_data: &BatchedRangeProofU256Data,
source_authority_keypair: Option<&S>,
range_proof_account_keypair: &S,
context_state_authority_keypair: Option<&S>,
signing_keypairs: &S,
) -> TokenResult<T::Output> {
self.create_range_proof_context_state_with_optional_transfer_with_fee(
context_state_accounts,
range_proof_data,
None,
source_authority_keypair,
range_proof_account_keypair,
context_state_authority_keypair,
signing_keypairs,
)
.await
}

/// Create range proof context state account for a confidential transfer with fee.
#[allow(clippy::too_many_arguments)]
pub async fn create_range_proof_context_state_for_transfer_with_fee_parallel<S: Signer>(
pub async fn create_range_proof_context_state_for_transfer_with_fee_parallel<S: Signers>(
&self,
context_state_accounts: TransferWithFeeSplitContextStateAccounts<'_>,
range_proof_data: &BatchedRangeProofU256Data,
transfer_instruction: &Instruction,
source_authority_keypair: Option<&S>,
range_proof_account_keypair: &S,
context_state_authority_keypair: Option<&S>,
signing_keypairs: &S,
) -> TokenResult<T::Output> {
self.create_range_proof_context_state_with_optional_transfer_with_fee(
context_state_accounts,
range_proof_data,
Some(transfer_instruction),
source_authority_keypair,
range_proof_account_keypair,
context_state_authority_keypair,
signing_keypairs,
)
.await
}

/// Create a range proof context state account and an optional confidential transfer instruction.
async fn create_range_proof_context_state_with_optional_transfer_with_fee<S: Signer>(
async fn create_range_proof_context_state_with_optional_transfer_with_fee<S: Signers>(
&self,
context_state_accounts: TransferWithFeeSplitContextStateAccounts<'_>,
range_proof_data: &BatchedRangeProofU256Data,
transfer_instruction: Option<&Instruction>,
source_authority_keypair: Option<&S>,
range_proof_account_keypair: &S,
context_state_authority_keypair: Option<&S>,
signing_keypairs: &S,
) -> TokenResult<T::Output> {
let mut signers = vec![range_proof_account_keypair];
if let Some(source_authority_keypair) = source_authority_keypair {
signers.push(source_authority_keypair);
}
if let Some(context_state_authority_keypair) = context_state_authority_keypair {
signers.push(context_state_authority_keypair);
}

let instruction_type = ProofInstruction::VerifyBatchedRangeProofU256;
let space = size_of::<ProofContextState<BatchedRangeProofContext>>();
let rent = self
Expand Down Expand Up @@ -3191,7 +3153,7 @@ where
instructions.push(transfer_instruction.clone());
}

self.process_ixs(&instructions, &signers).await
self.process_ixs(&instructions, signing_keypairs).await
}

/// Applies the confidential transfer pending balance to the available balance
Expand Down
25 changes: 15 additions & 10 deletions token/program-2022-test/tests/confidential_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2817,9 +2817,7 @@ async fn confidential_transfer_transfer_with_fee_and_split_proof_context() {
.create_range_proof_context_state_for_transfer_with_fee(
transfer_context_state_accounts,
&range_proof_data,
None,
&range_proof_context_state_account,
None,
&[&range_proof_context_state_account],
)
.await
.unwrap();
Expand Down Expand Up @@ -2992,6 +2990,17 @@ async fn confidential_transfer_transfer_with_fee_and_split_proof_context_in_para
close_split_context_state_accounts: None,
};

let equality_and_ciphertext_signers = vec![
&alice,
&equality_proof_context_state_account,
&transfer_amount_ciphertext_validity_proof_context_state_account,
];
let fee_sigma_signers = vec![
&alice,
&fee_sigma_proof_context_state_account,
&fee_ciphertext_validity_proof_context_state_account,
];
let range_proof_signers = vec![&alice, &range_proof_context_state_account];
token
.confidential_transfer_transfer_with_fee_and_split_proofs_in_parallel(
&alice_meta.token_account,
Expand All @@ -3007,13 +3016,9 @@ async fn confidential_transfer_transfer_with_fee_and_split_proof_context_in_para
withdraw_withheld_authority_elgamal_keypair.pubkey(),
TEST_FEE_BASIS_POINTS,
TEST_MAXIMUM_FEE,
&alice,
&equality_proof_context_state_account,
&transfer_amount_ciphertext_validity_proof_context_state_account,
&fee_sigma_proof_context_state_account,
&fee_ciphertext_validity_proof_context_state_account,
&range_proof_context_state_account,
None,
&equality_and_ciphertext_signers,
&fee_sigma_signers,
&range_proof_signers,
)
.await
.unwrap();
Expand Down

0 comments on commit 1dee02f

Please sign in to comment.