Skip to content

Commit a8a3e7f

Browse files
committed
Merge branch 'master' into 2714-cairo-native
# Conflicts: # crates/forge/tests/e2e/fuzzing.rs # crates/forge/tests/e2e/running.rs
2 parents 403eb8e + 0618a5d commit a8a3e7f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+2008
-924
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
- `Fuzzable` trait implementations for `bool` and `ContractAddress`
1515
- Type aliases for `StarkCurveKeyPair`, `Secp256k1CurveKeyPair`, `Secp256r1CurveKeyPair`
16+
- Option to display L2 gas for each call in the debugging trace
1617

1718
#### Changed
1819

1920
- Updated the error message returned when calling a nonexistent method on a contract to better align with the format used by the network
2021
- Oracle support in `snforge` is now stable and no longer requires the `--experimental-oracles` CLI flag
22+
- The default tracked resource is now Sierra gas, so gas reporting results may differ compared to previous versions. For more information refer to the [documentation](https://foundry-rs.github.io/starknet-foundry/testing/gas-and-resource-estimation.html)
23+
- When using the `--detailed-resources` flag, the used Sierra gas key is now shown as `sierra gas` instead of `sierra_gas_consumption`
2124

2225
### Cast
2326

@@ -28,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2831
- Possibility to use [`starknet-devnet`](https://github.com/0xSpaceShard/starknet-devnet) predeployed accounts directly in `sncast` without needing to import them. They are available under specific names - `devnet-1`, `devnet-2`, ..., `devnet-<N>`. Read more [here](https://foundry-rs.github.io/starknet-foundry/starknet/integration_with_devnet.html#predeployed-accounts)
2932
- Support for `--network devnet` flag that attempts to auto-detect running `starknet-devnet` instance and connect to it.
3033
- Support for automatically declaring the contract when running `sncast deploy`, by providing `--contract-name` flag instead of `--class-hash`.
34+
- `sncast balance` command to fetch the balance of an account for a specified token.
3135

3236
## [0.50.0] - 2025-09-29
3337

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ license-file = "LICENSE"
3535

3636
[workspace.dependencies]
3737
# TODO(#3770) Use blockifier directly
38-
blockifier = { git = "https://github.com/software-mansion-labs/sequencer.git", branch = "main-v0.14.0", features = ["testing", "tracing"] }
38+
blockifier = { git = "https://github.com/software-mansion-labs/sequencer.git", branch = "main-v0.14.0", features = ["testing", "tracing", "node_api"] }
3939
bigdecimal = "0.4.8"
4040
# TODO(#3770) Use starknet_api directly
4141
starknet_api = { git = "https://github.com/software-mansion-labs/sequencer.git", branch = "main-v0.14.0" }
@@ -95,7 +95,7 @@ snapbox = "0.4.17"
9595
scarb-ui = "0.1.7"
9696
semver = "1.0.27"
9797
bimap = "0.6.3"
98-
primitive-types = "0.13.1"
98+
primitive-types = { version = "0.13.1", features = ["serde"] }
9999
shellexpand = "3.1.0"
100100
toml = "0.8.20"
101101
rpassword = "7.3.1"

crates/cheatnet/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ pub mod predeployment;
66
pub mod runtime_extensions;
77
pub mod state;
88
pub mod sync_client;
9+
pub mod trace_data;

crates/cheatnet/src/runtime_extensions/call_to_blockifier_runtime_extension/execution/execution_utils.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use blockifier::execution::call_info::CallInfo;
1010
use blockifier::execution::entry_point::{CallEntryPoint, CallType, ExecutableCallEntryPoint};
1111
use blockifier::execution::errors::EntryPointExecutionError;
1212
use blockifier::execution::syscalls::vm_syscall_utils::SyscallUsageMap;
13-
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
1413

1514
pub(crate) fn resolve_cheated_data_for_call(
1615
entry_point: &mut CallEntryPoint,
@@ -75,14 +74,11 @@ pub(crate) fn exit_error_call(
7574
CallType::Call => AddressOrClassHash::ContractAddress(entry_point.storage_address),
7675
CallType::Delegate => AddressOrClassHash::ClassHash(entry_point.class_hash),
7776
};
78-
cheatnet_state.trace_data.update_and_exit_nested_call(
79-
ExecutionResources::default(),
80-
u64::default(),
81-
SyscallUsageMap::default(),
82-
SyscallUsageMap::default(),
83-
CallResult::from_err(error, &identifier),
84-
&[],
85-
vec![],
86-
vec![],
87-
);
77+
let trace_data = &mut cheatnet_state.trace_data;
78+
79+
// In case of a revert, clear all events and messages emitted by the current call.
80+
trace_data.clear_current_call_events_and_messages();
81+
82+
trace_data.update_current_call_result(CallResult::from_err(error, &identifier));
83+
trace_data.exit_nested_call();
8884
}

crates/cheatnet/src/runtime_extensions/forge_runtime_extension/mod.rs

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ use crate::runtime_extensions::{
1717
storage::{calculate_variable_address, load, store},
1818
},
1919
};
20-
use crate::state::{CallTrace, CallTraceNode};
20+
use crate::trace_data::{CallTrace, CallTraceNode, GasReportData};
2121
use anyhow::{Context, Result, anyhow};
2222
use blockifier::bouncer::vm_resources_to_sierra_gas;
2323
use blockifier::context::TransactionContext;
24-
use blockifier::execution::call_info::CallInfo;
24+
use blockifier::execution::call_info::{
25+
CallInfo, CallSummary, ChargedResources, EventSummary, ExecutionSummary, OrderedEvent,
26+
};
2527
use blockifier::execution::contract_class::TrackedResource;
2628
use blockifier::execution::syscalls::vm_syscall_utils::{SyscallSelector, SyscallUsageMap};
2729
use blockifier::state::errors::StateError;
30+
use blockifier::utils::u64_from_usize;
2831
use cairo_vm::vm::runners::cairo_runner::CairoRunner;
2932
use cairo_vm::vm::{
3033
errors::hint_errors::HintError, runners::cairo_runner::ExecutionResources,
@@ -42,10 +45,11 @@ use runtime::{
4245
};
4346
use scarb_oracle_hint_service::OracleHintService;
4447
use starknet::signers::SigningKey;
48+
use starknet_api::execution_resources::GasAmount;
4549
use starknet_api::{contract_class::EntryPointType::L1Handler, core::ClassHash};
4650
use starknet_types_core::felt::Felt;
4751
use std::cell::RefCell;
48-
use std::collections::HashMap;
52+
use std::collections::{HashMap, HashSet};
4953
use std::rc::Rc;
5054
use std::sync::{Arc, Mutex};
5155

@@ -738,6 +742,65 @@ pub fn update_top_call_vm_trace(runtime: &mut ForgeRuntime, cairo_runner: &mut C
738742
}
739743
}
740744

745+
pub fn compute_and_store_execution_summary(trace: &Rc<RefCell<CallTrace>>) {
746+
let execution_summary = if trace.borrow().nested_calls.is_empty() {
747+
get_execution_summary_without_nested_calls(trace)
748+
} else {
749+
let mut nested_calls_summaries = vec![];
750+
for nested_call in &trace.borrow().nested_calls {
751+
if let CallTraceNode::EntryPointCall(nested_call) = nested_call {
752+
compute_and_store_execution_summary(nested_call);
753+
nested_calls_summaries.push(
754+
nested_call
755+
.borrow()
756+
.gas_report_data
757+
.as_ref()
758+
.expect("Gas report data must be set after calling `compute_and_store_execution_summary`")
759+
.execution_summary
760+
.clone());
761+
}
762+
}
763+
let mut current_call_summary = get_execution_summary_without_nested_calls(trace)
764+
+ nested_calls_summaries.into_iter().sum();
765+
766+
// vm_resources and gas_consumed of a call already contain the resources of its inner calls.
767+
current_call_summary.charged_resources.vm_resources =
768+
trace.borrow().used_execution_resources.clone();
769+
current_call_summary.charged_resources.gas_consumed =
770+
GasAmount(trace.borrow().gas_consumed);
771+
current_call_summary
772+
};
773+
774+
trace.borrow_mut().gas_report_data = Some(GasReportData::new(execution_summary.clone()));
775+
}
776+
777+
// Based on blockifier/src/execution/call_info.rs (summarize)
778+
fn get_execution_summary_without_nested_calls(trace: &Rc<RefCell<CallTrace>>) -> ExecutionSummary {
779+
let current_call = trace.borrow();
780+
ExecutionSummary {
781+
charged_resources: ChargedResources {
782+
vm_resources: current_call.used_execution_resources.clone(),
783+
gas_consumed: GasAmount(current_call.gas_consumed),
784+
},
785+
l2_to_l1_payload_lengths: current_call.used_l1_resources.l2_l1_message_sizes.clone(),
786+
event_summary: {
787+
let mut event_summary = EventSummary {
788+
n_events: current_call.events.len(),
789+
..Default::default()
790+
};
791+
for OrderedEvent { event, .. } in &current_call.events {
792+
event_summary.total_event_data_size += u64_from_usize(event.data.0.len());
793+
event_summary.total_event_keys += u64_from_usize(event.keys.len());
794+
}
795+
event_summary
796+
},
797+
// Fields below are not relevant for partial gas calculation.
798+
call_summary: CallSummary::default(),
799+
executed_class_hashes: HashSet::default(),
800+
visited_storage_entries: HashSet::default(),
801+
}
802+
}
803+
741804
fn add_sierra_gas_resources(top_call: &Rc<RefCell<CallTrace>>) -> u64 {
742805
let mut gas_consumed = top_call.borrow().gas_consumed;
743806
for nested_call in &top_call.borrow().nested_calls {

0 commit comments

Comments
 (0)