Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
645 changes: 352 additions & 293 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 11 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ alloy-sol-types = { version = "0.8.2", default-features = false }
alloy-eip2930 = { version = "0.1.0", default-features = false }
alloy-eip7702 = { version = "0.5.0", default-features = false }

alloy-consensus = { version = "0.9.2", default-features = false }
alloy-eips = { version = "0.9.2", default-features = false }
alloy-provider = { version = "0.9.2", default-features = false }
alloy-signer = { version = "0.9.2", default-features = false }
alloy-signer-local = { version = "0.9.2", default-features = false }
alloy-transport = { version = "0.9.2", default-features = false }
alloy-transport-http = { version = "0.9.2", default-features = false }
alloy-consensus = { version = "0.11.1", default-features = false }
alloy-eips = { version = "0.11.1", default-features = false }
alloy-provider = { version = "0.11.1", default-features = false }
alloy-signer = { version = "0.11.1", default-features = false }
alloy-signer-local = { version = "0.11.1", default-features = false }
alloy-transport = { version = "0.11.1", default-features = false }
alloy-transport-http = { version = "0.11.1", default-features = false }

# misc
aurora-engine-modexp = { version = "1.1", default-features = false }
Expand All @@ -77,11 +77,10 @@ bitflags = { version = "2.6.0", default-features = false }
bitvec = { version = "1", default-features = false }
blst = "0.3.13"
bn = { package = "substrate-bn", version = "0.6", default-features = false }
c-kzg = { version = "1.0.3", default-features = false }
c-kzg = { version = "1.0.0", default-features = false }
cfg-if = { version = "1.0", default-features = false }
clap = "4"
criterion = { package = "codspeed-criterion-compat", version = "2.7" }
derive_more = { version = "1.0.0", default-features = false }
derive-where = { version = "1.2.7", default-features = false }
enumn = "0.1"
k256 = { version = "0.13.3", default-features = false }
Expand All @@ -94,7 +93,7 @@ phf = { version = "0.11", default-features = false }
rand = "0.8"
reqwest = "0.12"
ripemd = { version = "0.1", default-features = false }
secp256k1 = { version = "0.29", default-features = false }
secp256k1 = { version = "0.30", default-features = false }
serde = { version = "1.0", default-features = false }
serde_json = { version = "1.0", default-features = false }
sha2 = { version = "0.10", default-features = false }
Expand All @@ -105,13 +104,12 @@ anyhow = "1.0.89"
bincode = "1.3"
eyre = "0.6.12"
hash-db = "0.15"
hashbrown = "0.14"
indicatif = "0.17"
microbench = "0.5"
plain_hasher = "0.2"
rstest = "0.23.0"
rstest = "0.24.0"
serde_derive = "1.0"
thiserror = "1.0"
thiserror = "2.0"
triehash = "0.8"
walkdir = "2.5"

Expand Down
1 change: 0 additions & 1 deletion bins/revme/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ alloy-sol-types.workspace = true

# misc
hash-db.workspace = true
hashbrown.workspace = true
indicatif.workspace = true
microbench.workspace = true
plain_hasher.workspace = true
Expand Down
10 changes: 5 additions & 5 deletions crates/database/src/alloydb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use alloy_provider::{
},
Network, Provider,
};
use alloy_transport::{Transport, TransportError};
use alloy_transport::TransportError;
use core::error::Error;
use database_interface::{async_db::DatabaseAsyncRef, DBErrorMarker};
use primitives::{Address, B256, U256};
Expand Down Expand Up @@ -36,15 +36,15 @@ impl From<TransportError> for DBTransportError {
///
/// When accessing the database, it'll use the given provider to fetch the corresponding account's data.
#[derive(Debug)]
pub struct AlloyDB<T: Transport + Clone, N: Network, P: Provider<T, N>> {
pub struct AlloyDB<N: Network, P: Provider<N>> {
/// The provider to fetch the data from.
provider: P,
/// The block number on which the queries will be based on.
block_number: BlockId,
_marker: core::marker::PhantomData<fn() -> (T, N)>,
_marker: core::marker::PhantomData<fn() -> N>,
}

impl<T: Transport + Clone, N: Network, P: Provider<T, N>> AlloyDB<T, N, P> {
impl<N: Network, P: Provider<N>> AlloyDB<N, P> {
/// Creates a new AlloyDB instance, with a [Provider] and a block.
pub fn new(provider: P, block_number: BlockId) -> Self {
Self {
Expand All @@ -60,7 +60,7 @@ impl<T: Transport + Clone, N: Network, P: Provider<T, N>> AlloyDB<T, N, P> {
}
}

impl<T: Transport + Clone, N: Network, P: Provider<T, N>> DatabaseAsyncRef for AlloyDB<T, N, P> {
impl<N: Network, P: Provider<N>> DatabaseAsyncRef for AlloyDB<N, P> {
type Error = DBTransportError;

async fn basic_async_ref(&self, address: Address) -> Result<Option<AccountInfo>, Self::Error> {
Expand Down
2 changes: 1 addition & 1 deletion crates/precompile/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn benchmark_crypto_precompiles(c: &mut Criterion) {
let message = Message::from_digest_slice(&hash[..]).unwrap();
let s = SECP256K1.sign_ecdsa_recoverable(&message, &secret_key);
let (rec_id, data) = s.serialize_compact();
let rec_id = rec_id.to_i32() as u8 + 27;
let rec_id = i32::from(rec_id) as u8 + 27;

let mut message_and_signature = [0u8; 128];
message_and_signature[0..32].copy_from_slice(&hash[..]);
Expand Down
2 changes: 1 addition & 1 deletion crates/precompile/src/secp256k1/bitcoin_secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use secp256k1::{
use k256 as _;

pub fn ecrecover(sig: &B512, recid: u8, msg: &B256) -> Result<B256, secp256k1::Error> {
let recid = RecoveryId::from_i32(recid as i32).expect("recovery ID is valid");
let recid = RecoveryId::try_from(recid as i32).expect("recovery ID is valid");
let sig = RecoverableSignature::from_compact(sig.as_slice(), recid)?;

let msg = Message::from_digest(msg.0);
Expand Down
2 changes: 1 addition & 1 deletion examples/database_components/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ revm.workspace = true

# misc
auto_impl.workspace = true
derive_more.workspace = true
thiserror.workspace = true
8 changes: 3 additions & 5 deletions examples/database_components/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ pub mod state;
pub use block_hash::{BlockHash, BlockHashRef};
pub use state::{State, StateRef};

use core::{error::Error as StdError, fmt::Debug};
use derive_more::Display;
use revm::{
database_interface::{DBErrorMarker, Database, DatabaseCommit, DatabaseRef},
primitives::{Address, HashMap, B256, U256},
Expand All @@ -22,14 +20,14 @@ pub struct DatabaseComponents<S, BH> {
pub block_hash: BH,
}

#[derive(Debug, Display)]
#[derive(Debug, thiserror::Error)]
pub enum DatabaseComponentError<SE, BHE> {
#[error(transparent)]
State(SE),
#[error(transparent)]
BlockHash(BHE),
}

impl<SE: Debug + Display, BHE: Debug + Display> StdError for DatabaseComponentError<SE, BHE> {}

impl<SE, BHE> DBErrorMarker for DatabaseComponentError<SE, BHE> {}

impl<S: State, BH: BlockHash> Database for DatabaseComponents<S, BH> {
Expand Down
2 changes: 0 additions & 2 deletions examples/erc20_gas/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,5 @@ tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }

# alloy
alloy-sol-types = { workspace = true, features = ["std"] }
alloy-transport-http.workspace = true
alloy-provider = { workspace = true, default-features = true }
reqwest.workspace = true
anyhow.workspace = true
18 changes: 7 additions & 11 deletions examples/erc20_gas/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

#![cfg_attr(not(test), warn(unused_crate_dependencies))]

use alloy_provider::{network::Ethereum, ProviderBuilder, RootProvider};
use alloy_provider::{network::Ethereum, DynProvider, ProviderBuilder};
use alloy_sol_types::SolValue;
use alloy_transport_http::Http;
use anyhow::Result;
use database::{AlloyDB, BlockId, CacheDB};
use exec::transact_erc20evm_commit;
use reqwest::{Client, Url};
use revm::{
context_interface::{
result::{InvalidHeader, InvalidTransaction},
Expand All @@ -27,22 +25,20 @@ use revm::{
pub mod exec;
pub mod handler;

type AlloyCacheDB =
CacheDB<WrapDatabaseAsync<AlloyDB<Http<Client>, Ethereum, RootProvider<Http<Client>>>>>;
type AlloyCacheDB = CacheDB<WrapDatabaseAsync<AlloyDB<Ethereum, DynProvider>>>;

// Constants
pub const TOKEN: Address = address!("a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48");
pub const TREASURY: Address = address!("0000000000000000000000000000000000000001");

#[tokio::main]
async fn main() -> Result<()> {
// Set up the HTTP transport which is consumed by the RPC client.
let rpc_url: Url = "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27".parse()?;
// Initialize the Alloy provider and database
let rpc_url = "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27";
let provider = DynProvider::new(ProviderBuilder::new().on_builtin(rpc_url).await?);

let client = ProviderBuilder::new().on_http(rpc_url);

let alloy = WrapDatabaseAsync::new(AlloyDB::new(client, BlockId::latest())).unwrap();
let mut cache_db = CacheDB::new(alloy);
let alloy_db = WrapDatabaseAsync::new(AlloyDB::new(provider, BlockId::latest())).unwrap();
let mut cache_db = CacheDB::new(alloy_db);

// Random empty account: From
let account = address!("18B06aaF27d44B756FCF16Ca20C1f183EB49111f");
Expand Down
16 changes: 8 additions & 8 deletions examples/uniswap_get_reserves/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![cfg_attr(not(test), warn(unused_crate_dependencies))]

use alloy_eips::BlockId;
use alloy_provider::ProviderBuilder;
use alloy_provider::{DynProvider, ProviderBuilder};
use alloy_sol_types::{sol, SolCall};
use database::{AlloyDB, CacheDB};
use revm::{
Expand All @@ -14,12 +14,12 @@ use revm::{

#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Set up the HTTP transport which is consumed by the RPC client.
let rpc_url = "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27".parse()?;
// Initialize the Alloy provider and database
let rpc_url = "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27";
let provider = DynProvider::new(ProviderBuilder::new().on_builtin(rpc_url).await?);

// Create a provider
let client = ProviderBuilder::new().on_http(rpc_url);
let client = WrapDatabaseAsync::new(AlloyDB::new(client, BlockId::latest())).unwrap();
let alloy_db = WrapDatabaseAsync::new(AlloyDB::new(provider, BlockId::latest())).unwrap();
let cache_db = CacheDB::new(alloy_db);

// ----------------------------------------------------------- //
// Storage slots of UniV2Pair contract //
Expand Down Expand Up @@ -48,10 +48,10 @@ async fn main() -> anyhow::Result<()> {
let encoded = getReservesCall::new(()).abi_encode();

// Query basic properties of an account incl bytecode
let acc_info = client.basic_ref(pool_address).unwrap().unwrap();
let acc_info = cache_db.basic_ref(pool_address).unwrap().unwrap();

// Query value of storage slot at account address
let value = client.storage_ref(pool_address, slot).unwrap();
let value = cache_db.storage_ref(pool_address, slot).unwrap();

// Initialise empty in-memory-db
let mut cache_db = CacheDB::new(EmptyDB::default());
Expand Down
2 changes: 0 additions & 2 deletions examples/uniswap_v2_usdc_swap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,5 @@ tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
# alloy
alloy-sol-types = { workspace = true, features = ["std"] }
alloy-eips.workspace = true
alloy-transport-http.workspace = true
alloy-provider = { workspace = true, default-features = true }
reqwest.workspace = true
anyhow.workspace = true
19 changes: 7 additions & 12 deletions examples/uniswap_v2_usdc_swap/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
#![cfg_attr(not(test), warn(unused_crate_dependencies))]

use alloy_eips::BlockId;
use alloy_provider::{network::Ethereum, ProviderBuilder, RootProvider};
use alloy_provider::{network::Ethereum, DynProvider, ProviderBuilder};
use alloy_sol_types::{sol, SolCall, SolValue};
use alloy_transport_http::Http;
use anyhow::{anyhow, Result};
use database::{AlloyDB, CacheDB};
use reqwest::Client;
use revm::{
context_interface::result::{ExecutionResult, Output},
database_interface::WrapDatabaseAsync,
Expand All @@ -17,19 +15,16 @@ use revm::{
};
use std::ops::Div;

type AlloyCacheDB =
CacheDB<WrapDatabaseAsync<AlloyDB<Http<Client>, Ethereum, RootProvider<Http<Client>>>>>;
type AlloyCacheDB = CacheDB<WrapDatabaseAsync<AlloyDB<Ethereum, DynProvider>>>;

#[tokio::main]
async fn main() -> Result<()> {
// Set up the HTTP transport which is consumed by the RPC client.
let rpc_url = "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27".parse()?;
// Initialize the Alloy provider and database
let rpc_url = "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27";
let provider = DynProvider::new(ProviderBuilder::new().on_builtin(rpc_url).await?);

// Create a provider
let client = ProviderBuilder::new().on_http(rpc_url);

let alloy = WrapDatabaseAsync::new(AlloyDB::new(client, BlockId::latest())).unwrap();
let mut cache_db = CacheDB::new(alloy);
let alloy_db = WrapDatabaseAsync::new(AlloyDB::new(provider, BlockId::latest())).unwrap();
let mut cache_db = CacheDB::new(alloy_db);

// Random empty account
let account = address!("18B06aaF27d44B756FCF16Ca20C1f183EB49111f");
Expand Down
Loading