From 6ae62bcd5a93591bc5fbc268890992feb0a91fc0 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Fri, 17 Feb 2023 00:18:09 +1100 Subject: [PATCH 1/6] Add support for Deneb types --- Cargo.lock | 2 +- Cargo.toml | 3 +- mev-relay-rs/src/relay.rs | 18 ++++++- .../src/blinded_block_provider/api/client.rs | 5 +- mev-rs/src/types/deneb.rs | 31 +++++++++++ mev-rs/src/types/mod.rs | 53 +++++++++++++++++++ 6 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 mev-rs/src/types/deneb.rs diff --git a/Cargo.lock b/Cargo.lock index ec4afab1..94a8f657 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -800,7 +800,7 @@ dependencies = [ [[package]] name = "ethereum-consensus" version = "0.1.1" -source = "git+https://github.com/ralexstokes//ethereum-consensus?rev=ef89b4a#ef89b4a4ef97cdd53a66ddb52e554667aca0beb2" +source = "git+https://github.com/jimmygchen/ethereum-consensus?rev=4c82111#4c82111efe84a11ac0d4939d4ae166e1f1e3fac0" dependencies = [ "async-stream", "blst", diff --git a/Cargo.toml b/Cargo.toml index 799be735..1cdad087 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,8 @@ members = [ default-members = ["bin/mev"] [patch."https://github.com/ralexstokes/ethereum-consensus"] -ethereum-consensus = { git = "https://github.com/ralexstokes//ethereum-consensus", rev = "ef89b4a" } +# FIXME https://github.com/ralexstokes/ethereum-consensus/pull/170 +ethereum-consensus = { git = "https://github.com/jimmygchen/ethereum-consensus", rev = "4c82111" } [patch."https://github.com/ralexstokes/ssz-rs"] ssz-rs = { git = "https://github.com/ralexstokes//ssz-rs", rev = "45ff6f1" } diff --git a/mev-relay-rs/src/relay.rs b/mev-relay-rs/src/relay.rs index 738261da..aa848495 100644 --- a/mev-relay-rs/src/relay.rs +++ b/mev-relay-rs/src/relay.rs @@ -8,6 +8,7 @@ use ethereum_consensus::{ state_transition::Context, }; use mev_build_rs::NullBuilder; +use mev_rs::types::deneb; use mev_rs::{ signing::sign_builder_message, types::{ @@ -48,7 +49,7 @@ fn validate_execution_payload( // TODO allow for "adjustment cap" per the protocol rules // towards the proposer's preference if execution_payload.gas_limit() != preferences.gas_limit { - return Err(Error::InvalidGasLimit) + return Err(Error::InvalidGasLimit); } // verify payload is valid @@ -67,7 +68,7 @@ fn validate_signed_block( let local_block_hash = local_payload.block_hash(); let block_hash = signed_block.block_hash(); if block_hash != local_block_hash { - return Err(Error::UnknownBlock) + return Err(Error::UnknownBlock); } // OPTIONAL: @@ -202,6 +203,19 @@ impl BlindedBlockProvider for Relay { let signed_bid = capella::SignedBuilderBid { message: bid, signature }; Ok(SignedBuilderBid::Capella(signed_bid)) } + ExecutionPayloadHeader::Deneb(header) => { + let mut bid = deneb::BuilderBid { + header, + value, + public_key: self.public_key.clone(), + // FIXME: this is a placeholder + blinded_blob_sidecars: Default::default(), + }; + let signature = sign_builder_message(&mut bid, &self.secret_key, &self.context)?; + + let signed_bid = deneb::SignedBuilderBid { message: bid, signature }; + Ok(SignedBuilderBid::Deneb(signed_bid)) + } } } diff --git a/mev-rs/src/blinded_block_provider/api/client.rs b/mev-rs/src/blinded_block_provider/api/client.rs index 1c22d807..dc58880b 100644 --- a/mev-rs/src/blinded_block_provider/api/client.rs +++ b/mev-rs/src/blinded_block_provider/api/client.rs @@ -48,7 +48,7 @@ impl Client { let response = self.api.http_get(&target).await?; if response.status() == StatusCode::NO_CONTENT { - return Err(Error::NoBidPrepared(Box::new(bid_request.clone()))) + return Err(Error::NoBidPrepared(Box::new(bid_request.clone()))); } let result: ApiResult> = @@ -70,6 +70,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> = diff --git a/mev-rs/src/types/deneb.rs b/mev-rs/src/types/deneb.rs new file mode 100644 index 00000000..d904eda6 --- /dev/null +++ b/mev-rs/src/types/deneb.rs @@ -0,0 +1,31 @@ +use ethereum_consensus::primitives::{BlsPublicKey, BlsSignature, U256}; +pub use ethereum_consensus::{ + bellatrix::mainnet::MAX_TRANSACTIONS_PER_PAYLOAD, builder::SignedValidatorRegistration, + deneb::mainnet as spec, +}; +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 BlindedBlobSidecar = spec::BlindedBlobSidecar; +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 value: U256, + #[serde(rename = "pubkey")] + pub public_key: BlsPublicKey, + pub blinded_blob_sidecars: List, +} + +#[derive(Debug, Default, Clone, SimpleSerialize)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct SignedBuilderBid { + pub message: BuilderBid, + pub signature: BlsSignature, +} diff --git a/mev-rs/src/types/mod.rs b/mev-rs/src/types/mod.rs index 382764ad..16910d4f 100644 --- a/mev-rs/src/types/mod.rs +++ b/mev-rs/src/types/mod.rs @@ -1,5 +1,6 @@ pub mod bellatrix; pub mod capella; +pub mod deneb; use crate::signing::{ sign_builder_message, verify_signed_builder_message, verify_signed_consensus_message, @@ -34,6 +35,7 @@ impl std::fmt::Display for BidRequest { pub enum BuilderBid { Bellatrix(bellatrix::BuilderBid), Capella(capella::BuilderBid), + Deneb(deneb::BuilderBid), } impl From<(ExecutionPayloadHeader, U256, &BlsPublicKey)> for BuilderBid { @@ -51,6 +53,13 @@ impl From<(ExecutionPayloadHeader, U256, &BlsPublicKey)> for BuilderBid { value, public_key: public_key.clone(), }), + ExecutionPayloadHeader::Deneb(header) => BuilderBid::Deneb(deneb::BuilderBid { + header, + value, + public_key: public_key.clone(), + // FIXME: this is a placeholder for now + blinded_blob_sidecars: Default::default(), + }), } } } @@ -78,6 +87,12 @@ impl BuilderBid { }); Ok(signed_bid) } + BuilderBid::Deneb(mut bid) => { + let signature = sign_builder_message(&mut bid, secret_key, context)?; + let signed_bid = + SignedBuilderBid::Deneb(deneb::SignedBuilderBid { message: bid, signature }); + Ok(signed_bid) + } } } } @@ -89,6 +104,7 @@ impl BuilderBid { pub enum SignedBuilderBid { Bellatrix(bellatrix::SignedBuilderBid), Capella(capella::SignedBuilderBid), + Deneb(deneb::SignedBuilderBid), } impl std::fmt::Display for SignedBuilderBid { @@ -104,6 +120,7 @@ impl SignedBuilderBid { match self { Self::Bellatrix(bid) => &bid.message.value, Self::Capella(bid) => &bid.message.value, + Self::Deneb(bid) => &bid.message.value, } } @@ -111,6 +128,7 @@ impl SignedBuilderBid { match self { Self::Bellatrix(bid) => &bid.message.header.block_hash, Self::Capella(bid) => &bid.message.header.block_hash, + Self::Deneb(bid) => &bid.message.header.block_hash, } } @@ -118,6 +136,7 @@ impl SignedBuilderBid { match self { Self::Bellatrix(bid) => &bid.message.header.parent_hash, Self::Capella(bid) => &bid.message.header.parent_hash, + Self::Deneb(bid) => &bid.message.header.parent_hash, } } @@ -141,6 +160,15 @@ impl SignedBuilderBid { context, ) } + Self::Deneb(bid) => { + let public_key = bid.message.public_key.clone(); + verify_signed_builder_message( + &mut bid.message, + &bid.signature, + &public_key, + context, + ) + } } } } @@ -152,6 +180,7 @@ impl SignedBuilderBid { pub enum SignedBlindedBeaconBlock { Bellatrix(bellatrix::SignedBlindedBeaconBlock), Capella(capella::SignedBlindedBeaconBlock), + Deneb(deneb::SignedBlindedBeaconBlock), } impl SignedBlindedBeaconBlock { @@ -159,6 +188,7 @@ impl SignedBlindedBeaconBlock { match self { Self::Bellatrix(block) => block.message.slot, Self::Capella(block) => block.message.slot, + Self::Deneb(block) => block.message.slot, } } @@ -166,6 +196,7 @@ impl SignedBlindedBeaconBlock { match self { Self::Bellatrix(block) => block.message.proposer_index, Self::Capella(block) => block.message.proposer_index, + Self::Deneb(block) => block.message.proposer_index, } } @@ -173,6 +204,7 @@ impl SignedBlindedBeaconBlock { match self { Self::Bellatrix(block) => &block.message.body.execution_payload_header.block_hash, Self::Capella(block) => &block.message.body.execution_payload_header.block_hash, + Self::Deneb(block) => &block.message.body.execution_payload_header.block_hash, } } @@ -180,6 +212,7 @@ impl SignedBlindedBeaconBlock { match self { Self::Bellatrix(block) => &block.message.body.execution_payload_header.parent_hash, Self::Capella(block) => &block.message.body.execution_payload_header.parent_hash, + Self::Deneb(block) => &block.message.body.execution_payload_header.parent_hash, } } @@ -212,6 +245,17 @@ impl SignedBlindedBeaconBlock { Some(genesis_validators_root), ) } + Self::Deneb(block) => { + let slot = block.message.slot; + verify_signed_consensus_message( + &mut block.message, + &block.signature, + public_key, + context, + Some(slot), + Some(genesis_validators_root), + ) + } } } } @@ -223,6 +267,7 @@ impl SignedBlindedBeaconBlock { pub enum ExecutionPayload { Bellatrix(bellatrix::ExecutionPayload), Capella(capella::ExecutionPayload), + Deneb(deneb::ExecutionPayload), } impl ExecutionPayload { @@ -230,6 +275,7 @@ impl ExecutionPayload { match self { Self::Bellatrix(payload) => &payload.block_hash, Self::Capella(payload) => &payload.block_hash, + Self::Deneb(payload) => &payload.block_hash, } } @@ -237,6 +283,7 @@ impl ExecutionPayload { match self { Self::Bellatrix(payload) => payload.gas_limit, Self::Capella(payload) => payload.gas_limit, + Self::Deneb(payload) => payload.gas_limit, } } } @@ -254,6 +301,10 @@ impl TryFrom<&mut ExecutionPayload> for ExecutionPayloadHeader { let header = capella::ExecutionPayloadHeader::try_from(payload)?; Ok(Self::Capella(header)) } + ExecutionPayload::Deneb(payload) => { + let header = deneb::ExecutionPayloadHeader::try_from(payload)?; + Ok(Self::Deneb(header)) + } } } } @@ -262,6 +313,7 @@ impl TryFrom<&mut ExecutionPayload> for ExecutionPayloadHeader { pub enum ExecutionPayloadHeader { Bellatrix(bellatrix::ExecutionPayloadHeader), Capella(capella::ExecutionPayloadHeader), + Deneb(deneb::ExecutionPayloadHeader), } impl ExecutionPayloadHeader { @@ -269,6 +321,7 @@ impl ExecutionPayloadHeader { match self { Self::Bellatrix(header) => &header.block_hash, Self::Capella(header) => &header.block_hash, + Self::Deneb(header) => &header.block_hash, } } } From bacd022bafbd585b0dced6d8b04daabf66808388 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Wed, 12 Jul 2023 23:48:09 +1000 Subject: [PATCH 2/6] Update Deneb types to latest builder spec --- mev-boost-rs/tests/integration.rs | 1 + mev-relay-rs/src/relay.rs | 11 ++-- .../src/blinded_block_provider/api/client.rs | 2 +- mev-rs/src/engine_api_proxy/types.rs | 50 +++++++++++++++++++ mev-rs/src/types/deneb.rs | 28 ++++++++--- mev-rs/src/types/mod.rs | 4 +- 6 files changed, 80 insertions(+), 16 deletions(-) diff --git a/mev-boost-rs/tests/integration.rs b/mev-boost-rs/tests/integration.rs index e86b914b..8720c884 100644 --- a/mev-boost-rs/tests/integration.rs +++ b/mev-boost-rs/tests/integration.rs @@ -249,6 +249,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(); diff --git a/mev-relay-rs/src/relay.rs b/mev-relay-rs/src/relay.rs index 2a3428d1..da6d2a1b 100644 --- a/mev-relay-rs/src/relay.rs +++ b/mev-relay-rs/src/relay.rs @@ -8,11 +8,10 @@ use ethereum_consensus::{ state_transition::Context, }; use mev_build_rs::NullBuilder; -use mev_rs::types::deneb; use mev_rs::{ signing::sign_builder_message, types::{ - bellatrix, capella, BidRequest, ExecutionPayload, ExecutionPayloadHeader, + bellatrix, capella, deneb, BidRequest, ExecutionPayload, ExecutionPayloadHeader, SignedBlindedBeaconBlock, SignedBuilderBid, SignedValidatorRegistration, }, BlindedBlockProvider, Error, ValidatorRegistry, @@ -49,7 +48,7 @@ fn validate_execution_payload( // TODO allow for "adjustment cap" per the protocol rules // towards the proposer's preference if execution_payload.gas_limit() != preferences.gas_limit { - return Err(Error::InvalidGasLimit); + return Err(Error::InvalidGasLimit) } // verify payload is valid @@ -68,7 +67,7 @@ fn validate_signed_block( let local_block_hash = local_payload.block_hash(); let block_hash = signed_block.block_hash(); if block_hash != local_block_hash { - return Err(Error::UnknownBlock); + return Err(Error::UnknownBlock) } // OPTIONAL: @@ -204,10 +203,10 @@ impl BlindedBlockProvider for Relay { ExecutionPayloadHeader::Deneb(header) => { let mut bid = deneb::BuilderBid { header, + // FIXME: this is a placeholder + blinded_blobs_bundle: Default::default(), value, public_key: self.public_key.clone(), - // FIXME: this is a placeholder - blinded_blob_sidecars: Default::default(), }; let signature = sign_builder_message(&mut bid, &self.secret_key, &self.context)?; diff --git a/mev-rs/src/blinded_block_provider/api/client.rs b/mev-rs/src/blinded_block_provider/api/client.rs index 79546978..521d5985 100644 --- a/mev-rs/src/blinded_block_provider/api/client.rs +++ b/mev-rs/src/blinded_block_provider/api/client.rs @@ -49,7 +49,7 @@ impl Client { let response = self.api.http_get(&target).await?; if response.status() == StatusCode::NO_CONTENT { - return Err(Error::NoBidPrepared(Box::new(bid_request.clone()))); + return Err(Error::NoBidPrepared(Box::new(bid_request.clone()))) } let result: ApiResult> = diff --git a/mev-rs/src/engine_api_proxy/types.rs b/mev-rs/src/engine_api_proxy/types.rs index 92a6b46d..9a5f75f3 100644 --- a/mev-rs/src/engine_api_proxy/types.rs +++ b/mev-rs/src/engine_api_proxy/types.rs @@ -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}, }; @@ -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)] @@ -202,6 +215,43 @@ pub struct ExecutionPayloadV2 { pub withdrawals: Vec, } +#[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, + 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, + #[serde(deserialize_with = "u256_from_be_hex")] + pub base_fee_per_gas: U256, + pub block_hash: Hash32, + pub transactions: List, + pub withdrawals: Vec, + #[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, + pub proofs: List, + pub blobs: List, +} + #[cfg(test)] mod tests { use super::*; diff --git a/mev-rs/src/types/deneb.rs b/mev-rs/src/types/deneb.rs index d904eda6..3300743d 100644 --- a/mev-rs/src/types/deneb.rs +++ b/mev-rs/src/types/deneb.rs @@ -1,7 +1,8 @@ -use ethereum_consensus::primitives::{BlsPublicKey, BlsSignature, U256}; -pub use ethereum_consensus::{ - bellatrix::mainnet::MAX_TRANSACTIONS_PER_PAYLOAD, builder::SignedValidatorRegistration, - deneb::mainnet as spec, +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::*; @@ -9,18 +10,24 @@ use ssz_rs::prelude::*; pub type ExecutionPayload = spec::ExecutionPayload; pub type ExecutionPayloadHeader = spec::ExecutionPayloadHeader; pub type SignedBlindedBeaconBlock = spec::SignedBlindedBeaconBlock; -pub type BlindedBlobSidecar = spec::BlindedBlobSidecar; 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, - pub blinded_blob_sidecars: List, +} + +#[derive(Debug, Default, Clone, SimpleSerialize)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct BlindedBlobsBundle { + pub commitments: List, + pub proofs: List, + pub blob_roots: List, } #[derive(Debug, Default, Clone, SimpleSerialize)] @@ -29,3 +36,10 @@ 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, +} diff --git a/mev-rs/src/types/mod.rs b/mev-rs/src/types/mod.rs index 4f9e787a..381b9a0f 100644 --- a/mev-rs/src/types/mod.rs +++ b/mev-rs/src/types/mod.rs @@ -55,10 +55,10 @@ impl From<(ExecutionPayloadHeader, U256, &BlsPublicKey)> for BuilderBid { }), ExecutionPayloadHeader::Deneb(header) => BuilderBid::Deneb(deneb::BuilderBid { header, + // FIXME: this is a placeholder for now + blinded_blobs_bundle: Default::default(), value, public_key: public_key.clone(), - // FIXME: this is a placeholder for now - blinded_blob_sidecars: Default::default(), }), } } From 7a19d12cbf8113e01a5f222e5affd99366cf1240 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Wed, 12 Jul 2023 23:55:37 +1000 Subject: [PATCH 3/6] Replace FIXMEs with `unimplemented!` --- mev-relay-rs/src/relay.rs | 18 +++--------------- mev-rs/src/types/mod.rs | 8 +------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/mev-relay-rs/src/relay.rs b/mev-relay-rs/src/relay.rs index da6d2a1b..5eb492fb 100644 --- a/mev-relay-rs/src/relay.rs +++ b/mev-relay-rs/src/relay.rs @@ -48,7 +48,7 @@ fn validate_execution_payload( // TODO allow for "adjustment cap" per the protocol rules // towards the proposer's preference if execution_payload.gas_limit() != preferences.gas_limit { - return Err(Error::InvalidGasLimit) + return Err(Error::InvalidGasLimit); } // verify payload is valid @@ -67,7 +67,7 @@ fn validate_signed_block( let local_block_hash = local_payload.block_hash(); let block_hash = signed_block.block_hash(); if block_hash != local_block_hash { - return Err(Error::UnknownBlock) + return Err(Error::UnknownBlock); } // OPTIONAL: @@ -200,19 +200,7 @@ impl BlindedBlockProvider for Relay { let signed_bid = capella::SignedBuilderBid { message: bid, signature }; Ok(SignedBuilderBid::Capella(signed_bid)) } - ExecutionPayloadHeader::Deneb(header) => { - let mut bid = deneb::BuilderBid { - header, - // FIXME: this is a placeholder - blinded_blobs_bundle: Default::default(), - value, - public_key: self.public_key.clone(), - }; - let signature = sign_builder_message(&mut bid, &self.secret_key, &self.context)?; - - let signed_bid = deneb::SignedBuilderBid { message: bid, signature }; - Ok(SignedBuilderBid::Deneb(signed_bid)) - } + ExecutionPayloadHeader::Deneb(header) => unimplemented!(), } } diff --git a/mev-rs/src/types/mod.rs b/mev-rs/src/types/mod.rs index 381b9a0f..6b16bf4a 100644 --- a/mev-rs/src/types/mod.rs +++ b/mev-rs/src/types/mod.rs @@ -53,13 +53,7 @@ impl From<(ExecutionPayloadHeader, U256, &BlsPublicKey)> for BuilderBid { value, public_key: public_key.clone(), }), - ExecutionPayloadHeader::Deneb(header) => BuilderBid::Deneb(deneb::BuilderBid { - header, - // FIXME: this is a placeholder for now - blinded_blobs_bundle: Default::default(), - value, - public_key: public_key.clone(), - }), + ExecutionPayloadHeader::Deneb(header) => unimplemented!(), } } } From c9e6f0f2dc1daf663d2139ae4229cb2eb7c4973d Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Wed, 12 Jul 2023 23:58:27 +1000 Subject: [PATCH 4/6] Fix lints --- mev-relay-rs/src/relay.rs | 8 ++++---- mev-rs/src/types/mod.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mev-relay-rs/src/relay.rs b/mev-relay-rs/src/relay.rs index 5eb492fb..fe0e2f52 100644 --- a/mev-relay-rs/src/relay.rs +++ b/mev-relay-rs/src/relay.rs @@ -11,7 +11,7 @@ use mev_build_rs::NullBuilder; use mev_rs::{ signing::sign_builder_message, types::{ - bellatrix, capella, deneb, BidRequest, ExecutionPayload, ExecutionPayloadHeader, + bellatrix, capella, BidRequest, ExecutionPayload, ExecutionPayloadHeader, SignedBlindedBeaconBlock, SignedBuilderBid, SignedValidatorRegistration, }, BlindedBlockProvider, Error, ValidatorRegistry, @@ -48,7 +48,7 @@ fn validate_execution_payload( // TODO allow for "adjustment cap" per the protocol rules // towards the proposer's preference if execution_payload.gas_limit() != preferences.gas_limit { - return Err(Error::InvalidGasLimit); + return Err(Error::InvalidGasLimit) } // verify payload is valid @@ -67,7 +67,7 @@ fn validate_signed_block( let local_block_hash = local_payload.block_hash(); let block_hash = signed_block.block_hash(); if block_hash != local_block_hash { - return Err(Error::UnknownBlock); + return Err(Error::UnknownBlock) } // OPTIONAL: @@ -200,7 +200,7 @@ impl BlindedBlockProvider for Relay { let signed_bid = capella::SignedBuilderBid { message: bid, signature }; Ok(SignedBuilderBid::Capella(signed_bid)) } - ExecutionPayloadHeader::Deneb(header) => unimplemented!(), + ExecutionPayloadHeader::Deneb(_header) => unimplemented!(), } } diff --git a/mev-rs/src/types/mod.rs b/mev-rs/src/types/mod.rs index 6b16bf4a..88292386 100644 --- a/mev-rs/src/types/mod.rs +++ b/mev-rs/src/types/mod.rs @@ -53,7 +53,7 @@ impl From<(ExecutionPayloadHeader, U256, &BlsPublicKey)> for BuilderBid { value, public_key: public_key.clone(), }), - ExecutionPayloadHeader::Deneb(header) => unimplemented!(), + ExecutionPayloadHeader::Deneb(_header) => unimplemented!(), } } } From 16b9797e12e0cf3f3f185fa0e4e363093751387d Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Thu, 13 Jul 2023 00:16:58 +1000 Subject: [PATCH 5/6] Add `ExecutionPayloadAndBlobsBundle` --- mev-rs/src/types/deneb.rs | 16 +++++++++++++++ mev-rs/src/types/mod.rs | 41 ++++++++++++++++++++++++++++----------- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/mev-rs/src/types/deneb.rs b/mev-rs/src/types/deneb.rs index 3300743d..aae0505d 100644 --- a/mev-rs/src/types/deneb.rs +++ b/mev-rs/src/types/deneb.rs @@ -11,6 +11,7 @@ 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))] @@ -43,3 +44,18 @@ pub struct SignedBlindedBlockAndBlobSidecars { pub signed_blinded_block: SignedBlindedBeaconBlock, pub signed_blinded_blob_sidecars: List, } + +#[derive(Debug, Default, Clone, SimpleSerialize)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct BlobsBundle { + pub commitments: List, + pub proofs: List, + pub blobs: List, +} + +#[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, +} diff --git a/mev-rs/src/types/mod.rs b/mev-rs/src/types/mod.rs index 88292386..a5e5a4dc 100644 --- a/mev-rs/src/types/mod.rs +++ b/mev-rs/src/types/mod.rs @@ -174,7 +174,7 @@ impl SignedBuilderBid { pub enum SignedBlindedBeaconBlock { Bellatrix(bellatrix::SignedBlindedBeaconBlock), Capella(capella::SignedBlindedBeaconBlock), - Deneb(deneb::SignedBlindedBeaconBlock), + Deneb(deneb::SignedBlindedBlockAndBlobSidecars), } impl SignedBlindedBeaconBlock { @@ -182,7 +182,7 @@ impl SignedBlindedBeaconBlock { match self { Self::Bellatrix(block) => block.message.slot, Self::Capella(block) => block.message.slot, - Self::Deneb(block) => block.message.slot, + Self::Deneb(block_and_blobs) => block_and_blobs.signed_blinded_block.message.slot, } } @@ -190,7 +190,9 @@ impl SignedBlindedBeaconBlock { match self { Self::Bellatrix(block) => block.message.proposer_index, Self::Capella(block) => block.message.proposer_index, - Self::Deneb(block) => block.message.proposer_index, + Self::Deneb(block_and_blobs) => { + block_and_blobs.signed_blinded_block.message.proposer_index + } } } @@ -198,7 +200,14 @@ impl SignedBlindedBeaconBlock { match self { Self::Bellatrix(block) => &block.message.body.execution_payload_header.block_hash, Self::Capella(block) => &block.message.body.execution_payload_header.block_hash, - Self::Deneb(block) => &block.message.body.execution_payload_header.block_hash, + Self::Deneb(block_and_blobs) => { + &block_and_blobs + .signed_blinded_block + .message + .body + .execution_payload_header + .block_hash + } } } @@ -206,7 +215,14 @@ impl SignedBlindedBeaconBlock { match self { Self::Bellatrix(block) => &block.message.body.execution_payload_header.parent_hash, Self::Capella(block) => &block.message.body.execution_payload_header.parent_hash, - Self::Deneb(block) => &block.message.body.execution_payload_header.parent_hash, + Self::Deneb(block_and_blobs) => { + &block_and_blobs + .signed_blinded_block + .message + .body + .execution_payload_header + .parent_hash + } } } @@ -239,7 +255,8 @@ impl SignedBlindedBeaconBlock { Some(genesis_validators_root), ) } - Self::Deneb(block) => { + Self::Deneb(block_and_blobs) => { + let block = &mut block_and_blobs.signed_blinded_block; let slot = block.message.slot; verify_signed_consensus_message( &mut block.message, @@ -261,7 +278,7 @@ impl SignedBlindedBeaconBlock { pub enum ExecutionPayload { Bellatrix(bellatrix::ExecutionPayload), Capella(capella::ExecutionPayload), - Deneb(deneb::ExecutionPayload), + Deneb(deneb::ExecutionPayloadAndBlobsBundle), } impl ExecutionPayload { @@ -269,7 +286,7 @@ impl ExecutionPayload { match self { Self::Bellatrix(payload) => &payload.block_hash, Self::Capella(payload) => &payload.block_hash, - Self::Deneb(payload) => &payload.block_hash, + Self::Deneb(payload_and_blobs) => &payload_and_blobs.execution_payload.block_hash, } } @@ -277,7 +294,7 @@ impl ExecutionPayload { match self { Self::Bellatrix(payload) => payload.gas_limit, Self::Capella(payload) => payload.gas_limit, - Self::Deneb(payload) => payload.gas_limit, + Self::Deneb(payload_and_blobs) => payload_and_blobs.execution_payload.gas_limit, } } } @@ -295,8 +312,10 @@ impl TryFrom<&mut ExecutionPayload> for ExecutionPayloadHeader { let header = capella::ExecutionPayloadHeader::try_from(payload)?; Ok(Self::Capella(header)) } - ExecutionPayload::Deneb(payload) => { - let header = deneb::ExecutionPayloadHeader::try_from(payload)?; + ExecutionPayload::Deneb(payload_and_blobs) => { + let header = deneb::ExecutionPayloadHeader::try_from( + &mut payload_and_blobs.execution_payload, + )?; Ok(Self::Deneb(header)) } } From 41b1d9cceadb1e6224de60fbdb86a472673a3fab Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Mon, 17 Jul 2023 12:08:35 +1000 Subject: [PATCH 6/6] Remove patch and update beacon-api-client to a compatible version --- Cargo.lock | 39 ++++++++++++++++++++++++++++++++------- Cargo.toml | 8 ++------ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 584e8ee1..d45abb72 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -391,9 +391,10 @@ dependencies = [ [[package]] name = "beacon-api-client" version = "0.1.0" -source = "git+https://github.com/ralexstokes/beacon-api-client?rev=93d7e8c#93d7e8c38fe9782c4862909663e7b57c44f805a9" +source = "git+https://github.com/ralexstokes/beacon-api-client?rev=a6fe869#a6fe869c49f13b6ad6ff768af5fa8d35f158fa28" dependencies = [ - "ethereum-consensus", + "clap", + "ethereum-consensus 0.1.1 (git+https://github.com/ralexstokes/ethereum-consensus?rev=e380108)", "http", "itertools", "reqwest", @@ -859,7 +860,31 @@ dependencies = [ [[package]] name = "ethereum-consensus" version = "0.1.1" -source = "git+https://github.com/jimmygchen/ethereum-consensus?rev=4d40289#4d402897c87901f11616c71f000ea0c1f2863a38" +source = "git+https://github.com/ralexstokes/ethereum-consensus?rev=4d40289#4d402897c87901f11616c71f000ea0c1f2863a38" +dependencies = [ + "async-stream", + "blst", + "bs58", + "enr", + "hex", + "integer-sqrt", + "multiaddr", + "multihash", + "rand", + "serde", + "serde_json", + "serde_yaml", + "sha2 0.9.9", + "ssz_rs", + "thiserror", + "tokio", + "tokio-stream", +] + +[[package]] +name = "ethereum-consensus" +version = "0.1.1" +source = "git+https://github.com/ralexstokes/ethereum-consensus?rev=e380108#e380108d15fcc40349927fdf3d11c71f9edb67c2" dependencies = [ "async-stream", "blst", @@ -1557,7 +1582,7 @@ version = "0.3.0" dependencies = [ "async-trait", "beacon-api-client", - "ethereum-consensus", + "ethereum-consensus 0.1.1 (git+https://github.com/ralexstokes/ethereum-consensus?rev=4d40289)", "futures", "httpmock", "mev-build-rs", @@ -1581,7 +1606,7 @@ version = "0.3.0" dependencies = [ "async-trait", "beacon-api-client", - "ethereum-consensus", + "ethereum-consensus 0.1.1 (git+https://github.com/ralexstokes/ethereum-consensus?rev=4d40289)", "futures", "mev-rs", "parking_lot", @@ -1599,7 +1624,7 @@ version = "0.3.0" dependencies = [ "async-trait", "beacon-api-client", - "ethereum-consensus", + "ethereum-consensus 0.1.1 (git+https://github.com/ralexstokes/ethereum-consensus?rev=4d40289)", "futures", "http", "mev-build-rs", @@ -1621,7 +1646,7 @@ dependencies = [ "async-trait", "axum", "beacon-api-client", - "ethereum-consensus", + "ethereum-consensus 0.1.1 (git+https://github.com/ralexstokes/ethereum-consensus?rev=4d40289)", "hyper", "parking_lot", "reqwest", diff --git a/Cargo.toml b/Cargo.toml index 4c128050..24a0bd1d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,10 +10,6 @@ members = [ 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 = "93d7e8c" } +ethereum-consensus = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "4d40289" } +beacon-api-client = { git = "https://github.com/ralexstokes/beacon-api-client", rev = "a6fe869" } ssz_rs = "0.9.0" - -[patch."https://github.com/ralexstokes/ethereum-consensus"] -# FIXME https://github.com/ralexstokes/ethereum-consensus/pull/170 -ethereum-consensus = { git = "https://github.com/jimmygchen/ethereum-consensus", rev = "4d40289" }