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(deps): bump ethereum_ssz from 0.5.4 to 0.8.1 in /bolt-sidecar #534

Merged
merged 6 commits into from
Dec 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,853 changes: 706 additions & 1,147 deletions bolt-sidecar/Cargo.lock

Large diffs are not rendered by default.

29 changes: 15 additions & 14 deletions bolt-sidecar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,30 @@ tree_hash = "0.8"
tree_hash_derive = "0.8"
secp256k1 = { version = "0.29.0", features = ["rand"] }
ssz_rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "ec3073e" }
ethereum_ssz = "0.5"
ethereum_ssz = "0.8.1"

# alloy
alloy = { version = "0.7.3", features = [
alloy = { version = "0.8.0", features = [
"full",
"provider-trace-api",
"rpc-types-beacon",
] }
alloy-rpc-types-engine = { version = "0.7.2", default-features = false, features = ["jwt"] }
alloy-transport-http = { version = "0.7.2", default-features = false, features = ["jwt-auth"] }
alloy-provider = { version = "0.7.2", default-features = false, features = ["engine-api"] }
alloy-rpc-types-engine = { version = "0.8.0", default-features = false, features = ["jwt"] }
alloy-transport-http = { version = "0.8.0", default-features = false, features = ["jwt-auth"] }
alloy-provider = { version = "0.8.0", default-features = false, features = ["engine-api"] }

# reth
reth-primitives = { git = "https://github.com/paradigmxyz/reth", version = "1.1.2" }
reth-primitives = { git = "https://github.com/paradigmxyz/reth", version = "1.1.4" }

reqwest = "0.12"
ethereum-consensus = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "cf3c404" }
beacon-api-client = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "cf3c404" }

ethereum-consensus = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "8fbd8a5" } # Last release in 2022
beacon-api-client = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "8fbd8a5" } # Last release in 2022

# lighthouse
lighthouse_account_utils = { package = "account_utils", git = "https://github.com/sigp/lighthouse", rev = "a87f19d" }
lighthouse_eth2_keystore = { package = "eth2_keystore", git = "https://github.com/sigp/lighthouse", rev = "a87f19d" }
lighthouse_bls = { package = "bls", git = "https://github.com/sigp/lighthouse", rev = "a87f19d" }
lighthouse_account_utils = { package = "account_utils", git = "https://github.com/sigp/lighthouse", version = "0.1.0" }
lighthouse_eth2_keystore = { package = "eth2_keystore", git = "https://github.com/sigp/lighthouse", version = "0.1.0" }
lighthouse_bls = { package = "bls", git = "https://github.com/sigp/lighthouse", version = "0.2.0" }

# types
serde = { version = "1.0.197", features = ["derive"] }
Expand Down Expand Up @@ -76,11 +77,11 @@ metrics-exporter-prometheus = { version = "0.15.3", features = [
] }

# commit-boost
commit-boost = { git = "https://github.com/Commit-Boost/commit-boost-client", rev = "45ce8f1" }
cb-common = { git = "https://github.com/Commit-Boost/commit-boost-client", rev = "45ce8f1" }
commit-boost = { git = "https://github.com/Commit-Boost/commit-boost-client", rev = "0f8f69b" }
cb-common = { git = "https://github.com/Commit-Boost/commit-boost-client", rev = "0f8f69b" }

[dev-dependencies]
alloy-node-bindings = "0.7.2" # must match alloy version
alloy-node-bindings = "0.8.0" # must match alloy version
criterion = { version = "0.5", features = ["html_reports"] }

[package.metadata.cargo-machete]
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.82.0"
channel = "1.83.0"
profile = "default"
2 changes: 1 addition & 1 deletion bolt-sidecar/src/api/commitments/headers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::str::FromStr;

use alloy::primitives::{Address, Signature};
use alloy::primitives::{Address, PrimitiveSignature as Signature};
use axum::http::HeaderMap;

use crate::primitives::commitment::SignatureError;
Expand Down
4 changes: 4 additions & 0 deletions bolt-sidecar/src/config/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,22 @@ impl ChainConfig {

#[cfg(test)]
impl ChainConfig {
/// Create a new chain configuration for Mainnet.
pub fn mainnet() -> Self {
Self { chain: Chain::Mainnet, ..Default::default() }
}

/// Create a new chain configuration for Holesky.
pub fn holesky() -> Self {
Self { chain: Chain::Holesky, ..Default::default() }
}

/// Create a new chain configuration for Helder.
pub fn helder() -> Self {
Self { chain: Chain::Helder, ..Default::default() }
}

/// Create a new chain configuration for Kurtosis.
pub fn kurtosis(slot_time_in_seconds: u64, commitment_deadline: u64) -> Self {
Self {
chain: Chain::Kurtosis,
Expand Down
5 changes: 2 additions & 3 deletions bolt-sidecar/src/driver.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::{fmt, sync::Arc, time::Instant};

use alloy::consensus::Typed2718;
use alloy::{
consensus::{Transaction, TxType},
rpc::types::beacon::events::HeadEvent,
signers::local::PrivateKeySigner,
consensus::TxType, rpc::types::beacon::events::HeadEvent, signers::local::PrivateKeySigner,
};
use ethereum_consensus::{
clock::{self, SlotStream, SystemTimeProvider},
Expand Down
8 changes: 4 additions & 4 deletions bolt-sidecar/src/primitives/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::str::FromStr;
use alloy::{
consensus::Transaction,
hex,
primitives::{keccak256, Address, Signature, B256},
primitives::{keccak256, Address, PrimitiveSignature as Signature, B256},
};
use serde::{de, Deserialize, Deserializer, Serialize};

Expand Down Expand Up @@ -224,7 +224,7 @@ fn serialize_sig<S: serde::Serializer>(sig: &Signature, serializer: S) -> Result
let parity = sig.v();
// As bytes encodes the parity as 27/28, need to change that.
let mut bytes = sig.as_bytes();
bytes[bytes.len() - 1] = if parity.y_parity() { 1 } else { 0 };
bytes[bytes.len() - 1] = if parity { 1 } else { 0 };
serializer.serialize_str(&hex::encode_prefixed(bytes))
}

Expand Down Expand Up @@ -265,7 +265,7 @@ impl ECDSASignatureExt for Signature {
let parity = self.v();
// As bytes encodes the parity as 27/28, need to change that.
let mut bytes = self.as_bytes();
bytes[bytes.len() - 1] = if parity.y_parity() { 1 } else { 0 };
bytes[bytes.len() - 1] = if parity { 1 } else { 0 };

bytes
}
Expand All @@ -281,7 +281,7 @@ mod tests {

use alloy::{
hex,
primitives::{Address, Signature},
primitives::{Address, PrimitiveSignature as Signature},
};

use super::{CommitmentRequest, InclusionRequest};
Expand Down
80 changes: 40 additions & 40 deletions bolt-sidecar/src/signer/commit_boost.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
use std::{str::FromStr, sync::Arc};

use alloy::{primitives::Address, rpc::types::beacon::BlsSignature, signers::Signature};
use alloy::{
primitives::{Address, FixedBytes},
rpc::types::beacon::BlsSignature,
signers::Signature,
};
use cb_common::{
commit::{client::SignerClient, error::SignerClientError, request::SignConsensusRequest},
commit::{
client::SignerClient,
error::SignerClientError,
request::{GetPubkeysResponse, SignConsensusRequest},
},
signer::EcdsaPublicKey,
};
use commit_boost::prelude::SignProxyRequest;
use ethereum_consensus::crypto::bls::PublicKey as BlsPublicKey;
use parking_lot::RwLock;
use reqwest::Url;
use ssz::Decode;
use thiserror::Error;
use tracing::{debug, error, info};

Expand Down Expand Up @@ -45,9 +52,8 @@ pub enum CommitBoostError {
impl CommitBoostSigner {
/// Create a new [CommitBoostSigner] instance
pub fn new(signer_url: Url, jwt: &JwtSecretConfig) -> SignerResult<Self> {
let socket_addr = parse_address_from_url(signer_url).map_err(CommitBoostError::Other)?;
let signer_client =
SignerClient::new(socket_addr, &jwt.to_hex()).map_err(CommitBoostError::Other)?;
SignerClient::new(signer_url, &jwt.to_hex()).map_err(CommitBoostError::Other)?;

let client = Self {
signer_client,
Expand All @@ -58,21 +64,35 @@ impl CommitBoostSigner {
let mut this = client.clone();
tokio::spawn(async move {
match this.signer_client.get_pubkeys().await {
Ok(pubkeys) => {
Ok(GetPubkeysResponse { keys }) => {
// Calculate totals for each key type across all mappings
let consensus_count = keys.len();
let proxy_bls_count = keys.iter().map(|map| map.proxy_bls.len()).sum::<usize>();
let proxy_ecdsa_count =
keys.iter().map(|map| map.proxy_ecdsa.len()).sum::<usize>();

info!(
consensus = pubkeys.consensus.len(),
bls_proxy = pubkeys.proxy_bls.len(),
ecdsa_proxy = pubkeys.proxy_ecdsa.len(),
consensus = consensus_count,
bls_proxy = proxy_bls_count,
ecdsa_proxy = proxy_ecdsa_count,
"Received pubkeys"
);

let mut pubkeys_lock = this.pubkeys.write();
let mut proxy_ecdsa_lock = this.proxy_ecdsa.write();
*pubkeys_lock = pubkeys
.consensus
.into_iter()
.map(|k| BlsPublicKey::try_from(k.as_ref()).unwrap())

// Store consensus keys
*pubkeys_lock = keys
.iter()
.map(|map| {
BlsPublicKey::try_from(map.consensus.as_ref())
.expect("valid consensus public key")
})
.collect();
*proxy_ecdsa_lock = pubkeys.proxy_ecdsa;

// Collect all ECDSA proxy keys
*proxy_ecdsa_lock =
keys.iter().flat_map(|map| map.proxy_ecdsa.clone()).collect();
}
Err(e) => {
error!(?e, "Failed to fetch pubkeys");
Expand Down Expand Up @@ -126,8 +146,9 @@ impl CommitBoostSigner {
pub async fn sign_commit_boost_root(&self, data: [u8; 32]) -> SignerResult<BlsSignature> {
// convert the pubkey from ethereum_consensus to commit-boost format
// TODO: compat: this is the only way to obtain a BlsPubkey for now unfortunately
let pubkey = cb_common::signer::BlsPublicKey::from_ssz_bytes(self.pubkey().as_ref())
.expect("pubkey bytes conversion");
let pubkey = cb_common::signer::BlsPublicKey::from(FixedBytes::<48>::from_slice(
self.pubkey().as_ref(),
));

let request = SignConsensusRequest { pubkey, object_root: data };

Expand Down Expand Up @@ -166,19 +187,6 @@ impl SignerECDSA for CommitBoostSigner {
}
}

fn parse_address_from_url(url: Url) -> eyre::Result<String> {
let str = url.as_str();

// take the host out of the URL, e.g. "http://localhost:425" -> localhost:425
// and also "remotehost:2425" -> remotehost:2425
let without_base = url.as_str().split("://").last().unwrap_or(str);
let hostname = without_base.split(':').next().unwrap_or(without_base);
let port = without_base.split(':').last().ok_or_else(|| eyre::eyre!("No port found"))?;
let port = port.trim_end_matches('/');

Ok(format!("{}:{}", hostname, port))
}

#[cfg(test)]
mod test {
use super::*;
Expand All @@ -192,22 +200,14 @@ mod test {
rand::thread_rng().fill(&mut rnd);
let consensus_pubkey = BlsPublicKey::try_from(rnd[..48].as_ref()).unwrap();

let cb_pubkey = cb_common::signer::BlsPublicKey::from_ssz_bytes(consensus_pubkey.as_ref())
.expect("pubkey bytes conversion");
let cb_pubkey = cb_common::signer::BlsPublicKey::from(FixedBytes::<48>::from_slice(
consensus_pubkey.as_ref(),
));

// make sure the bytes haven't changed
assert_eq!(consensus_pubkey.to_vec(), cb_pubkey.to_vec());
}

#[test]
fn test_url_parse_address() {
let url = Url::parse("http://localhost:8080").unwrap();
assert_eq!(parse_address_from_url(url).unwrap(), "localhost:8080");

let url = Url::parse("remotehost:2425").unwrap();
assert_eq!(parse_address_from_url(url).unwrap(), "remotehost:2425");
}

#[tokio::test]
async fn test_bls_commit_boost_signer() -> eyre::Result<()> {
let _ = dotenvy::dotenv();
Expand Down
6 changes: 2 additions & 4 deletions bolt-sidecar/src/signer/keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use std::{
use ethereum_consensus::crypto::PublicKey as BlsPublicKey;
use lighthouse_bls::Keypair;
use lighthouse_eth2_keystore::Keystore;
use ssz::Encode;

use crate::{builder::signature::compute_signing_root, config::ChainConfig, crypto::bls::BLSSig};

Expand Down Expand Up @@ -127,13 +126,12 @@ impl KeystoreSigner {
let sk = self
.keypairs
.iter()
// `as_ssz_bytes` returns the raw bytes we need
.find(|kp| kp.pk.as_ssz_bytes() == public_key.as_ref())
.find(|kp| kp.pk.serialize() == public_key.as_ref())
.ok_or(KeystoreError::UnknownPublicKey(public_key.to_string()))?;

let signing_root = compute_signing_root(root, domain);

let sig = sk.sk.sign(signing_root.into()).as_ssz_bytes();
let sig = sk.sk.sign(signing_root.into()).serialize();
let sig = BLSSig::try_from(sig.as_slice())
.map_err(|e| KeystoreError::SignatureLength(hex::encode(sig), format!("{e:?}")))?;

Expand Down
1 change: 1 addition & 0 deletions bolt-sidecar/src/state/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ impl StateFetcher for StateClient {

#[cfg(test)]
impl StateClient {
/// Return a reference to the inner `ExecutionClient`.
pub fn inner(&self) -> &ExecutionClient {
&self.client
}
Expand Down
4 changes: 1 addition & 3 deletions bolt-sidecar/src/telemetry/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl ApiMetrics {
);
}

/// Counters ----------------------------------------------------------------
// Counters ----------------------------------------------------------------

pub fn increment_total_http_requests(method: String, path: String, status: String) {
counter!(
Expand Down Expand Up @@ -117,7 +117,6 @@ impl ApiMetrics {
}

/// Gauges ----------------------------------------------------------------

pub fn set_latest_head(slot: u32) {
gauge!(LATEST_HEAD).set(slot);
}
Expand All @@ -127,7 +126,6 @@ impl ApiMetrics {
}

/// Mixed ----------------------------------------------------------------

/// Observes the duration of an HTTP request by storing it in a histogram,
/// and incrementing the total number of HTTP requests received.
pub fn observe_http_request(duration: Duration, method: String, path: String, status: String) {
Expand Down
2 changes: 1 addition & 1 deletion bolt-sidecar/src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::env;
use alloy::{
eips::eip2718::Encodable2718,
network::{EthereumWallet, TransactionBuilder},
primitives::{Address, Signature, U256},
primitives::{Address, PrimitiveSignature as Signature, U256},
rpc::types::TransactionRequest,
signers::{
k256::{ecdsa::SigningKey as K256SigningKey, SecretKey as K256SecretKey},
Expand Down
Loading