@@ -3,7 +3,7 @@ use crate::{
3
3
circuit_input_builder:: { CircuitInputStateRef , ExecStep } ,
4
4
Error ,
5
5
} ;
6
- use eth_types:: GethExecStep ;
6
+ use eth_types:: { GethExecStep , Word } ;
7
7
8
8
#[ derive( Clone , Copy , Debug ) ]
9
9
pub ( crate ) struct PushN ;
@@ -16,27 +16,32 @@ impl Opcode for PushN {
16
16
let geth_step = & geth_steps[ 0 ] ;
17
17
let mut exec_step = state. new_step ( geth_step) ?;
18
18
19
- let max_len = {
20
- let code_hash = state. call ( ) ?. code_hash ;
21
- let code_size = state. code ( code_hash) ?. len ( ) ;
22
- let pc = geth_step. pc . 0 ;
23
- code_size - ( pc + 1 )
24
- } ;
25
-
19
+ let code_hash = state. call ( ) ?. code_hash ;
20
+ let code = state. code ( code_hash) ?;
21
+ let code_size = code. len ( ) ;
22
+ let pc = geth_step. pc . 0 ;
26
23
let data_len = geth_step. op . data_len ( ) ;
27
-
28
- let real_value = geth_steps [ 1 ] . stack . last ( ) ? ;
29
-
30
- let value = if data_len <= max_len {
31
- real_value
24
+ let data_start = pc + 1 ;
25
+ let max_len = code_size - data_start ;
26
+ let mut value_bytes = [ 0u8 ; 32 ] ;
27
+ if data_len <= max_len {
28
+ value_bytes [ 32 - data_len.. ] . copy_from_slice ( & code [ data_start..data_start + data_len ] ) ;
32
29
} else {
33
- // If the bytecode is truncated, the bytecode circuit interprets only the actual data
34
- // without zero-padding.
35
- let missing_bits = ( data_len - max_len) * 8 ;
36
- real_value >> missing_bits
30
+ value_bytes[ 32 - max_len..] . copy_from_slice ( & code[ data_start..] ) ;
37
31
} ;
38
-
39
- state. stack_push ( & mut exec_step, value) ?;
32
+ let real_value = Word :: from_big_endian ( & value_bytes) ;
33
+ assert_eq ! ( real_value, geth_steps[ 1 ] . stack. last( ) ?) ;
34
+ let missing_bits = ( data_len - max_len) * 8 ;
35
+
36
+ state. call_ctx_mut ( ) ?. stack . push ( real_value) ?;
37
+
38
+ // If the bytecode is truncated, the bytecode circuit interprets only the actual data
39
+ // without zero-padding.
40
+ state. stack_write (
41
+ & mut exec_step,
42
+ state. call_ctx ( ) ?. stack . last_filled ( ) ,
43
+ real_value >> missing_bits,
44
+ ) ?;
40
45
41
46
Ok ( vec ! [ exec_step] )
42
47
}
0 commit comments