@@ -12,7 +12,8 @@ use gkr_iop::error::CircuitBuilderError;
1212use witness:: { InstancePaddingStrategy , RowMajorMatrix } ;
1313
1414use super :: ram_impl:: {
15- DynVolatileRamTableConfig , NonVolatileInitTableConfig , NonVolatileTableConfig , PubIOTableConfig ,
15+ DynVolatileRamTableConfig , NonVolatileInitTableConfig , NonVolatileTableConfig ,
16+ NonVolatileTableConfigTrait , PubIOTableConfig ,
1617} ;
1718
1819#[ derive( Clone , Debug ) ]
@@ -62,12 +63,15 @@ pub trait NonVolatileTable {
6263/// - with fixed initial content,
6364/// - with witnessed final content that the program wrote, if WRITABLE,
6465/// - or final content equal to initial content, if not WRITABLE.
65- pub struct NonVolatileRamCircuit < E , R > ( PhantomData < ( E , R ) > ) ;
66+ pub struct NonVolatileRamCircuit < E , R , C > ( PhantomData < ( E , R , C ) > ) ;
6667
67- impl < E : ExtensionField , NVRAM : NonVolatileTable + Send + Sync + Clone > TableCircuit < E >
68- for NonVolatileRamCircuit < E , NVRAM >
68+ impl <
69+ E : ExtensionField ,
70+ NVRAM : NonVolatileTable + Send + Sync + Clone ,
71+ C : NonVolatileTableConfigTrait < NVRAM > ,
72+ > TableCircuit < E > for NonVolatileRamCircuit < E , NVRAM , C >
6973{
70- type TableConfig = NonVolatileTableConfig < NVRAM > ;
74+ type TableConfig = C :: Config ;
7175 type FixedInput = [ MemInitRecord ] ;
7276 type WitnessInput = [ MemFinalRecord ] ;
7377
@@ -79,10 +83,7 @@ impl<E: ExtensionField, NVRAM: NonVolatileTable + Send + Sync + Clone> TableCirc
7983 cb : & mut CircuitBuilder < E > ,
8084 params : & ProgramParams ,
8185 ) -> Result < Self :: TableConfig , ZKVMError > {
82- Ok ( cb. namespace (
83- || Self :: name ( ) ,
84- |cb| Self :: TableConfig :: construct_circuit ( cb, params) ,
85- ) ?)
86+ Ok ( cb. namespace ( || Self :: name ( ) , |cb| C :: construct_circuit ( cb, params) ) ?)
8687 }
8788
8889 fn generate_fixed_traces (
@@ -91,7 +92,7 @@ impl<E: ExtensionField, NVRAM: NonVolatileTable + Send + Sync + Clone> TableCirc
9192 init_v : & Self :: FixedInput ,
9293 ) -> RowMajorMatrix < E :: BaseField > {
9394 // assume returned table is well-formed include padding
94- config . gen_init_state ( num_fixed, init_v)
95+ C :: gen_init_state ( config , num_fixed, init_v)
9596 }
9697
9798 fn assign_instances (
@@ -102,57 +103,13 @@ impl<E: ExtensionField, NVRAM: NonVolatileTable + Send + Sync + Clone> TableCirc
102103 final_v : & Self :: WitnessInput ,
103104 ) -> Result < RMMCollections < E :: BaseField > , ZKVMError > {
104105 // assume returned table is well-formed include padding
105- Ok ( config. assign_instances ( num_witin, num_structural_witin, final_v) ?)
106- }
107- }
108-
109- /// NonVolatileRamCircuit initializes and finalizes memory
110- /// - at fixed addresses,
111- /// - with fixed initial content,
112- /// - with witnessed final content that the program wrote, if WRITABLE,
113- /// - or final content equal to initial content, if not WRITABLE.
114- pub struct NonVolatileInitRamCircuit < E , R > ( PhantomData < ( E , R ) > ) ;
115-
116- impl < E : ExtensionField , NVRAM : NonVolatileTable + Send + Sync + Clone > TableCircuit < E >
117- for NonVolatileInitRamCircuit < E , NVRAM >
118- {
119- type TableConfig = NonVolatileInitTableConfig < NVRAM > ;
120- type FixedInput = [ MemInitRecord ] ;
121- type WitnessInput = [ MemFinalRecord ] ;
122-
123- fn name ( ) -> String {
124- format ! ( "RAM_{:?}_{}" , NVRAM :: RAM_TYPE , NVRAM :: name( ) )
125- }
126-
127- fn construct_circuit (
128- cb : & mut CircuitBuilder < E > ,
129- params : & ProgramParams ,
130- ) -> Result < Self :: TableConfig , ZKVMError > {
131- Ok ( cb. namespace (
132- || Self :: name ( ) ,
133- |cb| Self :: TableConfig :: construct_circuit ( cb, params) ,
106+ Ok ( C :: assign_instances (
107+ config,
108+ num_witin,
109+ num_structural_witin,
110+ final_v,
134111 ) ?)
135112 }
136-
137- fn generate_fixed_traces (
138- config : & Self :: TableConfig ,
139- num_fixed : usize ,
140- init_v : & Self :: FixedInput ,
141- ) -> RowMajorMatrix < E :: BaseField > {
142- // assume returned table is well-formed include padding
143- config. gen_init_state ( num_fixed, init_v)
144- }
145-
146- fn assign_instances (
147- config : & Self :: TableConfig ,
148- num_witin : usize ,
149- num_structural_witin : usize ,
150- _multiplicity : & [ HashMap < u64 , usize > ] ,
151- final_v : & Self :: WitnessInput ,
152- ) -> Result < RMMCollections < E :: BaseField > , ZKVMError > {
153- // assume returned table is well-formed include padding
154- Ok ( config. assign_instances ( num_witin, num_structural_witin, final_v) ?)
155- }
156113}
157114
158115/// PubIORamCircuit initializes and finalizes memory
@@ -241,13 +198,13 @@ pub trait DynVolatileRamTable {
241198}
242199
243200pub trait DynVolatileRamTableConfigTrait < DVRAM > : Sized + Send + Sync {
244- type Output : Sized + Send + Sync ;
201+ type Config : Sized + Send + Sync ;
245202 fn construct_circuit < E : ExtensionField > (
246203 cb : & mut CircuitBuilder < E > ,
247204 params : & ProgramParams ,
248- ) -> Result < Self :: Output , CircuitBuilderError > ;
205+ ) -> Result < Self :: Config , CircuitBuilderError > ;
249206 fn assign_instances < F : SmallField > (
250- & self ,
207+ config : & Self :: Config ,
251208 num_witin : usize ,
252209 num_structural_witin : usize ,
253210 final_mem : & [ MemFinalRecord ] ,
@@ -270,7 +227,7 @@ impl<
270227 C : DynVolatileRamTableConfigTrait < DVRAM > ,
271228> TableCircuit < E > for DynVolatileRamCircuit < E , DVRAM , C >
272229{
273- type TableConfig = C :: Output ;
230+ type TableConfig = C :: Config ;
274231 type FixedInput = ( ) ;
275232 type WitnessInput = [ MemFinalRecord ] ;
276233
@@ -301,6 +258,13 @@ impl<
301258 final_v : & Self :: WitnessInput ,
302259 ) -> Result < RMMCollections < E :: BaseField > , ZKVMError > {
303260 // assume returned table is well-formed include padding
304- Ok ( config. assign_instances ( num_witin, num_structural_witin, final_v) ?)
261+ Ok (
262+ <C as DynVolatileRamTableConfigTrait < DVRAM > >:: assign_instances (
263+ config,
264+ num_witin,
265+ num_structural_witin,
266+ final_v,
267+ ) ?,
268+ )
305269 }
306270}
0 commit comments