Add Gloas protobuf definitions with spec tests (#15601)

* Add Gloas protobuf definitions with spec tests

* Potuz's feedback

* Update comment

* Update final commits for fastssz and go-bitfield

* Sync with develop offchain labs go bitfield changes

* Update deps.bzl

Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com>

* Update deps.bzl

Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com>

* Gazelle fix build

---------

Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com>
This commit is contained in:
terence
2025-11-05 08:37:16 -05:00
committed by GitHub
parent 7df60e8c9b
commit d945b1d905
25 changed files with 9196 additions and 2938 deletions

View File

@@ -200,6 +200,7 @@ go_test(
"fulu__sanity__blocks_test.go",
"fulu__sanity__slots_test.go",
"fulu__ssz_static__ssz_static_test.go",
"gloas__ssz_static__ssz_static_test.go",
"phase0__epoch_processing__effective_balance_updates_test.go",
"phase0__epoch_processing__epoch_processing_test.go",
"phase0__epoch_processing__eth1_data_reset_test.go",
@@ -277,6 +278,7 @@ go_test(
"//testing/spectest/shared/fulu/rewards:go_default_library",
"//testing/spectest/shared/fulu/sanity:go_default_library",
"//testing/spectest/shared/fulu/ssz_static:go_default_library",
"//testing/spectest/shared/gloas/ssz_static:go_default_library",
"//testing/spectest/shared/phase0/epoch_processing:go_default_library",
"//testing/spectest/shared/phase0/finality:go_default_library",
"//testing/spectest/shared/phase0/operations:go_default_library",

View File

@@ -0,0 +1,11 @@
package mainnet
import (
"testing"
"github.com/OffchainLabs/prysm/v6/testing/spectest/shared/gloas/ssz_static"
)
func TestMainnet_Gloas_SSZStatic(t *testing.T) {
ssz_static.RunSSZStaticTests(t, "mainnet")
}

View File

@@ -206,6 +206,7 @@ go_test(
"fulu__sanity__blocks_test.go",
"fulu__sanity__slots_test.go",
"fulu__ssz_static__ssz_static_test.go",
"gloas__ssz_static__ssz_static_test.go",
"phase0__epoch_processing__effective_balance_updates_test.go",
"phase0__epoch_processing__epoch_processing_test.go",
"phase0__epoch_processing__eth1_data_reset_test.go",
@@ -287,6 +288,7 @@ go_test(
"//testing/spectest/shared/fulu/rewards:go_default_library",
"//testing/spectest/shared/fulu/sanity:go_default_library",
"//testing/spectest/shared/fulu/ssz_static:go_default_library",
"//testing/spectest/shared/gloas/ssz_static:go_default_library",
"//testing/spectest/shared/phase0/epoch_processing:go_default_library",
"//testing/spectest/shared/phase0/finality:go_default_library",
"//testing/spectest/shared/phase0/operations:go_default_library",

View File

@@ -0,0 +1,11 @@
package minimal
import (
"testing"
"github.com/OffchainLabs/prysm/v6/testing/spectest/shared/gloas/ssz_static"
)
func TestMinimal_Gloas_SSZStatic(t *testing.T) {
ssz_static.RunSSZStaticTests(t, "minimal")
}

View File

@@ -0,0 +1,15 @@
load("@prysm//tools/go:def.bzl", "go_library")
go_library(
name = "go_default_library",
testonly = True,
srcs = ["ssz_static.go"],
importpath = "github.com/OffchainLabs/prysm/v6/testing/spectest/shared/gloas/ssz_static",
visibility = ["//testing/spectest:__subpackages__"],
deps = [
"//proto/engine/v1:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//testing/spectest/shared/common/ssz_static:go_default_library",
"@com_github_prysmaticlabs_fastssz//:go_default_library",
],
)

View File

@@ -0,0 +1,184 @@
package ssz_static
import (
"errors"
"testing"
enginev1 "github.com/OffchainLabs/prysm/v6/proto/engine/v1"
ethpb "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1"
common "github.com/OffchainLabs/prysm/v6/testing/spectest/shared/common/ssz_static"
fssz "github.com/prysmaticlabs/fastssz"
)
// RunSSZStaticTests executes "ssz_static" tests.
func RunSSZStaticTests(t *testing.T, config string) {
common.RunSSZStaticTests(t, config, "gloas", unmarshalledSSZ, customHtr)
}
func customHtr(t *testing.T, htrs []common.HTR, object interface{}) []common.HTR {
// TODO: Add custom HTR for BeaconStateGloas when state-native support is implemented
// For now, only use the default fastssz HTR methods
return htrs
}
// unmarshalledSSZ unmarshalls serialized input.
func unmarshalledSSZ(t *testing.T, serializedBytes []byte, folderName string) (interface{}, error) {
var obj interface{}
switch folderName {
// Gloas specific types
case "ExecutionPayloadBid":
obj = &ethpb.ExecutionPayloadBid{}
case "SignedExecutionPayloadBid":
obj = &ethpb.SignedExecutionPayloadBid{}
case "PayloadAttestationData":
obj = &ethpb.PayloadAttestationData{}
case "PayloadAttestation":
obj = &ethpb.PayloadAttestation{}
case "PayloadAttestationMessage":
obj = &ethpb.PayloadAttestationMessage{}
case "BeaconBlock":
obj = &ethpb.BeaconBlockGloas{}
case "BeaconBlockBody":
obj = &ethpb.BeaconBlockBodyGloas{}
case "BeaconState":
obj = &ethpb.BeaconStateGloas{}
case "BuilderPendingPayment":
obj = &ethpb.BuilderPendingPayment{}
case "BuilderPendingWithdrawal":
obj = &ethpb.BuilderPendingWithdrawal{}
case "ExecutionPayloadEnvelope":
obj = &ethpb.ExecutionPayloadEnvelope{}
case "SignedExecutionPayloadEnvelope":
obj = &ethpb.SignedExecutionPayloadEnvelope{}
case "ForkChoiceNode":
t.Skip("Not a consensus type")
case "IndexedPayloadAttestation":
t.Skip("Not a consensus type")
case "DataColumnSidecar":
obj = &ethpb.DataColumnSidecarGloas{}
// Standard types that also exist in gloas
case "ExecutionPayload":
obj = &enginev1.ExecutionPayloadDeneb{}
case "ExecutionPayloadHeader":
obj = &enginev1.ExecutionPayloadHeaderDeneb{}
case "Attestation":
obj = &ethpb.AttestationElectra{}
case "AttestationData":
obj = &ethpb.AttestationData{}
case "AttesterSlashing":
obj = &ethpb.AttesterSlashingElectra{}
case "AggregateAndProof":
obj = &ethpb.AggregateAttestationAndProofElectra{}
case "BeaconBlockHeader":
obj = &ethpb.BeaconBlockHeader{}
case "Checkpoint":
obj = &ethpb.Checkpoint{}
case "Deposit":
obj = &ethpb.Deposit{}
case "DepositMessage":
obj = &ethpb.DepositMessage{}
case "DepositData":
obj = &ethpb.Deposit_Data{}
case "Eth1Data":
obj = &ethpb.Eth1Data{}
case "Eth1Block":
t.Skip("Unused type")
case "Fork":
obj = &ethpb.Fork{}
case "ForkData":
obj = &ethpb.ForkData{}
case "HistoricalBatch":
obj = &ethpb.HistoricalBatch{}
case "IndexedAttestation":
obj = &ethpb.IndexedAttestationElectra{}
case "PendingAttestation":
obj = &ethpb.PendingAttestation{}
case "ProposerSlashing":
obj = &ethpb.ProposerSlashing{}
case "SignedAggregateAndProof":
obj = &ethpb.SignedAggregateAttestationAndProofElectra{}
case "SignedBeaconBlock":
obj = &ethpb.SignedBeaconBlockGloas{}
case "SignedBeaconBlockHeader":
obj = &ethpb.SignedBeaconBlockHeader{}
case "SignedVoluntaryExit":
obj = &ethpb.SignedVoluntaryExit{}
case "SigningData":
obj = &ethpb.SigningData{}
case "Validator":
obj = &ethpb.Validator{}
case "VoluntaryExit":
obj = &ethpb.VoluntaryExit{}
case "SyncCommitteeMessage":
obj = &ethpb.SyncCommitteeMessage{}
case "SyncCommitteeContribution":
obj = &ethpb.SyncCommitteeContribution{}
case "ContributionAndProof":
obj = &ethpb.ContributionAndProof{}
case "SignedContributionAndProof":
obj = &ethpb.SignedContributionAndProof{}
case "SingleAttestation":
obj = &ethpb.SingleAttestation{}
case "SyncAggregate":
obj = &ethpb.SyncAggregate{}
case "SyncAggregatorSelectionData":
obj = &ethpb.SyncAggregatorSelectionData{}
case "SyncCommittee":
obj = &ethpb.SyncCommittee{}
case "LightClientOptimisticUpdate":
obj = &ethpb.LightClientOptimisticUpdateDeneb{}
case "LightClientFinalityUpdate":
obj = &ethpb.LightClientFinalityUpdateElectra{}
case "LightClientBootstrap":
obj = &ethpb.LightClientBootstrapElectra{}
case "LightClientUpdate":
obj = &ethpb.LightClientUpdateElectra{}
case "LightClientHeader":
obj = &ethpb.LightClientHeaderDeneb{}
case "BlobIdentifier":
obj = &ethpb.BlobIdentifier{}
case "BlobSidecar":
t.Skip("Unused type")
case "PowBlock":
obj = &ethpb.PowBlock{}
case "Withdrawal":
obj = &enginev1.Withdrawal{}
case "HistoricalSummary":
obj = &ethpb.HistoricalSummary{}
case "BLSToExecutionChange":
obj = &ethpb.BLSToExecutionChange{}
case "SignedBLSToExecutionChange":
obj = &ethpb.SignedBLSToExecutionChange{}
case "PendingDeposit":
obj = &ethpb.PendingDeposit{}
case "PendingPartialWithdrawal":
obj = &ethpb.PendingPartialWithdrawal{}
case "PendingConsolidation":
obj = &ethpb.PendingConsolidation{}
case "WithdrawalRequest":
obj = &enginev1.WithdrawalRequest{}
case "DepositRequest":
obj = &enginev1.DepositRequest{}
case "ConsolidationRequest":
obj = &enginev1.ConsolidationRequest{}
case "ExecutionRequests":
obj = &enginev1.ExecutionRequests{}
case "DataColumnsByRootIdentifier":
obj = &ethpb.DataColumnsByRootIdentifier{}
case "MatrixEntry":
t.Skip("Unused type")
default:
return nil, errors.New("type not found")
}
var err error
if o, ok := obj.(fssz.Unmarshaler); ok {
err = o.UnmarshalSSZ(serializedBytes)
} else {
err = errors.New("could not unmarshal object, not a fastssz compatible object")
}
return obj, err
}