Skip to content

Commit

Permalink
Merge pull request #77 from jimmygchen/add-deneb-types
Browse files Browse the repository at this point in the history
Add support for Deneb EIP-4844 types (blobs support)
  • Loading branch information
ralexstokes authored Aug 3, 2023
2 parents e42adc3 + 81b0239 commit 9d88a23
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ members = ["bin/mev", "mev-boost-rs", "mev-relay-rs", "mev-build-rs", "mev-rs"]
default-members = ["bin/mev"]

[workspace.dependencies]
ethereum-consensus = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "e380108" }
beacon-api-client = { git = "https://github.com/ralexstokes/beacon-api-client", rev = "287d4dd" }
ethereum-consensus = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "56418ea" }
beacon-api-client = { git = "https://github.com/ralexstokes/beacon-api-client", rev = "56a290c" }
ssz_rs = "0.9.0"
1 change: 1 addition & 0 deletions mev-boost-rs/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ async fn propose_block(
assert_eq!(payload.parent_hash, parent_hash);
assert_eq!(payload.fee_recipient, proposer.fee_recipient);
}
_ => unimplemented!(),
}

beacon_node.check_status().await.unwrap();
Expand Down
1 change: 1 addition & 0 deletions mev-relay-rs/src/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ impl BlindedBlockProvider for Relay {
let signed_bid = capella::SignedBuilderBid { message: bid, signature };
Ok(SignedBuilderBid::Capella(signed_bid))
}
ExecutionPayloadHeader::Deneb(_header) => unimplemented!(),
}
}

Expand Down
3 changes: 3 additions & 0 deletions mev-rs/src/blinded_block_provider/api/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ impl Client {
SignedBlindedBeaconBlock::Capella(signed_block) => {
self.api.http_post("/eth/v1/builder/blinded_blocks", signed_block).await?
}
SignedBlindedBeaconBlock::Deneb(signed_block) => {
self.api.http_post("/eth/v1/builder/blinded_blocks", signed_block).await?
}
};

let result: ApiResult<VersionedValue<ExecutionPayload>> =
Expand Down
50 changes: 50 additions & 0 deletions mev-rs/src/engine_api_proxy/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use ethereum_consensus::{
bellatrix::mainnet::{
Transaction, BYTES_PER_LOGS_BLOOM, MAX_EXTRA_DATA_BYTES, MAX_TRANSACTIONS_PER_PAYLOAD,
},
deneb::mainnet::{Blob, MAX_BLOBS_PER_BLOCK},
kzg::{KzgCommitment, KzgProof},
primitives::{Bytes32, ExecutionAddress, Hash32},
ssz::{ByteList, ByteVector},
};
Expand Down Expand Up @@ -145,12 +147,23 @@ pub enum ExecutionPayload {

#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
// TODO: maybe rename this to `GetPayloadV2Response` for consistency with the V3 response type?
pub struct ExecutionPayloadWithValue {
pub execution_payload: ExecutionPayload,
#[serde(deserialize_with = "u256_from_be_hex")]
pub block_value: U256,
}

#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct GetPayloadV3Response {
pub execution_payload: ExecutionPayloadV3,
#[serde(deserialize_with = "u256_from_be_hex")]
pub block_value: U256,
pub blobs_bundle: BlobsBundleV1,
pub should_override_builder: bool,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(deny_unknown_fields)]
Expand Down Expand Up @@ -202,6 +215,43 @@ pub struct ExecutionPayloadV2 {
pub withdrawals: Vec<WithdrawalV1>,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ExecutionPayloadV3 {
pub parent_hash: Hash32,
pub fee_recipient: ExecutionAddress,
pub state_root: Bytes32,
pub receipts_root: Bytes32,
pub logs_bloom: ByteVector<BYTES_PER_LOGS_BLOOM>,
pub prev_randao: Bytes32,
#[serde(deserialize_with = "u64_from_hex")]
pub block_number: u64,
#[serde(deserialize_with = "u64_from_hex")]
pub gas_limit: u64,
#[serde(deserialize_with = "u64_from_hex")]
pub gas_used: u64,
#[serde(deserialize_with = "u64_from_hex")]
pub timestamp: u64,
pub extra_data: ByteList<MAX_EXTRA_DATA_BYTES>,
#[serde(deserialize_with = "u256_from_be_hex")]
pub base_fee_per_gas: U256,
pub block_hash: Hash32,
pub transactions: List<Transaction, MAX_TRANSACTIONS_PER_PAYLOAD>,
pub withdrawals: Vec<WithdrawalV1>,
#[serde(deserialize_with = "u64_from_hex")]
pub data_gas_used: u64,
#[serde(deserialize_with = "u64_from_hex")]
pub excess_data_gas: u64,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BlobsBundleV1 {
pub commitments: List<KzgCommitment, MAX_BLOBS_PER_BLOCK>,
pub proofs: List<KzgProof, MAX_BLOBS_PER_BLOCK>,
pub blobs: List<Blob, MAX_BLOBS_PER_BLOCK>,
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
61 changes: 61 additions & 0 deletions mev-rs/src/types/deneb.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
pub use ethereum_consensus::{builder::SignedValidatorRegistration, deneb::mainnet as spec};
use ethereum_consensus::{
deneb::mainnet::MAX_BLOBS_PER_BLOCK,
kzg::{KzgCommitment, KzgProof},
primitives::{BlsPublicKey, BlsSignature, Root, U256},
};
use ssz_rs::prelude::*;

// NOTE: type alias here to call out the important types clearly, in lieu of just `pub use ...`
pub type ExecutionPayload = spec::ExecutionPayload;
pub type ExecutionPayloadHeader = spec::ExecutionPayloadHeader;
pub type SignedBlindedBeaconBlock = spec::SignedBlindedBeaconBlock;
pub type SignedBlindedBlobSidecar = spec::SignedBlindedBlobSidecar;
pub type Blob = spec::Blob;

#[derive(Debug, Default, Clone, SimpleSerialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BuilderBid {
pub header: spec::ExecutionPayloadHeader,
pub blinded_blobs_bundle: BlindedBlobsBundle,
pub value: U256,
#[serde(rename = "pubkey")]
pub public_key: BlsPublicKey,
}

#[derive(Debug, Default, Clone, SimpleSerialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BlindedBlobsBundle {
pub commitments: List<KzgCommitment, MAX_BLOBS_PER_BLOCK>,
pub proofs: List<KzgProof, MAX_BLOBS_PER_BLOCK>,
pub blob_roots: List<Root, MAX_BLOBS_PER_BLOCK>,
}

#[derive(Debug, Default, Clone, SimpleSerialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SignedBuilderBid {
pub message: BuilderBid,
pub signature: BlsSignature,
}

#[derive(Debug, Default, Clone, SimpleSerialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SignedBlindedBlockAndBlobSidecars {
pub signed_blinded_block: SignedBlindedBeaconBlock,
pub signed_blinded_blob_sidecars: List<SignedBlindedBlobSidecar, MAX_BLOBS_PER_BLOCK>,
}

#[derive(Debug, Default, Clone, SimpleSerialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BlobsBundle {
pub commitments: List<KzgCommitment, MAX_BLOBS_PER_BLOCK>,
pub proofs: List<KzgProof, MAX_BLOBS_PER_BLOCK>,
pub blobs: List<Blob, MAX_BLOBS_PER_BLOCK>,
}

#[derive(Debug, Default, Clone, SimpleSerialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExecutionPayloadAndBlobsBundle {
pub execution_payload: ExecutionPayload,
pub blobs_bundle: BlobsBundle,
}
Loading

0 comments on commit 9d88a23

Please sign in to comment.