Skip to content

Commit 0083b99

Browse files
authored
fix: Handle fatal db error on load_account (#1111)
1 parent c51a2c4 commit 0083b99

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

crates/revm/src/context.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ impl<DB: Database> EvmContext<DB> {
162162
}
163163

164164
/// Sets precompiles
165+
#[inline]
165166
pub fn set_precompiles(&mut self, precompiles: Precompiles) {
166167
self.journaled_state.warm_preloaded_addresses =
167168
precompiles.addresses().copied().collect::<HashSet<_>>();
@@ -172,6 +173,7 @@ impl<DB: Database> EvmContext<DB> {
172173
///
173174
/// Loading of accounts/storages is needed to make them warm.
174175
#[inline]
176+
#[must_use]
175177
pub fn load_access_list(&mut self) -> Result<(), EVMError<DB::Error>> {
176178
for (address, slots) in self.env.tx.access_list.iter() {
177179
self.journaled_state
@@ -182,11 +184,14 @@ impl<DB: Database> EvmContext<DB> {
182184
}
183185

184186
/// Return environment.
187+
#[inline]
185188
pub fn env(&mut self) -> &mut Env {
186189
&mut self.env
187190
}
188191

189192
/// Fetch block hash from database.
193+
#[inline]
194+
#[must_use]
190195
pub fn block_hash(&mut self, number: U256) -> Option<B256> {
191196
self.db
192197
.block_hash(number)
@@ -195,6 +200,8 @@ impl<DB: Database> EvmContext<DB> {
195200
}
196201

197202
/// Load account and return flags (is_cold, exists)
203+
#[inline]
204+
#[must_use]
198205
pub fn load_account(&mut self, address: Address) -> Option<(bool, bool)> {
199206
self.journaled_state
200207
.load_account_exist(address, &mut self.db)
@@ -203,6 +210,8 @@ impl<DB: Database> EvmContext<DB> {
203210
}
204211

205212
/// Return account balance and is_cold flag.
213+
#[inline]
214+
#[must_use]
206215
pub fn balance(&mut self, address: Address) -> Option<(U256, bool)> {
207216
self.journaled_state
208217
.load_account(address, &mut self.db)
@@ -212,6 +221,8 @@ impl<DB: Database> EvmContext<DB> {
212221
}
213222

214223
/// Return account code and if address is cold loaded.
224+
#[inline]
225+
#[must_use]
215226
pub fn code(&mut self, address: Address) -> Option<(Bytecode, bool)> {
216227
let (acc, is_cold) = self
217228
.journaled_state
@@ -222,6 +233,8 @@ impl<DB: Database> EvmContext<DB> {
222233
}
223234

224235
/// Get code hash of address.
236+
#[inline]
237+
#[must_use]
225238
pub fn code_hash(&mut self, address: Address) -> Option<(B256, bool)> {
226239
let (acc, is_cold) = self
227240
.journaled_state
@@ -236,6 +249,8 @@ impl<DB: Database> EvmContext<DB> {
236249
}
237250

238251
/// Load storage slot, if storage is not present inside the account then it will be loaded from database.
252+
#[inline]
253+
#[must_use]
239254
pub fn sload(&mut self, address: Address, index: U256) -> Option<(U256, bool)> {
240255
// account is always warm. reference on that statement https://eips.ethereum.org/EIPS/eip-2929 see `Note 2:`
241256
self.journaled_state
@@ -245,6 +260,8 @@ impl<DB: Database> EvmContext<DB> {
245260
}
246261

247262
/// Storage change of storage slot, before storing `sload` will be called for that slot.
263+
#[inline]
264+
#[must_use]
248265
pub fn sstore(
249266
&mut self,
250267
address: Address,
@@ -258,16 +275,20 @@ impl<DB: Database> EvmContext<DB> {
258275
}
259276

260277
/// Returns transient storage value.
278+
#[inline]
261279
pub fn tload(&mut self, address: Address, index: U256) -> U256 {
262280
self.journaled_state.tload(address, index)
263281
}
264282

265283
/// Stores transient storage value.
284+
#[inline]
266285
pub fn tstore(&mut self, address: Address, index: U256, value: U256) {
267286
self.journaled_state.tstore(address, index, value)
268287
}
269288

270289
/// Make create frame.
290+
#[inline]
291+
#[must_use]
271292
pub fn make_create_frame(&mut self, spec_id: SpecId, inputs: &CreateInputs) -> FrameOrResult {
272293
// Prepare crate.
273294
let gas = Gas::new(inputs.gas_limit);
@@ -358,6 +379,8 @@ impl<DB: Database> EvmContext<DB> {
358379
}
359380

360381
/// Make call frame
382+
#[inline]
383+
#[must_use]
361384
pub fn make_call_frame(&mut self, inputs: &CallInputs) -> FrameOrResult {
362385
let gas = Gas::new(inputs.gas_limit);
363386

@@ -395,7 +418,9 @@ impl<DB: Database> EvmContext<DB> {
395418

396419
// Touch address. For "EIP-158 State Clear", this will erase empty accounts.
397420
if inputs.transfer.value == U256::ZERO {
398-
self.load_account(inputs.context.address);
421+
if self.load_account(inputs.context.address).is_none() {
422+
return return_result(InstructionResult::FatalExternalError);
423+
};
399424
self.journaled_state.touch(&inputs.context.address);
400425
}
401426

@@ -438,6 +463,7 @@ impl<DB: Database> EvmContext<DB> {
438463
}
439464

440465
/// Call precompile contract
466+
#[inline]
441467
fn call_precompile(
442468
&mut self,
443469
precompile: Precompile,

0 commit comments

Comments
 (0)