Skip to content

Commit

Permalink
Add double implementation for Felt (starknet-io#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger authored Mar 12, 2024
1 parent 32deb81 commit 4a7656e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions crates/starknet-types-core/src/felt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@ impl Felt {
Self(self.0.square())
}

/// Doubles the point `self`
pub fn double(&self) -> Self {
Self(self.0.add(self.0))
}

/// Raises `self` to the power of `exponent`.
pub fn pow(&self, exponent: impl Into<u128>) -> Self {
Self(self.0.pow(exponent.into()))
Expand Down Expand Up @@ -1304,6 +1309,11 @@ mod test {
}

#[test]
fn double_in_range(x in any::<Felt>()) {
prop_assert!(x.double() == x + x);
}

#[test]
fn square_in_range(x in any::<Felt>()) {
prop_assert!(x.square() <= Felt::MAX);
}
Expand Down

0 comments on commit 4a7656e

Please sign in to comment.