Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
Ensure nonnative field negate works in case of non-normalized input
Browse files Browse the repository at this point in the history
this commit also adds some assertions to make sure that we never
overflow max_mods_to_fit.
  • Loading branch information
jules committed Jun 9, 2024
1 parent 4bcb11f commit 63a7c9e
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ where
}
}

assert!(self.tracker.max_moduluses <= self.params.max_mods_to_fit);
new
}

Expand Down Expand Up @@ -334,6 +335,7 @@ where
}
}

assert!(self.tracker.max_moduluses <= self.params.max_mods_to_fit);
new
}

Expand Down Expand Up @@ -713,6 +715,7 @@ where
// enforce that r is canonical
new.enforce_reduced(cs);

assert!(self.tracker.max_moduluses <= self.params.max_mods_to_fit);
new
}

Expand Down Expand Up @@ -764,7 +767,9 @@ where
let new = Self {
limbs,
non_zero_limbs: used_words,
tracker: OverflowTracker { max_moduluses: 2 }, // NOTE: if self == 0, then limbs will be == modulus, so use 2
tracker: OverflowTracker {
max_moduluses: std::cmp::max(2, self.tracker.max_moduluses),
}, // NOTE: if self == 0, then limbs will be == modulus, so use 2
form: RepresentationForm::Normalized,
params: self.params.clone(),
_marker: std::marker::PhantomData,
Expand Down Expand Up @@ -858,6 +863,7 @@ where
}
}

assert!(self.tracker.max_moduluses <= self.params.max_mods_to_fit);
new
}

Expand Down

0 comments on commit 63a7c9e

Please sign in to comment.