Skip to content

Commit

Permalink
reuse revm-inspectors inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Sep 13, 2024
1 parent fc60e99 commit 1df373f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 48 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions crates/rpc/rpc-eth-api/src/helpers/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use reth_rpc_eth_types::{
apply_block_overrides, apply_state_overrides, caller_gas_allowance,
cap_tx_gas_limit_with_caller_allowance, get_precompiles, CallFees,
},
simulate::{self, EthSimulateError, TransferInspector},
simulate::{self, EthSimulateError},
EthApiError, RevertError, RpcInvalidTransactionError, StateCacheDb,
};
use reth_rpc_server_types::constants::gas_oracle::{
Expand All @@ -36,7 +36,7 @@ use reth_rpc_types::{
WithOtherFields,
};
use revm::{Database, DatabaseCommit, GetInspector};
use revm_inspectors::access_list::AccessListInspector;
use revm_inspectors::{access_list::AccessListInspector, transfer::TransferInspector};
use tracing::trace;

use super::{LoadBlock, LoadPendingBlock, LoadState, LoadTransaction, SpawnBlocking, Trace};
Expand Down Expand Up @@ -169,7 +169,11 @@ pub trait EthCall: Call + LoadPendingBlock {

let (res, env) = {
if trace_transfers {
this.transact_with_inspector(&mut db, env, TransferInspector)?
this.transact_with_inspector(
&mut db,
env,
TransferInspector::new(false).with_logs(true),
)?
} else {
this.transact(&mut db, env)?
}
Expand Down
43 changes: 2 additions & 41 deletions crates/rpc/rpc-eth-types/src/simulate.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Utilities for serving `eth_simulateV1`
use alloy_consensus::{TxEip4844Variant, TxType, TypedTransaction};
use alloy_sol_types::SolValue;
use jsonrpsee_types::ErrorObject;
use reth_primitives::{
BlockWithSenders, Signature, Transaction, TransactionSigned, TransactionSignedNoHash,
Expand All @@ -12,49 +11,11 @@ use reth_rpc_types::{
Block, BlockTransactionsKind, ToRpcError, TransactionRequest, WithOtherFields,
};
use reth_rpc_types_compat::block::from_block;
use revm::{interpreter::CallValue, Database, Inspector};
use revm_primitives::{
address, b256, Address, BlockEnv, Bytes, ExecutionResult, Log, LogData, TxKind, B256, U256,
};
use revm::Database;
use revm_primitives::{Address, BlockEnv, Bytes, ExecutionResult, TxKind, B256, U256};

use crate::{EthApiError, RevertError, RpcInvalidTransactionError};

/// Sender of ETH transfer log per `eth_simulateV1` spec.
///
/// <https://github.com/ethereum/execution-apis/pull/484>
pub const TRANSFER_LOG_EMITTER: Address = address!("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");

/// Topic of `Transfer(address,address,uint256)` event.
pub const TRANSFER_EVENT_TOPIC: B256 =
b256!("ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef");

/// Helper inspector for `eth_simulateV1` which injects `Transfer` logs for all ETH transfers.
#[derive(Debug, Default, Clone)]
pub struct TransferInspector;

impl<DB: Database> Inspector<DB> for TransferInspector {
fn call(
&mut self,
context: &mut revm::EvmContext<DB>,
inputs: &mut revm::interpreter::CallInputs,
) -> Option<revm::interpreter::CallOutcome> {
if let CallValue::Transfer(value) = inputs.value {
if !value.is_zero() {
let from = B256::from_slice(&inputs.caller.abi_encode());
let to = B256::from_slice(&inputs.target_address.abi_encode());
let data = value.abi_encode();

context.journaled_state.log(Log {
address: TRANSFER_LOG_EMITTER,
data: LogData::new_unchecked(vec![TRANSFER_EVENT_TOPIC, from, to], data.into()),
});
}
}

None
}
}

/// Errors which may occur during `eth_simulateV1` execution.
#[derive(Debug, thiserror::Error)]
pub enum EthSimulateError {
Expand Down
1 change: 1 addition & 0 deletions crates/rpc/rpc/src/otterscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ where
TransferKind::Create => OperationType::OpCreate,
TransferKind::Create2 => OperationType::OpCreate2,
TransferKind::SelfDestruct => OperationType::OpSelfDestruct,
TransferKind::EofCreate => OperationType::OpCreate,
},
})
.collect::<Vec<_>>()
Expand Down

0 comments on commit 1df373f

Please sign in to comment.