mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-05 17:22:18 +00:00
c5c039fd6b
* Unify `GenesisValidator(s)Root` throughout the codebase * comments and literals Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com>
56 lines
1.8 KiB
Go
56 lines
1.8 KiB
Go
package util
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/signing"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/time"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/transition"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/state"
|
|
"github.com/prysmaticlabs/prysm/config/params"
|
|
"github.com/prysmaticlabs/prysm/crypto/bls"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
|
|
)
|
|
|
|
// BlockSignatureBellatrix calculates the post-state root of the block and returns the signature.
|
|
func BlockSignatureBellatrix(
|
|
bState state.BeaconState,
|
|
block *ethpb.BeaconBlockBellatrix,
|
|
privKeys []bls.SecretKey,
|
|
) (bls.Signature, error) {
|
|
var err error
|
|
wsb, err := wrapper.WrappedBellatrixSignedBeaconBlock(ðpb.SignedBeaconBlockBellatrix{Block: block})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
s, err := transition.CalculateStateRoot(context.Background(), bState, wsb)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
block.StateRoot = s[:]
|
|
domain, err := signing.Domain(bState.Fork(), time.CurrentEpoch(bState), params.BeaconConfig().DomainBeaconProposer, bState.GenesisValidatorsRoot())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
blockRoot, err := signing.ComputeSigningRoot(block, domain)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
// Temporarily increasing the beacon state slot here since BeaconProposerIndex is a
|
|
// function deterministic on beacon state slot.
|
|
currentSlot := bState.Slot()
|
|
if err := bState.SetSlot(block.Slot); err != nil {
|
|
return nil, err
|
|
}
|
|
proposerIdx, err := helpers.BeaconProposerIndex(context.Background(), bState)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if err := bState.SetSlot(currentSlot); err != nil {
|
|
return nil, err
|
|
}
|
|
return privKeys[proposerIdx].Sign(blockRoot[:]), nil
|
|
}
|