Skip to content

Commit

Permalink
[program-2022] Make confidential mint/burn function parameters consis…
Browse files Browse the repository at this point in the history
…tent (#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
  • Loading branch information
samkim-crypto authored Dec 11, 2024
1 parent cf1e4de commit e97bd22
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 49 deletions.
26 changes: 15 additions & 11 deletions token/client/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl ExtensionInitializationParams {
token_program_id,
mint,
authority,
withdraw_withheld_authority_elgamal_pubkey,
&withdraw_withheld_authority_elgamal_pubkey,
)
}
Self::GroupPointer {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
)?],
Expand Down
5 changes: 4 additions & 1 deletion token/confidential-transfer/proof-generation/src/burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BurnProofData, TokenProofGenerationError> {
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)?;
Expand Down
5 changes: 4 additions & 1 deletion token/confidential-transfer/proof-generation/src/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MintProofData, TokenProofGenerationError> {
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)?;
Expand Down
4 changes: 2 additions & 2 deletions token/confidential-transfer/proof-tests/tests/proof_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion token/program-2022-test/tests/initialize_mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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<Instruction, ProgramError> {
check_program_account(token_program_id)?;
let accounts = vec![AccountMeta::new(*mint, false)];
Expand All @@ -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,
},
))
}
Expand All @@ -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<CiphertextCiphertextEqualityProofData>,
) -> Result<Vec<Instruction>, ProgramError> {
check_program_account(token_program_id)?;
Expand Down Expand Up @@ -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,
},
)];
Expand All @@ -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<Instruction, ProgramError> {
check_program_account(token_program_id)?;
let mut accounts = vec![
Expand All @@ -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,
},
))
}
Expand Down Expand Up @@ -417,7 +417,7 @@ pub fn confidential_mint_with_split_proofs(
BatchedGroupedCiphertext3HandlesValidityProofData,
>,
range_proof_location: ProofLocation<BatchedRangeProofU128Data>,
new_decryptable_supply: AeCiphertext,
new_decryptable_supply: &DecryptableBalance,
) -> Result<Vec<Instruction>, ProgramError> {
check_program_account(token_program_id)?;
let mut accounts = vec![AccountMeta::new(*token_account, false)];
Expand Down Expand Up @@ -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,
Expand All @@ -495,7 +495,7 @@ pub fn confidential_burn_with_split_proofs(
token_account: &Pubkey,
mint: &Pubkey,
supply_elgamal_pubkey: Option<ElGamalPubkey>,
new_decryptable_available_balance: DecryptableBalance,
new_decryptable_available_balance: &DecryptableBalance,
burn_amount_auditor_ciphertext_lo: &PodElGamalCiphertext,
burn_amount_auditor_ciphertext_hi: &PodElGamalCiphertext,
authority: &Pubkey,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit e97bd22

Please sign in to comment.