@@ -7,8 +7,9 @@ pub mod utils;
77
88use beacon_api_types:: {
99 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 ,
1213 } ,
1314 light_client_update:: LightClientUpdate ,
1415 ChainSpec , DomainType , ExecutionPayloadHeaderSsz , ForkParameters , LightClientHeader , Slot ,
@@ -42,6 +43,42 @@ pub trait BlsVerify {
4243 ) -> Result < ( ) , Error > ;
4344}
4445
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+
4582/// Verifies if the light client `update` is valid.
4683///
4784/// * `update`: The light client update we want to verify.
@@ -169,8 +206,7 @@ pub fn validate_light_client_update<C: ChainSpec, V: BlsVerify>(
169206 validate_merkle_branch (
170207 & update. finalized_header . beacon . tree_hash_root ( ) ,
171208 & 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) ,
174210 & update. attested_header . beacon . state_root ,
175211 ) ?;
176212
@@ -188,14 +224,17 @@ pub fn validate_light_client_update<C: ChainSpec, V: BlsVerify>(
188224 } ,
189225 ) ?;
190226 }
227+
191228 // This validates the given next sync committee against the attested header's state root.
192229 validate_merkle_branch (
193230 & TryInto :: < SyncCommitteeSsz < C > > :: try_into ( next_sync_committee. clone ( ) )
194231 . unwrap ( )
195232 . 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) ,
199238 & update. attested_header . beacon . state_root ,
200239 ) ?;
201240 }
@@ -245,19 +284,17 @@ pub fn get_lc_execution_root<C: ChainSpec>(
245284 header : & LightClientHeader ,
246285) -> H256 {
247286 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+ }
248293 if epoch >= fork_parameters. deneb . epoch {
249294 return TryInto :: < ExecutionPayloadHeaderSsz < C > > :: try_into ( header. execution . clone ( ) )
250295 . unwrap ( )
251296 . tree_hash_root ( ) ;
252297 }
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-
261298 H256 :: default ( )
262299}
263300
@@ -285,8 +322,7 @@ pub fn is_valid_light_client_header<C: ChainSpec>(
285322 validate_merkle_branch (
286323 & get_lc_execution_root :: < C > ( fork_parameters, header) ,
287324 & header. execution_branch ,
288- floorlog2 ( EXECUTION_PAYLOAD_INDEX ) ,
289- get_subtree_index ( EXECUTION_PAYLOAD_INDEX ) ,
325+ EXECUTION_PAYLOAD_GINDEX ,
290326 & header. beacon . body_root ,
291327 )
292328}
0 commit comments