Skip to content

Commit

Permalink
add scaffold for post image table
Browse files Browse the repository at this point in the history
  • Loading branch information
junyu0312 committed Oct 31, 2023
1 parent 37d9552 commit 4da8d4c
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 3 deletions.
1 change: 1 addition & 0 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/zkwasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2021"
ark-std = { version = "0.3.0", features = ["print-trace"] }
bitvec = "1.0.1"
downcast-rs = "1.2.0"
cfg-if = "0.1"
hex = "0.4.3"
log = "0.4.17"
num-integer = "0.1"
Expand Down
1 change: 1 addition & 0 deletions crates/zkwasm/src/circuits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mod traits;
pub mod config;
pub mod image_table;
pub mod jtable;
pub mod post_image_table;
pub mod rtable;
pub mod test_circuit;
pub mod utils;
Expand Down
47 changes: 47 additions & 0 deletions crates/zkwasm/src/circuits/post_image_table/continuation/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use halo2_proofs::arithmetic::FieldExt;
use halo2_proofs::circuit::Cell;
use halo2_proofs::circuit::Layouter;
use halo2_proofs::plonk::Error;

use crate::circuits::image_table::ImageTableChip;
use crate::circuits::image_table::ImageTableConfig;
use crate::circuits::image_table::ImageTableLayouter;

use super::PostImageTableChipTrait;
use super::PostImageTableConfigTrait;

#[derive(Clone)]
pub(in crate::circuits) struct ContinuationPostImageTableConfig<F: FieldExt> {
config: ImageTableConfig<F>,
}

impl<F: FieldExt> PostImageTableConfigTrait<F> for ContinuationPostImageTableConfig<F> {
fn configure(meta: &mut halo2_proofs::plonk::ConstraintSystem<F>) -> Self {
Self {
config: ImageTableConfig::configure(meta),
}
}
}

pub(in crate::circuits) struct ContinuationPostImageTableChip<F: FieldExt> {
chip: ImageTableChip<F>,
}

impl<F: FieldExt> PostImageTableChipTrait<F, ContinuationPostImageTableConfig<F>>
for ContinuationPostImageTableChip<F>
{
fn new(config: ContinuationPostImageTableConfig<F>) -> Self {
Self {
chip: ImageTableChip::new(config.config),
}
}

fn assign(
self,
layouter: &mut impl Layouter<F>,
image_table: ImageTableLayouter<F>,
permutation_cells: ImageTableLayouter<Cell>,
) -> Result<(), Error> {
self.chip.assign(layouter, image_table, permutation_cells)
}
}
43 changes: 43 additions & 0 deletions crates/zkwasm/src/circuits/post_image_table/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use halo2_proofs::arithmetic::FieldExt;
use halo2_proofs::circuit::Cell;
use halo2_proofs::circuit::Layouter;
use halo2_proofs::plonk::ConstraintSystem;
use halo2_proofs::plonk::Error;

use super::image_table::ImageTableLayouter;

pub(self) mod continuation;
pub(self) mod trivial;

pub(in crate::circuits) trait PostImageTableConfigTrait<F: FieldExt> {
fn configure(_meta: &mut ConstraintSystem<F>) -> Self;
}

pub(in crate::circuits) trait PostImageTableChipTrait<
F: FieldExt,
Config: PostImageTableConfigTrait<F>,
>
{
fn new(config: Config) -> Self;
fn assign(
self,
layouter: &mut impl Layouter<F>,
image_table: ImageTableLayouter<F>,
permutation_cells: ImageTableLayouter<Cell>,
) -> Result<(), Error>;
}

cfg_if::cfg_if! {
if #[cfg(feature = "continuation")] {
use self::continuation::*;

pub(in crate::circuits) type PostImageTableConfig<F> = ContinuationPostImageTableConfig<F>;
pub(in crate::circuits) type PostImageTableChip<F> = ContinuationPostImageTableChip<F>;

} else {
use self::trivial::*;

pub(in crate::circuits) type PostImageTableConfig<F> = TrivialPostImageTableConfig<F>;
pub(in crate::circuits) type PostImageTableChip<F> = TrivialPostImageTableChip<F>;
}
}
43 changes: 43 additions & 0 deletions crates/zkwasm/src/circuits/post_image_table/trivial/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use std::marker::PhantomData;

use halo2_proofs::arithmetic::FieldExt;
use halo2_proofs::circuit::Cell;
use halo2_proofs::circuit::Layouter;
use halo2_proofs::plonk::Error;

use crate::circuits::image_table::ImageTableLayouter;

use super::PostImageTableChipTrait;
use super::PostImageTableConfigTrait;

#[derive(Clone)]
pub(in crate::circuits) struct TrivialPostImageTableConfig<F: FieldExt> {
_mark: PhantomData<F>,
}

impl<F: FieldExt> PostImageTableConfigTrait<F> for TrivialPostImageTableConfig<F> {
fn configure(_meta: &mut halo2_proofs::plonk::ConstraintSystem<F>) -> Self {
Self { _mark: PhantomData }
}
}

pub(in crate::circuits) struct TrivialPostImageTableChip<F: FieldExt> {
_mark: PhantomData<F>,
}

impl<F: FieldExt> PostImageTableChipTrait<F, TrivialPostImageTableConfig<F>>
for TrivialPostImageTableChip<F>
{
fn new(_config: TrivialPostImageTableConfig<F>) -> Self {
Self { _mark: PhantomData }
}

fn assign(
self,
layouter: &mut impl Layouter<F>,
image_table: ImageTableLayouter<F>,
permutation_cells: ImageTableLayouter<Cell>,
) -> Result<(), Error> {
Ok(())
}
}
23 changes: 20 additions & 3 deletions crates/zkwasm/src/circuits/test_circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ use crate::circuits::image_table::ImageTableLayouter;
use crate::circuits::jtable::JumpTableChip;
use crate::circuits::jtable::JumpTableConfig;
use crate::circuits::mtable::MemoryTableConfig;
use crate::circuits::post_image_table::PostImageTableChip;
use crate::circuits::post_image_table::PostImageTableChipTrait;
use crate::circuits::post_image_table::PostImageTableConfig;
use crate::circuits::post_image_table::PostImageTableConfigTrait;
use crate::circuits::rtable::RangeTableChip;
use crate::circuits::rtable::RangeTableConfig;
use crate::circuits::utils::table_entry::EventTableWithMemoryInfo;
Expand Down Expand Up @@ -58,8 +62,10 @@ const RESERVE_ROWS: usize = crate::circuits::bit_table::STEP_SIZE;

#[derive(Clone)]
pub struct TestCircuitConfig<F: FieldExt> {
rtable: RangeTableConfig<F>,
pre_image_table: ImageTableConfig<F>,
post_image_table: PostImageTableConfig<F>,

rtable: RangeTableConfig<F>,
_mtable: MemoryTableConfig<F>,
jtable: JumpTableConfig<F>,
etable: EventTableConfig<F>,
Expand Down Expand Up @@ -97,8 +103,10 @@ impl<F: FieldExt> Circuit<F> for TestCircuit<F> {

let mut cols = [(); VAR_COLUMNS].map(|_| meta.advice_column()).into_iter();

let rtable = RangeTableConfig::configure(meta);
let pre_image_table = ImageTableConfig::configure(meta);
let post_image_table = PostImageTableConfig::configure(meta);

let rtable = RangeTableConfig::configure(meta);
let mtable = MemoryTableConfig::configure(meta, &mut cols, &rtable, &pre_image_table);
let jtable = JumpTableConfig::configure(meta, &mut cols);
let external_host_call_table = ExternalHostCallTableConfig::configure(meta);
Expand Down Expand Up @@ -138,8 +146,10 @@ impl<F: FieldExt> Circuit<F> for TestCircuit<F> {
debug!("max_available_rows: {:?}", max_available_rows);

Self::Config {
rtable,
pre_image_table,
post_image_table,

rtable,
// TODO: open mtable
_mtable: mtable,
jtable,
Expand All @@ -162,6 +172,8 @@ impl<F: FieldExt> Circuit<F> for TestCircuit<F> {

let rchip = RangeTableChip::new(config.rtable);
let pre_image_chip = ImageTableChip::new(config.pre_image_table);
let post_image_chip = PostImageTableChip::new(config.post_image_table);

// TODO: open mtable
// let mchip = MemoryTableChip::new(config.mtable, config.max_available_rows);
let jchip = JumpTableChip::new(config.jtable, config.max_available_rows);
Expand Down Expand Up @@ -287,6 +299,11 @@ impl<F: FieldExt> Circuit<F> for TestCircuit<F> {
)?
);

exec_with_profile!(
|| "Assign Post Image Table",
post_image_chip.assign(&mut layouter, todo!(), todo!(),)?
);

end_timer!(assign_timer);

Ok(())
Expand Down

0 comments on commit 4da8d4c

Please sign in to comment.