@@ -4,7 +4,7 @@ use crate::{
4
4
param:: N_BYTES_PROGRAM_COUNTER ,
5
5
step:: ExecutionState ,
6
6
util:: {
7
- common_gadget:: { CommonErrorGadget , WordByteCapGadget } ,
7
+ common_gadget:: { BytecodeLengthGadget , CommonErrorGadget , WordByteCapGadget } ,
8
8
constraint_builder:: { ConstrainBuilderCommon , EVMConstraintBuilder } ,
9
9
math_gadget:: { IsEqualGadget , IsZeroGadget } ,
10
10
CachedRegion , Cell ,
@@ -21,7 +21,6 @@ use halo2_proofs::{circuit::Value, plonk::Error};
21
21
pub ( crate ) struct ErrorInvalidJumpGadget < F > {
22
22
opcode : Cell < F > ,
23
23
dest : WordByteCapGadget < F , N_BYTES_PROGRAM_COUNTER > ,
24
- code_len : Cell < F > ,
25
24
value : Cell < F > ,
26
25
is_code : Cell < F > ,
27
26
push_rlc : Cell < F > ,
@@ -30,6 +29,7 @@ pub(crate) struct ErrorInvalidJumpGadget<F> {
30
29
phase2_condition : Cell < F > ,
31
30
is_condition_zero : IsZeroGadget < F > ,
32
31
common_error_gadget : CommonErrorGadget < F > ,
32
+ code_len_gadget : BytecodeLengthGadget < F > ,
33
33
}
34
34
35
35
impl < F : Field > ExecutionGadget < F > for ErrorInvalidJumpGadget < F > {
@@ -38,8 +38,9 @@ impl<F: Field> ExecutionGadget<F> for ErrorInvalidJumpGadget<F> {
38
38
const EXECUTION_STATE : ExecutionState = ExecutionState :: ErrorInvalidJump ;
39
39
40
40
fn configure ( cb : & mut EVMConstraintBuilder < F > ) -> Self {
41
- let code_len = cb. query_cell ( ) ;
42
- let dest = WordByteCapGadget :: construct ( cb, code_len. expr ( ) ) ;
41
+ // Look up bytecode length
42
+ let code_len_gadget = BytecodeLengthGadget :: construct ( cb, cb. curr . state . code_hash . clone ( ) ) ;
43
+ let dest = WordByteCapGadget :: construct ( cb, code_len_gadget. code_length . expr ( ) ) ;
43
44
44
45
let opcode = cb. query_cell ( ) ;
45
46
let value = cb. query_cell ( ) ;
@@ -71,9 +72,6 @@ impl<F: Field> ExecutionGadget<F> for ErrorInvalidJumpGadget<F> {
71
72
cb. require_zero ( "condition is not zero" , is_condition_zero. expr ( ) ) ;
72
73
} ) ;
73
74
74
- // Look up bytecode length
75
- cb. bytecode_length ( cb. curr . state . code_hash . expr ( ) , code_len. expr ( ) ) ;
76
-
77
75
// If destination is in valid range, lookup for the value.
78
76
cb. condition ( dest. lt_cap ( ) , |cb| {
79
77
cb. bytecode_lookup (
@@ -95,7 +93,6 @@ impl<F: Field> ExecutionGadget<F> for ErrorInvalidJumpGadget<F> {
95
93
Self {
96
94
opcode,
97
95
dest,
98
- code_len,
99
96
value,
100
97
is_code,
101
98
push_rlc,
@@ -104,6 +101,7 @@ impl<F: Field> ExecutionGadget<F> for ErrorInvalidJumpGadget<F> {
104
101
phase2_condition,
105
102
is_condition_zero,
106
103
common_error_gadget,
104
+ code_len_gadget,
107
105
}
108
106
}
109
107
@@ -132,9 +130,9 @@ impl<F: Field> ExecutionGadget<F> for ErrorInvalidJumpGadget<F> {
132
130
. bytecodes
133
131
. get ( & call. code_hash )
134
132
. expect ( "could not find current environment's bytecode" ) ;
135
- let code_len = code . bytes . len ( ) as u64 ;
136
- self . code_len
137
- . assign ( region, offset, Value :: known ( F :: from ( code_len ) ) ) ?;
133
+ let code_len = self
134
+ . code_len_gadget
135
+ . assign ( region, offset, block , & call . code_hash ) ?;
138
136
139
137
let dest = block. rws [ step. rw_indices [ 0 ] ] . stack_value ( ) ;
140
138
self . dest . assign ( region, offset, dest, F :: from ( code_len) ) ?;
0 commit comments