@@ -348,6 +348,12 @@ pub enum ProofAccount {
348
348
RecordAccount ( Pubkey , u32 ) ,
349
349
}
350
350
351
+ pub struct ProofAccountWithCiphertext {
352
+ pub proof_account : ProofAccount ,
353
+ pub ciphertext_lo : PodElGamalCiphertext ,
354
+ pub ciphertext_hi : PodElGamalCiphertext ,
355
+ }
356
+
351
357
pub struct Token < T > {
352
358
client : Arc < dyn ProgramClient < T > > ,
353
359
pubkey : Pubkey , /* token mint */
@@ -2198,11 +2204,9 @@ where
2198
2204
destination_account : & Pubkey ,
2199
2205
source_authority : & Pubkey ,
2200
2206
equality_proof_account : Option < & ProofAccount > ,
2201
- ciphertext_validity_proof_account : Option < & ProofAccount > ,
2207
+ ciphertext_validity_proof_account_with_ciphertext : Option < & ProofAccountWithCiphertext > ,
2202
2208
range_proof_account : Option < & ProofAccount > ,
2203
2209
transfer_amount : u64 ,
2204
- transfer_amount_auditor_ciphertext_lo : Option < & PodElGamalCiphertext > ,
2205
- transfer_amount_auditor_ciphertext_hi : Option < & PodElGamalCiphertext > ,
2206
2210
account_info : Option < TransferAccountInfo > ,
2207
2211
source_elgamal_keypair : & ElGamalKeypair ,
2208
2212
source_aes_key : & AeKey ,
@@ -2222,71 +2226,63 @@ where
2222
2226
TransferAccountInfo :: new ( confidential_transfer_account)
2223
2227
} ;
2224
2228
2225
- let ( equality_proof_data, ciphertext_validity_proof_data, range_proof_data) = if [
2226
- equality_proof_account,
2227
- ciphertext_validity_proof_account,
2228
- range_proof_account,
2229
- ]
2230
- . iter ( )
2231
- . all ( |proof_account| proof_account. is_some ( ) )
2232
- {
2233
- ( None , None , None )
2234
- } else {
2235
- let TransferProofData {
2236
- equality_proof_data,
2237
- ciphertext_validity_proof_data,
2238
- range_proof_data,
2239
- } = account_info
2240
- . generate_split_transfer_proof_data (
2241
- transfer_amount,
2242
- source_elgamal_keypair,
2243
- source_aes_key,
2244
- destination_elgamal_pubkey,
2245
- auditor_elgamal_pubkey,
2246
- )
2247
- . map_err ( |_| TokenError :: ProofGeneration ) ?;
2229
+ let ( equality_proof_data, ciphertext_validity_proof_data_with_ciphertext, range_proof_data) =
2230
+ if equality_proof_account. is_some ( )
2231
+ && ciphertext_validity_proof_account_with_ciphertext. is_some ( )
2232
+ && range_proof_account. is_some ( )
2233
+ {
2234
+ ( None , None , None )
2235
+ } else {
2236
+ let TransferProofData {
2237
+ equality_proof_data,
2238
+ ciphertext_validity_proof_data_with_ciphertext,
2239
+ range_proof_data,
2240
+ } = account_info
2241
+ . generate_split_transfer_proof_data (
2242
+ transfer_amount,
2243
+ source_elgamal_keypair,
2244
+ source_aes_key,
2245
+ destination_elgamal_pubkey,
2246
+ auditor_elgamal_pubkey,
2247
+ )
2248
+ . map_err ( |_| TokenError :: ProofGeneration ) ?;
2248
2249
2249
- // if proof accounts are none, then proof data must be included as instruction
2250
- // data
2251
- let equality_proof_data = equality_proof_account
2252
- . is_none ( )
2253
- . then_some ( equality_proof_data) ;
2254
- let ciphertext_validity_proof_data = ciphertext_validity_proof_account
2255
- . is_none ( )
2256
- . then_some ( ciphertext_validity_proof_data) ;
2257
- let range_proof_data = range_proof_account. is_none ( ) . then_some ( range_proof_data) ;
2250
+ // if proof accounts are none, then proof data must be included as instruction
2251
+ // data
2252
+ let equality_proof_data = equality_proof_account
2253
+ . is_none ( )
2254
+ . then_some ( equality_proof_data) ;
2255
+ let ciphertext_validity_proof_data_with_ciphertext =
2256
+ ciphertext_validity_proof_account_with_ciphertext
2257
+ . is_none ( )
2258
+ . then_some ( ciphertext_validity_proof_data_with_ciphertext) ;
2259
+ let range_proof_data = range_proof_account. is_none ( ) . then_some ( range_proof_data) ;
2258
2260
2259
- (
2260
- equality_proof_data,
2261
- ciphertext_validity_proof_data ,
2262
- range_proof_data,
2263
- )
2264
- } ;
2261
+ (
2262
+ equality_proof_data,
2263
+ ciphertext_validity_proof_data_with_ciphertext ,
2264
+ range_proof_data,
2265
+ )
2266
+ } ;
2265
2267
2266
2268
let ( transfer_amount_auditor_ciphertext_lo, transfer_amount_auditor_ciphertext_hi) =
2267
- if let Some ( proof_data) = ciphertext_validity_proof_data {
2268
- let transfer_amount_auditor_ciphertext_lo = proof_data
2269
- . context_data ( )
2270
- . grouped_ciphertext_lo
2271
- . try_extract_ciphertext ( 2 )
2272
- . map_err ( |_| TokenError :: ProofGeneration ) ?;
2273
- let transfer_amount_auditor_ciphertext_hi = proof_data
2274
- . context_data ( )
2275
- . grouped_ciphertext_hi
2276
- . try_extract_ciphertext ( 2 )
2277
- . map_err ( |_| TokenError :: ProofGeneration ) ?;
2269
+ if let Some ( proof_data_with_ciphertext) = ciphertext_validity_proof_data_with_ciphertext
2270
+ {
2278
2271
(
2279
- transfer_amount_auditor_ciphertext_lo ,
2280
- transfer_amount_auditor_ciphertext_hi ,
2272
+ proof_data_with_ciphertext . ciphertext_lo ,
2273
+ proof_data_with_ciphertext . ciphertext_hi ,
2281
2274
)
2282
2275
} else {
2283
- // the validity proof data is always generated unless
2284
- // `transfer_amount_auditor_ciphertext_lo` and
2285
- // `transfer_amount_auditor_ciphertext_hi` are `Some`, so it is
2286
- // safe to unwrap
2276
+ // unwrap is safe as long as either `proof_data_with_ciphertext`,
2277
+ // `proof_account_with_ciphertext` is `Some(..)`, which is guaranteed by the
2278
+ // previous check
2287
2279
(
2288
- * transfer_amount_auditor_ciphertext_lo. unwrap ( ) ,
2289
- * transfer_amount_auditor_ciphertext_hi. unwrap ( ) ,
2280
+ ciphertext_validity_proof_account_with_ciphertext
2281
+ . unwrap ( )
2282
+ . ciphertext_lo ,
2283
+ ciphertext_validity_proof_account_with_ciphertext
2284
+ . unwrap ( )
2285
+ . ciphertext_hi ,
2290
2286
)
2291
2287
} ;
2292
2288
@@ -2298,9 +2294,11 @@ where
2298
2294
1 ,
2299
2295
)
2300
2296
. unwrap ( ) ;
2297
+ let ciphertext_validity_proof_data =
2298
+ ciphertext_validity_proof_data_with_ciphertext. map ( |data| data. proof_data ) ;
2301
2299
let ciphertext_validity_proof_location = Self :: confidential_transfer_create_proof_location (
2302
2300
ciphertext_validity_proof_data. as_ref ( ) ,
2303
- ciphertext_validity_proof_account ,
2301
+ ciphertext_validity_proof_account_with_ciphertext . map ( |account| & account . proof_account ) ,
2304
2302
2 ,
2305
2303
)
2306
2304
. unwrap ( ) ;
@@ -2557,13 +2555,13 @@ where
2557
2555
destination_account : & Pubkey ,
2558
2556
source_authority : & Pubkey ,
2559
2557
equality_proof_account : Option < & ProofAccount > ,
2560
- transfer_amount_ciphertext_validity_proof_account : Option < & ProofAccount > ,
2558
+ transfer_amount_ciphertext_validity_proof_account_with_ciphertext : Option <
2559
+ & ProofAccountWithCiphertext ,
2560
+ > ,
2561
2561
percentage_with_cap_proof_account : Option < & ProofAccount > ,
2562
2562
fee_ciphertext_validity_proof_account : Option < & ProofAccount > ,
2563
2563
range_proof_account : Option < & ProofAccount > ,
2564
2564
transfer_amount : u64 ,
2565
- transfer_amount_auditor_ciphertext_lo : Option < & PodElGamalCiphertext > ,
2566
- transfer_amount_auditor_ciphertext_hi : Option < & PodElGamalCiphertext > ,
2567
2565
account_info : Option < TransferAccountInfo > ,
2568
2566
source_elgamal_keypair : & ElGamalKeypair ,
2569
2567
source_aes_key : & AeKey ,
@@ -2588,26 +2586,22 @@ where
2588
2586
2589
2587
let (
2590
2588
equality_proof_data,
2591
- transfer_amount_ciphertext_validity_proof_data ,
2589
+ transfer_amount_ciphertext_validity_proof_data_with_ciphertext ,
2592
2590
percentage_with_cap_proof_data,
2593
2591
fee_ciphertext_validity_proof_data,
2594
2592
range_proof_data,
2595
- ) = if [
2596
- equality_proof_account,
2597
- transfer_amount_ciphertext_validity_proof_account,
2598
- percentage_with_cap_proof_account,
2599
- fee_ciphertext_validity_proof_account,
2600
- range_proof_account,
2601
- ]
2602
- . iter ( )
2603
- . all ( |proof_account| proof_account. is_some ( ) )
2593
+ ) = if equality_proof_account. is_some ( )
2594
+ && transfer_amount_ciphertext_validity_proof_account_with_ciphertext. is_some ( )
2595
+ && percentage_with_cap_proof_account. is_some ( )
2596
+ && fee_ciphertext_validity_proof_account. is_some ( )
2597
+ && range_proof_account. is_some ( )
2604
2598
{
2605
2599
// is all proofs come from accounts, then skip proof generation
2606
2600
( None , None , None , None , None )
2607
2601
} else {
2608
2602
let TransferWithFeeProofData {
2609
2603
equality_proof_data,
2610
- transfer_amount_ciphertext_validity_proof_data ,
2604
+ transfer_amount_ciphertext_validity_proof_data_with_ciphertext ,
2611
2605
percentage_with_cap_proof_data,
2612
2606
fee_ciphertext_validity_proof_data,
2613
2607
range_proof_data,
@@ -2627,10 +2621,10 @@ where
2627
2621
let equality_proof_data = equality_proof_account
2628
2622
. is_none ( )
2629
2623
. then_some ( equality_proof_data) ;
2630
- let transfer_amount_ciphertext_validity_proof_data =
2631
- transfer_amount_ciphertext_validity_proof_account
2624
+ let transfer_amount_ciphertext_validity_proof_data_with_ciphertext =
2625
+ transfer_amount_ciphertext_validity_proof_account_with_ciphertext
2632
2626
. is_none ( )
2633
- . then_some ( transfer_amount_ciphertext_validity_proof_data ) ;
2627
+ . then_some ( transfer_amount_ciphertext_validity_proof_data_with_ciphertext ) ;
2634
2628
let percentage_with_cap_proof_data = percentage_with_cap_proof_account
2635
2629
. is_none ( )
2636
2630
. then_some ( percentage_with_cap_proof_data) ;
@@ -2641,37 +2635,32 @@ where
2641
2635
2642
2636
(
2643
2637
equality_proof_data,
2644
- transfer_amount_ciphertext_validity_proof_data ,
2638
+ transfer_amount_ciphertext_validity_proof_data_with_ciphertext ,
2645
2639
percentage_with_cap_proof_data,
2646
2640
fee_ciphertext_validity_proof_data,
2647
2641
range_proof_data,
2648
2642
)
2649
2643
} ;
2650
2644
2651
2645
let ( transfer_amount_auditor_ciphertext_lo, transfer_amount_auditor_ciphertext_hi) =
2652
- if let Some ( proof_data) = transfer_amount_ciphertext_validity_proof_data {
2653
- let transfer_amount_auditor_ciphertext_lo = proof_data
2654
- . context_data ( )
2655
- . grouped_ciphertext_lo
2656
- . try_extract_ciphertext ( 2 )
2657
- . map_err ( |_| TokenError :: ProofGeneration ) ?;
2658
- let transfer_amount_auditor_ciphertext_hi = proof_data
2659
- . context_data ( )
2660
- . grouped_ciphertext_hi
2661
- . try_extract_ciphertext ( 2 )
2662
- . map_err ( |_| TokenError :: ProofGeneration ) ?;
2646
+ if let Some ( proof_data_with_ciphertext) =
2647
+ transfer_amount_ciphertext_validity_proof_data_with_ciphertext
2648
+ {
2663
2649
(
2664
- transfer_amount_auditor_ciphertext_lo ,
2665
- transfer_amount_auditor_ciphertext_hi ,
2650
+ proof_data_with_ciphertext . ciphertext_lo ,
2651
+ proof_data_with_ciphertext . ciphertext_hi ,
2666
2652
)
2667
2653
} else {
2668
- // the validity proof data is always generated unless
2669
- // `transfer_amount_auditor_ciphertext_lo` and
2670
- // `transfer_amount_auditor_ciphertext_hi` are `Some`, so it is
2671
- // safe to unwrap
2654
+ // unwrap is safe as long as either `proof_data_with_ciphertext`,
2655
+ // `proof_account_with_ciphertext` is `Some(..)`, which is guaranteed by the
2656
+ // previous check
2672
2657
(
2673
- * transfer_amount_auditor_ciphertext_lo. unwrap ( ) ,
2674
- * transfer_amount_auditor_ciphertext_hi. unwrap ( ) ,
2658
+ transfer_amount_ciphertext_validity_proof_account_with_ciphertext
2659
+ . unwrap ( )
2660
+ . ciphertext_lo ,
2661
+ transfer_amount_ciphertext_validity_proof_account_with_ciphertext
2662
+ . unwrap ( )
2663
+ . ciphertext_hi ,
2675
2664
)
2676
2665
} ;
2677
2666
@@ -2683,10 +2672,14 @@ where
2683
2672
1 ,
2684
2673
)
2685
2674
. unwrap ( ) ;
2675
+ let transfer_amount_ciphertext_validity_proof_data =
2676
+ transfer_amount_ciphertext_validity_proof_data_with_ciphertext
2677
+ . map ( |data| data. proof_data ) ;
2686
2678
let transfer_amount_ciphertext_validity_proof_location =
2687
2679
Self :: confidential_transfer_create_proof_location (
2688
2680
transfer_amount_ciphertext_validity_proof_data. as_ref ( ) ,
2689
- transfer_amount_ciphertext_validity_proof_account,
2681
+ transfer_amount_ciphertext_validity_proof_account_with_ciphertext
2682
+ . map ( |account| & account. proof_account ) ,
2690
2683
2 ,
2691
2684
)
2692
2685
. unwrap ( ) ;
0 commit comments