From 5771c2777db3565390b5b31e296744c1918ce932 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Wed, 11 Sep 2024 09:08:11 -0400 Subject: [PATCH] Move to common crate --- Cargo.lock | 5 +++++ common/src/lib.rs | 19 ++++++++++++++++++- evm_arithmetization/Cargo.toml | 1 + evm_arithmetization/src/lib.rs | 12 +----------- proof_gen/Cargo.toml | 1 + proof_gen/src/lib.rs | 12 +----------- trace_decoder/src/lib.rs | 12 +----------- zero_bin/common/Cargo.toml | 1 + zero_bin/common/src/lib.rs | 12 +----------- zero_bin/leader/src/main.rs | 12 +----------- zero_bin/ops/Cargo.toml | 1 + zero_bin/ops/src/lib.rs | 12 +----------- zero_bin/prover/Cargo.toml | 1 + zero_bin/prover/src/lib.rs | 12 +----------- zero_bin/rpc/src/lib.rs | 12 +----------- zero_bin/verifier/src/main.rs | 12 +----------- 16 files changed, 37 insertions(+), 100 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dcd859ede..1cde9e71e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2075,6 +2075,7 @@ dependencies = [ "static_assertions", "thiserror", "tiny-keccak", + "zk_evm_common", "zk_evm_proc_macro", ] @@ -3305,6 +3306,7 @@ dependencies = [ "trace_decoder", "tracing", "zero_bin_common", + "zk_evm_common", ] [[package]] @@ -3849,6 +3851,7 @@ dependencies = [ "paste", "plonky2", "serde", + "zk_evm_common", ] [[package]] @@ -3893,6 +3896,7 @@ dependencies = [ "trace_decoder", "tracing", "zero_bin_common", + "zk_evm_common", ] [[package]] @@ -5826,6 +5830,7 @@ dependencies = [ "trace_decoder", "tracing", "vergen", + "zk_evm_common", ] [[package]] diff --git a/common/src/lib.rs b/common/src/lib.rs index 4119586a9..e23751cca 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -14,7 +14,24 @@ pub const EMPTY_TRIE_HASH: H256 = H256([ 108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33, ]); -pub const NETWORK_ERR_MSG: &str = "One and only one of the feature chains `cdk_erigon`, `polygon_pos` or `eth_mainnet` must be selected"; +#[macro_export] +/// A convenience macro to check the feature flags activating chain specific +/// behaviors. Only one of these flags may be activated at a time. +macro_rules! check_chain_features { + () => { + #[cfg(any( + all(feature = "cdk_erigon", feature = "polygon_pos"), + all(feature = "cdk_erigon", feature = "eth_mainnet"), + all(feature = "polygon_pos", feature = "eth_mainnet"), + not(any( + feature = "cdk_erigon", + feature = "eth_mainnet", + feature = "polygon_pos" + )) + ))] + compile_error!("One and only one of the feature chains `cdk_erigon`, `polygon_pos` or `eth_mainnet` must be selected"); + }; +} #[test] fn test_empty_code_hash() { diff --git a/evm_arithmetization/Cargo.toml b/evm_arithmetization/Cargo.toml index a2b38cc7e..ffdb8d2f5 100644 --- a/evm_arithmetization/Cargo.toml +++ b/evm_arithmetization/Cargo.toml @@ -49,6 +49,7 @@ serde-big-array = { workspace = true } # Local dependencies mpt_trie = { workspace = true } smt_trie = { workspace = true, optional = true } +zk_evm_common = { workspace = true } zk_evm_proc_macro = { workspace = true } [dev-dependencies] diff --git a/evm_arithmetization/src/lib.rs b/evm_arithmetization/src/lib.rs index 1a9afaf54..52d181834 100644 --- a/evm_arithmetization/src/lib.rs +++ b/evm_arithmetization/src/lib.rs @@ -183,17 +183,7 @@ #![allow(clippy::field_reassign_with_default)] #![feature(let_chains)] -#[cfg(any( - all(feature = "cdk_erigon", feature = "polygon_pos"), - all(feature = "cdk_erigon", feature = "eth_mainnet"), - all(feature = "polygon_pos", feature = "eth_mainnet"), - not(any( - feature = "cdk_erigon", - feature = "eth_mainnet", - feature = "polygon_pos" - )) -))] -compile_error!("One and only one of the feature chains `cdk_erigon`, `polygon_pos` or `eth_mainnet` must be selected"); +zk_evm_common::check_chain_features!(); // Individual STARK processing units pub mod arithmetic; diff --git a/proof_gen/Cargo.toml b/proof_gen/Cargo.toml index 86192bac6..1e2f595b9 100644 --- a/proof_gen/Cargo.toml +++ b/proof_gen/Cargo.toml @@ -18,6 +18,7 @@ hashbrown = { workspace = true } # Local dependencies evm_arithmetization = { workspace = true } +zk_evm_common = { workspace = true } [features] default = ["eth_mainnet"] diff --git a/proof_gen/src/lib.rs b/proof_gen/src/lib.rs index 2805d5112..f1e48a109 100644 --- a/proof_gen/src/lib.rs +++ b/proof_gen/src/lib.rs @@ -134,17 +134,7 @@ //! assert!(verifier_state.verify(block_proof.intern).is_ok()); //! ``` -#[cfg(any( - all(feature = "cdk_erigon", feature = "polygon_pos"), - all(feature = "cdk_erigon", feature = "eth_mainnet"), - all(feature = "polygon_pos", feature = "eth_mainnet"), - not(any( - feature = "cdk_erigon", - feature = "eth_mainnet", - feature = "polygon_pos" - )) -))] -compile_error!("One and only one of the feature chains `cdk_erigon`, `polygon_pos` or `eth_mainnet` must be selected"); +zk_evm_common::check_chain_features!(); pub(crate) mod constants; pub mod proof_gen; diff --git a/trace_decoder/src/lib.rs b/trace_decoder/src/lib.rs index d9cbeece5..335a7c92a 100644 --- a/trace_decoder/src/lib.rs +++ b/trace_decoder/src/lib.rs @@ -68,17 +68,7 @@ #![warn(missing_debug_implementations)] #![warn(missing_docs)] -#[cfg(any( - all(feature = "cdk_erigon", feature = "polygon_pos"), - all(feature = "cdk_erigon", feature = "eth_mainnet"), - all(feature = "polygon_pos", feature = "eth_mainnet"), - not(any( - feature = "cdk_erigon", - feature = "eth_mainnet", - feature = "polygon_pos" - )) -))] -compile_error!("One and only one of the feature chains `cdk_erigon`, `polygon_pos` or `eth_mainnet` must be selected"); +zk_evm_common::check_chain_features!(); /// The broad overview is as follows: /// diff --git a/zero_bin/common/Cargo.toml b/zero_bin/common/Cargo.toml index 3bae1348b..c0e6c51f8 100644 --- a/zero_bin/common/Cargo.toml +++ b/zero_bin/common/Cargo.toml @@ -31,6 +31,7 @@ directories = "5.0.1" evm_arithmetization = { workspace = true } proof_gen = { workspace = true } trace_decoder = { workspace = true } +zk_evm_common = { workspace = true } [build-dependencies] cargo_metadata = { workspace = true } diff --git a/zero_bin/common/src/lib.rs b/zero_bin/common/src/lib.rs index 93cc44ef5..dd6b1220f 100644 --- a/zero_bin/common/src/lib.rs +++ b/zero_bin/common/src/lib.rs @@ -1,14 +1,4 @@ -#[cfg(any( - all(feature = "cdk_erigon", feature = "polygon_pos"), - all(feature = "cdk_erigon", feature = "eth_mainnet"), - all(feature = "polygon_pos", feature = "eth_mainnet"), - not(any( - feature = "cdk_erigon", - feature = "eth_mainnet", - feature = "polygon_pos" - )) -))] -compile_error!("One and only one of the feature chains `cdk_erigon`, `polygon_pos` or `eth_mainnet` must be selected"); +zk_evm_common::check_chain_features!(); pub mod block_interval; pub mod debug_utils; diff --git a/zero_bin/leader/src/main.rs b/zero_bin/leader/src/main.rs index b74b61d95..949540ad8 100644 --- a/zero_bin/leader/src/main.rs +++ b/zero_bin/leader/src/main.rs @@ -1,14 +1,4 @@ -#[cfg(any( - all(feature = "cdk_erigon", feature = "polygon_pos"), - all(feature = "cdk_erigon", feature = "eth_mainnet"), - all(feature = "polygon_pos", feature = "eth_mainnet"), - not(any( - feature = "cdk_erigon", - feature = "eth_mainnet", - feature = "polygon_pos" - )) -))] -compile_error!("One and only one of the feature chains `cdk_erigon`, `polygon_pos` or `eth_mainnet` must be selected"); +zk_evm_common::check_chain_features!(); use std::sync::Arc; use std::{env, io}; diff --git a/zero_bin/ops/Cargo.toml b/zero_bin/ops/Cargo.toml index 9f0b21094..ff01811ed 100644 --- a/zero_bin/ops/Cargo.toml +++ b/zero_bin/ops/Cargo.toml @@ -19,6 +19,7 @@ evm_arithmetization = { workspace = true } proof_gen = { workspace = true } trace_decoder = { workspace = true } zero_bin_common = { workspace = true } +zk_evm_common = { workspace = true } [features] default = ["eth_mainnet"] diff --git a/zero_bin/ops/src/lib.rs b/zero_bin/ops/src/lib.rs index 6dd8095b7..b0b35f451 100644 --- a/zero_bin/ops/src/lib.rs +++ b/zero_bin/ops/src/lib.rs @@ -1,14 +1,4 @@ -#[cfg(any( - all(feature = "cdk_erigon", feature = "polygon_pos"), - all(feature = "cdk_erigon", feature = "eth_mainnet"), - all(feature = "polygon_pos", feature = "eth_mainnet"), - not(any( - feature = "cdk_erigon", - feature = "eth_mainnet", - feature = "polygon_pos" - )) -))] -compile_error!("One and only one of the feature chains `cdk_erigon`, `polygon_pos` or `eth_mainnet` must be selected"); +zk_evm_common::check_chain_features!(); use std::time::Instant; diff --git a/zero_bin/prover/Cargo.toml b/zero_bin/prover/Cargo.toml index c649c3e22..5f084e88c 100644 --- a/zero_bin/prover/Cargo.toml +++ b/zero_bin/prover/Cargo.toml @@ -29,6 +29,7 @@ evm_arithmetization = { workspace = true } proof_gen = { workspace = true } trace_decoder = { workspace = true } zero_bin_common = { workspace = true } +zk_evm_common = { workspace = true } [features] diff --git a/zero_bin/prover/src/lib.rs b/zero_bin/prover/src/lib.rs index bf3a4f40c..2f18abaf4 100644 --- a/zero_bin/prover/src/lib.rs +++ b/zero_bin/prover/src/lib.rs @@ -1,14 +1,4 @@ -#[cfg(any( - all(feature = "cdk_erigon", feature = "polygon_pos"), - all(feature = "cdk_erigon", feature = "eth_mainnet"), - all(feature = "polygon_pos", feature = "eth_mainnet"), - not(any( - feature = "cdk_erigon", - feature = "eth_mainnet", - feature = "polygon_pos" - )) -))] -compile_error!("One and only one of the feature chains `cdk_erigon`, `polygon_pos` or `eth_mainnet` must be selected"); +zk_evm_common::check_chain_features!(); pub mod cli; diff --git a/zero_bin/rpc/src/lib.rs b/zero_bin/rpc/src/lib.rs index f02b9b554..638f34af2 100644 --- a/zero_bin/rpc/src/lib.rs +++ b/zero_bin/rpc/src/lib.rs @@ -1,14 +1,4 @@ -#[cfg(any( - all(feature = "cdk_erigon", feature = "polygon_pos"), - all(feature = "cdk_erigon", feature = "eth_mainnet"), - all(feature = "polygon_pos", feature = "eth_mainnet"), - not(any( - feature = "cdk_erigon", - feature = "eth_mainnet", - feature = "polygon_pos" - )) -))] -compile_error!("One and only one of the feature chains `cdk_erigon`, `polygon_pos` or `eth_mainnet` must be selected"); +zk_evm_common::check_chain_features!(); use std::sync::Arc; diff --git a/zero_bin/verifier/src/main.rs b/zero_bin/verifier/src/main.rs index a8dbb94d3..aa97d6087 100644 --- a/zero_bin/verifier/src/main.rs +++ b/zero_bin/verifier/src/main.rs @@ -1,14 +1,4 @@ -#[cfg(any( - all(feature = "cdk_erigon", feature = "polygon_pos"), - all(feature = "cdk_erigon", feature = "eth_mainnet"), - all(feature = "polygon_pos", feature = "eth_mainnet"), - not(any( - feature = "cdk_erigon", - feature = "eth_mainnet", - feature = "polygon_pos" - )) -))] -compile_error!("One and only one of the feature chains `cdk_erigon`, `polygon_pos` or `eth_mainnet` must be selected"); +zk_evm_common::check_chain_features!(); use std::env; use std::fs::File;