Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
aurexav committed Sep 15, 2022
1 parent f2c8d6d commit a46069f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion frame/bridge/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ impl<T: Send + Sync + Config + TypeInfo> SignedExtension for CheckEthereumRelayH
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> Result<Self::Pre, TransactionValidityError> {
Ok(self.validate(who, call, info, len).map(|_| ()))
self.validate(who, call, info, len).map(|_| ())
}

fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {
Expand Down
20 changes: 12 additions & 8 deletions frame/wormhole/backing/parachain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ pub mod pallet {

/// The message bridge instance to send message
type MessagesBridge: MessagesBridge<
Self::Origin,
Self::AccountId,
RingBalance<Self>,
<<Self as Config>::OutboundPayloadCreator as IssueFromRemotePayload<
Expand Down Expand Up @@ -158,6 +159,8 @@ pub mod pallet {
RingDailyLimited,
/// Message nonce duplicated.
NonceDuplicated,
// Remote mapping token factory account not set.
RemoteMappingTokenFactoryAccountNotSet,
}

/// Period between security limitation. Zero means there is no period limitation.
Expand Down Expand Up @@ -186,21 +189,21 @@ pub mod pallet {
#[pallet::storage]
#[pallet::getter(fn remote_mapping_token_factory_account)]
pub type RemoteMappingTokenFactoryAccount<T: Config> =
StorageValue<_, AccountId<T>, ValueQuery>;
StorageValue<_, AccountId<T>, OptionQuery>;

#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
pub secure_limited_period: BlockNumberFor<T>,
pub secure_limited_ring_amount: RingBalance<T>,
pub remote_mapping_token_factory_account: AccountId<T>,
pub remote_mapping_token_factory_account: Option<AccountId<T>>,
}
#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self {
secure_limited_period: Zero::zero(),
secure_limited_ring_amount: Zero::zero(),
remote_mapping_token_factory_account: Default::default(),
remote_mapping_token_factory_account: None,
}
}
}
Expand All @@ -212,9 +215,9 @@ pub mod pallet {
<RingBalance<T>>::zero(),
self.secure_limited_ring_amount,
));
<RemoteMappingTokenFactoryAccount<T>>::put(
self.remote_mapping_token_factory_account.clone(),
);
if let Some(a) = self.remote_mapping_token_factory_account.clone() {
<RemoteMappingTokenFactoryAccount<T>>::put(a);
}
}
}

Expand Down Expand Up @@ -277,7 +280,7 @@ pub mod pallet {
DispatchFeePayment::AtSourceChain,
)?;
T::MessagesBridge::send_message(
RawOrigin::Signed(Self::pallet_account_id()),
RawOrigin::Signed(Self::pallet_account_id()).into(),
T::MessageLaneId::get(),
payload,
fee,
Expand Down Expand Up @@ -309,7 +312,8 @@ pub mod pallet {
// Check call origin
ensure_source_account::<T::AccountId, T::BridgedAccountIdConverter>(
T::BridgedChainId::get(),
<RemoteMappingTokenFactoryAccount<T>>::get(),
<RemoteMappingTokenFactoryAccount<T>>::get()
.ok_or(<Error<T>>::RemoteMappingTokenFactoryAccountNotSet)?,
&user,
)?;

Expand Down
29 changes: 23 additions & 6 deletions node/runtime/common/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ impl Get<Option<(usize, ExtendedBalance)>> for OffchainRandomBalancing {
pub struct FromThisChainMessageVerifier<B, R, I>(PhantomData<(B, R, I)>);
impl<B, R, I>
LaneMessageVerifier<
OriginOf<ThisChain<B>>,
AccountIdOf<ThisChain<B>>,
FromThisChainMessagePayload<B>,
BalanceOf<ThisChain<B>>,
Expand All @@ -132,22 +133,25 @@ where
B: MessageBridge,
R: pallet_fee_market::Config<I>,
I: 'static,
// matches requirements from the `frame_system::Config::Origin`
OriginOf<ThisChain<B>>: Clone
+ Into<Result<frame_system::RawOrigin<AccountIdOf<ThisChain<B>>>, OriginOf<ThisChain<B>>>>,
AccountIdOf<ThisChain<B>>: Clone + PartialEq,
pallet_fee_market::BalanceOf<R, I>: From<BalanceOf<ThisChain<B>>>,
{
type Error = &'static str;

#[cfg(not(feature = "runtime-benchmarks"))]
fn verify_message(
submitter: &Sender<AccountIdOf<ThisChain<B>>>,
submitter: &OriginOf<ThisChain<B>>,
delivery_and_dispatch_fee: &BalanceOf<ThisChain<B>>,
lane: &LaneId,
lane_outbound_data: &OutboundLaneData,
payload: &FromThisChainMessagePayload<B>,
) -> Result<(), Self::Error> {
// reject message if lane is blocked
if !ThisChain::<B>::is_outbound_lane_enabled(lane) {
return Err(OUTBOUND_LANE_DISABLED);
if !ThisChain::<B>::is_message_accepted(submitter, lane) {
return Err(MESSAGE_REJECTED_BY_OUTBOUND_LANE);
}

// reject message if there are too many pending messages at this lane
Expand All @@ -161,8 +165,21 @@ where

// Do the dispatch-specific check. We assume that the target chain uses
// `Dispatch`, so we verify the message accordingly.
pallet_bridge_dispatch::verify_message_origin(submitter, payload)
.map_err(|_| BAD_ORIGIN)?;
let raw_origin_or_err: Result<
frame_system::RawOrigin<AccountIdOf<ThisChain<B>>>,
OriginOf<ThisChain<B>>,
> = submitter.clone().into();
if let Ok(raw_origin) = raw_origin_or_err {
pallet_bridge_dispatch::verify_message_origin(&raw_origin, payload)
.map(drop)
.map_err(|_| BAD_ORIGIN)?
} else {
// so what it means that we've failed to convert origin to the
// `frame_system::RawOrigin`? now it means that the custom pallet origin has
// been used to send the message. Do we need to verify it? The answer is no,
// because pallet may craft any origin (e.g. root) && we can't verify whether it
// is valid, or not.
}

// Do the delivery_and_dispatch_fee. We assume that the delivery and dispatch fee always
// greater than the fee market provided fee.
Expand All @@ -185,7 +202,7 @@ where

#[cfg(feature = "runtime-benchmarks")]
fn verify_message(
_submitter: &Sender<AccountIdOf<ThisChain<B>>>,
_submitter: &OriginOf<ThisChain<B>>,
_delivery_and_dispatch_fee: &BalanceOf<ThisChain<B>>,
_lane: &LaneId,
_lane_outbound_data: &OutboundLaneData,
Expand Down

0 comments on commit a46069f

Please sign in to comment.