Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into fred
Browse files Browse the repository at this point in the history
  • Loading branch information
rakita committed Dec 31, 2024
2 parents bd07bb6 + d2a3b5b commit ebb9cd2
Show file tree
Hide file tree
Showing 44 changed files with 989 additions and 195 deletions.
120 changes: 111 additions & 9 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ members = [
"examples/database_components",
"examples/uniswap_get_reserves",
"examples/uniswap_v2_usdc_swap",
"examples/erc20_gas",
#"examples/custom_opcodes",
]
resolver = "2"
Expand Down
13 changes: 9 additions & 4 deletions bins/revme/src/cmd/statetest/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,16 @@ pub fn execute_test_suite(
cfg.chain_id = 1;

// Block env
block.number = unit.env.current_number;
block.number = unit.env.current_number.try_into().unwrap_or(u64::MAX);
block.beneficiary = unit.env.current_coinbase;
block.timestamp = unit.env.current_timestamp;
block.gas_limit = unit.env.current_gas_limit;
block.basefee = unit.env.current_base_fee.unwrap_or_default();
block.timestamp = unit.env.current_timestamp.try_into().unwrap_or(u64::MAX);
block.gas_limit = unit.env.current_gas_limit.try_into().unwrap_or(u64::MAX);
block.basefee = unit
.env
.current_base_fee
.unwrap_or_default()
.try_into()
.unwrap_or(u64::MAX);
block.difficulty = unit.env.current_difficulty;
// After the Merge prevrandao replaces mix_hash field in block and replaced difficulty opcode in EVM.
block.prevrandao = unit.env.current_random;
Expand Down
16 changes: 8 additions & 8 deletions crates/context/interface/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ use std::boxed::Box;
#[auto_impl(&, &mut, Box, Arc)]
pub trait Block {
/// The number of ancestor blocks of this block (block height).
fn number(&self) -> &U256;
fn number(&self) -> u64;

/// Beneficiary (Coinbase, miner) is a address that have signed the block.
///
/// This is the receiver address of priority gas rewards.
fn beneficiary(&self) -> &Address;
fn beneficiary(&self) -> Address;

/// The timestamp of the block in seconds since the UNIX epoch.
fn timestamp(&self) -> &U256;
fn timestamp(&self) -> u64;

/// The gas limit of the block.
fn gas_limit(&self) -> &U256;
fn gas_limit(&self) -> u64;

/// The base fee per gas, added in the London upgrade with [EIP-1559].
///
/// [EIP-1559]: https://eips.ethereum.org/EIPS/eip-1559
fn basefee(&self) -> &U256;
fn basefee(&self) -> u64;

/// The difficulty of the block.
///
/// Unused after the Paris (AKA the merge) upgrade, and replaced by `prevrandao`.
fn difficulty(&self) -> &U256;
fn difficulty(&self) -> U256;

/// The output of the randomness beacon provided by the beacon chain.
///
Expand All @@ -40,7 +40,7 @@ pub trait Block {
/// Note: `prevrandao` can be found in a block in place of `mix_hash`.
///
/// [EIP-4399]: https://eips.ethereum.org/EIPS/eip-4399
fn prevrandao(&self) -> Option<&B256>;
fn prevrandao(&self) -> Option<B256>;

/// Excess blob gas and blob gasprice.
/// See also [`calc_excess_blob_gas`]
Expand All @@ -49,7 +49,7 @@ pub trait Block {
/// Incorporated as part of the Cancun upgrade via [EIP-4844].
///
/// [EIP-4844]: https://eips.ethereum.org/EIPS/eip-4844
fn blob_excess_gas_and_price(&self) -> Option<&BlobExcessGasAndPrice>;
fn blob_excess_gas_and_price(&self) -> Option<BlobExcessGasAndPrice>;

/// See [EIP-4844] and [`calc_blob_gasprice`].
///
Expand Down
2 changes: 1 addition & 1 deletion crates/context/interface/src/block/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use specification::eip4844::{
/// Incorporated as part of the Cancun upgrade via [EIP-4844].
///
/// [EIP-4844]: https://eips.ethereum.org/EIPS/eip-4844
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BlobExcessGasAndPrice {
/// The excess blob gas of the block
Expand Down
10 changes: 7 additions & 3 deletions crates/context/interface/src/journaled_state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::ops::{Deref, DerefMut};
use database_interface::{Database, DatabaseGetter};
use primitives::{Address, Log, B256, U256};
use primitives::{Address, HashSet, Log, B256, U256};
use specification::hardfork::SpecId;
use state::{Account, Bytecode};
use std::boxed::Box;
Expand All @@ -17,10 +17,10 @@ pub trait Journal {
fn new(database: Self::Database) -> Self;

/// Returns the database.
fn db(&self) -> &Self::Database;
fn db_ref(&self) -> &Self::Database;

/// Returns the mutable database.
fn db_mut(&mut self) -> &mut Self::Database;
fn db(&mut self) -> &mut Self::Database;

/// Returns the storage value from Journal state.
///
Expand Down Expand Up @@ -63,6 +63,10 @@ pub trait Journal {

fn warm_account(&mut self, address: Address);

fn warm_precompiles(&mut self, addresses: HashSet<Address>);

fn precompile_addresses(&self) -> &HashSet<Address>;

fn set_spec_id(&mut self, spec_id: SpecId);

fn touch_account(&mut self, address: Address);
Expand Down
13 changes: 11 additions & 2 deletions crates/context/interface/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ impl<HaltReasonT: HaltReasonTrait> ExecutionResult<HaltReasonT> {
matches!(self, Self::Success { .. })
}

/// Returns created address if execution is Create transaction
/// and Contract was created.
pub fn created_address(&self) -> Option<Address> {
match self {
Self::Success { output, .. } => output.address().cloned(),
_ => None,
}
}

/// Returns true if execution result is a Halt.
pub fn is_halt(&self) -> bool {
matches!(self, Self::Halt { .. })
Expand Down Expand Up @@ -175,9 +184,9 @@ impl<DB, TX> FromStringError for EVMError<DB, TX> {
}
}

impl<DB, TXERROR: From<InvalidTransaction>> From<InvalidTransaction> for EVMError<DB, TXERROR> {
impl<DB> From<InvalidTransaction> for EVMError<DB, InvalidTransaction> {
fn from(value: InvalidTransaction) -> Self {
Self::Transaction(value.into())
Self::Transaction(value)
}
}

Expand Down
Loading

0 comments on commit ebb9cd2

Please sign in to comment.