mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 02:42:38 +00:00
Updated for queueless withdrawals spec
This commit is contained in:
@@ -49,6 +49,10 @@ pub enum BlockProcessingError {
|
||||
index: usize,
|
||||
reason: ExitInvalid,
|
||||
},
|
||||
BlsExecutionChangeInvalid {
|
||||
index: usize,
|
||||
reason: BlsExecutionChangeInvalid,
|
||||
},
|
||||
SyncAggregateInvalid {
|
||||
reason: SyncAggregateInvalid,
|
||||
},
|
||||
@@ -180,7 +184,8 @@ impl_into_block_processing_error_with_index!(
|
||||
IndexedAttestationInvalid,
|
||||
AttestationInvalid,
|
||||
DepositInvalid,
|
||||
ExitInvalid
|
||||
ExitInvalid,
|
||||
BlsExecutionChangeInvalid
|
||||
);
|
||||
|
||||
pub type HeaderValidationError = BlockOperationError<HeaderInvalid>;
|
||||
@@ -190,6 +195,7 @@ pub type AttestationValidationError = BlockOperationError<AttestationInvalid>;
|
||||
pub type SyncCommitteeMessageValidationError = BlockOperationError<SyncAggregateInvalid>;
|
||||
pub type DepositValidationError = BlockOperationError<DepositInvalid>;
|
||||
pub type ExitValidationError = BlockOperationError<ExitInvalid>;
|
||||
pub type BlsExecutionChangeValidationError = BlockOperationError<BlsExecutionChangeInvalid>;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub enum BlockOperationError<T> {
|
||||
@@ -405,6 +411,18 @@ pub enum ExitInvalid {
|
||||
SignatureSetError(SignatureSetError),
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub enum BlsExecutionChangeInvalid {
|
||||
/// The specified validator is not in the state's validator registry.
|
||||
ValidatorUnknown(u64),
|
||||
/// Validator does not have BLS Withdrawal credentials before this change
|
||||
NonBlsWithdrawalCredentials,
|
||||
/// Provided BLS pubkey does not match withdrawal credentials
|
||||
WithdrawalCredentialsMismatch,
|
||||
/// The signature is invalid
|
||||
BadSignature,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub enum SyncAggregateInvalid {
|
||||
/// One or more of the aggregate public keys is invalid.
|
||||
|
||||
@@ -33,6 +33,9 @@ pub fn process_operations<'a, T: EthSpec, Payload: AbstractExecPayload<T>>(
|
||||
process_attestations(state, block_body, verify_signatures, ctxt, spec)?;
|
||||
process_deposits(state, block_body.deposits(), spec)?;
|
||||
process_exits(state, block_body.voluntary_exits(), verify_signatures, spec)?;
|
||||
#[cfg(all(feature = "withdrawals", feature = "withdrawals-processing"))]
|
||||
process_bls_to_execution_changes(state, block_body, verify_signatures, spec)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -279,6 +282,46 @@ pub fn process_exits<T: EthSpec>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Validates each `bls_to_execution_change` and updates the state
|
||||
///
|
||||
/// Returns `Ok(())` if the validation and state updates completed successfully. Otherwise returs
|
||||
/// an `Err` describing the invalid object or cause of failure.
|
||||
///
|
||||
/// https://github.com/ethereum/consensus-specs/blob/dev/specs/capella/beacon-chain.md#new-process_bls_to_execution_change
|
||||
#[cfg(all(feature = "withdrawals", feature = "withdrawals-processing"))]
|
||||
pub fn process_bls_to_execution_changes<'a, T: EthSpec, Payload: AbstractExecPayload<T>>(
|
||||
state: &mut BeaconState<T>,
|
||||
block_body: BeaconBlockBodyRef<'a, T, Payload>,
|
||||
verify_signatures: VerifySignatures,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<(), BlockProcessingError> {
|
||||
match block_body {
|
||||
BeaconBlockBodyRef::Base(_)
|
||||
| BeaconBlockBodyRef::Altair(_)
|
||||
| BeaconBlockBodyRef::Merge(_) => Ok(()),
|
||||
BeaconBlockBodyRef::Capella(_) | BeaconBlockBodyRef::Eip4844(_) => {
|
||||
for (i, signed_address_change) in block_body.bls_to_execution_changes()?.enumerate() {
|
||||
verify_bls_to_execution_change(
|
||||
state,
|
||||
&signed_address_change,
|
||||
verify_signatures,
|
||||
spec,
|
||||
)
|
||||
.map_err(|e| e.into_with_index(i))?;
|
||||
|
||||
state
|
||||
.get_validator_mut(signed_address_change.message.validator_index)?
|
||||
.change_withdrawal_credentials(
|
||||
signed_address_change.message.to_execution_address,
|
||||
spec,
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Validates each `Deposit` and updates the state, short-circuiting on an invalid object.
|
||||
///
|
||||
/// Returns `Ok(())` if the validation and state updates completed successfully, otherwise returns
|
||||
|
||||
@@ -11,8 +11,8 @@ use types::{
|
||||
BeaconStateError, ChainSpec, DepositData, Domain, Epoch, EthSpec, Fork, Hash256,
|
||||
InconsistentFork, IndexedAttestation, ProposerSlashing, PublicKey, PublicKeyBytes, Signature,
|
||||
SignedAggregateAndProof, SignedBeaconBlock, SignedBeaconBlockHeader,
|
||||
SignedContributionAndProof, SignedRoot, SignedVoluntaryExit, SigningData, Slot, SyncAggregate,
|
||||
SyncAggregatorSelectionData, Unsigned,
|
||||
SignedBlsToExecutionChange, SignedContributionAndProof, SignedRoot, SignedVoluntaryExit,
|
||||
SigningData, Slot, SyncAggregate, SyncAggregatorSelectionData, Unsigned,
|
||||
};
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
@@ -156,6 +156,33 @@ where
|
||||
))
|
||||
}
|
||||
|
||||
pub fn bls_execution_change_signature_set<'a, T: EthSpec>(
|
||||
state: &'a BeaconState<T>,
|
||||
signed_address_change: &'a SignedBlsToExecutionChange,
|
||||
spec: &'a ChainSpec,
|
||||
) -> Result<SignatureSet<'a>> {
|
||||
let domain = spec.get_domain(
|
||||
state.current_epoch(),
|
||||
Domain::BlsToExecutionChange,
|
||||
&state.fork(),
|
||||
state.genesis_validators_root(),
|
||||
);
|
||||
let message = signed_address_change.message.signing_root(domain);
|
||||
let signing_key = Cow::Owned(
|
||||
signed_address_change
|
||||
.message
|
||||
.from_bls_pubkey
|
||||
.decompress()
|
||||
.map_err(|_| Error::PublicKeyDecompressionFailed)?,
|
||||
);
|
||||
|
||||
Ok(SignatureSet::single_pubkey(
|
||||
&signed_address_change.signature,
|
||||
signing_key,
|
||||
message,
|
||||
))
|
||||
}
|
||||
|
||||
/// A signature set that is valid if the block proposers randao reveal signature is correct.
|
||||
pub fn randao_signature_set<'a, T, F, Payload: AbstractExecPayload<T>>(
|
||||
state: &'a BeaconState<T>,
|
||||
|
||||
Reference in New Issue
Block a user