Shielded transactions support in block proposer (with crypto in WASM)#10
Merged
sam0x17 merged 17 commits intopolkadot-stable2506-2-otf-patchesfrom Mar 2, 2026
Conversation
sam0x17
approved these changes
Mar 2, 2026
6a3ec6d
into
polkadot-stable2506-2-otf-patches
134 of 227 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Companion PR to opentensor/subtensor#2477 - supersedes #6
Adds MEV shield support to Substrate: shielded (encrypted) transaction handling in the block
proposer, along with the shared primitive and client crates (
stp-shield,stc-shield) that weremoved here from subtensor to avoid a circular dependency between the two repos.
Users encrypt their extrinsics using ML-KEM-768 + XChaCha20-Poly1305 against the next block
author's public key. At block building time, the proposer passes the decapsulation key to the
runtime, which decrypts each shielded transaction entirely in WASM. Both the wrapper and the inner
extrinsic are then included in the block, keeping transaction contents hidden from the mempool.
Changes
stp-shield(new subtensor primitives crate)Shared types used by both the runtime and the node side:
ShieldedTransactionstruct and wire-format parsingShieldKeystoretrait (simplified to key management only:roll_for_next_slot,next_enc_key,current_dec_key)ShieldApiruntime API definition (try_decode_shielded_tx,try_unshield_tx)ShieldPublicKeytype, logging targetstc-shield(new subtensor client crate)Node-side shield logic:
MemoryShieldKeystore— in-memory ML-KEM keystore implementation (key generation and storageonly; no crypto operations — those now run in WASM)
InherentDataProvider— provides the next encapsulation (public) key as an inherentspawn_key_rotation_on_own_import— rotates ML-KEM keypairs when the validator imports its ownblock
sc-basic-authorship(block proposer)ProposerFactory/Proposeraccept aShieldKeystorePtrfor key accessShieldApiruntime callruntime's
try_unshield_tx, which performs ML-KEM-768 decapsulation and XChaCha20-Poly1305 AEADdecryption entirely in WASM
SUBSTRATE_SKIP_SHIELDED_TXS=1— skipped transactions stay in thepool for gossip to other authors
report_exhausted_resourceshelper shared between normal and unshielded tx pathssp-runtime(minor)fn call()to theApplyabletrait (needed to inspect the call after signature check)pallet-aura(minor)current_slot_from_digestspublic for shield key rotationsubstrate-test-runtimeShieldApiusing storage keys (Wasm-compatible) for proposer testsArchitecture
All cryptographic operations (ML-KEM-768 decapsulation, XChaCha20-Poly1305 decryption) run
entirely in WASM — no BLS12-381-style host function imports are needed. The node side is
responsible only for key generation, storage, and rotation; the raw decapsulation key bytes are
passed to the runtime API as a parameter.
stc-shield)MemoryShieldKeystorewith ML-KEM-768CurrentKey/NextKeytry_decode_shielded_txparses wrappertry_unshield_tx— pureml-kemcratetry_unshield_tx— purechacha20poly1305crateTests