Skip to content
Snippets Groups Projects
Commit 4dc474e4 authored by Wei Tang's avatar Wei Tang
Browse files

beacon: process_proposer_slashing

parent c64cdfbe
Branches
No related merge requests found
use crate::primitives::*;
use crate::types::*;
use crate::{Config, BeaconState, Error};
use bm_le::tree_root;
impl<C: Config> BeaconState<C> {
/// Process eth1 data vote given in a block.
pub fn process_eth1_data(&mut self, body: &BeaconBlockBody<C>) {
self.eth1_data_votes.push(body.eth1_data.clone());
if self.eth1_data_votes.iter()
.filter(|d| d == &&body.eth1_data)
.count() * 2 >
C::slots_per_eth1_voting_period() as usize
{
self.eth1_data = body.eth1_data.clone();
}
}
}
mod header;
mod randao;
mod eth1;
mod operations;
mod proposer_slashing;
use crate::primitives::*;
use crate::types::*;
use crate::{Config, BeaconState, Error, utils};
use bm_le::tree_root;
impl<C: Config> BeaconState<C> {
/// Push a new `ProposerSlashing` to the state.
pub fn process_proposer_slashing(
&mut self,
proposer_slashing: ProposerSlashing
) -> Result<(), Error> {
if utils::epoch_of_slot::<C>(proposer_slashing.header_1.slot) !=
utils::epoch_of_slot::<C>(proposer_slashing.header_2.slot)
{
return Err(Error::ProposerSlashingInvalidSlot)
}
if proposer_slashing.header_1 == proposer_slashing.header_2 {
return Err(Error::ProposerSlashingSameHeader)
}
{
if proposer_slashing.proposer_index as usize >= self.validators.len() {
return Err(Error::ProposerSlashingInvalidProposerIndex)
}
let proposer = &self.validators[
proposer_slashing.proposer_index as usize
];
if !proposer.is_slashable(self.current_epoch()) {
return Err(Error::ProposerSlashingAlreadySlashed)
}
for header in &[&proposer_slashing.header_1, &proposer_slashing.header_2] {
let domain = self.domain(
C::domain_beacon_proposer(),
Some(utils::epoch_of_slot::<C>(header.slot))
);
if !C::bls_verify(
&proposer.pubkey,
&tree_root::<C::Digest, _>(&SigningBeaconBlockHeader::from((*header).clone())),
&header.signature,
domain,
) {
return Err(Error::ProposerSlashingInvalidSignature)
}
}
}
self.slash_validator(proposer_slashing.proposer_index, None)
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment