From c573306621b8ba4ec94673663f7c1254a28c7f69 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Fri, 17 Jul 2020 23:39:43 -0700 Subject: [PATCH] Check for array out of bounds when calculating proposer delta -- follow up (#6630) * failing test * fix --- beacon-chain/core/epoch/precompute/reward_penalty.go | 2 +- beacon-chain/core/epoch/precompute/reward_penalty_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/beacon-chain/core/epoch/precompute/reward_penalty.go b/beacon-chain/core/epoch/precompute/reward_penalty.go index 07868da4f..8e1e108fd 100644 --- a/beacon-chain/core/epoch/precompute/reward_penalty.go +++ b/beacon-chain/core/epoch/precompute/reward_penalty.go @@ -162,7 +162,7 @@ func ProposersDelta(state *stateTrie.BeaconState, pBal *Balance, vp []*Validator baseRewardsPerEpoch := params.BeaconConfig().BaseRewardsPerEpoch proposerRewardQuotient := params.BeaconConfig().ProposerRewardQuotient for _, v := range vp { - if v.ProposerIndex > uint64(len(rewards)) { + if v.ProposerIndex >= uint64(len(rewards)) { // This should never happen with a valid state / validator. return nil, errors.New("proposer index out of range") } diff --git a/beacon-chain/core/epoch/precompute/reward_penalty_test.go b/beacon-chain/core/epoch/precompute/reward_penalty_test.go index 3df1ddddb..726263e77 100644 --- a/beacon-chain/core/epoch/precompute/reward_penalty_test.go +++ b/beacon-chain/core/epoch/precompute/reward_penalty_test.go @@ -368,7 +368,7 @@ func TestProposerDeltaPrecompute_ValidatorIndexOutOfRange(t *testing.T) { t.Fatal(err) } - proposerIndex := validatorCount + 1 + proposerIndex := validatorCount b := &Balance{ActiveCurrentEpoch: 1000} v := []*Validator{ {IsPrevEpochAttester: true, CurrentEpochEffectiveBalance: 32, ProposerIndex: proposerIndex},