Skip to content

Commit

Permalink
chore: cargo fmt and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
dutterbutter committed Feb 2, 2025
1 parent 69baf89 commit 782d7f5
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 26 deletions.
4 changes: 2 additions & 2 deletions crates/core/src/trace/abi_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub fn coerce_value(ty: &str, arg: &str) -> Result<DynSolValue> {

#[cfg(test)]
mod tests {
use crate::trace::decode::{get_indexed_event_for_vm, vm_event_to_log_data};
use crate::trace::decode::{get_indexed_event_from_vm_event, vm_event_to_log_data};

use super::*;
use alloy::dyn_abi::EventExt;
Expand Down Expand Up @@ -178,7 +178,7 @@ mod tests {
};

// Convert the `Event` into its indexed form, matching the number of topics in `VmEvent`.
let updated_event = get_indexed_event_for_vm(event, &vm_event);
let updated_event = get_indexed_event_from_vm_event(event, &vm_event);
assert_eq!(updated_event.inputs.len(), 3);

// Now convert the VmEvent into a `LogData`
Expand Down
19 changes: 7 additions & 12 deletions crates/core/src/trace/decode/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Attribution: File adapted from the `evm` crate for zksync usage //
// Attribution: File adapted from the Foundry `evm` crate for ZKsync usage //
// //
// Full credit goes to its authors. See the original implementation here: //
// https://github.com/foundry-rs/foundry/blob/master/crates/evm/traces/src/decoder/mod.rs. //
Expand Down Expand Up @@ -67,11 +67,8 @@ impl CallTraceDecoderBuilder {

/// The call trace decoder.
///
/// The decoder collects address labels and ABIs which it
/// The decoder collects address labels which it
/// then uses to decode the call trace.
///
/// Note that a call trace decoder is required for each new set of traces, since addresses in
/// different sets might overlap.
#[derive(Clone, Debug, Default)]
pub struct CallTraceDecoder {
/// Addresses identified to be a specific contract.
Expand Down Expand Up @@ -262,7 +259,7 @@ impl CallTraceDecoder {
None
}

/// Decodes an event from zksync type VmEvent.
/// Decodes an event from ZKsync type VmEvent.
pub async fn decode_event(&self, vm_event: &VmEvent) -> DecodedCallEvent {
let Some(&t0) = vm_event.indexed_topics.first() else {
return DecodedCallEvent {
Expand All @@ -279,7 +276,7 @@ impl CallTraceDecoder {
None => {
if let Some(identifier) = &self.signature_identifier {
if let Some(event) = identifier.write().await.identify_event(&t0[..]).await {
events.push(get_indexed_event_for_vm(event, vm_event));
events.push(get_indexed_event_from_vm_event(event, vm_event));
}
}
&events
Expand Down Expand Up @@ -342,7 +339,7 @@ impl CallTraceDecoder {
}

/// Pretty-prints a value.
fn format_value(&self, value: &DynSolValue) -> String {
fn format_value(&self, value: &DynSolValue) -> String {
if let DynSolValue::Address(addr) = value {
match <[u8; 20]>::try_from(addr.0.as_slice()) {
Ok(raw_bytes_20) => {
Expand All @@ -356,7 +353,7 @@ impl CallTraceDecoder {
}
}
}

format_token(value, false)
}
}
Expand All @@ -382,19 +379,17 @@ fn reconstruct_params(event: &Event, decoded: &DecodedEvent) -> Vec<DynSolValue>

inputs
}

fn indexed_inputs_zksync(event: &VmEvent) -> usize {
event.indexed_topics.len()
}

fn indexed_inputs(event: &Event) -> usize {
event.inputs.iter().filter(|param| param.indexed).count()
}

/// Given an `Event` without indexed parameters and a `VmEvent`, it tries to
/// return the `Event` with the proper indexed parameters. Otherwise,
/// it returns the original `Event`.
pub fn get_indexed_event_for_vm(mut event: Event, vm_event: &VmEvent) -> Event {
pub fn get_indexed_event_from_vm_event(mut event: Event, vm_event: &VmEvent) -> Event {
if !event.anonymous && vm_event.indexed_topics.len() > 1 {
let indexed_params = vm_event.indexed_topics.len() - 1;
let num_inputs = event.inputs.len();
Expand Down
4 changes: 1 addition & 3 deletions crates/core/src/trace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub mod writer;

/// Decode a collection of call traces.
///
/// The traces will be decoded using the given decoder, if possible.
/// The traces will be decoded if possible using openchain.
pub async fn decode_trace_arena(
arena: &mut CallTraceArena,
decoder: &CallTraceDecoder,
Expand All @@ -40,12 +40,10 @@ pub fn build_call_trace_arena(
) -> CallTraceArena {
let mut arena = CallTraceArena::default();
let root_idx = 0;

// Update the root node's execution_result with the actual transaction result
if let Some(root_node) = arena.arena.get_mut(root_idx) {
root_node.trace.execution_result = tx_result.clone();
}

// Process calls and their subcalls
for call in calls {
process_call_and_subcalls(call, root_idx, 0, &mut arena.arena, &tx_result, verbosity);
Expand Down
12 changes: 6 additions & 6 deletions crates/core/src/trace/signatures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ impl CachedSignatures {
if path.is_file() {
read_json_file(&path)
.map_err(
|err| tracing::warn!(target: "evm::traces", ?path, ?err, "failed to read cache file"),
|err| tracing::warn!(target: "trace::signatures", ?path, ?err, "failed to read cache file"),
)
.unwrap_or_default()
} else {
if let Err(err) = std::fs::create_dir_all(cache_path) {
tracing::warn!(target: "evm::traces", "could not create signatures cache dir: {:?}", err);
tracing::warn!(target: "trace::signatures", "could not create signatures cache dir: {:?}", err);
}
Self::default()
}
Expand Down Expand Up @@ -73,7 +73,7 @@ impl SignaturesIdentifier {

let identifier = if let Some(cache_path) = cache_path {
let path = cache_path.join("signatures");
tracing::trace!(target: "evm::traces", ?path, "reading signature cache");
tracing::trace!(target: "trace::signatures", ?path, "reading signature cache");
let cached = CachedSignatures::load(cache_path);
Self {
cached,
Expand All @@ -97,13 +97,13 @@ impl SignaturesIdentifier {
if let Some(cached_path) = &self.cached_path {
if let Some(parent) = cached_path.parent() {
if let Err(err) = std::fs::create_dir_all(parent) {
tracing::warn!(target: "evm::traces", ?parent, ?err, "failed to create cache");
tracing::warn!(target: "trace::signatures", ?parent, ?err, "failed to create cache");
}
}
if let Err(err) = write_json_file(cached_path, &self.cached) {
tracing::warn!(target: "evm::traces", ?cached_path, ?err, "failed to flush signature cache");
tracing::warn!(target: "trace::signatures", ?cached_path, ?err, "failed to flush signature cache");
} else {
tracing::trace!(target: "evm::traces", ?cached_path, "flushed signature cache")
tracing::trace!(target: "trace::signatures", ?cached_path, "flushed signature cache")
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions crates/core/src/trace/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use zksync_multivm::interface::{Call, ExecutionResult, VmEvent, VmExecutionResul
use zksync_types::web3::Bytes;
use zksync_types::{Address, H160, H256};

// Note: duplicated types from existing formatter.rs
// TODO: duplicated types from existing formatter.rs
// will be consolidated pending feedback
#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
pub enum ContractType {
Expand Down Expand Up @@ -276,7 +276,7 @@ impl Default for CallTraceArena {
let root_node = CallTraceNode {
parent: None,
children: Vec::new(),
idx: 0, // Assuming root index is 0
idx: 0,
trace: CallTrace {
depth: 0,
success: true,
Expand Down Expand Up @@ -355,6 +355,7 @@ impl CallTraceArena {
}
}

/// A trait for displaying the execution result.
pub trait ExecutionResultDisplay {
fn display(&self) -> String;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/trace/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ impl<W: Write> TraceWriter<W> {
FarCallOpcode::Delegate => Some(" [delegatecall]"),
FarCallOpcode::Mimic => Some(" [mimiccall]"),
},
CallType::NearCall => Some("[nearcall]"), // TODO check if this is correct
CallType::NearCall => Some("[nearcall]"),
CallType::Create => unreachable!(), // Create calls are handled separately.
};

Expand Down

0 comments on commit 782d7f5

Please sign in to comment.