-
Notifications
You must be signed in to change notification settings - Fork 583
chore: pedersen hash audit #19736
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
Open
nishatkoti
wants to merge
3
commits into
merge-train/barretenberg
Choose a base branch
from
nk/pedersen-hash-one
base: merge-train/barretenberg
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+151
−10
Open
chore: pedersen hash audit #19736
Changes from all commits
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 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
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
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
2 changes: 0 additions & 2 deletions
2
barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/pedersen.hpp
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
35 changes: 35 additions & 0 deletions
35
barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/README.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Pedersen Hash and Commitment | ||
|
|
||
| This module implements the Pedersen hash (`crypto/pedersen_hash`) and commitment (`crypto/pedersen_commitment`) over the Grumpkin curve. | ||
|
|
||
| ## Pederson Commitment | ||
| For a vector of field elements $x = [x_0, \dots, x_{n-1}]$, the commitment is $Commit(x) = \sum_{i=0}^{n-1} x_i \cdot G_i$, where $G = [G_0, G_1, \dots]$ are generators derived via `generator_data`. | ||
|
|
||
| ## Pederson Hash | ||
| For a vector of field elements $v = [v_0, \ldots, v_{n-1}]$, the hash is defined as the x-coordinate of $Hash(v) = n · H_{len} + Commit(v)$, where $H_{len}$ is a length generator derived with domain separator `"pedersen_hash_length"`. | ||
|
|
||
| The length term avoids trivial collisions arising from the `x(P) = x(-P)` symmetry and to bind the hash to the input length. | ||
|
|
||
| ## API | ||
| ### Hash | ||
| - `hash(const std::vector<Fq>& inputs, const GeneratorContext context)` | ||
| - Hashes a vector of field elements using generators from `context`. | ||
|
|
||
| - `hash_buffer(const std::vector<uint8_t>& input, const GeneratorContext context)` | ||
| - Converts an arbitrary byte buffer into field elements by splitting into 31-byte chunks, followed by hashing. | ||
| - For >2 chunks it hashes iteratively: `r = hash(e0,e1); r = hash(r,e2); ...`. | ||
|
|
||
| ### Commitment | ||
| - `commit_native(const std::vector<Fq>& inputs, GeneratorContext context)` | ||
| - Computes $Commit(inputs)$ using generators from `context`. | ||
|
|
||
| ## Tests | ||
| ### Hash tests | ||
| - `DeriveLengthGenerator`: verifies that the `"pedersen_hash_length"` generator matches a known point. | ||
| - `Hash`: regression test for `hash({1,1})`. | ||
| - `HashWithIndex`: regression test for `hash({1,1}, offset=5)`. | ||
| - `Hash32Bytes`: checks iterative hashing performed within `hash_buffer` on a 32=31+1 byte input. | ||
|
|
||
| ### Commitment tests | ||
| - `Commitment`: regression test for `commit_native({1,1})`. | ||
| - `CommitmentWithZero`: regression test for `commit_native({0,1})`. |
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.
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.
Removed the TODO referencing closed issue #2341; pedersen_commitment is used by pedersen_hash.