-
Notifications
You must be signed in to change notification settings - Fork 191
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
Move commitment verification into verifier #1051
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -329,3 +329,45 @@ func PairingsVerify(a1 *bn254.G1Affine, a2 *bn254.G2Affine, b1 *bn254.G1Affine, | |
|
||
return nil | ||
} | ||
|
||
// GenerateBlobCommitment computes a kzg-bn254 commitment of blob data using SRS | ||
func (v *Verifier) GenerateBlobCommitment(blob []byte) (*encoding.G1Commitment, error) { | ||
inputFr, err := rs.ToFrArray(blob) | ||
if err != nil { | ||
return nil, fmt.Errorf("convert bytes to field elements, %w", err) | ||
} | ||
|
||
if len(v.Srs.G1) < len(inputFr) { | ||
return nil, fmt.Errorf( | ||
"insufficient SRS in memory: have %v, need %v", | ||
len(v.Srs.G1), | ||
len(inputFr)) | ||
} | ||
|
||
var commitment bn254.G1Affine | ||
_, err = commitment.MultiExp(v.Srs.G1[:len(inputFr)], inputFr, ecc.MultiExpConfig{}) | ||
if err != nil { | ||
return nil, fmt.Errorf("MultiExp: %w", err) | ||
} | ||
|
||
return &encoding.G1Commitment{X: commitment.X, Y: commitment.Y}, nil | ||
} | ||
|
||
// GenerateAndCompareBlobCommitment generates the kzg-bn254 commitment of the blob, and compares it with a claimed | ||
// commitment. An error is returned if there is a problem generating the commitment, or if the comparison fails. | ||
func (v *Verifier) GenerateAndCompareBlobCommitment(claimedCommitment *encoding.G1Commitment, blobBytes []byte) error { | ||
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. does this need to be public? 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. Yes, this will be called by the v2 client |
||
|
||
computedCommitment, err := v.GenerateBlobCommitment(blobBytes) | ||
if err != nil { | ||
return fmt.Errorf("compute commitment: %w", err) | ||
} | ||
|
||
if claimedCommitment.X.Equal(&computedCommitment.X) && | ||
claimedCommitment.Y.Equal(&computedCommitment.Y) { | ||
return nil | ||
} | ||
|
||
return fmt.Errorf( | ||
"commitment field elements do not match. computed commitment: (x: %x, y: %x), claimed commitment (x: %x, y: %x)", | ||
computedCommitment.X, computedCommitment.Y, claimedCommitment.X, claimedCommitment.Y) | ||
} |
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.
does this need to be public?
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.
I don't have any particular external use cases in mind. My tendency would be to keep it public, since it's a general purpose method to compute commitment from bytes, with likelihood of being used elsewhere in the future. But I'd have no strong objection to making it private
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 can rework the API later but I find it a bit weird that this method is on a strict called Verifier. I might want to compute a kzg commitment without verifying anything.
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.
I see your point. We could create a new type
Committer
, which would accept a kzg configuration, and just produce the commitments.