Skip to content
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

Snowbridge - Ethereum Electra Upgrade Support #7075

Open
wants to merge 82 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
2536e78
adds snowbridge
Feb 8, 2024
bc607a0
Test pallet order (#112)
claravanstaden Feb 16, 2024
4cede80
Fix coverage (#115)
claravanstaden Feb 22, 2024
7bbe297
Merge branch 'master' into snowbridge
Feb 23, 2024
78c6c9b
Extract Ethereum chain id in tests (#117)
claravanstaden Feb 28, 2024
66505a7
Ignore reward when funds unavailable (#118)
yrong Feb 28, 2024
628b251
Increase MaxExecutionHeadersToKeep (#120)
yrong Mar 5, 2024
e553417
Smoke Tests in CI (#113)
claravanstaden Mar 5, 2024
5bac4ee
Sync execution update on demand (#123)
yrong Mar 14, 2024
8be52c9
Adds finalized header gap check (#124)
claravanstaden Mar 18, 2024
4c850e8
Inline execution update into proof of inbound message & Remove execut…
yrong Mar 20, 2024
cbcc449
Fix Smoketests CI (#126)
claravanstaden Mar 20, 2024
5da7df7
Add a linear fee multiplier to ensure safety margins (#127)
vgeddes Mar 21, 2024
9293295
Merge branch 'master' into snowbridge
Mar 25, 2024
aa3a75a
Remove MaxExecutionHeadersToKeep (#129)
yrong Mar 26, 2024
7fd2ea4
Merge branch 'master' into snowbridge
Mar 28, 2024
9368712
Forward message id to destination chain (#134)
alistair-singh Apr 5, 2024
cedc585
fix ci (#136)
claravanstaden Apr 9, 2024
0893dad
Merge branch 'master' into snowbridge
Apr 10, 2024
68ab248
Merge branch 'master' into snowbridge
Apr 11, 2024
3f495e5
Update Rust version (#138)
claravanstaden Apr 15, 2024
d95751b
Reject finalized updates without a sync committee in next store perio…
claravanstaden May 16, 2024
1816f4f
Merge branch 'master' into snowbridge
claravanstaden May 30, 2024
c13f7c7
fmt
claravanstaden May 30, 2024
5ca8277
Emit channel on Message Queue (#147)
alistair-singh May 30, 2024
e96ce3a
fix tests (#149)
alistair-singh Jun 3, 2024
d79ef62
Execution Header Cleanup Multi-Block Migration (#148)
claravanstaden Jun 11, 2024
f7054e7
Fix the format ci (#154)
yrong Jun 26, 2024
f0abb7e
Snowbridge on westend (#157)
yrong Jul 19, 2024
543f4ee
Merge branch 'master' into snowbridge
claravanstaden Jul 24, 2024
eaf4c43
merge fixes
claravanstaden Jul 24, 2024
f29f6d2
audit fixes (#161)
claravanstaden Jul 25, 2024
aa208a9
Merge remote-tracking branch 'origin/snowbridge' into snowbridge
claravanstaden Jul 25, 2024
3e8a9a0
merge fixes
claravanstaden Jul 25, 2024
2cef4bd
another fixes
claravanstaden Jul 25, 2024
c7cbd99
Free finalized Ethereum updates (#159)
claravanstaden Jul 31, 2024
df4bad7
Westend by default for local setup (#163)
yrong Aug 5, 2024
dfee885
Short epoch from ENV (#170)
yrong Aug 29, 2024
b19c1e1
Polkadot assets on ethereum (#128)
yrong Sep 2, 2024
64c2a29
electra upgrade
claravanstaden Sep 6, 2024
207cc10
electra progress
claravanstaden Sep 9, 2024
241c644
tests
claravanstaden Sep 9, 2024
29df723
relayer progress
claravanstaden Sep 9, 2024
a956c9c
electra header differences
claravanstaden Sep 10, 2024
7280cee
fix benchmarks
claravanstaden Sep 10, 2024
09ab053
fixes
claravanstaden Sep 10, 2024
ab01c19
missing fork version
claravanstaden Sep 10, 2024
56cffc2
fixes
claravanstaden Jan 7, 2025
ed9dac8
merge damage
claravanstaden Jan 7, 2025
94e811f
add deleted files
claravanstaden Jan 7, 2025
2d9b24e
revert unrelated changes
claravanstaden Jan 7, 2025
6704fd0
prdoc
claravanstaden Jan 8, 2025
f505570
Merge branch 'master' into electra
claravanstaden Jan 8, 2025
e1c9e52
Merge remote-tracking branch 'origin/electra' into electra
claravanstaden Jan 8, 2025
1913738
fmt
claravanstaden Jan 8, 2025
41e4a49
merge damage
claravanstaden Jan 8, 2025
7c0b1fe
cleanup
claravanstaden Jan 8, 2025
25c32b8
cleanup
claravanstaden Jan 8, 2025
0691e5d
ci fixes
claravanstaden Jan 13, 2025
5628817
Merge branch 'master' into electra
claravanstaden Jan 13, 2025
8fc15da
clippy
claravanstaden Jan 13, 2025
f1d5b25
Merge remote-tracking branch 'origin/electra' into electra
claravanstaden Jan 13, 2025
9308de9
add test files
claravanstaden Jan 13, 2025
c9a1a1e
progress
claravanstaden Jan 14, 2025
97f2bc8
revert log
claravanstaden Jan 15, 2025
42430f2
adds tests
claravanstaden Jan 16, 2025
54270e3
Merge branch 'master' into electra
claravanstaden Jan 16, 2025
81171b2
cleanup
claravanstaden Jan 16, 2025
a09b9fb
fmt
claravanstaden Jan 16, 2025
14000cc
Merge branch 'master' into electra
claravanstaden Jan 16, 2025
6ce330c
fix test and semver
claravanstaden Jan 16, 2025
a469eb1
remove unnecessary logs
claravanstaden Jan 16, 2025
8cfa781
Merge remote-tracking branch 'origin/electra' into electra
claravanstaden Jan 16, 2025
b3e0d8a
cleanup logs
claravanstaden Jan 16, 2025
97e3a9c
Merge branch 'master' into electra
claravanstaden Jan 20, 2025
96836c9
Update bridges/snowbridge/pallets/ethereum-client/src/benchmarking/mo…
claravanstaden Jan 20, 2025
66fa5f6
Update bridges/snowbridge/pallets/ethereum-client/src/lib.rs
claravanstaden Jan 20, 2025
3000cfa
Update bridges/snowbridge/pallets/ethereum-client/src/lib.rs
claravanstaden Jan 20, 2025
76d0b3d
Update bridges/snowbridge/pallets/ethereum-client/src/impls.rs
claravanstaden Jan 20, 2025
6b58968
Update bridges/snowbridge/pallets/ethereum-client/src/lib.rs
claravanstaden Jan 20, 2025
6d032fb
Update bridges/snowbridge/pallets/ethereum-client/src/lib.rs
claravanstaden Jan 20, 2025
a25a8b8
pr comments
claravanstaden Jan 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions bridges/snowbridge/pallets/ethereum-client/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ use crate::Pallet as EthereumBeaconClient;
use frame_benchmarking::v2::*;
use frame_system::RawOrigin;

use snowbridge_beacon_primitives::Fork;
use snowbridge_pallet_ethereum_client_fixtures::*;

use snowbridge_beacon_primitives::{
fast_aggregate_verify, prepare_aggregate_pubkey, prepare_aggregate_signature,
verify_merkle_branch,
fast_aggregate_verify,
merkle_proof::{generalized_index_length, subtree_index},
prepare_aggregate_pubkey, prepare_aggregate_signature, verify_merkle_branch,
};
use util::*;

Expand Down Expand Up @@ -111,13 +113,43 @@ mod benchmarks {
let update = make_sync_committee_update();
let block_root: H256 = update.finalized_header.hash_tree_root().unwrap();

let fork_versions = ForkVersions {
genesis: Fork {
version: [0, 0, 0, 0], // 0x00000000
epoch: 0,
},
altair: Fork {
version: [1, 0, 0, 0], // 0x01000000
epoch: 0,
},
bellatrix: Fork {
version: [2, 0, 0, 0], // 0x02000000
epoch: 0,
},
capella: Fork {
version: [3, 0, 0, 0], // 0x03000000
epoch: 0,
},
deneb: Fork {
version: [4, 0, 0, 0], // 0x04000000
epoch: 0,
},
electra: Fork {
version: [5, 0, 0, 0], // 0x05000000
epoch: 80000000000,
},
};
let finalized_root_g_index = EthereumBeaconClient::<T>::finalized_root_gindex_at_slot(
claravanstaden marked this conversation as resolved.
Show resolved Hide resolved
update.attested_header.slot,
fork_versions,
);
#[block]
{
verify_merkle_branch(
block_root,
&update.finality_branch,
config::FINALIZED_ROOT_SUBTREE_INDEX,
config::FINALIZED_ROOT_DEPTH,
subtree_index(finalized_root_g_index),
generalized_index_length(finalized_root_g_index),
update.attested_header.state_root,
);
}
Expand Down
15 changes: 15 additions & 0 deletions bridges/snowbridge/pallets/ethereum-client/src/config/altair.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]>

/// Generalized Indices
/// related to Merkle proofs
/// get_generalized_index(BeaconState, 'block_roots')
pub const BLOCK_ROOTS_INDEX: usize = 37;
/// get_generalized_index(BeaconState, 'finalized_checkpoint', 'root')
pub const FINALIZED_ROOT_INDEX: usize = 105;
/// get_generalized_index(BeaconState, 'current_sync_committee')
pub const CURRENT_SYNC_COMMITTEE_INDEX: usize = 54;
/// get_generalized_index(BeaconState, 'next_sync_committee')
pub const NEXT_SYNC_COMMITTEE_INDEX: usize = 55;
/// get_generalized_index(BeaconBlockBody, 'execution_payload')
pub const EXECUTION_HEADER_INDEX: usize = 25;
15 changes: 15 additions & 0 deletions bridges/snowbridge/pallets/ethereum-client/src/config/electra.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]>

/// Generalized Indices
/// related to Merkle proofs
/// get_generalized_index(BeaconState, 'block_roots')
pub const BLOCK_ROOTS_INDEX: usize = 69;
/// get_generalized_index(BeaconState, 'finalized_checkpoint', 'root')
pub const FINALIZED_ROOT_INDEX: usize = 169;
/// get_generalized_index(BeaconState, 'current_sync_committee')
pub const CURRENT_SYNC_COMMITTEE_INDEX: usize = 86;
/// get_generalized_index(BeaconState, 'next_sync_committee')
pub const NEXT_SYNC_COMMITTEE_INDEX: usize = 87;
/// get_generalized_index(BeaconBlockBody, 'execution_payload')
pub const EXECUTION_HEADER_INDEX: usize = 25;
30 changes: 2 additions & 28 deletions bridges/snowbridge/pallets/ethereum-client/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,9 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]>
use snowbridge_beacon_primitives::merkle_proof::{generalized_index_length, subtree_index};
use static_assertions::const_assert;

/// Generalized Indices
/// related to Merkle proofs
/// get_generalized_index(BeaconState, 'block_roots')
pub const BLOCK_ROOTS_INDEX: usize = 37;
pub const BLOCK_ROOTS_SUBTREE_INDEX: usize = subtree_index(BLOCK_ROOTS_INDEX);
pub const BLOCK_ROOTS_DEPTH: usize = generalized_index_length(BLOCK_ROOTS_INDEX);

/// get_generalized_index(BeaconState, 'finalized_checkpoint', 'root')
pub const FINALIZED_ROOT_INDEX: usize = 105;
pub const FINALIZED_ROOT_SUBTREE_INDEX: usize = subtree_index(FINALIZED_ROOT_INDEX);
pub const FINALIZED_ROOT_DEPTH: usize = generalized_index_length(FINALIZED_ROOT_INDEX);

/// get_generalized_index(BeaconState, 'current_sync_committee')
pub const CURRENT_SYNC_COMMITTEE_INDEX: usize = 54;
pub const CURRENT_SYNC_COMMITTEE_SUBTREE_INDEX: usize = subtree_index(CURRENT_SYNC_COMMITTEE_INDEX);
pub const CURRENT_SYNC_COMMITTEE_DEPTH: usize =
generalized_index_length(CURRENT_SYNC_COMMITTEE_INDEX);

/// get_generalized_index(BeaconState, 'next_sync_committee')
pub const NEXT_SYNC_COMMITTEE_INDEX: usize = 55;
pub const NEXT_SYNC_COMMITTEE_SUBTREE_INDEX: usize = subtree_index(NEXT_SYNC_COMMITTEE_INDEX);
pub const NEXT_SYNC_COMMITTEE_DEPTH: usize = generalized_index_length(NEXT_SYNC_COMMITTEE_INDEX);

/// get_generalized_index(BeaconBlockBody, 'execution_payload')
pub const EXECUTION_HEADER_INDEX: usize = 25;
pub const EXECUTION_HEADER_SUBTREE_INDEX: usize = subtree_index(EXECUTION_HEADER_INDEX);
pub const EXECUTION_HEADER_DEPTH: usize = generalized_index_length(EXECUTION_HEADER_INDEX);
pub mod altair;
pub mod electra;
Comment on lines +5 to +6
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config is now based on fork version, so add a module per fork specific settings.


/// Sizes related to SSZ encoding
pub const MAX_EXTRA_DATA_BYTES: usize = 32;
Expand Down
47 changes: 26 additions & 21 deletions bridges/snowbridge/pallets/ethereum-client/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::*;
use frame_support::ensure;
use snowbridge_beacon_primitives::ExecutionProof;

use snowbridge_beacon_primitives::merkle_proof::{generalized_index_length, subtree_index};
use snowbridge_core::inbound::{
VerificationError::{self, *},
*,
Expand All @@ -13,8 +14,9 @@ use snowbridge_ethereum::Receipt;
impl<T: Config> Verifier for Pallet<T> {
/// Verify a message by verifying the existence of the corresponding
/// Ethereum log in a block. Returns the log if successful. The execution header containing
/// the log should be in the beacon client storage, meaning it has been verified and is an
/// ancestor of a finalized beacon block.
/// the log is sent with the message. The beacon header containing the execution header
/// is also sent with the message, to check if the header is an ancestor of a finalized
/// header.
fn verify(event_log: &Log, proof: &Proof) -> Result<(), VerificationError> {
Self::verify_execution_proof(&proof.execution_proof)
.map_err(|e| InvalidExecutionProof(e.into()))?;
Expand Down Expand Up @@ -80,25 +82,6 @@ impl<T: Config> Pallet<T> {
Error::<T>::HeaderNotFinalized
);

// Gets the hash tree root of the execution header, in preparation for the execution
// header proof (used to check that the execution header is rooted in the beacon
// header body.
let execution_header_root: H256 = execution_proof
.execution_header
.hash_tree_root()
.map_err(|_| Error::<T>::BlockBodyHashTreeRootFailed)?;

ensure!(
verify_merkle_branch(
execution_header_root,
&execution_proof.execution_branch,
config::EXECUTION_HEADER_SUBTREE_INDEX,
config::EXECUTION_HEADER_DEPTH,
execution_proof.header.body_root
),
Error::<T>::InvalidExecutionHeaderProof
);

let beacon_block_root: H256 = execution_proof
.header
.hash_tree_root()
Expand All @@ -125,6 +108,28 @@ impl<T: Config> Pallet<T> {
},
}

// Gets the hash tree root of the execution header, in preparation for the execution
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the order of operations here, as suggested by the Oak Security audit.

// header proof (used to check that the execution header is rooted in the beacon
// header body.
let execution_header_root: H256 = execution_proof
.execution_header
.hash_tree_root()
.map_err(|_| Error::<T>::BlockBodyHashTreeRootFailed)?;

let execution_header_g_index = Self::execution_header_gindex_at_slot(
claravanstaden marked this conversation as resolved.
Show resolved Hide resolved
execution_proof.header.slot,
T::ForkVersions::get(),
);
ensure!(
verify_merkle_branch(
execution_header_root,
&execution_proof.execution_branch,
subtree_index(execution_header_g_index),
generalized_index_length(execution_header_g_index),
execution_proof.header.body_root
),
Error::<T>::InvalidExecutionHeaderProof
);
Ok(())
}

Expand Down
Loading
Loading