diff --git a/Cargo.lock b/Cargo.lock index 16fda46f7..dcd3ec2b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1244,6 +1244,8 @@ version = "1.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476" dependencies = [ + "jobserver", + "libc", "shlex", ] @@ -2368,6 +2370,19 @@ version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" +[[package]] +name = "git2" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b903b73e45dc0c6c596f2d37eccece7c1c8bb6e4407b001096387c63d0d93724" +dependencies = [ + "bitflags 2.6.0", + "libc", + "libgit2-sys", + "log", + "url", +] + [[package]] name = "glob" version = "0.3.1" @@ -2770,6 +2785,15 @@ dependencies = [ "libc", ] +[[package]] +name = "jobserver" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" +dependencies = [ + "libc", +] + [[package]] name = "js-sys" version = "0.3.70" @@ -2856,6 +2880,18 @@ version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +[[package]] +name = "libgit2-sys" +version = "0.17.0+1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10472326a8a6477c3c20a64547b0059e4b0d086869eee31e6d7da728a8eb7224" +dependencies = [ + "cc", + "libc", + "libz-sys", + "pkg-config", +] + [[package]] name = "libm" version = "0.2.8" @@ -2884,6 +2920,18 @@ dependencies = [ "threadpool", ] +[[package]] +name = "libz-sys" +version = "1.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2d16453e800a8cf6dd2fc3eb4bc99b786a9b90c663b8559a5b1a041bf89e472" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linkme" version = "0.3.28" @@ -5294,12 +5342,26 @@ checksum = "c32e7318e93a9ac53693b6caccfb05ff22e04a44c7cf8a279051f24c09da286f" dependencies = [ "anyhow", "derive_builder", - "rustc_version 0.4.1", "rustversion", "time", "vergen-lib", ] +[[package]] +name = "vergen-git2" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a62c52cd2b2b8b7ec75fc20111b3022ac3ff83e4fc14b9497cfcfd39c54f9c67" +dependencies = [ + "anyhow", + "derive_builder", + "git2", + "rustversion", + "time", + "vergen", + "vergen-lib", +] + [[package]] name = "vergen-lib" version = "0.1.3" @@ -5753,7 +5815,7 @@ dependencies = [ "tracing", "tracing-subscriber", "url", - "vergen", + "vergen-git2", "zk_evm_common", ] diff --git a/Cargo.toml b/Cargo.toml index 5bbffbb10..45f521447 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,7 +51,6 @@ criterion = "0.5.1" dotenvy = "0.15.7" either = "1.12.0" enum-as-inner = "0.6.0" -enumn = "0.1.13" env_logger = "0.11.3" eth_trie = "0.4.0" ethereum-types = "0.14.1" @@ -88,7 +87,6 @@ serde = "1.0.203" serde-big-array = "0.5.1" serde_json = "1.0.118" serde_path_to_error = "0.1.16" -serde_with = "3.8.1" sha2 = "0.10.8" static_assertions = "1.1.0" thiserror = "1.0.61" @@ -101,7 +99,6 @@ 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/zero/Cargo.toml b/zero/Cargo.toml index 109cb1f28..7086ecbd6 100644 --- a/zero/Cargo.toml +++ b/zero/Cargo.toml @@ -40,7 +40,6 @@ tower = { workspace = true, features = ["retry"] } tracing = { workspace = true } tracing-subscriber = { workspace = true } url = { workspace = true } -vergen = { workspace = true } # Local dependencies compat = { workspace = true } @@ -57,7 +56,7 @@ jemallocator = "0.5.4" [build-dependencies] anyhow = { workspace = true } cargo_metadata = { workspace = true } -vergen = { workspace = true } +vergen-git2 = { version = "1.0.0", features = ["build"] } [features] diff --git a/zero/build.rs b/zero/build.rs index c3e7b006d..53799224d 100644 --- a/zero/build.rs +++ b/zero/build.rs @@ -1,30 +1,9 @@ -use anyhow::Context as _; -use vergen::{BuildBuilder, Emitter, RustcBuilder}; +use vergen_git2::{BuildBuilder, Emitter, Git2Builder}; -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)? +fn main() -> Result<(), Box> { + Emitter::new() + .add_instructions(&BuildBuilder::default().build_timestamp(true).build()?)? + .add_instructions(&Git2Builder::default().describe(true, true, None).build()?)? .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_PKG_VER={}.{}.x", - // patch version change should not prompt circuits regeneration - version.major, - version.minor - ); - Ok(()) } diff --git a/zero/src/bin/leader.rs b/zero/src/bin/leader.rs index e01465c29..abf19bde3 100644 --- a/zero/src/bin/leader.rs +++ b/zero/src/bin/leader.rs @@ -1,6 +1,5 @@ zk_evm_common::check_chain_features!(); -use std::env; use std::sync::Arc; use anyhow::Result; @@ -15,7 +14,6 @@ use zero::{ block_interval::BlockInterval, prover_state::persistence::set_circuit_cache_dir_env_if_not_set, }; use zero::{fs::get_previous_proof, ops::register}; -use zero::{prover_state::persistence::CIRCUIT_VERSION, version}; use self::leader::*; use crate::client::{client_main, LeaderConfig}; @@ -32,17 +30,6 @@ async fn main() -> Result<()> { set_circuit_cache_dir_env_if_not_set()?; zero::tracing::init(); - let args: Vec = env::args().collect(); - - if args.contains(&"--version".to_string()) { - version::print_version( - CIRCUIT_VERSION.as_str(), - env!("VERGEN_RUSTC_COMMIT_HASH"), - env!("VERGEN_BUILD_TIMESTAMP"), - ); - return Ok(()); - } - let args = cli::Cli::parse(); if let Command::Clean = args.command { diff --git a/zero/src/bin/leader/cli.rs b/zero/src/bin/leader/cli.rs index ee45c946f..3569efc41 100644 --- a/zero/src/bin/leader/cli.rs +++ b/zero/src/bin/leader/cli.rs @@ -8,6 +8,7 @@ use zero::rpc::RpcType; /// zero-bin leader config #[derive(Parser)] +#[command(version = zero::version(), propagate_version = true)] pub(crate) struct Cli { #[command(subcommand)] pub(crate) command: Command, diff --git a/zero/src/bin/rpc.rs b/zero/src/bin/rpc.rs index 5f9d9c276..9c6baa535 100644 --- a/zero/src/bin/rpc.rs +++ b/zero/src/bin/rpc.rs @@ -1,4 +1,3 @@ -use std::env; use std::sync::Arc; use alloy::primitives::B256; @@ -11,11 +10,11 @@ use clap::{Args, Parser, Subcommand, ValueHint}; use futures::StreamExt; use tracing_subscriber::{prelude::*, EnvFilter}; use url::Url; +use zero::block_interval::BlockInterval; use zero::block_interval::BlockIntervalStream; use zero::prover::BlockProverInput; use zero::provider::CachedProvider; -use zero::{block_interval::BlockInterval, prover_state::persistence::CIRCUIT_VERSION}; -use zero::{rpc, version}; +use zero::rpc; use self::rpc::{retry::build_http_retry_provider, RpcType}; @@ -68,6 +67,7 @@ enum Command { } #[derive(Parser)] +#[command(version = zero::version(), propagate_version = true)] struct Cli { #[clap(flatten)] pub(crate) config: RpcToolConfig, @@ -203,16 +203,6 @@ impl Cli { #[tokio::main] async fn main() -> anyhow::Result<()> { - let args: Vec = env::args().collect(); - if args.contains(&"--version".to_string()) { - version::print_version( - CIRCUIT_VERSION.as_str(), - env!("VERGEN_RUSTC_COMMIT_HASH"), - env!("VERGEN_BUILD_TIMESTAMP"), - ); - return Ok(()); - } - tracing_subscriber::Registry::default() .with( tracing_subscriber::fmt::layer() diff --git a/zero/src/bin/verifier.rs b/zero/src/bin/verifier.rs index a7d80197a..7c5a671be 100644 --- a/zero/src/bin/verifier.rs +++ b/zero/src/bin/verifier.rs @@ -1,6 +1,5 @@ zk_evm_common::check_chain_features!(); -use std::env; use std::fs::File; use anyhow::Result; @@ -9,10 +8,7 @@ use dotenvy::dotenv; use proof_gen::proof_types::GeneratedBlockProof; use serde_json::Deserializer; use tracing::info; -use zero::{ - prover_state::persistence::{set_circuit_cache_dir_env_if_not_set, CIRCUIT_VERSION}, - version, -}; +use zero::prover_state::persistence::set_circuit_cache_dir_env_if_not_set; use self::verifier::*; mod verifier { @@ -25,16 +21,6 @@ fn main() -> Result<()> { init::tracing(); set_circuit_cache_dir_env_if_not_set()?; - let args: Vec = env::args().collect(); - if args.contains(&"--version".to_string()) { - version::print_version( - CIRCUIT_VERSION.as_str(), - env!("VERGEN_RUSTC_COMMIT_HASH"), - env!("VERGEN_BUILD_TIMESTAMP"), - ); - return Ok(()); - } - let args = cli::Cli::parse(); let file = File::open(args.file_path)?; diff --git a/zero/src/bin/verifier/cli.rs b/zero/src/bin/verifier/cli.rs index 157674130..8c046d85c 100644 --- a/zero/src/bin/verifier/cli.rs +++ b/zero/src/bin/verifier/cli.rs @@ -4,6 +4,7 @@ use clap::{Parser, ValueHint}; use zero::prover_state::cli::CliProverStateConfig; #[derive(Parser)] +#[command(version = zero::version(), propagate_version = true)] pub(crate) struct Cli { /// The file containing the proof to verify #[arg(short, long, value_hint = ValueHint::FilePath)] diff --git a/zero/src/bin/worker.rs b/zero/src/bin/worker.rs index 1d941341f..096863a53 100644 --- a/zero/src/bin/worker.rs +++ b/zero/src/bin/worker.rs @@ -1,14 +1,11 @@ -use std::env; - use anyhow::Result; use clap::Parser; use dotenvy::dotenv; use paladin::runtime::WorkerRuntime; use zero::prover_state::{ - cli::CliProverStateConfig, - persistence::{set_circuit_cache_dir_env_if_not_set, CIRCUIT_VERSION}, + cli::CliProverStateConfig, persistence::set_circuit_cache_dir_env_if_not_set, }; -use zero::{ops::register, tracing, version}; +use zero::{ops::register, tracing}; // TODO: https://github.com/0xPolygonZero/zk_evm/issues/302 // this should probably be removed. @@ -17,6 +14,7 @@ use zero::{ops::register, tracing, version}; static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc; #[derive(Parser)] +#[command(version = zero::version(), propagate_version = true)] struct Cli { #[clap(flatten)] paladin: paladin::config::Config, @@ -26,16 +24,6 @@ struct Cli { #[tokio::main] async fn main() -> Result<()> { - let args: Vec = env::args().collect(); - if args.contains(&"--version".to_string()) { - version::print_version( - CIRCUIT_VERSION.as_str(), - env!("VERGEN_RUSTC_COMMIT_HASH"), - env!("VERGEN_BUILD_TIMESTAMP"), - ); - return Ok(()); - } - dotenv().ok(); tracing::init(); set_circuit_cache_dir_env_if_not_set()?; diff --git a/zero/src/lib.rs b/zero/src/lib.rs index 3dc34d421..88f376fc7 100644 --- a/zero/src/lib.rs +++ b/zero/src/lib.rs @@ -12,10 +12,18 @@ pub mod prover_state; pub mod provider; pub mod rpc; pub mod tracing; -pub mod version; /// Size of the channel used to send block prover inputs to the per block /// proving task. If the proving task is slow and can not consume inputs fast /// enough retrieval of the block prover inputs will block until the proving /// task consumes some of the inputs. pub const BLOCK_CHANNEL_SIZE: usize = 16; + +/// Common information for the `--version` CLI flags. +pub fn version() -> String { + let pkg_name = env!("CARGO_PKG_NAME"); + let git_describe = env!("VERGEN_GIT_DESCRIBE"); + let timestamp = env!("VERGEN_BUILD_TIMESTAMP"); + let kernel_hash = &**prover_state::persistence::KERNEL_HASH; + format!("{pkg_name} ({git_describe}) (kernel hash: {kernel_hash}) [built: {timestamp}]") +} diff --git a/zero/src/prover_state/persistence.rs b/zero/src/prover_state/persistence.rs index 6096b7ab1..cd3f9a043 100644 --- a/zero/src/prover_state/persistence.rs +++ b/zero/src/prover_state/persistence.rs @@ -35,8 +35,14 @@ const KERNEL_HASH_PREFIX: usize = 8; /// kernel to determine if the circuit is compatible with our current binary. If /// the kernel hash of the circuit that we are loading in from disk differs, /// then using these circuits would cause failures during proof generation -pub static CIRCUIT_VERSION: Lazy = - Lazy::new(|| hex::encode(KERNEL.hash())[..KERNEL_HASH_PREFIX].to_string()); +pub static KERNEL_HASH: Lazy<&'static str> = Lazy::new(|| { + String::leak( + hex::encode(KERNEL.hash()) + .chars() + .take(KERNEL_HASH_PREFIX) + .collect(), + ) +}); fn get_serializers() -> ( DefaultGateSerializer, @@ -126,7 +132,7 @@ impl DiskResource for BaseProverResource { "{}/{}_base_{}_{}", circuit_dir(), PROVER_STATE_FILE_PREFIX, - *CIRCUIT_VERSION, + *KERNEL_HASH, p.get_configuration_digest() ) } @@ -162,7 +168,7 @@ impl DiskResource for MonolithicProverResource { "{}/{}_monolithic_{}_{}", circuit_dir(), PROVER_STATE_FILE_PREFIX, - *CIRCUIT_VERSION, + *KERNEL_HASH, p.get_configuration_digest() ) } @@ -197,7 +203,7 @@ impl DiskResource for RecursiveCircuitResource { "{}/{}_{}_{}_{}", circuit_dir(), PROVER_STATE_FILE_PREFIX, - *CIRCUIT_VERSION, + *KERNEL_HASH, circuit_type.as_short_str(), size ) @@ -241,7 +247,7 @@ impl DiskResource for VerifierResource { "{}/{}_{}_{}", circuit_dir(), VERIFIER_STATE_FILE_PREFIX, - *CIRCUIT_VERSION, + *KERNEL_HASH, p.get_configuration_digest() ) } diff --git a/zero/src/version.rs b/zero/src/version.rs deleted file mode 100644 index db5ff42b0..000000000 --- a/zero/src/version.rs +++ /dev/null @@ -1,10 +0,0 @@ -pub fn print_version( - evm_arithmetization_kernel_version: &str, - rustc_commit_hash: &str, - rustc_timestamp: &str, -) { - println!( - "evm_arithmetization Kernel Version: {}\nBuild Commit Hash: {}\nBuild Timestamp: {}", - evm_arithmetization_kernel_version, rustc_commit_hash, rustc_timestamp - ) -}