Skip to content

Commit

Permalink
fix: Program cmp depends on hints_ranges ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaRedHand committed Jul 26, 2023
1 parent 7a1cabb commit c803e6b
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion vm/src/types/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use arbitrary::Arbitrary;
// failures.
// Fields in `Program` (other than `SharedProgramData` itself) are used by the main logic.
#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))]
#[derive(Clone, Default, Debug, PartialEq, Eq)]
#[derive(Clone, Default, Debug, Eq)]
pub(crate) struct SharedProgramData {
pub(crate) data: Vec<MaybeRelocatable>,
pub(crate) hints: Vec<HintParams>,
Expand All @@ -66,6 +66,44 @@ pub(crate) struct SharedProgramData {
/// Is [`None`] if the range is empty, and it is [`Some`] tuple `(start, length)` otherwise.
type HintRange = Option<(usize, NonZeroUsize)>;

impl PartialEq for SharedProgramData {
fn eq(&self, other: &Self) -> bool {
self.data == other.data
&& self.main == other.main
&& self.start == other.start
&& self.end == other.end
&& self.error_message_attributes == other.error_message_attributes
&& self.instruction_locations == other.instruction_locations
&& self.identifiers == other.identifiers
&& self.reference_manager == other.reference_manager
&& self.hints_equal(other)
}
}

impl SharedProgramData {
pub(crate) fn hints_equal(&self, other: &Self) -> bool {
if self.hints.len() != other.hints.len() {
return false;
}
for (ranges, other_ranges) in self.hints_ranges.iter().zip(other.hints_ranges.iter()) {
if ranges != other_ranges {
return false;
}
let Some((index, len)) = *ranges else {
continue;
};
let self_hints = self.hints.get(index..index + len.get()).unwrap().to_vec();
let other_hints = other.hints.get(index..index + len.get()).unwrap().to_vec();
for hint in self_hints {
if !other_hints.contains(&hint) {
return false;
}
}
}
true
}
}

#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Program {
Expand Down

0 comments on commit c803e6b

Please sign in to comment.