-
Notifications
You must be signed in to change notification settings - Fork 25
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
feat: deterministic pseudorandom operations #140
Conversation
Really interesting, just wondering why this is not also implemented (or should I say required) to produce a |
Added! We can't get a |
Moving this from draft to ready, in case there's a desire to implement it directly. |
a37e5ad
to
a6b403c
Compare
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.
It's not clear why bounds are restricted to u32 here. Why wouldn't we just use u64?
I'm leaning towards all or nothing on the rand dependency - either impl our own |
The Do you think it could be the case that we'd still end up in dependency mismatch land if we update |
That is my concern, yes. |
49c19d2
to
509896d
Compare
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.
utACK
@CjS77 brought up the idea that if we take this approach, it's better to implement |
900f1a3
to
aee0a8c
Compare
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.
One nit in the doc string, but LGTM
704de49
to
13d83d1
Compare
This is a proof of concept for a deterministic shuffler and bounded number generator for use in consensus-critical applications. It provides a generic API that lets you choose your favorite CSPRNG.
Some protocol applications are likely to require the use of consensus-based pseudorandomness. For example, the network may need to choose or shuffle among validator nodes using chain state data as a common seed. This means that all such nodes must take this seed and use it to arrive at the same results. While
rand
has generic functionality for these kinds of operations using any random number generator, there is no guarantee that its algorithms for doing so will be the same across versions, which could lead to dependency issues.This work provides one design that has no
rand
dependency. It offers a genericDeterministicRandomizer
type that can be instantiated with any seedable CSPRNG. The tests use aChaCha12
-based generator that happens to be the standard one used inrand
currently, but which we import explicitly fromrand_chacha
instead.When a bounded
u32
is requested, it takes au64
value from the PRNG and reduces it. When a boundedu64
is requested, it takes twou64
values from the PRNG, uses bit shifting to produce au128
value, and reduces it. This approach mitigates bias.Comments welcome.