@@ -7,8 +7,9 @@ pub mod utils;
7
7
8
8
use beacon_api_types:: {
9
9
consts:: {
10
- floorlog2, get_subtree_index, EXECUTION_PAYLOAD_INDEX , FINALIZED_ROOT_INDEX ,
11
- NEXT_SYNC_COMMITTEE_INDEX ,
10
+ CURRENT_SYNC_COMMITTEE_GINDEX , CURRENT_SYNC_COMMITTEE_GINDEX_ELECTRA ,
11
+ EXECUTION_PAYLOAD_GINDEX , FINALIZED_ROOT_GINDEX , FINALIZED_ROOT_GINDEX_ELECTRA ,
12
+ NEXT_SYNC_COMMITTEE_GINDEX , NEXT_SYNC_COMMITTEE_GINDEX_ELECTRA ,
12
13
} ,
13
14
light_client_update:: LightClientUpdate ,
14
15
ChainSpec , DomainType , ExecutionPayloadHeaderSsz , ForkParameters , LightClientHeader , Slot ,
@@ -42,6 +43,42 @@ pub trait BlsVerify {
42
43
) -> Result < ( ) , Error > ;
43
44
}
44
45
46
+ // https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md#finalized_root_gindex_at_slot
47
+ pub fn finalized_root_gindex_at_slot < C : ChainSpec > (
48
+ fork_parameters : & ForkParameters ,
49
+ slot : Slot ,
50
+ ) -> u64 {
51
+ let epoch = compute_epoch_at_slot :: < C > ( slot) ;
52
+ if epoch >= fork_parameters. electra . epoch {
53
+ return FINALIZED_ROOT_GINDEX_ELECTRA ;
54
+ }
55
+ FINALIZED_ROOT_GINDEX
56
+ }
57
+
58
+ // https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md#current_sync_committee_gindex_at_slot
59
+ pub fn current_sync_committee_gindex_at_slot < C : ChainSpec > (
60
+ fork_parameters : & ForkParameters ,
61
+ slot : Slot ,
62
+ ) -> u64 {
63
+ let epoch = compute_epoch_at_slot :: < C > ( slot) ;
64
+ if epoch >= fork_parameters. electra . epoch {
65
+ return CURRENT_SYNC_COMMITTEE_GINDEX_ELECTRA ;
66
+ }
67
+ CURRENT_SYNC_COMMITTEE_GINDEX
68
+ }
69
+
70
+ // https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md#next_sync_committee_gindex_at_slot
71
+ pub fn next_sync_committee_gindex_at_slot < C : ChainSpec > (
72
+ fork_parameters : & ForkParameters ,
73
+ slot : Slot ,
74
+ ) -> u64 {
75
+ let epoch = compute_epoch_at_slot :: < C > ( slot) ;
76
+ if epoch >= fork_parameters. electra . epoch {
77
+ return NEXT_SYNC_COMMITTEE_GINDEX_ELECTRA ;
78
+ }
79
+ NEXT_SYNC_COMMITTEE_GINDEX
80
+ }
81
+
45
82
/// Verifies if the light client `update` is valid.
46
83
///
47
84
/// * `update`: The light client update we want to verify.
@@ -169,8 +206,7 @@ pub fn validate_light_client_update<C: ChainSpec, V: BlsVerify>(
169
206
validate_merkle_branch (
170
207
& update. finalized_header . beacon . tree_hash_root ( ) ,
171
208
& update. finality_branch ,
172
- floorlog2 ( FINALIZED_ROOT_INDEX ) ,
173
- get_subtree_index ( FINALIZED_ROOT_INDEX ) ,
209
+ finalized_root_gindex_at_slot :: < C > ( fork_parameters, update_attested_slot) ,
174
210
& update. attested_header . beacon . state_root ,
175
211
) ?;
176
212
@@ -188,14 +224,17 @@ pub fn validate_light_client_update<C: ChainSpec, V: BlsVerify>(
188
224
} ,
189
225
) ?;
190
226
}
227
+
191
228
// This validates the given next sync committee against the attested header's state root.
192
229
validate_merkle_branch (
193
230
& TryInto :: < SyncCommitteeSsz < C > > :: try_into ( next_sync_committee. clone ( ) )
194
231
. unwrap ( )
195
232
. tree_hash_root ( ) ,
196
- & update. next_sync_committee_branch . unwrap_or_default ( ) ,
197
- floorlog2 ( NEXT_SYNC_COMMITTEE_INDEX ) ,
198
- get_subtree_index ( NEXT_SYNC_COMMITTEE_INDEX ) ,
233
+ & update
234
+ . next_sync_committee_branch
235
+ . clone ( )
236
+ . unwrap_or_default ( ) [ ..] ,
237
+ next_sync_committee_gindex_at_slot :: < C > ( fork_parameters, update_attested_slot) ,
199
238
& update. attested_header . beacon . state_root ,
200
239
) ?;
201
240
}
@@ -245,19 +284,17 @@ pub fn get_lc_execution_root<C: ChainSpec>(
245
284
header : & LightClientHeader ,
246
285
) -> H256 {
247
286
let epoch = compute_epoch_at_slot :: < C > ( header. beacon . slot ) ;
287
+ // Now new field in electra
288
+ if epoch >= fork_parameters. electra . epoch {
289
+ return TryInto :: < ExecutionPayloadHeaderSsz < C > > :: try_into ( header. execution . clone ( ) )
290
+ . unwrap ( )
291
+ . tree_hash_root ( ) ;
292
+ }
248
293
if epoch >= fork_parameters. deneb . epoch {
249
294
return TryInto :: < ExecutionPayloadHeaderSsz < C > > :: try_into ( header. execution . clone ( ) )
250
295
. unwrap ( )
251
296
. tree_hash_root ( ) ;
252
297
}
253
-
254
- // TODO: Figure out what to do here
255
- // if epoch >= fork_parameters.capella.epoch {
256
- // return CapellaExecutionPayloadHeader::from(header.execution.clone())
257
- // .tree_hash_root()
258
- // .into();
259
- // }
260
-
261
298
H256 :: default ( )
262
299
}
263
300
@@ -285,8 +322,7 @@ pub fn is_valid_light_client_header<C: ChainSpec>(
285
322
validate_merkle_branch (
286
323
& get_lc_execution_root :: < C > ( fork_parameters, header) ,
287
324
& header. execution_branch ,
288
- floorlog2 ( EXECUTION_PAYLOAD_INDEX ) ,
289
- get_subtree_index ( EXECUTION_PAYLOAD_INDEX ) ,
325
+ EXECUTION_PAYLOAD_GINDEX ,
290
326
& header. beacon . body_root ,
291
327
)
292
328
}
0 commit comments