-
Notifications
You must be signed in to change notification settings - Fork 885
[XCM] Investigate better support for filtering XCM programs with Barrier
#7148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Comments
3 tasks
#7169 for the fix |
I found a very old similar issue: #837 |
This was referenced Jan 15, 2025
This was
linked to
pull requests
Jan 21, 2025
2 tasks
github-merge-queue bot
pushed a commit
that referenced
this issue
Jan 27, 2025
Resolves (partially): #7148 (see _Problem 1 - `ShouldExecute` tuple implementation and `Deny` filter tuple_) This PR changes the behavior of `DenyThenTry` from the pattern `DenyIfAllMatch` to `DenyIfAnyMatch` for the tuple. I would expect the latter is the right behavior so make the fix in place, but we can also add a dedicated Impl with the legacy one untouched. ## TODO - [x] add unit-test for `DenyReserveTransferToRelayChain` - [x] add test and investigate/check `DenyThenTry` as discussed [here](#6838 (comment)) and update documentation if needed --------- Co-authored-by: Branislav Kontur <[email protected]> Co-authored-by: Francisco Aguirre <[email protected]> Co-authored-by: command-bot <> Co-authored-by: Clara van Staden <[email protected]> Co-authored-by: Adrian Catangiu <[email protected]>
raymondkfcheung
added a commit
that referenced
this issue
Jan 31, 2025
Resolves (partially): #7148 Depends on: #7169, #7200 # Description For context and additional information, please refer to #7148 and #7200. # TODOs * [x] Rebase #7169 and #7200 * [x] Evaluate PoC described on #7200 | POC | Top-Level Denial | Nested Denial | Try `Allow` | Remark | |--------------------------------|--------------------|--------------------|--------------------|----------------------------------------------------------------------------------| | `DenyThenTry` | ✅ | ❌ | ✅ | Blocks top-level instructions only. | | `RecursiveDenyThenTry` | ✅ | ✅ | ✅ | Blocks both top-level and nested instructions. | | `DenyInstructionsWithXcm` | ❌ | ✅ | ❌ | Focuses on nested instructions, requires additional checks for top-level denial. | | `DenyFirstInstructionsWithXcm` | ✅ | ✅ | ❌ | Prioritises top-level denial before recursive checks. | --------- Co-authored-by: ron <[email protected]> Co-authored-by: Branislav Kontur <[email protected]> Co-authored-by: Francisco Aguirre <[email protected]> Co-authored-by: command-bot <> Co-authored-by: Clara van Staden <[email protected]> Co-authored-by: Adrian Catangiu <[email protected]> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-merge-queue bot
pushed a commit
that referenced
this issue
Feb 19, 2025
…o be executed on the local chain (#7200) Resolves (partially): #7148 Depends on: #7169 # Description This PR addresses partially #7148 (Problem 2) and ensures the proper checking of nested local instructions. It introduces a new barrier - `DenyRecursively` - to provide more refined control over instruction denial. The main change is the replacement of `DenyThenTry<Deny, Allow>` with `DenyThenTry<DenyRecursively<Deny>, Allow>` which handles both top-level and nested local instructions by applying allow condition after denial. For context and additional information, please refer to [_Problem 2 - Barrier vs nested XCM validation_](#7148). # TODO - [x] Evaluate PoC, more details at #7351: - **DenyNestedXcmInstructions**: Keep it as it is and be explicit: 1. Name the Deny barriers for the top level. 2. Name the Deny barrier for nested with `DenyInstructionsWithXcm`. - **DenyThenTry<DenyInstructionsWithXcm<Deny>, Allow>**: Alternatively, hard-code those three instructions in `DenyThenTry`, so we wouldn’t need `DenyInstructionsWithXcm`. However, this approach wouldn’t be as general. - **DenyInstructionsWithXcmFor**: Another possibility is to check `DenyInstructionsWithXcm::Inner` for the actual `message`, so we don’t need duplication for top-level and nested (not sure, maybe be explicit is good thing) - see _Problem2 - example_. Instead of this: ``` DenyThenTry< ( // Deny for top level XCM program DenyReserveTransferToRelayChain, // Dedicated barrier for nested XCM programs DenyInstructionsWithXcmFor< // Repeat all Deny filters here DenyReserveTransferToRelayChain, > ), ``` we could just use: ``` DenyThenTry< ( // Dedicated barrier for XCM programs DenyInstructionsWithXcmFor< // Add all `Deny` filters here DenyReserveTransferToRelayChain, ... > ), ``` - [POC Evaluation](#7200 (comment)) - [x] Consider better name `DenyInstructionsWithXcm` => `DenyRecursively`, more details at [here](#7200 (comment)) - [x] Clean-up and docs - [x] Merge #7169 or rebase this branch on the top of `yrong:fix-for-deny-then-try` - [x] Set for the runtimes where we use `DenyThenTry<Deny, Allow>` => `DenyThenTry<DenyRecursively<Deny>, Allow>` - [ ] Schedule sec.audit --------- Co-authored-by: Raymond Cheung <[email protected]> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: ron <[email protected]> Co-authored-by: Francisco Aguirre <[email protected]> Co-authored-by: Clara van Staden <[email protected]> Co-authored-by: Adrian Catangiu <[email protected]>
github-actions bot
pushed a commit
that referenced
this issue
Mar 3, 2025
…o be executed on the local chain (#7200) Resolves (partially): #7148 Depends on: #7169 # Description This PR addresses partially #7148 (Problem 2) and ensures the proper checking of nested local instructions. It introduces a new barrier - `DenyRecursively` - to provide more refined control over instruction denial. The main change is the replacement of `DenyThenTry<Deny, Allow>` with `DenyThenTry<DenyRecursively<Deny>, Allow>` which handles both top-level and nested local instructions by applying allow condition after denial. For context and additional information, please refer to [_Problem 2 - Barrier vs nested XCM validation_](#7148). # TODO - [x] Evaluate PoC, more details at #7351: - **DenyNestedXcmInstructions**: Keep it as it is and be explicit: 1. Name the Deny barriers for the top level. 2. Name the Deny barrier for nested with `DenyInstructionsWithXcm`. - **DenyThenTry<DenyInstructionsWithXcm<Deny>, Allow>**: Alternatively, hard-code those three instructions in `DenyThenTry`, so we wouldn’t need `DenyInstructionsWithXcm`. However, this approach wouldn’t be as general. - **DenyInstructionsWithXcmFor**: Another possibility is to check `DenyInstructionsWithXcm::Inner` for the actual `message`, so we don’t need duplication for top-level and nested (not sure, maybe be explicit is good thing) - see _Problem2 - example_. Instead of this: ``` DenyThenTry< ( // Deny for top level XCM program DenyReserveTransferToRelayChain, // Dedicated barrier for nested XCM programs DenyInstructionsWithXcmFor< // Repeat all Deny filters here DenyReserveTransferToRelayChain, > ), ``` we could just use: ``` DenyThenTry< ( // Dedicated barrier for XCM programs DenyInstructionsWithXcmFor< // Add all `Deny` filters here DenyReserveTransferToRelayChain, ... > ), ``` - [POC Evaluation](#7200 (comment)) - [x] Consider better name `DenyInstructionsWithXcm` => `DenyRecursively`, more details at [here](#7200 (comment)) - [x] Clean-up and docs - [x] Merge #7169 or rebase this branch on the top of `yrong:fix-for-deny-then-try` - [x] Set for the runtimes where we use `DenyThenTry<Deny, Allow>` => `DenyThenTry<DenyRecursively<Deny>, Allow>` - [ ] Schedule sec.audit --------- Co-authored-by: Raymond Cheung <[email protected]> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: ron <[email protected]> Co-authored-by: Francisco Aguirre <[email protected]> Co-authored-by: Clara van Staden <[email protected]> Co-authored-by: Adrian Catangiu <[email protected]> (cherry picked from commit bd7cf11)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
Imagine we have a barrier like the one below. For example, we want to add new rules:
LockAsset
(no real scenario, just for testing purposes to showcase XCM filtering).ExportMessage
from a particular originxyz
.Actually, we can use
DenyThenTry
e.g.:But this
DenyAndTry
has some problems mentioned below.Problem 1 -
ShouldExecute
tuple implementation andDeny
filter tupleThe tuple implementation for
ShouldExecute
returnsOk(())
immediately when one of the tuple items passesTuple::should_execute()
.Relates to comment.
This is problematic for the
Deny
filter becauseDeny
requires all items in the tuple to be checked. For example, ifDenyCase1
is okay (meaning it does not deny execution), the tuple will returnOk(())
[here](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/xcm/xcm-executor/src/traits/should_execute.rs#L63-L74). However,DenyCase2
andDenyCase3
will be skipped, which is not the desired behavior.Solution
#7169
Problem 2 -
Barrier
vs nested XCM validationInstructions like
SetErrorHandler(xcm)
,SetAppendix(xcm)
, andExecuteWithOrigin { xcm, .. }
are meant to be executed on the local chain, but their innerxcm
is not actually checked against theBarrier
.We do not have specific barriers for these instructions, which means they could potentially bypass the
Barrier
.DenyReserveTransferToRelayChain
is just one example (below). We may encounter different cases in the future. For instance, Snowbridge already has a specific case: #6838.Example:
For example, all our system parachain barriers are structured like this barrier below.
Ok, we can deny the instruction
TransferReserveAsset { dest: Location { parents: 1, interior: Here }, .. }
usingDenyReserveTransferToRelayChain
on the incoming XCM for system parachains. However, nothing prevents us from wrappingTransferReserveAsset { dest: Location { parents: 1, interior: Here }, .. }
withSetAppendix
orExecuteWithOrigin
orSetErrorHandler
.Possible solution - be explicit
Adding new
DenyInstructionsWithXcmFor
barrier which checks nested XCM forSetErrorHandler(xcm)
,SetAppendix(xcm)
, andExecuteWithOrigin { xcm, .. }
instruction.See PoC for
DenyInstructionsWithXcmFor
This will also require #7169 to be fixed/merged.
Solution
#7200
Related another potential problem in
xcm-executor
I think another potential problem could be in the
xcm-executor
, where we recursively triggerself.process(..)
.Barrier
only once duringXcmExecutor::execute(message)
here.let result = vm.process(message);
here.Ok
orErr
), we take the XCM fromSetAppendix
orSetErrorHandler
and again triggerlet result = vm.process(message);
.ExecuteWithOrigin
, where we again triggerself.process(message)
.An easy solution seems to be to trigger
Config::Barrier::should_execute(nested_xcm)
inside or beforeself.process(message)
orvm.process(message)
. However, this won't work because, as seen in the example Barrier above, it would require every nested XCM to containUnpaidExecution
orBuyExecution/PayFees
.Therefore, we may need another Barrier/Filter specifically for nested XCM in the
XcmExecutor
, or we need to adjust the existing Barrier logic.Scenario Test
#7200 should fix this potential issue, please check the scenario test.
The text was updated successfully, but these errors were encountered: