refactor: use Distribution trait for random samplers#824
Open
Farukest wants to merge 1 commit into0xMiden:nextfrom
Open
refactor: use Distribution trait for random samplers#824Farukest wants to merge 1 commit into0xMiden:nextfrom
Farukest wants to merge 1 commit into0xMiden:nextfrom
Conversation
fe96db0 to
64c8de5
Compare
Implement `Distribution<Word>` for `StandardUniform` and update all random field element sampling to use `Uniform::new(0, Felt::ORDER_U64)` for proper uniform distribution over the Goldilocks field. - Add `Distribution<Word> for StandardUniform` in word/mod.rs - Update `random_felt()` and `random_word()` in rand/mod.rs - Refactor test helpers in aead, ies, and smt tests - Update benchmark random word generation Closes 0xMiden#722
64c8de5 to
fec9f0b
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #722
This PR refactors random samplers across the codebase to use the
Distributiontrait from therandcrate.Changes
Distribution<Word>forStandardUniform, enabling idiomaticrng.random::<Word>()usagerandom_felt()to useUniform::new(0, Felt::ORDER_U64)for proper uniform sampling over the Goldilocks fieldrandom_word()to delegate to the newDistribution<Word>implaead_poseidon2,xchacha,ies, andsmttests to use uniform field element samplingNotes
Feltis a foreign type alias (p3_goldilocks::Goldilocks), soDistribution<Felt>cannot be implemented due to the orphan rule. Instead,Uniform::new(0, Felt::ORDER_U64)is used directly where needed.Wordis a local type, soDistribution<Word> for StandardUniformis implemented inword/mod.rs.Distributionimpls forSecretKey/Nonceinaead_poseidon2are kept as-is (out of scope per Refactor all random samplers to useDistribution#722).