@@ -13,17 +13,21 @@ use crate::{
13
13
Header ,
14
14
} ;
15
15
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 > ;
27
31
28
32
/// A block header with accumulator proof.
29
33
/// Type definition:
@@ -37,9 +41,12 @@ pub struct HeaderWithProof {
37
41
38
42
#[ derive( Debug , Clone , PartialEq , Eq , Deserialize ) ]
39
43
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 ) ,
43
50
}
44
51
45
52
impl ssz:: Decode for HeaderWithProof {
@@ -59,17 +66,15 @@ impl ssz::Decode for HeaderWithProof {
59
66
60
67
let proof = decoder. decode_next :: < ByteList1024 > ( ) ?;
61
68
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) ?,
64
71
)
65
72
} 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 (
67
76
& proof,
68
77
) ?)
69
- } else {
70
- BlockHeaderProof :: HistoricalSummariesBlockProof (
71
- HistoricalSummariesBlockProof :: from_ssz_bytes ( & proof) ?,
72
- )
73
78
} ;
74
79
Ok ( Self { header, proof } )
75
80
}
@@ -82,47 +87,60 @@ impl ssz::Encode for BlockHeaderProof {
82
87
83
88
fn ssz_append ( & self , buf : & mut Vec < u8 > ) {
84
89
match self {
85
- BlockHeaderProof :: HistoricalHashesAccumulatorProof ( proof) => {
90
+ BlockHeaderProof :: HistoricalHashes ( proof) => {
86
91
proof. ssz_append ( buf) ;
87
92
}
88
- BlockHeaderProof :: HistoricalRootsBlockProof ( proof) => {
93
+ BlockHeaderProof :: HistoricalRoots ( proof) => {
89
94
proof. ssz_append ( buf) ;
90
95
}
91
- BlockHeaderProof :: HistoricalSummariesBlockProof ( proof) => {
96
+ BlockHeaderProof :: HistoricalSummaries ( proof) => {
92
97
proof. ssz_append ( buf) ;
93
98
}
94
99
}
95
100
}
96
101
97
102
fn ssz_bytes_len ( & self ) -> usize {
98
103
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 ( ) ,
102
107
}
103
108
}
104
109
}
105
110
106
111
/// The struct holds a chain of proofs. This chain of proofs allows for verifying that an EL
107
112
/// `BlockHeader` is part of the canonical chain. The only requirement is having access to the
108
113
/// 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
110
116
#[ 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
113
122
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
115
126
pub slot : u64 ,
116
127
}
117
128
118
129
/// The struct holds a chain of proofs. This chain of proofs allows for verifying that an EL
119
130
/// `BlockHeader` is part of the canonical chain. The only requirement is having access to the
120
131
/// beacon chain `historical_summaries`.
132
+ ///
133
+ /// Proof for EL BlockHeader for Capella and onwards
121
134
#[ 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
124
140
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
126
144
pub slot : u64 ,
127
145
}
128
146
0 commit comments