-
Notifications
You must be signed in to change notification settings - Fork 17
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
[experiment] Remove PROGRAM_SIZE from type #587
Changes from all commits
b9fc250
3c209a5
a5c4aa4
9dbcc88
62f1fee
f05efd1
e6c031f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,18 +18,23 @@ pub use program::{InsnRecord, ProgramTableCircuit}; | |
mod ram; | ||
pub use ram::*; | ||
|
||
pub trait TableCircuit<E: ExtensionField> { | ||
pub trait TableCircuit<E: ExtensionField> | ||
where | ||
Self: Default, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This Default requirement could move as far out as possible towards the function that actually needs it. |
||
{ | ||
type TableConfig: Send + Sync; | ||
type FixedInput: Send + Sync + ?Sized; | ||
type WitnessInput: Send + Sync + ?Sized; | ||
|
||
fn name() -> String; | ||
|
||
fn construct_circuit( | ||
&self, | ||
circuit_builder: &mut CircuitBuilder<E>, | ||
) -> Result<Self::TableConfig, ZKVMError>; | ||
|
||
fn generate_fixed_traces( | ||
&self, | ||
config: &Self::TableConfig, | ||
num_fixed: usize, | ||
input: &Self::FixedInput, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,11 +104,22 @@ pub struct ProgramTableConfig { | |
mlt: WitIn, | ||
} | ||
|
||
pub struct ProgramTableCircuit<E, const PROGRAM_SIZE: usize>(PhantomData<E>); | ||
#[derive(Clone, Default)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default here is 0 size which is probably not what you want. Just leave it without default to force the use of the |
||
pub struct ProgramTableCircuit<E> { | ||
program_size: usize, | ||
phantom_data: PhantomData<E>, | ||
} | ||
|
||
impl<E: ExtensionField> ProgramTableCircuit<E> { | ||
pub fn new(program_size: usize) -> Self { | ||
ProgramTableCircuit { | ||
program_size, | ||
phantom_data: PhantomData, | ||
} | ||
} | ||
} | ||
|
||
impl<E: ExtensionField, const PROGRAM_SIZE: usize> TableCircuit<E> | ||
for ProgramTableCircuit<E, PROGRAM_SIZE> | ||
{ | ||
impl<E: ExtensionField> TableCircuit<E> for ProgramTableCircuit<E> { | ||
type TableConfig = ProgramTableConfig; | ||
type FixedInput = Program; | ||
type WitnessInput = Program; | ||
|
@@ -117,7 +128,10 @@ impl<E: ExtensionField, const PROGRAM_SIZE: usize> TableCircuit<E> | |
"PROGRAM".into() | ||
} | ||
|
||
fn construct_circuit(cb: &mut CircuitBuilder<E>) -> Result<ProgramTableConfig, ZKVMError> { | ||
fn construct_circuit( | ||
&self, | ||
cb: &mut CircuitBuilder<E>, | ||
) -> Result<ProgramTableConfig, ZKVMError> { | ||
let record = InsnRecord([ | ||
cb.create_fixed(|| "pc")?, | ||
cb.create_fixed(|| "kind")?, | ||
|
@@ -137,7 +151,7 @@ impl<E: ExtensionField, const PROGRAM_SIZE: usize> TableCircuit<E> | |
|
||
cb.lk_table_record( | ||
|| "prog table", | ||
PROGRAM_SIZE, | ||
self.program_size, | ||
ROMType::Instruction, | ||
record_exprs, | ||
mlt.expr(), | ||
|
@@ -147,13 +161,14 @@ impl<E: ExtensionField, const PROGRAM_SIZE: usize> TableCircuit<E> | |
} | ||
|
||
fn generate_fixed_traces( | ||
&self, | ||
config: &ProgramTableConfig, | ||
num_fixed: usize, | ||
program: &Self::FixedInput, | ||
) -> RowMajorMatrix<E::BaseField> { | ||
let num_instructions = program.instructions.len(); | ||
let pc_base = program.base_address; | ||
assert!(num_instructions <= PROGRAM_SIZE); | ||
assert!(num_instructions <= self.program_size); | ||
|
||
let mut fixed = RowMajorMatrix::<E::BaseField>::new(num_instructions, num_fixed); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I applied the same change to this new file.