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

chore(sidecar): bump alloy version to 0.6.3 #378

Merged
merged 2 commits into from
Nov 13, 2024
Merged
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
1,077 changes: 819 additions & 258 deletions bolt-sidecar/Cargo.lock

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions bolt-sidecar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@ ethereum_ssz = "0.5"
ethereum_ssz_derive = "0.5"

# alloy
alloy = { version = "0.2.0", features = [
alloy = { version = "0.6.3", features = [
"full",
"provider-trace-api",
"rpc-types-beacon",
"rpc-types-engine",
] }

# reth
reth-primitives = { git = "https://github.com/paradigmxyz/reth", version = "1.0.2" }
reth-rpc-layer = { git = "https://github.com/paradigmxyz/reth", version = "1.0.2" }
# reth-provider = { git = "https://github.com/paradigmxyz/reth", rev = "71c404d" }
reth-primitives = { git = "https://github.com/paradigmxyz/reth", version = "1.1.1" }
reth-rpc-layer = { git = "https://github.com/paradigmxyz/reth", version = "1.1.1" }

reqwest = "0.12"
ethereum-consensus = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "cf3c404" }
Expand Down Expand Up @@ -79,7 +78,7 @@ commit-boost = { git = "https://github.com/Commit-Boost/commit-boost-client", re
cb-common = { git = "https://github.com/Commit-Boost/commit-boost-client", rev = "45ce8f1" }

[dev-dependencies]
alloy-node-bindings = "0.2.0"
alloy-node-bindings = "0.6.3"


[[bin]]
Expand Down
2 changes: 1 addition & 1 deletion bolt-sidecar/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Stage 1: Base compiler image with necessary dependencies
FROM rust:1.81.0-slim-bullseye AS base
FROM rust:1.82.0-slim-bullseye AS base

# Install cargo-chef for dependency caching
RUN cargo install cargo-chef
Expand Down
2 changes: 1 addition & 1 deletion bolt-sidecar/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.81.0"
channel = "1.82.0"
merklefruit marked this conversation as resolved.
Show resolved Hide resolved
profile = "default"
14 changes: 8 additions & 6 deletions bolt-sidecar/src/api/commitments/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ pub fn auth_from_headers(headers: &HeaderMap) -> Result<(Address, Signature), Co
let address = Address::from_str(address).map_err(|_| CommitmentError::MalformedHeader)?;

let sig = split.next().ok_or(CommitmentError::MalformedHeader)?;
let sig = Signature::from_str(sig).map_err(|_| CommitmentError::InvalidSignature(SignatureError))?;
let sig =
Signature::from_str(sig).map_err(|_| CommitmentError::InvalidSignature(SignatureError))?;

Ok((address, sig))
}

#[cfg(test)]
mod test {
use alloy::{
hex::ToHexExt,
primitives::TxHash,
signers::{local::PrivateKeySigner, Signer},
};

use crate::primitives::commitment::ECDSASignatureExt;

use super::*;

#[tokio::test]
Expand All @@ -45,11 +45,13 @@ mod test {
let addr = signer.address();

let expected_sig = signer.sign_hash(&hash).await.unwrap();
headers
.insert(SIGNATURE_HEADER, format!("{addr}:{}", expected_sig.to_hex()).parse().unwrap());
headers.insert(
SIGNATURE_HEADER,
format!("{addr}:{}", expected_sig.as_bytes().encode_hex()).parse().unwrap(),
);

let (address, signature) = auth_from_headers(&headers).unwrap();
assert_eq!(signature, expected_sig);
assert_eq!(signature, Signature::try_from(expected_sig.as_bytes().as_ref()).unwrap());
assert_eq!(address, addr);
}
}
36 changes: 19 additions & 17 deletions bolt-sidecar/src/builder/compat.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use alloy::{
eips::eip4895::Withdrawal,
eips::{eip2718::Encodable2718, eip4895::Withdrawal},
primitives::{Address, Bloom, B256, U256},
rpc::types::engine::{
ExecutionPayload as AlloyExecutionPayload, ExecutionPayloadV1, ExecutionPayloadV2,
ExecutionPayloadV3,
rpc::types::{
engine::{
ExecutionPayload as AlloyExecutionPayload, ExecutionPayloadV1, ExecutionPayloadV2,
ExecutionPayloadV3,
},
Withdrawals,
},
};
use ethereum_consensus::{
Expand All @@ -20,7 +23,7 @@ use ethereum_consensus::{
ssz::prelude::{ssz_rs, ByteList, ByteVector, HashTreeRoot, List},
types::mainnet::ExecutionPayload as ConsensusExecutionPayload,
};
use reth_primitives::{SealedBlock, TransactionSigned, Withdrawals};
use reth_primitives::{SealedBlock, TransactionSigned};

/// Compatibility: convert a sealed header into an ethereum-consensus execution payload header.
/// This requires recalculating the withdrals and transactions roots as SSZ instead of MPT roots.
Expand All @@ -29,7 +32,7 @@ pub(crate) fn to_execution_payload_header(
transactions: Vec<TransactionSigned>,
) -> ConsensusExecutionPayloadHeader {
// Transactions and withdrawals are treated as opaque byte arrays in consensus types
let transactions_bytes = transactions.iter().map(|t| t.envelope_encoded()).collect::<Vec<_>>();
let transactions_bytes = transactions.iter().map(|t| t.encoded_2718()).collect::<Vec<_>>();

let mut transactions_ssz: List<Transaction, MAX_TRANSACTIONS_PER_PAYLOAD> = List::default();

Expand All @@ -42,7 +45,7 @@ pub(crate) fn to_execution_payload_header(
let mut withdrawals_ssz: List<ConsensusWithdrawal, MAX_WITHDRAWALS_PER_PAYLOAD> =
List::default();

if let Some(withdrawals) = sealed_block.withdrawals.as_ref() {
if let Some(withdrawals) = sealed_block.body.withdrawals.as_ref() {
for w in withdrawals.iter() {
withdrawals_ssz.push(to_consensus_withdrawal(w));
}
Expand Down Expand Up @@ -79,6 +82,7 @@ pub(crate) fn to_alloy_execution_payload(
block_hash: B256,
) -> AlloyExecutionPayload {
let alloy_withdrawals = block
.body
.withdrawals
.as_ref()
.map(|withdrawals| {
Expand Down Expand Up @@ -123,11 +127,11 @@ pub(crate) fn to_alloy_execution_payload(
pub(crate) fn to_consensus_execution_payload(value: &SealedBlock) -> ConsensusExecutionPayload {
let hash = value.hash();
let header = &value.header;
let transactions = &value.body;
let withdrawals = &value.withdrawals;
let transactions = &value.body.transactions;
let withdrawals = &value.body.withdrawals;
let transactions = transactions
.iter()
.map(|t| spec::Transaction::try_from(t.envelope_encoded().as_ref()).unwrap())
.map(|t| spec::Transaction::try_from(t.encoded_2718().as_ref()).unwrap())
.collect::<Vec<_>>();
let withdrawals = withdrawals
.as_ref()
Expand Down Expand Up @@ -163,21 +167,19 @@ pub(crate) fn to_consensus_execution_payload(value: &SealedBlock) -> ConsensusEx
ConsensusExecutionPayload::Deneb(payload)
}

/// Compatibility: convert a withdrawal from ethereum-consensus to a Reth withdrawal
pub(crate) fn to_reth_withdrawal(
value: ethereum_consensus::capella::Withdrawal,
) -> reth_primitives::Withdrawal {
reth_primitives::Withdrawal {
/// Compatibility: convert a Withdrawal from ethereum-consensus to alloy::primitives
pub(crate) fn to_alloy_withdrawal(value: ethereum_consensus::capella::Withdrawal) -> Withdrawal {
Withdrawal {
index: value.index as u64,
validator_index: value.validator_index as u64,
address: Address::from_slice(value.address.as_ref()),
amount: value.amount,
}
}

/// Compatibility: convert a withdrawal from Reth to ethereum-consensus
/// Compatibility: convert a withdrawal from alloy::primitives to ethereum-consensus
pub(crate) fn to_consensus_withdrawal(
value: &reth_primitives::Withdrawal,
value: &Withdrawal,
) -> ethereum_consensus::capella::Withdrawal {
ethereum_consensus::capella::Withdrawal {
index: value.index as usize,
Expand Down
45 changes: 23 additions & 22 deletions bolt-sidecar/src/builder/payload_builder.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
use std::fmt;

use alloy::{
consensus::{Header, EMPTY_OMMER_ROOT_HASH},
eips::{calc_excess_blob_gas, calc_next_block_base_fee, eip1559::BaseFeeParams},
primitives::{Address, Bytes, B256, U256},
rpc::types::{engine::ExecutionPayload as AlloyExecutionPayload, Block},
primitives::{Address, Bloom, Bytes, B256, B64, U256},
rpc::types::{engine::ExecutionPayload, Block, Withdrawal, Withdrawals},
};
use beacon_api_client::{BlockId, StateId};
use hex::FromHex;
use regex::Regex;
use reqwest::Url;
use reth_primitives::{
constants::BEACON_NONCE, proofs, BlockBody, Bloom, Header, SealedBlock, TransactionSigned,
Withdrawal, Withdrawals, EMPTY_OMMER_ROOT_HASH,
};
use reth_primitives::{proofs, BlockBody, SealedBlock, SealedHeader, TransactionSigned};
use reth_rpc_layer::{secret_to_bearer_header, JwtSecret};
use serde_json::Value;
use tracing::trace;

use super::{
compat::{to_alloy_execution_payload, to_reth_withdrawal},
compat::{to_alloy_execution_payload, to_alloy_withdrawal},
BuilderError,
};

Expand Down Expand Up @@ -124,8 +122,11 @@ impl FallbackPayloadBuilder {
let prev_randao = self.get_prev_randao().await?;
trace!(randao = ?prev_randao, "got prev_randao");

let parent_beacon_block_root =
self.beacon_api_client.get_beacon_block_root(BlockId::Head).await?;
let parent_beacon_block_root = B256::from_slice(
// TODO: compat: as_slice() from_slice() is necessary until we bump ethereum-consensus
// version to match alloy's.
self.beacon_api_client.get_beacon_block_root(BlockId::Head).await?.as_slice(),
Comment on lines +125 to +128
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annoying

);
trace!(parent = ?parent_beacon_block_root, "got parent_beacon_block_root");

let versioned_hashes = transactions
Expand Down Expand Up @@ -172,7 +173,6 @@ impl FallbackPayloadBuilder {
ommers: Vec::new(),
transactions: transactions.to_vec(),
withdrawals: Some(Withdrawals::new(withdrawals)),
requests: None,
};

let mut hints = Hints::default();
Expand All @@ -181,7 +181,8 @@ impl FallbackPayloadBuilder {
loop {
let header = build_header_with_hints_and_context(&latest_block, &hints, &ctx);

let sealed_header = header.seal_slow();
let sealed_hash = header.hash_slow();
let sealed_header = SealedHeader::new(header, sealed_hash);
let sealed_block = SealedBlock::new(sealed_header, body.clone());

let block_hash = hints.block_hash.unwrap_or(sealed_block.hash());
Expand Down Expand Up @@ -262,7 +263,7 @@ impl FallbackPayloadBuilder {
.get_expected_withdrawals(StateId::Head, None)
.await?
.into_iter()
.map(to_reth_withdrawal)
.map(to_alloy_withdrawal)
.collect::<Vec<_>>())
}
}
Expand Down Expand Up @@ -295,7 +296,7 @@ impl EngineHinter {
/// Fetch the next payload hint from the engine API to complete the sealed block.
pub async fn fetch_next_payload_hint(
&self,
exec_payload: &AlloyExecutionPayload,
exec_payload: &ExecutionPayload,
versioned_hashes: &[B256],
parent_beacon_root: B256,
) -> Result<EngineApiHint, BuilderError> {
Expand Down Expand Up @@ -380,7 +381,7 @@ fn build_header_with_hints_and_context(
let state_root = hints.state_root.unwrap_or_default();

Header {
parent_hash: latest_block.header.hash.unwrap_or_default(),
parent_hash: latest_block.header.hash,
ommers_hash: EMPTY_OMMER_ROOT_HASH,
beneficiary: context.fee_recipient,
state_root,
Expand All @@ -389,17 +390,17 @@ fn build_header_with_hints_and_context(
withdrawals_root: Some(context.withdrawals_root),
logs_bloom,
difficulty: U256::ZERO,
number: latest_block.header.number.unwrap_or_default() + 1,
gas_limit: latest_block.header.gas_limit as u64,
number: latest_block.header.number + 1,
gas_limit: latest_block.header.gas_limit,
gas_used,
timestamp: context.block_timestamp,
mix_hash: context.prev_randao,
nonce: BEACON_NONCE,
nonce: B64::ZERO,
base_fee_per_gas: Some(context.base_fee),
blob_gas_used: Some(context.blob_gas_used),
excess_blob_gas: Some(context.excess_blob_gas),
parent_beacon_block_root: Some(context.parent_beacon_block_root),
requests_root: None,
requests_hash: None,
extra_data: context.extra_data.clone(),
}
}
Expand All @@ -419,7 +420,7 @@ mod tests {
use std::time::{SystemTime, UNIX_EPOCH};

use alloy::{
eips::eip2718::Encodable2718,
eips::eip2718::{Decodable2718, Encodable2718},
network::{EthereumWallet, TransactionBuilder},
primitives::{hex, Address},
signers::{k256::ecdsa::SigningKey, local::PrivateKeySigner},
Expand Down Expand Up @@ -456,14 +457,14 @@ mod tests {
let tx = default_test_transaction(addy, Some(3)).with_chain_id(1);
let tx_signed = tx.build(&wallet).await?;
let raw_encoded = tx_signed.encoded_2718();
let tx_signed_reth = TransactionSigned::decode_enveloped(&mut raw_encoded.as_slice())?;
let tx_signed_reth = TransactionSigned::decode_2718(&mut raw_encoded.as_slice())?;

let slot = genesis_time +
(SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs() / cfg.chain.slot_time()) +
1;

let block = builder.build_fallback_payload(slot, &[tx_signed_reth]).await?;
assert_eq!(block.body.len(), 1);
assert_eq!(block.body.transactions.len(), 1);

Ok(())
}
Expand All @@ -473,7 +474,7 @@ mod tests {
// Withdrawal root in the execution layer header is MPT.
assert_eq!(
reth_primitives::proofs::calculate_withdrawals_root(&Vec::new()),
reth_primitives::constants::EMPTY_WITHDRAWALS
alloy::consensus::constants::EMPTY_WITHDRAWALS
);
}
}
4 changes: 2 additions & 2 deletions bolt-sidecar/src/builder/template.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::collections::HashMap;

use alloy::primitives::{Address, U256};
use alloy::primitives::{Address, TxHash, U256};
use ethereum_consensus::{
crypto::{KzgCommitment, KzgProof},
deneb::mainnet::{Blob, BlobsBundle},
};
use reth_primitives::{TransactionSigned, TxHash};
use reth_primitives::TransactionSigned;
use tracing::warn;

use crate::{
Expand Down
3 changes: 1 addition & 2 deletions bolt-sidecar/src/chain_io/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ use std::{collections::HashMap, str::FromStr};

use alloy::{
contract::Error as ContractError,
primitives::{Bytes, FixedBytes, B512},
primitives::{keccak256, Bytes, FixedBytes, B512},
sol_types::SolInterface,
transports::TransportError,
};
use ethereum_consensus::primitives::BlsPublicKey;
use reth_primitives::keccak256;

/// A 20-byte compressed hash of a BLS public key.
///
Expand Down
3 changes: 1 addition & 2 deletions bolt-sidecar/src/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::ops::{Deref, DerefMut};

use alloy::{
eips::BlockNumberOrTag,
primitives::{Address, Bytes, B256, U256, U64},
primitives::{Address, Bytes, TxHash, B256, U256, U64},
rpc::{
client::{self as alloyClient, ClientBuilder},
types::{Block, FeeHistory, TransactionReceipt},
Expand All @@ -12,7 +12,6 @@ use alloy::{

use futures::{stream::FuturesUnordered, StreamExt};
use reqwest::{Client, Url};
use reth_primitives::TxHash;

use crate::primitives::AccountState;

Expand Down
5 changes: 4 additions & 1 deletion bolt-sidecar/src/crypto/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ impl SignerECDSA for PrivateKeySigner {
}

async fn sign_hash(&self, hash: &[u8; 32]) -> eyre::Result<AlloySignature> {
Ok(Signer::sign_hash(self, hash.into()).await?)
let sig = Signer::sign_hash(self, hash.into()).await?;
// TODO: compat: this is necessary since alloy PrimitiveSignature and Signature
// are different types in the new version
Ok(AlloySignature::try_from(sig.as_bytes().as_ref()).expect("signature conversion"))
}
}

Expand Down
Loading