Skip to content

Commit 5bd034f

Browse files
authored
fix(forge): trace identify by creation code with stripped args (#10271)
1 parent 94ba51d commit 5bd034f

File tree

1 file changed

+14
-0
lines changed
  • crates/evm/traces/src/identifier

1 file changed

+14
-0
lines changed

crates/evm/traces/src/identifier/local.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::{AddressIdentity, TraceIdentifier};
2+
use alloy_dyn_abi::JsonAbiExt;
23
use alloy_json_abi::JsonAbi;
34
use alloy_primitives::Address;
45
use foundry_common::contracts::{bytecode_diff_score, ContractsByArtifact};
@@ -53,6 +54,19 @@ impl<'a> LocalTraceIdentifier<'a> {
5354
};
5455

5556
if let Some(bytecode) = contract_bytecode {
57+
let mut current_bytecode = current_bytecode;
58+
if is_creation && current_bytecode.len() > bytecode.len() {
59+
// Try to decode ctor args with contract abi.
60+
if let Some(constructor) = contract.abi.constructor() {
61+
let constructor_args = &current_bytecode[bytecode.len()..];
62+
if constructor.abi_decode_input(constructor_args, false).is_ok() {
63+
// If we can decode args with current abi then remove args from
64+
// code to compare.
65+
current_bytecode = &current_bytecode[..bytecode.len()]
66+
}
67+
}
68+
}
69+
5670
let score = bytecode_diff_score(bytecode, current_bytecode);
5771
if score == 0.0 {
5872
trace!(target: "evm::traces", "found exact match");

0 commit comments

Comments
 (0)