-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(deps): Move to Alloy ABI encoding/decoding & alloy types #5986
Changes from 1 commit
ee18e87
6c6aa4e
f33e414
a8bb5b0
adc2786
8bc67d2
65f0918
a54005a
2c70bd9
55ad9bf
94fb974
b3935cc
8737a52
988e756
5b8c207
bd2fbb3
3c3b35c
7484d3b
3adebd5
c44e796
b51f741
bb68371
079c879
d9207b2
efd0323
de459d4
8356303
bcb57a2
4d4255b
5f145b7
90d5b05
3ea011c
48832e5
2cefb6f
6bef6ad
170f5e6
d8e54b9
5b404e0
2dbe680
ea9b980
a1b7442
23e281d
bdc95bb
8507f92
e42aeba
dc05ee5
944174a
4b2f0ea
f297ace
403de57
ffcb558
2c64c3d
ef21ace
99c228d
ebf9523
92c6b5a
e3dfa8b
da9b483
adc940a
b1f5ff7
0dbcf71
0e2c954
4d9ea34
9b5c45c
1d1dc01
e50cc48
5ce86fe
5c37c4b
30b2295
cd25d3b
6c88473
fb7bd39
5500c14
e4e347a
823a6e3
27f107a
cf7fdce
371e817
4e4e4c1
bcd565f
bd3e506
f958758
963234d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,11 +9,9 @@ use crate::{ | |
trace::{node::CallTraceNode, utils}, | ||
CALLER, TEST_CONTRACT_ADDRESS, | ||
}; | ||
use alloy_primitives::FixedBytes; | ||
use ethers::{ | ||
abi::{Abi, Address, Event, Function, Param, ParamType, Token}, | ||
types::{H160, H256}, | ||
}; | ||
use alloy_primitives::{Address, FixedBytes, B256}; | ||
use alloy_dyn_abi::{DynSolType, DynSolValue}; | ||
use alloy_json_abi::{JsonAbi as Abi, Event, Function, Param}; | ||
use foundry_common::{abi::get_indexed_event, SELECTOR_LEN}; | ||
use foundry_utils::types::ToEthers; | ||
use hashbrown::HashSet; | ||
|
@@ -47,7 +45,7 @@ impl CallTraceDecoderBuilder { | |
for event in events { | ||
self.decoder | ||
.events | ||
.entry((event.signature(), indexed_inputs(&event))) | ||
.entry((event.selector(), indexed_inputs(&event))) | ||
.or_default() | ||
.push(event); | ||
} | ||
|
@@ -97,7 +95,7 @@ pub struct CallTraceDecoder { | |
/// A mapping of signatures to their known functions | ||
pub functions: BTreeMap<FixedBytes<4>, Vec<Function>>, | ||
/// All known events | ||
pub events: BTreeMap<(H256, usize), Vec<Event>>, | ||
pub events: BTreeMap<(B256, usize), Vec<Event>>, | ||
/// All known errors | ||
pub errors: Abi, | ||
/// A signature identifier for events and functions. | ||
|
@@ -110,17 +108,15 @@ pub struct CallTraceDecoder { | |
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]), | ||
Address::new([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, | ||
inputs: vec![$(Param { name: RustString::from(stringify!($name_in)), ty: $in, components: vec![], internal_type: None, }),*], | ||
outputs: vec![$(Param { name: RustString::from(stringify!($name_out)), ty: $out, components: vec![], internal_type: None, }),*], | ||
state_mutability: alloy_json_abi::StateMutability::Pure, | ||
}, | ||
), | ||
)+] | ||
|
@@ -144,25 +140,25 @@ impl CallTraceDecoder { | |
// TODO: These are the Ethereum precompiles. We should add a way to support precompiles | ||
// for other networks, too. | ||
precompiles: precompiles!( | ||
0x01: ecrecover(hash: FixedBytes(32), v: Uint(256), r: Uint(256), s: Uint(256)) -> (publicAddress: Address), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change looks a bit odd cc @DaniPopes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The whole point of this macro is to make it easy to modify. Slapping |
||
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), x2: Uint(256), y2: Uint(256), x3: Uint(256), y3: 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)), | ||
0x01: ecrecover(hash: format!("bytes32"), v: format!("uint256"), r: format!("uint256"), s: format!("uint256")) -> (publicAddress: format!("address")), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is very ugly and needs to be removed -- what's the plan for this? sol macro? let's pls track this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tracking on #6102 |
||
0x02: sha256(data: format!("bytes")) -> (hash: format!("bytes32")), | ||
0x03: ripemd(data: format!("bytes")) -> (hash: format!("bytes32")), | ||
0x04: identity(data: format!("bytes")) -> (data: format!("bytes")), | ||
0x05: modexp(Bsize: format!("uint256"), Esize: format!("uint256"), Msize: format!("uint256"), BEM: format!("bytes")) -> (value: format!("bytes")), | ||
0x06: ecadd(x1: format!("uint256"), y1: format!("uint256"), x2: format!("uint256"), y2: format!("uint256")) -> (x: format!("uint256"), y: format!("uint256")), | ||
0x07: ecmul(x1: format!("uint256"), y1: format!("uint256"), s: format!("uint256")) -> (x: format!("uint256"), y: format!("uint256")), | ||
0x08: ecpairing(x1: format!("uint256"), y1: format!("uint256"), x2: format!("uint256"), y2: format!("uint256"), x3: format!("uint256"), y3: format!("uint256")) -> (success: Uint(256)), | ||
0x09: blake2f(rounds: DynSolType::Uint(4).to_string(), h: DynSolType::FixedBytes(64).to_string(), m: DynSolType::FixedBytes(128).to_string(), t: DynSolType::FixedBytes(16).to_string(), f: DynSolType::FixedBytes(1).to_string()) -> (h: DynSolType::FixedBytes(64).to_string()), | ||
).into(), | ||
|
||
contracts: Default::default(), | ||
|
||
labels: [ | ||
(CHEATCODE_ADDRESS.to_ethers(), "VM".to_string()), | ||
(HARDHAT_CONSOLE_ADDRESS.to_ethers(), "console".to_string()), | ||
(DEFAULT_CREATE2_DEPLOYER.to_ethers(), "Create2Deployer".to_string()), | ||
(CALLER.to_ethers(), "DefaultSender".to_string()), | ||
(TEST_CONTRACT_ADDRESS.to_ethers(), "DefaultTestContract".to_string()), | ||
(CHEATCODE_ADDRESS, "VM".to_string()), | ||
(HARDHAT_CONSOLE_ADDRESS, "console".to_string()), | ||
(DEFAULT_CREATE2_DEPLOYER, "Create2Deployer".to_string()), | ||
(CALLER, "DefaultSender".to_string()), | ||
(TEST_CONTRACT_ADDRESS, "DefaultTestContract".to_string()), | ||
] | ||
.into(), | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,8 @@ use crate::{ | |
abi::CHEATCODE_ADDRESS, debug::Instruction, trace::identifier::LocalTraceIdentifier, CallKind, | ||
}; | ||
pub use decoder::{CallTraceDecoder, CallTraceDecoderBuilder}; | ||
use ethers::{ | ||
abi::{ethereum_types::BigEndianHash, Address, RawLog}, | ||
core::utils::to_checksum, | ||
types::{Bytes, DefaultFrame, GethDebugTracingOptions, StructLog, H256, U256}, | ||
}; | ||
use ethers::types::{DefaultFrame, GethDebugTracingOptions, StructLog}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These types should also go to alloy? I guess RPC crate under core/? Think good opportunity to get that started, along with the TxRequest/Response/Receipt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, we should move these to alloy somehow. Probably reth might have these somewhat reworked |
||
use alloy_primitives::{Address, B256, U256, Log as RawLog, Bytes}; | ||
pub use executor::TracingExecutor; | ||
use foundry_common::contracts::{ContractsByAddress, ContractsByArtifact}; | ||
use foundry_utils::types::{ToAlloy, ToEthers}; | ||
|
@@ -97,7 +94,7 @@ impl CallTraceArena { | |
// Recursively fill in the geth trace by going through the traces | ||
fn add_to_geth_trace( | ||
&self, | ||
storage: &mut HashMap<Address, BTreeMap<H256, H256>>, | ||
storage: &mut HashMap<Address, BTreeMap<B256, B256>>, | ||
trace_node: &CallTraceNode, | ||
struct_logs: &mut Vec<StructLog>, | ||
opts: &GethDebugTracingOptions, | ||
|
@@ -111,7 +108,7 @@ impl CallTraceArena { | |
if !opts.disable_storage.unwrap_or_default() { | ||
let contract_storage = storage.entry(step.contract).or_default(); | ||
if let Some((key, value)) = step.state_diff { | ||
contract_storage.insert(H256::from_uint(&key), H256::from_uint(&value)); | ||
contract_storage.insert(B256::from(key), B256::from(value)); | ||
log.storage = Some(contract_storage.clone()); | ||
} | ||
} | ||
|
@@ -275,7 +272,7 @@ impl fmt::Display for RawOrDecodedLog { | |
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match self { | ||
RawOrDecodedLog::Raw(log) => { | ||
for (i, topic) in log.topics.iter().enumerate() { | ||
for (i, topic) in log.topics().iter().enumerate() { | ||
writeln!( | ||
f, | ||
"{:>13}: {}", | ||
|
@@ -505,7 +502,7 @@ impl Default for CallTrace { | |
|
||
impl fmt::Display for CallTrace { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
let address = to_checksum(&self.address, None); | ||
let address = self.address.to_checksum(None); | ||
if self.created() { | ||
write!( | ||
f, | ||
|
@@ -543,7 +540,7 @@ impl fmt::Display for CallTrace { | |
self.gas_cost, | ||
color.paint(self.label.as_ref().unwrap_or(&address)), | ||
color.paint(func), | ||
if !self.value.is_zero() { | ||
if !self.value == U256::ZERO { | ||
DaniPopes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
format!("{{value: {}}}", self.value) | ||
} else { | ||
"".to_string() | ||
|
@@ -593,7 +590,7 @@ impl TraceKind { | |
|
||
/// Chooses the color of the trace depending on the destination address and status of the call. | ||
fn trace_color(trace: &CallTrace) -> Color { | ||
if trace.address == CHEATCODE_ADDRESS.to_ethers() { | ||
if trace.address == CHEATCODE_ADDRESS { | ||
Color::Blue | ||
} else if trace.success { | ||
Color::Green | ||
|
@@ -619,7 +616,7 @@ pub fn load_contracts( | |
.iter() | ||
.filter_map(|(addr, name)| { | ||
if let Ok(Some((_, (abi, _)))) = contracts.find_by_name_or_identifier(name) { | ||
return Some(((*addr).to_alloy(), (name.clone(), abi.clone()))) | ||
return Some((*addr, (name.clone(), abi.clone()))) | ||
} | ||
None | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Address::with_last_byte