Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[token-2022] Update confidential transfer instruction to support split proof contexts #5001

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading
Loading