Skip to content
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
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"crates/k1util",
"crates/relay-server",
"crates/p2p",
"crates/ssz",
"crates/testutil",
"crates/tracing",
"crates/peerinfo",
Expand Down Expand Up @@ -106,6 +107,7 @@ pluto-eth2util = { path = "crates/eth2util" }
pluto-eth1wrap = { path = "crates/eth1wrap" }
pluto-k1util = { path = "crates/k1util" }
pluto-relay-server = { path = "crates/relay-server" }
pluto-ssz = { path = "crates/ssz" }
pluto-testutil = { path = "crates/testutil" }
pluto-tracing = { path = "crates/tracing" }
pluto-p2p = { path = "crates/p2p" }
Expand Down
1 change: 1 addition & 0 deletions crates/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ tempfile.workspace = true
pluto-cluster.workspace = true
pluto-k1util.workspace = true
pluto-crypto.workspace = true
pluto-ssz.workspace = true

[build-dependencies]
pluto-build-proto.workspace = true
Expand Down
10 changes: 8 additions & 2 deletions crates/app/src/obolapi/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub enum Error {

/// SSZ hashing error from [`pluto_cluster`].
#[error("SSZ hashing error: {0}")]
Ssz(#[from] pluto_cluster::ssz::SSZError<pluto_cluster::ssz_hasher::Hasher>),
Ssz(#[from] pluto_cluster::ssz::SSZError<pluto_ssz::Hasher>),

/// K1 signing error.
#[error("K1 signing error: {0}")]
Expand Down Expand Up @@ -73,5 +73,11 @@ pub enum Error {

/// SSZ hasher error.
#[error("SSZ hasher error: {0}")]
HasherError(#[from] pluto_cluster::ssz_hasher::HasherError),
HasherError(#[from] pluto_ssz::HasherError),
}

impl From<pluto_ssz::Error<pluto_ssz::HasherError>> for Error {
fn from(error: pluto_ssz::Error<pluto_ssz::HasherError>) -> Self {
Self::Ssz(pluto_cluster::ssz::SSZError::from(error))
}
}
9 changes: 3 additions & 6 deletions crates/app/src/obolapi/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use serde::{Deserialize, Serialize};
use pluto_cluster::{
helpers::to_0x_hex,
ssz::{SSZ_LEN_BLS_SIG, SSZ_LEN_PUB_KEY},
ssz_hasher::{HashWalker, Hasher},
};
use pluto_eth2api::types::{
GetPoolVoluntaryExitsResponseResponseDatum, Phase0SignedVoluntaryExitMessage,
};
use pluto_ssz::{HashWalker, Hasher, put_bytes_n};

use crate::obolapi::{
client::Client,
Expand All @@ -26,9 +26,6 @@ use crate::obolapi::{
/// Type alias for signed voluntary exit from eth2api.
pub type SignedVoluntaryExit = GetPoolVoluntaryExitsResponseResponseDatum;

// TODO: Unify SSZ hashing across the workspace. `pluto-cluster` already has
// SSZ hashing utilities. Consider extracting a shared SSZ crate (or promoting
// the existing hasher) so all crates share one SSZ interface and error type.
/// Trait for types that can be hashed using SSZ hash tree root.
pub trait SszHashable {
/// Hashes this value into the provided hasher.
Expand All @@ -48,7 +45,7 @@ impl SszHashable for SignedVoluntaryExit {

self.message.hash_with(hh)?;
let sig_bytes = from_0x(&self.signature, SSZ_LEN_BLS_SIG)?;
pluto_cluster::helpers::put_bytes_n(hh, &sig_bytes, SSZ_LEN_BLS_SIG)?;
put_bytes_n(hh, &sig_bytes, SSZ_LEN_BLS_SIG)?;

hh.merkleize(index)?;
Ok(())
Expand Down Expand Up @@ -236,7 +233,7 @@ impl SszHashable for FullExitAuthBlob {
let index = hh.index();

hh.put_bytes(&self.lock_hash)?;
pluto_cluster::helpers::put_bytes_n(hh, &self.validator_pubkey, SSZ_LEN_PUB_KEY)?;
put_bytes_n(hh, &self.validator_pubkey, SSZ_LEN_PUB_KEY)?;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: maybe ssz::put_bytes_n?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

put_bytes_n is on pluto_ssz which is imported directly

hh.put_uint64(self.share_index)?;

hh.merkleize(index)?;
Expand Down
1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pluto-core.workspace = true
pluto-p2p.workspace = true
pluto-eth2util.workspace = true
pluto-k1util.workspace = true
pluto-ssz.workspace = true
libp2p.workspace = true
tokio-util.workspace = true
tracing.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/commands/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ use crate::{

use k256::SecretKey;
use pluto_app::obolapi::{Client, ClientOptions};
use pluto_cluster::ssz_hasher::{HashWalker, Hasher};
use pluto_eth2util::enr::Record;
use pluto_k1util::{load, sign};
use pluto_ssz::{HashWalker, Hasher};
use reqwest::{Method, StatusCode, header::CONTENT_TYPE};
use serde_with::{base64::Base64, serde_as};
use std::os::unix::fs::PermissionsExt as _;
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub enum CliError {

/// SSZ hasher error.
#[error("Hasher error: {0}")]
HasherError(#[from] pluto_cluster::ssz_hasher::HasherError),
HasherError(#[from] pluto_ssz::HasherError),

/// HTTP request error.
#[error("HTTP request error: {0}")]
Expand Down
1 change: 1 addition & 0 deletions crates/cluster/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pluto-p2p.workspace = true
pluto-eth2util.workspace = true
pluto-eth1wrap.workspace = true
pluto-k1util.workspace = true
pluto-ssz.workspace = true
k256.workspace = true
tokio.workspace = true
reqwest = { workspace = true, features = ["json"] }
Expand Down
45 changes: 23 additions & 22 deletions crates/cluster/src/definition.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use std::collections::HashSet;

use pluto_ssz::{Hasher, serde_utils::Hex0x};

use crate::{
eip712sigs::{
EIP712Error, digest_eip712, eip712_creator_config_hash, eip712_enr,
get_operator_eip712_type,
},
helpers::{EthHex, from_0x_hex_str},
helpers::from_0x_hex_str,
operator::{Operator, OperatorV1X1, OperatorV1X2OrLater},
ssz::{SSZError, hash_definition},
ssz_hasher::Hasher,
version::{CURRENT_VERSION, DKG_ALGO, versions::*},
};
use chrono::{DateTime, Timelike, Utc};
Expand Down Expand Up @@ -771,7 +772,7 @@ pub struct Creator {
/// The Ethereum address of the creator
pub address: String,
/// The creator's signature over the config hash
#[serde_as(as = "EthHex")]
#[serde_as(as = "Hex0x")]
pub config_signature: Vec<u8>,
}

Expand Down Expand Up @@ -817,7 +818,7 @@ pub struct DefinitionV1x0or1 {
pub dkg_algorithm: String,
/// Cluster's 4 byte beacon chain fork version
/// (network/chain identifier).
#[serde_as(as = "EthHex")]
#[serde_as(as = "Hex0x")]
pub fork_version: Vec<u8>,
/// Config hash uniquely identifies a cluster definition excluding operator
/// ENRs and signatures.
Expand Down Expand Up @@ -928,15 +929,15 @@ pub struct DefinitionV1x2or3 {
pub dkg_algorithm: String,
/// Cluster's 4 byte beacon chain fork version
/// (network/chain identifier).
#[serde_as(as = "EthHex")]
#[serde_as(as = "Hex0x")]
pub fork_version: Vec<u8>,
/// Config hash uniquely identifies a cluster definition excluding operator
/// ENRs and signatures.
#[serde_as(as = "EthHex")]
#[serde_as(as = "Hex0x")]
pub config_hash: Vec<u8>,
/// Definition hash uniquely identifies a cluster definition including
/// operator ENRs and signatures.
#[serde_as(as = "EthHex")]
#[serde_as(as = "Hex0x")]
pub definition_hash: Vec<u8>,
}

Expand Down Expand Up @@ -1042,15 +1043,15 @@ pub struct DefinitionV1x4 {
pub dkg_algorithm: String,
/// Cluster's 4 byte beacon chain fork version
/// (network/chain identifier).
#[serde_as(as = "EthHex")]
#[serde_as(as = "Hex0x")]
pub fork_version: Vec<u8>,
/// Config hash uniquely identifies a cluster definition excluding operator
/// ENRs and signatures.
#[serde_as(as = "EthHex")]
#[serde_as(as = "Hex0x")]
pub config_hash: Vec<u8>,
/// Definition hash uniquely identifies a cluster definition including
/// operator ENRs and signatures.
#[serde_as(as = "EthHex")]
#[serde_as(as = "Hex0x")]
pub definition_hash: Vec<u8>,
}

Expand Down Expand Up @@ -1154,15 +1155,15 @@ pub struct DefinitionV1x5to7 {
pub dkg_algorithm: String,
/// Cluster's 4 byte beacon chain fork version
/// (network/chain identifier).
#[serde_as(as = "EthHex")]
#[serde_as(as = "Hex0x")]
pub fork_version: Vec<u8>,
/// Config hash uniquely identifies a cluster definition excluding operator
/// ENRs and signatures.
#[serde_as(as = "EthHex")]
#[serde_as(as = "Hex0x")]
pub config_hash: Vec<u8>,
/// Definition hash uniquely identifies a cluster definition including
/// operator ENRs and signatures.
#[serde_as(as = "EthHex")]
#[serde_as(as = "Hex0x")]
pub definition_hash: Vec<u8>,
}

Expand Down Expand Up @@ -1251,19 +1252,19 @@ pub struct DefinitionV1x8 {
pub dkg_algorithm: String,
/// ForkVersion defines the cluster's 4 byte beacon chain fork version
/// (network/chain identifier).
#[serde_as(as = "EthHex")]
#[serde_as(as = "Hex0x")]
pub fork_version: Vec<u8>,
/// DepositAmounts specifies partial deposit amounts that sum up to at least
/// 32ETH.
#[serde_as(as = "DefaultOnNull<Vec<PickFirst<(DisplayFromStr, _)>>>")]
pub deposit_amounts: Vec<u64>,
/// ConfigHash uniquely identifies a cluster definition excluding operator
/// ENRs and signatures.
#[serde_as(as = "EthHex")]
#[serde_as(as = "Hex0x")]
pub config_hash: Vec<u8>,
/// DefinitionHash uniquely identifies a cluster definition including
/// operator ENRs and signatures.
#[serde_as(as = "EthHex")]
#[serde_as(as = "Hex0x")]
pub definition_hash: Vec<u8>,
}

Expand Down Expand Up @@ -1353,7 +1354,7 @@ pub struct DefinitionV1x9 {
pub dkg_algorithm: String,
/// ForkVersion defines the cluster's 4 byte beacon chain fork version
/// (network/chain identifier).
#[serde_as(as = "EthHex")]
#[serde_as(as = "Hex0x")]
pub fork_version: Vec<u8>,
/// DepositAmounts specifies partial deposit amounts that sum up to at least
/// 32ETH.
Expand All @@ -1364,11 +1365,11 @@ pub struct DefinitionV1x9 {
pub consensus_protocol: String,
/// ConfigHash uniquely identifies a cluster definition excluding operator
/// ENRs and signatures.
#[serde_as(as = "EthHex")]
#[serde_as(as = "Hex0x")]
pub config_hash: Vec<u8>,
/// DefinitionHash uniquely identifies a cluster definition including
/// operator ENRs and signatures.
#[serde_as(as = "EthHex")]
#[serde_as(as = "Hex0x")]
pub definition_hash: Vec<u8>,
}

Expand Down Expand Up @@ -1460,7 +1461,7 @@ pub struct DefinitionV1x10 {
pub dkg_algorithm: String,
/// Cluster's 4 byte beacon chain fork version
/// (network/chain identifier).
#[serde_as(as = "EthHex")]
#[serde_as(as = "Hex0x")]
pub fork_version: Vec<u8>,
/// Partial deposit amounts that sum up to at least
/// 32ETH.
Expand All @@ -1476,11 +1477,11 @@ pub struct DefinitionV1x10 {
pub compounding: bool,
/// Config hash uniquely identifies a cluster definition excluding operator
/// ENRs and signatures.
#[serde_as(as = "EthHex")]
#[serde_as(as = "Hex0x")]
pub config_hash: Vec<u8>,
/// Definition hash uniquely identifies a cluster definition including
/// operator ENRs and signatures.
#[serde_as(as = "EthHex")]
#[serde_as(as = "Hex0x")]
pub definition_hash: Vec<u8>,
}

Expand Down
10 changes: 5 additions & 5 deletions crates/cluster/src/deposit.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
use crate::helpers::EthHex;
use pluto_eth2api::spec::phase0;
use pluto_ssz::serde_utils::Hex0x;
use serde::{Deserialize, Serialize};
use serde_with::{DisplayFromStr, serde_as};

/// DepositData defines the deposit data to activate a validator.
///
/// This is a cluster-specific wrapper around the canonical
/// `phase0::DepositData` that uses EthHex serialization (with 0x prefix) to
/// `phase0::DepositData` that uses `Hex0x` serialization (with 0x prefix) to
/// maintain lock file JSON compatibility.
///
/// Specification: <https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#depositdata>
#[serde_as]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DepositData {
/// Validator's public key (48 bytes).
#[serde_as(as = "EthHex")]
#[serde_as(as = "Hex0x")]
#[serde(rename = "pubkey")]
pub pub_key: phase0::BLSPubKey,

/// Withdrawal credentials included in the deposit (32 bytes).
#[serde_as(as = "EthHex")]
#[serde_as(as = "Hex0x")]
pub withdrawal_credentials: phase0::WithdrawalCredentials,

/// Amount in Gwei to be deposited [1ETH..2048ETH].
Expand All @@ -28,7 +28,7 @@ pub struct DepositData {
pub amount: phase0::Gwei,

/// Signature is the BLS signature of the deposit message (96 bytes).
#[serde_as(as = "EthHex")]
#[serde_as(as = "Hex0x")]
pub signature: phase0::BLSSignature,
}

Expand Down
Loading
Loading