Skip to content

Commit

Permalink
feat(vm)!: 1 5 0 support (matter-labs#1508)
Browse files Browse the repository at this point in the history
## What ❔

- Pubdata counter support: now the VM counts how much pubdata has been
spent and charges the user at the end of the transaction.
- TSTORE/TLOAD support
- CodeOracle support
- 0-gas value transfers support (no changes needed in the `zksync-era`
repo, but the tests were added
- Previous returndata tracking logic in the bootloader stopped working
due to compiler optimization. Thus, we moved to a more long term
solution with `FarCallTracker`.

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## 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`.
- [ ] Linkcheck has been run via `zk linkcheck`.

---------

Co-authored-by: koloz <[email protected]>
Co-authored-by: perekopskiy <[email protected]>
  • Loading branch information
3 people authored Apr 5, 2024
1 parent e03e201 commit a6ccd25
Show file tree
Hide file tree
Showing 120 changed files with 3,553 additions and 902 deletions.
111 changes: 111 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,13 @@ url = "2"
web3 = "0.19.0"

# "Internal" dependencies
# TODO: use the v1.5.0 circuit_sequencer_api once the prover is integrated
circuit_sequencer_api = { package = "circuit_sequencer_api", git = "https://github.com/matter-labs/era-zkevm_test_harness.git", branch = "v1.4.2" }
circuit_sequencer_api_1_3_3 = { package = "circuit_sequencer_api", git = "https://github.com/matter-labs/era-zkevm_test_harness.git", branch = "v1.3.3" }
circuit_sequencer_api_1_4_0 = { package = "circuit_sequencer_api", git = "https://github.com/matter-labs/era-zkevm_test_harness.git", branch = "v1.4.0" }
circuit_sequencer_api_1_4_1 = { package = "circuit_sequencer_api", git = "https://github.com/matter-labs/era-zkevm_test_harness.git", branch = "v1.4.1" }
circuit_sequencer_api_1_4_2 = { package = "circuit_sequencer_api", git = "https://github.com/matter-labs/era-zkevm_test_harness.git", branch = "v1.4.2" }
circuit_sequencer_api_1_5_0 = { package = "circuit_sequencer_api", git = "https://github.com/matter-labs/era-zkevm_test_harness.git", branch = "v1.5.0" }
crypto_codegen = { package = "codegen", git = "https://github.com/matter-labs/solidity_plonk_verifier.git", branch = "dev" }
kzg = { package = "kzg", git = "https://github.com/matter-labs/era-zkevm_test_harness.git", branch = "v1.4.2" }
vise = { git = "https://github.com/matter-labs/vise.git", version = "0.1.0", rev = "1c9cc500e92cf9ea052b230e114a6f9cce4fb2c1" }
Expand All @@ -164,6 +166,7 @@ zk_evm_1_3_1 = { package = "zk_evm", git = "https://github.com/matter-labs/era-z
zk_evm_1_3_3 = { package = "zk_evm", git = "https://github.com/matter-labs/era-zk_evm.git", tag = "v1.3.3-rc2" }
zk_evm_1_4_0 = { package = "zk_evm", git = "https://github.com/matter-labs/era-zk_evm.git", branch = "v1.4.0" }
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_5_0 = { package = "zk_evm", git = "https://github.com/matter-labs/era-zk_evm.git", branch = "v1.5.0" }
zksync_concurrency = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "8833a9b7fef89d1ffc5c08d53a3560164bc1c694" }
zksync_consensus_bft = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "8833a9b7fef89d1ffc5c08d53a3560164bc1c694" }
zksync_consensus_crypto = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "8833a9b7fef89d1ffc5c08d53a3560164bc1c694" }
Expand Down
7 changes: 7 additions & 0 deletions checks-config/era.dic
Original file line number Diff line number Diff line change
Expand Up @@ -929,3 +929,10 @@ SIGINT
opentelemetry
PubdataSendingMode
FriGpuProverArchiver
vm
demuxer
2k
4k
superset
80M
780kb
2 changes: 1 addition & 1 deletion contracts
Submodule contracts updated 175 files
4 changes: 2 additions & 2 deletions core/bin/system-constants-generator/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{cell::RefCell, rc::Rc};

use multivm::{
interface::{
dyn_tracers::vm_1_4_1::DynTracer, tracer::VmExecutionStopReason, L1BatchEnv, L2BlockEnv,
dyn_tracers::vm_1_5_0::DynTracer, tracer::VmExecutionStopReason, L1BatchEnv, L2BlockEnv,
SystemEnv, TxExecutionMode, VmExecutionMode, VmInterface,
},
vm_latest::{
Expand Down Expand Up @@ -335,7 +335,7 @@ pub(super) fn execute_user_txs_in_test_gas_vm(
VmSpentResourcesResult {
// It is assumed that the entire `gas_used` was spent on computation and so it safe to convert to u32
gas_consumed: result.statistics.gas_used as u32,
total_gas_paid: total_gas_paid_upfront.as_u32() - total_gas_refunded as u32,
total_gas_paid: (total_gas_paid_upfront.as_u64() - total_gas_refunded) as u32,
pubdata_published: metrics.size() as u32,
total_pubdata_paid: 0,
}
Expand Down
19 changes: 9 additions & 10 deletions core/lib/basic_types/src/protocol_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@ pub enum ProtocolVersionId {
Version21,
Version22,
Version23,
Version24,
}

impl ProtocolVersionId {
pub fn latest() -> Self {
Self::Version22
Self::Version23
}

pub fn next() -> Self {
Self::Version23
Self::Version24
}

/// Returns VM version to be used by API for this protocol version.
Expand Down Expand Up @@ -83,7 +84,8 @@ impl ProtocolVersionId {
ProtocolVersionId::Version20 => VmVersion::Vm1_4_1,
ProtocolVersionId::Version21 => VmVersion::Vm1_4_2,
ProtocolVersionId::Version22 => VmVersion::Vm1_4_2,
ProtocolVersionId::Version23 => VmVersion::Vm1_4_2,
ProtocolVersionId::Version23 => VmVersion::Vm1_5_0,
ProtocolVersionId::Version24 => VmVersion::Vm1_5_0,
}
}

Expand Down Expand Up @@ -131,15 +133,11 @@ impl ProtocolVersionId {
}

pub fn is_pre_1_5_0(&self) -> bool {
// In the current codebase all the protocol versions are pre-1.5.0.
// This method will be updated once the v1.5.0 is added to the server
true
self < &ProtocolVersionId::Version23
}

pub fn is_post_1_5_0(&self) -> bool {
// In the current codebase all the protocol versions are pre-1.5.0.
// This method will be updated once the v1.5.0 is added to the server
false
self >= &ProtocolVersionId::Version23
}
}

Expand Down Expand Up @@ -225,7 +223,8 @@ impl From<ProtocolVersionId> for VmVersion {
ProtocolVersionId::Version20 => VmVersion::Vm1_4_1,
ProtocolVersionId::Version21 => VmVersion::Vm1_4_2,
ProtocolVersionId::Version22 => VmVersion::Vm1_4_2,
ProtocolVersionId::Version23 => VmVersion::Vm1_4_2,
ProtocolVersionId::Version23 => VmVersion::Vm1_5_0,
ProtocolVersionId::Version24 => VmVersion::Vm1_5_0,
}
}
}
3 changes: 2 additions & 1 deletion core/lib/basic_types/src/vm_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ pub enum VmVersion {
VmBoojumIntegration,
Vm1_4_1,
Vm1_4_2,
Vm1_5_0,
}

impl VmVersion {
/// Returns the latest supported VM version.
pub const fn latest() -> VmVersion {
Self::Vm1_4_2
Self::Vm1_5_0
}
}
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,7 +14,9 @@ zksync_types.workspace = true
zksync_utils.workspace = true
circuit_sequencer_api_1_4_0.workspace = true
circuit_sequencer_api_1_4_1.workspace = true
circuit_sequencer_api_1_5_0.workspace = true

zk_evm_1_5_0.workspace = true
zk_evm_1_4_1.workspace = true
zk_evm_1_3_3.workspace = true
multivm.workspace = true
33 changes: 33 additions & 0 deletions core/lib/commitment_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ 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 zk_evm_1_5_0::{
aux_structures::Timestamp as Timestamp_1_5_0,
zk_evm_abstractions::queries::LogQuery as LogQuery_1_5_0,
};
use zksync_types::{zk_evm_types::LogQuery, ProtocolVersionId, VmVersion, H256, U256};
use zksync_utils::expand_memory_contents;

Expand All @@ -32,6 +36,14 @@ pub fn events_queue_commitment(
.collect(),
),
)),
VmVersion::Vm1_5_0 => Some(H256(
circuit_sequencer_api_1_5_0::commitments::events_queue_commitment_fixed(
&events_queue
.iter()
.map(|x| to_log_query_1_5_0(*x))
.collect(),
),
)),
_ => None,
}
}
Expand Down Expand Up @@ -60,6 +72,11 @@ pub fn bootloader_initial_content_commitment(
&full_bootloader_memory,
),
)),
VmVersion::Vm1_5_0 => Some(H256(
circuit_sequencer_api_1_5_0::commitments::initial_heap_content_commitment_fixed(
&full_bootloader_memory,
),
)),
_ => unreachable!(),
}
}
Expand Down Expand Up @@ -95,3 +112,19 @@ fn to_log_query_1_4_1(log_query: LogQuery) -> LogQuery_1_4_1 {
is_service: log_query.is_service,
}
}

fn to_log_query_1_5_0(log_query: LogQuery) -> LogQuery_1_5_0 {
LogQuery_1_5_0 {
timestamp: Timestamp_1_5_0(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,
}
}
Loading

0 comments on commit a6ccd25

Please sign in to comment.