From 7440e4bc727af765f6704be7a6a5318bc71a882c Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Wed, 21 Aug 2024 20:47:21 +0900 Subject: [PATCH] [token-client] use `Signers`instead of `Signer` for confidential transfer client functions (#7175) --- token/cli/src/command.rs | 29 +++++--- token/client/src/token.rs | 32 ++++----- .../tests/confidential_transfer.rs | 72 +++++++++---------- .../tests/confidential_transfer_fee.rs | 12 ++-- 4 files changed, 76 insertions(+), 69 deletions(-) diff --git a/token/cli/src/command.rs b/token/cli/src/command.rs index cc3f7b93439..b104a026832 100644 --- a/token/cli/src/command.rs +++ b/token/cli/src/command.rs @@ -1604,27 +1604,32 @@ async fn command_transfer( .unwrap(); // setup proofs + let create_range_proof_context_signer = &[&range_proof_context_state_account]; + let create_equality_proof_context_signer = &[&equality_proof_context_state_account]; + let create_ciphertext_validity_proof_context_signer = + &[&ciphertext_validity_proof_context_state_account]; + let _ = try_join!( token.confidential_transfer_create_context_state_account( &range_proof_pubkey, &context_state_authority_pubkey, &range_proof_data, true, - &range_proof_context_state_account, + create_range_proof_context_signer ), token.confidential_transfer_create_context_state_account( &equality_proof_pubkey, &context_state_authority_pubkey, &equality_proof_data, false, - &equality_proof_context_state_account, + create_equality_proof_context_signer ), token.confidential_transfer_create_context_state_account( &ciphertext_validity_proof_pubkey, &context_state_authority_pubkey, &ciphertext_validity_proof_data, false, - &ciphertext_validity_proof_context_state_account, + create_ciphertext_validity_proof_context_signer ) )?; @@ -1655,24 +1660,25 @@ async fn command_transfer( .await?; // close context state accounts + let close_context_state_signer = &[&context_state_authority]; let _ = try_join!( token.confidential_transfer_close_context_state( &equality_proof_pubkey, &sender, &context_state_authority_pubkey, - &context_state_authority, + close_context_state_signer ), token.confidential_transfer_close_context_state( &ciphertext_validity_proof_pubkey, &sender, &context_state_authority_pubkey, - &context_state_authority, + close_context_state_signer ), token.confidential_transfer_close_context_state( &range_proof_pubkey, &sender, &context_state_authority_pubkey, - &context_state_authority, + close_context_state_signer ), )?; @@ -3353,6 +3359,8 @@ async fn command_deposit_withdraw_confidential_tokens( // set up context state accounts let context_state_authority_pubkey = context_state_authority.pubkey(); + let create_equality_proof_signer = &[&equality_proof_context_state_keypair]; + let create_range_proof_signer = &[&range_proof_context_state_keypair]; let _ = try_join!( token.confidential_transfer_create_context_state_account( @@ -3360,14 +3368,14 @@ async fn command_deposit_withdraw_confidential_tokens( &context_state_authority_pubkey, &equality_proof_data, false, - &equality_proof_context_state_keypair, + create_equality_proof_signer ), token.confidential_transfer_create_context_state_account( &range_proof_context_state_pubkey, &context_state_authority_pubkey, &range_proof_data, true, - &range_proof_context_state_keypair, + create_range_proof_signer, ) )?; @@ -3392,18 +3400,19 @@ async fn command_deposit_withdraw_confidential_tokens( .await?; // close context state account + let close_context_state_signer = &[&context_state_authority]; let _ = try_join!( token.confidential_transfer_close_context_state( &equality_proof_context_state_pubkey, &token_account_address, &context_state_authority_pubkey, - &context_state_authority, + close_context_state_signer ), token.confidential_transfer_close_context_state( &range_proof_context_state_pubkey, &token_account_address, &context_state_authority_pubkey, - &context_state_authority, + close_context_state_signer ) )?; diff --git a/token/client/src/token.rs b/token/client/src/token.rs index 5c4ce3499b1..d9e6a325f62 100644 --- a/token/client/src/token.rs +++ b/token/client/src/token.rs @@ -2271,7 +2271,8 @@ where /// Create a record account containing zero-knowledge proof needed for a /// confidential transfer. pub async fn confidential_transfer_create_record_account< - S: Signer, + S1: Signer, + S2: Signer, ZK: Pod + ZkProofData, U: Pod, >( @@ -2279,8 +2280,8 @@ where record_account: &Pubkey, record_authority: &Pubkey, proof_data: &ZK, - record_account_signer: &S, - record_authority_signer: &S, + record_account_signer: &S1, + record_authority_signer: &S2, ) -> TokenResult> { let proof_data = bytes_of(proof_data); let space = proof_data @@ -2326,11 +2327,8 @@ where }; let first_ixs = create_record_instructions(true, first_chunk, 0); - self.process_ixs( - &first_ixs, - &[record_account_signer, record_authority_signer], - ) - .await?; + let first_ixs_signers: [&dyn Signer; 2] = [record_account_signer, record_authority_signer]; + self.process_ixs(&first_ixs, &first_ixs_signers).await?; let subsequent_chunk_size = calculate_record_max_chunk_size(create_record_instructions, false); @@ -2354,12 +2352,12 @@ where } /// Close a record account. - pub async fn confidential_transfer_close_record_account( + pub async fn confidential_transfer_close_record_account( &self, record_account: &Pubkey, record_authority: &Pubkey, receiver: &Pubkey, - record_authority_signer: &S, + signing_keypairs: &S, ) -> TokenResult { self.process_ixs( &[spl_record::instruction::close_account( @@ -2367,7 +2365,7 @@ where record_authority, receiver, )], - &[record_authority_signer], + signing_keypairs, ) .await } @@ -2375,7 +2373,7 @@ where /// Create a context state account containing zero-knowledge proof needed /// for a confidential transfer instruction. pub async fn confidential_transfer_create_context_state_account< - S: Signer, + S: Signers, ZK: Pod + ZkProofData, U: Pod, >( @@ -2384,7 +2382,7 @@ where context_state_authority: &Pubkey, proof_data: &ZK, split_account_creation_and_proof_verification: bool, - signer: &S, + signing_keypairs: &S, ) -> TokenResult { let instruction_type = zk_proof_type_to_instruction(ZK::PROOF_TYPE)?; let space = size_of::>(); @@ -2410,7 +2408,7 @@ where space as u64, &zk_elgamal_proof_program::id(), )], - &[signer], + signing_keypairs, ) .await?; @@ -2443,14 +2441,14 @@ where ), instruction_type.encode_verify_proof(Some(context_state_info), proof_data), ], - &[signer], + signing_keypairs, ) .await } } /// Close a ZK Token proof program context state - pub async fn confidential_transfer_close_context_state( + pub async fn confidential_transfer_close_context_state( &self, context_state_account: &Pubkey, lamport_destination_account: &Pubkey, @@ -2467,7 +2465,7 @@ where context_state_info, lamport_destination_account, )], - &[signing_keypairs], + signing_keypairs, ) .await } diff --git a/token/program-2022-test/tests/confidential_transfer.rs b/token/program-2022-test/tests/confidential_transfer.rs index c7deca08ada..b8668fe9315 100644 --- a/token/program-2022-test/tests/confidential_transfer.rs +++ b/token/program-2022-test/tests/confidential_transfer.rs @@ -112,7 +112,7 @@ async fn configure_account_with_option( &pubkey_validity_proof_record_account.pubkey(), &record_account_authority.pubkey(), account, - &record_account_authority, + &[&record_account_authority], ) .await .unwrap(); @@ -131,7 +131,7 @@ async fn configure_account_with_option( &context_account_authority.pubkey(), &pubkey_validity_proof_data, false, - &pubkey_validity_proof_context_account, + &[&pubkey_validity_proof_context_account], ) .await .unwrap(); @@ -156,7 +156,7 @@ async fn configure_account_with_option( &pubkey_validity_proof_context_account.pubkey(), account, &context_account_authority.pubkey(), - &context_account_authority, + &[&context_account_authority], ) .await .unwrap(); @@ -639,7 +639,7 @@ async fn empty_account_with_option( &zero_ciphertext_proof_record_account.pubkey(), &record_account_authority.pubkey(), account, - &record_account_authority, + &[&record_account_authority], ) .await .unwrap(); @@ -665,7 +665,7 @@ async fn empty_account_with_option( &context_account_authority.pubkey(), &zero_ciphertext_proof_data, false, - &zero_ciphertext_proof_context_account, + &[&zero_ciphertext_proof_context_account], ) .await .unwrap(); @@ -689,7 +689,7 @@ async fn empty_account_with_option( &zero_ciphertext_proof_context_account.pubkey(), account, &context_account_authority.pubkey(), - &context_account_authority, + &[&context_account_authority], ) .await .unwrap(); @@ -1056,7 +1056,7 @@ async fn withdraw_with_option( &equality_proof_record_account.pubkey(), &record_account_authority.pubkey(), source_account, - &record_account_authority, + &[&record_account_authority], ) .await .unwrap(); @@ -1066,7 +1066,7 @@ async fn withdraw_with_option( &range_proof_record_account.pubkey(), &record_account_authority.pubkey(), source_account, - &record_account_authority, + &[&record_account_authority], ) .await .unwrap(); @@ -1097,7 +1097,7 @@ async fn withdraw_with_option( &context_account_authority.pubkey(), &equality_proof_data, false, - &equality_proof_context_account, + &[&equality_proof_context_account], ) .await .unwrap(); @@ -1111,7 +1111,7 @@ async fn withdraw_with_option( &context_account_authority.pubkey(), &range_proof_data, false, - &range_proof_context_account, + &[&range_proof_context_account], ) .await .unwrap(); @@ -1139,7 +1139,7 @@ async fn withdraw_with_option( &equality_proof_context_account.pubkey(), source_account, &context_account_authority.pubkey(), - &context_account_authority, + &[&context_account_authority], ) .await .unwrap(); @@ -1149,7 +1149,7 @@ async fn withdraw_with_option( &range_proof_context_account.pubkey(), source_account, &context_account_authority.pubkey(), - &context_account_authority, + &[&context_account_authority], ) .await .unwrap(); @@ -1428,7 +1428,7 @@ async fn confidential_transfer_with_option( &equality_proof_record_account.pubkey(), &record_account_authority.pubkey(), source_account, - &record_account_authority, + &[&record_account_authority], ) .await .unwrap(); @@ -1438,7 +1438,7 @@ async fn confidential_transfer_with_option( &ciphertext_validity_proof_record_account.pubkey(), &record_account_authority.pubkey(), source_account, - &record_account_authority, + &[&record_account_authority], ) .await .unwrap(); @@ -1448,7 +1448,7 @@ async fn confidential_transfer_with_option( &range_proof_record_account.pubkey(), &record_account_authority.pubkey(), source_account, - &record_account_authority, + &[&record_account_authority], ) .await .unwrap(); @@ -1487,7 +1487,7 @@ async fn confidential_transfer_with_option( &context_account_authority.pubkey(), &equality_proof_data, false, - &equality_proof_context_account, + &[&equality_proof_context_account], ) .await .unwrap(); @@ -1501,7 +1501,7 @@ async fn confidential_transfer_with_option( &context_account_authority.pubkey(), &ciphertext_validity_proof_data, false, - &ciphertext_validity_proof_context_account, + &[&ciphertext_validity_proof_context_account], ) .await .unwrap(); @@ -1515,7 +1515,7 @@ async fn confidential_transfer_with_option( &context_account_authority.pubkey(), &range_proof_data, false, - &range_proof_context_account, + &[&range_proof_context_account], ) .await .unwrap(); @@ -1552,7 +1552,7 @@ async fn confidential_transfer_with_option( &equality_proof_context_account.pubkey(), source_account, &context_account_authority.pubkey(), - &context_account_authority, + &[&context_account_authority], ) .await .unwrap(); @@ -1562,7 +1562,7 @@ async fn confidential_transfer_with_option( &ciphertext_validity_proof_context_account.pubkey(), source_account, &context_account_authority.pubkey(), - &context_account_authority, + &[&context_account_authority], ) .await .unwrap(); @@ -1572,7 +1572,7 @@ async fn confidential_transfer_with_option( &range_proof_context_account.pubkey(), source_account, &context_account_authority.pubkey(), - &context_account_authority, + &[&context_account_authority], ) .await .unwrap(); @@ -2026,7 +2026,7 @@ async fn confidential_transfer_with_fee_with_option( &equality_proof_record_account.pubkey(), &record_account_authority.pubkey(), source_account, - &record_account_authority, + &[&record_account_authority], ) .await .unwrap(); @@ -2036,7 +2036,7 @@ async fn confidential_transfer_with_fee_with_option( &transfer_amount_ciphertext_validity_proof_record_account.pubkey(), &record_account_authority.pubkey(), source_account, - &record_account_authority, + &[&record_account_authority], ) .await .unwrap(); @@ -2046,7 +2046,7 @@ async fn confidential_transfer_with_fee_with_option( &fee_sigma_proof_record_account.pubkey(), &record_account_authority.pubkey(), source_account, - &record_account_authority, + &[&record_account_authority], ) .await .unwrap(); @@ -2056,7 +2056,7 @@ async fn confidential_transfer_with_fee_with_option( &fee_ciphertext_validity_proof_record_account.pubkey(), &record_account_authority.pubkey(), source_account, - &record_account_authority, + &[&record_account_authority], ) .await .unwrap(); @@ -2066,7 +2066,7 @@ async fn confidential_transfer_with_fee_with_option( &range_proof_record_account.pubkey(), &record_account_authority.pubkey(), source_account, - &record_account_authority, + &[&record_account_authority], ) .await .unwrap(); @@ -2112,7 +2112,7 @@ async fn confidential_transfer_with_fee_with_option( &context_account_authority.pubkey(), &equality_proof_data, false, - &equality_proof_context_account, + &[&equality_proof_context_account], ) .await .unwrap(); @@ -2126,7 +2126,7 @@ async fn confidential_transfer_with_fee_with_option( &context_account_authority.pubkey(), &transfer_amount_ciphertext_validity_proof_data, false, - &transfer_amount_ciphertext_validity_proof_context_account, + &[&transfer_amount_ciphertext_validity_proof_context_account], ) .await .unwrap(); @@ -2142,7 +2142,7 @@ async fn confidential_transfer_with_fee_with_option( &context_account_authority.pubkey(), &percentage_with_cap_proof_data, false, - &percentage_with_cap_proof_context_account, + &[&percentage_with_cap_proof_context_account], ) .await .unwrap(); @@ -2156,7 +2156,7 @@ async fn confidential_transfer_with_fee_with_option( &context_account_authority.pubkey(), &fee_ciphertext_validity_proof_data, false, - &fee_ciphertext_validity_proof_context_account, + &[&fee_ciphertext_validity_proof_context_account], ) .await .unwrap(); @@ -2171,7 +2171,7 @@ async fn confidential_transfer_with_fee_with_option( &context_account_authority.pubkey(), &range_proof_data, false, - &range_proof_context_account, + &[&range_proof_context_account], ) .await .unwrap(); @@ -2213,7 +2213,7 @@ async fn confidential_transfer_with_fee_with_option( &equality_proof_context_account.pubkey(), source_account, &context_account_authority.pubkey(), - &context_account_authority, + &[&context_account_authority], ) .await .unwrap(); @@ -2223,7 +2223,7 @@ async fn confidential_transfer_with_fee_with_option( &transfer_amount_ciphertext_validity_proof_context_account.pubkey(), source_account, &context_account_authority.pubkey(), - &context_account_authority, + &[&context_account_authority], ) .await .unwrap(); @@ -2233,7 +2233,7 @@ async fn confidential_transfer_with_fee_with_option( &percentage_with_cap_proof_context_account.pubkey(), source_account, &context_account_authority.pubkey(), - &context_account_authority, + &[&context_account_authority], ) .await .unwrap(); @@ -2243,7 +2243,7 @@ async fn confidential_transfer_with_fee_with_option( &fee_ciphertext_validity_proof_context_account.pubkey(), source_account, &context_account_authority.pubkey(), - &context_account_authority, + &[&context_account_authority], ) .await .unwrap(); @@ -2253,7 +2253,7 @@ async fn confidential_transfer_with_fee_with_option( &range_proof_context_account.pubkey(), source_account, &context_account_authority.pubkey(), - &context_account_authority, + &[&context_account_authority], ) .await .unwrap(); diff --git a/token/program-2022-test/tests/confidential_transfer_fee.rs b/token/program-2022-test/tests/confidential_transfer_fee.rs index ebf3f86c7d9..fb6e4f4e08a 100644 --- a/token/program-2022-test/tests/confidential_transfer_fee.rs +++ b/token/program-2022-test/tests/confidential_transfer_fee.rs @@ -536,7 +536,7 @@ async fn withdraw_withheld_tokens_from_mint_with_option( &record_account.pubkey(), &record_account_authority.pubkey(), destination_account, - &record_account_authority, + &[&record_account_authority], ) .await .unwrap(); @@ -566,7 +566,7 @@ async fn withdraw_withheld_tokens_from_mint_with_option( &context_account_authority.pubkey(), &equality_proof, false, - &context_account, + &[&context_account], ) .await .unwrap(); @@ -591,7 +591,7 @@ async fn withdraw_withheld_tokens_from_mint_with_option( &context_account.pubkey(), destination_account, &context_account_authority.pubkey(), - &context_account_authority, + &[&context_account_authority], ) .await .unwrap(); @@ -861,7 +861,7 @@ async fn withdraw_withheld_tokens_from_accounts_with_option( &record_account.pubkey(), &record_account_authority.pubkey(), destination_account, - &record_account_authority, + &[&record_account_authority], ) .await .unwrap(); @@ -891,7 +891,7 @@ async fn withdraw_withheld_tokens_from_accounts_with_option( &context_account_authority.pubkey(), &equality_proof, false, - &context_account, + &[&context_account], ) .await .unwrap(); @@ -917,7 +917,7 @@ async fn withdraw_withheld_tokens_from_accounts_with_option( &context_account.pubkey(), destination_account, &context_account_authority.pubkey(), - &context_account_authority, + &[&context_account_authority], ) .await .unwrap();