Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EVM Simulator Flag #244

Merged
merged 8 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions core/lib/config/src/configs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub mod pruning;
pub mod secrets;
pub mod snapshot_recovery;
pub mod snapshots_creator;
pub mod use_evm_simulator;
pub mod utils;
pub mod vm_runner;
pub mod wallets;
Expand Down
7 changes: 7 additions & 0 deletions core/lib/config/src/configs/use_evm_simulator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use serde::Deserialize;

/// Configuration for the use evm simulator
#[derive(Debug, Deserialize, Clone, PartialEq)]
pub struct UseEvmSimulator {
pub use_evm_simulator: bool,
}
2 changes: 2 additions & 0 deletions core/lib/contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ categories.workspace = true

[dependencies]
zksync_utils.workspace = true
zksync_config.workspace = true
zksync_env_config.workspace = true

ethabi.workspace = true
serde_json.workspace = true
Expand Down
13 changes: 12 additions & 1 deletion core/lib/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ use ethabi::{
};
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use zksync_config::configs::{
house_keeper::HouseKeeperConfig,
use_evm_simulator::{self, UseEvmSimulator},
};
use zksync_env_config::FromEnv;
use zksync_utils::{bytecode::hash_bytecode, bytes_to_be_words, workspace_dir_or_current_dir};

pub mod test_contracts;
Expand Down Expand Up @@ -342,10 +347,16 @@ impl BaseSystemContracts {
hash,
};

let evm_simulator_bytecode =
let mut evm_simulator_bytecode =
read_sys_contract_bytecode("", "EvmInterpreter", ContractLanguage::Yul);
let evm_simulator_hash = hash_bytecode(&evm_simulator_bytecode);

let use_evm_simulator =
UseEvmSimulator::from_env().expect("USE EVM SIMULATOR FLAG SHOULD BE SET");
if !use_evm_simulator.use_evm_simulator {
evm_simulator_bytecode = vec![];
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe:

let evm_simulator_bytecode = if UseEvmSimulator::from_env().expect("USE EVM SIMULATOR FLAG SHOULD BE SET").use_evm_simulator {
    read_sys_contract_bytecode("", "EvmInterpreter", ContractLanguage::Yul)
} else {
    vec![]
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not possible, because then we need to calculate the hash of that bytecode, if we try to calculate the hash of an empty bytecode it gives an error when running zk init:
Invalid bytecode: ()
We need to still have the hash of the actual interpreter bytecode, and then setting that bytecode to an empty vector.


let evm_simulator = SystemContractCode {
code: bytes_to_be_words(evm_simulator_bytecode),
hash: evm_simulator_hash,
Expand Down
1 change: 1 addition & 0 deletions core/lib/env_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ mod genesis;
mod prover_job_monitor;
#[cfg(test)]
mod test_utils;
mod use_evm_simulator;
mod vm_runner;
mod wallets;

Expand Down
9 changes: 9 additions & 0 deletions core/lib/env_config/src/use_evm_simulator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use zksync_config::configs::use_evm_simulator::UseEvmSimulator;

use crate::{envy_load, FromEnv};

impl FromEnv for UseEvmSimulator {
fn from_env() -> anyhow::Result<Self> {
envy_load("use_evm_simulator", "USE_EVM_SIMULATOR_")
}
}
2 changes: 2 additions & 0 deletions etc/env/base/use_evm_simulator.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[use_evm_simulator]
use_evm_simulator = true
2 changes: 2 additions & 0 deletions prover/Cargo.lock

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

Loading