@@ -195,7 +195,7 @@ pub mod test {
195
195
bytecode_table : [ Column < Advice > ; 5 ] ,
196
196
block_table : [ Column < Advice > ; 3 ] ,
197
197
copy_table : CopyCircuit < F > ,
198
- evm_circuit : EvmCircuit < F > ,
198
+ pub evm_circuit : EvmCircuit < F > ,
199
199
}
200
200
201
201
impl < F : Field > TestCircuitConfig < F > {
@@ -515,3 +515,82 @@ pub mod test {
515
515
run_test_circuit ( block, FixedTableTag :: iter ( ) . collect ( ) )
516
516
}
517
517
}
518
+
519
+ #[ cfg( test) ]
520
+ mod evm_circuit_stats {
521
+ use super :: test:: * ;
522
+ use super :: * ;
523
+ use crate :: evm_circuit:: step:: ExecutionState ;
524
+ use eth_types:: { bytecode, evm_types:: OpcodeId , geth_types:: GethData } ;
525
+ use halo2_proofs:: pairing:: bn256:: Fr ;
526
+ use halo2_proofs:: plonk:: ConstraintSystem ;
527
+ use mock:: test_ctx:: { helpers:: * , TestContext } ;
528
+ use strum:: IntoEnumIterator ;
529
+
530
+ /// This function prints to stdout a table with all the implemented states
531
+ /// and their responsible opcodes with the following stats:
532
+ /// - height: number of rows used by the execution state
533
+ /// - gas: gas value used for the opcode execution
534
+ /// - height/gas: ratio between circuit cost and gas cost
535
+ ///
536
+ /// Run with:
537
+ /// `cargo test -p zkevm-circuits --release get_evm_states_stats --
538
+ /// --nocapture --ignored`
539
+ #[ ignore]
540
+ #[ test]
541
+ pub fn get_evm_states_stats ( ) {
542
+ let mut meta = ConstraintSystem :: < Fr > :: default ( ) ;
543
+ let circuit = TestCircuit :: configure ( & mut meta) ;
544
+
545
+ let mut implemented_states = Vec :: new ( ) ;
546
+ for state in ExecutionState :: iter ( ) {
547
+ let height = circuit. evm_circuit . execution . get_step_height_option ( state) ;
548
+ if let Some ( h) = height {
549
+ implemented_states. push ( ( state, h) ) ;
550
+ }
551
+ }
552
+
553
+ let mut stats = Vec :: new ( ) ;
554
+ for ( state, h) in implemented_states {
555
+ for opcode in state. responsible_opcodes ( ) {
556
+ let mut code = bytecode ! {
557
+ PUSH2 ( 0x8000 )
558
+ PUSH2 ( 0x00 )
559
+ PUSH2 ( 0x10 )
560
+ PUSH2 ( 0x20 )
561
+ PUSH2 ( 0x30 )
562
+ PUSH2 ( 0x40 )
563
+ PUSH2 ( 0x50 )
564
+ } ;
565
+ code. write_op ( opcode) ;
566
+ code. write_op ( OpcodeId :: STOP ) ;
567
+ let block: GethData = TestContext :: < 2 , 1 > :: new (
568
+ None ,
569
+ account_0_code_account_1_no_code ( code) ,
570
+ tx_from_1_to_0,
571
+ |block, _tx| block. number ( 0xcafeu64 ) ,
572
+ )
573
+ . unwrap ( )
574
+ . into ( ) ;
575
+ let gas_cost = block. geth_traces [ 0 ] . struct_logs [ 7 ] . gas_cost . 0 ;
576
+ stats. push ( ( state, opcode, h, gas_cost) ) ;
577
+ }
578
+ }
579
+
580
+ println ! (
581
+ "| {: <14} | {: <14} | {: <2} | {: >6} | {: <5} |" ,
582
+ "state" , "opcode" , "h" , "g" , "h/g"
583
+ ) ;
584
+ println ! ( "| --- | --- | ---| --- | --- |" ) ;
585
+ for ( state, opcode, height, gas_cost) in stats {
586
+ println ! (
587
+ "| {: <14} | {: <14} | {: >2} | {: >6} | {: >1.3} |" ,
588
+ format!( "{:?}" , state) ,
589
+ format!( "{:?}" , opcode) ,
590
+ height,
591
+ gas_cost,
592
+ height as f64 / gas_cost as f64
593
+ ) ;
594
+ }
595
+ }
596
+ }
0 commit comments