[cryptography/dkg] validate players length before cast in deal()#3272
Open
0xAysh wants to merge 1 commit intocommonwarexyz:mainfrom
Open
[cryptography/dkg] validate players length before cast in deal()#32720xAysh wants to merge 1 commit intocommonwarexyz:mainfrom
0xAysh wants to merge 1 commit intocommonwarexyz:mainfrom
Conversation
players.len() was cast to u32 without an upper bound check, allowing silent truncation on 64-bit systems. Mirror the existing validation pattern from Info::new() using the 1..u32::MAX range guard. Closes commonwarexyz#3062
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.
Fixes #3062
The issue flagged that
deal()was castingplayers.len() as u32without validating the upper bound. Values aboveu32::MAXsilently truncate — a set ofu32::MAX + 2players would cast to1, causingdeal()to compute a DKG withn = 1instead of the real participant count, producing cryptographically invalid shares with no error surfaced to the caller.The issue decription alos mentioned that
Info::new()already solves this exactly using aparticipant_rangeguard that covers both the lower bound (empty) and upper bound (overflow) in one check, reusing the existingError::NumPlayersvariant.deal()is a convenience helper that bypasses the full DKG path and had simply missed copying this guard.The fix mirrors
Info::new()directly so the validation pattern is consistent across the file.Closes #3062