Skip to content

Rework shielded transactions#2415

Open
l0r1s wants to merge 45 commits intomainfrom
mev-block-builder
Open

Rework shielded transactions#2415
l0r1s wants to merge 45 commits intomainfrom
mev-block-builder

Conversation

@l0r1s
Copy link
Collaborator

@l0r1s l0r1s commented Feb 10, 2026

Summary

Companion PR to the opentensor/polkadot-sdk#6

Update MEV shield on subtensor — a system that encrypts transactions client-side so their contents
are hidden from the mempool, preventing front-running and sandwich attacks. Block authors decrypt
shielded transactions at block building time using ML-KEM-768 + XChaCha20-Poly1305.

Changes

pallet-shield

  • announce_next_key inherent: rotates CurrentKey ← NextKey each block and publishes the
    upcoming block author's ML-KEM public key so users can encrypt for them
  • submit_encrypted extrinsic: accepts an encrypted ciphertext wrapper from users
  • try_decode_shielded_tx / try_unshield_tx: runtime helpers called by the block
    proposer (via the ShieldApi runtime API) to detect, decrypt, and decode shielded transactions
  • CheckShieldedTxValidity transaction extension: validates key_hash against
    CurrentKey/NextKey during block import; pool validation only checks ciphertext structure to
    avoid spurious rejections from stale views
  • FindAuthors trait for resolving current and next block author

stp-io (new crate — host functions)

  • mlkem768_decapsulate: ML-KEM-768 decapsulation via the ShieldKeystore extension
  • aead_decrypt: XChaCha20-Poly1305 decryption via the ShieldKeystore extension
  • Exported as SubtensorHostFunctions for registration in the node

Node integration

  • ShieldKeystore is created in service.rs and threaded through to the proposer and inherent
    providers
  • ShieldInherentDataProvider added to Aura and Babe consensus configurations
  • KeyRotationService generates a new ML-KEM keypair on each own-block import
  • SubtensorHostFunctions registered in the client executor

Runtime integration

  • ShieldApi runtime API implemented (try_decode_shielded_tx, try_unshield_tx)
  • CheckShieldedTxValidity added to the transaction extension pipeline

Tests

  • pallet-shield: key rotation, try_decode_shielded_tx, try_unshield_tx, depth-limit
    protection, inherent creation
  • CheckShieldedTxValidity extension: key_hash matching against CurrentKey/NextKey, malformed
    ciphertext rejection, pool vs in-block source behavior

@github-actions github-actions bot added the hotfix This PR needs to be merged very quickly and will likely skip testing on devnet and testnet label Feb 10, 2026
@github-actions
Copy link
Contributor

🚨🚨🚨 HOTFIX DETECTED 🚨🚨🚨

It looks like you are trying to merge a hotfix PR into main. If this isn't what you wanted to do, and you just wanted to make a regular PR, please close this PR, base your changes off the devnet-ready branch and open a new PR into devnet ready.

If you are trying to merge a hotfix PR, please complete the following essential steps:

  1. go ahead and get this PR into main merged, so we can get the change in as quickly as possible!
  2. merge main into testnet, bumping spec_version
  3. deploy testnet
  4. merge testnet into devnet, bumping spec_version
  5. deploy devnet
  6. merge devnet into devnet-ready

If you do not complete these steps, your hotfix may be inadvertently removed in the future when branches are promoted to main, so it is essential that you do so.

@l0r1s l0r1s changed the title Refactor of the MEV shield Rework shielded transactions Feb 14, 2026
@l0r1s l0r1s marked this pull request as ready for review February 14, 2026 04:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotfix This PR needs to be merged very quickly and will likely skip testing on devnet and testnet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant