Skip to content

Add XCM Precompile to pallet-xcm#8693

Merged
athei merged 78 commits intomasterfrom
tb/integ_xcm_precompile_pallet_xcm
Jun 11, 2025
Merged

Add XCM Precompile to pallet-xcm#8693
athei merged 78 commits intomasterfrom
tb/integ_xcm_precompile_pallet_xcm

Conversation

@tiagobndr
Copy link
Copy Markdown
Contributor

This PR adds the XCM precompile (with xcmSend, xcmExecute and weightMessage functionalities) to pallet-xcm.

This follows the discussion we had on the now closed PR, which attempted to add the precompile to pallet-revive, but that approach would have introduced unwanted cyclic dependencies. That's why we decided to migrate the precompile to pallet-xcm, avoiding adding unnecessary dependencies to pallet-revive.

This PR should also encapsulate unit tests in precompiles.rs as well as integration tests under cumulus/parachains/integration-tests/emulated/tests.

See tracking parent issue

@tiagobndr
Copy link
Copy Markdown
Contributor Author

/cmd fmt

@franciscoaguirre franciscoaguirre added the T6-XCM This PR/Issue is related to XCM. label May 28, 2025
/// @notice Execute an XCM message locally with the caller's origin
/// @param message The XCM message to send
/// @param weight The maximum amount of weight to be used to execute the message
function xcmExecute(bytes calldata message, Weight calldata weight) external;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't return anything from either xcmExecute or xcmSend, should we at least let the caller know if it was successful? Or we just revert?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about emitting an event @franciscoaguirre

Copy link
Copy Markdown
Contributor Author

@tiagobndr tiagobndr May 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about emitting an event @franciscoaguirre

We get that out of the box from calling pallet_xcm::send() or pallet_xcm::execute() - e.g. here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't return anything from either xcmExecute or xcmSend, should we at least let the caller know if it was successful? Or we just revert?

From the call to the precompile, we get back whatever gets returned from pallet_xcm::send() or pallet_xcm::execute(). It's just that we don't explicitly set it in the interface because we don't know its type in advance

Copy link
Copy Markdown
Member

@xermicus xermicus Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this interface. In practice, as @franciscoaguirre pointed out, how would you even know if it succeeded or not?

I suggest to version the interface in one way or the other, such that it will remain stable (then return values are possible - even if they are just untyped bytes[] the caller at least get's a chance to decode them, can be added later).

Copy link
Copy Markdown
Member

@xermicus xermicus Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW if the precompile reverts on errors, callers can at least check the call success variable in Solidity. But versioning it explicitly still seems like a good idea to me. Unless to whatever this is calling into is absolutely stable forever? I can't really imagine that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And those things should be documented in the interface as well.

Copy link
Copy Markdown
Member

@xermicus xermicus Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And pleases also consider this: Given the precompile reverts on error, any change in the conditions when reverts happen is a breaking change. Unless I am missing things I don't yet see how this will work out unless we get a mapping of exactly one (versioned) interface to one precompile contract address.

@sphamjoli
Copy link
Copy Markdown
Member

@tiagobndr @franciscoaguirre should precompile.rs not be named precompile.rs

@sphamjoli
Copy link
Copy Markdown
Member

/cmd fmt

@tiagobndr
Copy link
Copy Markdown
Contributor Author

@tiagobndr @franciscoaguirre should precompile.rs not be named precompile.rs

I followed the same convention (precompiles.rs) used in the ERC20 precompile (PR#8554). I don't have a strong opinion on it but one reason this approach could make sense is that we might add additional XCM precompiles to the same file in the future

Copy link
Copy Markdown
Contributor

@acatangiu acatangiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Left a couple of comments.

@tiagobndr
Copy link
Copy Markdown
Contributor Author

/cmd fmt

@tiagobndr tiagobndr marked this pull request as ready for review May 29, 2025 14:39
@tiagobndr tiagobndr requested a review from a team as a code owner May 29, 2025 14:39
@github-actions
Copy link
Copy Markdown
Contributor

Review required! Latest push from author must always be reviewed

@athei
Copy link
Copy Markdown
Member

athei commented Jun 7, 2025

  1. XCM is already versioned. We are just routing through the XCM as-is which preserves those properties. Please note that we read a VersionedXcm struct from the contract. So we should be fine here.
  2. Please note that contracts can match on the revert strings here. So they can never change. That might be really annoying for a string. I suggest just returning an Error which traps without an error to catch on.

Copy link
Copy Markdown
Member

@athei athei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry have to block until my comment is addressed. When adding the dispatchable weight to the pre-charged weight it also needs to be added to the actual weight. Otherwise it is only included once. Or am I wrong here?

@franciscoaguirre
Copy link
Copy Markdown
Contributor

@athei I commited in faceac5 a small fix regarding weights. The execute call has to take in the weight passed in as a parameter to the precompile, not what I called weight_to_charge which is that weight + the benchmark for execute.

The benchmarked weight for execute doesn't need to be added to the post dispatch info because the call itself adds it here in the case of a simple pre-validation error and here in the case of a partial execution of the XCM.

@paritytech-workflow-stopper
Copy link
Copy Markdown

All GitHub workflows were cancelled due to failure one of the required jobs.
Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/15578396319
Failed job name: test-linux-stable-no-try-runtime

@athei
Copy link
Copy Markdown
Member

athei commented Jun 11, 2025

Ahh yes I get it now. I missed that you are calling into a dispatch able that already includes its own weight. Thought you were calling into the executor directly.

@athei athei added this pull request to the merge queue Jun 11, 2025
Merged via the queue into master with commit 37951b6 Jun 11, 2025
244 checks passed
@athei athei deleted the tb/integ_xcm_precompile_pallet_xcm branch June 11, 2025 13:30
@github-project-automation github-project-automation bot moved this from In-Review to Done in Bridges + XCM Jun 11, 2025
ordian added a commit that referenced this pull request Jun 12, 2025
* master: (62 commits)
  release/build-macos-binaries: add missing FEATURES argument  (#8816)
  Add XCM Precompile to `pallet-xcm` (#8693)
  [Release|CI/CD] Exclude test runtimes from the runtimes build (#8820)
  Add freebsd sysinfo for telemetry (#7985)
  release-reusable-rc-build: add optional `features` input that can be considered for nodes building (#8755)
  [Staking] Cleanups and some improvements (#8701)
  Fix typos in 3 files in Implementers Guide (#8799)
  Update `RemoteExporter` docs to reflect removal of `forward_id_for` (#8795)
  Snowbridge: enforce fee when registering Polkadot native asset (#8725)
  Bump the ci_dependencies group across 1 directory with 7 updates (#8788)
  Docker hub 'master' image short sha (#8790)
  [Release|CI/CD] Combine branch-off and RC automation flows (#8754)
  Move Transaction depth limit checks (#8750)
  Add genesis presets for remaining runtimes in polkadot-parachain-bin (#8426)
  Do not make pallet-identity benchmarks signature-dependent (#8179)
  Introduction of Approval Slashes [Disabling Strategy Stage 4] (#6827)
  [AHM] Prepare For Westend Cleanup (#8715)
  Actually use RP offset in YAP parachain (#8745)
  [AHM] Relax the requirement for RC-Client to receive +1 session reports (#8702)
  Don't read storage items in logging (#8749)
  ...
@xermicus
Copy link
Copy Markdown
Member

xermicus commented Jun 30, 2025

@tiagobndr @Brianspha my review comments were dismissed entirely. Why? Developer experience wise, this is a disaster. This isn't done yet, please fix with a follow up PR. Also don't forget to document it externally on our docs (here / here).

@athei
Copy link
Copy Markdown
Member

athei commented Jun 30, 2025

But wait. Didn't we discuss that you detect whether this failed by catching the panic? But I guess this is really bad because in Solidity panics are silently ignored by default (lol).

@tiagobndr
Copy link
Copy Markdown
Contributor Author

@tiagobndr @Brianspha my review comments were dismissed entirely. Why? Developer experience wise, this is a disaster. This isn't done yet, please fix with a follow up PR.

@xermicus you’re right that the DevEx could be improved. We opened PR #9023 to address this — would really appreciate your feedback on it when you have a moment

@xermicus
Copy link
Copy Markdown
Member

Ah that's great, thanks! Didn't see 9023, happy to take a look once it's ready.

Just think about it from this perspective: You are a Solidity dev (know nothing about Polkadot) and try to do XCM. I was already asked exactly this a couple times. Ideally our interfaces together with doc comments and broader documentation are written well enough so we don't need to hand hold them at all.

fellowship-merge-bot bot pushed a commit to polkadot-fellows/runtimes that referenced this pull request Aug 15, 2025
This brings in `unstable2507` Polkadot SDK, and integrates new features.

Integrated breaking changes to be verified by the original authors:

- [ ] paritytech/polkadot-sdk#7953 @kianenigma
@Ank4n acatangiu#13
- [x] paritytech/polkadot-sdk#8684 @nkpar
- [x] paritytech/polkadot-sdk#8693 @tiagobndr
@franciscoaguirre
- [x] paritytech/polkadot-sdk#9137
@franciscoaguirre

fixes #837

---------

Co-authored-by: Branislav Kontur <[email protected]>
Co-authored-by: Kian Paimani <[email protected]>
Co-authored-by: kianenigma <[email protected]>
Co-authored-by: Christian Langenbacher <[email protected]>
alvicsam pushed a commit that referenced this pull request Oct 17, 2025
This PR adds the XCM precompile (with `xcmSend`, `xcmExecute` and
`weightMessage` functionalities) to `pallet-xcm`.

This follows the discussion we had on the now closed
[PR](#8471), which
attempted to add the precompile to `pallet-revive`, but that approach
would have introduced unwanted cyclic dependencies. That's why we
decided to migrate the precompile to `pallet-xcm`, avoiding adding
unnecessary dependencies to `pallet-revive`.

This PR should also encapsulate unit tests in `precompiles.rs` as well
as integration tests under
`cumulus/parachains/integration-tests/emulated/tests`.

See tracking parent
[issue](#6718)

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Siphamandla Mjoli <[email protected]>
Co-authored-by: Siphamandla Mjoli <[email protected]>
Co-authored-by: Alexander Theißen <[email protected]>
Co-authored-by: Francisco Aguirre <[email protected]>
Co-authored-by: PG Herveou <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T6-XCM This PR/Issue is related to XCM.

Projects

Status: Done
Status: Done
Status: To be released (SDK)

Development

Successfully merging this pull request may close these issues.

9 participants