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

Commit

Permalink
inline everything into create_artifacts_from_tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
joonazan committed Jan 12, 2024
1 parent 12db8d7 commit 9b2bcc9
Show file tree
Hide file tree
Showing 5 changed files with 795 additions and 831 deletions.
32 changes: 3 additions & 29 deletions src/external_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ pub fn run<
geometry: GeometryConfig,
storage: S,
tree: &mut impl BinarySparseStorageTree<256, 32, 32, 8, 32, Blake2s256, ZkSyncStorageLeaf>,
mut circuit_callback: CB,
mut queue_simulator_callback: QSCB,
circuit_callback: CB,
queue_simulator_callback: QSCB,
) -> (
SchedulerCircuitInstanceWitness<MainField, H, EXT>,
BlockAuxilaryOutputWitness<MainField>,
Expand Down Expand Up @@ -230,7 +230,7 @@ pub fn run<

// dbg!(tools.witness_tracer.vm_snapshots.len());

let (instance_oracles, artifacts) = create_artifacts_from_tracer(
let (basic_circuits, compact_form_witnesses) = create_artifacts_from_tracer(
out_of_circuit_vm.witness_tracer,
&round_function,
&geometry,
Expand All @@ -240,34 +240,8 @@ pub fn run<
),
tree,
num_non_deterministic_heap_queries,
);

assert!(artifacts.special_initial_decommittment_queries.len() == 1);

// use sync_vm::scheduler::queues::SpongeLikeQueueStateWitness;
// let memory_state_after_bootloader_heap_writes = if num_non_deterministic_heap_queries == 0 {
// // empty
// SpongeLikeQueueStateWitness::<Bn256, 3>::empty()
// } else {
// let full_info = &artifacts.all_memory_queue_states[num_non_deterministic_heap_queries-1];
// let sponge_state = full_info.tail;
// let length = full_info.num_items;

// SpongeLikeQueueStateWitness::<Bn256, 3> {
// length,
// sponge_state
// }
// };

use crate::witness::postprocessing::create_leaf_level_circuits_and_scheduler_witness;

let (basic_circuits, compact_form_witnesses) = create_leaf_level_circuits_and_scheduler_witness(
zk_porter_is_available,
default_aa_code_hash,
instance_oracles,
artifacts,
geometry,
&round_function,
circuit_callback,
queue_simulator_callback,
);
Expand Down
249 changes: 0 additions & 249 deletions src/witness/full_block_artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ pub struct FullBlockArtifacts<F: SmallField> {
pub deduplicated_rollup_storage_queue_simulator: LogQueueSimulator<F>,
pub deduplicated_to_l1_queue_simulator: LogQueueSimulator<F>,

//
pub special_initial_decommittment_queries: Vec<(DecommittmentQuery, Vec<U256>)>,

// keep precompile round functions data
pub keccak_round_function_witnesses: Vec<(u32, LogQuery, Vec<Keccak256RoundWitness>)>,
pub sha256_round_function_witnesses: Vec<(u32, LogQuery, Vec<Sha256RoundWitness>)>,
Expand All @@ -84,8 +81,6 @@ pub struct FullBlockArtifacts<F: SmallField> {
pub ram_permutation_circuits_data: Vec<RamPermutationCircuitInstanceWitness<F>>,
// processed code decommitter circuits, as well as sorting circuit
pub code_decommitter_circuits_data: Vec<CodeDecommitterCircuitInstanceWitness<F>>,
pub decommittments_deduplicator_circuits_data:
Vec<CodeDecommittmentsDeduplicatorInstanceWitness<F>>,
//
pub log_demuxer_circuit_data: Vec<LogDemuxerCircuitInstanceWitness<F>>,
// IO related circuits
Expand All @@ -110,247 +105,3 @@ pub struct LogQueue<F: SmallField> {
pub states: Vec<LogQueueState<F>>,
pub simulator: LogQueueSimulator<F>,
}

use crate::boojum::algebraic_props::round_function::AlgebraicRoundFunction;
use crate::witness::tree::*;
use blake2::Blake2s256;

impl<F: SmallField> FullBlockArtifacts<F> {
pub fn process<
R: BuildableCircuitRoundFunction<F, 8, 12, 4> + AlgebraicRoundFunction<F, 8, 12, 4>,
>(
&mut self,
round_function: &R,
geometry: &GeometryConfig,
tree: &mut impl BinarySparseStorageTree<256, 32, 32, 8, 32, Blake2s256, ZkSyncStorageLeaf>,
num_non_deterministic_heap_queries: usize,
) {
// this is parallelizable internally by the factor of 3 in round function implementation later on

tracing::debug!("Running memory queue simulation");

for (cycle, query) in self.vm_memory_queries_accumulated.iter() {
self.all_memory_queries_accumulated.push(*query);

let (_old_tail, intermediate_info) = self
.memory_queue_simulator
.push_and_output_intermediate_data(*query, round_function);

self.vm_memory_queue_states
.push((*cycle, false, intermediate_info));
self.all_memory_queue_states.push(intermediate_info);
}

assert!(
self.memory_queue_simulator.num_items as usize
== self.vm_memory_queries_accumulated.len()
);

// ----------------------------

{
assert_eq!(
self.all_memory_queries_accumulated.len(),
self.all_memory_queue_states.len()
);
assert_eq!(
self.all_memory_queries_accumulated.len(),
self.memory_queue_simulator.num_items as usize
);
}

// ----------------------------

// direct VM related part is done, other subcircuit's functionality is moved to other functions
// that should properly do sorts and memory writes

use crate::witness::individual_circuits::sort_decommit_requests::compute_decommitts_sorter_circuit_snapshots;

tracing::debug!("Running code decommittments sorter simulation");

let mut deduplicated_decommitment_queue_simulator = Default::default();
let mut deduplicated_decommittment_queue_states = Default::default();
let mut deduplicated_decommit_requests_with_data = Default::default();

let decommittments_deduplicator_witness = compute_decommitts_sorter_circuit_snapshots(
self,
&mut deduplicated_decommitment_queue_simulator,
&mut deduplicated_decommittment_queue_states,
&mut deduplicated_decommit_requests_with_data,
round_function,
geometry.cycles_code_decommitter_sorter as usize,
);

self.decommittments_deduplicator_circuits_data = decommittments_deduplicator_witness;

use crate::witness::individual_circuits::decommit_code::compute_decommitter_circuit_snapshots;

tracing::debug!("Running code code decommitter simulation");

let code_decommitter_circuits_data = compute_decommitter_circuit_snapshots(
self,
&mut deduplicated_decommitment_queue_simulator,
&mut deduplicated_decommittment_queue_states,
&mut deduplicated_decommit_requests_with_data,
round_function,
geometry.cycles_per_code_decommitter as usize,
);

self.code_decommitter_circuits_data = code_decommitter_circuits_data;

// demux log queue
use crate::witness::individual_circuits::log_demux::compute_logs_demux;

tracing::debug!("Running log demux simulation");

let (
log_demuxer_witness,
demuxed_rollup_storage_queue,
demuxed_event_queue,
demuxed_to_l1_queue,
demuxed_keccak_precompile_queue,
demuxed_sha256_precompile_queue,
demuxed_ecrecover_queue,
) = compute_logs_demux(
self,
geometry.cycles_per_log_demuxer as usize,
round_function,
);

self.log_demuxer_circuit_data = log_demuxer_witness;

// keccak precompile

use crate::witness::individual_circuits::keccak256_round_function::keccak256_decompose_into_per_circuit_witness;

tracing::debug!("Running keccak simulation");

let keccak256_circuits_data = keccak256_decompose_into_per_circuit_witness(
self,
demuxed_keccak_precompile_queue,
geometry.cycles_per_keccak256_circuit as usize,
round_function,
);
self.keccak256_circuits_data = keccak256_circuits_data;

// sha256 precompile

use crate::witness::individual_circuits::sha256_round_function::sha256_decompose_into_per_circuit_witness;

tracing::debug!("Running sha256 simulation");

let sha256_circuits_data = sha256_decompose_into_per_circuit_witness(
self,
demuxed_sha256_precompile_queue,
geometry.cycles_per_sha256_circuit as usize,
round_function,
);
self.sha256_circuits_data = sha256_circuits_data;

// ecrecover precompile

use crate::witness::individual_circuits::ecrecover::ecrecover_decompose_into_per_circuit_witness;

tracing::debug!("Running ecrecover simulation");

let ecrecover_circuits_data = ecrecover_decompose_into_per_circuit_witness(
self,
demuxed_ecrecover_queue,
geometry.cycles_per_ecrecover_circuit as usize,
round_function,
);
self.ecrecover_circuits_data = ecrecover_circuits_data;

// we are done with a memory and can do the processing and breaking of the logical arguments into individual circits

use crate::witness::individual_circuits::ram_permutation::compute_ram_circuit_snapshots;

tracing::debug!("Running RAM permutation simulation");

let ram_permutation_circuits_data = compute_ram_circuit_snapshots(
self,
round_function,
num_non_deterministic_heap_queries,
geometry.cycles_per_ram_permutation as usize,
);

self.ram_permutation_circuits_data = ram_permutation_circuits_data;

// now completely parallel process to reconstruct the states, with internally parallelism in each round function

use crate::witness::individual_circuits::storage_sort_dedup::compute_storage_dedup_and_sort;

tracing::debug!("Running storage deduplication simulation");

let storage_deduplicator_circuit_data = compute_storage_dedup_and_sort(
self,
demuxed_rollup_storage_queue,
geometry.cycles_per_storage_sorter as usize,
round_function,
);
self.storage_deduplicator_circuit_data = storage_deduplicator_circuit_data;

use crate::witness::individual_circuits::events_sort_dedup::compute_events_dedup_and_sort;

tracing::debug!("Running events deduplication simulation");

let events_deduplicator_circuit_data = compute_events_dedup_and_sort(
&self.demuxed_event_queries,
&demuxed_event_queue,
&mut Default::default(),
geometry.cycles_per_events_or_l1_messages_sorter as usize,
round_function,
);

self.events_deduplicator_circuit_data = events_deduplicator_circuit_data;

tracing::debug!("Running L1 messages deduplication simulation");

let mut deduplicated_to_l1_queue_simulator = Default::default();
let l1_messages_deduplicator_circuit_data = compute_events_dedup_and_sort(
&self.demuxed_to_l1_queries,
&demuxed_to_l1_queue,
&mut deduplicated_to_l1_queue_simulator,
geometry.cycles_per_events_or_l1_messages_sorter as usize,
round_function,
);

self.l1_messages_deduplicator_circuit_data = l1_messages_deduplicator_circuit_data;

// compute flattened hash of all messages

tracing::debug!("Running L1 messages linear hash simulation");

assert!(
deduplicated_to_l1_queue_simulator.num_items
<= geometry.limit_for_l1_messages_pudata_hasher,
"too many L1 messages to linearly hash by single circuit"
);

use crate::witness::individual_circuits::data_hasher_and_merklizer::compute_linear_keccak256;

let l1_messages_pubdata_hasher_data = compute_linear_keccak256(
&deduplicated_to_l1_queue_simulator,
geometry.limit_for_l1_messages_pudata_hasher as usize,
round_function,
);

self.l1_messages_linear_hash_data = l1_messages_pubdata_hasher_data;

// process the storage application

// and do the actual storage application
use crate::witness::individual_circuits::storage_application::decompose_into_storage_application_witnesses;

let rollup_storage_application_circuit_data = decompose_into_storage_application_witnesses(
self,
tree,
round_function,
geometry.cycles_per_storage_application as usize,
);

self.rollup_storage_application_circuit_data = rollup_storage_application_circuit_data;

self.is_processed = true;
}
}
Loading

0 comments on commit 9b2bcc9

Please sign in to comment.