From c1c5dc0a649a3c6c3de30ed5b58c298331baa305 Mon Sep 17 00:00:00 2001 From: ethDreamer <37123614+ethDreamer@users.noreply.github.com> Date: Thu, 13 Oct 2022 17:07:32 -0500 Subject: [PATCH] Fixed some stuff in state processing (#3640) --- consensus/state_processing/src/genesis.rs | 2 +- .../src/per_block_processing.rs | 21 ++++++++-------- .../block_signature_verifier.rs | 24 +++++++++---------- .../process_operations.rs | 4 ++-- .../per_block_processing/signature_sets.rs | 12 +++++----- 5 files changed, 32 insertions(+), 31 deletions(-) diff --git a/consensus/state_processing/src/genesis.rs b/consensus/state_processing/src/genesis.rs index fb2c9bfa7..32160a481 100644 --- a/consensus/state_processing/src/genesis.rs +++ b/consensus/state_processing/src/genesis.rs @@ -67,7 +67,7 @@ pub fn initialize_beacon_state_from_eth1( state.fork_mut().previous_version = spec.bellatrix_fork_version; // Override latest execution payload header. - // See https://github.com/ethereum/consensus-specs/blob/v1.1.0/specs/merge/beacon-chain.md#testing + // See https://github.com/ethereum/consensus-specs/blob/v1.1.0/specs/bellatrix/beacon-chain.md#testing *state.latest_execution_payload_header_mut()? = execution_payload_header.unwrap_or_default(); } diff --git a/consensus/state_processing/src/per_block_processing.rs b/consensus/state_processing/src/per_block_processing.rs index e409372dd..417e963ed 100644 --- a/consensus/state_processing/src/per_block_processing.rs +++ b/consensus/state_processing/src/per_block_processing.rs @@ -87,7 +87,7 @@ pub enum VerifyBlockRoot { /// re-calculating the root when it is already known. Note `block_root` should be equal to the /// tree hash root of the block, NOT the signing root of the block. This function takes /// care of mixing in the domain. -pub fn per_block_processing>( +pub fn per_block_processing>( state: &mut BeaconState, signed_block: &SignedBeaconBlock, block_root: Option, @@ -232,7 +232,7 @@ pub fn process_block_header( /// Verifies the signature of a block. /// /// Spec v0.12.1 -pub fn verify_block_signature>( +pub fn verify_block_signature>( state: &BeaconState, block: &SignedBeaconBlock, block_root: Option, @@ -255,7 +255,7 @@ pub fn verify_block_signature>( /// Verifies the `randao_reveal` against the block's proposer pubkey and updates /// `state.latest_randao_mixes`. -pub fn process_randao>( +pub fn process_randao>( state: &mut BeaconState, block: BeaconBlockRef<'_, T, Payload>, verify_signatures: VerifySignatures, @@ -376,30 +376,31 @@ pub fn process_execution_payload>( /// the merge has happened or if we're on the transition block. Thus we don't want to propagate /// errors from the `BeaconState` being an earlier variant than `BeaconStateMerge` as we'd have to /// repeaetedly write code to treat these errors as false. -/// https://github.com/ethereum/consensus-specs/blob/dev/specs/merge/beacon-chain.md#is_merge_transition_complete +/// https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#is_merge_transition_complete pub fn is_merge_transition_complete(state: &BeaconState) -> bool { state .latest_execution_payload_header() .map(|header| *header != >::default()) .unwrap_or(false) } -/// https://github.com/ethereum/consensus-specs/blob/dev/specs/merge/beacon-chain.md#is_merge_transition_block -pub fn is_merge_transition_block>( +/// https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#is_merge_transition_block +pub fn is_merge_transition_block>( state: &BeaconState, body: BeaconBlockBodyRef, ) -> bool { body.execution_payload() - .map(|payload| !is_merge_transition_complete(state) && *payload != Payload::default()) + .map(|payload| !is_merge_transition_complete(state) && !payload.is_default()) .unwrap_or(false) } -/// https://github.com/ethereum/consensus-specs/blob/dev/specs/merge/beacon-chain.md#is_execution_enabled -pub fn is_execution_enabled>( +/// https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#is_execution_enabled +pub fn is_execution_enabled>( state: &BeaconState, body: BeaconBlockBodyRef, ) -> bool { is_merge_transition_block(state, body) || is_merge_transition_complete(state) } -/// https://github.com/ethereum/consensus-specs/blob/dev/specs/merge/beacon-chain.md#compute_timestamp_at_slot + +/// https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#compute_timestamp_at_slot pub fn compute_timestamp_at_slot( state: &BeaconState, spec: &ChainSpec, diff --git a/consensus/state_processing/src/per_block_processing/block_signature_verifier.rs b/consensus/state_processing/src/per_block_processing/block_signature_verifier.rs index 78205ca92..cbfb5eeaf 100644 --- a/consensus/state_processing/src/per_block_processing/block_signature_verifier.rs +++ b/consensus/state_processing/src/per_block_processing/block_signature_verifier.rs @@ -7,8 +7,8 @@ use bls::{verify_signature_sets, PublicKey, PublicKeyBytes, SignatureSet}; use rayon::prelude::*; use std::borrow::Cow; use types::{ - BeaconState, BeaconStateError, ChainSpec, EthSpec, ExecPayload, Hash256, IndexedAttestation, - SignedBeaconBlock, + AbstractExecPayload, BeaconState, BeaconStateError, ChainSpec, EthSpec, Hash256, + IndexedAttestation, SignedBeaconBlock, }; pub type Result = std::result::Result; @@ -117,7 +117,7 @@ where /// contains invalid signatures on deposits._ /// /// See `Self::verify` for more detail. - pub fn verify_entire_block>( + pub fn verify_entire_block>( state: &'a BeaconState, get_pubkey: F, decompressor: D, @@ -131,7 +131,7 @@ where } /// Includes all signatures on the block (except the deposit signatures) for verification. - pub fn include_all_signatures>( + pub fn include_all_signatures>( &mut self, block: &'a SignedBeaconBlock, block_root: Option, @@ -144,7 +144,7 @@ where /// Includes all signatures on the block (except the deposit signatures and the proposal /// signature) for verification. - pub fn include_all_signatures_except_proposal>( + pub fn include_all_signatures_except_proposal>( &mut self, block: &'a SignedBeaconBlock, ) -> Result<()> { @@ -160,7 +160,7 @@ where } /// Includes the block signature for `self.block` for verification. - pub fn include_block_proposal>( + pub fn include_block_proposal>( &mut self, block: &'a SignedBeaconBlock, block_root: Option, @@ -177,7 +177,7 @@ where } /// Includes the randao signature for `self.block` for verification. - pub fn include_randao_reveal>( + pub fn include_randao_reveal>( &mut self, block: &'a SignedBeaconBlock, ) -> Result<()> { @@ -192,7 +192,7 @@ where } /// Includes all signatures in `self.block.body.proposer_slashings` for verification. - pub fn include_proposer_slashings>( + pub fn include_proposer_slashings>( &mut self, block: &'a SignedBeaconBlock, ) -> Result<()> { @@ -221,7 +221,7 @@ where } /// Includes all signatures in `self.block.body.attester_slashings` for verification. - pub fn include_attester_slashings>( + pub fn include_attester_slashings>( &mut self, block: &'a SignedBeaconBlock, ) -> Result<()> { @@ -250,7 +250,7 @@ where } /// Includes all signatures in `self.block.body.attestations` for verification. - pub fn include_attestations>( + pub fn include_attestations>( &mut self, block: &'a SignedBeaconBlock, ) -> Result>> { @@ -289,7 +289,7 @@ where } /// Includes all signatures in `self.block.body.voluntary_exits` for verification. - pub fn include_exits>( + pub fn include_exits>( &mut self, block: &'a SignedBeaconBlock, ) -> Result<()> { @@ -313,7 +313,7 @@ where } /// Include the signature of the block's sync aggregate (if it exists) for verification. - pub fn include_sync_aggregate>( + pub fn include_sync_aggregate>( &mut self, block: &'a SignedBeaconBlock, ) -> Result<()> { diff --git a/consensus/state_processing/src/per_block_processing/process_operations.rs b/consensus/state_processing/src/per_block_processing/process_operations.rs index 13c4b9123..b1f857b57 100644 --- a/consensus/state_processing/src/per_block_processing/process_operations.rs +++ b/consensus/state_processing/src/per_block_processing/process_operations.rs @@ -9,7 +9,7 @@ use crate::VerifySignatures; use safe_arith::SafeArith; use types::consts::altair::{PARTICIPATION_FLAG_WEIGHTS, PROPOSER_WEIGHT, WEIGHT_DENOMINATOR}; -pub fn process_operations<'a, T: EthSpec, Payload: ExecPayload>( +pub fn process_operations<'a, T: EthSpec, Payload: AbstractExecPayload>( state: &mut BeaconState, block_body: BeaconBlockBodyRef<'a, T, Payload>, proposer_index: u64, @@ -219,7 +219,7 @@ pub fn process_attester_slashings( } /// Wrapper function to handle calling the correct version of `process_attestations` based on /// the fork. -pub fn process_attestations<'a, T: EthSpec, Payload: ExecPayload>( +pub fn process_attestations<'a, T: EthSpec, Payload: AbstractExecPayload>( state: &mut BeaconState, block_body: BeaconBlockBodyRef<'a, T, Payload>, proposer_index: u64, diff --git a/consensus/state_processing/src/per_block_processing/signature_sets.rs b/consensus/state_processing/src/per_block_processing/signature_sets.rs index 5ce1bfddd..82a33acd7 100644 --- a/consensus/state_processing/src/per_block_processing/signature_sets.rs +++ b/consensus/state_processing/src/per_block_processing/signature_sets.rs @@ -7,9 +7,9 @@ use ssz::DecodeError; use std::borrow::Cow; use tree_hash::TreeHash; use types::{ - AggregateSignature, AttesterSlashing, BeaconBlockRef, BeaconState, BeaconStateError, ChainSpec, - DepositData, Domain, Epoch, EthSpec, ExecPayload, Fork, Hash256, InconsistentFork, - IndexedAttestation, ProposerSlashing, PublicKey, PublicKeyBytes, Signature, + AbstractExecPayload, AggregateSignature, AttesterSlashing, BeaconBlockRef, BeaconState, + BeaconStateError, ChainSpec, DepositData, Domain, Epoch, EthSpec, ExecPayload, Fork, Hash256, + InconsistentFork, IndexedAttestation, ProposerSlashing, PublicKey, PublicKeyBytes, Signature, SignedAggregateAndProof, SignedBeaconBlock, SignedBeaconBlockHeader, SignedContributionAndProof, SignedRoot, SignedVoluntaryExit, SigningData, Slot, SyncAggregate, SyncAggregatorSelectionData, Unsigned, @@ -71,7 +71,7 @@ where } /// A signature set that is valid if a block was signed by the expected block producer. -pub fn block_proposal_signature_set<'a, T, F, Payload: ExecPayload>( +pub fn block_proposal_signature_set<'a, T, F, Payload: AbstractExecPayload>( state: &'a BeaconState, get_pubkey: F, signed_block: &'a SignedBeaconBlock, @@ -108,7 +108,7 @@ where /// Unlike `block_proposal_signature_set` this does **not** check that the proposer index is /// correct according to the shuffling. It should only be used if no suitable `BeaconState` is /// available. -pub fn block_proposal_signature_set_from_parts<'a, T, F, Payload: ExecPayload>( +pub fn block_proposal_signature_set_from_parts<'a, T, F, Payload: AbstractExecPayload>( signed_block: &'a SignedBeaconBlock, block_root: Option, proposer_index: u64, @@ -152,7 +152,7 @@ where } /// A signature set that is valid if the block proposers randao reveal signature is correct. -pub fn randao_signature_set<'a, T, F, Payload: ExecPayload>( +pub fn randao_signature_set<'a, T, F, Payload: AbstractExecPayload>( state: &'a BeaconState, get_pubkey: F, block: BeaconBlockRef<'a, T, Payload>,