Skip to content
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

Electra #250

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
439 changes: 244 additions & 195 deletions Cargo.lock

Large diffs are not rendered by default.

35 changes: 27 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,30 @@ 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 = "269ba9b" }
beacon-api-client = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "269ba9b" }

reth = { git = "https://github.com/paradigmxyz/reth", rev = "5f82993c23164ce8ccdc7bf3ae5085205383a5c8" }
reth-db = { git = "https://github.com/paradigmxyz/reth", rev = "5f82993c23164ce8ccdc7bf3ae5085205383a5c8" }
reth-node-ethereum = { git = "https://github.com/paradigmxyz/reth", rev = "5f82993c23164ce8ccdc7bf3ae5085205383a5c8" }
reth-basic-payload-builder = { git = "https://github.com/paradigmxyz/reth", rev = "5f82993c23164ce8ccdc7bf3ae5085205383a5c8" }
alloy-signer = { git = "https://github.com/alloy-rs/alloy", rev = "77c1240" }
alloy-signer-wallet = { git = "https://github.com/alloy-rs/alloy", rev = "77c1240" }
reth = { git = "https://github.com/paradigmxyz/reth", rev = "3736d8f9aa7c5cf46edc1e5d1dbd9dcf6f50b9c9" }
reth-interfaces = { git = "https://github.com/paradigmxyz/reth", rev = "3736d8f9aa7c5cf46edc1e5d1dbd9dcf6f50b9c9" }
reth-db = { git = "https://github.com/paradigmxyz/reth", rev = "3736d8f9aa7c5cf46edc1e5d1dbd9dcf6f50b9c9" }
reth-node-ethereum = { git = "https://github.com/paradigmxyz/reth", rev = "3736d8f9aa7c5cf46edc1e5d1dbd9dcf6f50b9c9" }
reth-evm-ethereum = { git = "https://github.com/paradigmxyz/reth", rev = "3736d8f9aa7c5cf46edc1e5d1dbd9dcf6f50b9c9" }
reth-basic-payload-builder = { git = "https://github.com/paradigmxyz/reth", rev = "3736d8f9aa7c5cf46edc1e5d1dbd9dcf6f50b9c9" }
alloy-signer = { git = "https://github.com/alloy-rs/alloy", rev = "07611cf" }
alloy-signer-wallet = { git = "https://github.com/alloy-rs/alloy", rev = "07611cf" }

# revm
revm = { version = "9.0.0", features = [
"std",
"secp256k1",
], default-features = false }
revm-primitives = { version = "4.0.0", features = [
"std",
], default-features = false }
revm-interpreter = { version = "5.0.0", features = [
"std",
], default-features = false }
revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors", rev = "3215ff5" }

futures = "0.3.21"
tokio = "1.0"
Expand Down Expand Up @@ -65,3 +80,7 @@ clap = "4.1.4"

[patch.crates-io]
libffi-sys = { git = "https://github.com/tov/libffi-rs", rev = "d0704d634b6f3ffef5b6fc7e07fe965a1cff5c7b" }
revm = { git = "https://github.com/bluealloy/revm", rev = "276cdfb" }
revm-interpreter = { git = "https://github.com/bluealloy/revm", rev = "276cdfb" }
revm-precompile = { git = "https://github.com/bluealloy/revm", rev = "276cdfb" }
revm-primitives = { git = "https://github.com/bluealloy/revm", rev = "276cdfb" }
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json

ARG BUILD_PROFILE=maxperf
ARG BUILD_PROFILE=release
ENV BUILD_PROFILE ${BUILD_PROFILE}
ARG FEATURES=""
ENV FEATURES ${FEATURES}
Expand Down
2 changes: 2 additions & 0 deletions mev-build-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ beacon-api-client = { workspace = true }
mev-rs = { path = "../mev-rs" }

reth = { workspace = true }
reth-interfaces = { workspace = true }
reth-db = { workspace = true }
reth-node-ethereum = { workspace = true }
reth-evm-ethereum = { workspace = true }
reth-basic-payload-builder = { workspace = true }
alloy-signer = { workspace = true }
alloy-signer-wallet = { workspace = true, features = ["mnemonic"] }
Expand Down
15 changes: 14 additions & 1 deletion 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 Expand Up @@ -278,7 +286,12 @@ impl<
}

async fn submit_payload(&self, payload: EthBuiltPayload) {
let auction = self.open_auctions.get(&payload.id()).expect("has auction");
// TODO: resolve hot fix for short slot timings
let auction = self.open_auctions.get(&payload.id());
if auction.is_none() {
return
}
let auction = auction.unwrap();
let mut successful_relays_for_submission = Vec::with_capacity(auction.relays.len());
match prepare_submission(
&payload,
Expand Down
78 changes: 74 additions & 4 deletions mev-build-rs/src/compat.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
use crate::Error;
use ethereum_consensus::{
crypto::{KzgCommitment, KzgProof},
primitives::{Bytes32, ExecutionAddress},
electra::{DepositReceipt, ExecutionLayerWithdrawalRequest},
primitives::{BlsPublicKey, BlsSignature, Bytes32, ExecutionAddress},
ssz::prelude::{ByteList, ByteVector, SimpleSerializeError, U256},
Fork,
};
use mev_rs::types::{BlobsBundle, ExecutionPayload};
use reth::primitives::{Address, BlobTransactionSidecar, Bloom, SealedBlock, B256};
use reth::primitives::{Address, BlobTransactionSidecar, Bloom, Request, SealedBlock, B256};

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

pub fn to_bytes32(value: B256) -> Bytes32 {
Bytes32::try_from(value.as_ref()).unwrap()
Expand All @@ -30,6 +31,7 @@ pub fn to_execution_payload(value: &SealedBlock, fork: Fork) -> Result<Execution
let header = &value.header;
let transactions = &value.body;
let withdrawals = &value.withdrawals;
let requests = &value.requests;
match fork {
Fork::Deneb => {
let transactions = transactions
Expand Down Expand Up @@ -69,6 +71,74 @@ pub fn to_execution_payload(value: &SealedBlock, fork: Fork) -> Result<Execution
};
Ok(ExecutionPayload::Deneb(payload))
}
Fork::Electra => {
let transactions = transactions
.iter()
.map(|t| electra::Transaction::try_from(t.envelope_encoded().as_ref()).unwrap())
.collect::<Vec<_>>();
let withdrawals = withdrawals
.as_ref()
.unwrap()
.iter()
.map(|w| electra::Withdrawal {
index: w.index as usize,
validator_index: w.validator_index as usize,
address: to_bytes20(w.address),
amount: w.amount,
})
.collect::<Vec<_>>();
let mut deposit_receipts = vec![];
let mut withdrawal_requests = vec![];
let requests = requests.as_ref().cloned().unwrap();
for request in requests {
match request {
Request::DepositRequest(deposit) => {
let deposit_receipt = DepositReceipt {
public_key: BlsPublicKey::try_from(deposit.pubkey.as_ref()).unwrap(),
withdrawal_credentials: to_bytes32(deposit.withdrawal_credentials),
amount: deposit.amount,
signature: BlsSignature::try_from(deposit.signature.as_ref()).unwrap(),
index: deposit.index,
};
deposit_receipts.push(deposit_receipt);
}
Request::WithdrawalRequest(withdrawal) => {
let withdrawal_request = ExecutionLayerWithdrawalRequest {
source_address: to_bytes20(withdrawal.source_address),
validator_public_key: BlsPublicKey::try_from(
withdrawal.validator_public_key.as_ref(),
)
.unwrap(),
amount: withdrawal.amount,
};
withdrawal_requests.push(withdrawal_request);
}
_ => unreachable!("struct is non-exhaustive, but all variants are matched"),
}
}
let payload = electra::ExecutionPayload {
parent_hash: to_bytes32(header.parent_hash),
fee_recipient: to_bytes20(header.beneficiary),
state_root: to_bytes32(header.state_root),
receipts_root: to_bytes32(header.receipts_root),
logs_bloom: to_byte_vector(header.logs_bloom),
prev_randao: to_bytes32(header.mix_hash),
block_number: header.number,
gas_limit: header.gas_limit,
gas_used: header.gas_used,
timestamp: header.timestamp,
extra_data: ByteList::try_from(header.extra_data.as_ref()).unwrap(),
base_fee_per_gas: U256::from(header.base_fee_per_gas.unwrap_or_default()),
block_hash: to_bytes32(hash),
transactions: TryFrom::try_from(transactions).unwrap(),
withdrawals: TryFrom::try_from(withdrawals).unwrap(),
blob_gas_used: header.blob_gas_used.unwrap(),
excess_blob_gas: header.excess_blob_gas.unwrap(),
deposit_receipts: TryFrom::try_from(deposit_receipts).unwrap(),
withdrawal_requests: TryFrom::try_from(withdrawal_requests).unwrap(),
};
Ok(ExecutionPayload::Electra(payload))
}
fork => Err(Error::UnsupportedFork(fork)),
}
}
Expand Down
3 changes: 2 additions & 1 deletion mev-build-rs/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use reth::{
primitives::ChainSpec,
rpc::types::{
engine::{
ExecutionPayloadEnvelopeV2, ExecutionPayloadEnvelopeV3,
ExecutionPayloadEnvelopeV2, ExecutionPayloadEnvelopeV3, ExecutionPayloadEnvelopeV4,
PayloadAttributes as EthPayloadAttributes,
},
ExecutionPayloadV1,
Expand Down Expand Up @@ -64,6 +64,7 @@ impl EngineTypes for BuilderEngineTypes {
type ExecutionPayloadV1 = ExecutionPayloadV1;
type ExecutionPayloadV2 = ExecutionPayloadEnvelopeV2;
type ExecutionPayloadV3 = ExecutionPayloadEnvelopeV3;
type ExecutionPayloadV4 = ExecutionPayloadEnvelopeV4;

fn validate_version_specific_fields(
chain_spec: &ChainSpec,
Expand Down
Loading
Loading