From 4a565ac2c22392462a67d109471659d1022e5725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Tue, 13 Jan 2026 16:09:06 -0300 Subject: [PATCH 1/4] feat: decode gossiped attestations --- crates/blockchain/src/lib.rs | 16 ++++++++++++++++ crates/common/types/src/attestation.rs | 14 ++++++++++++-- crates/net/p2p/src/gossipsub.rs | 21 ++++++++++++++++----- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/crates/blockchain/src/lib.rs b/crates/blockchain/src/lib.rs index f51eabd7b..45b1f3094 100644 --- a/crates/blockchain/src/lib.rs +++ b/crates/blockchain/src/lib.rs @@ -1,5 +1,6 @@ use ethlambda_storage::Store; use ethlambda_types::{ + attestation::SignedAttestation, block::SignedBlockWithAttestation, primitives::{Encode, TreeHash}, }; @@ -27,6 +28,17 @@ impl BlockChain { .await .inspect_err(|err| error!(%err, "Failed to notify BlockChain of new block")); } + + /// Sends an attestation to the BlockChain for processing. + /// + /// Note that this is *NOT* `async`, since the internal [`GenServerHandle::cast`] is non-blocking. + pub async fn notify_new_attestation(&mut self, attestation: SignedAttestation) { + let _ = self + .handle + .cast(CastMessage::NewAttestation(attestation)) + .await + .inspect_err(|err| error!(%err, "Failed to notify BlockChain of new attestation")); + } } struct BlockChainServer { @@ -70,11 +82,14 @@ impl BlockChainServer { info!(%slot, %block_root, %state_root, "Processed new block"); update_head_slot(slot); } + + fn on_attestation(&mut self, attestation: SignedAttestation) {} } #[derive(Clone, Debug)] enum CastMessage { NewBlock(SignedBlockWithAttestation), + NewAttestation(SignedAttestation), } impl GenServer for BlockChainServer { @@ -103,6 +118,7 @@ impl GenServer for BlockChainServer { CastMessage::NewBlock(signed_block) => { self.on_block(signed_block); } + CastMessage::NewAttestation(attestation) => self.on_attestation(attestation), } CastResponse::NoReply } diff --git a/crates/common/types/src/attestation.rs b/crates/common/types/src/attestation.rs index 841bf6fda..1815ce1bf 100644 --- a/crates/common/types/src/attestation.rs +++ b/crates/common/types/src/attestation.rs @@ -1,3 +1,4 @@ +use ssz::Encode; use ssz_derive::{Decode, Encode}; use tree_hash_derive::TreeHash; @@ -36,9 +37,18 @@ pub struct AttestationData { #[derive(Clone, Encode, Decode)] pub struct SignedAttestation { /// The attestation message signed by the validator. - message: Attestation, + pub message: Attestation, /// Signature aggregation produced by the leanVM (SNARKs in the future). - signature: Signature, + pub signature: Signature, +} + +impl core::fmt::Debug for SignedAttestation { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("SignedAttestation") + .field("message", &self.message) + .field("signature", &self.signature.as_ssz_bytes()) + .finish() + } } /// Aggregated attestation consisting of participation bits and message. diff --git a/crates/net/p2p/src/gossipsub.rs b/crates/net/p2p/src/gossipsub.rs index 2007e51fc..5de7c9de0 100644 --- a/crates/net/p2p/src/gossipsub.rs +++ b/crates/net/p2p/src/gossipsub.rs @@ -1,5 +1,5 @@ use ethlambda_blockchain::BlockChain; -use ethlambda_types::block::SignedBlockWithAttestation; +use ethlambda_types::{attestation::SignedAttestation, block::SignedBlockWithAttestation}; use libp2p::gossipsub::Event; use ssz::Decode; use tracing::{error, info, trace}; @@ -36,10 +36,21 @@ pub async fn handle_gossipsub_message(blockchain: &mut BlockChain, event: Event) blockchain.notify_new_block(signed_block).await; } Some(ATTESTATION_TOPIC_KIND) => { - info!( - "Received attestation gossip message of size {} bytes", - message.data.len() - ); + let Ok(uncompressed_data) = decompress_message(&message.data) + .inspect_err(|err| error!(%err, "Failed to decompress gossipped attestation")) + else { + return; + }; + + let Ok(signed_attestation) = SignedAttestation::from_ssz_bytes(&uncompressed_data) + .inspect_err(|err| error!(?err, "Failed to decode gossipped attestation")) + else { + return; + }; + let slot = signed_attestation.message.data.slot; + let validator = signed_attestation.message.validator_id; + info!(%slot, %validator, "Received new attestation from gossipsub, sending for processing"); + blockchain.notify_new_attestation(signed_attestation).await; } _ => { trace!("Received message on unknown topic: {}", message.topic); From 7b83e4bfe5ead730048994bc3c894c9281e72214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Tue, 13 Jan 2026 16:13:29 -0300 Subject: [PATCH 2/4] fix: use correct SignedAttestation shape --- crates/blockchain/src/lib.rs | 4 +--- crates/common/types/src/attestation.rs | 4 +++- crates/net/p2p/src/gossipsub.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/blockchain/src/lib.rs b/crates/blockchain/src/lib.rs index 45b1f3094..2822145c1 100644 --- a/crates/blockchain/src/lib.rs +++ b/crates/blockchain/src/lib.rs @@ -1,8 +1,6 @@ use ethlambda_storage::Store; use ethlambda_types::{ - attestation::SignedAttestation, - block::SignedBlockWithAttestation, - primitives::{Encode, TreeHash}, + attestation::SignedAttestation, block::SignedBlockWithAttestation, primitives::TreeHash, }; use spawned_concurrency::tasks::{CallResponse, CastResponse, GenServer, GenServerHandle}; use tracing::{error, info, warn}; diff --git a/crates/common/types/src/attestation.rs b/crates/common/types/src/attestation.rs index 1815ce1bf..d03197010 100644 --- a/crates/common/types/src/attestation.rs +++ b/crates/common/types/src/attestation.rs @@ -36,8 +36,10 @@ pub struct AttestationData { /// Validator attestation bundled with its signature. #[derive(Clone, Encode, Decode)] pub struct SignedAttestation { + /// The index of the validator making the attestation. + pub validator_id: u64, /// The attestation message signed by the validator. - pub message: Attestation, + pub message: AttestationData, /// Signature aggregation produced by the leanVM (SNARKs in the future). pub signature: Signature, } diff --git a/crates/net/p2p/src/gossipsub.rs b/crates/net/p2p/src/gossipsub.rs index 5de7c9de0..b3bc31b2e 100644 --- a/crates/net/p2p/src/gossipsub.rs +++ b/crates/net/p2p/src/gossipsub.rs @@ -47,8 +47,8 @@ pub async fn handle_gossipsub_message(blockchain: &mut BlockChain, event: Event) else { return; }; - let slot = signed_attestation.message.data.slot; - let validator = signed_attestation.message.validator_id; + let slot = signed_attestation.message.slot; + let validator = signed_attestation.validator_id; info!(%slot, %validator, "Received new attestation from gossipsub, sending for processing"); blockchain.notify_new_attestation(signed_attestation).await; } From 99aeee09bd58ac3999670614e92394b3a3179fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Tue, 13 Jan 2026 16:19:19 -0300 Subject: [PATCH 3/4] fix: use opaque signatures instead of leanSig types --- crates/common/types/src/attestation.rs | 16 ++++------------ crates/common/types/src/block.rs | 5 +---- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/crates/common/types/src/attestation.rs b/crates/common/types/src/attestation.rs index d03197010..504010719 100644 --- a/crates/common/types/src/attestation.rs +++ b/crates/common/types/src/attestation.rs @@ -1,9 +1,8 @@ -use ssz::Encode; use ssz_derive::{Decode, Encode}; use tree_hash_derive::TreeHash; use crate::{ - signature::Signature, + signature::SignatureSize, state::{Checkpoint, ValidatorRegistryLimit}, }; @@ -34,24 +33,17 @@ pub struct AttestationData { } /// Validator attestation bundled with its signature. -#[derive(Clone, Encode, Decode)] +#[derive(Debug, Clone, Encode, Decode)] pub struct SignedAttestation { /// The index of the validator making the attestation. pub validator_id: u64, /// The attestation message signed by the validator. pub message: AttestationData, /// Signature aggregation produced by the leanVM (SNARKs in the future). - pub signature: Signature, + pub signature: XmssSignature, } -impl core::fmt::Debug for SignedAttestation { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("SignedAttestation") - .field("message", &self.message) - .field("signature", &self.signature.as_ssz_bytes()) - .finish() - } -} +pub type XmssSignature = ssz_types::FixedVector; /// Aggregated attestation consisting of participation bits and message. #[derive(Debug, Clone, Encode, Decode, TreeHash)] diff --git a/crates/common/types/src/block.rs b/crates/common/types/src/block.rs index 3cf515061..21884d5dc 100644 --- a/crates/common/types/src/block.rs +++ b/crates/common/types/src/block.rs @@ -3,9 +3,8 @@ use ssz_types::typenum::U1048576; use tree_hash_derive::TreeHash; use crate::{ - attestation::{AggregatedAttestation, Attestation}, + attestation::{AggregatedAttestation, Attestation, XmssSignature}, primitives::{ByteList, H256}, - signature::SignatureSize, state::ValidatorRegistryLimit, }; @@ -68,8 +67,6 @@ pub type AttestationSignatures = pub type NaiveAggregatedSignature = ssz_types::VariableList; -pub type XmssSignature = ssz_types::FixedVector; - /// Cryptographic proof that a set of validators signed a message. /// /// This container encapsulates the output of the leanVM signature aggregation, From 81cdbffe9e1219e3cad0c44d33107bc3ae16b496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Tue, 13 Jan 2026 16:20:26 -0300 Subject: [PATCH 4/4] docs: update readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7c8738587..548e1551d 100644 --- a/README.md +++ b/README.md @@ -71,8 +71,8 @@ This milestone focuses on computing the chain state from the gossiped by peers r This milestone focuses on choosing the head of the chain based on gossiped attestations. -- Listen for attestations in gossipsub 🏗️ -- Implement fork-choice rule +- Listen for attestations in gossipsub ✅ +- Implement fork-choice rule 🏗️ - Apply fork-choice rule based on received attestations ### Produce blocks and attestations