Skip to content

Commit

Permalink
chore: bump revm + accomodate cancun struct changes (#5858)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evalir authored Sep 20, 2023
1 parent ad37842 commit aeefc74
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 4 deletions.
118 changes: 114 additions & 4 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions crates/anvil/core/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,7 @@ impl PendingTransaction {
gas_priority_fee: None,
gas_limit: gas_limit.as_u64(),
access_list: vec![],
..Default::default()
}
}
TypedTransaction::EIP2930(tx) => {
Expand All @@ -1234,6 +1235,7 @@ impl PendingTransaction {
gas_priority_fee: None,
gas_limit: gas_limit.as_u64(),
access_list: to_revm_access_list(access_list.0.clone()),
..Default::default()
}
}
TypedTransaction::EIP1559(tx) => {
Expand All @@ -1260,6 +1262,7 @@ impl PendingTransaction {
gas_priority_fee: Some(u256_to_ru256(*max_priority_fee_per_gas)),
gas_limit: gas_limit.as_u64(),
access_list: to_revm_access_list(access_list.0.clone()),
..Default::default()
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/anvil/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ latest block number: {latest_block}"
// Keep previous `coinbase` and `basefee` value
coinbase: env.block.coinbase,
basefee: env.block.basefee,
..Default::default()
};

// apply changes such as difficulty -> prevrandao
Expand Down
5 changes: 5 additions & 0 deletions crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ impl Backend {
// Keep previous `coinbase` and `basefee` value
coinbase: env.block.coinbase,
basefee: env.block.basefee,
..Default::default()
};

self.time.reset(ru256_to_u256(env.block.timestamp).as_u64());
Expand Down Expand Up @@ -1035,6 +1036,7 @@ impl Backend {
chain_id: None,
nonce: nonce.map(|n| n.as_u64()),
access_list: to_revm_access_list(access_list.unwrap_or_default()),
..Default::default()
};

if env.block.basefee == revm::primitives::U256::ZERO {
Expand Down Expand Up @@ -1068,6 +1070,7 @@ impl Backend {
}
EVMError::PrevrandaoNotSet => return Err(BlockchainError::PrevrandaoNotSet),
EVMError::Database(e) => return Err(BlockchainError::DatabaseError(e)),
EVMError::ExcessBlobGasNotSet => return Err(BlockchainError::ExcessBlobGasNotSet),
},
};
let state = result_and_state.state;
Expand Down Expand Up @@ -1594,6 +1597,7 @@ impl Backend {
block.header.base_fee_per_gas.unwrap_or_default(),
),
gas_limit: u256_to_ru256(block.header.gas_limit),
..Default::default()
};
f(state, block)
})
Expand Down Expand Up @@ -1621,6 +1625,7 @@ impl Backend {
prevrandao: Some(block.header.mix_hash).map(h256_to_b256),
basefee: u256_to_ru256(block.header.base_fee_per_gas.unwrap_or_default()),
gas_limit: u256_to_ru256(block.header.gas_limit),
..Default::default()
};
return Ok(f(Box::new(state), block))
}
Expand Down
26 changes: 26 additions & 0 deletions crates/anvil/src/eth/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ pub enum BlockchainError {
EIP1559TransactionUnsupportedAtHardfork,
#[error("Access list received but is not supported by the current hardfork.\n\nYou can use it by running anvil with '--hardfork berlin' or later.")]
EIP2930TransactionUnsupportedAtHardfork,
#[error("Excess blob gas not set.")]
ExcessBlobGasNotSet,
}

impl From<RpcError> for BlockchainError {
Expand All @@ -98,6 +100,7 @@ where
EVMError::Transaction(err) => InvalidTransactionError::from(err).into(),
EVMError::PrevrandaoNotSet => BlockchainError::PrevrandaoNotSet,
EVMError::Database(err) => err.into(),
EVMError::ExcessBlobGasNotSet => BlockchainError::ExcessBlobGasNotSet,
}
}
}
Expand Down Expand Up @@ -184,6 +187,17 @@ pub enum InvalidTransactionError {
/// Thrown when an access list is used before the berlin hard fork.
#[error("Access lists are not supported before the Berlin hardfork")]
AccessListNotSupported,
/// Thrown when the block's `blob_gas_price` is greater than tx-specified
/// `max_fee_per_blob_gas` after Cancun.
#[error("Block `blob_gas_price` is greater than tx-specified `max_fee_per_blob_gas`")]
BlobGasPriceGreaterThanMax,
/// Thrown when we receive a tx with `blob_versioned_hashes` and we're not on the Cancun hard
/// fork.
#[error("Block `blob_versioned_hashes` is not supported before the Cancun hardfork")]
BlobVersionedHashesNotSupported,
/// Thrown when `max_fee_per_blob_gas` is not supported for blocks before the Cancun hardfork.
#[error("`max_fee_per_blob_gas` is not supported for blocks before the Cancun hardfork.")]
MaxFeePerBlobGasNotSupported,
}

impl From<revm::primitives::InvalidTransaction> for InvalidTransactionError {
Expand Down Expand Up @@ -223,6 +237,15 @@ impl From<revm::primitives::InvalidTransaction> for InvalidTransactionError {
InvalidTransaction::AccessListNotSupported => {
InvalidTransactionError::AccessListNotSupported
}
InvalidTransaction::BlobGasPriceGreaterThanMax => {
InvalidTransactionError::BlobGasPriceGreaterThanMax
}
InvalidTransaction::BlobVersionedHashesNotSupported => {
InvalidTransactionError::BlobVersionedHashesNotSupported
}
InvalidTransaction::MaxFeePerBlobGasNotSupported => {
InvalidTransactionError::MaxFeePerBlobGasNotSupported
}
}
}
}
Expand Down Expand Up @@ -374,6 +397,9 @@ impl<T: Serialize> ToRpcResponseResult for Result<T> {
err @ BlockchainError::EIP2930TransactionUnsupportedAtHardfork => {
RpcError::invalid_params(err.to_string())
}
err @ BlockchainError::ExcessBlobGasNotSet => {
RpcError::invalid_params(err.to_string())
}
}
.into(),
}
Expand Down
1 change: 1 addition & 0 deletions crates/evm/src/executor/fork/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ where
prevrandao: Some(block.mix_hash.map(h256_to_b256).unwrap_or_default()),
basefee: u256_to_ru256(block.base_fee_per_gas.unwrap_or_default()),
gas_limit: u256_to_ru256(block.gas_limit),
..Default::default()
},
tx: TxEnv {
caller: origin,
Expand Down
1 change: 1 addition & 0 deletions crates/evm/src/executor/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ impl EvmOpts {
prevrandao: Some(self.env.block_prevrandao),
basefee: U256::from(self.env.block_base_fee_per_gas),
gas_limit: self.gas_limit(),
..Default::default()
},
cfg,
tx: TxEnv {
Expand Down

0 comments on commit aeefc74

Please sign in to comment.