Skip to content
Open
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
2 changes: 2 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 crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pluto-featureset.workspace = true
prost.workspace = true
prost-types.workspace = true
regex.workspace = true
reqwest = { workspace = true, features = ["stream"] }
serde.workspace = true
serde_json.workspace = true
base64.workspace = true
Expand All @@ -34,6 +35,7 @@ pluto-eth2util.workspace = true
pluto-ssz.workspace = true
ssz.workspace = true
tree_hash.workspace = true
url.workspace = true

[dev-dependencies]
anyhow.workspace = true
Expand Down
51 changes: 51 additions & 0 deletions crates/core/src/ssz_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,57 @@ fn encode_proposal_block(block: &versioned::SignedProposalBlock) -> Result<Vec<u
})
}

/// Decodes a bare per-fork full (non-blinded) signed proposal block body from
/// SSZ binary, selecting the variant by `version`.
///
/// Unlike [`decode_versioned_signed_proposal`], this expects the raw
/// beacon-API SSZ block body with no Charon versioned header — the format a
/// validator client posts to `/eth/v{1,2}/beacon/blocks`. The fork is taken
/// from the `Eth-Consensus-Version` request header, not from the bytes. The
/// blinded endpoint uses [`decode_signed_blinded_proposal_block_body`].
pub fn decode_signed_proposal_block_body(
version: DataVersion,
bytes: &[u8],
) -> Result<versioned::SignedProposalBlock, SszCodecError> {
decode_proposal_block(version, false, bytes)
}

/// Decodes a bare per-fork blinded signed proposal block body from SSZ binary,
/// selecting the variant by `version`.
///
/// The raw beacon-API SSZ block body posted to
/// `/eth/v{1,2}/beacon/blinded_blocks`; the fork is taken from the
/// `Eth-Consensus-Version` request header.
pub fn decode_signed_blinded_proposal_block_body(
version: DataVersion,
bytes: &[u8],
) -> Result<versioned::SignedBlindedProposalBlock, SszCodecError> {
use versioned::SignedBlindedProposalBlock;
Ok(match version {
DataVersion::Bellatrix => SignedBlindedProposalBlock::Bellatrix(
bellatrix::SignedBlindedBeaconBlock::from_ssz_bytes(bytes)?,
),
DataVersion::Capella => SignedBlindedProposalBlock::Capella(
capella::SignedBlindedBeaconBlock::from_ssz_bytes(bytes)?,
),
DataVersion::Deneb => SignedBlindedProposalBlock::Deneb(
deneb::SignedBlindedBeaconBlock::from_ssz_bytes(bytes)?,
),
DataVersion::Electra => SignedBlindedProposalBlock::Electra(
electra::SignedBlindedBeaconBlock::from_ssz_bytes(bytes)?,
),
// Fulu blinded blocks share the Electra layout.
DataVersion::Fulu => SignedBlindedProposalBlock::Fulu(
electra::SignedBlindedBeaconBlock::from_ssz_bytes(bytes)?,
),
DataVersion::Phase0 | DataVersion::Altair | DataVersion::Unknown => {
return Err(SszCodecError::UnknownVersion(
version.to_legacy_u64().unwrap_or(u64::MAX),
));
}
})
}

fn decode_proposal_block(
version: DataVersion,
blinded: bool,
Expand Down
Loading
Loading