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

Commit b01ac24

Browse files
committed
review fixes
1 parent 534861e commit b01ac24

File tree

11 files changed

+85
-180
lines changed

11 files changed

+85
-180
lines changed

libraries/pod/src/optional_keys.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<'de> Visitor<'de> for OptionalNonZeroPubkeyVisitor {
101101
where
102102
E: Error,
103103
{
104-
let pkey = Pubkey::from_str(&v)
104+
let pkey = Pubkey::from_str(v)
105105
.map_err(|_| Error::invalid_value(Unexpected::Str(v), &"value string"))?;
106106

107107
OptionalNonZeroPubkey::try_from(Some(pkey))
@@ -162,14 +162,6 @@ impl From<OptionalNonZeroElGamalPubkey> for Option<PodElGamalPubkey> {
162162
}
163163
}
164164
}
165-
impl OptionalNonZeroElGamalPubkey {
166-
pub fn is_none(&self) -> bool {
167-
self.0 == PodElGamalPubkey::default()
168-
}
169-
pub fn is_some(&self) -> bool {
170-
self.0 != PodElGamalPubkey::default()
171-
}
172-
}
173165

174166
#[cfg(feature = "serde-traits")]
175167
impl Serialize for OptionalNonZeroElGamalPubkey {

token/cli/src/command.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,7 @@ use {
7373
},
7474
spl_token_group_interface::state::TokenGroup,
7575
spl_token_metadata_interface::state::{Field, TokenMetadata},
76-
std::{
77-
collections::HashMap,
78-
fmt::Display,
79-
process::exit,
80-
rc::Rc,
81-
str::{self, FromStr},
82-
sync::Arc,
83-
},
76+
std::{collections::HashMap, fmt::Display, process::exit, rc::Rc, str::FromStr, sync::Arc},
8477
};
8578

8679
fn print_error_and_exit<T, E: Display>(e: E) -> T {

token/client/src/token.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use {
3636
ApplyPendingBalanceAccountInfo, EmptyAccountAccountInfo, TransferAccountInfo,
3737
WithdrawAccountInfo,
3838
},
39-
instruction::{ProofContextState, ZkProofData},
4039
ConfidentialTransferAccount, DecryptableBalance,
4140
},
4241
confidential_transfer_fee::{
@@ -58,6 +57,8 @@ use {
5857
zk_elgamal_proof_program::{
5958
self,
6059
instruction::{close_context_state, ContextStateInfo},
60+
proof_data::*,
61+
state::ProofContextState,
6162
},
6263
},
6364
state::{Account, AccountState, Mint, Multisig},
@@ -110,7 +111,6 @@ pub enum TokenError {
110111
#[error("decimals specified, but incorrect")]
111112
InvalidDecimals,
112113
}
113-
114114
impl PartialEq for TokenError {
115115
fn eq(&self, other: &Self) -> bool {
116116
match (self, other) {

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

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

token/program-2022/src/error.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,6 @@ pub enum TokenError {
263263
/// Withdraw / Deposit not allowed for confidential-mint-burn
264264
#[error("Withdraw / Deposit not allowed for confidential-mint-burn")]
265265
IllegalMintBurnConversion,
266-
/// Undecryptable supply when trying to generate confidential-mint proofs
267-
#[error("Could not decrypt difference between current supply and decryptable supply when generating mint proofs")]
268-
SupplyDecryption,
269266
}
270267
impl From<TokenError> for ProgramError {
271268
fn from(e: TokenError) -> Self {
@@ -456,9 +453,6 @@ impl PrintProgramError for TokenError {
456453
TokenError::IllegalMintBurnConversion => {
457454
msg!("Conversions from normal to confidential token balance and vice versa are illegal if the confidential-mint-burn extension is enabled")
458455
}
459-
TokenError::SupplyDecryption => {
460-
msg!("Could not decrypt difference between current supply and decryptable supply when generating mint proofs")
461-
}
462456
}
463457
}
464458
}
@@ -471,7 +465,6 @@ impl From<TokenProofGenerationError> for TokenError {
471465
TokenProofGenerationError::NotEnoughFunds => TokenError::InsufficientFunds,
472466
TokenProofGenerationError::IllegalAmountBitLength => TokenError::IllegalBitLength,
473467
TokenProofGenerationError::FeeCalculation => TokenError::FeeCalculation,
474-
TokenProofGenerationError::SupplyDecryption => TokenError::SupplyDecryption,
475468
}
476469
}
477470
}

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ use {
77
auth_encryption::{AeCiphertext, AeKey},
88
elgamal::{ElGamalCiphertext, ElGamalKeypair},
99
pedersen::PedersenOpening,
10-
pod::{auth_encryption::PodAeCiphertext, elgamal::PodElGamalCiphertext},
10+
pod::{
11+
auth_encryption::PodAeCiphertext,
12+
elgamal::{PodElGamalCiphertext, PodElGamalPubkey},
13+
},
1114
},
1215
zk_elgamal_proof_program::proof_data::CiphertextCiphertextEqualityProofData,
1316
},
14-
spl_pod::optional_keys::OptionalNonZeroElGamalPubkey,
1517
};
1618

1719
/// Confidential Mint Burn extension information needed to construct a
@@ -24,7 +26,7 @@ pub struct SupplyAccountInfo {
2426
/// The decryptable supply
2527
pub decryptable_supply: PodAeCiphertext,
2628
/// The supply's elgamal pubkey
27-
pub supply_elgamal_pubkey: OptionalNonZeroElGamalPubkey,
29+
pub supply_elgamal_pubkey: PodElGamalPubkey,
2830
}
2931

3032
impl SupplyAccountInfo {
@@ -46,11 +48,8 @@ impl SupplyAccountInfo {
4648
aes_key: &AeKey,
4749
elgamal_keypair: &ElGamalKeypair,
4850
) -> Result<u64, TokenError> {
49-
if self.supply_elgamal_pubkey.is_none() {
50-
return Err(TokenError::InvalidState);
51-
}
5251
// decrypt the decryptable supply
53-
let current_decyptable_supply = TryInto::<AeCiphertext>::try_into(self.decryptable_supply)
52+
let current_decyptable_supply = AeCiphertext::try_from(self.decryptable_supply)
5453
.map_err(|_| TokenError::MalformedCiphertext)?
5554
.decrypt(aes_key)
5655
.ok_or(TokenError::MalformedCiphertext)?;
@@ -61,8 +60,8 @@ impl SupplyAccountInfo {
6160
elgamal_keypair.pubkey().encrypt(current_decyptable_supply);
6261
#[allow(clippy::arithmetic_side_effects)]
6362
let supply_delta_ciphertext = decryptable_supply_ciphertext
64-
- (TryInto::<ElGamalCiphertext>::try_into(self.current_supply)
65-
.map_err(|_| TokenError::MalformedCiphertext)?);
63+
- ElGamalCiphertext::try_from(self.current_supply)
64+
.map_err(|_| TokenError::MalformedCiphertext)?;
6665
let decryptable_to_current_diff = elgamal_keypair
6766
.secret()
6867
.decrypt_u32(&supply_delta_ciphertext)

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

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
#[cfg(not(target_os = "solana"))]
2-
use crate::proof::{process_proof_location, ProofLocation};
3-
#[cfg(not(target_os = "solana"))]
4-
use solana_zk_sdk::encryption::{auth_encryption::AeCiphertext, elgamal::ElGamalPubkey};
5-
#[cfg(not(target_os = "solana"))]
6-
use solana_zk_sdk::zk_elgamal_proof_program::{
7-
instruction::ProofInstruction,
8-
proof_data::{
9-
BatchedGroupedCiphertext3HandlesValidityProofData, BatchedRangeProofU128Data,
10-
CiphertextCiphertextEqualityProofData, CiphertextCommitmentEqualityProofData,
2+
use {
3+
crate::proof::{process_proof_location, ProofLocation},
4+
solana_zk_sdk::{
5+
encryption::{auth_encryption::AeCiphertext, elgamal::ElGamalPubkey},
6+
zk_elgamal_proof_program::{
7+
instruction::ProofInstruction,
8+
proof_data::{
9+
BatchedGroupedCiphertext3HandlesValidityProofData, BatchedRangeProofU128Data,
10+
CiphertextCiphertextEqualityProofData, CiphertextCommitmentEqualityProofData,
11+
},
12+
},
1113
},
1214
};
1315
#[cfg(feature = "serde-traits")]
1416
use {
15-
crate::serialization::aeciphertext_fromstr,
17+
crate::serialization::{aeciphertext_fromstr, elgamalpubkey_fromstr},
1618
serde::{Deserialize, Serialize},
1719
};
1820
use {
@@ -29,7 +31,7 @@ use {
2931
pubkey::Pubkey,
3032
},
3133
solana_zk_sdk::encryption::pod::{auth_encryption::PodAeCiphertext, elgamal::PodElGamalPubkey},
32-
spl_pod::optional_keys::{OptionalNonZeroElGamalPubkey, OptionalNonZeroPubkey},
34+
spl_pod::optional_keys::OptionalNonZeroPubkey,
3335
};
3436

3537
/// Confidential Transfer extension instructions
@@ -98,7 +100,6 @@ pub enum ConfidentialMintBurnInstruction {
98100
/// Mints tokens to confidential balance
99101
///
100102
/// Fails if the destination account is frozen.
101-
/// Fails if the associated mint is extended as `NonTransferable`.
102103
///
103104
/// Accounts expected by this instruction:
104105
///
@@ -135,11 +136,10 @@ pub enum ConfidentialMintBurnInstruction {
135136
///
136137
/// Data expected by this instruction:
137138
/// `MintInstructionData`
138-
ConfidentialMint,
139+
Mint,
139140
/// Burn tokens from confidential balance
140141
///
141142
/// Fails if the destination account is frozen.
142-
/// Fails if the associated mint is extended as `NonTransferable`.
143143
///
144144
/// Accounts expected by this instruction:
145145
///
@@ -176,7 +176,7 @@ pub enum ConfidentialMintBurnInstruction {
176176
///
177177
/// Data expected by this instruction:
178178
/// `BurnInstructionData`
179-
ConfidentialBurn,
179+
Burn,
180180
}
181181

182182
/// Data expected by `ConfidentialMintBurnInstruction::InitializeMint`
@@ -189,7 +189,8 @@ pub struct InitializeMintData {
189189
/// configuration and mint new tokens
190190
pub authority: OptionalNonZeroPubkey,
191191
/// The ElGamal pubkey used to encrypt the confidential supply
192-
pub supply_elgamal_pubkey: OptionalNonZeroElGamalPubkey,
192+
#[cfg_attr(feature = "serde-traits", serde(with = "elgamalpubkey_fromstr"))]
193+
pub supply_elgamal_pubkey: PodElGamalPubkey,
193194
/// The initial 0 supply ecrypted with the supply aes key
194195
#[cfg_attr(feature = "serde-traits", serde(with = "aeciphertext_fromstr"))]
195196
pub decryptable_supply: PodAeCiphertext,
@@ -202,7 +203,8 @@ pub struct InitializeMintData {
202203
#[repr(C)]
203204
pub struct RotateSupplyElGamalPubkeyData {
204205
/// The new ElGamal pubkey for supply encryption
205-
pub new_supply_elgamal_pubkey: OptionalNonZeroElGamalPubkey,
206+
#[cfg_attr(feature = "serde-traits", serde(with = "elgamalpubkey_fromstr"))]
207+
pub new_supply_elgamal_pubkey: PodElGamalPubkey,
206208
/// The location of the
207209
/// `ProofInstruction::VerifyCiphertextCiphertextEquality` instruction
208210
/// relative to the `RotateSupplyElGamal` instruction in the transaction
@@ -275,27 +277,21 @@ pub fn initialize_mint(
275277
token_program_id: &Pubkey,
276278
mint: &Pubkey,
277279
authority: &Pubkey,
278-
confidential_supply_pubkey: Option<PodElGamalPubkey>,
279-
decryptable_supply: Option<PodAeCiphertext>,
280+
supply_elgamal_pubkey: PodElGamalPubkey,
281+
decryptable_supply: PodAeCiphertext,
280282
) -> Result<Instruction, ProgramError> {
281283
check_program_account(token_program_id)?;
282284
let accounts = vec![AccountMeta::new(*mint, false)];
283285

284-
let decryptable_supply = if confidential_supply_pubkey.is_some() {
285-
decryptable_supply.ok_or(ProgramError::InvalidInstructionData)?
286-
} else {
287-
PodAeCiphertext::zeroed()
288-
};
289-
290-
let authority = Some(authority);
286+
let authority = Some(*authority);
291287
Ok(encode_instruction(
292288
token_program_id,
293289
accounts,
294290
TokenInstruction::ConfidentialMintBurnExtension,
295291
ConfidentialMintBurnInstruction::InitializeMint,
296292
&InitializeMintData {
297293
authority: authority.try_into()?,
298-
supply_elgamal_pubkey: confidential_supply_pubkey.try_into()?,
294+
supply_elgamal_pubkey,
299295
decryptable_supply,
300296
},
301297
))
@@ -341,10 +337,7 @@ pub fn rotate_supply_elgamal_pubkey(
341337
TokenInstruction::ConfidentialMintBurnExtension,
342338
ConfidentialMintBurnInstruction::RotateSupplyElGamalPubkey,
343339
&RotateSupplyElGamalPubkeyData {
344-
new_supply_elgamal_pubkey: Some(Into::<PodElGamalPubkey>::into(
345-
new_supply_elgamal_pubkey,
346-
))
347-
.try_into()?,
340+
new_supply_elgamal_pubkey: PodElGamalPubkey::from(new_supply_elgamal_pubkey),
348341
proof_instruction_offset,
349342
},
350343
)];
@@ -464,7 +457,7 @@ pub fn confidential_mint_with_split_proofs(
464457
token_program_id,
465458
accounts,
466459
TokenInstruction::ConfidentialMintBurnExtension,
467-
ConfidentialMintBurnInstruction::ConfidentialMint,
460+
ConfidentialMintBurnInstruction::Mint,
468461
&MintInstructionData {
469462
new_decryptable_supply: new_decryptable_supply.into(),
470463
equality_proof_instruction_offset,
@@ -546,7 +539,7 @@ pub fn confidential_burn_with_split_proofs(
546539
token_program_id,
547540
accounts,
548541
TokenInstruction::ConfidentialMintBurnExtension,
549-
ConfidentialMintBurnInstruction::ConfidentialBurn,
542+
ConfidentialMintBurnInstruction::Burn,
550543
&BurnInstructionData {
551544
new_decryptable_available_balance,
552545
equality_proof_instruction_offset,

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use {
22
crate::extension::{Extension, ExtensionType},
33
bytemuck::{Pod, Zeroable},
44
solana_zk_sdk::encryption::pod::{
5-
auth_encryption::PodAeCiphertext, elgamal::PodElGamalCiphertext,
5+
auth_encryption::PodAeCiphertext,
6+
elgamal::{PodElGamalCiphertext, PodElGamalPubkey},
67
},
7-
spl_pod::optional_keys::{OptionalNonZeroElGamalPubkey, OptionalNonZeroPubkey},
8+
spl_pod::optional_keys::OptionalNonZeroPubkey,
89
};
910

1011
/// Maximum bit length of any mint or burn amount
@@ -40,7 +41,7 @@ pub struct ConfidentialMintBurn {
4041
/// The decryptable confidential supply of the mint
4142
pub decryptable_supply: PodAeCiphertext,
4243
/// The ElGamal pubkey used to encrypt the confidential supply
43-
pub supply_elgamal_pubkey: OptionalNonZeroElGamalPubkey,
44+
pub supply_elgamal_pubkey: PodElGamalPubkey,
4445
}
4546

4647
impl Extension for ConfidentialMintBurn {

0 commit comments

Comments
 (0)