diff --git a/prover/Cargo.lock b/prover/Cargo.lock index 716a8fa24568..9652ee98a5c1 100644 --- a/prover/Cargo.lock +++ b/prover/Cargo.lock @@ -4968,6 +4968,7 @@ dependencies = [ "vlog", "zkevm_test_harness 1.3.3", "zksync_config", + "zksync_env_config", "zksync_types", ] @@ -6093,6 +6094,7 @@ dependencies = [ "vlog", "zkevm_test_harness 1.4.0", "zksync_config", + "zksync_env_config", "zksync_prover_fri_types", "zksync_prover_utils", "zksync_types", @@ -6701,6 +6703,7 @@ dependencies = [ "zkevm_test_harness 1.3.3", "zksync_config", "zksync_dal", + "zksync_env_config", "zksync_object_store", "zksync_prover_fri_utils", "zksync_prover_utils", @@ -6715,17 +6718,10 @@ name = "zksync_config" version = "0.1.0" dependencies = [ "anyhow", - "bigdecimal", "envy", - "hex", - "num 0.3.1", - "once_cell", "serde", - "serde_json", - "url", "zksync_basic_types", "zksync_contracts", - "zksync_utils", ] [[package]] @@ -6783,6 +6779,17 @@ dependencies = [ "zksync_utils", ] +[[package]] +name = "zksync_env_config" +version = "0.1.0" +dependencies = [ + "anyhow", + "envy", + "serde", + "zksync_basic_types", + "zksync_config", +] + [[package]] name = "zksync_eth_client" version = "0.1.0" @@ -6877,6 +6884,7 @@ dependencies = [ "zkevm_test_harness 1.4.0", "zksync_config", "zksync_dal", + "zksync_env_config", "zksync_object_store", "zksync_prover_fri_types", "zksync_prover_utils", @@ -6914,6 +6922,7 @@ dependencies = [ "zksync_circuit_breaker", "zksync_config", "zksync_dal", + "zksync_env_config", "zksync_eth_client", "zksync_object_store", "zksync_prover_utils", @@ -6943,6 +6952,7 @@ dependencies = [ "zkevm_test_harness 1.4.0", "zksync_config", "zksync_dal", + "zksync_env_config", "zksync_object_store", "zksync_prover_fri_types", "zksync_prover_fri_utils", @@ -6970,6 +6980,7 @@ dependencies = [ "vlog", "zksync_config", "zksync_dal", + "zksync_env_config", "zksync_object_store", "zksync_types", "zksync_utils", @@ -7169,6 +7180,7 @@ dependencies = [ "zkevm_test_harness 1.4.0", "zksync_config", "zksync_dal", + "zksync_env_config", "zksync_object_store", "zksync_prover_fri_types", "zksync_prover_fri_utils", @@ -7200,6 +7212,7 @@ dependencies = [ "vlog", "zksync_config", "zksync_dal", + "zksync_env_config", "zksync_object_store", "zksync_prover_fri_types", "zksync_prover_fri_utils", diff --git a/prover/witness_generator/src/basic_circuits.rs b/prover/witness_generator/src/basic_circuits.rs index e7e7cf43e098..04692dbced19 100644 --- a/prover/witness_generator/src/basic_circuits.rs +++ b/prover/witness_generator/src/basic_circuits.rs @@ -22,7 +22,10 @@ use zksync_prover_fri_types::circuit_definitions::zkevm_circuits::scheduler::blo use zksync_prover_fri_types::circuit_definitions::zkevm_circuits::scheduler::input::SchedulerCircuitInstanceWitness; use zksync_prover_fri_types::{AuxOutputWitnessWrapper, get_current_pod_name}; -use multivm::vm_latest::{constants::MAX_CYCLES_FOR_TX, HistoryDisabled, StorageOracle}; +use crate::storage_oracle::StorageOracle; +use multivm::vm_latest::{ + constants::MAX_CYCLES_FOR_TX, HistoryDisabled, StorageOracle as VmStorageOracle, +}; use zksync_config::configs::FriWitnessGeneratorConfig; use zksync_dal::fri_witness_generator_dal::FriWitnessJobStatus; use zksync_dal::ConnectionPool; @@ -537,6 +540,13 @@ async fn generate_witness( .map(|hash| u256_to_h256(*hash)) .collect(); + let storage_refunds = connection + .blocks_dal() + .get_storage_refunds(input.block_number) + .await + .unwrap() + .unwrap(); + let mut used_bytecodes = connection.storage_dal().get_factory_deps(&hashes).await; if input.used_bytecodes_hashes.contains(&account_code_hash) { used_bytecodes.insert(account_code_hash, account_bytecode); @@ -608,10 +618,14 @@ async fn generate_witness( let connection = rt_handle .block_on(connection_pool.access_storage()) .unwrap(); + let storage = PostgresStorage::new(rt_handle, connection, last_miniblock_number, true); let storage_view = StorageView::new(storage).to_rc_ptr(); - let storage_oracle: StorageOracle>, HistoryDisabled> = - StorageOracle::new(storage_view.clone()); + + let vm_storage_oracle: VmStorageOracle>, HistoryDisabled> = + VmStorageOracle::new(storage_view.clone()); + let storage_oracle = StorageOracle::new(vm_storage_oracle, storage_refunds); + zkevm_test_harness::external_calls::run_with_fixed_params( Address::zero(), BOOTLOADER_ADDRESS, diff --git a/prover/witness_generator/src/lib.rs b/prover/witness_generator/src/lib.rs index bb082c8557d8..f7f0fcb2642d 100644 --- a/prover/witness_generator/src/lib.rs +++ b/prover/witness_generator/src/lib.rs @@ -5,6 +5,7 @@ pub mod leaf_aggregation; pub mod node_aggregation; pub mod precalculated_merkle_paths_provider; pub mod scheduler; +mod storage_oracle; pub mod utils; #[cfg(test)] diff --git a/prover/witness_generator/src/main.rs b/prover/witness_generator/src/main.rs index 357aff42eb3e..c662b14405ce 100644 --- a/prover/witness_generator/src/main.rs +++ b/prover/witness_generator/src/main.rs @@ -29,6 +29,7 @@ mod leaf_aggregation; mod node_aggregation; mod precalculated_merkle_paths_provider; mod scheduler; +mod storage_oracle; mod utils; #[derive(Debug, StructOpt)] diff --git a/prover/witness_generator/src/storage_oracle.rs b/prover/witness_generator/src/storage_oracle.rs new file mode 100644 index 000000000000..a23a08aa6ee3 --- /dev/null +++ b/prover/witness_generator/src/storage_oracle.rs @@ -0,0 +1,46 @@ +use zksync_types::zkevm_test_harness::zk_evm::abstractions::{ + RefundType, RefundedAmounts, Storage, +}; +use zksync_types::{LogQuery, Timestamp}; + +#[derive(Debug)] +pub struct StorageOracle { + inn: T, + storage_refunds: std::vec::IntoIter, +} + +impl StorageOracle { + pub fn new(inn: T, storage_refunds: Vec) -> Self { + Self { + inn, + storage_refunds: storage_refunds.into_iter(), + } + } +} + +impl Storage for StorageOracle { + fn estimate_refunds_for_write( + &mut self, + _monotonic_cycle_counter: u32, + _partial_query: &LogQuery, + ) -> RefundType { + let pubdata_bytes = self.storage_refunds.next().expect("Missing refund"); + RefundType::RepeatedWrite(RefundedAmounts { + pubdata_bytes, + ergs: 0, + }) + } + + fn execute_partial_query(&mut self, monotonic_cycle_counter: u32, query: LogQuery) -> LogQuery { + self.inn + .execute_partial_query(monotonic_cycle_counter, query) + } + + fn finish_frame(&mut self, timestamp: Timestamp, panicked: bool) { + self.inn.finish_frame(timestamp, panicked) + } + + fn start_frame(&mut self, timestamp: Timestamp) { + self.inn.start_frame(timestamp) + } +}