From 8e921b26b86214346ba49d67f37a8e76a904d569 Mon Sep 17 00:00:00 2001 From: Vincent Geddes Date: Sun, 12 Nov 2023 16:15:21 +0200 Subject: [PATCH] Pass structured event log to ethereumInboundQueue.submit (#1003) --- parachain/Cargo.lock | 1 - .../ethereum-beacon-client/src/impls.rs | 42 +++++----- .../pallets/ethereum-beacon-client/src/lib.rs | 5 +- .../ethereum-beacon-client/src/mock.rs | 22 +++-- .../ethereum-beacon-client/src/tests.rs | 57 ++++++++----- .../src/benchmarking/fixtures.rs | 12 ++- .../pallets/inbound-queue/src/envelope.rs | 18 ++-- parachain/pallets/inbound-queue/src/lib.rs | 14 ++-- parachain/pallets/inbound-queue/src/test.rs | 83 +++++++++++++------ parachain/primitives/core/Cargo.toml | 2 - parachain/primitives/core/src/inbound.rs | 36 ++++++-- parachain/primitives/ethereum/src/log.rs | 3 +- parachain/primitives/ethereum/src/receipt.rs | 3 +- polkadot-sdk | 2 +- relayer/chain/ethereum/message.go | 20 +++-- relayer/chain/parachain/message.go | 10 ++- relayer/go.mod | 2 +- relayer/go.sum | 31 +++++++ smoketest/tests/register_token.rs | 23 ++++- 19 files changed, 256 insertions(+), 130 deletions(-) diff --git a/parachain/Cargo.lock b/parachain/Cargo.lock index 6cd203a21e..afd4954258 100644 --- a/parachain/Cargo.lock +++ b/parachain/Cargo.lock @@ -3551,7 +3551,6 @@ dependencies = [ "scale-info", "serde", "snowbridge-beacon-primitives", - "snowbridge-ethereum", "sp-arithmetic", "sp-core", "sp-runtime", diff --git a/parachain/pallets/ethereum-beacon-client/src/impls.rs b/parachain/pallets/ethereum-beacon-client/src/impls.rs index 35b2e287de..7e72b12631 100644 --- a/parachain/pallets/ethereum-beacon-client/src/impls.rs +++ b/parachain/pallets/ethereum-beacon-client/src/impls.rs @@ -2,7 +2,10 @@ // SPDX-FileCopyrightText: 2023 Snowfork use super::*; -use snowbridge_core::inbound::VerificationError::{self, *}; +use snowbridge_core::inbound::{ + VerificationError::{self, *}, + *, +}; use snowbridge_ethereum::Receipt; impl Verifier for Pallet { @@ -10,23 +13,22 @@ impl Verifier for Pallet { /// 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 = - >::get(message.proof.block_hash).ok_or(HeaderNotFound)?; + let header = >::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,27 +38,23 @@ impl Verifier for Pallet { 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) } @@ -64,7 +62,7 @@ impl Verifier for Pallet { log::info!( target: "ethereum-beacon-client", "💫 Receipt verification successful for {}", - message.proof.block_hash, + proof.block_hash, ); Ok(()) diff --git a/parachain/pallets/ethereum-beacon-client/src/lib.rs b/parachain/pallets/ethereum-beacon-client/src/lib.rs index 0f3cf025b5..11de3ce9b4 100644 --- a/parachain/pallets/ethereum-beacon-client/src/lib.rs +++ b/parachain/pallets/ethereum-beacon-client/src/lib.rs @@ -43,10 +43,7 @@ use primitives::{ CompactBeaconState, CompactExecutionHeader, ExecutionHeaderState, ForkData, ForkVersion, ForkVersions, PublicKeyPrepared, SigningData, }; -use snowbridge_core::{ - inbound::{Message, Proof, Verifier}, - BasicOperatingMode, RingBufferMap, -}; +use snowbridge_core::{BasicOperatingMode, RingBufferMap}; use sp_core::H256; use sp_std::prelude::*; pub use weights::WeightInfo; diff --git a/parachain/pallets/ethereum-beacon-client/src/mock.rs b/parachain/pallets/ethereum-beacon-client/src/mock.rs index 78e71833be..1addccf790 100644 --- a/parachain/pallets/ethereum-beacon-client/src/mock.rs +++ b/parachain/pallets/ethereum-beacon-client/src/mock.rs @@ -14,7 +14,7 @@ pub mod minimal { use crate::config; use hex_literal::hex; use primitives::CompactExecutionHeader; - use snowbridge_core::inbound::{Message, Proof}; + use snowbridge_core::inbound::{Log, Proof}; use sp_runtime::BuildStorage; use std::{fs::File, path::PathBuf}; @@ -141,10 +141,18 @@ pub mod minimal { load_fixture("next-finalized-header-update.minimal.json").unwrap() } - pub fn get_message_verification_payload() -> Message { - Message { - data: hex!("f9011c94ee9170abfbf9421ad6dd07f6bdec9d89f2b581e0f863a01b11dcf133cc240f682dab2d3a8e4cd35c5da8c9cf99adac4336f8512584c5ada000000000000000000000000000000000000000000000000000000000000003e8a00000000000000000000000000000000000000000000000000000000000000001b8a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004b000f000000000000000100d184c103f7acc340847eee82a0b909e3358bc28d440edffa1352b13227e8ee646f3ea37456dec701345772617070656420457468657210574554481235003511000000000000000000000000000000000000000000").to_vec(), - proof: Proof { + pub fn get_message_verification_payload() -> (Log, Proof) { + ( + Log { + address: hex!("ee9170abfbf9421ad6dd07f6bdec9d89f2b581e0").into(), + topics: vec![ + hex!("1b11dcf133cc240f682dab2d3a8e4cd35c5da8c9cf99adac4336f8512584c5ad").into(), + hex!("00000000000000000000000000000000000000000000000000000000000003e8").into(), + hex!("0000000000000000000000000000000000000000000000000000000000000001").into(), + ], + data: hex!("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004b000f000000000000000100d184c103f7acc340847eee82a0b909e3358bc28d440edffa1352b13227e8ee646f3ea37456dec701345772617070656420457468657210574554481235003511000000000000000000000000000000000000000000").into(), + }, + Proof { block_hash: hex!("05aaa60b0f27cce9e71909508527264b77ee14da7b5bf915fcc4e32715333213").into(), tx_index: 0, data: (vec![ @@ -156,8 +164,8 @@ pub mod minimal { hex!("f851a0b9890f91ca0d77aa2a4adfaf9b9e40c94cac9e638b6d9797923865872944b646a060a634b9280e3a23fb63375e7bbdd9ab07fd379ab6a67e2312bbc112195fa358808080808080808080808080808080").to_vec(), hex!("f9030820b9030402f90300018301d6e2b9010000000000000800000000000020040008000000000000000000000000400000008000000000000000000000000000000000000000000000000000000000042010000000001000000000000000000000000000000000040000000000000000000000000000000000000000000000008000000000000000002000000000000000000000000200000000000000200000000000100000000040000001000200008000000000000200000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000f901f5f87a942ffa5ecdbe006d30397c7636d3e015eee251369ff842a0c965575a00553e094ca7c5d14f02e107c258dda06867cbf9e0e69f80e71bbcc1a000000000000000000000000000000000000000000000000000000000000003e8a000000000000000000000000000000000000000000000000000000000000003e8f9011c94ee9170abfbf9421ad6dd07f6bdec9d89f2b581e0f863a01b11dcf133cc240f682dab2d3a8e4cd35c5da8c9cf99adac4336f8512584c5ada000000000000000000000000000000000000000000000000000000000000003e8a00000000000000000000000000000000000000000000000000000000000000001b8a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004b000f000000000000000100d184c103f7acc340847eee82a0b909e3358bc28d440edffa1352b13227e8ee646f3ea37456dec701345772617070656420457468657210574554481235003511000000000000000000000000000000000000000000f858948cf6147918a5cbb672703f879f385036f8793a24e1a01449abf21e49fd025f33495e77f7b1461caefdd3d4bb646424a3f445c4576a5ba0000000000000000000000000440edffa1352b13227e8ee646f3ea37456dec701").to_vec(), ]), - }, - } + } + ) } pub fn get_message_verification_header() -> CompactExecutionHeader { diff --git a/parachain/pallets/ethereum-beacon-client/src/tests.rs b/parachain/pallets/ethereum-beacon-client/src/tests.rs index 95a7c38229..112a7e0f83 100644 --- a/parachain/pallets/ethereum-beacon-client/src/tests.rs +++ b/parachain/pallets/ethereum-beacon-client/src/tests.rs @@ -911,73 +911,88 @@ fn submit_execution_header_not_finalized() { #[test] fn verify_message() { let header = get_message_verification_header(); - let message = get_message_verification_payload(); - let block_hash = message.proof.block_hash; + let (event_log, proof) = get_message_verification_payload(); + let block_hash = proof.block_hash; new_tester().execute_with(|| { >::insert(block_hash, header); - assert_ok!(EthereumBeaconClient::verify(&message)); + assert_ok!(EthereumBeaconClient::verify(&event_log, &proof)); }); } #[test] fn verify_message_missing_header() { - let message = get_message_verification_payload(); + let (event_log, proof) = get_message_verification_payload(); new_tester().execute_with(|| { - assert_err!(EthereumBeaconClient::verify(&message), VerificationError::HeaderNotFound); + assert_err!( + EthereumBeaconClient::verify(&event_log, &proof), + VerificationError::HeaderNotFound + ); }); } #[test] fn verify_message_invalid_proof() { let header = get_message_verification_header(); - let mut message = get_message_verification_payload(); - message.proof.data.1[0] = TEST_HASH.into(); - let block_hash = message.proof.block_hash; + let (event_log, mut proof) = get_message_verification_payload(); + proof.data.1[0] = TEST_HASH.into(); + let block_hash = proof.block_hash; new_tester().execute_with(|| { >::insert(block_hash, header); - assert_err!(EthereumBeaconClient::verify(&message), VerificationError::InvalidProof); + assert_err!( + EthereumBeaconClient::verify(&event_log, &proof), + VerificationError::InvalidProof + ); }); } #[test] fn verify_message_invalid_receipts_root() { let mut header = get_message_verification_header(); - let message = get_message_verification_payload(); - let block_hash = message.proof.block_hash; + let (event_log, proof) = get_message_verification_payload(); + let block_hash = proof.block_hash; header.receipts_root = TEST_HASH.into(); new_tester().execute_with(|| { >::insert(block_hash, header); - assert_err!(EthereumBeaconClient::verify(&message), VerificationError::InvalidProof); + assert_err!( + EthereumBeaconClient::verify(&event_log, &proof), + VerificationError::InvalidProof + ); }); } #[test] -fn verify_message_invalid_message_data() { +fn verify_message_invalid_log() { let header = get_message_verification_header(); - let mut message = get_message_verification_payload(); - let block_hash = message.proof.block_hash; - message.data = TEST_HASH.into(); + let (mut event_log, proof) = get_message_verification_payload(); + let block_hash = proof.block_hash; + event_log.topics = vec![H256::zero(); 10]; new_tester().execute_with(|| { >::insert(block_hash, header); - assert_err!(EthereumBeaconClient::verify(&message), VerificationError::InvalidLog); + assert_err!( + EthereumBeaconClient::verify(&event_log, &proof), + VerificationError::InvalidLog + ); }); } #[test] fn verify_message_receipt_does_not_contain_log() { let header = get_message_verification_header(); - let mut message = get_message_verification_payload(); - let block_hash = message.proof.block_hash; - message.data = hex!("f9013c94ee9170abfbf9421ad6dd07f6bdec9d89f2b581e0f863a01b11dcf133cc240f682dab2d3a8e4cd35c5da8c9cf99adac4336f8512584c5ada000000000000000000000000000000000000000000000000000000000000003e8a00000000000000000000000000000000000000000000000000000000000000002b8c000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000068000f000000000000000101d184c103f7acc340847eee82a0b909e3358bc28d440edffa1352b13227e8ee646f3ea37456dec70100000101001cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c0000e8890423c78a0000000000000000000000000000000000000000000000000000000000000000").to_vec(); + let (mut event_log, proof) = get_message_verification_payload(); + let block_hash = proof.block_hash; + event_log.data = hex!("f9013c94ee9170abfbf9421ad6dd07f6bdec9d89f2b581e0f863a01b11dcf133cc240f682dab2d3a8e4cd35c5da8c9cf99adac4336f8512584c5ada000000000000000000000000000000000000000000000000000000000000003e8a00000000000000000000000000000000000000000000000000000000000000002b8c000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000068000f000000000000000101d184c103f7acc340847eee82a0b909e3358bc28d440edffa1352b13227e8ee646f3ea37456dec70100000101001cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c0000e8890423c78a0000000000000000000000000000000000000000000000000000000000000000").to_vec(); new_tester().execute_with(|| { >::insert(block_hash, header); - assert_err!(EthereumBeaconClient::verify(&message), VerificationError::LogNotFound); + assert_err!( + EthereumBeaconClient::verify(&event_log, &proof), + VerificationError::LogNotFound + ); }); } diff --git a/parachain/pallets/inbound-queue/src/benchmarking/fixtures.rs b/parachain/pallets/inbound-queue/src/benchmarking/fixtures.rs index 11da799df8..cb4b77310f 100644 --- a/parachain/pallets/inbound-queue/src/benchmarking/fixtures.rs +++ b/parachain/pallets/inbound-queue/src/benchmarking/fixtures.rs @@ -1,6 +1,6 @@ use hex_literal::hex; use snowbridge_beacon_primitives::CompactExecutionHeader; -use snowbridge_core::inbound::{Message, Proof}; +use snowbridge_core::inbound::{Log, Message, Proof}; use sp_std::vec; pub struct InboundQueueTest { @@ -17,7 +17,15 @@ pub fn make_create_message() -> InboundQueueTest { receipts_root: hex!("0115ab735d37c5e4cdb0374d8bb547c6dd6ccaa996d996d1eabc5399a719219e").into(), }, message: Message { - data: hex!("f8fc94eda338e4dc46038493b885327842fd3e301cab39f863a05066fbba677e15936860e04088ca4cad3acd4c19706962196a5346f1457f7169a000000000000000000000000000000000000000000000000000000000000003e8a0afad3c9777134532ae230b4fad334eef2e0dacbb965920412a7eaa59b07d640fb88000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001e000f000000000000000087d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000").to_vec(), + event_log: Log { + address: hex!("eda338e4dc46038493b885327842fd3e301cab39").into(), + topics: vec![ + hex!("5066fbba677e15936860e04088ca4cad3acd4c19706962196a5346f1457f7169").into(), + hex!("00000000000000000000000000000000000000000000000000000000000003e8").into(), + hex!("afad3c9777134532ae230b4fad334eef2e0dacbb965920412a7eaa59b07d640f").into(), + ], + data: hex!("00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001e000f000000000000000087d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000").into(), + }, proof: Proof { block_hash: hex!("5f465744c166e9d10dc0031942a59ff82b640053253da517a1b576afdadb0363").into(), tx_index: 0, diff --git a/parachain/pallets/inbound-queue/src/envelope.rs b/parachain/pallets/inbound-queue/src/envelope.rs index e12ecf6c0f..86c3d7f79e 100644 --- a/parachain/pallets/inbound-queue/src/envelope.rs +++ b/parachain/pallets/inbound-queue/src/envelope.rs @@ -1,21 +1,13 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2023 Snowfork -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, - pub data: Bytes, -} - sol! { event OutboundMessageAccepted(uint256 indexed destination, uint64 nonce, bytes32 indexed messageID, bytes payload); } @@ -42,11 +34,13 @@ impl TryFrom for Envelope { type Error = EnvelopeDecodeError; fn try_from(log: Log) -> Result { - let event = OutboundMessageAccepted::decode_log(log.topics, &log.data, true) + let topics: Vec = 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::().into(), nonce: event.nonce, message_id: H256::from(event.messageID.as_ref()), diff --git a/parachain/pallets/inbound-queue/src/lib.rs b/parachain/pallets/inbound-queue/src/lib.rs index 2d9e421cae..d14cf0ee3a 100644 --- a/parachain/pallets/inbound-queue/src/lib.rs +++ b/parachain/pallets/inbound-queue/src/lib.rs @@ -36,9 +36,8 @@ pub mod weights; #[cfg(test)] mod test; -use alloy_rlp::Decodable as RlpDecodable; use codec::{Decode, DecodeAll, Encode}; -use envelope::{Envelope, Log}; +use envelope::Envelope; use frame_support::{ traits::{ fungible::{Inspect, Mutate}, @@ -216,13 +215,12 @@ pub mod pallet { ensure!(!Self::operating_mode().is_halted(), Error::::Halted); // submit message to verifier for verification - T::Verifier::verify(&message).map_err(|e| Error::::Verification(e))?; + T::Verifier::verify(&message.event_log, &message.proof) + .map_err(|e| Error::::Verification(e))?; - let log = Log::decode(&mut message.data.as_slice()) - .map_err(|_| Error::::InvalidEnvelope)?; - - // Decode log into an Envelope - let envelope = Envelope::try_from(log).map_err(|_| Error::::InvalidEnvelope)?; + // Decode event log into an Envelope + let envelope = + Envelope::try_from(message.event_log).map_err(|_| Error::::InvalidEnvelope)?; // Verify that the message was submitted from the known Gateway contract ensure!(T::GatewayAddress::get() == envelope.gateway, Error::::InvalidGateway,); diff --git a/parachain/pallets/inbound-queue/src/test.rs b/parachain/pallets/inbound-queue/src/test.rs index 673218577f..d431cadddc 100644 --- a/parachain/pallets/inbound-queue/src/test.rs +++ b/parachain/pallets/inbound-queue/src/test.rs @@ -10,7 +10,7 @@ use frame_support::{ use hex_literal::hex; use snowbridge_beacon_primitives::{Fork, ForkVersions}; use snowbridge_core::{ - inbound::{Message, Proof, VerificationError}, + inbound::{Log, Proof, VerificationError}, ParaId, }; use snowbridge_router_primitives::inbound::MessageToXcm; @@ -122,7 +122,7 @@ impl snowbridge_ethereum_beacon_client::Config for Test { pub struct MockVerifier; impl Verifier for MockVerifier { - fn verify(_: &Message) -> Result<(), VerificationError> { + fn verify(_: &Log, _: &Proof) -> Result<(), VerificationError> { Ok(()) } } @@ -228,26 +228,57 @@ pub fn new_tester() -> sp_io::TestExternalities { ext } -// dest para is 1000 -const OUTBOUND_QUEUE_EVENT_LOG: [u8; 254] = hex!( - " - f8fc94eda338e4dc46038493b885327842fd3e301cab39f863a05066fbba677e15936860e04088ca4cad3acd4c19706962196a5346f1457f7169a000000000000000000000000000000000000000000000000000000000000003e8a0afad3c9777134532ae230b4fad334eef2e0dacbb965920412a7eaa59b07d640fb88000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001e000f000000000000000087d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000 - " -); +// Generated from smoketests: +// cd smoketests +// ./make-bindings +// cargo test --test register_token -- --nocapture +fn mock_event_log() -> Log { + Log { + // gateway address + address: hex!("eda338e4dc46038493b885327842fd3e301cab39").into(), + topics: vec![ + hex!("5066fbba677e15936860e04088ca4cad3acd4c19706962196a5346f1457f7169").into(), + // destination parachain id + hex!("00000000000000000000000000000000000000000000000000000000000003e8").into(), + // message id + hex!("afad3c9777134532ae230b4fad334eef2e0dacbb965920412a7eaa59b07d640f").into(), + ], + // Nonce + Payload + data: hex!("00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001e000f000000000000000087d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000").into(), + } +} -// dest para is 1001 -const OUTBOUND_QUEUE_EVENT_LOG_INVALID_DEST: [u8; 254] = hex!( - " - f8fc94eda338e4dc46038493b885327842fd3e301cab39f863a05066fbba677e15936860e04088ca4cad3acd4c19706962196a5346f1457f7169a000000000000000000000000000000000000000000000000000000000000003e9a0afad3c9777134532ae230b4fad334eef2e0dacbb965920412a7eaa59b07d640fb88000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001e000f000000000000000087d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000 - " -); +fn mock_event_log_invalid_dest() -> Log { + Log { + // gateway address + address: hex!("eda338e4dc46038493b885327842fd3e301cab39").into(), + topics: vec![ + hex!("5066fbba677e15936860e04088ca4cad3acd4c19706962196a5346f1457f7169").into(), + // destination parachain id + hex!("00000000000000000000000000000000000000000000000000000000000003e9").into(), + // message id + hex!("afad3c9777134532ae230b4fad334eef2e0dacbb965920412a7eaa59b07d640f").into(), + ], + // Nonce + Payload + data: hex!("00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001e000f000000000000000087d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000").into(), + } +} -// gateway in message does not match configured gateway in runtimeå -const BAD_OUTBOUND_QUEUE_EVENT_LOG: [u8; 254] = hex!( - " - f8fc940000000000000000000000000000000000000000f863a05066fbba677e15936860e04088ca4cad3acd4c19706962196a5346f1457f7169a000000000000000000000000000000000000000000000000000000000000003e8a0afad3c9777134532ae230b4fad334eef2e0dacbb965920412a7eaa59b07d640fb88000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001e000f000000000000000087d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000 - " -); +fn mock_event_log_invalid_gateway() -> Log { + Log { + // gateway address + address: H160::zero(), + topics: vec![ + hex!("5066fbba677e15936860e04088ca4cad3acd4c19706962196a5346f1457f7169").into(), + // destination parachain id + hex!("00000000000000000000000000000000000000000000000000000000000003e8").into(), + // message id + hex!("afad3c9777134532ae230b4fad334eef2e0dacbb965920412a7eaa59b07d640f").into(), + ], + // Nonce + Payload + data: hex!("00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001e000f000000000000000087d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000").into(), + } +} const ASSET_HUB_PARAID: u32 = 1000u32; const TEMPLATE_PARAID: u32 = 1001u32; @@ -265,7 +296,7 @@ fn test_submit_happy_path() { // Submit message let message = Message { - data: OUTBOUND_QUEUE_EVENT_LOG.into(), + event_log: mock_event_log(), proof: Proof { block_hash: Default::default(), tx_index: Default::default(), @@ -298,7 +329,7 @@ fn test_submit_xcm_send_failure() { // Submit message let message = Message { - data: OUTBOUND_QUEUE_EVENT_LOG_INVALID_DEST.into(), + event_log: mock_event_log_invalid_dest(), proof: Proof { block_hash: Default::default(), tx_index: Default::default(), @@ -324,7 +355,7 @@ fn test_submit_with_invalid_gateway() { // Submit message let message = Message { - data: BAD_OUTBOUND_QUEUE_EVENT_LOG.into(), + event_log: mock_event_log_invalid_gateway(), proof: Proof { block_hash: Default::default(), tx_index: Default::default(), @@ -350,7 +381,7 @@ fn test_submit_with_invalid_nonce() { // Submit message let message = Message { - data: OUTBOUND_QUEUE_EVENT_LOG.into(), + event_log: mock_event_log(), proof: Proof { block_hash: Default::default(), tx_index: Default::default(), @@ -382,7 +413,7 @@ fn test_submit_no_funds_to_reward_relayers() { // Submit message let message = Message { - data: OUTBOUND_QUEUE_EVENT_LOG.into(), + event_log: mock_event_log(), proof: Proof { block_hash: Default::default(), tx_index: Default::default(), @@ -402,7 +433,7 @@ fn test_set_operating_mode() { let relayer: AccountId = Keyring::Bob.into(); let origin = RuntimeOrigin::signed(relayer); let message = Message { - data: OUTBOUND_QUEUE_EVENT_LOG.into(), + event_log: mock_event_log(), proof: Proof { block_hash: Default::default(), tx_index: Default::default(), diff --git a/parachain/primitives/core/Cargo.toml b/parachain/primitives/core/Cargo.toml index fb8938ad9e..3e78750a7b 100644 --- a/parachain/primitives/core/Cargo.toml +++ b/parachain/primitives/core/Cargo.toml @@ -8,7 +8,6 @@ edition = "2021" serde = { version = "1.0.188", optional = true, features = [ "derive", "alloc" ], default-features = false } codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false } scale-info = { version = "2.9.0", default-features = false, features = [ "derive" ] } -snowbridge-ethereum = { path = "../ethereum", default-features = false } polkadot-parachain-primitives = { path = "../../../polkadot-sdk/polkadot/parachain", default-features = false } xcm = { package = "staging-xcm", path = "../../../polkadot-sdk/polkadot/xcm", default-features = false } @@ -39,7 +38,6 @@ std = [ "sp-std/std", "sp-core/std", "sp-runtime/std", - "snowbridge-ethereum/std", "snowbridge-beacon-primitives/std", "xcm/std", "ethabi/std", diff --git a/parachain/primitives/core/src/inbound.rs b/parachain/primitives/core/src/inbound.rs index bc28c7e3bb..4b04470ad0 100644 --- a/parachain/primitives/core/src/inbound.rs +++ b/parachain/primitives/core/src/inbound.rs @@ -5,13 +5,13 @@ use codec::{Decode, Encode}; use frame_support::PalletError; use scale_info::TypeInfo; -use sp_core::H256; +use sp_core::{H160, H256}; use sp_runtime::RuntimeDebug; use sp_std::vec::Vec; /// A trait for verifying inbound messages from Ethereum. pub trait Verifier { - fn verify(message: &Message) -> Result<(), VerificationError>; + fn verify(event: &Log, proof: &Proof) -> Result<(), VerificationError>; } #[derive(Clone, Encode, Decode, RuntimeDebug, PalletError, TypeInfo)] @@ -19,9 +19,9 @@ pub trait Verifier { pub enum VerificationError { /// Execution header is missing HeaderNotFound, - /// Log was not found in the verified transaction receipt + /// Event log was not found in the verified transaction receipt LogNotFound, - /// Data payload does not decode into a valid Log + /// Event log has an invalid format InvalidLog, /// Unable to verify the transaction receipt with the provided proof InvalidProof, @@ -32,12 +32,36 @@ pub type MessageNonce = u64; /// A bridge message from the Gateway contract on Ethereum #[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] pub struct Message { - /// RLP-encoded event log - pub data: Vec, + /// Event log emitted by Gateway contract + pub event_log: Log, /// Inclusion proof for a transaction receipt containing the event log pub proof: Proof, } +const MAX_TOPICS: usize = 4; + +#[derive(Clone, RuntimeDebug)] +pub enum LogValidationError { + TooManyTopics, +} + +/// Event log +#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +pub struct Log { + pub address: H160, + pub topics: Vec, + pub data: Vec, +} + +impl Log { + pub fn validate(&self) -> Result<(), LogValidationError> { + if self.topics.len() > MAX_TOPICS { + return Err(LogValidationError::TooManyTopics) + } + Ok(()) + } +} + /// Inclusion proof for a transaction receipt #[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] pub struct Proof { diff --git a/parachain/primitives/ethereum/src/log.rs b/parachain/primitives/ethereum/src/log.rs index 021ab16776..7b8e35bb11 100644 --- a/parachain/primitives/ethereum/src/log.rs +++ b/parachain/primitives/ethereum/src/log.rs @@ -2,10 +2,9 @@ // SPDX-FileCopyrightText: 2023 Snowfork use codec::{Decode, Encode}; use ethereum_types::{H160, H256}; -use scale_info::TypeInfo; use sp_std::prelude::*; -#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq, Default, TypeInfo)] +#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq)] pub struct Log { pub address: H160, pub topics: Vec, diff --git a/parachain/primitives/ethereum/src/receipt.rs b/parachain/primitives/ethereum/src/receipt.rs index c2efa3ae61..665a93dbb1 100644 --- a/parachain/primitives/ethereum/src/receipt.rs +++ b/parachain/primitives/ethereum/src/receipt.rs @@ -2,11 +2,10 @@ // SPDX-FileCopyrightText: 2023 Snowfork use crate::{Bloom, Log}; use codec::{Decode, Encode}; -use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; use sp_std::prelude::*; -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug)] pub struct Receipt { pub post_state_or_status: Vec, pub cumulative_gas_used: u64, diff --git a/polkadot-sdk b/polkadot-sdk index cd3fe506a5..5fec1d3eeb 160000 --- a/polkadot-sdk +++ b/polkadot-sdk @@ -1 +1 @@ -Subproject commit cd3fe506a56118963ded71cce138f435823eec30 +Subproject commit 5fec1d3eebe5bbae911a3be9b6e653acd65ae5a9 diff --git a/relayer/chain/ethereum/message.go b/relayer/chain/ethereum/message.go index 9659ec1867..901aeb3c29 100644 --- a/relayer/chain/ethereum/message.go +++ b/relayer/chain/ethereum/message.go @@ -5,7 +5,6 @@ package ethereum import ( "bytes" - "encoding/hex" etypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rlp" @@ -36,8 +35,17 @@ func MakeMessageFromEvent(event *etypes.Log, receiptsTrie *etrie.Trie) (*paracha return nil, err } + var convertedTopics []types.H256 + for _, topic := range event.Topics { + convertedTopics = append(convertedTopics, types.H256(topic)) + } + m := parachain.Message{ - Data: buf.Bytes(), + EventLog: parachain.EventLog{ + Address: types.H160(event.Address), + Topics: convertedTopics, + Data: event.Data, + }, Proof: parachain.Proof{ BlockHash: types.NewH256(event.BlockHash.Bytes()), TxIndex: types.NewU32(uint32(event.TxIndex)), @@ -45,12 +53,10 @@ func MakeMessageFromEvent(event *etypes.Log, receiptsTrie *etrie.Trie) (*paracha }, } - value := hex.EncodeToString(m.Data) log.WithFields(logrus.Fields{ - "payload": value, - "blockHash": m.Proof.BlockHash.Hex(), - "eventIndex": m.Proof.TxIndex, - "txHash": event.TxHash.Hex(), + "EventLog": m.EventLog, + "Proof": m.Proof, + "txHash": event.TxHash.Hex(), }).Debug("Generated message from Ethereum log") return &m, nil diff --git a/relayer/chain/parachain/message.go b/relayer/chain/parachain/message.go index 9a60275f01..85bf8928ed 100644 --- a/relayer/chain/parachain/message.go +++ b/relayer/chain/parachain/message.go @@ -10,9 +10,15 @@ import ( "github.com/snowfork/go-substrate-rpc-client/v4/types" ) +type EventLog struct { + Address types.H160 + Topics []types.H256 + Data types.Bytes +} + type Message struct { - Data []byte - Proof Proof + EventLog EventLog + Proof Proof } type Proof struct { diff --git a/relayer/go.mod b/relayer/go.mod index 7796b8598f..450325b2b1 100644 --- a/relayer/go.mod +++ b/relayer/go.mod @@ -9,7 +9,7 @@ require ( github.com/magefile/mage v1.13.0 github.com/sirupsen/logrus v1.8.1 github.com/snowfork/ethashproof v0.0.0-20210729080250-93b61cd82454 - github.com/snowfork/go-substrate-rpc-client/v4 v4.0.1-0.20230831112246-2cf362679c74 + github.com/snowfork/go-substrate-rpc-client/v4 v4.0.1-0.20231109131025-3ece5b994f03 github.com/spf13/cobra v1.4.0 github.com/spf13/viper v1.12.0 github.com/stretchr/testify v1.8.1 diff --git a/relayer/go.sum b/relayer/go.sum index 3efed1ccce..e7ef284dfd 100644 --- a/relayer/go.sum +++ b/relayer/go.sum @@ -28,6 +28,7 @@ cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM7 cloud.google.com/go/bigtable v1.2.0/go.mod h1:JcVAOl45lrTmQfLj7T6TxyMzIN/3FGGcFm+2xVAli2o= cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= +cloud.google.com/go/firestore v1.6.1/go.mod h1:asNXNOzBdyVQmEU+ggO8UPodTkEVFW5Qx+rwHnAz+EY= cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= @@ -84,6 +85,7 @@ github.com/aristanetworks/glog v0.0.0-20191112221043-67e8567f59f3/go.mod h1:KASm github.com/aristanetworks/goarista v0.0.0-20170210015632-ea17b1a17847/go.mod h1:D/tb0zPVXnP7fmsLZjtdUhSsumbK/ij54UXjjVgMGxQ= github.com/aristanetworks/goarista v0.0.0-20200609010056-95bcf8053598/go.mod h1:QZe5Yh80Hp1b6JxQdpfSEEe8X7hTyTEZSosSrFf/oJE= github.com/aristanetworks/splunk-hec-go v0.3.3/go.mod h1:1VHO9r17b0K7WmOlLb9nTk/2YanvOEnLMUgsFrxBROc= +github.com/armon/go-metrics v0.3.10/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc= github.com/aws/aws-sdk-go v1.25.48/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/aws/aws-sdk-go-v2 v1.2.0/go.mod h1:zEQs02YRBw1DjK0PoJv3ygDYOFTre1ejlJWl8FwAuQo= github.com/aws/aws-sdk-go-v2/config v1.1.1/go.mod h1:0XsVy9lBI/BCXm+2Tuvt39YmdHwS5unDQmxZOYe8F5Y= @@ -140,6 +142,8 @@ github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnht github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/consensys/bavard v0.1.8-0.20210406032232-f3452dc9b572/go.mod h1:Bpd0/3mZuaj6Sj+PqrmIquiOKy397AKGThQPaGzNXAQ= github.com/consensys/gnark-crypto v0.4.1-0.20210426202927-39ac3d4b3f1f/go.mod h1:815PAHg3wvysy0SyIqanF8gZ0Y1wjk/hrDHD/iT88+Q= +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= @@ -162,10 +166,12 @@ github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 h1:HbphB4TFFXpv7MNrT52FGrrgVXF1owhMVTHFZIlnvd4= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0/go.mod h1:DZGJHZMqrU4JJqFAWUS2UO1+lbSKsdiOoYi9Zzey7Fc= github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218= +github.com/deepmap/oapi-codegen v1.8.2/go.mod h1:YLgSKSDv/bZQB7N4ws6luhozi3cEdRktEqrX88CvjIw= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-bitstream v0.0.0-20180413035011-3522498ce2c8/go.mod h1:VMaSuZ+SZcx/wljOQKvp5srsbCiKDEb6K2wC4+PiBmQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/dlclark/regexp2 v1.2.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= +github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/dop251/goja v0.0.0-20200219165308-d1232e640a87/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA= github.com/dop251/goja v0.0.0-20200721192441-a695b0cdd498/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA= @@ -191,6 +197,7 @@ github.com/ethereum/go-ethereum v1.10.26 h1:i/7d9RBBwiXCEuyduBQzJw/mKmnvzsN14jqB github.com/ethereum/go-ethereum v1.10.26/go.mod h1:EYFyF19u3ezGLD4RqOkLq+ZCXzYbLoNDdZlMt7kyKFg= github.com/fatih/color v1.3.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/ferranbt/fastssz v0.1.3 h1:ZI+z3JH05h4kgmFXdHuR1aWYsgrg7o+Fw7/NCzM16Mo= github.com/ferranbt/fastssz v0.1.3/go.mod h1:0Y9TEd/9XuFlh7mskMPfXiI2Dkw4Ddg9EyXt1W7MRvE= github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= @@ -225,6 +232,7 @@ github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNI github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-sourcemap/sourcemap v2.1.2+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= +github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw= @@ -233,6 +241,7 @@ github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg78 github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang-jwt/jwt/v4 v4.3.0 h1:kHL1vqdqWNfATmA0FNMdmZNMyZI1U6O31X4rlIPoBog= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI= @@ -240,6 +249,7 @@ github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfU github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= @@ -321,6 +331,10 @@ github.com/gtank/merlin v0.1.1/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/b github.com/gtank/ristretto255 v0.1.2 h1:JEqUCPA1NvLq5DwYtuzigd7ss8fwbYay9fi4/5uMzcc= github.com/gtank/ristretto255 v0.1.2/go.mod h1:Ph5OpO6c7xKUGROZfWVLiJf9icMDwUeIvY4OmlYW69o= github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE= +github.com/hashicorp/go-bexpr v0.1.10/go.mod h1:oxlubA2vC/gFVfX1A6JGp7ls7uCDlfJn732ehYYg+g0= +github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= +github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= @@ -345,9 +359,11 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt github.com/influxdata/flux v0.65.1/go.mod h1:J754/zds0vvpfwuq7Gc2wRdVwEodfpCFM7mYlOw2LqY= github.com/influxdata/influxdb v1.2.3-0.20180221223340-01288bdb0883/go.mod h1:qZna6X/4elxqT3yI9iZYdZrWWdeFOOprn86kgg4+IzY= github.com/influxdata/influxdb v1.8.3/go.mod h1:JugdFhsvvI8gadxOI6noqNeeBHvWNTbfYGtiAn+2jhI= +github.com/influxdata/influxdb-client-go/v2 v2.4.0/go.mod h1:vLNHdxTJkIf2mSLvGrpj8TCcISApPoXkaxP8g9uRlW8= github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= github.com/influxdata/influxql v1.1.1-0.20200828144457-65d3ef77d385/go.mod h1:gHp9y86a/pxhjJ+zMjNXiQAA197Xk9wLxaz+fGG+kWk= github.com/influxdata/line-protocol v0.0.0-20180522152040-32c6aa80de5e/go.mod h1:4kt73NQhadE3daL3WhR5EJ/J2ocX0PZzwxQ0gXJ7oFE= +github.com/influxdata/line-protocol v0.0.0-20210311194329-9aa0e372d097/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo= github.com/influxdata/promql/v2 v2.12.0/go.mod h1:fxOPu+DY0bqCTCECchSRtWfc+0X19ybifQhZoQNF5D8= github.com/influxdata/roaring v0.4.13-0.20180809181101-fc520f41fab6/go.mod h1:bSgUQ7q5ZLSO+bKBGqJiCBGAl+9DxyW63zLTujjUlOE= github.com/influxdata/tdigest v0.0.0-20181121200506-bf2b5ad3c0a9/go.mod h1:Js0mqiSBE6Ffsg94weZZ2c+v/ciT8QRHFOap7EKDrR0= @@ -364,6 +380,7 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfC github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jsternberg/zap-logfmt v1.0.0/go.mod h1:uvPs/4X51zdkcm5jXl5SYoN+4RK21K8mysFmDaM/h+o= @@ -396,6 +413,7 @@ github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= @@ -406,11 +424,13 @@ github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPK github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= +github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-ieproxy v0.0.0-20190610004146-91bb50d98149/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= github.com/mattn/go-ieproxy v0.0.0-20190702010315-6dee0af9227d/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.5-0.20180830101745-3fb116b82035/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= @@ -424,13 +444,16 @@ github.com/mimoo/StrobeGo v0.0.0-20220103164710-9a04d6ca976b h1:QrHweqAtyJ9EwCaG github.com/mimoo/StrobeGo v0.0.0-20220103164710-9a04d6ca976b/go.mod h1:xxLb2ip6sSUts3g1irPVHyk/DGslwQsNOo9I7smJfNU= github.com/minio/sha256-simd v1.0.0 h1:v1ta+49hkWZyvaKwrQB8elexRqm6Y0aMLjCNsrYxo6g= github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A= +github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae/go.mod h1:qAyveg+e4CE+eKJXWVjKXM4ck2QobLqTDytGJbLLhJg= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/naoina/go-stringutil v0.1.0/go.mod h1:XJ2SJL9jCtBh+P9q5btrd/Ylo8XwT/h1USek5+NqSA0= @@ -554,6 +577,8 @@ github.com/snowfork/go-substrate-rpc-client/v4 v4.0.1-0.20230324140453-5bb90e7b1 github.com/snowfork/go-substrate-rpc-client/v4 v4.0.1-0.20230324140453-5bb90e7b12b7/go.mod h1:MVk5+w9icYU7MViYFm7CKYhx1VMj6DpN2tWO6s4OK5g= github.com/snowfork/go-substrate-rpc-client/v4 v4.0.1-0.20230831112246-2cf362679c74 h1:rUdiDH2OfZuqMQPVLP0v/tCrCZjAZNcibC9ceWJyFAY= github.com/snowfork/go-substrate-rpc-client/v4 v4.0.1-0.20230831112246-2cf362679c74/go.mod h1:MVk5+w9icYU7MViYFm7CKYhx1VMj6DpN2tWO6s4OK5g= +github.com/snowfork/go-substrate-rpc-client/v4 v4.0.1-0.20231109131025-3ece5b994f03 h1:MdYbdpjFGIV3znyTYGsQd2ea/rNme9iQFwW85iX/YmY= +github.com/snowfork/go-substrate-rpc-client/v4 v4.0.1-0.20231109131025-3ece5b994f03/go.mod h1:MVk5+w9icYU7MViYFm7CKYhx1VMj6DpN2tWO6s4OK5g= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spaolacci/murmur3 v1.0.1-0.20190317074736-539464a789e9/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.8.2 h1:xehSyVa0YnHWsJ49JFljMpg1HX19V6NDZ1fkm1Xznbo= @@ -639,9 +664,13 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= +go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -852,6 +881,7 @@ golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxb golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba h1:O8mE0/t419eoIwhTFpKVkHiTs/Igowgfkj25AcZrtiE= +golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -1016,6 +1046,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/ini.v1 v1.66.6 h1:LATuAqN/shcYAOkv3wl2L4rkaKqkcgTBQjOyYDvcPKI= diff --git a/smoketest/tests/register_token.rs b/smoketest/tests/register_token.rs index d8d4af6469..47738c65f5 100644 --- a/smoketest/tests/register_token.rs +++ b/smoketest/tests/register_token.rs @@ -1,7 +1,7 @@ use codec::Encode; use ethers::{ - core::types::Address, - utils::{parse_units, rlp::Encodable}, + core::types::{Address, Log}, + utils::{parse_units}, }; use futures::StreamExt; use snowbridge_smoketest::{ @@ -52,8 +52,9 @@ async fn register_token() { // Log for OutboundMessageAccepted let outbound_message_accepted_log = receipt.logs.last().unwrap(); - // RLP-encode log and print it - println!("receipt log: {:#?}", hex::encode(outbound_message_accepted_log.rlp_bytes())); + + // print log for unit tests + print_event_log_for_unit_tests(outbound_message_accepted_log); assert_eq!(receipt.status.unwrap().as_u64(), 1u64); @@ -94,3 +95,17 @@ async fn register_token() { } assert!(created_event_found) } + +fn print_event_log_for_unit_tests(log: &Log) { + let topics: Vec = log.topics.iter().map(|t| hex::encode(t.as_ref())).collect(); + println!("Log {{"); + println!(" address: hex!(\"{}\").into(),", hex::encode(log.address.as_ref())); + println!(" topics: vec!["); + for topic in topics.iter() { + println!(" hex!(\"{}\").into(),", topic); + } + println!(" ],"); + println!(" data: hex!(\"{}\").into(),", hex::encode(&log.data)); + + println!("}}") +}