Skip to content

Commit

Permalink
fix: add git_version to both chunk and batch proofs (#215)
Browse files Browse the repository at this point in the history
* Add `git_version` to both chunk and batch proofs.

* Update prover/src/proof/batch.rs

Co-authored-by: Haichen Shen <shenhaichen@gmail.com>

* Update

* Update

* Update

* Fix lint.

* Fix

* Fix lint.

---------

Co-authored-by: Haichen Shen <shenhaichen@gmail.com>
  • Loading branch information
silathdiir and icemelon authored Aug 16, 2023
1 parent bd90176 commit 9b498b2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
15 changes: 12 additions & 3 deletions prover/src/proof.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::io::{deserialize_fr, deserialize_vk, serialize_fr, serialize_vk, write_file};
use crate::{
io::{deserialize_fr, deserialize_vk, serialize_fr, serialize_vk, write_file},
utils::short_git_version,
};
use anyhow::{bail, Result};
use halo2_proofs::{
halo2curves::bn256::{Fr, G1Affine},
Expand Down Expand Up @@ -35,17 +38,20 @@ pub struct Proof {
instances: Vec<u8>,
#[serde(with = "base64")]
vk: Vec<u8>,
pub git_version: Option<String>,
}

impl Proof {
pub fn new(proof: Vec<u8>, instances: &[Vec<Fr>], pk: Option<&ProvingKey<G1Affine>>) -> Self {
let instances = serialize_instances(instances);
let vk = pk.map_or_else(Vec::new, |pk| serialize_vk(pk.get_vk()));
let git_version = Some(short_git_version());

Self {
proof,
instances,
vk,
git_version,
}
}

Expand All @@ -54,12 +60,15 @@ impl Proof {
}

pub fn from_snark(snark: Snark, vk: Vec<u8>) -> Self {
let proof = snark.proof;
let instances = serialize_instances(&snark.instances);
let git_version = Some(short_git_version());

Proof {
proof: snark.proof,
vk,
proof,
instances,
vk,
git_version,
}
}

Expand Down
5 changes: 5 additions & 0 deletions prover/src/proof/batch.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::{dump_as_json, dump_data, dump_vk, from_json_file, serialize_instance, Proof};
use crate::utils::short_git_version;
use anyhow::Result;
use serde_derive::{Deserialize, Serialize};
use snark_verifier_sdk::encode_calldata;
Expand All @@ -22,6 +23,7 @@ impl From<Proof> for BatchProof {
assert_eq!(instances[0].len(), ACC_LEN + PI_LEN);

let vk = proof.vk;
let git_version = proof.git_version;

// raw_proof = acc + proof
let proof = serialize_instance(&instances[0][..ACC_LEN])
Expand All @@ -37,6 +39,7 @@ impl From<Proof> for BatchProof {
proof,
instances,
vk,
git_version,
},
}
}
Expand Down Expand Up @@ -79,11 +82,13 @@ impl BatchProof {
instances.extend(self.raw.instances);

let vk = self.raw.vk;
let git_version = Some(short_git_version());

Proof {
proof,
instances,
vk,
git_version,
}
}

Expand Down
5 changes: 5 additions & 0 deletions prover/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ pub fn init_env_and_log(id: &str) -> String {
log4rs::init_config(config).unwrap();

log::info!("git version {}", GIT_VERSION);
log::info!("short git version {}", short_git_version());
});

output_dir
Expand Down Expand Up @@ -192,6 +193,10 @@ pub fn gen_rng() -> impl Rng + Send {
XorShiftRng::from_seed(seed)
}

pub fn short_git_version() -> String {
GIT_VERSION.split('-').last().unwrap()[1..8].to_string()
}

pub fn tick(desc: &str) {
#[cfg(target_os = "linux")]
let memory = match procfs::Meminfo::new() {
Expand Down
12 changes: 11 additions & 1 deletion prover/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,24 @@ use prover::{
inner::{Prover, Verifier},
io::serialize_vk,
test_util::{load_block_traces_for_test, parse_trace_path_from_mode, PARAMS_DIR},
utils::{get_block_trace_from_file, init_env_and_log, load_params},
utils::{get_block_trace_from_file, init_env_and_log, load_params, short_git_version},
zkevm::{
circuit::{block_traces_to_padding_witness_block, SuperCircuit, TargetCircuit},
CircuitCapacityChecker,
},
};
use zkevm_circuits::util::SubCircuit;

#[test]
fn test_short_git_version() {
init_env_and_log("integration");

let git_version = short_git_version();
log::info!("short_git_version = {git_version}");

assert_eq!(git_version.len(), 7);
}

#[ignore]
#[test]
fn test_load_params() {
Expand Down

0 comments on commit 9b498b2

Please sign in to comment.