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
1 change: 0 additions & 1 deletion anvil/server/src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ impl tokio_util::codec::Decoder for JsonRpcCodec {
} else if is_whitespace(byte) {
whitespaces += 1;
}

is_escaped = byte == b'\\' && !is_escaped && in_str;

if depth == 0 && idx != start_idx && idx - start_idx + 1 > whitespaces {
Expand Down
22 changes: 9 additions & 13 deletions cli/src/cmd/cast/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,16 @@ impl RunArgs {
let mut etherscan_identifier =
EtherscanIdentifier::new(&config, evm_opts.get_remote_chain_id())?;

let labeled_addresses: BTreeMap<Address, String> = self
.label
.iter()
.filter_map(|label_str| {
let mut iter = label_str.split(':');

if let Some(addr) = iter.next() {
if let (Ok(address), Some(label)) = (Address::from_str(addr), iter.next()) {
return Some((address, label.to_string()))
}
let labeled_addresses = self.label.iter().filter_map(|label_str| {
let mut iter = label_str.split(':');

if let Some(addr) = iter.next() {
if let (Ok(address), Some(label)) = (Address::from_str(addr), iter.next()) {
return Some((address, label.to_string()))
}
None
})
.collect();
}
None
});

let mut decoder = CallTraceDecoderBuilder::new().with_labels(labeled_addresses).build();

Expand Down
2 changes: 1 addition & 1 deletion cli/src/cmd/forge/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ fn test(
// Identify addresses in each trace
let mut decoder = CallTraceDecoderBuilder::new()
.with_labels(result.labeled_addresses.clone())
.with_events(local_identifier.events())
.with_events(local_identifier.events().cloned())
.with_verbosity(verbosity)
.build();

Expand Down
6 changes: 3 additions & 3 deletions cli/src/cmd/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ mod tests {

#[test]
fn test_cli() {
let args = RetryArgs::parse_from(&["foundry-cli", "--retries", "10"]);
let args = RetryArgs::parse_from(["foundry-cli", "--retries", "10"]);
assert_eq!(args.retries, 10);
assert_eq!(args.delay, 5);

let args = RetryArgs::parse_from(&["foundry-cli", "--delay", "10"]);
let args = RetryArgs::parse_from(["foundry-cli", "--delay", "10"]);
assert_eq!(args.retries, 5);
assert_eq!(args.delay, 10);

let args = RetryArgs::parse_from(&["foundry-cli", "--retries", "10", "--delay", "10"]);
let args = RetryArgs::parse_from(["foundry-cli", "--retries", "10", "--delay", "10"]);
assert_eq!(args.retries, 10);
assert_eq!(args.delay, 10);
}
Expand Down
173 changes: 57 additions & 116 deletions evm/src/trace/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
};
use ethers::{
abi::{Abi, Address, Event, Function, Param, ParamType, Token},
types::H256,
types::{H160, H256},
};
use foundry_common::{abi::get_indexed_event, SELECTOR_LEN};
use hashbrown::HashSet;
Expand All @@ -28,24 +28,24 @@ impl CallTraceDecoderBuilder {
}

/// Add known labels to the decoder.
pub fn with_labels(mut self, labels: BTreeMap<Address, String>) -> Self {
for (address, label) in labels.into_iter() {
self.decoder.labels.insert(address, label);
}
pub fn with_labels(mut self, labels: impl IntoIterator<Item = (Address, String)>) -> Self {
self.decoder.labels.extend(labels);
self
}

/// Add known events to the decoder.
pub fn with_events(mut self, events: Vec<Event>) -> Self {
events
.into_iter()
.map(|event| ((event.signature(), indexed_inputs(&event)), event))
.for_each(|(sig, event)| {
self.decoder.events.entry(sig).or_default().push(event);
});
pub fn with_events(mut self, events: impl IntoIterator<Item = Event>) -> Self {
for event in events {
self.decoder
.events
.entry((event.signature(), indexed_inputs(&event)))
.or_default()
.push(event);
}
self
}

/// Sets the verbosity level of the decoder.
pub fn with_verbosity(mut self, level: u8) -> Self {
self.decoder.verbosity = level;
self
Expand Down Expand Up @@ -88,107 +88,72 @@ pub struct CallTraceDecoder {
pub verbosity: u8,
}

/// Returns an expression of the type `[(Address, Function); N]`
macro_rules! precompiles {
($($number:literal : $name:ident($( $name_in:ident : $in:expr ),* $(,)?) -> ($( $name_out:ident : $out:expr ),* $(,)?)),+ $(,)?) => {{
use std::string::String as RustString;
use ParamType::*;
[$(
(
H160([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, $number]),
#[allow(deprecated)]
Function {
name: RustString::from(stringify!($name)),
inputs: vec![$(Param { name: RustString::from(stringify!($name_in)), kind: $in, internal_type: None, }),*],
outputs: vec![$(Param { name: RustString::from(stringify!($name_out)), kind: $out, internal_type: None, }),*],
constant: None,
state_mutability: ethers::abi::StateMutability::Pure,
},
),
)+]
}};
}

impl CallTraceDecoder {
/// Creates a new call trace decoder.
///
/// The call trace decoder always knows how to decode calls to the cheatcode address, as well
/// as DSTest-style logs.
pub fn new() -> Self {
let functions = HARDHAT_CONSOLE_ABI
.functions()
.map(|func| (func.short_signature(), vec![func.clone()]))
.chain(HEVM_ABI.functions().map(|func| (func.short_signature(), vec![func.clone()])))
.collect::<BTreeMap<[u8; 4], Vec<Function>>>();

Self {
// TODO: These are the Ethereum precompiles. We should add a way to support precompiles
// for other networks, too.
precompiles: [
precompile(
1,
"ecrecover",
[
ParamType::FixedBytes(32),
ParamType::Uint(256),
ParamType::Uint(256),
ParamType::Uint(256),
],
[ParamType::Address],
),
precompile(2, "keccak", [ParamType::Bytes], [ParamType::FixedBytes(32)]),
precompile(3, "ripemd", [ParamType::Bytes], [ParamType::FixedBytes(32)]),
precompile(4, "identity", [ParamType::Bytes], [ParamType::Bytes]),
precompile(
5,
"modexp",
[
ParamType::Uint(256),
ParamType::Uint(256),
ParamType::Uint(256),
ParamType::Bytes,
],
[ParamType::Bytes],
),
precompile(
6,
"ecadd",
[
ParamType::Uint(256),
ParamType::Uint(256),
ParamType::Uint(256),
ParamType::Uint(256),
],
[ParamType::Uint(256), ParamType::Uint(256)],
),
precompile(
7,
"ecmul",
[ParamType::Uint(256), ParamType::Uint(256), ParamType::Uint(256)],
[ParamType::Uint(256), ParamType::Uint(256)],
),
precompile(
8,
"ecpairing",
[
ParamType::Uint(256),
ParamType::Uint(256),
ParamType::Uint(256),
ParamType::Uint(256),
ParamType::Uint(256),
ParamType::Uint(256),
],
[ParamType::Uint(256)],
),
precompile(
9,
"blake2f",
[
ParamType::Uint(4),
ParamType::FixedBytes(64),
ParamType::FixedBytes(128),
ParamType::FixedBytes(16),
ParamType::FixedBytes(1),
],
[ParamType::FixedBytes(64)],
),
]
.into(),
precompiles: precompiles!(
0x01: ecrecover(hash: FixedBytes(32), v: Uint(256), r: Uint(256), s: Uint(256)) -> (publicAddress: Address),
0x02: sha256(data: Bytes) -> (hash: FixedBytes(32)),
0x03: ripemd(data: Bytes) -> (hash: FixedBytes(32)),
0x04: identity(data: Bytes) -> (data: Bytes),
0x05: modexp(Bsize: Uint(256), Esize: Uint(256), Msize: Uint(256), BEM: Bytes) -> (value: Bytes),
0x06: ecadd(x1: Uint(256), y1: Uint(256), x2: Uint(256), y2: Uint(256)) -> (x: Uint(256), y: Uint(256)),
0x07: ecmul(x1: Uint(256), y1: Uint(256), s: Uint(256)) -> (x: Uint(256), y: Uint(256)),
0x08: ecpairing(x1: Uint(256), y1: Uint(256), x3: Uint(256), x2: Uint(256), y3: Uint(256), y2: Uint(256)) -> (success: Uint(256)),
0x09: blake2f(rounds: Uint(4), h: FixedBytes(64), m: FixedBytes(128), t: FixedBytes(16), f: FixedBytes(1)) -> (h: FixedBytes(64)),
).into(),

contracts: Default::default(),

labels: [
(CHEATCODE_ADDRESS, "VM".to_string()),
(HARDHAT_CONSOLE_ADDRESS, "console".to_string()),
(DEFAULT_CREATE2_DEPLOYER, "Create2Deployer".to_string()),
]
.into(),
functions,

functions: HARDHAT_CONSOLE_ABI
.functions()
.chain(HEVM_ABI.functions())
.map(|func| (func.short_signature(), vec![func.clone()]))
.collect(),

events: CONSOLE_ABI
.events()
.map(|event| ((event.signature(), indexed_inputs(event)), vec![event.clone()]))
.collect::<BTreeMap<(H256, usize), Vec<Event>>>(),
errors: Abi::default(),
.collect(),

errors: Default::default(),
signature_identifier: None,
receive_contracts: Default::default(),
verbosity: u8::default(),
verbosity: 0,
}
}

Expand Down Expand Up @@ -384,30 +349,6 @@ fn patch_nameless_params(event: &mut Event) -> HashSet<String> {
patches
}

fn precompile<I, O>(number: u8, name: impl ToString, inputs: I, outputs: O) -> (Address, Function)
where
I: IntoIterator<Item = ParamType>,
O: IntoIterator<Item = ParamType>,
{
(
Address::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, number]),
#[allow(deprecated)]
Function {
name: name.to_string(),
inputs: inputs
.into_iter()
.map(|kind| Param { name: "".to_string(), kind, internal_type: None })
.collect(),
outputs: outputs
.into_iter()
.map(|kind| Param { name: "".to_string(), kind, internal_type: None })
.collect(),
constant: None,
state_mutability: ethers::abi::StateMutability::Pure,
},
)
}

fn indexed_inputs(event: &Event) -> usize {
event.inputs.iter().filter(|param| param.indexed).count()
}
4 changes: 2 additions & 2 deletions evm/src/trace/identifier/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ impl LocalTraceIdentifier {
}

/// Get all the events of the local contracts.
pub fn events(&self) -> Vec<Event> {
self.local_contracts.iter().flat_map(|(_, (_, abi))| abi.events().cloned()).collect()
pub fn events(&self) -> impl Iterator<Item = &Event> {
self.local_contracts.iter().flat_map(|(_, (_, abi))| abi.events())
}
}

Expand Down
1 change: 0 additions & 1 deletion forge/src/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ impl<'a> CoverageReporter for LcovReporter<'a> {
}

/// A super verbose reporter for debugging coverage while it is still unstable.
#[derive(Default)]
pub struct DebugReporter;

impl CoverageReporter for DebugReporter {
Expand Down
5 changes: 2 additions & 3 deletions utils/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ pub fn abi_to_solidity(contract_abi: &RawAbi, mut contract_name: &str) -> eyre::
.collect::<eyre::Result<Vec<String>>>()?
.join(", ");

let event_final = format!("event {}({inputs})", event.name);

events.push(format!("{event_final};"));
let event_string = format!("event {}({inputs});", event.name);
events.push(event_string);
}

let mut functions = Vec::with_capacity(contract_abi.functions.len());
Expand Down