Repository navigation
fix: track monotonic entropy initialization - #141
Open
perfloop[bot] wants to merge 4 commits into
Open
perfloop[bot] wants to merge 4 commits into
perfloop[bot] wants to merge 4 commits into
Conversation
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
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.
@peterbourgon
Summary
MonotonicEntropyused the entropy value to decide whether it had initialized. An all-zero value is valid, so a same-timestamp call could reseed instead of incrementing and could return the same ID. The privatemonotonicStatenow keeps initialization in a separate bool within the 80-bit value's alignment padding, preserving the full entropy range. Timestamp changes still reseed, initial-read errors still propagate, and failed increments retain the last successful value so overflow continues to be reported. No public API changes.Conditional on successful independent uniform 80-bit reads and a same-timestamp follow-up, an initial zero selects the wrong branch with probability 2^-80 (about 1 in 1.21e24). An actual duplicate additionally requires the following read to be zero, so the two-read event is 2^-160. Other entropy readers can be non-uniform or correlated; these are not production-frequency estimates.
The changelog records these conditions.
This condition holds with this change and does not hold at
75921a7395850ea47ed4dfd832184a5a294c8fde:With Monotonic configured with inc=1 and a reader whose first 20 bytes are zero, two successful New calls at timestamp 123 return entropy zero followed by exactly one..TestMonotonicZeroEntropyreproduces the failure at timestamps 123 and 0; the nonzero-seed, changed-timestamp, and failed-initial-read controls pass on the base, and the test passes with the fix.TestMonotonicOverflowStatefails on the base and the earlier initialization-only change because a later same-timestamp call can return below the maximum; the final test passes with repeated overflow and timestamp-reseed checks.The small public-API comparison program used for the assertion is not part of this pull request.
Test plan
The formatting check,
go vet ./..., Staticcheck, andgo test -race ./...passed on Linux. The macOS and Windows variants ofgo test -race ./...did not run in this Linux sandbox and remain target-CI work.Generated by Perfloop.