From 386424c7cc743ea8791e38d9ea34270b08516075 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Fri, 1 Nov 2024 11:32:40 -0700 Subject: [PATCH 1/3] Add missed exit checks to consolidation processing --- CHANGELOG.md | 1 + beacon-chain/core/electra/consolidations.go | 19 +++++++++++++++++++ .../core/electra/consolidations_test.go | 14 ++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0db4182d620..4e988df5a75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve - Simplified `ExitedValidatorIndices`. - Simplified `EjectedValidatorIndices`. - `engine_newPayloadV4`,`engine_getPayloadV4` are changes due to new execution request serialization decisions, [PR](https://github.com/prysmaticlabs/prysm/pull/14580) +- Add missed exit checks to consolidation processing ### Deprecated diff --git a/beacon-chain/core/electra/consolidations.go b/beacon-chain/core/electra/consolidations.go index a4e08c19f8c..a11454697f0 100644 --- a/beacon-chain/core/electra/consolidations.go +++ b/beacon-chain/core/electra/consolidations.go @@ -156,6 +156,13 @@ func ProcessPendingConsolidations(ctx context.Context, st state.BeaconState) err // if target_validator.exit_epoch != FAR_FUTURE_EPOCH: // return // +// # Verify the source has been active long enough +// if current_epoch < source_validator.activation_epoch + SHARD_COMMITTEE_PERIOD: +// return +// +// # Verify the source has no pending withdrawals in the queue +// if get_pending_balance_to_withdraw(state, source_index) > 0: +// return // # Initiate source validator exit and append pending consolidation // source_validator.exit_epoch = compute_consolidation_epoch_and_update_churn( // state, source_validator.effective_balance @@ -258,6 +265,18 @@ func ProcessConsolidationRequests(ctx context.Context, st state.BeaconState, req continue } + if curEpoch < srcV.ActivationEpoch+params.BeaconConfig().ShardCommitteePeriod { + continue + } + bal, err := st.PendingBalanceToWithdraw(srcIdx) + if err != nil { + log.WithError(err).Error("failed to fetch pending balance to withdraw") + continue + } + if bal > 0 { + continue + } + // Initiate the exit of the source validator. exitEpoch, err := ComputeConsolidationEpochAndUpdateChurn(ctx, st, primitives.Gwei(srcV.EffectiveBalance)) if err != nil { diff --git a/beacon-chain/core/electra/consolidations_test.go b/beacon-chain/core/electra/consolidations_test.go index 8d065d91484..e6bf68a754c 100644 --- a/beacon-chain/core/electra/consolidations_test.go +++ b/beacon-chain/core/electra/consolidations_test.go @@ -213,6 +213,7 @@ func TestProcessConsolidationRequests(t *testing.T) { name: "one valid request", state: func() state.BeaconState { st := ð.BeaconStateElectra{ + Slot: params.BeaconConfig().SlotsPerEpoch.Mul(uint64(params.BeaconConfig().ShardCommitteePeriod)), Validators: createValidatorsWithTotalActiveBalance(32000000000000000), // 32M ETH } // Validator scenario setup. See comments in reqs section. @@ -222,6 +223,12 @@ func TestProcessConsolidationRequests(t *testing.T) { st.Validators[12].ActivationEpoch = params.BeaconConfig().FarFutureEpoch st.Validators[13].ExitEpoch = 10 st.Validators[16].ExitEpoch = 10 + st.PendingPartialWithdrawals = []*eth.PendingPartialWithdrawal{ + { + Index: 17, + Amount: 100, + }, + } s, err := state_native.InitializeFromProtoElectra(st) require.NoError(t, err) return s @@ -287,6 +294,12 @@ func TestProcessConsolidationRequests(t *testing.T) { SourcePubkey: []byte("val_0"), TargetPubkey: []byte("val_0"), }, + // Has pening partial withdrawal + { + SourceAddress: append(bytesutil.PadTo(nil, 19), byte(0)), + SourcePubkey: []byte("val_17"), + TargetPubkey: []byte("val_1"), + }, // Valid consolidation request. This should be last to ensure invalid requests do // not end the processing early. { @@ -347,6 +360,7 @@ func TestProcessConsolidationRequests(t *testing.T) { name: "pending consolidations limit reached during processing", state: func() state.BeaconState { st := ð.BeaconStateElectra{ + Slot: params.BeaconConfig().SlotsPerEpoch.Mul(uint64(params.BeaconConfig().ShardCommitteePeriod)), Validators: createValidatorsWithTotalActiveBalance(32000000000000000), // 32M ETH PendingConsolidations: make([]*eth.PendingConsolidation, params.BeaconConfig().PendingConsolidationsLimit-1), } From 599805f6a727fca9a4d9bcdf314bd6dd19e09be1 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Fri, 1 Nov 2024 19:48:15 -0700 Subject: [PATCH 2/3] Use safe add --- beacon-chain/core/electra/consolidations.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/beacon-chain/core/electra/consolidations.go b/beacon-chain/core/electra/consolidations.go index a11454697f0..d21d9b4d62f 100644 --- a/beacon-chain/core/electra/consolidations.go +++ b/beacon-chain/core/electra/consolidations.go @@ -5,6 +5,7 @@ import ( "context" "fmt" + "github.com/ethereum/go-ethereum/common/math" "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" @@ -265,7 +266,12 @@ func ProcessConsolidationRequests(ctx context.Context, st state.BeaconState, req continue } - if curEpoch < srcV.ActivationEpoch+params.BeaconConfig().ShardCommitteePeriod { + e, ok := math.SafeAdd(uint64(srcV.ActivationEpoch), uint64(params.BeaconConfig().ShardCommitteePeriod)) + if !ok { + log.Error("Overflow when adding activation epoch and shard committee period") + continue + } + if uint64(curEpoch) < e { continue } bal, err := st.PendingBalanceToWithdraw(srcIdx) From 7794a0ab854f4bb75170be8407715d7bf9fdd0f2 Mon Sep 17 00:00:00 2001 From: james-prysm Date: Mon, 4 Nov 2024 10:54:22 -0600 Subject: [PATCH 3/3] gaz --- beacon-chain/core/electra/BUILD.bazel | 1 + 1 file changed, 1 insertion(+) diff --git a/beacon-chain/core/electra/BUILD.bazel b/beacon-chain/core/electra/BUILD.bazel index 35ef921f3ef..ee2a0addf94 100644 --- a/beacon-chain/core/electra/BUILD.bazel +++ b/beacon-chain/core/electra/BUILD.bazel @@ -41,6 +41,7 @@ go_library( "//runtime/version:go_default_library", "//time/slots:go_default_library", "@com_github_ethereum_go_ethereum//common/hexutil:go_default_library", + "@com_github_ethereum_go_ethereum//common/math:go_default_library", "@com_github_pkg_errors//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", ],