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

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov committed Jul 23, 2024
1 parent a5b2605 commit c692816
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 42 deletions.
7 changes: 0 additions & 7 deletions src/witness/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,6 @@ pub struct MemoryArtifacts<F: SmallField> {
CircuitsEntryAccumulatorSparse<(u32, QueueStateWitness<F, FULL_SPONGE_QUEUE_STATE_WIDTH>)>,
}

#[derive(Derivative)]
#[derivative(Default)]
pub struct ImplicitMemoryArtifacts<F: SmallField> {
pub memory_queries: Vec<MemoryQuery>,
pub memory_queue_states: Vec<MemoryQueueState<F>>,
}

#[derive(Derivative)]
#[derivative(Default)]
pub struct LogCircuitsArtifacts<F: SmallField> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::zk_evm::ethereum_types::U256;
use crate::zkevm_circuits::base_structures::decommit_query::DecommitQueryWitness;
use crate::zkevm_circuits::base_structures::decommit_query::DECOMMIT_QUERY_PACKED_WIDTH;
use crate::zkevm_circuits::code_unpacker_sha256::input::*;
use artifacts::ImplicitMemoryArtifacts;
use circuit_definitions::encodings::decommittment_request::normalized_preimage_as_u256;
use circuit_definitions::encodings::decommittment_request::DecommittmentQueueSimulator;
use circuit_definitions::encodings::decommittment_request::DecommittmentQueueState;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use crate::witness::artifacts::{DemuxedLogQueries, ImplicitMemoryArtifacts, LogQueueStates};
use crate::witness::artifacts::{DemuxedLogQueries, LogQueueStates};
use crate::witness::aux_data_structs::one_per_circuit_accumulator::LastPerCircuitAccumulator;
use crate::witness::aux_data_structs::MemoryQueuePerCircuitSimulator;
use crate::zk_evm::aux_structures::LogQuery as LogQuery_;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use crate::witness::artifacts::{DemuxedLogQueries, ImplicitMemoryArtifacts, LogQueueStates};
use crate::witness::artifacts::{DemuxedLogQueries, LogQueueStates};
use crate::witness::aux_data_structs::one_per_circuit_accumulator::LastPerCircuitAccumulator;
use crate::witness::aux_data_structs::MemoryQueuePerCircuitSimulator;
use crate::zk_evm::aux_structures::LogQuery as LogQuery_;
Expand Down
23 changes: 4 additions & 19 deletions src/witness/individual_circuits/memory_related/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,25 +156,6 @@ impl<F: SmallField> ImplicitMemoryStates<F> {
+ self.secp256r1_memory_states.len()
+ self.sha256_memory_states.len()
}

fn get_vectors(&self) -> [&Vec<MemoryQueueState<F>>; 5] {
[
&self.decommitter_memory_states,
&self.keccak256_memory_states,
&self.sha256_memory_states,
&self.ecrecover_memory_states,
&self.secp256r1_memory_states,
]
}

pub fn iter(&self) -> ImplicitMemoryStatesIter<F> {
let mut outer_iter = self.get_vectors().into_iter();
let last_vector_iter = outer_iter.next().unwrap().iter();
ImplicitMemoryStatesIter {
last_vector: last_vector_iter,
outer_iter,
}
}
}

use core::array::IntoIter as ArrayIntoIter;
Expand Down Expand Up @@ -215,11 +196,14 @@ fn get_simulator_snapshot<F: SmallField>(
}
}

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

pub(crate) fn simulate_implicit_memory_queues<
F: SmallField,
R: BuildableCircuitRoundFunction<F, 8, 12, 4> + AlgebraicRoundFunction<F, 8, 12, 4>,
>(
memory_queue_simulator: &mut MemoryQueuePerCircuitSimulator<F>,
memory_queue_states_accumulator: &mut LastPerCircuitAccumulator<MemoryQueueState<F>>,
implicit_memory_queries: &ImplicitMemoryQueries,
round_function: R,
) -> ImplicitMemoryStates<F> {
Expand All @@ -234,6 +218,7 @@ pub(crate) fn simulate_implicit_memory_queues<
.push_and_output_intermediate_data(*query, &round_function);

memory_states.push(intermediate_info);
memory_queue_states_accumulator.push(intermediate_info);
}
snapshots.push(get_simulator_snapshot(memory_queue_simulator)); // after

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::zk_evm::ethereum_types::U256;
use crate::zkevm_circuits::{
base_structures::memory_query::MEMORY_QUERY_PACKED_WIDTH, ram_permutation::input::*,
};
use artifacts::{ImplicitMemoryArtifacts, MemoryArtifacts};
use artifacts::MemoryArtifacts;
use circuit_definitions::circuit_definitions::base_layer::{
RAMPermutationInstanceSynthesisFunction, ZkSyncBaseLayerCircuit,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use crate::witness::artifacts::{DemuxedLogQueries, ImplicitMemoryArtifacts, LogQueueStates};
use crate::witness::artifacts::{DemuxedLogQueries, LogQueueStates};
use crate::witness::aux_data_structs::one_per_circuit_accumulator::LastPerCircuitAccumulator;
use crate::witness::aux_data_structs::MemoryQueuePerCircuitSimulator;
use crate::zk_evm::aux_structures::LogQuery as LogQuery_;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;
use crate::boojum::gadgets::traits::allocatable::CSAllocatable;
use crate::witness::artifacts::{DemuxedLogQueries, ImplicitMemoryArtifacts, LogQueueStates};
use crate::witness::artifacts::{DemuxedLogQueries, LogQueueStates};
use crate::witness::aux_data_structs::one_per_circuit_accumulator::LastPerCircuitAccumulator;
use crate::witness::aux_data_structs::MemoryQueuePerCircuitSimulator;
use crate::zk_evm::aux_structures::LogQuery as LogQuery_;
Expand Down
13 changes: 3 additions & 10 deletions src/witness/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::boojum::gadgets::traits::allocatable::CSAllocatable;
use crate::ethereum_types::U256;
use crate::toolset::GeometryConfig;
use crate::witness::artifacts::{
DemuxedLogQueries, ImplicitMemoryArtifacts, MemoryArtifacts, MemoryCircuitsArtifacts,
DemuxedLogQueries, MemoryArtifacts, MemoryCircuitsArtifacts,
};
use crate::witness::aux_data_structs::one_per_circuit_accumulator::{
CircuitsEntryAccumulatorSparse, LastPerCircuitAccumulator,
Expand Down Expand Up @@ -893,16 +893,11 @@ fn simulate_memory_queue(
use crate::witness::individual_circuits::memory_related::simulate_implicit_memory_queues;
let implicit_memory_states = simulate_implicit_memory_queues(
&mut memory_queue_simulator,
&mut memory_queue_states_accumulator,
&implicit_memory_queries,
round_function,
);

// push implicit queries
memory_queue_states_accumulator.reserve_exact_flat(implicit_memory_states.amount_of_states());
for state in implicit_memory_states.iter() {
memory_queue_states_accumulator.push(*state);
}

(
memory_artifacts_for_main_vm,
final_explicit_memory_queue_state,
Expand Down Expand Up @@ -1095,10 +1090,8 @@ fn process_memory_related_circuits<
// direct VM related part is done, other subcircuit's functionality is moved to other functions
// that should properly do sorts and memory writes

let amount_of_implicit_queries = implicit_memory_queries.amount_of_queries();

assert_eq!(
amount_of_implicit_queries,
implicit_memory_queries.amount_of_queries(),
implicit_memory_states.amount_of_states()
);

Expand Down

0 comments on commit c692816

Please sign in to comment.