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

Conversation

lightsing
Copy link
Contributor

Current revm try to load bytecode just after depth check, but there are some conditions the code is not needed:

  • insufficient balance to transfer
  • call to a precompile address

As long as the code is not needed, the database provider may not have corresponding code, like in our implementation scroll-tech/stateless-block-verifier#15 use this as an optimization.

@rakita
Copy link
Member

rakita commented Jul 8, 2024

Looks reasonable, will check it again to be sure

Comment on lines 220 to 236
if !bytecode.is_empty() {
let contract = Contract::new_with_context(
inputs.input.clone(),
bytecode,
Some(code_hash),
inputs,
);
// Create interpreter and executes call and push new CallStackFrame.
Ok(FrameOrResult::new_call_frame(
inputs.return_memory_offset.clone(),
checkpoint,
Interpreter::new(contract, gas.limit(), inputs.is_static),
))
} else {
self.journaled_state.checkpoint_commit();
return_result(InstructionResult::Stop)
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if !bytecode.is_empty() {
let contract = Contract::new_with_context(
inputs.input.clone(),
bytecode,
Some(code_hash),
inputs,
);
// Create interpreter and executes call and push new CallStackFrame.
Ok(FrameOrResult::new_call_frame(
inputs.return_memory_offset.clone(),
checkpoint,
Interpreter::new(contract, gas.limit(), inputs.is_static),
))
} else {
self.journaled_state.checkpoint_commit();
return_result(InstructionResult::Stop)
}
if bytecode.is_empty() {
self.journaled_state.checkpoint_commit();
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.
Ok(FrameOrResult::new_call_frame(
inputs.return_memory_offset.clone(),
checkpoint,
Interpreter::new(contract, gas.limit(), inputs.is_static),
))

code style nit. Maybe it needs fmt

let (account, _) = 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(..)?

Copy link
Member

@rakita rakita left a comment

Choose a reason for hiding this comment

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

Left comment, and one nit

@rakita rakita changed the title fix(revm): defer bytecode load chore(revm): defer bytecode load Jul 8, 2024
Copy link
Member

@rakita rakita left a comment

Choose a reason for hiding this comment

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

lgtm

@rakita rakita merged commit 63824c7 into bluealloy:main Jul 10, 2024
26 checks passed
j75689 pushed a commit to j75689/revm that referenced this pull request Aug 1, 2024
* defer bytecode load

* apply review
@lightsing lightsing deleted the fix/defer-bytecode-load branch August 7, 2024 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants