diff --git a/token/program-2022-test/tests/confidential_mint_burn.rs b/token/program-2022-test/tests/confidential_mint_burn.rs index f0612eedec3..af2b05f42ec 100644 --- a/token/program-2022-test/tests/confidential_mint_burn.rs +++ b/token/program-2022-test/tests/confidential_mint_burn.rs @@ -1,4 +1,4 @@ -#![cfg(feature = "test-sbf")] +//#![cfg(feature = "test-sbf")] mod program_test; use { @@ -19,7 +19,7 @@ use { }, spl_token_client::{ client::ProgramBanksClientProcessTransaction, - token::{ExtensionInitializationParams, ProofAccount, Token}, + token::{ExtensionInitializationParams, ProofAccount, ProofAccountWithCiphertext, Token}, }, spl_token_confidential_transfer_proof_generation::{ burn::burn_split_proof_data, mint::mint_split_proof_data, @@ -36,21 +36,27 @@ async fn test_confidential_mint() { let auditor_elgamal_keypair = ElGamalKeypair::new_rand(); let auditor_elgamal_pubkey = (*auditor_elgamal_keypair.pubkey()).into(); let supply_aes_key = AeKey::new_rand(); + let mint_account = Keypair::new(); let mut context = TestContext::new().await; context - .init_token_with_mint(vec![ - ExtensionInitializationParams::ConfidentialTransferMint { - authority: Some(authority.pubkey()), - auto_approve_new_accounts: true, - auditor_elgamal_pubkey: Some(auditor_elgamal_pubkey), - }, - ExtensionInitializationParams::ConfidentialMintBurnMint { - authority: authority.pubkey(), - confidential_supply_pubkey: Some(auditor_elgamal_pubkey), - decryptable_supply: Some(supply_aes_key.encrypt(0).into()), - }, - ]) + .init_token_with_mint_keypair_and_freeze_authority_and_mint_authority( + mint_account, + vec![ + ExtensionInitializationParams::ConfidentialTransferMint { + authority: Some(authority.pubkey()), + auto_approve_new_accounts: true, + auditor_elgamal_pubkey: Some(auditor_elgamal_pubkey), + }, + ExtensionInitializationParams::ConfidentialMintBurnMint { + confidential_supply_pubkey: auditor_elgamal_pubkey, + decryptable_supply: supply_aes_key.encrypt(0).into(), + }, + ], + None, + // hacky but we have to clone somehow + Keypair::from_bytes(&authority.to_bytes()).unwrap(), + ) .await .unwrap(); @@ -121,21 +127,26 @@ async fn test_confidential_burn() { let auditor_elgamal_keypair = ElGamalKeypair::new_rand(); let auditor_elgamal_pubkey = (*auditor_elgamal_keypair.pubkey()).into(); let supply_aes_key = AeKey::new_rand(); + let mint_account = Keypair::new(); let mut context = TestContext::new().await; context - .init_token_with_mint(vec![ - ExtensionInitializationParams::ConfidentialTransferMint { - authority: Some(authority.pubkey()), - auto_approve_new_accounts: true, - auditor_elgamal_pubkey: Some(auditor_elgamal_pubkey), - }, - ExtensionInitializationParams::ConfidentialMintBurnMint { - authority: authority.pubkey(), - confidential_supply_pubkey: Some(auditor_elgamal_pubkey), - decryptable_supply: Some(supply_aes_key.encrypt(0).into()), - }, - ]) + .init_token_with_mint_keypair_and_freeze_authority_and_mint_authority( + mint_account, + vec![ + ExtensionInitializationParams::ConfidentialTransferMint { + authority: Some(authority.pubkey()), + auto_approve_new_accounts: true, + auditor_elgamal_pubkey: Some(auditor_elgamal_pubkey), + }, + ExtensionInitializationParams::ConfidentialMintBurnMint { + confidential_supply_pubkey: auditor_elgamal_pubkey, + decryptable_supply: supply_aes_key.encrypt(0).into(), + }, + ], + None, + Keypair::from_bytes(&authority.to_bytes()).unwrap(), + ) .await .unwrap(); @@ -227,7 +238,9 @@ async fn test_confidential_burn() { .confidential_transfer_create_context_state_account( &ciphertext_validity_proof_context_pubkey, &context_state_auth_pubkey, - &proof_data.ciphertext_validity_proof_data, + &proof_data + .ciphertext_validity_proof_data_with_ciphertext + .proof_data, false, ciphertext_validity_proof_signer, ) @@ -247,6 +260,15 @@ async fn test_confidential_burn() { let equality_proof_location = ProofAccount::ContextAccount(equality_proof_context_pubkey); let ciphertext_validity_proof_location = ProofAccount::ContextAccount(ciphertext_validity_proof_context_pubkey); + let ciphertext_validity_proof_location = ProofAccountWithCiphertext { + proof_account: ciphertext_validity_proof_location, + ciphertext_lo: proof_data + .ciphertext_validity_proof_data_with_ciphertext + .ciphertext_lo, + ciphertext_hi: proof_data + .ciphertext_validity_proof_data_with_ciphertext + .ciphertext_hi, + }; let range_proof_location = ProofAccount::ContextAccount(range_proof_context_pubkey); // do the burn @@ -324,21 +346,26 @@ async fn test_rotate_supply_elgamal() { let auditor_elgamal_keypair = ElGamalKeypair::new_rand(); let auditor_elgamal_pubkey = (*auditor_elgamal_keypair.pubkey()).into(); let supply_aes_key = AeKey::new_rand(); + let mint_account = Keypair::new(); let mut context = TestContext::new().await; context - .init_token_with_mint(vec![ - ExtensionInitializationParams::ConfidentialTransferMint { - authority: Some(authority.pubkey()), - auto_approve_new_accounts: true, - auditor_elgamal_pubkey: Some(auditor_elgamal_pubkey), - }, - ExtensionInitializationParams::ConfidentialMintBurnMint { - authority: authority.pubkey(), - confidential_supply_pubkey: Some(auditor_elgamal_pubkey), - decryptable_supply: Some(supply_aes_key.encrypt(0).into()), - }, - ]) + .init_token_with_mint_keypair_and_freeze_authority_and_mint_authority( + mint_account, + vec![ + ExtensionInitializationParams::ConfidentialTransferMint { + authority: Some(authority.pubkey()), + auto_approve_new_accounts: true, + auditor_elgamal_pubkey: Some(auditor_elgamal_pubkey), + }, + ExtensionInitializationParams::ConfidentialMintBurnMint { + confidential_supply_pubkey: auditor_elgamal_pubkey, + decryptable_supply: supply_aes_key.encrypt(0).into(), + }, + ], + None, + Keypair::from_bytes(&authority.to_bytes()).unwrap(), + ) .await .unwrap(); @@ -400,11 +427,7 @@ async fn test_rotate_supply_elgamal() { assert_eq!( mint_burn_extension.supply_elgamal_pubkey, - Some(Into::::into( - *new_supply_elgamal_keypair.pubkey(), - )) - .try_into() - .unwrap(), + Into::::into(*new_supply_elgamal_keypair.pubkey(),), ); } @@ -465,7 +488,9 @@ async fn mint_tokens( .confidential_transfer_create_context_state_account( &ciphertext_validity_proof_context_pubkey, &context_state_auth.pubkey(), - &proof_data.ciphertext_validity_proof_data, + &proof_data + .ciphertext_validity_proof_data_with_ciphertext + .proof_data, false, ciphertext_validity_proof_signer, ) @@ -485,8 +510,21 @@ async fn mint_tokens( let equality_proof_location = ProofAccount::ContextAccount(equality_proof_context_pubkey); let ciphertext_validity_proof_location = ProofAccount::ContextAccount(ciphertext_validity_proof_context_pubkey); + let ciphertext_validity_proof_location = ProofAccountWithCiphertext { + proof_account: ciphertext_validity_proof_location, + ciphertext_lo: proof_data + .ciphertext_validity_proof_data_with_ciphertext + .ciphertext_lo, + ciphertext_hi: proof_data + .ciphertext_validity_proof_data_with_ciphertext + .ciphertext_hi, + }; let range_proof_location = ProofAccount::ContextAccount(range_proof_context_pubkey); + println!( + "TOKEN: {}, ata: {token_account}, auth: {authority}", + token.get_address() + ); token .confidential_mint( token_account, diff --git a/token/program-2022-test/tests/program_test.rs b/token/program-2022-test/tests/program_test.rs index 1fbd749dae6..2b99efb93b5 100644 --- a/token/program-2022-test/tests/program_test.rs +++ b/token/program-2022-test/tests/program_test.rs @@ -103,6 +103,23 @@ impl TestContext { mint_account: Keypair, extension_init_params: Vec, freeze_authority: Option, + ) -> TokenResult<()> { + let mint_authority = Keypair::new(); + self.init_token_with_mint_keypair_and_freeze_authority_and_mint_authority( + mint_account, + extension_init_params, + freeze_authority, + mint_authority, + ) + .await + } + + pub async fn init_token_with_mint_keypair_and_freeze_authority_and_mint_authority( + &mut self, + mint_account: Keypair, + extension_init_params: Vec, + freeze_authority: Option, + mint_authority: Keypair, ) -> TokenResult<()> { let payer = keypair_clone(&self.context.lock().await.payer); let client: Arc> = @@ -113,7 +130,6 @@ impl TestContext { let decimals: u8 = 9; - let mint_authority = Keypair::new(); let mint_authority_pubkey = mint_authority.pubkey(); let freeze_authority_pubkey = freeze_authority .as_ref() diff --git a/token/program-2022/src/extension/confidential_mint_burn/processor.rs b/token/program-2022/src/extension/confidential_mint_burn/processor.rs index 1f63a7c4720..45eda2ad404 100644 --- a/token/program-2022/src/extension/confidential_mint_burn/processor.rs +++ b/token/program-2022/src/extension/confidential_mint_burn/processor.rs @@ -150,24 +150,30 @@ fn process_confidential_mint( accounts: &[AccountInfo], data: &MintInstructionData, ) -> ProgramResult { + println!("MINT 1"); let account_info_iter = &mut accounts.iter(); let token_account_info = next_account_info(account_info_iter)?; let mint_info = next_account_info(account_info_iter)?; + println!("MINT 2"); check_program_account(mint_info.owner)?; let mint_data = &mut mint_info.data.borrow_mut(); let mut mint = PodStateWithExtensionsMut::::unpack(mint_data)?; let mint_authority = mint.base.mint_authority; + println!("MINT 3"); let auditor_elgamal_pubkey = mint .get_extension::()? .auditor_elgamal_pubkey; + println!("MINT 4"); if let Ok(extension) = mint.get_extension::() { if extension.paused.into() { return Err(TokenError::MintPaused.into()); } } + println!("MINT 5"); let mint_burn_extension = mint.get_extension_mut::()?; + println!("MINT 6"); let proof_context = verify_mint_proof( account_info_iter, @@ -175,14 +181,17 @@ fn process_confidential_mint( data.ciphertext_validity_proof_instruction_offset, data.range_proof_instruction_offset, )?; + println!("MINT 7"); check_program_account(token_account_info.owner)?; let token_account_data = &mut token_account_info.data.borrow_mut(); let mut token_account = PodStateWithExtensionsMut::::unpack(token_account_data)?; + println!("MINT 8"); let authority_info = next_account_info(account_info_iter)?; let authority_info_data_len = authority_info.data_len(); let authority = mint_authority.ok_or(TokenError::NoAuthorityExists)?; + println!("MINT 9"); Processor::validate_owner( program_id, @@ -191,6 +200,7 @@ fn process_confidential_mint( authority_info_data_len, account_info_iter.as_slice(), )?; + println!("MINT 10"); if token_account.base.is_frozen() { return Err(TokenError::AccountFrozen.into()); @@ -206,6 +216,7 @@ fn process_confidential_mint( token_account.get_extension_mut::()?; confidential_transfer_account.valid_as_destination()?; + println!("MINT 12"); if proof_context.mint_pubkeys.destination != confidential_transfer_account.elgamal_pubkey { return Err(ProgramError::InvalidInstructionData); } @@ -215,6 +226,7 @@ fn process_confidential_mint( return Err(ProgramError::InvalidInstructionData); } } + println!("MINT 13"); let proof_context_auditor_ciphertext_lo = proof_context .mint_amount_ciphertext_lo @@ -224,6 +236,7 @@ fn process_confidential_mint( .mint_amount_ciphertext_hi .try_extract_ciphertext(2) .map_err(TokenError::from)?; + println!("MINT 14"); check_auditor_ciphertext( &data.mint_amount_auditor_ciphertext_lo, @@ -231,6 +244,7 @@ fn process_confidential_mint( &proof_context_auditor_ciphertext_lo, &proof_context_auditor_ciphertext_hi, )?; + println!("MINT 15"); confidential_transfer_account.pending_balance_lo = ciphertext_arithmetic::add( &confidential_transfer_account.pending_balance_lo, @@ -240,6 +254,7 @@ fn process_confidential_mint( .map_err(TokenError::from)?, ) .ok_or(TokenError::CiphertextArithmeticFailed)?; + println!("MINT 16"); confidential_transfer_account.pending_balance_hi = ciphertext_arithmetic::add( &confidential_transfer_account.pending_balance_hi, &proof_context @@ -248,6 +263,7 @@ fn process_confidential_mint( .map_err(TokenError::from)?, ) .ok_or(TokenError::CiphertextArithmeticFailed)?; + println!("MINT 17"); confidential_transfer_account.increment_pending_balance_credit_counter()?; @@ -268,6 +284,7 @@ fn process_confidential_mint( .map_err(|_| ProgramError::InvalidAccountData)?, ) .ok_or(TokenError::CiphertextArithmeticFailed)?; + println!("MINT 18"); mint_burn_extension.decryptable_supply = data.new_decryptable_supply; Ok(()) diff --git a/token/program-2022/src/processor.rs b/token/program-2022/src/processor.rs index 908d50a0547..e2edfa673b5 100644 --- a/token/program-2022/src/processor.rs +++ b/token/program-2022/src/processor.rs @@ -1903,6 +1903,10 @@ impl Processor { owner_account_data_len: usize, signers: &[AccountInfo], ) -> ProgramResult { + println!( + "expected owner: {expected_owner}; acc_info_owner: {}", + owner_account_info.key + ); if expected_owner != owner_account_info.key { return Err(TokenError::OwnerMismatch.into()); }