Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
Signed-off-by: litt3 <[email protected]>
  • Loading branch information
litt3 committed Jan 3, 2025
1 parent 4ea0ba8 commit c9bdbbe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions api/clients/v2/verification/commitment_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
// GenerateBlobCommitment computes a kzg-bn254 commitment of blob data using SRS
func GenerateBlobCommitment(
g1Srs []bn254.G1Affine,
blob []byte) (*encoding.G1Commitment, error) {
blobBytes []byte) (*encoding.G1Commitment, error) {

inputFr, err := rs.ToFrArray(blob)
inputFr, err := rs.ToFrArray(blobBytes)
if err != nil {
return nil, fmt.Errorf("convert bytes to field elements, %w", err)
}
Expand All @@ -38,8 +38,8 @@ func GenerateBlobCommitment(
// 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 GenerateAndCompareBlobCommitment(
g1Srs []bn254.G1Affine,
claimedCommitment *encoding.G1Commitment,
g1Srs []bn254.G1Affine,
blobBytes []byte) error {

computedCommitment, err := GenerateBlobCommitment(g1Srs, blobBytes)
Expand Down
34 changes: 17 additions & 17 deletions api/clients/v2/verification/commitment_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ func TestComputeAndCompareKzgCommitmentSuccess(t *testing.T) {

srsNumberToLoad := computeSrsNumber(len(randomBytes))

s1, err := kzg.ReadG1Points(g1Path, srsNumberToLoad, uint64(runtime.GOMAXPROCS(0)))
require.NotNil(t, s1)
g1Srs, err := kzg.ReadG1Points(g1Path, srsNumberToLoad, uint64(runtime.GOMAXPROCS(0)))
require.NotNil(t, g1Srs)
require.NoError(t, err)

commitment, err := GenerateBlobCommitment(s1, randomBytes)
commitment, err := GenerateBlobCommitment(g1Srs, randomBytes)
require.NotNil(t, commitment)
require.NoError(t, err)

// make sure the commitment verifies correctly
err = GenerateAndCompareBlobCommitment(
s1,
commitment,
g1Srs,
randomBytes)
require.NoError(t, err)
}
Expand All @@ -55,19 +55,19 @@ func TestComputeAndCompareKzgCommitmentFailure(t *testing.T) {

srsNumberToLoad := computeSrsNumber(len(randomBytes))

s1, err := kzg.ReadG1Points(g1Path, srsNumberToLoad, uint64(runtime.GOMAXPROCS(0)))
require.NotNil(t, s1)
g1Srs, err := kzg.ReadG1Points(g1Path, srsNumberToLoad, uint64(runtime.GOMAXPROCS(0)))
require.NotNil(t, g1Srs)
require.NoError(t, err)

commitment, err := GenerateBlobCommitment(s1, randomBytes)
commitment, err := GenerateBlobCommitment(g1Srs, randomBytes)
require.NotNil(t, commitment)
require.NoError(t, err)

// randomly modify the bytes, and make sure the commitment verification fails
randomlyModifyBytes(testRandom, randomBytes)
err = GenerateAndCompareBlobCommitment(
s1,
commitment,
g1Srs,
randomBytes)
require.NotNil(t, err)
}
Expand All @@ -78,15 +78,15 @@ func TestGenerateBlobCommitmentEquality(t *testing.T) {

srsNumberToLoad := computeSrsNumber(len(randomBytes))

s1, err := kzg.ReadG1Points(g1Path, srsNumberToLoad, uint64(runtime.GOMAXPROCS(0)))
require.NotNil(t, s1)
g1Srs, err := kzg.ReadG1Points(g1Path, srsNumberToLoad, uint64(runtime.GOMAXPROCS(0)))
require.NotNil(t, g1Srs)
require.NoError(t, err)

// generate two identical commitments
commitment1, err := GenerateBlobCommitment(s1, randomBytes)
commitment1, err := GenerateBlobCommitment(g1Srs, randomBytes)
require.NotNil(t, commitment1)
require.NoError(t, err)
commitment2, err := GenerateBlobCommitment(s1, randomBytes)
commitment2, err := GenerateBlobCommitment(g1Srs, randomBytes)
require.NotNil(t, commitment2)
require.NoError(t, err)

Expand All @@ -95,7 +95,7 @@ func TestGenerateBlobCommitmentEquality(t *testing.T) {

// randomly modify a byte
randomlyModifyBytes(testRandom, randomBytes)
commitmentA, err := GenerateBlobCommitment(s1, randomBytes)
commitmentA, err := GenerateBlobCommitment(g1Srs, randomBytes)
require.NotNil(t, commitmentA)
require.NoError(t, err)

Expand All @@ -106,22 +106,22 @@ func TestGenerateBlobCommitmentEquality(t *testing.T) {
func TestGenerateBlobCommitmentTooLong(t *testing.T) {
srsNumberToLoad := uint64(500)

s1, err := kzg.ReadG1Points(g1Path, srsNumberToLoad, uint64(runtime.GOMAXPROCS(0)))
require.NotNil(t, s1)
g1Srs, err := kzg.ReadG1Points(g1Path, srsNumberToLoad, uint64(runtime.GOMAXPROCS(0)))
require.NotNil(t, g1Srs)
require.NoError(t, err)

// this is the absolute maximum number of bytes we can handle, given how the verifier was configured
almostTooLongByteCount := srsNumberToLoad * 32

// an array of exactly this size should be fine
almostTooLongBytes := make([]byte, almostTooLongByteCount)
commitment1, err := GenerateBlobCommitment(s1, almostTooLongBytes)
commitment1, err := GenerateBlobCommitment(g1Srs, almostTooLongBytes)
require.NotNil(t, commitment1)
require.NoError(t, err)

// but 1 more byte is more than we can handle
tooLongBytes := make([]byte, almostTooLongByteCount+1)
commitment2, err := GenerateBlobCommitment(s1, tooLongBytes)
commitment2, err := GenerateBlobCommitment(g1Srs, tooLongBytes)
require.Nil(t, commitment2)
require.NotNil(t, err)
}

0 comments on commit c9bdbbe

Please sign in to comment.