From 3ff3d0562215bca620e07c5c4c154eec8da0f04b Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Mon, 30 Sep 2024 19:05:58 +0530 Subject: [PATCH] chore: bump alloy-core deps + revm (#8988) * chore: bump alloy-core deps + revm * bump alloy to 0.4.0 * bump revm-inspectors + type casting to u128 * fix * Revert "fix" This reverts commit 5e0e0d1128b6819acf600b42372156738e666247. * Revert "bump revm-inspectors + type casting to u128" This reverts commit 25aa23cffaadef1d047ce7b359b4d7ad5018704a. * Revert "bump alloy to 0.4.0" This reverts commit f9721e00f5ba726c4fea6651839d65b45faae488. * replace std HashMap with alloy_primitives maps * bump compilers * replace remaining HashMaps * fmt * nit * replace HashSets * fmt --- Cargo.lock | 8 ++-- Cargo.toml | 16 ++++---- crates/anvil/src/config.rs | 3 +- crates/anvil/src/eth/backend/cheats.rs | 8 ++-- crates/anvil/src/eth/backend/fork.rs | 19 ++++++---- crates/anvil/src/eth/backend/mem/storage.rs | 37 +++++++++++-------- crates/anvil/src/eth/sign.rs | 5 +-- crates/anvil/src/filter.rs | 3 +- crates/anvil/tests/it/logs.rs | 4 +- crates/anvil/tests/it/transaction.rs | 6 +-- crates/cheatcodes/src/config.rs | 5 +-- crates/cheatcodes/src/evm/mapping.rs | 17 +++++---- crates/cheatcodes/src/inspector.rs | 12 ++++-- crates/cheatcodes/src/utils.rs | 3 +- crates/chisel/src/runner.rs | 5 +-- crates/chisel/src/session_source.rs | 3 +- crates/common/src/selectors.rs | 3 +- crates/config/src/error.rs | 4 +- crates/config/src/inline/mod.rs | 4 +- crates/config/src/lib.rs | 7 ++-- crates/debugger/src/tui/builder.rs | 6 +-- crates/debugger/src/tui/mod.rs | 7 ++-- crates/doc/src/builder.rs | 2 +- crates/doc/src/document.rs | 2 +- crates/doc/src/parser/comment.rs | 2 +- .../src/preprocessor/contract_inheritance.rs | 3 +- crates/doc/src/preprocessor/inheritdoc.rs | 2 +- crates/doc/src/preprocessor/mod.rs | 3 +- crates/evm/core/src/backend/diagnostic.rs | 5 +-- crates/evm/core/src/fork/multi.rs | 3 +- crates/evm/core/src/state_snapshot.rs | 4 +- crates/evm/evm/src/executors/fuzz/mod.rs | 4 +- crates/evm/evm/src/executors/fuzz/types.rs | 3 +- .../evm/evm/src/executors/invariant/replay.rs | 4 +- crates/evm/evm/src/executors/mod.rs | 9 +++-- crates/evm/evm/src/inspectors/stack.rs | 5 +-- crates/evm/fuzz/src/lib.rs | 9 +++-- crates/evm/fuzz/src/strategies/calldata.rs | 3 +- crates/evm/traces/src/lib.rs | 4 +- crates/forge/bin/cmd/bind.rs | 3 +- crates/forge/bin/cmd/snapshot.rs | 3 +- crates/forge/bin/cmd/watch.rs | 4 +- crates/forge/src/progress.rs | 4 +- crates/forge/src/result.rs | 17 +++++---- crates/linking/src/lib.rs | 3 +- crates/script/src/broadcast.rs | 17 +++++---- crates/script/src/execute.rs | 6 ++- crates/script/src/lib.rs | 9 +++-- crates/script/src/progress.rs | 9 +++-- crates/script/src/sequence.rs | 4 +- crates/verify/src/sourcify.rs | 7 +++- crates/wallets/src/multi_wallet.rs | 10 ++--- 52 files changed, 187 insertions(+), 161 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fd4e2e0c62fb..7308606c9e3c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7029,9 +7029,9 @@ checksum = "d3edd4d5d42c92f0a659926464d4cce56b562761267ecf0f469d85b7de384175" [[package]] name = "redox_syscall" -version = "0.5.6" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "355ae415ccd3a04315d3f8246e86d67689ea74d88d915576e1589a351062a13b" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ "bitflags 2.6.0", ] @@ -7622,9 +7622,9 @@ dependencies = [ [[package]] name = "scc" -version = "2.1.17" +version = "2.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c947adb109a8afce5fc9c7bf951f87f146e9147b3a6a58413105628fb1d1e66" +checksum = "215b1103f73e23e9cb6883072c1fb26ae55c09d42054654955c739e5418a7c96" dependencies = [ "sdd", ] diff --git a/Cargo.toml b/Cargo.toml index 228bac2909fc..ae6ee18250fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -172,7 +172,7 @@ foundry-fork-db = "0.3.2" solang-parser = "=0.3.3" ## revm -revm = { version = "14.0.2", default-features = false } +revm = { version = "14.0.3", default-features = false } revm-primitives = { version = "10.0.0", default-features = false } revm-inspectors = { version = "0.7.7", features = ["serde"] } @@ -203,17 +203,17 @@ alloy-transport-ipc = { version = "0.3.6", default-features = false } alloy-transport-ws = { version = "0.3.6", default-features = false } ## alloy-core -alloy-dyn-abi = "0.8.1" -alloy-json-abi = "0.8.1" -alloy-primitives = { version = "0.8.1", features = [ +alloy-dyn-abi = "0.8.5" +alloy-json-abi = "0.8.5" +alloy-primitives = { version = "0.8.5", features = [ "getrandom", "rand", "map-fxhash", ] } -alloy-sol-macro-expander = "0.8.1" -alloy-sol-macro-input = "0.8.1" -alloy-sol-types = "0.8.1" -syn-solidity = "0.8.1" +alloy-sol-macro-expander = "0.8.5" +alloy-sol-macro-input = "0.8.5" +alloy-sol-types = "0.8.5" +syn-solidity = "0.8.5" alloy-chains = "0.1" alloy-rlp = "0.3" diff --git a/crates/anvil/src/config.rs b/crates/anvil/src/config.rs index d907fc200f53..f3dbf21f6013 100644 --- a/crates/anvil/src/config.rs +++ b/crates/anvil/src/config.rs @@ -17,7 +17,7 @@ use crate::{ }; use alloy_genesis::Genesis; use alloy_network::AnyNetwork; -use alloy_primitives::{hex, utils::Unit, BlockNumber, TxHash, U256}; +use alloy_primitives::{hex, map::HashMap, utils::Unit, BlockNumber, TxHash, U256}; use alloy_provider::Provider; use alloy_rpc_types::{Block, BlockNumberOrTag, Transaction}; use alloy_serde::WithOtherFields; @@ -46,7 +46,6 @@ use rand::thread_rng; use revm::primitives::BlobExcessGasAndPrice; use serde_json::{json, to_writer, Value}; use std::{ - collections::HashMap, fmt::Write as FmtWrite, fs::File, net::{IpAddr, Ipv4Addr}, diff --git a/crates/anvil/src/eth/backend/cheats.rs b/crates/anvil/src/eth/backend/cheats.rs index 5e941d004643..32115cf41c13 100644 --- a/crates/anvil/src/eth/backend/cheats.rs +++ b/crates/anvil/src/eth/backend/cheats.rs @@ -1,8 +1,8 @@ //! Support for "cheat codes" / bypass functions -use alloy_primitives::Address; +use alloy_primitives::{map::AddressHashSet, Address}; use parking_lot::RwLock; -use std::{collections::HashSet, sync::Arc}; +use std::sync::Arc; /// Manages user modifications that may affect the node's behavior /// @@ -55,7 +55,7 @@ impl CheatsManager { } /// Returns all accounts that are currently being impersonated. - pub fn impersonated_accounts(&self) -> HashSet
{ + pub fn impersonated_accounts(&self) -> AddressHashSet { self.state.read().impersonated_accounts.clone() } } @@ -64,7 +64,7 @@ impl CheatsManager { #[derive(Clone, Debug, Default)] pub struct CheatsState { /// All accounts that are currently impersonated - pub impersonated_accounts: HashSet
, + pub impersonated_accounts: AddressHashSet, /// If set to true will make the `is_impersonated` function always return true pub auto_impersonate_accounts: bool, } diff --git a/crates/anvil/src/eth/backend/fork.rs b/crates/anvil/src/eth/backend/fork.rs index c661eeaa89b8..ea41b85a954c 100644 --- a/crates/anvil/src/eth/backend/fork.rs +++ b/crates/anvil/src/eth/backend/fork.rs @@ -4,7 +4,10 @@ use crate::eth::{backend::db::Db, error::BlockchainError, pool::transactions::Po use alloy_consensus::Account; use alloy_eips::eip2930::AccessListResult; use alloy_network::BlockResponse; -use alloy_primitives::{Address, Bytes, StorageValue, B256, U256}; +use alloy_primitives::{ + map::{FbHashMap, HashMap}, + Address, Bytes, StorageValue, B256, U256, +}; use alloy_provider::{ ext::{DebugApi, TraceApi}, Provider, @@ -27,7 +30,7 @@ use parking_lot::{ RawRwLock, RwLock, }; use revm::primitives::BlobExcessGasAndPrice; -use std::{collections::HashMap, sync::Arc, time::Duration}; +use std::{sync::Arc, time::Duration}; use tokio::sync::RwLock as AsyncRwLock; /// Represents a fork of a remote client @@ -675,14 +678,14 @@ impl ClientForkConfig { /// This is used as a cache so repeated requests to the same data are not sent to the remote client #[derive(Clone, Debug, Default)] pub struct ForkedStorage { - pub uncles: HashMap>, - pub blocks: HashMap, + pub uncles: FbHashMap<32, Vec>, + pub blocks: FbHashMap<32, AnyNetworkBlock>, pub hashes: HashMap, - pub transactions: HashMap>, - pub transaction_receipts: HashMap, - pub transaction_traces: HashMap>, + pub transactions: FbHashMap<32, WithOtherFields>, + pub transaction_receipts: FbHashMap<32, ReceiptResponse>, + pub transaction_traces: FbHashMap<32, Vec>, pub logs: HashMap>, - pub geth_transaction_traces: HashMap, + pub geth_transaction_traces: FbHashMap<32, GethTrace>, pub block_traces: HashMap>, pub block_receipts: HashMap>, pub code_at: HashMap<(Address, u64), Bytes>, diff --git a/crates/anvil/src/eth/backend/mem/storage.rs b/crates/anvil/src/eth/backend/mem/storage.rs index 928fb66e4e03..abc520c3b014 100644 --- a/crates/anvil/src/eth/backend/mem/storage.rs +++ b/crates/anvil/src/eth/backend/mem/storage.rs @@ -10,7 +10,10 @@ use crate::eth::{ error::BlockchainError, pool::transactions::PoolTransaction, }; -use alloy_primitives::{Bytes, TxHash, B256, U256, U64}; +use alloy_primitives::{ + map::{B256HashMap, HashMap}, + Bytes, B256, U256, U64, +}; use alloy_rpc_types::{ trace::{ geth::{ @@ -35,12 +38,8 @@ use foundry_evm::{ }, }; use parking_lot::RwLock; -use std::{ - collections::{HashMap, VecDeque}, - fmt, - sync::Arc, - time::Duration, -}; +use std::{collections::VecDeque, fmt, sync::Arc, time::Duration}; +// use yansi::Paint; // === various limits in number of blocks === @@ -52,9 +51,9 @@ const MAX_ON_DISK_HISTORY_LIMIT: usize = 3_600; /// Represents the complete state of single block pub struct InMemoryBlockStates { /// The states at a certain block - states: HashMap, + states: B256HashMap, /// states which data is moved to disk - on_disk_states: HashMap, + on_disk_states: B256HashMap, /// How many states to store at most in_memory_limit: usize, /// minimum amount of states we keep in memory @@ -245,7 +244,7 @@ impl Default for InMemoryBlockStates { #[derive(Clone)] pub struct BlockchainStorage { /// all stored blocks (block hash -> block) - pub blocks: HashMap, + pub blocks: B256HashMap, /// mapping from block number -> block hash pub hashes: HashMap, /// The current best hash @@ -256,7 +255,7 @@ pub struct BlockchainStorage { pub genesis_hash: B256, /// Mapping from the transaction hash to a tuple containing the transaction as well as the /// transaction receipt - pub transactions: HashMap, + pub transactions: B256HashMap, /// The total difficulty of the chain until this block pub total_difficulty: U256, } @@ -280,9 +279,14 @@ impl BlockchainStorage { let best_hash = genesis_hash; let best_number: U64 = U64::from(0u64); + let mut blocks = B256HashMap::default(); + blocks.insert(genesis_hash, block); + + let mut hashes = HashMap::default(); + hashes.insert(best_number, genesis_hash); Self { - blocks: HashMap::from([(genesis_hash, block)]), - hashes: HashMap::from([(best_number, genesis_hash)]), + blocks, + hashes, best_hash, best_number, genesis_hash, @@ -292,9 +296,12 @@ impl BlockchainStorage { } pub fn forked(block_number: u64, block_hash: B256, total_difficulty: U256) -> Self { + let mut hashes = HashMap::default(); + hashes.insert(U64::from(block_number), block_hash); + Self { - blocks: Default::default(), - hashes: HashMap::from([(U64::from(block_number), block_hash)]), + blocks: B256HashMap::default(), + hashes, best_hash: block_hash, best_number: U64::from(block_number), genesis_hash: Default::default(), diff --git a/crates/anvil/src/eth/sign.rs b/crates/anvil/src/eth/sign.rs index d921b18d35e4..d322e47d2265 100644 --- a/crates/anvil/src/eth/sign.rs +++ b/crates/anvil/src/eth/sign.rs @@ -2,14 +2,13 @@ use crate::eth::error::BlockchainError; use alloy_consensus::SignableTransaction; use alloy_dyn_abi::TypedData; use alloy_network::TxSignerSync; -use alloy_primitives::{Address, Signature, B256}; +use alloy_primitives::{map::AddressHashMap, Address, Signature, B256}; use alloy_signer::Signer as AlloySigner; use alloy_signer_local::PrivateKeySigner; use anvil_core::eth::transaction::{ optimism::{DepositTransaction, DepositTransactionRequest}, TypedTransaction, TypedTransactionRequest, }; -use std::collections::HashMap; /// A transaction signer #[async_trait::async_trait] @@ -47,7 +46,7 @@ pub trait Signer: Send + Sync { /// Maintains developer keys pub struct DevSigner { addresses: Vec
, - accounts: HashMap, + accounts: AddressHashMap, } impl DevSigner { diff --git a/crates/anvil/src/filter.rs b/crates/anvil/src/filter.rs index 2144ce27c988..c0c8e7aef15e 100644 --- a/crates/anvil/src/filter.rs +++ b/crates/anvil/src/filter.rs @@ -4,13 +4,12 @@ use crate::{ pubsub::filter_logs, StorageInfo, }; -use alloy_primitives::TxHash; +use alloy_primitives::{map::HashMap, TxHash}; use alloy_rpc_types::{Filter, FilteredParams, Log}; use anvil_core::eth::subscription::SubscriptionId; use anvil_rpc::response::ResponseResult; use futures::{channel::mpsc::Receiver, Stream, StreamExt}; use std::{ - collections::HashMap, pin::Pin, sync::Arc, task::{Context, Poll}, diff --git a/crates/anvil/tests/it/logs.rs b/crates/anvil/tests/it/logs.rs index 1ce4ac64ffae..3bf09493d8aa 100644 --- a/crates/anvil/tests/it/logs.rs +++ b/crates/anvil/tests/it/logs.rs @@ -5,7 +5,7 @@ use crate::{ utils::{http_provider_with_signer, ws_provider_with_signer}, }; use alloy_network::EthereumWallet; -use alloy_primitives::B256; +use alloy_primitives::{map::B256HashSet, B256}; use alloy_provider::Provider; use alloy_rpc_types::{BlockNumberOrTag, Filter}; use anvil::{spawn, NodeConfig}; @@ -120,7 +120,7 @@ async fn get_all_events() { // test that logs returned from get_logs and get_transaction_receipt have // the same log_index, block_number, and transaction_hash let mut tasks = vec![]; - let mut seen_tx_hashes = std::collections::HashSet::new(); + let mut seen_tx_hashes = B256HashSet::default(); for log in &logs { if seen_tx_hashes.contains(&log.transaction_hash.unwrap()) { continue; diff --git a/crates/anvil/tests/it/transaction.rs b/crates/anvil/tests/it/transaction.rs index b3e82c380101..63ebbbcf3404 100644 --- a/crates/anvil/tests/it/transaction.rs +++ b/crates/anvil/tests/it/transaction.rs @@ -3,7 +3,7 @@ use crate::{ utils::{connect_pubsub, http_provider_with_signer}, }; use alloy_network::{EthereumWallet, TransactionBuilder}; -use alloy_primitives::{Address, Bytes, FixedBytes, U256}; +use alloy_primitives::{map::B256HashSet, Address, Bytes, FixedBytes, U256}; use alloy_provider::Provider; use alloy_rpc_types::{ state::{AccountOverride, StateOverride}, @@ -13,7 +13,7 @@ use alloy_serde::WithOtherFields; use anvil::{spawn, EthereumHardfork, NodeConfig}; use eyre::Ok; use futures::{future::join_all, FutureExt, StreamExt}; -use std::{collections::HashSet, str::FromStr, time::Duration}; +use std::{str::FromStr, time::Duration}; use tokio::time::timeout; #[tokio::test(flavor = "multi_thread")] @@ -950,7 +950,7 @@ async fn can_stream_pending_transactions() { if watch_received.len() == num_txs && sub_received.len() == num_txs { if let Some(sent) = &sent { assert_eq!(sent.len(), watch_received.len()); - let sent_txs = sent.iter().map(|tx| tx.transaction_hash).collect::>(); + let sent_txs = sent.iter().map(|tx| tx.transaction_hash).collect::(); assert_eq!(sent_txs, watch_received.iter().copied().collect()); assert_eq!(sent_txs, sub_received.iter().copied().collect()); break diff --git a/crates/cheatcodes/src/config.rs b/crates/cheatcodes/src/config.rs index 715e26dc57bb..531784e16339 100644 --- a/crates/cheatcodes/src/config.rs +++ b/crates/cheatcodes/src/config.rs @@ -1,6 +1,6 @@ use super::Result; use crate::{script::ScriptWallets, Vm::Rpc}; -use alloy_primitives::{Address, U256}; +use alloy_primitives::{map::AddressHashMap, U256}; use foundry_common::{fs::normalize_path, ContractsByArtifact}; use foundry_compilers::{utils::canonicalize, ProjectPathsConfig}; use foundry_config::{ @@ -10,7 +10,6 @@ use foundry_config::{ use foundry_evm_core::opts::EvmOpts; use semver::Version; use std::{ - collections::HashMap, path::{Path, PathBuf}, time::Duration, }; @@ -43,7 +42,7 @@ pub struct CheatsConfig { /// How the evm was configured by the user pub evm_opts: EvmOpts, /// Address labels from config - pub labels: HashMap, + pub labels: AddressHashMap, /// Script wallets pub script_wallets: Option, /// Artifacts which are guaranteed to be fresh (either recompiled or cached). diff --git a/crates/cheatcodes/src/evm/mapping.rs b/crates/cheatcodes/src/evm/mapping.rs index 679609274ed6..e8525908e847 100644 --- a/crates/cheatcodes/src/evm/mapping.rs +++ b/crates/cheatcodes/src/evm/mapping.rs @@ -1,26 +1,29 @@ use crate::{Cheatcode, Cheatcodes, Result, Vm::*}; -use alloy_primitives::{keccak256, Address, B256, U256}; +use alloy_primitives::{ + keccak256, + map::{AddressHashMap, B256HashMap}, + Address, B256, U256, +}; use alloy_sol_types::SolValue; use revm::interpreter::{opcode, Interpreter}; -use std::collections::HashMap; /// Recorded mapping slots. #[derive(Clone, Debug, Default)] pub struct MappingSlots { /// Holds mapping parent (slots => slots) - pub parent_slots: HashMap, + pub parent_slots: B256HashMap, /// Holds mapping key (slots => key) - pub keys: HashMap, + pub keys: B256HashMap, /// Holds mapping child (slots => slots[]) - pub children: HashMap>, + pub children: B256HashMap>, /// Holds the last sha3 result `sha3_result => (data_low, data_high)`, this would only record /// when sha3 is called with `size == 0x40`, and the lower 256 bits would be stored in /// `data_low`, higher 256 bits in `data_high`. /// This is needed for mapping_key detect if the slot is for some mapping and record that. - pub seen_sha3: HashMap, + pub seen_sha3: B256HashMap<(B256, B256)>, } impl MappingSlots { @@ -113,7 +116,7 @@ fn slot_child<'a>( } #[cold] -pub(crate) fn step(mapping_slots: &mut HashMap, interpreter: &Interpreter) { +pub(crate) fn step(mapping_slots: &mut AddressHashMap, interpreter: &Interpreter) { match interpreter.current_opcode() { opcode::KECCAK256 => { if interpreter.stack.peek(1) == Ok(U256::from(0x40)) { diff --git a/crates/cheatcodes/src/inspector.rs b/crates/cheatcodes/src/inspector.rs index 58d8ca5c9e70..f4d0ed82114a 100644 --- a/crates/cheatcodes/src/inspector.rs +++ b/crates/cheatcodes/src/inspector.rs @@ -20,7 +20,11 @@ use crate::{ CheatsConfig, CheatsCtxt, DynCheatcode, Error, Result, Vm, Vm::AccountAccess, }; -use alloy_primitives::{hex, Address, Bytes, Log, TxKind, B256, U256}; +use alloy_primitives::{ + hex, + map::{AddressHashMap, HashMap}, + Address, Bytes, Log, TxKind, B256, U256, +}; use alloy_rpc_types::request::{TransactionInput, TransactionRequest}; use alloy_sol_types::{SolCall, SolInterface, SolValue}; use foundry_common::{evm::Breakpoints, TransactionMaybeSigned, SELECTOR_LEN}; @@ -48,7 +52,7 @@ use revm::{ use rustc_hash::FxHashMap; use serde_json::Value; use std::{ - collections::{BTreeMap, HashMap, VecDeque}, + collections::{BTreeMap, VecDeque}, fs::File, io::BufReader, ops::Range, @@ -363,7 +367,7 @@ pub struct Cheatcodes { pub gas_price: Option, /// Address labels - pub labels: HashMap, + pub labels: AddressHashMap, /// Prank information pub prank: Option, @@ -432,7 +436,7 @@ pub struct Cheatcodes { pub gas_metering: GasMetering, /// Mapping slots. - pub mapping_slots: Option>, + pub mapping_slots: Option>, /// The current program counter. pub pc: usize, diff --git a/crates/cheatcodes/src/utils.rs b/crates/cheatcodes/src/utils.rs index b4e32748354a..eb4d2f525a4f 100644 --- a/crates/cheatcodes/src/utils.rs +++ b/crates/cheatcodes/src/utils.rs @@ -2,13 +2,12 @@ use crate::{Cheatcode, Cheatcodes, CheatsCtxt, Result, Vm::*}; use alloy_dyn_abi::{DynSolType, DynSolValue}; -use alloy_primitives::U256; +use alloy_primitives::{map::HashMap, U256}; use alloy_sol_types::SolValue; use foundry_common::ens::namehash; use foundry_evm_core::{backend::DatabaseExt, constants::DEFAULT_CREATE2_DEPLOYER}; use proptest::strategy::{Strategy, ValueTree}; use rand::{Rng, RngCore}; -use std::collections::HashMap; /// Contains locations of traces ignored via cheatcodes. /// diff --git a/crates/chisel/src/runner.rs b/crates/chisel/src/runner.rs index e78454ee363b..72b083e1fb88 100644 --- a/crates/chisel/src/runner.rs +++ b/crates/chisel/src/runner.rs @@ -3,14 +3,13 @@ //! This module contains the `ChiselRunner` struct, which assists with deploying //! and calling the REPL contract on a in-memory REVM instance. -use alloy_primitives::{Address, Bytes, Log, U256}; +use alloy_primitives::{map::AddressHashMap, Address, Bytes, Log, U256}; use eyre::Result; use foundry_evm::{ executors::{DeployResult, Executor, RawCallResult}, traces::{TraceKind, Traces}, }; use revm::interpreter::{return_ok, InstructionResult}; -use std::collections::HashMap; /// The function selector of the REPL contract's entrypoint, the `run()` function. static RUN_SELECTOR: [u8; 4] = [0xc0, 0x40, 0x62, 0x26]; @@ -43,7 +42,7 @@ pub struct ChiselResult { /// Amount of gas used in the transaction pub gas_used: u64, /// Map of addresses to their labels - pub labeled_addresses: HashMap, + pub labeled_addresses: AddressHashMap, /// Return data pub returned: Bytes, /// Called address diff --git a/crates/chisel/src/session_source.rs b/crates/chisel/src/session_source.rs index f7db438324c1..e1b31a972a37 100644 --- a/crates/chisel/src/session_source.rs +++ b/crates/chisel/src/session_source.rs @@ -4,6 +4,7 @@ //! the REPL contract's source code. It provides simple compilation, parsing, and //! execution helpers. +use alloy_primitives::map::HashMap; use eyre::Result; use forge_fmt::solang_ext::SafeUnwrap; use foundry_compilers::{ @@ -15,7 +16,7 @@ use foundry_evm::{backend::Backend, opts::EvmOpts}; use semver::Version; use serde::{Deserialize, Serialize}; use solang_parser::{diagnostics::Diagnostic, pt}; -use std::{collections::HashMap, fs, path::PathBuf}; +use std::{fs, path::PathBuf}; use yansi::Paint; /// The minimum Solidity version of the `Vm` interface. diff --git a/crates/common/src/selectors.rs b/crates/common/src/selectors.rs index 16565a07e8e6..3b10739162cb 100644 --- a/crates/common/src/selectors.rs +++ b/crates/common/src/selectors.rs @@ -4,11 +4,11 @@ use crate::abi::abi_decode_calldata; use alloy_json_abi::JsonAbi; +use alloy_primitives::map::HashMap; use eyre::Context; use reqwest::header::{HeaderMap, HeaderName, HeaderValue}; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use std::{ - collections::HashMap, fmt, sync::{ atomic::{AtomicBool, AtomicUsize, Ordering}, @@ -16,7 +16,6 @@ use std::{ }, time::Duration, }; - const SELECTOR_LOOKUP_URL: &str = "https://api.openchain.xyz/signature-database/v1/lookup"; const SELECTOR_IMPORT_URL: &str = "https://api.openchain.xyz/signature-database/v1/import"; diff --git a/crates/config/src/error.rs b/crates/config/src/error.rs index 3da1aee09e56..09f21605d110 100644 --- a/crates/config/src/error.rs +++ b/crates/config/src/error.rs @@ -1,8 +1,8 @@ //! error handling and solc error codes +use alloy_primitives::map::HashSet; use figment::providers::{Format, Toml}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use std::{collections::HashSet, error::Error, fmt, str::FromStr}; - +use std::{error::Error, fmt, str::FromStr}; /// The message shown upon panic if the config could not be extracted from the figment pub const FAILED_TO_EXTRACT_CONFIG_PANIC_MSG: &str = "failed to extract foundry config:"; diff --git a/crates/config/src/inline/mod.rs b/crates/config/src/inline/mod.rs index 36bad2514df3..8b5616a21afb 100644 --- a/crates/config/src/inline/mod.rs +++ b/crates/config/src/inline/mod.rs @@ -1,6 +1,6 @@ use crate::Config; -use std::{collections::HashMap, sync::LazyLock}; - +use alloy_primitives::map::HashMap; +use std::sync::LazyLock; mod conf_parser; pub use conf_parser::*; diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index 452365ce9551..18352aab9972 100644 --- a/crates/config/src/lib.rs +++ b/crates/config/src/lib.rs @@ -38,12 +38,11 @@ use foundry_compilers::{ }; use inflector::Inflector; use regex::Regex; -use revm_primitives::{FixedBytes, SpecId}; +use revm_primitives::{map::AddressHashMap, FixedBytes, SpecId}; use semver::Version; use serde::{Deserialize, Serialize, Serializer}; use std::{ borrow::Cow, - collections::HashMap, fs, path::{Path, PathBuf}, str::FromStr, @@ -418,7 +417,7 @@ pub struct Config { pub disable_block_gas_limit: bool, /// Address labels - pub labels: HashMap, + pub labels: AddressHashMap, /// Whether to enable safety checks for `vm.getCode` and `vm.getDeployedCode` invocations. /// If disabled, it is possible to access artifacts which were not recompiled or cached. @@ -5034,7 +5033,7 @@ mod tests { let config = Config::load(); assert_eq!( config.labels, - HashMap::from_iter(vec![ + AddressHashMap::from_iter(vec![ ( Address::from_str("0x1F98431c8aD98523631AE4a59f267346ea31F984").unwrap(), "Uniswap V3: Factory".to_string() diff --git a/crates/debugger/src/tui/builder.rs b/crates/debugger/src/tui/builder.rs index fd952def5bc4..484611c70e65 100644 --- a/crates/debugger/src/tui/builder.rs +++ b/crates/debugger/src/tui/builder.rs @@ -1,11 +1,9 @@ //! TUI debugger builder. use crate::{node::flatten_call_trace, DebugNode, Debugger}; -use alloy_primitives::Address; +use alloy_primitives::{map::AddressHashMap, Address}; use foundry_common::{evm::Breakpoints, get_contract_name}; use foundry_evm_traces::{debug::ContractSources, CallTraceArena, CallTraceDecoder, Traces}; -use std::collections::HashMap; - /// Debugger builder. #[derive(Debug, Default)] #[must_use = "builders do nothing unless you call `build` on them"] @@ -13,7 +11,7 @@ pub struct DebuggerBuilder { /// Debug traces returned from the EVM execution. debug_arena: Vec, /// Identified contracts. - identified_contracts: HashMap, + identified_contracts: AddressHashMap, /// Map of source files. sources: ContractSources, /// Map of the debugger breakpoints. diff --git a/crates/debugger/src/tui/mod.rs b/crates/debugger/src/tui/mod.rs index 155973e15830..75b747a7ed02 100644 --- a/crates/debugger/src/tui/mod.rs +++ b/crates/debugger/src/tui/mod.rs @@ -1,6 +1,6 @@ //! The TUI implementation. -use alloy_primitives::Address; +use alloy_primitives::map::AddressHashMap; use crossterm::{ event::{self, DisableMouseCapture, EnableMouseCapture, Event}, execute, @@ -14,7 +14,6 @@ use ratatui::{ Terminal, }; use std::{ - collections::HashMap, io, ops::ControlFlow, sync::{mpsc, Arc}, @@ -44,7 +43,7 @@ pub enum ExitReason { /// The TUI debugger. pub struct Debugger { debug_arena: Vec, - identified_contracts: HashMap, + identified_contracts: AddressHashMap, /// Source map of contract sources contracts_sources: ContractSources, breakpoints: Breakpoints, @@ -60,7 +59,7 @@ impl Debugger { /// Creates a new debugger. pub fn new( debug_arena: Vec, - identified_contracts: HashMap, + identified_contracts: AddressHashMap, contracts_sources: ContractSources, breakpoints: Breakpoints, ) -> Self { diff --git a/crates/doc/src/builder.rs b/crates/doc/src/builder.rs index e21e80c22bd5..3ec433c395f4 100644 --- a/crates/doc/src/builder.rs +++ b/crates/doc/src/builder.rs @@ -2,6 +2,7 @@ use crate::{ document::DocumentContent, helpers::merge_toml_table, AsDoc, BufWriter, Document, ParseItem, ParseSource, Parser, Preprocessor, }; +use alloy_primitives::map::HashMap; use forge_fmt::{FormatterConfig, Visitable}; use foundry_compilers::{compilers::solc::SOLC_EXTENSIONS, utils::source_files_iter}; use foundry_config::{filter::expand_globs, DocConfig}; @@ -10,7 +11,6 @@ use mdbook::MDBook; use rayon::prelude::*; use std::{ cmp::Ordering, - collections::HashMap, fs, path::{Path, PathBuf}, }; diff --git a/crates/doc/src/document.rs b/crates/doc/src/document.rs index be4c1e647670..10f72a672c25 100644 --- a/crates/doc/src/document.rs +++ b/crates/doc/src/document.rs @@ -1,6 +1,6 @@ use crate::{DocBuilder, ParseItem, PreprocessorId, PreprocessorOutput}; +use alloy_primitives::map::HashMap; use std::{ - collections::HashMap, path::{Path, PathBuf}, slice::IterMut, sync::Mutex, diff --git a/crates/doc/src/parser/comment.rs b/crates/doc/src/parser/comment.rs index 280dcfd0d712..13184112e6e0 100644 --- a/crates/doc/src/parser/comment.rs +++ b/crates/doc/src/parser/comment.rs @@ -1,6 +1,6 @@ +use alloy_primitives::map::HashMap; use derive_more::{Deref, DerefMut}; use solang_parser::doccomment::DocCommentTag; -use std::collections::HashMap; /// The natspec comment tag explaining the purpose of the comment. /// See: . diff --git a/crates/doc/src/preprocessor/contract_inheritance.rs b/crates/doc/src/preprocessor/contract_inheritance.rs index 7d74589bddb4..ac229a4342f5 100644 --- a/crates/doc/src/preprocessor/contract_inheritance.rs +++ b/crates/doc/src/preprocessor/contract_inheritance.rs @@ -1,7 +1,8 @@ use super::{Preprocessor, PreprocessorId}; use crate::{document::DocumentContent, Document, ParseSource, PreprocessorOutput}; +use alloy_primitives::map::HashMap; use forge_fmt::solang_ext::SafeUnwrap; -use std::{collections::HashMap, path::PathBuf}; +use std::path::PathBuf; /// [ContractInheritance] preprocessor id. pub const CONTRACT_INHERITANCE_ID: PreprocessorId = PreprocessorId("contract_inheritance"); diff --git a/crates/doc/src/preprocessor/inheritdoc.rs b/crates/doc/src/preprocessor/inheritdoc.rs index 8d29a64fcf3a..65cbb688c443 100644 --- a/crates/doc/src/preprocessor/inheritdoc.rs +++ b/crates/doc/src/preprocessor/inheritdoc.rs @@ -2,8 +2,8 @@ use super::{Preprocessor, PreprocessorId}; use crate::{ document::DocumentContent, Comments, Document, ParseItem, ParseSource, PreprocessorOutput, }; +use alloy_primitives::map::HashMap; use forge_fmt::solang_ext::SafeUnwrap; -use std::collections::HashMap; /// [`Inheritdoc`] preprocessor ID. pub const INHERITDOC_ID: PreprocessorId = PreprocessorId("inheritdoc"); diff --git a/crates/doc/src/preprocessor/mod.rs b/crates/doc/src/preprocessor/mod.rs index 25ed4db231ae..5011b59a1b5e 100644 --- a/crates/doc/src/preprocessor/mod.rs +++ b/crates/doc/src/preprocessor/mod.rs @@ -1,7 +1,8 @@ //! Module containing documentation preprocessors. use crate::{Comments, Document}; -use std::{collections::HashMap, fmt::Debug, path::PathBuf}; +use alloy_primitives::map::HashMap; +use std::{fmt::Debug, path::PathBuf}; mod contract_inheritance; pub use contract_inheritance::{ContractInheritance, CONTRACT_INHERITANCE_ID}; diff --git a/crates/evm/core/src/backend/diagnostic.rs b/crates/evm/core/src/backend/diagnostic.rs index 109190a8fe59..df215508da1c 100644 --- a/crates/evm/core/src/backend/diagnostic.rs +++ b/crates/evm/core/src/backend/diagnostic.rs @@ -1,7 +1,6 @@ use crate::backend::LocalForkId; -use alloy_primitives::Address; +use alloy_primitives::{map::AddressHashMap, Address}; use itertools::Itertools; -use std::collections::HashMap; /// Represents possible diagnostic cases on revert #[derive(Clone, Debug)] @@ -21,7 +20,7 @@ pub enum RevertDiagnostic { impl RevertDiagnostic { /// Converts the diagnostic to a readable error message - pub fn to_error_msg(&self, labels: &HashMap) -> String { + pub fn to_error_msg(&self, labels: &AddressHashMap) -> String { let get_label = |addr: &Address| labels.get(addr).cloned().unwrap_or_else(|| addr.to_string()); diff --git a/crates/evm/core/src/fork/multi.rs b/crates/evm/core/src/fork/multi.rs index a39b543ea254..14fa59aafc1f 100644 --- a/crates/evm/core/src/fork/multi.rs +++ b/crates/evm/core/src/fork/multi.rs @@ -4,7 +4,7 @@ //! concurrently active pairs at once. use super::CreateFork; -use alloy_primitives::U256; +use alloy_primitives::{map::HashMap, U256}; use alloy_provider::network::{BlockResponse, HeaderResponse}; use alloy_transport::layers::RetryBackoffService; use foundry_common::provider::{ @@ -20,7 +20,6 @@ use futures::{ }; use revm::primitives::Env; use std::{ - collections::HashMap, fmt::{self, Write}, pin::Pin, sync::{ diff --git a/crates/evm/core/src/state_snapshot.rs b/crates/evm/core/src/state_snapshot.rs index 0f453b8c6710..3be1172aded5 100644 --- a/crates/evm/core/src/state_snapshot.rs +++ b/crates/evm/core/src/state_snapshot.rs @@ -1,7 +1,7 @@ //! Support for snapshotting different states -use alloy_primitives::U256; -use std::{collections::HashMap, ops::Add}; +use alloy_primitives::{map::HashMap, U256}; +use std::ops::Add; /// Represents all state snapshots #[derive(Clone, Debug)] diff --git a/crates/evm/evm/src/executors/fuzz/mod.rs b/crates/evm/evm/src/executors/fuzz/mod.rs index 775b7e73e060..cb57f205326a 100644 --- a/crates/evm/evm/src/executors/fuzz/mod.rs +++ b/crates/evm/evm/src/executors/fuzz/mod.rs @@ -1,7 +1,7 @@ use crate::executors::{Executor, RawCallResult}; use alloy_dyn_abi::JsonAbiExt; use alloy_json_abi::Function; -use alloy_primitives::{Address, Bytes, Log, U256}; +use alloy_primitives::{map::HashMap, Address, Bytes, Log, U256}; use eyre::Result; use foundry_common::evm::Breakpoints; use foundry_config::FuzzConfig; @@ -17,7 +17,7 @@ use foundry_evm_fuzz::{ use foundry_evm_traces::SparsedTraceArena; use indicatif::ProgressBar; use proptest::test_runner::{TestCaseError, TestError, TestRunner}; -use std::{cell::RefCell, collections::HashMap}; +use std::cell::RefCell; mod types; pub use types::{CaseOutcome, CounterExampleOutcome, FuzzOutcome}; diff --git a/crates/evm/evm/src/executors/fuzz/types.rs b/crates/evm/evm/src/executors/fuzz/types.rs index 081ff91129cf..f5399c5c3ac1 100644 --- a/crates/evm/evm/src/executors/fuzz/types.rs +++ b/crates/evm/evm/src/executors/fuzz/types.rs @@ -1,11 +1,10 @@ use crate::executors::RawCallResult; -use alloy_primitives::{Bytes, Log}; +use alloy_primitives::{map::HashMap, Bytes, Log}; use foundry_common::evm::Breakpoints; use foundry_evm_coverage::HitMaps; use foundry_evm_fuzz::FuzzCase; use foundry_evm_traces::SparsedTraceArena; use revm::interpreter::InstructionResult; -use std::collections::HashMap; /// Returned by a single fuzz in the case of a successful run #[derive(Debug)] diff --git a/crates/evm/evm/src/executors/invariant/replay.rs b/crates/evm/evm/src/executors/invariant/replay.rs index 177e1b55b26c..969f1587f27e 100644 --- a/crates/evm/evm/src/executors/invariant/replay.rs +++ b/crates/evm/evm/src/executors/invariant/replay.rs @@ -4,7 +4,7 @@ use super::{ }; use crate::executors::Executor; use alloy_dyn_abi::JsonAbiExt; -use alloy_primitives::Log; +use alloy_primitives::{map::HashMap, Log}; use eyre::Result; use foundry_common::{ContractsByAddress, ContractsByArtifact}; use foundry_evm_coverage::HitMaps; @@ -17,7 +17,7 @@ use indicatif::ProgressBar; use parking_lot::RwLock; use proptest::test_runner::TestError; use revm::primitives::U256; -use std::{collections::HashMap, sync::Arc}; +use std::sync::Arc; /// Replays a call sequence for collecting logs and traces. /// Returns counterexample to be used when the call sequence is a failed scenario. diff --git a/crates/evm/evm/src/executors/mod.rs b/crates/evm/evm/src/executors/mod.rs index 421880c0da1b..5e2acc98f5d0 100644 --- a/crates/evm/evm/src/executors/mod.rs +++ b/crates/evm/evm/src/executors/mod.rs @@ -11,7 +11,10 @@ use crate::inspectors::{ }; use alloy_dyn_abi::{DynSolValue, FunctionExt, JsonAbiExt}; use alloy_json_abi::Function; -use alloy_primitives::{Address, Bytes, Log, U256}; +use alloy_primitives::{ + map::{AddressHashMap, HashMap}, + Address, Bytes, Log, U256, +}; use alloy_sol_types::{sol, SolCall}; use foundry_evm_core::{ backend::{Backend, BackendError, BackendResult, CowBackend, DatabaseExt, GLOBAL_FAIL_SLOT}, @@ -32,7 +35,7 @@ use revm::{ SpecId, TxEnv, TxKind, }, }; -use std::{borrow::Cow, collections::HashMap}; +use std::borrow::Cow; mod builder; pub use builder::ExecutorBuilder; @@ -723,7 +726,7 @@ pub struct RawCallResult { /// The logs emitted during the call pub logs: Vec, /// The labels assigned to addresses during the call - pub labels: HashMap, + pub labels: AddressHashMap, /// The traces of the call pub traces: Option, /// The coverage info collected during the call diff --git a/crates/evm/evm/src/inspectors/stack.rs b/crates/evm/evm/src/inspectors/stack.rs index 30271910b95b..fc270564133a 100644 --- a/crates/evm/evm/src/inspectors/stack.rs +++ b/crates/evm/evm/src/inspectors/stack.rs @@ -2,7 +2,7 @@ use super::{ Cheatcodes, CheatsConfig, ChiselState, CoverageCollector, Fuzzer, LogCollector, TracingInspector, }; -use alloy_primitives::{Address, Bytes, Log, TxKind, U256}; +use alloy_primitives::{map::AddressHashMap, Address, Bytes, Log, TxKind, U256}; use foundry_cheatcodes::CheatcodesExecutor; use foundry_evm_core::{ backend::{update_state, DatabaseExt}, @@ -22,7 +22,6 @@ use revm::{ EvmContext, Inspector, }; use std::{ - collections::HashMap, ops::{Deref, DerefMut}, sync::Arc, }; @@ -243,7 +242,7 @@ macro_rules! call_inspectors_adjust_depth { /// The collected results of [`InspectorStack`]. pub struct InspectorData { pub logs: Vec, - pub labels: HashMap, + pub labels: AddressHashMap, pub traces: Option, pub coverage: Option, pub cheatcodes: Option, diff --git a/crates/evm/fuzz/src/lib.rs b/crates/evm/fuzz/src/lib.rs index 2930a6aa020c..276958ecf6fd 100644 --- a/crates/evm/fuzz/src/lib.rs +++ b/crates/evm/fuzz/src/lib.rs @@ -9,13 +9,16 @@ extern crate tracing; use alloy_dyn_abi::{DynSolValue, JsonAbiExt}; -use alloy_primitives::{Address, Bytes, Log}; +use alloy_primitives::{ + map::{AddressHashMap, HashMap}, + Address, Bytes, Log, +}; use foundry_common::{calc, contracts::ContractsByAddress, evm::Breakpoints}; use foundry_evm_coverage::HitMaps; use foundry_evm_traces::{CallTraceArena, SparsedTraceArena}; use itertools::Itertools; use serde::{Deserialize, Serialize}; -use std::{collections::HashMap, fmt, sync::Arc}; +use std::{fmt, sync::Arc}; pub use proptest::test_runner::{Config as FuzzConfig, Reason}; @@ -166,7 +169,7 @@ pub struct FuzzTestResult { pub logs: Vec, /// Labeled addresses - pub labeled_addresses: HashMap, + pub labeled_addresses: AddressHashMap, /// Exemplary traces for a fuzz run of the test function /// diff --git a/crates/evm/fuzz/src/strategies/calldata.rs b/crates/evm/fuzz/src/strategies/calldata.rs index b919c477f413..6d9c0340bdca 100644 --- a/crates/evm/fuzz/src/strategies/calldata.rs +++ b/crates/evm/fuzz/src/strategies/calldata.rs @@ -65,9 +65,8 @@ mod tests { use crate::{strategies::fuzz_calldata, FuzzFixtures}; use alloy_dyn_abi::{DynSolValue, JsonAbiExt}; use alloy_json_abi::Function; - use alloy_primitives::Address; + use alloy_primitives::{map::HashMap, Address}; use proptest::prelude::Strategy; - use std::collections::HashMap; #[test] fn can_fuzz_with_fixtures() { diff --git a/crates/evm/traces/src/lib.rs b/crates/evm/traces/src/lib.rs index 382e3d3ec051..dd4a8966481a 100644 --- a/crates/evm/traces/src/lib.rs +++ b/crates/evm/traces/src/lib.rs @@ -17,10 +17,12 @@ use revm_inspectors::tracing::{ use serde::{Deserialize, Serialize}; use std::{ borrow::Cow, - collections::{BTreeSet, HashMap}, + collections::BTreeSet, ops::{Deref, DerefMut}, }; +use alloy_primitives::map::HashMap; + pub use revm_inspectors::tracing::{ types::{ CallKind, CallLog, CallTrace, CallTraceNode, DecodedCallData, DecodedCallLog, diff --git a/crates/forge/bin/cmd/bind.rs b/crates/forge/bin/cmd/bind.rs index d5d23633243f..d8739b42d9f1 100644 --- a/crates/forge/bin/cmd/bind.rs +++ b/crates/forge/bin/cmd/bind.rs @@ -1,3 +1,4 @@ +use alloy_primitives::map::HashSet; use clap::{Parser, ValueHint}; use ethers_contract_abigen::{ Abigen, ContractFilter, ExcludeContracts, MultiAbigen, SelectContracts, @@ -244,7 +245,7 @@ impl BindArgs { } fn get_solmacrogen(&self, artifacts: &Path) -> Result { - let mut dup = std::collections::HashSet::::new(); + let mut dup = HashSet::::default(); let instances = self .get_json_files(artifacts)? .filter_map(|(name, path)| { diff --git a/crates/forge/bin/cmd/snapshot.rs b/crates/forge/bin/cmd/snapshot.rs index 20c5013ec450..0d7c2843a83f 100644 --- a/crates/forge/bin/cmd/snapshot.rs +++ b/crates/forge/bin/cmd/snapshot.rs @@ -1,5 +1,5 @@ use super::test; -use alloy_primitives::U256; +use alloy_primitives::{map::HashMap, U256}; use clap::{builder::RangedU64ValueParser, Parser, ValueHint}; use eyre::{Context, Result}; use forge::result::{SuiteTestResult, TestKindReport, TestOutcome}; @@ -7,7 +7,6 @@ use foundry_cli::utils::STATIC_FUZZ_SEED; use regex::Regex; use std::{ cmp::Ordering, - collections::HashMap, fs, io::{self, BufRead}, path::{Path, PathBuf}, diff --git a/crates/forge/bin/cmd/watch.rs b/crates/forge/bin/cmd/watch.rs index 19b37009fd6f..4cf7dbabe597 100644 --- a/crates/forge/bin/cmd/watch.rs +++ b/crates/forge/bin/cmd/watch.rs @@ -1,11 +1,11 @@ use super::{build::BuildArgs, doc::DocArgs, snapshot::GasSnapshotArgs, test::TestArgs}; +use alloy_primitives::map::HashSet; use clap::Parser; use eyre::Result; use foundry_cli::utils::{self, FoundryPathExt}; use foundry_config::Config; use parking_lot::Mutex; use std::{ - collections::HashSet, path::PathBuf, sync::{ atomic::{AtomicU8, Ordering}, @@ -265,7 +265,7 @@ pub async fn watch_test(args: TestArgs) -> Result<()> { filter.args().contract_pattern.is_some() || args.watch.run_all; - let last_test_files = Mutex::new(HashSet::::new()); + let last_test_files = Mutex::new(HashSet::::default()); let project_root = config.root.0.to_string_lossy().into_owned(); let config = args.watch.watchexec_config_with_override( || [&config.test, &config.src], diff --git a/crates/forge/src/progress.rs b/crates/forge/src/progress.rs index 8d047c4133d3..2b45d5513a94 100644 --- a/crates/forge/src/progress.rs +++ b/crates/forge/src/progress.rs @@ -1,7 +1,7 @@ +use alloy_primitives::map::HashMap; use indicatif::{MultiProgress, ProgressBar}; use parking_lot::Mutex; -use std::{collections::HashMap, sync::Arc, time::Duration}; - +use std::{sync::Arc, time::Duration}; /// State of [ProgressBar]s displayed for the given test run. /// Shows progress of all test suites matching filter. /// For each test within the test suite an individual progress bar is displayed. diff --git a/crates/forge/src/result.rs b/crates/forge/src/result.rs index 171a234a5ee0..1ec829f6bc94 100644 --- a/crates/forge/src/result.rs +++ b/crates/forge/src/result.rs @@ -4,7 +4,10 @@ use crate::{ fuzz::{BaseCounterExample, FuzzedCases}, gas_report::GasReport, }; -use alloy_primitives::{Address, Log}; +use alloy_primitives::{ + map::{AddressHashMap, HashMap}, + Address, Log, +}; use eyre::Report; use foundry_common::{evm::Breakpoints, get_contract_name, get_file_name, shell}; use foundry_evm::{ @@ -16,7 +19,7 @@ use foundry_evm::{ }; use serde::{Deserialize, Serialize}; use std::{ - collections::{BTreeMap, HashMap}, + collections::BTreeMap, fmt::{self, Write}, time::Duration, }; @@ -402,7 +405,7 @@ pub struct TestResult { pub coverage: Option, /// Labeled addresses - pub labeled_addresses: HashMap, + pub labeled_addresses: AddressHashMap, pub duration: Duration, @@ -738,7 +741,7 @@ pub struct TestSetup { /// Call traces of the setup pub traces: Traces, /// Addresses labeled during setup - pub labeled_addresses: HashMap, + pub labeled_addresses: AddressHashMap, /// The reason the setup failed, if it did pub reason: Option, /// Coverage info during setup @@ -752,7 +755,7 @@ impl TestSetup { error: EvmError, mut logs: Vec, mut traces: Traces, - mut labeled_addresses: HashMap, + mut labeled_addresses: AddressHashMap, ) -> Self { match error { EvmError::Execution(err) => { @@ -775,7 +778,7 @@ impl TestSetup { address: Address, logs: Vec, traces: Traces, - labeled_addresses: HashMap, + labeled_addresses: AddressHashMap, coverage: Option, fuzz_fixtures: FuzzFixtures, ) -> Self { @@ -785,7 +788,7 @@ impl TestSetup { pub fn failed_with( logs: Vec, traces: Traces, - labeled_addresses: HashMap, + labeled_addresses: AddressHashMap, reason: String, ) -> Self { Self { diff --git a/crates/linking/src/lib.rs b/crates/linking/src/lib.rs index c62c29e6c299..d0959ddb7d50 100644 --- a/crates/linking/src/lib.rs +++ b/crates/linking/src/lib.rs @@ -283,9 +283,8 @@ impl<'a> Linker<'a> { #[cfg(test)] mod tests { use super::*; - use alloy_primitives::fixed_bytes; + use alloy_primitives::{fixed_bytes, map::HashMap}; use foundry_compilers::{Project, ProjectCompileOutput, ProjectPathsConfig}; - use std::collections::HashMap; struct LinkerTest { project: Project, diff --git a/crates/script/src/broadcast.rs b/crates/script/src/broadcast.rs index ff4e4205ecfd..ac893b19f7aa 100644 --- a/crates/script/src/broadcast.rs +++ b/crates/script/src/broadcast.rs @@ -6,7 +6,11 @@ use alloy_chains::Chain; use alloy_consensus::TxEnvelope; use alloy_eips::eip2718::Encodable2718; use alloy_network::{AnyNetwork, EthereumWallet, TransactionBuilder}; -use alloy_primitives::{utils::format_units, Address, TxHash}; +use alloy_primitives::{ + map::{AddressHashMap, AddressHashSet}, + utils::format_units, + Address, TxHash, +}; use alloy_provider::{utils::Eip1559Estimation, Provider}; use alloy_rpc_types::TransactionRequest; use alloy_serde::WithOtherFields; @@ -22,10 +26,7 @@ use foundry_common::{ use foundry_config::Config; use futures::{future::join_all, StreamExt}; use itertools::Itertools; -use std::{ - collections::{HashMap, HashSet}, - sync::Arc, -}; +use std::sync::Arc; pub async fn estimate_gas( tx: &mut WithOtherFields, @@ -115,9 +116,9 @@ pub enum SendTransactionKind<'a> { /// Represents how to send _all_ transactions pub enum SendTransactionsKind { /// Send via `eth_sendTransaction` and rely on the `from` address being unlocked. - Unlocked(HashSet
), + Unlocked(AddressHashSet), /// Send a signed transaction via `eth_sendRawTransaction` - Raw(HashMap), + Raw(AddressHashMap), } impl SendTransactionsKind { @@ -199,7 +200,7 @@ impl BundledState { .sequences() .iter() .flat_map(|sequence| sequence.transactions().map(|tx| tx.from().expect("missing from"))) - .collect::>(); + .collect::(); if required_addresses.contains(&Config::DEFAULT_SENDER) { eyre::bail!( diff --git a/crates/script/src/execute.rs b/crates/script/src/execute.rs index 97324e5cb39c..a1b3cf6133fb 100644 --- a/crates/script/src/execute.rs +++ b/crates/script/src/execute.rs @@ -6,7 +6,10 @@ use crate::{ }; use alloy_dyn_abi::FunctionExt; use alloy_json_abi::{Function, InternalType, JsonAbi}; -use alloy_primitives::{Address, Bytes}; +use alloy_primitives::{ + map::{HashMap, HashSet}, + Address, Bytes, +}; use alloy_provider::Provider; use alloy_rpc_types::TransactionInput; use async_recursion::async_recursion; @@ -31,7 +34,6 @@ use foundry_evm::{ }; use futures::future::join_all; use itertools::Itertools; -use std::collections::{HashMap, HashSet}; use yansi::Paint; /// State after linking, contains the linked build data along with library addresses and optional diff --git a/crates/script/src/lib.rs b/crates/script/src/lib.rs index b7d4088d435c..8231a5d54b56 100644 --- a/crates/script/src/lib.rs +++ b/crates/script/src/lib.rs @@ -11,7 +11,11 @@ extern crate tracing; use self::transaction::AdditionalContract; use crate::runner::ScriptRunner; use alloy_json_abi::{Function, JsonAbi}; -use alloy_primitives::{hex, Address, Bytes, Log, TxKind, U256}; +use alloy_primitives::{ + hex, + map::{AddressHashMap, HashMap}, + Address, Bytes, Log, TxKind, U256, +}; use alloy_signer::Signer; use broadcast::next_nonce; use build::PreprocessedState; @@ -47,7 +51,6 @@ use foundry_evm::{ }; use foundry_wallets::MultiWalletOpts; use serde::{Deserialize, Serialize}; -use std::collections::HashMap; use yansi::Paint; mod broadcast; @@ -476,7 +479,7 @@ pub struct ScriptResult { pub logs: Vec, pub traces: Traces, pub gas_used: u64, - pub labeled_addresses: HashMap, + pub labeled_addresses: AddressHashMap, #[serde(skip)] pub transactions: Option, pub returned: Bytes, diff --git a/crates/script/src/progress.rs b/crates/script/src/progress.rs index 819ebca99438..b8bedb6cdbad 100644 --- a/crates/script/src/progress.rs +++ b/crates/script/src/progress.rs @@ -3,14 +3,17 @@ use crate::{ sequence::ScriptSequence, }; use alloy_chains::Chain; -use alloy_primitives::B256; +use alloy_primitives::{ + map::{B256HashMap, HashMap}, + B256, +}; use eyre::Result; use foundry_cli::utils::init_progress; use foundry_common::provider::RetryProvider; use futures::StreamExt; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use parking_lot::RwLock; -use std::{collections::HashMap, fmt::Write, sync::Arc, time::Duration}; +use std::{fmt::Write, sync::Arc, time::Duration}; use yansi::Paint; /// State of [ProgressBar]s displayed for the given [ScriptSequence]. @@ -23,7 +26,7 @@ pub struct SequenceProgressState { /// Progress var with the count of confirmed transactions. receipts: ProgressBar, /// Standalone spinners for pending transactions. - tx_spinners: HashMap, + tx_spinners: B256HashMap, /// Copy of the main [MultiProgress] instance. multi: MultiProgress, } diff --git a/crates/script/src/sequence.rs b/crates/script/src/sequence.rs index 8e2101155491..3c31773ba3ab 100644 --- a/crates/script/src/sequence.rs +++ b/crates/script/src/sequence.rs @@ -3,7 +3,7 @@ use crate::{ transaction::{AdditionalContract, TransactionWithMetadata}, verify::VerifyBundle, }; -use alloy_primitives::{hex, Address, TxHash}; +use alloy_primitives::{hex, map::HashMap, Address, TxHash}; use alloy_rpc_types::AnyTransactionReceipt; use eyre::{eyre, ContextCompat, Result, WrapErr}; use forge_verify::provider::VerificationProviderType; @@ -13,7 +13,7 @@ use foundry_compilers::ArtifactId; use foundry_config::Config; use serde::{Deserialize, Serialize}; use std::{ - collections::{HashMap, VecDeque}, + collections::VecDeque, io::{BufWriter, Write}, path::{Path, PathBuf}, }; diff --git a/crates/verify/src/sourcify.rs b/crates/verify/src/sourcify.rs index 81fadd09e5b7..bbb5e9f9eddc 100644 --- a/crates/verify/src/sourcify.rs +++ b/crates/verify/src/sourcify.rs @@ -2,13 +2,15 @@ use crate::{ provider::{VerificationContext, VerificationProvider}, verify::{VerifyArgs, VerifyCheckArgs}, }; +use alloy_primitives::map::HashMap; use async_trait::async_trait; use eyre::Result; use foundry_common::{fs, retry::Retry}; use futures::FutureExt; use reqwest::Url; +use revm_primitives::map::FxBuildHasher; use serde::{Deserialize, Serialize}; -use std::{collections::HashMap, str::FromStr}; +use std::str::FromStr; pub static SOURCIFY_URL: &str = "https://sourcify.dev/server/"; @@ -112,7 +114,8 @@ impl SourcifyVerificationProvider { let metadata = context.get_target_metadata()?; let imports = context.get_target_imports()?; - let mut files = HashMap::with_capacity(2 + imports.len()); + let mut files = + HashMap::with_capacity_and_hasher(2 + imports.len(), FxBuildHasher::default()); let metadata = serde_json::to_string_pretty(&metadata)?; files.insert("metadata.json".to_string(), metadata); diff --git a/crates/wallets/src/multi_wallet.rs b/crates/wallets/src/multi_wallet.rs index 459074aaa584..28c3e31a168d 100644 --- a/crates/wallets/src/multi_wallet.rs +++ b/crates/wallets/src/multi_wallet.rs @@ -2,14 +2,14 @@ use crate::{ utils, wallet_signer::{PendingSigner, WalletSigner}, }; -use alloy_primitives::Address; +use alloy_primitives::{map::AddressHashMap, Address}; use alloy_signer::Signer; use clap::Parser; use derive_builder::Builder; use eyre::Result; use foundry_config::Config; use serde::Serialize; -use std::{collections::HashMap, iter::repeat, path::PathBuf}; +use std::{iter::repeat, path::PathBuf}; /// Container for multiple wallets. #[derive(Debug, Default)] @@ -18,7 +18,7 @@ pub struct MultiWallet { /// Those are lazily unlocked on the first access of the signers. pending_signers: Vec, /// Contains unlocked signers. - signers: HashMap, + signers: AddressHashMap, } impl MultiWallet { @@ -35,12 +35,12 @@ impl MultiWallet { Ok(()) } - pub fn signers(&mut self) -> Result<&HashMap> { + pub fn signers(&mut self) -> Result<&AddressHashMap> { self.maybe_unlock_pending()?; Ok(&self.signers) } - pub fn into_signers(mut self) -> Result> { + pub fn into_signers(mut self) -> Result> { self.maybe_unlock_pending()?; Ok(self.signers) }