forked from starknet-io/types-rs
-
Notifications
You must be signed in to change notification settings - Fork 1
[Preliminary Pull Request] Use LambdaWorks
' FieldElement
in stark-felt
crate
#1
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
Open
fmoletta
wants to merge
60
commits into
main
Choose a base branch
from
use-lambdaworks-felt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 59 commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
6aaa082
Set lambdaworks felt as Felt
fmoletta 1bfd360
Temporarily remove `Copy` derive trait + implement `Eq` & `PartialEq`…
fmoletta e1cbb86
Temporarily remove const + implement some fns
fmoletta 0e2413b
Impelemnt more methods
fmoletta 94571bf
Derive Copy
fmoletta 6ae2304
Implement methods + add questions in comment
fmoletta 8a7a08b
Add questions in comment
fmoletta e635d88
Implement basic traits
fmoletta 7cf2ac7
Implement addition
fmoletta 6b719ce
Implement sub + mul
fmoletta 2d38c76
Implement some traits
fmoletta d8aaff3
Add to_be_bytes impl
fmoletta 0bed61f
Move implementation of PartialEq & Eq to lambdaworks
fmoletta 304fe56
Implement `Display` for errors
fmoletta 8aa11b4
Implement constants
fmoletta 8915253
Remove Todo
fmoletta 2fb2bfa
Implement to_bits_le
fmoletta 91261e5
Implement to_bits_be
fmoletta d441085
Clippy
fmoletta 34c11c7
Simplify sqrt
fmoletta 5020bb8
Remove comment
fmoletta 25a35df
Simplify is_zero
fmoletta 3419d8b
Add split for not(target_pointer_width = "64")
fmoletta 74fbbb6
Fix array handling
fmoletta b669c3a
Remove comment & wrong impl
fmoletta a1a7c62
Fix wrong impl
fmoletta 6149f12
Remove wrong impls
fmoletta cd961ad
Add deserialization from hex string
fmoletta f6c116b
Implement UpperHex fmt
fmoletta 537f483
Remove comments
fmoletta d48cbb1
Implement `mul_mod` & `inverse_mod`
fmoletta 2695f68
Implement floor_div
fmoletta 63a6347
Fix constants
fmoletta 0a3a0b7
Add proptests
fmoletta 2a2a653
Add proptest
fmoletta 7f2bd3a
Remove wrong usage of from_raw
fmoletta ec76d87
Add proptest
fmoletta 59c1837
Add proptest
fmoletta 7c0a77a
Fix deserialization
fmoletta d9c51f5
Add tests for basic constants
fmoletta d81c0ae
Add test for max constant
fmoletta 8188168
Add test for zero constant
fmoletta d192fff
Test is_zero
fmoletta c4f4790
Add more proptests
fmoletta 02242f4
Fix serialization & deserialization
fmoletta 9ee8b6f
Test hexadecimal display
fmoletta a863f4e
Improve tests
fmoletta 2f47fe3
Implement Display
fmoletta 63acbf5
Fix Display + add tests
fmoletta 2eb99bd
fmt
fmoletta 6ee5950
Simplify methods
fmoletta 1bf28f7
Remove doc comments from tests
fmoletta 9523238
Add proptest for floor_div
fmoletta 51b0fd5
Add tests for basic operations
fmoletta b8b91e5
Add pow operations test
fmoletta 834a952
Update toml
fmoletta 39be089
Add arbitrary.rs
fmoletta f5e0cc8
Remove std import
fmoletta 7c09e6d
Clippy
fmoletta 1b6aaaa
Bump version
fmoletta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use lambdaworks_math::{field::element::FieldElement, unsigned_integer::element::UnsignedInteger}; | ||
use proptest::prelude::*; | ||
|
||
use crate::Felt; | ||
const FIELD_HIGH: u128 = (1 << 123) + (17 << 64); // this is equal to 10633823966279327296825105735305134080 | ||
const FIELD_LOW: u128 = 1; | ||
|
||
/// Returns a [`Strategy`] that generates any valid Felt | ||
fn any_felt() -> impl Strategy<Value = Felt> { | ||
(0..=FIELD_HIGH) | ||
// turn range into `impl Strategy` | ||
.prop_map(|x| x) | ||
// choose second 128-bit limb capped by first one | ||
.prop_flat_map(|high| { | ||
let low = if high == FIELD_HIGH { | ||
(0..FIELD_LOW).prop_map(|x| x).sboxed() | ||
} else { | ||
any::<u128>().sboxed() | ||
}; | ||
(Just(high), low) | ||
}) | ||
// turn (u128, u128) into limbs array and then into Felt | ||
.prop_map(|(high, low)| { | ||
let limbs = [ | ||
(high >> 64) as u64, | ||
(high & ((1 << 64) - 1)) as u64, | ||
(low >> 64) as u64, | ||
(low & ((1 << 64) - 1)) as u64, | ||
]; | ||
FieldElement::new(UnsignedInteger::from_limbs(limbs)) | ||
}) | ||
.prop_map(Felt) | ||
} | ||
|
||
/// Returns a [`Strategy`] that generates any nonzero Felt | ||
pub fn nonzero_felt() -> impl Strategy<Value = Felt> { | ||
any_felt().prop_filter("is zero", |x| !x.is_zero()) | ||
} | ||
|
||
impl Arbitrary for Felt { | ||
type Parameters = (); | ||
|
||
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { | ||
any_felt().sboxed() | ||
} | ||
|
||
type Strategy = SBoxedStrategy<Self>; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be moved to
0.1.2
: Even Spicier Shakshuka 🔥There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im waiting for
0.1.3
: * Insert even cooler name *There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spiciest Shakshuka 🔥 🔥 🔥 ?