From 884b663455aea917ba839ea7919219213867854d Mon Sep 17 00:00:00 2001 From: Potuz Date: Mon, 7 Oct 2024 11:33:23 -0300 Subject: [PATCH] Move back ConvertKzgCommitmentToVersionedHash to primitives package (#14508) * Move back ConvertKzgCommitmentToVersionedHash to primitives package * Changelog --- CHANGELOG.md | 1 + beacon-chain/blockchain/execution_engine.go | 11 +---------- beacon-chain/rpc/eth/events/BUILD.bazel | 1 + beacon-chain/rpc/eth/events/events.go | 4 ++-- consensus-types/primitives/BUILD.bazel | 2 ++ consensus-types/primitives/kzg.go | 15 +++++++++++++++ 6 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 consensus-types/primitives/kzg.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 6406fac571d4..ed4472c6efea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve - Updated Libp2p Dependencies to allow prysm to use gossipsub v1.2 . - Updated Sepolia bootnodes. - Make committee aware packing the default by deprecating `--enable-committee-aware-packing`. +- Moved `ConvertKzgCommitmentToVersionedHash` to the `primitives` package. ### Deprecated - `--disable-grpc-gateway` flag is deprecated due to grpc gateway removal. diff --git a/beacon-chain/blockchain/execution_engine.go b/beacon-chain/blockchain/execution_engine.go index 387bc552e9cc..9e7e440718cf 100644 --- a/beacon-chain/blockchain/execution_engine.go +++ b/beacon-chain/blockchain/execution_engine.go @@ -2,7 +2,6 @@ package blockchain import ( "context" - "crypto/sha256" "fmt" "github.com/ethereum/go-ethereum/common" @@ -28,8 +27,6 @@ import ( "github.com/sirupsen/logrus" ) -const blobCommitmentVersionKZG uint8 = 0x01 - var defaultLatestValidHash = bytesutil.PadTo([]byte{0xff}, 32) // notifyForkchoiceUpdate signals execution engine the fork choice updates. Execution engine should: @@ -402,13 +399,7 @@ func kzgCommitmentsToVersionedHashes(body interfaces.ReadOnlyBeaconBlockBody) ([ versionedHashes := make([]common.Hash, len(commitments)) for i, commitment := range commitments { - versionedHashes[i] = ConvertKzgCommitmentToVersionedHash(commitment) + versionedHashes[i] = primitives.ConvertKzgCommitmentToVersionedHash(commitment) } return versionedHashes, nil } - -func ConvertKzgCommitmentToVersionedHash(commitment []byte) common.Hash { - versionedHash := sha256.Sum256(commitment) - versionedHash[0] = blobCommitmentVersionKZG - return versionedHash -} diff --git a/beacon-chain/rpc/eth/events/BUILD.bazel b/beacon-chain/rpc/eth/events/BUILD.bazel index 8a549d05f872..caa311b6b515 100644 --- a/beacon-chain/rpc/eth/events/BUILD.bazel +++ b/beacon-chain/rpc/eth/events/BUILD.bazel @@ -20,6 +20,7 @@ go_library( "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/transition:go_default_library", "//config/params:go_default_library", + "//consensus-types/primitives:go_default_library", "//monitoring/tracing/trace:go_default_library", "//network/httputil:go_default_library", "//proto/eth/v1:go_default_library", diff --git a/beacon-chain/rpc/eth/events/events.go b/beacon-chain/rpc/eth/events/events.go index fe753d8714dd..28e31fc9840f 100644 --- a/beacon-chain/rpc/eth/events/events.go +++ b/beacon-chain/rpc/eth/events/events.go @@ -13,7 +13,6 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/api" "github.com/prysmaticlabs/prysm/v5/api/server/structs" - "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain" "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/feed" "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/feed/operation" statefeed "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/feed/state" @@ -21,6 +20,7 @@ import ( chaintime "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/v5/config/params" + "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace" "github.com/prysmaticlabs/prysm/v5/network/httputil" ethpb "github.com/prysmaticlabs/prysm/v5/proto/eth/v1" @@ -447,7 +447,7 @@ func (s *Server) lazyReaderForEvent(ctx context.Context, event *feed.Event, topi }, nil case *operation.BlobSidecarReceivedData: return func() io.Reader { - versionedHash := blockchain.ConvertKzgCommitmentToVersionedHash(v.Blob.KzgCommitment) + versionedHash := primitives.ConvertKzgCommitmentToVersionedHash(v.Blob.KzgCommitment) return jsonMarshalReader(eventName, &structs.BlobSidecarEvent{ BlockRoot: hexutil.Encode(v.Blob.BlockRootSlice()), Index: fmt.Sprintf("%d", v.Blob.Index), diff --git a/consensus-types/primitives/BUILD.bazel b/consensus-types/primitives/BUILD.bazel index 96506f9315f3..f9258a41145c 100644 --- a/consensus-types/primitives/BUILD.bazel +++ b/consensus-types/primitives/BUILD.bazel @@ -9,6 +9,7 @@ go_library( "domain.go", "epoch.go", "execution_address.go", + "kzg.go", "payload_id.go", "randao.go", "slot.go", @@ -21,6 +22,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//math:go_default_library", + "@com_github_ethereum_go_ethereum//common:go_default_library", "@com_github_prysmaticlabs_fastssz//:go_default_library", "@com_github_prysmaticlabs_go_bitfield//:go_default_library", ], diff --git a/consensus-types/primitives/kzg.go b/consensus-types/primitives/kzg.go new file mode 100644 index 000000000000..c59b5557d52f --- /dev/null +++ b/consensus-types/primitives/kzg.go @@ -0,0 +1,15 @@ +package primitives + +import ( + "crypto/sha256" + + "github.com/ethereum/go-ethereum/common" +) + +const blobCommitmentVersionKZG uint8 = 0x01 + +func ConvertKzgCommitmentToVersionedHash(commitment []byte) common.Hash { + versionedHash := sha256.Sum256(commitment) + versionedHash[0] = blobCommitmentVersionKZG + return versionedHash +}