-
Notifications
You must be signed in to change notification settings - Fork 4
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
Some security relevant comments #85
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,8 +74,9 @@ contract PDPVerifier is Initializable, UUPSUpgradeable, OwnableUpgradeable { | |
// randomness sampling for challenge generation. | ||
// | ||
// The purpose of this delay is to prevent SPs from biasing randomness by running forking attacks. | ||
// This is actually not possible with the challenge sampling method written here. Qe sample from DRAND | ||
// and forking attacks are unrelated to biasability, hence challengeFinality = 1 is a safe value. | ||
// Given a small enough challengeFinality an SP can run several trials of challenge sampling and | ||
// fork around samples that don't suit them, grinding the challenge randomness. | ||
// For the filecoin L1, a safe value is 150. | ||
// | ||
// We keep this around for future portability to a variety of environments with different assumptions | ||
// behind their challenge randomness sampling methods. | ||
|
@@ -383,6 +384,13 @@ contract PDPVerifier is Initializable, UUPSUpgradeable, OwnableUpgradeable { | |
uint256 sumTreeTop = 256 - BitOps.clz(nextRootId[setId]); | ||
for (uint64 i = 0; i < proofs.length; i++) { | ||
// Hash (SHA3) the seed, proof set id, and proof index to create challenge. | ||
// Note -- there is a slight deviation here from the uniform distribution. | ||
// Some leaves are challenged with probability p and some have probability p + deviation. | ||
// This deviation is bounded by leafCount / 2^256 given a 256 bit hash | ||
// Assuming a 1000EiB = 1 ZiB network size ~ 2^70 bytes of data or 2^65 leaves | ||
// This deviation is bounded by 2^65 / 2^256 = 2^-191 which is negligible. | ||
// If modifying this code to use a hash function with smaller output size | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'd add a comment on which is the "standard solution" (i.e. rejection sampling). Best would be to have a quick note on why we are not implementing it |
||
// this deviation will increase and caution is advised. | ||
bytes memory payload = abi.encodePacked(seed, setId, i); | ||
uint256 challengeIdx = uint256(keccak256(payload)) % leafCount; | ||
|
||
|
Oops, something went wrong.
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.
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.
// We are setting here this value at 150, as in the Filecoin L1 (epochs between PreCommit and ProveCommit for interactive PoRep Sectors)