diff --git a/Cargo.lock b/Cargo.lock index abdd9b672..0ac2383f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1581,6 +1581,41 @@ dependencies = [ "typenum", ] +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.70", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.70", +] + [[package]] name = "dashmap" version = "5.5.3" @@ -1658,6 +1693,37 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "derive_builder" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0350b5cb0331628a5916d6c5c0b72e97393b8b6b03b47a9284f4e7f5a405ffd7" +dependencies = [ + "derive_builder_macro", +] + +[[package]] +name = "derive_builder_core" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d48cda787f839151732d396ac69e3473923d54312c070ee21e9effcaa8ca0b1d" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.70", +] + +[[package]] +name = "derive_builder_macro" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "206868b8242f27cecce124c19fd88157fbd0dd334df2587f36417bafbc85097b" +dependencies = [ + "derive_builder_core", + "syn 2.0.70", +] + [[package]] name = "derive_more" version = "0.99.18" @@ -2223,6 +2289,18 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "getset" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e45727250e75cc04ff2846a66397da8ef2b3db8e40e0cef4df67950a07621eb9" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "gimli" version = "0.29.0" @@ -2456,6 +2534,12 @@ dependencies = [ "tracing", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "0.5.0" @@ -2767,6 +2851,7 @@ dependencies = [ "toml", "tracing", "tracing-subscriber", + "vergen", "zero_bin_common", ] @@ -3085,6 +3170,15 @@ dependencies = [ "syn 2.0.70", ] +[[package]] +name = "num_threads" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" +dependencies = [ + "libc", +] + [[package]] name = "nunny" version = "0.2.1" @@ -4018,6 +4112,7 @@ version = "0.1.0" dependencies = [ "alloy", "anyhow", + "cargo_metadata", "clap", "compat", "evm_arithmetization", @@ -4034,6 +4129,7 @@ dependencies = [ "trace_decoder", "tracing-subscriber", "url", + "vergen", "zero_bin_common", ] @@ -4775,7 +4871,9 @@ checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa", + "libc", "num-conv", + "num_threads", "powerfmt", "serde", "time-core", @@ -5234,11 +5332,38 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "vergen" +version = "9.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c32e7318e93a9ac53693b6caccfb05ff22e04a44c7cf8a279051f24c09da286f" +dependencies = [ + "anyhow", + "derive_builder", + "rustc_version 0.4.0", + "rustversion", + "time", + "vergen-lib", +] + +[[package]] +name = "vergen-lib" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e06bee42361e43b60f363bad49d63798d0f42fb1768091812270eca00c784720" +dependencies = [ + "anyhow", + "derive_builder", + "getset", + "rustversion", +] + [[package]] name = "verifier" version = "0.1.0" dependencies = [ "anyhow", + "cargo_metadata", "clap", "dotenvy", "proof_gen", @@ -5246,6 +5371,7 @@ dependencies = [ "serde_path_to_error", "tracing", "tracing-subscriber", + "vergen", "zero_bin_common", ] @@ -5596,6 +5722,7 @@ name = "worker" version = "0.1.0" dependencies = [ "anyhow", + "cargo_metadata", "clap", "dotenvy", "jemallocator", @@ -5603,6 +5730,7 @@ dependencies = [ "paladin-core", "tokio", "tracing-subscriber", + "vergen", "zero_bin_common", ] @@ -5650,6 +5778,7 @@ dependencies = [ "alloy", "anyhow", "async-stream", + "cargo_metadata", "clap", "evm_arithmetization", "futures", @@ -5660,6 +5789,7 @@ dependencies = [ "thiserror", "tokio", "tracing", + "vergen", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 22c913324..910ae4d11 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,6 +47,7 @@ axum = "0.7.5" bitflags = "2.5.0" bitvec = "1.0.1" bytes = "1.6.0" +cargo_metadata = "0.18.1" ciborium = "0.2.2" ciborium-io = "0.2.2" clap = { version = "4.5.7", features = ["derive", "env"] } @@ -104,6 +105,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] } u4 = "0.1.0" uint = "0.9.5" url = "2.5.2" +vergen = { version = "9.0.0", features = ["build", "rustc"] } winnow = "0.6.13" # local dependencies diff --git a/trace_decoder/src/typed_mpt.rs b/trace_decoder/src/typed_mpt.rs index 947727737..f42d7fa37 100644 --- a/trace_decoder/src/typed_mpt.rs +++ b/trace_decoder/src/typed_mpt.rs @@ -135,6 +135,7 @@ impl TriePath { pub fn from_hash(H256(bytes): H256) -> Self { Self::new(AsNibbles(bytes)).expect("32 bytes is 64 nibbles, which fits") } + #[allow(unused)] // TODO(0xaatif): https://github.com/0xPolygonZero/zk_evm/issues/275 fn from_txn_ix(txn_ix: usize) -> Self { TriePath::new(AsNibbles(rlp::encode(&txn_ix))).expect( "\ @@ -163,6 +164,7 @@ impl TriePath { } } +#[allow(unused)] // TODO(0xaatif): https://github.com/0xPolygonZero/zk_evm/issues/275 /// Per-block, `txn_ix -> [u8]`. /// /// See @@ -171,6 +173,7 @@ pub struct TransactionTrie { untyped: HashedPartialTrie, } +#[allow(unused)] // TODO(0xaatif): https://github.com/0xPolygonZero/zk_evm/issues/275 impl TransactionTrie { pub fn insert(&mut self, txn_ix: usize, val: Vec) -> Result>, Error> { let prev = self @@ -190,6 +193,7 @@ impl TransactionTrie { } } +#[allow(unused)] // TODO(0xaatif): https://github.com/0xPolygonZero/zk_evm/issues/275 /// Per-block, `txn_ix -> [u8]`. /// /// See @@ -198,6 +202,7 @@ pub struct ReceiptTrie { untyped: HashedPartialTrie, } +#[allow(unused)] // TODO(0xaatif): https://github.com/0xPolygonZero/zk_evm/issues/275 impl ReceiptTrie { pub fn insert(&mut self, txn_ix: usize, val: Vec) -> Result>, Error> { let prev = self @@ -300,6 +305,7 @@ impl StorageTrie { pub fn root(&self) -> H256 { self.untyped.hash() } + #[allow(unused)] // TODO(0xaatif): https://github.com/0xPolygonZero/zk_evm/issues/275 pub fn remove(&mut self, path: TriePath) -> Result>, Error> { self.untyped .delete(path.into_nibbles()) @@ -308,7 +314,7 @@ impl StorageTrie { pub fn as_hashed_partial_trie(&self) -> &mpt_trie::partial_trie::HashedPartialTrie { &self.untyped } - + #[allow(unused)] // TODO(0xaatif): https://github.com/0xPolygonZero/zk_evm/issues/275 pub fn as_mut_hashed_partial_trie_unchecked(&mut self) -> &mut HashedPartialTrie { &mut self.untyped } diff --git a/zero_bin/README.md b/zero_bin/README.md index 359830aeb..e97a2b2ee 100644 --- a/zero_bin/README.md +++ b/zero_bin/README.md @@ -87,13 +87,15 @@ Usage: leader [OPTIONS] Commands: stdio Reads input from stdin and writes output to stdout jerigon Reads input from a Jerigon node and writes output to stdout - native Reads input from a native node and writes output to stdout + native Reads input from a native node and writes output to stdout http Reads input from HTTP and writes output to a directory help Print this message or the help of the given subcommand(s) Options: -h, --help Print help (see a summary with '-h') + --version + Fetch the `evm_arithmetization` package version, build commit hash and build timestamp Paladin options: -t, --task-bus-routing-key @@ -366,6 +368,7 @@ cargo r --bin verifier -- --help Usage: verifier --file-path Options: + --version Fetch the `evm_arithmetization` package version, build commit hash and build timestamp -f, --file-path The file containing the proof to verify -h, --help Print help ``` @@ -386,11 +389,13 @@ cargo r --bin rpc -- --help Usage: rpc Commands: - fetch Fetch and generate prover input from the RPC endpoint - help Print this message or the help of the given subcommand(s) + fetch Fetch and generate prover input from the RPC endpoint + help Print this message or the help of the given subcommand(s) Options: -h, --help Print help + --version + Fetch the `evm_arithmetization` package version, build commit hash and build timestamp ``` Example: @@ -457,15 +462,20 @@ Finally, note that both of these testing scripts force proof generation to be se The trace decoder module has some basic regression tests, using the json witness data from the `trace_decoder/tests/data/witnesses` subdirectories. When needed (e.g. some block with corner-case discovered), additional input witness data should be generated using the following procedure: + 1. Run the `rpc` tool to fetch the block (or multiple blocks) witness: + ```sh cargo run --bin rpc fetch --rpc-url --start-block --end-block > ./b_.json ``` + 2. Download the header file for the block (or range of blocks), making the json array of headers: + ```sh file_name = "b__header.json" echo "[" > $file_name && cast rpc eth_getBlockByNumber "0x" 'false' --rpc-url >> $file_name && echo "]" >> $file_name ``` + Move the generated files to the appropriate subdirectory, and they will be automatically included in the test run. ## License diff --git a/zero_bin/common/Cargo.toml b/zero_bin/common/Cargo.toml index 9ee2ac5fe..0d0e35191 100644 --- a/zero_bin/common/Cargo.toml +++ b/zero_bin/common/Cargo.toml @@ -22,3 +22,10 @@ futures = { workspace = true } tokio = { workspace = true } alloy = { workspace = true } async-stream = { workspace = true } +cargo_metadata = { workspace = true } +vergen = { workspace = true } + +[build-dependencies] +cargo_metadata = { workspace = true } +vergen = { workspace = true } +anyhow = { workspace = true } diff --git a/zero_bin/leader/build.rs b/zero_bin/common/build.rs similarity index 56% rename from zero_bin/leader/build.rs rename to zero_bin/common/build.rs index 0adcbb347..c3e7b006d 100644 --- a/zero_bin/leader/build.rs +++ b/zero_bin/common/build.rs @@ -1,5 +1,15 @@ use anyhow::Context as _; +use vergen::{BuildBuilder, Emitter, RustcBuilder}; + fn main() -> anyhow::Result<()> { + let build_timestamp = BuildBuilder::default().build_timestamp(true).build()?; + let rust_commit_hash = RustcBuilder::default().commit_hash(true).build()?; + + Emitter::default() + .add_instructions(&build_timestamp)? + .add_instructions(&rust_commit_hash)? + .emit()?; + let meta = cargo_metadata::MetadataCommand::new() .exec() .context("failed to probe cargo-metadata")?; @@ -10,10 +20,11 @@ fn main() -> anyhow::Result<()> { .context("couldn't find evm_arithmetization package")? .version; println!( - "cargo::rustc-env=EVM_ARITHMETIZATION_PACKAGE_VERSION={}.{}.x", + "cargo::rustc-env=EVM_ARITHMETIZATION_PKG_VER={}.{}.x", // patch version change should not prompt circuits regeneration version.major, version.minor ); + Ok(()) } diff --git a/zero_bin/common/src/lib.rs b/zero_bin/common/src/lib.rs index 1b0b18e9b..5570a5d5f 100644 --- a/zero_bin/common/src/lib.rs +++ b/zero_bin/common/src/lib.rs @@ -3,3 +3,4 @@ pub mod debug_utils; pub mod fs; pub mod parsing; pub mod prover_state; +pub mod version; diff --git a/zero_bin/common/src/version.rs b/zero_bin/common/src/version.rs new file mode 100644 index 000000000..5dbbf7f9b --- /dev/null +++ b/zero_bin/common/src/version.rs @@ -0,0 +1,10 @@ +pub fn print_version( + evm_arithmetization_package_version: &str, + rustc_commit_hash: &str, + rustc_timestamp: &str, +) { + println!( + "evm_arithmetization Package Version: {}\nBuild Commit Hash: {}\nBuild Timestamp: {}", + evm_arithmetization_package_version, rustc_commit_hash, rustc_timestamp + ) +} diff --git a/zero_bin/leader/Cargo.toml b/zero_bin/leader/Cargo.toml index dfb0070b4..5d0881da1 100644 --- a/zero_bin/leader/Cargo.toml +++ b/zero_bin/leader/Cargo.toml @@ -7,6 +7,7 @@ license.workspace = true repository.workspace = true keywords.workspace = true categories.workspace = true +build = "../common/build.rs" [dependencies] paladin-core = { workspace = true } @@ -36,5 +37,6 @@ default = [] test_only = ["ops/test_only", "prover/test_only"] [build-dependencies] -cargo_metadata = "0.18.1" +cargo_metadata = { workspace = true } +vergen = { workspace = true } anyhow = { workspace = true } diff --git a/zero_bin/leader/src/main.rs b/zero_bin/leader/src/main.rs index 94b2abb94..9aafcd5fd 100644 --- a/zero_bin/leader/src/main.rs +++ b/zero_bin/leader/src/main.rs @@ -11,6 +11,7 @@ use paladin::runtime::Runtime; use proof_gen::proof_types::GeneratedBlockProof; use tracing::{info, warn}; use zero_bin_common::block_interval::BlockInterval; +use zero_bin_common::version; use crate::client::{client_main, ProofParams}; @@ -20,7 +21,7 @@ mod http; mod init; mod stdio; -const EVM_ARITH_VER_KEY: &str = "EVM_ARITHMETIZATION_PKG_VER"; +const EVM_ARITHMETIZATION_PKG_VER: &str = "EVM_ARITHMETIZATION_PKG_VER"; fn get_previous_proof(path: Option) -> Result> { if path.is_none() { @@ -39,17 +40,27 @@ async fn main() -> Result<()> { load_dotenvy_vars_if_present(); init::tracing(); - if env::var_os(EVM_ARITH_VER_KEY).is_none() { + if env::var_os(EVM_ARITHMETIZATION_PKG_VER).is_none() { // Safety: // - we're early enough in main that nothing else should race unsafe { env::set_var( - EVM_ARITH_VER_KEY, - // see build.rs - env!("EVM_ARITHMETIZATION_PACKAGE_VERSION"), + EVM_ARITHMETIZATION_PKG_VER, + env!("EVM_ARITHMETIZATION_PKG_VER"), ); } - }; + } + + let args: Vec = env::args().collect(); + + if args.contains(&"--version".to_string()) { + version::print_version( + env!("EVM_ARITHMETIZATION_PKG_VER"), + env!("VERGEN_RUSTC_COMMIT_HASH"), + env!("VERGEN_BUILD_TIMESTAMP"), + ); + return Ok(()); + } let args = cli::Cli::parse(); if let paladin::config::Runtime::InMemory = args.paladin.runtime { @@ -60,13 +71,12 @@ async fn main() -> Result<()> { .initialize()?; } - let runtime = Runtime::from_config(&args.paladin, register()).await?; - match args.command { Command::Stdio { previous_proof, save_inputs_on_error, } => { + let runtime = Runtime::from_config(&args.paladin, register()).await?; let previous_proof = get_previous_proof(previous_proof)?; stdio::stdio_main(runtime, previous_proof, save_inputs_on_error).await?; } @@ -75,6 +85,7 @@ async fn main() -> Result<()> { output_dir, save_inputs_on_error, } => { + let runtime = Runtime::from_config(&args.paladin, register()).await?; // check if output_dir exists, is a directory, and is writable let output_dir_metadata = std::fs::metadata(&output_dir); if output_dir_metadata.is_err() { @@ -99,6 +110,7 @@ async fn main() -> Result<()> { backoff, max_retries, } => { + let runtime = Runtime::from_config(&args.paladin, register()).await?; let previous_proof = get_previous_proof(previous_proof)?; let mut block_interval = BlockInterval::new(&block_interval)?; diff --git a/zero_bin/rpc/Cargo.toml b/zero_bin/rpc/Cargo.toml index 6724c16fe..14f447cef 100644 --- a/zero_bin/rpc/Cargo.toml +++ b/zero_bin/rpc/Cargo.toml @@ -7,6 +7,7 @@ license.workspace = true repository.workspace = true keywords.workspace = true categories.workspace = true +build = "../common/build.rs" [dependencies] __compat_primitive_types = { workspace = true } @@ -30,3 +31,8 @@ url = { workspace = true } compat = { workspace = true } zero_bin_common = { workspace = true } prover = { workspace = true } + +[build-dependencies] +cargo_metadata = { workspace = true } +vergen = { workspace = true } +anyhow = { workspace = true } diff --git a/zero_bin/rpc/src/main.rs b/zero_bin/rpc/src/main.rs index 197e387de..ee1ed08e0 100644 --- a/zero_bin/rpc/src/main.rs +++ b/zero_bin/rpc/src/main.rs @@ -1,4 +1,4 @@ -use std::io; +use std::{env, io}; use alloy::rpc::types::eth::BlockId; use clap::{Parser, ValueHint}; @@ -7,6 +7,7 @@ use rpc::{retry::build_http_retry_provider, RpcType}; use tracing_subscriber::{prelude::*, EnvFilter}; use url::Url; use zero_bin_common::block_interval::BlockInterval; +use zero_bin_common::version; #[derive(Parser)] pub enum Cli { @@ -78,6 +79,16 @@ impl Cli { #[tokio::main] async fn main() -> anyhow::Result<()> { + let args: Vec = env::args().collect(); + if args.contains(&"--version".to_string()) { + version::print_version( + env!("EVM_ARITHMETIZATION_PKG_VER"), + env!("VERGEN_RUSTC_COMMIT_HASH"), + env!("VERGEN_BUILD_TIMESTAMP"), + ); + return Ok(()); + } + tracing_subscriber::Registry::default() .with( tracing_subscriber::fmt::layer() diff --git a/zero_bin/verifier/Cargo.toml b/zero_bin/verifier/Cargo.toml index 39968b4a6..ab9e5068f 100644 --- a/zero_bin/verifier/Cargo.toml +++ b/zero_bin/verifier/Cargo.toml @@ -3,6 +3,7 @@ name = "verifier" authors = ["Polygon Zero "] version = "0.1.0" edition = "2021" +build = "../common/build.rs" [dependencies] clap = { workspace = true } @@ -16,3 +17,8 @@ proof_gen = { workspace = true } # Local dependencies zero_bin_common = { path = "../common" } + +[build-dependencies] +cargo_metadata = { workspace = true } +vergen = { workspace = true } +anyhow = { workspace = true } diff --git a/zero_bin/verifier/src/main.rs b/zero_bin/verifier/src/main.rs index 0c072fed9..e14ad7827 100644 --- a/zero_bin/verifier/src/main.rs +++ b/zero_bin/verifier/src/main.rs @@ -1,3 +1,4 @@ +use std::env; use std::fs::File; use anyhow::Result; @@ -6,6 +7,7 @@ use dotenvy::dotenv; use proof_gen::proof_types::GeneratedBlockProof; use serde_json::Deserializer; use tracing::info; +use zero_bin_common::version; mod cli; mod init; @@ -14,7 +16,18 @@ fn main() -> Result<()> { dotenv().ok(); init::tracing(); + let args: Vec = env::args().collect(); + if args.contains(&"--version".to_string()) { + version::print_version( + env!("EVM_ARITHMETIZATION_PKG_VER"), + env!("VERGEN_RUSTC_COMMIT_HASH"), + env!("VERGEN_BUILD_TIMESTAMP"), + ); + return Ok(()); + } + let args = cli::Cli::parse(); + let file = File::open(args.file_path)?; let des = &mut Deserializer::from_reader(&file); let input_proofs: Vec = serde_path_to_error::deserialize(des)?; diff --git a/zero_bin/worker/Cargo.toml b/zero_bin/worker/Cargo.toml index 16d55ef29..3a146c90e 100644 --- a/zero_bin/worker/Cargo.toml +++ b/zero_bin/worker/Cargo.toml @@ -7,6 +7,7 @@ license.workspace = true repository.workspace = true keywords.workspace = true categories.workspace = true +build = "../common/build.rs" [dependencies] paladin-core = { workspace = true } @@ -22,3 +23,8 @@ zero_bin_common = { workspace = true } [target.'cfg(not(target_env = "msvc"))'.dependencies] jemallocator = "0.5.4" + +[build-dependencies] +cargo_metadata = { workspace = true } +vergen = { workspace = true } +anyhow = { workspace = true } diff --git a/zero_bin/worker/src/main.rs b/zero_bin/worker/src/main.rs index 4fb8675ff..2358401f4 100644 --- a/zero_bin/worker/src/main.rs +++ b/zero_bin/worker/src/main.rs @@ -1,9 +1,12 @@ +use std::env; + use anyhow::Result; use clap::Parser; use dotenvy::dotenv; use ops::register; use paladin::runtime::WorkerRuntime; use zero_bin_common::prover_state::cli::CliProverStateConfig; +use zero_bin_common::version; mod init; @@ -13,7 +16,7 @@ mod init; #[global_allocator] static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc; -#[derive(Parser, Debug)] +#[derive(Parser)] struct Cli { #[clap(flatten)] paladin: paladin::config::Config, @@ -23,6 +26,16 @@ struct Cli { #[tokio::main] async fn main() -> Result<()> { + let args: Vec = env::args().collect(); + if args.contains(&"--version".to_string()) { + version::print_version( + env!("EVM_ARITHMETIZATION_PKG_VER"), + env!("VERGEN_RUSTC_COMMIT_HASH"), + env!("VERGEN_BUILD_TIMESTAMP"), + ); + return Ok(()); + } + dotenv().ok(); init::tracing(); let args = Cli::parse();