mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-10 11:41:21 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
51 lines
1.9 KiB
Go
51 lines
1.9 KiB
Go
package helpers
|
|
|
|
import (
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
|
"github.com/prysmaticlabs/prysm/v3/config/params"
|
|
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
|
"github.com/prysmaticlabs/prysm/v3/crypto/bls"
|
|
"github.com/prysmaticlabs/prysm/v3/crypto/hash"
|
|
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
|
)
|
|
|
|
// Seed returns the randao seed used for shuffling of a given epoch.
|
|
//
|
|
// Spec pseudocode definition:
|
|
// def get_seed(state: BeaconState, epoch: Epoch, domain_type: DomainType) -> Bytes32:
|
|
// """
|
|
// Return the seed at ``epoch``.
|
|
// """
|
|
// mix = get_randao_mix(state, Epoch(epoch + EPOCHS_PER_HISTORICAL_VECTOR - MIN_SEED_LOOKAHEAD - 1)) # Avoid underflow
|
|
// return hash(domain_type + uint_to_bytes(epoch) + mix)
|
|
func Seed(state state.ReadOnlyBeaconState, epoch types.Epoch, domain [bls.DomainByteLength]byte) ([32]byte, error) {
|
|
// See https://github.com/ethereum/consensus-specs/pull/1296 for
|
|
// rationale on why offset has to look down by 1.
|
|
lookAheadEpoch := epoch + params.BeaconConfig().EpochsPerHistoricalVector -
|
|
params.BeaconConfig().MinSeedLookahead - 1
|
|
|
|
randaoMix, err := RandaoMix(state, lookAheadEpoch)
|
|
if err != nil {
|
|
return [32]byte{}, err
|
|
}
|
|
seed := append(domain[:], bytesutil.Bytes8(uint64(epoch))...)
|
|
seed = append(seed, randaoMix...)
|
|
|
|
seed32 := hash.Hash(seed)
|
|
|
|
return seed32, nil
|
|
}
|
|
|
|
// RandaoMix returns the randao mix (xor'ed seed)
|
|
// of a given slot. It is used to shuffle validators.
|
|
//
|
|
// Spec pseudocode definition:
|
|
// def get_randao_mix(state: BeaconState, epoch: Epoch) -> Bytes32:
|
|
// """
|
|
// Return the randao mix at a recent ``epoch``.
|
|
// """
|
|
// return state.randao_mixes[epoch % EPOCHS_PER_HISTORICAL_VECTOR]
|
|
func RandaoMix(state state.ReadOnlyBeaconState, epoch types.Epoch) ([]byte, error) {
|
|
return state.RandaoMixAtIndex(uint64(epoch % params.BeaconConfig().EpochsPerHistoricalVector))
|
|
}
|