@@ -3906,6 +3906,7 @@ pub fn create_proof<C: ProofConstants, F: FieldWitness>(
3906
3906
proof
3907
3907
}
3908
3908
3909
+ #[ derive( Clone ) ]
3909
3910
pub struct Prover < F : FieldWitness > {
3910
3911
/// Constants to each kind of proof
3911
3912
pub internal_vars : InternalVars < F > ,
@@ -4048,6 +4049,7 @@ mod tests {
4048
4049
self ,
4049
4050
macros:: { BinProtRead , BinProtWrite } ,
4050
4051
} ;
4052
+ use once_cell:: sync:: Lazy ;
4051
4053
4052
4054
use crate :: {
4053
4055
proofs:: {
@@ -4285,11 +4287,14 @@ mod tests {
4285
4287
4286
4288
fn read_gates ( ) -> Gates {
4287
4289
let base_dir = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
4290
+ let base_dir = base_dir. join ( "rampup4" ) ;
4288
4291
4289
- fn read_gates_file < F : FieldWitness > ( filepath : & impl AsRef < Path > ) -> Vec < CircuitGate < F > > {
4290
- let file = std:: fs:: File :: open ( filepath) . unwrap ( ) ;
4292
+ fn read_gates_file < F : FieldWitness > (
4293
+ filepath : & impl AsRef < Path > ,
4294
+ ) -> std:: io:: Result < Vec < CircuitGate < F > > > {
4295
+ let file = std:: fs:: File :: open ( filepath) ?;
4291
4296
let reader = std:: io:: BufReader :: new ( file) ;
4292
- serde_json:: from_reader ( reader) . unwrap ( )
4297
+ serde_json:: from_reader ( reader) . map_err ( Into :: into )
4293
4298
}
4294
4299
4295
4300
let internal_vars_path = base_dir. join ( "internal_vars_rampup4.bin" ) ;
@@ -4302,63 +4307,55 @@ mod tests {
4302
4307
let ( internal_vars_wrap, rows_rev_wrap) =
4303
4308
read_constraints_data :: < Fq > ( & internal_vars_path, & rows_rev_path) . unwrap ( ) ;
4304
4309
4305
- let internal_vars_path = base_dir. join ( "rampup4" ) . join ( " merge_internal_vars.bin") ;
4306
- let rows_rev_path = base_dir. join ( "rampup4" ) . join ( " merge_rows_rev.bin") ;
4310
+ let internal_vars_path = base_dir. join ( "merge_internal_vars.bin" ) ;
4311
+ let rows_rev_path = base_dir. join ( "merge_rows_rev.bin" ) ;
4307
4312
let ( merge_internal_vars, merge_rows_rev) =
4308
4313
read_constraints_data :: < Fp > ( & internal_vars_path, & rows_rev_path) . unwrap ( ) ;
4309
4314
4310
- let internal_vars_path = base_dir. join ( "rampup4" ) . join ( " block_internal_vars.bin") ;
4311
- let rows_rev_path = base_dir. join ( "rampup4" ) . join ( " block_rows_rev.bin") ;
4315
+ let internal_vars_path = base_dir. join ( "block_internal_vars.bin" ) ;
4316
+ let rows_rev_path = base_dir. join ( "block_rows_rev.bin" ) ;
4312
4317
let ( block_internal_vars, block_rows_rev) =
4313
4318
read_constraints_data :: < Fp > ( & internal_vars_path, & rows_rev_path) . unwrap ( ) ;
4314
4319
4315
- let internal_vars_path = base_dir
4316
- . join ( "rampup4" )
4317
- . join ( "block_wrap_internal_vars.bin" ) ;
4318
- let rows_rev_path = base_dir. join ( "rampup4" ) . join ( "block_wrap_rows_rev.bin" ) ;
4320
+ let internal_vars_path = base_dir. join ( "block_wrap_internal_vars.bin" ) ;
4321
+ let rows_rev_path = base_dir. join ( "block_wrap_rows_rev.bin" ) ;
4319
4322
let ( block_wrap_internal_vars, block_wrap_rows_rev) =
4320
4323
read_constraints_data :: < Fq > ( & internal_vars_path, & rows_rev_path) . unwrap ( ) ;
4321
4324
4322
- let internal_vars_path = base_dir
4323
- . join ( "rampup4" )
4324
- . join ( "zkapp_step_internal_vars.bin" ) ;
4325
- let rows_rev_path = base_dir. join ( "rampup4" ) . join ( "zkapp_step_rows_rev.bin" ) ;
4325
+ let internal_vars_path = base_dir. join ( "zkapp_step_internal_vars.bin" ) ;
4326
+ let rows_rev_path = base_dir. join ( "zkapp_step_rows_rev.bin" ) ;
4326
4327
let (
4327
4328
zkapp_step_opt_signed_opt_signed_internal_vars,
4328
4329
zkapp_step_opt_signed_opt_signed_rows_rev,
4329
4330
) = read_constraints_data :: < Fp > ( & internal_vars_path, & rows_rev_path) . unwrap ( ) ;
4330
4331
4331
- let internal_vars_path = base_dir
4332
- . join ( "rampup4" )
4333
- . join ( "zkapp_step_opt_signed_internal_vars.bin" ) ;
4334
- let rows_rev_path = base_dir
4335
- . join ( "rampup4" )
4336
- . join ( "zkapp_step_opt_signed_rows_rev.bin" ) ;
4332
+ let internal_vars_path = base_dir. join ( "zkapp_step_opt_signed_internal_vars.bin" ) ;
4333
+ let rows_rev_path = base_dir. join ( "zkapp_step_opt_signed_rows_rev.bin" ) ;
4337
4334
let ( zkapp_step_opt_signed_internal_vars, zkapp_step_opt_signed_rows_rev) =
4338
4335
read_constraints_data :: < Fp > ( & internal_vars_path, & rows_rev_path) . unwrap ( ) ;
4339
4336
4340
4337
let gates: Vec < CircuitGate < Fp > > =
4341
- read_gates_file ( & base_dir. join ( "gates_step_rampup4.json" ) ) ;
4338
+ read_gates_file ( & base_dir. join ( "gates_step_rampup4.json" ) ) . unwrap ( ) ;
4342
4339
let wrap_gates: Vec < CircuitGate < Fq > > =
4343
- read_gates_file ( & base_dir. join ( "gates_wrap_rampup4.json" ) ) ;
4340
+ read_gates_file ( & base_dir. join ( "gates_wrap_rampup4.json" ) ) . unwrap ( ) ;
4344
4341
let merge_gates: Vec < CircuitGate < Fp > > =
4345
- read_gates_file ( & base_dir. join ( "gates_merge_rampup4.json" ) ) ;
4342
+ read_gates_file ( & base_dir. join ( "gates_merge_rampup4.json" ) ) . unwrap ( ) ;
4346
4343
4347
- let base_dir = base_dir . join ( "rampup4" ) ;
4348
- let block_gates : Vec < CircuitGate < Fp > > = read_gates_file ( & base_dir. join ( "block_gates.json" ) ) ;
4344
+ let block_gates : Vec < CircuitGate < Fp > > =
4345
+ read_gates_file ( & base_dir. join ( "block_gates.json" ) ) . unwrap ( ) ;
4349
4346
let block_wrap_gates: Vec < CircuitGate < Fq > > =
4350
- read_gates_file ( & base_dir. join ( "block_wrap_gates.json" ) ) ;
4347
+ read_gates_file ( & base_dir. join ( "block_wrap_gates.json" ) ) . unwrap ( ) ;
4351
4348
let zkapp_step_opt_signed_opt_signed_gates: Vec < CircuitGate < Fp > > =
4352
- read_gates_file ( & base_dir. join ( "zkapp_step_gates.json" ) ) ;
4349
+ read_gates_file ( & base_dir. join ( "zkapp_step_gates.json" ) ) . unwrap ( ) ;
4353
4350
let zkapp_step_opt_signed_gates: Vec < CircuitGate < Fp > > =
4354
- read_gates_file ( & base_dir. join ( "zkapp_step_opt_signed_gates.json" ) ) ;
4351
+ read_gates_file ( & base_dir. join ( "zkapp_step_opt_signed_gates.json" ) ) . unwrap ( ) ;
4355
4352
4356
4353
let internal_vars_path = base_dir. join ( "zkapp_step_proof_internal_vars.bin" ) ;
4357
4354
let rows_rev_path = base_dir. join ( "zkapp_step_proof_rows_rev.bin" ) ;
4358
4355
let ( zkapp_step_proof_internal_vars, zkapp_step_proof_rows_rev) =
4359
4356
read_constraints_data :: < Fp > ( & internal_vars_path, & rows_rev_path) . unwrap ( ) ;
4360
4357
let zkapp_step_proof_gates: Vec < CircuitGate < Fp > > =
4361
- read_gates_file ( & base_dir. join ( "zkapp_step_proof_gates.json" ) ) ;
4358
+ read_gates_file ( & base_dir. join ( "zkapp_step_proof_gates.json" ) ) . unwrap ( ) ;
4362
4359
4363
4360
Gates {
4364
4361
gates,
@@ -4388,6 +4385,9 @@ mod tests {
4388
4385
}
4389
4386
}
4390
4387
4388
+ static PROVERS : Lazy < Arc < Provers > > = Lazy :: new ( || Arc :: new ( make_provers ( ) ) ) ;
4389
+
4390
+ #[ derive( Clone ) ]
4391
4391
struct Provers {
4392
4392
tx_step_prover : Prover < Fp > ,
4393
4393
tx_wrap_prover : Prover < Fq > ,
@@ -4399,6 +4399,11 @@ mod tests {
4399
4399
zkapp_step_proof_prover : Prover < Fp > ,
4400
4400
}
4401
4401
4402
+ fn get_provers ( ) -> Provers {
4403
+ ( & * * PROVERS ) . clone ( )
4404
+ }
4405
+
4406
+ /// Slow, use `get_provers` instead
4402
4407
fn make_provers ( ) -> Provers {
4403
4408
let Gates {
4404
4409
gates,
@@ -4426,6 +4431,7 @@ mod tests {
4426
4431
zkapp_step_proof_internal_vars,
4427
4432
zkapp_step_proof_rows_rev,
4428
4433
} = read_gates ( ) ;
4434
+
4429
4435
let tx_prover_index = make_prover_index :: < StepTransactionProof , _ > ( gates) ;
4430
4436
let merge_prover_index = make_prover_index :: < StepMergeProof , _ > ( merge_gates) ;
4431
4437
let wrap_prover_index = make_prover_index :: < WrapTransactionProof , _ > ( wrap_gates) ;
@@ -4512,7 +4518,8 @@ mod tests {
4512
4518
zkapp_step_opt_signed_opt_signed_prover,
4513
4519
zkapp_step_opt_signed_prover,
4514
4520
zkapp_step_proof_prover,
4515
- } = make_provers ( ) ;
4521
+ } = get_provers ( ) ;
4522
+
4516
4523
let v = & tx_wrap_prover. index . verifier_index . as_ref ( ) . unwrap ( ) ;
4517
4524
let v_json = serde_json:: to_string ( & v) . unwrap ( ) ;
4518
4525
// std::fs::write("/tmp/tx.json", &v_json).unwrap();
@@ -4555,14 +4562,14 @@ mod tests {
4555
4562
zkapp_step_opt_signed_opt_signed_prover : _,
4556
4563
zkapp_step_opt_signed_prover : _,
4557
4564
zkapp_step_proof_prover : _,
4558
- } = make_provers ( ) ;
4565
+ } = get_provers ( ) ;
4559
4566
4560
4567
let mut witnesses: Witness < Fp > = Witness :: new :: < StepTransactionProof > ( ) ;
4561
4568
4562
4569
fn read_witnesses ( filename : & str ) -> Vec < Fp > {
4563
4570
let f = std:: fs:: read_to_string (
4564
4571
std:: path:: Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) )
4565
- // .join("rampup4")
4572
+ . join ( "rampup4" )
4566
4573
. join ( filename) ,
4567
4574
)
4568
4575
. unwrap ( ) ;
@@ -4617,7 +4624,7 @@ mod tests {
4617
4624
zkapp_step_opt_signed_opt_signed_prover : _,
4618
4625
zkapp_step_opt_signed_prover : _,
4619
4626
zkapp_step_proof_prover : _,
4620
- } = make_provers ( ) ;
4627
+ } = get_provers ( ) ;
4621
4628
4622
4629
let mut witnesses: Witness < Fp > = Witness :: new :: < StepMergeProof > ( ) ;
4623
4630
witnesses. ocaml_aux = crate :: proofs:: merge:: read_witnesses ( ) . unwrap ( ) ;
@@ -4667,7 +4674,7 @@ mod tests {
4667
4674
zkapp_step_opt_signed_opt_signed_prover,
4668
4675
zkapp_step_opt_signed_prover,
4669
4676
zkapp_step_proof_prover,
4670
- } = make_provers ( ) ;
4677
+ } = get_provers ( ) ;
4671
4678
4672
4679
let LedgerProof { proof, .. } = generate_zkapp_proof ( ZkappParams {
4673
4680
statement : & statement,
@@ -4713,7 +4720,7 @@ mod tests {
4713
4720
zkapp_step_opt_signed_opt_signed_prover,
4714
4721
zkapp_step_opt_signed_prover,
4715
4722
zkapp_step_proof_prover,
4716
- } = make_provers ( ) ;
4723
+ } = get_provers ( ) ;
4717
4724
4718
4725
let LedgerProof { proof, .. } = generate_zkapp_proof ( ZkappParams {
4719
4726
statement : & statement,
@@ -4775,7 +4782,7 @@ mod tests {
4775
4782
zkapp_step_opt_signed_opt_signed_prover : _,
4776
4783
zkapp_step_opt_signed_prover : _,
4777
4784
zkapp_step_proof_prover : _,
4778
- } = make_provers ( ) ;
4785
+ } = get_provers ( ) ;
4779
4786
let mut witnesses: Witness < Fp > = Witness :: new :: < StepBlockProof > ( ) ;
4780
4787
4781
4788
let WrapProof { proof, .. } = generate_block_proof (
@@ -4805,6 +4812,11 @@ mod tests {
4805
4812
fn test_proofs ( ) {
4806
4813
let base_dir = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( "rampup4" ) ;
4807
4814
4815
+ if !base_dir. exists ( ) {
4816
+ eprintln ! ( "{:?} not found" , base_dir) ;
4817
+ return ;
4818
+ }
4819
+
4808
4820
let Provers {
4809
4821
tx_step_prover,
4810
4822
tx_wrap_prover,
@@ -4814,7 +4826,7 @@ mod tests {
4814
4826
zkapp_step_opt_signed_opt_signed_prover,
4815
4827
zkapp_step_opt_signed_prover,
4816
4828
zkapp_step_proof_prover,
4817
- } = make_provers ( ) ;
4829
+ } = get_provers ( ) ;
4818
4830
4819
4831
#[ rustfmt:: skip]
4820
4832
let zkapp_cases = [
@@ -4913,11 +4925,6 @@ mod tests {
4913
4925
) ;
4914
4926
}
4915
4927
4916
- if !base_dir. exists ( ) {
4917
- eprintln ! ( "{:?} not found" , base_dir) ;
4918
- return ;
4919
- }
4920
-
4921
4928
// Same values than OCaml
4922
4929
#[ rustfmt:: skip]
4923
4930
let requests = [
@@ -4942,7 +4949,7 @@ mod tests {
4942
4949
// ("fee_transfer_6_rampup4.bin", "6b95aa737e1c8351bbb7a141108a73c808cb92aae9e266ecce13f679d6f6b2df"),
4943
4950
// ("fee_transfer_7_rampup4.bin", "5d97141c3adf576503381e485f5ab20ed856448880658a0a56fb23567225875c"),
4944
4951
// ("fee_transfer_8_rampup4.bin", "e1fa6b5a88b184428a0918cd4bd56952b54f05a5dc175b17e154204533167a78"),
4945
- ( "fee_transfer_9_rampup4.bin" , "087a07eddedf5de18b2f2bd7ded3cd474d00a0030e9c13d7a5fd2433c72fc7d5" ) ,
4952
+ // ("fee_transfer_9_rampup4.bin", "087a07eddedf5de18b2f2bd7ded3cd474d00a0030e9c13d7a5fd2433c72fc7d5"),
4946
4953
] ;
4947
4954
4948
4955
fn read_witnesses ( filename : & str ) -> Vec < Fp > {
0 commit comments