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

Commit a4ceea3

Browse files
[zk-token-sdk] Allow all zero auditor pubkey in proofs (#33106)
* allow auditor ElGamal public key to be all zero * remove test components on all zero auditor ElGamal pubkey
1 parent 9316655 commit a4ceea3

File tree

3 files changed

+4
-93
lines changed

3 files changed

+4
-93
lines changed

zk-token-sdk/src/instruction/transfer/with_fee.rs

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ mod test {
840840

841841
assert!(fee_data.verify_proof().is_ok());
842842

843-
// Case 4: invalid destination, auditor, or withdraw authority pubkeys
843+
// Case 4: destination pubkey invalid
844844
let spendable_balance: u64 = 120;
845845
let spendable_ciphertext = source_keypair.pubkey().encrypt(spendable_balance);
846846

@@ -871,47 +871,5 @@ mod test {
871871
.unwrap();
872872

873873
assert!(fee_data.verify_proof().is_err());
874-
875-
// auditor pubkey invalid
876-
let destination_keypair = ElGamalKeypair::new_rand();
877-
let destination_pubkey = destination_keypair.pubkey();
878-
879-
let auditor_pubkey = pod::ElGamalPubkey::zeroed().try_into().unwrap();
880-
881-
let withdraw_withheld_authority_keypair = ElGamalKeypair::new_rand();
882-
let withdraw_withheld_authority_pubkey = withdraw_withheld_authority_keypair.pubkey();
883-
884-
let fee_data = TransferWithFeeData::new(
885-
transfer_amount,
886-
(spendable_balance, &spendable_ciphertext),
887-
&source_keypair,
888-
(destination_pubkey, &auditor_pubkey),
889-
fee_parameters,
890-
withdraw_withheld_authority_pubkey,
891-
)
892-
.unwrap();
893-
894-
assert!(fee_data.verify_proof().is_err());
895-
896-
// withdraw authority invalid
897-
let destination_keypair = ElGamalKeypair::new_rand();
898-
let destination_pubkey = destination_keypair.pubkey();
899-
900-
let auditor_keypair = ElGamalKeypair::new_rand();
901-
let auditor_pubkey = auditor_keypair.pubkey();
902-
903-
let withdraw_withheld_authority_pubkey = pod::ElGamalPubkey::zeroed().try_into().unwrap();
904-
905-
let fee_data = TransferWithFeeData::new(
906-
transfer_amount,
907-
(spendable_balance, &spendable_ciphertext),
908-
&source_keypair,
909-
(destination_pubkey, auditor_pubkey),
910-
fee_parameters,
911-
&withdraw_withheld_authority_pubkey,
912-
)
913-
.unwrap();
914-
915-
assert!(fee_data.verify_proof().is_err());
916874
}
917875
}

zk-token-sdk/src/instruction/transfer/without_fee.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -524,13 +524,11 @@ mod test {
524524

525525
assert!(transfer_data.verify_proof().is_ok());
526526

527-
// Case 4: invalid destination or auditor pubkey
527+
// Case 4: destination pubkey is invalid
528528
let spendable_balance: u64 = 0;
529529
let spendable_ciphertext = source_keypair.pubkey().encrypt(spendable_balance);
530-
531530
let transfer_amount: u64 = 0;
532531

533-
// destination pubkey invalid
534532
let dest_pk = pod::ElGamalPubkey::zeroed().try_into().unwrap();
535533
let auditor_keypair = ElGamalKeypair::new_rand();
536534
let auditor_pk = auditor_keypair.pubkey();
@@ -544,21 +542,6 @@ mod test {
544542
.unwrap();
545543

546544
assert!(transfer_data.verify_proof().is_err());
547-
548-
// auditor pubkey invalid
549-
let dest_keypair = ElGamalKeypair::new_rand();
550-
let dest_pk = dest_keypair.pubkey();
551-
let auditor_pk = pod::ElGamalPubkey::zeroed().try_into().unwrap();
552-
553-
let transfer_data = TransferData::new(
554-
transfer_amount,
555-
(spendable_balance, &spendable_ciphertext),
556-
&source_keypair,
557-
(dest_pk, &auditor_pk),
558-
)
559-
.unwrap();
560-
561-
assert!(transfer_data.verify_proof().is_err());
562545
}
563546

564547
#[test]

zk-token-sdk/src/sigma_proofs/grouped_ciphertext_validity_proof.rs

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ impl GroupedCiphertext2HandlesValidityProof {
134134
// include Y_0, Y_1, Y_2 to transcript and extract challenges
135135
transcript.validate_and_append_point(b"Y_0", &self.Y_0)?;
136136
transcript.validate_and_append_point(b"Y_1", &self.Y_1)?;
137-
transcript.validate_and_append_point(b"Y_2", &self.Y_2)?;
137+
// Y_2 can be an all zero point if the auditor public key is all zero
138+
transcript.append_point(b"Y_2", &self.Y_2);
138139

139140
let c = transcript.challenge_scalar(b"c");
140141
let w = transcript.challenge_scalar(b"w");
@@ -301,37 +302,6 @@ mod test {
301302
)
302303
.is_err());
303304

304-
// if auditor public key zeroed, then the proof should always reject
305-
let destination_keypair = ElGamalKeypair::new_rand();
306-
let destination_pubkey = destination_keypair.pubkey();
307-
308-
let auditor_pubkey = ElGamalPubkey::from_bytes(&[0u8; 32]).unwrap();
309-
310-
let amount: u64 = 55;
311-
let (commitment, opening) = Pedersen::new(amount);
312-
313-
let destination_handle = destination_pubkey.decrypt_handle(&opening);
314-
let auditor_handle = auditor_pubkey.decrypt_handle(&opening);
315-
316-
let mut prover_transcript = Transcript::new(b"Test");
317-
let mut verifier_transcript = Transcript::new(b"Test");
318-
319-
let proof = GroupedCiphertext2HandlesValidityProof::new(
320-
(destination_pubkey, &auditor_pubkey),
321-
amount,
322-
&opening,
323-
&mut prover_transcript,
324-
);
325-
326-
assert!(proof
327-
.verify(
328-
&commitment,
329-
(destination_pubkey, &auditor_pubkey),
330-
(&destination_handle, &auditor_handle),
331-
&mut verifier_transcript,
332-
)
333-
.is_err());
334-
335305
// all zeroed ciphertext should still be valid
336306
let destination_keypair = ElGamalKeypair::new_rand();
337307
let destination_pubkey = destination_keypair.pubkey();

0 commit comments

Comments
 (0)