func (s *State) applyProposerSlashing(proposerSlashing ProposerSlashing, config *config.Config) error {
	if proposerSlashing.ProposerIndex >= uint32(len(s.ValidatorRegistry)) {
		return errors.New("invalid proposer index")
	}
	proposer := &s.ValidatorRegistry[proposerSlashing.ProposerIndex]
	if proposerSlashing.ProposalData1.Slot != proposerSlashing.ProposalData2.Slot {
		return errors.New("proposer slashing request does not have same slot")
	}
	if proposerSlashing.ProposalData1.Shard != proposerSlashing.ProposalData2.Shard {
		return errors.New("proposer slashing request does not have same shard number")
	}
	if proposerSlashing.ProposalData1.BlockHash.IsEqual(&proposerSlashing.ProposalData2.BlockHash) {
		return errors.New("proposer slashing request has same block hash (same proposal)")
	}
	if proposer.Status == ExitedWithPenalty {
		return errors.New("proposer is already exited")
	}
	hashProposal1, err := ssz.HashTreeRoot(proposerSlashing.ProposalData1)
	if err != nil {
		return err
	}
	hashProposal2, err := ssz.HashTreeRoot(proposerSlashing.ProposalData2)
	if err != nil {
		return err
	}
	pub, err := proposer.GetPublicKey()
	if err != nil {
		return err
	}

	sigProposal2, err := bls.DeserializeSignature(proposerSlashing.ProposalSignature2)
	if err != nil {
		return err
	}

	valid, err := bls.VerifySig(pub, hashProposal2[:], sigProposal2, bls.DomainProposal)
	if err != nil {
		return err
	}
	if !valid {
		return errors.New("invalid proposer signature")
	}

	sigProposal1, err := bls.DeserializeSignature(proposerSlashing.ProposalSignature1)
	if err != nil {
		return err
	}

	valid, err = bls.VerifySig(pub, hashProposal1[:], sigProposal1, bls.DomainProposal)
	if err != nil {
		return err
	}
	if !valid {
		return errors.New("invalid proposer signature")
	}
	return s.UpdateValidatorStatus(proposerSlashing.ProposerIndex, ExitedWithPenalty, config)
}
// applyProposerSlashing applies a proposer slashing if valid.
applyProposerSlashing applies a proposer slashing if valid.
// applyProposerSlashing applies a proposer slashing if valid .
func (s *State) applyProposerSlashing(proposerSlashing ProposerSlashing, config *config.Config) error {
	if proposerSlashing.ProposerIndex >= uint32(len(s.ValidatorRegistry)) {
		return errors.New("invalid proposer index")
	}
	proposer := &s.ValidatorRegistry[proposerSlashing.ProposerIndex]
	if proposerSlashing.ProposalData1.Slot != proposerSlashing.ProposalData2.Slot {
		return errors.New("proposer slashing request does not have same slot")
	}
	if proposerSlashing.ProposalData1.Shard != proposerSlashing.ProposalData2.Shard {
		return errors.New("proposer slashing request does not have same shard number")
	}
	if proposerSlashing.ProposalData1.BlockHash.IsEqual(&proposerSlashing.ProposalData2.BlockHash) {
		return errors.New("proposer slashing request has same block hash (same proposal)")
	}
	if proposer.Status == ExitedWithPenalty {
		return errors.New("proposer is already exited")
	}
	hashProposal1, err := ssz.HashTreeRoot(proposerSlashing.ProposalData1)
	if err != nil {
		return err
	}
	hashProposal2, err := ssz.HashTreeRoot(proposerSlashing.ProposalData2)
	if err != nil {
		return err
	}
	pub, err := proposer.GetPublicKey()
	if err != nil {
		return err
	}
	sigProposal2, err := bls.DeserializeSignature(proposerSlashing.ProposalSignature2)
	if err != nil {
		return err
	}
	valid, err := bls.VerifySig(pub, hashProposal2[:], sigProposal2, bls.DomainProposal)
	if err != nil {
		return err
	}
	if !valid {
		return errors.New("invalid proposer signature")
	}
	sigProposal1, err := bls.DeserializeSignature(proposerSlashing.ProposalSignature1)
	if err != nil {
		return err
	}
	valid, err = bls.VerifySig(pub, hashProposal1[:], sigProposal1, bls.DomainProposal)
	if err != nil {
		return err
	}
	if !valid {
		return errors.New("invalid proposer signature")
	}
	return s.UpdateValidatorStatus(proposerSlashing.ProposerIndex, ExitedWithPenalty, config)
}
func ( s * State ) applyProposerSlashing ( proposerSlashing ProposerSlashing , config * config . Config ) error { if proposerSlashing . ProposerIndex >= uint32 ( len ( s . ValidatorRegistry ) ) { return errors . New ( " " ) } proposer := & s . ValidatorRegistry [ proposerSlashing . ProposerIndex ] if proposerSlashing . ProposalData1 . Slot != proposerSlashing . ProposalData2 . Slot { return errors . New ( " " ) } if proposerSlashing . ProposalData1 . Shard != proposerSlashing . ProposalData2 . Shard { return errors . New ( " " ) } if proposerSlashing . ProposalData1 . BlockHash . IsEqual ( & proposerSlashing . ProposalData2 . BlockHash ) { return errors . New ( " " ) } if proposer . Status == ExitedWithPenalty { return errors . New ( " " ) } hashProposal1 , err := ssz . HashTreeRoot ( proposerSlashing . ProposalData1 ) if err != nil { return err } hashProposal2 , err := ssz . HashTreeRoot ( proposerSlashing . ProposalData2 ) if err != nil { return err } pub , err := proposer . GetPublicKey ( ) if err != nil { return err } sigProposal2 , err := bls . DeserializeSignature ( proposerSlashing . ProposalSignature2 ) if err != nil { return err } valid , err := bls . VerifySig ( pub , hashProposal2 [ : ] , sigProposal2 , bls . DomainProposal ) if err != nil { return err } if ! valid { return errors . New ( " " ) } sigProposal1 , err := bls . DeserializeSignature ( proposerSlashing . ProposalSignature1 ) if err != nil { return err } valid , err = bls . VerifySig ( pub , hashProposal1 [ : ] , sigProposal1 , bls . DomainProposal ) if err != nil { return err } if ! valid { return errors . New ( " " ) } return s . UpdateValidatorStatus ( proposerSlashing . ProposerIndex , ExitedWithPenalty , config ) }
applyProposerSlashing applies a proposer slashing if valid.
applyProposerSlashing applies a proposer slashing if valid .