-
Notifications
You must be signed in to change notification settings - Fork 680
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: Synchronize from Snowfork repository #3761
Merged
bkontur
merged 47 commits into
paritytech:master
from
Snowfork:beacon-client-improvements
Apr 2, 2024
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
2536e78
adds snowbridge
bc607a0
Test pallet order (#112)
claravanstaden 4cede80
Fix coverage (#115)
claravanstaden 7bbe297
Merge branch 'master' into snowbridge
78c6c9b
Extract Ethereum chain id in tests (#117)
claravanstaden 66505a7
Ignore reward when funds unavailable (#118)
yrong 628b251
Increase MaxExecutionHeadersToKeep (#120)
yrong e553417
Smoke Tests in CI (#113)
claravanstaden 5bac4ee
Sync execution update on demand (#123)
yrong 8be52c9
Adds finalized header gap check (#124)
claravanstaden 4c850e8
Inline execution update into proof of inbound message & Remove execut…
yrong cbcc449
Fix Smoketests CI (#126)
claravanstaden ae80de0
cleanup branch
b6fee8b
merge
e353ec0
remove fmt file
20ca52e
Merge branch 'master' into beacon-client-improvements
claravanstaden 98d8f2c
unused param
0892540
Merge remote-tracking branch 'origin/beacon-client-improvements' into…
0432944
prdoc
ad9c398
Merge branch 'master' into beacon-client-improvements
claravanstaden db1b4c1
remove rustdoc describing removed extrinsic
2730776
Merge branch 'master' into beacon-client-improvements
claravanstaden 71443be
taplo
5f2e751
Merge remote-tracking branch 'origin/beacon-client-improvements' into…
5da7df7
Add a linear fee multiplier to ensure safety margins (#127)
vgeddes a43b54e
change bitwise or to logical or
0fbceec
Merge branch 'master' into beacon-client-improvements
claravanstaden 75a33cf
Merge branch 'master' into beacon-client-improvements
e80219d
rustdoc
deec9eb
merge damage
9293295
Merge branch 'master' into snowbridge
5f5aef7
Merge branch 'master' into beacon-client-improvements
claravanstaden a0e7884
Merge branch 'snowbridge' into beacon-client-improvements
8c51118
Merge remote-tracking branch 'origin/beacon-client-improvements' into…
a0d5002
Fix typo in prdoc. Credit author yrong.
6e5e5c0
unused var
ae83b6c
Remove MaxExecutionHeadersToKeep (#129)
yrong 35c74ce
Merge branch 'master' into beacon-client-improvements
2ae3cab
Merge branch 'master' into beacon-client-improvements
claravanstaden b81f262
Merge branch 'master' into beacon-client-improvements
claravanstaden fcd5f71
Update bridges/snowbridge/pallets/inbound-queue/src/lib.rs
claravanstaden 7c0a097
Merge branch 'master' into beacon-client-improvements
claravanstaden ef97c0b
update prdoc
87de172
Merge remote-tracking branch 'origin/beacon-client-improvements' into…
3aad93a
Merge branch 'master' into beacon-client-improvements
claravanstaden 304f890
fix prdoc
0cfd048
Merge remote-tracking branch 'origin/beacon-client-improvements' into…
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
272 changes: 179 additions & 93 deletions
272
bridges/snowbridge/pallets/ethereum-client/fixtures/src/lib.rs
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
use super::*; | ||
use frame_support::ensure; | ||
use primitives::ExecutionProof; | ||
|
||
use snowbridge_core::inbound::{ | ||
VerificationError::{self, *}, | ||
|
@@ -14,32 +16,13 @@ impl<T: Config> Verifier for Pallet<T> { | |
/// the log should be in the beacon client storage, meaning it has been verified and is an | ||
/// ancestor of a finalized beacon block. | ||
fn verify(event_log: &Log, proof: &Proof) -> Result<(), VerificationError> { | ||
log::info!( | ||
target: "ethereum-client", | ||
"💫 Verifying message with block hash {}", | ||
proof.block_hash, | ||
); | ||
Self::verify_execution_proof(&proof.execution_proof) | ||
.map_err(|e| InvalidExecutionProof(e.into()))?; | ||
|
||
let header = <ExecutionHeaderBuffer<T>>::get(proof.block_hash).ok_or(HeaderNotFound)?; | ||
|
||
let receipt = match Self::verify_receipt_inclusion(header.receipts_root, proof) { | ||
Ok(receipt) => receipt, | ||
Err(err) => { | ||
log::error!( | ||
target: "ethereum-client", | ||
"💫 Verification of receipt inclusion failed for block {}: {:?}", | ||
proof.block_hash, | ||
err | ||
); | ||
return Err(err) | ||
}, | ||
}; | ||
|
||
log::trace!( | ||
target: "ethereum-client", | ||
"💫 Verified receipt inclusion for transaction at index {} in block {}", | ||
proof.tx_index, proof.block_hash, | ||
); | ||
let receipt = Self::verify_receipt_inclusion( | ||
proof.execution_proof.execution_header.receipts_root(), | ||
&proof.receipt_proof.1, | ||
)?; | ||
|
||
event_log.validate().map_err(|_| InvalidLog)?; | ||
|
||
|
@@ -53,18 +36,11 @@ impl<T: Config> Verifier for Pallet<T> { | |
if !receipt.contains_log(&event_log) { | ||
log::error!( | ||
target: "ethereum-client", | ||
"💫 Event log not found in receipt for transaction at index {} in block {}", | ||
proof.tx_index, proof.block_hash, | ||
"💫 Event log not found in receipt for transaction", | ||
); | ||
return Err(LogNotFound) | ||
} | ||
|
||
log::info!( | ||
target: "ethereum-client", | ||
"💫 Receipt verification successful for {}", | ||
proof.block_hash, | ||
); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
@@ -74,9 +50,9 @@ impl<T: Config> Pallet<T> { | |
/// `proof.block_hash`. | ||
pub fn verify_receipt_inclusion( | ||
receipts_root: H256, | ||
proof: &Proof, | ||
receipt_proof: &[Vec<u8>], | ||
) -> Result<Receipt, VerificationError> { | ||
let result = verify_receipt_proof(receipts_root, &proof.data.1).ok_or(InvalidProof)?; | ||
let result = verify_receipt_proof(receipts_root, receipt_proof).ok_or(InvalidProof)?; | ||
|
||
match result { | ||
Ok(receipt) => Ok(receipt), | ||
|
@@ -90,4 +66,96 @@ impl<T: Config> Pallet<T> { | |
}, | ||
} | ||
} | ||
|
||
/// Validates an execution header with ancestry_proof against a finalized checkpoint on | ||
/// chain.The beacon header containing the execution header is sent, plus the execution header, | ||
/// along with a proof that the execution header is rooted in the beacon header body. | ||
pub(crate) fn verify_execution_proof(execution_proof: &ExecutionProof) -> DispatchResult { | ||
let latest_finalized_state = | ||
FinalizedBeaconState::<T>::get(LatestFinalizedBlockRoot::<T>::get()) | ||
.ok_or(Error::<T>::NotBootstrapped)?; | ||
// Checks that the header is an ancestor of a finalized header, using slot number. | ||
ensure!( | ||
execution_proof.header.slot <= latest_finalized_state.slot, | ||
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() | ||
.map_err(|_| Error::<T>::HeaderHashTreeRootFailed)?; | ||
|
||
match &execution_proof.ancestry_proof { | ||
Some(proof) => { | ||
Self::verify_ancestry_proof( | ||
beacon_block_root, | ||
execution_proof.header.slot, | ||
&proof.header_branch, | ||
proof.finalized_block_root, | ||
)?; | ||
}, | ||
None => { | ||
// If the ancestry proof is not provided, we expect this beacon header to be a | ||
// finalized beacon header. We need to check that the header hash matches the | ||
// finalized header root at the expected slot. | ||
let state = <FinalizedBeaconState<T>>::get(beacon_block_root) | ||
.ok_or(Error::<T>::ExpectedFinalizedHeaderNotStored)?; | ||
if execution_proof.header.slot != state.slot { | ||
return Err(Error::<T>::ExpectedFinalizedHeaderNotStored.into()) | ||
} | ||
}, | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Verify that `block_root` is an ancestor of `finalized_block_root` Used to prove that | ||
/// an execution header is an ancestor of a finalized header (i.e. the blocks are | ||
/// on the same chain). | ||
fn verify_ancestry_proof( | ||
block_root: H256, | ||
block_slot: u64, | ||
block_root_proof: &[H256], | ||
finalized_block_root: H256, | ||
) -> DispatchResult { | ||
let state = <FinalizedBeaconState<T>>::get(finalized_block_root) | ||
.ok_or(Error::<T>::ExpectedFinalizedHeaderNotStored)?; | ||
|
||
ensure!(block_slot < state.slot, Error::<T>::HeaderNotFinalized); | ||
|
||
let index_in_array = block_slot % (SLOTS_PER_HISTORICAL_ROOT as u64); | ||
let leaf_index = (SLOTS_PER_HISTORICAL_ROOT as u64) + index_in_array; | ||
|
||
ensure!( | ||
verify_merkle_branch( | ||
block_root, | ||
block_root_proof, | ||
leaf_index as usize, | ||
config::BLOCK_ROOT_AT_INDEX_DEPTH, | ||
state.block_roots_root | ||
), | ||
Error::<T>::InvalidAncestryMerkleProof | ||
); | ||
|
||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
Why did you remove log params? I think this log became pretty non-relevant and useless, because you also remove input log with block_hash
Verifying message with block hash
.How will you investigate
Event log not found in receipt for transaction
without knowing block_hash or tx?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.
The reasoning behind this is on the original PR, over here: Snowfork#125 (comment)
A side-note, we don't generally have access to the parachain logs either, so we try and solve issues without having to look at the logs.
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.
ok, got it, and what about adding there some "identifier" from
proof.execution_proof
orproof.execution_proof.execution_header
, does it make sense?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.
I don't know if it would be useful. We have the same info in the relayer and that is more accessible to us.