From 87c10b3ac6422486b5bc6b117eb7f67ccd1e77ee Mon Sep 17 00:00:00 2001 From: Franco Giachetta Date: Fri, 3 Jan 2025 20:58:19 +0000 Subject: [PATCH] Add support for subtractions contenting references as right hand side operands (#1898) * take into account the sign of the reference * resolve conflicts * fix issue * add test with negated outer reference * update changelog * test passing * explain unreachable * format * fix test * fix test and changelog * revert changes in custom_hint/custom_hint.rs * remove unwanted files * Update CHANGELOG.md Co-authored-by: Gabriel Bosio <38794644+gabrielbosio@users.noreply.github.com> * Update vm/src/types/errors/program_errors.rs typo Co-authored-by: Gabriel Bosio <38794644+gabrielbosio@users.noreply.github.com> --------- Co-authored-by: Gabriel Bosio <38794644+gabrielbosio@users.noreply.github.com> --- CHANGELOG.md | 2 + .../builtin_hint_processor/hint_utils.rs | 2 +- .../builtin_hint_processor/math_utils.rs | 70 ++++++++++++--- .../hint_processor_definition.rs | 16 ++-- vm/src/hint_processor/hint_processor_utils.rs | 35 ++++---- vm/src/serde/deserialize_program.rs | 10 +-- vm/src/serde/deserialize_utils.rs | 86 +++++++++++++------ vm/src/types/errors/program_errors.rs | 2 + vm/src/types/program.rs | 4 +- vm/src/vm/errors/vm_exception.rs | 2 +- 10 files changed, 162 insertions(+), 67 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb3f2646d7..d0cd50c54b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ #### [2.0.0-rc2] - 2024-12-12 +* feat: Add support for subtractions containing references as right hand side operands [#1898](https://github.com/lambdaclass/cairo-vm/pull/1898) + * fix: Change wildcard getrandom dependency. * Update starknet-crypto to 0.7.3, removing the old FieldElement completly in favour of the new Felt (that is Copy). diff --git a/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs b/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs index 74caa13473..e104cb7e86 100644 --- a/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs +++ b/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs @@ -149,7 +149,7 @@ mod tests { fn get_ptr_from_var_name_immediate_value() { let mut vm = vm!(); vm.segments = segments![((1, 0), (0, 0))]; - let mut hint_ref = HintReference::new(0, 0, true, false); + let mut hint_ref = HintReference::new(0, 0, true, false, true); hint_ref.offset2 = OffsetValue::Value(2); let ids_data = HashMap::from([("imm".to_string(), hint_ref)]); diff --git a/vm/src/hint_processor/builtin_hint_processor/math_utils.rs b/vm/src/hint_processor/builtin_hint_processor/math_utils.rs index e10467b6ee..eb65aed496 100644 --- a/vm/src/hint_processor/builtin_hint_processor/math_utils.rs +++ b/vm/src/hint_processor/builtin_hint_processor/math_utils.rs @@ -2053,8 +2053,14 @@ mod tests { //Create ids let ids_data = HashMap::from([ ("value".to_string(), HintReference::new_simple(-4)), - ("low".to_string(), HintReference::new(-3, 0, true, true)), - ("high".to_string(), HintReference::new(-3, 1, true, true)), + ( + "low".to_string(), + HintReference::new(-3, 0, true, true, true), + ), + ( + "high".to_string(), + HintReference::new(-3, 1, true, true, true), + ), ]); //Execute the hint assert_matches!( @@ -2131,8 +2137,14 @@ mod tests { //Create ids_data & hint_data let ids_data = HashMap::from([ ("value".to_string(), HintReference::new_simple(-4)), - ("low".to_string(), HintReference::new(-3, 0, true, true)), - ("high".to_string(), HintReference::new(-3, 1, true, true)), + ( + "low".to_string(), + HintReference::new(-3, 0, true, true, true), + ), + ( + "high".to_string(), + HintReference::new(-3, 1, true, true, true), + ), ]); //Execute the hint @@ -2175,8 +2187,14 @@ mod tests { //Create ids_data & hint_data let ids_data = HashMap::from([ ("value".to_string(), HintReference::new_simple(-4)), - ("low".to_string(), HintReference::new(-3, 0, true, true)), - ("high".to_string(), HintReference::new(-3, 1, true, true)), + ( + "low".to_string(), + HintReference::new(-3, 0, true, true, true), + ), + ( + "high".to_string(), + HintReference::new(-3, 1, true, true, true), + ), ]); //Execute the hint assert_matches!( @@ -2213,8 +2231,14 @@ mod tests { //Create ids_data & hint_data let ids_data = HashMap::from([ ("value".to_string(), HintReference::new_simple(-4)), - ("low".to_string(), HintReference::new(-3, 0, true, true)), - ("high".to_string(), HintReference::new(-3, 1, true, true)), + ( + "low".to_string(), + HintReference::new(-3, 0, true, true, true), + ), + ( + "high".to_string(), + HintReference::new(-3, 1, true, true, true), + ), ]); //Execute the hint assert_matches!( @@ -2251,8 +2275,14 @@ mod tests { //Create ids let ids_data = HashMap::from([ ("value".to_string(), HintReference::new_simple(-4)), - ("low".to_string(), HintReference::new(-3, 0, true, true)), - ("high".to_string(), HintReference::new(-3, 1, true, true)), + ( + "low".to_string(), + HintReference::new(-3, 0, true, true, true), + ), + ( + "high".to_string(), + HintReference::new(-3, 1, true, true, true), + ), ]); //Execute the hint assert_matches!( @@ -2277,8 +2307,14 @@ mod tests { //Create ids let ids_data = HashMap::from([ ("value".to_string(), HintReference::new_simple(-4)), - ("low".to_string(), HintReference::new(-3, 0, true, true)), - ("high".to_string(), HintReference::new(-3, 1, true, true)), + ( + "low".to_string(), + HintReference::new(-3, 0, true, true, true), + ), + ( + "high".to_string(), + HintReference::new(-3, 1, true, true, true), + ), ]); //Execute the hint assert_matches!( @@ -2315,8 +2351,14 @@ mod tests { //Create ids let ids_data = HashMap::from([ ("value".to_string(), HintReference::new_simple(-4)), - ("low".to_string(), HintReference::new(-3, 0, true, true)), - ("high".to_string(), HintReference::new(-3, 1, true, true)), + ( + "low".to_string(), + HintReference::new(-3, 0, true, true, true), + ), + ( + "high".to_string(), + HintReference::new(-3, 1, true, true, true), + ), ]); //Execute the hint assert_matches!( diff --git a/vm/src/hint_processor/hint_processor_definition.rs b/vm/src/hint_processor/hint_processor_definition.rs index 496e8b1428..d4c871903a 100644 --- a/vm/src/hint_processor/hint_processor_definition.rs +++ b/vm/src/hint_processor/hint_processor_definition.rs @@ -112,7 +112,7 @@ pub struct HintReference { impl HintReference { pub fn new_simple(offset1: i32) -> Self { HintReference { - offset1: OffsetValue::Reference(Register::FP, offset1, false), + offset1: OffsetValue::Reference(Register::FP, offset1, false, true), offset2: OffsetValue::Value(0), ap_tracking_data: None, outer_dereference: true, @@ -121,9 +121,15 @@ impl HintReference { } } - pub fn new(offset1: i32, offset2: i32, inner_dereference: bool, dereference: bool) -> Self { + pub fn new( + offset1: i32, + offset2: i32, + inner_dereference: bool, + dereference: bool, + is_positive: bool, + ) -> Self { HintReference { - offset1: OffsetValue::Reference(Register::FP, offset1, inner_dereference), + offset1: OffsetValue::Reference(Register::FP, offset1, inner_dereference, is_positive), offset2: OffsetValue::Value(offset2), ap_tracking_data: None, outer_dereference: dereference, @@ -145,8 +151,8 @@ impl From for HintReference { &reference.value_address.offset1, &reference.value_address.offset2, ) { - (OffsetValue::Reference(Register::AP, _, _), _) - | (_, OffsetValue::Reference(Register::AP, _, _)) => { + (OffsetValue::Reference(Register::AP, _, _, _), _) + | (_, OffsetValue::Reference(Register::AP, _, _, _)) => { Some(reference.ap_tracking_data.clone()) } _ => None, diff --git a/vm/src/hint_processor/hint_processor_utils.rs b/vm/src/hint_processor/hint_processor_utils.rs index 8a0a3e9e58..3d442fbf7f 100644 --- a/vm/src/hint_processor/hint_processor_utils.rs +++ b/vm/src/hint_processor/hint_processor_utils.rs @@ -70,7 +70,12 @@ pub fn get_maybe_relocatable_from_reference( &hint_reference.ap_tracking_data, ap_tracking, )?; - let mut val = offset1.add(&offset2).ok()?; + let mut val = match hint_reference.offset2 { + OffsetValue::Reference(_, _, _, true) + | OffsetValue::Immediate(_) + | OffsetValue::Value(_) => offset1.add(&offset2).ok()?, + OffsetValue::Reference(_, _, _, false) => offset1.sub(&offset2).ok()?, + }; if hint_reference.inner_dereference && hint_reference.outer_dereference { val = vm.get_maybe(&val)?; } @@ -139,7 +144,7 @@ fn get_offset_value( match offset_value { OffsetValue::Immediate(f) => Some(f.into()), OffsetValue::Value(v) => Some(Felt252::from(*v).into()), - OffsetValue::Reference(register, offset, deref) => { + OffsetValue::Reference(register, offset, deref, _) => { let addr = (if matches!(register, Register::FP) { vm.get_fp() } else { @@ -176,7 +181,7 @@ mod tests { // Reference: cast(2, felt) let mut vm = vm!(); vm.segments = segments![((1, 0), 0)]; - let mut hint_ref = HintReference::new(0, 0, false, false); + let mut hint_ref = HintReference::new(0, 0, false, false, true); hint_ref.offset1 = OffsetValue::Immediate(Felt252::from(2)); assert_eq!( @@ -191,8 +196,8 @@ mod tests { fn get_offset_value_reference_valid() { let mut vm = vm!(); vm.segments = segments![((1, 0), 0)]; - let mut hint_ref = HintReference::new(0, 0, false, true); - hint_ref.offset1 = OffsetValue::Reference(Register::FP, 2_i32, false); + let mut hint_ref = HintReference::new(0, 0, false, true, true); + hint_ref.offset1 = OffsetValue::Reference(Register::FP, 2_i32, false, true); assert_matches!( get_offset_value(&vm, &hint_ref.offset1, &hint_ref.ap_tracking_data, &ApTracking::new()), @@ -205,8 +210,8 @@ mod tests { fn get_offset_value_invalid() { let mut vm = vm!(); vm.segments = segments![((1, 0), 0)]; - let mut hint_ref = HintReference::new(0, 0, false, true); - hint_ref.offset1 = OffsetValue::Reference(Register::FP, -2_i32, false); + let mut hint_ref = HintReference::new(0, 0, false, true, true); + hint_ref.offset1 = OffsetValue::Reference(Register::FP, -2_i32, false, true); assert_matches!( get_offset_value( @@ -228,7 +233,7 @@ mod tests { assert_matches!( get_ptr_from_reference( &vm, - &HintReference::new(0, 0, false, false), + &HintReference::new(0, 0, false, false, true), &ApTracking::new() ), Ok(x) if x == relocatable!(1, 0) @@ -244,7 +249,7 @@ mod tests { assert_matches!( get_ptr_from_reference( &vm, - &HintReference::new(0, 0, false, true), + &HintReference::new(0, 0, false, true, true), &ApTracking::new() ), Ok(x) if x == relocatable!(3, 0) @@ -256,7 +261,7 @@ mod tests { fn get_ptr_from_reference_with_dereference_and_imm() { let mut vm = vm!(); vm.segments = segments![((1, 0), (4, 0))]; - let mut hint_ref = HintReference::new(0, 0, true, false); + let mut hint_ref = HintReference::new(0, 0, true, false, true); hint_ref.offset2 = OffsetValue::Value(2); assert_matches!( @@ -270,7 +275,7 @@ mod tests { fn compute_addr_from_reference_no_regiter_in_reference() { let mut vm = vm!(); vm.segments = segments![((1, 0), (4, 0))]; - let mut hint_reference = HintReference::new(0, 0, false, false); + let mut hint_reference = HintReference::new(0, 0, false, false, true); hint_reference.offset1 = OffsetValue::Immediate(Felt252::from(2_i32)); assert!(compute_addr_from_reference(&hint_reference, &vm, &ApTracking::new()).is_none()); @@ -282,8 +287,8 @@ mod tests { let mut vm = vm!(); vm.segments = segments![((1, 0), 4)]; // vm.run_context.fp = -1; - let mut hint_reference = HintReference::new(0, 0, false, false); - hint_reference.offset1 = OffsetValue::Reference(Register::FP, -1, true); + let mut hint_reference = HintReference::new(0, 0, false, false, true); + hint_reference.offset1 = OffsetValue::Reference(Register::FP, -1, true, true); assert_matches!( compute_addr_from_reference(&hint_reference, &vm, &ApTracking::new()), @@ -356,7 +361,7 @@ mod tests { ((0, 5), 3) // [[[fp + 2] + 2]] -> [(0, 5)] -> 3 ]; let hint_ref = HintReference { - offset1: OffsetValue::Reference(Register::FP, 2, true), + offset1: OffsetValue::Reference(Register::FP, 2, true, true), offset2: OffsetValue::Value(2), outer_dereference: true, inner_dereference: true, @@ -381,7 +386,7 @@ mod tests { ]; // [fp + 4] + (-5) = 8 - 5 = 3 let hint_ref = HintReference { - offset1: OffsetValue::Reference(Register::FP, 4, true), + offset1: OffsetValue::Reference(Register::FP, 4, true, true), offset2: OffsetValue::Immediate(Felt252::from(-5)), outer_dereference: false, inner_dereference: false, diff --git a/vm/src/serde/deserialize_program.rs b/vm/src/serde/deserialize_program.rs index 82771f7552..8f0e9a0dee 100644 --- a/vm/src/serde/deserialize_program.rs +++ b/vm/src/serde/deserialize_program.rs @@ -275,7 +275,7 @@ pub struct Reference { pub enum OffsetValue { Immediate(Felt252), Value(i32), - Reference(Register, i32, bool), + Reference(Register, i32, bool, bool), } #[cfg_attr(feature = "test_utils", derive(Arbitrary))] @@ -714,7 +714,7 @@ mod tests { }, pc: Some(0), value_address: ValueAddress { - offset1: OffsetValue::Reference(Register::FP, -4, false), + offset1: OffsetValue::Reference(Register::FP, -4, false, true), offset2: OffsetValue::Value(0), outer_dereference: true, inner_dereference: false, @@ -728,7 +728,7 @@ mod tests { }, pc: Some(0), value_address: ValueAddress { - offset1: OffsetValue::Reference(Register::FP, -3, false), + offset1: OffsetValue::Reference(Register::FP, -3, false, true), offset2: OffsetValue::Value(0), outer_dereference: true, inner_dereference: false, @@ -742,7 +742,7 @@ mod tests { }, pc: Some(0), value_address: ValueAddress { - offset1: OffsetValue::Reference(Register::FP, -3, true), + offset1: OffsetValue::Reference(Register::FP, -3, true, true), offset2: OffsetValue::Immediate(Felt252::from(2)), outer_dereference: false, inner_dereference: false, @@ -756,7 +756,7 @@ mod tests { }, pc: Some(0), value_address: ValueAddress { - offset1: OffsetValue::Reference(Register::FP, 0, false), + offset1: OffsetValue::Reference(Register::FP, 0, false, true), offset2: OffsetValue::Value(0), outer_dereference: true, inner_dereference: false, diff --git a/vm/src/serde/deserialize_utils.rs b/vm/src/serde/deserialize_utils.rs index 8179605c52..7b4c7bb20e 100644 --- a/vm/src/serde/deserialize_utils.rs +++ b/vm/src/serde/deserialize_utils.rs @@ -125,7 +125,17 @@ fn inner_dereference(input: &str) -> IResult<&str, OffsetValue> { if input.is_empty() { return Ok(("", OffsetValue::Value(0))); } - let (input, _sign) = opt(alt((tag(" + "), tag(" - "))))(input)?; + let (input, sign) = opt(alt((tag(" + "), tag(" - "))))(input)?; + + let is_positive = match sign { + Some(s) => match s.trim() { + "+" => true, + "-" => false, + // can't happen since the alt parser only takes "+" or "-" + _ => unreachable!(), + }, + None => true, + }; map_res( delimited(tag("["), take_until("]"), tag("]")), @@ -135,7 +145,7 @@ fn inner_dereference(input: &str) -> IResult<&str, OffsetValue> { let (_, (register, offset)) = res; let offset_value = match register { None => OffsetValue::Value(offset), - Some(reg) => OffsetValue::Reference(reg, offset, true), + Some(reg) => OffsetValue::Reference(reg, offset, true, is_positive), }; (rem_input, offset_value) }) @@ -145,7 +155,7 @@ fn no_inner_dereference(input: &str) -> IResult<&str, OffsetValue> { let (rem_input, (register, offset)) = register_and_offset(input)?; let offset_value = match register { None => OffsetValue::Value(offset), - Some(reg) => OffsetValue::Reference(reg, offset, false), + Some(reg) => OffsetValue::Reference(reg, offset, false, true), }; Ok((rem_input, offset_value)) } @@ -177,13 +187,17 @@ pub(crate) fn parse_value(input: &str) -> IResult<&str, ValueAddress> { let offset1 = match fst_offset { OffsetValue::Immediate(imm) => OffsetValue::Immediate(imm), OffsetValue::Value(val) => OffsetValue::Immediate(Felt252::from(val)), - OffsetValue::Reference(reg, val, refe) => OffsetValue::Reference(reg, val, refe), + OffsetValue::Reference(reg, val, refe, is_positive) => { + OffsetValue::Reference(reg, val, refe, is_positive) + } }; let offset2 = match snd_offset { OffsetValue::Immediate(imm) => OffsetValue::Immediate(imm), OffsetValue::Value(val) => OffsetValue::Immediate(Felt252::from(val)), - OffsetValue::Reference(reg, val, refe) => OffsetValue::Reference(reg, val, refe), + OffsetValue::Reference(reg, val, refe, is_positive) => { + OffsetValue::Reference(reg, val, refe, is_positive) + } }; (offset1, offset2) @@ -368,7 +382,10 @@ mod tests { assert_eq!( parsed, - Ok((" + 2", OffsetValue::Reference(Register::FP, -1_i32, true))) + Ok(( + " + 2", + OffsetValue::Reference(Register::FP, -1_i32, true, true) + )) ); } @@ -380,7 +397,7 @@ mod tests { assert_eq!( parsed, - Ok(("", OffsetValue::Reference(Register::AP, 3_i32, false))) + Ok(("", OffsetValue::Reference(Register::AP, 3_i32, false, true))) ); } @@ -396,7 +413,7 @@ mod tests { "", ValueAddress { offset2: OffsetValue::Value(2), - offset1: OffsetValue::Reference(Register::FP, -1_i32, true), + offset1: OffsetValue::Reference(Register::FP, -1_i32, true, true), outer_dereference: true, inner_dereference: false, value_type: "felt".to_string(), @@ -405,6 +422,27 @@ mod tests { ); } + #[test] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn parse_value_with_neg_inner_dereference_test() { + let value = "cast(17 - [fp], felt)"; + let parsed = parse_value(value).unwrap(); + + assert_eq!( + parsed, + ( + "", + ValueAddress { + offset1: OffsetValue::Immediate(Felt252::from(17)), + offset2: OffsetValue::Reference(Register::FP, 0_i32, true, false), + outer_dereference: false, + inner_dereference: false, + value_type: "felt".to_string() + } + ) + ) + } + #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn parse_value_with_no_inner_dereference_test() { @@ -416,7 +454,7 @@ mod tests { Ok(( "", ValueAddress { - offset1: OffsetValue::Reference(Register::AP, 2_i32, false), + offset1: OffsetValue::Reference(Register::AP, 2_i32, false, true), offset2: OffsetValue::Value(0), outer_dereference: false, inner_dereference: false, @@ -457,7 +495,7 @@ mod tests { Ok(( "", ValueAddress { - offset1: OffsetValue::Reference(Register::AP, 0_i32, false), + offset1: OffsetValue::Reference(Register::AP, 0_i32, false, true), offset2: OffsetValue::Value(-1), outer_dereference: true, inner_dereference: false, @@ -478,7 +516,7 @@ mod tests { Ok(( "", ValueAddress { - offset1: OffsetValue::Reference(Register::AP, 0_i32, true), + offset1: OffsetValue::Reference(Register::AP, 0_i32, true, true), offset2: OffsetValue::Value(1), outer_dereference: true, inner_dereference: false, @@ -499,7 +537,7 @@ mod tests { Ok(( "", ValueAddress { - offset1: OffsetValue::Reference(Register::AP, 0_i32, true), + offset1: OffsetValue::Reference(Register::AP, 0_i32, true, true), offset2: OffsetValue::Immediate(Felt252::ONE), outer_dereference: true, inner_dereference: false, @@ -520,7 +558,7 @@ mod tests { Ok(( "", ValueAddress { - offset1: OffsetValue::Reference(Register::AP, 1_i32, true), + offset1: OffsetValue::Reference(Register::AP, 1_i32, true, true), offset2: OffsetValue::Value(1), outer_dereference: true, inner_dereference: false, @@ -541,8 +579,8 @@ mod tests { Ok(( "", ValueAddress { - offset1: OffsetValue::Reference(Register::AP, 0_i32, true), - offset2: OffsetValue::Reference(Register::FP, 1_i32, true), + offset1: OffsetValue::Reference(Register::AP, 0_i32, true, true), + offset2: OffsetValue::Reference(Register::FP, 1_i32, true, true), outer_dereference: true, inner_dereference: false, value_type: "__main__.felt".to_string(), @@ -562,8 +600,8 @@ mod tests { Ok(( "", ValueAddress { - offset1: OffsetValue::Reference(Register::AP, 1_i32, true), - offset2: OffsetValue::Reference(Register::FP, 1_i32, true), + offset1: OffsetValue::Reference(Register::AP, 1_i32, true, true), + offset2: OffsetValue::Reference(Register::FP, 1_i32, true, true), outer_dereference: true, inner_dereference: false, value_type: "__main__.felt".to_string(), @@ -604,7 +642,7 @@ mod tests { Ok(( "", ValueAddress { - offset1: OffsetValue::Reference(Register::AP, 0_i32, true), + offset1: OffsetValue::Reference(Register::AP, 0_i32, true, true), offset2: OffsetValue::Value(1), outer_dereference: true, inner_dereference: false, @@ -625,7 +663,7 @@ mod tests { Ok(( "", ValueAddress { - offset1: OffsetValue::Reference(Register::AP, 0_i32, true), + offset1: OffsetValue::Reference(Register::AP, 0_i32, true, true), offset2: OffsetValue::Value(1), outer_dereference: true, inner_dereference: false, @@ -646,8 +684,8 @@ mod tests { Ok(( "", ValueAddress { - offset1: OffsetValue::Reference(Register::AP, 0_i32, true), - offset2: OffsetValue::Reference(Register::AP, 0_i32, true), + offset1: OffsetValue::Reference(Register::AP, 0_i32, true, true), + offset2: OffsetValue::Reference(Register::AP, 0_i32, true, true), outer_dereference: true, inner_dereference: false, value_type: "felt".to_string(), @@ -667,7 +705,7 @@ mod tests { Ok(( "", ValueAddress { - offset1: OffsetValue::Reference(Register::FP, -3_i32, true), + offset1: OffsetValue::Reference(Register::FP, -3_i32, true, true), offset2: OffsetValue::Value(5), outer_dereference: true, inner_dereference: true, @@ -688,8 +726,8 @@ mod tests { Ok(( "", ValueAddress { - offset1: OffsetValue::Reference(Register::AP, 1_i32, true), - offset2: OffsetValue::Reference(Register::AP, 2_i32, true), + offset1: OffsetValue::Reference(Register::AP, 1_i32, true, true), + offset2: OffsetValue::Reference(Register::AP, 2_i32, true, true), outer_dereference: true, inner_dereference: false, value_type: "felt".to_string(), diff --git a/vm/src/types/errors/program_errors.rs b/vm/src/types/errors/program_errors.rs index e4a7c96d90..77f62585e0 100644 --- a/vm/src/types/errors/program_errors.rs +++ b/vm/src/types/errors/program_errors.rs @@ -9,6 +9,8 @@ pub enum ProgramError { IO(#[from] std::io::Error), #[error(transparent)] Parse(#[from] serde_json::Error), + #[error("The \"{0}\" operation is not supported")] + OperationNotSupported(String), #[error("Entrypoint {0} not found")] EntrypointNotFound(String), #[error("Constant {0} has no value")] diff --git a/vm/src/types/program.rs b/vm/src/types/program.rs index 1c97580ee0..fcc2cb1a3e 100644 --- a/vm/src/types/program.rs +++ b/vm/src/types/program.rs @@ -344,8 +344,8 @@ impl Program { inner_dereference: r.value_address.inner_dereference, // only store `ap` tracking data if the reference is referred to it ap_tracking_data: match (&r.value_address.offset1, &r.value_address.offset2) { - (OffsetValue::Reference(Register::AP, _, _), _) - | (_, OffsetValue::Reference(Register::AP, _, _)) => { + (OffsetValue::Reference(Register::AP, _, _, _), _) + | (_, OffsetValue::Reference(Register::AP, _, _, _)) => { Some(r.ap_tracking_data.clone()) } _ => None, diff --git a/vm/src/vm/errors/vm_exception.rs b/vm/src/vm/errors/vm_exception.rs index 5a31d6669c..005160d95b 100644 --- a/vm/src/vm/errors/vm_exception.rs +++ b/vm/src/vm/errors/vm_exception.rs @@ -177,7 +177,7 @@ fn get_value_from_simple_reference( .get(ref_id)?; // Filter ap-based references match reference.offset1 { - OffsetValue::Reference(Register::AP, _, _) => None, + OffsetValue::Reference(Register::AP, _, _, _) => None, _ => { // Filer complex types (only felt/felt pointers) match reference.cairo_type {