Skip to content

Commit

Permalink
Builder API: Fix max field check on toProto function (#13334)
Browse files Browse the repository at this point in the history
* fixing field param used in ToProto function

* fxing test to pass

* making blobs empty in test
  • Loading branch information
james-prysm authored Dec 14, 2023
1 parent 09f3df3 commit 45a2746
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
4 changes: 2 additions & 2 deletions api/client/builder/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
31 changes: 13 additions & 18 deletions api/client/builder/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 45a2746

Please sign in to comment.