Skip to content

Commit

Permalink
chore(deps): bump revm 11 (#9391)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Jul 9, 2024
1 parent 05ad783 commit b97ace2
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 75 deletions.
24 changes: 13 additions & 11 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,15 @@ reth-trie-common = { path = "crates/trie/common" }
reth-trie-parallel = { path = "crates/trie/parallel" }

# revm
revm = { version = "10.0.0", features = [
revm = { version = "11.0.0", features = [
"std",
"secp256k1",
"blst",
], default-features = false }
revm-primitives = { version = "5.0.0", features = [
revm-primitives = { version = "6.0.0", features = [
"std",
], default-features = false }
revm-inspectors = "0.1"
revm-inspectors = "0.4"

# eth
alloy-chains = "0.1.15"
Expand Down
1 change: 1 addition & 0 deletions crates/optimism/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl ConfigureEvmEnv for OptimismEvmConfig {
// blob fields can be None for this tx
blob_hashes: Vec::new(),
max_fee_per_blob_gas: None,
authorization_list: None,
optimism: OptimismFields {
source_hash: None,
mint: None,
Expand Down
6 changes: 3 additions & 3 deletions crates/payload/builder/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use std::{
pub struct CachedReads {
accounts: HashMap<Address, CachedAccount>,
contracts: HashMap<B256, Bytecode>,
block_hashes: HashMap<U256, B256>,
block_hashes: HashMap<u64, B256>,
}

// === impl CachedReads ===
Expand Down Expand Up @@ -114,7 +114,7 @@ impl<'a, DB: DatabaseRef> Database for CachedReadsDbMut<'a, DB> {
}
}

fn block_hash(&mut self, number: U256) -> Result<B256, Self::Error> {
fn block_hash(&mut self, number: u64) -> Result<B256, Self::Error> {
let code = match self.cached.block_hashes.entry(number) {
Entry::Occupied(entry) => *entry.get(),
Entry::Vacant(entry) => *entry.insert(self.db.block_hash_ref(number)?),
Expand Down Expand Up @@ -148,7 +148,7 @@ impl<'a, DB: DatabaseRef> DatabaseRef for CachedReadsDBRef<'a, DB> {
self.inner.borrow_mut().storage(address, index)
}

fn block_hash_ref(&self, number: U256) -> Result<B256, Self::Error> {
fn block_hash_ref(&self, number: u64) -> Result<B256, Self::Error> {
self.inner.borrow_mut().block_hash(number)
}
}
Expand Down
33 changes: 3 additions & 30 deletions crates/primitives/src/transaction/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,7 @@ impl FillTxEnv for TransactionSigned {
tx_env.data = tx.input.clone();
tx_env.chain_id = Some(tx.chain_id);
tx_env.nonce = Some(tx.nonce);
tx_env.access_list = tx
.access_list
.iter()
.map(|l| {
(
l.address,
l.storage_keys.iter().map(|k| U256::from_be_bytes(k.0)).collect(),
)
})
.collect();
tx_env.access_list = tx.access_list.0.clone();
tx_env.blob_hashes.clear();
tx_env.max_fee_per_blob_gas.take();
}
Expand All @@ -62,16 +53,7 @@ impl FillTxEnv for TransactionSigned {
tx_env.data = tx.input.clone();
tx_env.chain_id = Some(tx.chain_id);
tx_env.nonce = Some(tx.nonce);
tx_env.access_list = tx
.access_list
.iter()
.map(|l| {
(
l.address,
l.storage_keys.iter().map(|k| U256::from_be_bytes(k.0)).collect(),
)
})
.collect();
tx_env.access_list = tx.access_list.0.clone();
tx_env.blob_hashes.clear();
tx_env.max_fee_per_blob_gas.take();
}
Expand All @@ -84,16 +66,7 @@ impl FillTxEnv for TransactionSigned {
tx_env.data = tx.input.clone();
tx_env.chain_id = Some(tx.chain_id);
tx_env.nonce = Some(tx.nonce);
tx_env.access_list = tx
.access_list
.iter()
.map(|l| {
(
l.address,
l.storage_keys.iter().map(|k| U256::from_be_bytes(k.0)).collect(),
)
})
.collect();
tx_env.access_list = tx.access_list.0.clone();
tx_env.blob_hashes.clone_from(&tx.blob_versioned_hashes);
tx_env.max_fee_per_blob_gas = Some(U256::from(tx.max_fee_per_blob_gas));
}
Expand Down
9 changes: 3 additions & 6 deletions crates/revm/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl<DB: EvmStateProvider> Database for StateProviderDatabase<DB> {
///
/// Returns `Ok` with the block hash if found, or the default hash otherwise.
/// Note: It safely casts the `number` to `u64`.
fn block_hash(&mut self, number: U256) -> Result<B256, Self::Error> {
fn block_hash(&mut self, number: u64) -> Result<B256, Self::Error> {
DatabaseRef::block_hash_ref(self, number)
}
}
Expand Down Expand Up @@ -154,11 +154,8 @@ impl<DB: EvmStateProvider> DatabaseRef for StateProviderDatabase<DB> {
/// Retrieves the block hash for a given block number.
///
/// Returns `Ok` with the block hash if found, or the default hash otherwise.
fn block_hash_ref(&self, number: U256) -> Result<B256, Self::Error> {
fn block_hash_ref(&self, number: u64) -> Result<B256, Self::Error> {
// Get the block hash or default hash with an attempt to convert U256 block number to u64
Ok(self
.0
.block_hash(number.try_into().map_err(|_| Self::Error::BlockNumberOverflow(number))?)?
.unwrap_or_default())
Ok(self.0.block_hash(number)?.unwrap_or_default())
}
}
2 changes: 1 addition & 1 deletion crates/rpc/rpc-eth-api/src/helpers/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ pub trait Call: LoadState + SpawnBlocking {
}
ExecutionResult::Halt { reason, .. } => {
match reason {
HaltReason::OutOfGas(_) | HaltReason::InvalidEFOpcode => {
HaltReason::OutOfGas(_) | HaltReason::InvalidFEOpcode => {
// Both `OutOfGas` and `InvalidEFOpcode` can occur dynamically if the gas
// left is too low. Treat this as an out of gas
// condition, knowing that the call succeeds with a
Expand Down
16 changes: 8 additions & 8 deletions crates/rpc/rpc-eth-types/src/cache/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ impl<'a, 'b> Database for StateCacheDbRefMutWrapper<'a, 'b> {
self.0.basic(address)
}

fn block_hash(&mut self, number: U256) -> Result<B256, Self::Error> {
self.0.block_hash(number)
}

fn code_by_hash(&mut self, code_hash: B256) -> Result<revm_primitives::Bytecode, Self::Error> {
self.0.code_by_hash(code_hash)
}
Expand All @@ -142,6 +138,10 @@ impl<'a, 'b> Database for StateCacheDbRefMutWrapper<'a, 'b> {
) -> Result<U256, Self::Error> {
self.0.storage(address, index)
}

fn block_hash(&mut self, number: u64) -> Result<B256, Self::Error> {
self.0.block_hash(number)
}
}

impl<'a, 'b> DatabaseRef for StateCacheDbRefMutWrapper<'a, 'b> {
Expand All @@ -154,10 +154,6 @@ impl<'a, 'b> DatabaseRef for StateCacheDbRefMutWrapper<'a, 'b> {
self.0.basic_ref(address)
}

fn block_hash_ref(&self, number: U256) -> Result<B256, Self::Error> {
self.0.block_hash_ref(number)
}

fn code_by_hash_ref(&self, code_hash: B256) -> Result<revm_primitives::Bytecode, Self::Error> {
self.0.code_by_hash_ref(code_hash)
}
Expand All @@ -169,4 +165,8 @@ impl<'a, 'b> DatabaseRef for StateCacheDbRefMutWrapper<'a, 'b> {
) -> Result<U256, Self::Error> {
self.0.storage_ref(address, index)
}

fn block_hash_ref(&self, number: u64) -> Result<B256, Self::Error> {
self.0.block_hash_ref(number)
}
}
18 changes: 16 additions & 2 deletions crates/rpc/rpc-eth-types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,15 @@ pub enum RpcInvalidTransactionError {
/// Blob transaction is a create transaction
#[error("blob transaction is a create transaction")]
BlobTransactionIsCreate,
/// EOF crate should have `to` address
#[error("EOF crate should have `to` address")]
EofCrateShouldHaveToAddress,
/// EIP-7702 is not enabled.
#[error("EIP-7702 authorization list not supported")]
AuthorizationListNotSupported,
/// EIP-7702 transaction has invalid fields set.
#[error("EIP-7702 authorization list has invalid fields")]
AuthorizationListInvalidFields,
/// Optimism related error
#[error(transparent)]
#[cfg(feature = "optimism")]
Expand Down Expand Up @@ -454,6 +463,13 @@ impl From<revm::primitives::InvalidTransaction> for RpcInvalidTransactionError {
InvalidTransaction::BlobVersionNotSupported => Self::BlobHashVersionMismatch,
InvalidTransaction::TooManyBlobs { max, have } => Self::TooManyBlobs { max, have },
InvalidTransaction::BlobCreateTransaction => Self::BlobTransactionIsCreate,
InvalidTransaction::EofCrateShouldHaveToAddress => Self::EofCrateShouldHaveToAddress,
InvalidTransaction::AuthorizationListNotSupported => {
Self::AuthorizationListNotSupported
}
InvalidTransaction::AuthorizationListInvalidFields => {
Self::AuthorizationListInvalidFields
}
#[cfg(feature = "optimism")]
InvalidTransaction::DepositSystemTxPostRegolith => {
Self::Optimism(OptimismInvalidTransactionError::DepositSystemTxPostRegolith)
Expand All @@ -462,8 +478,6 @@ impl From<revm::primitives::InvalidTransaction> for RpcInvalidTransactionError {
InvalidTransaction::HaltedDepositPostRegolith => {
Self::Optimism(OptimismInvalidTransactionError::HaltedDepositPostRegolith)
}
// TODO(EOF)
InvalidTransaction::EofCrateShouldHaveToAddress => todo!("EOF"),
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions crates/rpc/rpc-eth-types/src/revm_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,11 @@ pub fn create_txn_env(block_env: &BlockEnv, request: TransactionRequest) -> EthR
value: value.unwrap_or_default(),
data: input.try_into_unique_input()?.unwrap_or_default(),
chain_id,
access_list: access_list
.map(reth_rpc_types::AccessList::into_flattened)
.unwrap_or_default(),
access_list: access_list.unwrap_or_default().into(),
// EIP-4844 fields
blob_hashes: blob_versioned_hashes.unwrap_or_default(),
max_fee_per_blob_gas,
authorization_list: None,
#[cfg(feature = "optimism")]
optimism: OptimismFields { enveloped_tx: Some(Bytes::new()), ..Default::default() },
};
Expand Down
13 changes: 6 additions & 7 deletions crates/transaction-pool/src/validate/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ use crate::{
use reth_chainspec::{ChainSpec, EthereumHardforks};
use reth_primitives::{
constants::{eip4844::MAX_BLOBS_PER_BLOCK, ETHEREUM_BLOCK_GAS_LIMIT},
Address, GotExpected, InvalidTransactionError, SealedBlock, TxKind, EIP1559_TX_TYPE_ID,
EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID, LEGACY_TX_TYPE_ID, U256,
GotExpected, InvalidTransactionError, SealedBlock, TxKind, EIP1559_TX_TYPE_ID,
EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID, LEGACY_TX_TYPE_ID,
};
use reth_provider::{AccountReader, BlockReaderIdExt, StateProviderFactory};
use reth_tasks::TaskSpawner;
use revm::{
interpreter::gas::validate_initial_tx_gas,
primitives::{EnvKzgSettings, SpecId},
primitives::{AccessListItem, EnvKzgSettings, SpecId},
};
use std::{
marker::PhantomData,
Expand Down Expand Up @@ -712,12 +712,11 @@ pub fn ensure_intrinsic_gas<T: PoolTransaction>(
transaction: &T,
is_shanghai: bool,
) -> Result<(), InvalidPoolTransactionError> {
let access_list = transaction.access_list().map(|list| list.flattened()).unwrap_or_default();
if transaction.gas_limit() <
calculate_intrinsic_gas_after_merge(
transaction.input(),
&transaction.kind(),
&access_list,
transaction.access_list().map(|list| list.0.as_slice()).unwrap_or(&[]),
is_shanghai,
)
{
Expand All @@ -734,11 +733,11 @@ pub fn ensure_intrinsic_gas<T: PoolTransaction>(
pub fn calculate_intrinsic_gas_after_merge(
input: &[u8],
kind: &TxKind,
access_list: &[(Address, Vec<U256>)],
access_list: &[AccessListItem],
is_shanghai: bool,
) -> u64 {
let spec_id = if is_shanghai { SpecId::SHANGHAI } else { SpecId::MERGE };
validate_initial_tx_gas(spec_id, input, kind.is_create(), access_list)
validate_initial_tx_gas(spec_id, input, kind.is_create(), access_list, 0)
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion examples/exex/rollup/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ impl reth_revm::Database for Database {
get_storage(&self.connection(), address, index.into()).map(|data| data.unwrap_or_default())
}

fn block_hash(&mut self, number: U256) -> Result<B256, Self::Error> {
fn block_hash(&mut self, number: u64) -> Result<B256, Self::Error> {
let block_hash = self.connection().query_row::<String, _, _>(
"SELECT hash FROM block WHERE number = ?",
(number.to_string(),),
Expand Down

0 comments on commit b97ace2

Please sign in to comment.