You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The fix correctly addresses a real bug where random_bit_list could set fewer than length bits due to duplicate indices. The original code looped length times, but could land on the same bit multiple times via rng.gen::<usize>() % 256, giving you a bitlist with fewer set bits than requested.
rand::seq::index::sample draws length unique indices from [0, 256) without replacement — exactly what's needed here. This is the correct, idiomatic fix.
Notes
1. Intentional divergence from Go — The Go reference (charon/testutil/random.go) has the same duplicate-index issue:
This PR makes Pluto's version stricter than the Go counterpart. Per AGENTS.md, the default is functional equivalence with Go, but since this is test utility code and the Go version's behavior appears to be a latent bug rather than an intentional design choice, the fix is justified. The overall test semantics (generating a bitlist with some bits set) are preserved.
2. The assert! guard is appropriate — Calling index::sample(rng, 256, n) with n > 256 would panic with a cryptic message from inside rand. The explicit assert! with a clear message is good practice.
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
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.
Should fix this: #317