Skip to content

Commit b80e7db

Browse files
committed
Refactor universal-sierra-compiler-api
commit-id:e0444c34
1 parent 33784c4 commit b80e7db

File tree

27 files changed

+303
-286
lines changed

27 files changed

+303
-286
lines changed

Cargo.lock

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

crates/cheatnet/src/forking/state.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use std::cell::{Ref, RefCell};
2828
use std::collections::HashMap;
2929
use std::io::Read;
3030
use std::sync::Arc;
31-
use universal_sierra_compiler_api::{SierraType, compile_sierra};
31+
use universal_sierra_compiler_api::compile_contract_sierra;
3232
use url::Url;
3333

3434
#[derive(Debug)]
@@ -239,13 +239,10 @@ impl StateReader for ForkStateReader {
239239
SierraVersion::extract_from_program(&flattened_class.sierra_program)
240240
.expect("Unable to extract Sierra version from Sierra program");
241241

242-
match compile_sierra::<String>(&sierra_contract_class, &SierraType::Contract) {
242+
match compile_contract_sierra(&sierra_contract_class) {
243243
Ok(casm_contract_class_raw) => Ok(RunnableCompiledClass::V1(
244-
CompiledClassV1::try_from_json_string(
245-
&casm_contract_class_raw,
246-
sierra_version,
247-
)
248-
.expect("Unable to create RunnableCompiledClass::V1"),
244+
CompiledClassV1::try_from((casm_contract_class_raw, sierra_version))
245+
.expect("Unable to create RunnableCompiledClass::V1"),
249246
)),
250247
Err(err) => Err(StateReadError(err.to_string())),
251248
}

crates/cheatnet/src/runtime_extensions/forge_runtime_extension/cheatcodes/declare.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,9 @@ pub fn get_class_hash(sierra_class: &SierraClass) -> Result<ClassHash> {
6868
}
6969

7070
fn get_contract_class(contract_artifact: &StarknetContractArtifacts) -> RunnableCompiledClass {
71-
let contract_class = CompiledClassV1::try_from_json_string(
72-
&contract_artifact.casm,
73-
get_current_sierra_version(),
74-
)
75-
.expect("Failed to read contract class from json");
71+
let contract_class =
72+
CompiledClassV1::try_from((contract_artifact.casm.clone(), get_current_sierra_version()))
73+
.expect("Failed to read contract class from json");
7674

7775
#[cfg(feature = "cairo-native")]
7876
return match &contract_artifact.executor {

crates/forge-runner/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::sync::{Arc, Mutex};
2323
use test_case_summary::{AnyTestCaseSummary, Fuzzing};
2424
use tokio::sync::mpsc::{Sender, channel};
2525
use tokio::task::JoinHandle;
26-
use universal_sierra_compiler_api::AssembledProgramWithDebugInfo;
26+
use universal_sierra_compiler_api::representation::RawCasmProgram;
2727

2828
pub mod build_trace_data;
2929
pub mod coverage_api;
@@ -114,7 +114,7 @@ pub fn maybe_generate_coverage(
114114
#[tracing::instrument(skip_all, level = "debug")]
115115
pub fn run_for_test_case(
116116
case: Arc<TestCaseWithResolvedConfig>,
117-
casm_program: Arc<AssembledProgramWithDebugInfo>,
117+
casm_program: Arc<RawCasmProgram>,
118118
forge_config: Arc<ForgeConfig>,
119119
versioned_program_path: Arc<Utf8PathBuf>,
120120
send: Sender<()>,
@@ -149,7 +149,7 @@ pub fn run_for_test_case(
149149
#[tracing::instrument(skip_all, level = "debug")]
150150
fn run_with_fuzzing(
151151
case: Arc<TestCaseWithResolvedConfig>,
152-
casm_program: Arc<AssembledProgramWithDebugInfo>,
152+
casm_program: Arc<RawCasmProgram>,
153153
forge_config: Arc<ForgeConfig>,
154154
versioned_program_path: Arc<Utf8PathBuf>,
155155
send: Sender<()>,

crates/forge-runner/src/package_tests.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use serde::Serialize;
1919
use starknet_types_core::felt::Felt;
2020
use std::collections::HashMap;
2121
use std::sync::Arc;
22-
use universal_sierra_compiler_api::AssembledProgramWithDebugInfo;
22+
use universal_sierra_compiler_api::representation::RawCasmProgram;
2323

2424
pub mod raw;
2525
pub mod with_config;
@@ -66,10 +66,7 @@ impl TestDetails {
6666
builtins
6767
}
6868

69-
pub fn try_into_program(
70-
&self,
71-
casm_program: &AssembledProgramWithDebugInfo,
72-
) -> Result<Program> {
69+
pub fn try_into_program(&self, casm_program: &RawCasmProgram) -> Result<Program> {
7370
let builtins = self.builtins();
7471

7572
let assembled_program = &casm_program.assembled_cairo_program;
@@ -102,7 +99,7 @@ pub struct TestTarget<C> {
10299
pub tests_location: TestTargetLocation,
103100
pub sierra_program: ProgramArtifact,
104101
pub sierra_program_path: Arc<Utf8PathBuf>,
105-
pub casm_program: Arc<AssembledProgramWithDebugInfo>,
102+
pub casm_program: Arc<RawCasmProgram>,
106103
pub test_cases: Vec<TestCase<C>>,
107104
}
108105

crates/forge-runner/src/package_tests/with_config_resolved.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use cheatnet::runtime_extensions::forge_config_extension::config::{
66
RawAvailableResourceBoundsConfig, RawFuzzerConfig,
77
};
88
use starknet_api::block::BlockNumber;
9-
use universal_sierra_compiler_api::AssembledProgramWithDebugInfo;
9+
use universal_sierra_compiler_api::representation::RawCasmProgram;
1010
use url::Url;
1111

1212
pub type TestTargetWithResolvedConfig = TestTarget<TestCaseResolvedConfig>;
@@ -29,10 +29,7 @@ impl TestCaseWithResolvedConfig {
2929
}
3030
}
3131

32-
pub fn try_into_program(
33-
&self,
34-
casm_program: &AssembledProgramWithDebugInfo,
35-
) -> Result<Program> {
32+
pub fn try_into_program(&self, casm_program: &RawCasmProgram) -> Result<Program> {
3633
self.test_details.try_into_program(casm_program)
3734
}
3835
}

crates/forge-runner/src/running.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use std::rc::Rc;
4444
use std::sync::{Arc, Mutex};
4545
use tokio::sync::mpsc::Sender;
4646
use tokio::task::JoinHandle;
47-
use universal_sierra_compiler_api::AssembledProgramWithDebugInfo;
47+
use universal_sierra_compiler_api::representation::RawCasmProgram;
4848

4949
pub mod config_run;
5050
mod execution;
@@ -63,7 +63,7 @@ pub use syscall_handler::syscall_handler_offset;
6363
#[tracing::instrument(skip_all, level = "debug")]
6464
pub fn run_test(
6565
case: Arc<TestCaseWithResolvedConfig>,
66-
casm_program: Arc<AssembledProgramWithDebugInfo>,
66+
casm_program: Arc<RawCasmProgram>,
6767
forge_config: Arc<ForgeConfig>,
6868
versioned_program_path: Arc<Utf8PathBuf>,
6969
send: Sender<()>,
@@ -100,7 +100,7 @@ pub fn run_test(
100100
pub(crate) fn run_fuzz_test(
101101
case: Arc<TestCaseWithResolvedConfig>,
102102
program: Program,
103-
casm_program: Arc<AssembledProgramWithDebugInfo>,
103+
casm_program: Arc<RawCasmProgram>,
104104
forge_config: Arc<ForgeConfig>,
105105
versioned_program_path: Arc<Utf8PathBuf>,
106106
send: Sender<()>,
@@ -167,7 +167,7 @@ pub enum RunResult {
167167
pub fn run_test_case(
168168
case: &TestCaseWithResolvedConfig,
169169
program: &Program,
170-
casm_program: &AssembledProgramWithDebugInfo,
170+
casm_program: &RawCasmProgram,
171171
runtime_config: &RuntimeConfig,
172172
fuzzer_rng: Option<Arc<Mutex<StdRng>>>,
173173
versioned_program_path: &Utf8Path,

crates/forge-runner/src/running/config_run.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use starknet_api::block::{
1818
};
1919
use starknet_types_core::felt::Felt;
2020
use std::default::Default;
21-
use universal_sierra_compiler_api::AssembledProgramWithDebugInfo;
21+
use universal_sierra_compiler_api::representation::RawCasmProgram;
2222

2323
struct PhantomStateReader;
2424

@@ -61,7 +61,7 @@ impl StateReader for PhantomStateReader {
6161
#[tracing::instrument(skip_all, level = "debug")]
6262
pub fn run_config_pass(
6363
test_details: &TestDetails,
64-
casm_program: &AssembledProgramWithDebugInfo,
64+
casm_program: &RawCasmProgram,
6565
tracked_resource: &ForgeTrackedResource,
6666
) -> Result<RawForgeConfig> {
6767
let program = test_details.try_into_program(casm_program)?;

crates/forge-runner/src/running/hints.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
use cairo_lang_casm::hints::Hint;
22
use cairo_vm::serde::deserialize_program::{ApTracking, FlowTrackingData, HintParams};
33
use std::collections::HashMap;
4-
use universal_sierra_compiler_api::AssembledCairoProgramWithSerde;
4+
use universal_sierra_compiler_api::representation::AssembledCairoProgram;
55

6-
pub fn hints_by_representation(
7-
assembled_program: &AssembledCairoProgramWithSerde,
8-
) -> HashMap<String, Hint> {
6+
pub fn hints_by_representation(assembled_program: &AssembledCairoProgram) -> HashMap<String, Hint> {
97
assembled_program
108
.hints
119
.iter()
@@ -16,7 +14,7 @@ pub fn hints_by_representation(
1614

1715
#[must_use]
1816
pub fn hints_to_params(
19-
assembled_program: &AssembledCairoProgramWithSerde,
17+
assembled_program: &AssembledCairoProgram,
2018
) -> HashMap<usize, Vec<HintParams>> {
2119
assembled_program
2220
.hints

crates/forge-runner/src/running/setup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use cairo_vm::vm::runners::cairo_runner::CairoRunner;
1515
use cheatnet::constants::build_test_entry_point;
1616
use starknet_api::deprecated_contract_class::EntryPointOffset;
1717
use std::collections::HashMap;
18-
use universal_sierra_compiler_api::AssembledProgramWithDebugInfo;
18+
use universal_sierra_compiler_api::representation::RawCasmProgram;
1919

2020
// Based on structure from https://github.com/starkware-libs/sequencer/blob/e417a9e7d50cbd78065d357763df2fbc2ad41f7c/crates/blockifier/src/execution/entry_point_execution.rs#L39
2121
// Logic of `initialize_execution_context` had to be modified so this struct ended up modified as well.
@@ -96,7 +96,7 @@ pub fn entry_point_initial_budget(syscall_hint_processor: &SyscallHintProcessor)
9696

9797
pub fn build_test_call_and_entry_point(
9898
test_details: &TestDetails,
99-
casm_program: &AssembledProgramWithDebugInfo,
99+
casm_program: &RawCasmProgram,
100100
program: &Program,
101101
) -> (ExecutableCallEntryPoint, EntryPointV1) {
102102
let sierra_instruction_idx = test_details.sierra_entry_point_statement_idx;

0 commit comments

Comments
 (0)