From 4bf935928bd172206e50f50c9250b5434e2d97bc Mon Sep 17 00:00:00 2001 From: terence tsao Date: Tue, 14 Dec 2021 10:42:05 -0800 Subject: [PATCH] Use field params root length (#10012) * Use config length 32 * Add root length to minimal * Fix build * Gaz --- beacon-chain/blockchain/BUILD.bazel | 1 + .../blockchain/process_attestation_test.go | 29 ++++++++------- .../weak_subjectivity_checks_test.go | 3 +- beacon-chain/core/altair/BUILD.bazel | 1 + beacon-chain/core/altair/attestation_test.go | 17 +++++---- beacon-chain/core/epoch/BUILD.bazel | 1 + .../core/epoch/epoch_processing_test.go | 21 ++++++----- .../core/epoch/precompute/BUILD.bazel | 1 + .../justification_finalization_test.go | 7 ++-- .../epoch/precompute/reward_penalty_test.go | 15 ++++---- beacon-chain/core/helpers/BUILD.bazel | 1 + beacon-chain/core/helpers/validators_test.go | 3 +- beacon-chain/core/transition/BUILD.bazel | 1 + .../core/transition/transition_test.go | 7 ++-- beacon-chain/db/kv/BUILD.bazel | 1 + .../db/kv/finalized_block_roots_test.go | 5 ++- beacon-chain/p2p/BUILD.bazel | 1 + beacon-chain/p2p/fork_test.go | 3 +- .../rpc/prysm/v1alpha1/beacon/BUILD.bazel | 1 + .../v1alpha1/beacon/attestations_test.go | 15 ++++---- .../rpc/prysm/v1alpha1/beacon/blocks_test.go | 31 ++++++++-------- .../prysm/v1alpha1/beacon/committees_test.go | 3 +- .../prysm/v1alpha1/beacon/validators_test.go | 3 +- .../rpc/prysm/v1alpha1/validator/BUILD.bazel | 1 + .../v1alpha1/validator/aggregator_test.go | 13 ++++--- .../v1alpha1/validator/assignments_test.go | 13 ++++--- .../prysm/v1alpha1/validator/status_test.go | 19 +++++----- beacon-chain/state/v1/BUILD.bazel | 1 + beacon-chain/state/v1/state_test.go | 13 ++++--- beacon-chain/state/v2/BUILD.bazel | 1 + beacon-chain/state/v2/getters_block_test.go | 3 +- beacon-chain/state/v2/getters_misc.go | 3 +- beacon-chain/state/v2/setters_test.go | 15 ++++---- beacon-chain/sync/BUILD.bazel | 1 + .../sync/rpc_beacon_blocks_by_range_test.go | 5 ++- .../sync/validate_beacon_attestation_test.go | 37 ++++++++++--------- config/fieldparams/mainnet.go | 1 + config/fieldparams/minimal.go | 1 + proto/migration/BUILD.bazel | 1 + proto/migration/v1alpha1_to_v1_test.go | 15 ++++---- testing/util/BUILD.bazel | 2 + testing/util/altair.go | 9 +++-- testing/util/attestation.go | 23 ++++++------ testing/util/attestation_test.go | 13 ++++--- testing/util/block.go | 25 +++++++------ testing/util/helpers_test.go | 3 +- testing/util/state.go | 11 +++--- testing/util/sync_committee.go | 3 +- validator/client/BUILD.bazel | 2 + validator/client/attest_test.go | 9 +++-- validator/client/sync_committee_test.go | 7 ++-- validator/client/validator.go | 3 +- validator/db/kv/BUILD.bazel | 1 + .../db/kv/deprecated_attester_protection.go | 3 +- validator/db/kv/proposer_protection.go | 3 +- 55 files changed, 244 insertions(+), 187 deletions(-) diff --git a/beacon-chain/blockchain/BUILD.bazel b/beacon-chain/blockchain/BUILD.bazel index 6f8d7e9b4a..fb712604a2 100644 --- a/beacon-chain/blockchain/BUILD.bazel +++ b/beacon-chain/blockchain/BUILD.bazel @@ -119,6 +119,7 @@ go_test( "//beacon-chain/powchain:go_default_library", "//beacon-chain/state/stateutil:go_default_library", "//beacon-chain/state/v1:go_default_library", + "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//encoding/bytesutil:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/beacon-chain/blockchain/process_attestation_test.go b/beacon-chain/blockchain/process_attestation_test.go index 216f3188a2..2279e54586 100644 --- a/beacon-chain/blockchain/process_attestation_test.go +++ b/beacon-chain/blockchain/process_attestation_test.go @@ -9,6 +9,7 @@ import ( testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -103,9 +104,9 @@ func TestStore_OnAttestation_ErrorConditions(t *testing.T) { name: "process nil field (a.Target) in attestation", a: ðpb.Attestation{ Data: ðpb.AttestationData{ - BeaconBlockRoot: make([]byte, 32), + BeaconBlockRoot: make([]byte, fieldparams.RootLength), Target: nil, - Source: ðpb.Checkpoint{Root: make([]byte, 32)}, + Source: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, }, AggregationBits: make([]byte, 1), Signature: make([]byte, 96), @@ -165,11 +166,11 @@ func TestStore_SaveCheckpointState(t *testing.T) { s, err := util.NewBeaconState() require.NoError(t, err) - err = s.SetFinalizedCheckpoint(ðpb.Checkpoint{Root: bytesutil.PadTo([]byte{'A'}, 32)}) + err = s.SetFinalizedCheckpoint(ðpb.Checkpoint{Root: bytesutil.PadTo([]byte{'A'}, fieldparams.RootLength)}) require.NoError(t, err) val := ðpb.Validator{ PublicKey: bytesutil.PadTo([]byte("foo"), 48), - WithdrawalCredentials: bytesutil.PadTo([]byte("bar"), 32), + WithdrawalCredentials: bytesutil.PadTo([]byte("bar"), fieldparams.RootLength), } err = s.SetValidators([]*ethpb.Validator{val}) require.NoError(t, err) @@ -184,17 +185,17 @@ func TestStore_SaveCheckpointState(t *testing.T) { service.prevFinalizedCheckpt = ðpb.Checkpoint{Root: r[:]} r = bytesutil.ToBytes32([]byte{'A'}) - cp1 := ðpb.Checkpoint{Epoch: 1, Root: bytesutil.PadTo([]byte{'A'}, 32)} + cp1 := ðpb.Checkpoint{Epoch: 1, Root: bytesutil.PadTo([]byte{'A'}, fieldparams.RootLength)} require.NoError(t, service.cfg.BeaconDB.SaveState(ctx, s, bytesutil.ToBytes32([]byte{'A'}))) - require.NoError(t, service.cfg.BeaconDB.SaveStateSummary(ctx, ðpb.StateSummary{Root: bytesutil.PadTo([]byte{'A'}, 32)})) + require.NoError(t, service.cfg.BeaconDB.SaveStateSummary(ctx, ðpb.StateSummary{Root: bytesutil.PadTo([]byte{'A'}, fieldparams.RootLength)})) s1, err := service.getAttPreState(ctx, cp1) require.NoError(t, err) assert.Equal(t, 1*params.BeaconConfig().SlotsPerEpoch, s1.Slot(), "Unexpected state slot") - cp2 := ðpb.Checkpoint{Epoch: 2, Root: bytesutil.PadTo([]byte{'B'}, 32)} + cp2 := ðpb.Checkpoint{Epoch: 2, Root: bytesutil.PadTo([]byte{'B'}, fieldparams.RootLength)} require.NoError(t, service.cfg.BeaconDB.SaveState(ctx, s, bytesutil.ToBytes32([]byte{'B'}))) - require.NoError(t, service.cfg.BeaconDB.SaveStateSummary(ctx, ðpb.StateSummary{Root: bytesutil.PadTo([]byte{'B'}, 32)})) + require.NoError(t, service.cfg.BeaconDB.SaveStateSummary(ctx, ðpb.StateSummary{Root: bytesutil.PadTo([]byte{'B'}, fieldparams.RootLength)})) s2, err := service.getAttPreState(ctx, cp2) require.NoError(t, err) assert.Equal(t, 2*params.BeaconConfig().SlotsPerEpoch, s2.Slot(), "Unexpected state slot") @@ -216,9 +217,9 @@ func TestStore_SaveCheckpointState(t *testing.T) { service.bestJustifiedCheckpt = ðpb.Checkpoint{Root: r[:]} service.finalizedCheckpt = ðpb.Checkpoint{Root: r[:]} service.prevFinalizedCheckpt = ðpb.Checkpoint{Root: r[:]} - cp3 := ðpb.Checkpoint{Epoch: 1, Root: bytesutil.PadTo([]byte{'C'}, 32)} + cp3 := ðpb.Checkpoint{Epoch: 1, Root: bytesutil.PadTo([]byte{'C'}, fieldparams.RootLength)} require.NoError(t, service.cfg.BeaconDB.SaveState(ctx, s, bytesutil.ToBytes32([]byte{'C'}))) - require.NoError(t, service.cfg.BeaconDB.SaveStateSummary(ctx, ðpb.StateSummary{Root: bytesutil.PadTo([]byte{'C'}, 32)})) + require.NoError(t, service.cfg.BeaconDB.SaveStateSummary(ctx, ðpb.StateSummary{Root: bytesutil.PadTo([]byte{'C'}, fieldparams.RootLength)})) s3, err := service.getAttPreState(ctx, cp3) require.NoError(t, err) assert.Equal(t, s.Slot(), s3.Slot(), "Unexpected state slot") @@ -237,7 +238,7 @@ func TestStore_UpdateCheckpointState(t *testing.T) { epoch := types.Epoch(1) baseState, _ := util.DeterministicGenesisState(t, 1) - checkpoint := ðpb.Checkpoint{Epoch: epoch, Root: bytesutil.PadTo([]byte("hi"), 32)} + checkpoint := ðpb.Checkpoint{Epoch: epoch, Root: bytesutil.PadTo([]byte("hi"), fieldparams.RootLength)} require.NoError(t, service.cfg.BeaconDB.SaveState(ctx, baseState, bytesutil.ToBytes32(checkpoint.Root))) returned, err := service.getAttPreState(ctx, checkpoint) require.NoError(t, err) @@ -248,7 +249,7 @@ func TestStore_UpdateCheckpointState(t *testing.T) { assert.Equal(t, returned.Slot(), cached.Slot(), "State should have been cached") epoch = 2 - newCheckpoint := ðpb.Checkpoint{Epoch: epoch, Root: bytesutil.PadTo([]byte("bye"), 32)} + newCheckpoint := ðpb.Checkpoint{Epoch: epoch, Root: bytesutil.PadTo([]byte("bye"), fieldparams.RootLength)} require.NoError(t, service.cfg.BeaconDB.SaveState(ctx, baseState, bytesutil.ToBytes32(newCheckpoint.Root))) returned, err = service.getAttPreState(ctx, newCheckpoint) require.NoError(t, err) @@ -267,7 +268,7 @@ func TestAttEpoch_MatchPrevEpoch(t *testing.T) { ctx := context.Background() nowTime := uint64(params.BeaconConfig().SlotsPerEpoch) * params.BeaconConfig().SecondsPerSlot - require.NoError(t, verifyAttTargetEpoch(ctx, 0, nowTime, ðpb.Checkpoint{Root: make([]byte, 32)})) + require.NoError(t, verifyAttTargetEpoch(ctx, 0, nowTime, ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)})) } func TestAttEpoch_MatchCurrentEpoch(t *testing.T) { @@ -281,7 +282,7 @@ func TestAttEpoch_NotMatch(t *testing.T) { ctx := context.Background() nowTime := 2 * uint64(params.BeaconConfig().SlotsPerEpoch) * params.BeaconConfig().SecondsPerSlot - err := verifyAttTargetEpoch(ctx, 0, nowTime, ðpb.Checkpoint{Root: make([]byte, 32)}) + err := verifyAttTargetEpoch(ctx, 0, nowTime, ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}) assert.ErrorContains(t, "target epoch 0 does not match current epoch 2 or prev epoch 1", err) } diff --git a/beacon-chain/blockchain/weak_subjectivity_checks_test.go b/beacon-chain/blockchain/weak_subjectivity_checks_test.go index ae2752ba0c..718712614e 100644 --- a/beacon-chain/blockchain/weak_subjectivity_checks_test.go +++ b/beacon-chain/blockchain/weak_subjectivity_checks_test.go @@ -7,6 +7,7 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper" @@ -45,7 +46,7 @@ func TestService_VerifyWeakSubjectivityRoot(t *testing.T) { }, { name: "can't find the block in DB", - checkpt: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte{'a'}, 32), Epoch: 1}, + checkpt: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte{'a'}, fieldparams.RootLength), Epoch: 1}, finalizedEpoch: 3, wantErr: errWSBlockNotFound, }, diff --git a/beacon-chain/core/altair/BUILD.bazel b/beacon-chain/core/altair/BUILD.bazel index 3ea18eb758..0d1b3c96ed 100644 --- a/beacon-chain/core/altair/BUILD.bazel +++ b/beacon-chain/core/altair/BUILD.bazel @@ -72,6 +72,7 @@ go_test( "//beacon-chain/state:go_default_library", "//beacon-chain/state/v2:go_default_library", "//beacon-chain/state/v3:go_default_library", + "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//container/trie:go_default_library", "//crypto/bls:go_default_library", diff --git a/beacon-chain/core/altair/attestation_test.go b/beacon-chain/core/altair/attestation_test.go index c1146c49ad..676474975f 100644 --- a/beacon-chain/core/altair/attestation_test.go +++ b/beacon-chain/core/altair/attestation_test.go @@ -14,6 +14,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" stateAltair "github.com/prysmaticlabs/prysm/beacon-chain/state/v2" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/bls" "github.com/prysmaticlabs/prysm/math" @@ -28,7 +29,7 @@ func TestProcessAttestations_InclusionDelayFailure(t *testing.T) { attestations := []*ethpb.Attestation{ util.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ - Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)}, + Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, fieldparams.RootLength)}, Slot: 5, }, }), @@ -88,8 +89,8 @@ func TestProcessAttestations_CurrentEpochFFGDataMismatches(t *testing.T) { attestations := []*ethpb.Attestation{ { Data: ðpb.AttestationData{ - Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)}, - Source: ðpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)}, + Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, fieldparams.RootLength)}, + Source: ðpb.Checkpoint{Epoch: 1, Root: make([]byte, fieldparams.RootLength)}, }, AggregationBits: bitfield.Bitlist{0x09}, }, @@ -127,8 +128,8 @@ func TestProcessAttestations_PrevEpochFFGDataMismatches(t *testing.T) { attestations := []*ethpb.Attestation{ { Data: ðpb.AttestationData{ - Source: ðpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)}, - Target: ðpb.Checkpoint{Epoch: 1, Root: make([]byte, 32)}, + Source: ðpb.Checkpoint{Epoch: 1, Root: make([]byte, fieldparams.RootLength)}, + Target: ðpb.Checkpoint{Epoch: 1, Root: make([]byte, fieldparams.RootLength)}, Slot: params.BeaconConfig().SlotsPerEpoch, }, AggregationBits: aggBits, @@ -250,8 +251,8 @@ func TestProcessAttestationNoVerify_SourceTargetHead(t *testing.T) { att := ðpb.Attestation{ Data: ðpb.AttestationData{ BeaconBlockRoot: r, - Source: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)}, - Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)}, + Source: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, fieldparams.RootLength)}, + Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, fieldparams.RootLength)}, }, AggregationBits: aggBits, } @@ -259,7 +260,7 @@ func TestProcessAttestationNoVerify_SourceTargetHead(t *testing.T) { att.Signature = zeroSig[:] ckp := beaconState.CurrentJustifiedCheckpoint() - copy(ckp.Root, make([]byte, 32)) + copy(ckp.Root, make([]byte, fieldparams.RootLength)) require.NoError(t, beaconState.SetCurrentJustifiedCheckpoint(ckp)) b, err := helpers.TotalActiveBalance(beaconState) diff --git a/beacon-chain/core/epoch/BUILD.bazel b/beacon-chain/core/epoch/BUILD.bazel index 641fada515..fbc35f35e6 100644 --- a/beacon-chain/core/epoch/BUILD.bazel +++ b/beacon-chain/core/epoch/BUILD.bazel @@ -36,6 +36,7 @@ go_test( "//beacon-chain/core/time:go_default_library", "//beacon-chain/state:go_default_library", "//beacon-chain/state/v1:go_default_library", + "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//testing/assert:go_default_library", diff --git a/beacon-chain/core/epoch/epoch_processing_test.go b/beacon-chain/core/epoch/epoch_processing_test.go index 87df87c47e..5f19dcd26d 100644 --- a/beacon-chain/core/epoch/epoch_processing_test.go +++ b/beacon-chain/core/epoch/epoch_processing_test.go @@ -13,6 +13,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/testing/assert" @@ -26,8 +27,8 @@ func TestUnslashedAttestingIndices_CanSortAndFilter(t *testing.T) { atts := make([]*ethpb.PendingAttestation, 2) for i := 0; i < len(atts); i++ { atts[i] = ðpb.PendingAttestation{ - Data: ðpb.AttestationData{Source: ðpb.Checkpoint{Root: make([]byte, 32)}, - Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)}, + Data: ðpb.AttestationData{Source: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, + Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, fieldparams.RootLength)}, }, AggregationBits: bitfield.Bitlist{0x00, 0xFF, 0xFF, 0xFF}, } @@ -73,7 +74,7 @@ func TestUnslashedAttestingIndices_DuplicatedAttestations(t *testing.T) { atts := make([]*ethpb.PendingAttestation, 5) for i := 0; i < len(atts); i++ { atts[i] = ðpb.PendingAttestation{ - Data: ðpb.AttestationData{Source: ðpb.Checkpoint{Root: make([]byte, 32)}, + Data: ðpb.AttestationData{Source: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, Target: ðpb.Checkpoint{Epoch: 0}}, AggregationBits: bitfield.Bitlist{0x00, 0xFF, 0xFF, 0xFF}, } @@ -111,8 +112,8 @@ func TestAttestingBalance_CorrectBalance(t *testing.T) { for i := 0; i < len(atts); i++ { atts[i] = ðpb.PendingAttestation{ Data: ðpb.AttestationData{ - Target: ðpb.Checkpoint{Root: make([]byte, 32)}, - Source: ðpb.Checkpoint{Root: make([]byte, 32)}, + Target: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, + Source: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, Slot: types.Slot(i), }, AggregationBits: bitfield.Bitlist{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, @@ -290,7 +291,7 @@ func TestProcessRegistryUpdates_NoRotation(t *testing.T) { params.BeaconConfig().MaxEffectiveBalance, params.BeaconConfig().MaxEffectiveBalance, }, - FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, + FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, } beaconState, err := v1.InitializeFromProto(base) require.NoError(t, err) @@ -304,7 +305,7 @@ func TestProcessRegistryUpdates_NoRotation(t *testing.T) { func TestProcessRegistryUpdates_EligibleToActivate(t *testing.T) { base := ðpb.BeaconState{ Slot: 5 * params.BeaconConfig().SlotsPerEpoch, - FinalizedCheckpoint: ðpb.Checkpoint{Epoch: 6, Root: make([]byte, 32)}, + FinalizedCheckpoint: ðpb.Checkpoint{Epoch: 6, Root: make([]byte, fieldparams.RootLength)}, } limit, err := helpers.ValidatorChurnLimit(0) require.NoError(t, err) @@ -342,7 +343,7 @@ func TestProcessRegistryUpdates_ActivationCompletes(t *testing.T) { {ExitEpoch: params.BeaconConfig().MaxSeedLookahead, ActivationEpoch: 5 + params.BeaconConfig().MaxSeedLookahead + 1}, }, - FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, + FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, } beaconState, err := v1.InitializeFromProto(base) require.NoError(t, err) @@ -366,7 +367,7 @@ func TestProcessRegistryUpdates_ValidatorsEjected(t *testing.T) { EffectiveBalance: params.BeaconConfig().EjectionBalance - 1, }, }, - FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, + FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, } beaconState, err := v1.InitializeFromProto(base) require.NoError(t, err) @@ -391,7 +392,7 @@ func TestProcessRegistryUpdates_CanExits(t *testing.T) { ExitEpoch: exitEpoch, WithdrawableEpoch: exitEpoch + minWithdrawalDelay}, }, - FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, + FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, } beaconState, err := v1.InitializeFromProto(base) require.NoError(t, err) diff --git a/beacon-chain/core/epoch/precompute/BUILD.bazel b/beacon-chain/core/epoch/precompute/BUILD.bazel index 089becdcf2..a857eb7686 100644 --- a/beacon-chain/core/epoch/precompute/BUILD.bazel +++ b/beacon-chain/core/epoch/precompute/BUILD.bazel @@ -48,6 +48,7 @@ go_test( "//beacon-chain/core/time:go_default_library", "//beacon-chain/state:go_default_library", "//beacon-chain/state/v1:go_default_library", + "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//math:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/beacon-chain/core/epoch/precompute/justification_finalization_test.go b/beacon-chain/core/epoch/precompute/justification_finalization_test.go index 308110e53e..c877d92d70 100644 --- a/beacon-chain/core/epoch/precompute/justification_finalization_test.go +++ b/beacon-chain/core/epoch/precompute/justification_finalization_test.go @@ -7,6 +7,7 @@ import ( "github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/testing/assert" @@ -30,7 +31,7 @@ func TestProcessJustificationAndFinalizationPreCompute_ConsecutiveEpochs(t *test Epoch: 0, Root: params.BeaconConfig().ZeroHash[:], }, - FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, + FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, JustificationBits: bitfield.Bitvector4{0x0F}, // 0b1111 Validators: []*ethpb.Validator{{ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}}, Balances: []uint64{a, a, a, a}, // validator total balance should be 128000000000 @@ -67,7 +68,7 @@ func TestProcessJustificationAndFinalizationPreCompute_JustifyCurrentEpoch(t *te Epoch: 0, Root: params.BeaconConfig().ZeroHash[:], }, - FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, + FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, JustificationBits: bitfield.Bitvector4{0x03}, // 0b0011 Validators: []*ethpb.Validator{{ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}}, Balances: []uint64{a, a, a, a}, // validator total balance should be 128000000000 @@ -107,7 +108,7 @@ func TestProcessJustificationAndFinalizationPreCompute_JustifyPrevEpoch(t *testi JustificationBits: bitfield.Bitvector4{0x03}, // 0b0011 Validators: []*ethpb.Validator{{ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}, {ExitEpoch: e}}, Balances: []uint64{a, a, a, a}, // validator total balance should be 128000000000 - BlockRoots: blockRoots, FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, + BlockRoots: blockRoots, FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, } state, err := v1.InitializeFromProto(base) require.NoError(t, err) diff --git a/beacon-chain/core/epoch/precompute/reward_penalty_test.go b/beacon-chain/core/epoch/precompute/reward_penalty_test.go index 40808c299b..73f4a60a2b 100644 --- a/beacon-chain/core/epoch/precompute/reward_penalty_test.go +++ b/beacon-chain/core/epoch/precompute/reward_penalty_test.go @@ -12,6 +12,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/math" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -27,8 +28,8 @@ func TestProcessRewardsAndPenaltiesPrecompute(t *testing.T) { for i := 0; i < len(atts); i++ { atts[i] = ðpb.PendingAttestation{ Data: ðpb.AttestationData{ - Target: ðpb.Checkpoint{Root: make([]byte, 32)}, - Source: ðpb.Checkpoint{Root: make([]byte, 32)}, + Target: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, + Source: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, }, AggregationBits: bitfield.Bitlist{0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0x01}, InclusionDelay: 1, @@ -219,8 +220,8 @@ func TestProcessRewardsAndPenaltiesPrecompute_SlashedInactivePenalty(t *testing. for i := 0; i < len(atts); i++ { atts[i] = ðpb.PendingAttestation{ Data: ðpb.AttestationData{ - Target: ðpb.Checkpoint{Root: make([]byte, 32)}, - Source: ðpb.Checkpoint{Root: make([]byte, 32)}, + Target: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, + Source: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, }, AggregationBits: bitfield.Bitlist{0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0x01}, InclusionDelay: 1, @@ -292,9 +293,9 @@ func buildState(slot types.Slot, validatorCount uint64) *ethpb.BeaconState { RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), Slashings: make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector), BlockRoots: make([][]byte, params.BeaconConfig().SlotsPerEpoch*10), - FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, - PreviousJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, - CurrentJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, + FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, + PreviousJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, + CurrentJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, } } diff --git a/beacon-chain/core/helpers/BUILD.bazel b/beacon-chain/core/helpers/BUILD.bazel index 3b78eb29e2..017422430f 100644 --- a/beacon-chain/core/helpers/BUILD.bazel +++ b/beacon-chain/core/helpers/BUILD.bazel @@ -83,6 +83,7 @@ go_test( "//beacon-chain/state/v1:go_default_library", "//beacon-chain/state/v2:go_default_library", "//config/features:go_default_library", + "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//container/slice:go_default_library", "//crypto/bls:go_default_library", diff --git a/beacon-chain/core/helpers/validators_test.go b/beacon-chain/core/helpers/validators_test.go index 363c76e665..ee628d1d7d 100644 --- a/beacon-chain/core/helpers/validators_test.go +++ b/beacon-chain/core/helpers/validators_test.go @@ -9,6 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/cache" "github.com/prysmaticlabs/prysm/beacon-chain/core/time" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/hash" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -291,7 +292,7 @@ func TestBeaconProposerIndex_BadState(t *testing.T) { } roots := make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot) for i := uint64(0); i < uint64(params.BeaconConfig().SlotsPerHistoricalRoot); i++ { - roots[i] = make([]byte, 32) + roots[i] = make([]byte, fieldparams.RootLength) } state, err := v1.InitializeFromProto(ðpb.BeaconState{ diff --git a/beacon-chain/core/transition/BUILD.bazel b/beacon-chain/core/transition/BUILD.bazel index d399c5cef8..df2d00aa87 100644 --- a/beacon-chain/core/transition/BUILD.bazel +++ b/beacon-chain/core/transition/BUILD.bazel @@ -84,6 +84,7 @@ go_test( "//beacon-chain/p2p/types:go_default_library", "//beacon-chain/state:go_default_library", "//beacon-chain/state/v1:go_default_library", + "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//crypto/bls:go_default_library", "//crypto/hash:go_default_library", diff --git a/beacon-chain/core/transition/transition_test.go b/beacon-chain/core/transition/transition_test.go index 5bc790d2af..ce8a231e91 100644 --- a/beacon-chain/core/transition/transition_test.go +++ b/beacon-chain/core/transition/transition_test.go @@ -14,6 +14,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/state" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/bls" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -265,7 +266,7 @@ func createFullBlockWithOperations(t *testing.T) (state.BeaconState, att2 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ Source: ðpb.Checkpoint{Epoch: 0, Root: mockRoot3[:]}, - Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)}, + Target: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, fieldparams.RootLength)}, }, AttestingIndices: []uint64{0, 1}, }) @@ -370,9 +371,9 @@ func TestProcessEpochPrecompute_CanProcess(t *testing.T) { Slashings: slashing, RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), CurrentEpochAttestations: atts, - FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, + FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, JustificationBits: bitfield.Bitvector4{0x00}, - CurrentJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, + CurrentJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, } s, err := v1.InitializeFromProto(base) require.NoError(t, err) diff --git a/beacon-chain/db/kv/BUILD.bazel b/beacon-chain/db/kv/BUILD.bazel index c5b9bc55a0..13853a7a0a 100644 --- a/beacon-chain/db/kv/BUILD.bazel +++ b/beacon-chain/db/kv/BUILD.bazel @@ -105,6 +105,7 @@ go_test( "//beacon-chain/state/v1:go_default_library", "//beacon-chain/state/v2:go_default_library", "//config/features:go_default_library", + "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//encoding/bytesutil:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/beacon-chain/db/kv/finalized_block_roots_test.go b/beacon-chain/db/kv/finalized_block_roots_test.go index c6733ea95f..1b4d67b861 100644 --- a/beacon-chain/db/kv/finalized_block_roots_test.go +++ b/beacon-chain/db/kv/finalized_block_roots_test.go @@ -5,6 +5,7 @@ import ( "testing" types "github.com/prysmaticlabs/eth2-types" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -217,7 +218,7 @@ func makeBlocks(t *testing.T, i, n uint64, previousRoot [32]byte) []block.Signed blocks := make([]*ethpb.SignedBeaconBlock, n) ifaceBlocks := make([]block.SignedBeaconBlock, n) for j := i; j < n+i; j++ { - parentRoot := make([]byte, 32) + parentRoot := make([]byte, fieldparams.RootLength) copy(parentRoot, previousRoot[:]) blocks[j-i] = util.NewBeaconBlock() blocks[j-i].Block.Slot = types.Slot(j + 1) @@ -234,7 +235,7 @@ func makeBlocksAltair(t *testing.T, startIdx, num uint64, previousRoot [32]byte) blocks := make([]*ethpb.SignedBeaconBlockAltair, num) ifaceBlocks := make([]block.SignedBeaconBlock, num) for j := startIdx; j < num+startIdx; j++ { - parentRoot := make([]byte, 32) + parentRoot := make([]byte, fieldparams.RootLength) copy(parentRoot, previousRoot[:]) blocks[j-startIdx] = util.NewBeaconBlockAltair() blocks[j-startIdx].Block.Slot = types.Slot(j + 1) diff --git a/beacon-chain/p2p/BUILD.bazel b/beacon-chain/p2p/BUILD.bazel index 7fb61a965f..049bdab183 100644 --- a/beacon-chain/p2p/BUILD.bazel +++ b/beacon-chain/p2p/BUILD.bazel @@ -143,6 +143,7 @@ go_test( "//beacon-chain/p2p/testing:go_default_library", "//beacon-chain/p2p/types:go_default_library", "//cmd/beacon-chain/flags:go_default_library", + "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//crypto/hash:go_default_library", "//encoding/bytesutil:go_default_library", diff --git a/beacon-chain/p2p/fork_test.go b/beacon-chain/p2p/fork_test.go index b91b5effa3..b2dc6c88a0 100644 --- a/beacon-chain/p2p/fork_test.go +++ b/beacon-chain/p2p/fork_test.go @@ -16,6 +16,7 @@ import ( types "github.com/prysmaticlabs/eth2-types" mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/network/forks" @@ -30,7 +31,7 @@ func TestStartDiscv5_DifferentForkDigests(t *testing.T) { port := 2000 ipAddr, pkey := createAddrAndPrivKey(t) genesisTime := time.Now() - genesisValidatorsRoot := make([]byte, 32) + genesisValidatorsRoot := make([]byte, fieldparams.RootLength) s := &Service{ cfg: &Config{ UDPPort: uint(port), diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/BUILD.bazel b/beacon-chain/rpc/prysm/v1alpha1/beacon/BUILD.bazel index 6601b5a005..f601e1d831 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/BUILD.bazel +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/BUILD.bazel @@ -101,6 +101,7 @@ go_test( "//cmd:go_default_library", "//cmd/beacon-chain/flags:go_default_library", "//config/features:go_default_library", + "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//encoding/bytesutil:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go index 2429b76eaa..cf72de3555 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go @@ -21,6 +21,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" "github.com/prysmaticlabs/prysm/cmd" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -375,9 +376,9 @@ func TestServer_ListAttestations_Pagination_OutOfRange(t *testing.T) { Attestations: []*ethpb.Attestation{ { Data: ðpb.AttestationData{ - BeaconBlockRoot: bytesutil.PadTo([]byte("root"), 32), - Source: ðpb.Checkpoint{Root: make([]byte, 32)}, - Target: ðpb.Checkpoint{Root: make([]byte, 32)}, + BeaconBlockRoot: bytesutil.PadTo([]byte("root"), fieldparams.RootLength), + Source: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, + Target: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, Slot: i, }, AggregationBits: bitfield.Bitlist{0b11}, @@ -515,12 +516,12 @@ func TestServer_ListIndexedAttestations_GenesisEpoch(t *testing.T) { { Signature: make([]byte, params.BeaconConfig().BLSSignatureLength), Data: ðpb.AttestationData{ - BeaconBlockRoot: make([]byte, 32), + BeaconBlockRoot: make([]byte, fieldparams.RootLength), Target: ðpb.Checkpoint{ Root: targetRoot[:], }, Source: ðpb.Checkpoint{ - Root: make([]byte, 32), + Root: make([]byte, fieldparams.RootLength), }, Slot: i, CommitteeIndex: 0, @@ -624,7 +625,7 @@ func TestServer_ListIndexedAttestations_OldEpoch(t *testing.T) { CommitteeIndex: 0, Target: ðpb.Checkpoint{ Epoch: epoch, - Root: make([]byte, 32), + Root: make([]byte, fieldparams.RootLength), }, }, AggregationBits: bitfield.Bitlist{0b11}, @@ -643,7 +644,7 @@ func TestServer_ListIndexedAttestations_OldEpoch(t *testing.T) { randaoMixes := make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector) for i := 0; i < len(randaoMixes); i++ { - randaoMixes[i] = make([]byte, 32) + randaoMixes[i] = make([]byte, fieldparams.RootLength) } require.NoError(t, state.SetRandaoMixes(randaoMixes)) require.NoError(t, state.SetSlot(startSlot)) diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks_test.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks_test.go index 06364869bb..4322929a3a 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks_test.go @@ -17,6 +17,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" "github.com/prysmaticlabs/prysm/cmd" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -63,7 +64,7 @@ func TestServer_ListBlocks_NoResults(t *testing.T) { } res, err = bs.ListBlocks(ctx, ðpb.ListBlocksRequest{ QueryFilter: ðpb.ListBlocksRequest_Root{ - Root: make([]byte, 32), + Root: make([]byte, fieldparams.RootLength), }, }) require.NoError(t, err) @@ -373,12 +374,12 @@ func TestServer_GetChainHead_NoFinalizedBlock(t *testing.T) { s, err := util.NewBeaconState() require.NoError(t, err) require.NoError(t, s.SetSlot(1)) - require.NoError(t, s.SetPreviousJustifiedCheckpoint(ðpb.Checkpoint{Epoch: 3, Root: bytesutil.PadTo([]byte{'A'}, 32)})) - require.NoError(t, s.SetCurrentJustifiedCheckpoint(ðpb.Checkpoint{Epoch: 2, Root: bytesutil.PadTo([]byte{'B'}, 32)})) - require.NoError(t, s.SetFinalizedCheckpoint(ðpb.Checkpoint{Epoch: 1, Root: bytesutil.PadTo([]byte{'C'}, 32)})) + require.NoError(t, s.SetPreviousJustifiedCheckpoint(ðpb.Checkpoint{Epoch: 3, Root: bytesutil.PadTo([]byte{'A'}, fieldparams.RootLength)})) + require.NoError(t, s.SetCurrentJustifiedCheckpoint(ðpb.Checkpoint{Epoch: 2, Root: bytesutil.PadTo([]byte{'B'}, fieldparams.RootLength)})) + require.NoError(t, s.SetFinalizedCheckpoint(ðpb.Checkpoint{Epoch: 1, Root: bytesutil.PadTo([]byte{'C'}, fieldparams.RootLength)})) genBlock := util.NewBeaconBlock() - genBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'G'}, 32) + genBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'G'}, fieldparams.RootLength) require.NoError(t, db.SaveBlock(context.Background(), wrapper.WrappedPhase0SignedBeaconBlock(genBlock))) gRoot, err := genBlock.Block.HashTreeRoot() require.NoError(t, err) @@ -411,7 +412,7 @@ func TestServer_GetChainHead(t *testing.T) { db := dbTest.SetupDB(t) genBlock := util.NewBeaconBlock() - genBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'G'}, 32) + genBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'G'}, fieldparams.RootLength) require.NoError(t, db.SaveBlock(context.Background(), wrapper.WrappedPhase0SignedBeaconBlock(genBlock))) gRoot, err := genBlock.Block.HashTreeRoot() require.NoError(t, err) @@ -419,21 +420,21 @@ func TestServer_GetChainHead(t *testing.T) { finalizedBlock := util.NewBeaconBlock() finalizedBlock.Block.Slot = 1 - finalizedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'A'}, 32) + finalizedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'A'}, fieldparams.RootLength) require.NoError(t, db.SaveBlock(context.Background(), wrapper.WrappedPhase0SignedBeaconBlock(finalizedBlock))) fRoot, err := finalizedBlock.Block.HashTreeRoot() require.NoError(t, err) justifiedBlock := util.NewBeaconBlock() justifiedBlock.Block.Slot = 2 - justifiedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'B'}, 32) + justifiedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'B'}, fieldparams.RootLength) require.NoError(t, db.SaveBlock(context.Background(), wrapper.WrappedPhase0SignedBeaconBlock(justifiedBlock))) jRoot, err := justifiedBlock.Block.HashTreeRoot() require.NoError(t, err) prevJustifiedBlock := util.NewBeaconBlock() prevJustifiedBlock.Block.Slot = 3 - prevJustifiedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'C'}, 32) + prevJustifiedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'C'}, fieldparams.RootLength) require.NoError(t, db.SaveBlock(context.Background(), wrapper.WrappedPhase0SignedBeaconBlock(prevJustifiedBlock))) pjRoot, err := prevJustifiedBlock.Block.HashTreeRoot() require.NoError(t, err) @@ -502,7 +503,7 @@ func TestServer_StreamChainHead_OnHeadUpdated(t *testing.T) { params.OverrideBeaconConfig(params.MainnetConfig()) db := dbTest.SetupDB(t) genBlock := util.NewBeaconBlock() - genBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'G'}, 32) + genBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'G'}, fieldparams.RootLength) require.NoError(t, db.SaveBlock(context.Background(), wrapper.WrappedPhase0SignedBeaconBlock(genBlock))) gRoot, err := genBlock.Block.HashTreeRoot() require.NoError(t, err) @@ -510,21 +511,21 @@ func TestServer_StreamChainHead_OnHeadUpdated(t *testing.T) { finalizedBlock := util.NewBeaconBlock() finalizedBlock.Block.Slot = 32 - finalizedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'A'}, 32) + finalizedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'A'}, fieldparams.RootLength) require.NoError(t, db.SaveBlock(context.Background(), wrapper.WrappedPhase0SignedBeaconBlock(finalizedBlock))) fRoot, err := finalizedBlock.Block.HashTreeRoot() require.NoError(t, err) justifiedBlock := util.NewBeaconBlock() justifiedBlock.Block.Slot = 64 - justifiedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'B'}, 32) + justifiedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'B'}, fieldparams.RootLength) require.NoError(t, db.SaveBlock(context.Background(), wrapper.WrappedPhase0SignedBeaconBlock(justifiedBlock))) jRoot, err := justifiedBlock.Block.HashTreeRoot() require.NoError(t, err) prevJustifiedBlock := util.NewBeaconBlock() prevJustifiedBlock.Block.Slot = 96 - prevJustifiedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'C'}, 32) + prevJustifiedBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'C'}, fieldparams.RootLength) require.NoError(t, db.SaveBlock(context.Background(), wrapper.WrappedPhase0SignedBeaconBlock(prevJustifiedBlock))) pjRoot, err := prevJustifiedBlock.Block.HashTreeRoot() require.NoError(t, err) @@ -768,11 +769,11 @@ func TestServer_GetWeakSubjectivityCheckpoint(t *testing.T) { require.NoError(t, beaconState.SetSlot(types.Slot(finalizedEpoch.Mul(uint64(params.BeaconConfig().SlotsPerEpoch))))) require.NoError(t, beaconState.SetCurrentJustifiedCheckpoint(ðpb.Checkpoint{ Epoch: finalizedEpoch - 1, - Root: bytesutil.PadTo([]byte{'A'}, 32), + Root: bytesutil.PadTo([]byte{'A'}, fieldparams.RootLength), })) require.NoError(t, beaconState.SetFinalizedCheckpoint(ðpb.Checkpoint{ Epoch: finalizedEpoch, - Root: bytesutil.PadTo([]byte{'B'}, 32), + Root: bytesutil.PadTo([]byte{'B'}, fieldparams.RootLength), })) chainService := &chainMock.ChainService{State: beaconState} diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/committees_test.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/committees_test.go index 8991e4b581..578d32be8e 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/committees_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/committees_test.go @@ -11,6 +11,7 @@ import ( dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper" @@ -81,7 +82,7 @@ func TestServer_ListBeaconCommittees_PreviousEpoch(t *testing.T) { mixes := make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector) for i := 0; i < len(mixes); i++ { - mixes[i] = make([]byte, 32) + mixes[i] = make([]byte, fieldparams.RootLength) } require.NoError(t, headState.SetRandaoMixes(mixes)) require.NoError(t, headState.SetSlot(params.BeaconConfig().SlotsPerEpoch)) diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go index 34eb507b5d..9a4f027080 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go @@ -22,6 +22,7 @@ import ( v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing" "github.com/prysmaticlabs/prysm/cmd" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -1265,7 +1266,7 @@ func TestServer_GetValidatorActiveSetChanges(t *testing.T) { bs := &Server{ FinalizationFetcher: &mock.ChainService{ - FinalizedCheckPoint: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)}, + FinalizedCheckPoint: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, fieldparams.RootLength)}, }, GenesisTimeFetcher: &mock.ChainService{}, StateGen: stategen.New(beaconDB), diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/BUILD.bazel b/beacon-chain/rpc/prysm/v1alpha1/validator/BUILD.bazel index d875db3151..e07abbe97b 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/BUILD.bazel +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/BUILD.bazel @@ -127,6 +127,7 @@ go_test( "//beacon-chain/state/v1:go_default_library", "//beacon-chain/sync/initial-sync/testing:go_default_library", "//config/features:go_default_library", + "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//container/trie:go_default_library", "//crypto/bls:go_default_library", diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/aggregator_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/aggregator_test.go index 8269c37642..1d143aa8a7 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/aggregator_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/aggregator_test.go @@ -15,6 +15,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/bls" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -298,15 +299,15 @@ func TestSubmitAggregateAndProof_PreferOwnAttestation(t *testing.T) { beaconState, privKeys := util.DeterministicGenesisState(t, 32) att0, err := generateAtt(beaconState, 0, privKeys) require.NoError(t, err) - att0.Data.BeaconBlockRoot = bytesutil.PadTo([]byte("foo"), 32) + att0.Data.BeaconBlockRoot = bytesutil.PadTo([]byte("foo"), fieldparams.RootLength) att0.AggregationBits = bitfield.Bitlist{0b11100} att1, err := generateAtt(beaconState, 0, privKeys) require.NoError(t, err) - att1.Data.BeaconBlockRoot = bytesutil.PadTo([]byte("bar"), 32) + att1.Data.BeaconBlockRoot = bytesutil.PadTo([]byte("bar"), fieldparams.RootLength) att1.AggregationBits = bitfield.Bitlist{0b11001} att2, err := generateAtt(beaconState, 2, privKeys) require.NoError(t, err) - att2.Data.BeaconBlockRoot = bytesutil.PadTo([]byte("foo"), 32) + att2.Data.BeaconBlockRoot = bytesutil.PadTo([]byte("foo"), fieldparams.RootLength) att2.AggregationBits = bitfield.Bitlist{0b11110} err = beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay) @@ -349,14 +350,14 @@ func TestSubmitAggregateAndProof_SelectsMostBitsWhenOwnAttestationNotPresent(t * // This test creates two distinct attestations, neither of which contain the validator's index, // index 0. This test should choose the most bits attestation, att1. - beaconState, privKeys := util.DeterministicGenesisState(t, 32) + beaconState, privKeys := util.DeterministicGenesisState(t, fieldparams.RootLength) att0, err := generateAtt(beaconState, 0, privKeys) require.NoError(t, err) - att0.Data.BeaconBlockRoot = bytesutil.PadTo([]byte("foo"), 32) + att0.Data.BeaconBlockRoot = bytesutil.PadTo([]byte("foo"), fieldparams.RootLength) att0.AggregationBits = bitfield.Bitlist{0b11100} att1, err := generateAtt(beaconState, 2, privKeys) require.NoError(t, err) - att1.Data.BeaconBlockRoot = bytesutil.PadTo([]byte("bar"), 32) + att1.Data.BeaconBlockRoot = bytesutil.PadTo([]byte("bar"), fieldparams.RootLength) att1.AggregationBits = bitfield.Bitlist{0b11110} err = beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay) diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/assignments_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/assignments_test.go index 63e322f94b..44c9d7fc17 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/assignments_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/assignments_test.go @@ -18,6 +18,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" mockPOW "github.com/prysmaticlabs/prysm/beacon-chain/powchain/testing" mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpbv1 "github.com/prysmaticlabs/prysm/proto/eth/v1" @@ -111,9 +112,9 @@ func TestGetAltairDuties_SyncCommitteeOK(t *testing.T) { require.NoError(t, err) bs, err := util.GenesisBeaconState(context.Background(), deposits, 0, eth1Data) h := ðpb.BeaconBlockHeader{ - StateRoot: bytesutil.PadTo([]byte{'a'}, 32), - ParentRoot: bytesutil.PadTo([]byte{'b'}, 32), - BodyRoot: bytesutil.PadTo([]byte{'c'}, 32), + StateRoot: bytesutil.PadTo([]byte{'a'}, fieldparams.RootLength), + ParentRoot: bytesutil.PadTo([]byte{'b'}, fieldparams.RootLength), + BodyRoot: bytesutil.PadTo([]byte{'c'}, fieldparams.RootLength), } require.NoError(t, bs.SetLatestBlockHeader(h)) require.NoError(t, err, "Could not setup genesis bs") @@ -213,9 +214,9 @@ func TestGetAltairDuties_UnknownPubkey(t *testing.T) { bs, err := util.GenesisBeaconState(context.Background(), deposits, 0, eth1Data) require.NoError(t, err) h := ðpb.BeaconBlockHeader{ - StateRoot: bytesutil.PadTo([]byte{'a'}, 32), - ParentRoot: bytesutil.PadTo([]byte{'b'}, 32), - BodyRoot: bytesutil.PadTo([]byte{'c'}, 32), + StateRoot: bytesutil.PadTo([]byte{'a'}, fieldparams.RootLength), + ParentRoot: bytesutil.PadTo([]byte{'b'}, fieldparams.RootLength), + BodyRoot: bytesutil.PadTo([]byte{'c'}, fieldparams.RootLength), } require.NoError(t, bs.SetLatestBlockHeader(h)) require.NoError(t, err, "Could not setup genesis bs") diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/status_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/status_test.go index 02bd02da31..945934aa6e 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/status_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/status_test.go @@ -17,6 +17,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/container/trie" "github.com/prysmaticlabs/prysm/crypto/bls" @@ -1231,14 +1232,14 @@ func createStateSetup(t *testing.T, head types.Epoch, mockgen *stategen.MockStat Data: ðpb.AttestationData{ Slot: ctr.AttesterSlot, CommitteeIndex: ctr.CommitteeIndex, - BeaconBlockRoot: make([]byte, 32), + BeaconBlockRoot: make([]byte, fieldparams.RootLength), Source: ðpb.Checkpoint{ Epoch: 0, - Root: make([]byte, 32), + Root: make([]byte, fieldparams.RootLength), }, Target: ðpb.Checkpoint{ Epoch: 1, - Root: make([]byte, 32), + Root: make([]byte, fieldparams.RootLength), }, }, InclusionDelay: 1, @@ -1263,14 +1264,14 @@ func createStateSetup(t *testing.T, head types.Epoch, mockgen *stategen.MockStat Data: ðpb.AttestationData{ Slot: ctr.AttesterSlot, CommitteeIndex: ctr.CommitteeIndex, - BeaconBlockRoot: make([]byte, 32), + BeaconBlockRoot: make([]byte, fieldparams.RootLength), Source: ðpb.Checkpoint{ Epoch: 0, - Root: make([]byte, 32), + Root: make([]byte, fieldparams.RootLength), }, Target: ðpb.Checkpoint{ Epoch: 1, - Root: make([]byte, 32), + Root: make([]byte, fieldparams.RootLength), }, }, InclusionDelay: 1, @@ -1299,14 +1300,14 @@ func createStateSetup(t *testing.T, head types.Epoch, mockgen *stategen.MockStat Data: ðpb.AttestationData{ Slot: attSlot, CommitteeIndex: ctr.CommitteeIndex, - BeaconBlockRoot: make([]byte, 32), + BeaconBlockRoot: make([]byte, fieldparams.RootLength), Source: ðpb.Checkpoint{ Epoch: 0, - Root: make([]byte, 32), + Root: make([]byte, fieldparams.RootLength), }, Target: ðpb.Checkpoint{ Epoch: 1, - Root: make([]byte, 32), + Root: make([]byte, fieldparams.RootLength), }, }, InclusionDelay: 1, diff --git a/beacon-chain/state/v1/BUILD.bazel b/beacon-chain/state/v1/BUILD.bazel index a7e2f158dc..eeb49e774d 100644 --- a/beacon-chain/state/v1/BUILD.bazel +++ b/beacon-chain/state/v1/BUILD.bazel @@ -88,6 +88,7 @@ go_test( "//beacon-chain/state/stateutil:go_default_library", "//beacon-chain/state/types:go_default_library", "//config/features:go_default_library", + "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//encoding/bytesutil:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/beacon-chain/state/v1/state_test.go b/beacon-chain/state/v1/state_test.go index 4056aecf41..027f689e15 100644 --- a/beacon-chain/state/v1/state_test.go +++ b/beacon-chain/state/v1/state_test.go @@ -9,6 +9,7 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -152,9 +153,9 @@ func TestBeaconState_AppendBalanceWithTrie(t *testing.T) { Epoch: 0, }, LatestBlockHeader: ðpb.BeaconBlockHeader{ - ParentRoot: make([]byte, 32), - StateRoot: make([]byte, 32), - BodyRoot: make([]byte, 32), + ParentRoot: make([]byte, fieldparams.RootLength), + StateRoot: make([]byte, fieldparams.RootLength), + BodyRoot: make([]byte, fieldparams.RootLength), }, Validators: vals, Balances: bals, @@ -166,9 +167,9 @@ func TestBeaconState_AppendBalanceWithTrie(t *testing.T) { StateRoots: mockstateRoots, RandaoMixes: mockrandaoMixes, JustificationBits: bitfield.NewBitvector4(), - PreviousJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, - CurrentJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, - FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, + PreviousJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, + CurrentJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, + FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, Slashings: make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector), }) assert.NoError(t, err) diff --git a/beacon-chain/state/v2/BUILD.bazel b/beacon-chain/state/v2/BUILD.bazel index 04993c007a..ee88efd29a 100644 --- a/beacon-chain/state/v2/BUILD.bazel +++ b/beacon-chain/state/v2/BUILD.bazel @@ -76,6 +76,7 @@ go_test( "//beacon-chain/state/types:go_default_library", "//beacon-chain/state/v1:go_default_library", "//config/features:go_default_library", + "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//encoding/bytesutil:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/beacon-chain/state/v2/getters_block_test.go b/beacon-chain/state/v2/getters_block_test.go index c8912cd949..923bd9b5ec 100644 --- a/beacon-chain/state/v2/getters_block_test.go +++ b/beacon-chain/state/v2/getters_block_test.go @@ -3,6 +3,7 @@ package v2 import ( "testing" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/testing/require" @@ -54,6 +55,6 @@ func TestBeaconState_BlockRootAtIndex(t *testing.T) { require.NoError(t, err) got, err = s.BlockRootAtIndex(0) require.NoError(t, err) - want := bytesutil.PadTo([]byte{'a'}, 32) + want := bytesutil.PadTo([]byte{'a'}, fieldparams.RootLength) require.DeepSSZEqual(t, want, got) } diff --git a/beacon-chain/state/v2/getters_misc.go b/beacon-chain/state/v2/getters_misc.go index a8fa1d516d..20be2f386b 100644 --- a/beacon-chain/state/v2/getters_misc.go +++ b/beacon-chain/state/v2/getters_misc.go @@ -4,6 +4,7 @@ import ( "time" types "github.com/prysmaticlabs/eth2-types" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -57,7 +58,7 @@ func (b *BeaconState) genesisValidatorRoot() []byte { return params.BeaconConfig().ZeroHash[:] } - root := make([]byte, 32) + root := make([]byte, fieldparams.RootLength) copy(root, b.state.GenesisValidatorsRoot) return root } diff --git a/beacon-chain/state/v2/setters_test.go b/beacon-chain/state/v2/setters_test.go index 2935cdc01e..41a64451cc 100644 --- a/beacon-chain/state/v2/setters_test.go +++ b/beacon-chain/state/v2/setters_test.go @@ -9,6 +9,7 @@ import ( "github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil" stateTypes "github.com/prysmaticlabs/prysm/beacon-chain/state/types" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -110,25 +111,25 @@ func TestBeaconState_AppendBalanceWithTrie(t *testing.T) { Epoch: 0, }, LatestBlockHeader: ðpb.BeaconBlockHeader{ - ParentRoot: make([]byte, 32), - StateRoot: make([]byte, 32), - BodyRoot: make([]byte, 32), + ParentRoot: make([]byte, fieldparams.RootLength), + StateRoot: make([]byte, fieldparams.RootLength), + BodyRoot: make([]byte, fieldparams.RootLength), }, CurrentEpochParticipation: []byte{}, PreviousEpochParticipation: []byte{}, Validators: vals, Balances: bals, Eth1Data: ðpb.Eth1Data{ - DepositRoot: make([]byte, 32), + DepositRoot: make([]byte, fieldparams.RootLength), BlockHash: make([]byte, 32), }, BlockRoots: mockblockRoots, StateRoots: mockstateRoots, RandaoMixes: mockrandaoMixes, JustificationBits: bitfield.NewBitvector4(), - PreviousJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, - CurrentJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, - FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, + PreviousJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, + CurrentJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, + FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, Slashings: make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector), CurrentSyncCommittee: ðpb.SyncCommittee{ Pubkeys: pubKeys, diff --git a/beacon-chain/sync/BUILD.bazel b/beacon-chain/sync/BUILD.bazel index f0f6dc2639..88a9a0ff56 100644 --- a/beacon-chain/sync/BUILD.bazel +++ b/beacon-chain/sync/BUILD.bazel @@ -190,6 +190,7 @@ go_test( "//beacon-chain/sync/initial-sync/testing:go_default_library", "//cache/lru:go_default_library", "//cmd/beacon-chain/flags:go_default_library", + "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//crypto/bls:go_default_library", "//crypto/rand:go_default_library", diff --git a/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go b/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go index e81a0f0418..e6394a6b1b 100644 --- a/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go +++ b/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go @@ -19,6 +19,7 @@ import ( p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing" p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -622,7 +623,7 @@ func TestRPCBeaconBlocksByRange_FilterBlocks(t *testing.T) { blocks := make([]*ethpb.SignedBeaconBlock, req.Count) // Populate the database with blocks that would match the request. for i, j := req.StartSlot, 0; i < req.StartSlot.Add(req.Step*req.Count); i += types.Slot(req.Step) { - parentRoot := make([]byte, 32) + parentRoot := make([]byte, fieldparams.RootLength) copy(parentRoot, previousRoot[:]) blocks[j] = util.NewBeaconBlock() blocks[j].Block.Slot = i @@ -668,7 +669,7 @@ func TestRPCBeaconBlocksByRange_FilterBlocks(t *testing.T) { blocks := make([]*ethpb.SignedBeaconBlock, req.Count) // Populate the database with blocks with non linear roots. for i, j := req.StartSlot, 0; i < req.StartSlot.Add(req.Step*req.Count); i += types.Slot(req.Step) { - parentRoot := make([]byte, 32) + parentRoot := make([]byte, fieldparams.RootLength) copy(parentRoot, previousRoot[:]) blocks[j] = util.NewBeaconBlock() blocks[j].Block.Slot = i diff --git a/beacon-chain/sync/validate_beacon_attestation_test.go b/beacon-chain/sync/validate_beacon_attestation_test.go index e52654d566..83f5b03f91 100644 --- a/beacon-chain/sync/validate_beacon_attestation_test.go +++ b/beacon-chain/sync/validate_beacon_attestation_test.go @@ -17,6 +17,7 @@ import ( p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing" mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing" lruwrpr "github.com/prysmaticlabs/prysm/cache/lru" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -91,7 +92,7 @@ func TestService_validateCommitteeIndexBeaconAttestation(t *testing.T) { Epoch: 0, Root: validBlockRoot[:], }, - Source: ðpb.Checkpoint{Root: make([]byte, 32)}, + Source: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, }, }, topic: fmt.Sprintf("/eth2/%x/beacon_attestation_1", digest), @@ -110,7 +111,7 @@ func TestService_validateCommitteeIndexBeaconAttestation(t *testing.T) { Epoch: 0, Root: validBlockRoot[:], }, - Source: ðpb.Checkpoint{Root: make([]byte, 32)}, + Source: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, }, }, topic: "", @@ -129,7 +130,7 @@ func TestService_validateCommitteeIndexBeaconAttestation(t *testing.T) { Epoch: 10, Root: validBlockRoot[:], }, - Source: ðpb.Checkpoint{Root: make([]byte, 32)}, + Source: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, }, }, topic: fmt.Sprintf("/eth2/%x/beacon_attestation_1", digest), @@ -144,8 +145,8 @@ func TestService_validateCommitteeIndexBeaconAttestation(t *testing.T) { BeaconBlockRoot: validBlockRoot[:], CommitteeIndex: 0, Slot: 1, - Target: ðpb.Checkpoint{Root: make([]byte, 32)}, - Source: ðpb.Checkpoint{Root: make([]byte, 32)}, + Target: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, + Source: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, }, }, topic: fmt.Sprintf("/eth2/%x/beacon_attestation_1", digest), @@ -160,8 +161,8 @@ func TestService_validateCommitteeIndexBeaconAttestation(t *testing.T) { BeaconBlockRoot: invalidRoot[:], CommitteeIndex: 0, Slot: 1, - Target: ðpb.Checkpoint{Root: make([]byte, 32)}, - Source: ðpb.Checkpoint{Root: make([]byte, 32)}, + Target: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, + Source: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, }, }, topic: fmt.Sprintf("/eth2/%x/beacon_attestation_1", digest), @@ -176,8 +177,8 @@ func TestService_validateCommitteeIndexBeaconAttestation(t *testing.T) { BeaconBlockRoot: validBlockRoot[:], CommitteeIndex: 4, Slot: 1, - Target: ðpb.Checkpoint{Root: make([]byte, 32)}, - Source: ðpb.Checkpoint{Root: make([]byte, 32)}, + Target: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, + Source: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, }, }, topic: fmt.Sprintf("/eth2/%x/beacon_attestation_2", digest), @@ -192,8 +193,8 @@ func TestService_validateCommitteeIndexBeaconAttestation(t *testing.T) { BeaconBlockRoot: validBlockRoot[:], CommitteeIndex: 2, Slot: 1, - Target: ðpb.Checkpoint{Root: make([]byte, 32)}, - Source: ðpb.Checkpoint{Root: make([]byte, 32)}, + Target: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, + Source: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, }, }, topic: fmt.Sprintf("/eth2/%x/beacon_attestation_2", digest), @@ -208,8 +209,8 @@ func TestService_validateCommitteeIndexBeaconAttestation(t *testing.T) { BeaconBlockRoot: validBlockRoot[:], CommitteeIndex: 1, Slot: 1, - Target: ðpb.Checkpoint{Root: make([]byte, 32)}, - Source: ðpb.Checkpoint{Root: make([]byte, 32)}, + Target: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, + Source: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, }, }, topic: fmt.Sprintf("/eth2/%x/beacon_attestation_1", digest), @@ -221,11 +222,11 @@ func TestService_validateCommitteeIndexBeaconAttestation(t *testing.T) { msg: ðpb.Attestation{ AggregationBits: bitfield.Bitlist{0b101}, Data: ðpb.AttestationData{ - BeaconBlockRoot: bytesutil.PadTo([]byte("missing"), 32), + BeaconBlockRoot: bytesutil.PadTo([]byte("missing"), fieldparams.RootLength), CommitteeIndex: 1, Slot: 1, - Target: ðpb.Checkpoint{Root: make([]byte, 32)}, - Source: ðpb.Checkpoint{Root: make([]byte, 32)}, + Target: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, + Source: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, }, }, topic: fmt.Sprintf("/eth2/%x/beacon_attestation_1", digest), @@ -240,8 +241,8 @@ func TestService_validateCommitteeIndexBeaconAttestation(t *testing.T) { BeaconBlockRoot: validBlockRoot[:], CommitteeIndex: 1, Slot: 1, - Target: ðpb.Checkpoint{Root: make([]byte, 32)}, - Source: ðpb.Checkpoint{Root: make([]byte, 32)}, + Target: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, + Source: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, }, }, topic: fmt.Sprintf("/eth2/%x/beacon_attestation_1", digest), diff --git a/config/fieldparams/mainnet.go b/config/fieldparams/mainnet.go index cbc6175e03..05b6e2d3df 100644 --- a/config/fieldparams/mainnet.go +++ b/config/fieldparams/mainnet.go @@ -13,4 +13,5 @@ const ( CurrentEpochAttestationsLength = 4096 // MAX_ATTESTATIONS * SLOTS_PER_EPOCH SlashingsLength = 8192 // EPOCHS_PER_SLASHINGS_VECTOR SyncCommitteeLength = 512 // SYNC_COMMITTEE_SIZE + RootLength = 32 // RootLength defines the byte length of a Merkle root . ) diff --git a/config/fieldparams/minimal.go b/config/fieldparams/minimal.go index 7ee8d4c63c..f6e4231c37 100644 --- a/config/fieldparams/minimal.go +++ b/config/fieldparams/minimal.go @@ -13,4 +13,5 @@ const ( CurrentEpochAttestationsLength = 1024 // MAX_ATTESTATIONS * SLOTS_PER_EPOCH SlashingsLength = 64 // EPOCHS_PER_SLASHINGS_VECTOR SyncCommitteeLength = 32 // SYNC_COMMITTEE_SIZE + RootLength = 32 // RootLength defines the byte length of a Merkle root . ) diff --git a/proto/migration/BUILD.bazel b/proto/migration/BUILD.bazel index 4480c61535..6df484086a 100644 --- a/proto/migration/BUILD.bazel +++ b/proto/migration/BUILD.bazel @@ -31,6 +31,7 @@ go_test( ], embed = [":go_default_library"], deps = [ + "//config/fieldparams:go_default_library", "//encoding/bytesutil:go_default_library", "//proto/eth/v1:go_default_library", "//proto/eth/v2:go_default_library", diff --git a/proto/migration/v1alpha1_to_v1_test.go b/proto/migration/v1alpha1_to_v1_test.go index 0dfd641415..9e7c14163a 100644 --- a/proto/migration/v1alpha1_to_v1_test.go +++ b/proto/migration/v1alpha1_to_v1_test.go @@ -5,6 +5,7 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/go-bitfield" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpbv1 "github.com/prysmaticlabs/prysm/proto/eth/v1" ethpbalpha "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -21,16 +22,16 @@ var ( committeeIndex = types.CommitteeIndex(1) depositCount = uint64(2) attestingIndices = []uint64{1, 2} - parentRoot = bytesutil.PadTo([]byte("parentroot"), 32) - stateRoot = bytesutil.PadTo([]byte("stateroot"), 32) + parentRoot = bytesutil.PadTo([]byte("parentroot"), fieldparams.RootLength) + stateRoot = bytesutil.PadTo([]byte("stateroot"), fieldparams.RootLength) signature = bytesutil.PadTo([]byte("signature"), 96) randaoReveal = bytesutil.PadTo([]byte("randaoreveal"), 96) - depositRoot = bytesutil.PadTo([]byte("depositroot"), 32) + depositRoot = bytesutil.PadTo([]byte("depositroot"), fieldparams.RootLength) blockHash = bytesutil.PadTo([]byte("blockhash"), 32) - beaconBlockRoot = bytesutil.PadTo([]byte("beaconblockroot"), 32) - sourceRoot = bytesutil.PadTo([]byte("sourceroot"), 32) - targetRoot = bytesutil.PadTo([]byte("targetroot"), 32) - bodyRoot = bytesutil.PadTo([]byte("bodyroot"), 32) + beaconBlockRoot = bytesutil.PadTo([]byte("beaconblockroot"), fieldparams.RootLength) + sourceRoot = bytesutil.PadTo([]byte("sourceroot"), fieldparams.RootLength) + targetRoot = bytesutil.PadTo([]byte("targetroot"), fieldparams.RootLength) + bodyRoot = bytesutil.PadTo([]byte("bodyroot"), fieldparams.RootLength) selectionProof = bytesutil.PadTo([]byte("selectionproof"), 96) aggregationBits = bitfield.Bitlist{0x01} ) diff --git a/testing/util/BUILD.bazel b/testing/util/BUILD.bazel index ff74981f39..bb164cd835 100644 --- a/testing/util/BUILD.bazel +++ b/testing/util/BUILD.bazel @@ -32,6 +32,7 @@ go_library( "//beacon-chain/state/v1:go_default_library", "//beacon-chain/state/v2:go_default_library", "//beacon-chain/state/v3:go_default_library", + "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//container/trie:go_default_library", "//crypto/bls:go_default_library", @@ -71,6 +72,7 @@ go_test( "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/transition:go_default_library", "//beacon-chain/core/transition/stateutils:go_default_library", + "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//encoding/bytesutil:go_default_library", "//proto/eth/v1:go_default_library", diff --git a/testing/util/altair.go b/testing/util/altair.go index dea3ed097b..0141c84bd2 100644 --- a/testing/util/altair.go +++ b/testing/util/altair.go @@ -17,6 +17,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil" stateAltair "github.com/prysmaticlabs/prysm/beacon-chain/state/v2" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/bls" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -180,7 +181,7 @@ func buildGenesisBeaconState(genesisTime uint64, preState state.BeaconStateAltai bodyRoot, err := (ðpb.BeaconBlockBodyAltair{ RandaoReveal: make([]byte, 96), Eth1Data: ðpb.Eth1Data{ - DepositRoot: make([]byte, 32), + DepositRoot: make([]byte, fieldparams.RootLength), BlockHash: make([]byte, 32), }, Graffiti: make([]byte, 32), @@ -246,12 +247,12 @@ func emptyGenesisState() (state.BeaconStateAltair, error) { func NewBeaconBlockAltair() *ethpb.SignedBeaconBlockAltair { return ðpb.SignedBeaconBlockAltair{ Block: ðpb.BeaconBlockAltair{ - ParentRoot: make([]byte, 32), - StateRoot: make([]byte, 32), + ParentRoot: make([]byte, fieldparams.RootLength), + StateRoot: make([]byte, fieldparams.RootLength), Body: ðpb.BeaconBlockBodyAltair{ RandaoReveal: make([]byte, 96), Eth1Data: ðpb.Eth1Data{ - DepositRoot: make([]byte, 32), + DepositRoot: make([]byte, fieldparams.RootLength), BlockHash: make([]byte, 32), }, Graffiti: make([]byte, 32), diff --git a/testing/util/attestation.go b/testing/util/attestation.go index b520f2d9c4..7cae375003 100644 --- a/testing/util/attestation.go +++ b/testing/util/attestation.go @@ -14,6 +14,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" v2 "github.com/prysmaticlabs/prysm/beacon-chain/state/v2" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/bls" "github.com/prysmaticlabs/prysm/crypto/rand" @@ -29,12 +30,12 @@ func NewAttestation() *ethpb.Attestation { return ðpb.Attestation{ AggregationBits: bitfield.Bitlist{0b1101}, Data: ðpb.AttestationData{ - BeaconBlockRoot: make([]byte, 32), + BeaconBlockRoot: make([]byte, fieldparams.RootLength), Source: ðpb.Checkpoint{ - Root: make([]byte, 32), + Root: make([]byte, fieldparams.RootLength), }, Target: ðpb.Checkpoint{ - Root: make([]byte, 32), + Root: make([]byte, fieldparams.RootLength), }, }, Signature: make([]byte, 96), @@ -61,7 +62,7 @@ func GenerateAttestations( } currentEpoch := slots.ToEpoch(slot) - targetRoot := make([]byte, 32) + targetRoot := make([]byte, fieldparams.RootLength) var headRoot []byte var err error // Only calculate head state if its an attestation for the current slot or future slot. @@ -112,7 +113,7 @@ func GenerateAttestations( } if randomRoot { randGen := rand.NewDeterministicGenerator() - b := make([]byte, 32) + b := make([]byte, fieldparams.RootLength) _, err := randGen.Read(b) if err != nil { return nil, err @@ -238,19 +239,19 @@ func HydrateV1Attestation(a *attv1.Attestation) *attv1.Attestation { // to comply with fssz marshalling and unmarshalling rules. func HydrateAttestationData(d *ethpb.AttestationData) *ethpb.AttestationData { if d.BeaconBlockRoot == nil { - d.BeaconBlockRoot = make([]byte, 32) + d.BeaconBlockRoot = make([]byte, fieldparams.RootLength) } if d.Target == nil { d.Target = ðpb.Checkpoint{} } if d.Target.Root == nil { - d.Target.Root = make([]byte, 32) + d.Target.Root = make([]byte, fieldparams.RootLength) } if d.Source == nil { d.Source = ðpb.Checkpoint{} } if d.Source.Root == nil { - d.Source.Root = make([]byte, 32) + d.Source.Root = make([]byte, fieldparams.RootLength) } return d } @@ -259,19 +260,19 @@ func HydrateAttestationData(d *ethpb.AttestationData) *ethpb.AttestationData { // to comply with fssz marshalling and unmarshalling rules. func HydrateV1AttestationData(d *attv1.AttestationData) *attv1.AttestationData { if d.BeaconBlockRoot == nil { - d.BeaconBlockRoot = make([]byte, 32) + d.BeaconBlockRoot = make([]byte, fieldparams.RootLength) } if d.Target == nil { d.Target = &attv1.Checkpoint{} } if d.Target.Root == nil { - d.Target.Root = make([]byte, 32) + d.Target.Root = make([]byte, fieldparams.RootLength) } if d.Source == nil { d.Source = &attv1.Checkpoint{} } if d.Source.Root == nil { - d.Source.Root = make([]byte, 32) + d.Source.Root = make([]byte, fieldparams.RootLength) } return d } diff --git a/testing/util/attestation_test.go b/testing/util/attestation_test.go index 8d0650130f..0b3fb8af72 100644 --- a/testing/util/attestation_test.go +++ b/testing/util/attestation_test.go @@ -3,6 +3,7 @@ package util import ( "testing" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" v1 "github.com/prysmaticlabs/prysm/proto/eth/v1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -20,9 +21,9 @@ func TestHydrateAttestationData(t *testing.T) { d := HydrateAttestationData(ðpb.AttestationData{}) _, err := d.HashTreeRoot() require.NoError(t, err) - require.DeepEqual(t, d.BeaconBlockRoot, make([]byte, 32)) - require.DeepEqual(t, d.Target.Root, make([]byte, 32)) - require.DeepEqual(t, d.Source.Root, make([]byte, 32)) + require.DeepEqual(t, d.BeaconBlockRoot, make([]byte, fieldparams.RootLength)) + require.DeepEqual(t, d.Target.Root, make([]byte, fieldparams.RootLength)) + require.DeepEqual(t, d.Source.Root, make([]byte, fieldparams.RootLength)) } func TestHydrateV1Attestation(t *testing.T) { @@ -36,9 +37,9 @@ func TestHydrateV1AttestationData(t *testing.T) { d := HydrateV1AttestationData(&v1.AttestationData{}) _, err := d.HashTreeRoot() require.NoError(t, err) - require.DeepEqual(t, d.BeaconBlockRoot, make([]byte, 32)) - require.DeepEqual(t, d.Target.Root, make([]byte, 32)) - require.DeepEqual(t, d.Source.Root, make([]byte, 32)) + require.DeepEqual(t, d.BeaconBlockRoot, make([]byte, fieldparams.RootLength)) + require.DeepEqual(t, d.Target.Root, make([]byte, fieldparams.RootLength)) + require.DeepEqual(t, d.Source.Root, make([]byte, fieldparams.RootLength)) } func TestHydrateIndexedAttestation(t *testing.T) { diff --git a/testing/util/block.go b/testing/util/block.go index f56ac65291..1d472a9092 100644 --- a/testing/util/block.go +++ b/testing/util/block.go @@ -10,6 +10,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/bls" "github.com/prysmaticlabs/prysm/crypto/rand" @@ -45,12 +46,12 @@ func DefaultBlockGenConfig() *BlockGenConfig { func NewBeaconBlock() *ethpb.SignedBeaconBlock { return ðpb.SignedBeaconBlock{ Block: ðpb.BeaconBlock{ - ParentRoot: make([]byte, 32), - StateRoot: make([]byte, 32), + ParentRoot: make([]byte, fieldparams.RootLength), + StateRoot: make([]byte, fieldparams.RootLength), Body: ðpb.BeaconBlockBody{ RandaoReveal: make([]byte, 96), Eth1Data: ðpb.Eth1Data{ - DepositRoot: make([]byte, 32), + DepositRoot: make([]byte, fieldparams.RootLength), BlockHash: make([]byte, 32), }, Graffiti: make([]byte, 32), @@ -213,8 +214,8 @@ func GenerateProposerSlashingForValidator( ProposerIndex: idx, Slot: bState.Slot(), BodyRoot: bytesutil.PadTo([]byte{0, 2, 0}, 32), - StateRoot: make([]byte, 32), - ParentRoot: make([]byte, 32), + StateRoot: make([]byte, fieldparams.RootLength), + ParentRoot: make([]byte, fieldparams.RootLength), }, } header2.Signature, err = signing.ComputeDomainAndSign(bState, currentEpoch, header2.Header, params.BeaconConfig().DomainBeaconProposer, priv) @@ -260,7 +261,7 @@ func GenerateAttesterSlashingForValidator( Data: ðpb.AttestationData{ Slot: bState.Slot(), CommitteeIndex: 0, - BeaconBlockRoot: make([]byte, 32), + BeaconBlockRoot: make([]byte, fieldparams.RootLength), Target: ðpb.Checkpoint{ Epoch: currentEpoch, Root: params.BeaconConfig().ZeroHash[:], @@ -282,7 +283,7 @@ func GenerateAttesterSlashingForValidator( Data: ðpb.AttestationData{ Slot: bState.Slot(), CommitteeIndex: 0, - BeaconBlockRoot: make([]byte, 32), + BeaconBlockRoot: make([]byte, fieldparams.RootLength), Target: ðpb.Checkpoint{ Epoch: currentEpoch, Root: params.BeaconConfig().ZeroHash[:], @@ -402,13 +403,13 @@ func HydrateBeaconHeader(h *ethpb.BeaconBlockHeader) *ethpb.BeaconBlockHeader { h = ðpb.BeaconBlockHeader{} } if h.BodyRoot == nil { - h.BodyRoot = make([]byte, 32) + h.BodyRoot = make([]byte, fieldparams.RootLength) } if h.StateRoot == nil { - h.StateRoot = make([]byte, 32) + h.StateRoot = make([]byte, fieldparams.RootLength) } if h.ParentRoot == nil { - h.ParentRoot = make([]byte, 32) + h.ParentRoot = make([]byte, fieldparams.RootLength) } return h } @@ -430,10 +431,10 @@ func HydrateBeaconBlock(b *ethpb.BeaconBlock) *ethpb.BeaconBlock { b = ðpb.BeaconBlock{} } if b.ParentRoot == nil { - b.ParentRoot = make([]byte, 32) + b.ParentRoot = make([]byte, fieldparams.RootLength) } if b.StateRoot == nil { - b.StateRoot = make([]byte, 32) + b.StateRoot = make([]byte, fieldparams.RootLength) } b.Body = HydrateBeaconBlockBody(b.Body) return b diff --git a/testing/util/helpers_test.go b/testing/util/helpers_test.go index bb7c793eb6..543a94b86f 100644 --- a/testing/util/helpers_test.go +++ b/testing/util/helpers_test.go @@ -10,6 +10,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" "github.com/prysmaticlabs/prysm/beacon-chain/core/time" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/testing/assert" "github.com/prysmaticlabs/prysm/testing/require" @@ -47,7 +48,7 @@ func TestRandaoReveal(t *testing.T) { proposerIdx, err := helpers.BeaconProposerIndex(context.Background(), beaconState) assert.NoError(t, err) - buf := make([]byte, 32) + buf := make([]byte, fieldparams.RootLength) binary.LittleEndian.PutUint64(buf, uint64(epoch)) // We make the previous validator's index sign the message instead of the proposer. sszUint := types.SSZUint64(epoch) diff --git a/testing/util/state.go b/testing/util/state.go index 4040eb8329..7c74381d75 100644 --- a/testing/util/state.go +++ b/testing/util/state.go @@ -7,6 +7,7 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/go-bitfield" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ) @@ -18,7 +19,7 @@ func FillRootsNaturalOpt(state *ethpb.BeaconState) error { rootsLen := params.MainnetConfig().SlotsPerHistoricalRoot roots := make([][]byte, rootsLen) for i := types.Slot(0); i < rootsLen; i++ { - roots[i] = make([]byte, 32) + roots[i] = make([]byte, fieldparams.RootLength) } for j := 0; j < len(roots); j++ { // Remove '0x' prefix and left-pad '0' to have 64 chars in total. @@ -42,9 +43,9 @@ func NewBeaconState(options ...func(state *ethpb.BeaconState) error) (*v1.Beacon Slashings: make([]uint64, params.MainnetConfig().EpochsPerSlashingsVector), RandaoMixes: filledByteSlice2D(uint64(params.MainnetConfig().EpochsPerHistoricalVector), 32), Validators: make([]*ethpb.Validator, 0), - CurrentJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, + CurrentJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, Eth1Data: ðpb.Eth1Data{ - DepositRoot: make([]byte, 32), + DepositRoot: make([]byte, fieldparams.RootLength), BlockHash: make([]byte, 32), }, Fork: ðpb.Fork{ @@ -54,11 +55,11 @@ func NewBeaconState(options ...func(state *ethpb.BeaconState) error) (*v1.Beacon Eth1DataVotes: make([]*ethpb.Eth1Data, 0), HistoricalRoots: make([][]byte, 0), JustificationBits: bitfield.Bitvector4{0x0}, - FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, + FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, LatestBlockHeader: HydrateBeaconHeader(ðpb.BeaconBlockHeader{}), PreviousEpochAttestations: make([]*ethpb.PendingAttestation, 0), CurrentEpochAttestations: make([]*ethpb.PendingAttestation, 0), - PreviousJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, + PreviousJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, } for _, opt := range options { diff --git a/testing/util/sync_committee.go b/testing/util/sync_committee.go index 6bf56ba7d9..ca03f93df9 100644 --- a/testing/util/sync_committee.go +++ b/testing/util/sync_committee.go @@ -1,6 +1,7 @@ package util import ( + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -12,7 +13,7 @@ func HydrateSyncCommittee(s *ethpb.SyncCommitteeMessage) *ethpb.SyncCommitteeMes s.Signature = make([]byte, 96) } if s.BlockRoot == nil { - s.BlockRoot = make([]byte, 32) + s.BlockRoot = make([]byte, fieldparams.RootLength) } return s } diff --git a/validator/client/BUILD.bazel b/validator/client/BUILD.bazel index a44cd92438..575647fa9e 100644 --- a/validator/client/BUILD.bazel +++ b/validator/client/BUILD.bazel @@ -28,6 +28,7 @@ go_library( "//beacon-chain/core/signing:go_default_library", "//cache/lru:go_default_library", "//config/features:go_default_library", + "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//crypto/bls:go_default_library", "//crypto/hash:go_default_library", @@ -105,6 +106,7 @@ go_test( "//beacon-chain/core/signing:go_default_library", "//cache/lru:go_default_library", "//config/features:go_default_library", + "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//crypto/bls:go_default_library", "//encoding/bytesutil:go_default_library", diff --git a/validator/client/attest_test.go b/validator/client/attest_test.go index 090b64011f..89c811d104 100644 --- a/validator/client/attest_test.go +++ b/validator/client/attest_test.go @@ -15,6 +15,7 @@ import ( "github.com/prysmaticlabs/prysm/async/event" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" "github.com/prysmaticlabs/prysm/config/features" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/bls" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -76,9 +77,9 @@ func TestAttestToBlockHead_SubmitAttestation_RequestFailure(t *testing.T) { gomock.Any(), // ctx gomock.AssignableToTypeOf(ðpb.AttestationDataRequest{}), ).Return(ðpb.AttestationData{ - BeaconBlockRoot: make([]byte, 32), - Target: ðpb.Checkpoint{Root: make([]byte, 32)}, - Source: ðpb.Checkpoint{Root: make([]byte, 32)}, + BeaconBlockRoot: make([]byte, fieldparams.RootLength), + Target: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, + Source: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, }, nil) m.validatorClient.EXPECT().DomainData( gomock.Any(), // ctx @@ -420,7 +421,7 @@ func TestAttestToBlockHead_CorrectBitfieldLength(t *testing.T) { ).Return(ðpb.AttestationData{ Target: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte("B"), 32)}, Source: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte("C"), 32), Epoch: 3}, - BeaconBlockRoot: make([]byte, 32), + BeaconBlockRoot: make([]byte, fieldparams.RootLength), }, nil) m.validatorClient.EXPECT().DomainData( diff --git a/validator/client/sync_committee_test.go b/validator/client/sync_committee_test.go index 818092f00e..ebd5686305 100644 --- a/validator/client/sync_committee_test.go +++ b/validator/client/sync_committee_test.go @@ -9,6 +9,7 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/go-bitfield" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/crypto/bls" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -358,7 +359,7 @@ func TestSubmitSignedContributionAndProof_CouldNotSubmitContribution(t *testing. SubnetId: 0, }, ).Return(ðpb.SyncCommitteeContribution{ - BlockRoot: make([]byte, 32), + BlockRoot: make([]byte, fieldparams.RootLength), Signature: make([]byte, 96), AggregationBits: aggBits, }, nil) @@ -376,7 +377,7 @@ func TestSubmitSignedContributionAndProof_CouldNotSubmitContribution(t *testing. Message: ðpb.ContributionAndProof{ AggregatorIndex: 7, Contribution: ðpb.SyncCommitteeContribution{ - BlockRoot: make([]byte, 32), + BlockRoot: make([]byte, fieldparams.RootLength), Signature: make([]byte, 96), AggregationBits: bitfield.NewBitvector128(), Slot: 1, @@ -436,7 +437,7 @@ func TestSubmitSignedContributionAndProof_Ok(t *testing.T) { SubnetId: 0, }, ).Return(ðpb.SyncCommitteeContribution{ - BlockRoot: make([]byte, 32), + BlockRoot: make([]byte, fieldparams.RootLength), Signature: make([]byte, 96), AggregationBits: aggBits, }, nil) diff --git a/validator/client/validator.go b/validator/client/validator.go index 83598c5150..209f634a4e 100644 --- a/validator/client/validator.go +++ b/validator/client/validator.go @@ -21,6 +21,7 @@ import ( "github.com/prysmaticlabs/prysm/async/event" "github.com/prysmaticlabs/prysm/beacon-chain/core/altair" "github.com/prysmaticlabs/prysm/config/features" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/hash" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -383,7 +384,7 @@ func (v *validator) CheckDoppelGanger(ctx context.Context) error { ðpb.DoppelGangerRequest_ValidatorRequest{ PublicKey: copiedKey[:], Epoch: 0, - SignedRoot: make([]byte, 32), + SignedRoot: make([]byte, fieldparams.RootLength), }) continue } diff --git a/validator/db/kv/BUILD.bazel b/validator/db/kv/BUILD.bazel index 092312ab2b..4457d287a2 100644 --- a/validator/db/kv/BUILD.bazel +++ b/validator/db/kv/BUILD.bazel @@ -27,6 +27,7 @@ go_library( "//async/abool:go_default_library", "//async/event:go_default_library", "//config/features:go_default_library", + "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//encoding/bytesutil:go_default_library", "//io/file:go_default_library", diff --git a/validator/db/kv/deprecated_attester_protection.go b/validator/db/kv/deprecated_attester_protection.go index 6d257e031f..ebd06429fe 100644 --- a/validator/db/kv/deprecated_attester_protection.go +++ b/validator/db/kv/deprecated_attester_protection.go @@ -5,6 +5,7 @@ import ( "fmt" types "github.com/prysmaticlabs/eth2-types" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ) @@ -104,7 +105,7 @@ func (dh deprecatedEncodedAttestingHistory) getTargetData(ctx context.Context, t } history := &deprecatedHistoryData{} history.Source = types.Epoch(bytesutil.FromBytes8(dh[cursor : cursor+sourceSize])) - sr := make([]byte, 32) + sr := make([]byte, fieldparams.RootLength) copy(sr, dh[cursor+sourceSize:cursor+historySize]) history.SigningRoot = sr return history, nil diff --git a/validator/db/kv/proposer_protection.go b/validator/db/kv/proposer_protection.go index ee517d95ee..fead5fc128 100644 --- a/validator/db/kv/proposer_protection.go +++ b/validator/db/kv/proposer_protection.go @@ -6,6 +6,7 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" + fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/time/slots" @@ -83,7 +84,7 @@ func (s *Store) ProposalHistoryForPubKey(ctx context.Context, publicKey [48]byte } return valBucket.ForEach(func(slotKey, signingRootBytes []byte) error { slot := bytesutil.BytesToSlotBigEndian(slotKey) - sr := make([]byte, 32) + sr := make([]byte, fieldparams.RootLength) copy(sr, signingRootBytes) proposals = append(proposals, &Proposal{ Slot: slot,