@@ -11,63 +11,63 @@ use ethrex_common::{U256, U512};
1111impl < ' a > VM < ' a > {
1212 // ADD operation
1313 pub fn op_add ( & mut self ) -> Result < OpcodeResult , VMError > {
14- let current_call_frame = & mut self . current_call_frame ;
15- current_call_frame . increase_consumed_gas ( gas_cost:: ADD ) ?;
14+ self . current_call_frame
15+ . increase_consumed_gas ( gas_cost:: ADD ) ?;
1616
17- let [ augend, addend] = * current_call_frame . stack . pop ( ) ?;
17+ let [ augend, addend] = * self . current_stack ( ) . pop ( ) ?;
1818 let sum = augend. overflowing_add ( addend) . 0 ;
19- current_call_frame . stack . push1 ( sum) ?;
19+ self . current_stack ( ) . push1 ( sum) ?;
2020
2121 Ok ( OpcodeResult :: Continue )
2222 }
2323
2424 // SUB operation
2525 pub fn op_sub ( & mut self ) -> Result < OpcodeResult , VMError > {
26- let current_call_frame = & mut self . current_call_frame ;
27- current_call_frame . increase_consumed_gas ( gas_cost:: SUB ) ?;
26+ self . current_call_frame
27+ . increase_consumed_gas ( gas_cost:: SUB ) ?;
2828
29- let [ minuend, subtrahend] = * current_call_frame . stack . pop ( ) ?;
29+ let [ minuend, subtrahend] = * self . current_stack ( ) . pop ( ) ?;
3030 let difference = minuend. overflowing_sub ( subtrahend) . 0 ;
31- current_call_frame . stack . push1 ( difference) ?;
31+ self . current_stack ( ) . push1 ( difference) ?;
3232
3333 Ok ( OpcodeResult :: Continue )
3434 }
3535
3636 // MUL operation
3737 pub fn op_mul ( & mut self ) -> Result < OpcodeResult , VMError > {
38- let current_call_frame = & mut self . current_call_frame ;
39- current_call_frame . increase_consumed_gas ( gas_cost:: MUL ) ?;
38+ self . current_call_frame
39+ . increase_consumed_gas ( gas_cost:: MUL ) ?;
4040
41- let [ multiplicand, multiplier] = * current_call_frame . stack . pop ( ) ?;
41+ let [ multiplicand, multiplier] = * self . current_stack ( ) . pop ( ) ?;
4242 let product = multiplicand. overflowing_mul ( multiplier) . 0 ;
43- current_call_frame . stack . push1 ( product) ?;
43+ self . current_stack ( ) . push1 ( product) ?;
4444
4545 Ok ( OpcodeResult :: Continue )
4646 }
4747
4848 // DIV operation
4949 pub fn op_div ( & mut self ) -> Result < OpcodeResult , VMError > {
50- let current_call_frame = & mut self . current_call_frame ;
51- current_call_frame . increase_consumed_gas ( gas_cost:: DIV ) ?;
50+ self . current_call_frame
51+ . increase_consumed_gas ( gas_cost:: DIV ) ?;
5252
53- let [ dividend, divisor] = * current_call_frame . stack . pop ( ) ?;
53+ let [ dividend, divisor] = * self . current_stack ( ) . pop ( ) ?;
5454 let Some ( quotient) = dividend. checked_div ( divisor) else {
55- current_call_frame . stack . push_zero ( ) ?;
55+ self . current_stack ( ) . push_zero ( ) ?;
5656 return Ok ( OpcodeResult :: Continue ) ;
5757 } ;
58- current_call_frame . stack . push1 ( quotient) ?;
58+ self . current_stack ( ) . push1 ( quotient) ?;
5959
6060 Ok ( OpcodeResult :: Continue )
6161 }
6262
6363 // SDIV operation
6464 pub fn op_sdiv ( & mut self ) -> Result < OpcodeResult , VMError > {
65- let current_call_frame = & mut self . current_call_frame ;
66- current_call_frame . increase_consumed_gas ( gas_cost:: SDIV ) ?;
65+ self . current_call_frame
66+ . increase_consumed_gas ( gas_cost:: SDIV ) ?;
6767
68- let [ dividend, divisor] = * current_call_frame . stack . pop ( ) ?;
68+ let [ dividend, divisor] = * self . current_stack ( ) . pop ( ) ?;
6969 if divisor. is_zero ( ) || dividend. is_zero ( ) {
70- current_call_frame . stack . push_zero ( ) ?;
70+ self . current_stack ( ) . push_zero ( ) ?;
7171 return Ok ( OpcodeResult :: Continue ) ;
7272 }
7373
@@ -86,34 +86,34 @@ impl<'a> VM<'a> {
8686 None => U256 :: zero ( ) ,
8787 } ;
8888
89- current_call_frame . stack . push1 ( quotient) ?;
89+ self . current_stack ( ) . push1 ( quotient) ?;
9090
9191 Ok ( OpcodeResult :: Continue )
9292 }
9393
9494 // MOD operation
9595 pub fn op_mod ( & mut self ) -> Result < OpcodeResult , VMError > {
96- let current_call_frame = & mut self . current_call_frame ;
97- current_call_frame . increase_consumed_gas ( gas_cost:: MOD ) ?;
96+ self . current_call_frame
97+ . increase_consumed_gas ( gas_cost:: MOD ) ?;
9898
99- let [ dividend, divisor] = * current_call_frame . stack . pop ( ) ?;
99+ let [ dividend, divisor] = * self . current_stack ( ) . pop ( ) ?;
100100
101101 let remainder = dividend. checked_rem ( divisor) . unwrap_or_default ( ) ;
102102
103- current_call_frame . stack . push1 ( remainder) ?;
103+ self . current_stack ( ) . push1 ( remainder) ?;
104104
105105 Ok ( OpcodeResult :: Continue )
106106 }
107107
108108 // SMOD operation
109109 pub fn op_smod ( & mut self ) -> Result < OpcodeResult , VMError > {
110- let current_call_frame = & mut self . current_call_frame ;
111- current_call_frame . increase_consumed_gas ( gas_cost:: SMOD ) ?;
110+ self . current_call_frame
111+ . increase_consumed_gas ( gas_cost:: SMOD ) ?;
112112
113- let [ unchecked_dividend, unchecked_divisor] = * current_call_frame . stack . pop ( ) ?;
113+ let [ unchecked_dividend, unchecked_divisor] = * self . current_stack ( ) . pop ( ) ?;
114114
115115 if unchecked_divisor. is_zero ( ) || unchecked_dividend. is_zero ( ) {
116- current_call_frame . stack . push_zero ( ) ?;
116+ self . current_stack ( ) . push_zero ( ) ?;
117117 return Ok ( OpcodeResult :: Continue ) ;
118118 }
119119
@@ -123,7 +123,7 @@ impl<'a> VM<'a> {
123123 let unchecked_remainder = match dividend. checked_rem ( divisor) {
124124 Some ( remainder) => remainder,
125125 None => {
126- current_call_frame . stack . push_zero ( ) ?;
126+ self . current_stack ( ) . push_zero ( ) ?;
127127 return Ok ( OpcodeResult :: Continue ) ;
128128 }
129129 } ;
@@ -134,20 +134,20 @@ impl<'a> VM<'a> {
134134 unchecked_remainder
135135 } ;
136136
137- current_call_frame . stack . push1 ( remainder) ?;
137+ self . current_stack ( ) . push1 ( remainder) ?;
138138
139139 Ok ( OpcodeResult :: Continue )
140140 }
141141
142142 // ADDMOD operation
143143 pub fn op_addmod ( & mut self ) -> Result < OpcodeResult , VMError > {
144- let current_call_frame = & mut self . current_call_frame ;
145- current_call_frame . increase_consumed_gas ( gas_cost:: ADDMOD ) ?;
144+ self . current_call_frame
145+ . increase_consumed_gas ( gas_cost:: ADDMOD ) ?;
146146
147- let [ augend, addend, modulus] = * current_call_frame . stack . pop ( ) ?;
147+ let [ augend, addend, modulus] = * self . current_stack ( ) . pop ( ) ?;
148148
149149 if modulus. is_zero ( ) {
150- current_call_frame . stack . push_zero ( ) ?;
150+ self . current_stack ( ) . push_zero ( ) ?;
151151 return Ok ( OpcodeResult :: Continue ) ;
152152 }
153153
@@ -170,20 +170,20 @@ impl<'a> VM<'a> {
170170 . try_into ( )
171171 . expect ( "can't fail because we applied % mod where mod is a U256 value" ) ;
172172
173- current_call_frame . stack . push1 ( sum_mod) ?;
173+ self . current_stack ( ) . push1 ( sum_mod) ?;
174174
175175 Ok ( OpcodeResult :: Continue )
176176 }
177177
178178 // MULMOD operation
179179 pub fn op_mulmod ( & mut self ) -> Result < OpcodeResult , VMError > {
180- let current_call_frame = & mut self . current_call_frame ;
181- current_call_frame . increase_consumed_gas ( gas_cost:: MULMOD ) ?;
180+ self . current_call_frame
181+ . increase_consumed_gas ( gas_cost:: MULMOD ) ?;
182182
183- let [ multiplicand, multiplier, modulus] = * current_call_frame . stack . pop ( ) ?;
183+ let [ multiplicand, multiplier, modulus] = * self . current_stack ( ) . pop ( ) ?;
184184
185185 if modulus. is_zero ( ) || multiplicand. is_zero ( ) || multiplier. is_zero ( ) {
186- current_call_frame . stack . push_zero ( ) ?;
186+ self . current_stack ( ) . push_zero ( ) ?;
187187 return Ok ( OpcodeResult :: Continue ) ;
188188 }
189189
@@ -203,35 +203,34 @@ impl<'a> VM<'a> {
203203 . try_into ( )
204204 . expect ( "can't fail because we applied % mod where mod is a U256 value" ) ;
205205
206- current_call_frame . stack . push1 ( product_mod) ?;
206+ self . current_stack ( ) . push1 ( product_mod) ?;
207207
208208 Ok ( OpcodeResult :: Continue )
209209 }
210210
211211 // EXP operation
212212 pub fn op_exp ( & mut self ) -> Result < OpcodeResult , VMError > {
213- let current_call_frame = & mut self . current_call_frame ;
214- let [ base, exponent] = * current_call_frame. stack . pop ( ) ?;
213+ let [ base, exponent] = * self . current_stack ( ) . pop ( ) ?;
215214
216215 let gas_cost = gas_cost:: exp ( exponent) ?;
217216
218- current_call_frame. increase_consumed_gas ( gas_cost) ?;
217+ self . current_call_frame . increase_consumed_gas ( gas_cost) ?;
219218
220219 let power = base. overflowing_pow ( exponent) . 0 ;
221- current_call_frame . stack . push1 ( power) ?;
220+ self . current_stack ( ) . push1 ( power) ?;
222221
223222 Ok ( OpcodeResult :: Continue )
224223 }
225224
226225 // SIGNEXTEND operation
227226 pub fn op_signextend ( & mut self ) -> Result < OpcodeResult , VMError > {
228- let current_call_frame = & mut self . current_call_frame ;
229- current_call_frame . increase_consumed_gas ( gas_cost:: SIGNEXTEND ) ?;
227+ self . current_call_frame
228+ . increase_consumed_gas ( gas_cost:: SIGNEXTEND ) ?;
230229
231- let [ byte_size_minus_one, value_to_extend] = * current_call_frame . stack . pop ( ) ?;
230+ let [ byte_size_minus_one, value_to_extend] = * self . current_stack ( ) . pop ( ) ?;
232231
233232 if byte_size_minus_one > U256 :: from ( 31 ) {
234- current_call_frame . stack . push1 ( value_to_extend) ?;
233+ self . current_stack ( ) . push1 ( value_to_extend) ?;
235234 return Ok ( OpcodeResult :: Continue ) ;
236235 }
237236
@@ -255,7 +254,7 @@ impl<'a> VM<'a> {
255254 value_to_extend | !mask
256255 } ;
257256
258- current_call_frame . stack . push1 ( result) ?;
257+ self . current_stack ( ) . push1 ( result) ?;
259258
260259 Ok ( OpcodeResult :: Continue )
261260 }
@@ -265,10 +264,9 @@ impl<'a> VM<'a> {
265264 self . current_call_frame
266265 . increase_consumed_gas ( gas_cost:: CLZ ) ?;
267266
268- let value = self . current_call_frame . stack . pop1 ( ) ?;
267+ let value = self . current_stack ( ) . pop1 ( ) ?;
269268
270- self . current_call_frame
271- . stack
269+ self . current_stack ( )
272270 . push1 ( U256 :: from ( value. leading_zeros ( ) ) ) ?;
273271
274272 Ok ( OpcodeResult :: Continue )
0 commit comments