mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-07 03:22:18 +00:00
3ab373787e
we need to extract this interface from the struct. i need to also break down the interface more, to better show what parts the caching is used, move some functions from the cache state to the underlying. don't merge
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package eth2
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/Giulio2002/bls"
|
|
"github.com/ledgerwatch/erigon/cl/abstract"
|
|
"github.com/ledgerwatch/erigon/cl/cltypes"
|
|
"github.com/ledgerwatch/erigon/cl/fork"
|
|
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
|
)
|
|
|
|
func (I *impl) VerifyTransition(s abstract.BeaconState, currentBlock *cltypes.BeaconBlock) error {
|
|
if !I.FullValidation {
|
|
return nil
|
|
}
|
|
expectedStateRoot, err := s.HashSSZ()
|
|
if err != nil {
|
|
return fmt.Errorf("unable to generate state root: %v", err)
|
|
}
|
|
if expectedStateRoot != currentBlock.StateRoot {
|
|
return fmt.Errorf("expected state root differs from received state root")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (I *impl) VerifyBlockSignature(s abstract.BeaconState, block *cltypes.SignedBeaconBlock) error {
|
|
if !I.FullValidation {
|
|
return nil
|
|
}
|
|
valid, err := verifyBlockSignature(s, block)
|
|
if err != nil {
|
|
return fmt.Errorf("error validating block signature: %v", err)
|
|
}
|
|
if !valid {
|
|
return fmt.Errorf("block not valid")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func verifyBlockSignature(s abstract.BeaconState, block *cltypes.SignedBeaconBlock) (bool, error) {
|
|
proposer, err := s.ValidatorForValidatorIndex(int(block.Block.ProposerIndex))
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
domain, err := s.GetDomain(s.BeaconConfig().DomainBeaconProposer, state.Epoch(s))
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
sigRoot, err := fork.ComputeSigningRoot(block.Block, domain)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
pk := proposer.PublicKey()
|
|
return bls.Verify(block.Signature[:], sigRoot[:], pk[:])
|
|
}
|