-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bump rand to 0.8, rand_chacha to 0.3, getrandom to 0.2 #32871
Conversation
@@ -25,6 +25,9 @@ use { | |||
pub struct Keypair(ed25519_dalek::Keypair); | |||
|
|||
impl Keypair { | |||
/// Can be used for generating a Keypair without a dependency on `rand` types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment might be too specific, but it shows why I needed it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hardcode 64
and static_assertions::const_assert_eq!(SECRET_KEY_LENGTH, ed25519_dalek::SECRET_KEY_LENGTH)
to keep dalek out of the api?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even better, will do!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in db48acc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good to me!
For the changes on the actual cryptographic bits, I think another set of eyes with proper experience would be a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this whole change set makes me want to take a hardline that traits have no business being versioned with logic
@@ -25,6 +25,7 @@ pub fn get_append_vec_path(path: &str) -> TempFile { | |||
let out_dir = get_append_vec_dir(); | |||
let rand_string: String = rand::thread_rng() | |||
.sample_iter(&Alphanumeric) | |||
.map(char::from) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this whole method seems ripe for replacement with tempfile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Truth
@@ -25,6 +25,9 @@ use { | |||
pub struct Keypair(ed25519_dalek::Keypair); | |||
|
|||
impl Keypair { | |||
/// Can be used for generating a Keypair without a dependency on `rand` types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hardcode 64
and static_assertions::const_assert_eq!(SECRET_KEY_LENGTH, ed25519_dalek::SECRET_KEY_LENGTH)
to keep dalek out of the api?
@@ -4,7 +4,7 @@ use { | |||
rand::{Rng, SeedableRng}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
til this module exists. think i might need a sick day 🤢
Run `git grep -l gen_range | xargs sed -i'' -e 's/gen_range(\(\S*\), /gen_range(\1../'
Run: ``` git grep -l hash::new_rand | xargs sed -i'' -e 's/hash::new_rand([^)]*/hash::new_with_thread_rng(/' ```
ledger/src/shred/merkle.rs
Outdated
let mut seed = [0u8; Keypair::SECRET_KEY_LENGTH]; | ||
rng.fill(&mut seed[..]); | ||
let keypair = keypair_from_seed(&seed).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one isn't using chacha, so changing to Keypair::new
ledger/src/shred/merkle.rs
Outdated
let mut seed = [0u8; Keypair::SECRET_KEY_LENGTH]; | ||
rng.fill(&mut seed[..]); | ||
let keypair = keypair_from_seed(&seed).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is also using thread_rng, so switching to Keypair::new
@@ -25,6 +25,9 @@ use { | |||
pub struct Keypair(ed25519_dalek::Keypair); | |||
|
|||
impl Keypair { | |||
/// Can be used for generating a Keypair without a dependency on `rand` types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in db48acc
Ok, I think all comments have been addressed, thanks for your careful and quick reviews! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm - all my concerns have been resolved. Thanks!
@@ -308,9 +308,16 @@ mod test { | |||
); | |||
} | |||
|
|||
fn generate_random_hash() -> Hash { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol... Hash::new_unique()
is broken. it should be hashing the counter, not using it straight up 🙃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can try changing it to that and see if the bloom filter test passes. On the flipside, and I might be understanding this wrong, but it seems like the test is meant for random hashes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nah don't mess with it here
Trying to resolve the additional rebuilds of |
I couldn't get a combination that linked successfully and also kept the rebuilds at the same number, so I had to increase from 14 to 15 rebuilds, which feels not-too-bad! |
presumably we're now linking something against both versions of rand, so expected? |
Yeah probably... all my efforts were useless since they just reintroduced the linking error, which is strange because I couldn't reproduce it on any local machine this time, whereas I could before. Anyway, had to increase the number of rebuilds to 17 🙃 |
Codecov Report
@@ Coverage Diff @@
## master #32871 +/- ##
=======================================
Coverage 82.0% 82.0%
=======================================
Files 785 784 -1
Lines 212387 212437 +50
=======================================
+ Hits 174190 174245 +55
+ Misses 38197 38192 -5 |
It finally passed woo! |
Problem
In order to properly address the cargo audit error in #32836, we'll need to bump ed25519-dalek everywhere, which also entails upgrading the various
rand
dependencies.Summary of Changes
Since we expose a dependency to the rand 0.7 types through functions like
Keypair::generate
, we need to be careful about performing this bump to avoid breaking downstream users. This PR does not break downstream users and avoids touching ed25519-dalek / libsecp256k1, except in tests. That work can be done in other PRs.Here are the Solana-specific changes in this PR:
hash::new_rand()
in favor ofhash::new_with_thread_rng()
, since just about everywhere that usednew_rand
was just passingthread_rng
, and it's only used in testssolana-zk-token-sdk
,solana_sdk::signer::keypair::Keypair
,solana_sdk::ed25519_instruction
,solana_sdk::secp256k1_instruction
Here are the rand-required changes in the PR:
gen_range
now takes a range, sogen_range(1, 2)
becomesgen_range(1..2)
map(char::from)
when generating a random stringFill
instead ofAsByteSliceMut
ThreadRng
implementingCopy
More information on rand at https://rust-random.github.io/book/update-0.8.html
You should be able to follow the commits pretty linearly, except when I wrongly created
Keypair::from_secret_key_bytes
, only to realize that it was justkeypair_from_seed
a few commits later. The concept was:git grep -l gen_range | xargs sed -i'' -e 's/gen_range(\(\S*\), /gen_range(\1../'
to fix mostgen_range
instances in 99a0f1e, then clean it up in f78cef6git grep -l hash::new_rand | xargs sed -i'' -e 's/hash::new_rand([^)]*/hash::new_with_thread_rng(/'
to deprecatehash::new_rand
everywhere in 5f9675aPlease tag anyone else who might be good to review this!
Fixes #