Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(revm): defer bytecode load #1588

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions crates/revm/src/context/evm_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,11 @@ impl<DB: Database> EvmContext<DB> {
return return_result(InstructionResult::CallTooDeep);
}

let (account, _) = self
// Make account warm and loaded
let _ = self
.inner
.journaled_state
.load_code(inputs.bytecode_address, &mut self.inner.db)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is slightly an edge case that is not a consensus error but would fix it to be consistent. CALL from instruction loads account that makes account warm loaded, while if we do it from tx as in TransactTo this is not the case, this is really a edge case where it is noticeable only that account will not be returned from finalization and only if tx is calling precompile.

We can add here load_account in place of load_code, something like let _ = self...load_acccount(..)?


let code_hash = account.info.code_hash();
let bytecode = account.info.code.clone().unwrap_or_default();

// ExtDelegateCall is not allowed to call non-EOF contracts.
if inputs.scheme.is_ext_delegate_call()
&& bytecode.bytes_slice().get(..2) != Some(&EOF_MAGIC_BYTES)
{
return return_result(InstructionResult::InvalidExtDelegateCallTarget);
}
.load_account(inputs.bytecode_address, &mut self.inner.db)?;

// Create subroutine checkpoint
let checkpoint = self.journaled_state.checkpoint();
Expand Down Expand Up @@ -216,7 +207,27 @@ impl<DB: Database> EvmContext<DB> {
result,
inputs.return_memory_offset.clone(),
))
} else if !bytecode.is_empty() {
} else {
let (account, _) = self
.inner
.journaled_state
.load_code(inputs.bytecode_address, &mut self.inner.db)?;

let code_hash = account.info.code_hash();
let bytecode = account.info.code.clone().unwrap_or_default();

// ExtDelegateCall is not allowed to call non-EOF contracts.
if inputs.scheme.is_ext_delegate_call()
&& bytecode.bytes_slice().get(..2) != Some(&EOF_MAGIC_BYTES)
{
return return_result(InstructionResult::InvalidExtDelegateCallTarget);
}

if bytecode.is_empty() {
self.journaled_state.checkpoint_commit();
return return_result(InstructionResult::Stop);
}

let contract =
Contract::new_with_context(inputs.input.clone(), bytecode, Some(code_hash), inputs);
// Create interpreter and executes call and push new CallStackFrame.
Expand All @@ -225,9 +236,6 @@ impl<DB: Database> EvmContext<DB> {
checkpoint,
Interpreter::new(contract, gas.limit(), inputs.is_static),
))
} else {
self.journaled_state.checkpoint_commit();
return_result(InstructionResult::Stop)
}
}
}
Expand Down
Loading