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

WIP: Zhangjunyu/cont dev #204

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 2 additions & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ wasmi.workspace = true

[features]
default = []
cuda = ["delphinus-zkwasm/cuda"]
cuda = ["delphinus-zkwasm/cuda"]
continuation = ["delphinus-zkwasm/continuation"]
1 change: 1 addition & 0 deletions crates/zkwasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ rusty-fork = "0.3.0"
[features]
default = []
cuda = ["halo2_proofs/cuda", "specs/cuda"]
continuation = []
19 changes: 10 additions & 9 deletions crates/zkwasm/src/circuits/etable/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ impl<F: FieldExt> EventTableCellAllocator<F> {
meta: &mut ConstraintSystem<F>,
sel: Column<Fixed>,
rtable: &RangeTableConfig<F>,
mtable: &impl ConfigureLookupTable<F>,
_mtable: &impl ConfigureLookupTable<F>,
jtable: &JumpTableConfig<F>,
cols: &mut impl Iterator<Item = Column<Advice>>,
) -> Self {
Expand Down Expand Up @@ -349,14 +349,15 @@ impl<F: FieldExt> EventTableCellAllocator<F> {
let end_eid_col = cols.next().unwrap();
let encode_col = cols.next().unwrap();
let value_col = cols.next().unwrap();
mtable.configure_in_table(meta, "c8e. mtable_lookup in mtable", |meta| {
vec![
curr!(meta, start_eid_col),
curr!(meta, end_eid_col),
curr!(meta, encode_col),
curr!(meta, value_col),
]
});
// TODO: open mtable
// mtable.configure_in_table(meta, "c8e. mtable_lookup in mtable", |meta| {
// vec![
// curr!(meta, start_eid_col),
// curr!(meta, end_eid_col),
// curr!(meta, encode_col),
// curr!(meta, value_col),
// ]
// });
vec![start_eid_col, end_eid_col, encode_col, value_col]
})
.into_iter()
Expand Down
34 changes: 18 additions & 16 deletions crates/zkwasm/src/circuits/test_circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use crate::circuits::image_table::ImageTableChip;
use crate::circuits::image_table::ImageTableLayouter;
use crate::circuits::jtable::JumpTableChip;
use crate::circuits::jtable::JumpTableConfig;
use crate::circuits::mtable::MemoryTableChip;
use crate::circuits::mtable::MemoryTableConfig;
use crate::circuits::rtable::RangeTableChip;
use crate::circuits::rtable::RangeTableConfig;
Expand Down Expand Up @@ -57,7 +56,7 @@ const RESERVE_ROWS: usize = crate::circuits::bit_table::STEP_SIZE;
pub struct TestCircuitConfig<F: FieldExt> {
rtable: RangeTableConfig<F>,
image_table: ImageTableConfig<F>,
mtable: MemoryTableConfig<F>,
_mtable: MemoryTableConfig<F>,
jtable: JumpTableConfig<F>,
etable: EventTableConfig<F>,
bit_table: BitTableConfig<F>,
Expand Down Expand Up @@ -137,7 +136,8 @@ impl<F: FieldExt> Circuit<F> for TestCircuit<F> {
Self::Config {
rtable,
image_table,
mtable,
// TODO: open mtable
_mtable: mtable,
jtable,
etable,
bit_table,
Expand All @@ -158,7 +158,8 @@ impl<F: FieldExt> Circuit<F> for TestCircuit<F> {

let rchip = RangeTableChip::new(config.rtable);
let image_chip = ImageTableChip::new(config.image_table);
let mchip = MemoryTableChip::new(config.mtable, config.max_available_rows);
// TODO: open mtable
// let mchip = MemoryTableChip::new(config.mtable, config.max_available_rows);
let jchip = JumpTableChip::new(config.jtable, config.max_available_rows);
let echip = EventTableChip::new(config.etable, config.max_available_rows);
let bit_chip = BitTableChip::new(config.bit_table, config.max_available_rows);
Expand Down Expand Up @@ -223,18 +224,19 @@ impl<F: FieldExt> Circuit<F> for TestCircuit<F> {
)?
);

{
ctx.reset();
exec_with_profile!(
|| "Assign mtable",
mchip.assign(
&mut ctx,
etable_permutation_cells.rest_mops,
&memory_writing_table,
&self.tables.compilation_tables.imtable
)?
);
}
// TODO: open mtable
// {
// ctx.reset();
// exec_with_profile!(
// || "Assign mtable",
// mchip.assign(
// &mut ctx,
// etable_permutation_cells.rest_mops,
// &memory_writing_table,
// &self.tables.compilation_tables.imtable
// )?
// );
// }

let jtable_info = {
ctx.reset();
Expand Down
10 changes: 10 additions & 0 deletions crates/zkwasm/src/continuation/loader.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use crate::loader::ZkWasmLoader;

use halo2_proofs::arithmetic::MultiMillerLoop;

impl<E: MultiMillerLoop> ZkWasmLoader<E> {
/// Compute the capability(the length of etable entry) with circuit size K.
pub fn slice_capability_with_k(&self) -> usize {
todo!("compute maximal etable entries with self.k");
}
}
2 changes: 2 additions & 0 deletions crates/zkwasm/src/continuation/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod loader;
pub mod slice;
66 changes: 66 additions & 0 deletions crates/zkwasm/src/continuation/slice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use specs::etable::EventTable;
use specs::CompilationTable;
use specs::ExecutionTable;
use specs::Tables;

use crate::circuits::etable::EVENT_TABLE_ENTRY_ROWS;

pub struct Slice {
table: Tables,
current_slice: usize,
total_slice: usize,
}

pub struct Slices {
slices: Vec<Slice>,
// the length of etable entries
capability: usize,
}

impl Slices {
/// Split table to slices
pub fn from_table(table: Tables, capability: usize) -> Slices {
let mut etable_slices = table
.execution_tables
.etable
.entries()
.chunks((capability - 1) * EVENT_TABLE_ENTRY_ROWS as usize)
.collect::<Vec<_>>()
.iter()
.map(|v| v.to_vec())
.collect::<Vec<Vec<_>>>();

for index in 1..etable_slices.len() {
let first_entry = etable_slices[index - 1].last().unwrap().clone();
etable_slices[index].insert(0, first_entry);
}

let total_slice = etable_slices.len();
let slices = etable_slices
.into_iter()
.enumerate()
.map(|(current_slice, etable_slice)| Slice {
table: Tables {
compilation_tables: CompilationTable {
itable: table.compilation_tables.itable.clone(),
// TODO: imtable should be updated.
imtable: table.compilation_tables.imtable.clone(),
elem_table: table.compilation_tables.elem_table.clone(),
configure_table: table.compilation_tables.configure_table,
static_jtable: table.compilation_tables.static_jtable.clone(),
// TODO: fid_of_entry should be updated or removed.
fid_of_entry: table.compilation_tables.fid_of_entry,
},
execution_tables: ExecutionTable {
etable: EventTable::new(etable_slice),
jtable: table.execution_tables.jtable.clone(),
},
},
current_slice,
total_slice,
})
.collect();

Slices { slices, capability }
}
}
6 changes: 4 additions & 2 deletions crates/zkwasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#![deny(dead_code)]
// #![deny(dead_code)]
#![deny(unused_variables)]
#![deny(unused_imports)]
#![feature(thread_local)]

pub mod checksum;
pub mod circuits;
pub mod foreign;
pub mod loader;
pub mod runtime;

#[cfg(feature = "continuation")]
mod continuation;

mod profile;

#[cfg(test)]
Expand Down
3 changes: 3 additions & 0 deletions crates/zkwasm/src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ mod test_rlp;
mod test_start;
mod test_uniform_verifier;

#[cfg(feature = "continuation")]
mod test_rlp_continuation;

/// Create circuit with trace and run mock test.
fn test_circuit_mock<F: FieldExt>(
execution_result: ExecutionResult<wasmi::RuntimeValue>,
Expand Down
172 changes: 172 additions & 0 deletions crates/zkwasm/src/test/test_rlp_continuation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
use std::sync::Arc;
use std::sync::Mutex;

use crate::continuation::slice::Slices;
use crate::loader::ExecutionArg;
use crate::loader::ZkWasmLoader;

use anyhow::Result;
use halo2_proofs::pairing::bn256::Bn256;

fn test_slices() -> Result<()> {
let public_inputs = vec![133];
let private_inputs: Vec<u64> = vec![
14625441452057167097,
441,
0,
0,
144115188084244480,
17592186044416,
0,
0,
2,
0,
281474976710656,
72057594037928224,
0,
144115188075855872,
4398046511104,
2048,
0,
288230376151711744,
562949953421312,
36033195065475072,
0,
1152921504606846992,
0,
72057594037927936,
0,
0,
72057594037927936,
274877906944,
0,
8192,
0,
0,
0,
142172368092004352,
10663670667014018268,
15598333267600830878,
4825637194728734969,
11537926770794296992,
8941585237026987872,
1060144843738714138,
15286290987074524363,
41041,
0,
0,
0,
549784760702,
0,
0,
13839280179932823552,
9466528,
0,
1245741926200423424,
9993052845762533317,
643603743268,
0,
0,
0,
687194767360,
0,
0,
0,
274894684160,
0,
17752714368831347629,
14734568103978781184,
16340025600,
0,
0,
0,
17179869184,
0,
0,
13839280179932823552,
9466528,
0,
0,
13839280179932823552,
9466528,
0,
0,
13839280179932823552,
9466528,
0,
0,
13983395368008679424,
180934170288,
0,
0,
0,
216736848758702080,
0,
0,
0,
10708425217887174656,
8187143887307480351,
70325280878010241,
117203507575396024,
11486502108844260361,
13539931197926996738,
18161434576524511916,
11561024771253616253,
0,
0,
0,
12789659991778787328,
160,
0,
0,
0,
40960,
0,
0,
15880255236061790208,
17950538412901046486,
8547692942764276983,
8509190860294355049,
5730928406529570843,
18210150271972058323,
3994395479395232905,
6563862530498629762,
688805136118,
0,
0,
13839280179932823552,
175921869910688,
0,
0,
0,
45231150997700608,
0,
0,
0,
43020438485336064,
];

let wasm = std::fs::read("wasm/rlp.wasm").unwrap();

let loader = ZkWasmLoader::<Bn256>::new(18, wasm, vec![])?;

let execution_result = loader.run(ExecutionArg {
public_inputs,
private_inputs,
context_inputs: vec![],
context_outputs: Arc::new(Mutex::new(vec![])),
})?;

let _slices = Slices::from_table(execution_result.tables, loader.slice_capability_with_k());
todo!("build circuits for all slices");
todo!("mock test for all circuits");
}

mod tests {
use super::*;

#[test]
fn test_rlp_mock() {
test_slices().unwrap();
}
}