Fix Operations Length Check For Attestations (#15134)

* fix check for electra

* changelog
This commit is contained in:
Nishant Das
2025-04-07 06:35:12 +08:00
committed by GitHub
parent fa5d2a88ce
commit a6052efefb
3 changed files with 27 additions and 2 deletions

View File

@@ -415,11 +415,15 @@ func VerifyOperationLengths(_ context.Context, state state.BeaconState, b interf
)
}
if uint64(len(body.Attestations())) > params.BeaconConfig().MaxAttestations {
maxAttestations := params.BeaconConfig().MaxAttestations
if body.Version() >= version.Electra {
maxAttestations = params.BeaconConfig().MaxAttestationsElectra
}
if uint64(len(body.Attestations())) > maxAttestations {
return nil, fmt.Errorf(
"number of attestations (%d) in block body exceeds allowed threshold of %d",
len(body.Attestations()),
params.BeaconConfig().MaxAttestations,
maxAttestations,
)
}

View File

@@ -474,6 +474,24 @@ func TestProcessBlock_OverMaxAttestations(t *testing.T) {
assert.ErrorContains(t, want, err)
}
func TestProcessBlock_OverMaxAttestationsElectra(t *testing.T) {
b := &ethpb.SignedBeaconBlockElectra{
Block: &ethpb.BeaconBlockElectra{
Body: &ethpb.BeaconBlockBodyElectra{
Attestations: make([]*ethpb.AttestationElectra, params.BeaconConfig().MaxAttestationsElectra+1),
},
},
}
want := fmt.Sprintf("number of attestations (%d) in block body exceeds allowed threshold of %d",
len(b.Block.Body.Attestations), params.BeaconConfig().MaxAttestationsElectra)
s, err := state_native.InitializeFromProtoUnsafeElectra(&ethpb.BeaconStateElectra{})
require.NoError(t, err)
wsb, err := consensusblocks.NewSignedBeaconBlock(b)
require.NoError(t, err)
_, err = transition.VerifyOperationLengths(context.Background(), s, wsb.Block())
assert.ErrorContains(t, want, err)
}
func TestProcessBlock_OverMaxVoluntaryExits(t *testing.T) {
maxExits := params.BeaconConfig().MaxVoluntaryExits
b := &ethpb.SignedBeaconBlock{

View File

@@ -0,0 +1,3 @@
### Fixed
- Fixed a bug in checking for attestation lengths in our block.