From e9ad115f14ed7d5b3e7033275498bd56a57a0eaf Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Sun, 12 Nov 2023 11:33:11 +0300 Subject: [PATCH 01/12] add print hints --- vm/Cargo.toml | 2 + .../builtin_hint_processor_definition.rs | 11 ++ .../builtin_hint_processor/hint_code.rs | 14 ++ .../builtin_hint_processor/mod.rs | 2 + .../builtin_hint_processor/print.rs | 128 ++++++++++++++++++ 5 files changed, 157 insertions(+) create mode 100644 vm/src/hint_processor/builtin_hint_processor/print.rs diff --git a/vm/Cargo.toml b/vm/Cargo.toml index d1d5a77ab3..208216df36 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -33,9 +33,11 @@ lambdaworks-felt = ["felt/lambdaworks-felt"] test_utils = [ "skip_next_instruction_hint", "hooks", + "print", ] # This feature will reference every test-oriented feature skip_next_instruction_hint = [] hooks = [] +print = [] [dependencies] mimalloc = { workspace = true, optional = true } diff --git a/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs b/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs index 1c3c5f4b40..cba8fdb506 100644 --- a/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs +++ b/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs @@ -116,6 +116,9 @@ use felt::Felt252; #[cfg(feature = "skip_next_instruction_hint")] use crate::hint_processor::builtin_hint_processor::skip_next_instruction::skip_next_instruction; +#[cfg(feature = "print")] +use crate::hint_processor::builtin_hint_processor::print::{print_array, print_dict, print_u256}; + use super::blake2s_utils::example_blake2s_compress; pub struct HintProcessorData { @@ -815,6 +818,14 @@ impl HintProcessorLogic for BuiltinHintProcessor { hint_code::SPLIT_XX => split_xx(vm, &hint_data.ids_data, &hint_data.ap_tracking), #[cfg(feature = "skip_next_instruction_hint")] hint_code::SKIP_NEXT_INSTRUCTION => skip_next_instruction(vm), + #[cfg(feature = "print")] + hint_code::PRINT_U256 => print_u256(vm, &hint_data.ids_data, &hint_data.ap_tracking), + #[cfg(feature = "print")] + hint_code::PRINT_ARR => print_array(vm, &hint_data.ids_data, &hint_data.ap_tracking), + #[cfg(feature = "print")] + hint_code::PRINT_DICT => { + print_dict(vm, exec_scopes, &hint_data.ids_data, &hint_data.ap_tracking) + } code => Err(HintError::UnknownHint(code.to_string().into_boxed_str())), } } diff --git a/vm/src/hint_processor/builtin_hint_processor/hint_code.rs b/vm/src/hint_processor/builtin_hint_processor/hint_code.rs index 2b55c91f30..ac096480b8 100644 --- a/vm/src/hint_processor/builtin_hint_processor/hint_code.rs +++ b/vm/src/hint_processor/builtin_hint_processor/hint_code.rs @@ -1409,3 +1409,17 @@ ids.x.low = x & ((1<<128)-1) ids.x.high = x >> 128"; #[cfg(feature = "skip_next_instruction_hint")] pub const SKIP_NEXT_INSTRUCTION: &str = "skip_next_instruction()"; + +pub const PRINT_U256: &str = r#"low = ids.val.low +high = ids.val.high +print(f"Uint256(low={low}, high={high}) = {2 ** 128 * high + low}")"#; + +pub const PRINT_ARR: &str = r#"print(bytes.fromhex(f"{ids.name:062x}").decode().replace('\x00','')) +arr = [memory[ids.arr + i] for i in range(ids.arr_len)] +print(arr)"#; + +pub const PRINT_DICT: &str = r#"print(bytes.fromhex(f"{ids.name:062x}").decode().replace('\x00','')) +data = __dict_manager.get_dict(ids.dict_ptr) +print( + {k: v if isinstance(v, int) else [memory[v + i] for i in range(ids.pointer_size)] for k, v in data.items()} +)"#; diff --git a/vm/src/hint_processor/builtin_hint_processor/mod.rs b/vm/src/hint_processor/builtin_hint_processor/mod.rs index 0a3f067b5b..8236f8a866 100644 --- a/vm/src/hint_processor/builtin_hint_processor/mod.rs +++ b/vm/src/hint_processor/builtin_hint_processor/mod.rs @@ -18,6 +18,8 @@ pub mod memcpy_hint_utils; pub mod memset_utils; pub mod poseidon_utils; pub mod pow_utils; +#[cfg(feature = "print")] +pub mod print; pub mod secp; pub mod segments; pub mod set; diff --git a/vm/src/hint_processor/builtin_hint_processor/print.rs b/vm/src/hint_processor/builtin_hint_processor/print.rs new file mode 100644 index 0000000000..9934142f5f --- /dev/null +++ b/vm/src/hint_processor/builtin_hint_processor/print.rs @@ -0,0 +1,128 @@ +use core::fmt::{Debug, Formatter}; + +use felt::Felt252; +use num_traits::ToPrimitive; + +use crate::hint_processor::builtin_hint_processor::dict_manager::Dictionary; +use crate::hint_processor::builtin_hint_processor::hint_utils::{ + get_integer_from_var_name, get_ptr_from_var_name, get_relocatable_from_var_name, +}; +use crate::serde::deserialize_program::ApTracking; +use crate::stdlib::collections::HashMap; + +use crate::types::exec_scope::ExecutionScopes; +use crate::types::relocatable::MaybeRelocatable; +use crate::vm::errors::hint_errors::HintError; +use crate::{ + hint_processor::hint_processor_definition::HintReference, vm::vm_core::VirtualMachine, +}; + +pub fn print_u256( + vm: &VirtualMachine, + ids_data: &HashMap, + ap_tracking: &ApTracking, +) -> Result<(), HintError> { + let val = get_relocatable_from_var_name("val", vm, ids_data, ap_tracking)?; + let low = vm.get_relocatable(val)?; + let low = vm.get_integer(low)?; + let high = vm.get_relocatable(val)?; + let high = vm.get_integer((high + 1_usize)?)?; + println!("Uint256(low={low}, high={high}) = {{2 ** 128 * high + low}}"); + Ok(()) +} + +fn print_name( + vm: &VirtualMachine, + ids_data: &HashMap, + ap_tracking: &ApTracking, +) -> Result<(), HintError> { + let name = get_integer_from_var_name("name", vm, ids_data, ap_tracking)?; + let name = String::from_utf8(name.to_bigint().to_signed_bytes_be()) + .map_err(|err| HintError::CustomHint(err.to_string().into_boxed_str()))?; + println!("{name}"); + Ok(()) +} + +pub fn print_array( + vm: &VirtualMachine, + ids_data: &HashMap, + ap_tracking: &ApTracking, +) -> Result<(), HintError> { + print_name(vm, ids_data, ap_tracking)?; + + let mut acc = Vec::new(); + let arr = get_ptr_from_var_name("arr", vm, ids_data, ap_tracking)?; + let arr_len = get_integer_from_var_name("arr_len", vm, ids_data, ap_tracking)?; + let arr_len = arr_len.to_usize().ok_or_else(|| { + HintError::CustomHint(String::from("arr_len must be a positive integer").into_boxed_str()) + })?; + for i in 0..arr_len { + let val = vm.get_integer((arr + i)?)?; + acc.push(val); + } + println!("{:?}", acc); + Ok(()) +} + +enum DictValue { + Int(Felt252), + Relocatable(Vec), +} + +impl Debug for DictValue { + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { + match self { + Self::Int(int) => write!(f, "{:?}", int), + Self::Relocatable(relocatable) => write!(f, "{:?}", relocatable), + } + } +} + +pub fn print_dict( + vm: &VirtualMachine, + exec_scopes: &ExecutionScopes, + ids_data: &HashMap, + ap_tracking: &ApTracking, +) -> Result<(), HintError> { + print_name(vm, ids_data, ap_tracking)?; + + let dict_ptr = get_ptr_from_var_name("dict_ptr", vm, ids_data, ap_tracking)?; + let pointer_size = get_integer_from_var_name("pointer_size", vm, ids_data, ap_tracking)?; + let pointer_size = pointer_size.to_usize().ok_or_else(|| { + HintError::CustomHint( + String::from("pointer_size must be a positive integer").into_boxed_str(), + ) + })?; + + let dict_manager = exec_scopes.get_dict_manager()?; + let dict_manager = dict_manager.borrow(); + let tracker = dict_manager.get_tracker(dict_ptr)?; + + let map = match &tracker.data { + Dictionary::SimpleDictionary(dict) => dict, + Dictionary::DefaultDictionary { dict, .. } => dict, + }; + + let mut acc = HashMap::new(); + for (k, v) in map.iter() { + let key = k.get_int_ref().ok_or_else(|| { + HintError::CustomHint(String::from("Expected felt key for dict").into_boxed_str()) + })?; + match v { + MaybeRelocatable::Int(value) => { + acc.insert(key, DictValue::Int(value.clone())); + } + MaybeRelocatable::RelocatableValue(val) => { + let mut structure = Vec::new(); + for i in 0..pointer_size { + let val = vm.get_integer((*val + i)?)?.as_ref().clone(); + structure.push(val); + } + acc.insert(key, DictValue::Relocatable(structure)); + } + } + } + + println!("{:?}", acc); + Ok(()) +} From bd9b10413d243cf7f092b0f013e048e5d8c0fa38 Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Sun, 12 Nov 2023 11:33:38 +0300 Subject: [PATCH 02/12] test --- cairo_programs/print_array.cairo | 20 ++++++++++++++++ cairo_programs/print_dict_array.cairo | 34 +++++++++++++++++++++++++++ cairo_programs/print_dict_felt.cairo | 24 +++++++++++++++++++ cairo_programs/print_u256.cairo | 13 ++++++++++ vm/src/tests/cairo_run_test.rs | 23 ++++++++++++++++++ 5 files changed, 114 insertions(+) create mode 100644 cairo_programs/print_array.cairo create mode 100644 cairo_programs/print_dict_array.cairo create mode 100644 cairo_programs/print_dict_felt.cairo create mode 100644 cairo_programs/print_u256.cairo diff --git a/cairo_programs/print_array.cairo b/cairo_programs/print_array.cairo new file mode 100644 index 0000000000..18183092e3 --- /dev/null +++ b/cairo_programs/print_array.cairo @@ -0,0 +1,20 @@ +%builtins range_check + +from starkware.cairo.common.alloc import alloc + +func main{range_check_ptr: felt}() { + let name = 0x4b4b5254; + let (arr: felt*) = alloc(); + assert arr[0] = 1; + assert arr[1] = 2; + assert arr[2] = 3; + assert arr[3] = 4; + assert arr[4] = 5; + let arr_len = 5; + %{ + print(bytes.fromhex(f"{ids.name:062x}").decode().replace('\x00','')) + arr = [memory[ids.arr + i] for i in range(ids.arr_len)] + print(arr) + %} + return(); +} diff --git a/cairo_programs/print_dict_array.cairo b/cairo_programs/print_dict_array.cairo new file mode 100644 index 0000000000..4bdb56b76e --- /dev/null +++ b/cairo_programs/print_dict_array.cairo @@ -0,0 +1,34 @@ +%builtins range_check + +from starkware.cairo.common.dict_access import DictAccess +from starkware.cairo.common.default_dict import default_dict_new, default_dict_finalize +from starkware.cairo.common.dict import dict_write + +struct MyStruct { + a: felt, + b: felt, + c: felt, +} + +func main{range_check_ptr: felt}() { + let name = 0x4b4b5254; + let (dict_ptr) = default_dict_new(0); + let pointer_size = 3; + + tempvar one = new MyStruct(1,2,3); + dict_write{dict_ptr=dict_ptr}(0, cast(one, felt)); + tempvar two = new MyStruct(2,3,4); + dict_write{dict_ptr=dict_ptr}(1, cast(two, felt)); + tempvar three = new MyStruct(3,4,5); + dict_write{dict_ptr=dict_ptr}(2, cast(three, felt)); + tempvar four = new MyStruct(4,5,6); + dict_write{dict_ptr=dict_ptr}(3, cast(four, felt)); + %{ + print(bytes.fromhex(f"{ids.name:062x}").decode().replace('\x00','')) + data = __dict_manager.get_dict(ids.dict_ptr) + print( + {k: v if isinstance(v, int) else [memory[v + i] for i in range(ids.pointer_size)] for k, v in data.items()} + ) + %} + return(); +} diff --git a/cairo_programs/print_dict_felt.cairo b/cairo_programs/print_dict_felt.cairo new file mode 100644 index 0000000000..10c3344e0d --- /dev/null +++ b/cairo_programs/print_dict_felt.cairo @@ -0,0 +1,24 @@ +%builtins range_check + +from starkware.cairo.common.dict_access import DictAccess +from starkware.cairo.common.default_dict import default_dict_new, default_dict_finalize +from starkware.cairo.common.dict import dict_write + +func main{range_check_ptr: felt}() { + let name = 0x4b4b5254; + let (dict_ptr) = default_dict_new(0); + let pointer_size = 1; + dict_write{dict_ptr=dict_ptr}(0, 1); + dict_write{dict_ptr=dict_ptr}(1, 2); + dict_write{dict_ptr=dict_ptr}(2, 3); + dict_write{dict_ptr=dict_ptr}(3, 4); + dict_write{dict_ptr=dict_ptr}(4, 5); + %{ + print(bytes.fromhex(f"{ids.name:062x}").decode().replace('\x00','')) + data = __dict_manager.get_dict(ids.dict_ptr) + print( + {k: v if isinstance(v, int) else [memory[v + i] for i in range(ids.pointer_size)] for k, v in data.items()} + ) + %} + return(); +} diff --git a/cairo_programs/print_u256.cairo b/cairo_programs/print_u256.cairo new file mode 100644 index 0000000000..caf4dd652c --- /dev/null +++ b/cairo_programs/print_u256.cairo @@ -0,0 +1,13 @@ +%builtins range_check + +from starkware.cairo.common.uint256 import Uint256 + +func main{range_check_ptr: felt}() { + tempvar val = new Uint256(1, 2); + %{ + low = ids.val.low + high = ids.val.high + print(f"Uint256(low={low}, high={high}) = {2 ** 128 * high + low}") + %} + return(); +} diff --git a/vm/src/tests/cairo_run_test.rs b/vm/src/tests/cairo_run_test.rs index 715a087f45..de495a4319 100644 --- a/vm/src/tests/cairo_run_test.rs +++ b/vm/src/tests/cairo_run_test.rs @@ -1032,3 +1032,26 @@ fn divmod_igcdex_not_one() { let error_msg = "Operation failed: divmod(1, 340282366920938463463374607431768211457, 340282366920938463463374607431768211457), igcdex(340282366920938463463374607431768211457, 340282366920938463463374607431768211457) != 1"; run_program_with_error(program_data.as_slice(), error_msg); } + +fn cairo_run_print_u256() { + let program_data = include_bytes!("../../../cairo_programs/print_u256.json"); + run_program_simple(program_data); +} + +#[test] +fn cairo_run_print_array() { + let program_data = include_bytes!("../../../cairo_programs/print_array.json"); + run_program_simple(program_data); +} + +#[test] +fn cairo_run_print_dict_felt() { + let program_data = include_bytes!("../../../cairo_programs/print_dict_felt.json"); + run_program_simple_with_memory_holes(program_data, 5); +} + +#[test] +fn cairo_run_print_dict_array() { + let program_data = include_bytes!("../../../cairo_programs/print_dict_array.json"); + run_program_simple_with_memory_holes(program_data, 4); +} From e7e12140f29b2e3f2a00dcfd473de878e6127a5a Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Sun, 12 Nov 2023 11:50:51 +0300 Subject: [PATCH 03/12] remove u256 add felt --- cairo_programs/print_felt.cairo | 9 +++++++++ cairo_programs/print_u256.cairo | 13 ------------- .../builtin_hint_processor_definition.rs | 4 ++-- .../builtin_hint_processor/hint_code.rs | 4 +--- .../hint_processor/builtin_hint_processor/print.rs | 12 ++++-------- vm/src/tests/cairo_run_test.rs | 4 ++-- 6 files changed, 18 insertions(+), 28 deletions(-) create mode 100644 cairo_programs/print_felt.cairo delete mode 100644 cairo_programs/print_u256.cairo diff --git a/cairo_programs/print_felt.cairo b/cairo_programs/print_felt.cairo new file mode 100644 index 0000000000..383c6d6db2 --- /dev/null +++ b/cairo_programs/print_felt.cairo @@ -0,0 +1,9 @@ +%builtins range_check + +func main{range_check_ptr: felt}() { + let x = 123; + %{ + print(ids.x) + %} + return(); +} diff --git a/cairo_programs/print_u256.cairo b/cairo_programs/print_u256.cairo deleted file mode 100644 index caf4dd652c..0000000000 --- a/cairo_programs/print_u256.cairo +++ /dev/null @@ -1,13 +0,0 @@ -%builtins range_check - -from starkware.cairo.common.uint256 import Uint256 - -func main{range_check_ptr: felt}() { - tempvar val = new Uint256(1, 2); - %{ - low = ids.val.low - high = ids.val.high - print(f"Uint256(low={low}, high={high}) = {2 ** 128 * high + low}") - %} - return(); -} diff --git a/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs b/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs index cba8fdb506..0b367e3edd 100644 --- a/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs +++ b/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs @@ -117,7 +117,7 @@ use felt::Felt252; use crate::hint_processor::builtin_hint_processor::skip_next_instruction::skip_next_instruction; #[cfg(feature = "print")] -use crate::hint_processor::builtin_hint_processor::print::{print_array, print_dict, print_u256}; +use crate::hint_processor::builtin_hint_processor::print::{print_array, print_dict, print_felt}; use super::blake2s_utils::example_blake2s_compress; @@ -819,7 +819,7 @@ impl HintProcessorLogic for BuiltinHintProcessor { #[cfg(feature = "skip_next_instruction_hint")] hint_code::SKIP_NEXT_INSTRUCTION => skip_next_instruction(vm), #[cfg(feature = "print")] - hint_code::PRINT_U256 => print_u256(vm, &hint_data.ids_data, &hint_data.ap_tracking), + hint_code::PRINT_FELT => print_felt(vm, &hint_data.ids_data, &hint_data.ap_tracking), #[cfg(feature = "print")] hint_code::PRINT_ARR => print_array(vm, &hint_data.ids_data, &hint_data.ap_tracking), #[cfg(feature = "print")] diff --git a/vm/src/hint_processor/builtin_hint_processor/hint_code.rs b/vm/src/hint_processor/builtin_hint_processor/hint_code.rs index ac096480b8..77365943f8 100644 --- a/vm/src/hint_processor/builtin_hint_processor/hint_code.rs +++ b/vm/src/hint_processor/builtin_hint_processor/hint_code.rs @@ -1410,9 +1410,7 @@ ids.x.high = x >> 128"; #[cfg(feature = "skip_next_instruction_hint")] pub const SKIP_NEXT_INSTRUCTION: &str = "skip_next_instruction()"; -pub const PRINT_U256: &str = r#"low = ids.val.low -high = ids.val.high -print(f"Uint256(low={low}, high={high}) = {2 ** 128 * high + low}")"#; +pub const PRINT_FELT: &str = "print(ids.x)"; pub const PRINT_ARR: &str = r#"print(bytes.fromhex(f"{ids.name:062x}").decode().replace('\x00','')) arr = [memory[ids.arr + i] for i in range(ids.arr_len)] diff --git a/vm/src/hint_processor/builtin_hint_processor/print.rs b/vm/src/hint_processor/builtin_hint_processor/print.rs index 9934142f5f..10ce39c504 100644 --- a/vm/src/hint_processor/builtin_hint_processor/print.rs +++ b/vm/src/hint_processor/builtin_hint_processor/print.rs @@ -5,7 +5,7 @@ use num_traits::ToPrimitive; use crate::hint_processor::builtin_hint_processor::dict_manager::Dictionary; use crate::hint_processor::builtin_hint_processor::hint_utils::{ - get_integer_from_var_name, get_ptr_from_var_name, get_relocatable_from_var_name, + get_integer_from_var_name, get_ptr_from_var_name, }; use crate::serde::deserialize_program::ApTracking; use crate::stdlib::collections::HashMap; @@ -17,17 +17,13 @@ use crate::{ hint_processor::hint_processor_definition::HintReference, vm::vm_core::VirtualMachine, }; -pub fn print_u256( +pub fn print_felt( vm: &VirtualMachine, ids_data: &HashMap, ap_tracking: &ApTracking, ) -> Result<(), HintError> { - let val = get_relocatable_from_var_name("val", vm, ids_data, ap_tracking)?; - let low = vm.get_relocatable(val)?; - let low = vm.get_integer(low)?; - let high = vm.get_relocatable(val)?; - let high = vm.get_integer((high + 1_usize)?)?; - println!("Uint256(low={low}, high={high}) = {{2 ** 128 * high + low}}"); + let val = get_integer_from_var_name("x", vm, ids_data, ap_tracking)?; + println!("{val}"); Ok(()) } diff --git a/vm/src/tests/cairo_run_test.rs b/vm/src/tests/cairo_run_test.rs index de495a4319..55d33bb73c 100644 --- a/vm/src/tests/cairo_run_test.rs +++ b/vm/src/tests/cairo_run_test.rs @@ -1033,8 +1033,8 @@ fn divmod_igcdex_not_one() { run_program_with_error(program_data.as_slice(), error_msg); } -fn cairo_run_print_u256() { - let program_data = include_bytes!("../../../cairo_programs/print_u256.json"); +fn cairo_run_print_felt() { + let program_data = include_bytes!("../../../cairo_programs/print_felt.json"); run_program_simple(program_data); } From c6b4e00737538ddd9ce95c0f25b14407f4ff5067 Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Sun, 12 Nov 2023 11:59:25 +0300 Subject: [PATCH 04/12] change log --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7c72ebe7e..367807f9fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ #### Upcoming Changes +* feat: add debugging capabilities behind `print` feature flag. [#1476](https://github.com/lambdaclass/cairo-vm/pull/1476) + * chore: bump starknet-crypto to v0.6.1 [#1469](https://github.com/lambdaclass/cairo-vm/pull/1469) * feat: Implement the Serialize and Deserialize methods for the Program struct [#1458](https://github.com/lambdaclass/cairo-vm/pull/1458) From 74310fb5bfdd06121daaa91982fb63d0cc434ca0 Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Wed, 15 Nov 2023 13:36:45 +0300 Subject: [PATCH 05/12] fix based on comments --- vm/src/tests/cairo_run_test.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/vm/src/tests/cairo_run_test.rs b/vm/src/tests/cairo_run_test.rs index 55d33bb73c..ebed550b39 100644 --- a/vm/src/tests/cairo_run_test.rs +++ b/vm/src/tests/cairo_run_test.rs @@ -1033,24 +1033,29 @@ fn divmod_igcdex_not_one() { run_program_with_error(program_data.as_slice(), error_msg); } +#[test] +#[cfg(feature = "test_utils")] fn cairo_run_print_felt() { let program_data = include_bytes!("../../../cairo_programs/print_felt.json"); run_program_simple(program_data); } #[test] +#[cfg(feature = "test_utils")] fn cairo_run_print_array() { let program_data = include_bytes!("../../../cairo_programs/print_array.json"); run_program_simple(program_data); } #[test] +#[cfg(feature = "test_utils")] fn cairo_run_print_dict_felt() { let program_data = include_bytes!("../../../cairo_programs/print_dict_felt.json"); run_program_simple_with_memory_holes(program_data, 5); } #[test] +#[cfg(feature = "test_utils")] fn cairo_run_print_dict_array() { let program_data = include_bytes!("../../../cairo_programs/print_dict_array.json"); run_program_simple_with_memory_holes(program_data, 4); From 285ec9f5435b2d6be6cd869cf79a59dcaa92e2d1 Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Sat, 18 Nov 2023 12:05:26 +0100 Subject: [PATCH 06/12] add std feature for print --- vm/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/Cargo.toml b/vm/Cargo.toml index 208216df36..ed3e45a2df 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -37,7 +37,7 @@ test_utils = [ ] # This feature will reference every test-oriented feature skip_next_instruction_hint = [] hooks = [] -print = [] +print = ["std"] [dependencies] mimalloc = { workspace = true, optional = true } From 4aebc827e7f02cfe620fb6071a6a4ef63facc467 Mon Sep 17 00:00:00 2001 From: Pedro Fontana Date: Wed, 22 Nov 2023 15:51:53 -0300 Subject: [PATCH 07/12] Move Cairo Programs --- cairo_programs/{ => print_feature}/print_array.cairo | 0 cairo_programs/{ => print_feature}/print_dict_array.cairo | 0 cairo_programs/{ => print_feature}/print_dict_felt.cairo | 0 cairo_programs/{ => print_feature}/print_felt.cairo | 0 vm/src/tests/cairo_run_test.rs | 8 ++++---- 5 files changed, 4 insertions(+), 4 deletions(-) rename cairo_programs/{ => print_feature}/print_array.cairo (100%) rename cairo_programs/{ => print_feature}/print_dict_array.cairo (100%) rename cairo_programs/{ => print_feature}/print_dict_felt.cairo (100%) rename cairo_programs/{ => print_feature}/print_felt.cairo (100%) diff --git a/cairo_programs/print_array.cairo b/cairo_programs/print_feature/print_array.cairo similarity index 100% rename from cairo_programs/print_array.cairo rename to cairo_programs/print_feature/print_array.cairo diff --git a/cairo_programs/print_dict_array.cairo b/cairo_programs/print_feature/print_dict_array.cairo similarity index 100% rename from cairo_programs/print_dict_array.cairo rename to cairo_programs/print_feature/print_dict_array.cairo diff --git a/cairo_programs/print_dict_felt.cairo b/cairo_programs/print_feature/print_dict_felt.cairo similarity index 100% rename from cairo_programs/print_dict_felt.cairo rename to cairo_programs/print_feature/print_dict_felt.cairo diff --git a/cairo_programs/print_felt.cairo b/cairo_programs/print_feature/print_felt.cairo similarity index 100% rename from cairo_programs/print_felt.cairo rename to cairo_programs/print_feature/print_felt.cairo diff --git a/vm/src/tests/cairo_run_test.rs b/vm/src/tests/cairo_run_test.rs index ebed550b39..27a1a4e729 100644 --- a/vm/src/tests/cairo_run_test.rs +++ b/vm/src/tests/cairo_run_test.rs @@ -1036,27 +1036,27 @@ fn divmod_igcdex_not_one() { #[test] #[cfg(feature = "test_utils")] fn cairo_run_print_felt() { - let program_data = include_bytes!("../../../cairo_programs/print_felt.json"); + let program_data = include_bytes!("../../../cairo_programs/print_feature/print_felt.json"); run_program_simple(program_data); } #[test] #[cfg(feature = "test_utils")] fn cairo_run_print_array() { - let program_data = include_bytes!("../../../cairo_programs/print_array.json"); + let program_data = include_bytes!("../../../cairo_programs/print_feature/print_array.json"); run_program_simple(program_data); } #[test] #[cfg(feature = "test_utils")] fn cairo_run_print_dict_felt() { - let program_data = include_bytes!("../../../cairo_programs/print_dict_felt.json"); + let program_data = include_bytes!("../../../cairo_programs/print_feature/print_dict_felt.json"); run_program_simple_with_memory_holes(program_data, 5); } #[test] #[cfg(feature = "test_utils")] fn cairo_run_print_dict_array() { - let program_data = include_bytes!("../../../cairo_programs/print_dict_array.json"); + let program_data = include_bytes!("../../../cairo_programs/print_feature/print_dict_array.json"); run_program_simple_with_memory_holes(program_data, 4); } From f8d3733669fe6d8d524b3eb9ec20a3806230d87e Mon Sep 17 00:00:00 2001 From: Pedro Fontana Date: Wed, 22 Nov 2023 15:52:10 -0300 Subject: [PATCH 08/12] Update Makefile --- Makefile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 401f41ffe2..faafc38534 100644 --- a/Makefile +++ b/Makefile @@ -73,6 +73,11 @@ BAD_TEST_DIR=cairo_programs/bad_programs BAD_TEST_FILES:=$(wildcard $(BAD_TEST_DIR)/*.cairo) COMPILED_BAD_TESTS:=$(patsubst $(BAD_TEST_DIR)/%.cairo, $(BAD_TEST_DIR)/%.json, $(BAD_TEST_FILES)) +PRINT_TEST_DIR=cairo_programs/print_feature +PRINT_TEST_FILES:=$(wildcard $(PRINT_TEST_DIR)/*.cairo) +COMPILED_PRINT_TESTS:=$(patsubst $(PRINT_TEST_DIR)/%.cairo, $(PRINT_TEST_DIR)/%.json, $(PRINT_TEST_FILES)) + + NORETROCOMPAT_DIR:=cairo_programs/noretrocompat NORETROCOMPAT_FILES:=$(wildcard $(NORETROCOMPAT_DIR)/*.cairo) COMPILED_NORETROCOMPAT_TESTS:=$(patsubst $(NORETROCOMPAT_DIR)/%.cairo, $(NORETROCOMPAT_DIR)/%.json, $(NORETROCOMPAT_FILES)) @@ -217,7 +222,7 @@ run: check: cargo check -cairo_test_programs: $(COMPILED_TESTS) $(COMPILED_BAD_TESTS) $(COMPILED_NORETROCOMPAT_TESTS) +cairo_test_programs: $(COMPILED_TESTS) $(COMPILED_BAD_TESTS) $(COMPILED_NORETROCOMPAT_TESTS) $(COMPILED_PRINT_TESTS) cairo_proof_programs: $(COMPILED_PROOF_TESTS) cairo_bench_programs: $(COMPILED_BENCHES) cairo_1_test_contracts: $(CAIRO_1_COMPILED_CASM_CONTRACTS) @@ -301,13 +306,14 @@ clean: rm -f $(TEST_DIR)/*.trace rm -f $(BENCH_DIR)/*.json rm -f $(BAD_TEST_DIR)/*.json + rm -f $(PRINT_TEST_DIR)/*.json rm -f $(CAIRO_1_CONTRACTS_TEST_DIR)/*.sierra rm -f $(CAIRO_1_CONTRACTS_TEST_DIR)/*.casm rm -f $(TEST_PROOF_DIR)/*.json rm -f $(TEST_PROOF_DIR)/*.memory rm -f $(TEST_PROOF_DIR)/*.trace rm -f $(TEST_PROOF_DIR)/*.air_public_input - rm -rf cairo-vm-env + # rm -rf cairo-vm-env rm -rf cairo-vm-pypy-env rm -rf cairo rm -rf cairo1 From 0dd9b0bc55b93267139ca0e1c148646770b19a0f Mon Sep 17 00:00:00 2001 From: Pedro Fontana Date: Wed, 22 Nov 2023 16:45:11 -0300 Subject: [PATCH 09/12] Use print tag in test --- vm/src/tests/cairo_run_test.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vm/src/tests/cairo_run_test.rs b/vm/src/tests/cairo_run_test.rs index 27a1a4e729..75b1e390ec 100644 --- a/vm/src/tests/cairo_run_test.rs +++ b/vm/src/tests/cairo_run_test.rs @@ -1034,28 +1034,28 @@ fn divmod_igcdex_not_one() { } #[test] -#[cfg(feature = "test_utils")] +#[cfg(feature = "print")] fn cairo_run_print_felt() { let program_data = include_bytes!("../../../cairo_programs/print_feature/print_felt.json"); run_program_simple(program_data); } #[test] -#[cfg(feature = "test_utils")] +#[cfg(feature = "print")] fn cairo_run_print_array() { let program_data = include_bytes!("../../../cairo_programs/print_feature/print_array.json"); run_program_simple(program_data); } #[test] -#[cfg(feature = "test_utils")] +#[cfg(feature = "print")] fn cairo_run_print_dict_felt() { let program_data = include_bytes!("../../../cairo_programs/print_feature/print_dict_felt.json"); run_program_simple_with_memory_holes(program_data, 5); } #[test] -#[cfg(feature = "test_utils")] +#[cfg(feature = "print")] fn cairo_run_print_dict_array() { let program_data = include_bytes!("../../../cairo_programs/print_feature/print_dict_array.json"); run_program_simple_with_memory_holes(program_data, 4); From d48f4d56e0f3e118e6e05651ff3c3d79443fecf3 Mon Sep 17 00:00:00 2001 From: Pedro Fontana Date: Wed, 22 Nov 2023 17:06:53 -0300 Subject: [PATCH 10/12] cargo fmt --- Makefile | 2 +- vm/src/tests/cairo_run_test.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index faafc38534..07f4780f7a 100644 --- a/Makefile +++ b/Makefile @@ -313,7 +313,7 @@ clean: rm -f $(TEST_PROOF_DIR)/*.memory rm -f $(TEST_PROOF_DIR)/*.trace rm -f $(TEST_PROOF_DIR)/*.air_public_input - # rm -rf cairo-vm-env + rm -rf cairo-vm-env rm -rf cairo-vm-pypy-env rm -rf cairo rm -rf cairo1 diff --git a/vm/src/tests/cairo_run_test.rs b/vm/src/tests/cairo_run_test.rs index 75b1e390ec..fdcbe16f60 100644 --- a/vm/src/tests/cairo_run_test.rs +++ b/vm/src/tests/cairo_run_test.rs @@ -1057,6 +1057,7 @@ fn cairo_run_print_dict_felt() { #[test] #[cfg(feature = "print")] fn cairo_run_print_dict_array() { - let program_data = include_bytes!("../../../cairo_programs/print_feature/print_dict_array.json"); + let program_data = + include_bytes!("../../../cairo_programs/print_feature/print_dict_array.json"); run_program_simple_with_memory_holes(program_data, 4); } From 5562f5e1a971d09f94533ddd13cc9e1a38793bd7 Mon Sep 17 00:00:00 2001 From: Pedro Fontana Date: Wed, 22 Nov 2023 18:01:10 -0300 Subject: [PATCH 11/12] Update Makefile --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 07f4780f7a..7b582606f0 100644 --- a/Makefile +++ b/Makefile @@ -77,6 +77,8 @@ PRINT_TEST_DIR=cairo_programs/print_feature PRINT_TEST_FILES:=$(wildcard $(PRINT_TEST_DIR)/*.cairo) COMPILED_PRINT_TESTS:=$(patsubst $(PRINT_TEST_DIR)/%.cairo, $(PRINT_TEST_DIR)/%.json, $(PRINT_TEST_FILES)) +$(PRINT_TEST_DIR)/%.json: $(PRINT_TEST_DIR)/%.cairo + cairo-compile $< --output $@ NORETROCOMPAT_DIR:=cairo_programs/noretrocompat NORETROCOMPAT_FILES:=$(wildcard $(NORETROCOMPAT_DIR)/*.cairo) From f5180c8e9240d57c8ba54718eb08b5807afe7d40 Mon Sep 17 00:00:00 2001 From: Pedro Fontana Date: Wed, 22 Nov 2023 18:33:46 -0300 Subject: [PATCH 12/12] Update Makefile --- Makefile | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 7b582606f0..8925012f37 100644 --- a/Makefile +++ b/Makefile @@ -77,9 +77,6 @@ PRINT_TEST_DIR=cairo_programs/print_feature PRINT_TEST_FILES:=$(wildcard $(PRINT_TEST_DIR)/*.cairo) COMPILED_PRINT_TESTS:=$(patsubst $(PRINT_TEST_DIR)/%.cairo, $(PRINT_TEST_DIR)/%.json, $(PRINT_TEST_FILES)) -$(PRINT_TEST_DIR)/%.json: $(PRINT_TEST_DIR)/%.cairo - cairo-compile $< --output $@ - NORETROCOMPAT_DIR:=cairo_programs/noretrocompat NORETROCOMPAT_FILES:=$(wildcard $(NORETROCOMPAT_DIR)/*.cairo) COMPILED_NORETROCOMPAT_TESTS:=$(patsubst $(NORETROCOMPAT_DIR)/%.cairo, $(NORETROCOMPAT_DIR)/%.json, $(NORETROCOMPAT_FILES)) @@ -99,15 +96,12 @@ $(TEST_DIR)/%.trace $(TEST_DIR)/%.memory: $(TEST_DIR)/%.json $(NORETROCOMPAT_DIR)/%.json: $(NORETROCOMPAT_DIR)/%.cairo cairo-compile --cairo_path="$(TEST_DIR):$(BENCH_DIR):$(NORETROCOMPAT_DIR)" $< --output $@ - -BAD_TEST_DIR=cairo_programs/bad_programs -BAD_TEST_FILES:=$(wildcard $(BAD_TEST_DIR)/*.cairo) -COMPILED_BAD_TESTS:=$(patsubst $(BAD_TEST_DIR)/%.cairo, $(BAD_TEST_DIR)/%.json, $(BAD_TEST_FILES)) - - $(BAD_TEST_DIR)/%.json: $(BAD_TEST_DIR)/%.cairo cairo-compile $< --output $@ +$(PRINT_TEST_DIR)/%.json: $(PRINT_TEST_DIR)/%.cairo + cairo-compile $< --output $@ + # ====================== # Test Cairo 1 Contracts # ======================