Skip to content

Commit

Permalink
fix issue
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoGiachetta committed Dec 20, 2024
1 parent d3eeda7 commit ee21d2e
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 22 deletions.
70 changes: 56 additions & 14 deletions vm/src/hint_processor/builtin_hint_processor/math_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, true)),
("high".to_string(), HintReference::new(-3, 1, true, 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!(
Expand Down Expand Up @@ -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, true)),
("high".to_string(), HintReference::new(-3, 1, true, 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
Expand Down Expand Up @@ -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, true)),
("high".to_string(), HintReference::new(-3, 1, true, 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!(
Expand Down Expand Up @@ -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, true)),
("high".to_string(), HintReference::new(-3, 1, true, 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!(
Expand Down Expand Up @@ -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, true)),
("high".to_string(), HintReference::new(-3, 1, true, 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!(
Expand All @@ -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, true)),
("high".to_string(), HintReference::new(-3, 1, true, 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!(
Expand Down Expand Up @@ -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, true)),
("high".to_string(), HintReference::new(-3, 1, true, 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!(
Expand Down
8 changes: 7 additions & 1 deletion vm/src/hint_processor/hint_processor_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ impl HintReference {
}
}

pub fn new(offset1: i32, offset2: i32, inner_dereference: bool, dereference: bool, is_positive: 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, is_positive),
offset2: OffsetValue::Value(offset2),
Expand Down
7 changes: 6 additions & 1 deletion vm/src/hint_processor/hint_processor_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
Expand Down
19 changes: 13 additions & 6 deletions vm/src/serde/deserialize_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ fn inner_dereference(input: &str) -> IResult<&str, OffsetValue> {
let (input, sign) = opt(alt((tag(" + "), tag(" - "))))(input)?;

let is_positive = match sign {
Some(s) => match s {
Some(s) => match s.trim() {
"+" => true,
"-" => false,
_ => unreachable!()
a => unreachable!("{}", a),
},
None => true
None => true,
};

map_res(
Expand Down Expand Up @@ -188,13 +188,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, is_positive) => OffsetValue::Reference(reg, val, refe, is_positive),
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, is_positive) => OffsetValue::Reference(reg, val, refe, is_positive),
OffsetValue::Reference(reg, val, refe, is_positive) => {
OffsetValue::Reference(reg, val, refe, is_positive)
}
};

(offset1, offset2)
Expand Down Expand Up @@ -379,7 +383,10 @@ mod tests {

assert_eq!(
parsed,
Ok((" + 2", OffsetValue::Reference(Register::FP, -1_i32, true, true)))
Ok((
" + 2",
OffsetValue::Reference(Register::FP, -1_i32, true, true)
))
);
}

Expand Down

0 comments on commit ee21d2e

Please sign in to comment.