Skip to content

Commit

Permalink
update client for split transfer proofs
Browse files Browse the repository at this point in the history
  • Loading branch information
samkim-crypto committed Aug 13, 2023
1 parent 556d28c commit 089fa9a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 7 deletions.
26 changes: 22 additions & 4 deletions token/client/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ use {
ApplyPendingBalanceAccountInfo, EmptyAccountAccountInfo, TransferAccountInfo,
WithdrawAccountInfo,
},
ciphertext_extraction::SourceDecryptHandles,
instruction::TransferContextStateAccounts,
ConfidentialTransferAccount, DecryptableBalance,
},
confidential_transfer_fee::{
Expand Down Expand Up @@ -2139,14 +2141,15 @@ where
source_account: &Pubkey,
destination_account: &Pubkey,
source_authority: &Pubkey,
context_state_account: Option<&Pubkey>,
context_state_accounts: Option<TransferContextStateAccounts<'_>>,
transfer_amount: u64,
account_info: Option<TransferAccountInfo>,
source_elgamal_keypair: &ElGamalKeypair,
source_aes_key: &AeKey,
destination_elgamal_pubkey: &ElGamalPubkey,
auditor_elgamal_pubkey: Option<&ElGamalPubkey>,
signing_keypairs: &S,
source_decrypt_handles: Option<&SourceDecryptHandles>,
) -> TokenResult<T::Output> {
let signing_pubkeys = signing_keypairs.pubkeys();
let multisig_signers = self.get_multisig_signers(source_authority, &signing_pubkeys);
Expand All @@ -2160,7 +2163,7 @@ where
TransferAccountInfo::new(confidential_transfer_account)
};

let proof_data = if context_state_account.is_some() {
let proof_data = if context_state_accounts.is_some() {
None
} else {
Some(
Expand All @@ -2176,11 +2179,23 @@ where
)
};

let mut split_context_state_accounts = Vec::with_capacity(3);
let proof_location = if let Some(proof_data_temp) = proof_data.as_ref() {
ProofLocation::InstructionOffset(1.try_into().unwrap(), proof_data_temp)
} else {
let context_state_account = context_state_account.unwrap();
ProofLocation::ContextStateAccount(context_state_account)
let context_state_accounts = context_state_accounts.unwrap();
match context_state_accounts {
TransferContextStateAccounts::SingleAccount(context_state_account) => {
ProofLocation::ContextStateAccount(context_state_account)
}
TransferContextStateAccounts::SplitAccounts(context_state_accounts) => {
split_context_state_accounts.push(context_state_accounts.equality_proof);
split_context_state_accounts
.push(context_state_accounts.ciphertext_validity_proof);
split_context_state_accounts.push(context_state_accounts.range_proof);
ProofLocation::SplitContextStateAccounts(&split_context_state_accounts)
}
}
};

let new_decryptable_available_balance = account_info
Expand All @@ -2197,6 +2212,7 @@ where
source_authority,
&multisig_signers,
proof_location,
source_decrypt_handles,
)?,
signing_keypairs,
)
Expand All @@ -2221,6 +2237,7 @@ where
fee_rate_basis_points: u16,
maximum_fee: u64,
signing_keypairs: &S,
source_decrypt_handles: Option<&SourceDecryptHandles>,
) -> TokenResult<T::Output> {
let signing_pubkeys = signing_keypairs.pubkeys();
let multisig_signers = self.get_multisig_signers(source_authority, &signing_pubkeys);
Expand Down Expand Up @@ -2274,6 +2291,7 @@ where
source_authority,
&multisig_signers,
proof_location,
source_decrypt_handles,
)?,
signing_keypairs,
)
Expand Down
25 changes: 22 additions & 3 deletions token/program-2022-test/tests/confidential_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use {
error::TokenError,
extension::{
confidential_transfer::{
self, ConfidentialTransferAccount, MAXIMUM_DEPOSIT_TRANSFER_AMOUNT,
self, instruction::TransferContextStateAccounts, ConfidentialTransferAccount,
MAXIMUM_DEPOSIT_TRANSFER_AMOUNT,
},
BaseStateWithExtensions, ExtensionType,
},
Expand Down Expand Up @@ -972,6 +973,7 @@ async fn confidential_transfer_transfer() {
alice_meta.elgamal_keypair.pubkey(),
Some(auditor_elgamal_keypair.pubkey()),
&[&alice],
None,
)
.await
.unwrap();
Expand Down Expand Up @@ -1002,6 +1004,7 @@ async fn confidential_transfer_transfer() {
alice_meta.elgamal_keypair.pubkey(),
Some(auditor_elgamal_keypair.pubkey()),
&[&alice],
None,
)
.await
.unwrap();
Expand Down Expand Up @@ -1055,6 +1058,7 @@ async fn confidential_transfer_transfer() {
bob_meta.elgamal_keypair.pubkey(),
Some(auditor_elgamal_keypair.pubkey()),
&[&alice],
None,
)
.await
.unwrap();
Expand Down Expand Up @@ -1096,6 +1100,7 @@ async fn confidential_transfer_transfer() {
bob_meta.elgamal_keypair.pubkey(),
Some(auditor_elgamal_keypair.pubkey()),
&[&bob],
None,
)
.await
.unwrap();
Expand All @@ -1113,6 +1118,7 @@ async fn confidential_transfer_transfer() {
bob_meta.elgamal_keypair.pubkey(),
Some(auditor_elgamal_keypair.pubkey()),
&[&bob],
None,
)
.await
.unwrap_err();
Expand Down Expand Up @@ -1232,6 +1238,7 @@ async fn confidential_transfer_transfer_with_fee() {
TEST_FEE_BASIS_POINTS,
TEST_MAXIMUM_FEE,
&[&alice],
None,
)
.await
.unwrap();
Expand Down Expand Up @@ -1265,6 +1272,7 @@ async fn confidential_transfer_transfer_with_fee() {
TEST_FEE_BASIS_POINTS,
TEST_MAXIMUM_FEE,
&[&alice],
None,
)
.await
.unwrap();
Expand Down Expand Up @@ -1321,6 +1329,7 @@ async fn confidential_transfer_transfer_with_fee() {
TEST_FEE_BASIS_POINTS,
TEST_MAXIMUM_FEE,
&[&alice],
None,
)
.await
.unwrap();
Expand Down Expand Up @@ -1465,6 +1474,7 @@ async fn confidential_transfer_transfer_memo() {
bob_meta.elgamal_keypair.pubkey(),
Some(auditor_elgamal_keypair.pubkey()),
&[&alice],
None,
)
.await
.unwrap_err();
Expand Down Expand Up @@ -1494,6 +1504,7 @@ async fn confidential_transfer_transfer_memo() {
bob_meta.elgamal_keypair.pubkey(),
Some(auditor_elgamal_keypair.pubkey()),
&[&alice],
None,
)
.await
.unwrap();
Expand Down Expand Up @@ -1600,6 +1611,7 @@ async fn confidential_transfer_transfer_with_fee_and_memo() {
TEST_FEE_BASIS_POINTS,
TEST_MAXIMUM_FEE,
&[&alice],
None,
)
.await
.unwrap_err();
Expand Down Expand Up @@ -1631,6 +1643,7 @@ async fn confidential_transfer_transfer_with_fee_and_memo() {
TEST_FEE_BASIS_POINTS,
TEST_MAXIMUM_FEE,
&[&alice],
None,
)
.await
.unwrap();
Expand Down Expand Up @@ -2268,14 +2281,17 @@ async fn confidential_transfer_transfer_with_proof_context() {
&alice_meta.token_account,
&bob_meta.token_account,
&alice.pubkey(),
Some(&context_state_account.pubkey()),
Some(TransferContextStateAccounts::SingleAccount(
&context_state_account.pubkey(),
)),
42,
None,
&alice_meta.elgamal_keypair,
&alice_meta.aes_key,
bob_meta.elgamal_keypair.pubkey(),
Some(auditor_elgamal_keypair.pubkey()),
&[&alice],
None,
)
.await
.unwrap();
Expand Down Expand Up @@ -2339,14 +2355,17 @@ async fn confidential_transfer_transfer_with_proof_context() {
&alice_meta.token_account,
&bob_meta.token_account,
&alice.pubkey(),
Some(&context_state_account.pubkey()),
Some(TransferContextStateAccounts::SingleAccount(
&context_state_account.pubkey(),
)),
0,
None,
&alice_meta.elgamal_keypair,
&alice_meta.aes_key,
bob_meta.elgamal_keypair.pubkey(),
Some(auditor_elgamal_keypair.pubkey()),
&[&alice],
None,
)
.await
.unwrap_err();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,26 @@ pub struct ApplyPendingBalanceData {
pub new_decryptable_available_balance: DecryptableBalance,
}

/// Type for transfer instruction proof context state account addresses intended to be used as
/// parameters to functions.
pub enum TransferContextStateAccounts<'a> {
/// The context state account address for a single transfer proof context.
SingleAccount(&'a Pubkey),
/// The context state account addresses for the context states of a split transfer proof.
SplitAccounts(TransferSplitContextStateAccounts<'a>),
}

/// Type for split transfer instruction proof context state account addresses intended to be used
/// as parameters to functions.
pub struct TransferSplitContextStateAccounts<'a> {
/// The context state account address for an equality proof needed for a transfer.
pub equality_proof: &'a Pubkey,
/// The context state account address for a ciphertext validity proof needed for a transfer.
pub ciphertext_validity_proof: &'a Pubkey,
/// The context state account address for a range proof needed for a transfer.
pub range_proof: &'a Pubkey,
}

/// Create a `InitializeMint` instruction
#[cfg(not(target_os = "solana"))]
pub fn initialize_mint(
Expand Down

0 comments on commit 089fa9a

Please sign in to comment.