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

[program-2022] Make confidential mint/burn function parameters consistent #7570

Merged
merged 5 commits into from
Dec 11, 2024
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: 15 additions & 11 deletions token/client/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ impl ExtensionInitializationParams {
token_program_id,
mint,
authority,
withdraw_withheld_authority_elgamal_pubkey,
&withdraw_withheld_authority_elgamal_pubkey,
)
}
Self::GroupPointer {
Expand Down Expand Up @@ -2002,14 +2002,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 @@ -2216,7 +2216,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 @@ -2225,7 +2226,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 @@ -2351,14 +2352,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 @@ -2745,14 +2747,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 @@ -2807,14 +2810,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
Loading