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

Commit 1928685

Browse files
committed
add tests for confidential mint and burn
1 parent 20e820b commit 1928685

File tree

1 file changed

+93
-2
lines changed

1 file changed

+93
-2
lines changed

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

Lines changed: 93 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,92 @@ 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 supply_keypair = ElGamalKeypair::new_rand();
205+
let supply_pubkey = supply_keypair.pubkey();
206+
207+
let MintProofData {
208+
ciphertext_validity_proof_data,
209+
range_proof_data,
210+
} = mint_split_proof_data(
211+
mint_amount,
212+
destination_pubkey,
213+
auditor_pubkey,
214+
supply_pubkey,
215+
)
216+
.unwrap();
217+
218+
ciphertext_validity_proof_data.verify_proof().unwrap();
219+
range_proof_data.verify_proof().unwrap();
220+
221+
MintProofContext::verify_and_extract(
222+
ciphertext_validity_proof_data.context_data(),
223+
range_proof_data.context_data(),
224+
)
225+
.unwrap();
226+
}
227+
228+
#[test]
229+
fn test_burn_proof_correctness() {
230+
test_burn_validity(0, 0);
231+
test_burn_validity(77, 55);
232+
test_burn_validity(65535, 65535);
233+
test_burn_validity(65536, 65536);
234+
test_burn_validity(281474976710655, 281474976710655);
235+
}
236+
237+
fn test_burn_validity(spendable_balance: u64, burn_amount: u64) {
238+
let source_keypair = ElGamalKeypair::new_rand();
239+
let aes_key = AeKey::new_rand();
240+
241+
let auditor_keypair = ElGamalKeypair::new_rand();
242+
let auditor_pubkey = auditor_keypair.pubkey();
243+
244+
let supply_keypair = ElGamalKeypair::new_rand();
245+
let supply_pubkey = supply_keypair.pubkey();
246+
247+
let spendable_balance_ciphertext = source_keypair.pubkey().encrypt(spendable_balance);
248+
let decryptable_balance = aes_key.encrypt(spendable_balance);
249+
250+
let BurnProofData {
251+
equality_proof_data,
252+
ciphertext_validity_proof_data,
253+
range_proof_data,
254+
} = burn_split_proof_data(
255+
&spendable_balance_ciphertext,
256+
&decryptable_balance,
257+
burn_amount,
258+
&source_keypair,
259+
&aes_key,
260+
auditor_pubkey,
261+
supply_pubkey,
262+
)
263+
.unwrap();
264+
265+
equality_proof_data.verify_proof().unwrap();
266+
ciphertext_validity_proof_data.verify_proof().unwrap();
267+
range_proof_data.verify_proof().unwrap();
268+
269+
BurnProofContext::verify_and_extract(
270+
equality_proof_data.context_data(),
271+
ciphertext_validity_proof_data.context_data(),
272+
range_proof_data.context_data(),
273+
)
274+
.unwrap();
275+
}

0 commit comments

Comments
 (0)