0

I am sending an XCM Transact message in on_finalize hook, which calls on_transact_received function on the receiving side. I would like to assure that this call was called by the hook (trusted data) and not by some random person. I assume I have to use the DescendOrigin() instruction but I am not sure what to put in on the sending side (a sovereign account? how?) and how to decode it on the receiving side. Can you provide a small code excerpt for both sides?

1 Answer 1

2
  1. On the sending side, I think you can send your XCM directly without including DescendOrigin instruction.

    The XCM might be:

    WithdrawAsset(..),
    BuyExecution(..),
    Transact(..)
    
  2. And then on the receiving side, you need to make sure the Origin which call your function is the sending chain's sovereign account.

Let me explain to you why.

For the first step, in general, without DescendOrigin represent the XCM is sent via sudo or governance or your runtime code, which will be your sovereign account on receiving chain, and it is trustworthy. Because a DescendOrigin will be added when an ordinary user send a XCM.

For the second step, maybe you want to know how to calculate the sovereign account, please refer to how to calculate sovereignAccount for parachain?

6
  • Thanks @Guantong, on the receiving side, it does not return on ensure_signed(origin) but the XCM call is successful - function signature Do you know why? On the sending side I call it with OriginKind::Native, I define sovereign account as pub const SovereignAccount: AccountId = sp_runtime::AccountId32::new(hex_literal::hex!["7369626c07d10000000000000000000000000000000000000000000000000000"]); however it does not execute this check.
    – birbomakar
    Dec 5, 2022 at 12:32
  • 1
    Maybe you should add logs and debug it.
    – Guantong
    Dec 7, 2022 at 5:47
  • I get the BadSigner error. Do I have to do something with the OriginFor on the receiving side? I am trying to find an example of this.
    – birbomakar
    Dec 7, 2022 at 18:03
  • 1
    github.com/paritytech/polkadot/blob/v0.9.34/runtime/parachains/… May be this can be a reference.
    – Guantong
    Dec 8, 2022 at 2:36
  • 1
    Yeah hrmp_init_open_channel can't be called by ordinary user, if an ordinary user send the call, ensure_parachain would fail.
    – Guantong
    Dec 8, 2022 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.