diff --git a/config/spec/special_cases.go b/config/spec/special_cases.go index 77dac006c..1cafd06e6 100644 --- a/config/spec/special_cases.go +++ b/config/spec/special_cases.go @@ -20,6 +20,8 @@ package spec +import "math" + // Special cased Bartio for some ad-hoc handling due to the way // some bugs were handled on Bartio. To be removed. const ( @@ -34,4 +36,6 @@ const ( BoonetFork1Height uint64 = 69420 BoonetFork2Height uint64 = 1722000 + + BoonetFork3Height uint64 = math.MaxUint64 ) diff --git a/state-transition/core/state_processor.go b/state-transition/core/state_processor.go index cf8ab4433..422daf6cf 100644 --- a/state-transition/core/state_processor.go +++ b/state-transition/core/state_processor.go @@ -30,6 +30,7 @@ import ( "github.com/berachain/beacon-kit/errors" "github.com/berachain/beacon-kit/log" "github.com/berachain/beacon-kit/primitives/common" + "github.com/berachain/beacon-kit/primitives/constants" "github.com/berachain/beacon-kit/primitives/crypto" "github.com/berachain/beacon-kit/primitives/math" "github.com/berachain/beacon-kit/primitives/transition" @@ -374,15 +375,36 @@ func (sp *StateProcessor[ ]) processEpoch( st BeaconStateT, ) (transition.ValidatorUpdates, error) { - // currently no processRewardsAndPenalties + slot, err := st.GetSlot() + if err != nil { + return nil, err + } - if err := sp.processEffectiveBalanceUpdates(st); err != nil { + switch { + case sp.cs.DepositEth1ChainID() == spec.BartioChainID: + if err = sp.hollowProcessRewardsAndPenalties(st); err != nil { + return nil, err + } + case sp.cs.DepositEth1ChainID() == spec.BoonetEth1ChainID && + slot < math.U64(spec.BoonetFork3Height): + // We cannot simply drop hollowProcessRewardsAndPenalties because + // appHash accounts for the list of operations carried out + // over the state even if the operations does not affect the state + // (rewards and penalties are always zero at this stage of beaconKit) + if err = sp.hollowProcessRewardsAndPenalties(st); err != nil { + return nil, err + } + default: + // no real need to perform hollowProcessRewardsAndPenalties + } + + if err = sp.processEffectiveBalanceUpdates(st); err != nil { return nil, err } - if err := sp.processSlashingsReset(st); err != nil { + if err = sp.processSlashingsReset(st); err != nil { return nil, err } - if err := sp.processRandaoMixesReset(st); err != nil { + if err = sp.processRandaoMixesReset(st); err != nil { return nil, err } return sp.processValidatorsSetUpdates(st) @@ -470,6 +492,40 @@ func (sp *StateProcessor[ return st.SetLatestBlockHeader(lbh) } +func (sp *StateProcessor[ + _, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _, _, _, +]) hollowProcessRewardsAndPenalties(st BeaconStateT) error { + slot, err := st.GetSlot() + if err != nil { + return err + } + + if sp.cs.SlotToEpoch(slot) == math.U64(constants.GenesisEpoch) { + return nil + } + + // this has been simplified to make clear that + // we are not really doing anything here + valCount, err := st.GetTotalValidators() + if err != nil { + return err + } + + for i := range valCount { + // Increase the balance of the validator. + if err = st.IncreaseBalance(math.ValidatorIndex(i), 0); err != nil { + return err + } + + // Decrease the balance of the validator. + if err = st.DecreaseBalance(math.ValidatorIndex(i), 0); err != nil { + return err + } + } + + return nil +} + // processEffectiveBalanceUpdates as defined in the Ethereum 2.0 specification. // https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#effective-balances-updates // diff --git a/state-transition/core/state_processor_staking.go b/state-transition/core/state_processor_staking.go index 0b0039c9d..8c3458e71 100644 --- a/state-transition/core/state_processor_staking.go +++ b/state-transition/core/state_processor_staking.go @@ -84,7 +84,7 @@ func (sp *StateProcessor[ // We keep it for backward compatibility. depositIndex++ case sp.cs.DepositEth1ChainID() == spec.BoonetEth1ChainID && - slot < math.U64(spec.BoonetFork2Height): + slot != 0 && slot < math.U64(spec.BoonetFork2Height): // Boonet pre fork2 has a bug which makes DepositEth1ChainID point to // next deposit index, not latest processed deposit index. // We keep it for backward compatibility.