evm_interpreter/eval/
mod.rs

1//! Actual opcode evaluation implementations.
2
3#[macro_use]
4mod macros;
5mod arithmetic;
6mod bitwise;
7mod misc;
8mod system;
9
10#[allow(unused_imports)]
11use crate::uint::{U256, U256Ext};
12use alloc::boxed::Box;
13#[allow(unused_imports)]
14use core::ops::{BitAnd, BitOr, BitXor};
15
16use crate::{
17	Control, ExitException, ExitSucceed, Machine, Opcode,
18	runtime::{GasState, RuntimeBackend, RuntimeConfig, RuntimeEnvironment, RuntimeState},
19	trap::{CallCreateOpcode, CallCreateTrap},
20};
21
22/// Do nothing, and continue to the next instruction.
23pub fn eval_pass<S, H, Tr>(
24	_machine: &mut Machine<S>,
25	_handle: &mut H,
26	_position: usize,
27) -> Control<Tr> {
28	Control::Continue(1)
29}
30
31/// `STOP`
32pub fn eval_stop<S, H, Tr>(
33	_machine: &mut Machine<S>,
34	_handle: &mut H,
35	_position: usize,
36) -> Control<Tr> {
37	Control::Exit(ExitSucceed::Stopped.into())
38}
39
40/// `ADD`
41pub fn eval_add<S, H, Tr>(
42	machine: &mut Machine<S>,
43	_handle: &mut H,
44	_position: usize,
45) -> Control<Tr> {
46	op2_u256_tuple!(machine, overflowing_add)
47}
48
49/// `MUL`
50pub fn eval_mul<S, H, Tr>(
51	machine: &mut Machine<S>,
52	_handle: &mut H,
53	_position: usize,
54) -> Control<Tr> {
55	op2_u256_tuple!(machine, overflowing_mul)
56}
57
58/// `SUB`
59pub fn eval_sub<S, H, Tr>(
60	machine: &mut Machine<S>,
61	_handle: &mut H,
62	_position: usize,
63) -> Control<Tr> {
64	op2_u256_tuple!(machine, overflowing_sub)
65}
66
67/// `DIV`
68pub fn eval_div<S, H, Tr>(
69	machine: &mut Machine<S>,
70	_handle: &mut H,
71	_position: usize,
72) -> Control<Tr> {
73	op2_u256_fn!(machine, self::arithmetic::div)
74}
75
76/// `SDIV`
77pub fn eval_sdiv<S, H, Tr>(
78	machine: &mut Machine<S>,
79	_handle: &mut H,
80	_position: usize,
81) -> Control<Tr> {
82	op2_u256_fn!(machine, self::arithmetic::sdiv)
83}
84
85/// `MOD`
86pub fn eval_mod<S, H, Tr>(
87	machine: &mut Machine<S>,
88	_handle: &mut H,
89	_position: usize,
90) -> Control<Tr> {
91	op2_u256_fn!(machine, self::arithmetic::rem)
92}
93
94/// `SMOD`
95pub fn eval_smod<S, H, Tr>(
96	machine: &mut Machine<S>,
97	_handle: &mut H,
98	_position: usize,
99) -> Control<Tr> {
100	op2_u256_fn!(machine, self::arithmetic::srem)
101}
102
103/// `ADDMOD`
104pub fn eval_addmod<S, H, Tr>(
105	machine: &mut Machine<S>,
106	_handle: &mut H,
107	_position: usize,
108) -> Control<Tr> {
109	op3_u256_fn!(machine, self::arithmetic::addmod)
110}
111
112/// `MULMOD`
113pub fn eval_mulmod<S, H, Tr>(
114	machine: &mut Machine<S>,
115	_handle: &mut H,
116	_position: usize,
117) -> Control<Tr> {
118	op3_u256_fn!(machine, self::arithmetic::mulmod)
119}
120
121/// `EXP`
122pub fn eval_exp<S, H, Tr>(
123	machine: &mut Machine<S>,
124	_handle: &mut H,
125	_position: usize,
126) -> Control<Tr> {
127	op2_u256_fn!(machine, self::arithmetic::exp)
128}
129
130/// `SIGNEXTEND`
131pub fn eval_signextend<S, H, Tr>(
132	machine: &mut Machine<S>,
133	_handle: &mut H,
134	_position: usize,
135) -> Control<Tr> {
136	op2_u256_fn!(machine, self::arithmetic::signextend)
137}
138
139/// `LT`
140pub fn eval_lt<S, H, Tr>(
141	machine: &mut Machine<S>,
142	_handle: &mut H,
143	_position: usize,
144) -> Control<Tr> {
145	op2_u256_bool_ref!(machine, lt)
146}
147
148/// `GT`
149pub fn eval_gt<S, H, Tr>(
150	machine: &mut Machine<S>,
151	_handle: &mut H,
152	_position: usize,
153) -> Control<Tr> {
154	op2_u256_bool_ref!(machine, gt)
155}
156
157/// `SLT`
158pub fn eval_slt<S, H, Tr>(
159	machine: &mut Machine<S>,
160	_handle: &mut H,
161	_position: usize,
162) -> Control<Tr> {
163	op2_u256_fn!(machine, self::bitwise::slt)
164}
165
166/// `SGT`
167pub fn eval_sgt<S, H, Tr>(
168	machine: &mut Machine<S>,
169	_handle: &mut H,
170	_position: usize,
171) -> Control<Tr> {
172	op2_u256_fn!(machine, self::bitwise::sgt)
173}
174
175/// `EQ`
176pub fn eval_eq<S, H, Tr>(
177	machine: &mut Machine<S>,
178	_handle: &mut H,
179	_position: usize,
180) -> Control<Tr> {
181	op2_u256_bool_ref!(machine, eq)
182}
183
184/// `ISZERO`
185pub fn eval_iszero<S, H, Tr>(
186	machine: &mut Machine<S>,
187	_handle: &mut H,
188	_position: usize,
189) -> Control<Tr> {
190	op1_u256_fn!(machine, self::bitwise::iszero)
191}
192
193/// `AND`
194pub fn eval_and<S, H, Tr>(
195	machine: &mut Machine<S>,
196	_handle: &mut H,
197	_position: usize,
198) -> Control<Tr> {
199	op2_u256!(machine, bitand)
200}
201
202/// `OR`
203pub fn eval_or<S, H, Tr>(
204	machine: &mut Machine<S>,
205	_handle: &mut H,
206	_position: usize,
207) -> Control<Tr> {
208	op2_u256!(machine, bitor)
209}
210
211/// `XOR`
212pub fn eval_xor<S, H, Tr>(
213	machine: &mut Machine<S>,
214	_handle: &mut H,
215	_position: usize,
216) -> Control<Tr> {
217	op2_u256!(machine, bitxor)
218}
219
220/// `NOT`
221pub fn eval_not<S, H, Tr>(
222	machine: &mut Machine<S>,
223	_handle: &mut H,
224	_position: usize,
225) -> Control<Tr> {
226	op1_u256_fn!(machine, self::bitwise::not)
227}
228
229/// `BYTE`
230pub fn eval_byte<S, H, Tr>(
231	machine: &mut Machine<S>,
232	_handle: &mut H,
233	_position: usize,
234) -> Control<Tr> {
235	op2_u256_fn!(machine, self::bitwise::byte)
236}
237
238/// `SHL`
239pub fn eval_shl<S, H, Tr>(
240	machine: &mut Machine<S>,
241	_handle: &mut H,
242	_position: usize,
243) -> Control<Tr> {
244	op2_u256_fn!(machine, self::bitwise::shl)
245}
246
247/// `SHR`
248pub fn eval_shr<S, H, Tr>(
249	machine: &mut Machine<S>,
250	_handle: &mut H,
251	_position: usize,
252) -> Control<Tr> {
253	op2_u256_fn!(machine, self::bitwise::shr)
254}
255
256/// `SAR`
257pub fn eval_sar<S, H, Tr>(
258	machine: &mut Machine<S>,
259	_handle: &mut H,
260	_position: usize,
261) -> Control<Tr> {
262	op2_u256_fn!(machine, self::bitwise::sar)
263}
264
265/// `CODESIZE`
266pub fn eval_codesize<S, H, Tr>(
267	machine: &mut Machine<S>,
268	_handle: &mut H,
269	_position: usize,
270) -> Control<Tr> {
271	self::misc::codesize(machine)
272}
273
274/// `CODECOPY`
275pub fn eval_codecopy<S, H, Tr>(
276	machine: &mut Machine<S>,
277	_handle: &mut H,
278	_position: usize,
279) -> Control<Tr> {
280	self::misc::codecopy(machine)
281}
282
283/// `CALLDATALOAD`
284pub fn eval_calldataload<S, H, Tr>(
285	machine: &mut Machine<S>,
286	_handle: &mut H,
287	_position: usize,
288) -> Control<Tr> {
289	self::misc::calldataload(machine)
290}
291
292/// `CALLDATASIZE`
293pub fn eval_calldatasize<S, H, Tr>(
294	machine: &mut Machine<S>,
295	_handle: &mut H,
296	_position: usize,
297) -> Control<Tr> {
298	self::misc::calldatasize(machine)
299}
300
301/// `CALLDATACOPY`
302pub fn eval_calldatacopy<S, H, Tr>(
303	machine: &mut Machine<S>,
304	_handle: &mut H,
305	_position: usize,
306) -> Control<Tr> {
307	self::misc::calldatacopy(machine)
308}
309
310/// `POP`
311pub fn eval_pop<S, H, Tr>(
312	machine: &mut Machine<S>,
313	_handle: &mut H,
314	_position: usize,
315) -> Control<Tr> {
316	self::misc::pop(machine)
317}
318
319/// `MLOAD`
320pub fn eval_mload<S, H, Tr>(
321	machine: &mut Machine<S>,
322	_handle: &mut H,
323	_position: usize,
324) -> Control<Tr> {
325	self::misc::mload(machine)
326}
327
328/// `MSTORE`
329pub fn eval_mstore<S, H, Tr>(
330	machine: &mut Machine<S>,
331	_handle: &mut H,
332	_position: usize,
333) -> Control<Tr> {
334	self::misc::mstore(machine)
335}
336
337/// `MSTORE8`
338pub fn eval_mstore8<S, H, Tr>(
339	machine: &mut Machine<S>,
340	_handle: &mut H,
341	_position: usize,
342) -> Control<Tr> {
343	self::misc::mstore8(machine)
344}
345
346/// `JUMP`
347pub fn eval_jump<S, H, Tr>(
348	machine: &mut Machine<S>,
349	_handle: &mut H,
350	_position: usize,
351) -> Control<Tr> {
352	self::misc::jump(machine)
353}
354
355/// `JUMPI`
356pub fn eval_jumpi<S, H, Tr>(
357	machine: &mut Machine<S>,
358	_handle: &mut H,
359	_position: usize,
360) -> Control<Tr> {
361	self::misc::jumpi(machine)
362}
363
364/// `PC`
365pub fn eval_pc<S, H, Tr>(
366	machine: &mut Machine<S>,
367	_handle: &mut H,
368	position: usize,
369) -> Control<Tr> {
370	self::misc::pc(machine, position)
371}
372
373/// `MSIZE`
374pub fn eval_msize<S, H, Tr>(
375	machine: &mut Machine<S>,
376	_handle: &mut H,
377	_position: usize,
378) -> Control<Tr> {
379	self::misc::msize(machine)
380}
381
382/// `JUMPDEST`
383pub fn eval_jumpdest<S, H, Tr>(
384	_machine: &mut Machine<S>,
385	_handle: &mut H,
386	_position: usize,
387) -> Control<Tr> {
388	Control::Continue(1)
389}
390
391/// `MCOPY`
392pub fn eval_mcopy<S, H, Tr>(
393	machine: &mut Machine<S>,
394	_handle: &mut H,
395	_position: usize,
396) -> Control<Tr> {
397	self::misc::mcopy(machine)
398}
399
400macro_rules! eval_push {
401    ($($num:expr),*) => {
402		$(paste::paste! {
403			/// `PUSHn`
404			pub fn [<eval_push $num>]<S, H, Tr>(
405				machine: &mut Machine<S>,
406				_handle: &mut H,
407				position: usize,
408			) -> Control<Tr> {
409				self::misc::push(machine, $num, position)
410			}
411		})*
412	};
413}
414
415eval_push! {
416	0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
417	17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32
418}
419
420macro_rules! eval_dup {
421    ($($num:expr),*) => {
422		$(paste::paste! {
423			/// `DUPn`
424			pub fn [<eval_dup $num>]<S, H, Tr>(
425				machine: &mut Machine<S>,
426				_handle: &mut H,
427				_position: usize,
428			) -> Control<Tr> {
429				self::misc::dup(machine, $num)
430			}
431		})*
432	};
433}
434
435eval_dup! { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }
436
437macro_rules! eval_swap {
438    ($($num:expr),*) => {
439		$(paste::paste! {
440			/// `SWAPn`
441			pub fn [<eval_swap $num>]<S, H, Tr>(
442				machine: &mut Machine<S>,
443				_handle: &mut H,
444				_position: usize,
445			) -> Control<Tr> {
446				self::misc::swap(machine, $num)
447			}
448		})*
449	};
450}
451
452eval_swap! { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }
453
454/// `RETURN`
455pub fn eval_return<S, H, Tr>(
456	machine: &mut Machine<S>,
457	_handle: &mut H,
458	_position: usize,
459) -> Control<Tr> {
460	self::misc::ret(machine)
461}
462
463/// `REVERT`
464pub fn eval_revert<S, H, Tr>(
465	machine: &mut Machine<S>,
466	_handle: &mut H,
467	_position: usize,
468) -> Control<Tr> {
469	self::misc::revert(machine)
470}
471
472/// `INVALID`
473pub fn eval_invalid<S, H, Tr>(
474	_machine: &mut Machine<S>,
475	_handle: &mut H,
476	_position: usize,
477) -> Control<Tr> {
478	Control::Exit(ExitException::DesignatedInvalid.into())
479}
480
481/// Any unknown opcode.
482pub fn eval_unknown<S, H, Tr>(
483	machine: &mut Machine<S>,
484	_handle: &mut H,
485	position: usize,
486) -> Control<Tr> {
487	Control::Exit(ExitException::InvalidOpcode(Opcode(machine.code()[position])).into())
488}
489
490/// `SHA3`
491pub fn eval_sha3<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
492	machine: &mut Machine<S>,
493	_handle: &mut H,
494	_position: usize,
495) -> Control<Tr> {
496	self::system::sha3(machine)
497}
498
499/// `ADDRESS`
500pub fn eval_address<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
501	machine: &mut Machine<S>,
502	_handle: &mut H,
503	_position: usize,
504) -> Control<Tr> {
505	self::system::address(machine)
506}
507
508/// `BALANCE`
509pub fn eval_balance<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
510	machine: &mut Machine<S>,
511	handle: &mut H,
512	_position: usize,
513) -> Control<Tr> {
514	self::system::balance(machine, handle)
515}
516
517/// `SELFBALANCE`
518pub fn eval_selfbalance<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
519	machine: &mut Machine<S>,
520	handle: &mut H,
521	_position: usize,
522) -> Control<Tr> {
523	self::system::selfbalance(machine, handle)
524}
525
526/// `ORIGIN`
527pub fn eval_origin<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
528	machine: &mut Machine<S>,
529	handle: &mut H,
530	_position: usize,
531) -> Control<Tr> {
532	self::system::origin(machine, handle)
533}
534
535/// `CALLER`
536pub fn eval_caller<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
537	machine: &mut Machine<S>,
538	_handle: &mut H,
539	_position: usize,
540) -> Control<Tr> {
541	self::system::caller(machine)
542}
543
544/// `CALLVALUE`
545pub fn eval_callvalue<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
546	machine: &mut Machine<S>,
547	_handle: &mut H,
548	_position: usize,
549) -> Control<Tr> {
550	self::system::callvalue(machine)
551}
552
553/// `GASPRICE`
554pub fn eval_gasprice<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
555	machine: &mut Machine<S>,
556	handle: &mut H,
557	_position: usize,
558) -> Control<Tr> {
559	self::system::gasprice(machine, handle)
560}
561
562/// `EXTCODESIZE`
563pub fn eval_extcodesize<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
564	machine: &mut Machine<S>,
565	handle: &mut H,
566	_position: usize,
567) -> Control<Tr> {
568	self::system::extcodesize(machine, handle)
569}
570
571/// `EXTCODEHASH`
572pub fn eval_extcodehash<
573	S: AsRef<RuntimeState> + AsRef<RuntimeConfig>,
574	H: RuntimeEnvironment + RuntimeBackend,
575	Tr,
576>(
577	machine: &mut Machine<S>,
578	handle: &mut H,
579	_position: usize,
580) -> Control<Tr> {
581	self::system::extcodehash(machine, handle)
582}
583
584/// `EXTCODECOPY`
585pub fn eval_extcodecopy<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
586	machine: &mut Machine<S>,
587	handle: &mut H,
588	_position: usize,
589) -> Control<Tr> {
590	self::system::extcodecopy(machine, handle)
591}
592
593/// `RETURNDATASIZE`
594pub fn eval_returndatasize<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
595	machine: &mut Machine<S>,
596	_handle: &mut H,
597	_position: usize,
598) -> Control<Tr> {
599	self::system::returndatasize(machine)
600}
601
602/// `RETURNDATACOPY`
603pub fn eval_returndatacopy<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
604	machine: &mut Machine<S>,
605	_handle: &mut H,
606	_position: usize,
607) -> Control<Tr> {
608	self::system::returndatacopy(machine)
609}
610
611/// `BLOCKHASH`
612pub fn eval_blockhash<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
613	machine: &mut Machine<S>,
614	handle: &mut H,
615	_position: usize,
616) -> Control<Tr> {
617	self::system::blockhash(machine, handle)
618}
619
620/// `COINBASE`
621pub fn eval_coinbase<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
622	machine: &mut Machine<S>,
623	handle: &mut H,
624	_position: usize,
625) -> Control<Tr> {
626	self::system::coinbase(machine, handle)
627}
628
629/// `TIMESTAMP`
630pub fn eval_timestamp<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
631	machine: &mut Machine<S>,
632	handle: &mut H,
633	_position: usize,
634) -> Control<Tr> {
635	self::system::timestamp(machine, handle)
636}
637
638/// `NUMBER`
639pub fn eval_number<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
640	machine: &mut Machine<S>,
641	handle: &mut H,
642	_position: usize,
643) -> Control<Tr> {
644	self::system::number(machine, handle)
645}
646
647/// `DIFFICULTY`
648pub fn eval_difficulty<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
649	machine: &mut Machine<S>,
650	handle: &mut H,
651	_position: usize,
652) -> Control<Tr> {
653	self::system::prevrandao(machine, handle)
654}
655
656/// `GASLIMIT`
657pub fn eval_gaslimit<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
658	machine: &mut Machine<S>,
659	handle: &mut H,
660	_position: usize,
661) -> Control<Tr> {
662	self::system::gaslimit(machine, handle)
663}
664
665/// `BLOBHASH`
666pub fn eval_blobhash<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
667	machine: &mut Machine<S>,
668	handle: &mut H,
669	_position: usize,
670) -> Control<Tr> {
671	self::system::blobhash(machine, handle)
672}
673
674/// `BLOBBASEFEE`
675pub fn eval_blobbasefee<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
676	machine: &mut Machine<S>,
677	handle: &mut H,
678	_position: usize,
679) -> Control<Tr> {
680	self::system::blobbasefee(machine, handle)
681}
682
683/// `SLOAD`
684pub fn eval_sload<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
685	machine: &mut Machine<S>,
686	handle: &mut H,
687	_position: usize,
688) -> Control<Tr> {
689	self::system::sload(machine, handle)
690}
691
692/// `SSTORE`
693pub fn eval_sstore<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
694	machine: &mut Machine<S>,
695	handle: &mut H,
696	_position: usize,
697) -> Control<Tr> {
698	self::system::sstore(machine, handle)
699}
700
701/// `GAS`
702pub fn eval_gas<S: GasState, H: RuntimeEnvironment + RuntimeBackend, Tr>(
703	machine: &mut Machine<S>,
704	handle: &mut H,
705	_position: usize,
706) -> Control<Tr> {
707	self::system::gas(machine, handle)
708}
709
710/// `TLOAD`
711pub fn eval_tload<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
712	machine: &mut Machine<S>,
713	handle: &mut H,
714	_position: usize,
715) -> Control<Tr> {
716	self::system::tload(machine, handle)
717}
718
719/// `TSTORE`
720pub fn eval_tstore<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
721	machine: &mut Machine<S>,
722	handle: &mut H,
723	_position: usize,
724) -> Control<Tr> {
725	self::system::tstore(machine, handle)
726}
727
728macro_rules! eval_log {
729    ($($num:expr),*) => {
730		$(paste::paste! {
731			/// `LOGn`
732			pub fn [<eval_log $num>]<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
733				machine: &mut Machine<S>,
734				handle: &mut H,
735				_position: usize,
736			) -> Control<Tr> {
737				self::system::log(machine, $num, handle)
738			}
739		})*
740	};
741}
742
743eval_log! { 0, 1, 2, 3, 4 }
744
745/// `SUICIDE`
746pub fn eval_suicide<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
747	machine: &mut Machine<S>,
748	handle: &mut H,
749	_position: usize,
750) -> Control<Tr> {
751	self::system::suicide(machine, handle)
752}
753
754/// `CHAINID`
755pub fn eval_chainid<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
756	machine: &mut Machine<S>,
757	handle: &mut H,
758	_position: usize,
759) -> Control<Tr> {
760	self::system::chainid(machine, handle)
761}
762
763/// `BASEFEE`
764pub fn eval_basefee<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
765	machine: &mut Machine<S>,
766	handle: &mut H,
767	_position: usize,
768) -> Control<Tr> {
769	self::system::basefee(machine, handle)
770}
771
772/// `CREATE`, `CREATE2`, `CALL`, `CALLCODE`, `DELEGATECALL`, `STATICCALL`
773pub fn eval_call_create_trap<
774	S: AsRef<RuntimeState> + AsMut<RuntimeState>,
775	H,
776	Tr: From<CallCreateTrap>,
777>(
778	machine: &mut Machine<S>,
779	_handle: &mut H,
780	position: usize,
781) -> Control<Tr> {
782	let raw_opcode = Opcode(machine.code()[position]);
783
784	let opcode = match raw_opcode {
785		Opcode::CREATE => CallCreateOpcode::Create,
786		Opcode::CREATE2 => CallCreateOpcode::Create2,
787		Opcode::CALL => CallCreateOpcode::Call,
788		Opcode::CALLCODE => CallCreateOpcode::CallCode,
789		Opcode::DELEGATECALL => CallCreateOpcode::DelegateCall,
790		Opcode::STATICCALL => CallCreateOpcode::StaticCall,
791		_ => return Control::Exit(Err(ExitException::InvalidOpcode(raw_opcode).into())),
792	};
793
794	let trap = match CallCreateTrap::new_from(opcode, machine) {
795		Ok(trap) => trap,
796		Err(err) => return Control::Exit(Err(err)),
797	};
798
799	Control::Trap(Box::new(trap.into()))
800}
801
802/// Eval any known opcode, uses `match`.
803pub fn eval_any<S, H, Tr>(machine: &mut Machine<S>, handle: &mut H, position: usize) -> Control<Tr>
804where
805	S: AsRef<RuntimeState> + AsMut<RuntimeState> + AsRef<RuntimeConfig> + GasState,
806	H: RuntimeEnvironment + RuntimeBackend,
807	Tr: From<CallCreateTrap>,
808{
809	let opcode = Opcode(machine.code()[position]);
810
811	match opcode {
812		Opcode::STOP => eval_stop(machine, handle, position),
813		Opcode::ADD => eval_add(machine, handle, position),
814		Opcode::MUL => eval_mul(machine, handle, position),
815		Opcode::SUB => eval_sub(machine, handle, position),
816		Opcode::DIV => eval_div(machine, handle, position),
817		Opcode::SDIV => eval_sdiv(machine, handle, position),
818		Opcode::MOD => eval_mod(machine, handle, position),
819		Opcode::SMOD => eval_smod(machine, handle, position),
820		Opcode::ADDMOD => eval_addmod(machine, handle, position),
821		Opcode::MULMOD => eval_mulmod(machine, handle, position),
822		Opcode::EXP => eval_exp(machine, handle, position),
823		Opcode::SIGNEXTEND => eval_signextend(machine, handle, position),
824
825		Opcode::LT => eval_lt(machine, handle, position),
826		Opcode::GT => eval_gt(machine, handle, position),
827		Opcode::SLT => eval_slt(machine, handle, position),
828		Opcode::SGT => eval_sgt(machine, handle, position),
829		Opcode::EQ => eval_eq(machine, handle, position),
830		Opcode::ISZERO => eval_iszero(machine, handle, position),
831		Opcode::AND => eval_and(machine, handle, position),
832		Opcode::OR => eval_or(machine, handle, position),
833		Opcode::XOR => eval_xor(machine, handle, position),
834		Opcode::NOT => eval_not(machine, handle, position),
835		Opcode::BYTE => eval_byte(machine, handle, position),
836
837		Opcode::SHL => eval_shl(machine, handle, position),
838		Opcode::SHR => eval_shr(machine, handle, position),
839		Opcode::SAR => eval_sar(machine, handle, position),
840
841		Opcode::CALLDATALOAD => eval_calldataload(machine, handle, position),
842		Opcode::CALLDATASIZE => eval_calldatasize(machine, handle, position),
843		Opcode::CALLDATACOPY => eval_calldatacopy(machine, handle, position),
844		Opcode::CODESIZE => eval_codesize(machine, handle, position),
845		Opcode::CODECOPY => eval_codecopy(machine, handle, position),
846
847		Opcode::POP => eval_pop(machine, handle, position),
848		Opcode::MLOAD => eval_mload(machine, handle, position),
849		Opcode::MSTORE => eval_mstore(machine, handle, position),
850		Opcode::MSTORE8 => eval_mstore8(machine, handle, position),
851
852		Opcode::JUMP => eval_jump(machine, handle, position),
853		Opcode::JUMPI => eval_jumpi(machine, handle, position),
854		Opcode::PC => eval_pc(machine, handle, position),
855		Opcode::MSIZE => eval_msize(machine, handle, position),
856
857		Opcode::JUMPDEST => eval_jumpdest(machine, handle, position),
858		Opcode::MCOPY => eval_mcopy(machine, handle, position),
859
860		Opcode::PUSH0 => eval_push0(machine, handle, position),
861		Opcode::PUSH1 => eval_push1(machine, handle, position),
862		Opcode::PUSH2 => eval_push2(machine, handle, position),
863		Opcode::PUSH3 => eval_push3(machine, handle, position),
864		Opcode::PUSH4 => eval_push4(machine, handle, position),
865		Opcode::PUSH5 => eval_push5(machine, handle, position),
866		Opcode::PUSH6 => eval_push6(machine, handle, position),
867		Opcode::PUSH7 => eval_push7(machine, handle, position),
868		Opcode::PUSH8 => eval_push8(machine, handle, position),
869		Opcode::PUSH9 => eval_push9(machine, handle, position),
870		Opcode::PUSH10 => eval_push10(machine, handle, position),
871		Opcode::PUSH11 => eval_push11(machine, handle, position),
872		Opcode::PUSH12 => eval_push12(machine, handle, position),
873		Opcode::PUSH13 => eval_push13(machine, handle, position),
874		Opcode::PUSH14 => eval_push14(machine, handle, position),
875		Opcode::PUSH15 => eval_push15(machine, handle, position),
876		Opcode::PUSH16 => eval_push16(machine, handle, position),
877		Opcode::PUSH17 => eval_push17(machine, handle, position),
878		Opcode::PUSH18 => eval_push18(machine, handle, position),
879		Opcode::PUSH19 => eval_push19(machine, handle, position),
880		Opcode::PUSH20 => eval_push20(machine, handle, position),
881		Opcode::PUSH21 => eval_push21(machine, handle, position),
882		Opcode::PUSH22 => eval_push22(machine, handle, position),
883		Opcode::PUSH23 => eval_push23(machine, handle, position),
884		Opcode::PUSH24 => eval_push24(machine, handle, position),
885		Opcode::PUSH25 => eval_push25(machine, handle, position),
886		Opcode::PUSH26 => eval_push26(machine, handle, position),
887		Opcode::PUSH27 => eval_push27(machine, handle, position),
888		Opcode::PUSH28 => eval_push28(machine, handle, position),
889		Opcode::PUSH29 => eval_push29(machine, handle, position),
890		Opcode::PUSH30 => eval_push30(machine, handle, position),
891		Opcode::PUSH31 => eval_push31(machine, handle, position),
892		Opcode::PUSH32 => eval_push32(machine, handle, position),
893
894		Opcode::DUP1 => eval_dup1(machine, handle, position),
895		Opcode::DUP2 => eval_dup2(machine, handle, position),
896		Opcode::DUP3 => eval_dup3(machine, handle, position),
897		Opcode::DUP4 => eval_dup4(machine, handle, position),
898		Opcode::DUP5 => eval_dup5(machine, handle, position),
899		Opcode::DUP6 => eval_dup6(machine, handle, position),
900		Opcode::DUP7 => eval_dup7(machine, handle, position),
901		Opcode::DUP8 => eval_dup8(machine, handle, position),
902		Opcode::DUP9 => eval_dup9(machine, handle, position),
903		Opcode::DUP10 => eval_dup10(machine, handle, position),
904		Opcode::DUP11 => eval_dup11(machine, handle, position),
905		Opcode::DUP12 => eval_dup12(machine, handle, position),
906		Opcode::DUP13 => eval_dup13(machine, handle, position),
907		Opcode::DUP14 => eval_dup14(machine, handle, position),
908		Opcode::DUP15 => eval_dup15(machine, handle, position),
909		Opcode::DUP16 => eval_dup16(machine, handle, position),
910
911		Opcode::SWAP1 => eval_swap1(machine, handle, position),
912		Opcode::SWAP2 => eval_swap2(machine, handle, position),
913		Opcode::SWAP3 => eval_swap3(machine, handle, position),
914		Opcode::SWAP4 => eval_swap4(machine, handle, position),
915		Opcode::SWAP5 => eval_swap5(machine, handle, position),
916		Opcode::SWAP6 => eval_swap6(machine, handle, position),
917		Opcode::SWAP7 => eval_swap7(machine, handle, position),
918		Opcode::SWAP8 => eval_swap8(machine, handle, position),
919		Opcode::SWAP9 => eval_swap9(machine, handle, position),
920		Opcode::SWAP10 => eval_swap10(machine, handle, position),
921		Opcode::SWAP11 => eval_swap11(machine, handle, position),
922		Opcode::SWAP12 => eval_swap12(machine, handle, position),
923		Opcode::SWAP13 => eval_swap13(machine, handle, position),
924		Opcode::SWAP14 => eval_swap14(machine, handle, position),
925		Opcode::SWAP15 => eval_swap15(machine, handle, position),
926		Opcode::SWAP16 => eval_swap16(machine, handle, position),
927
928		Opcode::RETURN => eval_return(machine, handle, position),
929
930		Opcode::REVERT => eval_revert(machine, handle, position),
931
932		Opcode::INVALID => eval_invalid(machine, handle, position),
933
934		Opcode::SHA3 => eval_sha3(machine, handle, position),
935
936		Opcode::ADDRESS => eval_address(machine, handle, position),
937		Opcode::BALANCE => eval_balance(machine, handle, position),
938		Opcode::ORIGIN => eval_origin(machine, handle, position),
939		Opcode::CALLER => eval_caller(machine, handle, position),
940		Opcode::CALLVALUE => eval_callvalue(machine, handle, position),
941
942		Opcode::GASPRICE => eval_gasprice(machine, handle, position),
943		Opcode::EXTCODESIZE => eval_extcodesize(machine, handle, position),
944		Opcode::EXTCODECOPY => eval_extcodecopy(machine, handle, position),
945		Opcode::RETURNDATASIZE => eval_returndatasize(machine, handle, position),
946		Opcode::RETURNDATACOPY => eval_returndatacopy(machine, handle, position),
947		Opcode::EXTCODEHASH => eval_extcodehash(machine, handle, position),
948
949		Opcode::BLOCKHASH => eval_blockhash(machine, handle, position),
950		Opcode::COINBASE => eval_coinbase(machine, handle, position),
951		Opcode::TIMESTAMP => eval_timestamp(machine, handle, position),
952		Opcode::NUMBER => eval_number(machine, handle, position),
953		Opcode::DIFFICULTY => eval_difficulty(machine, handle, position),
954		Opcode::GASLIMIT => eval_gaslimit(machine, handle, position),
955		Opcode::CHAINID => eval_chainid(machine, handle, position),
956		Opcode::SELFBALANCE => eval_selfbalance(machine, handle, position),
957		Opcode::BASEFEE => eval_basefee(machine, handle, position),
958		Opcode::BLOBHASH => eval_blobhash(machine, handle, position),
959		Opcode::BLOBBASEFEE => eval_blobbasefee(machine, handle, position),
960
961		Opcode::SLOAD => eval_sload(machine, handle, position),
962		Opcode::SSTORE => eval_sstore(machine, handle, position),
963
964		Opcode::GAS => eval_gas(machine, handle, position),
965
966		Opcode::TLOAD => eval_tload(machine, handle, position),
967		Opcode::TSTORE => eval_tstore(machine, handle, position),
968
969		Opcode::LOG0 => eval_log0(machine, handle, position),
970		Opcode::LOG1 => eval_log1(machine, handle, position),
971		Opcode::LOG2 => eval_log2(machine, handle, position),
972		Opcode::LOG3 => eval_log3(machine, handle, position),
973		Opcode::LOG4 => eval_log4(machine, handle, position),
974
975		Opcode::CREATE => eval_call_create_trap(machine, handle, position),
976		Opcode::CALL => eval_call_create_trap(machine, handle, position),
977		Opcode::CALLCODE => eval_call_create_trap(machine, handle, position),
978
979		Opcode::DELEGATECALL => eval_call_create_trap(machine, handle, position),
980		Opcode::CREATE2 => eval_call_create_trap(machine, handle, position),
981
982		Opcode::STATICCALL => eval_call_create_trap(machine, handle, position),
983
984		Opcode::SUICIDE => eval_suicide(machine, handle, position),
985
986		_ => eval_unknown(machine, handle, position),
987	}
988}