Skip to content

Comments

Add Paras authorize_code_hash + apply_authorized_code feature#7592

Merged
acatangiu merged 77 commits intomasterfrom
bko-paras-authorize-set-current-code
May 29, 2025
Merged

Add Paras authorize_code_hash + apply_authorized_code feature#7592
acatangiu merged 77 commits intomasterfrom
bko-paras-authorize-set-current-code

Conversation

@bkontur
Copy link
Contributor

@bkontur bkontur commented Feb 17, 2025

Closes: #7574
Relates to: #7591

Motivation

This feature is useful when triggering a Paras pallet call from a different chain than the one where the Paras pallet is deployed. For example, we may want to send Paras::force_set_current_code(para, code) from the Collectives and/or AssetHub to the relay chain (because the relaychain governance will be migrated to the AssetHub as a part of AHM).

The primary reason for this approach is to avoid transferring the entire new_code Wasm blob between chains. Instead, we authorize the code_hash using root via fn authorize_force_set_current_code_hash(new_authorization, expire_at). This authorization can later be applied by anyone using Paras::apply_authorized_force_set_current_code(para, new_code). If expire_at is reached without the authorization being used, it is automatically removed.

Usage

This feature is intended for use in two scenarios:

TODO

Open questions

  • Do we need something like poke_authorized_code_hash? E.g. in case that we authorize code hash, but nobody would apply it and the parachain starts working with old/other_new code? Is this possible?
  • Do we need something similar for frame_system pallet and set_code / set_code_without_checks?
  • Can we achieve the same with pallet-whitelist?
  • Do we have other extrinsics over chains which has code attribute?
  • Do we need to add validate_unsigned for apply_authorized_code?

@bkontur
Copy link
Contributor Author

bkontur commented Feb 17, 2025

/cmd fmt

@bkontur bkontur added T14-system_parachains This PR/Issue is related to system parachains. A4-needs-backport labels Feb 17, 2025
@bkontur
Copy link
Contributor Author

bkontur commented Feb 17, 2025

/cmd prdoc --audience runtime_dev --bump patch

@bkontur
Copy link
Contributor Author

bkontur commented Feb 17, 2025

/cmd bench --pallet polkadot_runtime_parachains::paras --runtime westend rococo

@github-actions
Copy link
Contributor

Command "bench --pallet polkadot_runtime_parachains::paras --runtime westend rococo" has started 🚀 See logs here

@github-actions
Copy link
Contributor

Command "bench --pallet polkadot_runtime_parachains::paras --runtime westend rococo" has finished ✅ See logs here

Details

Subweight results:
File Extrinsic Old New Change [%]
cumulus/pallets/collator-selection/src/weights.rs leave_intent - - ERROR
cumulus/pallets/collator-selection/src/weights.rs new_session - - ERROR
cumulus/pallets/collator-selection/src/weights.rs register_as_candidate - - ERROR
cumulus/pallets/collator-selection/src/weights.rs set_invulnerables - - ERROR
cumulus/pallets/collator-selection/src/weights.rs take_candidate_slot - - ERROR
cumulus/pallets/collator-selection/src/weights.rs update_bond - - ERROR
cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_preimage.rs ensure_updated - - ERROR
cumulus/parachains/runtimes/people/people-rococo/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/people/people-rococo/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/people/people-westend/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/people/people-westend/src/weights/pallet_collator_selection.rs update_bond - - ERROR
polkadot/runtime/rococo/src/weights/polkadot_runtime_parachains_paras.rs add_trusted_validation_code - - ERROR
polkadot/runtime/rococo/src/weights/polkadot_runtime_parachains_paras.rs force_note_new_head - - ERROR
polkadot/runtime/rococo/src/weights/polkadot_runtime_parachains_paras.rs force_schedule_code_upgrade - - ERROR
polkadot/runtime/rococo/src/weights/polkadot_runtime_parachains_paras.rs force_set_current_code - - ERROR
polkadot/runtime/rococo/src/weights/polkadot_runtime_parachains_paras.rs force_set_current_head - - ERROR
polkadot/runtime/westend/src/weights/pallet_preimage.rs ensure_updated - - ERROR
polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_paras.rs add_trusted_validation_code - - ERROR
polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_paras.rs force_note_new_head - - ERROR
polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_paras.rs force_schedule_code_upgrade - - ERROR
polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_paras.rs force_set_current_code - - ERROR
polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_paras.rs force_set_current_head - - ERROR
substrate/frame/election-provider-support/src/weights.rs phragmen - - ERROR
substrate/frame/election-provider-support/src/weights.rs phragmms - - ERROR
polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_paras.rs force_set_most_recent_context 110.16us 103.91us -5.67
polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_paras.rs include_pvf_check_statement_finalize_onboarding_accept 1.21ms 1.03ms -14.87
polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_paras.rs authorize_force_set_current_code_hash 137.18us Added
polkadot/runtime/westend/src/weights/polkadot_runtime_parachains_paras.rs apply_authorized_force_set_current_code 40.31ms Added
polkadot/runtime/rococo/src/weights/polkadot_runtime_parachains_paras.rs authorize_force_set_current_code_hash 137.30us Added
polkadot/runtime/rococo/src/weights/polkadot_runtime_parachains_paras.rs apply_authorized_force_set_current_code 38.43ms Added
Command output:

✅ Successful benchmarks of runtimes/pallets:
-- westend: ['polkadot_runtime_parachains::paras']
-- rococo: ['polkadot_runtime_parachains::paras']

bkontur and others added 3 commits February 18, 2025 10:27
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Bastian Köcher <git@kchr.de>
@bkontur
Copy link
Contributor Author

bkontur commented Feb 18, 2025

/cmd fmt

@bkontur bkontur requested a review from bkchr February 18, 2025 10:05
@bkontur bkontur self-assigned this Feb 18, 2025
@paritytech-workflow-stopper
Copy link

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

let code = ValidationCode(vec![0; c as usize]);
let para_id = ParaId::from(1000);
let expire_at =
frame_system::Pallet::<T>::block_number().saturating_add(BlockNumberFor::<T>::from(c));
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems strange to also use the code size as the expiry time. If we expect this to affect the benchmark, it should be its own parameter, if not should we not just set it to something constant?

);
for para in to_remove {
AuthorizedCodeHash::<T>::remove(&para);
weight.saturating_accrue(T::DbWeight::get().writes(1));
Copy link
Contributor

Choose a reason for hiding this comment

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

Yea I believe @kianenigma looked into this quite a bit for benchmarking MB staking when there were a lot of removals and ended up using a measured weight IIRC

@acatangiu acatangiu added this pull request to the merge queue May 29, 2025
@acatangiu acatangiu moved this to To be released (SDK) in fellowship/runtimes integrations queue May 29, 2025
Merged via the queue into master with commit d6b9159 May 29, 2025
245 checks passed
@acatangiu acatangiu deleted the bko-paras-authorize-set-current-code branch May 29, 2025 11:13
@github-project-automation github-project-automation bot moved this from In review to Done in Plaza: AHM May 29, 2025
@bkontur bkontur moved this from In Progress to Done in @bkontur's board May 29, 2025
@miss-stake miss-stake moved this from Backlog to Scheduled in Security Audit (PRs) - SRLabs Jun 3, 2025
pgherveou pushed a commit that referenced this pull request Jun 11, 2025
…7592)

Closes: #7574
Relates to: #7591

## Motivation

This feature is useful when triggering a `Paras` pallet call from a
different chain than the one where the `Paras` pallet is deployed. For
example, we may want to send `Paras::force_set_current_code(para, code)`
from the Collectives and/or AssetHub to the relay chain (because the
relaychain governance will be migrated to the AssetHub as a part of
AHM).

The primary reason for this approach is to avoid transferring the entire
`new_code` Wasm blob between chains. Instead, we authorize the
`code_hash` using `root` via `fn
authorize_force_set_current_code_hash(new_authorization, expire_at)`.
This authorization can later be applied by anyone using
`Paras::apply_authorized_force_set_current_code(para, new_code)`. If
`expire_at` is reached without the authorization being used, it is
automatically removed.

## Usage

This feature is intended for use in two scenarios:

- The D-Day scenario, where we can restart AssetHub from Collectives —
see the PoC: #8141
- Using `force_set_current_code` for any parachain from migrated
governance to AssetHub (AHM)

## TODO
- [x] ~cover also `add_trusted_validation_code` or
`force_schedule_code_upgrade` - see comment bellow:
#7592 (comment)
no see other
[comment](#7592 (comment))


## Open questions

- [ ] ~Do we need something like `poke_authorized_code_hash`? E.g. in
case that we authorize code hash, but nobody would apply it and the
parachain starts working with old/other_new code? Is this possible?~
- [ ] Do we need something similar for `frame_system` pallet and
`set_code` / `set_code_without_checks`?
- [ ] Can we achieve the same with `pallet-whitelist`?
- [ ] Do we have other extrinsics over chains which has `code`
attribute?
- [x] Do we need to add `validate_unsigned` for `apply_authorized_code`?

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Adrian Catangiu <adrian@parity.io>
@redzsina redzsina moved this from Scheduled to In progress in Security Audit (PRs) - SRLabs Jun 30, 2025
@redzsina redzsina moved this from In progress to Scheduled in Security Audit (PRs) - SRLabs Jul 1, 2025
fellowship-merge-bot bot pushed a commit to polkadot-fellows/runtimes that referenced this pull request Aug 7, 2025
This brings in `stable2506` Polkadot SDK, and integrates many new
features.

Integrated breaking changes to be verified by the original authors:

- [x] ~paritytech/polkadot-sdk#8127 @kianenigma
@Ank4n~
     This will come in with AHM, and not before.
- [x] paritytech/polkadot-sdk#7597 @gui1117 
- [x] paritytech/polkadot-sdk#8254 @bkchr 
- [x] paritytech/polkadot-sdk#7592 @bkontur 
- [x] paritytech/polkadot-sdk#8382
@UtkarshBhardwaj007
- [x] paritytech/polkadot-sdk#8021 @serban300 
- [x] paritytech/polkadot-sdk#8344 @serban300 
- [x] paritytech/polkadot-sdk#8262 @athei 
- [x] paritytech/polkadot-sdk#8584 @athei 
- [x] paritytech/polkadot-sdk#8299 @skunert
- [x] paritytech/polkadot-sdk#8652 @pgherveou 
- [x] paritytech/polkadot-sdk#8554 @pgherveou 
- [x] paritytech/polkadot-sdk#8281 @mrshiposha 
- [x] paritytech/polkadot-sdk#7730
@franciscoaguirre
- [x] paritytech/polkadot-sdk#8599 @yrong
@claravanstaden
- [x] paritytech/polkadot-sdk#8531 @bkontur 
- [x] paritytech/polkadot-sdk#8409 @kianenigma 
- [x] paritytech/polkadot-sdk#9137
@franciscoaguirre
- [x] paritytech/polkadot-sdk#7944 @bkontur 
- [x] paritytech/polkadot-sdk#8179 @bkontur 
- [x] paritytech/polkadot-sdk#8037 @yrong

---------

Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: claravanstaden <claravanstaden64@gmail.com>
Co-authored-by: Branislav Kontur <bkontur@gmail.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Alain Brenzikofer <alain@integritee.network>
Co-authored-by: kianenigma <kian@parity.io>
Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
Co-authored-by: ron <yrong1997@gmail.com>
Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
Co-authored-by: Overkillus <maciej.zyszkiewicz@parity.io>
@redzsina redzsina moved this from Scheduled to Waiting for fix in Security Audit (PRs) - SRLabs Aug 12, 2025
@redzsina redzsina moved this from Waiting for fix to Audited in Security Audit (PRs) - SRLabs Aug 26, 2025
alvicsam pushed a commit that referenced this pull request Oct 17, 2025
…7592)

Closes: #7574
Relates to: #7591

## Motivation

This feature is useful when triggering a `Paras` pallet call from a
different chain than the one where the `Paras` pallet is deployed. For
example, we may want to send `Paras::force_set_current_code(para, code)`
from the Collectives and/or AssetHub to the relay chain (because the
relaychain governance will be migrated to the AssetHub as a part of
AHM).

The primary reason for this approach is to avoid transferring the entire
`new_code` Wasm blob between chains. Instead, we authorize the
`code_hash` using `root` via `fn
authorize_force_set_current_code_hash(new_authorization, expire_at)`.
This authorization can later be applied by anyone using
`Paras::apply_authorized_force_set_current_code(para, new_code)`. If
`expire_at` is reached without the authorization being used, it is
automatically removed.

## Usage

This feature is intended for use in two scenarios:

- The D-Day scenario, where we can restart AssetHub from Collectives —
see the PoC: #8141
- Using `force_set_current_code` for any parachain from migrated
governance to AssetHub (AHM)

## TODO
- [x] ~cover also `add_trusted_validation_code` or
`force_schedule_code_upgrade` - see comment bellow:
#7592 (comment)
no see other
[comment](#7592 (comment))


## Open questions

- [ ] ~Do we need something like `poke_authorized_code_hash`? E.g. in
case that we authorize code hash, but nobody would apply it and the
parachain starts working with old/other_new code? Is this possible?~
- [ ] Do we need something similar for `frame_system` pallet and
`set_code` / `set_code_without_checks`?
- [ ] Can we achieve the same with `pallet-whitelist`?
- [ ] Do we have other extrinsics over chains which has `code`
attribute?
- [x] Do we need to add `validate_unsigned` for `apply_authorized_code`?

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Adrian Catangiu <adrian@parity.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T14-system_parachains This PR/Issue is related to system parachains.

Projects

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

Development

Successfully merging this pull request may close these issues.

paras pallet - add new extrinsincs for authorize/apply set_current_code

7 participants