diff --git a/scripts/setup-tests.sh b/scripts/setup-tests.sh index c37193b23..435517845 100755 --- a/scripts/setup-tests.sh +++ b/scripts/setup-tests.sh @@ -42,3 +42,4 @@ cairo-compile cairo-lang/src/starkware/starknet/core/os/os.cairo --output build/ cairo-compile tests/programs/different_output.cairo --output build/different_output.json cairo-compile tests/programs/fact.cairo --output build/fact.json cairo-compile tests/programs/hint.cairo --output build/hint.json +cairo-compile tests/programs/load_compiled_classes.cairo --output build/load_compiled_classes.json diff --git a/src/hints/mod.rs b/src/hints/mod.rs index 8f9a46376..3e0e2e39b 100644 --- a/src/hints/mod.rs +++ b/src/hints/mod.rs @@ -7,6 +7,7 @@ use cairo_vm::hint_processor::builtin_hint_processor::hint_utils::{ }; use cairo_vm::hint_processor::hint_processor_definition::HintReference; +use crate::io::StarknetOsInput; use cairo_vm::serde::deserialize_program::ApTracking; use cairo_vm::types::exec_scope::ExecutionScopes; use cairo_vm::types::relocatable::MaybeRelocatable; @@ -18,9 +19,6 @@ use cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_def BuiltinHintProcessor, HintFunc, }; -use crate::os_input::StarknetOsInput; -use crate::utils::hasher::pedersen::PedersenHasher; - pub mod hints_raw; pub fn sn_hint_processor() -> BuiltinHintProcessor { @@ -98,8 +96,8 @@ pub fn load_compiled_class_facts( // %{ os_input = ... %} // Can't directly get os_input.compiled_classes so we need to get the whole os_input let compiled_class_facts = exec_scopes - .get_ref::>("os_input")? - .compiled_classes + .get_ref::("os_input")? + .compiled_classes() .clone(); // ids.n_compiled_class_facts = len(os_input.compiled_classes) insert_value_from_var_name( diff --git a/src/io.rs b/src/io.rs index dfe6df611..577935f24 100644 --- a/src/io.rs +++ b/src/io.rs @@ -10,7 +10,7 @@ use crate::{ }; #[allow(unused)] -struct StarknetOsInput { +pub struct StarknetOsInput { contract_state_commitment_info: CommitmentInfo, contract_class_commitment_info: CommitmentInfo, deprecated_compiled_classes: HashMap, // TODO: Add contract_class module @@ -21,6 +21,11 @@ struct StarknetOsInput { transactions: Vec, block_hash: Felt252, } +impl StarknetOsInput { + pub fn compiled_classes(&self) -> &HashMap { + &self.compiled_classes + } +} pub struct StarknetOsOutput { /// The state commitment before this block. diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 0a62ab565..d4df413c0 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -17,15 +17,6 @@ pub trait Storage { /// Returns the value of the leaf at the given path. fn leaf(&self, path: &BitSlice) -> anyhow::Result>; } -impl Storage for () { - fn set_value(&self, _key: Vec, _value: Vec) {} - - fn get_value(&self, _key: Vec) -> Option> { - None - } - - fn del_value(&self, _key: Vec) {} -} #[derive(Clone, Debug)] pub enum Node { diff --git a/tests/contracts/load_compiled_classes.cairo b/tests/contracts/load_compiled_classes.cairo index 420c5ff4f..6d618bb98 100644 --- a/tests/contracts/load_compiled_classes.cairo +++ b/tests/contracts/load_compiled_classes.cairo @@ -2,7 +2,6 @@ func main(output_ptr: felt*) -> (output_ptr: felt*) { alloc_locals; - %{ mock_os_input %} local compiled_class_facts; local n_compiled_class_facts; %{ diff --git a/tests/programs/load_compiled_classes.cairo b/tests/programs/load_compiled_classes.cairo new file mode 100644 index 000000000..6d618bb98 --- /dev/null +++ b/tests/programs/load_compiled_classes.cairo @@ -0,0 +1,17 @@ +%builtins output + +func main(output_ptr: felt*) -> (output_ptr: felt*) { + alloc_locals; + local compiled_class_facts; + local n_compiled_class_facts; + %{ + ids.compiled_class_facts = segments.add() + ids.n_compiled_class_facts = len(os_input.compiled_classes) + vm_enter_scope({ + 'compiled_class_facts': iter(os_input.compiled_classes.items()), + }) + %} + // When entering a scope we need to exit it afterwards otherwise the vm panics. + %{ vm_exit_scope() %} + return(output_ptr = output_ptr); +} diff --git a/tests/snos.rs b/tests/snos.rs index a9079f1f0..71c1845a6 100644 --- a/tests/snos.rs +++ b/tests/snos.rs @@ -12,18 +12,9 @@ use snos::{state::SharedState, SnOsRunner}; use starknet_api::block::BlockNumber; use starknet_api::transaction::Calldata; -use cairo_vm::hint_processor::builtin_hint_processor::hint_utils::get_integer_from_var_name; -use cairo_vm::hint_processor::hint_processor_definition::HintReference; -use cairo_vm::serde::deserialize_program::ApTracking; -use cairo_vm::types::exec_scope::ExecutionScopes; -use cairo_vm::vm::{errors::hint_errors::HintError, vm_core::VirtualMachine}; -use common::{check_output_vs_python, compile_contracts}; use snos::hints::hints_raw::*; use snos::hints::load_compiled_class_facts; -use snos::os_input::StarknetOsInput; -use snos::utils::hasher::pedersen::PedersenHasher; -use snos::SnOsRunner; -use std::collections::HashMap; + use std::fs; use std::rc::Rc; @@ -45,32 +36,6 @@ fn prepared_os_test(prepare_os_test: (SharedState, Vec