From a9ac358443df4d2e69872f8a67645ebe8d3eb634 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Tue, 14 May 2024 15:20:42 +0300 Subject: [PATCH] reth electra payload support --- mev-build-rs/src/compat.rs | 23 ++++++++++++++--------- mev-build-rs/src/node.rs | 3 ++- mev-build-rs/src/payload/builder.rs | 4 ++-- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/mev-build-rs/src/compat.rs b/mev-build-rs/src/compat.rs index 37d28501..e4e685fc 100644 --- a/mev-build-rs/src/compat.rs +++ b/mev-build-rs/src/compat.rs @@ -2,7 +2,7 @@ use crate::Error; use ethereum_consensus::{ crypto::{KzgCommitment, KzgProof}, electra::{DepositReceipt, ExecutionLayerWithdrawalRequest}, - primitives::{Bytes32, ExecutionAddress}, + primitives::{BlsPublicKey, BlsSignature, Bytes32, ExecutionAddress}, ssz::prelude::{ByteList, ByteVector, SimpleSerializeError, U256}, Fork, }; @@ -89,26 +89,31 @@ pub fn to_execution_payload(value: &SealedBlock, fork: Fork) -> Result>(); let mut deposit_receipts = vec![]; let mut withdrawal_requests = vec![]; - for request in requests.as_ref().unwrap() { + let requests = requests.unwrap(); + for request in requests { match request { Request::DepositRequest(deposit) => { let deposit_receipt = DepositReceipt { - public_key: deposit.pubkey, - withdrawal_credentials: deposit.withdrawal_credentials, + public_key: BlsPublicKey::try_from(deposit.pubkey.as_ref()).unwrap(), + withdrawal_credentials: to_bytes32(deposit.withdrawal_credentials), amount: deposit.amount, - signature: deposit.signature, + 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: withdrawal.source_address, - validator_public_key: withdrawal.validator_public_key, + 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 { @@ -129,8 +134,8 @@ pub fn to_execution_payload(value: &SealedBlock, fork: Fork) -> Result( drop(evm); db.commit(state); - let Block { mut header, mut body, ommers, withdrawals } = block.unseal(); + let Block { mut header, mut body, ommers, withdrawals, requests } = block.unseal(); // Verify we reserved the correct amount of gas for the payment transaction let gas_limit = header.gas_limit + result.gas_used(); @@ -181,7 +181,7 @@ fn append_payment( header.gas_used = cumulative_gas_used; header.gas_limit = gas_limit; - let block = Block { header, body, ommers, withdrawals }; + let block = Block { header, body, ommers, withdrawals, requests }; Ok(block.seal_slow()) }