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

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

View File

@@ -3,7 +3,6 @@ package enginev1
import (
"fmt"
"github.com/OffchainLabs/prysm/v6/config/params"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/pkg/errors"
)
@@ -23,7 +22,14 @@ const (
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{}
var prevTypeNum *uint8
for i := range ebe.ExecutionRequests {
@@ -37,19 +43,19 @@ func (ebe *ExecutionBundleElectra) GetDecodedExecutionRequests() (*ExecutionRequ
prevTypeNum = &requestType
switch requestType {
case DepositRequestType:
drs, err := unmarshalDeposits(requestListInSSZBytes)
drs, err := unmarshalDeposits(requestListInSSZBytes, limits.Deposits)
if err != nil {
return nil, err
}
requests.Deposits = drs
case WithdrawalRequestType:
wrs, err := unmarshalWithdrawals(requestListInSSZBytes)
wrs, err := unmarshalWithdrawals(requestListInSSZBytes, limits.Withdrawals)
if err != nil {
return nil, err
}
requests.Withdrawals = wrs
case ConsolidationRequestType:
crs, err := unmarshalConsolidations(requestListInSSZBytes)
crs, err := unmarshalConsolidations(requestListInSSZBytes, limits.Consolidations)
if err != nil {
return nil, err
}
@@ -61,33 +67,33 @@ func (ebe *ExecutionBundleElectra) GetDecodedExecutionRequests() (*ExecutionRequ
return requests, nil
}
func unmarshalDeposits(requestListInSSZBytes []byte) ([]*DepositRequest, error) {
func unmarshalDeposits(requestListInSSZBytes []byte, maxDepositRequests uint64) ([]*DepositRequest, error) {
if 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 {
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{} })
}
func unmarshalWithdrawals(requestListInSSZBytes []byte) ([]*WithdrawalRequest, error) {
func unmarshalWithdrawals(requestListInSSZBytes []byte, maxWithdrawals uint64) ([]*WithdrawalRequest, error) {
if 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 {
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{} })
}
func unmarshalConsolidations(requestListInSSZBytes []byte) ([]*ConsolidationRequest, error) {
func unmarshalConsolidations(requestListInSSZBytes []byte, maxConsolidations uint64) ([]*ConsolidationRequest, error) {
if 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 {
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"
func TestGetDecodedExecutionRequests(t *testing.T) {
cfg := params.BeaconConfig()
t.Run("All requests decode successfully", func(t *testing.T) {
depositRequestBytes, err := hexutil.Decode("0x610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
"620000000000000000000000000000000000000000000000000000000000000000" +
@@ -31,7 +32,7 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
append([]byte{uint8(enginev1.WithdrawalRequestType)}, withdrawalRequestBytes...),
append([]byte{uint8(enginev1.ConsolidationRequestType)}, consolidationRequestBytes...)},
}
requests, err := ebe.GetDecodedExecutionRequests()
requests, err := ebe.GetDecodedExecutionRequests(cfg.ExecutionRequestLimits())
require.NoError(t, err)
require.Equal(t, len(requests.Deposits), 1)
require.Equal(t, len(requests.Withdrawals), 1)
@@ -50,7 +51,7 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
ebe := &enginev1.ExecutionBundleElectra{
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.Equal(t, len(requests.Deposits), 1)
require.Equal(t, len(requests.Withdrawals), 0)
@@ -69,7 +70,7 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
ebe := &enginev1.ExecutionBundleElectra{
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)
})
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{
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)
})
t.Run("a duplicate request should fail", func(t *testing.T) {
@@ -93,7 +94,7 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
ebe := &enginev1.ExecutionBundleElectra{
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)
})
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{
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)
})
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{
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)
})
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 {
requests[i] = &enginev1.DepositRequest{
Pubkey: bytesutil.PadTo([]byte("pk"), 48),
@@ -142,11 +143,11 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
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)
})
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 {
requests[i] = &enginev1.WithdrawalRequest{
SourceAddress: bytesutil.PadTo([]byte("sa"), 20),
@@ -161,11 +162,11 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
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)
})
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 {
requests[i] = &enginev1.ConsolidationRequest{
SourceAddress: bytesutil.PadTo([]byte("sa"), 20),
@@ -180,7 +181,7 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
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)
})
}

View File

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

View File

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

View File

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

View File

@@ -1,4 +1,4 @@
package attestations
package attestations_test
import (
"io"
@@ -10,6 +10,7 @@ import (
"github.com/OffchainLabs/prysm/v6/encoding/ssz/equality"
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/attestations"
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/require"
@@ -46,7 +47,7 @@ func TestAggregateAttestations_AggregatePair(t *testing.T) {
},
}
for _, tt := range tests {
got, err := AggregatePair(tt.a1, tt.a2)
got, err := attestations.AggregatePair(tt.a1, tt.a2)
require.NoError(t, err)
require.Equal(t, true, equality.DeepEqual(got, tt.want))
}
@@ -67,7 +68,7 @@ func TestAggregateAttestations_AggregatePair_OverlapFails(t *testing.T) {
},
}
for _, tt := range tests {
_, err := AggregatePair(tt.a1, tt.a2)
_, err := attestations.AggregatePair(tt.a1, tt.a2)
require.ErrorContains(t, aggregation.ErrBitsOverlap.Error(), err)
}
}
@@ -83,7 +84,7 @@ func TestAggregateAttestations_AggregatePair_DiffLengthFails(t *testing.T) {
},
}
for _, tt := range tests {
_, err := AggregatePair(tt.a1, tt.a2)
_, err := attestations.AggregatePair(tt.a1, tt.a2)
require.ErrorContains(t, bitfield.ErrBitlistDifferentLength.Error(), err)
}
}
@@ -209,7 +210,7 @@ func TestAggregateAttestations_Aggregate(t *testing.T) {
for _, tt := range tests {
runner := func() {
got, err := Aggregate(aggtesting.MakeAttestationsFromBitlists(tt.inputs))
got, err := attestations.Aggregate(aggtesting.MakeAttestationsFromBitlists(tt.inputs))
if tt.err != nil {
require.ErrorContains(t, tt.err.Error(), err)
return
@@ -233,7 +234,7 @@ func TestAggregateAttestations_Aggregate(t *testing.T) {
t.Run("broken attestation bitset", func(t *testing.T) {
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},
{0b00000111, 0b100},
{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,
// 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).
got, err := Aggregate(aggtesting.MakeAttestationsFromBitlists([]bitfield.Bitlist{
got, err := attestations.Aggregate(aggtesting.MakeAttestationsFromBitlists([]bitfield.Bitlist{
{0b10000000, 0b1},
{0b11000101, 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 (
"testing"
@@ -6,6 +6,7 @@ import (
"github.com/OffchainLabs/prysm/v6/crypto/bls"
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/attestations"
"github.com/OffchainLabs/prysm/v6/testing/assert"
"github.com/prysmaticlabs/go-bitfield"
)
@@ -70,7 +71,7 @@ func TestAggregateAttestations_MaxCover_NewMaxCover(t *testing.T) {
}
for _, tt := range tests {
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) {
tests := []struct {
name string
atts attList
atts attestations.AttList
wantedErr string
}{
{
@@ -88,17 +89,17 @@ func TestAggregateAttestations_MaxCover_AttList_validate(t *testing.T) {
},
{
name: "empty list",
atts: attList{},
atts: attestations.AttList{},
wantedErr: "empty list",
},
{
name: "first bitlist is nil",
atts: attList{&ethpb.Attestation{}},
atts: attestations.AttList{&ethpb.Attestation{}},
wantedErr: "bitlist cannot be nil or empty",
},
{
name: "non first bitlist is nil",
atts: attList{
atts: attestations.AttList{
&ethpb.Attestation{AggregationBits: bitfield.NewBitlist(64)},
&ethpb.Attestation{},
},
@@ -106,14 +107,14 @@ func TestAggregateAttestations_MaxCover_AttList_validate(t *testing.T) {
},
{
name: "first bitlist is empty",
atts: attList{
atts: attestations.AttList{
&ethpb.Attestation{AggregationBits: bitfield.Bitlist{}},
},
wantedErr: "bitlist cannot be nil or empty",
},
{
name: "non first bitlist is empty",
atts: attList{
atts: attestations.AttList{
&ethpb.Attestation{AggregationBits: bitfield.NewBitlist(64)},
&ethpb.Attestation{AggregationBits: bitfield.Bitlist{}},
},
@@ -121,7 +122,7 @@ func TestAggregateAttestations_MaxCover_AttList_validate(t *testing.T) {
},
{
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)},
@@ -131,7 +132,7 @@ func TestAggregateAttestations_MaxCover_AttList_validate(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.atts.validate()
err := tt.atts.ValidateForTesting()
if tt.wantedErr != "" {
assert.ErrorContains(t, tt.wantedErr, err)
} 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)
})
}
@@ -312,7 +313,7 @@ func TestAggregateAttestations_aggregateAttestations(t *testing.T) {
{
name: "nil attestation",
wantTargetIdx: 0,
wantErr: ErrInvalidAttestationCount.Error(),
wantErr: attestations.ErrInvalidAttestationCount.Error(),
keys: []int{0, 1, 2},
},
{
@@ -321,13 +322,13 @@ func TestAggregateAttestations_aggregateAttestations(t *testing.T) {
&ethpb.Attestation{},
},
wantTargetIdx: 0,
wantErr: ErrInvalidAttestationCount.Error(),
wantErr: attestations.ErrInvalidAttestationCount.Error(),
keys: []int{0, 1, 2},
},
{
name: "no keys",
wantTargetIdx: 0,
wantErr: ErrInvalidAttestationCount.Error(),
wantErr: attestations.ErrInvalidAttestationCount.Error(),
},
{
name: "two attestations, none selected",
@@ -336,7 +337,7 @@ func TestAggregateAttestations_aggregateAttestations(t *testing.T) {
&ethpb.Attestation{AggregationBits: bitfield.Bitlist{0x01}},
},
wantTargetIdx: 0,
wantErr: ErrInvalidAttestationCount.Error(),
wantErr: attestations.ErrInvalidAttestationCount.Error(),
keys: []int{},
},
{
@@ -346,7 +347,7 @@ func TestAggregateAttestations_aggregateAttestations(t *testing.T) {
&ethpb.Attestation{AggregationBits: bitfield.Bitlist{0x01}},
},
wantTargetIdx: 0,
wantErr: ErrInvalidAttestationCount.Error(),
wantErr: attestations.ErrInvalidAttestationCount.Error(),
keys: []int{0},
},
{
@@ -414,7 +415,7 @@ func TestAggregateAttestations_aggregateAttestations(t *testing.T) {
}
for _, tt := range tests {
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 != "" {
assert.ErrorContains(t, tt.wantErr, err)
return

View File

@@ -1,10 +1,11 @@
package aggregation
package aggregation_test
import (
"fmt"
"testing"
"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"
"github.com/prysmaticlabs/go-bitfield"
)
@@ -66,7 +67,7 @@ func BenchmarkMaxCoverProblem_MaxCover(b *testing.B) {
},
}
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.StopTimer()
var bitlists []bitfield.Bitlist
@@ -78,11 +79,11 @@ func BenchmarkMaxCoverProblem_MaxCover(b *testing.B) {
}
b.StartTimer()
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++ {
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
}
@@ -98,7 +99,7 @@ func BenchmarkMaxCoverProblem_MaxCover(b *testing.B) {
}
b.StartTimer()
for i := 0; i < b.N; i++ {
_, _, err := MaxCover(bitlists, len(bitlists), tt.allowOverlaps)
_, _, err := aggregation.MaxCover(bitlists, len(bitlists), tt.allowOverlaps)
_ = err
}
})

View File

@@ -11,7 +11,6 @@ import (
"sort"
"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/crypto/bls"
"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“
// 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:
//
// 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)
// signing_root = compute_signing_root(indexed_attestation.data, domain)
// 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")
defer span.End()
@@ -202,12 +205,12 @@ func IsValidAttestationIndices(ctx context.Context, indexedAttestation ethpb.Ind
return errors.New("expected non-empty attesting indices")
}
if indexedAttestation.Version() < version.Electra {
maxLength := params.BeaconConfig().MaxValidatorsPerCommittee
maxLength := committeeValMax
if uint64(len(indices)) > maxLength {
return fmt.Errorf("validator indices count exceeds MAX_VALIDATORS_PER_COMMITTEE, %d > %d", len(indices), maxLength)
}
} else {
maxLength := params.BeaconConfig().MaxValidatorsPerCommittee * params.BeaconConfig().MaxCommitteesPerSlot
maxLength := committeeValMax * maxCommittees
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)
}

View File

@@ -204,7 +204,7 @@ func TestIsValidAttestationIndices(t *testing.T) {
}
for _, tt := range tests {
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 != "" {
assert.ErrorContains(t, tt.wantedErr, err)
} else {
@@ -240,7 +240,7 @@ func BenchmarkIsValidAttestationIndices(b *testing.B) {
}
b.ResetTimer()
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)
}
}