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

Commit 18aa58d

Browse files
committed
mint burn with new proof generation
1 parent 48fcb02 commit 18aa58d

File tree

13 files changed

+423
-461
lines changed

13 files changed

+423
-461
lines changed

token/cli/src/command.rs

Lines changed: 90 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ use {
3939
error::TokenError,
4040
extension::{
4141
confidential_mint_burn::{
42-
instruction::BurnSplitContextStateAccounts,
43-
proof_generation::{generate_burn_proofs, generate_mint_proofs},
42+
instruction::{BurnSplitContextStateAccounts, MintSplitContextStateAccounts},
43+
ConfidentialMintBurn,
4444
},
4545
confidential_transfer::{
4646
account_info::{
@@ -62,7 +62,6 @@ use {
6262
transfer_hook::TransferHook,
6363
BaseStateWithExtensions, ExtensionType, StateWithExtensionsOwned,
6464
},
65-
proof::ProofLocation,
6665
solana_zk_sdk::encryption::{
6766
auth_encryption::AeKey,
6867
elgamal::{self, ElGamalKeypair},
@@ -75,7 +74,8 @@ use {
7574
token::{ComputeUnitLimit, ExtensionInitializationParams, ProofAccount, Token},
7675
},
7776
spl_token_confidential_transfer_proof_generation::{
78-
transfer::TransferProofData, withdraw::WithdrawProofData,
77+
burn::burn_split_proof_data, mint::mint_split_proof_data, transfer::TransferProofData,
78+
withdraw::WithdrawProofData,
7979
},
8080
spl_token_group_interface::state::TokenGroup,
8181
spl_token_metadata_interface::state::{Field, TokenMetadata},
@@ -3444,59 +3444,100 @@ async fn command_deposit_withdraw_mint_confidential_tokens(
34443444
}
34453445
ConfidentialInstructionType::Mint => {
34463446
let payer = config.fee_payer()?;
3447-
let range_proof_context_state_account = Keypair::new();
3448-
let range_proof_context_pubkey = range_proof_context_state_account.pubkey();
3447+
3448+
let equality_proof_context_state_account = Keypair::new();
3449+
let equality_proof_context_pubkey = equality_proof_context_state_account.pubkey();
34493450
let ciphertext_validity_proof_context_state_account = Keypair::new();
34503451
let ciphertext_validity_proof_context_pubkey =
34513452
ciphertext_validity_proof_context_state_account.pubkey();
3453+
let range_proof_context_state_account = Keypair::new();
3454+
let range_proof_context_pubkey = range_proof_context_state_account.pubkey();
34523455

34533456
let mint_to_elgamal_pubkey =
34543457
token.account_elgamal_pubkey(&token_account_address).await?;
34553458
let auditor_elgamal_pubkey = token.auditor_elgamal_pubkey().await?;
34563459
let supply_elgamal_pubkey = token.supply_elgamal_pubkey().await?;
34573460

3458-
let (range_proof, ciphertext_validity_proof, pedersen_openings) = generate_mint_proofs(
3461+
let dummy_elgamal = ElGamalKeypair::new_rand();
3462+
let dummy_aes = AeKey::new_rand();
3463+
let supply_elgamal_keypair = match elgamal_keypair {
3464+
Some(e) => e,
3465+
None => {
3466+
// if no ElGamalKeypair supplied just use a dummy for
3467+
// proof creation
3468+
&dummy_elgamal
3469+
}
3470+
};
3471+
let supply_aes_key = match aes_key {
3472+
Some(e) => e,
3473+
None => {
3474+
// see above
3475+
&dummy_aes
3476+
}
3477+
};
3478+
3479+
let mint = token.get_mint_info().await?;
3480+
let conf_mb_ext = mint.get_extension::<ConfidentialMintBurn>()?;
3481+
3482+
let context_state_accounts = MintSplitContextStateAccounts {
3483+
equality_proof: &equality_proof_context_pubkey,
3484+
ciphertext_validity_proof: &ciphertext_validity_proof_context_pubkey,
3485+
range_proof: &range_proof_context_pubkey,
3486+
authority: &payer.pubkey(),
3487+
};
3488+
3489+
let proof_data = mint_split_proof_data(
3490+
&conf_mb_ext
3491+
.confidential_supply
3492+
.try_into()
3493+
.map_err(|_| TokenError::MalformedCiphertext)?,
3494+
&conf_mb_ext
3495+
.decryptable_supply
3496+
.try_into()
3497+
.map_err(|_| TokenError::MalformedCiphertext)?,
34593498
amount,
3499+
supply_elgamal_keypair,
3500+
supply_aes_key,
34603501
&mint_to_elgamal_pubkey,
3461-
&auditor_elgamal_pubkey,
3462-
&supply_elgamal_pubkey,
3502+
&auditor_elgamal_pubkey.unwrap_or_default(),
34633503
)?;
34643504

3505+
let equality_proof_signer = &[&equality_proof_context_state_account];
3506+
let ciphertext_validity_proof_signer =
3507+
&[&ciphertext_validity_proof_context_state_account];
34653508
let range_proof_signer = &[&range_proof_context_state_account];
3466-
let ciphertext_validity_proof_signer = &[&ciphertext_validity_proof_context_state_account];
34673509
let context_state_auth = payer.pubkey();
34683510
let _ = try_join!(
34693511
token.confidential_transfer_create_context_state_account(
3470-
&range_proof_context_pubkey,
3512+
&equality_proof_context_pubkey,
34713513
&context_state_auth,
3472-
&range_proof,
3514+
&proof_data.equality_proof_data,
34733515
true,
3474-
range_proof_signer,
3516+
equality_proof_signer,
34753517
),
34763518
token.confidential_transfer_create_context_state_account(
34773519
&ciphertext_validity_proof_context_pubkey,
34783520
&context_state_auth,
3479-
&ciphertext_validity_proof,
3521+
&proof_data.ciphertext_validity_proof_data,
34803522
false,
34813523
ciphertext_validity_proof_signer,
34823524
),
3525+
token.confidential_transfer_create_context_state_account(
3526+
&range_proof_context_pubkey,
3527+
&context_state_auth,
3528+
&proof_data.range_proof_data,
3529+
true,
3530+
range_proof_signer,
3531+
),
34833532
)?;
34843533

3485-
let range_proof_location =
3486-
ProofLocation::ContextStateAccount(&range_proof_context_pubkey);
3487-
let ciphertext_validity_proof_location =
3488-
ProofLocation::ContextStateAccount(&ciphertext_validity_proof_context_pubkey);
3489-
34903534
let res = token
34913535
.confidential_mint(
34923536
&token_account_address,
34933537
&owner,
3494-
amount,
3495-
auditor_elgamal_pubkey,
34963538
supply_elgamal_pubkey,
3497-
range_proof_location,
3498-
ciphertext_validity_proof_location,
3499-
&pedersen_openings,
3539+
&context_state_accounts,
3540+
proof_data.new_decryptable_supply,
35003541
&bulk_signers,
35013542
)
35023543
.await?;
@@ -4911,50 +4952,49 @@ async fn command_confidential_burn(
49114952
.unwrap();
49124953
let transfer_account_info = TransferAccountInfo::new(extension);
49134954

4914-
let (equality_proof_data, ciphertext_validity_proof_data, range_proof_data, pedersen_openings) =
4915-
generate_burn_proofs(
4916-
&transfer_account_info
4917-
.available_balance
4918-
.try_into()
4919-
.map_err(|_| TokenError::MalformedCiphertext)?,
4920-
&transfer_account_info
4921-
.decryptable_available_balance
4922-
.try_into()
4923-
.map_err(|_| TokenError::MalformedCiphertext)?,
4924-
burn_amount,
4925-
elgamal_keypair,
4926-
aes_key,
4927-
&auditor_elgamal_pubkey,
4928-
&supply_elgamal_pubkey,
4929-
)
4930-
.unwrap();
4955+
let proof_data = burn_split_proof_data(
4956+
&transfer_account_info
4957+
.available_balance
4958+
.try_into()
4959+
.map_err(|_| TokenError::MalformedCiphertext)?,
4960+
&transfer_account_info
4961+
.decryptable_available_balance
4962+
.try_into()
4963+
.map_err(|_| TokenError::MalformedCiphertext)?,
4964+
burn_amount,
4965+
elgamal_keypair,
4966+
aes_key,
4967+
&auditor_elgamal_pubkey.unwrap_or_default(),
4968+
&supply_elgamal_pubkey.unwrap_or_default(),
4969+
)
4970+
.unwrap();
49314971

49324972
let range_proof_signer = &[&range_proof_context_state_account];
49334973
let equality_proof_signer = &[&equality_proof_context_state_account];
49344974
let ciphertext_validity_proof_signer = &[&ciphertext_validity_proof_context_state_account];
49354975
// setup proofs
49364976
let _ = try_join!(
4937-
token.confidential_transfer_create_context_state_account(
4938-
context_state_accounts.range_proof,
4939-
context_state_accounts.authority,
4940-
&range_proof_data,
4941-
true,
4942-
range_proof_signer,
4943-
),
49444977
token.confidential_transfer_create_context_state_account(
49454978
context_state_accounts.equality_proof,
49464979
context_state_accounts.authority,
4947-
&equality_proof_data,
4980+
&proof_data.equality_proof_data,
49484981
false,
49494982
equality_proof_signer,
49504983
),
49514984
token.confidential_transfer_create_context_state_account(
49524985
context_state_accounts.ciphertext_validity_proof,
49534986
context_state_accounts.authority,
4954-
&ciphertext_validity_proof_data,
4987+
&proof_data.ciphertext_validity_proof_data,
49554988
false,
49564989
ciphertext_validity_proof_signer,
49574990
),
4991+
token.confidential_transfer_create_context_state_account(
4992+
context_state_accounts.range_proof,
4993+
context_state_accounts.authority,
4994+
&proof_data.range_proof_data,
4995+
true,
4996+
range_proof_signer,
4997+
),
49584998
)?;
49594999

49605000
// do the burn
@@ -4964,11 +5004,9 @@ async fn command_confidential_burn(
49645004
&authority,
49655005
&context_state_accounts,
49665006
burn_amount,
4967-
auditor_elgamal_pubkey,
49685007
supply_elgamal_pubkey,
49695008
aes_key,
49705009
&bulk_signers,
4971-
&pedersen_openings,
49725010
)
49735011
.await?;
49745012

token/client/src/token.rs

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,17 @@ use {
3232
error::TokenError as Token2022Error,
3333
extension::{
3434
confidential_mint_burn::{
35-
self, instruction::BurnSplitContextStateAccounts, ConfidentialMintBurn,
35+
self,
36+
instruction::{BurnSplitContextStateAccounts, MintSplitContextStateAccounts},
37+
ConfidentialMintBurn,
3638
},
3739
confidential_transfer::{
3840
self,
3941
account_info::{
4042
combine_balances, ApplyPendingBalanceAccountInfo, EmptyAccountAccountInfo,
4143
TransferAccountInfo, WithdrawAccountInfo,
4244
},
43-
instruction::{
44-
BatchedGroupedCiphertext3HandlesValidityProofData, BatchedRangeProofU64Data,
45-
ProofContextState, ZkProofData,
46-
},
45+
instruction::{ProofContextState, ZkProofData},
4746
ConfidentialTransferAccount, ConfidentialTransferMint, DecryptableBalance,
4847
},
4948
confidential_transfer_fee::{
@@ -58,9 +57,8 @@ use {
5857
proof::{zk_proof_type_to_instruction, ProofData, ProofLocation},
5958
solana_zk_sdk::{
6059
encryption::{
61-
auth_encryption::AeKey,
60+
auth_encryption::{AeCiphertext, AeKey},
6261
elgamal::{ElGamalCiphertext, ElGamalKeypair, ElGamalPubkey, ElGamalSecretKey},
63-
pedersen::PedersenOpening,
6462
pod::elgamal::PodElGamalPubkey,
6563
},
6664
zk_elgamal_proof_program::{
@@ -3483,33 +3481,27 @@ where
34833481
&self,
34843482
account: &Pubkey,
34853483
authority: &Pubkey,
3486-
amount: u64,
3487-
auditor_elgamal_pubkey: Option<ElGamalPubkey>,
34883484
supply_elgamal_pubkey: Option<ElGamalPubkey>,
3489-
range_proof_location: ProofLocation<'_, BatchedRangeProofU64Data>,
3490-
ciphertext_validity_proof_location: ProofLocation<
3491-
'_,
3492-
BatchedGroupedCiphertext3HandlesValidityProofData,
3493-
>,
3494-
pedersen_openings: &(PedersenOpening, PedersenOpening),
3485+
context_state_accounts: &MintSplitContextStateAccounts<'_>,
3486+
new_decryptable_supply: AeCiphertext,
34953487
signing_keypairs: &S,
34963488
) -> TokenResult<T::Output> {
34973489
let signing_pubkeys = signing_keypairs.pubkeys();
34983490
let multisig_signers = self.get_multisig_signers(authority, &signing_pubkeys);
3491+
34993492
self.process_ixs(
3500-
&confidential_mint_burn::instruction::confidential_mint(
3501-
&self.program_id,
3502-
account,
3503-
&self.pubkey,
3504-
amount,
3505-
auditor_elgamal_pubkey,
3506-
supply_elgamal_pubkey,
3507-
authority,
3508-
&multisig_signers,
3509-
range_proof_location,
3510-
ciphertext_validity_proof_location,
3511-
pedersen_openings,
3512-
)?,
3493+
&[
3494+
confidential_mint_burn::instruction::confidential_mint_with_split_proofs(
3495+
&self.program_id,
3496+
account,
3497+
&self.pubkey,
3498+
supply_elgamal_pubkey,
3499+
authority,
3500+
&multisig_signers,
3501+
context_state_accounts,
3502+
new_decryptable_supply,
3503+
)?,
3504+
],
35133505
signing_keypairs,
35143506
)
35153507
.await
@@ -3524,11 +3516,9 @@ where
35243516
authority: &Pubkey,
35253517
context_state_accounts: &BurnSplitContextStateAccounts<'_>,
35263518
amount: u64,
3527-
auditor_elgamal_pubkey: Option<ElGamalPubkey>,
35283519
supply_elgamal_pubkey: Option<ElGamalPubkey>,
35293520
aes_key: &AeKey,
35303521
signing_keypairs: &S,
3531-
pedersen_openings: &(PedersenOpening, PedersenOpening),
35323522
) -> TokenResult<T::Output> {
35333523
let signing_pubkeys = signing_keypairs.pubkeys();
35343524
let multisig_signers = self.get_multisig_signers(authority, &signing_pubkeys);
@@ -3546,15 +3536,12 @@ where
35463536
&confidential_mint_burn::instruction::confidential_burn_with_split_proofs(
35473537
&self.program_id,
35483538
ata_pubkey,
3549-
self.get_address(),
3550-
auditor_elgamal_pubkey,
3539+
&self.pubkey,
35513540
supply_elgamal_pubkey,
3552-
amount,
35533541
new_decryptable_available_balance.into(),
35543542
context_state_accounts,
35553543
authority,
35563544
&multisig_signers,
3557-
pedersen_openings,
35583545
)?,
35593546
signing_keypairs,
35603547
)

token/confidential-transfer/proof-extraction/src/encryption.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,36 @@ impl PodFeeCiphertext {
5151
#[repr(C)]
5252
pub struct PodBurnAmountCiphertext(pub(crate) PodGroupedElGamalCiphertext3Handles);
5353

54+
impl PodBurnAmountCiphertext {
55+
pub fn extract_commitment(&self) -> PodPedersenCommitment {
56+
self.0.extract_commitment()
57+
}
58+
59+
pub fn try_extract_ciphertext(
60+
&self,
61+
index: usize,
62+
) -> Result<PodElGamalCiphertext, TokenProofExtractionError> {
63+
self.0
64+
.try_extract_ciphertext(index)
65+
.map_err(|_| TokenProofExtractionError::CiphertextExtraction)
66+
}
67+
}
68+
5469
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5570
#[repr(C)]
5671
pub struct PodMintAmountCiphertext(pub(crate) PodGroupedElGamalCiphertext3Handles);
72+
73+
impl PodMintAmountCiphertext {
74+
pub fn extract_commitment(&self) -> PodPedersenCommitment {
75+
self.0.extract_commitment()
76+
}
77+
78+
pub fn try_extract_ciphertext(
79+
&self,
80+
index: usize,
81+
) -> Result<PodElGamalCiphertext, TokenProofExtractionError> {
82+
self.0
83+
.try_extract_ciphertext(index)
84+
.map_err(|_| TokenProofExtractionError::CiphertextExtraction)
85+
}
86+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ pub enum TokenProofGenerationError {
1010
IllegalAmountBitLength,
1111
#[error("fee calculation failed")]
1212
FeeCalculation,
13+
#[error("supply decryption failed")]
14+
SupplyDecryption,
1315
}

0 commit comments

Comments
 (0)