From 4198fd988e7b4bcd40f18fd99052d75971a3bf0f Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Sun, 28 Jul 2024 19:11:34 +0530 Subject: [PATCH 1/8] implement version command for all zero bin binaries --- Cargo.lock | 128 ++++++++++++++++++++++++++++++++++ zero_bin/README.md | 14 +++- zero_bin/leader/Cargo.toml | 2 + zero_bin/leader/build.rs | 11 +++ zero_bin/leader/src/cli.rs | 1 + zero_bin/leader/src/main.rs | 39 ++++++++++- zero_bin/rpc/Cargo.toml | 6 ++ zero_bin/rpc/build.rs | 30 ++++++++ zero_bin/rpc/src/main.rs | 50 ++++++++++++- zero_bin/verifier/Cargo.toml | 6 ++ zero_bin/verifier/build.rs | 30 ++++++++ zero_bin/verifier/src/cli.rs | 14 +++- zero_bin/verifier/src/main.rs | 60 +++++++++++++++- zero_bin/worker/Cargo.toml | 6 ++ zero_bin/worker/build.rs | 30 ++++++++ zero_bin/worker/src/main.rs | 66 +++++++++++++++++- 16 files changed, 479 insertions(+), 14 deletions(-) create mode 100644 zero_bin/rpc/build.rs create mode 100644 zero_bin/verifier/build.rs create mode 100644 zero_bin/worker/build.rs diff --git a/Cargo.lock b/Cargo.lock index abdd9b672..f1a1c856f 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", ] diff --git a/zero_bin/README.md b/zero_bin/README.md index 359830aeb..08b56844f 100644 --- a/zero_bin/README.md +++ b/zero_bin/README.md @@ -87,7 +87,8 @@ 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 + version Fetch the version, build commit hash, build timestamp http Reads input from HTTP and writes output to a directory help Print this message or the help of the given subcommand(s) @@ -366,6 +367,7 @@ cargo r --bin verifier -- --help Usage: verifier --file-path Options: + version Fetch the version, build commit hash, build timestamp -f, --file-path The file containing the proof to verify -h, --help Print help ``` @@ -386,8 +388,9 @@ 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 + version Fetch the version, build commit hash, build timestamp + help Print this message or the help of the given subcommand(s) Options: -h, --help Print help @@ -457,15 +460,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/leader/Cargo.toml b/zero_bin/leader/Cargo.toml index dfb0070b4..aa7624397 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 = "build.rs" [dependencies] paladin-core = { workspace = true } @@ -38,3 +39,4 @@ test_only = ["ops/test_only", "prover/test_only"] [build-dependencies] cargo_metadata = "0.18.1" anyhow = { workspace = true } +vergen = { version = "9.0.0", features = ["build", "rustc"] } diff --git a/zero_bin/leader/build.rs b/zero_bin/leader/build.rs index 0adcbb347..da63d6e21 100644 --- a/zero_bin/leader/build.rs +++ b/zero_bin/leader/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")?; @@ -15,5 +25,6 @@ fn main() -> anyhow::Result<()> { version.major, version.minor ); + Ok(()) } diff --git a/zero_bin/leader/src/cli.rs b/zero_bin/leader/src/cli.rs index eb3ea08f8..9dc4501e3 100644 --- a/zero_bin/leader/src/cli.rs +++ b/zero_bin/leader/src/cli.rs @@ -87,4 +87,5 @@ pub(crate) enum Command { #[arg(short, long, default_value_t = false)] save_inputs_on_error: bool, }, + Version {}, } diff --git a/zero_bin/leader/src/main.rs b/zero_bin/leader/src/main.rs index 94b2abb94..94f02b729 100644 --- a/zero_bin/leader/src/main.rs +++ b/zero_bin/leader/src/main.rs @@ -21,6 +21,8 @@ mod init; mod stdio; const EVM_ARITH_VER_KEY: &str = "EVM_ARITHMETIZATION_PKG_VER"; +const VERGEN_BUILD_TIMESTAMP: &str = "VERGEN_BUILD_TIMESTAMP"; +const VERGEN_RUSTC_COMMIT_HASH: &str = "VERGEN_RUSTC_COMMIT_HASH"; fn get_previous_proof(path: Option) -> Result> { if path.is_none() { @@ -49,7 +51,29 @@ async fn main() -> Result<()> { env!("EVM_ARITHMETIZATION_PACKAGE_VERSION"), ); } - }; + } + if env::var_os(VERGEN_BUILD_TIMESTAMP).is_none() { + // Safety: + // - we're early enough in main that nothing else should race + unsafe { + env::set_var( + VERGEN_BUILD_TIMESTAMP, + // see build.rs + env!("VERGEN_BUILD_TIMESTAMP"), + ); + } + } + if env::var_os(VERGEN_RUSTC_COMMIT_HASH).is_none() { + // Safety: + // - we're early enough in main that nothing else should race + unsafe { + env::set_var( + VERGEN_RUSTC_COMMIT_HASH, + // see build.rs + env!("VERGEN_RUSTC_COMMIT_HASH"), + ); + } + } let args = cli::Cli::parse(); if let paladin::config::Runtime::InMemory = args.paladin.runtime { @@ -60,13 +84,20 @@ async fn main() -> Result<()> { .initialize()?; } - let runtime = Runtime::from_config(&args.paladin, register()).await?; - match args.command { + Command::Version {} => { + println!( + "Evm Arithmetization package version: {}", + env::var(EVM_ARITH_VER_KEY)? + ); + println!("Build Commit Hash: {}", env::var(VERGEN_RUSTC_COMMIT_HASH)?); + println!("Build Timestamp: {}", env::var(VERGEN_BUILD_TIMESTAMP)?); + } 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 +106,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 +131,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..cba6c926c 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 = "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] +vergen = { version = "9.0.0", features = ["build", "rustc"] } +anyhow = { workspace = true } +cargo_metadata = "0.18.1" diff --git a/zero_bin/rpc/build.rs b/zero_bin/rpc/build.rs new file mode 100644 index 000000000..da63d6e21 --- /dev/null +++ b/zero_bin/rpc/build.rs @@ -0,0 +1,30 @@ +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")?; + let version = &meta + .packages + .iter() + .find(|it| it.name == "evm_arithmetization") + .context("couldn't find evm_arithmetization package")? + .version; + println!( + "cargo::rustc-env=EVM_ARITHMETIZATION_PACKAGE_VERSION={}.{}.x", + // patch version change should not prompt circuits regeneration + version.major, + version.minor + ); + + Ok(()) +} diff --git a/zero_bin/rpc/src/main.rs b/zero_bin/rpc/src/main.rs index 197e387de..cdb671ffd 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}; @@ -8,8 +8,14 @@ use tracing_subscriber::{prelude::*, EnvFilter}; use url::Url; use zero_bin_common::block_interval::BlockInterval; +const EVM_ARITH_VER_KEY: &str = "EVM_ARITHMETIZATION_PKG_VER"; +const VERGEN_BUILD_TIMESTAMP: &str = "VERGEN_BUILD_TIMESTAMP"; +const VERGEN_RUSTC_COMMIT_HASH: &str = "VERGEN_RUSTC_COMMIT_HASH"; + #[derive(Parser)] pub enum Cli { + /// Print the version of the rpc package + Version {}, /// Fetch and generate prover input from the RPC endpoint Fetch { // Starting block of interval to fetch @@ -41,6 +47,14 @@ impl Cli { /// Execute the cli command. pub async fn execute(self) -> anyhow::Result<()> { match self { + Self::Version {} => { + println!( + "Evm Arithmetization package version: {}", + env::var(EVM_ARITH_VER_KEY)? + ); + println!("Build Commit Hash: {}", env::var(VERGEN_RUSTC_COMMIT_HASH)?); + println!("Build Timestamp: {}", env::var(VERGEN_BUILD_TIMESTAMP)?); + } Self::Fetch { start_block, end_block, @@ -78,6 +92,40 @@ impl Cli { #[tokio::main] async fn main() -> anyhow::Result<()> { + if env::var_os(EVM_ARITH_VER_KEY).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"), + ); + } + } + if env::var_os(VERGEN_BUILD_TIMESTAMP).is_none() { + // Safety: + // - we're early enough in main that nothing else should race + unsafe { + env::set_var( + VERGEN_BUILD_TIMESTAMP, + // see build.rs + env!("VERGEN_BUILD_TIMESTAMP"), + ); + } + } + if env::var_os(VERGEN_RUSTC_COMMIT_HASH).is_none() { + // Safety: + // - we're early enough in main that nothing else should race + unsafe { + env::set_var( + VERGEN_RUSTC_COMMIT_HASH, + // see build.rs + env!("VERGEN_RUSTC_COMMIT_HASH"), + ); + } + } + 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..c1a76f56a 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 = "build.rs" [dependencies] clap = { workspace = true } @@ -16,3 +17,8 @@ proof_gen = { workspace = true } # Local dependencies zero_bin_common = { path = "../common" } + +[build-dependencies] +vergen = { version = "9.0.0", features = ["build", "rustc"] } +anyhow = { workspace = true } +cargo_metadata = "0.18.1" diff --git a/zero_bin/verifier/build.rs b/zero_bin/verifier/build.rs new file mode 100644 index 000000000..da63d6e21 --- /dev/null +++ b/zero_bin/verifier/build.rs @@ -0,0 +1,30 @@ +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")?; + let version = &meta + .packages + .iter() + .find(|it| it.name == "evm_arithmetization") + .context("couldn't find evm_arithmetization package")? + .version; + println!( + "cargo::rustc-env=EVM_ARITHMETIZATION_PACKAGE_VERSION={}.{}.x", + // patch version change should not prompt circuits regeneration + version.major, + version.minor + ); + + Ok(()) +} diff --git a/zero_bin/verifier/src/cli.rs b/zero_bin/verifier/src/cli.rs index 76306ec41..f31db98fc 100644 --- a/zero_bin/verifier/src/cli.rs +++ b/zero_bin/verifier/src/cli.rs @@ -1,15 +1,23 @@ -use std::path::PathBuf; +use std::{path::PathBuf, string}; -use clap::{Parser, ValueHint}; +use clap::{Parser, Subcommand, ValueHint}; use zero_bin_common::prover_state::cli::CliProverStateConfig; #[derive(Parser)] pub(crate) struct Cli { + #[command(subcommand)] + pub(crate) command: Option, + /// The file containing the proof to verify #[arg(short, long, value_hint = ValueHint::FilePath)] - pub(crate) file_path: PathBuf, + pub(crate) file_path: Option, /// The prover configuration used to generate the preprocessed circuits /// and the verifier state. #[clap(flatten)] pub(crate) prover_state_config: CliProverStateConfig, } + +#[derive(Subcommand)] +pub(crate) enum Command { + Version {}, +} diff --git a/zero_bin/verifier/src/main.rs b/zero_bin/verifier/src/main.rs index 0c072fed9..c31f19050 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; @@ -10,12 +11,67 @@ use tracing::info; mod cli; mod init; +use cli::Command; + +const EVM_ARITH_VER_KEY: &str = "EVM_ARITHMETIZATION_PKG_VER"; +const VERGEN_BUILD_TIMESTAMP: &str = "VERGEN_BUILD_TIMESTAMP"; +const VERGEN_RUSTC_COMMIT_HASH: &str = "VERGEN_RUSTC_COMMIT_HASH"; + fn main() -> Result<()> { dotenv().ok(); init::tracing(); - let args = cli::Cli::parse(); - let file = File::open(args.file_path)?; + + if env::var_os(EVM_ARITH_VER_KEY).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"), + ); + } + } + if env::var_os(VERGEN_BUILD_TIMESTAMP).is_none() { + // Safety: + // - we're early enough in main that nothing else should race + unsafe { + env::set_var( + VERGEN_BUILD_TIMESTAMP, + // see build.rs + env!("VERGEN_BUILD_TIMESTAMP"), + ); + } + } + if env::var_os(VERGEN_RUSTC_COMMIT_HASH).is_none() { + // Safety: + // - we're early enough in main that nothing else should race + unsafe { + env::set_var( + VERGEN_RUSTC_COMMIT_HASH, + // see build.rs + env!("VERGEN_RUSTC_COMMIT_HASH"), + ); + } + } + + if args.command.is_some() { + match args.command { + Some(Command::Version {}) => { + println!( + "Evm Arithmetization package version: {}", + env::var(EVM_ARITH_VER_KEY)? + ); + println!("Build Commit Hash: {}", env::var(VERGEN_RUSTC_COMMIT_HASH)?); + println!("Build Timestamp: {}", env::var(VERGEN_BUILD_TIMESTAMP)?); + return Ok(()); + } + None => {} + } + } + + let file = File::open(args.file_path.unwrap())?; 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..1dc01077f 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 = "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] +vergen = { version = "9.0.0", features = ["build", "rustc"] } +anyhow = { workspace = true } +cargo_metadata = "0.18.1" diff --git a/zero_bin/worker/build.rs b/zero_bin/worker/build.rs new file mode 100644 index 000000000..da63d6e21 --- /dev/null +++ b/zero_bin/worker/build.rs @@ -0,0 +1,30 @@ +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")?; + let version = &meta + .packages + .iter() + .find(|it| it.name == "evm_arithmetization") + .context("couldn't find evm_arithmetization package")? + .version; + println!( + "cargo::rustc-env=EVM_ARITHMETIZATION_PACKAGE_VERSION={}.{}.x", + // patch version change should not prompt circuits regeneration + version.major, + version.minor + ); + + Ok(()) +} diff --git a/zero_bin/worker/src/main.rs b/zero_bin/worker/src/main.rs index 4fb8675ff..3bf899e54 100644 --- a/zero_bin/worker/src/main.rs +++ b/zero_bin/worker/src/main.rs @@ -1,5 +1,7 @@ +use std::env::{self}; + use anyhow::Result; -use clap::Parser; +use clap::{Parser, Subcommand}; use dotenvy::dotenv; use ops::register; use paladin::runtime::WorkerRuntime; @@ -13,20 +15,80 @@ mod init; #[global_allocator] static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc; -#[derive(Parser, Debug)] +const EVM_ARITH_VER_KEY: &str = "EVM_ARITHMETIZATION_PKG_VER"; +const VERGEN_BUILD_TIMESTAMP: &str = "VERGEN_BUILD_TIMESTAMP"; +const VERGEN_RUSTC_COMMIT_HASH: &str = "VERGEN_RUSTC_COMMIT_HASH"; + +#[derive(Parser)] struct Cli { + #[command(subcommand)] + pub(crate) command: Option, #[clap(flatten)] paladin: paladin::config::Config, #[clap(flatten)] prover_state_config: CliProverStateConfig, } +#[derive(Debug, Subcommand)] +pub(crate) enum Command { + Version {}, +} + #[tokio::main] async fn main() -> Result<()> { dotenv().ok(); init::tracing(); let args = Cli::parse(); + if env::var_os(EVM_ARITH_VER_KEY).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"), + ); + } + } + if env::var_os(VERGEN_BUILD_TIMESTAMP).is_none() { + // Safety: + // - we're early enough in main that nothing else should race + unsafe { + env::set_var( + VERGEN_BUILD_TIMESTAMP, + // see build.rs + env!("VERGEN_BUILD_TIMESTAMP"), + ); + } + } + if env::var_os(VERGEN_RUSTC_COMMIT_HASH).is_none() { + // Safety: + // - we're early enough in main that nothing else should race + unsafe { + env::set_var( + VERGEN_RUSTC_COMMIT_HASH, + // see build.rs + env!("VERGEN_RUSTC_COMMIT_HASH"), + ); + } + } + + if args.command.is_some() { + match args.command { + Some(Command::Version {}) => { + println!( + "Evm Arithmetization package version: {}", + env::var(EVM_ARITH_VER_KEY)? + ); + println!("Build Commit Hash: {}", env::var(VERGEN_RUSTC_COMMIT_HASH)?); + println!("Build Timestamp: {}", env::var(VERGEN_BUILD_TIMESTAMP)?); + return Ok(()); + } + None => {} + } + } + args.prover_state_config .into_prover_state_manager() .initialize()?; From 21cfff3a4985af230563d9dba7ac991801aebc2d Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Mon, 29 Jul 2024 10:18:57 +0530 Subject: [PATCH 2/8] fix clippy issues --- zero_bin/verifier/src/cli.rs | 2 +- zero_bin/verifier/src/main.rs | 21 ++++++++------------- zero_bin/worker/src/main.rs | 21 ++++++++------------- 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/zero_bin/verifier/src/cli.rs b/zero_bin/verifier/src/cli.rs index f31db98fc..82c1ba49f 100644 --- a/zero_bin/verifier/src/cli.rs +++ b/zero_bin/verifier/src/cli.rs @@ -1,4 +1,4 @@ -use std::{path::PathBuf, string}; +use std::string; use clap::{Parser, Subcommand, ValueHint}; use zero_bin_common::prover_state::cli::CliProverStateConfig; diff --git a/zero_bin/verifier/src/main.rs b/zero_bin/verifier/src/main.rs index c31f19050..99d9cfb87 100644 --- a/zero_bin/verifier/src/main.rs +++ b/zero_bin/verifier/src/main.rs @@ -56,19 +56,14 @@ fn main() -> Result<()> { } } - if args.command.is_some() { - match args.command { - Some(Command::Version {}) => { - println!( - "Evm Arithmetization package version: {}", - env::var(EVM_ARITH_VER_KEY)? - ); - println!("Build Commit Hash: {}", env::var(VERGEN_RUSTC_COMMIT_HASH)?); - println!("Build Timestamp: {}", env::var(VERGEN_BUILD_TIMESTAMP)?); - return Ok(()); - } - None => {} - } + if let Some(Command::Version {}) = args.command { + println!( + "Evm Arithmetization package version: {}", + env::var(EVM_ARITH_VER_KEY)? + ); + println!("Build Commit Hash: {}", env::var(VERGEN_RUSTC_COMMIT_HASH)?); + println!("Build Timestamp: {}", env::var(VERGEN_BUILD_TIMESTAMP)?); + return Ok(()); } let file = File::open(args.file_path.unwrap())?; diff --git a/zero_bin/worker/src/main.rs b/zero_bin/worker/src/main.rs index 3bf899e54..92e401843 100644 --- a/zero_bin/worker/src/main.rs +++ b/zero_bin/worker/src/main.rs @@ -74,19 +74,14 @@ async fn main() -> Result<()> { } } - if args.command.is_some() { - match args.command { - Some(Command::Version {}) => { - println!( - "Evm Arithmetization package version: {}", - env::var(EVM_ARITH_VER_KEY)? - ); - println!("Build Commit Hash: {}", env::var(VERGEN_RUSTC_COMMIT_HASH)?); - println!("Build Timestamp: {}", env::var(VERGEN_BUILD_TIMESTAMP)?); - return Ok(()); - } - None => {} - } + if let Some(Command::Version {}) = args.command { + println!( + "Evm Arithmetization package version: {}", + env::var(EVM_ARITH_VER_KEY)? + ); + println!("Build Commit Hash: {}", env::var(VERGEN_RUSTC_COMMIT_HASH)?); + println!("Build Timestamp: {}", env::var(VERGEN_BUILD_TIMESTAMP)?); + return Ok(()); } args.prover_state_config From 5d4356ac240abeabffd004ea8d206b15a93a8bc9 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Mon, 29 Jul 2024 17:58:49 +0530 Subject: [PATCH 3/8] fix review comments --- zero_bin/common/src/lib.rs | 1 + zero_bin/common/src/version.rs | 12 ++++++ zero_bin/leader/Cargo.toml | 2 +- zero_bin/leader/src/main.rs | 48 +++++----------------- zero_bin/rpc/Cargo.toml | 2 +- zero_bin/rpc/build.rs | 30 -------------- zero_bin/rpc/src/main.rs | 52 +++--------------------- zero_bin/verifier/Cargo.toml | 2 +- zero_bin/verifier/build.rs | 30 -------------- zero_bin/verifier/src/main.rs | 48 +++------------------- zero_bin/{leader/build.rs => version.rs} | 2 +- zero_bin/worker/Cargo.toml | 2 +- zero_bin/worker/build.rs | 30 -------------- zero_bin/worker/src/main.rs | 50 +++-------------------- 14 files changed, 46 insertions(+), 265 deletions(-) create mode 100644 zero_bin/common/src/version.rs delete mode 100644 zero_bin/rpc/build.rs delete mode 100644 zero_bin/verifier/build.rs rename zero_bin/{leader/build.rs => version.rs} (92%) delete mode 100644 zero_bin/worker/build.rs 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..94e9529c1 --- /dev/null +++ b/zero_bin/common/src/version.rs @@ -0,0 +1,12 @@ +pub fn print_version( + evm_arithmetization_package_version: &str, + rustc_commit_hash: &str, + rustc_timestamp: &str, +) { + println!( + "Evm Arithmetization package version: {:?}", + evm_arithmetization_package_version + ); + println!("Build Commit Hash: {:?}", rustc_commit_hash); + println!("Build Timestamp: {:?}", rustc_timestamp); +} diff --git a/zero_bin/leader/Cargo.toml b/zero_bin/leader/Cargo.toml index aa7624397..7ebfc95b4 100644 --- a/zero_bin/leader/Cargo.toml +++ b/zero_bin/leader/Cargo.toml @@ -7,7 +7,7 @@ license.workspace = true repository.workspace = true keywords.workspace = true categories.workspace = true -build = "build.rs" +build = "../version.rs" [dependencies] paladin-core = { workspace = true } diff --git a/zero_bin/leader/src/main.rs b/zero_bin/leader/src/main.rs index 94f02b729..94b6945ba 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,9 +21,7 @@ mod http; mod init; mod stdio; -const EVM_ARITH_VER_KEY: &str = "EVM_ARITHMETIZATION_PKG_VER"; -const VERGEN_BUILD_TIMESTAMP: &str = "VERGEN_BUILD_TIMESTAMP"; -const VERGEN_RUSTC_COMMIT_HASH: &str = "VERGEN_RUSTC_COMMIT_HASH"; +const EVM_ARITHMETIZATION_PKG_VER: &str = "EVM_ARITHMETIZATION_PKG_VER"; fn get_previous_proof(path: Option) -> Result> { if path.is_none() { @@ -41,36 +40,14 @@ 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"), - ); - } - } - if env::var_os(VERGEN_BUILD_TIMESTAMP).is_none() { - // Safety: - // - we're early enough in main that nothing else should race - unsafe { - env::set_var( - VERGEN_BUILD_TIMESTAMP, - // see build.rs - env!("VERGEN_BUILD_TIMESTAMP"), - ); - } - } - if env::var_os(VERGEN_RUSTC_COMMIT_HASH).is_none() { - // Safety: - // - we're early enough in main that nothing else should race - unsafe { - env::set_var( - VERGEN_RUSTC_COMMIT_HASH, - // see build.rs - env!("VERGEN_RUSTC_COMMIT_HASH"), + EVM_ARITHMETIZATION_PKG_VER, + // see version.rs + env!("EVM_ARITHMETIZATION_PKG_VER"), ); } } @@ -85,14 +62,11 @@ async fn main() -> Result<()> { } match args.command { - Command::Version {} => { - println!( - "Evm Arithmetization package version: {}", - env::var(EVM_ARITH_VER_KEY)? - ); - println!("Build Commit Hash: {}", env::var(VERGEN_RUSTC_COMMIT_HASH)?); - println!("Build Timestamp: {}", env::var(VERGEN_BUILD_TIMESTAMP)?); - } + Command::Version {} => version::print_version( + env!("EVM_ARITHMETIZATION_PKG_VER"), + env!("VERGEN_RUSTC_COMMIT_HASH"), + env!("VERGEN_BUILD_TIMESTAMP"), + ), Command::Stdio { previous_proof, save_inputs_on_error, diff --git a/zero_bin/rpc/Cargo.toml b/zero_bin/rpc/Cargo.toml index cba6c926c..2dce86d99 100644 --- a/zero_bin/rpc/Cargo.toml +++ b/zero_bin/rpc/Cargo.toml @@ -7,7 +7,7 @@ license.workspace = true repository.workspace = true keywords.workspace = true categories.workspace = true -build = "build.rs" +build = "../version.rs" [dependencies] __compat_primitive_types = { workspace = true } diff --git a/zero_bin/rpc/build.rs b/zero_bin/rpc/build.rs deleted file mode 100644 index da63d6e21..000000000 --- a/zero_bin/rpc/build.rs +++ /dev/null @@ -1,30 +0,0 @@ -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")?; - let version = &meta - .packages - .iter() - .find(|it| it.name == "evm_arithmetization") - .context("couldn't find evm_arithmetization package")? - .version; - println!( - "cargo::rustc-env=EVM_ARITHMETIZATION_PACKAGE_VERSION={}.{}.x", - // patch version change should not prompt circuits regeneration - version.major, - version.minor - ); - - Ok(()) -} diff --git a/zero_bin/rpc/src/main.rs b/zero_bin/rpc/src/main.rs index cdb671ffd..893c44535 100644 --- a/zero_bin/rpc/src/main.rs +++ b/zero_bin/rpc/src/main.rs @@ -7,10 +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; - -const EVM_ARITH_VER_KEY: &str = "EVM_ARITHMETIZATION_PKG_VER"; -const VERGEN_BUILD_TIMESTAMP: &str = "VERGEN_BUILD_TIMESTAMP"; -const VERGEN_RUSTC_COMMIT_HASH: &str = "VERGEN_RUSTC_COMMIT_HASH"; +use zero_bin_common::version; #[derive(Parser)] pub enum Cli { @@ -47,14 +44,11 @@ impl Cli { /// Execute the cli command. pub async fn execute(self) -> anyhow::Result<()> { match self { - Self::Version {} => { - println!( - "Evm Arithmetization package version: {}", - env::var(EVM_ARITH_VER_KEY)? - ); - println!("Build Commit Hash: {}", env::var(VERGEN_RUSTC_COMMIT_HASH)?); - println!("Build Timestamp: {}", env::var(VERGEN_BUILD_TIMESTAMP)?); - } + Self::Version {} => version::print_version( + env!("EVM_ARITHMETIZATION_PKG_VER"), + env!("VERGEN_RUSTC_COMMIT_HASH"), + env!("VERGEN_BUILD_TIMESTAMP"), + ), Self::Fetch { start_block, end_block, @@ -92,40 +86,6 @@ impl Cli { #[tokio::main] async fn main() -> anyhow::Result<()> { - if env::var_os(EVM_ARITH_VER_KEY).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"), - ); - } - } - if env::var_os(VERGEN_BUILD_TIMESTAMP).is_none() { - // Safety: - // - we're early enough in main that nothing else should race - unsafe { - env::set_var( - VERGEN_BUILD_TIMESTAMP, - // see build.rs - env!("VERGEN_BUILD_TIMESTAMP"), - ); - } - } - if env::var_os(VERGEN_RUSTC_COMMIT_HASH).is_none() { - // Safety: - // - we're early enough in main that nothing else should race - unsafe { - env::set_var( - VERGEN_RUSTC_COMMIT_HASH, - // see build.rs - env!("VERGEN_RUSTC_COMMIT_HASH"), - ); - } - } - tracing_subscriber::Registry::default() .with( tracing_subscriber::fmt::layer() diff --git a/zero_bin/verifier/Cargo.toml b/zero_bin/verifier/Cargo.toml index c1a76f56a..d55e681bc 100644 --- a/zero_bin/verifier/Cargo.toml +++ b/zero_bin/verifier/Cargo.toml @@ -3,7 +3,7 @@ name = "verifier" authors = ["Polygon Zero "] version = "0.1.0" edition = "2021" -build = "build.rs" +build = "../version.rs" [dependencies] clap = { workspace = true } diff --git a/zero_bin/verifier/build.rs b/zero_bin/verifier/build.rs deleted file mode 100644 index da63d6e21..000000000 --- a/zero_bin/verifier/build.rs +++ /dev/null @@ -1,30 +0,0 @@ -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")?; - let version = &meta - .packages - .iter() - .find(|it| it.name == "evm_arithmetization") - .context("couldn't find evm_arithmetization package")? - .version; - println!( - "cargo::rustc-env=EVM_ARITHMETIZATION_PACKAGE_VERSION={}.{}.x", - // patch version change should not prompt circuits regeneration - version.major, - version.minor - ); - - Ok(()) -} diff --git a/zero_bin/verifier/src/main.rs b/zero_bin/verifier/src/main.rs index 99d9cfb87..6f5d9db0a 100644 --- a/zero_bin/verifier/src/main.rs +++ b/zero_bin/verifier/src/main.rs @@ -7,62 +7,24 @@ 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; use cli::Command; -const EVM_ARITH_VER_KEY: &str = "EVM_ARITHMETIZATION_PKG_VER"; -const VERGEN_BUILD_TIMESTAMP: &str = "VERGEN_BUILD_TIMESTAMP"; -const VERGEN_RUSTC_COMMIT_HASH: &str = "VERGEN_RUSTC_COMMIT_HASH"; - fn main() -> Result<()> { dotenv().ok(); init::tracing(); let args = cli::Cli::parse(); - if env::var_os(EVM_ARITH_VER_KEY).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"), - ); - } - } - if env::var_os(VERGEN_BUILD_TIMESTAMP).is_none() { - // Safety: - // - we're early enough in main that nothing else should race - unsafe { - env::set_var( - VERGEN_BUILD_TIMESTAMP, - // see build.rs - env!("VERGEN_BUILD_TIMESTAMP"), - ); - } - } - if env::var_os(VERGEN_RUSTC_COMMIT_HASH).is_none() { - // Safety: - // - we're early enough in main that nothing else should race - unsafe { - env::set_var( - VERGEN_RUSTC_COMMIT_HASH, - // see build.rs - env!("VERGEN_RUSTC_COMMIT_HASH"), - ); - } - } - if let Some(Command::Version {}) = args.command { - println!( - "Evm Arithmetization package version: {}", - env::var(EVM_ARITH_VER_KEY)? + version::print_version( + env!("EVM_ARITHMETIZATION_PKG_VER"), + env!("VERGEN_RUSTC_COMMIT_HASH"), + env!("VERGEN_BUILD_TIMESTAMP"), ); - println!("Build Commit Hash: {}", env::var(VERGEN_RUSTC_COMMIT_HASH)?); - println!("Build Timestamp: {}", env::var(VERGEN_BUILD_TIMESTAMP)?); return Ok(()); } diff --git a/zero_bin/leader/build.rs b/zero_bin/version.rs similarity index 92% rename from zero_bin/leader/build.rs rename to zero_bin/version.rs index da63d6e21..c3e7b006d 100644 --- a/zero_bin/leader/build.rs +++ b/zero_bin/version.rs @@ -20,7 +20,7 @@ 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 diff --git a/zero_bin/worker/Cargo.toml b/zero_bin/worker/Cargo.toml index 1dc01077f..9d85f2197 100644 --- a/zero_bin/worker/Cargo.toml +++ b/zero_bin/worker/Cargo.toml @@ -7,7 +7,7 @@ license.workspace = true repository.workspace = true keywords.workspace = true categories.workspace = true -build = "build.rs" +build = "../version.rs" [dependencies] paladin-core = { workspace = true } diff --git a/zero_bin/worker/build.rs b/zero_bin/worker/build.rs deleted file mode 100644 index da63d6e21..000000000 --- a/zero_bin/worker/build.rs +++ /dev/null @@ -1,30 +0,0 @@ -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")?; - let version = &meta - .packages - .iter() - .find(|it| it.name == "evm_arithmetization") - .context("couldn't find evm_arithmetization package")? - .version; - println!( - "cargo::rustc-env=EVM_ARITHMETIZATION_PACKAGE_VERSION={}.{}.x", - // patch version change should not prompt circuits regeneration - version.major, - version.minor - ); - - Ok(()) -} diff --git a/zero_bin/worker/src/main.rs b/zero_bin/worker/src/main.rs index 92e401843..de8c346ad 100644 --- a/zero_bin/worker/src/main.rs +++ b/zero_bin/worker/src/main.rs @@ -1,4 +1,4 @@ -use std::env::{self}; +use std::env; use anyhow::Result; use clap::{Parser, Subcommand}; @@ -6,6 +6,7 @@ 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; @@ -15,10 +16,6 @@ mod init; #[global_allocator] static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc; -const EVM_ARITH_VER_KEY: &str = "EVM_ARITHMETIZATION_PKG_VER"; -const VERGEN_BUILD_TIMESTAMP: &str = "VERGEN_BUILD_TIMESTAMP"; -const VERGEN_RUSTC_COMMIT_HASH: &str = "VERGEN_RUSTC_COMMIT_HASH"; - #[derive(Parser)] struct Cli { #[command(subcommand)] @@ -40,47 +37,12 @@ async fn main() -> Result<()> { init::tracing(); let args = Cli::parse(); - if env::var_os(EVM_ARITH_VER_KEY).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"), - ); - } - } - if env::var_os(VERGEN_BUILD_TIMESTAMP).is_none() { - // Safety: - // - we're early enough in main that nothing else should race - unsafe { - env::set_var( - VERGEN_BUILD_TIMESTAMP, - // see build.rs - env!("VERGEN_BUILD_TIMESTAMP"), - ); - } - } - if env::var_os(VERGEN_RUSTC_COMMIT_HASH).is_none() { - // Safety: - // - we're early enough in main that nothing else should race - unsafe { - env::set_var( - VERGEN_RUSTC_COMMIT_HASH, - // see build.rs - env!("VERGEN_RUSTC_COMMIT_HASH"), - ); - } - } - if let Some(Command::Version {}) = args.command { - println!( - "Evm Arithmetization package version: {}", - env::var(EVM_ARITH_VER_KEY)? + version::print_version( + env!("EVM_ARITHMETIZATION_PKG_VER"), + env!("VERGEN_RUSTC_COMMIT_HASH"), + env!("VERGEN_BUILD_TIMESTAMP"), ); - println!("Build Commit Hash: {}", env::var(VERGEN_RUSTC_COMMIT_HASH)?); - println!("Build Timestamp: {}", env::var(VERGEN_BUILD_TIMESTAMP)?); return Ok(()); } From 1abd61c3de7a90c26a62270b741b37716894e61c Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 31 Jul 2024 08:39:30 +0100 Subject: [PATCH 4/8] Update zero_bin/README.md Co-authored-by: Robin Salen <30937548+Nashtare@users.noreply.github.com> --- zero_bin/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zero_bin/README.md b/zero_bin/README.md index 08b56844f..347713dcd 100644 --- a/zero_bin/README.md +++ b/zero_bin/README.md @@ -88,7 +88,7 @@ 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 - version Fetch the version, build commit hash, build timestamp + version Fetch the `evm_arithmetization` package version, build commit hash and build timestamp http Reads input from HTTP and writes output to a directory help Print this message or the help of the given subcommand(s) From d5baa5b12f2132b7ebb21cbc3a1772ee8711214c Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Thu, 1 Aug 2024 11:58:47 +0530 Subject: [PATCH 5/8] review fixes --- Cargo.lock | 2 ++ Cargo.toml | 3 +++ zero_bin/README.md | 8 ++++--- zero_bin/common/Cargo.toml | 6 +++++ .../src/build_version.rs} | 11 +++++++++ zero_bin/common/src/lib.rs | 2 +- zero_bin/common/src/version.rs | 12 ---------- zero_bin/leader/Cargo.toml | 6 ++--- zero_bin/leader/src/cli.rs | 1 - zero_bin/leader/src/main.rs | 18 +++++++++----- zero_bin/rpc/Cargo.toml | 6 ++--- zero_bin/rpc/src/main.rs | 19 ++++++++------- zero_bin/verifier/Cargo.toml | 6 ++--- zero_bin/verifier/src/cli.rs | 12 ++-------- zero_bin/verifier/src/main.rs | 14 +++++------ zero_bin/worker/Cargo.toml | 6 ++--- zero_bin/worker/src/main.rs | 24 +++++++------------ 17 files changed, 81 insertions(+), 75 deletions(-) rename zero_bin/{version.rs => common/src/build_version.rs} (74%) delete mode 100644 zero_bin/common/src/version.rs diff --git a/Cargo.lock b/Cargo.lock index f1a1c856f..0ac2383f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5778,6 +5778,7 @@ dependencies = [ "alloy", "anyhow", "async-stream", + "cargo_metadata", "clap", "evm_arithmetization", "futures", @@ -5788,6 +5789,7 @@ dependencies = [ "thiserror", "tokio", "tracing", + "vergen", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 22c913324..1e8d7f07c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -131,3 +131,6 @@ proc-macro2 = "1.0" quote = "1.0" syn = "2.0" trybuild = "1.0" + +vergen = { version = "9.0.0", features = ["build", "rustc"] } +cargo_metadata = "0.18.1" diff --git a/zero_bin/README.md b/zero_bin/README.md index 08b56844f..e97a2b2ee 100644 --- a/zero_bin/README.md +++ b/zero_bin/README.md @@ -88,13 +88,14 @@ 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 - version Fetch the version, build commit hash, build timestamp 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 @@ -367,7 +368,7 @@ cargo r --bin verifier -- --help Usage: verifier --file-path Options: - version Fetch the version, build commit hash, build timestamp + --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 ``` @@ -389,11 +390,12 @@ Usage: rpc Commands: fetch Fetch and generate prover input from the RPC endpoint - version Fetch the version, build commit hash, build timestamp 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: diff --git a/zero_bin/common/Cargo.toml b/zero_bin/common/Cargo.toml index 9ee2ac5fe..7d63afb9d 100644 --- a/zero_bin/common/Cargo.toml +++ b/zero_bin/common/Cargo.toml @@ -22,3 +22,9 @@ 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 } diff --git a/zero_bin/version.rs b/zero_bin/common/src/build_version.rs similarity index 74% rename from zero_bin/version.rs rename to zero_bin/common/src/build_version.rs index c3e7b006d..c556fd775 100644 --- a/zero_bin/version.rs +++ b/zero_bin/common/src/build_version.rs @@ -28,3 +28,14 @@ fn main() -> anyhow::Result<()> { Ok(()) } + +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/common/src/lib.rs b/zero_bin/common/src/lib.rs index 5570a5d5f..9a612c5b1 100644 --- a/zero_bin/common/src/lib.rs +++ b/zero_bin/common/src/lib.rs @@ -1,6 +1,6 @@ pub mod block_interval; +pub mod build_version; 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 deleted file mode 100644 index 94e9529c1..000000000 --- a/zero_bin/common/src/version.rs +++ /dev/null @@ -1,12 +0,0 @@ -pub fn print_version( - evm_arithmetization_package_version: &str, - rustc_commit_hash: &str, - rustc_timestamp: &str, -) { - println!( - "Evm Arithmetization package version: {:?}", - evm_arithmetization_package_version - ); - println!("Build Commit Hash: {:?}", rustc_commit_hash); - println!("Build Timestamp: {:?}", rustc_timestamp); -} diff --git a/zero_bin/leader/Cargo.toml b/zero_bin/leader/Cargo.toml index 7ebfc95b4..b12d90249 100644 --- a/zero_bin/leader/Cargo.toml +++ b/zero_bin/leader/Cargo.toml @@ -7,7 +7,7 @@ license.workspace = true repository.workspace = true keywords.workspace = true categories.workspace = true -build = "../version.rs" +build = "../common/src/build_version.rs" [dependencies] paladin-core = { workspace = true } @@ -37,6 +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 } -vergen = { version = "9.0.0", features = ["build", "rustc"] } diff --git a/zero_bin/leader/src/cli.rs b/zero_bin/leader/src/cli.rs index 9dc4501e3..eb3ea08f8 100644 --- a/zero_bin/leader/src/cli.rs +++ b/zero_bin/leader/src/cli.rs @@ -87,5 +87,4 @@ pub(crate) enum Command { #[arg(short, long, default_value_t = false)] save_inputs_on_error: bool, }, - Version {}, } diff --git a/zero_bin/leader/src/main.rs b/zero_bin/leader/src/main.rs index 94b6945ba..08c39d687 100644 --- a/zero_bin/leader/src/main.rs +++ b/zero_bin/leader/src/main.rs @@ -11,7 +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 zero_bin_common::build_version; use crate::client::{client_main, ProofParams}; @@ -52,6 +52,17 @@ async fn main() -> Result<()> { } } + let args: Vec = env::args().collect(); + + if args.contains(&"--version".to_string()) { + build_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 { // If running in emulation mode, we'll need to initialize the prover @@ -62,11 +73,6 @@ async fn main() -> Result<()> { } match args.command { - Command::Version {} => version::print_version( - env!("EVM_ARITHMETIZATION_PKG_VER"), - env!("VERGEN_RUSTC_COMMIT_HASH"), - env!("VERGEN_BUILD_TIMESTAMP"), - ), Command::Stdio { previous_proof, save_inputs_on_error, diff --git a/zero_bin/rpc/Cargo.toml b/zero_bin/rpc/Cargo.toml index 2dce86d99..441fe7533 100644 --- a/zero_bin/rpc/Cargo.toml +++ b/zero_bin/rpc/Cargo.toml @@ -7,7 +7,7 @@ license.workspace = true repository.workspace = true keywords.workspace = true categories.workspace = true -build = "../version.rs" +build = "../common/src/build_version.rs" [dependencies] __compat_primitive_types = { workspace = true } @@ -33,6 +33,6 @@ zero_bin_common = { workspace = true } prover = { workspace = true } [build-dependencies] -vergen = { version = "9.0.0", features = ["build", "rustc"] } +cargo_metadata = { workspace = true } +vergen = { workspace = true } anyhow = { workspace = true } -cargo_metadata = "0.18.1" diff --git a/zero_bin/rpc/src/main.rs b/zero_bin/rpc/src/main.rs index 893c44535..695375df8 100644 --- a/zero_bin/rpc/src/main.rs +++ b/zero_bin/rpc/src/main.rs @@ -7,12 +7,10 @@ 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; +use zero_bin_common::build_version; #[derive(Parser)] pub enum Cli { - /// Print the version of the rpc package - Version {}, /// Fetch and generate prover input from the RPC endpoint Fetch { // Starting block of interval to fetch @@ -44,11 +42,6 @@ impl Cli { /// Execute the cli command. pub async fn execute(self) -> anyhow::Result<()> { match self { - Self::Version {} => version::print_version( - env!("EVM_ARITHMETIZATION_PKG_VER"), - env!("VERGEN_RUSTC_COMMIT_HASH"), - env!("VERGEN_BUILD_TIMESTAMP"), - ), Self::Fetch { start_block, end_block, @@ -86,6 +79,16 @@ impl Cli { #[tokio::main] async fn main() -> anyhow::Result<()> { + let args: Vec = env::args().collect(); + if args.contains(&"--version".to_string()) { + build_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 d55e681bc..a8e0abe25 100644 --- a/zero_bin/verifier/Cargo.toml +++ b/zero_bin/verifier/Cargo.toml @@ -3,7 +3,7 @@ name = "verifier" authors = ["Polygon Zero "] version = "0.1.0" edition = "2021" -build = "../version.rs" +build = "../common/src/build_version.rs" [dependencies] clap = { workspace = true } @@ -19,6 +19,6 @@ proof_gen = { workspace = true } zero_bin_common = { path = "../common" } [build-dependencies] -vergen = { version = "9.0.0", features = ["build", "rustc"] } +cargo_metadata = { workspace = true } +vergen = { workspace = true } anyhow = { workspace = true } -cargo_metadata = "0.18.1" diff --git a/zero_bin/verifier/src/cli.rs b/zero_bin/verifier/src/cli.rs index 82c1ba49f..a49799799 100644 --- a/zero_bin/verifier/src/cli.rs +++ b/zero_bin/verifier/src/cli.rs @@ -1,23 +1,15 @@ use std::string; -use clap::{Parser, Subcommand, ValueHint}; +use clap::{Parser, ValueHint}; use zero_bin_common::prover_state::cli::CliProverStateConfig; #[derive(Parser)] pub(crate) struct Cli { - #[command(subcommand)] - pub(crate) command: Option, - /// The file containing the proof to verify #[arg(short, long, value_hint = ValueHint::FilePath)] - pub(crate) file_path: Option, + pub(crate) file_path: string::String, /// The prover configuration used to generate the preprocessed circuits /// and the verifier state. #[clap(flatten)] pub(crate) prover_state_config: CliProverStateConfig, } - -#[derive(Subcommand)] -pub(crate) enum Command { - Version {}, -} diff --git a/zero_bin/verifier/src/main.rs b/zero_bin/verifier/src/main.rs index 6f5d9db0a..72d7f643c 100644 --- a/zero_bin/verifier/src/main.rs +++ b/zero_bin/verifier/src/main.rs @@ -7,20 +7,18 @@ use dotenvy::dotenv; use proof_gen::proof_types::GeneratedBlockProof; use serde_json::Deserializer; use tracing::info; -use zero_bin_common::version; +use zero_bin_common::build_version; mod cli; mod init; -use cli::Command; - fn main() -> Result<()> { dotenv().ok(); init::tracing(); - let args = cli::Cli::parse(); - if let Some(Command::Version {}) = args.command { - version::print_version( + let args: Vec = env::args().collect(); + if args.contains(&"--version".to_string()) { + build_version::print_version( env!("EVM_ARITHMETIZATION_PKG_VER"), env!("VERGEN_RUSTC_COMMIT_HASH"), env!("VERGEN_BUILD_TIMESTAMP"), @@ -28,7 +26,9 @@ fn main() -> Result<()> { return Ok(()); } - let file = File::open(args.file_path.unwrap())?; + 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 9d85f2197..2b0f72564 100644 --- a/zero_bin/worker/Cargo.toml +++ b/zero_bin/worker/Cargo.toml @@ -7,7 +7,7 @@ license.workspace = true repository.workspace = true keywords.workspace = true categories.workspace = true -build = "../version.rs" +build = "../common/src/build_version.rs" [dependencies] paladin-core = { workspace = true } @@ -25,6 +25,6 @@ zero_bin_common = { workspace = true } jemallocator = "0.5.4" [build-dependencies] -vergen = { version = "9.0.0", features = ["build", "rustc"] } +cargo_metadata = { workspace = true } +vergen = { workspace = true } anyhow = { workspace = true } -cargo_metadata = "0.18.1" diff --git a/zero_bin/worker/src/main.rs b/zero_bin/worker/src/main.rs index de8c346ad..000e67a3a 100644 --- a/zero_bin/worker/src/main.rs +++ b/zero_bin/worker/src/main.rs @@ -1,12 +1,12 @@ use std::env; use anyhow::Result; -use clap::{Parser, Subcommand}; +use clap::Parser; use dotenvy::dotenv; use ops::register; use paladin::runtime::WorkerRuntime; +use zero_bin_common::build_version; use zero_bin_common::prover_state::cli::CliProverStateConfig; -use zero_bin_common::version; mod init; @@ -18,27 +18,17 @@ static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc; #[derive(Parser)] struct Cli { - #[command(subcommand)] - pub(crate) command: Option, #[clap(flatten)] paladin: paladin::config::Config, #[clap(flatten)] prover_state_config: CliProverStateConfig, } -#[derive(Debug, Subcommand)] -pub(crate) enum Command { - Version {}, -} - #[tokio::main] async fn main() -> Result<()> { - dotenv().ok(); - init::tracing(); - let args = Cli::parse(); - - if let Some(Command::Version {}) = args.command { - version::print_version( + let args: Vec = env::args().collect(); + if args.contains(&"--version".to_string()) { + build_version::print_version( env!("EVM_ARITHMETIZATION_PKG_VER"), env!("VERGEN_RUSTC_COMMIT_HASH"), env!("VERGEN_BUILD_TIMESTAMP"), @@ -46,6 +36,10 @@ async fn main() -> Result<()> { return Ok(()); } + dotenv().ok(); + init::tracing(); + let args = Cli::parse(); + args.prover_state_config .into_prover_state_manager() .initialize()?; From 4615cb5305aba903d39dea80d3f44fe0f782aed8 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Mon, 5 Aug 2024 17:39:48 +0530 Subject: [PATCH 6/8] fix cliipy issues in develop --- trace_decoder/src/typed_mpt.rs | 71 ---------------------------------- 1 file changed, 71 deletions(-) diff --git a/trace_decoder/src/typed_mpt.rs b/trace_decoder/src/typed_mpt.rs index 947727737..af0e983b3 100644 --- a/trace_decoder/src/typed_mpt.rs +++ b/trace_decoder/src/typed_mpt.rs @@ -135,14 +135,6 @@ impl TriePath { pub fn from_hash(H256(bytes): H256) -> Self { Self::new(AsNibbles(bytes)).expect("32 bytes is 64 nibbles, which fits") } - fn from_txn_ix(txn_ix: usize) -> Self { - TriePath::new(AsNibbles(rlp::encode(&txn_ix))).expect( - "\ - rlp of an usize goes through a u64, which is 8 bytes, - which will be 9 bytes RLP'ed. - 9 < 32", - ) - } fn into_nibbles(self) -> mpt_trie::nibbles::Nibbles { let mut theirs = mpt_trie::nibbles::Nibbles::default(); for component in self.0 { @@ -163,60 +155,6 @@ impl TriePath { } } -/// Per-block, `txn_ix -> [u8]`. -/// -/// See -#[derive(Debug, Clone, Default)] -pub struct TransactionTrie { - untyped: HashedPartialTrie, -} - -impl TransactionTrie { - pub fn insert(&mut self, txn_ix: usize, val: Vec) -> Result>, Error> { - let prev = self - .untyped - .get(TriePath::from_txn_ix(txn_ix).into_nibbles()) - .map(Vec::from); - self.untyped - .insert(TriePath::from_txn_ix(txn_ix).into_nibbles(), val) - .map_err(|source| Error { source })?; - Ok(prev) - } - pub fn root(&self) -> H256 { - self.untyped.hash() - } - pub fn as_hashed_partial_trie(&self) -> &mpt_trie::partial_trie::HashedPartialTrie { - &self.untyped - } -} - -/// Per-block, `txn_ix -> [u8]`. -/// -/// See -#[derive(Debug, Clone, Default)] -pub struct ReceiptTrie { - untyped: HashedPartialTrie, -} - -impl ReceiptTrie { - pub fn insert(&mut self, txn_ix: usize, val: Vec) -> Result>, Error> { - let prev = self - .untyped - .get(TriePath::from_txn_ix(txn_ix).into_nibbles()) - .map(Vec::from); - self.untyped - .insert(TriePath::from_txn_ix(txn_ix).into_nibbles(), val) - .map_err(|source| Error { source })?; - Ok(prev) - } - pub fn root(&self) -> H256 { - self.untyped.hash() - } - pub fn as_hashed_partial_trie(&self) -> &mpt_trie::partial_trie::HashedPartialTrie { - &self.untyped - } -} - /// Global, [`Address`] `->` [`AccountRlp`]. /// /// See @@ -300,16 +238,7 @@ impl StorageTrie { pub fn root(&self) -> H256 { self.untyped.hash() } - pub fn remove(&mut self, path: TriePath) -> Result>, Error> { - self.untyped - .delete(path.into_nibbles()) - .map_err(|source| Error { source }) - } pub fn as_hashed_partial_trie(&self) -> &mpt_trie::partial_trie::HashedPartialTrie { &self.untyped } - - pub fn as_mut_hashed_partial_trie_unchecked(&mut self) -> &mut HashedPartialTrie { - &mut self.untyped - } } From 1c5dfe057d0bd21daa0c3369a689684699218330 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Tue, 6 Aug 2024 10:34:45 +0530 Subject: [PATCH 7/8] Revert "fix cliipy issues in develop" This reverts commit 4615cb5305aba903d39dea80d3f44fe0f782aed8. --- trace_decoder/src/typed_mpt.rs | 71 ++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/trace_decoder/src/typed_mpt.rs b/trace_decoder/src/typed_mpt.rs index af0e983b3..947727737 100644 --- a/trace_decoder/src/typed_mpt.rs +++ b/trace_decoder/src/typed_mpt.rs @@ -135,6 +135,14 @@ impl TriePath { pub fn from_hash(H256(bytes): H256) -> Self { Self::new(AsNibbles(bytes)).expect("32 bytes is 64 nibbles, which fits") } + fn from_txn_ix(txn_ix: usize) -> Self { + TriePath::new(AsNibbles(rlp::encode(&txn_ix))).expect( + "\ + rlp of an usize goes through a u64, which is 8 bytes, + which will be 9 bytes RLP'ed. + 9 < 32", + ) + } fn into_nibbles(self) -> mpt_trie::nibbles::Nibbles { let mut theirs = mpt_trie::nibbles::Nibbles::default(); for component in self.0 { @@ -155,6 +163,60 @@ impl TriePath { } } +/// Per-block, `txn_ix -> [u8]`. +/// +/// See +#[derive(Debug, Clone, Default)] +pub struct TransactionTrie { + untyped: HashedPartialTrie, +} + +impl TransactionTrie { + pub fn insert(&mut self, txn_ix: usize, val: Vec) -> Result>, Error> { + let prev = self + .untyped + .get(TriePath::from_txn_ix(txn_ix).into_nibbles()) + .map(Vec::from); + self.untyped + .insert(TriePath::from_txn_ix(txn_ix).into_nibbles(), val) + .map_err(|source| Error { source })?; + Ok(prev) + } + pub fn root(&self) -> H256 { + self.untyped.hash() + } + pub fn as_hashed_partial_trie(&self) -> &mpt_trie::partial_trie::HashedPartialTrie { + &self.untyped + } +} + +/// Per-block, `txn_ix -> [u8]`. +/// +/// See +#[derive(Debug, Clone, Default)] +pub struct ReceiptTrie { + untyped: HashedPartialTrie, +} + +impl ReceiptTrie { + pub fn insert(&mut self, txn_ix: usize, val: Vec) -> Result>, Error> { + let prev = self + .untyped + .get(TriePath::from_txn_ix(txn_ix).into_nibbles()) + .map(Vec::from); + self.untyped + .insert(TriePath::from_txn_ix(txn_ix).into_nibbles(), val) + .map_err(|source| Error { source })?; + Ok(prev) + } + pub fn root(&self) -> H256 { + self.untyped.hash() + } + pub fn as_hashed_partial_trie(&self) -> &mpt_trie::partial_trie::HashedPartialTrie { + &self.untyped + } +} + /// Global, [`Address`] `->` [`AccountRlp`]. /// /// See @@ -238,7 +300,16 @@ impl StorageTrie { pub fn root(&self) -> H256 { self.untyped.hash() } + pub fn remove(&mut self, path: TriePath) -> Result>, Error> { + self.untyped + .delete(path.into_nibbles()) + .map_err(|source| Error { source }) + } pub fn as_hashed_partial_trie(&self) -> &mpt_trie::partial_trie::HashedPartialTrie { &self.untyped } + + pub fn as_mut_hashed_partial_trie_unchecked(&mut self) -> &mut HashedPartialTrie { + &mut self.untyped + } } From 428c3c8c24a90a6f990035d6afc51e2d3ee089c8 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Tue, 6 Aug 2024 10:37:09 +0530 Subject: [PATCH 8/8] added removed code --- trace_decoder/src/typed_mpt.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 }