From e97bd22dc80a40fdc5956b6f8c137120fda649eb Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Wed, 11 Dec 2024 09:22:28 +0900 Subject: [PATCH] [program-2022] Make confidential mint/burn function parameters consistent (#7570) * make instruction constructor function parameters consistent * fix typo * make auditor pubkey optional in mint and burn proof generation * update token client * update program-2022 tests --- token/client/src/token.rs | 26 +++++++++------- .../proof-generation/src/burn.rs | 5 +++- .../proof-generation/src/mint.rs | 5 +++- .../proof-tests/tests/proof_test.rs | 4 +-- .../tests/initialize_mint.rs | 2 +- .../confidential_mint_burn/instruction.rs | 26 ++++++++-------- .../confidential_transfer/account_info.rs | 4 +-- .../confidential_transfer/instruction.rs | 30 +++++++++---------- .../extension/confidential_transfer/mod.rs | 2 +- .../confidential_transfer_fee/instruction.rs | 4 +-- 10 files changed, 59 insertions(+), 49 deletions(-) diff --git a/token/client/src/token.rs b/token/client/src/token.rs index 30fa7d40318..3d9f14777ff 100644 --- a/token/client/src/token.rs +++ b/token/client/src/token.rs @@ -305,7 +305,7 @@ impl ExtensionInitializationParams { token_program_id, mint, authority, - withdraw_withheld_authority_elgamal_pubkey, + &withdraw_withheld_authority_elgamal_pubkey, ) } Self::GroupPointer { @@ -2051,14 +2051,14 @@ where ) .unwrap(); - let decryptable_balance = aes_key.encrypt(0); + let decryptable_balance = aes_key.encrypt(0).into(); self.process_ixs( &confidential_transfer::instruction::configure_account( &self.program_id, account, &self.pubkey, - decryptable_balance.into(), + &decryptable_balance, maximum_pending_balance_credit_counter, authority, &multisig_signers, @@ -2265,7 +2265,8 @@ where let new_decryptable_available_balance = account_info .new_decryptable_available_balance(withdraw_amount, aes_key) - .map_err(|_| TokenError::AccountDecryption)?; + .map_err(|_| TokenError::AccountDecryption)? + .into(); self.process_ixs( &confidential_transfer::instruction::withdraw( @@ -2274,7 +2275,7 @@ where &self.pubkey, withdraw_amount, decimals, - new_decryptable_available_balance.into(), + &new_decryptable_available_balance, authority, &multisig_signers, equality_proof_location, @@ -2400,14 +2401,15 @@ where let new_decryptable_available_balance = account_info .new_decryptable_available_balance(transfer_amount, source_aes_key) - .map_err(|_| TokenError::AccountDecryption)?; + .map_err(|_| TokenError::AccountDecryption)? + .into(); let mut instructions = confidential_transfer::instruction::transfer( &self.program_id, source_account, self.get_address(), destination_account, - new_decryptable_available_balance.into(), + &new_decryptable_available_balance, &transfer_amount_auditor_ciphertext_lo, &transfer_amount_auditor_ciphertext_hi, source_authority, @@ -2794,14 +2796,15 @@ where let new_decryptable_available_balance = account_info .new_decryptable_available_balance(transfer_amount, source_aes_key) - .map_err(|_| TokenError::AccountDecryption)?; + .map_err(|_| TokenError::AccountDecryption)? + .into(); let mut instructions = confidential_transfer::instruction::transfer_with_fee( &self.program_id, source_account, self.get_address(), destination_account, - new_decryptable_available_balance.into(), + &new_decryptable_available_balance, &transfer_amount_auditor_ciphertext_lo, &transfer_amount_auditor_ciphertext_hi, source_authority, @@ -2856,14 +2859,15 @@ where let expected_pending_balance_credit_counter = account_info.pending_balance_credit_counter(); let new_decryptable_available_balance = account_info .new_decryptable_available_balance(elgamal_secret_key, aes_key) - .map_err(|_| TokenError::AccountDecryption)?; + .map_err(|_| TokenError::AccountDecryption)? + .into(); self.process_ixs( &[confidential_transfer::instruction::apply_pending_balance( &self.program_id, account, expected_pending_balance_credit_counter, - new_decryptable_available_balance.into(), + &new_decryptable_available_balance, authority, &multisig_signers, )?], diff --git a/token/confidential-transfer/proof-generation/src/burn.rs b/token/confidential-transfer/proof-generation/src/burn.rs index ae127d9e9a6..7d7b788fb11 100644 --- a/token/confidential-transfer/proof-generation/src/burn.rs +++ b/token/confidential-transfer/proof-generation/src/burn.rs @@ -36,9 +36,12 @@ pub fn burn_split_proof_data( burn_amount: u64, source_elgamal_keypair: &ElGamalKeypair, source_aes_key: &AeKey, - auditor_elgamal_pubkey: &ElGamalPubkey, + auditor_elgamal_pubkey: Option<&ElGamalPubkey>, supply_elgamal_pubkey: &ElGamalPubkey, ) -> Result { + let default_auditor_pubkey = ElGamalPubkey::default(); + let auditor_elgamal_pubkey = auditor_elgamal_pubkey.unwrap_or(&default_auditor_pubkey); + // split the burn amount into low and high bits let (burn_amount_lo, burn_amount_hi) = try_split_u64(burn_amount, BURN_AMOUNT_LO_BIT_LENGTH) .ok_or(TokenProofGenerationError::IllegalAmountBitLength)?; diff --git a/token/confidential-transfer/proof-generation/src/mint.rs b/token/confidential-transfer/proof-generation/src/mint.rs index 1f06a1c0156..a670a26ee27 100644 --- a/token/confidential-transfer/proof-generation/src/mint.rs +++ b/token/confidential-transfer/proof-generation/src/mint.rs @@ -38,8 +38,11 @@ pub fn mint_split_proof_data( supply_elgamal_keypair: &ElGamalKeypair, supply_aes_key: &AeKey, destination_elgamal_pubkey: &ElGamalPubkey, - auditor_elgamal_pubkey: &ElGamalPubkey, + auditor_elgamal_pubkey: Option<&ElGamalPubkey>, ) -> Result { + let default_auditor_pubkey = ElGamalPubkey::default(); + let auditor_elgamal_pubkey = auditor_elgamal_pubkey.unwrap_or(&default_auditor_pubkey); + // split the mint amount into low and high bits let (mint_amount_lo, mint_amount_hi) = try_split_u64(mint_amount, MINT_AMOUNT_LO_BIT_LENGTH) .ok_or(TokenProofGenerationError::IllegalAmountBitLength)?; diff --git a/token/confidential-transfer/proof-tests/tests/proof_test.rs b/token/confidential-transfer/proof-tests/tests/proof_test.rs index d5e0110e0af..9bcbfa25951 100644 --- a/token/confidential-transfer/proof-tests/tests/proof_test.rs +++ b/token/confidential-transfer/proof-tests/tests/proof_test.rs @@ -238,7 +238,7 @@ fn test_mint_validity(mint_amount: u64, supply: u64) { &supply_keypair, &supply_aes_key, destination_pubkey, - auditor_pubkey, + Some(auditor_pubkey), ) .unwrap(); @@ -291,7 +291,7 @@ fn test_burn_validity(spendable_balance: u64, burn_amount: u64) { burn_amount, &source_keypair, &aes_key, - auditor_pubkey, + Some(auditor_pubkey), supply_pubkey, ) .unwrap(); diff --git a/token/program-2022-test/tests/initialize_mint.rs b/token/program-2022-test/tests/initialize_mint.rs index 9152d2942aa..a14641f211d 100644 --- a/token/program-2022-test/tests/initialize_mint.rs +++ b/token/program-2022-test/tests/initialize_mint.rs @@ -523,7 +523,7 @@ async fn fail_invalid_extensions_combination() { &spl_token_2022::id(), &mint_account.pubkey(), Some(Pubkey::new_unique()), - PodElGamalPubkey::default(), + &PodElGamalPubkey::default(), ) .unwrap(); diff --git a/token/program-2022/src/extension/confidential_mint_burn/instruction.rs b/token/program-2022/src/extension/confidential_mint_burn/instruction.rs index 6ecd112433d..065e7ff9aeb 100644 --- a/token/program-2022/src/extension/confidential_mint_burn/instruction.rs +++ b/token/program-2022/src/extension/confidential_mint_burn/instruction.rs @@ -26,7 +26,7 @@ use { #[cfg(not(target_os = "solana"))] use { solana_zk_sdk::{ - encryption::{auth_encryption::AeCiphertext, elgamal::ElGamalPubkey}, + encryption::elgamal::ElGamalPubkey, zk_elgamal_proof_program::{ instruction::ProofInstruction, proof_data::{ @@ -291,8 +291,8 @@ pub struct BurnInstructionData { pub fn initialize_mint( token_program_id: &Pubkey, mint: &Pubkey, - supply_elgamal_pubkey: PodElGamalPubkey, - decryptable_supply: PodAeCiphertext, + supply_elgamal_pubkey: &PodElGamalPubkey, + decryptable_supply: &DecryptableBalance, ) -> Result { check_program_account(token_program_id)?; let accounts = vec![AccountMeta::new(*mint, false)]; @@ -303,8 +303,8 @@ pub fn initialize_mint( TokenInstruction::ConfidentialMintBurnExtension, ConfidentialMintBurnInstruction::InitializeMint, &InitializeMintData { - supply_elgamal_pubkey, - decryptable_supply, + supply_elgamal_pubkey: *supply_elgamal_pubkey, + decryptable_supply: *decryptable_supply, }, )) } @@ -317,7 +317,7 @@ pub fn rotate_supply_elgamal_pubkey( mint: &Pubkey, authority: &Pubkey, multisig_signers: &[&Pubkey], - new_supply_elgamal_pubkey: ElGamalPubkey, + new_supply_elgamal_pubkey: &PodElGamalPubkey, ciphertext_equality_proof: ProofLocation, ) -> Result, ProgramError> { check_program_account(token_program_id)?; @@ -349,7 +349,7 @@ pub fn rotate_supply_elgamal_pubkey( TokenInstruction::ConfidentialMintBurnExtension, ConfidentialMintBurnInstruction::RotateSupplyElGamalPubkey, &RotateSupplyElGamalPubkeyData { - new_supply_elgamal_pubkey: PodElGamalPubkey::from(new_supply_elgamal_pubkey), + new_supply_elgamal_pubkey: *new_supply_elgamal_pubkey, proof_instruction_offset, }, )]; @@ -366,7 +366,7 @@ pub fn update_decryptable_supply( mint: &Pubkey, authority: &Pubkey, multisig_signers: &[&Pubkey], - new_decryptable_supply: AeCiphertext, + new_decryptable_supply: &DecryptableBalance, ) -> Result { check_program_account(token_program_id)?; let mut accounts = vec![ @@ -382,7 +382,7 @@ pub fn update_decryptable_supply( TokenInstruction::ConfidentialMintBurnExtension, ConfidentialMintBurnInstruction::UpdateDecryptableSupply, &UpdateDecryptableSupplyData { - new_decryptable_supply: new_decryptable_supply.into(), + new_decryptable_supply: *new_decryptable_supply, }, )) } @@ -417,7 +417,7 @@ pub fn confidential_mint_with_split_proofs( BatchedGroupedCiphertext3HandlesValidityProofData, >, range_proof_location: ProofLocation, - new_decryptable_supply: AeCiphertext, + new_decryptable_supply: &DecryptableBalance, ) -> Result, ProgramError> { check_program_account(token_program_id)?; let mut accounts = vec![AccountMeta::new(*token_account, false)]; @@ -473,7 +473,7 @@ pub fn confidential_mint_with_split_proofs( TokenInstruction::ConfidentialMintBurnExtension, ConfidentialMintBurnInstruction::Mint, &MintInstructionData { - new_decryptable_supply: new_decryptable_supply.into(), + new_decryptable_supply: *new_decryptable_supply, mint_amount_auditor_ciphertext_lo: *mint_amount_auditor_ciphertext_lo, mint_amount_auditor_ciphertext_hi: *mint_amount_auditor_ciphertext_hi, equality_proof_instruction_offset, @@ -495,7 +495,7 @@ pub fn confidential_burn_with_split_proofs( token_account: &Pubkey, mint: &Pubkey, supply_elgamal_pubkey: Option, - new_decryptable_available_balance: DecryptableBalance, + new_decryptable_available_balance: &DecryptableBalance, burn_amount_auditor_ciphertext_lo: &PodElGamalCiphertext, burn_amount_auditor_ciphertext_hi: &PodElGamalCiphertext, authority: &Pubkey, @@ -559,7 +559,7 @@ pub fn confidential_burn_with_split_proofs( TokenInstruction::ConfidentialMintBurnExtension, ConfidentialMintBurnInstruction::Burn, &BurnInstructionData { - new_decryptable_available_balance, + new_decryptable_available_balance: *new_decryptable_available_balance, burn_amount_auditor_ciphertext_lo: *burn_amount_auditor_ciphertext_lo, burn_amount_auditor_ciphertext_hi: *burn_amount_auditor_ciphertext_hi, equality_proof_instruction_offset, diff --git a/token/program-2022/src/extension/confidential_transfer/account_info.rs b/token/program-2022/src/extension/confidential_transfer/account_info.rs index 39b819b9a70..672a8028904 100644 --- a/token/program-2022/src/extension/confidential_transfer/account_info.rs +++ b/token/program-2022/src/extension/confidential_transfer/account_info.rs @@ -147,7 +147,7 @@ impl ApplyPendingBalanceAccountInfo { #[repr(C)] #[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)] pub struct WithdrawAccountInfo { - /// The available balance (encrypted by `encrypiton_pubkey`) + /// The available balance (encrypted by `encryption_pubkey`) pub available_balance: EncryptedBalance, /// The decryptable available balance pub decryptable_available_balance: DecryptableBalance, @@ -214,7 +214,7 @@ impl WithdrawAccountInfo { #[repr(C)] #[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)] pub struct TransferAccountInfo { - /// The available balance (encrypted by `encrypiton_pubkey`) + /// The available balance (encrypted by `encryption_pubkey`) pub available_balance: EncryptedBalance, /// The decryptable available balance pub decryptable_available_balance: DecryptableBalance, diff --git a/token/program-2022/src/extension/confidential_transfer/instruction.rs b/token/program-2022/src/extension/confidential_transfer/instruction.rs index 9c641a01adc..5fa822529b5 100644 --- a/token/program-2022/src/extension/confidential_transfer/instruction.rs +++ b/token/program-2022/src/extension/confidential_transfer/instruction.rs @@ -762,7 +762,7 @@ pub fn inner_configure_account( token_program_id: &Pubkey, token_account: &Pubkey, mint: &Pubkey, - decryptable_zero_balance: PodAeCiphertext, + decryptable_zero_balance: &DecryptableBalance, maximum_pending_balance_credit_counter: u64, authority: &Pubkey, multisig_signers: &[&Pubkey], @@ -804,7 +804,7 @@ pub fn inner_configure_account( TokenInstruction::ConfidentialTransferExtension, ConfidentialTransferInstruction::ConfigureAccount, &ConfigureAccountInstructionData { - decryptable_zero_balance, + decryptable_zero_balance: *decryptable_zero_balance, maximum_pending_balance_credit_counter: maximum_pending_balance_credit_counter.into(), proof_instruction_offset, }, @@ -817,7 +817,7 @@ pub fn configure_account( token_program_id: &Pubkey, token_account: &Pubkey, mint: &Pubkey, - decryptable_zero_balance: PodAeCiphertext, + decryptable_zero_balance: &DecryptableBalance, maximum_pending_balance_credit_counter: u64, authority: &Pubkey, multisig_signers: &[&Pubkey], @@ -1015,7 +1015,7 @@ pub fn inner_withdraw( mint: &Pubkey, amount: u64, decimals: u8, - new_decryptable_available_balance: DecryptableBalance, + new_decryptable_available_balance: &DecryptableBalance, authority: &Pubkey, multisig_signers: &[&Pubkey], equality_proof_data_location: ProofLocation, @@ -1078,7 +1078,7 @@ pub fn inner_withdraw( &WithdrawInstructionData { amount: amount.into(), decimals, - new_decryptable_available_balance, + new_decryptable_available_balance: *new_decryptable_available_balance, equality_proof_instruction_offset, range_proof_instruction_offset, }, @@ -1093,7 +1093,7 @@ pub fn withdraw( mint: &Pubkey, amount: u64, decimals: u8, - new_decryptable_available_balance: PodAeCiphertext, + new_decryptable_available_balance: &DecryptableBalance, authority: &Pubkey, multisig_signers: &[&Pubkey], equality_proof_data_location: ProofLocation, @@ -1164,7 +1164,7 @@ pub fn inner_transfer( source_token_account: &Pubkey, mint: &Pubkey, destination_token_account: &Pubkey, - new_source_decryptable_available_balance: DecryptableBalance, + new_source_decryptable_available_balance: &DecryptableBalance, transfer_amount_auditor_ciphertext_lo: &PodElGamalCiphertext, transfer_amount_auditor_ciphertext_hi: &PodElGamalCiphertext, authority: &Pubkey, @@ -1246,7 +1246,7 @@ pub fn inner_transfer( TokenInstruction::ConfidentialTransferExtension, ConfidentialTransferInstruction::Transfer, &TransferInstructionData { - new_source_decryptable_available_balance, + new_source_decryptable_available_balance: *new_source_decryptable_available_balance, transfer_amount_auditor_ciphertext_lo: *transfer_amount_auditor_ciphertext_lo, transfer_amount_auditor_ciphertext_hi: *transfer_amount_auditor_ciphertext_hi, equality_proof_instruction_offset, @@ -1263,7 +1263,7 @@ pub fn transfer( source_token_account: &Pubkey, mint: &Pubkey, destination_token_account: &Pubkey, - new_source_decryptable_available_balance: DecryptableBalance, + new_source_decryptable_available_balance: &DecryptableBalance, transfer_amount_auditor_ciphertext_lo: &PodElGamalCiphertext, transfer_amount_auditor_ciphertext_hi: &PodElGamalCiphertext, authority: &Pubkey, @@ -1361,7 +1361,7 @@ pub fn inner_apply_pending_balance( token_program_id: &Pubkey, token_account: &Pubkey, expected_pending_balance_credit_counter: u64, - new_decryptable_available_balance: DecryptableBalance, + new_decryptable_available_balance: &DecryptableBalance, authority: &Pubkey, multisig_signers: &[&Pubkey], ) -> Result { @@ -1382,7 +1382,7 @@ pub fn inner_apply_pending_balance( ConfidentialTransferInstruction::ApplyPendingBalance, &ApplyPendingBalanceData { expected_pending_balance_credit_counter: expected_pending_balance_credit_counter.into(), - new_decryptable_available_balance, + new_decryptable_available_balance: *new_decryptable_available_balance, }, )) } @@ -1392,7 +1392,7 @@ pub fn apply_pending_balance( token_program_id: &Pubkey, token_account: &Pubkey, pending_balance_instructions: u64, - new_decryptable_available_balance: PodAeCiphertext, + new_decryptable_available_balance: &DecryptableBalance, authority: &Pubkey, multisig_signers: &[&Pubkey], ) -> Result { @@ -1505,7 +1505,7 @@ pub fn inner_transfer_with_fee( source_token_account: &Pubkey, mint: &Pubkey, destination_token_account: &Pubkey, - new_source_decryptable_available_balance: DecryptableBalance, + new_source_decryptable_available_balance: &DecryptableBalance, transfer_amount_auditor_ciphertext_lo: &PodElGamalCiphertext, transfer_amount_auditor_ciphertext_hi: &PodElGamalCiphertext, authority: &Pubkey, @@ -1620,7 +1620,7 @@ pub fn inner_transfer_with_fee( TokenInstruction::ConfidentialTransferExtension, ConfidentialTransferInstruction::TransferWithFee, &TransferWithFeeInstructionData { - new_source_decryptable_available_balance, + new_source_decryptable_available_balance: *new_source_decryptable_available_balance, transfer_amount_auditor_ciphertext_lo: *transfer_amount_auditor_ciphertext_lo, transfer_amount_auditor_ciphertext_hi: *transfer_amount_auditor_ciphertext_hi, equality_proof_instruction_offset, @@ -1639,7 +1639,7 @@ pub fn transfer_with_fee( source_token_account: &Pubkey, mint: &Pubkey, destination_token_account: &Pubkey, - new_source_decryptable_available_balance: DecryptableBalance, + new_source_decryptable_available_balance: &DecryptableBalance, transfer_amount_auditor_ciphertext_lo: &PodElGamalCiphertext, transfer_amount_auditor_ciphertext_hi: &PodElGamalCiphertext, authority: &Pubkey, diff --git a/token/program-2022/src/extension/confidential_transfer/mod.rs b/token/program-2022/src/extension/confidential_transfer/mod.rs index ab1bb71e162..baa371cf89f 100644 --- a/token/program-2022/src/extension/confidential_transfer/mod.rs +++ b/token/program-2022/src/extension/confidential_transfer/mod.rs @@ -90,7 +90,7 @@ pub struct ConfidentialTransferAccount { /// The high 48 bits of the pending balance (encrypted by `elgamal_pubkey`) pub pending_balance_hi: EncryptedBalance, - /// The available balance (encrypted by `encrypiton_pubkey`) + /// The available balance (encrypted by `encryption_pubkey`) pub available_balance: EncryptedBalance, /// The decryptable available balance diff --git a/token/program-2022/src/extension/confidential_transfer_fee/instruction.rs b/token/program-2022/src/extension/confidential_transfer_fee/instruction.rs index b27c82acb61..1d140e5af01 100644 --- a/token/program-2022/src/extension/confidential_transfer_fee/instruction.rs +++ b/token/program-2022/src/extension/confidential_transfer_fee/instruction.rs @@ -275,7 +275,7 @@ pub fn initialize_confidential_transfer_fee_config( token_program_id: &Pubkey, mint: &Pubkey, authority: Option, - withdraw_withheld_authority_elgamal_pubkey: PodElGamalPubkey, + withdraw_withheld_authority_elgamal_pubkey: &PodElGamalPubkey, ) -> Result { check_program_account(token_program_id)?; let accounts = vec![AccountMeta::new(*mint, false)]; @@ -287,7 +287,7 @@ pub fn initialize_confidential_transfer_fee_config( ConfidentialTransferFeeInstruction::InitializeConfidentialTransferFeeConfig, &InitializeConfidentialTransferFeeConfigData { authority: authority.try_into()?, - withdraw_withheld_authority_elgamal_pubkey, + withdraw_withheld_authority_elgamal_pubkey: *withdraw_withheld_authority_elgamal_pubkey, }, )) }