remove usages of params from proto packages (#15403)

* remove usages of params from proto packages

* make it harder to mess up the order of request limit args

* remove errant edit (Terence review)

* fix missed updates after sig change

---------

Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com>
This commit is contained in:
kasey
2025-06-11 16:15:10 -05:00
committed by GitHub
parent 6087875da5
commit d12da8cbe0
20 changed files with 110 additions and 73 deletions

View File

@@ -5,6 +5,7 @@ import (
"time" "time"
"github.com/OffchainLabs/prysm/v6/beacon-chain/core/helpers" "github.com/OffchainLabs/prysm/v6/beacon-chain/core/helpers"
"github.com/OffchainLabs/prysm/v6/config/params"
"github.com/OffchainLabs/prysm/v6/encoding/bytesutil" "github.com/OffchainLabs/prysm/v6/encoding/bytesutil"
"github.com/OffchainLabs/prysm/v6/monitoring/tracing/trace" "github.com/OffchainLabs/prysm/v6/monitoring/tracing/trace"
ethpb "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1" ethpb "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1"
@@ -88,7 +89,7 @@ func (s *Service) OnAttestation(ctx context.Context, a ethpb.Att, disparity time
if err != nil { if err != nil {
return err return err
} }
if err := attestation.IsValidAttestationIndices(ctx, indexedAtt); err != nil { if err := attestation.IsValidAttestationIndices(ctx, indexedAtt, params.BeaconConfig().MaxValidatorsPerCommittee, params.BeaconConfig().MaxCommitteesPerSlot); err != nil {
return err return err
} }

View File

@@ -178,7 +178,7 @@ func VerifyAttestationNoVerifySignature(
} }
} }
return attestation.IsValidAttestationIndices(ctx, indexedAtt) return attestation.IsValidAttestationIndices(ctx, indexedAtt, params.BeaconConfig().MaxValidatorsPerCommittee, params.BeaconConfig().MaxCommitteesPerSlot)
} }
// ProcessAttestationNoVerifySignature processes the attestation without verifying the attestation signature. This // ProcessAttestationNoVerifySignature processes the attestation without verifying the attestation signature. This
@@ -243,7 +243,7 @@ func VerifyIndexedAttestation(ctx context.Context, beaconState state.ReadOnlyBea
ctx, span := trace.StartSpan(ctx, "core.VerifyIndexedAttestation") ctx, span := trace.StartSpan(ctx, "core.VerifyIndexedAttestation")
defer span.End() defer span.End()
if err := attestation.IsValidAttestationIndices(ctx, indexedAtt); err != nil { if err := attestation.IsValidAttestationIndices(ctx, indexedAtt, params.BeaconConfig().MaxValidatorsPerCommittee, params.BeaconConfig().MaxCommitteesPerSlot); err != nil {
return err return err
} }
domain, err := signing.Domain( domain, err := signing.Domain(

View File

@@ -200,7 +200,7 @@ func createAttestationSignatureBatch(
if err != nil { if err != nil {
return nil, err return nil, err
} }
if err := attestation.IsValidAttestationIndices(ctx, ia); err != nil { if err := attestation.IsValidAttestationIndices(ctx, ia, params.BeaconConfig().MaxValidatorsPerCommittee, params.BeaconConfig().MaxCommitteesPerSlot); err != nil {
return nil, err return nil, err
} }
indices := ia.GetAttestingIndices() indices := ia.GetAttestingIndices()

View File

@@ -0,0 +1,2 @@
### Ignored
- remove usages of params from the proto package so that the params package can access proto types.

View File

@@ -29,6 +29,7 @@ go_library(
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//encoding/bytesutil:go_default_library", "//encoding/bytesutil:go_default_library",
"//math:go_default_library", "//math:go_default_library",
"//proto/engine/v1:go_default_library",
"//runtime/version:go_default_library", "//runtime/version:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library", "@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_ethereum_go_ethereum//params:go_default_library", "@com_github_ethereum_go_ethereum//params:go_default_library",

View File

@@ -9,6 +9,7 @@ import (
fieldparams "github.com/OffchainLabs/prysm/v6/config/fieldparams" fieldparams "github.com/OffchainLabs/prysm/v6/config/fieldparams"
"github.com/OffchainLabs/prysm/v6/consensus-types/primitives" "github.com/OffchainLabs/prysm/v6/consensus-types/primitives"
"github.com/OffchainLabs/prysm/v6/encoding/bytesutil" "github.com/OffchainLabs/prysm/v6/encoding/bytesutil"
enginev1 "github.com/OffchainLabs/prysm/v6/proto/engine/v1"
"github.com/OffchainLabs/prysm/v6/runtime/version" "github.com/OffchainLabs/prysm/v6/runtime/version"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
) )
@@ -315,6 +316,14 @@ type BeaconChainConfig struct {
DeprecatedMaxBlobsPerBlockFulu int `yaml:"MAX_BLOBS_PER_BLOCK_FULU" spec:"true"` DeprecatedMaxBlobsPerBlockFulu int `yaml:"MAX_BLOBS_PER_BLOCK_FULU" spec:"true"`
} }
func (b *BeaconChainConfig) ExecutionRequestLimits() enginev1.ExecutionRequestLimits {
return enginev1.ExecutionRequestLimits{
Deposits: b.MaxDepositRequestsPerPayload,
Withdrawals: b.MaxWithdrawalsPerPayload,
Consolidations: b.MaxConsolidationsRequestsPerPayload,
}
}
type BlobScheduleEntry struct { type BlobScheduleEntry struct {
Epoch primitives.Epoch `yaml:"EPOCH"` Epoch primitives.Epoch `yaml:"EPOCH"`
MaxBlobsPerBlock uint64 `yaml:"MAX_BLOBS_PER_BLOCK"` MaxBlobsPerBlock uint64 `yaml:"MAX_BLOBS_PER_BLOCK"`

View File

@@ -1,6 +1,7 @@
package blocks package blocks
import ( import (
"github.com/OffchainLabs/prysm/v6/config/params"
"github.com/OffchainLabs/prysm/v6/consensus-types/interfaces" "github.com/OffchainLabs/prysm/v6/consensus-types/interfaces"
"github.com/OffchainLabs/prysm/v6/consensus-types/primitives" "github.com/OffchainLabs/prysm/v6/consensus-types/primitives"
pb "github.com/OffchainLabs/prysm/v6/proto/engine/v1" pb "github.com/OffchainLabs/prysm/v6/proto/engine/v1"
@@ -33,7 +34,7 @@ type shouldOverrideBuilderGetter interface {
} }
type executionRequestsGetter interface { type executionRequestsGetter interface {
GetDecodedExecutionRequests() (*pb.ExecutionRequests, error) GetDecodedExecutionRequests(pb.ExecutionRequestLimits) (*pb.ExecutionRequests, error)
} }
func NewGetPayloadResponse(msg proto.Message) (*GetPayloadResponse, error) { func NewGetPayloadResponse(msg proto.Message) (*GetPayloadResponse, error) {
@@ -63,7 +64,7 @@ func NewGetPayloadResponse(msg proto.Message) (*GetPayloadResponse, error) {
} }
r.ExecutionData = ed r.ExecutionData = ed
if hasExecutionRequests { if hasExecutionRequests {
requests, err := executionRequestsGetter.GetDecodedExecutionRequests() requests, err := executionRequestsGetter.GetDecodedExecutionRequests(params.BeaconConfig().ExecutionRequestLimits())
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -89,7 +89,6 @@ go_library(
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
deps = [ deps = [
"//config/fieldparams:go_default_library", "//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//encoding/bytesutil:go_default_library", "//encoding/bytesutil:go_default_library",
"//proto/eth/ext:go_default_library", "//proto/eth/ext:go_default_library",

View File

@@ -3,7 +3,6 @@ package enginev1
import ( import (
"fmt" "fmt"
"github.com/OffchainLabs/prysm/v6/config/params"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@@ -23,7 +22,14 @@ const (
ConsolidationRequestType ConsolidationRequestType
) )
func (ebe *ExecutionBundleElectra) GetDecodedExecutionRequests() (*ExecutionRequests, error) { // ExecutionRequestConfig ensures that we don't mix up the execution request params
type ExecutionRequestLimits struct {
Deposits uint64
Withdrawals uint64
Consolidations uint64
}
func (ebe *ExecutionBundleElectra) GetDecodedExecutionRequests(limits ExecutionRequestLimits) (*ExecutionRequests, error) {
requests := &ExecutionRequests{} requests := &ExecutionRequests{}
var prevTypeNum *uint8 var prevTypeNum *uint8
for i := range ebe.ExecutionRequests { for i := range ebe.ExecutionRequests {
@@ -37,19 +43,19 @@ func (ebe *ExecutionBundleElectra) GetDecodedExecutionRequests() (*ExecutionRequ
prevTypeNum = &requestType prevTypeNum = &requestType
switch requestType { switch requestType {
case DepositRequestType: case DepositRequestType:
drs, err := unmarshalDeposits(requestListInSSZBytes) drs, err := unmarshalDeposits(requestListInSSZBytes, limits.Deposits)
if err != nil { if err != nil {
return nil, err return nil, err
} }
requests.Deposits = drs requests.Deposits = drs
case WithdrawalRequestType: case WithdrawalRequestType:
wrs, err := unmarshalWithdrawals(requestListInSSZBytes) wrs, err := unmarshalWithdrawals(requestListInSSZBytes, limits.Withdrawals)
if err != nil { if err != nil {
return nil, err return nil, err
} }
requests.Withdrawals = wrs requests.Withdrawals = wrs
case ConsolidationRequestType: case ConsolidationRequestType:
crs, err := unmarshalConsolidations(requestListInSSZBytes) crs, err := unmarshalConsolidations(requestListInSSZBytes, limits.Consolidations)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -61,33 +67,33 @@ func (ebe *ExecutionBundleElectra) GetDecodedExecutionRequests() (*ExecutionRequ
return requests, nil return requests, nil
} }
func unmarshalDeposits(requestListInSSZBytes []byte) ([]*DepositRequest, error) { func unmarshalDeposits(requestListInSSZBytes []byte, maxDepositRequests uint64) ([]*DepositRequest, error) {
if len(requestListInSSZBytes) < drSize { if len(requestListInSSZBytes) < drSize {
return nil, fmt.Errorf("invalid deposit requests SSZ size, got %d expected at least %d", len(requestListInSSZBytes), drSize) return nil, fmt.Errorf("invalid deposit requests SSZ size, got %d expected at least %d", len(requestListInSSZBytes), drSize)
} }
maxSSZsize := uint64(drSize) * params.BeaconConfig().MaxDepositRequestsPerPayload maxSSZsize := uint64(drSize) * maxDepositRequests
if uint64(len(requestListInSSZBytes)) > maxSSZsize { if uint64(len(requestListInSSZBytes)) > maxSSZsize {
return nil, fmt.Errorf("invalid deposit requests SSZ size, requests should not be more than the max per payload, got %d max %d", len(requestListInSSZBytes), maxSSZsize) return nil, fmt.Errorf("invalid deposit requests SSZ size, requests should not be more than the max per payload, got %d max %d", len(requestListInSSZBytes), maxSSZsize)
} }
return unmarshalItems(requestListInSSZBytes, drSize, func() *DepositRequest { return &DepositRequest{} }) return unmarshalItems(requestListInSSZBytes, drSize, func() *DepositRequest { return &DepositRequest{} })
} }
func unmarshalWithdrawals(requestListInSSZBytes []byte) ([]*WithdrawalRequest, error) { func unmarshalWithdrawals(requestListInSSZBytes []byte, maxWithdrawals uint64) ([]*WithdrawalRequest, error) {
if len(requestListInSSZBytes) < wrSize { if len(requestListInSSZBytes) < wrSize {
return nil, fmt.Errorf("invalid withdrawal requests SSZ size, got %d expected at least %d", len(requestListInSSZBytes), wrSize) return nil, fmt.Errorf("invalid withdrawal requests SSZ size, got %d expected at least %d", len(requestListInSSZBytes), wrSize)
} }
maxSSZsize := uint64(wrSize) * params.BeaconConfig().MaxWithdrawalRequestsPerPayload maxSSZsize := uint64(wrSize) * maxWithdrawals
if uint64(len(requestListInSSZBytes)) > maxSSZsize { if uint64(len(requestListInSSZBytes)) > maxSSZsize {
return nil, fmt.Errorf("invalid withdrawal requests SSZ size, requests should not be more than the max per payload, got %d max %d", len(requestListInSSZBytes), maxSSZsize) return nil, fmt.Errorf("invalid withdrawal requests SSZ size, requests should not be more than the max per payload, got %d max %d", len(requestListInSSZBytes), maxSSZsize)
} }
return unmarshalItems(requestListInSSZBytes, wrSize, func() *WithdrawalRequest { return &WithdrawalRequest{} }) return unmarshalItems(requestListInSSZBytes, wrSize, func() *WithdrawalRequest { return &WithdrawalRequest{} })
} }
func unmarshalConsolidations(requestListInSSZBytes []byte) ([]*ConsolidationRequest, error) { func unmarshalConsolidations(requestListInSSZBytes []byte, maxConsolidations uint64) ([]*ConsolidationRequest, error) {
if len(requestListInSSZBytes) < crSize { if len(requestListInSSZBytes) < crSize {
return nil, fmt.Errorf("invalid consolidation requests SSZ size, got %d expected at least %d", len(requestListInSSZBytes), crSize) return nil, fmt.Errorf("invalid consolidation requests SSZ size, got %d expected at least %d", len(requestListInSSZBytes), crSize)
} }
maxSSZsize := uint64(crSize) * params.BeaconConfig().MaxConsolidationsRequestsPerPayload maxSSZsize := uint64(crSize) * maxConsolidations
if uint64(len(requestListInSSZBytes)) > maxSSZsize { if uint64(len(requestListInSSZBytes)) > maxSSZsize {
return nil, fmt.Errorf("invalid consolidation requests SSZ size, requests should not be more than the max per payload, got %d max %d", len(requestListInSSZBytes), maxSSZsize) return nil, fmt.Errorf("invalid consolidation requests SSZ size, requests should not be more than the max per payload, got %d max %d", len(requestListInSSZBytes), maxSSZsize)
} }

View File

@@ -13,6 +13,7 @@ import (
var depositRequestsSSZHex = "0x706b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000077630000000000000000000000000000000000000000000000000000000000007b00000000000000736967000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c801000000000000706b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000776300000000000000000000000000000000000000000000000000000000000090010000000000007369670000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000" var depositRequestsSSZHex = "0x706b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000077630000000000000000000000000000000000000000000000000000000000007b00000000000000736967000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c801000000000000706b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000776300000000000000000000000000000000000000000000000000000000000090010000000000007369670000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000"
func TestGetDecodedExecutionRequests(t *testing.T) { func TestGetDecodedExecutionRequests(t *testing.T) {
cfg := params.BeaconConfig()
t.Run("All requests decode successfully", func(t *testing.T) { t.Run("All requests decode successfully", func(t *testing.T) {
depositRequestBytes, err := hexutil.Decode("0x610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + depositRequestBytes, err := hexutil.Decode("0x610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
"620000000000000000000000000000000000000000000000000000000000000000" + "620000000000000000000000000000000000000000000000000000000000000000" +
@@ -31,7 +32,7 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
append([]byte{uint8(enginev1.WithdrawalRequestType)}, withdrawalRequestBytes...), append([]byte{uint8(enginev1.WithdrawalRequestType)}, withdrawalRequestBytes...),
append([]byte{uint8(enginev1.ConsolidationRequestType)}, consolidationRequestBytes...)}, append([]byte{uint8(enginev1.ConsolidationRequestType)}, consolidationRequestBytes...)},
} }
requests, err := ebe.GetDecodedExecutionRequests() requests, err := ebe.GetDecodedExecutionRequests(cfg.ExecutionRequestLimits())
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, len(requests.Deposits), 1) require.Equal(t, len(requests.Deposits), 1)
require.Equal(t, len(requests.Withdrawals), 1) require.Equal(t, len(requests.Withdrawals), 1)
@@ -50,7 +51,7 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
ebe := &enginev1.ExecutionBundleElectra{ ebe := &enginev1.ExecutionBundleElectra{
ExecutionRequests: [][]byte{append([]byte{uint8(enginev1.DepositRequestType)}, depositRequestBytes...), append([]byte{uint8(enginev1.ConsolidationRequestType)}, consolidationRequestBytes...)}, ExecutionRequests: [][]byte{append([]byte{uint8(enginev1.DepositRequestType)}, depositRequestBytes...), append([]byte{uint8(enginev1.ConsolidationRequestType)}, consolidationRequestBytes...)},
} }
requests, err := ebe.GetDecodedExecutionRequests() requests, err := ebe.GetDecodedExecutionRequests(cfg.ExecutionRequestLimits())
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, len(requests.Deposits), 1) require.Equal(t, len(requests.Deposits), 1)
require.Equal(t, len(requests.Withdrawals), 0) require.Equal(t, len(requests.Withdrawals), 0)
@@ -69,7 +70,7 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
ebe := &enginev1.ExecutionBundleElectra{ ebe := &enginev1.ExecutionBundleElectra{
ExecutionRequests: [][]byte{append([]byte{uint8(enginev1.ConsolidationRequestType)}, consolidationRequestBytes...), append([]byte{uint8(enginev1.DepositRequestType)}, depositRequestBytes...)}, ExecutionRequests: [][]byte{append([]byte{uint8(enginev1.ConsolidationRequestType)}, consolidationRequestBytes...), append([]byte{uint8(enginev1.DepositRequestType)}, depositRequestBytes...)},
} }
_, err = ebe.GetDecodedExecutionRequests() _, err = ebe.GetDecodedExecutionRequests(cfg.ExecutionRequestLimits())
require.ErrorContains(t, "invalid execution request type order", err) require.ErrorContains(t, "invalid execution request type order", err)
}) })
t.Run("Requests should error if the request type is shorter than 1 byte", func(t *testing.T) { t.Run("Requests should error if the request type is shorter than 1 byte", func(t *testing.T) {
@@ -80,7 +81,7 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
ebe := &enginev1.ExecutionBundleElectra{ ebe := &enginev1.ExecutionBundleElectra{
ExecutionRequests: [][]byte{append([]byte{}, []byte{}...), append([]byte{uint8(enginev1.ConsolidationRequestType)}, consolidationRequestBytes...)}, ExecutionRequests: [][]byte{append([]byte{}, []byte{}...), append([]byte{uint8(enginev1.ConsolidationRequestType)}, consolidationRequestBytes...)},
} }
_, err = ebe.GetDecodedExecutionRequests() _, err = ebe.GetDecodedExecutionRequests(cfg.ExecutionRequestLimits())
require.ErrorContains(t, "invalid execution request, length less than 1", err) require.ErrorContains(t, "invalid execution request, length less than 1", err)
}) })
t.Run("a duplicate request should fail", func(t *testing.T) { t.Run("a duplicate request should fail", func(t *testing.T) {
@@ -93,7 +94,7 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
ebe := &enginev1.ExecutionBundleElectra{ ebe := &enginev1.ExecutionBundleElectra{
ExecutionRequests: [][]byte{append([]byte{uint8(enginev1.WithdrawalRequestType)}, withdrawalRequestBytes...), append([]byte{uint8(enginev1.WithdrawalRequestType)}, withdrawalRequestBytes2...)}, ExecutionRequests: [][]byte{append([]byte{uint8(enginev1.WithdrawalRequestType)}, withdrawalRequestBytes...), append([]byte{uint8(enginev1.WithdrawalRequestType)}, withdrawalRequestBytes2...)},
} }
_, err = ebe.GetDecodedExecutionRequests() _, err = ebe.GetDecodedExecutionRequests(cfg.ExecutionRequestLimits())
require.ErrorContains(t, "requests should be in sorted order and unique", err) require.ErrorContains(t, "requests should be in sorted order and unique", err)
}) })
t.Run("a duplicate withdrawals ( non 0 request type )request should fail", func(t *testing.T) { t.Run("a duplicate withdrawals ( non 0 request type )request should fail", func(t *testing.T) {
@@ -110,7 +111,7 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
ebe := &enginev1.ExecutionBundleElectra{ ebe := &enginev1.ExecutionBundleElectra{
ExecutionRequests: [][]byte{append([]byte{uint8(enginev1.DepositRequestType)}, depositRequestBytes...), append([]byte{uint8(enginev1.DepositRequestType)}, depositRequestBytes2...)}, ExecutionRequests: [][]byte{append([]byte{uint8(enginev1.DepositRequestType)}, depositRequestBytes...), append([]byte{uint8(enginev1.DepositRequestType)}, depositRequestBytes2...)},
} }
_, err = ebe.GetDecodedExecutionRequests() _, err = ebe.GetDecodedExecutionRequests(cfg.ExecutionRequestLimits())
require.ErrorContains(t, "requests should be in sorted order and unique", err) require.ErrorContains(t, "requests should be in sorted order and unique", err)
}) })
t.Run("If a request type is provided, but the request list is shorter than the ssz of 1 request we error", func(t *testing.T) { t.Run("If a request type is provided, but the request list is shorter than the ssz of 1 request we error", func(t *testing.T) {
@@ -121,11 +122,11 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
ebe := &enginev1.ExecutionBundleElectra{ ebe := &enginev1.ExecutionBundleElectra{
ExecutionRequests: [][]byte{append([]byte{uint8(enginev1.DepositRequestType)}, []byte{}...), append([]byte{uint8(enginev1.ConsolidationRequestType)}, consolidationRequestBytes...)}, ExecutionRequests: [][]byte{append([]byte{uint8(enginev1.DepositRequestType)}, []byte{}...), append([]byte{uint8(enginev1.ConsolidationRequestType)}, consolidationRequestBytes...)},
} }
_, err = ebe.GetDecodedExecutionRequests() _, err = ebe.GetDecodedExecutionRequests(cfg.ExecutionRequestLimits())
require.ErrorContains(t, "invalid deposit requests SSZ size", err) require.ErrorContains(t, "invalid deposit requests SSZ size", err)
}) })
t.Run("If deposit requests are over the max allowed per payload then we should error", func(t *testing.T) { t.Run("If deposit requests are over the max allowed per payload then we should error", func(t *testing.T) {
requests := make([]*enginev1.DepositRequest, params.BeaconConfig().MaxDepositRequestsPerPayload+1) requests := make([]*enginev1.DepositRequest, cfg.MaxDepositRequestsPerPayload+1)
for i := range requests { for i := range requests {
requests[i] = &enginev1.DepositRequest{ requests[i] = &enginev1.DepositRequest{
Pubkey: bytesutil.PadTo([]byte("pk"), 48), Pubkey: bytesutil.PadTo([]byte("pk"), 48),
@@ -142,11 +143,11 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
append([]byte{uint8(enginev1.DepositRequestType)}, by...), append([]byte{uint8(enginev1.DepositRequestType)}, by...),
}, },
} }
_, err = ebe.GetDecodedExecutionRequests() _, err = ebe.GetDecodedExecutionRequests(cfg.ExecutionRequestLimits())
require.ErrorContains(t, "invalid deposit requests SSZ size, requests should not be more than the max per payload", err) require.ErrorContains(t, "invalid deposit requests SSZ size, requests should not be more than the max per payload", err)
}) })
t.Run("If withdrawal requests are over the max allowed per payload then we should error", func(t *testing.T) { t.Run("If withdrawal requests are over the max allowed per payload then we should error", func(t *testing.T) {
requests := make([]*enginev1.WithdrawalRequest, params.BeaconConfig().MaxWithdrawalRequestsPerPayload+1) requests := make([]*enginev1.WithdrawalRequest, cfg.MaxWithdrawalRequestsPerPayload+1)
for i := range requests { for i := range requests {
requests[i] = &enginev1.WithdrawalRequest{ requests[i] = &enginev1.WithdrawalRequest{
SourceAddress: bytesutil.PadTo([]byte("sa"), 20), SourceAddress: bytesutil.PadTo([]byte("sa"), 20),
@@ -161,11 +162,11 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
append([]byte{uint8(enginev1.WithdrawalRequestType)}, by...), append([]byte{uint8(enginev1.WithdrawalRequestType)}, by...),
}, },
} }
_, err = ebe.GetDecodedExecutionRequests() _, err = ebe.GetDecodedExecutionRequests(cfg.ExecutionRequestLimits())
require.ErrorContains(t, "invalid withdrawal requests SSZ size, requests should not be more than the max per payload", err) require.ErrorContains(t, "invalid withdrawal requests SSZ size, requests should not be more than the max per payload", err)
}) })
t.Run("If consolidation requests are over the max allowed per payload then we should error", func(t *testing.T) { t.Run("If consolidation requests are over the max allowed per payload then we should error", func(t *testing.T) {
requests := make([]*enginev1.ConsolidationRequest, params.BeaconConfig().MaxConsolidationsRequestsPerPayload+1) requests := make([]*enginev1.ConsolidationRequest, cfg.MaxConsolidationsRequestsPerPayload+1)
for i := range requests { for i := range requests {
requests[i] = &enginev1.ConsolidationRequest{ requests[i] = &enginev1.ConsolidationRequest{
SourceAddress: bytesutil.PadTo([]byte("sa"), 20), SourceAddress: bytesutil.PadTo([]byte("sa"), 20),
@@ -180,7 +181,7 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
append([]byte{uint8(enginev1.ConsolidationRequestType)}, by...), append([]byte{uint8(enginev1.ConsolidationRequestType)}, by...),
}, },
} }
_, err = ebe.GetDecodedExecutionRequests() _, err = ebe.GetDecodedExecutionRequests(cfg.ExecutionRequestLimits())
require.ErrorContains(t, "invalid consolidation requests SSZ size, requests should not be more than the max per payload", err) require.ErrorContains(t, "invalid consolidation requests SSZ size, requests should not be more than the max per payload", err)
}) })
} }

View File

@@ -4,7 +4,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
) )
func (ebe *ExecutionBundleFulu) GetDecodedExecutionRequests() (*ExecutionRequests, error) { func (ebe *ExecutionBundleFulu) GetDecodedExecutionRequests(limits ExecutionRequestLimits) (*ExecutionRequests, error) {
requests := &ExecutionRequests{} requests := &ExecutionRequests{}
var prevTypeNum *uint8 var prevTypeNum *uint8
for i := range ebe.ExecutionRequests { for i := range ebe.ExecutionRequests {
@@ -18,19 +18,19 @@ func (ebe *ExecutionBundleFulu) GetDecodedExecutionRequests() (*ExecutionRequest
prevTypeNum = &requestType prevTypeNum = &requestType
switch requestType { switch requestType {
case DepositRequestType: case DepositRequestType:
drs, err := unmarshalDeposits(requestListInSSZBytes) drs, err := unmarshalDeposits(requestListInSSZBytes, limits.Deposits)
if err != nil { if err != nil {
return nil, err return nil, err
} }
requests.Deposits = drs requests.Deposits = drs
case WithdrawalRequestType: case WithdrawalRequestType:
wrs, err := unmarshalWithdrawals(requestListInSSZBytes) wrs, err := unmarshalWithdrawals(requestListInSSZBytes, limits.Withdrawals)
if err != nil { if err != nil {
return nil, err return nil, err
} }
requests.Withdrawals = wrs requests.Withdrawals = wrs
case ConsolidationRequestType: case ConsolidationRequestType:
crs, err := unmarshalConsolidations(requestListInSSZBytes) crs, err := unmarshalConsolidations(requestListInSSZBytes, limits.Consolidations)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -10,7 +10,6 @@ go_library(
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
deps = [ deps = [
"//beacon-chain/core/signing:go_default_library", "//beacon-chain/core/signing:go_default_library",
"//config/params:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//crypto/bls:go_default_library", "//crypto/bls:go_default_library",
"//crypto/hash:go_default_library", "//crypto/hash:go_default_library",

View File

@@ -23,6 +23,7 @@ go_test(
name = "go_default_test", name = "go_default_test",
srcs = [ srcs = [
"attestations_test.go", "attestations_test.go",
"export_test.go",
"maxcover_test.go", "maxcover_test.go",
], ],
embed = [":go_default_library"], embed = [":go_default_library"],

View File

@@ -1,4 +1,4 @@
package attestations package attestations_test
import ( import (
"io" "io"
@@ -10,6 +10,7 @@ import (
"github.com/OffchainLabs/prysm/v6/encoding/ssz/equality" "github.com/OffchainLabs/prysm/v6/encoding/ssz/equality"
ethpb "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1" ethpb "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1"
"github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1/attestation/aggregation" "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1/attestation/aggregation"
"github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1/attestation/aggregation/attestations"
aggtesting "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1/attestation/aggregation/testing" aggtesting "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1/attestation/aggregation/testing"
"github.com/OffchainLabs/prysm/v6/testing/assert" "github.com/OffchainLabs/prysm/v6/testing/assert"
"github.com/OffchainLabs/prysm/v6/testing/require" "github.com/OffchainLabs/prysm/v6/testing/require"
@@ -46,7 +47,7 @@ func TestAggregateAttestations_AggregatePair(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
got, err := AggregatePair(tt.a1, tt.a2) got, err := attestations.AggregatePair(tt.a1, tt.a2)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, true, equality.DeepEqual(got, tt.want)) require.Equal(t, true, equality.DeepEqual(got, tt.want))
} }
@@ -67,7 +68,7 @@ func TestAggregateAttestations_AggregatePair_OverlapFails(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
_, err := AggregatePair(tt.a1, tt.a2) _, err := attestations.AggregatePair(tt.a1, tt.a2)
require.ErrorContains(t, aggregation.ErrBitsOverlap.Error(), err) require.ErrorContains(t, aggregation.ErrBitsOverlap.Error(), err)
} }
} }
@@ -83,7 +84,7 @@ func TestAggregateAttestations_AggregatePair_DiffLengthFails(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
_, err := AggregatePair(tt.a1, tt.a2) _, err := attestations.AggregatePair(tt.a1, tt.a2)
require.ErrorContains(t, bitfield.ErrBitlistDifferentLength.Error(), err) require.ErrorContains(t, bitfield.ErrBitlistDifferentLength.Error(), err)
} }
} }
@@ -209,7 +210,7 @@ func TestAggregateAttestations_Aggregate(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
runner := func() { runner := func() {
got, err := Aggregate(aggtesting.MakeAttestationsFromBitlists(tt.inputs)) got, err := attestations.Aggregate(aggtesting.MakeAttestationsFromBitlists(tt.inputs))
if tt.err != nil { if tt.err != nil {
require.ErrorContains(t, tt.err.Error(), err) require.ErrorContains(t, tt.err.Error(), err)
return return
@@ -233,7 +234,7 @@ func TestAggregateAttestations_Aggregate(t *testing.T) {
t.Run("broken attestation bitset", func(t *testing.T) { t.Run("broken attestation bitset", func(t *testing.T) {
wantErr := "bitlist cannot be nil or empty: invalid max_cover problem" wantErr := "bitlist cannot be nil or empty: invalid max_cover problem"
_, err := Aggregate(aggtesting.MakeAttestationsFromBitlists([]bitfield.Bitlist{ _, err := attestations.Aggregate(aggtesting.MakeAttestationsFromBitlists([]bitfield.Bitlist{
{0b00000011, 0b0}, {0b00000011, 0b0},
{0b00000111, 0b100}, {0b00000111, 0b100},
{0b00000100, 0b1}, {0b00000100, 0b1},
@@ -245,7 +246,7 @@ func TestAggregateAttestations_Aggregate(t *testing.T) {
// The first item cannot be aggregated, and should be pushed down the list, // The first item cannot be aggregated, and should be pushed down the list,
// by two swaps with aggregated items (aggregation is done in-place, so the very same // by two swaps with aggregated items (aggregation is done in-place, so the very same
// underlying array is used for storing both aggregated and non-aggregated items). // underlying array is used for storing both aggregated and non-aggregated items).
got, err := Aggregate(aggtesting.MakeAttestationsFromBitlists([]bitfield.Bitlist{ got, err := attestations.Aggregate(aggtesting.MakeAttestationsFromBitlists([]bitfield.Bitlist{
{0b10000000, 0b1}, {0b10000000, 0b1},
{0b11000101, 0b1}, {0b11000101, 0b1},
{0b00011000, 0b1}, {0b00011000, 0b1},

View File

@@ -0,0 +1,11 @@
package attestations
// export attList for the attestations_test package
type AttList attList
func (a AttList) ValidateForTesting() error {
return attList(a).validate()
}
var RearrangeProcessedAttestations = rearrangeProcessedAttestations
var AggregateAttestations = aggregateAttestations

View File

@@ -1,4 +1,4 @@
package attestations package attestations_test
import ( import (
"testing" "testing"
@@ -6,6 +6,7 @@ import (
"github.com/OffchainLabs/prysm/v6/crypto/bls" "github.com/OffchainLabs/prysm/v6/crypto/bls"
ethpb "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1" ethpb "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1"
"github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1/attestation/aggregation" "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1/attestation/aggregation"
"github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1/attestation/aggregation/attestations"
"github.com/OffchainLabs/prysm/v6/testing/assert" "github.com/OffchainLabs/prysm/v6/testing/assert"
"github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/go-bitfield"
) )
@@ -70,7 +71,7 @@ func TestAggregateAttestations_MaxCover_NewMaxCover(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
assert.DeepEqual(t, tt.want, NewMaxCover(tt.args.atts)) assert.DeepEqual(t, tt.want, attestations.NewMaxCover(tt.args.atts))
}) })
} }
} }
@@ -78,7 +79,7 @@ func TestAggregateAttestations_MaxCover_NewMaxCover(t *testing.T) {
func TestAggregateAttestations_MaxCover_AttList_validate(t *testing.T) { func TestAggregateAttestations_MaxCover_AttList_validate(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
atts attList atts attestations.AttList
wantedErr string wantedErr string
}{ }{
{ {
@@ -88,17 +89,17 @@ func TestAggregateAttestations_MaxCover_AttList_validate(t *testing.T) {
}, },
{ {
name: "empty list", name: "empty list",
atts: attList{}, atts: attestations.AttList{},
wantedErr: "empty list", wantedErr: "empty list",
}, },
{ {
name: "first bitlist is nil", name: "first bitlist is nil",
atts: attList{&ethpb.Attestation{}}, atts: attestations.AttList{&ethpb.Attestation{}},
wantedErr: "bitlist cannot be nil or empty", wantedErr: "bitlist cannot be nil or empty",
}, },
{ {
name: "non first bitlist is nil", name: "non first bitlist is nil",
atts: attList{ atts: attestations.AttList{
&ethpb.Attestation{AggregationBits: bitfield.NewBitlist(64)}, &ethpb.Attestation{AggregationBits: bitfield.NewBitlist(64)},
&ethpb.Attestation{}, &ethpb.Attestation{},
}, },
@@ -106,14 +107,14 @@ func TestAggregateAttestations_MaxCover_AttList_validate(t *testing.T) {
}, },
{ {
name: "first bitlist is empty", name: "first bitlist is empty",
atts: attList{ atts: attestations.AttList{
&ethpb.Attestation{AggregationBits: bitfield.Bitlist{}}, &ethpb.Attestation{AggregationBits: bitfield.Bitlist{}},
}, },
wantedErr: "bitlist cannot be nil or empty", wantedErr: "bitlist cannot be nil or empty",
}, },
{ {
name: "non first bitlist is empty", name: "non first bitlist is empty",
atts: attList{ atts: attestations.AttList{
&ethpb.Attestation{AggregationBits: bitfield.NewBitlist(64)}, &ethpb.Attestation{AggregationBits: bitfield.NewBitlist(64)},
&ethpb.Attestation{AggregationBits: bitfield.Bitlist{}}, &ethpb.Attestation{AggregationBits: bitfield.Bitlist{}},
}, },
@@ -121,7 +122,7 @@ func TestAggregateAttestations_MaxCover_AttList_validate(t *testing.T) {
}, },
{ {
name: "valid bitlists", name: "valid bitlists",
atts: attList{ atts: attestations.AttList{
&ethpb.Attestation{AggregationBits: bitfield.NewBitlist(64)}, &ethpb.Attestation{AggregationBits: bitfield.NewBitlist(64)},
&ethpb.Attestation{AggregationBits: bitfield.NewBitlist(64)}, &ethpb.Attestation{AggregationBits: bitfield.NewBitlist(64)},
&ethpb.Attestation{AggregationBits: bitfield.NewBitlist(64)}, &ethpb.Attestation{AggregationBits: bitfield.NewBitlist(64)},
@@ -131,7 +132,7 @@ func TestAggregateAttestations_MaxCover_AttList_validate(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
err := tt.atts.validate() err := tt.atts.ValidateForTesting()
if tt.wantedErr != "" { if tt.wantedErr != "" {
assert.ErrorContains(t, tt.wantedErr, err) assert.ErrorContains(t, tt.wantedErr, err)
} else { } else {
@@ -292,7 +293,7 @@ func TestAggregateAttestations_rearrangeProcessedAttestations(t *testing.T) {
} }
} }
} }
rearrangeProcessedAttestations(tt.atts, candidates, tt.keys) attestations.RearrangeProcessedAttestations(tt.atts, candidates, tt.keys)
assert.DeepEqual(t, tt.atts, tt.wantAtts) assert.DeepEqual(t, tt.atts, tt.wantAtts)
}) })
} }
@@ -312,7 +313,7 @@ func TestAggregateAttestations_aggregateAttestations(t *testing.T) {
{ {
name: "nil attestation", name: "nil attestation",
wantTargetIdx: 0, wantTargetIdx: 0,
wantErr: ErrInvalidAttestationCount.Error(), wantErr: attestations.ErrInvalidAttestationCount.Error(),
keys: []int{0, 1, 2}, keys: []int{0, 1, 2},
}, },
{ {
@@ -321,13 +322,13 @@ func TestAggregateAttestations_aggregateAttestations(t *testing.T) {
&ethpb.Attestation{}, &ethpb.Attestation{},
}, },
wantTargetIdx: 0, wantTargetIdx: 0,
wantErr: ErrInvalidAttestationCount.Error(), wantErr: attestations.ErrInvalidAttestationCount.Error(),
keys: []int{0, 1, 2}, keys: []int{0, 1, 2},
}, },
{ {
name: "no keys", name: "no keys",
wantTargetIdx: 0, wantTargetIdx: 0,
wantErr: ErrInvalidAttestationCount.Error(), wantErr: attestations.ErrInvalidAttestationCount.Error(),
}, },
{ {
name: "two attestations, none selected", name: "two attestations, none selected",
@@ -336,7 +337,7 @@ func TestAggregateAttestations_aggregateAttestations(t *testing.T) {
&ethpb.Attestation{AggregationBits: bitfield.Bitlist{0x01}}, &ethpb.Attestation{AggregationBits: bitfield.Bitlist{0x01}},
}, },
wantTargetIdx: 0, wantTargetIdx: 0,
wantErr: ErrInvalidAttestationCount.Error(), wantErr: attestations.ErrInvalidAttestationCount.Error(),
keys: []int{}, keys: []int{},
}, },
{ {
@@ -346,7 +347,7 @@ func TestAggregateAttestations_aggregateAttestations(t *testing.T) {
&ethpb.Attestation{AggregationBits: bitfield.Bitlist{0x01}}, &ethpb.Attestation{AggregationBits: bitfield.Bitlist{0x01}},
}, },
wantTargetIdx: 0, wantTargetIdx: 0,
wantErr: ErrInvalidAttestationCount.Error(), wantErr: attestations.ErrInvalidAttestationCount.Error(),
keys: []int{0}, keys: []int{0},
}, },
{ {
@@ -414,7 +415,7 @@ func TestAggregateAttestations_aggregateAttestations(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
gotTargetIdx, err := aggregateAttestations(tt.atts, tt.keys, tt.coverage) gotTargetIdx, err := attestations.AggregateAttestations(tt.atts, tt.keys, tt.coverage)
if tt.wantErr != "" { if tt.wantErr != "" {
assert.ErrorContains(t, tt.wantErr, err) assert.ErrorContains(t, tt.wantErr, err)
return return

View File

@@ -1,10 +1,11 @@
package aggregation package aggregation_test
import ( import (
"fmt" "fmt"
"testing" "testing"
"github.com/OffchainLabs/prysm/v6/config/params" "github.com/OffchainLabs/prysm/v6/config/params"
"github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1/attestation/aggregation"
aggtesting "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1/attestation/aggregation/testing" aggtesting "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1/attestation/aggregation/testing"
"github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/go-bitfield"
) )
@@ -66,7 +67,7 @@ func BenchmarkMaxCoverProblem_MaxCover(b *testing.B) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
name := fmt.Sprintf("%d_attestations_with_%d_bit(s)_set", tt.numCandidates, tt.numMarkedBits) name := fmt.Sprintf("%d_aggregations_with_%d_bit(s)_set", tt.numCandidates, tt.numMarkedBits)
b.Run(fmt.Sprintf("cur_%s", name), func(b *testing.B) { b.Run(fmt.Sprintf("cur_%s", name), func(b *testing.B) {
b.StopTimer() b.StopTimer()
var bitlists []bitfield.Bitlist var bitlists []bitfield.Bitlist
@@ -78,11 +79,11 @@ func BenchmarkMaxCoverProblem_MaxCover(b *testing.B) {
} }
b.StartTimer() b.StartTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
candidates := make([]*MaxCoverCandidate, len(bitlists)) candidates := make([]*aggregation.MaxCoverCandidate, len(bitlists))
for i := 0; i < len(bitlists); i++ { for i := 0; i < len(bitlists); i++ {
candidates[i] = NewMaxCoverCandidate(i, &bitlists[i]) candidates[i] = aggregation.NewMaxCoverCandidate(i, &bitlists[i])
} }
mc := &MaxCoverProblem{Candidates: candidates} mc := &aggregation.MaxCoverProblem{Candidates: candidates}
_, err := mc.Cover(len(bitlists), tt.allowOverlaps) _, err := mc.Cover(len(bitlists), tt.allowOverlaps)
_ = err _ = err
} }
@@ -98,7 +99,7 @@ func BenchmarkMaxCoverProblem_MaxCover(b *testing.B) {
} }
b.StartTimer() b.StartTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_, _, err := MaxCover(bitlists, len(bitlists), tt.allowOverlaps) _, _, err := aggregation.MaxCover(bitlists, len(bitlists), tt.allowOverlaps)
_ = err _ = err
} }
}) })

View File

@@ -11,7 +11,6 @@ import (
"sort" "sort"
"github.com/OffchainLabs/prysm/v6/beacon-chain/core/signing" "github.com/OffchainLabs/prysm/v6/beacon-chain/core/signing"
"github.com/OffchainLabs/prysm/v6/config/params"
"github.com/OffchainLabs/prysm/v6/consensus-types/primitives" "github.com/OffchainLabs/prysm/v6/consensus-types/primitives"
"github.com/OffchainLabs/prysm/v6/crypto/bls" "github.com/OffchainLabs/prysm/v6/crypto/bls"
"github.com/OffchainLabs/prysm/v6/monitoring/tracing/trace" "github.com/OffchainLabs/prysm/v6/monitoring/tracing/trace"
@@ -174,6 +173,10 @@ func VerifyIndexedAttestationSig(ctx context.Context, indexedAtt ethpb.IndexedAt
// spec indexed attestation validation starting at Check if “indexed_attestation“ // spec indexed attestation validation starting at Check if “indexed_attestation“
// comment and ends at Verify aggregate signature comment. // comment and ends at Verify aggregate signature comment.
// //
// requires the caller to pass config params:
// MAX_VALIDATORS_PER_COMMITTEE = committeeValMax
// MAX_COMMITTEES_PER_SLOT = maxCommittees
//
// Spec pseudocode definition: // Spec pseudocode definition:
// //
// def is_valid_indexed_attestation(state: BeaconState, indexed_attestation: IndexedAttestation) -> bool: // def is_valid_indexed_attestation(state: BeaconState, indexed_attestation: IndexedAttestation) -> bool:
@@ -189,7 +192,7 @@ func VerifyIndexedAttestationSig(ctx context.Context, indexedAtt ethpb.IndexedAt
// domain = get_domain(state, DOMAIN_BEACON_ATTESTER, indexed_attestation.data.target.epoch) // domain = get_domain(state, DOMAIN_BEACON_ATTESTER, indexed_attestation.data.target.epoch)
// signing_root = compute_signing_root(indexed_attestation.data, domain) // signing_root = compute_signing_root(indexed_attestation.data, domain)
// return bls.FastAggregateVerify(pubkeys, signing_root, indexed_attestation.signature) // return bls.FastAggregateVerify(pubkeys, signing_root, indexed_attestation.signature)
func IsValidAttestationIndices(ctx context.Context, indexedAttestation ethpb.IndexedAtt) error { func IsValidAttestationIndices(ctx context.Context, indexedAttestation ethpb.IndexedAtt, committeeValMax, maxCommittees uint64) error {
_, span := trace.StartSpan(ctx, "attestationutil.IsValidAttestationIndices") _, span := trace.StartSpan(ctx, "attestationutil.IsValidAttestationIndices")
defer span.End() defer span.End()
@@ -202,12 +205,12 @@ func IsValidAttestationIndices(ctx context.Context, indexedAttestation ethpb.Ind
return errors.New("expected non-empty attesting indices") return errors.New("expected non-empty attesting indices")
} }
if indexedAttestation.Version() < version.Electra { if indexedAttestation.Version() < version.Electra {
maxLength := params.BeaconConfig().MaxValidatorsPerCommittee maxLength := committeeValMax
if uint64(len(indices)) > maxLength { if uint64(len(indices)) > maxLength {
return fmt.Errorf("validator indices count exceeds MAX_VALIDATORS_PER_COMMITTEE, %d > %d", len(indices), maxLength) return fmt.Errorf("validator indices count exceeds MAX_VALIDATORS_PER_COMMITTEE, %d > %d", len(indices), maxLength)
} }
} else { } else {
maxLength := params.BeaconConfig().MaxValidatorsPerCommittee * params.BeaconConfig().MaxCommitteesPerSlot maxLength := committeeValMax * maxCommittees
if uint64(len(indices)) > maxLength { if uint64(len(indices)) > maxLength {
return fmt.Errorf("validator indices count exceeds MAX_VALIDATORS_PER_COMMITTEE * MAX_COMMITTEES_PER_SLOT, %d > %d", len(indices), maxLength) return fmt.Errorf("validator indices count exceeds MAX_VALIDATORS_PER_COMMITTEE * MAX_COMMITTEES_PER_SLOT, %d > %d", len(indices), maxLength)
} }

View File

@@ -204,7 +204,7 @@ func TestIsValidAttestationIndices(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
err := attestation.IsValidAttestationIndices(context.Background(), tt.att) err := attestation.IsValidAttestationIndices(context.Background(), tt.att, params.BeaconConfig().MaxValidatorsPerCommittee, params.BeaconConfig().MaxCommitteesPerSlot)
if tt.wantedErr != "" { if tt.wantedErr != "" {
assert.ErrorContains(t, tt.wantedErr, err) assert.ErrorContains(t, tt.wantedErr, err)
} else { } else {
@@ -240,7 +240,7 @@ func BenchmarkIsValidAttestationIndices(b *testing.B) {
} }
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
if err := attestation.IsValidAttestationIndices(context.Background(), att); err != nil { if err := attestation.IsValidAttestationIndices(context.Background(), att, params.BeaconConfig().MaxValidatorsPerCommittee, params.BeaconConfig().MaxCommitteesPerSlot); err != nil {
require.NoError(b, err) require.NoError(b, err)
} }
} }

View File

@@ -631,7 +631,7 @@ func (p *Builder) handleHeaderRequestElectra(w http.ResponseWriter) {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
requests, err := b.GetDecodedExecutionRequests() requests, err := b.GetDecodedExecutionRequests(params.BeaconConfig().ExecutionRequestLimits())
if err != nil { if err != nil {
p.cfg.logger.WithError(err).Error("Could not get decoded execution requests") p.cfg.logger.WithError(err).Error("Could not get decoded execution requests")
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)