Skip to content

Commit

Permalink
more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
samkim-crypto committed Dec 10, 2024
1 parent 7fbfcfd commit 13809a9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
4 changes: 0 additions & 4 deletions token/confidential-transfer/proof-generation/src/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use {
},
solana_zk_sdk::{
encryption::{
auth_encryption::{AeCiphertext, AeKey},
elgamal::{ElGamalCiphertext, ElGamalKeypair, ElGamalPubkey},
pedersen::Pedersen,
},
Expand All @@ -28,15 +27,13 @@ pub struct MintProofData {
pub ciphertext_validity_proof_data_with_ciphertext:
CiphertextValidityProofWithAuditorCiphertext,
pub range_proof_data: BatchedRangeProofU128Data,
pub new_decryptable_supply: AeCiphertext,
}

pub fn mint_split_proof_data(
current_supply_ciphertext: &ElGamalCiphertext,
mint_amount: u64,
current_supply: u64,
supply_elgamal_keypair: &ElGamalKeypair,
supply_aes_key: &AeKey,
destination_elgamal_pubkey: &ElGamalPubkey,
auditor_elgamal_pubkey: Option<&ElGamalPubkey>,
) -> Result<MintProofData, TokenProofGenerationError> {
Expand Down Expand Up @@ -161,6 +158,5 @@ pub fn mint_split_proof_data(
equality_proof_data,
ciphertext_validity_proof_data_with_ciphertext,
range_proof_data,
new_decryptable_supply: supply_aes_key.encrypt(new_supply),
})
}
3 changes: 0 additions & 3 deletions token/confidential-transfer/proof-tests/tests/proof_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,18 @@ fn test_mint_validity(mint_amount: u64, supply: u64) {
let auditor_pubkey = auditor_keypair.pubkey();

let supply_keypair = ElGamalKeypair::new_rand();
let supply_aes_key = AeKey::new_rand();

let supply_ciphertext = supply_keypair.pubkey().encrypt(supply);

let MintProofData {
equality_proof_data,
ciphertext_validity_proof_data_with_ciphertext,
range_proof_data,
new_decryptable_supply: _,
} = mint_split_proof_data(
&supply_ciphertext,
mint_amount,
supply,
&supply_keypair,
&supply_aes_key,
destination_pubkey,
Some(auditor_pubkey),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl SupplyAccountInfo {
/// Computes the current supply from the decryptable supply and the
/// difference between the decryptable supply and the ElGamal encrypted
/// supply ciphertext
pub fn decrypt_current_supply(
pub fn decrypted_current_supply(
&self,
aes_key: &AeKey,
elgamal_keypair: &ElGamalKeypair,
Expand Down Expand Up @@ -91,7 +91,7 @@ impl SupplyAccountInfo {
new_supply_elgamal_keypair: &ElGamalKeypair,
) -> Result<CiphertextCiphertextEqualityProofData, TokenError> {
let current_supply =
self.decrypt_current_supply(aes_key, current_supply_elgamal_keypair)?;
self.decrypted_current_supply(aes_key, current_supply_elgamal_keypair)?;

let new_supply_opening = PedersenOpening::new_rand();
let new_supply_ciphertext = new_supply_elgamal_keypair
Expand Down Expand Up @@ -119,7 +119,6 @@ impl SupplyAccountInfo {
mint_amount: u64,
current_supply: u64,
supply_elgamal_keypair: &ElGamalKeypair,
aes_key: &AeKey,
destination_elgamal_pubkey: &ElGamalPubkey,
auditor_elgamal_pubkey: Option<&ElGamalPubkey>,
) -> Result<MintProofData, TokenError> {
Expand All @@ -133,12 +132,26 @@ impl SupplyAccountInfo {
mint_amount,
current_supply,
supply_elgamal_keypair,
aes_key,
destination_elgamal_pubkey,
auditor_elgamal_pubkey,
)
.map_err(|e| -> TokenError { e.into() })
}

/// Compute the new decryptable supply.
pub fn new_decryptable_supply(
&self,
mint_amount: u64,
aes_key: &AeKey,
elgamal_keypair: &ElGamalKeypair, // TODO: check consistency of the order of params
) -> Result<AeCiphertext, TokenError> {
let current_decrypted_supply = self.decrypted_current_supply(aes_key, elgamal_keypair)?;
let new_decrypted_available_balance = current_decrypted_supply
.checked_add(mint_amount)
.ok_or(TokenError::Overflow)?;

Ok(aes_key.encrypt(new_decrypted_available_balance))
}
}

/// Confidential Mint Burn extension information needed to construct a
Expand Down

0 comments on commit 13809a9

Please sign in to comment.