-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass structured event log to ethereumInboundQueue.submit (#1003)
- Loading branch information
Showing
19 changed files
with
256 additions
and
130 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,31 +2,33 @@ | |
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
use super::*; | ||
|
||
use snowbridge_core::inbound::VerificationError::{self, *}; | ||
use snowbridge_core::inbound::{ | ||
VerificationError::{self, *}, | ||
*, | ||
}; | ||
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. | ||
fn verify(message: &Message) -> Result<(), VerificationError> { | ||
fn verify(event_log: &Log, proof: &Proof) -> Result<(), VerificationError> { | ||
log::info!( | ||
target: "ethereum-beacon-client", | ||
"💫 Verifying message with block hash {}", | ||
message.proof.block_hash, | ||
proof.block_hash, | ||
); | ||
|
||
let header = | ||
<ExecutionHeaderBuffer<T>>::get(message.proof.block_hash).ok_or(HeaderNotFound)?; | ||
let header = <ExecutionHeaderBuffer<T>>::get(proof.block_hash).ok_or(HeaderNotFound)?; | ||
|
||
let receipt = match Self::verify_receipt_inclusion(header.receipts_root, &message.proof) { | ||
let receipt = match Self::verify_receipt_inclusion(header.receipts_root, proof) { | ||
Ok(receipt) => receipt, | ||
Err(err) => { | ||
log::error!( | ||
target: "ethereum-beacon-client", | ||
"💫 Verification of receipt inclusion failed for block {}: {:?}", | ||
message.proof.block_hash, | ||
proof.block_hash, | ||
err | ||
); | ||
return Err(err) | ||
|
@@ -36,35 +38,31 @@ impl<T: Config> Verifier for Pallet<T> { | |
log::trace!( | ||
target: "ethereum-beacon-client", | ||
"💫 Verified receipt inclusion for transaction at index {} in block {}", | ||
message.proof.tx_index, message.proof.block_hash, | ||
proof.tx_index, proof.block_hash, | ||
); | ||
|
||
let log = match rlp::decode(&message.data) { | ||
Ok(log) => log, | ||
Err(err) => { | ||
log::error!( | ||
target: "ethereum-beacon-client", | ||
"💫 RLP log decoded failed {}: {:?}", | ||
message.proof.block_hash, | ||
err | ||
); | ||
return Err(InvalidLog) | ||
}, | ||
event_log.validate().map_err(|_| InvalidLog)?; | ||
|
||
// Convert snowbridge_core::inbound::Log to snowbridge_ethereum::Log. | ||
let event_log = snowbridge_ethereum::Log { | ||
address: event_log.address, | ||
topics: event_log.topics.clone(), | ||
data: event_log.data.clone(), | ||
}; | ||
|
||
if !receipt.contains_log(&log) { | ||
if !receipt.contains_log(&event_log) { | ||
log::error!( | ||
target: "ethereum-beacon-client", | ||
"💫 Event log not found in receipt for transaction at index {} in block {}", | ||
message.proof.tx_index, message.proof.block_hash, | ||
proof.tx_index, proof.block_hash, | ||
); | ||
return Err(LogNotFound) | ||
} | ||
|
||
log::info!( | ||
target: "ethereum-beacon-client", | ||
"💫 Receipt verification successful for {}", | ||
message.proof.block_hash, | ||
proof.block_hash, | ||
); | ||
|
||
Ok(()) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,13 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
use snowbridge_core::ParaId; | ||
use snowbridge_core::{inbound::Log, ParaId}; | ||
|
||
use sp_core::{RuntimeDebug, H160, H256}; | ||
use sp_std::{convert::TryFrom, prelude::*}; | ||
|
||
use alloy_primitives::{Address, Bytes, B256}; | ||
use alloy_rlp::RlpDecodable; | ||
use alloy_primitives::B256; | ||
use alloy_sol_types::{sol, SolEvent}; | ||
|
||
#[derive(RlpDecodable, RuntimeDebug)] | ||
pub struct Log { | ||
pub address: Address, | ||
pub topics: Vec<B256>, | ||
pub data: Bytes, | ||
} | ||
|
||
sol! { | ||
event OutboundMessageAccepted(uint256 indexed destination, uint64 nonce, bytes32 indexed messageID, bytes payload); | ||
} | ||
|
@@ -42,11 +34,13 @@ impl TryFrom<Log> for Envelope { | |
type Error = EnvelopeDecodeError; | ||
|
||
fn try_from(log: Log) -> Result<Self, Self::Error> { | ||
let event = OutboundMessageAccepted::decode_log(log.topics, &log.data, true) | ||
let topics: Vec<B256> = log.topics.iter().map(|x| B256::from_slice(x.as_ref())).collect(); | ||
|
||
let event = OutboundMessageAccepted::decode_log(topics, &log.data, true) | ||
.map_err(|_| EnvelopeDecodeError)?; | ||
|
||
Ok(Self { | ||
gateway: H160::from(log.address.as_ref()), | ||
gateway: log.address, | ||
dest: event.destination.saturating_to::<u32>().into(), | ||
nonce: event.nonce, | ||
message_id: H256::from(event.messageID.as_ref()), | ||
|
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
Oops, something went wrong.