revm_context_interface/
host.rs1use crate::{
4 context::{SStoreResult, SelfDestructResult, StateLoad},
5 journaled_state::AccountLoad,
6};
7use auto_impl::auto_impl;
8use primitives::{Address, Bytes, Log, StorageKey, StorageValue, B256, U256};
9
10#[auto_impl(&mut, Box)]
16pub trait Host {
17 fn basefee(&self) -> U256;
21 fn blob_gasprice(&self) -> U256;
23 fn gas_limit(&self) -> U256;
25 fn difficulty(&self) -> U256;
27 fn prevrandao(&self) -> Option<U256>;
29 fn block_number(&self) -> U256;
31 fn timestamp(&self) -> U256;
33 fn beneficiary(&self) -> Address;
35 fn chain_id(&self) -> U256;
37
38 fn effective_gas_price(&self) -> U256;
42 fn caller(&self) -> Address;
44 fn blob_hash(&self, number: usize) -> Option<U256>;
46
47 fn max_initcode_size(&self) -> usize;
51
52 fn block_hash(&mut self, number: u64) -> Option<B256>;
56
57 fn selfdestruct(
61 &mut self,
62 address: Address,
63 target: Address,
64 ) -> Option<StateLoad<SelfDestructResult>>;
65
66 fn log(&mut self, log: Log);
68 fn sstore(
70 &mut self,
71 address: Address,
72 key: StorageKey,
73 value: StorageValue,
74 ) -> Option<StateLoad<SStoreResult>>;
75
76 fn sload(&mut self, address: Address, key: StorageKey) -> Option<StateLoad<StorageValue>>;
78 fn tstore(&mut self, address: Address, key: StorageKey, value: StorageValue);
80 fn tload(&mut self, address: Address, key: StorageKey) -> StorageValue;
82 fn balance(&mut self, address: Address) -> Option<StateLoad<U256>>;
84 fn load_account_delegated(&mut self, address: Address) -> Option<StateLoad<AccountLoad>>;
86 fn load_account_code(&mut self, address: Address) -> Option<StateLoad<Bytes>>;
88 fn load_account_code_hash(&mut self, address: Address) -> Option<StateLoad<B256>>;
90}
91
92#[derive(Debug)]
94pub struct DummyHost;
95
96impl Host for DummyHost {
97 fn basefee(&self) -> U256 {
98 U256::ZERO
99 }
100
101 fn blob_gasprice(&self) -> U256 {
102 U256::ZERO
103 }
104
105 fn gas_limit(&self) -> U256 {
106 U256::ZERO
107 }
108
109 fn difficulty(&self) -> U256 {
110 U256::ZERO
111 }
112
113 fn prevrandao(&self) -> Option<U256> {
114 None
115 }
116
117 fn block_number(&self) -> U256 {
118 U256::ZERO
119 }
120
121 fn timestamp(&self) -> U256 {
122 U256::ZERO
123 }
124
125 fn beneficiary(&self) -> Address {
126 Address::ZERO
127 }
128
129 fn chain_id(&self) -> U256 {
130 U256::ZERO
131 }
132
133 fn effective_gas_price(&self) -> U256 {
134 U256::ZERO
135 }
136
137 fn caller(&self) -> Address {
138 Address::ZERO
139 }
140
141 fn blob_hash(&self, _number: usize) -> Option<U256> {
142 None
143 }
144
145 fn max_initcode_size(&self) -> usize {
146 0
147 }
148
149 fn block_hash(&mut self, _number: u64) -> Option<B256> {
150 None
151 }
152
153 fn selfdestruct(
154 &mut self,
155 _address: Address,
156 _target: Address,
157 ) -> Option<StateLoad<SelfDestructResult>> {
158 None
159 }
160
161 fn log(&mut self, _log: Log) {}
162
163 fn sstore(
164 &mut self,
165 _address: Address,
166 _key: StorageKey,
167 _value: StorageValue,
168 ) -> Option<StateLoad<SStoreResult>> {
169 None
170 }
171
172 fn sload(&mut self, _address: Address, _key: StorageKey) -> Option<StateLoad<StorageValue>> {
173 None
174 }
175
176 fn tstore(&mut self, _address: Address, _key: StorageKey, _value: StorageValue) {}
177
178 fn tload(&mut self, _address: Address, _key: StorageKey) -> StorageValue {
179 StorageValue::ZERO
180 }
181
182 fn balance(&mut self, _address: Address) -> Option<StateLoad<U256>> {
183 None
184 }
185
186 fn load_account_delegated(&mut self, _address: Address) -> Option<StateLoad<AccountLoad>> {
187 None
188 }
189
190 fn load_account_code(&mut self, _address: Address) -> Option<StateLoad<Bytes>> {
191 None
192 }
193
194 fn load_account_code_hash(&mut self, _address: Address) -> Option<StateLoad<B256>> {
195 None
196 }
197}