mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-18 21:38:31 +00:00
Whole Bunch of Changes Sorry
This commit is contained in:
@@ -8,8 +8,9 @@ use superstruct::superstruct;
|
||||
use test_random_derive::TestRandom;
|
||||
use tree_hash_derive::TreeHash;
|
||||
|
||||
// in all likelihood, this will be superstructed so might as well start early eh?
|
||||
#[superstruct(
|
||||
variants(EIP7732),
|
||||
variants(EIP7732, NextFork),
|
||||
variant_attributes(
|
||||
derive(
|
||||
Debug,
|
||||
@@ -27,6 +28,10 @@ use tree_hash_derive::TreeHash;
|
||||
serde(bound = "E: EthSpec", deny_unknown_fields),
|
||||
arbitrary(bound = "E: EthSpec")
|
||||
),
|
||||
ref_attributes(
|
||||
derive(Debug, PartialEq, TreeHash),
|
||||
tree_hash(enum_behaviour = "transparent")
|
||||
),
|
||||
cast_error(ty = "Error", expr = "BeaconStateError::IncorrectStateVariant"),
|
||||
partial_getter_error(ty = "Error", expr = "BeaconStateError::IncorrectStateVariant")
|
||||
)]
|
||||
@@ -41,12 +46,32 @@ use tree_hash_derive::TreeHash;
|
||||
pub struct ExecutionEnvelope<E: EthSpec> {
|
||||
#[superstruct(only(EIP7732), partial_getter(rename = "payload_eip7732"))]
|
||||
pub payload: ExecutionPayloadEIP7732<E>,
|
||||
#[superstruct(only(NextFork), partial_getter(rename = "payload_next_fork"))]
|
||||
pub payload: ExecutionPayloadEIP7732<E>,
|
||||
pub execution_requests: ExecutionRequests<E>,
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
#[superstruct(getter(copy))]
|
||||
pub builder_index: u64,
|
||||
#[superstruct(getter(copy))]
|
||||
pub beacon_block_root: Hash256,
|
||||
pub blob_kzg_commitments: KzgCommitments<E>,
|
||||
pub payment_withheld: bool,
|
||||
#[superstruct(getter(copy))]
|
||||
pub payload_withheld: bool,
|
||||
#[superstruct(getter(copy))]
|
||||
pub state_root: Hash256,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> SignedRoot for ExecutionEnvelopeEIP7732<E> {}
|
||||
impl<'a, E: EthSpec> SignedRoot for ExecutionEnvelopeRef<'a, E> {}
|
||||
|
||||
impl<'a, E: EthSpec> ExecutionEnvelopeRef<'a, E> {
|
||||
pub fn payload(&self) -> ExecutionPayloadRef<'a, E> {
|
||||
match self {
|
||||
ExecutionEnvelopeRef::EIP7732(envelope) => {
|
||||
ExecutionPayloadRef::EIP7732(&envelope.payload)
|
||||
}
|
||||
ExecutionEnvelopeRef::NextFork(envelope) => {
|
||||
ExecutionPayloadRef::EIP7732(&envelope.payload)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +172,9 @@ pub use crate::eth_spec::EthSpecId;
|
||||
pub use crate::execution_bid::ExecutionBid;
|
||||
pub use crate::execution_block_hash::ExecutionBlockHash;
|
||||
pub use crate::execution_block_header::{EncodableExecutionBlockHeader, ExecutionBlockHeader};
|
||||
pub use crate::execution_envelope::{ExecutionEnvelope, ExecutionEnvelopeEIP7732};
|
||||
pub use crate::execution_envelope::{
|
||||
ExecutionEnvelope, ExecutionEnvelopeEIP7732, ExecutionEnvelopeRef,
|
||||
};
|
||||
pub use crate::execution_payload::{
|
||||
ExecutionPayload, ExecutionPayloadBellatrix, ExecutionPayloadCapella, ExecutionPayloadDeneb,
|
||||
ExecutionPayloadEIP7732, ExecutionPayloadElectra, ExecutionPayloadRef, Transaction,
|
||||
|
||||
@@ -7,8 +7,9 @@ use superstruct::superstruct;
|
||||
use test_random_derive::TestRandom;
|
||||
use tree_hash_derive::TreeHash;
|
||||
|
||||
// in all likelihood, this will be superstructed so might as well start early eh?
|
||||
#[superstruct(
|
||||
variants(EIP7732),
|
||||
variants(EIP7732, NextFork),
|
||||
variant_attributes(
|
||||
derive(
|
||||
Debug,
|
||||
@@ -40,5 +41,51 @@ use tree_hash_derive::TreeHash;
|
||||
pub struct SignedExecutionEnvelope<E: EthSpec> {
|
||||
#[superstruct(only(EIP7732), partial_getter(rename = "message_eip7732"))]
|
||||
pub message: ExecutionEnvelopeEIP7732<E>,
|
||||
#[superstruct(only(NextFork), partial_getter(rename = "message_next_fork"))]
|
||||
pub message: crate::execution_envelope::ExecutionEnvelopeNextFork<E>,
|
||||
pub signature: Signature,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> SignedExecutionEnvelope<E> {
|
||||
pub fn message(&self) -> ExecutionEnvelopeRef<E> {
|
||||
match self {
|
||||
SignedExecutionEnvelope::EIP7732(ref signed) => {
|
||||
ExecutionEnvelopeRef::EIP7732(&signed.message)
|
||||
}
|
||||
SignedExecutionEnvelope::NextFork(ref signed) => {
|
||||
ExecutionEnvelopeRef::NextFork(&signed.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Verify `self.signature`.
|
||||
///
|
||||
/// The `parent_state` is the post-state of the beacon block with
|
||||
/// block_root = self.message.beacon_block_root
|
||||
pub fn verify_signature(
|
||||
&self,
|
||||
parent_state: &BeaconState<E>,
|
||||
genesis_validators_root: Hash256,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<bool, BeaconStateError> {
|
||||
let domain = spec.get_domain(
|
||||
parent_state.current_epoch(),
|
||||
Domain::BeaconBuilder,
|
||||
&parent_state.fork(),
|
||||
genesis_validators_root,
|
||||
);
|
||||
let pubkey = parent_state
|
||||
.validators()
|
||||
.get(self.message().builder_index() as usize)
|
||||
.and_then(|v| {
|
||||
let pk: Option<PublicKey> = v.pubkey.decompress().ok();
|
||||
pk
|
||||
})
|
||||
.ok_or_else(|| {
|
||||
BeaconStateError::UnknownValidator(self.message().builder_index() as usize)
|
||||
})?;
|
||||
let message = self.message().signing_root(domain);
|
||||
|
||||
Ok(self.signature().verify(&pubkey, message))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user