From 00673e995ea9f141e1afcb35f143cfb03d4b217c Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Wed, 4 Oct 2023 15:06:58 -0300 Subject: [PATCH] Simplify and explain arbitrary --- crates/stark-felt/src/lib.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/stark-felt/src/lib.rs b/crates/stark-felt/src/lib.rs index 43ee8ae..5e0a4fd 100644 --- a/crates/stark-felt/src/lib.rs +++ b/crates/stark-felt/src/lib.rs @@ -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 { - 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::::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)) } }