Skip to content
Merged
333 changes: 160 additions & 173 deletions Cargo.lock

Large diffs are not rendered by default.

25 changes: 18 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,13 @@ reth-trie-sparse = { path = "crates/trie/sparse", default-features = false }
reth-zstd-compressors = { version = "0.2.0", default-features = false }

# revm
revm = { version = "36.0.0", default-features = false }
revm-bytecode = { version = "9.0.0", default-features = false }
revm-database = { version = "12.0.0", default-features = false }
revm-state = { version = "10.0.0", default-features = false }
revm-primitives = { version = "22.1.0", default-features = false }
revm-interpreter = { version = "34.0.0", default-features = false }
revm-database-interface = { version = "10.0.0", default-features = false }
revm = { version = "37.0.0", default-features = false }
revm-bytecode = { version = "10.0.0", default-features = false }
revm-database = { version = "13.0.0", default-features = false }
revm-state = { version = "11.0.0", default-features = false }
revm-primitives = { version = "23.0.0", default-features = false }
revm-interpreter = { version = "35.0.0", default-features = false }
revm-database-interface = { version = "11.0.0", default-features = false }
revm-inspectors = "0.37.0"

# eth
Expand Down Expand Up @@ -698,3 +698,14 @@ vergen-git2 = "9.1.0"

# networking
ipnet = "2.11"

[patch.crates-io]
alloy-evm = { git = "https://github.com/alloy-rs/evm", rev = "0331f40e9deab54edb4fe548e1b627e0f2041721" }

revm-inspectors = { git = "https://github.com/paradigmxyz/revm-inspectors", rev = "bf531ab5d761f95572c34289405fd2d1f1045e60" }

# reth-core with revm v37 deps
reth-primitives-traits = { git = "https://github.com/paradigmxyz/reth-core", rev = "189f29d851766cef507ff947dd6e565800bc27ec" }
reth-codecs = { git = "https://github.com/paradigmxyz/reth-core", rev = "189f29d851766cef507ff947dd6e565800bc27ec" }
reth-codecs-derive = { git = "https://github.com/paradigmxyz/reth-core", rev = "189f29d851766cef507ff947dd6e565800bc27ec" }
reth-zstd-compressors = { git = "https://github.com/paradigmxyz/reth-core", rev = "189f29d851766cef507ff947dd6e565800bc27ec" }
7 changes: 5 additions & 2 deletions bin/reth-bb/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use alloy_eips::eip7685::Requests;
use alloy_evm::{
block::{
BlockExecutionError, BlockExecutionResult, BlockExecutor, BlockExecutorFactory,
BlockExecutorFor, ExecutableTx, OnStateHook, StateChangeSource, StateDB,
BlockExecutorFor, ExecutableTx, GasOutput, OnStateHook, StateChangeSource, StateDB,
},
eth::{EthBlockExecutionCtx, EthBlockExecutor, EthEvmContext, EthTxResult},
precompiles::PrecompilesMap,
Expand Down Expand Up @@ -386,7 +386,10 @@ where
self.inner_mut().execute_transaction_without_commit(tx)
}

fn commit_transaction(&mut self, output: Self::Result) -> Result<u64, BlockExecutionError> {
fn commit_transaction(
&mut self,
output: Self::Result,
) -> Result<GasOutput, BlockExecutionError> {
let gas_used = self.inner_mut().commit_transaction(output)?;

// Fix up cumulative_gas_used on the just-committed receipt so that
Expand Down
25 changes: 16 additions & 9 deletions crates/engine/tree/src/tree/precompile_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,21 @@ mod tests {
use super::*;
use reth_evm::{EthEvmFactory, Evm, EvmEnv, EvmFactory};
use reth_revm::db::EmptyDB;
use revm::{context::TxEnv, precompile::PrecompileOutput};
use revm::{
context::TxEnv,
precompile::{PrecompileOutput, PrecompileStatus},
};
use revm_primitives::hardfork::SpecId;

#[test]
fn test_precompile_cache_basic() {
let dyn_precompile: DynPrecompile = (|_input: PrecompileInput<'_>| -> PrecompileResult {
Ok(PrecompileOutput {
status: PrecompileStatus::Success,
gas_used: 0,
gas_refunded: 0,
state_gas_used: 0,
reservoir: 0,
bytes: Bytes::default(),
reverted: false,
})
})
.into();
Expand All @@ -247,10 +251,11 @@ mod tests {
CachedPrecompile::new(dyn_precompile, PrecompileCache::default(), SpecId::PRAGUE, None);

let output = PrecompileOutput {
status: PrecompileStatus::Success,
gas_used: 50,
gas_refunded: 0,
state_gas_used: 0,
reservoir: 0,
bytes: alloy_primitives::Bytes::copy_from_slice(b"cached_result"),
reverted: false,
};

let input = b"test_input";
Expand Down Expand Up @@ -279,10 +284,11 @@ mod tests {
assert_eq!(input.data, input_data);

Ok(PrecompileOutput {
status: PrecompileStatus::Success,
gas_used: 5000,
gas_refunded: 0,
state_gas_used: 0,
reservoir: 0,
bytes: alloy_primitives::Bytes::copy_from_slice(b"output_from_precompile_1"),
reverted: false,
})
}
})
Expand All @@ -294,10 +300,11 @@ mod tests {
assert_eq!(input.data, input_data);

Ok(PrecompileOutput {
status: PrecompileStatus::Success,
gas_used: 7000,
gas_refunded: 0,
state_gas_used: 0,
reservoir: 0,
bytes: alloy_primitives::Bytes::copy_from_slice(b"output_from_precompile_2"),
reverted: false,
})
}
})
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ where
self.executor.execute_transaction_with_commit_condition((tx_env, &tx), f)?
{
self.transactions.push(tx);
Ok(Some(gas_used))
Ok(Some(gas_used.tx_gas_used()))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is this right? i believe the only actual consumer of this output is here

let gas_used = match builder.execute_transaction(tx) {

and we might need to change it given Amsterdam changes how block gas limit is calculated?

} else {
Ok(None)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc/rpc-eth-api/src/helpers/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA

let result = this.inspect(&mut db, evm_env.clone(), tx_env.clone(), &mut inspector)?;
let access_list = inspector.into_access_list();
let gas_used = result.result.gas_used();
let gas_used = result.result.tx_gas_used();
tx_env.set_access_list(access_list.clone());
if let Err(err) = Self::Error::ensure_success(result.result) {
return Ok(AccessListResult {
Expand All @@ -529,7 +529,7 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA

// transact again to get the exact gas used
let result = this.transact(&mut db, evm_env, tx_env)?;
let gas_used = result.result.gas_used();
let gas_used = result.result.tx_gas_used();
let error = Self::Error::ensure_success(result.result).err().map(|e| e.to_string());

Ok(AccessListResult { access_list, gas_used: U256::from(gas_used), error })
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc/rpc-eth-api/src/helpers/estimate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ pub trait EstimateCall: Call {

// NOTE: this is the gas the transaction used, which is less than the
// transaction requires to succeed.
let mut gas_used = res.result.gas_used();
let mut gas_used = res.result.tx_gas_used();
// the lowest value is capped by the gas used by the unconstrained transaction
let mut lowest_gas_limit = gas_used.saturating_sub(1);

Expand All @@ -225,7 +225,7 @@ pub trait EstimateCall: Call {
res = evm.transact(optimistic_tx_env).map_err(Self::Error::from_evm_err)?;

// Update the gas used based on the new result.
gas_used = res.result.gas_used();
gas_used = res.result.tx_gas_used();
// Update the gas limit estimates (highest and lowest) based on the execution result.
update_estimated_gas_range(
res.result,
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-eth-types/src/error/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub trait FromEvmError<Evm: ConfigureEvm>:
ExecutionResult::Success { output, .. } => Ok(output.into_data()),
ExecutionResult::Revert { output, .. } => Err(Self::from_revert(output)),
ExecutionResult::Halt { reason, gas, .. } => {
Err(Self::from_evm_halt(reason, gas.used()))
Err(Self::from_evm_halt(reason, gas.tx_gas_used()))
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/rpc/rpc-eth-types/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ where
EVMError::Header(err) => err.into(),
EVMError::Database(err) => err.into(),
EVMError::Custom(err) => Self::EvmCustom(err),
EVMError::CustomAny(err) => Self::EvmCustom(err.to_string()),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/rpc/rpc-eth-types/src/simulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ where
code: SIMULATE_VM_ERROR_CODE,
..SimulateError::invalid_params()
}),
gas_used: gas.used(),
gas_used: gas.tx_gas_used(),
logs: Vec::new(),
status: false,
..Default::default()
Expand All @@ -329,7 +329,7 @@ where
code: SIMULATE_REVERT_CODE,
..SimulateError::invalid_params()
}),
gas_used: gas.used(),
gas_used: gas.tx_gas_used(),
status: false,
logs: Vec::new(),
..Default::default()
Expand All @@ -338,7 +338,7 @@ where
ExecutionResult::Success { output, gas, logs, .. } => SimCallResult {
return_data: output.into_data(),
error: None,
gas_used: gas.used(),
gas_used: gas.tx_gas_used(),
logs: logs
.into_iter()
.map(|log| {
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc/src/eth/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ where
let gas_price = tx
.effective_tip_per_gas(basefee)
.expect("fee is always valid; execution succeeded");
let gas_used = result.gas_used();
let gas_used = result.tx_gas_used();
total_gas_used += gas_used;

let gas_fees = U256::from(gas_used) * U256::from(gas_price);
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc/src/eth/sim_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ where
.into());
}

let gas_used = result.gas_used();
let gas_used = result.tx_gas_used();
total_gas_used += gas_used;

// coinbase is always present in the result state
Expand Down
2 changes: 1 addition & 1 deletion crates/transaction-pool/src/validate/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ pub fn ensure_intrinsic_gas<T: EthPoolTransaction>(
);

let gas_limit = transaction.gas_limit();
if gas_limit < gas.initial_gas || gas_limit < gas.floor_gas {
if gas_limit < gas.initial_total_gas || gas_limit < gas.floor_gas {
Err(InvalidPoolTransactionError::IntrinsicGasTooLow)
} else {
Ok(())
Expand Down
7 changes: 5 additions & 2 deletions examples/custom-beacon-withdrawals/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use alloy_eips::eip4895::Withdrawal;
use alloy_evm::{
block::{BlockExecutorFactory, BlockExecutorFor, ExecutableTx},
block::{BlockExecutorFactory, BlockExecutorFor, ExecutableTx, GasOutput},
eth::{EthBlockExecutionCtx, EthBlockExecutor, EthTxResult},
precompiles::PrecompilesMap,
revm::context::Block as _,
Expand Down Expand Up @@ -211,7 +211,10 @@ where
self.inner.execute_transaction_without_commit(tx)
}

fn commit_transaction(&mut self, output: Self::Result) -> Result<u64, BlockExecutionError> {
fn commit_transaction(
&mut self,
output: Self::Result,
) -> Result<GasOutput, BlockExecutionError> {
self.inner.commit_transaction(output)
}

Expand Down
4 changes: 2 additions & 2 deletions examples/custom-evm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use reth_ethereum::{
context_interface::result::{EVMError, HaltReason},
inspector::{Inspector, NoOpInspector},
interpreter::interpreter::EthInterpreter,
precompile::{PrecompileOutput, PrecompileResult, Precompiles},
precompile::{PrecompileOutput, Precompiles},
primitives::hardfork::SpecId,
MainBuilder, MainContext,
},
Expand Down Expand Up @@ -110,7 +110,7 @@ pub fn prague_custom() -> &'static Precompiles {
let precompile = Precompile::new(
PrecompileId::custom("custom"),
address!("0x0000000000000000000000000000000000000999"),
|_, _| PrecompileResult::Ok(PrecompileOutput::new(0, Bytes::new())),
|_, _, _| Ok(PrecompileOutput::new(0, Bytes::new(), 0)),
);
precompiles.extend([precompile]);
precompiles
Expand Down
Loading