Skip to content

[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
wants to merge 60 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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 Jun 27, 2023
1bfd360
Temporarily remove `Copy` derive trait + implement `Eq` & `PartialEq`…
fmoletta Jun 27, 2023
e1cbb86
Temporarily remove const + implement some fns
fmoletta Jun 27, 2023
0e2413b
Impelemnt more methods
fmoletta Jun 27, 2023
94571bf
Derive Copy
fmoletta Jun 27, 2023
6ae2304
Implement methods + add questions in comment
fmoletta Jun 27, 2023
8a7a08b
Add questions in comment
fmoletta Jun 27, 2023
e635d88
Implement basic traits
fmoletta Jun 27, 2023
7cf2ac7
Implement addition
fmoletta Jun 27, 2023
6b719ce
Implement sub + mul
fmoletta Jun 27, 2023
2d38c76
Implement some traits
fmoletta Jun 27, 2023
d8aaff3
Add to_be_bytes impl
fmoletta Jun 27, 2023
0bed61f
Move implementation of PartialEq & Eq to lambdaworks
fmoletta Jun 27, 2023
304fe56
Implement `Display` for errors
fmoletta Jun 27, 2023
8aa11b4
Implement constants
fmoletta Jun 27, 2023
8915253
Remove Todo
fmoletta Jun 29, 2023
2fb2bfa
Implement to_bits_le
fmoletta Jun 29, 2023
91261e5
Implement to_bits_be
fmoletta Jun 29, 2023
d441085
Clippy
fmoletta Jun 29, 2023
34c11c7
Simplify sqrt
fmoletta Jun 29, 2023
5020bb8
Remove comment
fmoletta Jun 29, 2023
25a35df
Simplify is_zero
fmoletta Jun 29, 2023
3419d8b
Add split for not(target_pointer_width = "64")
fmoletta Jun 29, 2023
74fbbb6
Fix array handling
fmoletta Jun 29, 2023
b669c3a
Remove comment & wrong impl
fmoletta Jun 29, 2023
a1a7c62
Fix wrong impl
fmoletta Jun 29, 2023
6149f12
Remove wrong impls
fmoletta Jun 29, 2023
cd961ad
Add deserialization from hex string
fmoletta Jun 29, 2023
f6c116b
Implement UpperHex fmt
fmoletta Jun 29, 2023
537f483
Remove comments
fmoletta Jun 30, 2023
d48cbb1
Implement `mul_mod` & `inverse_mod`
fmoletta Jul 3, 2023
2695f68
Implement floor_div
fmoletta Jul 3, 2023
63a6347
Fix constants
fmoletta Jul 3, 2023
0a3a0b7
Add proptests
fmoletta Jul 3, 2023
2a2a653
Add proptest
fmoletta Jul 3, 2023
7f2bd3a
Remove wrong usage of from_raw
fmoletta Jul 3, 2023
ec76d87
Add proptest
fmoletta Jul 3, 2023
59c1837
Add proptest
fmoletta Jul 3, 2023
7c0a77a
Fix deserialization
fmoletta Jul 4, 2023
d9c51f5
Add tests for basic constants
fmoletta Jul 4, 2023
d81c0ae
Add test for max constant
fmoletta Jul 4, 2023
8188168
Add test for zero constant
fmoletta Jul 4, 2023
d192fff
Test is_zero
fmoletta Jul 4, 2023
c4f4790
Add more proptests
fmoletta Jul 4, 2023
02242f4
Fix serialization & deserialization
fmoletta Jul 4, 2023
9ee8b6f
Test hexadecimal display
fmoletta Jul 4, 2023
a863f4e
Improve tests
fmoletta Jul 4, 2023
2f47fe3
Implement Display
fmoletta Jul 4, 2023
63acbf5
Fix Display + add tests
fmoletta Jul 4, 2023
2eb99bd
fmt
fmoletta Jul 4, 2023
6ee5950
Simplify methods
fmoletta Jul 4, 2023
1bf28f7
Remove doc comments from tests
fmoletta Jul 4, 2023
9523238
Add proptest for floor_div
fmoletta Jul 4, 2023
51b0fd5
Add tests for basic operations
fmoletta Jul 4, 2023
b8b91e5
Add pow operations test
fmoletta Jul 4, 2023
834a952
Update toml
fmoletta Jul 4, 2023
39be089
Add arbitrary.rs
fmoletta Jul 4, 2023
f5e0cc8
Remove std import
fmoletta Jul 4, 2023
7c09e6d
Clippy
fmoletta Jul 4, 2023
1b6aaaa
Bump version
fmoletta Jul 4, 2023
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
8 changes: 7 additions & 1 deletion crates/stark-felt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ readme = "README.md"
[dependencies]
bitvec = { version = "1.0.1", default-features = false }
serde = { version = "1.0.163", optional = true, default-features = false }

# TODO: use version once published
# lambdaworks-math = { version = "0.1.1", default-features = false }
Comment on lines +16 to +17

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 🔥

Copy link
Collaborator Author

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 *

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spiciest Shakshuka 🔥 🔥 🔥 ?

lambdaworks-math = { git = "https://github.com/lambdaclass/lambdaworks.git", rev = "bfd91d4e8116ab8b0bf25f75a9f1e8bb61d355d9", default_features = false}
[features]
default = ["std", "serde"]
std = []
alloc = ["serde?/alloc"]

[dev-dependencies]
proptest = "1.1.0"
serde_test = "1.0.1"
48 changes: 48 additions & 0 deletions crates/stark-felt/src/arbitrary.rs
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>;
}
Loading