Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
add tests for confidential mint and burn
Browse files Browse the repository at this point in the history
  • Loading branch information
samkim-crypto committed Sep 6, 2024
1 parent f789010 commit fdc24e0
Showing 1 changed file with 80 additions and 2 deletions.
82 changes: 80 additions & 2 deletions token/confidential-transfer/proof-tests/tests/proof_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ use {
zk_elgamal_proof_program::proof_data::ZkProofData,
},
spl_token_confidential_transfer_proof_extraction::{
transfer::TransferProofContext, transfer_with_fee::TransferWithFeeProofContext,
withdraw::WithdrawProofContext,
burn::BurnProofContext, mint::MintProofContext, transfer::TransferProofContext,
transfer_with_fee::TransferWithFeeProofContext, withdraw::WithdrawProofContext,
},
spl_token_confidential_transfer_proof_generation::{
burn::{burn_split_proof_data, BurnProofData},
mint::{mint_split_proof_data, MintProofData},
transfer::{transfer_split_proof_data, TransferProofData},
transfer_with_fee::{transfer_with_fee_split_proof_data, TransferWithFeeProofData},
withdraw::{withdraw_proof_data, WithdrawProofData},
Expand Down Expand Up @@ -182,3 +184,79 @@ fn test_withdraw_validity(spendable_balance: u64, withdraw_amount: u64) {
)
.unwrap();
}

#[test]
fn test_mint_proof_correctness() {
test_mint_validity(0);
test_mint_validity(1);
test_mint_validity(65535);
test_mint_validity(65536);
test_mint_validity(281474976710655);
}

fn test_mint_validity(mint_amount: u64) {
let destination_keypair = ElGamalKeypair::new_rand();
let destination_pubkey = destination_keypair.pubkey();

let auditor_keypair = ElGamalKeypair::new_rand();
let auditor_pubkey = auditor_keypair.pubkey();

let MintProofData {
ciphertext_validity_proof_data,
range_proof_data,
} = mint_split_proof_data(mint_amount, destination_pubkey, auditor_pubkey).unwrap();

ciphertext_validity_proof_data.verify_proof().unwrap();
range_proof_data.verify_proof().unwrap();

MintProofContext::verify_and_extract(
ciphertext_validity_proof_data.context_data(),
range_proof_data.context_data(),
)
.unwrap();
}

#[test]
fn test_burn_proof_correctness() {
test_burn_validity(0, 0);
test_burn_validity(77, 55);
test_burn_validity(65535, 65535);
test_burn_validity(65536, 65536);
test_burn_validity(281474976710655, 281474976710655);
}

fn test_burn_validity(spendable_balance: u64, burn_amount: u64) {
let source_keypair = ElGamalKeypair::new_rand();
let aes_key = AeKey::new_rand();

let auditor_keypair = ElGamalKeypair::new_rand();
let auditor_pubkey = auditor_keypair.pubkey();

let spendable_balance_ciphertext = source_keypair.pubkey().encrypt(spendable_balance);
let decryptable_balance = aes_key.encrypt(spendable_balance);

let BurnProofData {
equality_proof_data,
ciphertext_validity_proof_data,
range_proof_data,
} = burn_split_proof_data(
&spendable_balance_ciphertext,
&decryptable_balance,
burn_amount,
&source_keypair,
&aes_key,
auditor_pubkey,
)
.unwrap();

equality_proof_data.verify_proof().unwrap();
ciphertext_validity_proof_data.verify_proof().unwrap();
range_proof_data.verify_proof().unwrap();

BurnProofContext::verify_and_extract(
equality_proof_data.context_data(),
ciphertext_validity_proof_data.context_data(),
range_proof_data.context_data(),
)
.unwrap();
}

0 comments on commit fdc24e0

Please sign in to comment.