From daad030c9ed07e8f560ecc3ae1aa77c4ffaeccad Mon Sep 17 00:00:00 2001 From: litt3 <102969658+litt3@users.noreply.github.com> Date: Mon, 16 Dec 2024 15:59:49 -0500 Subject: [PATCH 1/7] Start upstream work of blob verifier Signed-off-by: litt3 <102969658+litt3@users.noreply.github.com> --- .../verification/verification_utils.go | 176 ++++++++++++++++++ .../verification/verification_utils_test.go | 142 ++++++++++++++ 2 files changed, 318 insertions(+) create mode 100644 api/clients/verification/verification_utils.go create mode 100644 api/clients/verification/verification_utils_test.go diff --git a/api/clients/verification/verification_utils.go b/api/clients/verification/verification_utils.go new file mode 100644 index 0000000000..8f746c8f7d --- /dev/null +++ b/api/clients/verification/verification_utils.go @@ -0,0 +1,176 @@ +package verification + +import ( + "errors" + "fmt" + "github.com/Layr-Labs/eigenda/encoding" + "slices" + + core "github.com/Layr-Labs/eigenda/core/v2" + "github.com/ethereum/go-ethereum/crypto" + + "github.com/ethereum/go-ethereum/common" + + "github.com/consensys/gnark-crypto/ecc" + "github.com/consensys/gnark-crypto/ecc/bn254" + + disperserpb "github.com/Layr-Labs/eigenda/api/grpc/disperser/v2" + "github.com/Layr-Labs/eigenda/encoding/kzg/verifier" + "github.com/Layr-Labs/eigenda/encoding/rs" +) + +// VerifyBlobStatusReply verifies all blob data, as required to trust that the blob is valid +func VerifyBlobStatusReply( + kzgVerifier *verifier.Verifier, + reply *disperserpb.BlobStatusReply, + // these bytes must represent the blob in coefficient form (i.e. IFFTed) + blobBytes []byte) error { + + blobHeader, err := core.BlobHeaderFromProtobuf(reply.BlobVerificationInfo.BlobCertificate.BlobHeader) + if err != nil { + return fmt.Errorf("blob header from protobuf: %w", err) + } + blobKey, err := blobHeader.BlobKey() + if err != nil { + return fmt.Errorf("compute blob key: %w", err) + } + + err = VerifyMerkleProof( + &blobKey, + reply.BlobVerificationInfo.InclusionProof, + reply.SignedBatch.Header.BatchRoot, + reply.BlobVerificationInfo.BlobIndex) + if err != nil { + return fmt.Errorf("verify merkle proof: %w", err) + } + + commitments, err := encoding.BlobCommitmentsFromProtobuf(reply.BlobVerificationInfo.BlobCertificate.BlobHeader.Commitment) + if err != nil { + return fmt.Errorf("commitments from protobuf: %w", err) + } + + err = VerifyKzgCommitment(kzgVerifier, commitments.Commitment, blobBytes) + if err != nil { + return fmt.Errorf("verify commitment: %w", err) + } + + if uint(len(blobBytes)) != commitments.Length { + return fmt.Errorf("actual blob length (%d) doesn't match claimed length in commitment (%d)", len(blobBytes), commitments.Length) + } + + err = kzgVerifier.VerifyBlobLength(*commitments) + if err != nil { + return fmt.Errorf("verify blob length: %w", err) + } + + return nil +} + +// VerifyKzgCommitment asserts that the claimed commitment from the certificate matches the commitment computed +// from the blob. +// +// TODO: Optimize implementation by opening a point on the commitment instead (don’t compute the g2 point. ask Bowen) +func VerifyKzgCommitment( + kzgVerifier *verifier.Verifier, + claimedCommitment *encoding.G1Commitment, + blobBytes []byte) error { + + computedCommitment, err := GenerateBlobCommitment(kzgVerifier, 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) +} + +// GenerateBlobCommitment computes kzg-bn254 commitment of blob data using SRS +// +// The blob data input to this method should be in coefficient form (IFFTed) +func GenerateBlobCommitment( + kzgVerifier *verifier.Verifier, + blob []byte) (*bn254.G1Affine, error) { + + inputFr, err := rs.ToFrArray(blob) + if err != nil { + return nil, fmt.Errorf("cannot convert bytes to field elements, %w", err) + } + + if len(kzgVerifier.Srs.G1) < len(inputFr) { + return nil, fmt.Errorf( + "cannot verify commitment because the number of stored srs in the memory is insufficient, have %v need %v", + len(kzgVerifier.Srs.G1), + len(inputFr)) + } + + config := ecc.MultiExpConfig{} + var commitment bn254.G1Affine + _, err = commitment.MultiExp(kzgVerifier.Srs.G1[:len(inputFr)], inputFr, config) + if err != nil { + return nil, err + } + + return &commitment, nil +} + +// TODO: I don't think that any of the checks done in `verifySecurityParams` from the proxy code are necessary in v2. confirm this. +// TODO: look at bug report https://eigenlabs.slack.com/archives/C07A5GD76AK/p1734118139046819 + +// VerifyMerkleProof verifies the blob batch inclusion proof against the claimed batch root +func VerifyMerkleProof( + // the key of the blob, which functions as the leaf in the batch merkle tree + blobKey *core.BlobKey, + // the inclusion proof, which contains the sibling hashes necessary to compute the root hash starting at the leaf + inclusionProof []byte, + // the claimed merkle root hash, which must be verified + claimedRoot []byte, + // the index of the blob in the batch. this informs whether the leaf being verified is a left or right child + blobIndex uint32) error { + + generatedRoot, err := GenerateRootHash(inclusionProof, blobKey, uint64(blobIndex)) + if err != nil { + return err + } + + equal := slices.Equal(claimedRoot, generatedRoot.Bytes()) + if !equal { + return fmt.Errorf("root hash mismatch, expected: %x, got: %x", claimedRoot, generatedRoot) + } + + return nil +} + +// GenerateRootHash computes the root hash, using the leaf and relevant inclusion proof +func GenerateRootHash(proof []byte, blobKey *core.BlobKey, index uint64) (common.Hash, error) { + if len(proof)%32 != 0 { + return common.Hash{}, errors.New("proof length should be a multiple of 32 bytes or 256 bits") + } + + // computedHash starts out equal to the hash of the leaf (the blob key) + var computedHash common.Hash + copy(computedHash[:], blobKey[:]) + + // we then work our way up the merkle tree, to compute the root hash + for i := 0; i < len(proof); i += 32 { + var proofElement common.Hash + copy(proofElement[:], proof[i:i+32]) + + var combined []byte + if index%2 == 0 { // right + combined = append(computedHash.Bytes(), proofElement.Bytes()...) + } else { // left + combined = append(proofElement.Bytes(), computedHash.Bytes()...) + } + + computedHash = crypto.Keccak256Hash(combined) + index /= 2 + } + + return computedHash, nil +} diff --git a/api/clients/verification/verification_utils_test.go b/api/clients/verification/verification_utils_test.go new file mode 100644 index 0000000000..3d95c5be33 --- /dev/null +++ b/api/clients/verification/verification_utils_test.go @@ -0,0 +1,142 @@ +package verification + +import ( + "github.com/Layr-Labs/eigenda/common/testutils/random" + "github.com/Layr-Labs/eigenda/encoding" + "github.com/Layr-Labs/eigenda/encoding/kzg" + "github.com/Layr-Labs/eigenda/encoding/kzg/verifier" + "github.com/Layr-Labs/eigenda/encoding/utils/codec" + "github.com/stretchr/testify/assert" + "log" + "os" + "runtime" + "testing" +) + +var ( + gettysburgAddressBytes = codec.ConvertByPaddingEmptyByte( + []byte("Fourscore and seven years ago our fathers brought forth, on this continent, a new nation, conceived in liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived, and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting-place for those who here gave their lives, that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we cannot dedicate, we cannot consecrate—we cannot hallow—this ground. The brave men, living and dead, who struggled here, have consecrated it far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us—that from these honored dead we take increased devotion to that cause for which they here gave the last full measure of devotion—that we here highly resolve that these dead shall not have died in vain—that this nation, under God, shall have a new birth of freedom, and that government of the people, by the people, for the people, shall not perish from the earth.")) + + kzgConfig *kzg.KzgConfig + testRandom *random.TestRandom + srsNumberToLoad uint64 +) + +func setup() { + log.Println("Setting up suite") + + srsNumberToLoad = 2900 + + kzgConfig = &kzg.KzgConfig{ + G1Path: "../../../inabox/resources/kzg/g1.point", + G2Path: "../../../inabox/resources/kzg/g2.point", + G2PowerOf2Path: "../../../inabox/resources/kzg/g2.point.powerOf2", + CacheDir: "../../../inabox/resources/kzg/SRSTables", + SRSOrder: 3000, + SRSNumberToLoad: srsNumberToLoad, + NumWorker: uint64(runtime.GOMAXPROCS(0)), + LoadG2Points: false, + } + + testRandom = random.NewTestRandom() +} + +func randomlyModifyBytes(inputBytes []byte) { + indexToModify := testRandom.Intn(len(inputBytes)) + inputBytes[indexToModify] = inputBytes[indexToModify] + 1 +} + +func TestMain(m *testing.M) { + setup() + result := m.Run() + teardown() + os.Exit(result) +} + +func teardown() { + log.Println("Tearing down") +} + +func TestVerifyKzgCommitmentSuccess(t *testing.T) { + kzgVerifier, err := verifier.NewVerifier(kzgConfig, nil) + assert.NotNil(t, kzgVerifier) + assert.Nil(t, err) + + commitment, err := GenerateBlobCommitment(kzgVerifier, gettysburgAddressBytes) + assert.NotNil(t, commitment) + assert.Nil(t, err) + + g1Commitment := &encoding.G1Commitment{X: commitment.X, Y: commitment.Y} + + // make sure the commitment verifies correctly + err = VerifyKzgCommitment( + kzgVerifier, + g1Commitment, + gettysburgAddressBytes) + assert.Nil(t, err) +} + +func TestVerifyKzgCommitmentFailure(t *testing.T) { + kzgVerifier, err := verifier.NewVerifier(kzgConfig, nil) + assert.NotNil(t, kzgVerifier) + assert.Nil(t, err) + + commitment, err := GenerateBlobCommitment(kzgVerifier, gettysburgAddressBytes) + assert.NotNil(t, commitment) + assert.Nil(t, err) + + // randomly modify the bytes, and make sure the commitment verification fails + randomlyModifyBytes(gettysburgAddressBytes) + err = VerifyKzgCommitment( + kzgVerifier, + &encoding.G1Commitment{X: commitment.X, Y: commitment.Y}, + gettysburgAddressBytes) + assert.NotNil(t, err) +} + +func TestGenerateBlobCommitmentEquality(t *testing.T) { + kzgVerifier, err := verifier.NewVerifier(kzgConfig, nil) + assert.NotNil(t, kzgVerifier) + assert.Nil(t, err) + + // generate two identical commitments + commitment1, err := GenerateBlobCommitment(kzgVerifier, gettysburgAddressBytes) + assert.NotNil(t, commitment1) + assert.Nil(t, err) + commitment2, err := GenerateBlobCommitment(kzgVerifier, gettysburgAddressBytes) + assert.NotNil(t, commitment2) + assert.Nil(t, err) + + // commitments to identical bytes should be equal + assert.Equal(t, commitment1, commitment2) + + // randomly modify a byte + randomlyModifyBytes(gettysburgAddressBytes) + commitmentA, err := GenerateBlobCommitment(kzgVerifier, gettysburgAddressBytes) + assert.NotNil(t, commitmentA) + assert.Nil(t, err) + + // commitments to non-identical bytes should not be equal + assert.NotEqual(t, commitment1, commitmentA) +} + +func TestGenerateBlobCommitmentTooLong(t *testing.T) { + kzgVerifier, err := verifier.NewVerifier(kzgConfig, nil) + assert.NotNil(t, kzgVerifier) + assert.Nil(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(kzgVerifier, almostTooLongBytes) + assert.NotNil(t, commitment1) + assert.Nil(t, err) + + // but 1 more byte is more than we can handle + tooLongBytes := make([]byte, almostTooLongByteCount+1) + commitment2, err := GenerateBlobCommitment(kzgVerifier, tooLongBytes) + assert.Nil(t, commitment2) + assert.NotNil(t, err) +} From 60b87903130d6a3e6525d5bcd481fda87e3d1ff6 Mon Sep 17 00:00:00 2001 From: litt3 <102969658+litt3@users.noreply.github.com> Date: Tue, 17 Dec 2024 14:26:21 -0500 Subject: [PATCH 2/7] Resolve TODO Signed-off-by: litt3 <102969658+litt3@users.noreply.github.com> --- .../verification/verification_utils.go | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/api/clients/verification/verification_utils.go b/api/clients/verification/verification_utils.go index 8f746c8f7d..8cee9e1c33 100644 --- a/api/clients/verification/verification_utils.go +++ b/api/clients/verification/verification_utils.go @@ -23,7 +23,7 @@ import ( func VerifyBlobStatusReply( kzgVerifier *verifier.Verifier, reply *disperserpb.BlobStatusReply, - // these bytes must represent the blob in coefficient form (i.e. IFFTed) +// these bytes must represent the blob in coefficient form (i.e. IFFTed) blobBytes []byte) error { blobHeader, err := core.BlobHeaderFromProtobuf(reply.BlobVerificationInfo.BlobCertificate.BlobHeader) @@ -120,20 +120,19 @@ func GenerateBlobCommitment( } // TODO: I don't think that any of the checks done in `verifySecurityParams` from the proxy code are necessary in v2. confirm this. -// TODO: look at bug report https://eigenlabs.slack.com/archives/C07A5GD76AK/p1734118139046819 // VerifyMerkleProof verifies the blob batch inclusion proof against the claimed batch root func VerifyMerkleProof( - // the key of the blob, which functions as the leaf in the batch merkle tree +// the key of the blob, which functions as the leaf in the batch merkle tree blobKey *core.BlobKey, - // the inclusion proof, which contains the sibling hashes necessary to compute the root hash starting at the leaf +// the inclusion proof, which contains the sibling hashes necessary to compute the root hash starting at the leaf inclusionProof []byte, - // the claimed merkle root hash, which must be verified +// the claimed merkle root hash, which must be verified claimedRoot []byte, - // the index of the blob in the batch. this informs whether the leaf being verified is a left or right child +// the index of the blob in the batch. this informs whether the leaf being verified is a left or right child blobIndex uint32) error { - generatedRoot, err := GenerateRootHash(inclusionProof, blobKey, uint64(blobIndex)) + generatedRoot, err := ProcessInclusionProof(inclusionProof, blobKey, uint64(blobIndex)) if err != nil { return err } @@ -146,8 +145,13 @@ func VerifyMerkleProof( return nil } -// GenerateRootHash computes the root hash, using the leaf and relevant inclusion proof -func GenerateRootHash(proof []byte, blobKey *core.BlobKey, index uint64) (common.Hash, error) { +// ProcessInclusionProof computes the root hash, using the leaf and relevant inclusion proof +// +// This logic is implemented here, rather than using merkletree.VerifyProofUsing, in order to exactly mirror +// https://github.com/Layr-Labs/eigenlayer-contracts/blob/dev/src/contracts/libraries/Merkle.sol#L49-L76, which is the +// verification method that executes on chain. It is important that the offchain verification result exactly matches +// the onchain result +func ProcessInclusionProof(proof []byte, blobKey *core.BlobKey, index uint64) (common.Hash, error) { if len(proof)%32 != 0 { return common.Hash{}, errors.New("proof length should be a multiple of 32 bytes or 256 bits") } From 1b1bca27020b7bfb6a422eda60aa744cc7097233 Mon Sep 17 00:00:00 2001 From: litt3 <102969658+litt3@users.noreply.github.com> Date: Thu, 19 Dec 2024 15:54:15 -0500 Subject: [PATCH 3/7] Remove unnecessary code Signed-off-by: litt3 <102969658+litt3@users.noreply.github.com> --- .../verification/verification_utils.go | 155 ++---------------- .../verification/verification_utils_test.go | 17 +- 2 files changed, 25 insertions(+), 147 deletions(-) diff --git a/api/clients/verification/verification_utils.go b/api/clients/verification/verification_utils.go index 8cee9e1c33..3246e26b25 100644 --- a/api/clients/verification/verification_utils.go +++ b/api/clients/verification/verification_utils.go @@ -1,76 +1,44 @@ package verification import ( - "errors" "fmt" "github.com/Layr-Labs/eigenda/encoding" - "slices" - - core "github.com/Layr-Labs/eigenda/core/v2" - "github.com/ethereum/go-ethereum/crypto" - - "github.com/ethereum/go-ethereum/common" - "github.com/consensys/gnark-crypto/ecc" "github.com/consensys/gnark-crypto/ecc/bn254" - disperserpb "github.com/Layr-Labs/eigenda/api/grpc/disperser/v2" "github.com/Layr-Labs/eigenda/encoding/kzg/verifier" "github.com/Layr-Labs/eigenda/encoding/rs" ) -// VerifyBlobStatusReply verifies all blob data, as required to trust that the blob is valid -func VerifyBlobStatusReply( +// GenerateBlobCommitment computes a kzg-bn254 commitment of blob data using SRS +func GenerateBlobCommitment( kzgVerifier *verifier.Verifier, - reply *disperserpb.BlobStatusReply, -// these bytes must represent the blob in coefficient form (i.e. IFFTed) - blobBytes []byte) error { - - blobHeader, err := core.BlobHeaderFromProtobuf(reply.BlobVerificationInfo.BlobCertificate.BlobHeader) - if err != nil { - return fmt.Errorf("blob header from protobuf: %w", err) - } - blobKey, err := blobHeader.BlobKey() - if err != nil { - return fmt.Errorf("compute blob key: %w", err) - } - - err = VerifyMerkleProof( - &blobKey, - reply.BlobVerificationInfo.InclusionProof, - reply.SignedBatch.Header.BatchRoot, - reply.BlobVerificationInfo.BlobIndex) - if err != nil { - return fmt.Errorf("verify merkle proof: %w", err) - } - - commitments, err := encoding.BlobCommitmentsFromProtobuf(reply.BlobVerificationInfo.BlobCertificate.BlobHeader.Commitment) - if err != nil { - return fmt.Errorf("commitments from protobuf: %w", err) - } + blob []byte) (*encoding.G1Commitment, error) { - err = VerifyKzgCommitment(kzgVerifier, commitments.Commitment, blobBytes) + inputFr, err := rs.ToFrArray(blob) if err != nil { - return fmt.Errorf("verify commitment: %w", err) + return nil, fmt.Errorf("convert bytes to field elements, %w", err) } - if uint(len(blobBytes)) != commitments.Length { - return fmt.Errorf("actual blob length (%d) doesn't match claimed length in commitment (%d)", len(blobBytes), commitments.Length) + if len(kzgVerifier.Srs.G1) < len(inputFr) { + return nil, fmt.Errorf( + "insufficient SRS in memory: have %v, need %v", + len(kzgVerifier.Srs.G1), + len(inputFr)) } - err = kzgVerifier.VerifyBlobLength(*commitments) + var commitment bn254.G1Affine + _, err = commitment.MultiExp(kzgVerifier.Srs.G1[:len(inputFr)], inputFr, ecc.MultiExpConfig{}) if err != nil { - return fmt.Errorf("verify blob length: %w", err) + return nil, fmt.Errorf("MultiExp: %w", err) } - return nil + return &encoding.G1Commitment{X: commitment.X, Y: commitment.Y}, nil } -// VerifyKzgCommitment asserts that the claimed commitment from the certificate matches the commitment computed -// from the blob. -// -// TODO: Optimize implementation by opening a point on the commitment instead (don’t compute the g2 point. ask Bowen) -func VerifyKzgCommitment( +// 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( kzgVerifier *verifier.Verifier, claimedCommitment *encoding.G1Commitment, blobBytes []byte) error { @@ -89,92 +57,3 @@ func VerifyKzgCommitment( "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) } - -// GenerateBlobCommitment computes kzg-bn254 commitment of blob data using SRS -// -// The blob data input to this method should be in coefficient form (IFFTed) -func GenerateBlobCommitment( - kzgVerifier *verifier.Verifier, - blob []byte) (*bn254.G1Affine, error) { - - inputFr, err := rs.ToFrArray(blob) - if err != nil { - return nil, fmt.Errorf("cannot convert bytes to field elements, %w", err) - } - - if len(kzgVerifier.Srs.G1) < len(inputFr) { - return nil, fmt.Errorf( - "cannot verify commitment because the number of stored srs in the memory is insufficient, have %v need %v", - len(kzgVerifier.Srs.G1), - len(inputFr)) - } - - config := ecc.MultiExpConfig{} - var commitment bn254.G1Affine - _, err = commitment.MultiExp(kzgVerifier.Srs.G1[:len(inputFr)], inputFr, config) - if err != nil { - return nil, err - } - - return &commitment, nil -} - -// TODO: I don't think that any of the checks done in `verifySecurityParams` from the proxy code are necessary in v2. confirm this. - -// VerifyMerkleProof verifies the blob batch inclusion proof against the claimed batch root -func VerifyMerkleProof( -// the key of the blob, which functions as the leaf in the batch merkle tree - blobKey *core.BlobKey, -// the inclusion proof, which contains the sibling hashes necessary to compute the root hash starting at the leaf - inclusionProof []byte, -// the claimed merkle root hash, which must be verified - claimedRoot []byte, -// the index of the blob in the batch. this informs whether the leaf being verified is a left or right child - blobIndex uint32) error { - - generatedRoot, err := ProcessInclusionProof(inclusionProof, blobKey, uint64(blobIndex)) - if err != nil { - return err - } - - equal := slices.Equal(claimedRoot, generatedRoot.Bytes()) - if !equal { - return fmt.Errorf("root hash mismatch, expected: %x, got: %x", claimedRoot, generatedRoot) - } - - return nil -} - -// ProcessInclusionProof computes the root hash, using the leaf and relevant inclusion proof -// -// This logic is implemented here, rather than using merkletree.VerifyProofUsing, in order to exactly mirror -// https://github.com/Layr-Labs/eigenlayer-contracts/blob/dev/src/contracts/libraries/Merkle.sol#L49-L76, which is the -// verification method that executes on chain. It is important that the offchain verification result exactly matches -// the onchain result -func ProcessInclusionProof(proof []byte, blobKey *core.BlobKey, index uint64) (common.Hash, error) { - if len(proof)%32 != 0 { - return common.Hash{}, errors.New("proof length should be a multiple of 32 bytes or 256 bits") - } - - // computedHash starts out equal to the hash of the leaf (the blob key) - var computedHash common.Hash - copy(computedHash[:], blobKey[:]) - - // we then work our way up the merkle tree, to compute the root hash - for i := 0; i < len(proof); i += 32 { - var proofElement common.Hash - copy(proofElement[:], proof[i:i+32]) - - var combined []byte - if index%2 == 0 { // right - combined = append(computedHash.Bytes(), proofElement.Bytes()...) - } else { // left - combined = append(proofElement.Bytes(), computedHash.Bytes()...) - } - - computedHash = crypto.Keccak256Hash(combined) - index /= 2 - } - - return computedHash, nil -} diff --git a/api/clients/verification/verification_utils_test.go b/api/clients/verification/verification_utils_test.go index 3d95c5be33..f32321677d 100644 --- a/api/clients/verification/verification_utils_test.go +++ b/api/clients/verification/verification_utils_test.go @@ -2,7 +2,6 @@ package verification import ( "github.com/Layr-Labs/eigenda/common/testutils/random" - "github.com/Layr-Labs/eigenda/encoding" "github.com/Layr-Labs/eigenda/encoding/kzg" "github.com/Layr-Labs/eigenda/encoding/kzg/verifier" "github.com/Layr-Labs/eigenda/encoding/utils/codec" @@ -18,6 +17,7 @@ var ( []byte("Fourscore and seven years ago our fathers brought forth, on this continent, a new nation, conceived in liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived, and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting-place for those who here gave their lives, that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we cannot dedicate, we cannot consecrate—we cannot hallow—this ground. The brave men, living and dead, who struggled here, have consecrated it far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us—that from these honored dead we take increased devotion to that cause for which they here gave the last full measure of devotion—that we here highly resolve that these dead shall not have died in vain—that this nation, under God, shall have a new birth of freedom, and that government of the people, by the people, for the people, shall not perish from the earth.")) kzgConfig *kzg.KzgConfig + kzgVerifier *verifier.Verifier testRandom *random.TestRandom srsNumberToLoad uint64 ) @@ -41,6 +41,7 @@ func setup() { testRandom = random.NewTestRandom() } +// randomlyModifyBytes picks a random byte from the input array, and increments it func randomlyModifyBytes(inputBytes []byte) { indexToModify := testRandom.Intn(len(inputBytes)) inputBytes[indexToModify] = inputBytes[indexToModify] + 1 @@ -57,7 +58,7 @@ func teardown() { log.Println("Tearing down") } -func TestVerifyKzgCommitmentSuccess(t *testing.T) { +func TestComputeAndCompareKzgCommitmentSuccess(t *testing.T) { kzgVerifier, err := verifier.NewVerifier(kzgConfig, nil) assert.NotNil(t, kzgVerifier) assert.Nil(t, err) @@ -66,17 +67,15 @@ func TestVerifyKzgCommitmentSuccess(t *testing.T) { assert.NotNil(t, commitment) assert.Nil(t, err) - g1Commitment := &encoding.G1Commitment{X: commitment.X, Y: commitment.Y} - // make sure the commitment verifies correctly - err = VerifyKzgCommitment( + err = GenerateAndCompareBlobCommitment( kzgVerifier, - g1Commitment, + commitment, gettysburgAddressBytes) assert.Nil(t, err) } -func TestVerifyKzgCommitmentFailure(t *testing.T) { +func TestComputeAndCompareKzgCommitmentFailure(t *testing.T) { kzgVerifier, err := verifier.NewVerifier(kzgConfig, nil) assert.NotNil(t, kzgVerifier) assert.Nil(t, err) @@ -87,9 +86,9 @@ func TestVerifyKzgCommitmentFailure(t *testing.T) { // randomly modify the bytes, and make sure the commitment verification fails randomlyModifyBytes(gettysburgAddressBytes) - err = VerifyKzgCommitment( + err = GenerateAndCompareBlobCommitment( kzgVerifier, - &encoding.G1Commitment{X: commitment.X, Y: commitment.Y}, + commitment, gettysburgAddressBytes) assert.NotNil(t, err) } From 8881a19bdc24541744cd3f2619d11e81df2d9c98 Mon Sep 17 00:00:00 2001 From: litt3 <102969658+litt3@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:11:48 -0500 Subject: [PATCH 4/7] Fix conflicts with upstream Signed-off-by: litt3 <102969658+litt3@users.noreply.github.com> --- .../verification/verification_utils.go | 0 .../verification/verification_utils_test.go | 20 +++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) rename api/clients/{ => v2}/verification/verification_utils.go (100%) rename api/clients/{ => v2}/verification/verification_utils_test.go (90%) diff --git a/api/clients/verification/verification_utils.go b/api/clients/v2/verification/verification_utils.go similarity index 100% rename from api/clients/verification/verification_utils.go rename to api/clients/v2/verification/verification_utils.go diff --git a/api/clients/verification/verification_utils_test.go b/api/clients/v2/verification/verification_utils_test.go similarity index 90% rename from api/clients/verification/verification_utils_test.go rename to api/clients/v2/verification/verification_utils_test.go index f32321677d..0d1d1185d6 100644 --- a/api/clients/verification/verification_utils_test.go +++ b/api/clients/v2/verification/verification_utils_test.go @@ -17,8 +17,6 @@ var ( []byte("Fourscore and seven years ago our fathers brought forth, on this continent, a new nation, conceived in liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived, and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting-place for those who here gave their lives, that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we cannot dedicate, we cannot consecrate—we cannot hallow—this ground. The brave men, living and dead, who struggled here, have consecrated it far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us—that from these honored dead we take increased devotion to that cause for which they here gave the last full measure of devotion—that we here highly resolve that these dead shall not have died in vain—that this nation, under God, shall have a new birth of freedom, and that government of the people, by the people, for the people, shall not perish from the earth.")) kzgConfig *kzg.KzgConfig - kzgVerifier *verifier.Verifier - testRandom *random.TestRandom srsNumberToLoad uint64 ) @@ -28,21 +26,19 @@ func setup() { srsNumberToLoad = 2900 kzgConfig = &kzg.KzgConfig{ - G1Path: "../../../inabox/resources/kzg/g1.point", - G2Path: "../../../inabox/resources/kzg/g2.point", - G2PowerOf2Path: "../../../inabox/resources/kzg/g2.point.powerOf2", - CacheDir: "../../../inabox/resources/kzg/SRSTables", + G1Path: "../../../../inabox/resources/kzg/g1.point", + G2Path: "../../../../inabox/resources/kzg/g2.point", + G2PowerOf2Path: "../../../../inabox/resources/kzg/g2.point.powerOf2", + CacheDir: "../../../../inabox/resources/kzg/SRSTables", SRSOrder: 3000, SRSNumberToLoad: srsNumberToLoad, NumWorker: uint64(runtime.GOMAXPROCS(0)), LoadG2Points: false, } - - testRandom = random.NewTestRandom() } // randomlyModifyBytes picks a random byte from the input array, and increments it -func randomlyModifyBytes(inputBytes []byte) { +func randomlyModifyBytes(testRandom *random.TestRandom, inputBytes []byte) { indexToModify := testRandom.Intn(len(inputBytes)) inputBytes[indexToModify] = inputBytes[indexToModify] + 1 } @@ -85,7 +81,8 @@ func TestComputeAndCompareKzgCommitmentFailure(t *testing.T) { assert.Nil(t, err) // randomly modify the bytes, and make sure the commitment verification fails - randomlyModifyBytes(gettysburgAddressBytes) + testRandom := random.NewTestRandom(t) + randomlyModifyBytes(testRandom, gettysburgAddressBytes) err = GenerateAndCompareBlobCommitment( kzgVerifier, commitment, @@ -110,7 +107,8 @@ func TestGenerateBlobCommitmentEquality(t *testing.T) { assert.Equal(t, commitment1, commitment2) // randomly modify a byte - randomlyModifyBytes(gettysburgAddressBytes) + testRandom := random.NewTestRandom(t) + randomlyModifyBytes(testRandom, gettysburgAddressBytes) commitmentA, err := GenerateBlobCommitment(kzgVerifier, gettysburgAddressBytes) assert.NotNil(t, commitmentA) assert.Nil(t, err) From 8795dc349c49ca6ff37841f59cbde2b8c64396d1 Mon Sep 17 00:00:00 2001 From: litt3 <102969658+litt3@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:22:01 -0500 Subject: [PATCH 5/7] Make fixes to unit tests Signed-off-by: litt3 <102969658+litt3@users.noreply.github.com> --- .../verification/verification_utils_test.go | 70 ++++++++----------- 1 file changed, 28 insertions(+), 42 deletions(-) diff --git a/api/clients/v2/verification/verification_utils_test.go b/api/clients/v2/verification/verification_utils_test.go index 0d1d1185d6..36e5b751fb 100644 --- a/api/clients/v2/verification/verification_utils_test.go +++ b/api/clients/v2/verification/verification_utils_test.go @@ -6,32 +6,18 @@ import ( "github.com/Layr-Labs/eigenda/encoding/kzg/verifier" "github.com/Layr-Labs/eigenda/encoding/utils/codec" "github.com/stretchr/testify/assert" - "log" - "os" "runtime" "testing" ) -var ( - gettysburgAddressBytes = codec.ConvertByPaddingEmptyByte( - []byte("Fourscore and seven years ago our fathers brought forth, on this continent, a new nation, conceived in liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived, and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting-place for those who here gave their lives, that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we cannot dedicate, we cannot consecrate—we cannot hallow—this ground. The brave men, living and dead, who struggled here, have consecrated it far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us—that from these honored dead we take increased devotion to that cause for which they here gave the last full measure of devotion—that we here highly resolve that these dead shall not have died in vain—that this nation, under God, shall have a new birth of freedom, and that government of the people, by the people, for the people, shall not perish from the earth.")) - - kzgConfig *kzg.KzgConfig - srsNumberToLoad uint64 -) - -func setup() { - log.Println("Setting up suite") - - srsNumberToLoad = 2900 - - kzgConfig = &kzg.KzgConfig{ +func getKzgConfig() *kzg.KzgConfig { + return &kzg.KzgConfig{ G1Path: "../../../../inabox/resources/kzg/g1.point", G2Path: "../../../../inabox/resources/kzg/g2.point", G2PowerOf2Path: "../../../../inabox/resources/kzg/g2.point.powerOf2", CacheDir: "../../../../inabox/resources/kzg/SRSTables", SRSOrder: 3000, - SRSNumberToLoad: srsNumberToLoad, + SRSNumberToLoad: 2900, NumWorker: uint64(runtime.GOMAXPROCS(0)), LoadG2Points: false, } @@ -43,23 +29,19 @@ func randomlyModifyBytes(testRandom *random.TestRandom, inputBytes []byte) { inputBytes[indexToModify] = inputBytes[indexToModify] + 1 } -func TestMain(m *testing.M) { - setup() - result := m.Run() - teardown() - os.Exit(result) -} - -func teardown() { - log.Println("Tearing down") +func getRandomPaddedBytes(testRandom *random.TestRandom, count int) []byte { + return codec.ConvertByPaddingEmptyByte(testRandom.Bytes(count)) } func TestComputeAndCompareKzgCommitmentSuccess(t *testing.T) { - kzgVerifier, err := verifier.NewVerifier(kzgConfig, nil) + testRandom := random.NewTestRandom(t) + randomBytes := getRandomPaddedBytes(testRandom, 1000) + + kzgVerifier, err := verifier.NewVerifier(getKzgConfig(), nil) assert.NotNil(t, kzgVerifier) assert.Nil(t, err) - commitment, err := GenerateBlobCommitment(kzgVerifier, gettysburgAddressBytes) + commitment, err := GenerateBlobCommitment(kzgVerifier, randomBytes) assert.NotNil(t, commitment) assert.Nil(t, err) @@ -67,39 +49,44 @@ func TestComputeAndCompareKzgCommitmentSuccess(t *testing.T) { err = GenerateAndCompareBlobCommitment( kzgVerifier, commitment, - gettysburgAddressBytes) + randomBytes) assert.Nil(t, err) } func TestComputeAndCompareKzgCommitmentFailure(t *testing.T) { - kzgVerifier, err := verifier.NewVerifier(kzgConfig, nil) + testRandom := random.NewTestRandom(t) + randomBytes := getRandomPaddedBytes(testRandom, 1000) + + kzgVerifier, err := verifier.NewVerifier(getKzgConfig(), nil) assert.NotNil(t, kzgVerifier) assert.Nil(t, err) - commitment, err := GenerateBlobCommitment(kzgVerifier, gettysburgAddressBytes) + commitment, err := GenerateBlobCommitment(kzgVerifier, randomBytes) assert.NotNil(t, commitment) assert.Nil(t, err) // randomly modify the bytes, and make sure the commitment verification fails - testRandom := random.NewTestRandom(t) - randomlyModifyBytes(testRandom, gettysburgAddressBytes) + randomlyModifyBytes(testRandom, randomBytes) err = GenerateAndCompareBlobCommitment( kzgVerifier, commitment, - gettysburgAddressBytes) + randomBytes) assert.NotNil(t, err) } func TestGenerateBlobCommitmentEquality(t *testing.T) { - kzgVerifier, err := verifier.NewVerifier(kzgConfig, nil) + testRandom := random.NewTestRandom(t) + randomBytes := getRandomPaddedBytes(testRandom, 1000) + + kzgVerifier, err := verifier.NewVerifier(getKzgConfig(), nil) assert.NotNil(t, kzgVerifier) assert.Nil(t, err) // generate two identical commitments - commitment1, err := GenerateBlobCommitment(kzgVerifier, gettysburgAddressBytes) + commitment1, err := GenerateBlobCommitment(kzgVerifier, randomBytes) assert.NotNil(t, commitment1) assert.Nil(t, err) - commitment2, err := GenerateBlobCommitment(kzgVerifier, gettysburgAddressBytes) + commitment2, err := GenerateBlobCommitment(kzgVerifier, randomBytes) assert.NotNil(t, commitment2) assert.Nil(t, err) @@ -107,9 +94,8 @@ func TestGenerateBlobCommitmentEquality(t *testing.T) { assert.Equal(t, commitment1, commitment2) // randomly modify a byte - testRandom := random.NewTestRandom(t) - randomlyModifyBytes(testRandom, gettysburgAddressBytes) - commitmentA, err := GenerateBlobCommitment(kzgVerifier, gettysburgAddressBytes) + randomlyModifyBytes(testRandom, randomBytes) + commitmentA, err := GenerateBlobCommitment(kzgVerifier, randomBytes) assert.NotNil(t, commitmentA) assert.Nil(t, err) @@ -118,12 +104,12 @@ func TestGenerateBlobCommitmentEquality(t *testing.T) { } func TestGenerateBlobCommitmentTooLong(t *testing.T) { - kzgVerifier, err := verifier.NewVerifier(kzgConfig, nil) + kzgVerifier, err := verifier.NewVerifier(getKzgConfig(), nil) assert.NotNil(t, kzgVerifier) assert.Nil(t, err) // this is the absolute maximum number of bytes we can handle, given how the verifier was configured - almostTooLongByteCount := srsNumberToLoad * 32 + almostTooLongByteCount := 2900 * 32 // an array of exactly this size should be fine almostTooLongBytes := make([]byte, almostTooLongByteCount) From 344d927dccfe38886c53d8c8f3c885a85bc11ba3 Mon Sep 17 00:00:00 2001 From: litt3 <102969658+litt3@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:22:56 -0500 Subject: [PATCH 6/7] Use require instead of assert Signed-off-by: litt3 <102969658+litt3@users.noreply.github.com> --- .../verification/verification_utils_test.go | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/api/clients/v2/verification/verification_utils_test.go b/api/clients/v2/verification/verification_utils_test.go index 36e5b751fb..3924e4e934 100644 --- a/api/clients/v2/verification/verification_utils_test.go +++ b/api/clients/v2/verification/verification_utils_test.go @@ -5,7 +5,7 @@ import ( "github.com/Layr-Labs/eigenda/encoding/kzg" "github.com/Layr-Labs/eigenda/encoding/kzg/verifier" "github.com/Layr-Labs/eigenda/encoding/utils/codec" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "runtime" "testing" ) @@ -38,19 +38,19 @@ func TestComputeAndCompareKzgCommitmentSuccess(t *testing.T) { randomBytes := getRandomPaddedBytes(testRandom, 1000) kzgVerifier, err := verifier.NewVerifier(getKzgConfig(), nil) - assert.NotNil(t, kzgVerifier) - assert.Nil(t, err) + require.NotNil(t, kzgVerifier) + require.Nil(t, err) commitment, err := GenerateBlobCommitment(kzgVerifier, randomBytes) - assert.NotNil(t, commitment) - assert.Nil(t, err) + require.NotNil(t, commitment) + require.Nil(t, err) // make sure the commitment verifies correctly err = GenerateAndCompareBlobCommitment( kzgVerifier, commitment, randomBytes) - assert.Nil(t, err) + require.Nil(t, err) } func TestComputeAndCompareKzgCommitmentFailure(t *testing.T) { @@ -58,12 +58,12 @@ func TestComputeAndCompareKzgCommitmentFailure(t *testing.T) { randomBytes := getRandomPaddedBytes(testRandom, 1000) kzgVerifier, err := verifier.NewVerifier(getKzgConfig(), nil) - assert.NotNil(t, kzgVerifier) - assert.Nil(t, err) + require.NotNil(t, kzgVerifier) + require.Nil(t, err) commitment, err := GenerateBlobCommitment(kzgVerifier, randomBytes) - assert.NotNil(t, commitment) - assert.Nil(t, err) + require.NotNil(t, commitment) + require.Nil(t, err) // randomly modify the bytes, and make sure the commitment verification fails randomlyModifyBytes(testRandom, randomBytes) @@ -71,7 +71,7 @@ func TestComputeAndCompareKzgCommitmentFailure(t *testing.T) { kzgVerifier, commitment, randomBytes) - assert.NotNil(t, err) + require.NotNil(t, err) } func TestGenerateBlobCommitmentEquality(t *testing.T) { @@ -79,34 +79,34 @@ func TestGenerateBlobCommitmentEquality(t *testing.T) { randomBytes := getRandomPaddedBytes(testRandom, 1000) kzgVerifier, err := verifier.NewVerifier(getKzgConfig(), nil) - assert.NotNil(t, kzgVerifier) - assert.Nil(t, err) + require.NotNil(t, kzgVerifier) + require.Nil(t, err) // generate two identical commitments commitment1, err := GenerateBlobCommitment(kzgVerifier, randomBytes) - assert.NotNil(t, commitment1) - assert.Nil(t, err) + require.NotNil(t, commitment1) + require.Nil(t, err) commitment2, err := GenerateBlobCommitment(kzgVerifier, randomBytes) - assert.NotNil(t, commitment2) - assert.Nil(t, err) + require.NotNil(t, commitment2) + require.Nil(t, err) // commitments to identical bytes should be equal - assert.Equal(t, commitment1, commitment2) + require.Equal(t, commitment1, commitment2) // randomly modify a byte randomlyModifyBytes(testRandom, randomBytes) commitmentA, err := GenerateBlobCommitment(kzgVerifier, randomBytes) - assert.NotNil(t, commitmentA) - assert.Nil(t, err) + require.NotNil(t, commitmentA) + require.Nil(t, err) // commitments to non-identical bytes should not be equal - assert.NotEqual(t, commitment1, commitmentA) + require.NotEqual(t, commitment1, commitmentA) } func TestGenerateBlobCommitmentTooLong(t *testing.T) { kzgVerifier, err := verifier.NewVerifier(getKzgConfig(), nil) - assert.NotNil(t, kzgVerifier) - assert.Nil(t, err) + require.NotNil(t, kzgVerifier) + require.Nil(t, err) // this is the absolute maximum number of bytes we can handle, given how the verifier was configured almostTooLongByteCount := 2900 * 32 @@ -114,12 +114,12 @@ func TestGenerateBlobCommitmentTooLong(t *testing.T) { // an array of exactly this size should be fine almostTooLongBytes := make([]byte, almostTooLongByteCount) commitment1, err := GenerateBlobCommitment(kzgVerifier, almostTooLongBytes) - assert.NotNil(t, commitment1) - assert.Nil(t, err) + require.NotNil(t, commitment1) + require.Nil(t, err) // but 1 more byte is more than we can handle tooLongBytes := make([]byte, almostTooLongByteCount+1) commitment2, err := GenerateBlobCommitment(kzgVerifier, tooLongBytes) - assert.Nil(t, commitment2) - assert.NotNil(t, err) + require.Nil(t, commitment2) + require.NotNil(t, err) } From 5b786f95d19a9c4d55d8df15c7885e40acb6e5e1 Mon Sep 17 00:00:00 2001 From: litt3 <102969658+litt3@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:24:20 -0500 Subject: [PATCH 7/7] Use better pattern for asserting no error Signed-off-by: litt3 <102969658+litt3@users.noreply.github.com> --- .../verification/verification_utils_test.go | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/api/clients/v2/verification/verification_utils_test.go b/api/clients/v2/verification/verification_utils_test.go index 3924e4e934..3ebb01ba63 100644 --- a/api/clients/v2/verification/verification_utils_test.go +++ b/api/clients/v2/verification/verification_utils_test.go @@ -39,18 +39,18 @@ func TestComputeAndCompareKzgCommitmentSuccess(t *testing.T) { kzgVerifier, err := verifier.NewVerifier(getKzgConfig(), nil) require.NotNil(t, kzgVerifier) - require.Nil(t, err) + require.NoError(t, err) commitment, err := GenerateBlobCommitment(kzgVerifier, randomBytes) require.NotNil(t, commitment) - require.Nil(t, err) + require.NoError(t, err) // make sure the commitment verifies correctly err = GenerateAndCompareBlobCommitment( kzgVerifier, commitment, randomBytes) - require.Nil(t, err) + require.NoError(t, err) } func TestComputeAndCompareKzgCommitmentFailure(t *testing.T) { @@ -59,11 +59,11 @@ func TestComputeAndCompareKzgCommitmentFailure(t *testing.T) { kzgVerifier, err := verifier.NewVerifier(getKzgConfig(), nil) require.NotNil(t, kzgVerifier) - require.Nil(t, err) + require.NoError(t, err) commitment, err := GenerateBlobCommitment(kzgVerifier, randomBytes) require.NotNil(t, commitment) - require.Nil(t, err) + require.NoError(t, err) // randomly modify the bytes, and make sure the commitment verification fails randomlyModifyBytes(testRandom, randomBytes) @@ -80,15 +80,15 @@ func TestGenerateBlobCommitmentEquality(t *testing.T) { kzgVerifier, err := verifier.NewVerifier(getKzgConfig(), nil) require.NotNil(t, kzgVerifier) - require.Nil(t, err) + require.NoError(t, err) // generate two identical commitments commitment1, err := GenerateBlobCommitment(kzgVerifier, randomBytes) require.NotNil(t, commitment1) - require.Nil(t, err) + require.NoError(t, err) commitment2, err := GenerateBlobCommitment(kzgVerifier, randomBytes) require.NotNil(t, commitment2) - require.Nil(t, err) + require.NoError(t, err) // commitments to identical bytes should be equal require.Equal(t, commitment1, commitment2) @@ -97,7 +97,7 @@ func TestGenerateBlobCommitmentEquality(t *testing.T) { randomlyModifyBytes(testRandom, randomBytes) commitmentA, err := GenerateBlobCommitment(kzgVerifier, randomBytes) require.NotNil(t, commitmentA) - require.Nil(t, err) + require.NoError(t, err) // commitments to non-identical bytes should not be equal require.NotEqual(t, commitment1, commitmentA) @@ -106,7 +106,7 @@ func TestGenerateBlobCommitmentEquality(t *testing.T) { func TestGenerateBlobCommitmentTooLong(t *testing.T) { kzgVerifier, err := verifier.NewVerifier(getKzgConfig(), nil) require.NotNil(t, kzgVerifier) - require.Nil(t, err) + require.NoError(t, err) // this is the absolute maximum number of bytes we can handle, given how the verifier was configured almostTooLongByteCount := 2900 * 32 @@ -115,7 +115,7 @@ func TestGenerateBlobCommitmentTooLong(t *testing.T) { almostTooLongBytes := make([]byte, almostTooLongByteCount) commitment1, err := GenerateBlobCommitment(kzgVerifier, almostTooLongBytes) require.NotNil(t, commitment1) - require.Nil(t, err) + require.NoError(t, err) // but 1 more byte is more than we can handle tooLongBytes := make([]byte, almostTooLongByteCount+1)