Ugrade rand to 0.10.1#2042
Merged
ImplOfAnImpl merged 6 commits intorand_upgrade_autorename_gen_to_randomfrom Apr 23, 2026
Merged
Ugrade rand to 0.10.1#2042ImplOfAnImpl merged 6 commits intorand_upgrade_autorename_gen_to_randomfrom
rand to 0.10.1#2042ImplOfAnImpl merged 6 commits intorand_upgrade_autorename_gen_to_randomfrom
Conversation
923130c to
f6d8d3b
Compare
OBorce
approved these changes
Apr 23, 2026
…e `RngCoreAndCrypto` trait.
…te some comments. Pacify clippy and `cargo vet`.
…version to 20.x in .github/workflows/wasm.yml
2e45c58 to
c9f47dd
Compare
f6d8d3b to
07ff2c4
Compare
252725e
into
rand_upgrade_autorename_gen_to_random
20 checks passed
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.
Initially this PR was intended to address the recently discovered unsoundness in
rand, where the fix was only available in versions 0.9.3 and 0.10.1, but not in 0.8.x (which we use widely in master) and earlier versions.It turned out that 0.8.x has also been patched and 0.8.6 is sound. But I still would like to merge this:
CryptoRngis now a sub-trait ofRng.genis a reserved keyword, so we'd have to do a massive auto-replace anyway, changinggentor#gen. The latter is ugly, so why not just upgraderandto a newer version, where this function has already been renamed torandom.So in this PR the version of
randthat we directly use was upped to 0.10.1. Some of our dependencies still use0.9.x and0.8.x, so when a 0.10 RNG has to be passed to a method where an older one is expected, an adapter struct is used.To avoid having to use an adapter struct with the
random_usingcall that comes fromfixed_hash, I created a wrapper forfixed_hash::construct_fixed_hash!, so that the constructed hash'srandom_usingmethod accepts a 0.10 RNG instead of a 0.8 one.After this, the number of places where an adapter has to be used is relatively small.
The list of breaking changes that happened in 0.9.x is here and in 0.10.x here.
Some notable changes:
genis a reserved keyword in Rust 2024, the corresponding method was renamed torandom. For consistency,gen_rangebecamerandom_rangeandgen_boolbecamerandom_bool.RngCoretrait was renamed toRngand the originalRngtoRngExt.CryptoRngis now a sub-trait ofRng, soimpl Rng + CryptoRngcan be replaced with justimpl CryptoRngand the traitRngCoreAndCryptois no longer needed.TryRng/TryCryptoRngwere added, which are fallible versions ofRng/CryptoRng. Also, nowTryRng<Error = Infallible>is a sub-trait ofRngandRngis implemented for everyR: TryRng<Error = Infallible>.And infallible RNGs now have to implement
TryRng<Error = Infallible>instead ofRng.StepRng, which we used for testing, was removed, so I had to add a custom struct intest-utilsinstead.choose_multiplemethod is now deprecated in favor ofsample, but the difference is only in the name.Standardwas renamed toStandardUniformand it's no longer implemented forusize, sorng.random::<usize>()no longer compiles.SliceRandomtrait has been split into three traits:IndexedRandom,IndexedMutRandomandSliceRandom.Additionally I updatedsecp256k1to 0.31 (it uses rand 0.9). There is also 0.32, but according to their changelog - https://github.com/rust-bitcoin/rust-secp256k1/blob/master/CHANGELOG.md - there are lots of breaking changes and they still use rand 0.9, so I decided to leave it at 0.31 for now.Related changes:* methods that accept a slice were deprecated in favor of similar functions that accept a fixed-size array (Signature::from_slice->from_byte_array,Message::from_digest_slice->from_digest). So slice-to-array conversion now has to be done at the caller side.*Signature::serializewas deprecated in favor ofto_byte_array(only the name differs).I reverted the update of
secp256k1to 0.31, because there were issues with building it for wasm. (More precisely, its dependencysecp256k1-syswasn't compiling because apparently the underlying C library usesmemmove, but the crate'swasm-sysroot/string.honly declaresmemset/memcpy/memcmp. Looks like this is fixed in 0.32, but 0.32 hasn't been released yet it seems).P.S.
deny.tomlstill has the exception for therandunsoundness issue, because technically we still userand0.7.x as well, which is brought in by theprobabilistic-collectionscrate. But we don't useprobabilistic-collectionsin a way that would make it construct a new RNG, so the unsoundness is only "technical".getrandomv0.2 (used byrand0.8) had some workarounds related to older nodejs versions that were removed ingetrandomv0.3. But nodejs v18 is long past its EOL, so I uppednode-versionin.github/workflows/wasm.ymlto20.x(BTW nodejs 20 will also reach it EOL at the end of this month).