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

Commit 7fbfcfd

Browse files
committed
clean up and extend mint/burn account infos
1 parent 253c2d7 commit 7fbfcfd

File tree

6 files changed

+105
-9
lines changed

6 files changed

+105
-9
lines changed

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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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/src/extension/confidential_mint_burn/account_info.rs

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
use {
22
super::ConfidentialMintBurn,
3-
crate::error::TokenError,
3+
crate::{
4+
error::TokenError,
5+
extension::confidential_transfer::{
6+
ConfidentialTransferAccount, DecryptableBalance, EncryptedBalance,
7+
},
8+
},
49
bytemuck::{Pod, Zeroable},
510
solana_zk_sdk::{
611
encryption::{
712
auth_encryption::{AeCiphertext, AeKey},
8-
elgamal::{ElGamalCiphertext, ElGamalKeypair},
13+
elgamal::{ElGamalCiphertext, ElGamalKeypair, ElGamalPubkey},
914
pedersen::PedersenOpening,
1015
pod::{
1116
auth_encryption::PodAeCiphertext,
@@ -14,6 +19,10 @@ use {
1419
},
1520
zk_elgamal_proof_program::proof_data::CiphertextCiphertextEqualityProofData,
1621
},
22+
spl_token_confidential_transfer_proof_generation::{
23+
burn::{burn_split_proof_data, BurnProofData},
24+
mint::{mint_split_proof_data, MintProofData},
25+
},
1726
};
1827

1928
/// Confidential Mint Burn extension information needed to construct a
@@ -102,4 +111,85 @@ impl SupplyAccountInfo {
102111
)
103112
.map_err(|_| TokenError::ProofGeneration)
104113
}
114+
115+
/// Create a mint proof data that is split into equality, ciphertext
116+
/// validity, and range proof.
117+
pub fn generate_split_mint_proof_data(
118+
&self,
119+
mint_amount: u64,
120+
current_supply: u64,
121+
supply_elgamal_keypair: &ElGamalKeypair,
122+
aes_key: &AeKey,
123+
destination_elgamal_pubkey: &ElGamalPubkey,
124+
auditor_elgamal_pubkey: Option<&ElGamalPubkey>,
125+
) -> Result<MintProofData, TokenError> {
126+
let current_supply_ciphertext = self
127+
.current_supply
128+
.try_into()
129+
.map_err(|_| TokenError::MalformedCiphertext)?;
130+
131+
mint_split_proof_data(
132+
&current_supply_ciphertext,
133+
mint_amount,
134+
current_supply,
135+
supply_elgamal_keypair,
136+
aes_key,
137+
destination_elgamal_pubkey,
138+
auditor_elgamal_pubkey,
139+
)
140+
.map_err(|e| -> TokenError { e.into() })
141+
}
142+
}
143+
144+
/// Confidential Mint Burn extension information needed to construct a
145+
/// `Burn` instruction.
146+
#[repr(C)]
147+
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
148+
pub struct BurnAccountInfo {
149+
/// The available balance (encrypted by `encryption_pubkey`)
150+
pub available_balance: EncryptedBalance,
151+
/// The decryptable available balance
152+
pub decryptable_available_balance: DecryptableBalance,
153+
}
154+
155+
impl BurnAccountInfo {
156+
/// Create the `ApplyPendingBalance` instruction account information from
157+
/// `ConfidentialTransferAccount`.
158+
pub fn new(account: &ConfidentialTransferAccount) -> Self {
159+
Self {
160+
available_balance: account.available_balance,
161+
decryptable_available_balance: account.decryptable_available_balance,
162+
}
163+
}
164+
165+
/// Create a burn proof data that is split into equality, ciphertext
166+
/// validity, and range proof.
167+
pub fn generate_split_burn_proof_data(
168+
&self,
169+
burn_amount: u64,
170+
source_elgamal_keypair: &ElGamalKeypair,
171+
aes_key: &AeKey,
172+
auditor_elgamal_pubkey: Option<&ElGamalPubkey>,
173+
supply_elgamal_pubkey: &ElGamalPubkey,
174+
) -> Result<BurnProofData, TokenError> {
175+
let current_available_balance_ciphertext = self
176+
.available_balance
177+
.try_into()
178+
.map_err(|_| TokenError::MalformedCiphertext)?;
179+
let current_decryptable_available_balance = self
180+
.decryptable_available_balance
181+
.try_into()
182+
.map_err(|_| TokenError::MalformedCiphertext)?;
183+
184+
burn_split_proof_data(
185+
&current_available_balance_ciphertext,
186+
&current_decryptable_available_balance,
187+
burn_amount,
188+
source_elgamal_keypair,
189+
aes_key,
190+
auditor_elgamal_pubkey,
191+
supply_elgamal_pubkey,
192+
)
193+
.map_err(|e| -> TokenError { e.into() })
194+
}
105195
}

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

Lines changed: 2 additions & 2 deletions
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,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub struct ConfidentialTransferAccount {
9090
/// The high 48 bits of the pending balance (encrypted by `elgamal_pubkey`)
9191
pub pending_balance_hi: EncryptedBalance,
9292

93-
/// The available balance (encrypted by `encrypiton_pubkey`)
93+
/// The available balance (encrypted by `encryption_pubkey`)
9494
pub available_balance: EncryptedBalance,
9595

9696
/// The decryptable available balance

0 commit comments

Comments
 (0)