diff --git a/Cargo.lock b/Cargo.lock index b5c0b64412..4d6366753e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -507,7 +507,7 @@ dependencies = [ "cairo-lang-starknet-classes", "cairo-lang-utils", "cairo-vm", - "derive_more", + "derive_more 0.99.18", "indexmap 2.5.0", "itertools 0.10.5", "keccak", @@ -621,6 +621,21 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ade8366b8bd5ba243f0a58f036cc0ca8a2f069cff1a2351ef1cac6b083e16fc0" +[[package]] +name = "cairo-annotations" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b27bd803ae8b063e8fba0ee9a94af33b4881582d9a337e271d6be882313aa5cd" +dependencies = [ + "cairo-lang-sierra", + "cairo-lang-sierra-to-casm", + "camino", + "derive_more 1.0.0", + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "cairo-lang-casm" version = "2.8.2" @@ -1240,6 +1255,7 @@ dependencies = [ "anyhow", "bimap", "blockifier", + "cairo-annotations", "cairo-lang-casm", "cairo-lang-runner", "cairo-lang-starknet", @@ -1273,7 +1289,6 @@ dependencies = [ "test-case", "thiserror", "tokio", - "trace-data", "universal-sierra-compiler-api", "url", ] @@ -1730,6 +1745,27 @@ dependencies = [ "syn 2.0.79", ] +[[package]] +name = "derive_more" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", + "unicode-xid", +] + [[package]] name = "diff" version = "0.1.13" @@ -2061,6 +2097,7 @@ dependencies = [ "assert_fs", "axum", "blockifier", + "cairo-annotations", "cairo-lang-casm", "cairo-lang-compiler", "cairo-lang-filesystem", @@ -2113,7 +2150,6 @@ dependencies = [ "tokio", "tokio-util", "toml_edit", - "trace-data", "universal-sierra-compiler-api", "url", "walkdir", @@ -2126,6 +2162,7 @@ dependencies = [ "anyhow", "bimap", "blockifier", + "cairo-annotations", "cairo-lang-casm", "cairo-lang-compiler", "cairo-lang-filesystem", @@ -2167,7 +2204,6 @@ dependencies = [ "tokio", "tokio-util", "toml_edit", - "trace-data", "universal-sierra-compiler-api", "url", "which", @@ -5011,7 +5047,7 @@ checksum = "1b505c9c076d9fce854304bd743c93ea540ebea6b16ec96819b07343a3aa2c7c" dependencies = [ "bitvec", "cairo-lang-starknet-classes", - "derive_more", + "derive_more 0.99.18", "hex", "indexmap 2.5.0", "itertools 0.12.1", @@ -5478,15 +5514,6 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" -[[package]] -name = "trace-data" -version = "0.4.0" -source = "git+https://github.com/software-mansion/cairo-profiler/?rev=e61a4a7#e61a4a78af6409714024dbdbe3f1b6be2603491a" -dependencies = [ - "camino", - "serde", -] - [[package]] name = "tracing" version = "0.1.40" diff --git a/Cargo.toml b/Cargo.toml index b259a4988c..fdfc86f13b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,6 +50,7 @@ cairo-lang-starknet-classes = "2.7.0" cairo-lang-parser = "2.7.0" cairo-lang-macro = "0.1.0" cairo-vm = "1.0.0-rc3" +cairo-annotations = "0.1.0" starknet-types-core = { version = "0.1.6", features = ["hash", "prime-bigint"] } anyhow = "1.0.89" assert_fs = "1.1.2" @@ -66,7 +67,6 @@ serde = { version = "1.0.209", features = ["derive"] } serde_json = "1.0.127" starknet = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "660a732" } starknet-crypto = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "660a732" } -trace-data = { git = "https://github.com/software-mansion/cairo-profiler/", rev = "e61a4a7" } tempfile = "3.13.0" thiserror = "1.0.64" ctor = "0.2.8" diff --git a/crates/cheatnet/Cargo.toml b/crates/cheatnet/Cargo.toml index b7c1b5949e..787a9e3451 100644 --- a/crates/cheatnet/Cargo.toml +++ b/crates/cheatnet/Cargo.toml @@ -19,6 +19,7 @@ cairo-lang-utils.workspace = true cairo-lang-starknet.workspace = true cairo-lang-starknet-classes.workspace = true cairo-vm.workspace = true +cairo-annotations.workspace = true regex.workspace = true indoc.workspace = true starknet.workspace = true @@ -33,7 +34,6 @@ tokio.workspace = true num-bigint.workspace = true conversions.workspace = true scarb-metadata.workspace = true -trace-data.workspace = true fs2.workspace = true flate2.workspace = true scarb-api = { path = "../scarb-api" } diff --git a/crates/cheatnet/src/state.rs b/crates/cheatnet/src/state.rs index 7e8d31a74e..4281d491fc 100644 --- a/crates/cheatnet/src/state.rs +++ b/crates/cheatnet/src/state.rs @@ -15,6 +15,7 @@ use blockifier::{ execution::contract_class::ContractClass, state::state_api::{StateReader, StateResult}, }; +use cairo_annotations::trace_data::L1Resources; use cairo_vm::vm::runners::cairo_runner::ExecutionResources; use cairo_vm::vm::trace::trace_entry::RelocatedTraceEntry; use cairo_vm::Felt252; @@ -32,7 +33,6 @@ use starknet_api::{ use std::cell::{Ref, RefCell}; use std::collections::HashMap; use std::rc::Rc; -use trace_data::L1Resources; // Specifies the duration of the cheat #[derive(CairoDeserialize, Copy, Clone, Debug, PartialEq, Eq)] diff --git a/crates/forge-runner/Cargo.toml b/crates/forge-runner/Cargo.toml index 3171af1aec..929c0f720f 100644 --- a/crates/forge-runner/Cargo.toml +++ b/crates/forge-runner/Cargo.toml @@ -19,6 +19,7 @@ cairo-lang-sierra-type-size.workspace = true cairo-lang-sierra-gas.workspace = true cairo-lang-sierra-ap-change.workspace = true cairo-lang-test-plugin.workspace = true +cairo-annotations.workspace = true starknet-types-core.workspace = true starknet_api.workspace = true starknet.workspace = true @@ -43,7 +44,6 @@ semver.workspace = true console.workspace = true serde.workspace = true bimap.workspace = true -trace-data.workspace = true flatten-serde-json.workspace = true rayon.workspace = true cheatnet = { path = "../cheatnet" } diff --git a/crates/forge-runner/src/build_trace_data.rs b/crates/forge-runner/src/build_trace_data.rs index 88a3b446ef..bb4541795a 100644 --- a/crates/forge-runner/src/build_trace_data.rs +++ b/crates/forge-runner/src/build_trace_data.rs @@ -9,6 +9,15 @@ use crate::build_trace_data::test_sierra_program_path::VersionedProgramPath; use blockifier::execution::deprecated_syscalls::DeprecatedSyscallSelector; use blockifier::execution::entry_point::{CallEntryPoint, CallType}; use blockifier::execution::syscalls::hint_processor::SyscallCounter; +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, TraceEntry as ProfilerTraceEntry, + VersionedCallTrace as VersionedProfilerCallTrace, VmExecutionResources, +}; use cairo_vm::vm::runners::cairo_runner::ExecutionResources; use cairo_vm::vm::trace::trace_entry::RelocatedTraceEntry; use camino::Utf8PathBuf; @@ -20,14 +29,6 @@ use conversions::IntoConv; use starknet::core::utils::get_selector_from_name; use starknet_api::core::{ClassHash, EntryPointSelector}; use starknet_api::deprecated_contract_class::EntryPointType; -use trace_data::{ - CairoExecutionInfo, CallEntryPoint as ProfilerCallEntryPoint, CallTrace as ProfilerCallTrace, - CallTraceNode as ProfilerCallTraceNode, CallType as ProfilerCallType, CasmLevelInfo, - ContractAddress, DeprecatedSyscallSelector as ProfilerDeprecatedSyscallSelector, - EntryPointSelector as ProfilerEntryPointSelector, EntryPointType as ProfilerEntryPointType, - ExecutionResources as ProfilerExecutionResources, TraceEntry as ProfilerTraceEntry, - VmExecutionResources, -}; pub mod test_sierra_program_path; @@ -173,7 +174,7 @@ pub fn build_profiler_call_entry_point( let function_name = get_function_name(&entry_point_selector, contracts_data); ProfilerCallEntryPoint { - class_hash: class_hash.map(|ch| trace_data::ClassHash(ch.to_string())), + class_hash: class_hash.map(|ch| cairo_annotations::trace_data::ClassHash(ch.to_string())), entry_point_type: build_profiler_entry_point_type(entry_point_type), entry_point_selector: ProfilerEntryPointSelector(format!("{}", entry_point_selector.0)), contract_address: ContractAddress(format!("{}", storage_address.0.key())), @@ -306,7 +307,10 @@ fn build_profiler_trace_entry(value: &RelocatedTraceEntry) -> ProfilerTraceEntry } } -pub fn save_trace_data(test_name: &String, trace_data: &ProfilerCallTrace) -> Result { +pub fn save_trace_data( + test_name: &String, + trace_data: &VersionedProfilerCallTrace, +) -> Result { let serialized_trace = serde_json::to_string(trace_data).expect("Failed to serialize call trace"); let dir_to_save_trace = PathBuf::from(TRACE_DIR); diff --git a/crates/forge-runner/src/test_case_summary.rs b/crates/forge-runner/src/test_case_summary.rs index 309e2182ae..8224a0ab33 100644 --- a/crates/forge-runner/src/test_case_summary.rs +++ b/crates/forge-runner/src/test_case_summary.rs @@ -3,6 +3,7 @@ use crate::build_trace_data::test_sierra_program_path::VersionedProgramPath; use crate::expected_result::{ExpectedPanicValue, ExpectedTestResult}; use crate::gas::check_available_gas; use crate::package_tests::with_config_resolved::TestCaseWithResolvedConfig; +use cairo_annotations::trace_data::VersionedCallTrace as VersionedProfilerCallTrace; use cairo_lang_runner::short_string::as_cairo_short_string; use cairo_lang_runner::{RunResult, RunResultValue}; use cairo_vm::Felt252; @@ -15,7 +16,6 @@ use shared::utils::build_readable_text; use std::cell::RefCell; use std::option::Option; use std::rc::Rc; -use trace_data::CallTrace as ProfilerCallTrace; #[derive(Debug, PartialEq, Clone, Default)] pub struct GasStatistics { @@ -78,7 +78,7 @@ pub struct Single; impl TestType for Single { type GasInfo = u128; type TestStatistics = (); - type TraceData = ProfilerCallTrace; + type TraceData = VersionedProfilerCallTrace; } /// Summary of running a single test case @@ -231,11 +231,11 @@ impl TestCaseSummary { test_statistics: (), gas_info: gas, used_resources, - trace_data: build_profiler_call_trace( + trace_data: VersionedProfilerCallTrace::V1(build_profiler_call_trace( call_trace, contracts_data, maybe_versioned_program_path, - ), + )), }; check_available_gas(&test_case.config.available_gas, summary) } @@ -269,11 +269,11 @@ impl TestCaseSummary { test_statistics: (), gas_info: gas, used_resources, - trace_data: build_profiler_call_trace( + trace_data: VersionedProfilerCallTrace::V1(build_profiler_call_trace( call_trace, contracts_data, maybe_versioned_program_path, - ), + )), }, }, }, diff --git a/crates/forge/Cargo.toml b/crates/forge/Cargo.toml index 9d1b4d8618..89ef67d13d 100644 --- a/crates/forge/Cargo.toml +++ b/crates/forge/Cargo.toml @@ -32,6 +32,7 @@ cairo-lang-starknet.workspace = true cairo-lang-compiler.workspace = true cairo-lang-filesystem.workspace = true cairo-lang-test-plugin.workspace = true +cairo-annotations.workspace = true starknet-types-core.workspace = true itertools.workspace = true regex.workspace = true @@ -63,7 +64,6 @@ tokio-util.workspace = true futures.workspace = true num-integer.workspace = true url.workspace = true -trace-data.workspace = true fs_extra.workspace = true project-root.workspace = true indoc.workspace = true diff --git a/crates/forge/tests/e2e/build_trace_data.rs b/crates/forge/tests/e2e/build_trace_data.rs index 88e48d241c..2f9f6502f6 100644 --- a/crates/forge/tests/e2e/build_trace_data.rs +++ b/crates/forge/tests/e2e/build_trace_data.rs @@ -1,10 +1,13 @@ use super::common::runner::{setup_package, test_runner}; use crate::e2e::common::get_trace_from_trace_node; +use cairo_annotations::trace_data::{ + CallTraceNode as ProfilerCallTraceNode, CallTraceV1 as ProfilerCallTrace, + VersionedCallTrace as VersionedProfilerCallTrace, +}; use cairo_lang_sierra::program::VersionedProgram; use cairo_lang_starknet_classes::contract_class::ContractClass; use forge_runner::build_trace_data::{TEST_CODE_CONTRACT_NAME, TEST_CODE_FUNCTION_NAME, TRACE_DIR}; use std::fs; -use trace_data::{CallTrace as ProfilerCallTrace, CallTraceNode as ProfilerCallTraceNode}; #[test] fn simple_package_save_trace() { @@ -34,7 +37,7 @@ fn simple_package_save_trace() { ) .unwrap(); - let call_trace: ProfilerCallTrace = + let VersionedProfilerCallTrace::V1(call_trace) = serde_json::from_str(&trace_data).expect("Failed to parse call_trace"); assert!(call_trace.nested_calls.is_empty()); @@ -152,14 +155,14 @@ fn trace_has_deploy_with_no_constructor_phantom_nodes() { // 3 first calls are deploys with empty constructors matches!( call_trace.nested_calls[0], - trace_data::CallTraceNode::DeployWithoutConstructor + cairo_annotations::trace_data::CallTraceNode::DeployWithoutConstructor ); matches!( call_trace.nested_calls[1], - trace_data::CallTraceNode::DeployWithoutConstructor + cairo_annotations::trace_data::CallTraceNode::DeployWithoutConstructor ); matches!( call_trace.nested_calls[2], - trace_data::CallTraceNode::DeployWithoutConstructor + cairo_annotations::trace_data::CallTraceNode::DeployWithoutConstructor ); } diff --git a/crates/forge/tests/e2e/common/mod.rs b/crates/forge/tests/e2e/common/mod.rs index 575b63a851..0f6b4f3849 100644 --- a/crates/forge/tests/e2e/common/mod.rs +++ b/crates/forge/tests/e2e/common/mod.rs @@ -1,4 +1,6 @@ -use trace_data::{CallTrace as ProfilerCallTrace, CallTraceNode as ProfilerCallTraceNode}; +use cairo_annotations::trace_data::{ + CallTraceNode as ProfilerCallTraceNode, CallTraceV1 as ProfilerCallTrace, +}; pub mod runner; diff --git a/crates/forge/tests/e2e/trace_resources.rs b/crates/forge/tests/e2e/trace_resources.rs index 3f91da9123..7ceb37373f 100644 --- a/crates/forge/tests/e2e/trace_resources.rs +++ b/crates/forge/tests/e2e/trace_resources.rs @@ -1,16 +1,17 @@ use super::common::runner::{setup_package, test_runner}; use crate::e2e::common::get_trace_from_trace_node; use assert_fs::TempDir; -use forge_runner::build_trace_data::TRACE_DIR; -use std::{collections::HashMap, fs}; -use trace_data::{ - CallTrace as ProfilerCallTrace, CallTraceNode as ProfilerCallTraceNode, +use cairo_annotations::trace_data::{ + CallTraceNode as ProfilerCallTraceNode, CallTraceV1 as ProfilerCallTrace, DeprecatedSyscallSelector::{ CallContract, Deploy, EmitEvent, GetBlockHash, GetExecutionInfo, Keccak, LibraryCall, SendMessageToL1, StorageRead, StorageWrite, }, ExecutionResources as ProfilerExecutionResources, + VersionedCallTrace as VersionedProfilerCallTrace, }; +use forge_runner::build_trace_data::TRACE_DIR; +use std::{collections::HashMap, fs}; #[test] fn trace_resources_call() { @@ -56,13 +57,13 @@ fn assert_resources_for_test( .assert() .success(); - let call_trace = deserialize_call_trace(test_name, &temp); + let VersionedProfilerCallTrace::V1(call_trace) = deserialize_call_trace(test_name, &temp); check_vm_resources_and_easily_unifiable_syscalls(&call_trace); // test Deploy, CallContract and LibraryCall syscalls as their counts cannot be unified as easily as the rest check_not_easily_unifiable_syscalls(&call_trace); } -fn deserialize_call_trace(test_name: &str, temp_dir: &TempDir) -> ProfilerCallTrace { +fn deserialize_call_trace(test_name: &str, temp_dir: &TempDir) -> VersionedProfilerCallTrace { let trace_data = fs::read_to_string(temp_dir.join(TRACE_DIR).join(format!( "trace_resources_tests::{test_name}::{test_name}.json" ))) @@ -75,7 +76,7 @@ fn check_vm_resources_and_easily_unifiable_syscalls( ) -> &ProfilerExecutionResources { let mut child_resources = vec![]; for call_node in &call_trace.nested_calls { - if let trace_data::CallTraceNode::EntryPointCall(call) = call_node { + if let cairo_annotations::trace_data::CallTraceNode::EntryPointCall(call) = call_node { child_resources.push(check_vm_resources_and_easily_unifiable_syscalls(call)); } }