Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v83 tag (revm v28.0.0) from v82 tag (revm v27.1.0)

* `SystemCallEvm` functions got renamed and old ones are deprecated. Renaming is done to align it with other API calls.
* `transact_system_call_finalize` is now `system_call`.
* `transact_system_call` is now `system_call_one`.

# v82 tag (revm v27.1.0) from v81 tag (revm v27.0.3)

* `ContextTr` gained `Host` supertrait.
Expand Down
2 changes: 1 addition & 1 deletion crates/ee-tests/src/op_revm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ fn test_system_call() {

let mut evm = ctx.build_op();

let _ = evm.system_call_one(SYSTEM_ADDRESS, BENCH_TARGET, bytes!("0x0001"));
let _ = evm.system_call_one(BENCH_TARGET, bytes!("0x0001"));
let state = evm.finalize();

assert!(state.get(&SYSTEM_ADDRESS).is_none());
Expand Down
76 changes: 45 additions & 31 deletions crates/handler/src/system_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,19 @@ impl SystemCallTx for TxEnv {
/// beneficiary. They are used before and after block execution to insert or obtain blockchain state.
///
/// It act similar to `transact` function and sets default Tx with data and system contract as a target.
///
/// # Note
///
/// Only one function needs implementation [`SystemCallEvm::system_call_one_with_caller`], other functions
/// are derived from it.
pub trait SystemCallEvm: ExecuteEvm {
/// System call is a special transaction call that is used to call a system contract.
///
/// Transaction fields are reset and set in [`SystemCallTx`] and data and target are set to
/// given values.
///
/// Block values are taken into account and will determent how system call will be executed.
fn system_call_one(
fn system_call_one_with_caller(
&mut self,
caller: Address,
system_contract_address: Address,
Expand All @@ -92,62 +97,71 @@ pub trait SystemCallEvm: ExecuteEvm {
/// given values.
///
/// Block values are taken into account and will determent how system call will be executed.
#[deprecated(since = "0.1.0", note = "Use `system_call_one` instead")]
fn transact_system_call_with_caller(
fn system_call_one(
&mut self,
caller: Address,
system_contract_address: Address,
data: Bytes,
) -> Result<Self::ExecutionResult, Self::Error> {
self.system_call_one(caller, system_contract_address, data)
self.system_call_one_with_caller(SYSTEM_ADDRESS, system_contract_address, data)
}

/// Calls [`SystemCallEvm::system_call_one`] with [`SYSTEM_ADDRESS`] as a caller.
#[deprecated(
since = "0.1.0",
note = "Use `system_call_one` with SYSTEM_ADDRESS instead"
)]
fn transact_system_call(
/// Internally calls [`SystemCallEvm::system_call_with_caller`].
fn system_call(
&mut self,
system_contract_address: Address,
data: Bytes,
) -> Result<Self::ExecutionResult, Self::Error> {
self.system_call_one(SYSTEM_ADDRESS, system_contract_address, data)
) -> Result<ExecResultAndState<Self::ExecutionResult, Self::State>, Self::Error> {
self.system_call_with_caller(SYSTEM_ADDRESS, system_contract_address, data)
}

/// Transact the system call and finalize.
///
/// Internally calls combo of `system_call_one` and `finalize` functions.
fn system_call(
/// Internally calls [`SystemCallEvm::system_call_one`] and [`ExecuteEvm::finalize`] functions to obtain the changed state.
fn system_call_with_caller(
&mut self,
caller: Address,
system_contract_address: Address,
data: Bytes,
) -> Result<ExecResultAndState<Self::ExecutionResult, Self::State>, Self::Error> {
self.system_call_with_caller(SYSTEM_ADDRESS, system_contract_address, data)
let result = self.system_call_one_with_caller(caller, system_contract_address, data)?;
let state = self.finalize();
Ok(ExecResultAndState::new(result, state))
}

/// Transact the system call and finalize.
/// System call is a special transaction call that is used to call a system contract.
///
/// Internally calls combo of `transact_system_call` and `finalize` functions.
#[deprecated(since = "0.1.0", note = "Use `system_call` instead")]
fn transact_system_call_finalize(
/// Transaction fields are reset and set in [`SystemCallTx`] and data and target are set to
/// given values.
///
/// Block values are taken into account and will determent how system call will be executed.
#[deprecated(since = "0.1.0", note = "Use `system_call_one_with_caller` instead")]
fn transact_system_call_with_caller(
&mut self,
caller: Address,
system_contract_address: Address,
data: Bytes,
) -> Result<ExecResultAndState<Self::ExecutionResult, Self::State>, Self::Error> {
self.system_call(system_contract_address, data)
) -> Result<Self::ExecutionResult, Self::Error> {
self.system_call_one_with_caller(caller, system_contract_address, data)
}

/// Calls [`SystemCallEvm::system_call_one`] and `finalize` functions.
fn system_call_with_caller(
/// Calls [`SystemCallEvm::system_call_one`] with [`SYSTEM_ADDRESS`] as a caller.
#[deprecated(since = "0.1.0", note = "Use `system_call_one` instead")]
fn transact_system_call(
&mut self,
system_contract_address: Address,
data: Bytes,
) -> Result<Self::ExecutionResult, Self::Error> {
self.system_call_one(system_contract_address, data)
}

/// Transact the system call and finalize.
///
/// Internally calls combo of `transact_system_call` and `finalize` functions.
#[deprecated(since = "0.1.0", note = "Use `system_call` instead")]
fn transact_system_call_finalize(
&mut self,
caller: Address,
system_contract_address: Address,
data: Bytes,
) -> Result<ExecResultAndState<Self::ExecutionResult, Self::State>, Self::Error> {
let result = self.system_call_one(caller, system_contract_address, data)?;
let state = self.finalize();
Ok(ExecResultAndState::new(result, state))
self.system_call(system_contract_address, data)
}

/// Calls [`SystemCallEvm::system_call_one`] and `finalize` functions.
Expand Down Expand Up @@ -210,7 +224,7 @@ where
INST: InstructionProvider<Context = CTX, InterpreterTypes = EthInterpreter>,
PRECOMPILES: PrecompileProvider<CTX, Output = InterpreterResult>,
{
fn system_call_one(
fn system_call_one_with_caller(
&mut self,
caller: Address,
system_contract_address: Address,
Expand Down
34 changes: 34 additions & 0 deletions crates/inspector/src/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,38 @@ pub trait InspectSystemCallEvm: InspectEvm + SystemCallEvm {
let state = self.finalize();
Ok(ExecResultAndState::new(output, state))
}

/// Inspect a system call with a given inspector and caller.
///
/// Similar to [`InspectEvm::inspect_one`] but for system calls.
fn inspect_one_system_call_with_inspector_and_caller(
&mut self,
caller: Address,
system_contract_address: Address,
data: Bytes,
inspector: Self::Inspector,
) -> Result<Self::ExecutionResult, Self::Error> {
self.set_inspector(inspector);
self.inspect_one_system_call_with_caller(caller, system_contract_address, data)
}

/// Inspect a system call with a given inspector and finalize the state.
///
/// Similar to [`InspectEvm::inspect`] but for system calls.
fn inspect_system_call_with_inspector_and_caller(
&mut self,
caller: Address,
system_contract_address: Address,
data: Bytes,
inspector: Self::Inspector,
) -> Result<ExecResultAndState<Self::ExecutionResult, Self::State>, Self::Error> {
let output = self.inspect_one_system_call_with_inspector_and_caller(
caller,
system_contract_address,
data,
inspector,
)?;
let state = self.finalize();
Ok(ExecResultAndState::new(output, state))
}
}
2 changes: 1 addition & 1 deletion crates/op-revm/src/api/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ where
CTX: OpContextTr<Tx: SystemCallTx> + ContextSetters,
PRECOMPILE: PrecompileProvider<CTX, Output = InterpreterResult>,
{
fn system_call_one(
fn system_call_one_with_caller(
&mut self,
caller: Address,
system_contract_address: Address,
Expand Down
Loading