@@ -34,14 +34,14 @@ use circuit_definitions::circuit_definitions::aux_layer::compression::{
3434
3535use fflonk:: bellman:: plonk:: better_better_cs:: cs:: Circuit ;
3636use fflonk:: fflonk:: L1_VERIFIER_DOMAIN_SIZE_LOG ;
37- use fflonk:: { init_compact_crs , CombinedMonomialDeviceStorage , DeviceContextWithSingleDevice } ;
37+ use fflonk:: { CombinedMonomialDeviceStorage , DeviceContextWithSingleDevice } ;
3838use gpu_prover:: { DeviceMemoryManager , ManagerConfigs } ;
3939use shivini:: gpu_proof_config:: GpuProofConfig ;
40- use shivini:: { cs:: GpuSetup , GpuTreeHasher , ProverContext } ;
4140use shivini:: {
4241 CacheStrategy , CommitmentCacheStrategy , GPUPoWRunner , PolynomialsCacheStrategy ,
4342 ProverContextConfig ,
4443} ;
44+ use shivini:: { GpuTreeHasher , ProverContext } ;
4545pub trait ProofSystemDefinition : Sized {
4646 type FieldElement ;
4747 type ExternalWitnessData ;
@@ -160,7 +160,7 @@ where
160160{
161161 type FieldElement = GoldilocksField ;
162162 type ExternalWitnessData = WitnessVec < Self :: FieldElement , Self :: Allocator > ;
163- type Precomputation = GpuSetup < CF :: ThisLayerHasher > ;
163+ type Precomputation = BoojumDeviceSetupWrapper < CF :: ThisLayerHasher > ;
164164 type Proof = Proof < Self :: FieldElement , CF :: ThisLayerHasher , GoldilocksExt2 > ;
165165 type VK = VerificationKey < Self :: FieldElement , CF :: ThisLayerHasher > ;
166166 type FinalizationHint = FinalizationHintsForProver ;
@@ -277,7 +277,7 @@ where
277277 commitment : CommitmentCacheStrategy :: CacheCosetCaps ,
278278 } ;
279279 let worker = Worker :: new ( ) ;
280- let precomputation = precomputation. wait ( ) ;
280+ let precomputation = precomputation. wait ( ) . into_inner ( ) ;
281281 let ctx = ctx. wait ( ) ;
282282 let gpu_proof = shivini:: gpu_prove_from_external_witness_data_with_cache_strategy :: <
283283 CF :: ThisLayerTranscript ,
@@ -338,7 +338,7 @@ where
338338 > ( setup_base, vk_params, vars_hint, wits_hint, & worker)
339339 . unwrap ( ) ;
340340 drop ( ctx) ;
341- ( precomputation, vk)
341+ ( BoojumDeviceSetupWrapper :: from_inner ( precomputation) , vk)
342342 }
343343 fn synthesize_for_setup (
344344 circuit : CompressionLayerCircuit < Self > ,
@@ -406,7 +406,11 @@ impl ProofSystemDefinition for PlonkSnarkWrapper {
406406}
407407
408408impl SnarkWrapperProofSystem for PlonkSnarkWrapper {
409- type CRS = bellman:: kate_commitment:: Crs < bellman:: compact_bn256:: Bn256 , CrsForMonomialForm > ;
409+ type CRS = bellman:: kate_commitment:: Crs <
410+ bellman:: compact_bn256:: Bn256 ,
411+ CrsForMonomialForm ,
412+ Self :: Allocator ,
413+ > ;
410414 type Circuit = PlonkSnarkVerifierCircuit ;
411415 type ContextConfig = ( Vec < usize > , Vec < CompactG1Affine > ) ;
412416 type Context = UnsafePlonkProverDeviceMemoryManagerWrapper ;
@@ -508,18 +512,21 @@ impl ProofSystemDefinition for FflonkSnarkWrapper {
508512}
509513
510514impl SnarkWrapperProofSystem for FflonkSnarkWrapper {
511- type CRS = bellman:: kate_commitment:: Crs < bellman:: compact_bn256:: Bn256 , CrsForMonomialForm > ;
515+ type CRS = bellman:: kate_commitment:: Crs <
516+ bellman:: compact_bn256:: Bn256 ,
517+ CrsForMonomialForm ,
518+ Self :: Allocator ,
519+ > ;
512520 type Circuit = FflonkSnarkVerifierCircuit ;
513521 type ContextConfig = ( usize , Self :: CRS ) ;
514522 type Context = DeviceContextWithSingleDevice ;
515523
516524 fn load_crs ( domain_size : Self :: FinalizationHint ) -> Self :: CRS {
517- // let raw_compact_crs_file_path = std::env::var("FFLONK_COMPACT_RAW_CRS_FILE").unwrap();
518- // let raw_compact_crs_file = std::fs::File::open(raw_compact_crs_file_path).unwrap();
519- // let num_points = domain_size * fflonk::MAX_COMBINED_DEGREE_FACTOR;
520- // read_crs_from_raw_compact_form::<_, Self::Allocator>(raw_compact_crs_file, num_points)
521- // .unwrap()
522- init_compact_crs ( & bellman:: worker:: Worker :: new ( ) , domain_size)
525+ let raw_compact_crs_file_path = std:: env:: var ( "FFLONK_COMPACT_RAW_CRS_FILE" ) . unwrap ( ) ;
526+ let raw_compact_crs_file = std:: fs:: File :: open ( raw_compact_crs_file_path) . unwrap ( ) ;
527+ let num_points = domain_size * fflonk:: MAX_COMBINED_DEGREE_FACTOR ;
528+ read_crs_from_raw_compact_form :: < _ , Self :: Allocator > ( raw_compact_crs_file, num_points)
529+ . unwrap ( )
523530 }
524531
525532 fn get_context_config ( ) -> Self :: ContextConfig {
@@ -531,7 +538,6 @@ impl SnarkWrapperProofSystem for FflonkSnarkWrapper {
531538 fn init_context ( config : Self :: ContextConfig ) -> Self :: Context {
532539 let ( domain_size, crs) = config;
533540 let context = Self :: Context :: init_from_preloaded_crs ( domain_size, crs) . unwrap ( ) ;
534-
535541 context
536542 }
537543
@@ -624,7 +630,7 @@ impl SnarkWrapperProofSystemExt for FflonkSnarkWrapper {
624630 & raw_compact_crs_file_path
625631 ) ) ) ;
626632 let raw_compact_crs_file = std:: fs:: File :: create ( raw_compact_crs_file_path) . unwrap ( ) ;
627- write_crs_into_raw_compact_form ( original_crs, raw_compact_crs_file, num_points) . unwrap ( ) ;
633+ write_crs_into_raw_compact_form ( & original_crs, raw_compact_crs_file, num_points) . unwrap ( ) ;
628634 }
629635}
630636
@@ -649,7 +655,7 @@ impl ProofSystemDefinition for MarkerProofSystem {
649655}
650656
651657pub fn write_crs_into_raw_compact_form < W : std:: io:: Write > (
652- original_crs : Crs < bellman:: bn256:: Bn256 , CrsForMonomialForm > ,
658+ original_crs : & Crs < bellman:: bn256:: Bn256 , CrsForMonomialForm > ,
653659 mut dst_raw_compact_crs : W ,
654660 num_points : usize ,
655661) -> std:: io:: Result < ( ) > {
@@ -660,15 +666,16 @@ pub fn write_crs_into_raw_compact_form<W: std::io::Write>(
660666 dst_raw_compact_crs. write_u32 :: < BigEndian > ( num_points as u32 ) ?;
661667 for g1_base in original_crs. g1_bases . iter ( ) {
662668 let ( x, y) = g1_base. as_xy ( ) ;
663- x. into_raw_repr ( ) . write_be ( & mut dst_raw_compact_crs) ?;
664- y. into_raw_repr ( ) . write_be ( & mut dst_raw_compact_crs) ?;
669+ x. into_raw_repr ( ) . write_le ( & mut dst_raw_compact_crs) ?;
670+ y. into_raw_repr ( ) . write_le ( & mut dst_raw_compact_crs) ?;
665671 }
672+ assert_eq ! ( original_crs. g2_monomial_bases. len( ) , 2 ) ;
666673 for g2_base in original_crs. g2_monomial_bases . iter ( ) {
667674 let ( x, y) = g2_base. as_xy ( ) ;
668- x. c0 . into_raw_repr ( ) . write_be ( & mut dst_raw_compact_crs) ?;
669- x. c1 . into_raw_repr ( ) . write_be ( & mut dst_raw_compact_crs) ?;
670- y. c0 . into_raw_repr ( ) . write_be ( & mut dst_raw_compact_crs) ?;
671- y. c1 . into_raw_repr ( ) . write_be ( & mut dst_raw_compact_crs) ?;
675+ x. c0 . into_raw_repr ( ) . write_le ( & mut dst_raw_compact_crs) ?;
676+ x. c1 . into_raw_repr ( ) . write_le ( & mut dst_raw_compact_crs) ?;
677+ y. c0 . into_raw_repr ( ) . write_le ( & mut dst_raw_compact_crs) ?;
678+ y. c1 . into_raw_repr ( ) . write_le ( & mut dst_raw_compact_crs) ?;
672679 }
673680
674681 Ok ( ( ) )
@@ -677,28 +684,22 @@ pub fn write_crs_into_raw_compact_form<W: std::io::Write>(
677684// TODO: Crs doesn't allow bases located in a custom allocator
678685pub fn read_crs_from_raw_compact_form < R : std:: io:: Read , A : Allocator + Default > (
679686 mut src_raw_compact_crs : R ,
680- num_points : usize ,
681- ) -> std:: io:: Result < Crs < bellman:: compact_bn256:: Bn256 , CrsForMonomialForm > > {
682- println ! ( "Reading Raw compact CRS" ) ;
687+ num_g1_points : usize ,
688+ ) -> std:: io:: Result < Crs < bellman:: compact_bn256:: Bn256 , CrsForMonomialForm , A > > {
683689 use byteorder:: { BigEndian , ReadBytesExt } ;
684690 let actual_num_points = src_raw_compact_crs. read_u32 :: < BigEndian > ( ) ? as usize ;
685- assert ! ( num_points <= actual_num_points as usize ) ;
686- use bellman:: { PrimeField , PrimeFieldRepr } ;
687- // let mut g1_bases = Vec::with_capacity_in(num_points, A::default());
688- println ! ( "Reading G1 points" ) ;
689- let mut g1_bases = Vec :: with_capacity ( num_points) ;
691+ assert ! ( num_g1_points <= actual_num_points as usize ) ;
692+ let mut g1_bases = Vec :: with_capacity_in ( num_g1_points, A :: default ( ) ) ;
690693 unsafe {
691- g1_bases. set_len ( num_points ) ;
694+ g1_bases. set_len ( num_g1_points ) ;
692695 let buf = std:: slice:: from_raw_parts_mut (
693696 g1_bases. as_mut_ptr ( ) as * mut u8 ,
694- num_points * std:: mem:: size_of :: < bellman:: compact_bn256:: G1Affine > ( ) ,
697+ num_g1_points * std:: mem:: size_of :: < bellman:: compact_bn256:: G1Affine > ( ) ,
695698 ) ;
696699 src_raw_compact_crs. read_exact ( buf) ?;
697700 }
698701 let num_g2_points = 2 ;
699- // let mut g2_bases = Vec::with_capacity_in(num_g2_points, A::default());
700- println ! ( "Reading G2 points" ) ;
701- let mut g2_bases = Vec :: with_capacity ( num_g2_points) ;
702+ let mut g2_bases = Vec :: with_capacity_in ( num_g2_points, A :: default ( ) ) ;
702703 unsafe {
703704 g2_bases. set_len ( num_g2_points) ;
704705 let buf = std:: slice:: from_raw_parts_mut (
@@ -707,9 +708,5 @@ pub fn read_crs_from_raw_compact_form<R: std::io::Read, A: Allocator + Default>(
707708 ) ;
708709 src_raw_compact_crs. read_exact ( buf) ?;
709710 }
710- let mut compact_crs = Crs :: < _ , CrsForMonomialForm > :: dummy_crs ( 1 ) ;
711- compact_crs. g1_bases = std:: sync:: Arc :: new ( g1_bases) ;
712- compact_crs. g2_monomial_bases = std:: sync:: Arc :: new ( g2_bases) ;
713-
714- Ok ( compact_crs)
711+ Ok ( Crs :: < _ , CrsForMonomialForm , A > :: new_in ( g1_bases, g2_bases) )
715712}
0 commit comments