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

Feat/structural witin add #740

Merged
merged 36 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
87899de
init structural witin
hero78119 Dec 6, 2024
2679755
skip structural witin commitment & PCS(#654)
10to4 Dec 10, 2024
2c21443
skip structural witin commitment & PCS(#654):
10to4 Dec 12, 2024
9c9f4a5
Merge branch 'master' into feat/structural_witin_add
10to4 Dec 12, 2024
e9d24ab
Upgrade `pprof` (#706)
matthiasgoergens Dec 6, 2024
357595b
Update toolchain (#707)
matthiasgoergens Dec 7, 2024
614f385
Turn Transcript into trait (#692)
noel2004 Dec 9, 2024
774bab5
Further break down e2e logic (#703)
mcalancea Dec 9, 2024
be59026
Simplify SLTI tests (#710)
matthiasgoergens Dec 10, 2024
2c566e2
[FIX] Broken integration test caused by transcript (#715) (#721)
noel2004 Dec 10, 2024
2a35302
Enable debug assertions in integration tests (#714)
matthiasgoergens Dec 10, 2024
a45eced
Remove redundant format Make targets (#724)
matthiasgoergens Dec 10, 2024
cf15c14
Rename `mod divu` to `mod div` (#733)
matthiasgoergens Dec 11, 2024
e28e557
Introduce `Value::as_i32` (#732)
matthiasgoergens Dec 12, 2024
f3566bc
Remove broken features `non_pow2_rayon_thread` and `riv64` (#723)
matthiasgoergens Dec 12, 2024
5077eb1
Rename `AssertLTConfig` to `AssertLtConfig` (#731)
matthiasgoergens Dec 12, 2024
c07fa00
Remove unused and untested `u128`/`i128` implementations (#737)
matthiasgoergens Dec 12, 2024
1812068
Merge branch 'feat/structural_witin_add' of https://github.com/10to4/…
10to4 Dec 12, 2024
55e3b6b
skip structural witin commitment & PCS(#654):
10to4 Dec 12, 2024
65869f1
skip structural witin commitment & PCS(#654):
10to4 Dec 12, 2024
92687a4
skip structural witin commitment & PCS(#654):
10to4 Dec 16, 2024
3c9b862
refactor and support structural witness evaluation
hero78119 Dec 17, 2024
1f06873
cleanup multi-factor backend concept from ram circuit frontend
hero78119 Dec 17, 2024
601cc48
Merge pull request #1 from hero78119/feat/structural_witin_add
10to4 Dec 18, 2024
77b1887
skip structural witin commitment & PCS(#654):
10to4 Dec 20, 2024
103d82c
skip structural witin commitment & PCS(#654):
10to4 Dec 23, 2024
c040d45
Merge branch 'master' into feat/structural_witin_add
10to4 Dec 23, 2024
c05d3e2
skip structural witin commitment & PCS(#654):
10to4 Dec 23, 2024
669ae05
Merge branch 'master' into feat/structural_witin_add
10to4 Dec 24, 2024
e8eed3c
skip structural witin commitment & PCS(#654):
10to4 Dec 24, 2024
acf0d9f
skip structural witin commitment & PCS(#654):
10to4 Dec 24, 2024
88cd547
Less cloning
matthiasgoergens Dec 26, 2024
689691e
Merge branch 'matthias/less-cloning-2' into matthias/feat/structural_…
matthiasgoergens Dec 26, 2024
c60475b
Remove unnecessary wrapping in Expression
matthiasgoergens Dec 26, 2024
0601b4b
Unwrap instead of unreachable
matthiasgoergens Dec 26, 2024
606e1bf
Doc comment
matthiasgoergens Dec 26, 2024
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
21 changes: 18 additions & 3 deletions ceno_zkvm/src/chip_handler/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ff_ext::ExtensionField;
use crate::{
circuit_builder::{CircuitBuilder, ConstraintSystem, SetTableSpec},
error::ZKVMError,
expression::{Expression, Fixed, Instance, ToExpr, WitIn},
expression::{Expression, Fixed, Instance, StructuralWitIn, ToExpr, WitIn},
instructions::riscv::constants::{
END_CYCLE_IDX, END_PC_IDX, EXIT_CODE_IDX, INIT_CYCLE_IDX, INIT_PC_IDX, PUBLIC_IO_IDX,
UINT_LIMBS,
Expand All @@ -28,6 +28,21 @@ impl<'a, E: ExtensionField> CircuitBuilder<'a, E> {
self.cs.create_witin(name_fn)
}

pub fn create_structural_witin<NR, N>(
&mut self,
name_fn: N,
max_len: usize,
offset: u32,
multi_factor: usize,
) -> StructuralWitIn
where
NR: Into<String>,
N: FnOnce() -> NR,
{
self.cs
.create_structural_witin(name_fn, max_len, offset, multi_factor)
}

pub fn create_fixed<NR, N>(&mut self, name_fn: N) -> Result<Fixed, ZKVMError>
where
NR: Into<String>,
Expand Down Expand Up @@ -97,7 +112,7 @@ impl<'a, E: ExtensionField> CircuitBuilder<'a, E> {
&mut self,
name_fn: N,
ram_type: RAMType,
table_spec: SetTableSpec,
table_spec: SetTableSpec<E>,
record: Vec<Expression<E>>,
) -> Result<(), ZKVMError>
where
Expand All @@ -112,7 +127,7 @@ impl<'a, E: ExtensionField> CircuitBuilder<'a, E> {
&mut self,
name_fn: N,
ram_type: RAMType,
table_spec: SetTableSpec,
table_spec: SetTableSpec<E>,
record: Vec<Expression<E>>,
) -> Result<(), ZKVMError>
where
Expand Down
59 changes: 36 additions & 23 deletions ceno_zkvm/src/circuit_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
ROMType,
chip_handler::utils::rlc_chip_record,
error::ZKVMError,
expression::{Expression, Fixed, Instance, WitIn},
expression::{Expression, Fixed, Instance, StructuralWitIn, WitIn},
structs::{ProgramParams, ProvingKey, RAMType, VerifyingKey, WitnessId},
witness::RowMajorMatrix,
};
Expand Down Expand Up @@ -59,43 +59,38 @@ pub struct LogupTableExpression<E: ExtensionField> {
pub table_len: usize,
}

// TODO encapsulate few information of table spec to SetTableAddrType value
// once confirm syntax is friendly and parsed by recursive verifier
#[derive(Clone, Debug)]
pub enum SetTableAddrType {
FixedAddr,
DynamicAddr(DynamicAddr),
}

#[derive(Clone, Debug)]
pub struct DynamicAddr {
pub addr_witin_id: usize,
pub offset: Addr,
}

#[derive(Clone, Debug)]
pub struct SetTableSpec {
pub addr_type: SetTableAddrType,
pub len: usize,
pub struct SetTableSpec<E: ExtensionField> {
pub len: Option<usize>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does Some(0) differ from None?

pub structural_witins: Vec<Expression<E>>,
}

#[derive(Clone, Debug)]
pub struct SetTableExpression<E: ExtensionField> {
// table expression
pub expr: Expression<E>,

// TODO make decision to have enum/struct
// for which option is more friendly to be processed by ConstrainSystem + recursive verifier
pub table_spec: SetTableSpec,
pub table_spec: SetTableSpec<E>,
}

#[derive(Clone, Debug)]
pub struct ConstraintSystem<E: ExtensionField> {
pub(crate) ns: NameSpace,

// pub platform: Platform,
pub num_witin: WitnessId,
pub witin_namespace_map: Vec<String>,

pub num_structural_witin: WitnessId,
pub structural_witin_namespace_map: Vec<String>,

pub num_fixed: usize,
pub fixed_namespace_map: Vec<String>,

Expand Down Expand Up @@ -152,6 +147,8 @@ impl<E: ExtensionField> ConstraintSystem<E> {
num_witin: 0,
// platform,
witin_namespace_map: vec![],
num_structural_witin: 0,
structural_witin_namespace_map: vec![],
num_fixed: 0,
fixed_namespace_map: vec![],
ns: NameSpace::new(root_name_fn),
Expand Down Expand Up @@ -209,20 +206,36 @@ impl<E: ExtensionField> ConstraintSystem<E> {
}

pub fn create_witin<NR: Into<String>, N: FnOnce() -> NR>(&mut self, n: N) -> WitIn {
let wit_in = WitIn {
id: {
let id = self.num_witin;
self.num_witin = self.num_witin.strict_add(1);
id
},
};
let wit_in = WitIn { id: self.num_witin };
self.num_witin = self.num_witin.strict_add(1);

let path = self.ns.compute_path(n().into());
self.witin_namespace_map.push(path);

wit_in
}

pub fn create_structural_witin<NR: Into<String>, N: FnOnce() -> NR>(
&mut self,
n: N,
max_len: usize,
offset: u32,
multi_factor: usize,
) -> StructuralWitIn {
let wit_in = StructuralWitIn {
id: self.num_structural_witin,
max_len,
offset,
multi_factor,
};
self.num_structural_witin = self.num_structural_witin.strict_add(1);

let path = self.ns.compute_path(n().into());
self.structural_witin_namespace_map.push(path);

wit_in
}

pub fn create_fixed<NR: Into<String>, N: FnOnce() -> NR>(
&mut self,
n: N,
Expand Down Expand Up @@ -325,7 +338,7 @@ impl<E: ExtensionField> ConstraintSystem<E> {
&mut self,
name_fn: N,
ram_type: RAMType,
table_spec: SetTableSpec,
table_spec: SetTableSpec<E>,
record: Vec<Expression<E>>,
) -> Result<(), ZKVMError>
where
Expand Down Expand Up @@ -354,7 +367,7 @@ impl<E: ExtensionField> ConstraintSystem<E> {
&mut self,
name_fn: N,
ram_type: RAMType,
table_spec: SetTableSpec,
table_spec: SetTableSpec<E>,
record: Vec<Expression<E>>,
) -> Result<(), ZKVMError>
where
Expand Down
Loading