Fix length check between kzg commitments and exist (#14581)

This commit is contained in:
terence
2024-10-25 10:59:57 -07:00
committed by GitHub
parent 48fe9d9c4d
commit 53f1f11c6d
3 changed files with 15 additions and 2 deletions

View File

@@ -560,8 +560,8 @@ func (s *Service) ReconstructBlobSidecars(ctx context.Context, block interfaces.
if err != nil {
return nil, errors.Wrap(err, "could not get blob KZG commitments")
}
if len(kzgCommitments) != len(exists) {
return nil, fmt.Errorf("mismatched lengths: KZG commitments %d, exists %d", len(kzgCommitments), len(exists))
if len(kzgCommitments) > len(exists) {
return nil, fmt.Errorf("length of KZG commitments (%d) is greater than length of exists (%d)", len(kzgCommitments), len(exists))
}
// Collect KZG hashes for non-existing blobs

View File

@@ -2446,6 +2446,18 @@ func TestReconstructBlobSidecars(t *testing.T) {
require.NoError(t, err)
require.Equal(t, 3, len(verifiedBlobs))
})
t.Run("kzg is longer than exist", func(t *testing.T) {
srv := createBlobServer(t, 3)
defer srv.Close()
rpcClient, client := setupRpcClient(t, srv.URL, client)
defer rpcClient.Close()
exists := []bool{true, false, true, false, true}
_, err := client.ReconstructBlobSidecars(ctx, sb, r, exists)
require.ErrorContains(t, "length of KZG commitments (6) is greater than length of exists (5)", err)
})
}
func createRandomKzgCommitments(t *testing.T, num int) [][]byte {