Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
Do witness processing without CS (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov authored Aug 12, 2024
1 parent 1662fd7 commit 0fa2472
Show file tree
Hide file tree
Showing 10 changed files with 271 additions and 261 deletions.
2 changes: 1 addition & 1 deletion circuit_encodings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ description = "ZKsync Era circuits encodings"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
zkevm_circuits = "=0.150.2"
zkevm_circuits = "=0.150.3"
zk_evm = "=0.150.0"

derivative = "2.2"
Expand Down
2 changes: 1 addition & 1 deletion kzg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ once_cell = "1"
serde_with = {version = "1", features = ["hex"]}

boojum = "=0.2.2"
zkevm_circuits = "=0.150.2"
zkevm_circuits = "=0.150.3"

[dev-dependencies]
rand = "0.4"
Expand Down
8 changes: 1 addition & 7 deletions src/witness/individual_circuits/log_demux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use circuit_definitions::encodings::recursion_request::RecursionQueueSimulator;
use circuit_definitions::zkevm_circuits::demux_log_queue::DemuxOutput;
use circuit_definitions::zkevm_circuits::scheduler::aux::BaseLayerCircuitType;
use circuit_definitions::{encodings::*, Field, RoundFunction};
use postprocessing::CsForWitnessGeneration;
use zk_evm::zkevm_opcode_defs::SECP256R1_VERIFY_PRECOMPILE_ADDRESS;

use crate::zk_evm::aux_structures::LogQuery as LogQuery_;
Expand Down Expand Up @@ -182,7 +181,6 @@ pub(crate) fn process_logs_demux_and_make_circuits<
per_circuit_capacity: usize,
round_function: &RoundFunction,
geometry: &GeometryConfig,
cs_for_witness_generation: &mut CsForWitnessGeneration,
mut circuit_callback: CB,
mut recursion_queue_callback: QSCB,
) -> (
Expand All @@ -198,11 +196,7 @@ pub(crate) fn process_logs_demux_and_make_circuits<

let circuit_type = BaseLayerCircuitType::LogDemultiplexer;

let mut maker = CircuitMaker::new(
geometry.cycles_per_log_demuxer,
round_function.clone(),
cs_for_witness_generation,
);
let mut maker = CircuitMaker::new(geometry.cycles_per_log_demuxer, round_function.clone());

// trivial empty case
if log_demux_artifacts
Expand Down
20 changes: 8 additions & 12 deletions src/witness/individual_circuits/main_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ use crate::witness::aux_data_structs::one_per_circuit_accumulator::CircuitsEntry
use crate::witness::aux_data_structs::per_circuit_accumulator::PerCircuitAccumulatorSparse;
use crate::witness::individual_circuits::SmallField;
use crate::witness::oracle::FrameLogQueueDetailedState;
use crate::witness::postprocessing::{
ClosedFormInputField, CsForWitnessGeneration, FirstAndLastCircuitWitness,
};
use crate::witness::postprocessing::{ClosedFormInputField, FirstAndLastCircuitWitness};
use crate::witness::tracer::vm_snapshot::VmSnapshot;
use crate::witness::utils::simulate_public_input_value_from_encodable_witness;
use crate::zk_evm::aux_structures::MemoryQuery;
use crate::zk_evm::vm_state::VmLocalState;
use crate::zkevm_circuits::base_structures::vm_state::{
Expand Down Expand Up @@ -316,9 +315,7 @@ fn repack_input_for_main_vm(
use crate::witness::postprocessing::observable_witness::VmObservableWitness;
use crate::zkevm_circuits::fsm_input_output::circuit_inputs::main_vm::VmCircuitWitness;

use super::{
simulate_public_input_value_from_witness, vm_instance_witness_to_circuit_formal_input,
};
use super::vm_instance_witness_to_circuit_formal_input;

pub(crate) fn process_main_vm<
CB: FnMut(ZkSyncBaseLayerCircuit),
Expand All @@ -344,7 +341,6 @@ pub(crate) fn process_main_vm<
flat_new_frames_history: Vec<(Cycle, CallStackEntry)>,
mut vm_snapshots: Vec<VmSnapshot>,
round_function: Poseidon2Goldilocks,
cs_for_witness_generation: &mut CsForWitnessGeneration,
circuit_callback: &mut CB,
recursion_queue_callback: &mut QSCB,
) -> (
Expand Down Expand Up @@ -372,11 +368,11 @@ pub(crate) fn process_main_vm<
observable_input.as_ref().unwrap().clone();
}

let (proof_system_input, compact_form_witness) = simulate_public_input_value_from_witness(
cs_for_witness_generation.take_cs(),
circuit_input.closed_form_input.clone(),
&round_function,
);
let (proof_system_input, compact_form_witness) =
simulate_public_input_value_from_encodable_witness(
circuit_input.closed_form_input.clone(),
&round_function,
);

let instance = VMMainCircuit {
witness: AtomicCell::new(Some(circuit_input)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use circuit_definitions::encodings::recursion_request::RecursionQueueSimulator;
use circuit_definitions::zkevm_circuits::scheduler::aux::BaseLayerCircuitType;
use circuit_definitions::{encodings::*, Field, RoundFunction};
use memory_query::{CustomMemoryQueueSimulator, QueueWitness};
use postprocessing::{CsForWitnessGeneration, FirstAndLastCircuitWitness};
use postprocessing::FirstAndLastCircuitWitness;

use rayon::prelude::*;
use snark_wrapper::boojum::field::Field as _;
Expand All @@ -45,7 +45,6 @@ pub(crate) fn compute_ram_circuit_snapshots<
num_non_deterministic_heap_queries: usize,
per_circuit_capacity: usize,
geometry: &GeometryConfig,
cs_for_witness_generation: &mut CsForWitnessGeneration,
mut circuit_callback: CB,
mut recursion_queue_callback: QSCB,
) -> (
Expand Down Expand Up @@ -274,11 +273,7 @@ pub(crate) fn compute_ram_circuit_snapshots<
let mut last_queue_state = (placeholder_witness.clone(), placeholder_witness);

let circuit_type = BaseLayerCircuitType::RamValidation;
let mut maker = CircuitMaker::new(
geometry.cycles_per_ram_permutation,
round_function.clone(),
cs_for_witness_generation,
);
let mut maker = CircuitMaker::new(geometry.cycles_per_ram_permutation, round_function.clone());

for (
idx,
Expand Down
3 changes: 0 additions & 3 deletions src/witness/individual_circuits/storage_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use circuit_definitions::encodings::recursion_request::RecursionQueueSimulator;
use circuit_definitions::encodings::state_diff_record::StateDiffRecord;
use circuit_definitions::encodings::LogQueueSimulator;
use circuit_definitions::zkevm_circuits::scheduler::aux::BaseLayerCircuitType;
use postprocessing::CsForWitnessGeneration;
use tracing;
use zk_evm::aux_structures::LogQuery;

Expand All @@ -41,7 +40,6 @@ pub(crate) fn decompose_into_storage_application_witnesses<
round_function: &Poseidon2Goldilocks,
num_rounds_per_circuit: usize,
geometry: &GeometryConfig,
cs_for_witness_generation: &mut CsForWitnessGeneration,
mut circuit_callback: CB,
mut recursion_queue_callback: QSCB,
) -> (
Expand All @@ -54,7 +52,6 @@ pub(crate) fn decompose_into_storage_application_witnesses<
let mut maker = CircuitMaker::new(
geometry.cycles_per_storage_application,
round_function.clone(),
cs_for_witness_generation,
);

if deduplicated_rollup_storage_queries.is_empty() {
Expand Down
27 changes: 1 addition & 26 deletions src/witness/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
use super::artifacts::LogCircuitsArtifacts;
use super::individual_circuits::main_vm::CallstackSimulationResult;
use super::postprocessing::{
BlockFirstAndLastBasicCircuitsObservableWitnesses, CsForWitnessGeneration,
FirstAndLastCircuitWitness,
BlockFirstAndLastBasicCircuitsObservableWitnesses, FirstAndLastCircuitWitness,
};
use super::tracer::callstack_handler::*;
use super::utils::*;
Expand Down Expand Up @@ -701,7 +700,6 @@ fn process_io_log_circuits<
demuxed_log_queues_states: IOLogsQueuesStates,
demuxed_log_queries: DemuxedIOLogQueries,
round_function: &Poseidon2Goldilocks,
cs_for_witness_generation: &mut CsForWitnessGeneration,
mut circuit_callback: &mut CB,
mut recursion_queue_callback: &mut QSCB,
) -> (
Expand Down Expand Up @@ -799,7 +797,6 @@ fn process_io_log_circuits<
round_function,
geometry.cycles_per_storage_application as usize,
geometry,
cs_for_witness_generation,
&mut circuit_callback,
&mut recursion_queue_callback,
);
Expand Down Expand Up @@ -919,7 +916,6 @@ fn process_memory_related_circuits<
executed_decommittment_queries: Vec<(Cycle, DecommittmentQuery, Vec<U256>)>,
precompiles_data: PrecompilesInputData,
round_function: &Poseidon2Goldilocks,
cs_for_witness_generation: &mut CsForWitnessGeneration,
mut circuit_callback: &mut CB,
mut recursion_queue_callback: &mut QSCB,
) -> (
Expand Down Expand Up @@ -1112,7 +1108,6 @@ fn process_memory_related_circuits<
num_non_deterministic_heap_queries,
geometry.cycles_per_ram_permutation as usize,
geometry,
cs_for_witness_generation,
&mut circuit_callback,
&mut recursion_queue_callback,
);
Expand Down Expand Up @@ -1216,10 +1211,6 @@ pub(crate) fn create_artifacts_from_tracer<
*round_function,
);

// Scratch-space constraint system for circuits processing
// Used when creating circuit instances and compact form witnesses
let mut cs_for_witness_generation = CsForWitnessGeneration::new();

// demux log queue circuit
use crate::witness::individual_circuits::log_demux::process_logs_demux_and_make_circuits;

Expand All @@ -1238,7 +1229,6 @@ pub(crate) fn create_artifacts_from_tracer<
geometry.cycles_per_log_demuxer as usize,
round_function,
geometry,
&mut cs_for_witness_generation,
&mut circuit_callback,
&mut recursion_queue_callback,
);
Expand All @@ -1255,7 +1245,6 @@ pub(crate) fn create_artifacts_from_tracer<
io_logs_queues_states,
demuxed_log_queries.io,
round_function,
&mut cs_for_witness_generation,
&mut circuit_callback,
&mut recursion_queue_callback,
);
Expand Down Expand Up @@ -1291,7 +1280,6 @@ pub(crate) fn create_artifacts_from_tracer<
executed_decommittment_queries,
precompiles_data,
round_function,
&mut cs_for_witness_generation,
&mut circuit_callback,
&mut recursion_queue_callback,
);
Expand Down Expand Up @@ -1339,7 +1327,6 @@ pub(crate) fn create_artifacts_from_tracer<
flat_new_frames_history,
vm_snapshots,
*round_function,
&mut cs_for_witness_generation,
&mut circuit_callback,
&mut recursion_queue_callback,
);
Expand Down Expand Up @@ -1377,7 +1364,6 @@ pub(crate) fn create_artifacts_from_tracer<
*round_function,
|x| circuit_callback(ZkSyncBaseLayerCircuit::CodeDecommittmentsSorter(x)),
&mut recursion_queue_callback,
&mut cs_for_witness_generation,
);

// Actual decommitter
Expand All @@ -1389,7 +1375,6 @@ pub(crate) fn create_artifacts_from_tracer<
*round_function,
|x| circuit_callback(ZkSyncBaseLayerCircuit::CodeDecommitter(x)),
&mut recursion_queue_callback,
&mut cs_for_witness_generation,
);

// keccak precompiles
Expand All @@ -1401,7 +1386,6 @@ pub(crate) fn create_artifacts_from_tracer<
*round_function,
|x| circuit_callback(ZkSyncBaseLayerCircuit::KeccakRoundFunction(x)),
&mut recursion_queue_callback,
&mut cs_for_witness_generation,
);

// sha256 precompiles
Expand All @@ -1413,7 +1397,6 @@ pub(crate) fn create_artifacts_from_tracer<
*round_function,
|x| circuit_callback(ZkSyncBaseLayerCircuit::Sha256RoundFunction(x)),
&mut recursion_queue_callback,
&mut cs_for_witness_generation,
);

// ecrecover precompiles
Expand All @@ -1425,7 +1408,6 @@ pub(crate) fn create_artifacts_from_tracer<
*round_function,
|x| circuit_callback(ZkSyncBaseLayerCircuit::ECRecover(x)),
&mut recursion_queue_callback,
&mut cs_for_witness_generation,
);

// secp256r1 verify
Expand All @@ -1437,7 +1419,6 @@ pub(crate) fn create_artifacts_from_tracer<
*round_function,
|x| circuit_callback(ZkSyncBaseLayerCircuit::Secp256r1Verify(x)),
&mut recursion_queue_callback,
&mut cs_for_witness_generation,
);

// storage sorter
Expand All @@ -1448,7 +1429,6 @@ pub(crate) fn create_artifacts_from_tracer<
*round_function,
|x| circuit_callback(ZkSyncBaseLayerCircuit::StorageSorter(x)),
&mut recursion_queue_callback,
&mut cs_for_witness_generation,
);

// events sorter
Expand All @@ -1459,7 +1439,6 @@ pub(crate) fn create_artifacts_from_tracer<
*round_function,
|x| circuit_callback(ZkSyncBaseLayerCircuit::EventsSorter(x)),
&mut recursion_queue_callback,
&mut cs_for_witness_generation,
);

// l1 messages sorter
Expand All @@ -1471,7 +1450,6 @@ pub(crate) fn create_artifacts_from_tracer<
*round_function,
|x| circuit_callback(ZkSyncBaseLayerCircuit::L1MessagesSorter(x)),
&mut recursion_queue_callback,
&mut cs_for_witness_generation,
);

// l1 messages pubdata hasher
Expand All @@ -1483,7 +1461,6 @@ pub(crate) fn create_artifacts_from_tracer<
*round_function,
|x| circuit_callback(ZkSyncBaseLayerCircuit::L1MessagesHasher(x)),
&mut recursion_queue_callback,
&mut cs_for_witness_generation,
);

// transient storage sorter
Expand All @@ -1497,7 +1474,6 @@ pub(crate) fn create_artifacts_from_tracer<
*round_function,
|x| circuit_callback(ZkSyncBaseLayerCircuit::TransientStorageSorter(x)),
&mut recursion_queue_callback,
&mut cs_for_witness_generation,
);

// eip 4844 circuits are basic, but they do not need closed form input commitments
Expand All @@ -1512,7 +1488,6 @@ pub(crate) fn create_artifacts_from_tracer<
*round_function,
|x| circuit_callback(ZkSyncBaseLayerCircuit::EIP4844Repack(x)),
&mut recursion_queue_callback,
&mut cs_for_witness_generation,
);

// All done!
Expand Down
Loading

0 comments on commit 0fa2472

Please sign in to comment.