From 4198fd988e7b4bcd40f18fd99052d75971a3bf0f Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Sun, 28 Jul 2024 19:11:34 +0530 Subject: [PATCH] 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()?;