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
18 changes: 10 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ cb-pbs = { path = "crates/pbs" }
cb-signer = { path = "crates/signer" }

# ethereum
alloy = { version = "0.2.0", features = ["rpc-types-beacon"] }
ethereum_ssz = "0.5"
ethereum_ssz_derive = "0.5.3"
ssz_types = "0.5"
ethereum_serde_utils = "0.5.2"
ethereum-types = "0.14.1"
alloy = { version = "0.3.6", features = [
"rpc-types-beacon",
"serde",
"ssz",
"getrandom",
] }
ssz_types = "0.8"
ethereum_serde_utils = "0.7.0"

# networking
axum = { version = "0.7.5", features = ["macros"] }
Expand Down Expand Up @@ -60,8 +62,8 @@ prometheus = "0.13.4"

# crypto
blst = "0.3.11"
tree_hash = "0.5"
tree_hash_derive = "0.5"
tree_hash = "0.8"
tree_hash_derive = "0.8"
eth2_keystore = { git = "https://github.com/sigp/lighthouse", rev = "9e12c21f268c80a3f002ae0ca27477f9f512eb6f" }
k256 = "0.13"

Expand Down
5 changes: 1 addition & 4 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ publish = false

[dependencies]
# ethereum
alloy = { workspace = true, features = ["ssz"] }
ethereum_ssz.workspace = true
alloy = { workspace = true }
ssz_types.workspace = true
ethereum_ssz_derive.workspace = true
ethereum_serde_utils.workspace = true
ethereum-types.workspace = true

# networking
axum.workspace = true
Expand Down
9 changes: 2 additions & 7 deletions crates/common/src/commit/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use std::fmt::{self, Debug, Display, LowerHex};
use alloy::rpc::types::beacon::BlsSignature;
use derive_more::derive::From;
use serde::{Deserialize, Serialize};
use ssz::{Decode, Encode};
use ssz_derive::{Decode, Encode};
use tree_hash::TreeHash;
use tree_hash_derive::TreeHash;

Expand All @@ -16,17 +14,14 @@ use crate::{
types::Chain,
};

pub trait PublicKey:
AsRef<[u8]> + Debug + Clone + Copy + Encode + Decode + TreeHash + Display + LowerHex
{
}
pub trait PublicKey: AsRef<[u8]> + Debug + Clone + Copy + TreeHash + Display + LowerHex {}

impl PublicKey for EcdsaPublicKey {}

impl PublicKey for BlsPublicKey {}

// GENERIC PROXY DELEGATION
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Encode, Decode, TreeHash)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, TreeHash)]
pub struct ProxyDelegation<T: PublicKey> {
pub delegator: BlsPublicKey,
pub proxy: T,
Expand Down
46 changes: 23 additions & 23 deletions crates/common/src/pbs/types/beacon_block.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use alloy::{primitives::B256, rpc::types::beacon::BlsSignature};
use serde::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};

use super::{
blinded_block_body::BlindedBeaconBlockBody, blobs_bundle::BlobsBundle,
execution_payload::ExecutionPayload, spec::DenebSpec, utils::VersionedResponse,
};

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
/// Sent to relays in submit_block
pub struct SignedBlindedBeaconBlock {
pub message: BlindedBeaconBlock,
Expand All @@ -20,7 +19,7 @@ impl SignedBlindedBeaconBlock {
}
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct BlindedBeaconBlock {
#[serde(with = "serde_utils::quoted_u64")]
pub slot: u64,
Expand All @@ -34,7 +33,7 @@ pub struct BlindedBeaconBlock {
/// Returned by relay in submit_block
pub type SubmitBlindedBlockResponse = VersionedResponse<PayloadAndBlobs>;

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct PayloadAndBlobs {
pub execution_payload: ExecutionPayload<DenebSpec>,
pub blobs_bundle: Option<BlobsBundle<DenebSpec>>,
Expand All @@ -48,7 +47,10 @@ impl SubmitBlindedBlockResponse {

#[cfg(test)]
mod tests {
use serde_json::json;

use super::{SignedBlindedBeaconBlock, SubmitBlindedBlockResponse};
use crate::utils::test_encode_decode;

#[test]
// this is from the builder api spec, but with sync_committee_bits fixed to
Expand Down Expand Up @@ -248,7 +250,7 @@ mod tests {
"signature": "0x1b66ac1fb663c9bc59509846d6ec05345bd908eda73e670af888da41af171505cc411d61252fb6cb3fa0017b679f8bb2305b26a285fa2737f175668d0dff91cc1b66ac1fb663c9bc59509846d6ec05345bd908eda73e670af888da41af171505"
}"#;

assert!(serde_json::from_str::<SignedBlindedBeaconBlock>(&data).is_ok());
test_encode_decode::<SignedBlindedBeaconBlock>(&data);
}

#[test]
Expand Down Expand Up @@ -535,7 +537,7 @@ mod tests {
},
"execution_payload_header": {
"parent_hash": "0xa330251430b91a6fb5342f30a1f527dc76499c03a411464235951dbd51b94d9f",
"fee_recipient": "0xf97e180c050e5Ab072211Ad2C213Eb5AEE4DF134",
"fee_recipient": "0xf97e180c050e5ab072211ad2c213eb5aee4df134",
"state_root": "0x079f2cc22a29388fd4fc20f451cbaa3ff39845d68b2c368ff7be314617418e38",
"receipts_root": "0xed980a4cf6df8ba330c14ed9fe0597ec20515f44e5a9adfd2f7b72aa14890996",
"logs_bloom": "0x0000000400000008000008000040000000000000000000001000104880000200000004000000400000000204000020002000000000000000000000000022000800000004000000000002000c000000000000000000000100000000000000000000000000000000000000000000000040000000000040000001000014000000010002104000000000000000000000000000000000000000000000000000000080020000000000000000002400000000000001000000000002000200102000000040100002000000000000000000000000000000000000000800000000000000000010000000000000000000000000000000000400002000000000000000200000",
Expand All @@ -562,19 +564,19 @@ mod tests {
"signature": "0x8c3095fd9d3a18e43ceeb7648281e16bb03044839dffea796432c4e5a1372bef22c11a98a31e0c1c5389b98cc6d45917170a0f1634bcf152d896f360dc599fabba2ec4de77898b5dff080fa1628482bdbad5b37d2e64fea3d8721095186cfe50"
}"#;

assert!(serde_json::from_str::<SignedBlindedBeaconBlock>(&data).is_ok());
test_encode_decode::<SignedBlindedBeaconBlock>(&data);
}

#[test]
// this is from the builder api spec, but with blobs fixed to deserialize
// correctly
fn test_submit_blinded_block_response() {
let blob = alloy::primitives::hex::encode([1; 131072]);
let data = format!(
r#"{{
let blob = alloy::primitives::hex::encode_prefixed([1; 131072]);

let data = json!({
"version": "deneb",
"data": {{
"execution_payload": {{
"data": {
"execution_payload": {
"parent_hash":
"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
"fee_recipient": "0xabcf8e0d4e9587369b2301d0790347320302cc09",
Expand All @@ -598,30 +600,28 @@ mod tests {
"0x02f878831469668303f51d843b9ac9f9843b9aca0082520894c93269b73096998db66be0441e836d873535cb9c8894a19041886f000080c001a031cc29234036afbf9a1fb9476b463367cb1f957ac0b919b69bbc798436e604aaa018c4e9c3914eb27aadd0b91e10b18655739fcf8c1fc398763a9f1beecb8ddc86"
],
"withdrawals": [
{{
{
"index": "1",
"validator_index": "1",
"address": "0xabcf8e0d4e9587369b2301d0790347320302cc09",
"amount": "32000000000"
}}
}
]
}},
"blobs_bundle": {{
},
"blobs_bundle": {
"commitments": [
"0x8dab030c51e16e84be9caab84ee3d0b8bbec1db4a0e4de76439da8424d9b957370a10a78851f97e4b54d2ce1ab0d686f"
],
"proofs": [
"0xb4021b0de10f743893d4f71e1bf830c019e832958efd6795baf2f83b8699a9eccc5dc99015d8d4d8ec370d0cc333c06a"
],
"blobs": [
"0x{}"
blob
]
}}
}}
}}"#,
blob
);
}
}
}).to_string();

assert!(serde_json::from_str::<SubmitBlindedBlockResponse>(&data).is_ok());
test_encode_decode::<SubmitBlindedBlockResponse>(&data);
}
}
35 changes: 17 additions & 18 deletions crates/common/src/pbs/types/blinded_block_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ use alloy::{
rpc::types::beacon::{BlsPublicKey, BlsSignature},
};
use serde::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};
use ssz_types::{typenum, BitList, BitVector, FixedVector, VariableList};

use super::{
execution_payload::ExecutionPayloadHeader, kzg::KzgCommitments, spec::EthSpec, utils::*,
};
use crate::utils::as_str;

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct BlindedBeaconBlockBody<T: EthSpec> {
pub randao_reveal: BlsSignature,
pub eth1_data: Eth1Data,
Expand All @@ -28,15 +27,15 @@ pub struct BlindedBeaconBlockBody<T: EthSpec> {
pub blob_kzg_commitments: KzgCommitments<T>,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct Eth1Data {
pub deposit_root: B256,
#[serde(with = "serde_utils::quoted_u64")]
pub deposit_count: u64,
pub block_hash: B256,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct BeaconBlockHeader {
#[serde(with = "serde_utils::quoted_u64")]
pub slot: u64,
Expand All @@ -47,39 +46,39 @@ pub struct BeaconBlockHeader {
pub body_root: B256,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct SignedBeaconBlockHeader {
pub message: BeaconBlockHeader,
pub signature: BlsSignature,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct BlsToExecutionChange {
#[serde(with = "as_str")]
pub validator_index: u64,
pub from_bls_pubkey: BlsPublicKey,
pub to_execution_address: Address,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct SignedBlsToExecutionChange {
pub message: BlsToExecutionChange,
pub signature: BlsSignature,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct ProposerSlashing {
pub signed_header_1: SignedBeaconBlockHeader,
pub signed_header_2: SignedBeaconBlockHeader,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct AttesterSlashing<T: EthSpec> {
pub attestation_1: IndexedAttestation<T>,
pub attestation_2: IndexedAttestation<T>,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[serde(bound = "T: EthSpec")]
pub struct IndexedAttestation<T: EthSpec> {
/// Lists validator registry indices, not committee indices.
Expand All @@ -89,7 +88,7 @@ pub struct IndexedAttestation<T: EthSpec> {
pub signature: BlsSignature,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct AttestationData {
#[serde(with = "serde_utils::quoted_u64")]
pub slot: u64,
Expand All @@ -102,28 +101,28 @@ pub struct AttestationData {
pub target: Checkpoint,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct Checkpoint {
#[serde(with = "serde_utils::quoted_u64")]
pub epoch: u64,
pub root: B256,
}

#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(bound = "T: EthSpec")]
pub struct Attestation<T: EthSpec> {
pub aggregation_bits: BitList<T::MaxValidatorsPerCommittee>,
pub data: AttestationData,
pub signature: BlsSignature,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct Deposit {
pub proof: FixedVector<B256, typenum::U33>, // put this in EthSpec?
pub data: DepositData,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct DepositData {
pub pubkey: BlsPublicKey,
pub withdrawal_credentials: B256,
Expand All @@ -132,13 +131,13 @@ pub struct DepositData {
pub signature: BlsSignature,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct SignedVoluntaryExit {
pub message: VoluntaryExit,
pub signature: BlsSignature,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct VoluntaryExit {
/// Earliest epoch when voluntary exit can be processed.
#[serde(with = "serde_utils::quoted_u64")]
Expand All @@ -147,7 +146,7 @@ pub struct VoluntaryExit {
pub validator_index: u64,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[serde(bound = "T: EthSpec")]
pub struct SyncAggregate<T: EthSpec> {
pub sync_committee_bits: BitVector<T::SyncCommitteeSize>,
Expand Down
3 changes: 1 addition & 2 deletions crates/common/src/pbs/types/blobs_bundle.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use serde::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};
use ssz_types::{FixedVector, VariableList};

use super::{
kzg::{KzgCommitments, KzgProofs},
spec::EthSpec,
};

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[serde(bound = "T: EthSpec")]
pub struct BlobsBundle<T: EthSpec> {
pub commitments: KzgCommitments<T>,
Expand Down
Loading