Skip to content

Commit 3a01a97

Browse files
committed
Merge branch 'master' into klkvr/internal-fns-in-traces
2 parents 7976e27 + 539742e commit 3a01a97

File tree

14 files changed

+167
-174
lines changed

14 files changed

+167
-174
lines changed

Cargo.lock

Lines changed: 108 additions & 108 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ solang-parser = "=0.3.3"
155155
# no default features to avoid c-kzg
156156
revm = { version = "10.0.0", default-features = false }
157157
revm-primitives = { version = "5.0.0", default-features = false }
158-
revm-inspectors = { version = "0.2", features = ["serde"] }
158+
revm-inspectors = { version = "0.3", features = ["serde"] }
159159

160160
## ethers
161161
ethers-contract-abigen = { version = "2.0.14", default-features = false }

crates/anvil/src/eth/otterscan/types.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,13 @@ impl OtsInternalOperation {
306306
};
307307
let mut from = node.trace.caller;
308308
let mut to = node.trace.address;
309+
let mut value = node.trace.value;
309310
if node.is_selfdestruct() {
310311
from = node.trace.address;
311312
to = node.trace.selfdestruct_refund_target.unwrap_or_default();
313+
value = node.trace.selfdestruct_transferred_value.unwrap_or_default();
312314
}
313-
Some(Self { r#type, from, to, value: node.trace.value })
315+
Some(Self { r#type, from, to, value })
314316
})
315317
.collect()
316318
}

crates/cast/bin/cmd/wallet/vanity.rs

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use alloy_primitives::{hex, Address};
22
use alloy_signer::{k256::ecdsa::SigningKey, utils::secret_key_to_address};
33
use alloy_signer_local::PrivateKeySigner;
4-
use clap::{builder::TypedValueParser, Parser};
4+
use clap::Parser;
55
use eyre::Result;
6+
use itertools::Either;
67
use rayon::iter::{self, ParallelIterator};
78
use regex::Regex;
89
use serde::{Deserialize, Serialize};
@@ -19,16 +20,11 @@ pub type GeneratedWallet = (SigningKey, Address);
1920
#[derive(Clone, Debug, Parser)]
2021
pub struct VanityArgs {
2122
/// Prefix regex pattern or hex string.
22-
#[arg(
23-
long,
24-
required_unless_present = "ends_with",
25-
value_parser = HexAddressValidator,
26-
value_name = "HEX"
27-
)]
23+
#[arg(long, value_name = "PATTERN", required_unless_present = "ends_with")]
2824
pub starts_with: Option<String>,
2925

3026
/// Suffix regex pattern or hex string.
31-
#[arg(long, value_parser = HexAddressValidator, value_name = "HEX")]
27+
#[arg(long, value_name = "PATTERN")]
3228
pub ends_with: Option<String>,
3329

3430
// 2^64-1 is max possible nonce per [eip-2681](https://eips.ethereum.org/EIPS/eip-2681).
@@ -74,24 +70,22 @@ impl WalletData {
7470
impl VanityArgs {
7571
pub fn run(self) -> Result<PrivateKeySigner> {
7672
let Self { starts_with, ends_with, nonce, save_path } = self;
73+
7774
let mut left_exact_hex = None;
7875
let mut left_regex = None;
79-
let mut right_exact_hex = None;
80-
let mut right_regex = None;
81-
8276
if let Some(prefix) = starts_with {
83-
if let Ok(decoded) = hex::decode(&prefix) {
84-
left_exact_hex = Some(decoded)
85-
} else {
86-
left_regex = Some(Regex::new(&format!(r"^{prefix}"))?);
77+
match parse_pattern(&prefix, true)? {
78+
Either::Left(left) => left_exact_hex = Some(left),
79+
Either::Right(re) => left_regex = Some(re),
8780
}
8881
}
8982

83+
let mut right_exact_hex = None;
84+
let mut right_regex = None;
9085
if let Some(suffix) = ends_with {
91-
if let Ok(decoded) = hex::decode(&suffix) {
92-
right_exact_hex = Some(decoded)
93-
} else {
94-
right_regex = Some(Regex::new(&format!(r"{suffix}$"))?);
86+
match parse_pattern(&suffix, false)? {
87+
Either::Left(right) => right_exact_hex = Some(right),
88+
Either::Right(re) => right_regex = Some(re),
9589
}
9690
}
9791

@@ -331,29 +325,15 @@ impl VanityMatcher for RegexMatcher {
331325
}
332326
}
333327

334-
/// Parse 40 byte addresses
335-
#[derive(Clone, Copy, Debug, Default)]
336-
pub struct HexAddressValidator;
337-
338-
impl TypedValueParser for HexAddressValidator {
339-
type Value = String;
340-
341-
fn parse_ref(
342-
&self,
343-
_cmd: &clap::Command,
344-
_arg: Option<&clap::Arg>,
345-
value: &std::ffi::OsStr,
346-
) -> Result<Self::Value, clap::Error> {
347-
if value.len() > 40 {
348-
return Err(clap::Error::raw(
349-
clap::error::ErrorKind::InvalidValue,
350-
"vanity patterns length exceeded. cannot be more than 40 characters",
351-
))
328+
fn parse_pattern(pattern: &str, is_start: bool) -> Result<Either<Vec<u8>, Regex>> {
329+
if let Ok(decoded) = hex::decode(pattern) {
330+
if decoded.len() > 20 {
331+
return Err(eyre::eyre!("Hex pattern must be less than 20 bytes"));
352332
}
353-
let value = value.to_str().ok_or_else(|| {
354-
clap::Error::raw(clap::error::ErrorKind::InvalidUtf8, "address must be valid utf8")
355-
})?;
356-
Ok(value.to_string())
333+
Ok(Either::Left(decoded))
334+
} else {
335+
let (prefix, suffix) = if is_start { ("^", "") } else { ("", "$") };
336+
Ok(Either::Right(Regex::new(&format!("{prefix}{pattern}{suffix}"))?))
357337
}
358338
}
359339

crates/debugger/src/tui/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<'a> DebuggerContext<'a> {
129129

130130
fn active_buffer(&self) -> &[u8] {
131131
match self.active_buffer {
132-
BufferKind::Memory => self.current_step().memory.as_bytes(),
132+
BufferKind::Memory => self.current_step().memory.as_ref().unwrap().as_bytes(),
133133
BufferKind::Calldata => &self.debug_call().calldata,
134134
BufferKind::Returndata => &self.current_step().returndata,
135135
}

crates/debugger/src/tui/draw.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ impl DebuggerContext<'_> {
452452
let call = self.debug_call();
453453
let step = self.current_step();
454454
let buf = match self.active_buffer {
455-
BufferKind::Memory => step.memory.as_ref(),
455+
BufferKind::Memory => step.memory.as_ref().unwrap().as_ref(),
456456
BufferKind::Calldata => call.calldata.as_ref(),
457457
BufferKind::Returndata => step.returndata.as_ref(),
458458
};

crates/evm/evm/src/inspectors/stack.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,11 @@ impl InspectorStack {
407407
/// Set whether to enable the tracer.
408408
#[inline]
409409
pub fn tracing(&mut self, mode: TraceMode) {
410-
self.tracer = mode.into_config().map(TracingInspector::new);
410+
if let Some(config) = mode.into_config() {
411+
*self.tracer.get_or_insert_with(Default::default).config_mut() = config;
412+
} else {
413+
self.tracer = None;
414+
}
411415
}
412416

413417
/// Collects all the data gathered during inspection into a single struct.
@@ -424,13 +428,14 @@ impl InspectorStack {
424428
.as_ref()
425429
.map(|cheatcodes| cheatcodes.labels.clone())
426430
.unwrap_or_default(),
427-
traces: tracer.map(|tracer| tracer.get_traces().clone()),
431+
traces: tracer.map(|tracer| tracer.into_traces()),
428432
coverage: coverage.map(|coverage| coverage.maps),
429433
cheatcodes,
430434
chisel_state: chisel_state.and_then(|state| state.state),
431435
}
432436
}
433437

438+
#[inline(always)]
434439
fn as_mut(&mut self) -> InspectorStackRefMut<'_> {
435440
InspectorStackRefMut { cheatcodes: self.cheatcodes.as_mut(), inner: &mut self.inner }
436441
}

crates/evm/traces/src/debug/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ fn try_decode_args_from_step(args: &Parameters<'_>, step: &CallTraceStep) -> Opt
281281
(DynSolType::Uint(8), Some(Storage::Memory | Storage::Storage)) => None,
282282
(_, Some(Storage::Memory)) => decode_from_memory(
283283
type_,
284-
step.memory.as_bytes(),
284+
step.memory.as_ref().unwrap().as_bytes(),
285285
input.try_into().ok()?,
286286
),
287287
// Read other types from stack

crates/evm/traces/src/decoder/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ impl CallTraceDecoder {
589589

590590
let events_it = nodes
591591
.iter()
592-
.flat_map(|node| node.logs.iter().filter_map(|log| log.topics().first()))
592+
.flat_map(|node| node.logs.iter().filter_map(|log| log.raw_log.topics().first()))
593593
.unique();
594594
identifier.write().await.identify_events(events_it).await;
595595

crates/evm/traces/src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,23 @@ pub async fn render_trace_arena(
108108
let child = &node.ordering[ordering_idx];
109109
match child {
110110
TraceMemberOrder::Log(index) => {
111-
let log = render_trace_log(&node.logs[*index], decoder).await?;
111+
let log = render_trace_log(&node.logs[*index].raw_log, decoder).await?;
112112

113113
// Prepend our tree structure symbols to each line of the displayed log
114114
log.lines().enumerate().try_for_each(|(i, line)| {
115-
writeln!(s, "{}{}", if i == 0 { left } else { right }, line)
115+
writeln!(
116+
s,
117+
"{}{}",
118+
if i == 0 { left } else { right },
119+
line
120+
)
116121
})?;
117122
}
118123
TraceMemberOrder::Call(index) => {
119124
inner(
120125
arena,
121126
decoder,
122-
identified_internals,
127+
&identified_internals,
123128
s,
124129
node.children[*index],
125130
left,

crates/forge/src/runner.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,18 +307,19 @@ impl<'a> ContractRunner<'a> {
307307
});
308308

309309
// Invariant testing requires tracing to figure out what contracts were created.
310+
// We also want to disable `debug` for setup since we won't be using those traces.
310311
let has_invariants = self.contract.abi.functions().any(|func| func.is_invariant_test());
311-
let tmp_tracing =
312-
self.executor.inspector().tracer.is_none() && has_invariants && call_setup;
313-
if tmp_tracing {
312+
313+
let prev_tracer = self.executor.inspector_mut().tracer.take();
314+
if prev_tracer.is_some() || has_invariants {
314315
self.executor.set_tracing(TraceMode::Call);
315316
}
317+
316318
let setup_time = Instant::now();
317319
let setup = self.setup(call_setup);
318320
debug!("finished setting up in {:?}", setup_time.elapsed());
319-
if tmp_tracing {
320-
self.executor.set_tracing(TraceMode::None);
321-
}
321+
322+
self.executor.inspector_mut().tracer = prev_tracer;
322323

323324
if setup.reason.is_some() {
324325
// The setup failed, so we return a single test result for `setUp`

crates/forge/tests/fixtures/can_test_repeatedly.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ No files changed, compilation skipped
22

33
Ran 2 tests for test/Counter.t.sol:CounterTest
44
[PASS] testFuzz_SetNumber(uint256) (runs: 256, μ: 26521, ~: 28387)
5-
[PASS] test_Increment() (gas: 31325)
5+
[PASS] test_Increment() (gas: 31303)
66
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 9.42ms
77

88
Ran 1 test suite: 2 tests passed, 0 failed, 0 skipped (2 total tests)

crates/forge/tests/fixtures/include_custom_types_in_traces.stdout

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ Solc 0.8.23 finished in 798.51ms
33
Compiler run successful!
44

55
Ran 2 tests for test/Contract.t.sol:CustomTypesTest
6-
[FAIL. Reason: PoolNotInitialized()] testErr() (gas: 231)
6+
[FAIL. Reason: PoolNotInitialized()] testErr() (gas: 254)
77
Traces:
8-
[231] CustomTypesTest::testErr()
8+
[254] CustomTypesTest::testErr()
99
└─ ← [Revert] PoolNotInitialized()
1010

11-
[PASS] testEvent() (gas: 1312)
11+
[PASS] testEvent() (gas: 1268)
1212
Traces:
13-
[1312] CustomTypesTest::testEvent()
13+
[1268] CustomTypesTest::testEvent()
1414
├─ emit MyEvent(a: 100)
1515
└─ ← [Stop]
1616

@@ -20,6 +20,6 @@ Ran 1 test suite: 1 tests passed, 1 failed, 0 skipped (2 total tests)
2020

2121
Failing tests:
2222
Encountered 1 failing test in test/Contract.t.sol:CustomTypesTest
23-
[FAIL. Reason: PoolNotInitialized()] testErr() (gas: 231)
23+
[FAIL. Reason: PoolNotInitialized()] testErr() (gas: 254)
2424

2525
Encountered a total of 1 failing tests, 1 tests succeeded

crates/forge/tests/fixtures/repro_6531.stdout

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Compiling 1 files with 0.8.23
33
Compiler run successful!
44

55
Ran 1 test for test/Contract.t.sol:USDTCallingTest
6-
[PASS] test() (gas: 9559)
6+
[PASS] test() (gas: 9537)
77
Traces:
8-
[9559] USDTCallingTest::test()
8+
[9537] USDTCallingTest::test()
99
├─ [0] VM::createSelectFork("<url>")
1010
│ └─ ← [Return] 0
1111
├─ [3110] 0xdAC17F958D2ee523a2206206994597C13D831ec7::name() [staticcall]

0 commit comments

Comments
 (0)