-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(eth-lc): electra fork #3878
Open
hussein-aitlahcen
wants to merge
3
commits into
main
Choose a base branch
from
ethereum-electra
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+92
−59
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
lib/ethereum-light-client-types/src/light_client_update_data.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,9 @@ pub mod utils; | |
|
||
use beacon_api_types::{ | ||
consts::{ | ||
floorlog2, get_subtree_index, EXECUTION_PAYLOAD_INDEX, FINALIZED_ROOT_INDEX, | ||
NEXT_SYNC_COMMITTEE_INDEX, | ||
CURRENT_SYNC_COMMITTEE_GINDEX, CURRENT_SYNC_COMMITTEE_GINDEX_ELECTRA, | ||
EXECUTION_PAYLOAD_GINDEX, FINALIZED_ROOT_GINDEX, FINALIZED_ROOT_GINDEX_ELECTRA, | ||
NEXT_SYNC_COMMITTEE_GINDEX, NEXT_SYNC_COMMITTEE_GINDEX_ELECTRA, | ||
}, | ||
light_client_update::LightClientUpdate, | ||
ChainSpec, DomainType, ExecutionPayloadHeaderSsz, ForkParameters, LightClientHeader, Slot, | ||
|
@@ -42,6 +43,42 @@ pub trait BlsVerify { | |
) -> Result<(), Error>; | ||
} | ||
|
||
// https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md#finalized_root_gindex_at_slot | ||
pub fn finalized_root_gindex_at_slot<C: ChainSpec>( | ||
fork_parameters: &ForkParameters, | ||
slot: Slot, | ||
) -> u64 { | ||
let epoch = compute_epoch_at_slot::<C>(slot); | ||
if epoch >= fork_parameters.electra.epoch { | ||
return FINALIZED_ROOT_GINDEX_ELECTRA; | ||
} | ||
FINALIZED_ROOT_GINDEX | ||
} | ||
|
||
// https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md#current_sync_committee_gindex_at_slot | ||
pub fn current_sync_committee_gindex_at_slot<C: ChainSpec>( | ||
fork_parameters: &ForkParameters, | ||
slot: Slot, | ||
) -> u64 { | ||
let epoch = compute_epoch_at_slot::<C>(slot); | ||
if epoch >= fork_parameters.electra.epoch { | ||
return CURRENT_SYNC_COMMITTEE_GINDEX_ELECTRA; | ||
} | ||
CURRENT_SYNC_COMMITTEE_GINDEX | ||
} | ||
|
||
// https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md#next_sync_committee_gindex_at_slot | ||
pub fn next_sync_committee_gindex_at_slot<C: ChainSpec>( | ||
fork_parameters: &ForkParameters, | ||
slot: Slot, | ||
) -> u64 { | ||
let epoch = compute_epoch_at_slot::<C>(slot); | ||
if epoch >= fork_parameters.electra.epoch { | ||
return NEXT_SYNC_COMMITTEE_GINDEX_ELECTRA; | ||
} | ||
NEXT_SYNC_COMMITTEE_GINDEX | ||
} | ||
|
||
Comment on lines
+46
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. small nit but make the links doc comments: |
||
/// Verifies if the light client `update` is valid. | ||
/// | ||
/// * `update`: The light client update we want to verify. | ||
|
@@ -169,8 +206,7 @@ pub fn validate_light_client_update<C: ChainSpec, V: BlsVerify>( | |
validate_merkle_branch( | ||
&update.finalized_header.beacon.tree_hash_root(), | ||
&update.finality_branch, | ||
floorlog2(FINALIZED_ROOT_INDEX), | ||
get_subtree_index(FINALIZED_ROOT_INDEX), | ||
finalized_root_gindex_at_slot::<C>(fork_parameters, update_attested_slot), | ||
&update.attested_header.beacon.state_root, | ||
)?; | ||
|
||
|
@@ -188,14 +224,17 @@ pub fn validate_light_client_update<C: ChainSpec, V: BlsVerify>( | |
}, | ||
)?; | ||
} | ||
|
||
// This validates the given next sync committee against the attested header's state root. | ||
validate_merkle_branch( | ||
&TryInto::<SyncCommitteeSsz<C>>::try_into(next_sync_committee.clone()) | ||
.unwrap() | ||
.tree_hash_root(), | ||
&update.next_sync_committee_branch.unwrap_or_default(), | ||
floorlog2(NEXT_SYNC_COMMITTEE_INDEX), | ||
get_subtree_index(NEXT_SYNC_COMMITTEE_INDEX), | ||
&update | ||
.next_sync_committee_branch | ||
.clone() | ||
.unwrap_or_default()[..], | ||
next_sync_committee_gindex_at_slot::<C>(fork_parameters, update_attested_slot), | ||
&update.attested_header.beacon.state_root, | ||
)?; | ||
} | ||
|
@@ -245,19 +284,17 @@ pub fn get_lc_execution_root<C: ChainSpec>( | |
header: &LightClientHeader, | ||
) -> H256 { | ||
let epoch = compute_epoch_at_slot::<C>(header.beacon.slot); | ||
// Now new field in electra | ||
if epoch >= fork_parameters.electra.epoch { | ||
return TryInto::<ExecutionPayloadHeaderSsz<C>>::try_into(header.execution.clone()) | ||
.unwrap() | ||
.tree_hash_root(); | ||
} | ||
if epoch >= fork_parameters.deneb.epoch { | ||
return TryInto::<ExecutionPayloadHeaderSsz<C>>::try_into(header.execution.clone()) | ||
.unwrap() | ||
.tree_hash_root(); | ||
} | ||
Comment on lines
+287
to
297
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these branches are the same? |
||
|
||
// TODO: Figure out what to do here | ||
// if epoch >= fork_parameters.capella.epoch { | ||
// return CapellaExecutionPayloadHeader::from(header.execution.clone()) | ||
// .tree_hash_root() | ||
// .into(); | ||
// } | ||
|
||
H256::default() | ||
} | ||
|
||
|
@@ -285,8 +322,7 @@ pub fn is_valid_light_client_header<C: ChainSpec>( | |
validate_merkle_branch( | ||
&get_lc_execution_root::<C>(fork_parameters, header), | ||
&header.execution_branch, | ||
floorlog2(EXECUTION_PAYLOAD_INDEX), | ||
get_subtree_index(EXECUTION_PAYLOAD_INDEX), | ||
EXECUTION_PAYLOAD_GINDEX, | ||
&header.beacon.body_root, | ||
) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename the old ones to deneb?