Skip to content

Commit

Permalink
refactor: Remove zk_evm deps from zksync_types (#944)
Browse files Browse the repository at this point in the history
## What ❔

- Remove `zk_evm_xxx` deps from `zksync_types`

## Why ❔

- These deps only needed for a few use cases, so these use cases are
implemented elsewhere. Part of initiative of moving heavyweight stuff
from `zksync_types`.

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.
- [ ] Spellcheck has been run via `zk spellcheck`.
  • Loading branch information
popzxc authored Jan 25, 2024
1 parent fa45aa9 commit 9e45135
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 88 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions core/lib/commitment_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ zksync_types = { path = "../../lib/types" }
zksync_utils = { path = "../../lib/utils" }
zkevm_test_harness_1_4_0 = { git = "https://github.com/matter-labs/era-zkevm_test_harness.git", branch = "v1.4.0", package = "zkevm_test_harness" }
zkevm_test_harness_1_4_1 = { git = "https://github.com/matter-labs/era-zkevm_test_harness.git", branch = "v1.4.1", package = "zkevm_test_harness" }
zk_evm_1_4_1 = { package = "zk_evm", git = "https://github.com/matter-labs/era-zk_evm.git", branch = "v1.4.1" }
zk_evm_1_3_3 = { package = "zk_evm", git = "https://github.com/matter-labs/era-zk_evm.git", tag = "v1.3.3-rc2" }
multivm = { path = "../../lib/multivm" }
50 changes: 48 additions & 2 deletions core/lib/commitment_utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
//! Utils for commitment calculation.
use multivm::utils::get_used_bootloader_memory_bytes;
use zk_evm_1_3_3::{
aux_structures::Timestamp as Timestamp_1_3_3,
zk_evm_abstractions::queries::LogQuery as LogQuery_1_3_3,
};
use zk_evm_1_4_1::{
aux_structures::Timestamp as Timestamp_1_4_1,
zk_evm_abstractions::queries::LogQuery as LogQuery_1_4_1,
};
use zksync_types::{zk_evm_types::LogQuery, ProtocolVersionId, VmVersion, H256, U256};
use zksync_utils::expand_memory_contents;

Expand All @@ -10,12 +18,18 @@ pub fn events_queue_commitment(
match VmVersion::from(protocol_version) {
VmVersion::VmBoojumIntegration => Some(H256(
zkevm_test_harness_1_4_0::witness::utils::events_queue_commitment_fixed(
&events_queue.iter().map(|x| (*x).into()).collect(),
&events_queue
.iter()
.map(|x| to_log_query_1_3_3(*x))
.collect(),
),
)),
VmVersion::Vm1_4_1 => Some(H256(
zkevm_test_harness_1_4_1::witness::utils::events_queue_commitment_fixed(
&events_queue.iter().map(|x| (*x).into()).collect(),
&events_queue
.iter()
.map(|x| to_log_query_1_4_1(*x))
.collect(),
),
)),
_ => None,
Expand Down Expand Up @@ -49,3 +63,35 @@ pub fn bootloader_initial_content_commitment(
_ => unreachable!(),
}
}

fn to_log_query_1_3_3(log_query: LogQuery) -> LogQuery_1_3_3 {
LogQuery_1_3_3 {
timestamp: Timestamp_1_3_3(log_query.timestamp.0),
tx_number_in_block: log_query.tx_number_in_block,
aux_byte: log_query.aux_byte,
shard_id: log_query.shard_id,
address: log_query.address,
key: log_query.key,
read_value: log_query.read_value,
written_value: log_query.written_value,
rw_flag: log_query.rw_flag,
rollback: log_query.rollback,
is_service: log_query.is_service,
}
}

fn to_log_query_1_4_1(log_query: LogQuery) -> LogQuery_1_4_1 {
LogQuery_1_4_1 {
timestamp: Timestamp_1_4_1(log_query.timestamp.0),
tx_number_in_block: log_query.tx_number_in_block,
aux_byte: log_query.aux_byte,
shard_id: log_query.shard_id,
address: log_query.address,
key: log_query.key,
read_value: log_query.read_value,
written_value: log_query.written_value,
rw_flag: log_query.rw_flag,
rollback: log_query.rollback,
is_service: log_query.is_service,
}
}
2 changes: 0 additions & 2 deletions core/lib/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ zksync_config = { path = "../config" }
# We need this import because we wanat DAL to be responsible for (de)serialization
codegen = { git = "https://github.com/matter-labs/solidity_plonk_verifier.git", branch = "dev" }
zkevm_test_harness = { git = "https://github.com/matter-labs/era-zkevm_test_harness.git", branch = "v1.3.3" }
zk_evm_1_4_1 = { package = "zk_evm", git = "https://github.com/matter-labs/era-zk_evm.git", branch = "v1.4.1" }
zk_evm_1_3_3 = { package = "zk_evm", git = "https://github.com/matter-labs/era-zk_evm.git", tag = "v1.3.3-rc2" }
zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "5727a3e0b22470bb90092388f9125bcb366df613" }

anyhow = "1.0.75"
Expand Down
80 changes: 0 additions & 80 deletions core/lib/types/src/zk_evm_types.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
use zk_evm_1_3_3::{
aux_structures::Timestamp as Timestamp_1_3_3,
zk_evm_abstractions::queries::LogQuery as LogQuery_1_3_3,
};
use zk_evm_1_4_1::{
aux_structures::Timestamp as Timestamp_1_4_1,
zk_evm_abstractions::queries::LogQuery as LogQuery_1_4_1,
};
use zksync_basic_types::{Address, U256};

#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
Expand Down Expand Up @@ -36,75 +28,3 @@ pub struct LogQuery {
pub rollback: bool,
pub is_service: bool,
}

impl From<LogQuery> for LogQuery_1_3_3 {
fn from(log_query: LogQuery) -> Self {
Self {
timestamp: Timestamp_1_3_3(log_query.timestamp.0),
tx_number_in_block: log_query.tx_number_in_block,
aux_byte: log_query.aux_byte,
shard_id: log_query.shard_id,
address: log_query.address,
key: log_query.key,
read_value: log_query.read_value,
written_value: log_query.written_value,
rw_flag: log_query.rw_flag,
rollback: log_query.rollback,
is_service: log_query.is_service,
}
}
}

impl From<LogQuery_1_3_3> for LogQuery {
fn from(log_query: LogQuery_1_3_3) -> Self {
Self {
timestamp: Timestamp(log_query.timestamp.0),
tx_number_in_block: log_query.tx_number_in_block,
aux_byte: log_query.aux_byte,
shard_id: log_query.shard_id,
address: log_query.address,
key: log_query.key,
read_value: log_query.read_value,
written_value: log_query.written_value,
rw_flag: log_query.rw_flag,
rollback: log_query.rollback,
is_service: log_query.is_service,
}
}
}

impl From<LogQuery> for LogQuery_1_4_1 {
fn from(log_query: LogQuery) -> Self {
Self {
timestamp: Timestamp_1_4_1(log_query.timestamp.0),
tx_number_in_block: log_query.tx_number_in_block,
aux_byte: log_query.aux_byte,
shard_id: log_query.shard_id,
address: log_query.address,
key: log_query.key,
read_value: log_query.read_value,
written_value: log_query.written_value,
rw_flag: log_query.rw_flag,
rollback: log_query.rollback,
is_service: log_query.is_service,
}
}
}

impl From<LogQuery_1_4_1> for LogQuery {
fn from(log_query: LogQuery_1_4_1) -> Self {
Self {
timestamp: Timestamp(log_query.timestamp.0),
tx_number_in_block: log_query.tx_number_in_block,
aux_byte: log_query.aux_byte,
shard_id: log_query.shard_id,
address: log_query.address,
key: log_query.key,
read_value: log_query.read_value,
written_value: log_query.written_value,
rw_flag: log_query.rw_flag,
rollback: log_query.rollback,
is_service: log_query.is_service,
}
}
}
16 changes: 14 additions & 2 deletions core/lib/zksync_core/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use zksync_types::{
get_code_key, get_system_context_init_logs,
protocol_version::{L1VerifierConfig, ProtocolVersion},
tokens::{TokenInfo, TokenMetadata, ETHEREUM_ADDRESS},
zk_evm_types::LogQuery,
zk_evm_types::{LogQuery, Timestamp},
AccountTreeId, Address, L1BatchNumber, L2ChainId, MiniblockNumber, ProtocolVersionId,
StorageKey, StorageLog, StorageLogKind, H256,
};
Expand Down Expand Up @@ -231,7 +231,19 @@ async fn insert_system_contracts(
let deduped_log_queries: Vec<LogQuery> = sort_storage_access_queries(&log_queries)
.1
.into_iter()
.map(Into::into)
.map(|log_query| LogQuery {
timestamp: Timestamp(log_query.timestamp.0),
tx_number_in_block: log_query.tx_number_in_block,
aux_byte: log_query.aux_byte,
shard_id: log_query.shard_id,
address: log_query.address,
key: log_query.key,
read_value: log_query.read_value,
written_value: log_query.written_value,
rw_flag: log_query.rw_flag,
rollback: log_query.rollback,
is_service: log_query.is_service,
})
.collect();

let (deduplicated_writes, protective_reads): (Vec<_>, Vec<_>) = deduped_log_queries
Expand Down

0 comments on commit 9e45135

Please sign in to comment.