From 599805f6a727fca9a4d9bcdf314bd6dd19e09be1 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Fri, 1 Nov 2024 19:48:15 -0700 Subject: [PATCH] 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)