Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Light client consensus types #14512

Closed
wants to merge 5 commits into from
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
- Light client support: Add light client database changes.
- Light client support: Implement capella and deneb changes.
- Light client support: Implement `BlockToLightClientHeader` function.
- Light client support: Consensus types.
- GetBeaconStateV2: add Electra case.
- Implement [consensus-specs/3875](https://github.com/ethereum/consensus-specs/pull/3875)
- Tests to ensure sepolia config matches the official upstream yaml
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/core/light-client/lightclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ func createDefaultLightClientUpdate() (*ethpbv2.LightClientUpdate, error) {
Pubkeys: pubKeys,
AggregatePubkey: make([]byte, fieldparams.BLSPubkeyLength),
}
nextSyncCommitteeBranch := make([][]byte, fieldparams.NextSyncCommitteeBranchDepth)
for i := 0; i < fieldparams.NextSyncCommitteeBranchDepth; i++ {
nextSyncCommitteeBranch := make([][]byte, fieldparams.SyncCommitteeBranchDepth)
for i := 0; i < fieldparams.SyncCommitteeBranchDepth; i++ {
nextSyncCommitteeBranch[i] = make([]byte, fieldparams.RootLength)
}
executionBranch := make([][]byte, executionBranchNumOfLeaves)
Expand Down
8 changes: 4 additions & 4 deletions beacon-chain/rpc/eth/light-client/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func createLightClientBootstrapAltair(ctx context.Context, state state.BeaconSta
return nil, errors.Wrap(err, "could not get current sync committee proof")
}

branch := make([]string, fieldparams.NextSyncCommitteeBranchDepth)
branch := make([]string, fieldparams.SyncCommitteeBranchDepth)
for i, proof := range currentSyncCommitteeProof {
branch[i] = hexutil.Encode(proof)
}
Expand Down Expand Up @@ -159,7 +159,7 @@ func createLightClientBootstrapCapella(ctx context.Context, state state.BeaconSt
return nil, errors.Wrap(err, "could not get current sync committee proof")
}

branch := make([]string, fieldparams.NextSyncCommitteeBranchDepth)
branch := make([]string, fieldparams.SyncCommitteeBranchDepth)
for i, proof := range currentSyncCommitteeProof {
branch[i] = hexutil.Encode(proof)
}
Expand Down Expand Up @@ -227,7 +227,7 @@ func createLightClientBootstrapDeneb(ctx context.Context, state state.BeaconStat
return nil, errors.Wrap(err, "could not get current sync committee proof")
}

branch := make([]string, fieldparams.NextSyncCommitteeBranchDepth)
branch := make([]string, fieldparams.SyncCommitteeBranchDepth)
for i, proof := range currentSyncCommitteeProof {
branch[i] = hexutil.Encode(proof)
}
Expand Down Expand Up @@ -288,7 +288,7 @@ func newLightClientOptimisticUpdateFromBeaconState(
}

func IsSyncCommitteeUpdate(update *v2.LightClientUpdate) bool {
nextSyncCommitteeBranch := make([][]byte, fieldparams.NextSyncCommitteeBranchDepth)
nextSyncCommitteeBranch := make([][]byte, fieldparams.SyncCommitteeBranchDepth)
return !reflect.DeepEqual(update.NextSyncCommitteeBranch, nextSyncCommitteeBranch)
}

Expand Down
6 changes: 3 additions & 3 deletions beacon-chain/rpc/eth/light-client/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

// When the update has relevant sync committee
func createNonEmptySyncCommitteeBranch() [][]byte {
res := make([][]byte, fieldparams.NextSyncCommitteeBranchDepth)
res := make([][]byte, fieldparams.SyncCommitteeBranchDepth)
res[0] = []byte("xyz")
return res
}
Expand Down Expand Up @@ -101,7 +101,7 @@ func TestIsBetterUpdate(t *testing.T) {
}},
},
},
NextSyncCommitteeBranch: make([][]byte, fieldparams.NextSyncCommitteeBranchDepth),
NextSyncCommitteeBranch: make([][]byte, fieldparams.SyncCommitteeBranchDepth),
SignatureSlot: 9999,
},
newUpdate: &ethpbv2.LightClientUpdate{
Expand Down Expand Up @@ -147,7 +147,7 @@ func TestIsBetterUpdate(t *testing.T) {
}},
},
},
NextSyncCommitteeBranch: make([][]byte, fieldparams.NextSyncCommitteeBranchDepth),
NextSyncCommitteeBranch: make([][]byte, fieldparams.SyncCommitteeBranchDepth),
SignatureSlot: 9999,
},
expectedResult: false,
Expand Down
4 changes: 3 additions & 1 deletion config/fieldparams/mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ const (
BlobSize = 131072 // defined to match blob.size in bazel ssz codegen
BlobSidecarSize = 131928 // defined to match blob sidecar size in bazel ssz codegen
KzgCommitmentInclusionProofDepth = 17 // Merkle proof depth for blob_kzg_commitments list item
NextSyncCommitteeBranchDepth = 5 // NextSyncCommitteeBranchDepth defines the depth of the next sync committee branch.
ExecutionBranchDepth = 4 // ExecutionBranchDepth defines the number of leaves in a merkle proof of the execution payload header.
SyncCommitteeBranchDepth = 5 // SyncCommitteeBranchDepth defines the number of leaves in a merkle proof of a sync committee.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec defines a CurrentSyncCommitteeBranch and NextSyncCommitteeBranch, but since the depth is the same, we might as well keep one variable. Even if we defined two separate types in the interfaces package, they would both alias [5][32]byte and thus would be assignable to each other, so compiler won't catch slip-ups.

FinalityBranchDepth = 6 // FinalityBranchDepth defines the number of leaves in a merkle proof of the finalized checkpoint root.
PendingBalanceDepositsLimit = 134217728 // Maximum number of pending balance deposits in the beacon state.
PendingPartialWithdrawalsLimit = 134217728 // Maximum number of pending partial withdrawals in the beacon state.
PendingConsolidationsLimit = 262144 // Maximum number of pending consolidations in the beacon state.
Expand Down
4 changes: 3 additions & 1 deletion config/fieldparams/minimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ const (
BlobSize = 131072 // defined to match blob.size in bazel ssz codegen
BlobSidecarSize = 131928 // defined to match blob sidecar size in bazel ssz codegen
KzgCommitmentInclusionProofDepth = 17 // Merkle proof depth for blob_kzg_commitments list item
NextSyncCommitteeBranchDepth = 5 // NextSyncCommitteeBranchDepth defines the depth of the next sync committee branch.
ExecutionBranchDepth = 4 // ExecutionBranchDepth defines the number of leaves in a merkle proof of the execution payload header.
SyncCommitteeBranchDepth = 5 // SyncCommitteeBranchDepth defines the number of leaves in a merkle proof of a sync committee.
FinalityBranchDepth = 6 // FinalityBranchDepth defines the number of leaves in a merkle proof of the finalized checkpoint root.
PendingBalanceDepositsLimit = 134217728 // Maximum number of pending balance deposits in the beacon state.
PendingPartialWithdrawalsLimit = 64 // Maximum number of pending partial withdrawals in the beacon state.
PendingConsolidationsLimit = 64 // Maximum number of pending consolidations in the beacon state.
Expand Down
1 change: 1 addition & 0 deletions consensus-types/interfaces/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go_library(
srcs = [
"beacon_block.go",
"error.go",
"light_client.go",
"utils.go",
"validator.go",
],
Expand Down
58 changes: 58 additions & 0 deletions consensus-types/interfaces/light_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package interfaces

import (
ssz "github.com/prysmaticlabs/fastssz"
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
pb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
)

type LightClientExecutionBranch = [fieldparams.ExecutionBranchDepth][fieldparams.RootLength]byte
type LightClientSyncCommitteeBranch = [fieldparams.SyncCommitteeBranchDepth][fieldparams.RootLength]byte
type LightClientFinalityBranch = [fieldparams.FinalityBranchDepth][fieldparams.RootLength]byte

type LightClientHeader interface {
ssz.Marshaler
Version() int
Beacon() *pb.BeaconBlockHeader
Execution() (ExecutionData, error)
ExecutionBranch() (LightClientExecutionBranch, error)
}

type LightClientBootstrap interface {
ssz.Marshaler
Version() int
Header() LightClientHeader
CurrentSyncCommittee() *pb.SyncCommittee
CurrentSyncCommitteeBranch() LightClientSyncCommitteeBranch
}

type LightClientUpdate interface {
ssz.Marshaler
Version() int
AttestedHeader() LightClientHeader
NextSyncCommittee() *pb.SyncCommittee
NextSyncCommitteeBranch() LightClientSyncCommitteeBranch
FinalizedHeader() LightClientHeader
FinalityBranch() LightClientFinalityBranch
SyncAggregate() *pb.SyncAggregate
SignatureSlot() primitives.Slot
}

type LightClientFinalityUpdate interface {
ssz.Marshaler
Version() int
AttestedHeader() LightClientHeader
FinalizedHeader() LightClientHeader
FinalityBranch() LightClientFinalityBranch
SyncAggregate() *pb.SyncAggregate
SignatureSlot() primitives.Slot
}

type LightClientOptimisticUpdate interface {
ssz.Marshaler
Version() int
AttestedHeader() LightClientHeader
SyncAggregate() *pb.SyncAggregate
SignatureSlot() primitives.Slot
}
26 changes: 26 additions & 0 deletions consensus-types/light-client/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
load("@prysm//tools/go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = [
"bootstrap.go",
"finality_update.go",
"header.go",
"helpers.go",
"optimistic_update.go",
"update.go",
],
importpath = "github.com/prysmaticlabs/prysm/v5/consensus-types/light-client",
visibility = ["//visibility:public"],
deps = [
"//config/fieldparams:go_default_library",
"//consensus-types:go_default_library",
"//consensus-types/blocks:go_default_library",
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//encoding/bytesutil:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//runtime/version:go_default_library",
"@org_golang_google_protobuf//proto:go_default_library",
],
)
Loading
Loading