Skip to content

feat(pbs): add builder SSZ flow #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ alloy = { version = "0.8.0", features = [
] }
ssz_types = "0.8"
ethereum_serde_utils = "0.7.0"
ethereum_ssz = "0.7"
ethereum_ssz_derive = "0.7"

# networking
axum = { version = "0.8.1", features = ["macros"] }
Expand Down Expand Up @@ -101,3 +103,5 @@ derive_more = { version = "1.0.0", features = [
"deref",
"display",
] }
mediatype = "0.19.13"
bytes = "1.6"
4 changes: 4 additions & 0 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ publish = false
# ethereum
alloy.workspace = true
ssz_types.workspace = true
ethereum_ssz.workspace = true
ethereum_ssz_derive.workspace = true
ethereum_serde_utils.workspace = true

# networking
Expand Down Expand Up @@ -49,6 +51,8 @@ url.workspace = true
rand.workspace = true
bimap.workspace = true
derive_more.workspace = true
mediatype.workspace = true
bytes.workspace = true

unicode-normalization.workspace = true
base64.workspace = true
7 changes: 4 additions & 3 deletions crates/common/src/pbs/types/beacon_block.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use alloy::{primitives::B256, rpc::types::beacon::BlsSignature};
use serde::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};

use super::{
blinded_block_body::BlindedBeaconBlockBody, blobs_bundle::BlobsBundle,
execution_payload::ExecutionPayload, spec::DenebSpec, utils::VersionedResponse,
};

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Decode)]
/// Sent to relays in submit_block
pub struct SignedBlindedBeaconBlock {
pub message: BlindedBeaconBlock,
Expand All @@ -19,7 +20,7 @@ impl SignedBlindedBeaconBlock {
}
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Decode)]
pub struct BlindedBeaconBlock {
#[serde(with = "serde_utils::quoted_u64")]
pub slot: u64,
Expand All @@ -33,7 +34,7 @@ pub struct BlindedBeaconBlock {
/// Returned by relay in submit_block
pub type SubmitBlindedBlockResponse = VersionedResponse<PayloadAndBlobs>;

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode)]
pub struct PayloadAndBlobs {
pub execution_payload: ExecutionPayload<DenebSpec>,
pub blobs_bundle: Option<BlobsBundle<DenebSpec>>,
Expand Down
35 changes: 18 additions & 17 deletions crates/common/src/pbs/types/blinded_block_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ use alloy::{
rpc::types::beacon::{BlsPublicKey, BlsSignature},
};
use serde::{Deserialize, Serialize};
use ssz_derive::Decode;
use ssz_types::{typenum, BitList, BitVector, FixedVector, VariableList};

use super::{
execution_payload::ExecutionPayloadHeader, kzg::KzgCommitments, spec::EthSpec, utils::*,
};
use crate::utils::as_str;

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Decode)]
pub struct BlindedBeaconBlockBody<T: EthSpec> {
pub randao_reveal: BlsSignature,
pub eth1_data: Eth1Data,
Expand All @@ -27,15 +28,15 @@ pub struct BlindedBeaconBlockBody<T: EthSpec> {
pub blob_kzg_commitments: KzgCommitments<T>,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Decode)]
pub struct Eth1Data {
pub deposit_root: B256,
#[serde(with = "serde_utils::quoted_u64")]
pub deposit_count: u64,
pub block_hash: B256,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Decode)]
pub struct BeaconBlockHeader {
#[serde(with = "serde_utils::quoted_u64")]
pub slot: u64,
Expand All @@ -46,39 +47,39 @@ pub struct BeaconBlockHeader {
pub body_root: B256,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Decode)]
pub struct SignedBeaconBlockHeader {
pub message: BeaconBlockHeader,
pub signature: BlsSignature,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Decode)]
pub struct BlsToExecutionChange {
#[serde(with = "as_str")]
pub validator_index: u64,
pub from_bls_pubkey: BlsPublicKey,
pub to_execution_address: Address,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Decode)]
pub struct SignedBlsToExecutionChange {
pub message: BlsToExecutionChange,
pub signature: BlsSignature,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Decode)]
pub struct ProposerSlashing {
pub signed_header_1: SignedBeaconBlockHeader,
pub signed_header_2: SignedBeaconBlockHeader,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Decode)]
pub struct AttesterSlashing<T: EthSpec> {
pub attestation_1: IndexedAttestation<T>,
pub attestation_2: IndexedAttestation<T>,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Decode)]
#[serde(bound = "T: EthSpec")]
pub struct IndexedAttestation<T: EthSpec> {
/// Lists validator registry indices, not committee indices.
Expand All @@ -88,7 +89,7 @@ pub struct IndexedAttestation<T: EthSpec> {
pub signature: BlsSignature,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Decode)]
pub struct AttestationData {
#[serde(with = "serde_utils::quoted_u64")]
pub slot: u64,
Expand All @@ -101,28 +102,28 @@ pub struct AttestationData {
pub target: Checkpoint,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Decode)]
pub struct Checkpoint {
#[serde(with = "serde_utils::quoted_u64")]
pub epoch: u64,
pub root: B256,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, Decode)]
#[serde(bound = "T: EthSpec")]
pub struct Attestation<T: EthSpec> {
pub aggregation_bits: BitList<T::MaxValidatorsPerCommittee>,
pub data: AttestationData,
pub signature: BlsSignature,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Decode)]
pub struct Deposit {
pub proof: FixedVector<B256, typenum::U33>, // put this in EthSpec?
pub data: DepositData,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Decode)]
pub struct DepositData {
pub pubkey: BlsPublicKey,
pub withdrawal_credentials: B256,
Expand All @@ -131,13 +132,13 @@ pub struct DepositData {
pub signature: BlsSignature,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Decode)]
pub struct SignedVoluntaryExit {
pub message: VoluntaryExit,
pub signature: BlsSignature,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Decode)]
pub struct VoluntaryExit {
/// Earliest epoch when voluntary exit can be processed.
#[serde(with = "serde_utils::quoted_u64")]
Expand All @@ -146,7 +147,7 @@ pub struct VoluntaryExit {
pub validator_index: u64,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Decode)]
#[serde(bound = "T: EthSpec")]
pub struct SyncAggregate<T: EthSpec> {
pub sync_committee_bits: BitVector<T::SyncCommitteeSize>,
Expand Down
3 changes: 2 additions & 1 deletion crates/common/src/pbs/types/blobs_bundle.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use serde::{Deserialize, Serialize};
use ssz_derive::Encode;
use ssz_types::{FixedVector, VariableList};

use super::{
kzg::{KzgCommitments, KzgProofs},
spec::EthSpec,
};

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode)]
#[serde(bound = "T: EthSpec")]
pub struct BlobsBundle<T: EthSpec> {
pub commitments: KzgCommitments<T>,
Expand Down
7 changes: 4 additions & 3 deletions crates/common/src/pbs/types/execution_payload.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use alloy::primitives::{b256, Address, B256, U256};
use serde::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};
use ssz_types::{FixedVector, VariableList};
use tree_hash_derive::TreeHash;

Expand All @@ -9,7 +10,7 @@ use crate::utils::as_str;
pub const EMPTY_TX_ROOT_HASH: B256 =
b256!("7ffe241ea60187fdb0187bfa22de35d1f9bed7ab061d9401fd47e34a54fbede1");

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode)]
pub struct ExecutionPayload<T: EthSpec> {
pub parent_hash: B256,
pub fee_recipient: Address,
Expand Down Expand Up @@ -46,7 +47,7 @@ pub type Transactions<T> = VariableList<
>;
pub type Transaction<N> = VariableList<u8, N>;

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode)]
pub struct Withdrawal {
#[serde(with = "serde_utils::quoted_u64")]
pub index: u64,
Expand All @@ -57,7 +58,7 @@ pub struct Withdrawal {
pub amount: u64,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, TreeHash)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, TreeHash, Encode, Decode)]
pub struct ExecutionPayloadHeader<T: EthSpec> {
pub parent_hash: B256,
pub fee_recipient: Address,
Expand Down
5 changes: 3 additions & 2 deletions crates/common/src/pbs/types/get_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use alloy::{
rpc::types::beacon::{BlsPublicKey, BlsSignature},
};
use serde::{Deserialize, Serialize};
use ssz_derive::Encode;
use tree_hash_derive::TreeHash;

use super::{
Expand Down Expand Up @@ -37,13 +38,13 @@ impl GetHeaderResponse {
}
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode)]
pub struct SignedExecutionPayloadHeader {
pub message: ExecutionPayloadHeaderMessage,
pub signature: BlsSignature,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, TreeHash)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, TreeHash, Encode)]
pub struct ExecutionPayloadHeaderMessage {
pub header: ExecutionPayloadHeader<DenebSpec>,
pub blob_kzg_commitments: KzgCommitments<DenebSpec>,
Expand Down
Loading
Loading