Skip to content

Commit

Permalink
Simplify and explain arbitrary
Browse files Browse the repository at this point in the history
  • Loading branch information
Oppen committed Oct 4, 2023
1 parent 2db8cfd commit 00673e9
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions crates/stark-felt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,13 @@ impl Felt {

#[cfg(feature = "arbitrary")]
impl<'a> Arbitrary<'a> for Felt {
// Creates an arbitrary `Felt` from unstructured input for fuzzing.
// It uses the default implementation to create the internal limbs and then
// uses the usual constructors from `lambdaworks-math`.
fn arbitrary(u: &mut Unstructured) -> arbitrary::Result<Self> {
let hex_chars = [
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f",
];
let mut hex_string = String::new();
for _ in 0..63 {
hex_string.push_str(u.choose(&hex_chars)?);
}
let felt = FieldElement::<Stark252PrimeField>::from_hex_unchecked(&hex_string);
let limbs = <[u64; 4]>::arbitrary(u);
let uint = UnsignedInteger::from_limbs(limbs);
let felt = FieldElement::from(uint);
Ok(Felt(felt))
}
}
Expand Down

0 comments on commit 00673e9

Please sign in to comment.