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

Commit fdc24e0

Browse files
committed
add tests for confidential mint and burn
1 parent f789010 commit fdc24e0

File tree

1 file changed

+80
-2
lines changed

1 file changed

+80
-2
lines changed

token/confidential-transfer/proof-tests/tests/proof_test.rs

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ use {
44
zk_elgamal_proof_program::proof_data::ZkProofData,
55
},
66
spl_token_confidential_transfer_proof_extraction::{
7-
transfer::TransferProofContext, transfer_with_fee::TransferWithFeeProofContext,
8-
withdraw::WithdrawProofContext,
7+
burn::BurnProofContext, mint::MintProofContext, transfer::TransferProofContext,
8+
transfer_with_fee::TransferWithFeeProofContext, withdraw::WithdrawProofContext,
99
},
1010
spl_token_confidential_transfer_proof_generation::{
11+
burn::{burn_split_proof_data, BurnProofData},
12+
mint::{mint_split_proof_data, MintProofData},
1113
transfer::{transfer_split_proof_data, TransferProofData},
1214
transfer_with_fee::{transfer_with_fee_split_proof_data, TransferWithFeeProofData},
1315
withdraw::{withdraw_proof_data, WithdrawProofData},
@@ -182,3 +184,79 @@ fn test_withdraw_validity(spendable_balance: u64, withdraw_amount: u64) {
182184
)
183185
.unwrap();
184186
}
187+
188+
#[test]
189+
fn test_mint_proof_correctness() {
190+
test_mint_validity(0);
191+
test_mint_validity(1);
192+
test_mint_validity(65535);
193+
test_mint_validity(65536);
194+
test_mint_validity(281474976710655);
195+
}
196+
197+
fn test_mint_validity(mint_amount: u64) {
198+
let destination_keypair = ElGamalKeypair::new_rand();
199+
let destination_pubkey = destination_keypair.pubkey();
200+
201+
let auditor_keypair = ElGamalKeypair::new_rand();
202+
let auditor_pubkey = auditor_keypair.pubkey();
203+
204+
let MintProofData {
205+
ciphertext_validity_proof_data,
206+
range_proof_data,
207+
} = mint_split_proof_data(mint_amount, destination_pubkey, auditor_pubkey).unwrap();
208+
209+
ciphertext_validity_proof_data.verify_proof().unwrap();
210+
range_proof_data.verify_proof().unwrap();
211+
212+
MintProofContext::verify_and_extract(
213+
ciphertext_validity_proof_data.context_data(),
214+
range_proof_data.context_data(),
215+
)
216+
.unwrap();
217+
}
218+
219+
#[test]
220+
fn test_burn_proof_correctness() {
221+
test_burn_validity(0, 0);
222+
test_burn_validity(77, 55);
223+
test_burn_validity(65535, 65535);
224+
test_burn_validity(65536, 65536);
225+
test_burn_validity(281474976710655, 281474976710655);
226+
}
227+
228+
fn test_burn_validity(spendable_balance: u64, burn_amount: u64) {
229+
let source_keypair = ElGamalKeypair::new_rand();
230+
let aes_key = AeKey::new_rand();
231+
232+
let auditor_keypair = ElGamalKeypair::new_rand();
233+
let auditor_pubkey = auditor_keypair.pubkey();
234+
235+
let spendable_balance_ciphertext = source_keypair.pubkey().encrypt(spendable_balance);
236+
let decryptable_balance = aes_key.encrypt(spendable_balance);
237+
238+
let BurnProofData {
239+
equality_proof_data,
240+
ciphertext_validity_proof_data,
241+
range_proof_data,
242+
} = burn_split_proof_data(
243+
&spendable_balance_ciphertext,
244+
&decryptable_balance,
245+
burn_amount,
246+
&source_keypair,
247+
&aes_key,
248+
auditor_pubkey,
249+
)
250+
.unwrap();
251+
252+
equality_proof_data.verify_proof().unwrap();
253+
ciphertext_validity_proof_data.verify_proof().unwrap();
254+
range_proof_data.verify_proof().unwrap();
255+
256+
BurnProofContext::verify_and_extract(
257+
equality_proof_data.context_data(),
258+
ciphertext_validity_proof_data.context_data(),
259+
range_proof_data.context_data(),
260+
)
261+
.unwrap();
262+
}

0 commit comments

Comments
 (0)