From 45a2746d0ea46e8d32c657777a1ad468ba46b437 Mon Sep 17 00:00:00 2001 From: james-prysm <90280386+james-prysm@users.noreply.github.com> Date: Wed, 13 Dec 2023 21:03:00 -0600 Subject: [PATCH] Builder API: Fix max field check on toProto function (#13334) * fixing field param used in ToProto function * fxing test to pass * making blobs empty in test --- api/client/builder/types.go | 4 ++-- api/client/builder/types_test.go | 31 +++++++++++++------------------ 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/api/client/builder/types.go b/api/client/builder/types.go index ddbccc26baf0..cf1dc6edcb6b 100644 --- a/api/client/builder/types.go +++ b/api/client/builder/types.go @@ -1021,8 +1021,8 @@ type BlobsBundle struct { // ToProto returns a BlobsBundle Proto. func (b BlobsBundle) ToProto() (*v1.BlobsBundle, error) { - if len(b.Blobs) > fieldparams.MaxBlobsPerBlock { - return nil, fmt.Errorf("blobs length %d is more than max %d", len(b.Blobs), fieldparams.MaxBlobsPerBlock) + if len(b.Blobs) > fieldparams.MaxBlobCommitmentsPerBlock { + return nil, fmt.Errorf("blobs length %d is more than max %d", len(b.Blobs), fieldparams.MaxBlobCommitmentsPerBlock) } if len(b.Commitments) != len(b.Blobs) { return nil, fmt.Errorf("commitments length %d does not equal blobs length %d", len(b.Commitments), len(b.Blobs)) diff --git a/api/client/builder/types_test.go b/api/client/builder/types_test.go index 849788c4acb6..08ec2f13cd71 100644 --- a/api/client/builder/types_test.go +++ b/api/client/builder/types_test.go @@ -666,25 +666,20 @@ var testExampleExecutionPayloadDenebTooManyBlobs = fmt.Sprintf(`{ "proofs": [ "0xb4021b0de10f743893d4f71e1bf830c019e832958efd6795baf2f83b8699a9eccc5dc99015d8d4d8ec370d0cc333c06a" ], - "blobs": [ - "%s", - "%s", - "%s", - "%s", - "%s", - "%s", - "%s" - ] + "blobs": %s } } -}`, hexutil.Encode(make([]byte, fieldparams.BlobLength)), // 1 - hexutil.Encode(make([]byte, fieldparams.BlobLength)), // 2 - hexutil.Encode(make([]byte, fieldparams.BlobLength)), // 3 - hexutil.Encode(make([]byte, fieldparams.BlobLength)), // 4 - hexutil.Encode(make([]byte, fieldparams.BlobLength)), // 5 - hexutil.Encode(make([]byte, fieldparams.BlobLength)), // 6 - hexutil.Encode(make([]byte, fieldparams.BlobLength)), // 7 -) +}`, beyondMaxEmptyBlobs()) + +func beyondMaxEmptyBlobs() string { + moreThanMax := fieldparams.MaxBlobCommitmentsPerBlock + 2 + blobs := make([]string, moreThanMax) + b, err := json.Marshal(blobs) + if err != nil { + panic(err) + } + return string(b) +} var testExampleExecutionPayloadDenebDifferentCommitmentCount = fmt.Sprintf(`{ "version": "deneb", @@ -1238,7 +1233,7 @@ func TestExecutionPayloadResponseDenebToProtoInvalidBlobCount(t *testing.T) { hr := &ExecPayloadResponseDeneb{} require.NoError(t, json.Unmarshal([]byte(testExampleExecutionPayloadDenebTooManyBlobs), hr)) _, _, err := hr.ToProto() - require.ErrorContains(t, "blobs length 7 is more than max 6", err) + require.ErrorContains(t, fmt.Sprintf("blobs length %d is more than max %d", fieldparams.MaxBlobCommitmentsPerBlock+2, fieldparams.MaxBlobCommitmentsPerBlock), err) } func TestExecutionPayloadResponseDenebToProtoDifferentCommitmentCount(t *testing.T) {