Skip to content

Commit 1b02425

Browse files
authored
circuit builder and constrain system share between ceno_zkvm + gkr_iop (#978)
PR build on top of #973 #976 This PR refactor `ConstrainSystem`, `CircuitBuilder` to `gkr-iop`, thus gkr-iop can leverage few existing utilization implemented in `ConstrainSystem`, e.g. register_read/write, assert_lt etc. `CircuitBuilder` some util dedicate to zkvm logic are stayed in original crate ### benchmark For fibonacci remain the same (4194304 improvement just due to noise I guess) | Benchmark | Median Time (s) | Median Change (%) | |----------------------------------|------------------|----------------------------------------------| | fibonacci_max_steps_1048576 | 2.0913 | +0.6455% (No change in performance detected) | | fibonacci_max_steps_2097152 | 3.5427 | -0.3998% (No change in performance detected) | | fibonacci_max_steps_4194304 | 6.4078 | -10.032% (Performance has improved) | For lookup keccak | Benchmark | Median Time (s) | Median Change (%) | |----------------------------------|------------------|----------------------------------------------| | keccak_lookup_f_4096 | 0.88398 | -1.5324% (No change in performance detected) | | keccak_lookup_f_8192 | 1.7557 | -1.2695% (No change in performance detected) |
1 parent 3385423 commit 1b02425

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1819
-1588
lines changed

ceno_zkvm/src/chip_handler.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
use ff_ext::ExtensionField;
2+
use gkr_iop::{error::CircuitBuilderError, gadgets::AssertLtConfig};
23

3-
use crate::{
4-
error::ZKVMError, gadgets::AssertLtConfig, instructions::riscv::constants::UINT_LIMBS,
5-
};
4+
use crate::instructions::riscv::constants::UINT_LIMBS;
65
use multilinear_extensions::{Expression, ToExpr};
76

87
pub mod general;
98
pub mod global_state;
109
pub mod memory;
1110
pub mod register;
1211

13-
#[cfg(test)]
14-
pub mod test;
15-
1612
pub trait GlobalStateRegisterMachineChipOperations<E: ExtensionField> {
17-
fn state_in(&mut self, pc: Expression<E>, ts: Expression<E>) -> Result<(), ZKVMError>;
13+
fn state_in(&mut self, pc: Expression<E>, ts: Expression<E>)
14+
-> Result<(), CircuitBuilderError>;
1815

19-
fn state_out(&mut self, pc: Expression<E>, ts: Expression<E>) -> Result<(), ZKVMError>;
16+
fn state_out(
17+
&mut self,
18+
pc: Expression<E>,
19+
ts: Expression<E>,
20+
) -> Result<(), CircuitBuilderError>;
2021
}
2122

2223
/// The common representation of a register value.
@@ -31,7 +32,7 @@ pub trait RegisterChipOperations<E: ExtensionField, NR: Into<String>, N: FnOnce(
3132
prev_ts: Expression<E>,
3233
ts: Expression<E>,
3334
value: RegisterExpr<E>,
34-
) -> Result<(Expression<E>, AssertLtConfig), ZKVMError>;
35+
) -> Result<(Expression<E>, AssertLtConfig), CircuitBuilderError>;
3536

3637
#[allow(clippy::too_many_arguments)]
3738
fn register_write(
@@ -42,7 +43,7 @@ pub trait RegisterChipOperations<E: ExtensionField, NR: Into<String>, N: FnOnce(
4243
ts: Expression<E>,
4344
prev_values: RegisterExpr<E>,
4445
value: RegisterExpr<E>,
45-
) -> Result<(Expression<E>, AssertLtConfig), ZKVMError>;
46+
) -> Result<(Expression<E>, AssertLtConfig), CircuitBuilderError>;
4647
}
4748

4849
/// The common representation of a memory address.
@@ -59,7 +60,7 @@ pub trait MemoryChipOperations<E: ExtensionField, NR: Into<String>, N: FnOnce()
5960
prev_ts: Expression<E>,
6061
ts: Expression<E>,
6162
value: MemoryExpr<E>,
62-
) -> Result<(Expression<E>, AssertLtConfig), ZKVMError>;
63+
) -> Result<(Expression<E>, AssertLtConfig), CircuitBuilderError>;
6364

6465
#[allow(clippy::too_many_arguments)]
6566
fn memory_write(
@@ -70,5 +71,5 @@ pub trait MemoryChipOperations<E: ExtensionField, NR: Into<String>, N: FnOnce()
7071
ts: Expression<E>,
7172
prev_values: MemoryExpr<E>,
7273
value: MemoryExpr<E>,
73-
) -> Result<(Expression<E>, AssertLtConfig), ZKVMError>;
74+
) -> Result<(Expression<E>, AssertLtConfig), CircuitBuilderError>;
7475
}

0 commit comments

Comments
 (0)