diff --git a/token/confidential-transfer/proof-tests/tests/proof_test.rs b/token/confidential-transfer/proof-tests/tests/proof_test.rs index 0796cbb9a6a..b83013921da 100644 --- a/token/confidential-transfer/proof-tests/tests/proof_test.rs +++ b/token/confidential-transfer/proof-tests/tests/proof_test.rs @@ -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}, @@ -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(); +}