Skip to content

Commit

Permalink
wip: electra support
Browse files Browse the repository at this point in the history
  • Loading branch information
ralexstokes committed Oct 23, 2024
1 parent 76f45eb commit bfeb347
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 5 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 @@ -24,8 +24,8 @@ codegen-units = 1
incremental = false

[workspace.dependencies]
ethereum-consensus = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "cf3c404043230559660810bc0c9d6d5a8498d819" }
beacon-api-client = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "cf3c404043230559660810bc0c9d6d5a8498d819" }
ethereum-consensus = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "3068ca2bab27c39a5a409dcd359e46319d82c431" }
beacon-api-client = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "3068ca2bab27c39a5a409dcd359e46319d82c431" }

reth = { git = "https://github.com/paradigmxyz/reth", tag = "v1.0.8" }
reth-basic-payload-builder = { git = "https://github.com/paradigmxyz/reth", tag = "v1.0.8" }
Expand Down
8 changes: 8 additions & 0 deletions mev-build-rs/src/auctioneer/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ fn prepare_submission(
blobs_bundle: to_blobs_bundle(payload.sidecars())?,
signature,
}),
Fork::Electra => {
SignedBidSubmission::Electra(block_submission::electra::SignedBidSubmission {
message,
execution_payload,
blobs_bundle: to_blobs_bundle(payload.sidecars())?,
signature,
})
}
fork => return Err(Error::UnsupportedFork(fork)),
};
Ok(submission)
Expand Down
2 changes: 1 addition & 1 deletion mev-build-rs/src/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn to_execution_payload(value: &SealedBlock, fork: Fork) -> Result<Execution
let transactions = &value.body.transactions;
let withdrawals = &value.body.withdrawals;
match fork {
Fork::Deneb => {
Fork::Deneb | Fork::Electra => {
let transactions = transactions
.iter()
.map(|t| deneb::Transaction::try_from(t.encoded_2718().as_ref()).unwrap())
Expand Down
65 changes: 65 additions & 0 deletions mev-relay-rs/src/auction_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fn to_header(execution_payload: &ExecutionPayload) -> Result<ExecutionPayloadHea
}
ExecutionPayload::Capella(payload) => ExecutionPayloadHeader::Capella(payload.try_into()?),
ExecutionPayload::Deneb(payload) => ExecutionPayloadHeader::Deneb(payload.try_into()?),
ExecutionPayload::Electra(payload) => ExecutionPayloadHeader::Electra(payload.try_into()?),
};
Ok(header)
}
Expand Down Expand Up @@ -89,11 +90,52 @@ pub mod deneb {
}
}

pub mod electra {
use super::*;

#[cfg(not(feature = "minimal-preset"))]
use ethereum_consensus::electra::mainnet as electra;
#[cfg(feature = "minimal-preset")]
use ethereum_consensus::electra::minimal as electra;

#[derive(Debug, PartialEq, Eq)]
pub struct AuctionContext {
pub builder_public_key: BlsPublicKey,
pub bid_trace: BidTrace,
pub receive_duration: Duration,
pub signed_builder_bid: SignedBuilderBid,
pub execution_payload: ExecutionPayload,
pub execution_requests: electra::ExecutionRequests,
pub value: U256,
pub blobs_bundle: BlobsBundle,
}

impl Hash for AuctionContext {
fn hash<H: Hasher>(&self, state: &mut H) {
self.builder_public_key.hash(state);
self.bid_trace.hash(state);
self.receive_duration.hash(state);
self.signed_builder_bid.hash(state);
let payload_root =
self.execution_payload.hash_tree_root().expect("can get hash tree root");
payload_root.hash(state);
let requests_root =
self.execution_requests.hash_tree_root().expect("can get hash tree root");
requests_root.hash(state);
self.value.hash(state);
let blobs_bundle_root =
self.blobs_bundle.hash_tree_root().expect("can get hash tree root");
blobs_bundle_root.hash(state);
}
}
}

#[derive(Debug, PartialEq, Eq, Hash)]
pub enum AuctionContext {
Bellatrix(bellatrix::AuctionContext),
Capella(capella::AuctionContext),
Deneb(deneb::AuctionContext),
Electra(electra::AuctionContext),
}

impl AuctionContext {
Expand Down Expand Up @@ -167,6 +209,16 @@ impl AuctionContext {
value,
blobs_bundle: submission.blobs_bundle,
}),
SignedBidSubmission::Electra(submission) => Self::Electra(electra::AuctionContext {
builder_public_key,
bid_trace: submission.message,
receive_duration,
signed_builder_bid,
execution_payload,
execution_requests: submission.execution_requests,
value,
blobs_bundle: submission.blobs_bundle,
}),
};

Ok(auction_context)
Expand All @@ -177,6 +229,7 @@ impl AuctionContext {
Self::Bellatrix(context) => &context.builder_public_key,
Self::Capella(context) => &context.builder_public_key,
Self::Deneb(context) => &context.builder_public_key,
Self::Electra(context) => &context.builder_public_key,
}
}

Expand All @@ -185,6 +238,7 @@ impl AuctionContext {
Self::Bellatrix(context) => &context.bid_trace,
Self::Capella(context) => &context.bid_trace,
Self::Deneb(context) => &context.bid_trace,
Self::Electra(context) => &context.bid_trace,
}
}

Expand All @@ -193,6 +247,7 @@ impl AuctionContext {
Self::Bellatrix(context) => context.receive_duration,
Self::Capella(context) => context.receive_duration,
Self::Deneb(context) => context.receive_duration,
Self::Electra(context) => context.receive_duration,
}
}

Expand All @@ -201,6 +256,7 @@ impl AuctionContext {
Self::Bellatrix(context) => &context.signed_builder_bid,
Self::Capella(context) => &context.signed_builder_bid,
Self::Deneb(context) => &context.signed_builder_bid,
Self::Electra(context) => &context.signed_builder_bid,
}
}

Expand All @@ -209,6 +265,7 @@ impl AuctionContext {
Self::Bellatrix(context) => &context.execution_payload,
Self::Capella(context) => &context.execution_payload,
Self::Deneb(context) => &context.execution_payload,
Self::Electra(context) => &context.execution_payload,
}
}

Expand All @@ -217,6 +274,7 @@ impl AuctionContext {
Self::Bellatrix(_) => None,
Self::Capella(_) => None,
Self::Deneb(context) => Some(&context.blobs_bundle),
Self::Electra(context) => Some(&context.blobs_bundle),
}
}

Expand All @@ -225,6 +283,7 @@ impl AuctionContext {
Self::Bellatrix(context) => context.value,
Self::Capella(context) => context.value,
Self::Deneb(context) => context.value,
Self::Electra(context) => context.value,
}
}

Expand All @@ -240,6 +299,12 @@ impl AuctionContext {
blobs_bundle: context.blobs_bundle.clone(),
})
}
Self::Electra(context) => {
AuctionContents::El(auction_contents::deneb::AuctionContents {
execution_payload: context.execution_payload.clone(),
blobs_bundle: context.blobs_bundle.clone(),
})
}
}
}
}
40 changes: 40 additions & 0 deletions mev-rs/src/types/auction_contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,47 @@ pub mod deneb {
}
}

pub mod electra {
use super::ExecutionPayload;
use ethereum_consensus::{
crypto::{KzgCommitment, KzgProof},
ssz::prelude::*,
};

#[cfg(not(feature = "minimal-preset"))]
use ethereum_consensus::electra::mainnet::{
Blob, ExecutionRequests, MAX_BLOB_COMMITMENTS_PER_BLOCK,
};
#[cfg(feature = "minimal-preset")]
use ethereum_consensus::electra::minimal::{
Blob, ExecutionRequests, MAX_BLOB_COMMITMENTS_PER_BLOCK,
};

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

#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AuctionContents {
pub execution_payload: ExecutionPayload,
pub execution_requests: ExecutionRequests,
pub blobs_bundle: BlobsBundle,
}
}

#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[serde(untagged)]
pub enum AuctionContents {
Bellatrix(bellatrix::AuctionContents),
Capella(capella::AuctionContents),
Deneb(deneb::AuctionContents),
Electra(deneb::AuctionContents),
}

impl<'de> serde::Deserialize<'de> for AuctionContents {
Expand All @@ -55,6 +89,9 @@ impl<'de> serde::Deserialize<'de> for AuctionContents {
D: serde::Deserializer<'de>,
{
let value = serde_json::Value::deserialize(deserializer)?;
if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) {
return Ok(Self::Electra(inner))
}
if let Ok(inner) = <_ as serde::Deserialize>::deserialize(&value) {
return Ok(Self::Deneb(inner))
}
Expand All @@ -74,6 +111,7 @@ impl AuctionContents {
Self::Bellatrix(..) => Fork::Bellatrix,
Self::Capella(..) => Fork::Capella,
Self::Deneb(..) => Fork::Deneb,
Self::Electra(..) => Fork::Electra,
}
}

Expand All @@ -82,12 +120,14 @@ impl AuctionContents {
Self::Bellatrix(inner) => inner,
Self::Capella(inner) => inner,
Self::Deneb(inner) => &inner.execution_payload,
Self::Electra(inner) => &inner.execution_payload,
}
}

pub fn blobs_bundle(&self) -> Option<&BlobsBundle> {
match self {
Self::Deneb(inner) => Some(&inner.blobs_bundle),
Self::Electra(inner) => Some(&inner.blobs_bundle),
_ => None,
}
}
Expand Down

0 comments on commit bfeb347

Please sign in to comment.