diff --git a/zero_bin/common/src/prover_state/persistence.rs b/zero_bin/common/src/prover_state/persistence.rs index 02637df3c..c40299bce 100644 --- a/zero_bin/common/src/prover_state/persistence.rs +++ b/zero_bin/common/src/prover_state/persistence.rs @@ -1,4 +1,3 @@ -use std::env; use std::{ fmt::{Debug, Display}, fs::{self, OpenOptions}, @@ -6,7 +5,10 @@ use std::{ path::Path, }; +use alloy::hex; use directories::ProjectDirs; +use evm_arithmetization::cpu::kernel::aggregator::KERNEL; +use once_cell::sync::Lazy; use plonky2::util::serialization::{ Buffer, DefaultGateSerializer, DefaultGeneratorSerializer, IoError, }; @@ -23,6 +25,18 @@ const VERIFIER_STATE_FILE_PREFIX: &str = "verifier_state"; const ZK_EVM_CACHE_DIR_NAME: &str = "zk_evm_circuit_cache"; const ZK_EVM_CACHE_DIR_ENV: &str = "ZK_EVM_CACHE_DIR"; +/// We version serialized circuits by the kernel hash they were serialized with, +/// but we really only need a few of the starting hex nibbles to reliably +/// differentiate. +const KERNEL_HASH_PREFIX: usize = 8; + +/// When we serialize/deserialize circuits, we rely on the hash of the plonky +/// 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()); + fn get_serializers() -> ( DefaultGateSerializer, DefaultGeneratorSerializer, @@ -80,8 +94,8 @@ pub(crate) trait DiskResource { if std::fs::metadata(&circuits_dir).is_err() { std::fs::create_dir_all(&circuits_dir).map_err(|err| { DiskResourceError::IoError::(std::io::Error::other(format!( - "Could not create circuits folder with error \"{:?}\"", - err + "Could not create circuits folder at {} (err: {})", + err, circuits_dir ))) })?; } @@ -111,7 +125,7 @@ impl DiskResource for BaseProverResource { "{}/{}_base_{}_{}", circuit_dir(), PROVER_STATE_FILE_PREFIX, - env!("EVM_ARITHMETIZATION_PKG_VER"), + *CIRCUIT_VERSION, p.get_configuration_digest() ) } @@ -147,7 +161,7 @@ impl DiskResource for MonolithicProverResource { "{}/{}_monolithic_{}_{}", circuit_dir(), PROVER_STATE_FILE_PREFIX, - env!("EVM_ARITHMETIZATION_PKG_VER"), + *CIRCUIT_VERSION, p.get_configuration_digest() ) } @@ -182,7 +196,7 @@ impl DiskResource for RecursiveCircuitResource { "{}/{}_{}_{}_{}", circuit_dir(), PROVER_STATE_FILE_PREFIX, - env!("EVM_ARITHMETIZATION_PKG_VER"), + *CIRCUIT_VERSION, circuit_type.as_short_str(), size ) @@ -226,7 +240,7 @@ impl DiskResource for VerifierResource { "{}/{}_{}_{}", circuit_dir(), VERIFIER_STATE_FILE_PREFIX, - env!("EVM_ARITHMETIZATION_PKG_VER"), + *CIRCUIT_VERSION, p.get_configuration_digest() ) } diff --git a/zero_bin/common/src/version.rs b/zero_bin/common/src/version.rs index 5dbbf7f9b..db5ff42b0 100644 --- a/zero_bin/common/src/version.rs +++ b/zero_bin/common/src/version.rs @@ -1,10 +1,10 @@ pub fn print_version( - evm_arithmetization_package_version: &str, + evm_arithmetization_kernel_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 + "evm_arithmetization Kernel Version: {}\nBuild Commit Hash: {}\nBuild Timestamp: {}", + evm_arithmetization_kernel_version, rustc_commit_hash, rustc_timestamp ) } diff --git a/zero_bin/leader/src/main.rs b/zero_bin/leader/src/main.rs index 04a8126b1..eb250d199 100644 --- a/zero_bin/leader/src/main.rs +++ b/zero_bin/leader/src/main.rs @@ -10,10 +10,10 @@ use ops::register; use paladin::runtime::Runtime; use proof_gen::proof_types::GeneratedBlockProof; use tracing::{info, warn}; -use zero_bin_common::version; use zero_bin_common::{ block_interval::BlockInterval, prover_state::persistence::set_circuit_cache_dir_env_if_not_set, }; +use zero_bin_common::{prover_state::persistence::CIRCUIT_VERSION, version}; use crate::client::{client_main, ProofParams}; @@ -23,8 +23,6 @@ mod http; mod init; mod stdio; -const EVM_ARITHMETIZATION_PKG_VER: &str = "EVM_ARITHMETIZATION_PKG_VER"; - fn get_previous_proof(path: Option) -> Result> { if path.is_none() { return Ok(None); @@ -43,22 +41,11 @@ async fn main() -> Result<()> { set_circuit_cache_dir_env_if_not_set()?; init::tracing(); - 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_ARITHMETIZATION_PKG_VER, - env!("EVM_ARITHMETIZATION_PKG_VER"), - ); - } - } - let args: Vec = env::args().collect(); if args.contains(&"--version".to_string()) { version::print_version( - env!("EVM_ARITHMETIZATION_PKG_VER"), + CIRCUIT_VERSION.as_str(), env!("VERGEN_RUSTC_COMMIT_HASH"), env!("VERGEN_BUILD_TIMESTAMP"), ); diff --git a/zero_bin/rpc/src/main.rs b/zero_bin/rpc/src/main.rs index ee1ed08e0..444e89e3b 100644 --- a/zero_bin/rpc/src/main.rs +++ b/zero_bin/rpc/src/main.rs @@ -6,8 +6,8 @@ use rpc::provider::CachedProvider; 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::{block_interval::BlockInterval, prover_state::persistence::CIRCUIT_VERSION}; #[derive(Parser)] pub enum Cli { @@ -82,7 +82,7 @@ async fn main() -> anyhow::Result<()> { let args: Vec = env::args().collect(); if args.contains(&"--version".to_string()) { version::print_version( - env!("EVM_ARITHMETIZATION_PKG_VER"), + CIRCUIT_VERSION.as_str(), env!("VERGEN_RUSTC_COMMIT_HASH"), env!("VERGEN_BUILD_TIMESTAMP"), ); diff --git a/zero_bin/tools/prove_rpc.sh b/zero_bin/tools/prove_rpc.sh index cf300625e..d7651b65a 100755 --- a/zero_bin/tools/prove_rpc.sh +++ b/zero_bin/tools/prove_rpc.sh @@ -39,9 +39,6 @@ fi # Force the working directory to always be the `tools/` directory. TOOLS_DIR=$(dirname $(realpath "$0")) -# Set the environment variable to let the binary know that we're running in the project workspace. -export CARGO_WORKSPACE_DIR="${TOOLS_DIR}/../" - PROOF_OUTPUT_DIR="${TOOLS_DIR}/proofs" OUT_LOG_PATH="${PROOF_OUTPUT_DIR}/b$1_$2.log" ALWAYS_WRITE_LOGS=0 # Change this to `1` if you always want logs to be written. diff --git a/zero_bin/tools/prove_stdio.sh b/zero_bin/tools/prove_stdio.sh index d284a0fa1..5e4792f4c 100755 --- a/zero_bin/tools/prove_stdio.sh +++ b/zero_bin/tools/prove_stdio.sh @@ -25,9 +25,6 @@ PROOFS_JSON_PATH="${TOOLS_DIR}/proofs.json" VERIFY_OUT_PATH="${TOOLS_DIR}/verify.out" TEST_OUT_PATH="${TOOLS_DIR}/test.out" -# Set the environment variable to let the binary know that we're running in the project workspace. -export CARGO_WORKSPACE_DIR="${TOOLS_DIR}/../" - # Configured Rayon and Tokio with rough defaults export RAYON_NUM_THREADS=$num_procs export TOKIO_WORKER_THREADS=$num_procs diff --git a/zero_bin/verifier/src/main.rs b/zero_bin/verifier/src/main.rs index 4b8c3a9ab..30f6c9ab5 100644 --- a/zero_bin/verifier/src/main.rs +++ b/zero_bin/verifier/src/main.rs @@ -7,7 +7,10 @@ use dotenvy::dotenv; use proof_gen::proof_types::GeneratedBlockProof; use serde_json::Deserializer; use tracing::info; -use zero_bin_common::{prover_state::persistence::set_circuit_cache_dir_env_if_not_set, version}; +use zero_bin_common::{ + prover_state::persistence::{set_circuit_cache_dir_env_if_not_set, CIRCUIT_VERSION}, + version, +}; mod cli; mod init; @@ -20,7 +23,7 @@ fn main() -> Result<()> { let args: Vec = env::args().collect(); if args.contains(&"--version".to_string()) { version::print_version( - env!("EVM_ARITHMETIZATION_PKG_VER"), + CIRCUIT_VERSION.as_str(), env!("VERGEN_RUSTC_COMMIT_HASH"), env!("VERGEN_BUILD_TIMESTAMP"), ); diff --git a/zero_bin/worker/src/main.rs b/zero_bin/worker/src/main.rs index 7e26fb7c3..08b125ad9 100644 --- a/zero_bin/worker/src/main.rs +++ b/zero_bin/worker/src/main.rs @@ -6,7 +6,8 @@ use dotenvy::dotenv; use ops::register; use paladin::runtime::WorkerRuntime; use zero_bin_common::prover_state::{ - cli::CliProverStateConfig, persistence::set_circuit_cache_dir_env_if_not_set, + cli::CliProverStateConfig, + persistence::{set_circuit_cache_dir_env_if_not_set, CIRCUIT_VERSION}, }; use zero_bin_common::version; @@ -31,7 +32,7 @@ async fn main() -> Result<()> { let args: Vec = env::args().collect(); if args.contains(&"--version".to_string()) { version::print_version( - env!("EVM_ARITHMETIZATION_PKG_VER"), + CIRCUIT_VERSION.as_str(), env!("VERGEN_RUSTC_COMMIT_HASH"), env!("VERGEN_BUILD_TIMESTAMP"), );