Skip to content

Commit

Permalink
Merge branch 'dev' into dev-with-foundry-commits
Browse files Browse the repository at this point in the history
  • Loading branch information
Karrq authored Aug 6, 2024
2 parents 8b2031e + 4144021 commit b6b8e72
Show file tree
Hide file tree
Showing 30 changed files with 1,114 additions and 257 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,38 @@ jobs:
# - name: Test ZK VM
# run: RUST_LOG=1 cargo test --package forge --test it --jobs=1 -- zk

zk-cargo-test:
name: zk-cargo-test
runs-on: ubuntu-22.04-github-hosted-16core

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
ref: ${{ github.event.pull_request.head.sha }}

- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly-2024-04-28

- name: Run era-test-node
uses: dutterbutter/era-test-node-action@v1
with:
mode: fork
network: mainnet
log: info
logFilePath: era_test_node.log
target: x86_64-unknown-linux-gnu
releaseTag: v0.1.0-alpha.25

- name: Run zk tests
env:
RUST_BACKTRACE: full
TEST_MAINNET_URL: http://localhost:8011
run: cargo test zk

zk-smoke-test:
name: zk-smoke-test
runs-on: ubuntu-22.04-github-hosted-16core
Expand Down
8 changes: 6 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ alloy-rlp = "0.3.3"
solang-parser = "=0.3.3"

## zksync
era_test_node = { git="https://github.com/matter-labs/era-test-node.git" , rev = "1d72eae6e9400b5b6caed5e60093e7c32eee8abb" }
era_test_node = { git="https://github.com/matter-labs/era-test-node.git" , rev = "dd6d2f463eb9697dc2365899a72ae12dae3ec809" }
zksync-web3-rs = {git = "https://github.com/lambdaclass/zksync-web3-rs.git", rev = "fd7adf634c016f40ea01f702e0e05f57aa5ba614"}
zksync_basic_types = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e10bbdd1e863962552f37e768ae6af649353e4ea" }
zksync_types = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e10bbdd1e863962552f37e768ae6af649353e4ea" }
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This repository enhances Foundry to support zkSync Era, enabling Solidity-based

> 🔧 **Fork Notice:** This is a Foundry fork with added zkSync support.
>
> ⚠️ **Alpha Stage:** The project is in alpha, so you might encounter issues.
> ⚠️ **Alpha Stage:** The project is in alpha, so you might encounter issues. For more information, please review [Limitations](#limitations) section.
>
> 🐞 **Found an Issue?** Please report it to help us improve.
Expand Down Expand Up @@ -59,6 +59,7 @@ While `foundry-zksync` is **alpha stage**, there are some limitations to be awar
- **Contract Verification**: Currently contract verification via the `--verify` flag do not work as expected but will be added shortly.
- **Specific Foundry Features**: Currently features such as `--gas-report`, `--coverage` may not work as intended. We are actively working on providing support for these feature types.
- **Solc Compatibility**: `zksolc` requires a `solc` binary to be run as a child process. The version/path to use for each can be specified by the `zksolc` and `solc` options in `foundry.toml`. Not all `solc` versions are supported by all `zksolc` versions, compiling with a `solc` version higher than the one supported may lead to unexpected errors. [Read the docs](https://docs.zksync.io/zk-stack/components/compiler/toolchain/solidity.html#limitations) about version limitations and check the [zksolc changelog](https://github.com/matter-labs/era-compiler-solidity/blob/main/CHANGELOG.md) to see the latest supported `solc` version.
- **Windows Compatibility**: Windows is not officially supported yet. The reported issues would be investigated on a best-effort basis.
For the most effective use of our library, we recommend familiarizing yourself with these features and limitations.
Expand Down
8 changes: 4 additions & 4 deletions crates/cheatcodes/src/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ impl Cheatcodes {
data.env.block.timestamp = U256::from(block_timestamp);

let test_contract = data.db.get_test_contract_address();
for address in data.db.persistent_accounts() {
for address in data.db.persistent_accounts().into_iter().chain([data.env.tx.caller]) {
info!(?address, "importing to evm state");

let zk_address = address.to_h160();
Expand Down Expand Up @@ -546,7 +546,7 @@ impl Cheatcodes {
let mut known_codes_storage: rHashMap<U256, EvmStorageSlot> = Default::default();
let mut deployed_codes: HashMap<Address, AccountInfo> = Default::default();

for address in data.db.persistent_accounts() {
for address in data.db.persistent_accounts().into_iter().chain([data.env.tx.caller]) {
info!(?address, "importing to zk state");

let account = journaled_account(data, address).expect("failed to load account");
Expand Down Expand Up @@ -626,7 +626,7 @@ impl Cheatcodes {
}
}

impl<DB: DatabaseExt + Send> Inspector<DB> for Cheatcodes {
impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {
#[inline]
fn initialize_interp(&mut self, _: &mut Interpreter, ecx: &mut EvmContext<DB>) {
// When the first interpreter is initialized we've circumvented the balance and gas checks,
Expand Down Expand Up @@ -2083,7 +2083,7 @@ impl<DB: DatabaseExt + Send> Inspector<DB> for Cheatcodes {
}
}

impl<DB: DatabaseExt + Send> InspectorExt<DB> for Cheatcodes {
impl<DB: DatabaseExt> InspectorExt<DB> for Cheatcodes {
fn should_use_create2_factory(
&mut self,
ecx: &mut EvmContext<DB>,
Expand Down
4 changes: 2 additions & 2 deletions crates/config/src/zksync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct ZkSyncConfig {
pub solc_path: Option<PathBuf>,

/// Whether to include the metadata hash for zksolc compiled bytecode.
pub bytecode_hash: BytecodeHash,
pub bytecode_hash: Option<BytecodeHash>,

/// Whether to try to recompile with -Oz if the bytecode is too large.
pub fallback_oz: bool,
Expand Down Expand Up @@ -111,7 +111,7 @@ impl ZkSyncConfig {
libraries,
optimizer,
evm_version: Some(evm_version),
metadata: Some(SettingsMetadata { bytecode_hash: Some(self.bytecode_hash) }),
metadata: Some(SettingsMetadata { bytecode_hash: self.bytecode_hash }),
via_ir: Some(via_ir),
// Set in project paths.
remappings: Vec::new(),
Expand Down
11 changes: 4 additions & 7 deletions crates/evm/core/src/backend/fork_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@ impl CachedForkType {

let is_zk_url = foundry_common::provider::try_get_http_provider(fork_url)
.map(|provider| {
let is_zk_url = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap()
.block_on(provider.raw_request("zks_L1ChainId".into(), ()))
.map(|_: String| true)
.unwrap_or_default();
let is_zk_url =
futures::executor::block_on(provider.raw_request("zks_L1ChainId".into(), ()))
.map(|_: String| true)
.unwrap_or_default();

is_zk_url
})
Expand Down
5 changes: 5 additions & 0 deletions crates/forge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ tikv-jemallocator = { workspace = true, optional = true }
anvil.workspace = true
foundry-test-utils.workspace = true

# zk
era_test_node.workspace = true
jsonrpc-core = { git = "https://github.com/matter-labs/jsonrpc.git", branch = "master" }
jsonrpc-http-server = { git = "https://github.com/matter-labs/jsonrpc.git", branch = "master" }

mockall = "0.12"
criterion = "0.5"
paste = "1.0"
Expand Down
2 changes: 2 additions & 0 deletions crates/forge/tests/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ mod svm;
mod test_cmd;
mod verify;

mod zksync_node;

mod ext_integration;
115 changes: 55 additions & 60 deletions crates/forge/tests/cli/script.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Contains various tests related to `forge script`.
use crate::constants::TEMPLATE_CONTRACT;
use crate::{constants::TEMPLATE_CONTRACT, zksync_node};
use alloy_primitives::{Address, Bytes};
use anvil::{spawn, NodeConfig};
use foundry_test_utils::{rpc, util::OutputExt, ScriptOutcome, ScriptTester};
Expand Down Expand Up @@ -1452,39 +1452,35 @@ forgetest_async!(can_deploy_library_create2_different_sender, |prj, cmd| {
.await;
});

// ignoring test as it requires a local era-test-node to be running on port 8011
forgetest_async!(
#[ignore]
can_execute_zk_script_with_arguments,
|prj, cmd| {
#[derive(serde::Deserialize, Debug)]
#[allow(dead_code)]
struct ZkTransactions {
transactions: Vec<ZkTransaction>,
}
forgetest_async!(test_zk_can_execute_script_with_arguments, |prj, cmd| {
#[derive(serde::Deserialize, Debug)]
#[allow(dead_code)]
struct ZkTransactions {
transactions: Vec<ZkTransaction>,
}

#[derive(serde::Deserialize, Debug)]
#[allow(dead_code)]
struct ZkTransaction {
zk: Zk,
}
#[derive(serde::Deserialize, Debug)]
#[allow(dead_code)]
struct ZkTransaction {
zk: Zk,
}

#[derive(serde::Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
#[allow(dead_code)]
struct Zk {
factory_deps: Vec<Vec<u8>>,
}
#[derive(serde::Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
#[allow(dead_code)]
struct Zk {
factory_deps: Vec<Vec<u8>>,
}

cmd.args(["init", "--force"]).arg(prj.root());
cmd.assert_non_empty_stdout();
cmd.forge_fuse();
let node = zksync_node::ZkSyncNode::start();

let (_api, _handle) = spawn(NodeConfig::test()).await;
let script = prj
.add_script(
"Deploy.s.sol",
r#"
cmd.args(["init", "--force"]).arg(prj.root());
cmd.assert_non_empty_stdout();
cmd.forge_fuse();

prj.add_script(
"Deploy.s.sol",
r#"
pragma solidity ^0.8.18;
import {Script} from "forge-std/Script.sol";
Expand Down Expand Up @@ -1527,34 +1523,33 @@ contract DeployScript is Script {
}
}
"#,
)
.unwrap();
)
.unwrap();

cmd.arg("script").arg(script).args([
"--tc",
"DeployScript",
"--broadcast",
"--private-key",
"0x3d3cbc973389cb26f657686445bcc75662b415b656078503592ac8c1abb8810e",
"--chain",
"260",
"--gas-estimate-multiplier",
"310",
"--rpc-url",
"http://localhost:8011",
"--slow",
]);

assert!(cmd.stdout_lossy().contains("ONCHAIN EXECUTION COMPLETE & SUCCESSFUL"));

let run_latest = foundry_common::fs::json_files(prj.root().join("broadcast").as_path())
.find(|file| file.ends_with("run-latest.json"))
.expect("No broadcast artifacts");

let content = foundry_common::fs::read_to_string(run_latest).unwrap();

let transactions: ZkTransactions = serde_json::from_str(&content).unwrap();
let transactions = transactions.transactions;
assert_eq!(transactions.len(), 3);
}
);
cmd.arg("script").args([
"--zksync",
"DeployScript",
"--broadcast",
"--private-key",
"0x3d3cbc973389cb26f657686445bcc75662b415b656078503592ac8c1abb8810e",
"--chain",
"260",
"--gas-estimate-multiplier",
"310",
"--rpc-url",
node.url().as_str(),
"--slow",
]);

assert!(cmd.stdout_lossy().contains("ONCHAIN EXECUTION COMPLETE & SUCCESSFUL"));

let run_latest = foundry_common::fs::json_files(prj.root().join("broadcast").as_path())
.find(|file| file.ends_with("run-latest.json"))
.expect("No broadcast artifacts");

let content = foundry_common::fs::read_to_string(run_latest).unwrap();

let transactions: ZkTransactions = serde_json::from_str(&content).unwrap();
let transactions = transactions.transactions;
assert_eq!(transactions.len(), 3);
});
Loading

0 comments on commit b6b8e72

Please sign in to comment.