Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add double implementation for Felt #44

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions crates/starknet-types-core/proptest-regressions/felt/mod.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Seeds for failure cases proptest has generated in the past. It is
tcoratger marked this conversation as resolved.
Show resolved Hide resolved
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc 7cc7e05316cf3a4fc6fc302a9d0addd5ec76e6cd733ef30c109c14be6d0bf9d5 # shrinks to x = Felt(FieldElement { value: UnsignedInteger { limbs: [300729720636178304, 1831347307108920996, 11337269826263459472, 8939133563709308857] } })
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))
0xLucqs marked this conversation as resolved.
Show resolved Hide resolved
}

/// 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