@@ -3,7 +3,7 @@ use crate::{
33 circuit_input_builder:: { CircuitInputStateRef , ExecStep } ,
44 Error ,
55} ;
6- use eth_types:: GethExecStep ;
6+ use eth_types:: { GethExecStep , Word } ;
77
88#[ derive( Clone , Copy , Debug ) ]
99pub ( crate ) struct PushN ;
@@ -16,27 +16,32 @@ impl Opcode for PushN {
1616 let geth_step = & geth_steps[ 0 ] ;
1717 let mut exec_step = state. new_step ( geth_step) ?;
1818
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 ;
2623 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 ] ) ;
3229 } 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..] ) ;
3731 } ;
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+ ) ?;
4045
4146 Ok ( vec ! [ exec_step] )
4247 }
0 commit comments