Skip to content

XCM executor keeps track and resolves all imbalances created by XCM operations#10384

Merged
acatangiu merged 79 commits intoparitytech:masterfrom
acatangiu:xcm-executor-annoyance
Feb 16, 2026
Merged

XCM executor keeps track and resolves all imbalances created by XCM operations#10384
acatangiu merged 79 commits intoparitytech:masterfrom
acatangiu:xcm-executor-annoyance

Conversation

@acatangiu
Copy link
Copy Markdown
Contributor

@acatangiu acatangiu commented Nov 21, 2025

Introduce "ImbalanceAccounting" traits for dynamic dispatch management of imbalances. These are helper traits to be used for generic Imbalance, helpful for tracking multiple concrete types of Imbalance using dynamic dispatch of these traits.

xcm-executor now tracks imbalances in holding.

Change the xcm executor implementation and inner types and adapters so that it keeps track of imbalances across the stack.

Previously, XCM operations on fungible assets would break the respective fungibles' total issuance invariants by burning and minting them in different stages of XCM processing pipeline.

This commit fixes that by keeping track of the "withdrawn" or "deposited" fungible assets in holding and other XCM registers as imbalances. The imbalances are tied to the underlying pallet managing the asset so that they keep the assets' total issuance correctness throughout the execution of the XCM program.

Imbalances in XCM registers are resolved by the underlying pallets managing them whenever they move from XCM registers to other parts of the stack (e.g. deposited to accounts, burned, etc).

XCM emulated tests now also verify total issuance before/after transfers, swaps, traps, claims, etc to guarantee implementation correctness.

@acatangiu acatangiu added the T6-XCM This PR/Issue is related to XCM. label Nov 21, 2025
Copy link
Copy Markdown
Contributor

@muharem muharem left a comment

Choose a reason for hiding this comment

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

thanks, this is a big effort. looks good to me. It does make things even more complex, though, but I don’t have a fundamentally better idea. I left a few suggestions that might make things a bit safer.

this definitely requires us to write new tests for all affected types to verify the correct total issuance.

Comment thread polkadot/xcm/xcm-executor/src/traits/transact_asset.rs
Comment thread polkadot/xcm/xcm-executor/src/config.rs Outdated
Comment thread polkadot/xcm/xcm-executor/src/assets.rs
Comment thread polkadot/xcm/xcm-executor/src/assets.rs
Comment thread polkadot/xcm/xcm-executor/src/assets.rs
Comment thread polkadot/xcm/pallet-xcm/src/lib.rs
Comment thread polkadot/xcm/pallet-xcm/src/lib.rs
Comment thread substrate/frame/support/src/traits/tokens/fungible/imbalance.rs Outdated
Comment thread substrate/frame/support/src/traits/tokens/imbalance/imbalance_accounting.rs Outdated
Comment thread polkadot/xcm/xcm-executor/src/assets.rs
@acatangiu acatangiu force-pushed the xcm-executor-annoyance branch from 3f3726e to f1311eb Compare November 27, 2025 09:02
…t of imbalances

Helper traits to be used for generic Imbalance, helpful for tracking multiple concrete
types of `Imbalance` using dynamic dispatch of these traits.
Change the xcm executor implementation and inner types and adapters so that
it keeps track of imbalances across the stack.

Previously, XCM operations on fungible assets would break the respective
fungibles' total issuance invariants by burning and minting them in different
stages of XCM processing pipeline.

This commit fixes that by keeping track of the "withdrawn" or "deposited"
fungible assets in holding and other XCM registers as imbalances. The
imbalances are tied to the underlying pallet managing the asset so that they
keep the assets' total issuance correctness throughout the execution of the
XCM program.

Imbalances in XCM registers are resolved by the underlying pallets managing
them whenever they move from XCM registers to other parts of the stack
(e.g. deposited to accounts, burned, etc).
@acatangiu acatangiu force-pushed the xcm-executor-annoyance branch from 7cc28e9 to ab8e24f Compare December 3, 2025 15:50
@acatangiu acatangiu changed the title [wip] XCM executor keeps track and resolves all imbalances created by XCM operations XCM executor keeps track and resolves all imbalances created by XCM operations Dec 3, 2025
@acatangiu acatangiu marked this pull request as ready for review December 3, 2025 15:51
@acatangiu acatangiu requested review from a team as code owners December 3, 2025 15:51
@paritytech-review-bot paritytech-review-bot Bot requested review from a team December 3, 2025 15:52
Comment thread polkadot/xcm/xcm-executor/src/traits/transact_asset.rs
Copy link
Copy Markdown
Contributor

@muharem muharem 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. few comments to double check

Comment thread polkadot/xcm/xcm-builder/src/nonfungible_adapter.rs
Comment thread polkadot/xcm/xcm-builder/src/transfer.rs Outdated
Comment thread polkadot/xcm/xcm-builder/src/transfer.rs Outdated
Comment thread polkadot/xcm/xcm-executor/src/lib.rs
Comment thread polkadot/xcm/xcm-executor/src/lib.rs
@acatangiu
Copy link
Copy Markdown
Contributor Author

@seadanda @rockbmb do we have Treasury cross-chain payments tests in Polkadot Ecosytem Tests?

I would like to validate this doesn't break that case.

@rockbmb
Copy link
Copy Markdown
Contributor

rockbmb commented Jan 16, 2026

@acatangiu we don't; (@dhirajs0 might be good to consider for https://github.com/open-web3-stack/polkadot-ecosystem-tests/pull/439/changes)

@acatangiu
Copy link
Copy Markdown
Contributor Author

/cmd fmt

@acatangiu
Copy link
Copy Markdown
Contributor Author

@muharem all comments are now addressed. ptal

@rachsrl rachsrl moved this from Scheduled to In progress in Security Audit (PRs) - SRLabs Jan 22, 2026
@redzsina redzsina moved this from In progress to Scheduled in Security Audit (PRs) - SRLabs Feb 2, 2026
@redzsina redzsina moved this from Scheduled to Audited in Security Audit (PRs) - SRLabs Feb 2, 2026
@rachsrl rachsrl moved this from Audited to In progress in Security Audit (PRs) - SRLabs Feb 2, 2026
@acatangiu
Copy link
Copy Markdown
Contributor Author

/cmd fmt

@redzsina redzsina moved this from In progress to Waiting for fix in Security Audit (PRs) - SRLabs Feb 12, 2026
@acatangiu acatangiu added this pull request to the merge queue Feb 16, 2026
Merged via the queue into paritytech:master with commit 1323611 Feb 16, 2026
242 of 244 checks passed
@acatangiu acatangiu added the A4-backport-stable2603 Pull request must be backported to the stable2603 release branch label Mar 10, 2026
paritytech-release-backport-bot Bot pushed a commit that referenced this pull request Mar 10, 2026
…perations (#10384)

Introduce "ImbalanceAccounting" traits for dynamic dispatch management
of imbalances. These are helper traits to be used for generic Imbalance,
helpful for tracking multiple concrete types of `Imbalance` using
dynamic dispatch of these traits.

`xcm-executor` now tracks imbalances in holding.

Change the xcm executor implementation and inner types and adapters so
that it keeps track of imbalances across the stack.

Previously, XCM operations on fungible assets would break the respective
fungibles' total issuance invariants by burning and minting them in
different stages of XCM processing pipeline.

This commit fixes that by keeping track of the "withdrawn" or
"deposited" fungible assets in holding and other XCM registers as
imbalances. The imbalances are tied to the underlying pallet managing
the asset so that they keep the assets' total issuance correctness
throughout the execution of the XCM program.

Imbalances in XCM registers are resolved by the underlying pallets
managing them whenever they move from XCM registers to other parts of
the stack (e.g. deposited to accounts, burned, etc).

XCM emulated tests now also verify total issuance before/after
transfers, swaps, traps, claims, etc to guarantee implementation
correctness.

---------

Signed-off-by: Adrian Catangiu <adrian@parity.io>
Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Daniel Shiposha <dev@shiposha.com>
Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: 0xRVE <robertvaneerdewijk@gmail.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
Co-authored-by: Paolo La Camera <paolo@parity.io>
Co-authored-by: Ankan <10196091+Ank4n@users.noreply.github.com>
Co-authored-by: Alexander Samusev <41779041+alvicsam@users.noreply.github.com>
Co-authored-by: Manuel Mauro <manuel.mauro@protonmail.com>
Co-authored-by: Alexandre R. Baldé <alexandre.balde@parity.io>
Co-authored-by: Omar <OmarAbdulla7@hotmail.com>
Co-authored-by: BDevParity <bruno.devic@parity.io>
Co-authored-by: Egor_P <egor@parity.io>
Co-authored-by: Andrei Eres <eresav@me.com>
Co-authored-by: Klapeyron <11329616+Klapeyron@users.noreply.github.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: Alexandru Gheorghe <49718502+alexggh@users.noreply.github.com>
Co-authored-by: Xavier Lau <x@acg.box>
Co-authored-by: Dónal Murray <donal.murray@parity.io>
(cherry picked from commit 1323611)
@paritytech-release-backport-bot
Copy link
Copy Markdown

Successfully created backport PR for stable2603:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A4-backport-stable2603 Pull request must be backported to the stable2603 release branch T6-XCM This PR/Issue is related to XCM.

Projects

Status: Waiting for fix
Status: Done
Status: To be released (SDK)

Development

Successfully merging this pull request may close these issues.