Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions ff/src/fields/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ pub trait Field:
/// least significant limb first.
#[must_use]
fn pow<S: AsRef<[u64]>>(&self, exp: S) -> Self {
// handle the special case when self = 0 and exp = 0
if self.is_zero() {
assert_ne!(exp.as_ref().iter().filter(|x| **x != 0u64).count(), 0);
return Self::zero();
}

let mut res = Self::one();

for i in BitIteratorBE::without_leading_zeros(exp) {
Expand Down Expand Up @@ -797,4 +803,14 @@ mod no_std_tests {
assert_eq!(expected, actual, "failed on test {:?}", i);
}
}

#[test]
#[should_panic]
fn pow_zero_by_zero() {
use crate::test_field::Fr;
use crate::Field;
use ark_std::Zero;

let _ = Fr::zero().pow(&[0u64, 0u64, 0u64, 0u64]);
}
}