@@ -4,58 +4,49 @@ use mozak_runner::instruction::{Args, Instruction, Op, NOP};
4
4
use mozak_runner:: vm:: ExecutionRecord ;
5
5
use starky:: config:: StarkConfig ;
6
6
7
- use super :: benches :: Bench ;
7
+ use super :: Bench ;
8
8
use crate :: test_utils:: { prove_and_verify_mozak_stark, F } ;
9
9
10
- #[ allow( clippy:: module_name_repetitions) ]
11
- pub fn nop_execute ( ( program, record) : ( Program , ExecutionRecord < F > ) ) -> Result < ( ) , anyhow:: Error > {
12
- prove_and_verify_mozak_stark ( & program, & record, & StarkConfig :: standard_fast_config ( ) )
13
- }
14
-
15
- #[ allow( clippy:: module_name_repetitions) ]
16
- #[ must_use]
17
- pub fn nop_prepare ( iterations : u32 ) -> ( Program , ExecutionRecord < F > ) {
18
- let instructions = [
19
- Instruction {
20
- op : Op :: ADD ,
21
- args : Args {
22
- rd : 1 ,
23
- rs1 : 1 ,
24
- imm : 1_u32 . wrapping_neg ( ) ,
25
- ..Args :: default ( )
26
- } ,
27
- } ,
28
- NOP ,
29
- Instruction {
30
- op : Op :: BLT ,
31
- args : Args {
32
- rs1 : 0 ,
33
- rs2 : 1 ,
34
- imm : 0 ,
35
- ..Args :: default ( )
36
- } ,
37
- } ,
38
- ] ;
39
- code:: execute ( instructions, & [ ] , & [ ( 1 , iterations) ] )
40
- }
41
-
42
10
pub ( crate ) struct NopBench ;
43
11
44
12
impl Bench for NopBench {
45
13
type Args = u32 ;
46
14
type Prepared = ( Program , ExecutionRecord < F > ) ;
47
15
48
- fn prepare ( & self , args : & Self :: Args ) -> Self :: Prepared { nop_prepare ( * args) }
16
+ fn prepare ( & self , & iterations: & u32 ) -> Self :: Prepared {
17
+ let instructions = [
18
+ Instruction {
19
+ op : Op :: ADD ,
20
+ args : Args {
21
+ rd : 1 ,
22
+ rs1 : 1 ,
23
+ imm : 1_u32 . wrapping_neg ( ) ,
24
+ ..Args :: default ( )
25
+ } ,
26
+ } ,
27
+ NOP ,
28
+ Instruction {
29
+ op : Op :: BLT ,
30
+ args : Args {
31
+ rs1 : 0 ,
32
+ rs2 : 1 ,
33
+ imm : 0 ,
34
+ ..Args :: default ( )
35
+ } ,
36
+ } ,
37
+ ] ;
38
+ code:: execute ( instructions, & [ ] , & [ ( 1 , iterations) ] )
39
+ }
49
40
50
- fn execute ( & self , prepared : Self :: Prepared ) -> anyhow:: Result < ( ) > { nop_execute ( prepared) }
41
+ fn execute ( & self , ( program, record) : ( Program , ExecutionRecord < F > ) ) -> anyhow:: Result < ( ) > {
42
+ prove_and_verify_mozak_stark ( & program, & record, & StarkConfig :: standard_fast_config ( ) )
43
+ }
51
44
}
52
45
#[ cfg( test) ]
53
46
mod tests {
54
- use super :: { nop_execute, nop_prepare} ;
47
+ use super :: NopBench ;
48
+ use crate :: benches:: Bench ;
55
49
56
50
#[ test]
57
- fn test_nop_bench ( ) -> anyhow:: Result < ( ) > {
58
- let iterations = 10 ;
59
- nop_execute ( nop_prepare ( iterations) )
60
- }
51
+ fn test_nop_bench ( ) -> anyhow:: Result < ( ) > { NopBench { } . execute ( NopBench { } . prepare ( & 10 ) ) }
61
52
}
0 commit comments