diff --git a/bridges/snowbridge/pallets/outbound-queue-v2/src/api.rs b/bridges/snowbridge/pallets/outbound-queue-v2/src/api.rs index 56a3cce2f0af..f45e15bad647 100644 --- a/bridges/snowbridge/pallets/outbound-queue-v2/src/api.rs +++ b/bridges/snowbridge/pallets/outbound-queue-v2/src/api.rs @@ -14,7 +14,7 @@ use snowbridge_core::{ use snowbridge_merkle_tree::{merkle_proof, MerkleProof}; use snowbridge_router_primitives::outbound::v2::XcmConverter; use sp_core::Get; -use sp_std::vec::Vec; +use sp_std::{default::Default, vec::Vec}; use xcm::{ latest::Location, prelude::{Parachain, Xcm}, @@ -41,10 +41,10 @@ where &xcm, T::EthereumNetwork::get(), AgentIdOf::convert_location(&Location::new(1, Parachain(1000))) - .ok_or(DryRunError::ConvertFailed)?, + .ok_or(DryRunError::ConvertLocationFailed)?, ); - let message: Message = converter.convert().map_err(|_| DryRunError::ConvertFailed)?; + let message: Message = converter.convert().map_err(|_| DryRunError::ConvertXcmFailed)?; let fee = Fee::from(crate::Pallet::::calculate_local_fee()); @@ -58,8 +58,11 @@ where }) .collect(); - let committed_message = - InboundMessage { origin: message.origin.0.to_vec(), nonce: 0, commands }; + let committed_message = InboundMessage { + origin: message.origin, + nonce: Default::default(), + commands: commands.try_into().map_err(|_| DryRunError::ConvertXcmFailed)?, + }; Ok((committed_message, fee)) } diff --git a/bridges/snowbridge/pallets/outbound-queue-v2/src/lib.rs b/bridges/snowbridge/pallets/outbound-queue-v2/src/lib.rs index b420bae903bb..3294c97ded12 100644 --- a/bridges/snowbridge/pallets/outbound-queue-v2/src/lib.rs +++ b/bridges/snowbridge/pallets/outbound-queue-v2/src/lib.rs @@ -114,7 +114,7 @@ use frame_support::{ }; use snowbridge_core::{ inbound::Message as DeliveryMessage, - outbound::v2::{CommandWrapper, Fee, GasMeter, InboundMessage, Message}, + outbound::v2::{CommandWrapper, Fee, GasMeter, InboundMessage, InboundMessageWrapper, Message}, BasicOperatingMode, RewardLedger, TokenId, }; use snowbridge_merkle_tree::merkle_root; @@ -131,19 +131,23 @@ pub use pallet::*; use alloy_sol_types::SolValue; +use alloy_primitives::FixedBytes; + use sp_runtime::traits::TrailingZeroInput; use sp_runtime::traits::MaybeEquivalence; use xcm::prelude::{Location, NetworkId}; +use snowbridge_core::inbound::{VerificationError, Verifier}; + +use sp_core::H160; + #[frame_support::pallet] pub mod pallet { use super::*; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; - use snowbridge_core::inbound::{VerificationError, Verifier}; - use sp_core::H160; #[pallet::pallet] pub struct Pallet(_); @@ -389,14 +393,23 @@ pub mod pallet { .collect(); // Construct the final committed message - let committed_message = - InboundMessage { origin: message.origin.0.to_vec(), nonce, commands }; + let inbound_message = InboundMessage { + origin: message.origin, + nonce, + commands: commands.clone().try_into().map_err(|_| Corrupt)?, + }; + + let committed_message = InboundMessageWrapper { + origin: FixedBytes::from(message.origin.as_fixed_bytes()), + nonce, + commands, + }; // ABI-encode and hash the prepared message let message_abi_encoded = committed_message.abi_encode(); let message_abi_encoded_hash = ::Hashing::hash(&message_abi_encoded); - Messages::::append(Box::new(committed_message.clone())); + Messages::::append(Box::new(inbound_message)); MessageLeaves::::append(message_abi_encoded_hash); >::try_mutate(nonce, |maybe_locked| -> DispatchResult { diff --git a/bridges/snowbridge/pallets/outbound-queue-v2/src/test.rs b/bridges/snowbridge/pallets/outbound-queue-v2/src/test.rs index 45e43e0c7c9d..b4d70e37a9e4 100644 --- a/bridges/snowbridge/pallets/outbound-queue-v2/src/test.rs +++ b/bridges/snowbridge/pallets/outbound-queue-v2/src/test.rs @@ -1,3 +1,4 @@ +use alloy_primitives::FixedBytes; // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2023 Snowfork use crate::{mock::*, *}; @@ -12,7 +13,7 @@ use frame_support::{ use codec::Encode; use snowbridge_core::{ outbound::{ - v2::{primary_governance_origin, Command, SendMessage}, + v2::{primary_governance_origin, Command, InboundMessageWrapper, SendMessage}, SendError, }, ChannelId, ParaId, @@ -261,10 +262,12 @@ fn encode_mock_message() { }) .collect(); - // Todo: print the abi-encoded message and try to decode with solidity test - let committed_message = - InboundMessage { origin: message.origin.0.to_vec(), nonce: 1, commands }; + // print the abi-encoded message and decode with solidity test + let committed_message = InboundMessageWrapper { + origin: FixedBytes::from(message.origin.as_fixed_bytes()), + nonce: 1, + commands, + }; let message_abi_encoded = committed_message.abi_encode(); - // print_hex(message_abi_encoded.as_slice()); println!("{}", HexDisplay::from(&message_abi_encoded)); } diff --git a/bridges/snowbridge/pallets/system/src/mock.rs b/bridges/snowbridge/pallets/system/src/mock.rs index b02aa62e52f3..f20f8886450f 100644 --- a/bridges/snowbridge/pallets/system/src/mock.rs +++ b/bridges/snowbridge/pallets/system/src/mock.rs @@ -12,13 +12,7 @@ use xcm_executor::traits::ConvertLocation; use snowbridge_core::{ gwei, meth, - outbound::{ - v1::ConstantGasMeter, - v2::{ - DefaultOutboundQueue, Fee as FeeV2, Message as MessageV2, SendMessage as SendMessageV2, - }, - SendError, SendMessageFeeProvider, - }, + outbound::{v1::ConstantGasMeter, v2::DefaultOutboundQueue}, sibling_sovereign_account, AgentId, AllowSiblingsOnly, ParaId, PricingParameters, Rewards, }; use sp_runtime::{ diff --git a/bridges/snowbridge/primitives/core/src/outbound/mod.rs b/bridges/snowbridge/primitives/core/src/outbound/mod.rs index 6197211acbc0..0aa60f479195 100644 --- a/bridges/snowbridge/primitives/core/src/outbound/mod.rs +++ b/bridges/snowbridge/primitives/core/src/outbound/mod.rs @@ -44,5 +44,6 @@ pub enum SendError { #[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, Debug, TypeInfo)] pub enum DryRunError { - ConvertFailed, + ConvertLocationFailed, + ConvertXcmFailed, } diff --git a/bridges/snowbridge/primitives/core/src/outbound/v2.rs b/bridges/snowbridge/primitives/core/src/outbound/v2.rs index 57cb5b90fe2c..4443a6ea5297 100644 --- a/bridges/snowbridge/primitives/core/src/outbound/v2.rs +++ b/bridges/snowbridge/primitives/core/src/outbound/v2.rs @@ -16,19 +16,16 @@ use alloy_primitives::{Address, FixedBytes}; use alloy_sol_types::SolValue; sol! { - #[derive(Encode, Decode, RuntimeDebug, TypeInfo)] - #[cfg_attr(feature = "std", derive(PartialEq))] - struct InboundMessage { + struct InboundMessageWrapper { // origin - bytes origin; + bytes32 origin; // Message nonce uint64 nonce; // Commands CommandWrapper[] commands; } - #[derive(Encode, Decode, RuntimeDebug, TypeInfo)] - #[cfg_attr(feature = "std", derive(PartialEq))] + #[derive(Encode, Decode, RuntimeDebug, PartialEq,TypeInfo)] struct CommandWrapper { uint8 kind; uint64 gas; @@ -90,6 +87,16 @@ sol! { } } +#[derive(Encode, Decode, TypeInfo, PartialEq, Clone, RuntimeDebug)] +pub struct InboundMessage { + /// Origin + pub origin: H256, + /// Nonce + pub nonce: u64, + /// Commands + pub commands: BoundedVec>, +} + pub const MAX_COMMANDS: u32 = 8; /// A message which can be accepted by implementations of `/[`SendMessage`\]`