10
10
} ,
11
11
solana_zk_token_sdk:: {
12
12
encryption:: {
13
- elgamal:: ElGamalKeypair ,
13
+ elgamal:: { ElGamalKeypair , ElGamalSecretKey } ,
14
14
grouped_elgamal:: GroupedElGamal ,
15
15
pedersen:: { Pedersen , PedersenOpening } ,
16
16
} ,
@@ -42,13 +42,13 @@ const VERIFY_INSTRUCTION_TYPES: [ProofInstruction; 13] = [
42
42
async fn test_zero_balance ( ) {
43
43
let elgamal_keypair = ElGamalKeypair :: new_rand ( ) ;
44
44
45
- let zero_ciphertext = elgamal_keypair. public . encrypt ( 0_u64 ) ;
45
+ let zero_ciphertext = elgamal_keypair. pubkey ( ) . encrypt ( 0_u64 ) ;
46
46
let success_proof_data = ZeroBalanceProofData :: new ( & elgamal_keypair, & zero_ciphertext) . unwrap ( ) ;
47
47
48
- let incorrect_keypair = ElGamalKeypair {
49
- public : ElGamalKeypair :: new_rand ( ) . public ,
50
- secret : ElGamalKeypair :: new_rand ( ) . secret ,
51
- } ;
48
+ let incorrect_pubkey = elgamal_keypair . pubkey ( ) ;
49
+ let incorrect_secret = ElGamalSecretKey :: new_rand ( ) ;
50
+ let incorrect_keypair = ElGamalKeypair :: new_for_tests ( * incorrect_pubkey , incorrect_secret ) ;
51
+
52
52
let fail_proof_data = ZeroBalanceProofData :: new ( & incorrect_keypair, & zero_ciphertext) . unwrap ( ) ;
53
53
54
54
test_verify_proof_without_context (
@@ -80,30 +80,30 @@ async fn test_ciphertext_ciphertext_equality() {
80
80
let destination_keypair = ElGamalKeypair :: new_rand ( ) ;
81
81
82
82
let amount: u64 = 0 ;
83
- let source_ciphertext = source_keypair. public . encrypt ( amount) ;
83
+ let source_ciphertext = source_keypair. pubkey ( ) . encrypt ( amount) ;
84
84
85
85
let destination_opening = PedersenOpening :: new_rand ( ) ;
86
86
let destination_ciphertext = destination_keypair
87
- . public
87
+ . pubkey ( )
88
88
. encrypt_with ( amount, & destination_opening) ;
89
89
90
90
let success_proof_data = CiphertextCiphertextEqualityProofData :: new (
91
91
& source_keypair,
92
- & destination_keypair. public ,
92
+ destination_keypair. pubkey ( ) ,
93
93
& source_ciphertext,
94
94
& destination_ciphertext,
95
95
& destination_opening,
96
96
amount,
97
97
)
98
98
. unwrap ( ) ;
99
99
100
- let incorrect_keypair = ElGamalKeypair {
101
- public : ElGamalKeypair :: new_rand ( ) . public ,
102
- secret : ElGamalKeypair :: new_rand ( ) . secret ,
103
- } ;
100
+ let incorrect_pubkey = source_keypair . pubkey ( ) ;
101
+ let incorrect_secret = ElGamalSecretKey :: new_rand ( ) ;
102
+ let incorrect_keypair = ElGamalKeypair :: new_for_tests ( * incorrect_pubkey , incorrect_secret ) ;
103
+
104
104
let fail_proof_data = CiphertextCiphertextEqualityProofData :: new (
105
105
& incorrect_keypair,
106
- & destination_keypair. public ,
106
+ destination_keypair. pubkey ( ) ,
107
107
& source_ciphertext,
108
108
& destination_ciphertext,
109
109
& destination_opening,
@@ -137,32 +137,35 @@ async fn test_ciphertext_ciphertext_equality() {
137
137
#[ tokio:: test]
138
138
async fn test_transfer ( ) {
139
139
let source_keypair = ElGamalKeypair :: new_rand ( ) ;
140
- let dest_pubkey = ElGamalKeypair :: new_rand ( ) . public ;
141
- let auditor_pubkey = ElGamalKeypair :: new_rand ( ) . public ;
140
+
141
+ let destination_keypair = ElGamalKeypair :: new_rand ( ) ;
142
+ let destination_pubkey = destination_keypair. pubkey ( ) ;
143
+
144
+ let auditor_keypair = ElGamalKeypair :: new_rand ( ) ;
145
+ let auditor_pubkey = auditor_keypair. pubkey ( ) ;
142
146
143
147
let spendable_balance: u64 = 0 ;
144
- let spendable_ciphertext = source_keypair. public . encrypt ( spendable_balance) ;
148
+ let spendable_ciphertext = source_keypair. pubkey ( ) . encrypt ( spendable_balance) ;
145
149
146
150
let transfer_amount: u64 = 0 ;
147
151
148
152
let success_proof_data = TransferData :: new (
149
153
transfer_amount,
150
154
( spendable_balance, & spendable_ciphertext) ,
151
155
& source_keypair,
152
- ( & dest_pubkey , & auditor_pubkey) ,
156
+ ( destination_pubkey , auditor_pubkey) ,
153
157
)
154
158
. unwrap ( ) ;
155
159
156
- let incorrect_keypair = ElGamalKeypair {
157
- public : ElGamalKeypair :: new_rand ( ) . public ,
158
- secret : ElGamalKeypair :: new_rand ( ) . secret ,
159
- } ;
160
+ let incorrect_pubkey = source_keypair. pubkey ( ) ;
161
+ let incorrect_secret = ElGamalSecretKey :: new_rand ( ) ;
162
+ let incorrect_keypair = ElGamalKeypair :: new_for_tests ( * incorrect_pubkey, incorrect_secret) ;
160
163
161
164
let fail_proof_data = TransferData :: new (
162
165
transfer_amount,
163
166
( spendable_balance, & spendable_ciphertext) ,
164
167
& incorrect_keypair,
165
- ( & dest_pubkey , & auditor_pubkey) ,
168
+ ( destination_pubkey , auditor_pubkey) ,
166
169
)
167
170
. unwrap ( ) ;
168
171
@@ -192,12 +195,18 @@ async fn test_transfer() {
192
195
#[ tokio:: test]
193
196
async fn test_transfer_with_fee ( ) {
194
197
let source_keypair = ElGamalKeypair :: new_rand ( ) ;
195
- let destination_pubkey = ElGamalKeypair :: new_rand ( ) . public ;
196
- let auditor_pubkey = ElGamalKeypair :: new_rand ( ) . public ;
197
- let withdraw_withheld_authority_pubkey = ElGamalKeypair :: new_rand ( ) . public ;
198
+
199
+ let destination_keypair = ElGamalKeypair :: new_rand ( ) ;
200
+ let destination_pubkey = destination_keypair. pubkey ( ) ;
201
+
202
+ let auditor_keypair = ElGamalKeypair :: new_rand ( ) ;
203
+ let auditor_pubkey = auditor_keypair. pubkey ( ) ;
204
+
205
+ let withdraw_withheld_authority_keypair = ElGamalKeypair :: new_rand ( ) ;
206
+ let withdraw_withheld_authority_pubkey = withdraw_withheld_authority_keypair. pubkey ( ) ;
198
207
199
208
let spendable_balance: u64 = 120 ;
200
- let spendable_ciphertext = source_keypair. public . encrypt ( spendable_balance) ;
209
+ let spendable_ciphertext = source_keypair. pubkey ( ) . encrypt ( spendable_balance) ;
201
210
202
211
let transfer_amount: u64 = 0 ;
203
212
@@ -210,24 +219,23 @@ async fn test_transfer_with_fee() {
210
219
transfer_amount,
211
220
( spendable_balance, & spendable_ciphertext) ,
212
221
& source_keypair,
213
- ( & destination_pubkey, & auditor_pubkey) ,
222
+ ( destination_pubkey, auditor_pubkey) ,
214
223
fee_parameters,
215
- & withdraw_withheld_authority_pubkey,
224
+ withdraw_withheld_authority_pubkey,
216
225
)
217
226
. unwrap ( ) ;
218
227
219
- let incorrect_keypair = ElGamalKeypair {
220
- public : ElGamalKeypair :: new_rand ( ) . public ,
221
- secret : ElGamalKeypair :: new_rand ( ) . secret ,
222
- } ;
228
+ let incorrect_pubkey = source_keypair. pubkey ( ) ;
229
+ let incorrect_secret = ElGamalSecretKey :: new_rand ( ) ;
230
+ let incorrect_keypair = ElGamalKeypair :: new_for_tests ( * incorrect_pubkey, incorrect_secret) ;
223
231
224
232
let fail_proof_data = TransferWithFeeData :: new (
225
233
transfer_amount,
226
234
( spendable_balance, & spendable_ciphertext) ,
227
235
& incorrect_keypair,
228
- ( & destination_pubkey, & auditor_pubkey) ,
236
+ ( destination_pubkey, auditor_pubkey) ,
229
237
fee_parameters,
230
- & withdraw_withheld_authority_pubkey,
238
+ withdraw_withheld_authority_pubkey,
231
239
)
232
240
. unwrap ( ) ;
233
241
@@ -259,7 +267,7 @@ async fn test_withdraw() {
259
267
let elgamal_keypair = ElGamalKeypair :: new_rand ( ) ;
260
268
261
269
let current_balance: u64 = 77 ;
262
- let current_ciphertext = elgamal_keypair. public . encrypt ( current_balance) ;
270
+ let current_ciphertext = elgamal_keypair. pubkey ( ) . encrypt ( current_balance) ;
263
271
let withdraw_amount: u64 = 55 ;
264
272
265
273
let success_proof_data = WithdrawData :: new (
@@ -270,10 +278,10 @@ async fn test_withdraw() {
270
278
)
271
279
. unwrap ( ) ;
272
280
273
- let incorrect_keypair = ElGamalKeypair {
274
- public : ElGamalKeypair :: new_rand ( ) . public ,
275
- secret : ElGamalKeypair :: new_rand ( ) . secret ,
276
- } ;
281
+ let incorrect_pubkey = elgamal_keypair . pubkey ( ) ;
282
+ let incorrect_secret = ElGamalSecretKey :: new_rand ( ) ;
283
+ let incorrect_keypair = ElGamalKeypair :: new_for_tests ( * incorrect_pubkey , incorrect_secret ) ;
284
+
277
285
let fail_proof_data = WithdrawData :: new (
278
286
withdraw_amount,
279
287
& incorrect_keypair,
@@ -311,10 +319,9 @@ async fn test_pubkey_validity() {
311
319
312
320
let success_proof_data = PubkeyValidityData :: new ( & elgamal_keypair) . unwrap ( ) ;
313
321
314
- let incorrect_keypair = ElGamalKeypair {
315
- public : ElGamalKeypair :: new_rand ( ) . public ,
316
- secret : ElGamalKeypair :: new_rand ( ) . secret ,
317
- } ;
322
+ let incorrect_pubkey = elgamal_keypair. pubkey ( ) ;
323
+ let incorrect_secret = ElGamalSecretKey :: new_rand ( ) ;
324
+ let incorrect_keypair = ElGamalKeypair :: new_for_tests ( * incorrect_pubkey, incorrect_secret) ;
318
325
319
326
let fail_proof_data = PubkeyValidityData :: new ( & incorrect_keypair) . unwrap ( ) ;
320
327
@@ -526,7 +533,7 @@ async fn test_batched_range_proof_u256() {
526
533
async fn test_ciphertext_commitment_equality ( ) {
527
534
let keypair = ElGamalKeypair :: new_rand ( ) ;
528
535
let amount: u64 = 55 ;
529
- let ciphertext = keypair. public . encrypt ( amount) ;
536
+ let ciphertext = keypair. pubkey ( ) . encrypt ( amount) ;
530
537
let ( commitment, opening) = Pedersen :: new ( amount) ;
531
538
532
539
let success_proof_data = CiphertextCommitmentEqualityProofData :: new (
@@ -538,10 +545,9 @@ async fn test_ciphertext_commitment_equality() {
538
545
)
539
546
. unwrap ( ) ;
540
547
541
- let incorrect_keypair = ElGamalKeypair {
542
- public : ElGamalKeypair :: new_rand ( ) . public ,
543
- secret : ElGamalKeypair :: new_rand ( ) . secret ,
544
- } ;
548
+ let incorrect_pubkey = keypair. pubkey ( ) ;
549
+ let incorrect_secret = ElGamalSecretKey :: new_rand ( ) ;
550
+ let incorrect_keypair = ElGamalKeypair :: new_for_tests ( * incorrect_pubkey, incorrect_secret) ;
545
551
546
552
let fail_proof_data = CiphertextCommitmentEqualityProofData :: new (
547
553
& incorrect_keypair,
@@ -577,17 +583,20 @@ async fn test_ciphertext_commitment_equality() {
577
583
578
584
#[ tokio:: test]
579
585
async fn test_grouped_ciphertext_2_handles_validity ( ) {
580
- let destination_pubkey = ElGamalKeypair :: new_rand ( ) . public ;
581
- let auditor_pubkey = ElGamalKeypair :: new_rand ( ) . public ;
586
+ let destination_keypair = ElGamalKeypair :: new_rand ( ) ;
587
+ let destination_pubkey = destination_keypair. pubkey ( ) ;
588
+
589
+ let auditor_keypair = ElGamalKeypair :: new_rand ( ) ;
590
+ let auditor_pubkey = auditor_keypair. pubkey ( ) ;
582
591
583
592
let amount: u64 = 55 ;
584
593
let opening = PedersenOpening :: new_rand ( ) ;
585
594
let grouped_ciphertext =
586
- GroupedElGamal :: encrypt_with ( [ & destination_pubkey, & auditor_pubkey] , amount, & opening) ;
595
+ GroupedElGamal :: encrypt_with ( [ destination_pubkey, auditor_pubkey] , amount, & opening) ;
587
596
588
597
let success_proof_data = GroupedCiphertext2HandlesValidityProofData :: new (
589
- & destination_pubkey,
590
- & auditor_pubkey,
598
+ destination_pubkey,
599
+ auditor_pubkey,
591
600
& grouped_ciphertext,
592
601
amount,
593
602
& opening,
@@ -596,8 +605,8 @@ async fn test_grouped_ciphertext_2_handles_validity() {
596
605
597
606
let incorrect_opening = PedersenOpening :: new_rand ( ) ;
598
607
let fail_proof_data = GroupedCiphertext2HandlesValidityProofData :: new (
599
- & destination_pubkey,
600
- & auditor_pubkey,
608
+ destination_pubkey,
609
+ auditor_pubkey,
601
610
& grouped_ciphertext,
602
611
amount,
603
612
& incorrect_opening,
@@ -629,29 +638,26 @@ async fn test_grouped_ciphertext_2_handles_validity() {
629
638
630
639
#[ tokio:: test]
631
640
async fn test_batched_grouped_ciphertext_2_handles_validity ( ) {
632
- let destination_pubkey = ElGamalKeypair :: new_rand ( ) . public ;
633
- let auditor_pubkey = ElGamalKeypair :: new_rand ( ) . public ;
641
+ let destination_keypair = ElGamalKeypair :: new_rand ( ) ;
642
+ let destination_pubkey = destination_keypair. pubkey ( ) ;
643
+
644
+ let auditor_keypair = ElGamalKeypair :: new_rand ( ) ;
645
+ let auditor_pubkey = auditor_keypair. pubkey ( ) ;
634
646
635
647
let amount_lo: u64 = 55 ;
636
648
let amount_hi: u64 = 22 ;
637
649
638
650
let opening_lo = PedersenOpening :: new_rand ( ) ;
639
651
let opening_hi = PedersenOpening :: new_rand ( ) ;
640
652
641
- let grouped_ciphertext_lo = GroupedElGamal :: encrypt_with (
642
- [ & destination_pubkey, & auditor_pubkey] ,
643
- amount_lo,
644
- & opening_lo,
645
- ) ;
646
- let grouped_ciphertext_hi = GroupedElGamal :: encrypt_with (
647
- [ & destination_pubkey, & auditor_pubkey] ,
648
- amount_hi,
649
- & opening_hi,
650
- ) ;
653
+ let grouped_ciphertext_lo =
654
+ GroupedElGamal :: encrypt_with ( [ destination_pubkey, auditor_pubkey] , amount_lo, & opening_lo) ;
655
+ let grouped_ciphertext_hi =
656
+ GroupedElGamal :: encrypt_with ( [ destination_pubkey, auditor_pubkey] , amount_hi, & opening_hi) ;
651
657
652
658
let success_proof_data = BatchedGroupedCiphertext2HandlesValidityProofData :: new (
653
- & destination_pubkey,
654
- & auditor_pubkey,
659
+ destination_pubkey,
660
+ auditor_pubkey,
655
661
& grouped_ciphertext_lo,
656
662
& grouped_ciphertext_hi,
657
663
amount_lo,
@@ -663,8 +669,8 @@ async fn test_batched_grouped_ciphertext_2_handles_validity() {
663
669
664
670
let incorrect_opening = PedersenOpening :: new_rand ( ) ;
665
671
let fail_proof_data = BatchedGroupedCiphertext2HandlesValidityProofData :: new (
666
- & destination_pubkey,
667
- & auditor_pubkey,
672
+ destination_pubkey,
673
+ auditor_pubkey,
668
674
& grouped_ciphertext_lo,
669
675
& grouped_ciphertext_hi,
670
676
amount_lo,
0 commit comments