diff --git a/consensus/types/src/eth_spec.rs b/consensus/types/src/eth_spec.rs index 09ef8e3c1a..b03094243b 100644 --- a/consensus/types/src/eth_spec.rs +++ b/consensus/types/src/eth_spec.rs @@ -160,6 +160,11 @@ pub trait EthSpec: type MaxAttestationsElectra: Unsigned + Clone + Sync + Send + Debug + PartialEq; type MaxWithdrawalRequestsPerPayload: Unsigned + Clone + Sync + Send + Debug + PartialEq; + /* + * New in EIP-7736 + */ + type PTCSize: Unsigned + Clone + Sync + Send + Debug + PartialEq; + fn default_spec() -> ChainSpec; fn spec_name() -> EthSpecId; @@ -438,6 +443,7 @@ impl EthSpec for MainnetEthSpec { type MaxAttesterSlashingsElectra = U1; type MaxAttestationsElectra = U8; type MaxWithdrawalRequestsPerPayload = U16; + type PTCSize = U512; fn default_spec() -> ChainSpec { ChainSpec::mainnet() @@ -503,7 +509,8 @@ impl EthSpec for MinimalEthSpec { PendingBalanceDepositsLimit, MaxConsolidationRequestsPerPayload, MaxAttesterSlashingsElectra, - MaxAttestationsElectra + MaxAttestationsElectra, + PTCSize }); fn default_spec() -> ChainSpec { @@ -569,6 +576,7 @@ impl EthSpec for GnosisEthSpec { type FieldElementsPerExtBlob = U8192; type BytesPerCell = U2048; type KzgCommitmentsInclusionProofDepth = U4; + type PTCSize = U512; fn default_spec() -> ChainSpec { ChainSpec::gnosis() diff --git a/consensus/types/src/execution_payload_envelope.rs b/consensus/types/src/execution_payload_envelope.rs new file mode 100644 index 0000000000..ae8ffd1d32 --- /dev/null +++ b/consensus/types/src/execution_payload_envelope.rs @@ -0,0 +1,50 @@ +use crate::test_utils::TestRandom; +use crate::*; +use beacon_block_body::KzgCommitments; +use derivative::Derivative; +use serde::{Deserialize, Serialize}; +use ssz_derive::{Decode, Encode}; +use superstruct::superstruct; +use test_random_derive::TestRandom; +use tree_hash_derive::TreeHash; + +#[superstruct( + variants(EIP7732), + variant_attributes( + derive( + Debug, + Clone, + Serialize, + Deserialize, + Encode, + Decode, + TreeHash, + TestRandom, + Derivative, + arbitrary::Arbitrary + ), + derivative(PartialEq, Hash(bound = "E: EthSpec")), + serde(bound = "E: EthSpec", deny_unknown_fields), + arbitrary(bound = "E: EthSpec") + ), + cast_error(ty = "Error", expr = "BeaconStateError::IncorrectStateVariant"), + partial_getter_error(ty = "Error", expr = "BeaconStateError::IncorrectStateVariant") +)] +#[derive( + Debug, Clone, Serialize, Encode, Deserialize, TreeHash, Derivative, arbitrary::Arbitrary, +)] +#[derivative(PartialEq, Hash(bound = "E: EthSpec"))] +#[serde(bound = "E: EthSpec", untagged)] +#[arbitrary(bound = "E: EthSpec")] +#[ssz(enum_behaviour = "transparent")] +#[tree_hash(enum_behaviour = "transparent")] +pub struct ExecutionPayloadEnvelope { + #[superstruct(only(EIP7732), partial_getter(rename = "payload_eip7732"))] + pub payload: ExecutionPayloadEIP7732, + #[serde(with = "serde_utils::quoted_u64")] + pub builder_index: u64, + pub beacon_block_root: Hash256, + pub blob_kzg_commitments: KzgCommitments, + pub payment_withheld: bool, + pub state_root: Hash256, +} diff --git a/consensus/types/src/indexed_payload_attestation.rs b/consensus/types/src/indexed_payload_attestation.rs new file mode 100644 index 0000000000..0cc62ed08a --- /dev/null +++ b/consensus/types/src/indexed_payload_attestation.rs @@ -0,0 +1,34 @@ +use crate::test_utils::TestRandom; +use crate::*; +use serde::{Deserialize, Serialize}; +use ssz_derive::{Decode, Encode}; +use test_random_derive::TestRandom; +use tree_hash_derive::TreeHash; + +#[derive( + arbitrary::Arbitrary, + TestRandom, + TreeHash, + Debug, + Clone, + PartialEq, + Encode, + Decode, + Serialize, + Deserialize, +)] +#[serde(bound = "E: EthSpec", deny_unknown_fields)] +#[arbitrary(bound = "E: EthSpec")] +pub struct IndexedPayloadAttestation { + #[serde(with = "ssz_types::serde_utils::quoted_u64_var_list")] + pub attesting_indices: VariableList, + pub data: PayloadAttestationData, + signature: AggregateSignature, +} + +#[cfg(test)] +mod tests { + use super::*; + + ssz_and_tree_hash_tests!(IndexedPayloadAttestation); +} diff --git a/consensus/types/src/lib.rs b/consensus/types/src/lib.rs index 0ce0c94974..423f3effb5 100644 --- a/consensus/types/src/lib.rs +++ b/consensus/types/src/lib.rs @@ -42,6 +42,7 @@ pub mod eth_spec; pub mod execution_bid; pub mod execution_block_hash; pub mod execution_payload; +pub mod execution_payload_envelope; pub mod execution_payload_header; pub mod fork; pub mod fork_data; @@ -51,10 +52,15 @@ pub mod graffiti; pub mod historical_batch; pub mod historical_summary; pub mod indexed_attestation; +pub mod indexed_payload_attestation; pub mod light_client_bootstrap; pub mod light_client_finality_update; pub mod light_client_optimistic_update; pub mod light_client_update; +pub mod payload; +pub mod payload_attestation; +pub mod payload_attestation_data; +pub mod payload_attestation_message; pub mod pending_attestation; pub mod pending_balance_deposit; pub mod pending_consolidation; @@ -69,6 +75,8 @@ pub mod signed_beacon_block; pub mod signed_beacon_block_header; pub mod signed_bls_to_execution_change; pub mod signed_contribution_and_proof; +pub mod signed_execution_bid; +pub mod signed_execution_payload_envelope; pub mod signed_voluntary_exit; pub mod signing_data; pub mod sync_committee_subscription; @@ -86,7 +94,6 @@ pub mod execution_block_header; pub mod execution_requests; pub mod fork_context; pub mod participation_flags; -pub mod payload; pub mod preset; pub mod slot_epoch; pub mod subnet_id; @@ -169,6 +176,9 @@ pub use crate::execution_payload::{ ExecutionPayloadEIP7732, ExecutionPayloadElectra, ExecutionPayloadRef, Transaction, Transactions, Withdrawals, }; +pub use crate::execution_payload_envelope::{ + ExecutionPayloadEnvelope, ExecutionPayloadEnvelopeEIP7732, +}; pub use crate::execution_payload_header::{ ExecutionPayloadHeader, ExecutionPayloadHeaderBellatrix, ExecutionPayloadHeaderCapella, ExecutionPayloadHeaderDeneb, ExecutionPayloadHeaderElectra, ExecutionPayloadHeaderRef, @@ -185,6 +195,7 @@ pub use crate::historical_batch::HistoricalBatch; pub use crate::indexed_attestation::{ IndexedAttestation, IndexedAttestationBase, IndexedAttestationElectra, IndexedAttestationRef, }; +pub use crate::indexed_payload_attestation::IndexedPayloadAttestation; pub use crate::light_client_bootstrap::{ LightClientBootstrap, LightClientBootstrapAltair, LightClientBootstrapCapella, LightClientBootstrapDeneb, LightClientBootstrapElectra, @@ -213,6 +224,9 @@ pub use crate::payload::{ FullPayload, FullPayloadBellatrix, FullPayloadCapella, FullPayloadDeneb, FullPayloadElectra, FullPayloadRef, OwnedExecPayload, }; +pub use crate::payload_attestation::PayloadAttestation; +pub use crate::payload_attestation_data::PayloadAttestationData; +pub use crate::payload_attestation_message::PayloadAttestationMessage; pub use crate::pending_attestation::PendingAttestation; pub use crate::pending_balance_deposit::PendingBalanceDeposit; pub use crate::pending_consolidation::PendingConsolidation; @@ -238,6 +252,8 @@ pub use crate::signed_beacon_block::{ pub use crate::signed_beacon_block_header::SignedBeaconBlockHeader; pub use crate::signed_bls_to_execution_change::SignedBlsToExecutionChange; pub use crate::signed_contribution_and_proof::SignedContributionAndProof; +pub use crate::signed_execution_bid::SignedExecutionBid; +pub use crate::signed_execution_payload_envelope::SignedExecutionPayloadEnvelope; pub use crate::signed_voluntary_exit::SignedVoluntaryExit; pub use crate::signing_data::{SignedRoot, SigningData}; pub use crate::slot_epoch::{Epoch, Slot}; diff --git a/consensus/types/src/payload_attestation.rs b/consensus/types/src/payload_attestation.rs new file mode 100644 index 0000000000..67224fd8bd --- /dev/null +++ b/consensus/types/src/payload_attestation.rs @@ -0,0 +1,34 @@ +use crate::test_utils::TestRandom; +use crate::*; +use serde::{Deserialize, Serialize}; +use ssz_derive::{Decode, Encode}; +use test_random_derive::TestRandom; +use tree_hash_derive::TreeHash; + +#[derive( + arbitrary::Arbitrary, + TestRandom, + TreeHash, + Debug, + Clone, + PartialEq, + Eq, + Encode, + Decode, + Serialize, + Deserialize, +)] +#[serde(bound = "E: EthSpec", deny_unknown_fields)] +#[arbitrary(bound = "E: EthSpec")] +pub struct PayloadAttestation { + pub aggregation_bits: BitList, + pub slot: Slot, + pub payload_status: u8, +} + +#[cfg(test)] +mod tests { + use super::*; + + ssz_and_tree_hash_tests!(PayloadAttestation); +} diff --git a/consensus/types/src/payload_attestation_data.rs b/consensus/types/src/payload_attestation_data.rs new file mode 100644 index 0000000000..9546713e2c --- /dev/null +++ b/consensus/types/src/payload_attestation_data.rs @@ -0,0 +1,32 @@ +use crate::test_utils::TestRandom; +use crate::*; +use serde::{Deserialize, Serialize}; +use ssz_derive::{Decode, Encode}; +use test_random_derive::TestRandom; +use tree_hash_derive::TreeHash; + +#[derive( + arbitrary::Arbitrary, + TestRandom, + TreeHash, + Debug, + Clone, + PartialEq, + Eq, + Encode, + Decode, + Serialize, + Deserialize, +)] +pub struct PayloadAttestationData { + pub beacon_block_root: Hash256, + pub slot: Slot, + pub payload_status: u8, +} + +#[cfg(test)] +mod tests { + use super::*; + + ssz_and_tree_hash_tests!(PayloadAttestationData); +} diff --git a/consensus/types/src/payload_attestation_message.rs b/consensus/types/src/payload_attestation_message.rs new file mode 100644 index 0000000000..7178b0f175 --- /dev/null +++ b/consensus/types/src/payload_attestation_message.rs @@ -0,0 +1,32 @@ +use crate::test_utils::TestRandom; +use crate::*; +use serde::{Deserialize, Serialize}; +use ssz_derive::{Decode, Encode}; +use test_random_derive::TestRandom; +use tree_hash_derive::TreeHash; + +#[derive( + arbitrary::Arbitrary, + TestRandom, + TreeHash, + Debug, + Clone, + PartialEq, + Encode, + Decode, + Serialize, + Deserialize, +)] +pub struct PayloadAttestationMessage { + #[serde(with = "serde_utils::quoted_u64")] + pub validator_index: u64, + pub data: PayloadAttestationData, + pub signature: AggregateSignature, +} + +#[cfg(test)] +mod tests { + use super::*; + + ssz_and_tree_hash_tests!(PayloadAttestationMessage); +} diff --git a/consensus/types/src/signed_execution_bid.rs b/consensus/types/src/signed_execution_bid.rs new file mode 100644 index 0000000000..04fef02c4d --- /dev/null +++ b/consensus/types/src/signed_execution_bid.rs @@ -0,0 +1,30 @@ +use crate::test_utils::TestRandom; +use crate::*; +use serde::{Deserialize, Serialize}; +use ssz_derive::{Decode, Encode}; +use test_random_derive::TestRandom; +use tree_hash_derive::TreeHash; + +#[derive( + arbitrary::Arbitrary, + TestRandom, + TreeHash, + Debug, + Clone, + PartialEq, + Encode, + Decode, + Serialize, + Deserialize, +)] +pub struct SignedExecutionBid { + pub message: ExecutionBid, + pub signature: Signature, +} + +#[cfg(test)] +mod tests { + use super::*; + + ssz_and_tree_hash_tests!(SignedExecutionBid); +} diff --git a/consensus/types/src/signed_execution_payload_envelope.rs b/consensus/types/src/signed_execution_payload_envelope.rs new file mode 100644 index 0000000000..5e265ab83c --- /dev/null +++ b/consensus/types/src/signed_execution_payload_envelope.rs @@ -0,0 +1,44 @@ +use crate::test_utils::TestRandom; +use crate::*; +use derivative::Derivative; +use serde::{Deserialize, Serialize}; +use ssz_derive::{Decode, Encode}; +use superstruct::superstruct; +use test_random_derive::TestRandom; +use tree_hash_derive::TreeHash; + +#[superstruct( + variants(EIP7732), + variant_attributes( + derive( + Debug, + Clone, + Serialize, + Deserialize, + Encode, + Decode, + TreeHash, + TestRandom, + Derivative, + arbitrary::Arbitrary + ), + derivative(PartialEq, Hash(bound = "E: EthSpec")), + serde(bound = "E: EthSpec", deny_unknown_fields), + arbitrary(bound = "E: EthSpec") + ), + cast_error(ty = "Error", expr = "BeaconStateError::IncorrectStateVariant"), + partial_getter_error(ty = "Error", expr = "BeaconStateError::IncorrectStateVariant") +)] +#[derive( + Debug, Clone, Serialize, Encode, Deserialize, TreeHash, Derivative, arbitrary::Arbitrary, +)] +#[derivative(PartialEq, Hash(bound = "E: EthSpec"))] +#[serde(bound = "E: EthSpec", untagged)] +#[arbitrary(bound = "E: EthSpec")] +#[ssz(enum_behaviour = "transparent")] +#[tree_hash(enum_behaviour = "transparent")] +pub struct SignedExecutionPayloadEnvelope { + #[superstruct(only(EIP7732), partial_getter(rename = "message_eip7732"))] + pub message: ExecutionPayloadEnvelopeEIP7732, + pub signature: Signature, +}