1#![deny(warnings)]
4#![forbid(unused_variables, unused_imports)]
5#![warn(missing_docs)]
6#![cfg_attr(not(feature = "std"), no_std)]
7
8extern crate alloc;
9
10use evm::{
11 backend::TransactionalBackend,
12 interpreter::{
13 ExitError, etable,
14 runtime::{RuntimeBackend, RuntimeEnvironment},
15 },
16 standard::{
17 Config, EtableResolver, ExecutionEtable, GasometerEtable, Invoker, TransactArgs,
18 TransactValue,
19 },
20};
21use evm_precompile::StandardPrecompileSet;
22
23#[doc(hidden)]
24pub use evm;
25#[doc(hidden)]
26pub use evm_precompile;
27
28pub static MAINNET_ETABLE: etable::Chained<GasometerEtable<'static>, ExecutionEtable<'static>> =
30 etable::Chained(GasometerEtable::new(), ExecutionEtable::new());
31pub static MAINNET_PRECOMPILE_SET: StandardPrecompileSet = StandardPrecompileSet;
33pub static MAINNET_RESOLVER: EtableResolver<
35 'static,
36 'static,
37 StandardPrecompileSet,
38 etable::Chained<GasometerEtable<'static>, ExecutionEtable<'static>>,
39> = EtableResolver::new(&MAINNET_PRECOMPILE_SET, &MAINNET_ETABLE);
40pub static MAINNET_INVOKER: Invoker<
42 'static,
43 'static,
44 EtableResolver<
45 'static,
46 'static,
47 StandardPrecompileSet,
48 etable::Chained<GasometerEtable<'static>, ExecutionEtable<'static>>,
49 >,
50> = Invoker::new(&MAINNET_RESOLVER);
51
52pub static FRONTIER_CONFIG: Config = Config::frontier();
54pub static HOMESTEAD_CONFIG: Config = Config::homestead();
56pub static TAGERINE_WHISTLE_CONFIG: Config = Config::tangerine_whistle();
58pub static SPURIOUS_DRAGON_CONFIG: Config = Config::spurious_dragon();
60pub static BYZANTIUM_CONFIG: Config = Config::byzantium();
62pub static PETERSBURG_CONFIG: Config = Config::petersburg();
64pub static ISTANBUL_CONFIG: Config = Config::istanbul();
66pub static BERLIN_CONFIG: Config = Config::berlin();
68pub static LONDON_CONFIG: Config = Config::london();
70pub static SHANGHAI_CONFIG: Config = Config::shanghai();
72pub static CANCUN_CONFIG: Config = Config::cancun();
74
75const TRANSACT_MAINNET_HEAP_DEPTH: Option<usize> = Some(4);
76pub fn transact_static<H>(
78 args: TransactArgs<'static>,
79 backend: &mut H,
80) -> Result<TransactValue, ExitError>
81where
82 H: TransactionalBackend + RuntimeEnvironment + RuntimeBackend,
83{
84 evm::transact(args, TRANSACT_MAINNET_HEAP_DEPTH, backend, &MAINNET_INVOKER)
85}
86
87#[macro_export]
89macro_rules! with_mainnet_invoker {
90 ( |$invoker:ident| $body:expr ) => {{
92 let precompiles = $crate::evm_precompile::StandardPrecompileSet;
93 let gas_etable =
94 $crate::evm::interpreter::etable::Single::new($crate::evm::standard::eval_gasometer);
95 let exec_etable = $crate::evm::standard::DispatchEtable::runtime();
96 let etable = $crate::evm::interpreter::etable::Chained(gas_etable, exec_etable);
97 let resolver = $crate::evm::standard::EtableResolver::new(&precompiles, &etable);
98 let $invoker = $crate::evm::standard::Invoker::new(&resolver);
99 $body
100 }};
101}
102
103pub fn transact<'config, H>(
105 args: TransactArgs<'config>,
106 backend: &mut H,
107) -> Result<TransactValue, ExitError>
108where
109 H: TransactionalBackend + RuntimeEnvironment + RuntimeBackend,
110{
111 with_mainnet_invoker!(|invoker| {
112 evm::transact(args, TRANSACT_MAINNET_HEAP_DEPTH, backend, &invoker)
113 })
114}