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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ cairo-lang-starknet-classes = "2.12.0"
cairo-lang-parser = "2.12.0"
cairo-lang-sierra-to-casm = "2.12.0"
cairo-vm = "2.2.0"
cairo-annotations = "=0.5.0"
cairo-annotations = "0.5.1"
dirs = "6.0.0"
dialoguer = "0.11.0"
starknet-types-core = { version = "0.1.7", features = ["hash", "prime-bigint"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub fn execute_call_entry_point(
// We skip recursion depth validation here.
cheatnet_state
.trace_data
.enter_nested_call(entry_point.clone(), cheated_data);
.enter_nested_call(entry_point.clone(), cheated_data.clone());

if let Some(cheat_status) = get_mocked_function_cheat_status(entry_point, cheatnet_state)
&& let CheatStatus::Cheated(ret_data, _) = (*cheat_status).clone()
Expand All @@ -94,6 +94,8 @@ pub fn execute_call_entry_point(
},
&[],
None,
vec![],
vec![],
);
let tracked_resource = *context
.tracked_resource_stack
Expand Down Expand Up @@ -199,6 +201,7 @@ pub fn execute_call_entry_point(
context,
cheatnet_state,
vm_trace,
cheated_data.tx_info.signature.unwrap_or_default(),
);
Ok(call_info)
}
Expand Down Expand Up @@ -302,6 +305,7 @@ fn remove_syscall_resources_and_exit_non_error_call(
context: &mut EntryPointExecutionContext,
cheatnet_state: &mut CheatnetState,
vm_trace: Option<Vec<RelocatedTraceEntry>>,
signature: Vec<Felt>,
) {
let versioned_constants = context.tx_context.block_context.versioned_constants();
// We don't want the syscall resources to pollute the results
Expand Down Expand Up @@ -341,6 +345,8 @@ fn remove_syscall_resources_and_exit_non_error_call(
CallResult::from_non_error(call_info),
&call_info.execution.l2_to_l1_messages,
vm_trace,
signature,
call_info.execution.events.clone(),
);
}

Expand All @@ -362,6 +368,8 @@ fn exit_error_call(
CallResult::from_err(error, &identifier),
&[],
vm_trace,
vec![],
vec![],
);
}

Expand Down
10 changes: 9 additions & 1 deletion crates/cheatnet/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::runtime_extensions::forge_runtime_extension::cheatcodes::cheat_execut
};
use crate::runtime_extensions::forge_runtime_extension::cheatcodes::spy_events::Event;
use crate::runtime_extensions::forge_runtime_extension::cheatcodes::spy_messages_to_l1::MessageToL1;
use blockifier::execution::call_info::OrderedL2ToL1Message;
use blockifier::execution::call_info::{OrderedEvent, OrderedL2ToL1Message};
use blockifier::execution::contract_class::RunnableCompiledClass;
use blockifier::execution::entry_point::CallEntryPoint;
use blockifier::execution::syscalls::vm_syscall_utils::SyscallUsageMap;
Expand Down Expand Up @@ -219,6 +219,8 @@ pub struct CallTrace {
pub used_syscalls_sierra_gas: SyscallUsageMap,
pub vm_trace: Option<Vec<RelocatedTraceEntry>>,
pub gas_consumed: u64,
pub events: Vec<OrderedEvent>,
pub signature: Vec<Felt>,
}

impl CairoSerialize for CallTrace {
Expand Down Expand Up @@ -249,6 +251,8 @@ impl CallTrace {
result: CallResult::Success { ret_data: vec![] },
vm_trace: None,
gas_consumed: u64::default(),
events: vec![],
signature: vec![],
}
}

Expand Down Expand Up @@ -563,6 +567,8 @@ impl TraceData {
result: CallResult,
l2_to_l1_messages: &[OrderedL2ToL1Message],
vm_trace: Option<Vec<RelocatedTraceEntry>>,
signature: Vec<Felt>,
events: Vec<OrderedEvent>,
) {
let CallStackElement {
call_trace: last_call,
Expand All @@ -582,6 +588,8 @@ impl TraceData {

last_call.result = result;
last_call.vm_trace = vm_trace;
last_call.signature = signature;
last_call.events = events;
}

pub fn add_deploy_without_constructor_node(&mut self) {
Expand Down
32 changes: 27 additions & 5 deletions crates/forge-runner/src/build_trace_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ use blockifier::execution::syscalls::vm_syscall_utils::{
SyscallSelector, SyscallUsage, SyscallUsageMap,
};

use blockifier::execution::call_info::OrderedEvent;
use cairo_annotations::trace_data::{
CairoExecutionInfo, CallEntryPoint as ProfilerCallEntryPoint,
CallTraceNode as ProfilerCallTraceNode, CallTraceV1 as ProfilerCallTrace,
CallType as ProfilerCallType, CasmLevelInfo, ContractAddress,
DeprecatedSyscallSelector as ProfilerDeprecatedSyscallSelector,
EntryPointSelector as ProfilerEntryPointSelector, EntryPointType as ProfilerEntryPointType,
ExecutionResources as ProfilerExecutionResources, SyscallUsage as ProfilerSyscallUsage,
TraceEntry as ProfilerTraceEntry, VersionedCallTrace as VersionedProfilerCallTrace,
VmExecutionResources,
ExecutionResources as ProfilerExecutionResources, SummedUpEvent,
SyscallUsage as ProfilerSyscallUsage, TraceEntry as ProfilerTraceEntry,
VersionedCallTrace as VersionedProfilerCallTrace, VmExecutionResources,
};
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use cairo_vm::vm::trace::trace_entry::RelocatedTraceEntry;
Expand All @@ -27,6 +28,7 @@ use runtime::starknet::constants::{TEST_CONTRACT_CLASS_HASH, TEST_ENTRY_POINT_SE
use starknet::core::utils::get_selector_from_name;
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::{ClassHash, EntryPointSelector};
use starknet_types_core::felt::Felt;
use std::cell::RefCell;
use std::fs;
use std::path::PathBuf;
Expand All @@ -45,8 +47,13 @@ pub fn build_profiler_call_trace(
) -> ProfilerCallTrace {
let value = value.borrow();

let entry_point =
build_profiler_call_entry_point(value.entry_point.clone(), contracts_data, fork_data);
let entry_point = build_profiler_call_entry_point(
value.entry_point.clone(),
contracts_data,
fork_data,
&value.events,
&value.signature,
);
let vm_trace = value
.vm_trace
.as_ref()
Expand Down Expand Up @@ -160,6 +167,8 @@ pub fn build_profiler_call_entry_point(
value: CallEntryPoint,
contracts_data: &ContractsData,
fork_data: &ForkData,
events: &[OrderedEvent],
signature: &[Felt],
) -> ProfilerCallEntryPoint {
let CallEntryPoint {
class_hash,
Expand All @@ -174,6 +183,7 @@ pub fn build_profiler_call_entry_point(
let contract_name = get_contract_name(class_hash, contracts_data);
let function_name = get_function_name(&entry_point_selector, contracts_data, fork_data);
let calldata_len = calldata.0.len();
let signature_len = signature.len();

ProfilerCallEntryPoint {
class_hash: class_hash.map(|ch| cairo_annotations::trace_data::ClassHash(ch.0)),
Expand All @@ -184,6 +194,8 @@ pub fn build_profiler_call_entry_point(
contract_name,
function_name,
calldata_len: Some(calldata_len),
events_summary: Some(to_summed_up_events(events)),
signature_len: Some(signature_len),
}
}

Expand Down Expand Up @@ -344,3 +356,13 @@ pub fn save_trace_data(
.context("Failed to write call trace to a file")?;
Ok(dir_to_save_trace.join(&filename))
}

fn to_summed_up_events(events: &[OrderedEvent]) -> Vec<SummedUpEvent> {
events
.iter()
.map(|ev| SummedUpEvent {
keys_len: ev.event.keys.len(),
data_len: ev.event.data.0.len(),
})
.collect()
}
Loading