Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
fix: fix circuit version consistency check (#58)
Browse files Browse the repository at this point in the history
* fix: fix circuit version consistency check

* fix: fix clippy issues

* fix: update deps

---------

Co-authored-by: Vladimir Trifonov <[email protected]>
Co-authored-by: Robin Salen <[email protected]>
  • Loading branch information
3 people authored Apr 24, 2024
1 parent e18dbd5 commit b25c112
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 120 deletions.
51 changes: 49 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 5 additions & 23 deletions common/src/prover_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,24 @@ use std::{fmt::Display, sync::OnceLock};

use clap::ValueEnum;
use evm_arithmetization::{
cpu::kernel::aggregator::KERNEL, proof::AllProof, prover::prove, AllStark, GenerationInputs,
StarkConfig,
proof::AllProof, prover::prove, AllStark, GenerationInputs, StarkConfig,
};
use plonky2::{
field::goldilocks_field::GoldilocksField,
plonk::config::{GenericHashOut, PoseidonGoldilocksConfig},
field::goldilocks_field::GoldilocksField, plonk::config::PoseidonGoldilocksConfig,
util::timing::TimingTree,
};
use proof_gen::{proof_types::GeneratedTxnProof, prover_state::ProverState, VerifierState};
use tracing::info;

use self::circuit::{CircuitConfig, NUM_TABLES};
use crate::prover_state::{
persistence::{
BaseProverResource, DiskResource, MonolithicProverResource, RecursiveCircuitResource,
VerifierResource,
},
utils::pkg_consistency_check,
use crate::prover_state::persistence::{
BaseProverResource, DiskResource, MonolithicProverResource, RecursiveCircuitResource,
VerifierResource,
};

pub mod circuit;
pub mod cli;
pub mod persistence;
mod utils;

pub(crate) type Config = PoseidonGoldilocksConfig;
pub(crate) type Field = GoldilocksField;
Expand Down Expand Up @@ -259,18 +253,6 @@ impl ProverStateManager {
CircuitPersistence::Disk(strategy) => {
info!("attempting to load preprocessed circuits from disk...");

// Check the package consistency before loading the circuits.
pkg_consistency_check([
self.circuit_config
.as_all_recursive_circuits()
.block
.circuit
.verifier_only
.circuit_digest
.to_bytes(),
KERNEL.hash().to_fixed_bytes().to_vec(),
]);

let disk_state = match strategy {
TableLoadStrategy::OnDemand => BaseProverResource::get(&self.circuit_config),
TableLoadStrategy::Monolithic => {
Expand Down
15 changes: 10 additions & 5 deletions common/src/prover_state/persistence.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::env;
use std::{
fmt::{Debug, Display},
fs::{self, OpenOptions},
Expand All @@ -16,7 +17,7 @@ use super::{
Config, RecursiveCircuitsForTableSize, SIZE,
};

pub(crate) const CIRCUITS_FOLDER: &str = "./circuits";
const CIRCUITS_FOLDER: &str = "./circuits";
const PROVER_STATE_FILE_PREFIX: &str = "prover_state";
const VERIFIER_STATE_FILE_PREFIX: &str = "verifier_state";

Expand Down Expand Up @@ -102,9 +103,10 @@ impl DiskResource for BaseProverResource {

fn path(p: &Self::PathConstrutor) -> impl AsRef<Path> {
format!(
"{}/{}_base_{}",
"{}/{}_base_{}_{}",
CIRCUITS_FOLDER,
PROVER_STATE_FILE_PREFIX,
env::var("EVM_ARITHMETIZATION_PKG_VER").unwrap_or("NA".to_string()),
p.get_configuration_digest()
)
}
Expand Down Expand Up @@ -137,9 +139,10 @@ impl DiskResource for MonolithicProverResource {

fn path(p: &Self::PathConstrutor) -> impl AsRef<Path> {
format!(
"{}/{}_monolithic_{}",
"{}/{}_monolithic_{}_{}",
CIRCUITS_FOLDER,
PROVER_STATE_FILE_PREFIX,
env::var("EVM_ARITHMETIZATION_PKG_VER").unwrap_or("NA".to_string()),
p.get_configuration_digest()
)
}
Expand Down Expand Up @@ -171,9 +174,10 @@ impl DiskResource for RecursiveCircuitResource {

fn path((circuit_type, size): &Self::PathConstrutor) -> impl AsRef<Path> {
format!(
"{}/{}_{}_{}",
"{}/{}_{}_{}_{}",
CIRCUITS_FOLDER,
PROVER_STATE_FILE_PREFIX,
env::var("EVM_ARITHMETIZATION_PKG_VER").unwrap_or("NA".to_string()),
circuit_type.as_short_str(),
size
)
Expand Down Expand Up @@ -214,9 +218,10 @@ impl DiskResource for VerifierResource {

fn path(p: &Self::PathConstrutor) -> impl AsRef<Path> {
format!(
"{}/{}_{}",
"{}/{}_{}_{}",
CIRCUITS_FOLDER,
VERIFIER_STATE_FILE_PREFIX,
env::var("EVM_ARITHMETIZATION_PKG_VER").unwrap_or("NA".to_string()),
p.get_configuration_digest()
)
}
Expand Down
90 changes: 0 additions & 90 deletions common/src/prover_state/utils.rs

This file was deleted.

1 change: 1 addition & 0 deletions leader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ serde_json = { workspace = true }
serde_path_to_error = { workspace = true }
ethereum-types = { workspace = true }
axum = "0.7.4"
toml = "0.8.12"

# Local dependencies
ops = { path = "../ops" }
Expand Down
17 changes: 17 additions & 0 deletions leader/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::env;
use std::{fs::File, path::PathBuf};

use anyhow::Result;
Expand All @@ -9,11 +10,14 @@ use ops::register;
use paladin::runtime::Runtime;
use proof_gen::types::PlonkyProofIntern;

use crate::utils::get_package_version;

mod cli;
mod http;
mod init;
mod jerigon;
mod stdio;
mod utils;

fn get_previous_proof(path: Option<PathBuf>) -> Result<Option<PlonkyProofIntern>> {
if path.is_none() {
Expand All @@ -32,6 +36,19 @@ async fn main() -> Result<()> {
dotenv().ok();
init::tracing();

if env::var("EVM_ARITHMETIZATION_PKG_VER").is_err() {
let pkg_ver = get_package_version("evm_arithmetization")?;
// Extract the major and minor version parts and append 'x' as the patch version
if let Some((major_minor, _)) = pkg_ver.as_ref().and_then(|s| s.rsplit_once('.')) {
let circuits_version = format!("{}.x", major_minor);
// Set the environment variable for the evm_arithmetization package version
env::set_var("EVM_ARITHMETIZATION_PKG_VER", circuits_version);
} else {
// Set to "NA" if version extraction fails
env::set_var("EVM_ARITHMETIZATION_PKG_VER", "NA");
}
}

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
Expand Down
Loading

0 comments on commit b25c112

Please sign in to comment.