Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions beacon-chain/execution/engine_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1479,9 +1479,9 @@ func fixtures() map[string]interface{} {
},
BlockValue: "0x11fffffffff",
BlobsBundle: &pb.BlobBundleJSON{
Commitments: [][48]byte{bytesutil.ToBytes48([]byte("commitment1")), bytesutil.ToBytes48([]byte("commitment2"))},
Proofs: [][48]byte{bytesutil.ToBytes48([]byte("proof1")), bytesutil.ToBytes48([]byte("proof2"))},
Blobs: [][]byte{{'a'}, {'b'}},
Commitments: []hexutil.Bytes{[]byte("commitment1"), []byte("commitment2")},
Proofs: []hexutil.Bytes{[]byte("proof1"), []byte("proof2")},
Blobs: []hexutil.Bytes{{'a'}, {'b'}},
},
}
parent := bytesutil.PadTo([]byte("parentHash"), fieldparams.RootLength)
Expand Down
2 changes: 2 additions & 0 deletions encoding/bytesutil/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ go_library(
deps = [
"//config/fieldparams:go_default_library",
"//consensus-types/primitives:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
"@com_github_pkg_errors//:go_default_library",
],
)
Expand All @@ -35,5 +36,6 @@ go_test(
"//config/fieldparams:go_default_library",
"//testing/assert:go_default_library",
"//testing/require:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
],
)
14 changes: 14 additions & 0 deletions encoding/bytesutil/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package bytesutil

import (
"fmt"

"github.com/ethereum/go-ethereum/common/hexutil"
)

// ToBytes48Array is a convenience method for converting an array of
Expand Down Expand Up @@ -100,6 +102,18 @@ func SafeCopy2d32Bytes(ary [][32]byte) [][32]byte {
return nil
}

// SafeCopy2dHexUtilBytes will copy and return a non-nil 2d hex util byte slice, otherwise it returns nil.
func SafeCopy2dHexUtilBytes(ary []hexutil.Bytes) [][]byte {
if ary != nil {
copied := make([][]byte, len(ary))
for i, a := range ary {
copied[i] = SafeCopyBytes(a)
}
return copied
}
return nil
}

// ReverseBytes32Slice will reverse the provided slice's order.
func ReverseBytes32Slice(arr [][32]byte) [][32]byte {
for i, j := 0, len(arr)-1; i < j; i, j = i+1, j-1 {
Expand Down
9 changes: 9 additions & 0 deletions encoding/bytesutil/bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"reflect"
"testing"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v4/testing/assert"
)
Expand Down Expand Up @@ -161,6 +162,14 @@ func TestSafeCopy2d32Bytes(t *testing.T) {
assert.DeepEqual(t, input, output)
}

func TestSafeCopy2dHexUtilBytes(t *testing.T) {
input := make([]hexutil.Bytes, 2)
input[0] = hexutil.Bytes{'a'}
input[1] = hexutil.Bytes{'b'}
output := bytesutil.SafeCopy2dHexUtilBytes(input)
assert.DeepEqual(t, output, [][]byte{{'a'}, {'b'}})
}

func TestToBytes48Array(t *testing.T) {
tests := []struct {
a [][]byte
Expand Down
12 changes: 6 additions & 6 deletions proto/engine/v1/json_marshal_unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,16 +713,16 @@ func (f *ForkchoiceState) UnmarshalJSON(enc []byte) error {
}

type BlobBundleJSON struct {
Commitments [][48]byte `json:"commitments"`
Proofs [][48]byte `json:"proofs"`
Blobs [][]byte `json:"blobs"`
Commitments []hexutil.Bytes `json:"commitments"`
Proofs []hexutil.Bytes `json:"proofs"`
Blobs []hexutil.Bytes `json:"blobs"`
}

func (b BlobBundleJSON) ToProto() *BlobsBundle {
return &BlobsBundle{
KzgCommitments: bytesutil.SafeCopy2dBytes(bytesutil.FromBytes48Array(b.Commitments)),
Proofs: bytesutil.SafeCopy2dBytes(bytesutil.FromBytes48Array(b.Proofs)),
Blobs: bytesutil.SafeCopy2dBytes(b.Blobs),
KzgCommitments: bytesutil.SafeCopy2dHexUtilBytes(b.Commitments),
Proofs: bytesutil.SafeCopy2dHexUtilBytes(b.Proofs),
Blobs: bytesutil.SafeCopy2dHexUtilBytes(b.Blobs),
}
}

Expand Down
6 changes: 3 additions & 3 deletions proto/engine/v1/json_marshal_unmarshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ func TestJsonMarshalUnmarshal(t *testing.T) {

resp := &enginev1.GetPayloadV3ResponseJson{
BlobsBundle: &enginev1.BlobBundleJSON{
Commitments: [][48]byte{{'a'}, {'b'}, {'c'}, {'d'}},
Proofs: [][48]byte{{'e'}, {'f'}, {'g'}, {'h'}},
Blobs: [][]byte{{'i'}, {'j'}, {'k'}, {'l'}},
Commitments: []hexutil.Bytes{{'a'}, {'b'}, {'c'}, {'d'}},
Proofs: []hexutil.Bytes{{'e'}, {'f'}, {'g'}, {'h'}},
Blobs: []hexutil.Bytes{{'i'}, {'j'}, {'k'}, {'l'}},
},
BlockValue: fmt.Sprint("0x123"),
ExecutionPayload: &enginev1.ExecutionPayloadDenebJSON{
Expand Down