Skip to content

Commit

Permalink
chore: bump alloy and add foundry-fork-db (#712)
Browse files Browse the repository at this point in the history
Co-authored-by: Agost Biro <[email protected]>
Co-authored-by: Arsenii Kulikov <[email protected]>
  • Loading branch information
3 people authored Oct 25, 2024
1 parent fc4064b commit 6b288fd
Show file tree
Hide file tree
Showing 21 changed files with 335 additions and 1,943 deletions.
316 changes: 122 additions & 194 deletions Cargo.lock

Large diffs are not rendered by default.

62 changes: 33 additions & 29 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ foundry-evm-traces = { path = "crates/foundry/evm/traces" }
# solc & compilation utilities
foundry-block-explorers = { version = "=0.2.7", default-features = false }
foundry-compilers = { version = "0.4.3", features = ["full"] }
foundry-fork-db = "=0.1.0"

## revm
# no default features to avoid c-kzg
Expand All @@ -188,37 +189,40 @@ revm-inspectors = { version = "0.1", features = ["serde"] }
ethers-contract-abigen = { version = "2.0.14", default-features = false }

## alloy
alloy-consensus = { git = "https://github.com/alloy-rs/alloy", rev = "f415827", default-features = false }
alloy-contract = { git = "https://github.com/alloy-rs/alloy", rev = "f415827", default-features = false }
alloy-eips = { git = "https://github.com/alloy-rs/alloy", rev = "f415827", default-features = false }
alloy-genesis = { git = "https://github.com/alloy-rs/alloy", rev = "f415827", default-features = false }
alloy-json-rpc = { git = "https://github.com/alloy-rs/alloy", rev = "f415827", default-features = false }
alloy-network = { git = "https://github.com/alloy-rs/alloy", rev = "f415827", default-features = false }
alloy-node-bindings = { git = "https://github.com/alloy-rs/alloy", rev = "f415827", default-features = false }
alloy-provider = { git = "https://github.com/alloy-rs/alloy", rev = "f415827", default-features = false }
alloy-pubsub = { git = "https://github.com/alloy-rs/alloy", rev = "f415827", default-features = false }
alloy-rpc-client = { git = "https://github.com/alloy-rs/alloy", rev = "f415827", default-features = false }
alloy-rpc-types-engine = { git = "https://github.com/alloy-rs/alloy", rev = "f415827", default-features = false }
alloy-rpc-types-trace = { git = "https://github.com/alloy-rs/alloy", rev = "f415827", default-features = false }
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "f415827", default-features = false }
alloy-serde = { git = "https://github.com/alloy-rs/alloy", rev = "f415827", default-features = false }
alloy-signer = { git = "https://github.com/alloy-rs/alloy", rev = "f415827", default-features = false }
alloy-signer-wallet = { git = "https://github.com/alloy-rs/alloy", rev = "f415827", default-features = false }
alloy-signer-aws = { git = "https://github.com/alloy-rs/alloy", rev = "f415827", default-features = false }
alloy-signer-ledger = { git = "https://github.com/alloy-rs/alloy", rev = "f415827", default-features = false }
alloy-signer-trezor = { git = "https://github.com/alloy-rs/alloy", rev = "f415827", default-features = false }
alloy-transport = { git = "https://github.com/alloy-rs/alloy", rev = "f415827", default-features = false }
alloy-transport-http = { git = "https://github.com/alloy-rs/alloy", rev = "f415827", default-features = false }
alloy-transport-ipc = { git = "https://github.com/alloy-rs/alloy", rev = "f415827", default-features = false }
alloy-transport-ws = { git = "https://github.com/alloy-rs/alloy", rev = "f415827", default-features = false }
alloy-primitives = { version = "0.7.1", features = ["getrandom"] }
alloy-dyn-abi = "0.7.1"
alloy-json-abi = "0.7.1"
alloy-sol-types = "0.7.1"
syn-solidity = "0.7.1"
alloy-consensus = { version = "0.1.2", default-features = false }
alloy-contract = { version = "0.1.2", default-features = false }
alloy-eips = { version = "0.1.2", default-features = false }
alloy-genesis = { version = "0.1.2", default-features = false }
alloy-json-rpc = { version = "0.1.2", default-features = false }
alloy-network = { version = "0.1.2", default-features = false }
alloy-node-bindings = { version = "0.1.2", default-features = false }
alloy-provider = { version = "0.1.2", default-features = false }
alloy-pubsub = { version = "0.1.2", default-features = false }
alloy-rpc-client = { version = "0.1.2", default-features = false }
alloy-rpc-types = { version = "0.1.2", default-features = false }
alloy-serde = { version = "0.1.2", default-features = false }
alloy-signer = { version = "0.1.2", default-features = false }
alloy-signer-aws = { version = "0.1.2", default-features = false }
alloy-signer-gcp = { version = "0.1.2", default-features = false }
alloy-signer-ledger = { version = "0.1.2", default-features = false }
alloy-signer-local = { version = "0.1.2", default-features = false }
alloy-signer-trezor = { version = "0.1.2", default-features = false }
alloy-transport = { version = "0.1.2", default-features = false }
alloy-transport-http = { version = "0.1.2", default-features = false }
alloy-transport-ipc = { version = "0.1.2", default-features = false }
alloy-transport-ws = { version = "0.1.2", default-features = false }

alloy-dyn-abi = "0.7.3"
alloy-json-abi = "0.7.3"
alloy-primitives = { version = "0.7.3", features = ["getrandom", "rand"] }
alloy-sol-macro-expander = "0.7.3"
alloy-sol-macro-input = "0.7.3"
alloy-sol-types = "0.7.3"
syn-solidity = "0.7.3"

alloy-chains = "0.1"
alloy-trie = "0.3.1"
alloy-rlp = "0.3.3"
alloy-trie = "0.4.1"

## misc
arrayvec = "0.7"
Expand Down
2 changes: 0 additions & 2 deletions crates/edr_solidity_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ svm = { package = "svm-rs", version = "0.5", default-features = false, features
tempfile.workspace = true
tracing-subscriber = { workspace = true, features = ["env-filter", "fmt"] }

alloy-signer-wallet.workspace = true

[features]
test-remote = []

Expand Down
2 changes: 1 addition & 1 deletion crates/foundry/cheatcodes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ alloy-sol-types.workspace = true
alloy-provider.workspace = true
alloy-rpc-types.workspace = true
alloy-signer.workspace = true
alloy-signer-wallet = { workspace = true, features = ["mnemonic-all-languages", "keystore"] }
alloy-signer-local = { workspace = true, features = ["mnemonic-all-languages", "keystore"] }

base64.workspace = true
dunce.workspace = true
Expand Down
13 changes: 7 additions & 6 deletions crates/foundry/cheatcodes/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use std::{borrow::Cow, fmt};

use alloy_primitives::{Address, Bytes};
use alloy_signer::Error as SignerError;
use alloy_signer_wallet::WalletError;
use alloy_signer_local::LocalSignerError;
use alloy_sol_types::SolError;
use edr_common::errors::FsPathError;
use foundry_evm_core::backend::DatabaseError;
use foundry_evm_core::backend::{BackendError, DatabaseError};
use k256::ecdsa::signature::Error as SignatureError;
use revm::primitives::EVMError;

Expand Down Expand Up @@ -299,6 +299,7 @@ impl_from!(
FsPathError,
hex::FromHexError,
eyre::Error,
BackendError,
DatabaseError,
jsonpath_lib::JsonPathError,
serde_json::Error,
Expand All @@ -307,14 +308,14 @@ impl_from!(
std::num::TryFromIntError,
std::str::Utf8Error,
std::string::FromUtf8Error,
WalletError,
LocalSignerError,
SignerError,
);

impl From<EVMError<DatabaseError>> for Error {
impl<T: Into<BackendError>> From<EVMError<T>> for Error {
#[inline]
fn from(err: EVMError<DatabaseError>) -> Self {
Self::display(DatabaseError::from(err))
fn from(err: EVMError<T>) -> Self {
Self::display(BackendError::from(err))
}
}

Expand Down
12 changes: 4 additions & 8 deletions crates/foundry/cheatcodes/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use alloy_primitives::{B256, U256};
use alloy_signer::SignerSync;
use alloy_signer_wallet::LocalWallet;
use alloy_signer_local::PrivateKeySigner;
use alloy_sol_types::SolValue;
use foundry_evm_core::constants::DEFAULT_CREATE2_DEPLOYER;
use k256::{ecdsa::SigningKey, elliptic_curve::Curve, Secp256k1};
Expand Down Expand Up @@ -85,12 +85,8 @@ fn encode_vrs(sig: alloy_primitives::Signature) -> Vec<u8> {
pub(super) fn sign(private_key: &U256, digest: &B256) -> Result {
// The `ecrecover` precompile does not use EIP-155. No chain ID is needed.
let wallet = parse_wallet(private_key)?;

let sig = wallet.sign_hash_sync(digest)?;
let recovered = sig.recover_address_from_prehash(digest)?;

assert_eq!(recovered, wallet.address());

debug_assert_eq!(sig.recover_address_from_prehash(digest)?, wallet.address());
Ok(encode_vrs(sig))
}

Expand Down Expand Up @@ -124,8 +120,8 @@ pub(super) fn parse_private_key(private_key: &U256) -> Result<SigningKey> {
SigningKey::from_bytes((&bytes).into()).map_err(Into::into)
}

pub(super) fn parse_wallet(private_key: &U256) -> Result<LocalWallet> {
parse_private_key(private_key).map(LocalWallet::from)
pub(super) fn parse_wallet(private_key: &U256) -> Result<PrivateKeySigner> {
parse_private_key(private_key).map(PrivateKeySigner::from)
}

#[cfg(test)]
Expand Down
5 changes: 3 additions & 2 deletions crates/foundry/evm/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ alloy-primitives = { workspace = true, features = ["serde", "getrandom", "arbitr
alloy-genesis.workspace = true
alloy-provider.workspace = true
alloy-pubsub.workspace = true
alloy-rpc-types-engine.workspace = true
alloy-rpc-client.workspace = true
alloy-rpc-types.workspace = true
alloy-rpc-types = { workspace = true, features = ["eth", "engine"] }
alloy-serde.workspace = true
alloy-sol-types.workspace = true
alloy-transport.workspace = true
alloy-transport-http = { workspace = true, features = ["reqwest", "reqwest-rustls-tls"] }
alloy-transport-ws.workspace = true
alloy-transport-ipc.workspace = true
foundry-fork-db.workspace = true

revm = { workspace = true, features = [
"std",
Expand Down
12 changes: 10 additions & 2 deletions crates/foundry/evm/core/src/abi/fmt/transactions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! wrappers for transactions
use alloy_provider::{network::AnyNetwork, Provider};
use alloy_rpc_types::{AnyTransactionReceipt, BlockId, WithOtherFields};
use alloy_rpc_types::{AnyTransactionReceipt, BlockId};
use alloy_serde::WithOtherFields;
use alloy_transport::Transport;
use eyre::Result;
use serde::{Deserialize, Serialize};
Expand All @@ -20,7 +21,14 @@ pub struct TransactionReceiptWithRevertReason {
impl TransactionReceiptWithRevertReason {
/// Returns if the status of the transaction is 0 (failure)
pub fn is_failure(&self) -> bool {
!self.receipt.inner.inner.inner.receipt.status
!self
.receipt
.inner
.inner
.inner
.receipt
.status
.coerce_status()
}

/// Updates the revert reason field using `eth_call` and returns an Err
Expand Down
23 changes: 14 additions & 9 deletions crates/foundry/evm/core/src/abi/fmt/ui.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Helper trait and functions to format Ethereum types.

use alloy_consensus::{AnyReceiptEnvelope, Receipt, ReceiptWithBloom, TxType};
use alloy_consensus::{AnyReceiptEnvelope, Eip658Value, Receipt, ReceiptWithBloom, TxType};
use alloy_primitives::{hex, Address, Bloom, Bytes, FixedBytes, Uint, B256, I256, U256, U64};
use alloy_rpc_types::{
other::OtherFields, AnyTransactionReceipt, Block, BlockTransactions, Log, Transaction,
TransactionReceipt,
AnyTransactionReceipt, Block, BlockTransactions, Log, Transaction, TransactionReceipt,
};
use alloy_serde::OtherFields;
use serde::Deserialize;

use crate::abi::fmt::transactions::TransactionReceiptWithRevertReason;
Expand Down Expand Up @@ -148,8 +148,13 @@ impl UIfmt for [u8] {
}
}

pub fn pretty_status(status: bool) -> String {
if status { "1 (success)" } else { "0 (failed)" }.to_string()
impl UIfmt for Eip658Value {
fn pretty(&self) -> String {
match self {
Self::Eip658(status) => if *status { "1 (success)" } else { "0 (failed)" }.to_string(),
Self::PostState(state) => state.pretty(),
}
}
}

impl UIfmt for AnyTransactionReceipt {
Expand Down Expand Up @@ -215,7 +220,7 @@ blobGasUsed {}",
serde_json::to_string(&logs).unwrap(),
logs_bloom.pretty(),
state_root.pretty(),
pretty_status(*status),
status.pretty(),
transaction_hash.pretty(),
transaction_index.pretty(),
transaction_type,
Expand Down Expand Up @@ -446,9 +451,9 @@ pub fn get_pretty_tx_receipt_attr(
),
"logsBloom" | "logs_bloom" => Some(receipt.receipt.inner.inner.inner.logs_bloom.pretty()),
"root" | "stateRoot" | "state_root " => Some(receipt.receipt.state_root.pretty()),
"status" | "statusCode" | "status_code" => Some(pretty_status(
receipt.receipt.inner.inner.inner.receipt.status,
)),
"status" | "statusCode" | "status_code" => {
Some(receipt.receipt.inner.inner.inner.receipt.status.pretty())
}
"transactionHash" | "transaction_hash" => Some(receipt.receipt.transaction_hash.pretty()),
"transactionIndex" | "transaction_index" => {
Some(receipt.receipt.transaction_index.pretty())
Expand Down
7 changes: 4 additions & 3 deletions crates/foundry/evm/core/src/backend/cow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{borrow::Cow, collections::BTreeMap};
use alloy_genesis::GenesisAccount;
use alloy_primitives::{Address, B256, U256};
use eyre::WrapErr;
use foundry_fork_db::DatabaseError;
use revm::{
db::DatabaseRef,
primitives::{
Expand All @@ -14,10 +15,10 @@ use revm::{
Database, DatabaseCommit, JournaledState,
};

use super::BackendError;
use crate::{
backend::{
diagnostic::RevertDiagnostic, error::DatabaseError, Backend, DatabaseExt, LocalForkId,
RevertSnapshotAction,
diagnostic::RevertDiagnostic, Backend, DatabaseExt, LocalForkId, RevertSnapshotAction,
},
fork::{CreateFork, ForkId},
InspectorExt,
Expand Down Expand Up @@ -236,7 +237,7 @@ impl<'a> DatabaseExt for CowBackend<'a> {
&mut self,
allocs: &BTreeMap<Address, GenesisAccount>,
journaled_state: &mut JournaledState,
) -> Result<(), DatabaseError> {
) -> Result<(), BackendError> {
self.backend_mut(&Env::default())
.load_allocs(allocs, journaled_state)
}
Expand Down
Loading

0 comments on commit 6b288fd

Please sign in to comment.