Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable checksum #203

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions crates/cli/src/app_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use crate::exec::exec_dry_run;
use super::command::CommandBuilder;
use super::exec::exec_create_proof;
use super::exec::exec_dry_run_service;
use super::exec::exec_image_checksum;
use super::exec::exec_setup;
use super::exec::exec_verify_proof;

Expand Down Expand Up @@ -71,7 +70,6 @@ pub trait AppBuilder: CommandBuilder {
let app = Self::append_dry_run_subcommand(app);
let app = Self::append_create_single_proof_subcommand(app);
let app = Self::append_verify_single_proof_subcommand(app);
let app = Self::append_image_checksum_subcommand(app);

app
}
Expand All @@ -92,8 +90,7 @@ pub trait AppBuilder: CommandBuilder {
let md5 = format!("{:X}", md5::compute(&wasm_binary));
let phantom_functions = Self::parse_phantom_functions(&top_matches);

let param_dir =
load_or_generate_output_path(&md5, top_matches.get_one::<PathBuf>("param"));
let param_dir = load_or_generate_output_path(&md5, top_matches.get_one::<PathBuf>("param"));

let output_dir =
load_or_generate_output_path(&md5, top_matches.get_one::<PathBuf>("output"));
Expand All @@ -109,9 +106,6 @@ pub trait AppBuilder: CommandBuilder {
&output_dir,
&param_dir,
),
Some(("checksum", _)) => {
exec_image_checksum(zkwasm_k, wasm_binary, phantom_functions, &output_dir)
}
Some(("dry-run", sub_matches)) => {
let public_inputs: Vec<u64> = Self::parse_single_public_arg(&sub_matches);
let private_inputs: Vec<u64> = Self::parse_single_private_arg(&sub_matches);
Expand Down Expand Up @@ -182,11 +176,7 @@ pub trait AppBuilder: CommandBuilder {
let _proof_path: PathBuf = Self::parse_proof_path_arg(&sub_matches);
let _instance_path: PathBuf = Self::parse_single_instance_arg(&sub_matches);

exec_verify_proof(
Self::NAME,
&output_dir,
&param_dir
)
exec_verify_proof(Self::NAME, &output_dir, &param_dir)
}
Some((_, _)) => todo!(),
None => todo!(),
Expand Down
6 changes: 0 additions & 6 deletions crates/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ pub trait CommandBuilder: ArgBuilder {
app.subcommand(command)
}

fn append_image_checksum_subcommand(app: App) -> App {
let command = Command::new("checksum");

app.subcommand(command)
}

fn append_dry_run_subcommand(app: App) -> App {
let command = Command::new("dry-run")
.arg(Self::single_public_arg())
Expand Down
48 changes: 12 additions & 36 deletions crates/cli/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use std::path::Path;
use std::path::PathBuf;
use std::rc::Rc;
use wasmi::RuntimeValue;
use std::io::Write;

//const AGGREGATE_PREFIX: &'static str = "aggregate-circuit";

Expand Down Expand Up @@ -82,33 +81,6 @@ pub fn exec_setup(
Ok(())
}

pub fn exec_image_checksum(
zkwasm_k: u32,
wasm_binary: Vec<u8>,
phantom_functions: Vec<String>,
output_dir: &PathBuf,
) -> Result<()> {
let loader = ZkWasmLoader::<Bn256>::new(zkwasm_k, wasm_binary, phantom_functions, None)?;

let params = load_or_build_unsafe_params::<Bn256>(
zkwasm_k,
Some(&output_dir.join(format!("K{}.params", zkwasm_k))),
);

let checksum = loader.checksum(&params)?;
assert_eq!(checksum.len(), 1);
let checksum = checksum[0];

println!("image checksum: {:?}", checksum);

let mut fd =
std::fs::File::create(&output_dir.join(format!("checksum.data",)).as_path()).unwrap();

write!(fd, "{:?}", checksum)?;

Ok(())
}

pub fn exec_dry_run_service(
zkwasm_k: u32,
wasm_binary: Vec<u8>,
Expand Down Expand Up @@ -268,20 +240,20 @@ pub fn exec_create_proof(
info!("Mock test passed");
}

let circuit: CircuitInfo<Bn256, TestCircuit<Fr>> = CircuitInfo::new(
let circuit: CircuitInfo<Bn256, TestCircuit<Fr>> = CircuitInfo::new(
circuit,
prefix.to_string(),
vec![instances],
zkwasm_k as usize,
circuits_batcher::args::HashType::Poseidon
circuits_batcher::args::HashType::Poseidon,
);
circuit.proofloadinfo.save(output_dir);
circuit.exec_create_proof(
output_dir,
param_dir,
PKEY_CACHE.lock().as_mut().unwrap(),
0,
K_PARAMS_CACHE.lock().as_mut().unwrap()
K_PARAMS_CACHE.lock().as_mut().unwrap(),
);

info!("Proof has been created.");
Expand All @@ -296,17 +268,21 @@ pub fn exec_verify_proof(
) -> Result<()> {
let load_info = output_dir.join(format!("{}.loadinfo.json", prefix));
let proofloadinfo = ProofLoadInfo::load(&load_info);
let proofs:Vec<ProofInfo<Bn256>> = ProofInfo::load_proof(&output_dir, &param_dir, &proofloadinfo);
let proofs: Vec<ProofInfo<Bn256>> =
ProofInfo::load_proof(&output_dir, &param_dir, &proofloadinfo);
let params = load_or_build_unsafe_params::<Bn256>(
proofloadinfo.k as u32,
Some(&param_dir.join(format!("K{}.params", proofloadinfo.k))),
);
let mut public_inputs_size = 0;
for proof in proofs.iter() {
public_inputs_size =
usize::max(public_inputs_size,
proof.instances.iter().fold(0, |acc, x| usize::max(acc, x.len()))
);
public_inputs_size = usize::max(
public_inputs_size,
proof
.instances
.iter()
.fold(0, |acc, x| usize::max(acc, x.len())),
);
}

let params_verifier: ParamsVerifier<Bn256> = params.verifier(public_inputs_size).unwrap();
Expand Down
24 changes: 0 additions & 24 deletions crates/zkwasm/src/checksum/mod.rs

This file was deleted.

34 changes: 8 additions & 26 deletions crates/zkwasm/src/circuits/etable/assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ use crate::circuits::utils::Context;
pub(in crate::circuits) struct EventTablePermutationCells {
pub(in crate::circuits) rest_mops: Option<Cell>,
pub(in crate::circuits) rest_jops: Option<Cell>,
pub(in crate::circuits) fid_of_entry: Cell,
pub(in crate::circuits) initial_memory_pages: Cell,
pub(in crate::circuits) maximal_memory_pages: Cell,
}

impl<F: FieldExt> EventTableChip<F> {
Expand Down Expand Up @@ -119,7 +116,7 @@ impl<F: FieldExt> EventTableChip<F> {
configure_table: &ConfigureTable,
fid_of_entry: u32,
rest_ops: Vec<(u32, u32)>,
) -> Result<(Cell, Cell, Cell), Error> {
) -> Result<(), Error> {
macro_rules! assign_advice {
($cell:ident, $value:expr) => {
self.config.common_config.$cell.assign(ctx, $value)?
Expand Down Expand Up @@ -155,18 +152,18 @@ impl<F: FieldExt> EventTableChip<F> {
external_host_call_index_cell,
F::from(external_host_call_call_index as u64)
);
let initial_memory_pages_cell = assign_advice!(
assign_constant!(
mpages_cell,
F::from(configure_table.init_memory_pages as u64)
);
let maximal_memory_pages_cell = assign_advice!(
assign_constant!(
maximal_memory_pages_cell,
F::from(configure_table.maximal_memory_pages as u64)
);
assign_constant!(sp_cell, F::from(DEFAULT_VALUE_STACK_LIMIT as u64 - 1));
assign_constant!(frame_id_cell, F::zero());
assign_constant!(eid_cell, F::one());
let fid_of_entry_cell = assign_advice!(fid_cell, F::from(fid_of_entry as u64));
assign_constant!(fid_cell, F::from(fid_of_entry as u64));
assign_constant!(iid_cell, F::zero());

/*
Expand All @@ -175,23 +172,15 @@ impl<F: FieldExt> EventTableChip<F> {
{
let assigned_cell = assign_advice!(enabled_cell, F::zero());
if assigned_cell.value().is_none() {
return Ok((
fid_of_entry_cell.cell(),
initial_memory_pages_cell.cell(),
maximal_memory_pages_cell.cell(),
));
return Ok(());
}
}

/*
* The length of event_table equals 0: without_witness
*/
if event_table.0.len() == 0 {
return Ok((
fid_of_entry_cell.cell(),
initial_memory_pages_cell.cell(),
maximal_memory_pages_cell.cell(),
));
return Ok(());
}

let status = {
Expand Down Expand Up @@ -320,11 +309,7 @@ impl<F: FieldExt> EventTableChip<F> {
F::from(external_host_call_call_index as u64)
);

Ok((
fid_of_entry_cell.cell(),
initial_memory_pages_cell.cell(),
maximal_memory_pages_cell.cell(),
))
Ok(())
}

pub(in crate::circuits) fn assign(
Expand All @@ -349,7 +334,7 @@ impl<F: FieldExt> EventTableChip<F> {
)?;
ctx.reset();

let (fid_of_entry, initial_memory_pages, maximal_memory_pages) = self.assign_entries(
self.assign_entries(
ctx,
&self.config.op_configs,
event_table,
Expand All @@ -362,9 +347,6 @@ impl<F: FieldExt> EventTableChip<F> {
Ok(EventTablePermutationCells {
rest_mops: Some(rest_mops_cell),
rest_jops: Some(rest_jops_cell),
fid_of_entry,
initial_memory_pages,
maximal_memory_pages,
})
}
}
52 changes: 5 additions & 47 deletions crates/zkwasm/src/circuits/image_table/assign.rs
Original file line number Diff line number Diff line change
@@ -1,71 +1,29 @@
use halo2_proofs::arithmetic::FieldExt;
use halo2_proofs::circuit::Cell;
use halo2_proofs::circuit::Layouter;
use halo2_proofs::plonk::Error;

use super::ImageTableChip;
use super::ImageTableLayouter;
use crate::circuits::utils::Context;

impl<F: FieldExt> ImageTableChip<F> {
pub fn assign(
self,
layouter: &mut impl Layouter<F>,
image_table: ImageTableLayouter<F>,
permutation_cells: ImageTableLayouter<Cell>,
) -> Result<(), Error> {
layouter.assign_region(
layouter.assign_table(
|| "image table",
|region| {
let mut ctx = Context::new(region);
|mut table| {
let mut offset = 0;

macro_rules! assign_one_line {
($v: expr) => {{
let cell = ctx
.region
.assign_advice(
|| "image table",
self.config.col,
ctx.offset,
|| Ok($v),
)?
.cell();
table.assign_cell(|| "image table", self.config.col, offset, || Ok($v))?;

ctx.next();

cell
offset += 1;
}};
}

let entry_fid_cell = assign_one_line!(image_table.entry_fid);
ctx.region
.constrain_equal(permutation_cells.entry_fid, entry_fid_cell)?;

let initial_memory_pages_cell = assign_one_line!(image_table.initial_memory_pages);
ctx.region.constrain_equal(
permutation_cells.initial_memory_pages,
initial_memory_pages_cell,
)?;

let maximal_memory_pages_cell = assign_one_line!(image_table.maximal_memory_pages);
ctx.region.constrain_equal(
permutation_cells.maximal_memory_pages,
maximal_memory_pages_cell,
)?;

for (static_frame_entry, cell_in_frame_table) in image_table
.static_frame_entries
.iter()
.zip(permutation_cells.static_frame_entries.iter())
{
// Enable cell
let cell = assign_one_line!(static_frame_entry.0);
ctx.region.constrain_equal(cell, cell_in_frame_table.0)?;

let cell = assign_one_line!(static_frame_entry.1);
ctx.region.constrain_equal(cell, cell_in_frame_table.1)?;
}

for value in image_table.lookup_entries.as_ref().unwrap() {
assign_one_line!(*value);
}
Expand Down
Loading
Loading