@@ -5,6 +5,7 @@ use log::debug;
5
5
use specs:: configure_table:: ConfigureTable ;
6
6
use specs:: itable:: Opcode ;
7
7
use specs:: itable:: OpcodeClassPlain ;
8
+ use specs:: InitializationState ;
8
9
use std:: collections:: BTreeMap ;
9
10
use std:: rc:: Rc ;
10
11
use wasmi:: DEFAULT_VALUE_STACK_LIMIT ;
@@ -111,15 +112,115 @@ impl<F: FieldExt> EventTableChip<F> {
111
112
Ok ( ( rest_mops_cell. cell ( ) , rest_mops_jell. cell ( ) ) )
112
113
}
113
114
115
+ #[ cfg( not( feature = "continuation" ) ) ]
116
+ fn assign_initialization_state (
117
+ & self ,
118
+ ctx : & mut Context < ' _ , F > ,
119
+ initialization_state : & InitializationState < u32 > ,
120
+ ) -> Result < InitializationState < Cell > , Error > {
121
+ macro_rules! assign_advice {
122
+ ( $cell: ident, $value: expr) => {
123
+ self . config. common_config. $cell. assign( ctx, $value) ?. cell( )
124
+ } ;
125
+ }
126
+
127
+ macro_rules! assign_constant {
128
+ ( $cell: ident, $value: expr) => {
129
+ self . config
130
+ . common_config
131
+ . $cell
132
+ . assign_constant( ctx, $value) ?
133
+ . cell( )
134
+ } ;
135
+ }
136
+
137
+ let eid = assign_constant ! ( eid_cell, initialization_state. eid) ;
138
+ let fid = assign_advice ! ( fid_cell, F :: from( initialization_state. fid as u64 ) ) ;
139
+ let iid = assign_constant ! ( iid_cell, F :: from( initialization_state. iid as u64 ) ) ;
140
+ let sp = assign_constant ! ( sp_cell, F :: from( initialization_state. sp as u64 ) ) ;
141
+ let frame_id =
142
+ assign_constant ! ( frame_id_cell, F :: from( initialization_state. frame_id as u64 ) ) ;
143
+
144
+ let initial_memory_pages = assign_advice ! (
145
+ mpages_cell,
146
+ F :: from( initialization_state. initial_memory_pages as u64 )
147
+ ) ;
148
+ let maximal_memory_pages = assign_advice ! (
149
+ maximal_memory_pages_cell,
150
+ F :: from( initialization_state. maximal_memory_pages as u64 )
151
+ ) ;
152
+
153
+ let rest_jops = assign_advice ! (
154
+ rest_jops_cell,
155
+ F :: from( initialization_state. rest_jops as u64 )
156
+ ) ;
157
+
158
+ Ok ( InitializationState {
159
+ eid,
160
+ fid,
161
+ iid,
162
+ frame_id,
163
+ sp,
164
+ initial_memory_pages,
165
+ maximal_memory_pages,
166
+ rest_jops,
167
+ is_very_first_step : initialization_state. is_very_first_step ,
168
+ } )
169
+ }
170
+
171
+ #[ cfg( feature = "continuation" ) ]
172
+ fn assign_initialization_state (
173
+ & self ,
174
+ ctx : & mut Context < ' _ , F > ,
175
+ initialization_state : & InitializationState < u32 > ,
176
+ ) -> Result < InitializationState < Cell > , Error > {
177
+ macro_rules! assign_advice {
178
+ ( $cell: ident, $value: expr) => {
179
+ self . config. common_config. $cell. assign( ctx, $value) ?. cell( )
180
+ } ;
181
+ }
182
+
183
+ let eid = assign_advice ! ( eid_cell, initialization_state. eid) ;
184
+ let fid = assign_advice ! ( fid_cell, F :: from( initialization_state. fid as u64 ) ) ;
185
+ let iid = assign_advice ! ( iid_cell, F :: from( initialization_state. iid as u64 ) ) ;
186
+ let sp = assign_advice ! ( sp_cell, F :: from( initialization_state. sp as u64 ) ) ;
187
+ let frame_id = assign_advice ! ( frame_id_cell, F :: from( initialization_state. frame_id as u64 ) ) ;
188
+
189
+ let initial_memory_pages = assign_advice ! (
190
+ mpages_cell,
191
+ F :: from( initialization_state. initial_memory_pages as u64 )
192
+ ) ;
193
+ let maximal_memory_pages = assign_advice ! (
194
+ maximal_memory_pages_cell,
195
+ F :: from( initialization_state. maximal_memory_pages as u64 )
196
+ ) ;
197
+
198
+ let rest_jops = assign_advice ! (
199
+ rest_jops_cell,
200
+ F :: from( initialization_state. rest_jops as u64 )
201
+ ) ;
202
+
203
+ Ok ( InitializationState {
204
+ eid,
205
+ fid,
206
+ iid,
207
+ frame_id,
208
+ sp,
209
+ initial_memory_pages,
210
+ maximal_memory_pages,
211
+ rest_jops,
212
+ is_very_first_step : initialization_state. is_very_first_step ,
213
+ } )
214
+ }
215
+
114
216
fn assign_entries (
115
217
& self ,
116
218
ctx : & mut Context < ' _ , F > ,
117
219
op_configs : & BTreeMap < OpcodeClassPlain , Rc < Box < dyn EventTableOpcodeConfig < F > > > > ,
118
220
event_table : & EventTableWithMemoryInfo ,
119
- configure_table : & ConfigureTable ,
120
- fid_of_entry : u32 ,
221
+ initialization_state : & InitializationState < u32 > ,
121
222
rest_ops : Vec < ( u32 , u32 ) > ,
122
- ) -> Result < ( Cell , Cell , Cell ) , Error > {
223
+ ) -> Result < ( ) , Error > {
123
224
macro_rules! assign_advice {
124
225
( $cell: ident, $value: expr) => {
125
226
self . config. common_config. $cell. assign( ctx, $value) ?
@@ -153,43 +254,22 @@ impl<F: FieldExt> EventTableChip<F> {
153
254
external_host_call_index_cell,
154
255
F :: from( external_host_call_call_index as u64 )
155
256
) ;
156
- let initial_memory_pages_cell = assign_advice ! (
157
- mpages_cell,
158
- F :: from( configure_table. init_memory_pages as u64 )
159
- ) ;
160
- let maximal_memory_pages_cell = assign_advice ! (
161
- maximal_memory_pages_cell,
162
- F :: from( configure_table. maximal_memory_pages as u64 )
163
- ) ;
164
- assign_constant ! ( sp_cell, F :: from( DEFAULT_VALUE_STACK_LIMIT as u64 - 1 ) ) ;
165
- assign_constant ! ( frame_id_cell, F :: zero( ) ) ;
166
- assign_constant ! ( eid_cell, 1 ) ;
167
- let fid_of_entry_cell = assign_advice ! ( fid_cell, F :: from( fid_of_entry as u64 ) ) ;
168
- assign_constant ! ( iid_cell, F :: zero( ) ) ;
169
257
170
258
/*
171
259
* Skip subsequent advice assignment in the first pass to enhance performance.
172
260
*/
173
261
{
174
262
let assigned_cell = assign_advice ! ( enabled_cell, F :: zero( ) ) ;
175
263
if assigned_cell. value ( ) . is_none ( ) {
176
- return Ok ( (
177
- fid_of_entry_cell. cell ( ) ,
178
- initial_memory_pages_cell. cell ( ) ,
179
- maximal_memory_pages_cell. cell ( ) ,
180
- ) ) ;
264
+ return Ok ( ( ) ) ;
181
265
}
182
266
}
183
267
184
268
/*
185
269
* The length of event_table equals 0: without_witness
186
270
*/
187
271
if event_table. 0 . len ( ) == 0 {
188
- return Ok ( (
189
- fid_of_entry_cell. cell ( ) ,
190
- initial_memory_pages_cell. cell ( ) ,
191
- maximal_memory_pages_cell. cell ( ) ,
192
- ) ) ;
272
+ return Ok ( ( ) ) ;
193
273
}
194
274
195
275
let status = {
@@ -234,7 +314,7 @@ impl<F: FieldExt> EventTableChip<F> {
234
314
current : & status[ index] ,
235
315
next : & status[ index + 1 ] ,
236
316
current_external_host_call_index : external_host_call_call_index,
237
- configure_table : * configure_table ,
317
+ maximal_memory_pages : initialization_state . maximal_memory_pages ,
238
318
host_public_inputs,
239
319
context_in_index,
240
320
context_out_index,
@@ -264,7 +344,7 @@ impl<F: FieldExt> EventTableChip<F> {
264
344
) ;
265
345
assign_advice ! (
266
346
maximal_memory_pages_cell,
267
- F :: from( configure_table . maximal_memory_pages as u64 )
347
+ F :: from( initialization_state . maximal_memory_pages as u64 )
268
348
) ;
269
349
assign_advice ! ( frame_id_cell, F :: from( entry. eentry. last_jump_eid as u64 ) ) ;
270
350
assign_advice ! ( eid_cell, entry. eentry. eid) ;
@@ -308,7 +388,7 @@ impl<F: FieldExt> EventTableChip<F> {
308
388
) ;
309
389
assign_advice ! (
310
390
maximal_memory_pages_cell,
311
- F :: from( configure_table . maximal_memory_pages as u64 )
391
+ F :: from( initialization_state . maximal_memory_pages as u64 )
312
392
) ;
313
393
assign_advice ! ( input_index_cell, F :: from( host_public_inputs as u64 ) ) ;
314
394
assign_advice ! ( context_input_index_cell, F :: from( context_in_index as u64 ) ) ;
@@ -318,20 +398,15 @@ impl<F: FieldExt> EventTableChip<F> {
318
398
F :: from( external_host_call_call_index as u64 )
319
399
) ;
320
400
321
- Ok ( (
322
- fid_of_entry_cell. cell ( ) ,
323
- initial_memory_pages_cell. cell ( ) ,
324
- maximal_memory_pages_cell. cell ( ) ,
325
- ) )
401
+ Ok ( ( ) )
326
402
}
327
403
328
404
pub ( in crate :: circuits) fn assign (
329
405
& self ,
330
406
ctx : & mut Context < ' _ , F > ,
331
407
event_table : & EventTableWithMemoryInfo ,
332
- configure_table : & ConfigureTable ,
333
- fid_of_entry : u32 ,
334
- ) -> Result < EventTablePermutationCells , Error > {
408
+ initialization_state : & InitializationState < u32 > ,
409
+ ) -> Result < InitializationState < Cell > , Error > {
335
410
debug ! ( "size of execution table: {}" , event_table. 0 . len( ) ) ;
336
411
assert ! ( event_table. 0 . len( ) * EVENT_TABLE_ENTRY_ROWS as usize <= self . max_available_rows) ;
337
412
@@ -340,29 +415,26 @@ impl<F: FieldExt> EventTableChip<F> {
340
415
self . init ( ctx) ?;
341
416
ctx. reset ( ) ;
342
417
343
- let ( rest_mops_cell, rest_jops_cell) = self . assign_rest_ops_first_step (
344
- ctx,
345
- rest_ops. first ( ) . map_or ( 0u32 , |( rest_mops, _) | * rest_mops) ,
346
- rest_ops. first ( ) . map_or ( 0u32 , |( _, rest_jops) | * rest_jops) ,
347
- ) ?;
418
+ // let (rest_mops_cell, rest_jops_cell) = self.assign_rest_ops_first_step(
419
+ // ctx,
420
+ // rest_ops.first().map_or(0u32, |(rest_mops, _)| *rest_mops),
421
+ // rest_ops.first().map_or(0u32, |(_, rest_jops)| *rest_jops),
422
+ // )?;
423
+ // ctx.reset();
424
+
425
+ let initialization_state_cells =
426
+ self . assign_initialization_state ( ctx, initialization_state) ?;
348
427
ctx. reset ( ) ;
349
428
350
- let ( fid_of_entry , initial_memory_pages , maximal_memory_pages ) = self . assign_entries (
429
+ self . assign_entries (
351
430
ctx,
352
431
& self . config . op_configs ,
353
432
event_table,
354
- configure_table,
355
- fid_of_entry,
433
+ initialization_state,
356
434
rest_ops,
357
435
) ?;
358
436
ctx. reset ( ) ;
359
437
360
- Ok ( EventTablePermutationCells {
361
- rest_mops : Some ( rest_mops_cell) ,
362
- rest_jops : Some ( rest_jops_cell) ,
363
- fid_of_entry,
364
- initial_memory_pages,
365
- maximal_memory_pages,
366
- } )
438
+ Ok ( initialization_state_cells)
367
439
}
368
440
}
0 commit comments