Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit e97bd22

Browse files
[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
1 parent cf1e4de commit e97bd22

File tree

10 files changed

+59
-49
lines changed

10 files changed

+59
-49
lines changed

token/client/src/token.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ impl ExtensionInitializationParams {
305305
token_program_id,
306306
mint,
307307
authority,
308-
withdraw_withheld_authority_elgamal_pubkey,
308+
&withdraw_withheld_authority_elgamal_pubkey,
309309
)
310310
}
311311
Self::GroupPointer {
@@ -2051,14 +2051,14 @@ where
20512051
)
20522052
.unwrap();
20532053

2054-
let decryptable_balance = aes_key.encrypt(0);
2054+
let decryptable_balance = aes_key.encrypt(0).into();
20552055

20562056
self.process_ixs(
20572057
&confidential_transfer::instruction::configure_account(
20582058
&self.program_id,
20592059
account,
20602060
&self.pubkey,
2061-
decryptable_balance.into(),
2061+
&decryptable_balance,
20622062
maximum_pending_balance_credit_counter,
20632063
authority,
20642064
&multisig_signers,
@@ -2265,7 +2265,8 @@ where
22652265

22662266
let new_decryptable_available_balance = account_info
22672267
.new_decryptable_available_balance(withdraw_amount, aes_key)
2268-
.map_err(|_| TokenError::AccountDecryption)?;
2268+
.map_err(|_| TokenError::AccountDecryption)?
2269+
.into();
22692270

22702271
self.process_ixs(
22712272
&confidential_transfer::instruction::withdraw(
@@ -2274,7 +2275,7 @@ where
22742275
&self.pubkey,
22752276
withdraw_amount,
22762277
decimals,
2277-
new_decryptable_available_balance.into(),
2278+
&new_decryptable_available_balance,
22782279
authority,
22792280
&multisig_signers,
22802281
equality_proof_location,
@@ -2400,14 +2401,15 @@ where
24002401

24012402
let new_decryptable_available_balance = account_info
24022403
.new_decryptable_available_balance(transfer_amount, source_aes_key)
2403-
.map_err(|_| TokenError::AccountDecryption)?;
2404+
.map_err(|_| TokenError::AccountDecryption)?
2405+
.into();
24042406

24052407
let mut instructions = confidential_transfer::instruction::transfer(
24062408
&self.program_id,
24072409
source_account,
24082410
self.get_address(),
24092411
destination_account,
2410-
new_decryptable_available_balance.into(),
2412+
&new_decryptable_available_balance,
24112413
&transfer_amount_auditor_ciphertext_lo,
24122414
&transfer_amount_auditor_ciphertext_hi,
24132415
source_authority,
@@ -2794,14 +2796,15 @@ where
27942796

27952797
let new_decryptable_available_balance = account_info
27962798
.new_decryptable_available_balance(transfer_amount, source_aes_key)
2797-
.map_err(|_| TokenError::AccountDecryption)?;
2799+
.map_err(|_| TokenError::AccountDecryption)?
2800+
.into();
27982801

27992802
let mut instructions = confidential_transfer::instruction::transfer_with_fee(
28002803
&self.program_id,
28012804
source_account,
28022805
self.get_address(),
28032806
destination_account,
2804-
new_decryptable_available_balance.into(),
2807+
&new_decryptable_available_balance,
28052808
&transfer_amount_auditor_ciphertext_lo,
28062809
&transfer_amount_auditor_ciphertext_hi,
28072810
source_authority,
@@ -2856,14 +2859,15 @@ where
28562859
let expected_pending_balance_credit_counter = account_info.pending_balance_credit_counter();
28572860
let new_decryptable_available_balance = account_info
28582861
.new_decryptable_available_balance(elgamal_secret_key, aes_key)
2859-
.map_err(|_| TokenError::AccountDecryption)?;
2862+
.map_err(|_| TokenError::AccountDecryption)?
2863+
.into();
28602864

28612865
self.process_ixs(
28622866
&[confidential_transfer::instruction::apply_pending_balance(
28632867
&self.program_id,
28642868
account,
28652869
expected_pending_balance_credit_counter,
2866-
new_decryptable_available_balance.into(),
2870+
&new_decryptable_available_balance,
28672871
authority,
28682872
&multisig_signers,
28692873
)?],

token/confidential-transfer/proof-generation/src/burn.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ pub fn burn_split_proof_data(
3636
burn_amount: u64,
3737
source_elgamal_keypair: &ElGamalKeypair,
3838
source_aes_key: &AeKey,
39-
auditor_elgamal_pubkey: &ElGamalPubkey,
39+
auditor_elgamal_pubkey: Option<&ElGamalPubkey>,
4040
supply_elgamal_pubkey: &ElGamalPubkey,
4141
) -> Result<BurnProofData, TokenProofGenerationError> {
42+
let default_auditor_pubkey = ElGamalPubkey::default();
43+
let auditor_elgamal_pubkey = auditor_elgamal_pubkey.unwrap_or(&default_auditor_pubkey);
44+
4245
// split the burn amount into low and high bits
4346
let (burn_amount_lo, burn_amount_hi) = try_split_u64(burn_amount, BURN_AMOUNT_LO_BIT_LENGTH)
4447
.ok_or(TokenProofGenerationError::IllegalAmountBitLength)?;

token/confidential-transfer/proof-generation/src/mint.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ pub fn mint_split_proof_data(
3838
supply_elgamal_keypair: &ElGamalKeypair,
3939
supply_aes_key: &AeKey,
4040
destination_elgamal_pubkey: &ElGamalPubkey,
41-
auditor_elgamal_pubkey: &ElGamalPubkey,
41+
auditor_elgamal_pubkey: Option<&ElGamalPubkey>,
4242
) -> Result<MintProofData, TokenProofGenerationError> {
43+
let default_auditor_pubkey = ElGamalPubkey::default();
44+
let auditor_elgamal_pubkey = auditor_elgamal_pubkey.unwrap_or(&default_auditor_pubkey);
45+
4346
// split the mint amount into low and high bits
4447
let (mint_amount_lo, mint_amount_hi) = try_split_u64(mint_amount, MINT_AMOUNT_LO_BIT_LENGTH)
4548
.ok_or(TokenProofGenerationError::IllegalAmountBitLength)?;

token/confidential-transfer/proof-tests/tests/proof_test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ fn test_mint_validity(mint_amount: u64, supply: u64) {
238238
&supply_keypair,
239239
&supply_aes_key,
240240
destination_pubkey,
241-
auditor_pubkey,
241+
Some(auditor_pubkey),
242242
)
243243
.unwrap();
244244

@@ -291,7 +291,7 @@ fn test_burn_validity(spendable_balance: u64, burn_amount: u64) {
291291
burn_amount,
292292
&source_keypair,
293293
&aes_key,
294-
auditor_pubkey,
294+
Some(auditor_pubkey),
295295
supply_pubkey,
296296
)
297297
.unwrap();

token/program-2022-test/tests/initialize_mint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ async fn fail_invalid_extensions_combination() {
523523
&spl_token_2022::id(),
524524
&mint_account.pubkey(),
525525
Some(Pubkey::new_unique()),
526-
PodElGamalPubkey::default(),
526+
&PodElGamalPubkey::default(),
527527
)
528528
.unwrap();
529529

token/program-2022/src/extension/confidential_mint_burn/instruction.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use {
2626
#[cfg(not(target_os = "solana"))]
2727
use {
2828
solana_zk_sdk::{
29-
encryption::{auth_encryption::AeCiphertext, elgamal::ElGamalPubkey},
29+
encryption::elgamal::ElGamalPubkey,
3030
zk_elgamal_proof_program::{
3131
instruction::ProofInstruction,
3232
proof_data::{
@@ -291,8 +291,8 @@ pub struct BurnInstructionData {
291291
pub fn initialize_mint(
292292
token_program_id: &Pubkey,
293293
mint: &Pubkey,
294-
supply_elgamal_pubkey: PodElGamalPubkey,
295-
decryptable_supply: PodAeCiphertext,
294+
supply_elgamal_pubkey: &PodElGamalPubkey,
295+
decryptable_supply: &DecryptableBalance,
296296
) -> Result<Instruction, ProgramError> {
297297
check_program_account(token_program_id)?;
298298
let accounts = vec![AccountMeta::new(*mint, false)];
@@ -303,8 +303,8 @@ pub fn initialize_mint(
303303
TokenInstruction::ConfidentialMintBurnExtension,
304304
ConfidentialMintBurnInstruction::InitializeMint,
305305
&InitializeMintData {
306-
supply_elgamal_pubkey,
307-
decryptable_supply,
306+
supply_elgamal_pubkey: *supply_elgamal_pubkey,
307+
decryptable_supply: *decryptable_supply,
308308
},
309309
))
310310
}
@@ -317,7 +317,7 @@ pub fn rotate_supply_elgamal_pubkey(
317317
mint: &Pubkey,
318318
authority: &Pubkey,
319319
multisig_signers: &[&Pubkey],
320-
new_supply_elgamal_pubkey: ElGamalPubkey,
320+
new_supply_elgamal_pubkey: &PodElGamalPubkey,
321321
ciphertext_equality_proof: ProofLocation<CiphertextCiphertextEqualityProofData>,
322322
) -> Result<Vec<Instruction>, ProgramError> {
323323
check_program_account(token_program_id)?;
@@ -349,7 +349,7 @@ pub fn rotate_supply_elgamal_pubkey(
349349
TokenInstruction::ConfidentialMintBurnExtension,
350350
ConfidentialMintBurnInstruction::RotateSupplyElGamalPubkey,
351351
&RotateSupplyElGamalPubkeyData {
352-
new_supply_elgamal_pubkey: PodElGamalPubkey::from(new_supply_elgamal_pubkey),
352+
new_supply_elgamal_pubkey: *new_supply_elgamal_pubkey,
353353
proof_instruction_offset,
354354
},
355355
)];
@@ -366,7 +366,7 @@ pub fn update_decryptable_supply(
366366
mint: &Pubkey,
367367
authority: &Pubkey,
368368
multisig_signers: &[&Pubkey],
369-
new_decryptable_supply: AeCiphertext,
369+
new_decryptable_supply: &DecryptableBalance,
370370
) -> Result<Instruction, ProgramError> {
371371
check_program_account(token_program_id)?;
372372
let mut accounts = vec![
@@ -382,7 +382,7 @@ pub fn update_decryptable_supply(
382382
TokenInstruction::ConfidentialMintBurnExtension,
383383
ConfidentialMintBurnInstruction::UpdateDecryptableSupply,
384384
&UpdateDecryptableSupplyData {
385-
new_decryptable_supply: new_decryptable_supply.into(),
385+
new_decryptable_supply: *new_decryptable_supply,
386386
},
387387
))
388388
}
@@ -417,7 +417,7 @@ pub fn confidential_mint_with_split_proofs(
417417
BatchedGroupedCiphertext3HandlesValidityProofData,
418418
>,
419419
range_proof_location: ProofLocation<BatchedRangeProofU128Data>,
420-
new_decryptable_supply: AeCiphertext,
420+
new_decryptable_supply: &DecryptableBalance,
421421
) -> Result<Vec<Instruction>, ProgramError> {
422422
check_program_account(token_program_id)?;
423423
let mut accounts = vec![AccountMeta::new(*token_account, false)];
@@ -473,7 +473,7 @@ pub fn confidential_mint_with_split_proofs(
473473
TokenInstruction::ConfidentialMintBurnExtension,
474474
ConfidentialMintBurnInstruction::Mint,
475475
&MintInstructionData {
476-
new_decryptable_supply: new_decryptable_supply.into(),
476+
new_decryptable_supply: *new_decryptable_supply,
477477
mint_amount_auditor_ciphertext_lo: *mint_amount_auditor_ciphertext_lo,
478478
mint_amount_auditor_ciphertext_hi: *mint_amount_auditor_ciphertext_hi,
479479
equality_proof_instruction_offset,
@@ -495,7 +495,7 @@ pub fn confidential_burn_with_split_proofs(
495495
token_account: &Pubkey,
496496
mint: &Pubkey,
497497
supply_elgamal_pubkey: Option<ElGamalPubkey>,
498-
new_decryptable_available_balance: DecryptableBalance,
498+
new_decryptable_available_balance: &DecryptableBalance,
499499
burn_amount_auditor_ciphertext_lo: &PodElGamalCiphertext,
500500
burn_amount_auditor_ciphertext_hi: &PodElGamalCiphertext,
501501
authority: &Pubkey,
@@ -559,7 +559,7 @@ pub fn confidential_burn_with_split_proofs(
559559
TokenInstruction::ConfidentialMintBurnExtension,
560560
ConfidentialMintBurnInstruction::Burn,
561561
&BurnInstructionData {
562-
new_decryptable_available_balance,
562+
new_decryptable_available_balance: *new_decryptable_available_balance,
563563
burn_amount_auditor_ciphertext_lo: *burn_amount_auditor_ciphertext_lo,
564564
burn_amount_auditor_ciphertext_hi: *burn_amount_auditor_ciphertext_hi,
565565
equality_proof_instruction_offset,

token/program-2022/src/extension/confidential_transfer/account_info.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl ApplyPendingBalanceAccountInfo {
147147
#[repr(C)]
148148
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
149149
pub struct WithdrawAccountInfo {
150-
/// The available balance (encrypted by `encrypiton_pubkey`)
150+
/// The available balance (encrypted by `encryption_pubkey`)
151151
pub available_balance: EncryptedBalance,
152152
/// The decryptable available balance
153153
pub decryptable_available_balance: DecryptableBalance,
@@ -214,7 +214,7 @@ impl WithdrawAccountInfo {
214214
#[repr(C)]
215215
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
216216
pub struct TransferAccountInfo {
217-
/// The available balance (encrypted by `encrypiton_pubkey`)
217+
/// The available balance (encrypted by `encryption_pubkey`)
218218
pub available_balance: EncryptedBalance,
219219
/// The decryptable available balance
220220
pub decryptable_available_balance: DecryptableBalance,

0 commit comments

Comments
 (0)