Skip to content

Commit

Permalink
update revm, fix env update for deployed contracts and era-test-node
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaztec committed Nov 8, 2023
1 parent 29cab92 commit 9ebeac8
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 58 deletions.
98 changes: 60 additions & 38 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ foundry-debugger = { path = "crates/debugger" }
## revm
# no default features to avoid c-kzg
# Using a fork of revm as zksync-era requires the usage of sha3 0.10.6, and the latest revm uses 0.10.8
revm = { git = "https://github.com/dutterbutter/revm.git", tag = "sha3_0.10.6", default-features = false }
revm = { version = "3.5.0", default-features = false }
era_revm = { git="https://github.com/matter-labs/era-revm", rev = "dc04c89902ea317f3b0e68b80765b5634a4f42b2" }

# We use a fork of `ethers` to gain access to a previously private variable.
# This ensures that all artifact files, freshly compiled and saved in the `output` directory, are publicly accessible.
Expand Down Expand Up @@ -194,3 +195,4 @@ ethers-signers = { git = "https://github.com/mm-zk/ethers-rs", tag = "main_publi
ethers-middleware = { git = "https://github.com/mm-zk/ethers-rs", tag = "main_public_artifact", default-features = false }
ethers-etherscan = { git = "https://github.com/mm-zk/ethers-rs", tag = "main_public_artifact", default-features = false }
ethers-solc = { git = "https://github.com/mm-zk/ethers-rs", tag = "main_public_artifact", default-features = false }

2 changes: 1 addition & 1 deletion crates/anvil/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repository.workspace = true
foundry-evm = { path = "../../evm" }
foundry-utils = { path = "../../utils" }
# Using a fork of revm as zksync-era requires the usage of sha3 0.10.6, and the latest revm uses 0.10.8
revm = { git = "https://github.com/dutterbutter/revm.git", tag = "sha3_0.10.6", default-features = false, features = ["std", "serde", "memory_limit"] }
revm = { workspace = true, default-features = false, features = ["std", "serde", "memory_limit"] }

alloy-primitives = { workspace = true, features = ["serde"] }
ethers-core.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/cheatcodes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ hex = { workspace = true, optional = true }
itertools = { workspace = true, optional = true }
jsonpath_lib = { workspace = true, optional = true }
# Using a fork of revm as zksync-era requires the usage of sha3 0.10.6, and the latest revm uses 0.10.8
revm = { git = "https://github.com/dutterbutter/revm.git", tag = "sha3_0.10.6", default-features = false, optional = true }
revm = { workspace = true, default-features = false, optional = true }
thiserror = { version = "1", optional = true }
tracing = { workspace = true, optional = true }
walkdir = { version = "2", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ethers-etherscan = { workspace = true, features = ["ethers-solc"] }

# zksync
zksync-web3-rs = {git = "https://github.com/lambdaclass/zksync-web3-rs.git", rev = "70327ae5413c517bd4d27502507cdd96ee40cd22"}
era_revm = { git = "https://github.com/matter-labs/era-revm.git", tag = "v0.0.1-alpha" }
era_revm = { workspace = true }
anyhow = {version = "1.0.70"}
dirs = {version = "5.0.0"}
ansi_term = "0.12.1"
Expand Down
16 changes: 11 additions & 5 deletions crates/common/src/zk_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ impl ZkSolc {
// when output is empty, it has a length of 3, `[]\n`
// solc returns true for success if output is empty
if output.stderr.len() <= 3 {
continue;
continue
}
eyre::bail!(
"Compilation failed with {:?}. Using compiler: {:?}, with args {:?} {:?}",
Expand Down Expand Up @@ -434,8 +434,14 @@ impl ZkSolc {
write_artifacts: Option<PathBuf>,
) -> BTreeMap<String, Vec<ArtifactFile<ConfigurableContractArtifact>>> {
// Deserialize the compiler output into a serde_json::Value object
let compiler_output: ZkSolcCompilerOutput = serde_json::from_slice(&output)
.unwrap_or_else(|e| panic!("Could not parse zksolc compiler output: {}", e));
let compiler_output: ZkSolcCompilerOutput =
serde_json::from_slice(&output).unwrap_or_else(|e| {
panic!(
"Could not parse zksolc compiler output: {}\n{}",
e,
std::str::from_utf8(&output).unwrap_or_default()
)
});

// Handle errors and warnings in the output
ZkSolc::handle_output_errors(&compiler_output, displayed_warnings);
Expand Down Expand Up @@ -903,7 +909,7 @@ fn substitute_remapped_paths(content: String, remappings: &[RelativeRemapping])

// Exit the loop if no more replacements were made
if !made_replacements {
break;
break
}
}

Expand All @@ -926,7 +932,7 @@ fn remap_source_path(source_path: &mut PathBuf, remappings: &[RelativeRemapping]

*source_path =
PathBuf::from(temp_path.to_str().unwrap().replace("src/src/", "src/"));
break;
break
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ethers-core.workspace = true
ethers-solc = { workspace = true, features = ["async", "svm-solc"] }
ethers-etherscan.workspace = true
# Using a fork of revm as zksync-era requires the usage of sha3 0.10.6, and the latest revm uses 0.10.8
revm = { git = "https://github.com/dutterbutter/revm.git", tag = "sha3_0.10.6", default-features = false, features = ["std", "serde", "memory_limit"] }
revm = { workspace = true, default-features = false, features = ["std", "serde", "memory_limit"] }

# formats
Inflector = "0.11"
Expand Down
4 changes: 2 additions & 2 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1799,15 +1799,15 @@ impl Default for Config {
sender: Config::DEFAULT_SENDER,
tx_origin: Config::DEFAULT_SENDER,
initial_balance: U256::from(0xffffffffffffffffffffffffu128),
block_number: 1,
block_number: 0, // era-test-node starts at block 0
fork_block_number: None,
chain_id: None,
gas_limit: i64::MAX.into(),
code_size_limit: None,
gas_price: None,
block_base_fee_per_gas: 0,
block_coinbase: Address::zero(),
block_timestamp: 1,
block_timestamp: 0, // era-test-node starts at timestamp 0
block_difficulty: 0,
block_prevrandao: Default::default(),
block_gas_limit: None,
Expand Down
2 changes: 1 addition & 1 deletion crates/debugger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ crossterm = "0.27"
eyre.workspace = true
tracing.workspace = true
# Using a fork of revm as zksync-era requires the usage of sha3 0.10.6, and the latest revm uses 0.10.8
revm = { git = "https://github.com/dutterbutter/revm.git", tag = "sha3_0.10.6", default-features = false, features = [
revm = { workspace = true, default-features = false, features = [
"std",
"serde",
"memory_limit",
Expand Down
4 changes: 2 additions & 2 deletions crates/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ once_cell = "1"
bytes = "1"
hashbrown = { version = "0.14", features = ["serde"] }
# Using a fork of revm as zksync-era requires the usage of sha3 0.10.6, and the latest revm uses 0.10.8
revm = { git = "https://github.com/dutterbutter/revm.git", tag = "sha3_0.10.6", default-features = false, features = [
revm = { workspace = true, default-features = false, features = [
"std",
"serde",
"memory_limit",
Expand All @@ -50,7 +50,7 @@ revm = { git = "https://github.com/dutterbutter/revm.git", tag = "sha3_0.10.6",
"optional_no_base_fee",
"arbitrary",
] }
era_revm = { git = "https://github.com/matter-labs/era-revm.git", tag = "v0.0.1-alpha" }
era_revm = { workspace = true }
alloy-primitives = { workspace = true, features = ["serde", "getrandom", "arbitrary", "rlp"] }
alloy-dyn-abi = { workspace = true, features = ["arbitrary"] }

Expand Down
21 changes: 16 additions & 5 deletions crates/evm/src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@ impl Executor {
self
}

// Record any changes made to the block's environment during setup,
// and also the chainid, which can be set manually.
pub fn record_env_changes(&mut self, env: &Env) {
// record any changes made to the block's environment during setup
self.env.block = env.block.clone();
// and also the chainid, which can be set manually
self.env.cfg.chain_id = env.cfg.chain_id;
}

/// Calls the `setUp()` function on a contract.
///
/// This will commit any state changes to the underlying database.
Expand All @@ -185,10 +194,7 @@ impl Executor {
self.backend.set_test_contract(to).set_caller(from);
let res = self.call_committing::<(), _, _>(from, to, "setUp()", (), U256::ZERO, None)?;

// record any changes made to the block's environment during setup
self.env.block = res.env.block.clone();
// and also the chainid, which can be set manually
self.env.cfg.chain_id = res.env.cfg.chain_id;
self.record_env_changes(&res.env);

match res.state_changeset.as_ref() {
Some(changeset) => {
Expand Down Expand Up @@ -446,7 +452,12 @@ impl Executor {
abi: Option<&Abi>,
) -> Result<DeployResult, EvmError> {
let env = self.build_test_env(from, TransactTo::Create(CreateScheme::Create), code, value);
self.deploy_with_env(env, abi)
let res = self.deploy_with_env(env, abi);
if let Ok(DeployResult { env, .. }) = &res {
self.record_env_changes(env);
}

res
}

/// Check if a call to a test contract was successful.
Expand Down

0 comments on commit 9ebeac8

Please sign in to comment.