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

EIP 7549 spectests #14027

Merged
merged 5 commits into from
Jun 10, 2024
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
1 change: 1 addition & 0 deletions beacon-chain/core/electra/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = [
"attestation.go",
"churn.go",
"consolidations.go",
"deposits.go",
Expand Down
7 changes: 7 additions & 0 deletions beacon-chain/core/electra/attestation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package electra

import "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/altair"

var (
ProcessAttestationsNoVerifySignature = altair.ProcessAttestationsNoVerifySignature
)
1 change: 1 addition & 0 deletions testing/spectest/mainnet/electra/operations/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("@prysm//tools/go:def.bzl", "go_test")
go_test(
name = "go_default_test",
srcs = [
"attestation_test.go",
"attester_slashing_test.go",
"block_header_test.go",
"bls_to_execution_change_test.go",
Expand Down
11 changes: 11 additions & 0 deletions testing/spectest/mainnet/electra/operations/attestation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package operations

import (
"testing"

"github.com/prysmaticlabs/prysm/v5/testing/spectest/shared/electra/operations"
)

func TestMainnet_Electra_Operations_Attestation(t *testing.T) {
operations.RunAttestationTest(t, "mainnet")
}
1 change: 1 addition & 0 deletions testing/spectest/minimal/electra/operations/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("@prysm//tools/go:def.bzl", "go_test")
go_test(
name = "go_default_test",
srcs = [
"attestation_test.go",
"attester_slashing_test.go",
"block_header_test.go",
"bls_to_execution_change_test.go",
Expand Down
11 changes: 11 additions & 0 deletions testing/spectest/minimal/electra/operations/attestation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package operations

import (
"testing"

"github.com/prysmaticlabs/prysm/v5/testing/spectest/shared/electra/operations"
)

func TestMinimal_Electra_Operations_Attestation(t *testing.T) {
operations.RunAttestationTest(t, "minimal")
}
1 change: 1 addition & 0 deletions testing/spectest/shared/electra/operations/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go_library(
name = "go_default_library",
testonly = True,
srcs = [
"attestation.go",
"attester_slashing.go",
"block_header.go",
"bls_to_execution_changes.go",
Expand Down
59 changes: 59 additions & 0 deletions testing/spectest/shared/electra/operations/attestation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package operations

import (
"context"
"path"
"testing"

"github.com/golang/snappy"
"github.com/pkg/errors"
b "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/electra"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/testing/require"
"github.com/prysmaticlabs/prysm/v5/testing/spectest/utils"
"github.com/prysmaticlabs/prysm/v5/testing/util"
)

func RunAttestationTest(t *testing.T, config string) {
require.NoError(t, utils.SetConfig(t, config))
testFolders, testsFolderPath := utils.TestFolders(t, config, "electra", "operations/attestation/pyspec_tests")
if len(testFolders) == 0 {
t.Fatalf("No test folders found for %s/%s/%s", config, "electra", "operations/attestation/pyspec_tests")
}
for _, folder := range testFolders {
t.Run(folder.Name(), func(t *testing.T) {
folderPath := path.Join(testsFolderPath, folder.Name())
attestationFile, err := util.BazelFileBytes(folderPath, "attestation.ssz_snappy")
require.NoError(t, err)
attestationSSZ, err := snappy.Decode(nil /* dst */, attestationFile)
require.NoError(t, err, "Failed to decompress")
att := &ethpb.AttestationElectra{}
require.NoError(t, att.UnmarshalSSZ(attestationSSZ), "Failed to unmarshal")

body := &ethpb.BeaconBlockBodyElectra{Attestations: []*ethpb.AttestationElectra{att}}
processAtt := func(ctx context.Context, st state.BeaconState, blk interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
st, err = electra.ProcessAttestationsNoVerifySignature(ctx, st, blk.Block())
if err != nil {
return nil, err
}
aSet, err := b.AttestationSignatureBatch(ctx, st, blk.Block().Body().Attestations())
if err != nil {
return nil, err
}
verified, err := aSet.Verify()
if err != nil {
return nil, err
}
if !verified {
return nil, errors.New("could not batch verify attestation signature")
}
return st, nil
}

RunBlockOperationTest(t, folderPath, body, processAtt)
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func RunAttesterSlashingTest(t *testing.T, config string) {
require.NoError(t, attSlashing.UnmarshalSSZ(attSlashingSSZ), "Failed to unmarshal")

body := &ethpb.BeaconBlockBodyElectra{AttesterSlashings: []*ethpb.AttesterSlashingElectra{attSlashing}}
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) {
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
return blocks.ProcessAttesterSlashings(ctx, s, b.Block().Body().AttesterSlashings(), validators.SlashValidator)
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func RunBLSToExecutionChangeTest(t *testing.T, config string) {
body := &ethpb.BeaconBlockBodyElectra{
BlsToExecutionChanges: []*ethpb.SignedBLSToExecutionChange{change},
}
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) {
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
st, err := blocks.ProcessBLSToExecutionChanges(s, b.Block())
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func RunConsolidationTest(t *testing.T, config string) {
require.NoError(t, consolidation.UnmarshalSSZ(consolidationSSZ), "Failed to unmarshal")

body := &ethpb.BeaconBlockBodyElectra{Consolidations: []*ethpb.SignedConsolidation{consolidation}}
processConsolidationFunc := func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) {
processConsolidationFunc := func(ctx context.Context, s state.BeaconState, b interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
body, ok := b.Block().Body().(interfaces.ROBlockBodyElectra)
if !ok {
t.Error("block body is not electra")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func RunExecutionLayerWithdrawalRequestTest(t *testing.T, config string) {
withdrawalRequest,
},
}}
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) {
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
bod, ok := b.Block().Body().(interfaces.ROBlockBodyElectra)
require.Equal(t, true, ok)
e, err := bod.Execution()
Expand Down
2 changes: 1 addition & 1 deletion testing/spectest/shared/electra/operations/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"google.golang.org/protobuf/testing/protocmp"
)

type blockOperation func(context.Context, state.BeaconState, interfaces.SignedBeaconBlock) (state.BeaconState, error)
type blockOperation func(context.Context, state.BeaconState, interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error)

// RunBlockOperationTest takes in the prestate and the beacon block body, processes it through the
// passed in block operation function and checks the post state with the expected post state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func RunProposerSlashingTest(t *testing.T, config string) {
require.NoError(t, proposerSlashing.UnmarshalSSZ(proposerSlashingSSZ), "Failed to unmarshal")

body := &ethpb.BeaconBlockBodyElectra{ProposerSlashings: []*ethpb.ProposerSlashing{proposerSlashing}}
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) {
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
return blocks.ProcessProposerSlashings(ctx, s, b.Block().Body().ProposerSlashings(), validators.SlashValidator)
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func RunSyncCommitteeTest(t *testing.T, config string) {
require.NoError(t, sc.UnmarshalSSZ(syncCommitteeSSZ), "Failed to unmarshal")

body := &ethpb.BeaconBlockBodyElectra{SyncAggregate: sc}
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) {
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
st, _, err := electra.ProcessSyncAggregate(context.Background(), s, body.SyncAggregate)
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func RunVoluntaryExitTest(t *testing.T, config string) {
require.NoError(t, voluntaryExit.UnmarshalSSZ(exitSSZ), "Failed to unmarshal")

body := &ethpb.BeaconBlockBodyElectra{VoluntaryExits: []*ethpb.SignedVoluntaryExit{voluntaryExit}}
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) {
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
return blocks.ProcessVoluntaryExits(ctx, s, b.Block().Body().VoluntaryExits())
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func RunWithdrawalsTest(t *testing.T, config string) {
require.NoError(t, payload.UnmarshalSSZ(payloadSSZ), "failed to unmarshal")

body := &ethpb.BeaconBlockBodyElectra{ExecutionPayload: payload}
RunBlockOperationTest(t, folderPath, body, func(_ context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) {
RunBlockOperationTest(t, folderPath, body, func(_ context.Context, s state.BeaconState, b interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
payload, err := b.Block().Body().Execution()
if err != nil {
return nil, err
Expand Down
Loading