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