Skip to content

Conversation

@joncinque
Copy link
Collaborator

Problem

The repo is still on rand v0.8 in a lot of places, but that version isn't very compatible with rust 2024 due to its usage of gen as a function name, which is becoming a keyword.

Summary of changes

Follow https://rust-random.github.io/book/update-0.9.html to perform the upgrade to rand v0.9 where possible.

Most crypto libraries are still on rand v0.8 / rand_core v0.6, and the blstrs and ecdsa implementations of random aren't as simple as just taking 32 or 64 random bytes, so I left those back.

cc @puhtaytow

#### Problem

The repo is still on rand v0.8 in a lot of places, but that version
isn't very compatible with rust 2024 due to its usage of `gen` as a
function name, which is becoming a keyword.

#### Summary of changes

Follow https://rust-random.github.io/book/update-0.9.html to perform the
upgrade to rand v0.9 where possible.

Most crypto libraries are still on rand v0.8 / rand_core v0.6, and the
blstrs and ecdsa implementations of `random` aren't as simple as just
taking 32 or 64 random bytes, so I left those back.
Copy link
Contributor

@alexpyattaev alexpyattaev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked the crates I know:

  • address
  • frozen-abi
  • keypair
  • serde-varint

Overall the change looks good, but I'd prefer if we pinned some version for frozen-abi. Technically, changing the rand version for frozen-abi at this point would require a major version bump (assuming someone has already started using the version with ABI checks).

# to avoid version skew and keep digest computation stable regardless of consumer dependencies.
rand = "0.8.5"
rand_chacha = "0.3.1"
rand = { workspace = true }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we pin the version of rand here to avoid ABI hashes from breaking accidentally? None of this runs in prod, so perf is a non-issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The frozen-abi tests in this repo would catch that, no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add those tests. But yes, they should catch this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@puhtaytow puhtaytow Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have this draft here #484 this should early catch eventual changes. Somehow it has the same issue as described here #477 - Works with cargo test, but with cargo hack those are skipped.

pub fn new() -> Self {
let mut rng = OsRng;
Self(ed25519_dalek::SigningKey::generate(&mut rng))
let secret_bytes = rand::random::<[u8; Self::SECRET_KEY_LENGTH]>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, this changes from explicitly using OsRng to using ThreadRng. Not sure it matters, just pointing it out. It is probably for the best.

@joncinque
Copy link
Collaborator Author

Technically, changing the rand version for frozen-abi at this point would require a major version bump (assuming someone has already started using the version with ABI checks).

Right, it's a little annoying, but probably for the best

@puhtaytow
Copy link
Contributor

puhtaytow commented Dec 2, 2025

Technically, changing the rand version for frozen-abi at this point would require a major version bump (assuming someone has already started using the version with ABI checks).

Right, it's a little annoying, but probably for the best

Unfortunately.

I have spoken with Alex and we agreed that perhaps it would be better if we switch frozen-abi to rand/chacha v0.9 using this ocassion. It would be breaking change, but performed now, would reflect in less work later.

If you think this is the good move then please leave frozen-abi crate deps as it was and here i have prepared the small PR #482 to be merged after yours.

@joncinque
Copy link
Collaborator Author

If you think this is the good move then please leave frozen-abi crate deps as it was and here i have prepared the small PR #482 to be merged after yours.

I don't understand, is the separate PR mainly to do the contribution in a separate PR? The changes are here and passing CI, why force me to spend extra time to revert parts of this PR?

@puhtaytow
Copy link
Contributor

If you think this is the good move then please leave frozen-abi crate deps as it was and here i have prepared the small PR #482 to be merged after yours.

I don't understand, is the separate PR mainly to do the contribution in a separate PR? The changes are here and passing CI, why force me to spend extra time to revert parts of this PR?

Sorry! I didn't notice that you adjusted the interface definition as well. All good! 🙏

alexpyattaev
alexpyattaev previously approved these changes Dec 3, 2025
Copy link
Contributor

@alexpyattaev alexpyattaev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving for crates:

  • address
    
  • frozen-abi
    
  • keypair
    
  • serde-varint
    

@joncinque
Copy link
Collaborator Author

@samkim-crypto can you review the other crates not covered by @alexpyattaev ?

samkim-crypto
samkim-crypto previously approved these changes Dec 4, 2025
Copy link
Contributor

@samkim-crypto samkim-crypto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I checked the rest of the crates and things look good to me.

  • we should keep rand to v0.8 for crates that depend on blstrs and ecdsa implementations
  • double checked the getrandom version update for sdk-wasm-js
  • the other crates seem pretty straightforward. There seems to be some places where we can write things in slightly more idiomatic way, but very minor nits that you can choose to update only if you want to

Comment on lines 136 to 140
let test_value = if rand::random_bool(0.5) {
Some(rand::random::<u64>())
} else {
None
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let test_value = if rand::random_bool(0.5) {
Some(rand::random::<u64>())
} else {
None
};
let test_value = rand::rng()
.random_bool(0.5)
.then(|| rand::random::<u64>());

Very minor nit: I guess this could be written slightly more idiomatically.

.sorted_by_key(|lockout| lockout.slot())
.collect();
let root = rng.gen_ratio(1, 2).then(|| {
let root = rng.random_ratio(1, 2).then(|| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Seems like random_ratio should be used for fractions like 1/3 or 5/7. For this particular case, it seems like rng.random_bool(0.5) is probably more idiomatic.

});
let timestamp = rng.gen_ratio(1, 2).then(|| rng.gen());
let hash = Hash::from(rng.gen::<[u8; 32]>());
let timestamp = rng.random_ratio(1, 2).then(|| rng.random());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: same here

@joncinque joncinque dismissed stale reviews from samkim-crypto and alexpyattaev via 0b27d3f December 4, 2025 10:41
@joncinque
Copy link
Collaborator Author

Addressed the nits, let me know what you think!

Copy link
Contributor

@samkim-crypto samkim-crypto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@joncinque joncinque merged commit 0623f42 into anza-xyz:master Dec 4, 2025
24 checks passed
@joncinque joncinque deleted the rand9 branch December 4, 2025 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants