@@ -357,13 +357,15 @@ impl<'a, C: CircuitsParams> CircuitInputBuilder<C> {
357
357
// Optain the first op of the next GethExecStep, for fixed case also lookahead
358
358
let ( mut cib, mut tx, mut tx_ctx) = ( self . clone ( ) , tx, tx_ctx) ;
359
359
let mut cib_ref = cib. state_ref ( & mut tx, & mut tx_ctx) ;
360
+ println ! ( "aa before self.block_ctx.rwc.0 {}" , self . block_ctx. rwc. 0 ) ;
360
361
let next_ops = if let Some ( ( i, step) ) = next_geth_step {
361
362
log:: trace!( "chunk at {}th opcode {:?} " , i, step. op) ;
362
363
gen_associated_ops ( & step. op , & mut cib_ref, & geth_trace. struct_logs [ i..] ) ?. remove ( 0 )
363
364
} else {
364
365
log:: trace!( "chunk at EndTx" ) ;
365
366
gen_associated_steps ( & mut cib_ref, ExecState :: EndTx ) ?
366
367
} ;
368
+ println ! ( "aa before self.block_ctx.rwc.0 {}" , self . block_ctx. rwc. 0 ) ;
367
369
368
370
let last_copy = self . block . copy_events . len ( ) ;
369
371
// Generate EndChunk and proceed to the next if it's not the last chunk
@@ -421,6 +423,12 @@ impl<'a, C: CircuitsParams> CircuitInputBuilder<C> {
421
423
step. op,
422
424
self . chunk_rws( )
423
425
) ;
426
+ println ! (
427
+ "handle {}th opcode {:?} rws = {:?}" ,
428
+ i,
429
+ step. op,
430
+ self . chunk_rws( )
431
+ ) ;
424
432
let exec_steps = gen_associated_ops (
425
433
& step. op ,
426
434
& mut self . state_ref ( & mut tx, & mut tx_ctx) ,
@@ -431,7 +439,8 @@ impl<'a, C: CircuitsParams> CircuitInputBuilder<C> {
431
439
. map ( |step| tx. calls ( ) . get ( step. call_index ) . unwrap ( ) . clone ( ) ) ;
432
440
tx. steps_mut ( ) . extend ( exec_steps) ;
433
441
}
434
-
442
+ println ! ( "before end_tx rws = {:?}" , self . chunk_rws( ) ) ;
443
+ println ! ( "before end_tx block rws = {:?}" , self . block_ctx. rwc. 0 ) ;
435
444
// Peek the end_tx_step
436
445
self . check_and_chunk (
437
446
geth_trace,
@@ -445,6 +454,8 @@ impl<'a, C: CircuitsParams> CircuitInputBuilder<C> {
445
454
let end_tx_step =
446
455
gen_associated_steps ( & mut self . state_ref ( & mut tx, & mut tx_ctx) , ExecState :: EndTx ) ?;
447
456
tx. steps_mut ( ) . push ( end_tx_step. clone ( ) ) ;
457
+ println ! ( "after end_tx rws = {:?}" , self . chunk_rws( ) ) ;
458
+ println ! ( "after end_tx block rws = {:?}" , self . block_ctx. rwc. 0 ) ;
448
459
( end_tx_step, last_call)
449
460
} else if self . feature_config . invalid_tx {
450
461
// chunk before hands to avoid chunk between [InvalidTx, BeginTx)
@@ -466,8 +477,7 @@ impl<'a, C: CircuitsParams> CircuitInputBuilder<C> {
466
477
Ok ( res)
467
478
}
468
479
469
- // TODO Fix this, for current logic on processing `call` is incorrect
470
- // TODO re-design `gen_chunk_associated_steps` to separate RW
480
+ // generate chunk related steps
471
481
fn gen_chunk_associated_steps ( & mut self , step : & mut ExecStep , rw : RW ) {
472
482
let STEP_STATE_LEN = 10 ;
473
483
let mut dummy_tx = Transaction :: default ( ) ;
@@ -560,15 +570,20 @@ impl<'a, C: CircuitsParams> CircuitInputBuilder<C> {
560
570
fn set_begin_chunk ( & mut self , first_step : & ExecStep ) {
561
571
let mut begin_chunk = first_step. clone ( ) ;
562
572
begin_chunk. exec_state = ExecState :: BeginChunk ;
573
+ begin_chunk. bus_mapping_instance = Vec :: new ( ) ;
563
574
self . gen_chunk_associated_steps ( & mut begin_chunk, RW :: READ ) ;
564
575
self . chunks [ self . chunk_ctx . idx ] . begin_chunk = Some ( begin_chunk) ;
565
576
}
566
577
567
578
fn set_end_chunk ( & mut self , next_step : & ExecStep ) {
579
+ println ! ( "before self.block_ctx.rwc.0 {}" , self . block_ctx. rwc. 0 ) ;
580
+ println ! ( "next step {:?}" , next_step) ;
568
581
let mut end_chunk = next_step. clone ( ) ;
569
582
end_chunk. exec_state = ExecState :: EndChunk ;
583
+ end_chunk. bus_mapping_instance = Vec :: new ( ) ;
570
584
self . gen_chunk_associated_steps ( & mut end_chunk, RW :: WRITE ) ;
571
585
self . gen_chunk_padding ( & mut end_chunk) ;
586
+ println ! ( "after self.block_ctx.rwc.0 {}" , self . block_ctx. rwc. 0 ) ;
572
587
self . chunks [ self . chunk_ctx . idx ] . end_chunk = Some ( end_chunk) ;
573
588
}
574
589
@@ -710,7 +725,11 @@ impl CircuitInputBuilder<FixedCParams> {
710
725
println ! ( "--------------{:?}" , self . circuits_params) ;
711
726
// accumulates gas across all txs in the block
712
727
let ( last_step, last_call) = self . begin_handle_block ( eth_block, geth_traces) ?;
713
- let last_step = last_step. unwrap_or_default ( ) ;
728
+ let mut dummy_next_step = last_step. unwrap_or_default ( ) ;
729
+ ( 0 ..dummy_next_step. rw_indices_len ( ) ) . for_each ( |_| {
730
+ dummy_next_step. rwc . inc_pre ( ) ;
731
+ dummy_next_step. rwc_inner_chunk . inc_pre ( ) ;
732
+ } ) ;
714
733
715
734
assert ! ( self . circuits_params. max_rws( ) . is_some( ) ) ;
716
735
@@ -734,16 +753,29 @@ impl CircuitInputBuilder<FixedCParams> {
734
753
last_call. clone ( ) ,
735
754
) ;
736
755
} else {
737
- // it doent matter what step was put to set_end_chunk/set_begin_chunk on no-used
738
- // chunks before end_block. Just need to make sure it's step lookup is consistency.
739
- self . set_end_chunk ( & last_step) ;
756
+ // since there is no next step, we cook dummy next step from last step to reuse
757
+ // existing field while update its `rwc`.
758
+ println ! ( "for end_chunk dummy_next_step {:?}" , dummy_next_step) ;
759
+ self . set_end_chunk ( & dummy_next_step) ;
760
+ dummy_next_step. rwc = self . block_ctx . rwc ;
740
761
self . commit_chunk_ctx (
741
762
true ,
742
763
eth_block. transactions . len ( ) ,
743
764
last_copy,
744
765
last_call. clone ( ) ,
745
766
) ;
746
- self . set_begin_chunk ( & last_step) ;
767
+ dummy_next_step. rwc_inner_chunk = self . chunk_ctx . rwc ;
768
+ println ! ( "for begin_chunk dummy_next_step {:?}" , dummy_next_step) ;
769
+ self . set_begin_chunk ( & dummy_next_step) ;
770
+ dummy_next_step. rwc = self . block_ctx . rwc ;
771
+ dummy_next_step. rwc_inner_chunk = self . chunk_ctx . rwc ;
772
+ println ! ( "for end_block dummy_next_step {:?}" , dummy_next_step) ;
773
+ self . block . end_block = dummy_next_step. clone ( ) ;
774
+ self . cur_chunk_mut ( ) . padding = {
775
+ let mut padding = dummy_next_step. clone ( ) ;
776
+ padding. exec_state = ExecState :: Padding ;
777
+ Some ( padding)
778
+ } ;
747
779
}
748
780
Ok :: < ( ) , Error > ( ( ) )
749
781
} ) ?;
@@ -773,6 +805,7 @@ impl CircuitInputBuilder<FixedCParams> {
773
805
fn set_end_block ( & mut self ) -> Result < ( ) , Error > {
774
806
let mut end_block = self . block . end_block . clone ( ) ;
775
807
end_block. rwc = self . block_ctx . rwc ;
808
+ end_block. exec_state = ExecState :: EndBlock ;
776
809
end_block. rwc_inner_chunk = self . chunk_ctx . rwc ;
777
810
778
811
let mut dummy_tx = Transaction :: default ( ) ;
0 commit comments