From 20c7efda2c1cd197615ab6cd0efceac2fbcd8a30 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Mon, 18 Oct 2021 05:40:47 -0700 Subject: [PATCH] Process slashings return error on unknown state (#9778) Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> --- beacon-chain/core/blocks/attester_slashing.go | 9 +++++++-- beacon-chain/core/blocks/proposer_slashing.go | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/beacon-chain/core/blocks/attester_slashing.go b/beacon-chain/core/blocks/attester_slashing.go index d31be8a89d..f28634746f 100644 --- a/beacon-chain/core/blocks/attester_slashing.go +++ b/beacon-chain/core/blocks/attester_slashing.go @@ -61,9 +61,14 @@ func ProcessAttesterSlashings( } if helpers.IsSlashableValidator(val.ActivationEpoch(), val.WithdrawableEpoch(), val.Slashed(), currentEpoch) { cfg := params.BeaconConfig() - slashingQuotient := cfg.MinSlashingPenaltyQuotient - if beaconState.Version() == version.Altair { + var slashingQuotient uint64 + switch { + case beaconState.Version() == version.Phase0: + slashingQuotient = cfg.MinSlashingPenaltyQuotient + case beaconState.Version() == version.Altair: slashingQuotient = cfg.MinSlashingPenaltyQuotientAltair + default: + return nil, errors.New("unknown state version") } beaconState, err = slashFunc(ctx, beaconState, types.ValidatorIndex(validatorIndex), slashingQuotient, cfg.ProposerRewardQuotient) if err != nil { diff --git a/beacon-chain/core/blocks/proposer_slashing.go b/beacon-chain/core/blocks/proposer_slashing.go index 8de5ced292..d42636ec60 100644 --- a/beacon-chain/core/blocks/proposer_slashing.go +++ b/beacon-chain/core/blocks/proposer_slashing.go @@ -59,9 +59,14 @@ func ProcessProposerSlashings( return nil, errors.Wrapf(err, "could not verify proposer slashing %d", idx) } cfg := params.BeaconConfig() - slashingQuotient := cfg.MinSlashingPenaltyQuotient - if beaconState.Version() == version.Altair { + var slashingQuotient uint64 + switch { + case beaconState.Version() == version.Phase0: + slashingQuotient = cfg.MinSlashingPenaltyQuotient + case beaconState.Version() == version.Altair: slashingQuotient = cfg.MinSlashingPenaltyQuotientAltair + default: + return nil, errors.New("unknown state version") } beaconState, err = slashFunc(ctx, beaconState, slashing.Header_1.Header.ProposerIndex, slashingQuotient, cfg.ProposerRewardQuotient) if err != nil {