Skip to content

Commit

Permalink
Merge pull request #415 from matter-labs/sb-fixes-for-pr
Browse files Browse the repository at this point in the history
chore: Fixes to the boojum integration PR
  • Loading branch information
StanislavBreadless authored Nov 6, 2023
2 parents b4eaf7d + e728767 commit ac9c6e2
Show file tree
Hide file tree
Showing 56 changed files with 477 additions and 432 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions core/lib/config/src/configs/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ use zksync_basic_types::{Address, H256};
// Local uses
use super::envy_load;

#[derive(Debug, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum ProverAtGenesis {
Fri,
Old,
}

/// Data about deployed contracts.
#[derive(Debug, Deserialize, Clone, PartialEq)]
pub struct ContractsConfig {
Expand Down Expand Up @@ -34,7 +41,7 @@ pub struct ContractsConfig {
pub fri_recursion_scheduler_level_vk_hash: H256,
pub fri_recursion_node_level_vk_hash: H256,
pub fri_recursion_leaf_level_vk_hash: H256,
pub prover_at_genesis: String,
pub prover_at_genesis: ProverAtGenesis,
pub snark_wrapper_vk_hash: H256,
}

Expand Down Expand Up @@ -95,7 +102,7 @@ mod tests {
fri_recursion_leaf_level_vk_hash: hash(
"0x72167c43a46cf38875b267d67716edc4563861364a3c03ab7aee73498421e828",
),
prover_at_genesis: "fri".to_string(),
prover_at_genesis: ProverAtGenesis::Fri,
snark_wrapper_vk_hash: hash(
"0x4be443afd605a782b6e56d199df2460a025c81b3dea144e135bece83612563f2",
),
Expand Down
13 changes: 8 additions & 5 deletions core/lib/dal/src/blocks_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,12 @@ impl BlocksDal<'_, '_> {
let l2_to_l1_logs: Vec<_> = header
.l2_to_l1_logs
.iter()
.map(|log| log.to_bytes().to_vec())
.map(|log| log.0.to_bytes().to_vec())
.collect();
let system_logs = header
.system_logs
.iter()
.map(|log| log.to_bytes().to_vec())
.map(|log| log.0.to_bytes().to_vec())
.collect::<Vec<Vec<u8>>>();

// Serialization should always succeed.
Expand Down Expand Up @@ -1496,7 +1496,10 @@ impl BlocksDal<'_, '_> {
#[cfg(test)]
mod tests {
use zksync_contracts::BaseSystemContractsHashes;
use zksync_types::{l2_to_l1_log::L2ToL1Log, Address, ProtocolVersion, ProtocolVersionId};
use zksync_types::{
l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log},
Address, ProtocolVersion, ProtocolVersionId,
};

use super::*;
use crate::ConnectionPool;
Expand Down Expand Up @@ -1525,14 +1528,14 @@ mod tests {
);
header.l1_tx_count = 3;
header.l2_tx_count = 5;
header.l2_to_l1_logs.push(L2ToL1Log {
header.l2_to_l1_logs.push(UserL2ToL1Log(L2ToL1Log {
shard_id: 0,
is_service: false,
tx_number_in_block: 2,
sender: Address::repeat_byte(2),
key: H256::repeat_byte(3),
value: H256::zero(),
});
}));
header.l2_to_l1_messages.push(vec![22; 22]);
header.l2_to_l1_messages.push(vec![33; 33]);

Expand Down
32 changes: 17 additions & 15 deletions core/lib/dal/src/events_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use std::fmt;

use crate::{models::storage_event::StorageL2ToL1Log, SqlxError, StorageProcessor};
use zksync_types::{
l2_to_l1_log::L2ToL1Log, tx::IncludedTxLocation, MiniblockNumber, VmEvent, H256,
l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log},
tx::IncludedTxLocation,
MiniblockNumber, VmEvent, H256,
};

/// Wrapper around an optional event topic allowing to hex-format it for `COPY` instructions.
Expand Down Expand Up @@ -99,12 +101,12 @@ impl EventsDal<'_, '_> {
.unwrap();
}

/// Saves L2-to-L1 logs from a miniblock. Logs must be ordered by transaction location
/// Saves user L2-to-L1 logs from a miniblock. Logs must be ordered by transaction location
/// and within each transaction.
pub async fn save_l2_to_l1_logs(
pub async fn save_user_l2_to_l1_logs(
&mut self,
block_number: MiniblockNumber,
all_block_l2_to_l1_logs: &[(IncludedTxLocation, Vec<&L2ToL1Log>)],
all_block_l2_to_l1_logs: &[(IncludedTxLocation, Vec<&UserL2ToL1Log>)],
) {
let mut copy = self
.storage
Expand Down Expand Up @@ -139,7 +141,7 @@ impl EventsDal<'_, '_> {
sender,
key,
value,
} = log;
} = log.0;

write_str!(
&mut buffer,
Expand Down Expand Up @@ -273,15 +275,15 @@ mod tests {
}
}

fn create_l2_to_l1_log(tx_number_in_block: u16, index: u8) -> L2ToL1Log {
L2ToL1Log {
fn create_l2_to_l1_log(tx_number_in_block: u16, index: u8) -> UserL2ToL1Log {
UserL2ToL1Log(L2ToL1Log {
shard_id: 0,
is_service: false,
tx_number_in_block,
sender: Address::repeat_byte(index),
key: H256::from_low_u64_be(u64::from(index)),
value: H256::repeat_byte(index),
}
})
}

#[tokio::test]
Expand Down Expand Up @@ -324,7 +326,7 @@ mod tests {
(second_location, second_logs.iter().collect()),
];
conn.events_dal()
.save_l2_to_l1_logs(MiniblockNumber(1), &all_logs)
.save_user_l2_to_l1_logs(MiniblockNumber(1), &all_logs)
.await;

let logs = conn
Expand All @@ -338,9 +340,9 @@ mod tests {
assert_eq!(log.log_index_in_tx as usize, i);
}
for (log, expected_log) in logs.iter().zip(&first_logs) {
assert_eq!(log.key, expected_log.key.as_bytes());
assert_eq!(log.value, expected_log.value.as_bytes());
assert_eq!(log.sender, expected_log.sender.as_bytes());
assert_eq!(log.key, expected_log.0.key.as_bytes());
assert_eq!(log.value, expected_log.0.value.as_bytes());
assert_eq!(log.sender, expected_log.0.sender.as_bytes());
}

let logs = conn
Expand All @@ -354,9 +356,9 @@ mod tests {
assert_eq!(log.log_index_in_tx as usize, i);
}
for (log, expected_log) in logs.iter().zip(&second_logs) {
assert_eq!(log.key, expected_log.key.as_bytes());
assert_eq!(log.value, expected_log.value.as_bytes());
assert_eq!(log.sender, expected_log.sender.as_bytes());
assert_eq!(log.key, expected_log.0.key.as_bytes());
assert_eq!(log.value, expected_log.0.value.as_bytes());
assert_eq!(log.sender, expected_log.0.sender.as_bytes());
}
}
}
24 changes: 9 additions & 15 deletions core/lib/dal/src/models/storage_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use zksync_types::{
api,
block::{L1BatchHeader, MiniblockHeader},
commitment::{L1BatchMetaParameters, L1BatchMetadata},
l2_to_l1_log::L2ToL1Log,
l2_to_l1_log::{L2ToL1Log, SystemL2ToL1Log, UserL2ToL1Log},
Address, L1BatchNumber, MiniblockNumber, H2048, H256,
};

Expand Down Expand Up @@ -61,11 +61,8 @@ impl From<StorageL1BatchHeader> for L1BatchHeader {
.map(|raw_data| raw_data.into())
.collect();

let system_logs: Vec<_> = l1_batch
.system_logs
.into_iter()
.map(|raw_log| L2ToL1Log::from_slice(&raw_log))
.collect();
let system_logs = convert_l2_to_l1_logs(l1_batch.system_logs);
let user_l2_to_l1_logs = convert_l2_to_l1_logs(l1_batch.l2_to_l1_logs);

L1BatchHeader {
number: L1BatchNumber(l1_batch.number as u32),
Expand All @@ -75,7 +72,7 @@ impl From<StorageL1BatchHeader> for L1BatchHeader {
priority_ops_onchain_data,
l1_tx_count: l1_batch.l1_tx_count as u16,
l2_tx_count: l1_batch.l2_tx_count as u16,
l2_to_l1_logs: convert_l2_to_l1_logs(l1_batch.l2_to_l1_logs),
l2_to_l1_logs: user_l2_to_l1_logs.into_iter().map(UserL2ToL1Log).collect(),
l2_to_l1_messages: l1_batch.l2_to_l1_messages,

bloom: H2048::from_slice(&l1_batch.bloom),
Expand All @@ -91,7 +88,7 @@ impl From<StorageL1BatchHeader> for L1BatchHeader {
),
l1_gas_price: l1_batch.l1_gas_price as u64,
l2_fair_gas_price: l1_batch.l2_fair_gas_price as u64,
system_logs,
system_logs: system_logs.into_iter().map(SystemL2ToL1Log).collect(),
protocol_version: l1_batch
.protocol_version
.map(|v| (v as u16).try_into().unwrap()),
Expand Down Expand Up @@ -183,11 +180,8 @@ impl From<StorageL1Batch> for L1BatchHeader {
.map(Vec::into)
.collect();

let system_logs: Vec<_> = l1_batch
.system_logs
.into_iter()
.map(|raw_log| L2ToL1Log::from_slice(&raw_log))
.collect();
let system_logs = convert_l2_to_l1_logs(l1_batch.system_logs);
let user_l2_to_l1_logs = convert_l2_to_l1_logs(l1_batch.l2_to_l1_logs);

L1BatchHeader {
number: L1BatchNumber(l1_batch.number as u32),
Expand All @@ -197,7 +191,7 @@ impl From<StorageL1Batch> for L1BatchHeader {
priority_ops_onchain_data,
l1_tx_count: l1_batch.l1_tx_count as u16,
l2_tx_count: l1_batch.l2_tx_count as u16,
l2_to_l1_logs: convert_l2_to_l1_logs(l1_batch.l2_to_l1_logs),
l2_to_l1_logs: user_l2_to_l1_logs.into_iter().map(UserL2ToL1Log).collect(),
l2_to_l1_messages: l1_batch.l2_to_l1_messages,

bloom: H2048::from_slice(&l1_batch.bloom),
Expand All @@ -213,7 +207,7 @@ impl From<StorageL1Batch> for L1BatchHeader {
),
l1_gas_price: l1_batch.l1_gas_price as u64,
l2_fair_gas_price: l1_batch.l2_fair_gas_price as u64,
system_logs,
system_logs: system_logs.into_iter().map(SystemL2ToL1Log).collect(),
protocol_version: l1_batch
.protocol_version
.map(|v| (v as u16).try_into().unwrap()),
Expand Down
17 changes: 0 additions & 17 deletions core/lib/multivm/src/glue/types/vm/current_execution_state.rs

This file was deleted.

37 changes: 32 additions & 5 deletions core/lib/multivm/src/glue/types/vm/vm_block_result.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use zksync_types::l2_to_l1_log::UserL2ToL1Log;

use crate::glue::{GlueFrom, GlueInto};
use crate::interface::{
types::outputs::VmExecutionLogs, CurrentExecutionState, ExecutionResult, Refunds,
Expand Down Expand Up @@ -29,7 +31,12 @@ impl GlueFrom<crate::vm_m5::vm::VmBlockResult> for crate::interface::FinishedL1B
events: value.full_result.events,
storage_log_queries: value.full_result.storage_log_queries,
used_contract_hashes: value.full_result.used_contract_hashes,
user_l2_to_l1_logs: value.full_result.l2_to_l1_logs,
user_l2_to_l1_logs: value
.full_result
.l2_to_l1_logs
.into_iter()
.map(UserL2ToL1Log)
.collect(),
system_logs: vec![],
total_log_queries: value.full_result.total_log_queries,
cycles_used: value.full_result.cycles_used,
Expand Down Expand Up @@ -61,7 +68,12 @@ impl GlueFrom<crate::vm_m6::vm::VmBlockResult> for crate::interface::FinishedL1B
events: value.full_result.events,
storage_log_queries: value.full_result.storage_log_queries,
used_contract_hashes: value.full_result.used_contract_hashes,
user_l2_to_l1_logs: value.full_result.l2_to_l1_logs,
user_l2_to_l1_logs: value
.full_result
.l2_to_l1_logs
.into_iter()
.map(UserL2ToL1Log)
.collect(),
system_logs: vec![],
total_log_queries: value.full_result.total_log_queries,
cycles_used: value.full_result.cycles_used,
Expand Down Expand Up @@ -99,7 +111,12 @@ impl GlueFrom<crate::vm_1_3_2::vm::VmBlockResult> for crate::interface::Finished
events: value.full_result.events,
storage_log_queries: value.full_result.storage_log_queries,
used_contract_hashes: value.full_result.used_contract_hashes,
user_l2_to_l1_logs: value.full_result.l2_to_l1_logs,
user_l2_to_l1_logs: value
.full_result
.l2_to_l1_logs
.into_iter()
.map(UserL2ToL1Log)
.collect(),
system_logs: vec![],
total_log_queries: value.full_result.total_log_queries,
cycles_used: value.full_result.cycles_used,
Expand Down Expand Up @@ -127,7 +144,12 @@ impl GlueFrom<crate::vm_1_3_2::vm::VmBlockResult> for crate::interface::VmExecut
result,
logs: VmExecutionLogs {
events: value.full_result.events,
user_l2_to_l1_logs: value.full_result.l2_to_l1_logs,
user_l2_to_l1_logs: value
.full_result
.l2_to_l1_logs
.into_iter()
.map(UserL2ToL1Log)
.collect(),
system_l2_to_l1_logs: vec![],
storage_logs: value.full_result.storage_log_queries,
total_log_queries_count: value.full_result.total_log_queries,
Expand Down Expand Up @@ -189,7 +211,12 @@ impl GlueFrom<crate::vm_m6::vm::VmBlockResult> for crate::interface::VmExecution
result,
logs: VmExecutionLogs {
events: value.full_result.events,
user_l2_to_l1_logs: value.full_result.l2_to_l1_logs,
user_l2_to_l1_logs: value
.full_result
.l2_to_l1_logs
.into_iter()
.map(UserL2ToL1Log)
.collect(),
system_l2_to_l1_logs: vec![],
storage_logs: value.full_result.storage_log_queries,
total_log_queries_count: value.full_result.total_log_queries,
Expand Down
58 changes: 0 additions & 58 deletions core/lib/multivm/src/glue/types/vm/vm_execution_result.rs

This file was deleted.

Loading

0 comments on commit ac9c6e2

Please sign in to comment.