|
4 | 4 | zk_elgamal_proof_program::proof_data::ZkProofData,
|
5 | 5 | },
|
6 | 6 | 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, |
9 | 9 | },
|
10 | 10 | spl_token_confidential_transfer_proof_generation::{
|
| 11 | + burn::{burn_split_proof_data, BurnProofData}, |
| 12 | + mint::{mint_split_proof_data, MintProofData}, |
11 | 13 | transfer::{transfer_split_proof_data, TransferProofData},
|
12 | 14 | transfer_with_fee::{transfer_with_fee_split_proof_data, TransferWithFeeProofData},
|
13 | 15 | withdraw::{withdraw_proof_data, WithdrawProofData},
|
@@ -182,3 +184,79 @@ fn test_withdraw_validity(spendable_balance: u64, withdraw_amount: u64) {
|
182 | 184 | )
|
183 | 185 | .unwrap();
|
184 | 186 | }
|
| 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