Skip to content

Commit

Permalink
fix PR comments 2
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislavBreadless committed Nov 6, 2023
1 parent 7360070 commit 155dea7
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub struct Refunds {
pub struct VmExecutionLogs {
pub storage_logs: Vec<StorageLogQuery>,
pub events: Vec<VmEvent>,
// For pre-boojum VMs, there was no distinction between user logs and system
// logs and so all the outputted logs were treated as user_l2_to_l1_logs.
pub user_l2_to_l1_logs: Vec<L2ToL1Log>,
pub system_l2_to_l1_logs: Vec<L2ToL1Log>,
// This field moved to statistics, but we need to keep it for backward compatibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ pub struct CurrentExecutionState {
pub used_contract_hashes: Vec<U256>,
/// L2 to L1 logs produced by the VM.
pub system_logs: Vec<L2ToL1Log>,
/// L2 to L1 logs produced by the L1Messeger
/// L2 to L1 logs produced by the L1Messeger.
/// For pre-boojum VMs, there was no distinction between user logs and system
/// logs and so all the outputted logs were treated as user_l2_to_l1_logs.
pub user_l2_to_l1_logs: Vec<L2ToL1Log>,
/// Number of log queries produced by the VM. Including l2_to_l1 logs, storage logs and events.
pub total_log_queries: usize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub(crate) struct BootloaderStateSnapshot {
/// Current offset of the free space in the bootloader memory.
pub(crate) free_tx_offset: usize,
/// Whether the pubdata information has been provided already
pub(crate) pubdata_information: bool,
pub(crate) is_pubdata_information_provided: bool,
}

#[derive(Debug, Clone)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl BootloaderState {
last_l2_block: self.last_l2_block().make_snapshot(),
compressed_bytecodes_encoding: self.compressed_bytecodes_encoding,
free_tx_offset: self.free_tx_offset,
pubdata_information: self.pubdata_information.get().is_some(),
is_pubdata_information_provided: self.pubdata_information.get().is_some(),
}
}

Expand All @@ -271,12 +271,15 @@ impl BootloaderState {
self.last_mut_l2_block()
.apply_snapshot(snapshot.last_l2_block);

if !snapshot.pubdata_information {
if !snapshot.is_pubdata_information_provided {
self.pubdata_information = Default::default();
} else {
// Under the correct usage of the snapshots of the bootloader state,
// this assertion should never fail, i.e. since the pubdata information
// can be set only once. However, we have this assertion just in case.
assert!(
self.pubdata_information.get().is_some(),
"Can not use snapshot from future"
"Snapshot with no pubdata can not rollback to snapshot with one"
);
}
}
Expand Down
19 changes: 14 additions & 5 deletions core/lib/multivm/src/versions/vm_latest/bootloader_state/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use crate::interface::{BootloaderMemory, TxExecutionMode};
use crate::vm_latest::bootloader_state::l2_block::BootloaderL2Block;
use crate::vm_latest::constants::{
BOOTLOADER_TX_DESCRIPTION_OFFSET, BOOTLOADER_TX_DESCRIPTION_SIZE, COMPRESSED_BYTECODES_OFFSET,
OPERATOR_PROVIDED_L1_MESSENGER_PUBDATA_OFFSET, OPERATOR_REFUNDS_OFFSET, TX_DESCRIPTION_OFFSET,
TX_OPERATOR_L2_BLOCK_INFO_OFFSET, TX_OPERATOR_SLOTS_PER_L2_BLOCK_INFO, TX_OVERHEAD_OFFSET,
TX_TRUSTED_GAS_LIMIT_OFFSET,
OPERATOR_PROVIDED_L1_MESSENGER_PUBDATA_OFFSET, OPERATOR_PROVIDED_L1_MESSENGER_PUBDATA_SLOTS,
OPERATOR_REFUNDS_OFFSET, TX_DESCRIPTION_OFFSET, TX_OPERATOR_L2_BLOCK_INFO_OFFSET,
TX_OPERATOR_SLOTS_PER_L2_BLOCK_INFO, TX_OVERHEAD_OFFSET, TX_TRUSTED_GAS_LIMIT_OFFSET,
};
use crate::vm_latest::types::internals::pubdata::PubdataInput;

Expand Down Expand Up @@ -116,10 +116,19 @@ pub(crate) fn apply_pubdata_to_memory(
memory: &mut BootloaderMemory,
pubdata_information: PubdataInput,
) {
// Skipping two slots as they will be filled by the bootloader itself:
// - One slot is for the selector of the call to the L1Messenger.
// - The other slot is for the 0x20 offset for the calldata.
let l1_messenger_pubdata_start_slot = OPERATOR_PROVIDED_L1_MESSENGER_PUBDATA_OFFSET + 2;

pubdata_information
.build_pubdata()
let pubdata = pubdata_information.build_pubdata();

assert!(
pubdata.len() / 32 <= OPERATOR_PROVIDED_L1_MESSENGER_PUBDATA_SLOTS - 2,
"The encoded pubdata is too big"
);

pubdata
.chunks(32)
.enumerate()
.for_each(|(slot_offset, value)| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<S: WriteStorage, H: HistoryMode> Vm<S, H> {
let storage_logs_count = storage_logs.len();

let (events, system_l2_to_l1_logs) =
self.collect_events_and_l1_logs_after_timestamp(from_timestamp);
self.collect_events_and_l1_system_logs_after_timestamp(from_timestamp);

let log_queries = self
.state
Expand All @@ -52,11 +52,11 @@ impl<S: WriteStorage, H: HistoryMode> Vm<S, H> {
}
}

pub(crate) fn collect_events_and_l1_logs_after_timestamp(
pub(crate) fn collect_events_and_l1_system_logs_after_timestamp(
&self,
from_timestamp: Timestamp,
) -> (Vec<VmEvent>, Vec<L2ToL1Log>) {
logs::collect_events_and_l1_logs_after_timestamp(
logs::collect_events_and_l1_system_logs_after_timestamp(
&self.state,
&self.batch_env,
from_timestamp,
Expand Down
24 changes: 16 additions & 8 deletions core/lib/multivm/src/versions/vm_latest/tracers/pubdata_tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::vm_latest::tracers::{
utils::VmHook,
};
use crate::vm_latest::types::internals::ZkSyncVmState;
use crate::vm_latest::utils::logs::collect_events_and_l1_logs_after_timestamp;
use crate::vm_latest::utils::logs::collect_events_and_l1_system_logs_after_timestamp;
use crate::{
interface::VmExecutionMode,
vm_latest::bootloader_state::{utils::apply_pubdata_to_memory, BootloaderState},
Expand Down Expand Up @@ -59,8 +59,11 @@ impl PubdataTracer {
&self,
state: &ZkSyncVmState<S, H>,
) -> Vec<L1MessengerL2ToL1Log> {
let (all_generated_events, _) =
collect_events_and_l1_logs_after_timestamp(state, &self.l1_batch_env, Timestamp(0));
let (all_generated_events, _) = collect_events_and_l1_system_logs_after_timestamp(
state,
&self.l1_batch_env,
Timestamp(0),
);
extract_l2tol1logs_from_l1_messenger(&all_generated_events)
}

Expand All @@ -70,8 +73,11 @@ impl PubdataTracer {
&self,
state: &ZkSyncVmState<S, H>,
) -> Vec<Vec<u8>> {
let (all_generated_events, _) =
collect_events_and_l1_logs_after_timestamp(state, &self.l1_batch_env, Timestamp(0));
let (all_generated_events, _) = collect_events_and_l1_system_logs_after_timestamp(
state,
&self.l1_batch_env,
Timestamp(0),
);

extract_long_l2_to_l1_messages(&all_generated_events)
}
Expand All @@ -82,8 +88,11 @@ impl PubdataTracer {
&self,
state: &ZkSyncVmState<S, H>,
) -> Vec<Vec<u8>> {
let (all_generated_events, _) =
collect_events_and_l1_logs_after_timestamp(state, &self.l1_batch_env, Timestamp(0));
let (all_generated_events, _) = collect_events_and_l1_system_logs_after_timestamp(
state,
&self.l1_batch_env,
Timestamp(0),
);

let bytecode_publication_requests =
extract_bytecode_publication_requests_from_l1_messenger(&all_generated_events);
Expand Down Expand Up @@ -185,7 +194,6 @@ impl<S: WriteStorage, H: HistoryMode> VmTracer<S, H> for PubdataTracer {
}

if self.pubdata_info_requested {
// Whenever we are executing the block tip, we want to avoid publishing the full pubdata
let pubdata_input = self.build_pubdata_input(state);

// Save the pubdata for the future initial bootloader memory building
Expand Down
2 changes: 1 addition & 1 deletion core/lib/multivm/src/versions/vm_latest/utils/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
vm_latest::old_vm::history_recorder::HistoryMode, vm_latest::types::internals::ZkSyncVmState,
};

pub(crate) fn collect_events_and_l1_logs_after_timestamp<S: WriteStorage, H: HistoryMode>(
pub(crate) fn collect_events_and_l1_system_logs_after_timestamp<S: WriteStorage, H: HistoryMode>(
vm_state: &ZkSyncVmState<S, H>,
batch_env: &L1BatchEnv,
from_timestamp: Timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,6 @@ impl RequestProcessor {

let mut storage = self.pool.access_storage().await.unwrap();

// let header = storage
// .blocks_dal()
// .get_l1_batch_header(l1_batch_number)
// .await
// .unwrap()
// .expect("Proved block without a header");

let l1_batch = storage
.blocks_dal()
.get_l1_batch_metadata(l1_batch_number)
Expand Down

0 comments on commit 155dea7

Please sign in to comment.