Skip to content

Commit 4e2e230

Browse files
authored
refactor: update names to be spec compliant for new hwp (#1678)
1 parent 1d8a6f3 commit 4e2e230

File tree

1 file changed

+52
-34
lines changed

1 file changed

+52
-34
lines changed

crates/ethportal-api/src/types/execution/header_with_proof_new.rs

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,21 @@ use crate::{
1313
Header,
1414
};
1515

16-
/// The accumulator proof for the pre-merge blocks.
17-
pub type HistoricalHashesAccumulatorProof = FixedVector<B256, typenum::U15>;
18-
19-
/// Proof that execution header root is part of BeaconBlock, post-Merge and pre-Capella
20-
pub type BeaconBlockProofPreCapella = FixedVector<B256, typenum::U11>;
21-
/// Proof that execution header root is part of BeaconBlock, post-Capella
22-
pub type BeaconBlockProof = VariableList<B256, typenum::U12>;
23-
/// Proof that BeaconBlockHeader root is part of HistoricalRoots
24-
pub type HistoricalRootsProof = FixedVector<B256, typenum::U14>;
25-
/// Proof that BeaconBlockHeader root is part of HistoricalSummaries
26-
pub type HistoricalSummariesProof = FixedVector<B256, typenum::U13>;
16+
/// The accumulator proof for EL BlockHeader for the pre-merge blocks.
17+
pub type BlockProofHistoricalHashesAccumulator = FixedVector<B256, typenum::U15>;
18+
19+
/// Proof that EL block_hash is in BeaconBlock -> BeaconBlockBody -> ExecutionPayload
20+
/// for TheMerge until Capella
21+
pub type ExecutionBlockProof = FixedVector<B256, typenum::U11>;
22+
/// Proof that EL block_hash is in BeaconBlock -> BeaconBlockBody -> ExecutionPayload
23+
/// for Post-Capella
24+
pub type ExecutionBlockProofCapella = VariableList<B256, typenum::U12>;
25+
/// Proof that BeaconBlock root is part of historical_summaries and thus canonical
26+
/// for Capella and onwards
27+
pub type BeaconBlockProofHistoricalSummaries = FixedVector<B256, typenum::U13>;
28+
/// Proof that BeaconBlock root is part of historical_roots and thus canonical
29+
/// from TheMerge until Capella -> Bellatrix fork.
30+
pub type BeaconBlockProofHistoricalRoots = FixedVector<B256, typenum::U14>;
2731

2832
/// A block header with accumulator proof.
2933
/// Type definition:
@@ -37,9 +41,12 @@ pub struct HeaderWithProof {
3741

3842
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
3943
pub enum BlockHeaderProof {
40-
HistoricalHashesAccumulatorProof(HistoricalHashesAccumulatorProof),
41-
HistoricalRootsBlockProof(HistoricalRootsBlockProof),
42-
HistoricalSummariesBlockProof(HistoricalSummariesBlockProof),
44+
// Pre-Merge
45+
HistoricalHashes(BlockProofHistoricalHashesAccumulator),
46+
// Merge -> Capella
47+
HistoricalRoots(BlockProofHistoricalRoots),
48+
// Post-Capella
49+
HistoricalSummaries(BlockProofHistoricalSummaries),
4350
}
4451

4552
impl ssz::Decode for HeaderWithProof {
@@ -59,17 +66,15 @@ impl ssz::Decode for HeaderWithProof {
5966

6067
let proof = decoder.decode_next::<ByteList1024>()?;
6168
let proof = if header.timestamp <= MERGE_TIMESTAMP {
62-
BlockHeaderProof::HistoricalHashesAccumulatorProof(
63-
HistoricalHashesAccumulatorProof::from_ssz_bytes(&proof)?,
69+
BlockHeaderProof::HistoricalHashes(
70+
BlockProofHistoricalHashesAccumulator::from_ssz_bytes(&proof)?,
6471
)
6572
} else if header.number <= SHANGHAI_TIMESTAMP {
66-
BlockHeaderProof::HistoricalRootsBlockProof(HistoricalRootsBlockProof::from_ssz_bytes(
73+
BlockHeaderProof::HistoricalRoots(BlockProofHistoricalRoots::from_ssz_bytes(&proof)?)
74+
} else {
75+
BlockHeaderProof::HistoricalSummaries(BlockProofHistoricalSummaries::from_ssz_bytes(
6776
&proof,
6877
)?)
69-
} else {
70-
BlockHeaderProof::HistoricalSummariesBlockProof(
71-
HistoricalSummariesBlockProof::from_ssz_bytes(&proof)?,
72-
)
7378
};
7479
Ok(Self { header, proof })
7580
}
@@ -82,47 +87,60 @@ impl ssz::Encode for BlockHeaderProof {
8287

8388
fn ssz_append(&self, buf: &mut Vec<u8>) {
8489
match self {
85-
BlockHeaderProof::HistoricalHashesAccumulatorProof(proof) => {
90+
BlockHeaderProof::HistoricalHashes(proof) => {
8691
proof.ssz_append(buf);
8792
}
88-
BlockHeaderProof::HistoricalRootsBlockProof(proof) => {
93+
BlockHeaderProof::HistoricalRoots(proof) => {
8994
proof.ssz_append(buf);
9095
}
91-
BlockHeaderProof::HistoricalSummariesBlockProof(proof) => {
96+
BlockHeaderProof::HistoricalSummaries(proof) => {
9297
proof.ssz_append(buf);
9398
}
9499
}
95100
}
96101

97102
fn ssz_bytes_len(&self) -> usize {
98103
match self {
99-
BlockHeaderProof::HistoricalHashesAccumulatorProof(proof) => proof.ssz_bytes_len(),
100-
BlockHeaderProof::HistoricalRootsBlockProof(proof) => proof.ssz_bytes_len(),
101-
BlockHeaderProof::HistoricalSummariesBlockProof(proof) => proof.ssz_bytes_len(),
104+
BlockHeaderProof::HistoricalHashes(proof) => proof.ssz_bytes_len(),
105+
BlockHeaderProof::HistoricalRoots(proof) => proof.ssz_bytes_len(),
106+
BlockHeaderProof::HistoricalSummaries(proof) => proof.ssz_bytes_len(),
102107
}
103108
}
104109
}
105110

106111
/// The struct holds a chain of proofs. This chain of proofs allows for verifying that an EL
107112
/// `BlockHeader` is part of the canonical chain. The only requirement is having access to the
108113
/// beacon chain `historical_roots`.
109-
// Total size (8 + 1 + 3 + 1 + 14) * 32 bytes + 4 bytes = 868 bytes
114+
///
115+
/// Proof for EL BlockHeader from TheMerge until Capella
110116
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, Serialize, Deserialize)]
111-
pub struct HistoricalRootsBlockProof {
112-
pub beacon_block_proof: BeaconBlockProofPreCapella,
117+
pub struct BlockProofHistoricalRoots {
118+
/// Proof that the BeaconBlock is part of the historical roots
119+
/// and thus part of the canonical chain.
120+
pub beacon_block_proof: BeaconBlockProofHistoricalRoots,
121+
/// hash_tree_root of BeaconBlock used to verify the proofs
113122
pub beacon_block_root: B256,
114-
pub historical_roots_proof: HistoricalRootsProof,
123+
/// Proof that EL BlockHash is part of the BeaconBlock
124+
pub execution_block_proof: ExecutionBlockProof,
125+
/// Slot of BeaconBlock, used to calculate the historical_roots index
115126
pub slot: u64,
116127
}
117128

118129
/// The struct holds a chain of proofs. This chain of proofs allows for verifying that an EL
119130
/// `BlockHeader` is part of the canonical chain. The only requirement is having access to the
120131
/// beacon chain `historical_summaries`.
132+
///
133+
/// Proof for EL BlockHeader for Capella and onwards
121134
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, Serialize, Deserialize)]
122-
pub struct HistoricalSummariesBlockProof {
123-
pub beacon_block_proof: BeaconBlockProof,
135+
pub struct BlockProofHistoricalSummaries {
136+
/// Proof that the BeaconBlock is part of the historical_summaries
137+
/// and thus part of the canonical chain.
138+
pub beacon_block_proof: BeaconBlockProofHistoricalSummaries,
139+
/// hash_tree_root of BeaconBlock used to verify the proofs
124140
pub beacon_block_root: B256,
125-
pub historical_summaries_proof: HistoricalSummariesProof,
141+
/// Proof that EL BlockHash is part of the BeaconBlock
142+
pub execution_block_proof: ExecutionBlockProofCapella,
143+
/// Slot of BeaconBlock, used to calculate the historical_summaries index
126144
pub slot: u64,
127145
}
128146

0 commit comments

Comments
 (0)