@@ -246,27 +246,27 @@ pub trait SingleTraceStep<F, CTX> {
246
246
fn get_opcode_name ( & self , opcode : usize ) -> String ;
247
247
}
248
248
249
- pub struct NewVmChipWrapper < F , AIR , C > {
249
+ pub struct NewVmChipWrapper < F , AIR , STEP > {
250
250
pub air : AIR ,
251
- pub inner : C ,
251
+ pub step : STEP ,
252
252
pub trace_buffer : Vec < F > ,
253
253
width : usize ,
254
254
buffer_idx : usize ,
255
255
mem_helper : SharedMemoryHelper < F > ,
256
256
}
257
257
258
- impl < F , AIR , C > NewVmChipWrapper < F , AIR , C >
258
+ impl < F , AIR , STEP > NewVmChipWrapper < F , AIR , STEP >
259
259
where
260
260
F : Field ,
261
261
AIR : BaseAir < F > ,
262
262
{
263
- pub fn new ( air : AIR , inner : C , height : usize , mem_helper : SharedMemoryHelper < F > ) -> Self {
263
+ pub fn new ( air : AIR , step : STEP , height : usize , mem_helper : SharedMemoryHelper < F > ) -> Self {
264
264
assert ! ( height == 0 || height. is_power_of_two( ) ) ;
265
265
let width = air. width ( ) ;
266
266
let trace_buffer = F :: zero_vec ( height * width) ;
267
267
Self {
268
268
air,
269
- inner ,
269
+ step ,
270
270
trace_buffer,
271
271
width,
272
272
buffer_idx : 0 ,
@@ -275,10 +275,10 @@ where
275
275
}
276
276
}
277
277
278
- impl < F , Air , C > InstructionExecutor < F > for NewVmChipWrapper < F , Air , C >
278
+ impl < F , AIR , STEP > InstructionExecutor < F > for NewVmChipWrapper < F , AIR , STEP >
279
279
where
280
280
F : PrimeField32 ,
281
- C : SingleTraceStep < F , ( ) > , // TODO: CTX?
281
+ STEP : SingleTraceStep < F , ( ) > , // TODO: CTX?
282
282
{
283
283
fn execute (
284
284
& mut self ,
@@ -305,27 +305,27 @@ where
305
305
self . trace_buffer
306
306
. get_unchecked_mut ( start_idx..self . buffer_idx )
307
307
} ;
308
- self . inner . execute ( state, instruction, row_slice) ?;
308
+ self . step . execute ( state, instruction, row_slice) ?;
309
309
Ok ( ExecutionState {
310
310
pc,
311
311
timestamp : memory. memory . timestamp ,
312
312
} )
313
313
}
314
314
315
315
fn get_opcode_name ( & self , opcode : usize ) -> String {
316
- self . inner . get_opcode_name ( opcode)
316
+ self . step . get_opcode_name ( opcode)
317
317
}
318
318
}
319
319
320
320
// Note[jpw]: the statement we want is:
321
321
// - `Air` is an `Air<AB>` for all `AB: AirBuilder`s needed by stark-backend
322
322
// which is equivalent to saying it implements AirRef<SC>
323
323
// The where clauses to achieve this statement is unfortunately really verbose.
324
- impl < SC , AIR , C > Chip < SC > for NewVmChipWrapper < Val < SC > , AIR , C >
324
+ impl < SC , AIR , STEP > Chip < SC > for NewVmChipWrapper < Val < SC > , AIR , STEP >
325
325
where
326
326
SC : StarkGenericConfig ,
327
327
Val < SC > : PrimeField32 ,
328
- C : SingleTraceStep < Val < SC > , ( ) > + Send + Sync ,
328
+ STEP : SingleTraceStep < Val < SC > , ( ) > + Send + Sync ,
329
329
AIR : Clone + AnyRap < SC > + ' static ,
330
330
{
331
331
fn air ( & self ) -> AirRef < SC > {
@@ -346,13 +346,13 @@ where
346
346
self . trace_buffer [ ..rows_used * self . width ]
347
347
. par_chunks_exact_mut ( self . width )
348
348
. for_each ( |row_slice| {
349
- self . inner . fill_trace_row ( & mem_helper, row_slice) ;
349
+ self . step . fill_trace_row ( & mem_helper, row_slice) ;
350
350
} ) ;
351
351
drop ( self . mem_helper ) ;
352
352
let trace = RowMajorMatrix :: new ( self . trace_buffer , self . width ) ;
353
353
// self.inner.finalize(&mut trace, num_records);
354
354
355
- AirProofInput :: simple ( trace, self . inner . generate_public_values ( ) )
355
+ AirProofInput :: simple ( trace, self . step . generate_public_values ( ) )
356
356
}
357
357
}
358
358
@@ -371,6 +371,47 @@ where
371
371
}
372
372
}
373
373
374
+ // TODO[jpw]: switch read,write to store into abstract buffer, then fill_trace_row using buffer
375
+ /// A helper trait for expressing generic state accesses within the implementation of
376
+ /// [SingleTraceStep]. Note that this is only a helper trait when the same interface of state access
377
+ /// is reused or shared by multiple implementations. It is not required to implement this trait if
378
+ /// it is easier to implement the [SingleTraceStep] trait directly without this trait.
379
+ pub trait AdapterTraceStep < F , CTX > {
380
+ /// Adapter row width
381
+ const WIDTH : usize ;
382
+ type ReadData ;
383
+ type WriteData ;
384
+ /// The minimal amount of information needed to generate the sub-row of the trace matrix.
385
+ /// This type has a lifetime so other context, such as references to other chips, can be
386
+ /// provided.
387
+ type TraceContext < ' a >
388
+ where
389
+ Self : ' a ;
390
+
391
+ fn start ( pc : u32 , memory : & TracingMemory , adapter_row : & mut [ F ] ) ;
392
+
393
+ fn read (
394
+ memory : & mut TracingMemory ,
395
+ instruction : & Instruction < F > ,
396
+ adapter_row : & mut [ F ] ,
397
+ ) -> Self :: ReadData ;
398
+
399
+ fn write (
400
+ memory : & mut TracingMemory ,
401
+ instruction : & Instruction < F > ,
402
+ adapter_row : & mut [ F ] ,
403
+ data : & Self :: WriteData ,
404
+ ) ;
405
+
406
+ // Note[jpw]: should we reuse TraceSubRowGenerator trait instead?
407
+ /// Post-execution filling of rest of adapter row.
408
+ fn fill_trace_row (
409
+ mem_helper : & MemoryAuxColsFactory < F > ,
410
+ ctx : Self :: TraceContext < ' _ > ,
411
+ adapter_row : & mut [ F ] ,
412
+ ) ;
413
+ }
414
+
374
415
pub struct VmChipWrapper < F , A : VmAdapterChip < F > , C : VmCoreChip < F , A :: Interface > > {
375
416
pub adapter : A ,
376
417
pub core : C ,
@@ -440,18 +481,18 @@ where
440
481
}
441
482
}
442
483
443
- impl < Mem , Ctx , F , A , C > InsExecutorE1 < Mem , Ctx , F > for NewVmChipWrapper < F , A , C >
484
+ impl < Mem , Ctx , F , A , S > InsExecutorE1 < Mem , Ctx , F > for NewVmChipWrapper < F , A , S >
444
485
where
445
486
Mem : GuestMemory ,
446
487
F : PrimeField32 ,
447
- C : InsExecutorE1 < Mem , Ctx , F > ,
488
+ S : InsExecutorE1 < Mem , Ctx , F > ,
448
489
{
449
490
fn execute_e1 (
450
491
& mut self ,
451
492
state : & mut VmExecutionState < Mem , Ctx > ,
452
493
instruction : & Instruction < F > ,
453
494
) -> Result < ( ) > {
454
- self . inner . execute_e1 ( state, instruction)
495
+ self . step . execute_e1 ( state, instruction)
455
496
}
456
497
}
457
498
0 commit comments