fix(rust-client): replace RandomCoin with ChaCha20Rng - #2414
Open
ricomateo wants to merge 12 commits into
Open
Conversation
…ects a non-CryptoRng
ricomateo
marked this pull request as ready for review
August 19, 2026 15:51
ricomateo
requested review from
SantiagoPittella,
TomasArrachea,
igamigo and
juan518munoz
August 19, 2026 15:51
RandomCoinRandomCoin with ChaCha20Rng
juan518munoz
left a comment
Collaborator
There was a problem hiding this comment.
Looks good overall. What I still don't understand is why we are keeping rng and secure_rng separately, for what I see we could just get away with the new secure implementation in all places.
If I'm not mistaken, keeping a single rng would also make the trybuild test redundant.
| /// the field modulus, which keeps the result uniform over the field. The rejection | ||
| /// probability is about 2^-32. | ||
| pub fn draw_felt(rng: &mut impl rand::Rng) -> crate::Felt { | ||
| use rand::RngExt; |
Collaborator
There was a problem hiding this comment.
we should move the import outside this function
| /// Uses rejection sampling: [`Felt::new`](crate::Felt::new) rejects any `u64` at or beyond | ||
| /// the field modulus, which keeps the result uniform over the field. The rejection | ||
| /// probability is about 2^-32. | ||
| pub fn draw_felt(rng: &mut impl rand::Rng) -> crate::Felt { |
Collaborator
There was a problem hiding this comment.
Maybe this functions are better suited in a separate file, similar to how we do with utils.rs, we could add an rng.rs file.
| /// | ||
| /// Use this for note serial numbers when building notes from a plain [`rand`] generator, which | ||
| /// does not implement [`FeltRng`]. | ||
| pub fn draw_word(rng: &mut impl rand::Rng) -> crate::Word { |
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 #2204
RandomCoinwithChaCha20Rng.ClientBuilder::rngnow requires the RNG to implementCryptoRng(i.e.RandomCoinis no longer accepted, since it is not aCryptoRng).Client::secure_rng, a second RNG intended to be used to generate randomness for secret values.trybuildtest asserting thatClientBuilder::rngrejects aFeltRngwhich is not aCryptoRng.