From 282f5dc9f5ab7287b3d739d36a5ff9dce3452ad0 Mon Sep 17 00:00:00 2001 From: olesHolem Date: Thu, 12 Oct 2023 03:19:51 +0300 Subject: [PATCH 1/7] done --- Cargo.toml | 6 ---- circuit_definitions/Cargo.toml | 5 ---- .../aux_layer/compression_modes/mod.rs | 6 ++-- .../src/circuit_definitions/aux_layer/mod.rs | 4 +-- circuit_definitions/src/lib.rs | 2 +- src/data_source/local_file_data_source.rs | 6 ++-- src/lib.rs | 4 +++ src/proof_wrapper_utils/mod.rs | 28 ++++++++--------- src/proof_wrapper_utils/wrapper.rs | 2 +- src/snark_wrapper_test/mod.rs | 30 +++++++++++-------- 10 files changed, 46 insertions(+), 47 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 293b358f..d3944154 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,12 +21,6 @@ resolver = "2" [dependencies] circuit_definitions = {path = "./circuit_definitions"} -snark_wrapper = {git = "https://github.com/matter-labs/snark-wrapper.git", branch = "main"} -rescue_poseidon = {git = "https://github.com/matter-labs/rescue-poseidon.git", branch = "poseidon2"} - -# snark_wrapper = {path = "../snark_wrapper"} -# rescue_poseidon = {path = "../rescue-poseidon"} - zkevm-assembly = {git = "https://github.com/matter-labs/era-zkEVM-assembly.git", branch = "v1.3.2"} rand = "0.4" diff --git a/circuit_definitions/Cargo.toml b/circuit_definitions/Cargo.toml index 39327bba..2543c23f 100644 --- a/circuit_definitions/Cargo.toml +++ b/circuit_definitions/Cargo.toml @@ -11,12 +11,7 @@ license = "MIT OR Apache-2.0" # zkevm_circuits = {path = "../../zkevm_circuits", features = ["verbose_circuits"]} snark_wrapper = {git = "https://github.com/matter-labs/snark-wrapper.git", branch = "main"} -franklin_crypto = {package = "franklin-crypto", features = ["plonk"], git = "https://github.com/matter-labs/franklin-crypto", branch = "snark_wrapper"} -rescue_poseidon = {git = "https://github.com/matter-labs/rescue-poseidon.git", branch = "poseidon2"} - # snark_wrapper = {path = "../../snark_wrapper"} -# franklin_crypto = {package = "franklin-crypto", features = ["plonk"], path = "../../franklin-crypto"} -# rescue_poseidon = {path = "../../rescue-poseidon"} zkevm_circuits = {git = "https://github.com/matter-labs/era-zkevm_circuits.git", branch = "main"} zk_evm = {git = "https://github.com/matter-labs/era-zk_evm.git", branch = "v1.4.0"} diff --git a/circuit_definitions/src/circuit_definitions/aux_layer/compression_modes/mod.rs b/circuit_definitions/src/circuit_definitions/aux_layer/compression_modes/mod.rs index b48478e1..a7294758 100644 --- a/circuit_definitions/src/circuit_definitions/aux_layer/compression_modes/mod.rs +++ b/circuit_definitions/src/circuit_definitions/aux_layer/compression_modes/mod.rs @@ -16,9 +16,9 @@ use crate::circuit_definitions::recursion_layer::scheduler::SchedulerCircuitBuil use crate::circuit_definitions::traits::circuit::ErasedBuilderForRecursiveVerifier; use crate::circuit_definitions::traits::gate::GatePlacementStrategy; -use franklin_crypto::bellman::pairing::bn256::{Bn256, Fr}; -use rescue_poseidon::poseidon2::transcript::Poseidon2Transcript; -use rescue_poseidon::poseidon2::*; +use snark_wrapper::franklin_crypto::bellman::pairing::bn256::{Bn256, Fr}; +use snark_wrapper::rescue_poseidon::poseidon2::transcript::Poseidon2Transcript; +use snark_wrapper::rescue_poseidon::poseidon2::*; use snark_wrapper::implementations::poseidon2::tree_hasher::AbsorptionModeReplacement; use zkevm_circuits::boojum::cs::implementations::prover::ProofConfig; diff --git a/circuit_definitions/src/circuit_definitions/aux_layer/mod.rs b/circuit_definitions/src/circuit_definitions/aux_layer/mod.rs index 4002f76d..e53b4607 100644 --- a/circuit_definitions/src/circuit_definitions/aux_layer/mod.rs +++ b/circuit_definitions/src/circuit_definitions/aux_layer/mod.rs @@ -12,7 +12,7 @@ use crate::circuit_definitions::cs_builder_reference::CsReferenceImplementationB use crate::circuit_definitions::implementations::reference_cs::CSReferenceAssembly; use crate::recursion_layer_proof_config; -use franklin_crypto::plonk::circuit; +use snark_wrapper::franklin_crypto::plonk::circuit; use zkevm_circuits::recursion::compression::CompressionRecursionConfig; use crate::ProofConfig; @@ -587,7 +587,7 @@ use crate::boojum::field::goldilocks::{GoldilocksExt2, GoldilocksField}; use crate::circuit_definitions::implementations::proof::Proof; use crate::circuit_definitions::implementations::setup::FinalizationHintsForProver; -use rescue_poseidon::poseidon2::Poseidon2Sponge; +use snark_wrapper::rescue_poseidon::poseidon2::Poseidon2Sponge; use snark_wrapper::franklin_crypto::bellman::pairing::bn256::{Bn256, Fr}; use snark_wrapper::implementations::poseidon2::tree_hasher::AbsorptionModeReplacement; diff --git a/circuit_definitions/src/lib.rs b/circuit_definitions/src/lib.rs index 7541217e..018f5b31 100644 --- a/circuit_definitions/src/lib.rs +++ b/circuit_definitions/src/lib.rs @@ -16,7 +16,7 @@ pub const RECURSION_LAYER_CAP_SIZE: usize = 16; pub const L1_SECURITY_BITS: usize = 80; -pub use franklin_crypto; +pub use snark_wrapper; use crate::boojum::cs::implementations::prover::ProofConfig; diff --git a/src/data_source/local_file_data_source.rs b/src/data_source/local_file_data_source.rs index aa3504e5..ad79cfb9 100644 --- a/src/data_source/local_file_data_source.rs +++ b/src/data_source/local_file_data_source.rs @@ -13,9 +13,9 @@ use circuit_definitions::circuit_definitions::recursion_layer::{ ZkSyncRecursionLayerVerificationKey, }; -use snark_wrapper::franklin_crypto::bellman::plonk::better_better_cs::proof::Proof as SnarkProof; -use snark_wrapper::franklin_crypto::bellman::plonk::better_better_cs::setup::Setup as SnarkSetup; -use snark_wrapper::franklin_crypto::bellman::plonk::better_better_cs::setup::VerificationKey as SnarkVK; +use crate::snark_wrapper::franklin_crypto::bellman::plonk::better_better_cs::proof::Proof as SnarkProof; +use crate::snark_wrapper::franklin_crypto::bellman::plonk::better_better_cs::setup::Setup as SnarkSetup; +use crate::snark_wrapper::franklin_crypto::bellman::plonk::better_better_cs::setup::VerificationKey as SnarkVK; use derivative::*; use std::sync::Arc; diff --git a/src/lib.rs b/src/lib.rs index 779077c8..3f8231df 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,6 +17,10 @@ pub use circuit_definitions::boojum; pub use circuit_definitions::zk_evm; pub use circuit_definitions::zkevm_circuits; +pub use circuit_definitions::snark_wrapper; +pub use rescue_poseidon::franklin_crypto; +pub use snark_wrapper::rescue_poseidon; + pub use crate::zk_evm::blake2; pub use crate::zk_evm::sha2; pub use crate::zk_evm::sha3; diff --git a/src/proof_wrapper_utils/mod.rs b/src/proof_wrapper_utils/mod.rs index 80c8cbc8..a9264bf9 100644 --- a/src/proof_wrapper_utils/mod.rs +++ b/src/proof_wrapper_utils/mod.rs @@ -10,20 +10,20 @@ use circuit_definitions::circuit_definitions::aux_layer::wrapper::ZkSyncCompress use circuit_definitions::circuit_definitions::recursion_layer::{ZkSyncRecursionLayerProof, ZkSyncRecursionLayerStorageType, ZkSyncRecursionLayerVerificationKey}; use circuit_definitions::zkevm_circuits::recursion::compression::CompressionRecursionConfig; use circuit_definitions::zkevm_circuits::scheduler::NUM_SCHEDULER_PUBLIC_INPUTS; -use snark_wrapper::franklin_crypto::bellman::kate_commitment::{Crs, CrsForMonomialForm}; -use snark_wrapper::franklin_crypto::bellman::plonk::better_better_cs::cs::{Circuit, PlonkCsWidth4WithNextStepAndCustomGatesParams, TrivialAssembly, SetupAssembly, ProvingAssembly}; -use snark_wrapper::franklin_crypto::bellman::plonk::better_better_cs::gates::selector_optimized_with_d_next::SelectorOptimizedWidth4MainGateWithDNext; -use snark_wrapper::franklin_crypto::bellman::plonk::better_better_cs::proof::Proof as SnarkProof; -use snark_wrapper::franklin_crypto::bellman::plonk::better_better_cs::setup::Setup as SnarkSetup; -use snark_wrapper::franklin_crypto::bellman::plonk::better_better_cs::setup::VerificationKey as SnarkVK; -use snark_wrapper::franklin_crypto::bellman::plonk::commitments::transcript::keccak_transcript::RollingKeccakTranscript; -use snark_wrapper::franklin_crypto::bellman::worker::Worker as BellmanWorker; -use snark_wrapper::implementations::poseidon2::CircuitPoseidon2Sponge; -use snark_wrapper::implementations::poseidon2::transcript::CircuitPoseidon2Transcript; -use snark_wrapper::verifier::WrapperCircuit; -use snark_wrapper::verifier_structs::allocated_vk::AllocatedVerificationKey; -use circuit_definitions::franklin_crypto::bellman::pairing::bn256::{Bn256, Fr}; -use circuit_definitions::franklin_crypto::bellman::{Field, PrimeField, PrimeFieldRepr}; +use crate::snark_wrapper::franklin_crypto::bellman::kate_commitment::{Crs, CrsForMonomialForm}; +use crate::snark_wrapper::franklin_crypto::bellman::plonk::better_better_cs::cs::{Circuit, PlonkCsWidth4WithNextStepAndCustomGatesParams, TrivialAssembly, SetupAssembly, ProvingAssembly}; +use crate::snark_wrapper::franklin_crypto::bellman::plonk::better_better_cs::gates::selector_optimized_with_d_next::SelectorOptimizedWidth4MainGateWithDNext; +use crate::snark_wrapper::franklin_crypto::bellman::plonk::better_better_cs::proof::Proof as SnarkProof; +use crate::snark_wrapper::franklin_crypto::bellman::plonk::better_better_cs::setup::Setup as SnarkSetup; +use crate::snark_wrapper::franklin_crypto::bellman::plonk::better_better_cs::setup::VerificationKey as SnarkVK; +use crate::snark_wrapper::franklin_crypto::bellman::plonk::commitments::transcript::keccak_transcript::RollingKeccakTranscript; +use crate::snark_wrapper::franklin_crypto::bellman::worker::Worker as BellmanWorker; +use crate::snark_wrapper::implementations::poseidon2::CircuitPoseidon2Sponge; +use crate::snark_wrapper::implementations::poseidon2::transcript::CircuitPoseidon2Transcript; +use crate::snark_wrapper::verifier::WrapperCircuit; +use crate::snark_wrapper::verifier_structs::allocated_vk::AllocatedVerificationKey; +use crate::franklin_crypto::bellman::pairing::bn256::{Bn256, Fr}; +use crate::franklin_crypto::bellman::{Field, PrimeField, PrimeFieldRepr}; use circuit_definitions::circuit_definitions::aux_layer::*; use crate::boojum::worker::Worker; diff --git a/src/proof_wrapper_utils/wrapper.rs b/src/proof_wrapper_utils/wrapper.rs index 828ee917..5bbccd55 100644 --- a/src/proof_wrapper_utils/wrapper.rs +++ b/src/proof_wrapper_utils/wrapper.rs @@ -71,7 +71,7 @@ pub(crate) fn compute_wrapper_proof_and_vk>(&snark_vk.into_inner(), &snark_proof, None) .unwrap(); diff --git a/src/snark_wrapper_test/mod.rs b/src/snark_wrapper_test/mod.rs index 64f07c99..db9c2286 100644 --- a/src/snark_wrapper_test/mod.rs +++ b/src/snark_wrapper_test/mod.rs @@ -1,12 +1,12 @@ #[cfg(test)] mod test { use crate::boojum::cs::implementations::verifier::*; - use snark_wrapper::franklin_crypto::bellman::pairing::bn256::{Bn256, Fr}; - use snark_wrapper::franklin_crypto::bellman::plonk::better_better_cs::cs::*; - use snark_wrapper::franklin_crypto::plonk::circuit::bigint_new::BITWISE_LOGICAL_OPS_TABLE_NAME; - use snark_wrapper::franklin_crypto::plonk::circuit::goldilocks::GoldilocksField; - use snark_wrapper::implementations::poseidon2::transcript::CircuitPoseidon2Transcript; - use snark_wrapper::implementations::poseidon2::CircuitPoseidon2Sponge; + use crate::snark_wrapper::franklin_crypto::bellman::pairing::bn256::{Bn256, Fr}; + use crate::snark_wrapper::franklin_crypto::bellman::plonk::better_better_cs::cs::*; + use crate::snark_wrapper::franklin_crypto::plonk::circuit::bigint_new::BITWISE_LOGICAL_OPS_TABLE_NAME; + use crate::snark_wrapper::franklin_crypto::plonk::circuit::goldilocks::GoldilocksField; + use crate::snark_wrapper::implementations::poseidon2::transcript::CircuitPoseidon2Transcript; + use crate::snark_wrapper::implementations::poseidon2::CircuitPoseidon2Sponge; use crate::boojum::cs::implementations::proof::Proof; use crate::boojum::cs::implementations::prover::ProofConfig; @@ -17,9 +17,9 @@ mod test { use crate::boojum::field::U64Representable; // use crate::snark_wrapper; - use snark_wrapper::verifier_structs::allocated_proof::AllocatedProof; - use snark_wrapper::verifier_structs::allocated_vk::AllocatedVerificationKey; - use snark_wrapper::verifier_structs::WrapperVerifier; + use crate::snark_wrapper::verifier_structs::allocated_proof::AllocatedProof; + use crate::snark_wrapper::verifier_structs::allocated_vk::AllocatedVerificationKey; + use crate::snark_wrapper::verifier_structs::WrapperVerifier; use circuit_definitions::circuit_definitions::aux_layer::compression::CompressionMode2ForWrapperCircuitBuilder; use circuit_definitions::circuit_definitions::aux_layer::compression::ProofCompressionFunction; @@ -54,7 +54,7 @@ mod test { assembly.add_table(bitwise_logic_table).unwrap(); // Allocate proof and vk - use snark_wrapper::traits::circuit::ErasedBuilderForWrapperVerifier; + use crate::snark_wrapper::traits::circuit::ErasedBuilderForWrapperVerifier; let verifier_builder = CompressionMode2ForWrapperCircuitBuilder::default(); let verifier = verifier_builder.create_wrapper_verifier(&mut assembly); @@ -94,7 +94,12 @@ mod test { .unwrap(); // Verify proof - snark_wrapper::verifier::verify::<_, _, _, CircuitPoseidon2Transcript>( + crate::snark_wrapper::verifier::verify::< + _, + _, + _, + CircuitPoseidon2Transcript, + >( &mut assembly, (), &proof_config, @@ -102,7 +107,8 @@ mod test { &verifier, &fixed_parameters, &vk, - ).unwrap(); + ) + .unwrap(); let after = assembly.n(); From 9e749c529f12a3980d80af9dc6691440b62de67f Mon Sep 17 00:00:00 2001 From: olesHolem Date: Thu, 12 Oct 2023 03:24:52 +0300 Subject: [PATCH 2/7] cargo fmt --- .../src/circuit_definitions/aux_layer/compression_modes/mod.rs | 2 +- circuit_definitions/src/circuit_definitions/aux_layer/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/circuit_definitions/src/circuit_definitions/aux_layer/compression_modes/mod.rs b/circuit_definitions/src/circuit_definitions/aux_layer/compression_modes/mod.rs index a7294758..b1519535 100644 --- a/circuit_definitions/src/circuit_definitions/aux_layer/compression_modes/mod.rs +++ b/circuit_definitions/src/circuit_definitions/aux_layer/compression_modes/mod.rs @@ -17,9 +17,9 @@ use crate::circuit_definitions::traits::circuit::ErasedBuilderForRecursiveVerifi use crate::circuit_definitions::traits::gate::GatePlacementStrategy; use snark_wrapper::franklin_crypto::bellman::pairing::bn256::{Bn256, Fr}; +use snark_wrapper::implementations::poseidon2::tree_hasher::AbsorptionModeReplacement; use snark_wrapper::rescue_poseidon::poseidon2::transcript::Poseidon2Transcript; use snark_wrapper::rescue_poseidon::poseidon2::*; -use snark_wrapper::implementations::poseidon2::tree_hasher::AbsorptionModeReplacement; use zkevm_circuits::boojum::cs::implementations::prover::ProofConfig; diff --git a/circuit_definitions/src/circuit_definitions/aux_layer/mod.rs b/circuit_definitions/src/circuit_definitions/aux_layer/mod.rs index e53b4607..55513160 100644 --- a/circuit_definitions/src/circuit_definitions/aux_layer/mod.rs +++ b/circuit_definitions/src/circuit_definitions/aux_layer/mod.rs @@ -587,9 +587,9 @@ use crate::boojum::field::goldilocks::{GoldilocksExt2, GoldilocksField}; use crate::circuit_definitions::implementations::proof::Proof; use crate::circuit_definitions::implementations::setup::FinalizationHintsForProver; -use snark_wrapper::rescue_poseidon::poseidon2::Poseidon2Sponge; use snark_wrapper::franklin_crypto::bellman::pairing::bn256::{Bn256, Fr}; use snark_wrapper::implementations::poseidon2::tree_hasher::AbsorptionModeReplacement; +use snark_wrapper::rescue_poseidon::poseidon2::Poseidon2Sponge; pub type CompressionProofsTreeHasher = GoldilocksPoseidon2Sponge; pub type CompressionProofsTreeHasherForWrapper = From 11168e95fab8fc9bc737c29185f7e26294ca00f4 Mon Sep 17 00:00:00 2001 From: olesHolem Date: Wed, 18 Oct 2023 04:45:48 +0300 Subject: [PATCH 3/7] InMemoryDataSource fixed and some test changes --- src/data_source/in_memory_data_source.rs | 28 ++++++- src/tests/complex_tests/mod.rs | 97 ++++++------------------ 2 files changed, 47 insertions(+), 78 deletions(-) diff --git a/src/data_source/in_memory_data_source.rs b/src/data_source/in_memory_data_source.rs index 99d7bd47..255aa99c 100644 --- a/src/data_source/in_memory_data_source.rs +++ b/src/data_source/in_memory_data_source.rs @@ -122,7 +122,12 @@ impl SetupDataSource for InMemoryDataSource { } fn get_recursion_layer_node_vk(&self) -> SourceResult { - Ok(self.recursion_layer_node_vk.clone().unwrap()) + self.recursion_layer_node_vk + .clone() + .ok_or(Box::new(Error::new( + ErrorKind::Other, + format!("no data for recursion layer node vk"), + ))) } fn get_recursion_layer_padding_proof( @@ -152,17 +157,32 @@ impl SetupDataSource for InMemoryDataSource { } fn get_recursion_layer_leaf_padding_proof(&self) -> SourceResult { - Ok(self.recursion_layer_leaf_padding_proof.clone().unwrap()) + self.recursion_layer_leaf_padding_proof + .clone() + .ok_or(Box::new(Error::new( + ErrorKind::Other, + format!("no data for recursion layer node vk"), + ))) } fn get_recursion_layer_node_padding_proof(&self) -> SourceResult { - Ok(self.recursion_layer_node_padding_proof.clone().unwrap()) + self.recursion_layer_node_padding_proof + .clone() + .ok_or(Box::new(Error::new( + ErrorKind::Other, + format!("no data for recursion layer node vk"), + ))) } fn get_recursion_layer_node_finalization_hint( &self, ) -> SourceResult { - Ok(self.recursion_layer_node_finalization_hint.clone().unwrap()) + self.recursion_layer_node_finalization_hint + .clone() + .ok_or(Box::new(Error::new( + ErrorKind::Other, + format!("no data for recursion layer node vk"), + ))) } fn get_compression_vk( diff --git a/src/tests/complex_tests/mod.rs b/src/tests/complex_tests/mod.rs index 0c948f15..c094f837 100644 --- a/src/tests/complex_tests/mod.rs +++ b/src/tests/complex_tests/mod.rs @@ -57,14 +57,14 @@ fn basic_test() { } #[test] -fn basic_test_compression_only() { +fn test_single_compression() { let config = testing_wrapper::get_testing_wrapper_config(); testing_wrapper::test_compression_for_compression_num(config); } #[test] -fn basic_test_compression_all_modes() { +fn test_compression_all_modes() { for compression in 1..=WrapperConfig::MAX_COMPRESSION_LAYERS { println!("Testing wrapper for mode {}", compression); let config = WrapperConfig::new(compression as u8); @@ -105,25 +105,25 @@ use crate::data_source::in_memory_data_source::InMemoryDataSource; use crate::witness::full_block_artifact::*; fn get_geometry_config() -> GeometryConfig { - // let geometry = crate::geometry_config::get_geometry_config(); - - GeometryConfig { - // cycles_per_vm_snapshot: 1, - cycles_per_vm_snapshot: 1024, - cycles_per_ram_permutation: 1024, - cycles_per_code_decommitter: 256, - cycles_per_storage_application: 4, - cycles_per_keccak256_circuit: 7, - cycles_per_sha256_circuit: 7, - cycles_per_ecrecover_circuit: 2, - // cycles_code_decommitter_sorter: 512, - cycles_code_decommitter_sorter: 3, - cycles_per_log_demuxer: 16, - cycles_per_storage_sorter: 16, - cycles_per_events_or_l1_messages_sorter: 4, - - limit_for_l1_messages_pudata_hasher: 32, - } + crate::geometry_config::get_geometry_config() + + // GeometryConfig { + // // cycles_per_vm_snapshot: 1, + // cycles_per_vm_snapshot: 1024, + // cycles_per_ram_permutation: 1024, + // cycles_per_code_decommitter: 256, + // cycles_per_storage_application: 4, + // cycles_per_keccak256_circuit: 7, + // cycles_per_sha256_circuit: 7, + // cycles_per_ecrecover_circuit: 2, + // // cycles_code_decommitter_sorter: 512, + // cycles_code_decommitter_sorter: 3, + // cycles_per_log_demuxer: 16, + // cycles_per_storage_sorter: 16, + // cycles_per_events_or_l1_messages_sorter: 4, + + // limit_for_l1_messages_pudata_hasher: 32, + // } } pub(crate) fn generate_base_layer( @@ -306,7 +306,8 @@ fn run_and_try_create_witness_inner(test_artifact: TestArtifact, cycle_limit: us let mut setup_data = None; - let mut source = InMemoryDataSource::new(); + // let mut source = InMemoryDataSource::new(); + let mut source = LocalFileDataSource; use crate::data_source::*; for (idx, el) in basic_block_circuits @@ -1100,58 +1101,6 @@ fn run_and_try_create_witness_inner(test_artifact: TestArtifact, cycle_limit: us .unwrap(); } - println!("Computing compression proofs"); - - try_to_compress_and_wrap_to_snark(scheduler_witness); - - println!("DONE"); -} - -fn try_to_compress_and_wrap_to_snark( - scheduler_witness: SchedulerCircuitInstanceWitness< - GoldilocksField, - boojum::gadgets::round_function::CircuitSimpleAlgebraicSponge< - GoldilocksField, - 8, - 12, - 4, - Poseidon2Goldilocks, - true, - >, - GoldilocksExt2, - >, -) { - use crate::data_source::*; - use crate::zkevm_circuits::scheduler::SchedulerConfig; - - let worker = Worker::new_with_num_threads(8); - - println!("Computing scheduler proof"); - let mut source = LocalFileDataSource; - - let node_vk = source.get_recursion_layer_node_vk().unwrap().into_inner(); - - let config = SchedulerConfig { - proof_config: recursion_layer_proof_config(), - vk_fixed_parameters: node_vk.fixed_parameters, - capacity: SCHEDULER_CAPACITY, - _marker: std::marker::PhantomData, - }; - - let scheduler_circuit = SchedulerCircuit { - witness: scheduler_witness, - config, - transcript_params: (), - _marker: std::marker::PhantomData, - }; - - let scheduler_circuit = ZkSyncRecursiveLayerCircuit::SchedulerCircuit(scheduler_circuit); - - match source.get_scheduler_proof() { - Err(_) => panic!(), - Ok(proof) => {} - } - println!("DONE"); } From ecd0480b733bed884433ac594c76ac62aab9169c Mon Sep 17 00:00:00 2001 From: olesHolem Date: Tue, 31 Oct 2023 19:34:12 +0200 Subject: [PATCH 4/7] better LocalFileDataSource --- circuit_definitions/Cargo.toml | 3 +- src/compute_setups.rs | 2 + src/data_source/local_file_data_source.rs | 178 ++++++++++++--------- src/geometry_config/mod.rs | 4 +- src/proof_compression/mod.rs | 2 + src/tests/complex_tests/mod.rs | 2 + src/tests/complex_tests/testing_wrapper.rs | 3 + 7 files changed, 115 insertions(+), 79 deletions(-) diff --git a/circuit_definitions/Cargo.toml b/circuit_definitions/Cargo.toml index 2543c23f..c5597961 100644 --- a/circuit_definitions/Cargo.toml +++ b/circuit_definitions/Cargo.toml @@ -13,12 +13,13 @@ license = "MIT OR Apache-2.0" snark_wrapper = {git = "https://github.com/matter-labs/snark-wrapper.git", branch = "main"} # snark_wrapper = {path = "../../snark_wrapper"} -zkevm_circuits = {git = "https://github.com/matter-labs/era-zkevm_circuits.git", branch = "main"} +zkevm_circuits = {git = "https://github.com/matter-labs/zkevm_circuits.git", branch = "main"} zk_evm = {git = "https://github.com/matter-labs/era-zk_evm.git", branch = "v1.4.0"} derivative = "*" serde = {version = "1", features = ["derive"]} crossbeam = "0.8" +seq-macro = "0.3.5" [features] default = [] diff --git a/src/compute_setups.rs b/src/compute_setups.rs index 8ac4d7e8..6192e80c 100644 --- a/src/compute_setups.rs +++ b/src/compute_setups.rs @@ -338,12 +338,14 @@ mod test { #[test] fn test_run_create_base_layer_vks_and_proofs() { + LocalFileDataSource::create_folders_for_storing_data(); let mut source = LocalFileDataSource; generate_base_layer_vks_and_proofs(&mut source).expect("must compute setup"); } #[test] fn test_run_create_recursion_layer_vks_and_proofs() { + LocalFileDataSource::create_folders_for_storing_data(); let mut source = LocalFileDataSource; generate_recursive_layer_vks_and_proofs(&mut source).expect("must compute setup"); } diff --git a/src/data_source/local_file_data_source.rs b/src/data_source/local_file_data_source.rs index ad79cfb9..6b01e342 100644 --- a/src/data_source/local_file_data_source.rs +++ b/src/data_source/local_file_data_source.rs @@ -25,9 +25,35 @@ use std::{error::Error, fs::File}; #[derivative(Clone, Copy, Debug)] pub struct LocalFileDataSource; +impl LocalFileDataSource { + pub const SETUP_DATA_LOCATION: &'static str = "./setup"; + pub const BLOCK_DATA_LOCATION: &'static str = "./test_proofs"; + + /// creates folders if missing + pub fn create_folders_for_storing_data() { + let subfolders = [ + "/base_layer", + "/recursion_layer", + "/aux_layer" + ]; + + for subfolder in subfolders.iter() { + let dir_location = format!("{}{}", Self::SETUP_DATA_LOCATION, subfolder); + if std::fs::read_dir(&dir_location).is_err() { + std::fs::create_dir_all(dir_location).unwrap(); + } + + let dir_location = format!("{}{}", Self::BLOCK_DATA_LOCATION, subfolder); + if std::fs::read_dir(&dir_location).is_err() { + std::fs::create_dir_all(dir_location).unwrap(); + } + } + } +} + impl SetupDataSource for LocalFileDataSource { fn get_base_layer_vk(&self, circuit_type: u8) -> SourceResult { - let file = File::open(format!("./setup/base_layer/vk_{}.json", circuit_type)) + let file = File::open(format!("{}/base_layer/vk_{}.json", Self::SETUP_DATA_LOCATION, circuit_type)) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -35,8 +61,8 @@ impl SetupDataSource for LocalFileDataSource { } fn get_base_layer_padding_proof(&self, circuit_type: u8) -> SourceResult { let file = File::open(format!( - "./setup/base_layer/padding_proof_{}.json", - circuit_type + "{}/base_layer/padding_proof_{}.json", + Self::SETUP_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -48,8 +74,8 @@ impl SetupDataSource for LocalFileDataSource { circuit_type: u8, ) -> SourceResult { let file = File::open(format!( - "./setup/base_layer/finalization_hint_{}.json", - circuit_type + "{}/base_layer/finalization_hint_{}.json", + Self::SETUP_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -60,14 +86,14 @@ impl SetupDataSource for LocalFileDataSource { &self, circuit_type: u8, ) -> SourceResult { - let file = File::open(format!("./setup/recursion_layer/vk_{}.json", circuit_type)) + let file = File::open(format!("{}/recursion_layer/vk_{}.json", Self::SETUP_DATA_LOCATION, circuit_type)) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; Ok(result) } fn get_recursion_layer_node_vk(&self) -> SourceResult { - let file = File::open("./setup/recursion_layer/vk_node.json") + let file = File::open(format!("{}/recursion_layer/vk_node.json", Self::SETUP_DATA_LOCATION)) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -78,8 +104,8 @@ impl SetupDataSource for LocalFileDataSource { circuit_type: u8, ) -> SourceResult { let file = File::open(format!( - "./setup/recursion_layer/padding_proof_{}.json", - circuit_type + "{}/recursion_layer/padding_proof_{}.json", + Self::SETUP_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -87,14 +113,14 @@ impl SetupDataSource for LocalFileDataSource { Ok(result) } fn get_recursion_layer_leaf_padding_proof(&self) -> SourceResult { - let file = File::open("./setup/recursion_layer/padding_proof_leaf.json") + let file = File::open(format!("{}/recursion_layer/padding_proof_leaf.json", Self::SETUP_DATA_LOCATION)) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; Ok(result) } fn get_recursion_layer_node_padding_proof(&self) -> SourceResult { - let file = File::open("./setup/recursion_layer/padding_proof_node.json") + let file = File::open(format!("{}/recursion_layer/padding_proof_node.json", Self::SETUP_DATA_LOCATION)) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -105,8 +131,8 @@ impl SetupDataSource for LocalFileDataSource { circuit_type: u8, ) -> SourceResult { let file = File::open(format!( - "./setup/recursion_layer/finalization_hint_{}.json", - circuit_type + "{}/recursion_layer/finalization_hint_{}.json", + Self::SETUP_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -116,7 +142,7 @@ impl SetupDataSource for LocalFileDataSource { fn get_recursion_layer_node_finalization_hint( &self, ) -> SourceResult { - let file = File::open("./setup/recursion_layer/finalization_hint_node.json") + let file = File::open(format!("{}/recursion_layer/finalization_hint_node.json", Self::SETUP_DATA_LOCATION)) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -127,8 +153,8 @@ impl SetupDataSource for LocalFileDataSource { circuit_type: u8, ) -> SourceResult { let file = File::open(format!( - "./setup/aux_layer/compression_vk_{}.json", - circuit_type + "{}/aux_layer/compression_vk_{}.json", + Self::SETUP_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -140,8 +166,8 @@ impl SetupDataSource for LocalFileDataSource { circuit_type: u8, ) -> SourceResult { let file = File::open(format!( - "./setup/aux_layer/compression_hint_{}.json", - circuit_type + "{}/aux_layer/compression_hint_{}.json", + Self::SETUP_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -153,8 +179,8 @@ impl SetupDataSource for LocalFileDataSource { circuit_type: u8, ) -> SourceResult { let file = File::open(format!( - "./setup/aux_layer/compression_for_wrapper_vk_{}.json", - circuit_type + "{}/aux_layer/compression_for_wrapper_vk_{}.json", + Self::SETUP_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -166,8 +192,8 @@ impl SetupDataSource for LocalFileDataSource { circuit_type: u8, ) -> SourceResult { let file = File::open(format!( - "./setup/aux_layer/compression_for_wrapper_hint_{}.json", - circuit_type + "{}/aux_layer/compression_for_wrapper_hint_{}.json", + Self::SETUP_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -179,8 +205,8 @@ impl SetupDataSource for LocalFileDataSource { let start = std::time::Instant::now(); let mut file = File::open(format!( - "./setup/aux_layer/wrapper_setup_{}.setup", - circuit_type + "{}/aux_layer/wrapper_setup_{}.setup", + Self::SETUP_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; @@ -194,7 +220,7 @@ impl SetupDataSource for LocalFileDataSource { Ok(result) } fn get_wrapper_vk(&self, circuit_type: u8) -> SourceResult { - let mut file = File::open(format!("./setup/aux_layer/wrapper_vk_{}.key", circuit_type)) + let mut file = File::open(format!("{}/aux_layer/wrapper_vk_{}.key", Self::SETUP_DATA_LOCATION, circuit_type)) .map_err(|el| Box::new(el) as Box)?; let result = ZkSyncSnarkWrapperVK::from_inner( @@ -207,7 +233,7 @@ impl SetupDataSource for LocalFileDataSource { fn set_base_layer_vk(&mut self, vk: ZkSyncBaseLayerVerificationKey) -> SourceResult<()> { let circuit_type = vk.numeric_circuit_type(); - let file = File::create(format!("./setup/base_layer/vk_{}.json", circuit_type)) + let file = File::create(format!("{}/base_layer/vk_{}.json", Self::SETUP_DATA_LOCATION, circuit_type)) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &vk).map_err(|el| Box::new(el) as Box)?; @@ -216,8 +242,8 @@ impl SetupDataSource for LocalFileDataSource { fn set_base_layer_padding_proof(&mut self, proof: ZkSyncBaseLayerProof) -> SourceResult<()> { let circuit_type = proof.numeric_circuit_type(); let file = File::create(format!( - "./setup/base_layer/padding_proof_{}.json", - circuit_type + "{}/base_layer/padding_proof_{}.json", + Self::SETUP_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &proof).map_err(|el| Box::new(el) as Box)?; @@ -230,8 +256,8 @@ impl SetupDataSource for LocalFileDataSource { ) -> SourceResult<()> { let circuit_type = hint.numeric_circuit_type(); let file = File::create(format!( - "./setup/base_layer/finalization_hint_{}.json", - circuit_type + "{}/base_layer/finalization_hint_{}.json", + Self::SETUP_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &hint).map_err(|el| Box::new(el) as Box)?; @@ -243,7 +269,7 @@ impl SetupDataSource for LocalFileDataSource { vk: ZkSyncRecursionLayerVerificationKey, ) -> SourceResult<()> { let circuit_type = vk.numeric_circuit_type(); - let file = File::create(format!("./setup/recursion_layer/vk_{}.json", circuit_type)) + let file = File::create(format!("{}/recursion_layer/vk_{}.json", Self::SETUP_DATA_LOCATION, circuit_type)) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &vk).map_err(|el| Box::new(el) as Box)?; @@ -253,7 +279,7 @@ impl SetupDataSource for LocalFileDataSource { &mut self, vk: ZkSyncRecursionLayerVerificationKey, ) -> SourceResult<()> { - let file = File::create("./setup/recursion_layer/vk_node.json") + let file = File::create(format!("{}/recursion_layer/vk_node.json", Self::SETUP_DATA_LOCATION)) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &vk).map_err(|el| Box::new(el) as Box)?; @@ -265,8 +291,8 @@ impl SetupDataSource for LocalFileDataSource { ) -> SourceResult<()> { let circuit_type = proof.numeric_circuit_type(); let file = File::create(format!( - "./setup/recursion_layer/padding_proof_{}.json", - circuit_type + "{}/recursion_layer/padding_proof_{}.json", + Self::SETUP_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &proof).map_err(|el| Box::new(el) as Box)?; @@ -277,7 +303,7 @@ impl SetupDataSource for LocalFileDataSource { &mut self, proof: ZkSyncRecursionLayerProof, ) -> SourceResult<()> { - let file = File::create("./setup/recursion_layer/padding_proof_leaf.json") + let file = File::create(format!("{}/recursion_layer/padding_proof_leaf.json", Self::SETUP_DATA_LOCATION)) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &proof).map_err(|el| Box::new(el) as Box)?; @@ -287,7 +313,7 @@ impl SetupDataSource for LocalFileDataSource { &mut self, proof: ZkSyncRecursionLayerProof, ) -> SourceResult<()> { - let file = File::create("./setup/recursion_layer/padding_proof_node.json") + let file = File::create(format!("{}/recursion_layer/padding_proof_node.json", Self::SETUP_DATA_LOCATION)) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &proof).map_err(|el| Box::new(el) as Box)?; @@ -299,8 +325,8 @@ impl SetupDataSource for LocalFileDataSource { ) -> SourceResult<()> { let circuit_type = hint.numeric_circuit_type(); let file = File::create(format!( - "./setup/recursion_layer/finalization_hint_{}.json", - circuit_type + "{}/recursion_layer/finalization_hint_{}.json", + Self::SETUP_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &hint).map_err(|el| Box::new(el) as Box)?; @@ -311,7 +337,7 @@ impl SetupDataSource for LocalFileDataSource { &mut self, hint: ZkSyncRecursionLayerFinalizationHint, ) -> SourceResult<()> { - let file = File::create("./setup/recursion_layer/finalization_hint_node.json") + let file = File::create(format!("{}/recursion_layer/finalization_hint_node.json", Self::SETUP_DATA_LOCATION)) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &hint).map_err(|el| Box::new(el) as Box)?; @@ -323,8 +349,8 @@ impl SetupDataSource for LocalFileDataSource { ) -> SourceResult<()> { let circuit_type = vk.numeric_circuit_type(); let file = File::create(format!( - "./setup/aux_layer/compression_vk_{}.json", - circuit_type + "{}/setup/aux_layer/compression_vk_{}.json", + Self::SETUP_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &vk).map_err(|el| Box::new(el) as Box)?; @@ -337,8 +363,8 @@ impl SetupDataSource for LocalFileDataSource { ) -> SourceResult<()> { let circuit_type = hint.numeric_circuit_type(); let file = File::create(format!( - "./setup/aux_layer/compression_hint_{}.json", - circuit_type + "{}/aux_layer/compression_hint_{}.json", + Self::SETUP_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &hint).map_err(|el| Box::new(el) as Box)?; @@ -351,8 +377,8 @@ impl SetupDataSource for LocalFileDataSource { ) -> SourceResult<()> { let circuit_type = vk.numeric_circuit_type(); let file = File::create(format!( - "./setup/aux_layer/compression_for_wrapper_vk_{}.json", - circuit_type + "{}/aux_layer/compression_for_wrapper_vk_{}.json", + Self::SETUP_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &vk).map_err(|el| Box::new(el) as Box)?; @@ -365,8 +391,8 @@ impl SetupDataSource for LocalFileDataSource { ) -> SourceResult<()> { let circuit_type = hint.numeric_circuit_type(); let file = File::create(format!( - "./setup/aux_layer/compression_for_wrapper_hint_{}.json", - circuit_type + "{}/aux_layer/compression_for_wrapper_hint_{}.json", + Self::SETUP_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &hint).map_err(|el| Box::new(el) as Box)?; @@ -379,8 +405,8 @@ impl SetupDataSource for LocalFileDataSource { let circuit_type = setup.numeric_circuit_type(); let mut file = File::create(format!( - "./setup/aux_layer/wrapper_setup_{}.setup", - circuit_type + "{}/aux_layer/wrapper_setup_{}.setup", + Self::SETUP_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; @@ -395,7 +421,7 @@ impl SetupDataSource for LocalFileDataSource { } fn set_wrapper_vk(&mut self, vk: ZkSyncSnarkWrapperVK) -> SourceResult<()> { let circuit_type = vk.numeric_circuit_type(); - let mut file = File::create(format!("./setup/aux_layer/wrapper_vk_{}.key", circuit_type)) + let mut file = File::create(format!("{}/aux_layer/wrapper_vk_{}.key", Self::SETUP_DATA_LOCATION, circuit_type)) .map_err(|el| Box::new(el) as Box)?; vk.into_inner() @@ -413,8 +439,8 @@ impl BlockDataSource for LocalFileDataSource { index: usize, ) -> SourceResult { let file = File::open(format!( - "./test_proofs/base_layer/basic_circuit_proof_{}_{}.json", - circuit_type, index + "{}/base_layer/basic_circuit_proof_{}_{}.json", + Self::BLOCK_DATA_LOCATION, circuit_type, index )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -427,8 +453,8 @@ impl BlockDataSource for LocalFileDataSource { index: usize, ) -> SourceResult { let file = File::open(format!( - "./test_proofs/recursion_layer/leaf_layer_proof_{}_{}.json", - circuit_type, index + "{}/recursion_layer/leaf_layer_proof_{}_{}.json", + Self::BLOCK_DATA_LOCATION, circuit_type, index )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -442,8 +468,8 @@ impl BlockDataSource for LocalFileDataSource { index: usize, ) -> SourceResult { let file = File::open(format!( - "./test_proofs/recursion_layer/node_layer_proof_{}_{}_{}.json", - circuit_type, step, index + "{}/recursion_layer/node_layer_proof_{}_{}_{}.json", + Self::BLOCK_DATA_LOCATION, circuit_type, step, index )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -451,7 +477,7 @@ impl BlockDataSource for LocalFileDataSource { Ok(result) } fn get_scheduler_proof(&self) -> SourceResult { - let file = File::open("./test_proofs/recursion_layer/scheduler_proof.json") + let file = File::open(format!("{}/recursion_layer/scheduler_proof.json", Self::BLOCK_DATA_LOCATION)) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -459,8 +485,8 @@ impl BlockDataSource for LocalFileDataSource { } fn get_compression_proof(&self, circuit_type: u8) -> SourceResult { let file = File::open(format!( - "./test_proofs/aux_layer/compression_proof_{}.json", - circuit_type + "{}/aux_layer/compression_proof_{}.json", + Self::BLOCK_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -472,8 +498,8 @@ impl BlockDataSource for LocalFileDataSource { circuit_type: u8, ) -> SourceResult { let file = File::open(format!( - "./test_proofs/aux_layer/compression_for_wrapper_proof_{}.json", - circuit_type + "{}/aux_layer/compression_for_wrapper_proof_{}.json", + Self::BLOCK_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -482,8 +508,8 @@ impl BlockDataSource for LocalFileDataSource { } fn get_wrapper_proof(&self, circuit_type: u8) -> SourceResult { let mut file = File::open(format!( - "./test_proofs/aux_layer/wrapper_proof_{}.proof", - circuit_type + "{}/aux_layer/wrapper_proof_{}.proof", + Self::BLOCK_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; @@ -502,8 +528,8 @@ impl BlockDataSource for LocalFileDataSource { ) -> SourceResult<()> { let circuit_type = proof.numeric_circuit_type(); let file = File::create(format!( - "./test_proofs/base_layer/basic_circuit_proof_{}_{}.json", - circuit_type, index + "{}/base_layer/basic_circuit_proof_{}_{}.json", + Self::BLOCK_DATA_LOCATION, circuit_type, index )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &proof).map_err(|el| Box::new(el) as Box)?; @@ -517,8 +543,8 @@ impl BlockDataSource for LocalFileDataSource { ) -> SourceResult<()> { let circuit_type = proof.numeric_circuit_type(); let file = File::create(format!( - "./test_proofs/recursion_layer/leaf_layer_proof_{}_{}.json", - circuit_type, index + "{}/recursion_layer/leaf_layer_proof_{}_{}.json", + Self::BLOCK_DATA_LOCATION, circuit_type, index )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &proof).map_err(|el| Box::new(el) as Box)?; @@ -533,8 +559,8 @@ impl BlockDataSource for LocalFileDataSource { proof: ZkSyncRecursionLayerProof, ) -> SourceResult<()> { let file = File::create(format!( - "./test_proofs/recursion_layer/node_layer_proof_{}_{}_{}.json", - circuit_type, step, index + "{}/recursion_layer/node_layer_proof_{}_{}_{}.json", + Self::BLOCK_DATA_LOCATION, circuit_type, step, index )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &proof).map_err(|el| Box::new(el) as Box)?; @@ -542,7 +568,7 @@ impl BlockDataSource for LocalFileDataSource { Ok(()) } fn set_scheduler_proof(&mut self, proof: ZkSyncRecursionLayerProof) -> SourceResult<()> { - let file = File::create("./test_proofs/recursion_layer/scheduler_proof.json") + let file = File::create(format!("{}/recursion_layer/scheduler_proof.json", Self::BLOCK_DATA_LOCATION)) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &proof).map_err(|el| Box::new(el) as Box)?; @@ -551,8 +577,8 @@ impl BlockDataSource for LocalFileDataSource { fn set_compression_proof(&mut self, proof: ZkSyncCompressionLayerProof) -> SourceResult<()> { let circuit_type = proof.numeric_circuit_type(); let file = File::create(format!( - "./test_proofs/aux_layer/compression_proof_{}.json", - circuit_type + "{}/aux_layer/compression_proof_{}.json", + Self::BLOCK_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &proof).map_err(|el| Box::new(el) as Box)?; @@ -565,8 +591,8 @@ impl BlockDataSource for LocalFileDataSource { ) -> SourceResult<()> { let circuit_type = proof.numeric_circuit_type(); let file = File::create(format!( - "./test_proofs/aux_layer/compression_for_wrapper_proof_{}.json", - circuit_type + "{}/aux_layer/compression_for_wrapper_proof_{}.json", + Self::BLOCK_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &proof).map_err(|el| Box::new(el) as Box)?; @@ -576,8 +602,8 @@ impl BlockDataSource for LocalFileDataSource { fn set_wrapper_proof(&mut self, proof: ZkSyncSnarkWrapperProof) -> SourceResult<()> { let circuit_type = proof.numeric_circuit_type(); let mut file = File::create(format!( - "./test_proofs/aux_layer/wrapper_proof_{}.proof", - circuit_type + "{}/aux_layer/wrapper_proof_{}.proof", + Self::BLOCK_DATA_LOCATION, circuit_type )) .map_err(|el| Box::new(el) as Box)?; diff --git a/src/geometry_config/mod.rs b/src/geometry_config/mod.rs index 8c906d4a..b1096d78 100644 --- a/src/geometry_config/mod.rs +++ b/src/geometry_config/mod.rs @@ -4,10 +4,10 @@ use crate::toolset::GeometryConfig; pub const fn get_geometry_config() -> GeometryConfig { GeometryConfig { - cycles_per_vm_snapshot: 5713, + cycles_per_vm_snapshot: 5692, cycles_code_decommitter_sorter: 117500, cycles_per_log_demuxer: 58750, - cycles_per_storage_sorter: 44687, + cycles_per_storage_sorter: 46921, cycles_per_events_or_l1_messages_sorter: 31287, cycles_per_ram_permutation: 136714, cycles_per_code_decommitter: 2845, diff --git a/src/proof_compression/mod.rs b/src/proof_compression/mod.rs index ab500f2f..e56f7412 100644 --- a/src/proof_compression/mod.rs +++ b/src/proof_compression/mod.rs @@ -86,6 +86,7 @@ mod test { #[test] fn preform_step_1_compression() { + LocalFileDataSource::create_folders_for_storing_data(); let source = LocalFileDataSource; let proof = source.get_scheduler_proof().unwrap(); let vk = source @@ -300,6 +301,7 @@ mod test { #[test] fn compress_1() { + LocalFileDataSource::create_folders_for_storing_data(); let source = LocalFileDataSource; let proof = source.get_scheduler_proof().unwrap(); let vk = source diff --git a/src/tests/complex_tests/mod.rs b/src/tests/complex_tests/mod.rs index c094f837..aa8cea9c 100644 --- a/src/tests/complex_tests/mod.rs +++ b/src/tests/complex_tests/mod.rs @@ -308,6 +308,7 @@ fn run_and_try_create_witness_inner(test_artifact: TestArtifact, cycle_limit: us // let mut source = InMemoryDataSource::new(); let mut source = LocalFileDataSource; + LocalFileDataSource::create_folders_for_storing_data(); use crate::data_source::*; for (idx, el) in basic_block_circuits @@ -1133,6 +1134,7 @@ fn run_single() { ZkSyncRecursionLayerStorageType::NodeLayerCircuit, ); let verifier = verifier_builder.create_verifier(); + LocalFileDataSource::create_folders_for_storing_data(); let source = LocalFileDataSource; let vk = source.get_recursion_layer_node_vk().unwrap().into_inner(); diff --git a/src/tests/complex_tests/testing_wrapper.rs b/src/tests/complex_tests/testing_wrapper.rs index 7fa90fbb..7bc53551 100644 --- a/src/tests/complex_tests/testing_wrapper.rs +++ b/src/tests/complex_tests/testing_wrapper.rs @@ -17,6 +17,7 @@ pub(crate) fn test_compression_for_compression_num(config: WrapperConfig) { let worker = Worker::new(); let bellman_worker = BellmanWorker::new(); + LocalFileDataSource::create_folders_for_storing_data(); let mut file_source = LocalFileDataSource; let mut source = InMemoryDataSource::new(); @@ -73,6 +74,7 @@ pub(crate) fn test_wrapper_pi_inner( fn test_wrapper_pi() { let config = get_testing_wrapper_config(); + LocalFileDataSource::create_folders_for_storing_data(); let mut source = LocalFileDataSource; test_wrapper_pi_inner(&mut source, config); @@ -115,6 +117,7 @@ fn test_pi_aggregation_function() { fn test_wrapper_vk_generation() { let config = get_testing_wrapper_config(); + LocalFileDataSource::create_folders_for_storing_data(); let mut source = LocalFileDataSource; let scheduler_vk = source From 0d5606d857889a4dd42b1fc76c998f8bab4cbccb Mon Sep 17 00:00:00 2001 From: olesHolem Date: Tue, 31 Oct 2023 19:38:32 +0200 Subject: [PATCH 5/7] better geometry config using --- src/tests/complex_tests/mod.rs | 43 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/tests/complex_tests/mod.rs b/src/tests/complex_tests/mod.rs index aa8cea9c..34ca951b 100644 --- a/src/tests/complex_tests/mod.rs +++ b/src/tests/complex_tests/mod.rs @@ -104,26 +104,26 @@ use crate::boojum::gadgets::recursion::recursive_tree_hasher::CircuitGoldilocksP use crate::data_source::in_memory_data_source::InMemoryDataSource; use crate::witness::full_block_artifact::*; -fn get_geometry_config() -> GeometryConfig { - crate::geometry_config::get_geometry_config() - - // GeometryConfig { - // // cycles_per_vm_snapshot: 1, - // cycles_per_vm_snapshot: 1024, - // cycles_per_ram_permutation: 1024, - // cycles_per_code_decommitter: 256, - // cycles_per_storage_application: 4, - // cycles_per_keccak256_circuit: 7, - // cycles_per_sha256_circuit: 7, - // cycles_per_ecrecover_circuit: 2, - // // cycles_code_decommitter_sorter: 512, - // cycles_code_decommitter_sorter: 3, - // cycles_per_log_demuxer: 16, - // cycles_per_storage_sorter: 16, - // cycles_per_events_or_l1_messages_sorter: 4, - - // limit_for_l1_messages_pudata_hasher: 32, - // } +/// Lover memory requirements +/// Used only for base layer debugging +fn get_testing_geometry_config() -> GeometryConfig { + GeometryConfig { + // cycles_per_vm_snapshot: 1, + cycles_per_vm_snapshot: 1024, + cycles_per_ram_permutation: 1024, + cycles_per_code_decommitter: 256, + cycles_per_storage_application: 4, + cycles_per_keccak256_circuit: 7, + cycles_per_sha256_circuit: 7, + cycles_per_ecrecover_circuit: 2, + // cycles_code_decommitter_sorter: 512, + cycles_code_decommitter_sorter: 3, + cycles_per_log_demuxer: 16, + cycles_per_storage_sorter: 16, + cycles_per_events_or_l1_messages_sorter: 4, + + limit_for_l1_messages_pudata_hasher: 32, + } } pub(crate) fn generate_base_layer( @@ -255,7 +255,8 @@ fn run_and_try_create_witness_inner(test_artifact: TestArtifact, cycle_limit: us use crate::external_calls::run; use crate::toolset::GeometryConfig; - let geometry = get_geometry_config(); + // let geometry = get_testing_geometry_config(); + let geometry = crate::geometry_config::get_geometry_config(); // let (basic_block_circuits, basic_block_circuits_inputs, mut scheduler_partial_input) = run( let ( From 58c102b6c06a63ab67c7cbdf90c8dac98e56f6a3 Mon Sep 17 00:00:00 2001 From: olesHolem Date: Tue, 31 Oct 2023 19:39:24 +0200 Subject: [PATCH 6/7] cargo fmt --- src/data_source/local_file_data_source.rs | 224 +++++++++++++++------- 1 file changed, 156 insertions(+), 68 deletions(-) diff --git a/src/data_source/local_file_data_source.rs b/src/data_source/local_file_data_source.rs index 6b01e342..7e83cc29 100644 --- a/src/data_source/local_file_data_source.rs +++ b/src/data_source/local_file_data_source.rs @@ -31,18 +31,14 @@ impl LocalFileDataSource { /// creates folders if missing pub fn create_folders_for_storing_data() { - let subfolders = [ - "/base_layer", - "/recursion_layer", - "/aux_layer" - ]; + let subfolders = ["/base_layer", "/recursion_layer", "/aux_layer"]; for subfolder in subfolders.iter() { let dir_location = format!("{}{}", Self::SETUP_DATA_LOCATION, subfolder); if std::fs::read_dir(&dir_location).is_err() { std::fs::create_dir_all(dir_location).unwrap(); } - + let dir_location = format!("{}{}", Self::BLOCK_DATA_LOCATION, subfolder); if std::fs::read_dir(&dir_location).is_err() { std::fs::create_dir_all(dir_location).unwrap(); @@ -53,8 +49,12 @@ impl LocalFileDataSource { impl SetupDataSource for LocalFileDataSource { fn get_base_layer_vk(&self, circuit_type: u8) -> SourceResult { - let file = File::open(format!("{}/base_layer/vk_{}.json", Self::SETUP_DATA_LOCATION, circuit_type)) - .map_err(|el| Box::new(el) as Box)?; + let file = File::open(format!( + "{}/base_layer/vk_{}.json", + Self::SETUP_DATA_LOCATION, + circuit_type + )) + .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; Ok(result) @@ -62,7 +62,8 @@ impl SetupDataSource for LocalFileDataSource { fn get_base_layer_padding_proof(&self, circuit_type: u8) -> SourceResult { let file = File::open(format!( "{}/base_layer/padding_proof_{}.json", - Self::SETUP_DATA_LOCATION, circuit_type + Self::SETUP_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -75,7 +76,8 @@ impl SetupDataSource for LocalFileDataSource { ) -> SourceResult { let file = File::open(format!( "{}/base_layer/finalization_hint_{}.json", - Self::SETUP_DATA_LOCATION, circuit_type + Self::SETUP_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -86,15 +88,22 @@ impl SetupDataSource for LocalFileDataSource { &self, circuit_type: u8, ) -> SourceResult { - let file = File::open(format!("{}/recursion_layer/vk_{}.json", Self::SETUP_DATA_LOCATION, circuit_type)) - .map_err(|el| Box::new(el) as Box)?; + let file = File::open(format!( + "{}/recursion_layer/vk_{}.json", + Self::SETUP_DATA_LOCATION, + circuit_type + )) + .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; Ok(result) } fn get_recursion_layer_node_vk(&self) -> SourceResult { - let file = File::open(format!("{}/recursion_layer/vk_node.json", Self::SETUP_DATA_LOCATION)) - .map_err(|el| Box::new(el) as Box)?; + let file = File::open(format!( + "{}/recursion_layer/vk_node.json", + Self::SETUP_DATA_LOCATION + )) + .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; Ok(result) @@ -105,7 +114,8 @@ impl SetupDataSource for LocalFileDataSource { ) -> SourceResult { let file = File::open(format!( "{}/recursion_layer/padding_proof_{}.json", - Self::SETUP_DATA_LOCATION, circuit_type + Self::SETUP_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -113,15 +123,21 @@ impl SetupDataSource for LocalFileDataSource { Ok(result) } fn get_recursion_layer_leaf_padding_proof(&self) -> SourceResult { - let file = File::open(format!("{}/recursion_layer/padding_proof_leaf.json", Self::SETUP_DATA_LOCATION)) - .map_err(|el| Box::new(el) as Box)?; + let file = File::open(format!( + "{}/recursion_layer/padding_proof_leaf.json", + Self::SETUP_DATA_LOCATION + )) + .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; Ok(result) } fn get_recursion_layer_node_padding_proof(&self) -> SourceResult { - let file = File::open(format!("{}/recursion_layer/padding_proof_node.json", Self::SETUP_DATA_LOCATION)) - .map_err(|el| Box::new(el) as Box)?; + let file = File::open(format!( + "{}/recursion_layer/padding_proof_node.json", + Self::SETUP_DATA_LOCATION + )) + .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; Ok(result) @@ -132,7 +148,8 @@ impl SetupDataSource for LocalFileDataSource { ) -> SourceResult { let file = File::open(format!( "{}/recursion_layer/finalization_hint_{}.json", - Self::SETUP_DATA_LOCATION, circuit_type + Self::SETUP_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -142,8 +159,11 @@ impl SetupDataSource for LocalFileDataSource { fn get_recursion_layer_node_finalization_hint( &self, ) -> SourceResult { - let file = File::open(format!("{}/recursion_layer/finalization_hint_node.json", Self::SETUP_DATA_LOCATION)) - .map_err(|el| Box::new(el) as Box)?; + let file = File::open(format!( + "{}/recursion_layer/finalization_hint_node.json", + Self::SETUP_DATA_LOCATION + )) + .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; Ok(result) @@ -154,7 +174,8 @@ impl SetupDataSource for LocalFileDataSource { ) -> SourceResult { let file = File::open(format!( "{}/aux_layer/compression_vk_{}.json", - Self::SETUP_DATA_LOCATION, circuit_type + Self::SETUP_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -167,7 +188,8 @@ impl SetupDataSource for LocalFileDataSource { ) -> SourceResult { let file = File::open(format!( "{}/aux_layer/compression_hint_{}.json", - Self::SETUP_DATA_LOCATION, circuit_type + Self::SETUP_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -180,7 +202,8 @@ impl SetupDataSource for LocalFileDataSource { ) -> SourceResult { let file = File::open(format!( "{}/aux_layer/compression_for_wrapper_vk_{}.json", - Self::SETUP_DATA_LOCATION, circuit_type + Self::SETUP_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -193,7 +216,8 @@ impl SetupDataSource for LocalFileDataSource { ) -> SourceResult { let file = File::open(format!( "{}/aux_layer/compression_for_wrapper_hint_{}.json", - Self::SETUP_DATA_LOCATION, circuit_type + Self::SETUP_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -206,7 +230,8 @@ impl SetupDataSource for LocalFileDataSource { let mut file = File::open(format!( "{}/aux_layer/wrapper_setup_{}.setup", - Self::SETUP_DATA_LOCATION, circuit_type + Self::SETUP_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; @@ -220,8 +245,12 @@ impl SetupDataSource for LocalFileDataSource { Ok(result) } fn get_wrapper_vk(&self, circuit_type: u8) -> SourceResult { - let mut file = File::open(format!("{}/aux_layer/wrapper_vk_{}.key", Self::SETUP_DATA_LOCATION, circuit_type)) - .map_err(|el| Box::new(el) as Box)?; + let mut file = File::open(format!( + "{}/aux_layer/wrapper_vk_{}.key", + Self::SETUP_DATA_LOCATION, + circuit_type + )) + .map_err(|el| Box::new(el) as Box)?; let result = ZkSyncSnarkWrapperVK::from_inner( circuit_type, @@ -233,8 +262,12 @@ impl SetupDataSource for LocalFileDataSource { fn set_base_layer_vk(&mut self, vk: ZkSyncBaseLayerVerificationKey) -> SourceResult<()> { let circuit_type = vk.numeric_circuit_type(); - let file = File::create(format!("{}/base_layer/vk_{}.json", Self::SETUP_DATA_LOCATION, circuit_type)) - .map_err(|el| Box::new(el) as Box)?; + let file = File::create(format!( + "{}/base_layer/vk_{}.json", + Self::SETUP_DATA_LOCATION, + circuit_type + )) + .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &vk).map_err(|el| Box::new(el) as Box)?; Ok(()) @@ -243,7 +276,8 @@ impl SetupDataSource for LocalFileDataSource { let circuit_type = proof.numeric_circuit_type(); let file = File::create(format!( "{}/base_layer/padding_proof_{}.json", - Self::SETUP_DATA_LOCATION, circuit_type + Self::SETUP_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &proof).map_err(|el| Box::new(el) as Box)?; @@ -257,7 +291,8 @@ impl SetupDataSource for LocalFileDataSource { let circuit_type = hint.numeric_circuit_type(); let file = File::create(format!( "{}/base_layer/finalization_hint_{}.json", - Self::SETUP_DATA_LOCATION, circuit_type + Self::SETUP_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &hint).map_err(|el| Box::new(el) as Box)?; @@ -269,8 +304,12 @@ impl SetupDataSource for LocalFileDataSource { vk: ZkSyncRecursionLayerVerificationKey, ) -> SourceResult<()> { let circuit_type = vk.numeric_circuit_type(); - let file = File::create(format!("{}/recursion_layer/vk_{}.json", Self::SETUP_DATA_LOCATION, circuit_type)) - .map_err(|el| Box::new(el) as Box)?; + let file = File::create(format!( + "{}/recursion_layer/vk_{}.json", + Self::SETUP_DATA_LOCATION, + circuit_type + )) + .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &vk).map_err(|el| Box::new(el) as Box)?; Ok(()) @@ -279,8 +318,11 @@ impl SetupDataSource for LocalFileDataSource { &mut self, vk: ZkSyncRecursionLayerVerificationKey, ) -> SourceResult<()> { - let file = File::create(format!("{}/recursion_layer/vk_node.json", Self::SETUP_DATA_LOCATION)) - .map_err(|el| Box::new(el) as Box)?; + let file = File::create(format!( + "{}/recursion_layer/vk_node.json", + Self::SETUP_DATA_LOCATION + )) + .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &vk).map_err(|el| Box::new(el) as Box)?; Ok(()) @@ -292,7 +334,8 @@ impl SetupDataSource for LocalFileDataSource { let circuit_type = proof.numeric_circuit_type(); let file = File::create(format!( "{}/recursion_layer/padding_proof_{}.json", - Self::SETUP_DATA_LOCATION, circuit_type + Self::SETUP_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &proof).map_err(|el| Box::new(el) as Box)?; @@ -303,8 +346,11 @@ impl SetupDataSource for LocalFileDataSource { &mut self, proof: ZkSyncRecursionLayerProof, ) -> SourceResult<()> { - let file = File::create(format!("{}/recursion_layer/padding_proof_leaf.json", Self::SETUP_DATA_LOCATION)) - .map_err(|el| Box::new(el) as Box)?; + let file = File::create(format!( + "{}/recursion_layer/padding_proof_leaf.json", + Self::SETUP_DATA_LOCATION + )) + .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &proof).map_err(|el| Box::new(el) as Box)?; Ok(()) @@ -313,8 +359,11 @@ impl SetupDataSource for LocalFileDataSource { &mut self, proof: ZkSyncRecursionLayerProof, ) -> SourceResult<()> { - let file = File::create(format!("{}/recursion_layer/padding_proof_node.json", Self::SETUP_DATA_LOCATION)) - .map_err(|el| Box::new(el) as Box)?; + let file = File::create(format!( + "{}/recursion_layer/padding_proof_node.json", + Self::SETUP_DATA_LOCATION + )) + .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &proof).map_err(|el| Box::new(el) as Box)?; Ok(()) @@ -326,7 +375,8 @@ impl SetupDataSource for LocalFileDataSource { let circuit_type = hint.numeric_circuit_type(); let file = File::create(format!( "{}/recursion_layer/finalization_hint_{}.json", - Self::SETUP_DATA_LOCATION, circuit_type + Self::SETUP_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &hint).map_err(|el| Box::new(el) as Box)?; @@ -337,8 +387,11 @@ impl SetupDataSource for LocalFileDataSource { &mut self, hint: ZkSyncRecursionLayerFinalizationHint, ) -> SourceResult<()> { - let file = File::create(format!("{}/recursion_layer/finalization_hint_node.json", Self::SETUP_DATA_LOCATION)) - .map_err(|el| Box::new(el) as Box)?; + let file = File::create(format!( + "{}/recursion_layer/finalization_hint_node.json", + Self::SETUP_DATA_LOCATION + )) + .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &hint).map_err(|el| Box::new(el) as Box)?; Ok(()) @@ -350,7 +403,8 @@ impl SetupDataSource for LocalFileDataSource { let circuit_type = vk.numeric_circuit_type(); let file = File::create(format!( "{}/setup/aux_layer/compression_vk_{}.json", - Self::SETUP_DATA_LOCATION, circuit_type + Self::SETUP_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &vk).map_err(|el| Box::new(el) as Box)?; @@ -364,7 +418,8 @@ impl SetupDataSource for LocalFileDataSource { let circuit_type = hint.numeric_circuit_type(); let file = File::create(format!( "{}/aux_layer/compression_hint_{}.json", - Self::SETUP_DATA_LOCATION, circuit_type + Self::SETUP_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &hint).map_err(|el| Box::new(el) as Box)?; @@ -378,7 +433,8 @@ impl SetupDataSource for LocalFileDataSource { let circuit_type = vk.numeric_circuit_type(); let file = File::create(format!( "{}/aux_layer/compression_for_wrapper_vk_{}.json", - Self::SETUP_DATA_LOCATION, circuit_type + Self::SETUP_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &vk).map_err(|el| Box::new(el) as Box)?; @@ -392,7 +448,8 @@ impl SetupDataSource for LocalFileDataSource { let circuit_type = hint.numeric_circuit_type(); let file = File::create(format!( "{}/aux_layer/compression_for_wrapper_hint_{}.json", - Self::SETUP_DATA_LOCATION, circuit_type + Self::SETUP_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &hint).map_err(|el| Box::new(el) as Box)?; @@ -406,7 +463,8 @@ impl SetupDataSource for LocalFileDataSource { let circuit_type = setup.numeric_circuit_type(); let mut file = File::create(format!( "{}/aux_layer/wrapper_setup_{}.setup", - Self::SETUP_DATA_LOCATION, circuit_type + Self::SETUP_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; @@ -421,8 +479,12 @@ impl SetupDataSource for LocalFileDataSource { } fn set_wrapper_vk(&mut self, vk: ZkSyncSnarkWrapperVK) -> SourceResult<()> { let circuit_type = vk.numeric_circuit_type(); - let mut file = File::create(format!("{}/aux_layer/wrapper_vk_{}.key", Self::SETUP_DATA_LOCATION, circuit_type)) - .map_err(|el| Box::new(el) as Box)?; + let mut file = File::create(format!( + "{}/aux_layer/wrapper_vk_{}.key", + Self::SETUP_DATA_LOCATION, + circuit_type + )) + .map_err(|el| Box::new(el) as Box)?; vk.into_inner() .write(&mut file) @@ -440,7 +502,9 @@ impl BlockDataSource for LocalFileDataSource { ) -> SourceResult { let file = File::open(format!( "{}/base_layer/basic_circuit_proof_{}_{}.json", - Self::BLOCK_DATA_LOCATION, circuit_type, index + Self::BLOCK_DATA_LOCATION, + circuit_type, + index )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -454,7 +518,9 @@ impl BlockDataSource for LocalFileDataSource { ) -> SourceResult { let file = File::open(format!( "{}/recursion_layer/leaf_layer_proof_{}_{}.json", - Self::BLOCK_DATA_LOCATION, circuit_type, index + Self::BLOCK_DATA_LOCATION, + circuit_type, + index )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -469,7 +535,10 @@ impl BlockDataSource for LocalFileDataSource { ) -> SourceResult { let file = File::open(format!( "{}/recursion_layer/node_layer_proof_{}_{}_{}.json", - Self::BLOCK_DATA_LOCATION, circuit_type, step, index + Self::BLOCK_DATA_LOCATION, + circuit_type, + step, + index )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -477,8 +546,11 @@ impl BlockDataSource for LocalFileDataSource { Ok(result) } fn get_scheduler_proof(&self) -> SourceResult { - let file = File::open(format!("{}/recursion_layer/scheduler_proof.json", Self::BLOCK_DATA_LOCATION)) - .map_err(|el| Box::new(el) as Box)?; + let file = File::open(format!( + "{}/recursion_layer/scheduler_proof.json", + Self::BLOCK_DATA_LOCATION + )) + .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; Ok(result) @@ -486,7 +558,8 @@ impl BlockDataSource for LocalFileDataSource { fn get_compression_proof(&self, circuit_type: u8) -> SourceResult { let file = File::open(format!( "{}/aux_layer/compression_proof_{}.json", - Self::BLOCK_DATA_LOCATION, circuit_type + Self::BLOCK_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -499,7 +572,8 @@ impl BlockDataSource for LocalFileDataSource { ) -> SourceResult { let file = File::open(format!( "{}/aux_layer/compression_for_wrapper_proof_{}.json", - Self::BLOCK_DATA_LOCATION, circuit_type + Self::BLOCK_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; let result = serde_json::from_reader(file).map_err(|el| Box::new(el) as Box)?; @@ -509,7 +583,8 @@ impl BlockDataSource for LocalFileDataSource { fn get_wrapper_proof(&self, circuit_type: u8) -> SourceResult { let mut file = File::open(format!( "{}/aux_layer/wrapper_proof_{}.proof", - Self::BLOCK_DATA_LOCATION, circuit_type + Self::BLOCK_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; @@ -529,7 +604,9 @@ impl BlockDataSource for LocalFileDataSource { let circuit_type = proof.numeric_circuit_type(); let file = File::create(format!( "{}/base_layer/basic_circuit_proof_{}_{}.json", - Self::BLOCK_DATA_LOCATION, circuit_type, index + Self::BLOCK_DATA_LOCATION, + circuit_type, + index )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &proof).map_err(|el| Box::new(el) as Box)?; @@ -544,7 +621,9 @@ impl BlockDataSource for LocalFileDataSource { let circuit_type = proof.numeric_circuit_type(); let file = File::create(format!( "{}/recursion_layer/leaf_layer_proof_{}_{}.json", - Self::BLOCK_DATA_LOCATION, circuit_type, index + Self::BLOCK_DATA_LOCATION, + circuit_type, + index )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &proof).map_err(|el| Box::new(el) as Box)?; @@ -560,7 +639,10 @@ impl BlockDataSource for LocalFileDataSource { ) -> SourceResult<()> { let file = File::create(format!( "{}/recursion_layer/node_layer_proof_{}_{}_{}.json", - Self::BLOCK_DATA_LOCATION, circuit_type, step, index + Self::BLOCK_DATA_LOCATION, + circuit_type, + step, + index )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &proof).map_err(|el| Box::new(el) as Box)?; @@ -568,8 +650,11 @@ impl BlockDataSource for LocalFileDataSource { Ok(()) } fn set_scheduler_proof(&mut self, proof: ZkSyncRecursionLayerProof) -> SourceResult<()> { - let file = File::create(format!("{}/recursion_layer/scheduler_proof.json", Self::BLOCK_DATA_LOCATION)) - .map_err(|el| Box::new(el) as Box)?; + let file = File::create(format!( + "{}/recursion_layer/scheduler_proof.json", + Self::BLOCK_DATA_LOCATION + )) + .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &proof).map_err(|el| Box::new(el) as Box)?; Ok(()) @@ -578,7 +663,8 @@ impl BlockDataSource for LocalFileDataSource { let circuit_type = proof.numeric_circuit_type(); let file = File::create(format!( "{}/aux_layer/compression_proof_{}.json", - Self::BLOCK_DATA_LOCATION, circuit_type + Self::BLOCK_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &proof).map_err(|el| Box::new(el) as Box)?; @@ -592,7 +678,8 @@ impl BlockDataSource for LocalFileDataSource { let circuit_type = proof.numeric_circuit_type(); let file = File::create(format!( "{}/aux_layer/compression_for_wrapper_proof_{}.json", - Self::BLOCK_DATA_LOCATION, circuit_type + Self::BLOCK_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; serde_json::to_writer(file, &proof).map_err(|el| Box::new(el) as Box)?; @@ -603,7 +690,8 @@ impl BlockDataSource for LocalFileDataSource { let circuit_type = proof.numeric_circuit_type(); let mut file = File::create(format!( "{}/aux_layer/wrapper_proof_{}.proof", - Self::BLOCK_DATA_LOCATION, circuit_type + Self::BLOCK_DATA_LOCATION, + circuit_type )) .map_err(|el| Box::new(el) as Box)?; From 3f455de2980919f50189b6b3dfe43b1357b08e54 Mon Sep 17 00:00:00 2001 From: olesHolem Date: Fri, 3 Nov 2023 13:48:09 +0200 Subject: [PATCH 7/7] using public circuits --- circuit_definitions/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circuit_definitions/Cargo.toml b/circuit_definitions/Cargo.toml index c5597961..75b0a3e1 100644 --- a/circuit_definitions/Cargo.toml +++ b/circuit_definitions/Cargo.toml @@ -13,7 +13,7 @@ license = "MIT OR Apache-2.0" snark_wrapper = {git = "https://github.com/matter-labs/snark-wrapper.git", branch = "main"} # snark_wrapper = {path = "../../snark_wrapper"} -zkevm_circuits = {git = "https://github.com/matter-labs/zkevm_circuits.git", branch = "main"} +zkevm_circuits = {git = "https://github.com/matter-labs/era-zkevm_circuits.git", branch = "main"} zk_evm = {git = "https://github.com/matter-labs/era-zk_evm.git", branch = "v1.4.0"} derivative = "*"