Skip to content

Commit

Permalink
cli: add pre/post image col consistent checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason authored and junyu0312 committed Oct 17, 2024
1 parent 32df1e2 commit 7dae657
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 42 deletions.
46 changes: 42 additions & 4 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"

[dependencies]
env_logger = "0.9.3"
halo2aggregator-s = { git = "https://github.com/DelphinusLab/halo2aggregator-s.git", tag="on-prove-pairing-0.6.2" }
log = "0.4.17"
md5 = "0.7.0"
sha2 = "0.10.6"
Expand Down
76 changes: 38 additions & 38 deletions crates/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ impl Config {
println!("skip first {} slice(s)", skip);
}

#[cfg(feature = "continuation")]
let mut last_post_image_table_commitment: Option<(String, String)> = None;

let mut slices = Slices::new(self.k, tables, padding)?
.into_iter()
.enumerate()
Expand Down Expand Up @@ -408,12 +411,14 @@ impl Config {
transcript: name_of_transcript(&self.name, index),
};

let pkey = &cached_proving_key.as_ref().unwrap().1;

let proof = match circuit {
ZkWasmCircuit::Ongoing(circuit) => proof_piece_info.create_proof::<Bn256, _>(
&circuit,
&vec![instances.clone()],
&params,
&cached_proving_key.as_ref().unwrap().1,
pkey,
proof_load_info.hashtype,
self.scheme.into(),
),
Expand All @@ -422,12 +427,43 @@ impl Config {
&circuit,
&vec![instances.clone()],
&params,
&cached_proving_key.as_ref().unwrap().1,
pkey,
proof_load_info.hashtype,
self.scheme.into(),
),
};

#[cfg(feature = "continuation")]
{
use crate::utils::get_named_advice_commitment;
use delphinus_zkwasm::circuits::image_table::IMAGE_COL_NAME;
use delphinus_zkwasm::circuits::post_image_table::POST_IMAGE_TABLE;

// checks pre image col equals to last's post image col commitment
let pre_image_table_msm =
get_named_advice_commitment(pkey.get_vk(), &proof, IMAGE_COL_NAME);

let last_post_image_table_msm = last_post_image_table_commitment.take();
if let Some(last_post_image_table_msm) = last_post_image_table_msm {
assert_eq!(
pre_image_table_msm.x.to_string(),
last_post_image_table_msm.0
);
assert_eq!(
pre_image_table_msm.y.to_string(),
last_post_image_table_msm.1
);
}

let post_image_table_msm =
get_named_advice_commitment(pkey.get_vk(), &proof, POST_IMAGE_TABLE);

last_post_image_table_commitment = Some((
post_image_table_msm.x.to_string(),
post_image_table_msm.y.to_string(),
));
}

proof_piece_info.save_proof_data(&vec![instances.clone()], &proof, output_dir);

proof_load_info.append_single_proof(proof_piece_info);
Expand Down Expand Up @@ -514,42 +550,6 @@ impl Config {
.verify_proof(&params_verifier, self.scheme.into())
.unwrap();

// TODO: handle checksum sanity check
// #[cfg(feature = "uniform-circuit")]
// {
// use delphinus_zkwasm::circuits::image_table::IMAGE_COL_NAME;
// use halo2_proofs::plonk::get_advice_commitments_from_transcript;
// use halo2aggregator_s::transcript::poseidon::PoseidonRead;

// let _img_col_idx = proof
// .vkey
// .cs
// .named_advices
// .iter()
// .find(|(k, _)| k == IMAGE_COL_NAME)
// .unwrap()
// .1;
// let _img_col_commitment: Vec<G1Affine> =
// get_advice_commitments_from_transcript::<Bn256, _, _>(
// &proof.vkey,
// &mut PoseidonRead::init(&proof.transcripts[..]),
// )
// .unwrap();

// assert!(
// vec![_img_col_commitment[_img_col_idx as usize]][0]
// .x
// .to_string()
// == self.checksum.0
// );
// assert!(
// vec![_img_col_commitment[_img_col_idx as usize]][0]
// .y
// .to_string()
// == self.checksum.1
// );
// }

progress_bar.inc(1);
}
progress_bar.finish_and_clear();
Expand Down
2 changes: 2 additions & 0 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ mod config;
mod file_backend;
mod names;

pub mod utils;

const TRIVIAL_WASM: &str = r#"
(module
(func (export "zkmain"))
Expand Down
22 changes: 22 additions & 0 deletions crates/cli/src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use halo2_proofs::pairing::bn256::Bn256;
use halo2_proofs::pairing::bn256::G1Affine;
use halo2_proofs::plonk::get_advice_commitments_from_transcript;
use halo2_proofs::plonk::VerifyingKey;
use halo2aggregator_s::transcript::poseidon::PoseidonRead;

pub fn get_named_advice_commitment(
vkey: &VerifyingKey<G1Affine>,
proof: &[u8],
named_advice: &str,
) -> G1Affine {
let img_col_idx = vkey
.cs
.named_advices
.iter()
.find(|(k, _)| k == named_advice)
.unwrap()
.1;

get_advice_commitments_from_transcript::<Bn256, _, _>(vkey, &mut PoseidonRead::init(proof))
.unwrap()[img_col_idx as usize]
}

0 comments on commit 7dae657

Please sign in to comment.