Skip to content

Commit

Permalink
Cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov committed Oct 2, 2024
1 parent fdf434f commit a89d429
Show file tree
Hide file tree
Showing 12 changed files with 253 additions and 193 deletions.
4 changes: 3 additions & 1 deletion crates/zkevm_test_harness/src/external_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ pub fn run<S: Storage>(
cycle_limit: usize,
geometry: GeometryConfig,
storage: S,
tree: impl BinarySparseStorageTree<256, 32, 32, 8, 32, Blake2s256, ZkSyncStorageLeaf> + 'static + std::marker::Send,
tree: impl BinarySparseStorageTree<256, 32, 32, 8, 32, Blake2s256, ZkSyncStorageLeaf>
+ 'static
+ std::marker::Send,
trusted_setup_path: String,
eip_4844_repack_inputs: [Option<Vec<u8>>; MAX_4844_BLOBS_PER_BLOCK],
artifacts_callback_sender: SyncSender<WitnessGenerationArtifact>,
Expand Down
4 changes: 3 additions & 1 deletion crates/zkevm_test_harness/src/run_vms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ pub fn run_vms<S: Storage>(
cycle_limit: usize,
geometry: GeometryConfig,
storage: S,
tree: impl BinarySparseStorageTree<256, 32, 32, 8, 32, Blake2s256, ZkSyncStorageLeaf> + 'static + std::marker::Send,
tree: impl BinarySparseStorageTree<256, 32, 32, 8, 32, Blake2s256, ZkSyncStorageLeaf>
+ 'static
+ std::marker::Send,
trusted_setup_path: String,
eip_4844_repack_inputs: [Option<Vec<u8>>; MAX_4844_BLOBS_PER_BLOCK],
artifacts_callback_sender: SyncSender<WitnessGenerationArtifact>,
Expand Down
4 changes: 3 additions & 1 deletion crates/zkevm_test_harness/src/tests/complex_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@ pub(crate) fn generate_base_layer(
let artifacts_receiver_handle = thread::spawn(move || {
while let Ok(artifact) = receiver.recv() {
match artifact {
WitnessGenerationArtifact::BaseLayerCircuit(circuit) => basic_block_circuits.push(circuit),
WitnessGenerationArtifact::BaseLayerCircuit(circuit) => {
basic_block_circuits.push(circuit)
}
WitnessGenerationArtifact::RecursionQueue((a, b, c)) => recursion_queues.push((
a,
b,
Expand Down
6 changes: 4 additions & 2 deletions crates/zkevm_test_harness/src/tests/run_manually.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,15 @@ pub(crate) fn run_with_options(entry_point_bytecode: Vec<[u8; 32]>, options: Opt
// we are using TestingTracer to track prints and exceptions inside out_of_circuit_vm cycles
let mut out_of_circuit_tracer =
TestingTracer::new(Some(storage_impl.create_refund_controller()));

let (sender, receiver) = sync_channel(1);

let artifacts_receiver_handle = thread::spawn(move || {
while let Ok(artifact) = receiver.recv() {
match artifact {
WitnessGenerationArtifact::BaseLayerCircuit(circuit) => basic_block_circuits.push(circuit),
WitnessGenerationArtifact::BaseLayerCircuit(circuit) => {
basic_block_circuits.push(circuit)
}
_ => {}
}
}
Expand Down
39 changes: 23 additions & 16 deletions crates/zkevm_test_harness/src/witness/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,29 +123,29 @@ pub struct MemoryArtifacts<F: SmallField> {
#[derive(Derivative)]
#[derivative(Default)]
pub(crate) struct LogCircuitsArtifacts<F: SmallField> {
pub storage_application_artifacts:(
pub storage_application_artifacts: (
FirstAndLastCircuitWitness<StorageApplicationObservableWitness<F>>,
Vec<ClosedFormInputCompactFormWitness<F>>
Vec<ClosedFormInputCompactFormWitness<F>>,
),
pub storage_deduplicator_artifacts: (
FirstAndLastCircuitWitness<StorageDeduplicatorObservableWitness<F>>,
Vec<ClosedFormInputCompactFormWitness<F>>
Vec<ClosedFormInputCompactFormWitness<F>>,
),
pub events_deduplicator_artifacts: (
FirstAndLastCircuitWitness<EventsDeduplicatorObservableWitness<F>>,
Vec<ClosedFormInputCompactFormWitness<F>>
Vec<ClosedFormInputCompactFormWitness<F>>,
),
pub l1_messages_deduplicator_artifacts: (
pub l1_messages_deduplicator_artifacts: (
FirstAndLastCircuitWitness<EventsDeduplicatorObservableWitness<F>>,
Vec<ClosedFormInputCompactFormWitness<F>>
Vec<ClosedFormInputCompactFormWitness<F>>,
),
pub transient_storage_sorter_artifacts: (
FirstAndLastCircuitWitness<TransientStorageDeduplicatorObservableWitness<F>>,
Vec<ClosedFormInputCompactFormWitness<F>>
Vec<ClosedFormInputCompactFormWitness<F>>,
),
pub l1_messages_linear_hash_artifacts:(
pub l1_messages_linear_hash_artifacts: (
FirstAndLastCircuitWitness<LinearHasherObservableWitness<F>>,
Vec<ClosedFormInputCompactFormWitness<F>>
Vec<ClosedFormInputCompactFormWitness<F>>,
),
}

Expand All @@ -154,33 +154,40 @@ pub(crate) struct LogCircuitsArtifacts<F: SmallField> {
pub(crate) struct MemoryCircuitsArtifacts<F: SmallField> {
pub ram_permutation_artifacts: (
FirstAndLastCircuitWitness<RamPermutationObservableWitness<F>>,
Vec<ClosedFormInputCompactFormWitness<F>>
Vec<ClosedFormInputCompactFormWitness<F>>,
),
pub code_decommitter_artifacts: (
FirstAndLastCircuitWitness<CodeDecommitterObservableWitness<F>>,
Vec<ClosedFormInputCompactFormWitness<F>>
Vec<ClosedFormInputCompactFormWitness<F>>,
),
pub keccak256_circuits_data: (
FirstAndLastCircuitWitness<Keccak256RoundFunctionObservableWitness<F>>,
Vec<ClosedFormInputCompactFormWitness<F>>
Vec<ClosedFormInputCompactFormWitness<F>>,
),
pub sha256_circuits_data: (
FirstAndLastCircuitWitness<Sha256RoundFunctionObservableWitness<F>>,
Vec<ClosedFormInputCompactFormWitness<F>>
Vec<ClosedFormInputCompactFormWitness<F>>,
),
pub ecrecover_circuits_data: (
FirstAndLastCircuitWitness<EcrecoverObservableWitness<F>>,
Vec<ClosedFormInputCompactFormWitness<F>>
Vec<ClosedFormInputCompactFormWitness<F>>,
),
pub secp256r1_verify_circuits_data: (
FirstAndLastCircuitWitness<Secp256r1VerifyObservableWitness<F>>,
Vec<ClosedFormInputCompactFormWitness<F>>
Vec<ClosedFormInputCompactFormWitness<F>>,
),
}

use crate::witness::aux_data_structs::one_per_circuit_accumulator::LastPerCircuitAccumulator;

use super::postprocessing::observable_witness::{CodeDecommitterObservableWitness, EcrecoverObservableWitness, EventsDeduplicatorObservableWitness, Keccak256RoundFunctionObservableWitness, LinearHasherObservableWitness, RamPermutationObservableWitness, Secp256r1VerifyObservableWitness, Sha256RoundFunctionObservableWitness, StorageApplicationObservableWitness, StorageDeduplicatorObservableWitness, TransientStorageDeduplicatorObservableWitness};
use super::postprocessing::observable_witness::{
CodeDecommitterObservableWitness, EcrecoverObservableWitness,
EventsDeduplicatorObservableWitness, Keccak256RoundFunctionObservableWitness,
LinearHasherObservableWitness, RamPermutationObservableWitness,
Secp256r1VerifyObservableWitness, Sha256RoundFunctionObservableWitness,
StorageApplicationObservableWitness, StorageDeduplicatorObservableWitness,
TransientStorageDeduplicatorObservableWitness,
};
use super::postprocessing::FirstAndLastCircuitWitness;

#[derive(Derivative)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,13 @@ pub(crate) fn process_logs_demux_and_make_circuits(
{
let (log_demux_circuits, queue_simulator, log_demux_circuits_compact_forms_witnesses) =
maker.into_results();
artifacts_callback_sender.send(WitnessGenerationArtifact::RecursionQueue((
circuit_type as u64,
queue_simulator,
log_demux_circuits_compact_forms_witnesses.clone(),
))).unwrap();
artifacts_callback_sender
.send(WitnessGenerationArtifact::RecursionQueue((
circuit_type as u64,
queue_simulator,
log_demux_circuits_compact_forms_witnesses.clone(),
)))
.unwrap();

let (io_queues_states, precompiles_queues_states) =
DemuxedQueuesStatesSimulator::build_empty(*round_function);
Expand Down Expand Up @@ -389,18 +391,22 @@ pub(crate) fn process_logs_demux_and_make_circuits(
}
previous_hidden_fsm_output = Some(witness.closed_form_input.hidden_fsm_output.clone());

artifacts_callback_sender.send(WitnessGenerationArtifact::BaseLayerCircuit(
ZkSyncBaseLayerCircuit::LogDemuxer(maker.process(witness, circuit_type)),
)).unwrap();
artifacts_callback_sender
.send(WitnessGenerationArtifact::BaseLayerCircuit(
ZkSyncBaseLayerCircuit::LogDemuxer(maker.process(witness, circuit_type)),
))
.unwrap();
}

let (log_demux_circuits, queue_simulator, log_demux_circuits_compact_forms_witnesses) =
maker.into_results();
artifacts_callback_sender.send(WitnessGenerationArtifact::RecursionQueue((
circuit_type as u64,
queue_simulator,
log_demux_circuits_compact_forms_witnesses.clone(),
))).unwrap();
artifacts_callback_sender
.send(WitnessGenerationArtifact::RecursionQueue((
circuit_type as u64,
queue_simulator,
log_demux_circuits_compact_forms_witnesses.clone(),
)))
.unwrap();

for (sub_queue, mut iter) in queries_iterators {
assert!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,9 @@ pub(crate) fn process_main_vm(
FirstAndLastCircuitWitness<VmObservableWitness<GoldilocksField>>,
Vec<ClosedFormInputCompactFormWitness<GoldilocksField>>,
) {
let mut instances_witnesses: Vec<VmInstanceWitness<GoldilocksField, VmWitnessOracle<GoldilocksField>>> = vec![];
let mut instances_witnesses: Vec<
VmInstanceWitness<GoldilocksField, VmWitnessOracle<GoldilocksField>>,
> = vec![];

let main_vm_inputs = repack_input_for_main_vm(
geometry,
Expand All @@ -368,7 +370,6 @@ pub(crate) fn process_main_vm(
for ((circuit_idx, pair), main_vm_input) in
vm_snapshots.windows(2).enumerate().zip(main_vm_inputs)
{

let is_last = circuit_idx == circuits_len - 1;

let initial_state = &pair[0];
Expand Down Expand Up @@ -463,13 +464,15 @@ pub(crate) fn process_main_vm(
let mut main_vm_circuits = FirstAndLastCircuitWitness::default();
let mut main_vm_circuits_compact_forms_witnesses = vec![];
let mut queue_simulator = RecursionQueueSimulator::empty();

let observable_input = vm_instance_witness_to_circuit_formal_input(
instances_witnesses.first().unwrap().clone(),
true,
instances_witnesses.len() == 1,
in_circuit_global_context.clone(),
).closed_form_input.observable_input;
)
.closed_form_input
.observable_input;

let instances_len = instances_witnesses.len();
for (index, vm_instance) in instances_witnesses.into_iter().enumerate() {
Expand Down Expand Up @@ -523,17 +526,21 @@ pub(crate) fn process_main_vm(
),
public_input: proof_system_input,
};

queue_simulator.push(recursive_request, &round_function);
artifacts_callback_sender.send(WitnessGenerationArtifact::BaseLayerCircuit(instance)).unwrap();
artifacts_callback_sender
.send(WitnessGenerationArtifact::BaseLayerCircuit(instance))
.unwrap();
main_vm_circuits_compact_forms_witnesses.push(compact_form_witness);
}

artifacts_callback_sender.send(WitnessGenerationArtifact::RecursionQueue((
BaseLayerCircuitType::VM as u64,
queue_simulator,
main_vm_circuits_compact_forms_witnesses.clone(),
))).unwrap();
artifacts_callback_sender
.send(WitnessGenerationArtifact::RecursionQueue((
BaseLayerCircuitType::VM as u64,
queue_simulator,
main_vm_circuits_compact_forms_witnesses.clone(),
)))
.unwrap();

(main_vm_circuits, main_vm_circuits_compact_forms_witnesses)
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,15 @@ pub(crate) fn compute_ram_circuit_snapshots(
let mut rhs_grand_product_chains =
Vec::with_capacity(DEFAULT_NUM_PERMUTATION_ARGUMENT_REPETITIONS);
{
let lhs_contributions: Vec<_> = all_memory_queries.par_iter().map(|x| x.encoding_witness()).collect();
let rhs_contributions: Vec<_> = sorted_memory_queries_indexes.into_par_iter().map(|x| lhs_contributions[x]).collect();

let lhs_contributions: Vec<_> = all_memory_queries
.par_iter()
.map(|x| x.encoding_witness())
.collect();
let rhs_contributions: Vec<_> = sorted_memory_queries_indexes
.into_par_iter()
.map(|x| lhs_contributions[x])
.collect();

let challenges = produce_fs_challenges::<
Field,
RoundFunction,
Expand Down Expand Up @@ -396,9 +402,13 @@ pub(crate) fn compute_ram_circuit_snapshots(
tmp.current_sorted_queue_state.clone(),
);

artifacts_callback_sender.send(WitnessGenerationArtifact::BaseLayerCircuit(
ZkSyncBaseLayerCircuit::RAMPermutation(maker.process(instance_witness, circuit_type)),
)).unwrap();
artifacts_callback_sender
.send(WitnessGenerationArtifact::BaseLayerCircuit(
ZkSyncBaseLayerCircuit::RAMPermutation(
maker.process(instance_witness, circuit_type),
),
))
.unwrap();
}

drop(lhs_grand_product_chains);
Expand All @@ -409,11 +419,13 @@ pub(crate) fn compute_ram_circuit_snapshots(
queue_simulator,
ram_permutation_circuits_compact_forms_witnesses,
) = maker.into_results();
artifacts_callback_sender.send(WitnessGenerationArtifact::RecursionQueue((
circuit_type as u64,
queue_simulator,
ram_permutation_circuits_compact_forms_witnesses.clone(),
))).unwrap();
artifacts_callback_sender
.send(WitnessGenerationArtifact::RecursionQueue((
circuit_type as u64,
queue_simulator,
ram_permutation_circuits_compact_forms_witnesses.clone(),
)))
.unwrap();

(
ram_permutation_circuits,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ pub(crate) fn secp256r1_verify_decompose_into_per_circuit_witness<
drop(demuxed_secp256r1_verify_queue.states_accumulator);
assert!(precompile_calls.len() == round_function_witness.len());



if precompile_calls.len() == 0 {
return vec![];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,21 +255,25 @@ pub(crate) fn decompose_into_storage_application_witnesses(

initial_fsm_state = final_fsm_state.clone();

artifacts_callback_sender.send(WitnessGenerationArtifact::BaseLayerCircuit(
ZkSyncBaseLayerCircuit::StorageApplication(maker.process(input, circuit_type)),
)).unwrap();
artifacts_callback_sender
.send(WitnessGenerationArtifact::BaseLayerCircuit(
ZkSyncBaseLayerCircuit::StorageApplication(maker.process(input, circuit_type)),
))
.unwrap();
}

let (
storage_application_circuits,
queue_simulator,
storage_application_circuits_compact_forms_witnesses,
) = maker.into_results();
artifacts_callback_sender.send(WitnessGenerationArtifact::RecursionQueue((
circuit_type as u64,
queue_simulator,
storage_application_circuits_compact_forms_witnesses.clone(),
))).unwrap();
artifacts_callback_sender
.send(WitnessGenerationArtifact::RecursionQueue((
circuit_type as u64,
queue_simulator,
storage_application_circuits_compact_forms_witnesses.clone(),
)))
.unwrap();

tracing::debug!(
"Final enumeration index = {}",
Expand Down
Loading

0 comments on commit a89d429

Please sign in to comment.