Back to Browse

Use with your AI agent

  1. Install — run npx skills add Kali-Decoder/Midnight-skills --skill midnight-onchain-logic for this skill, or npx skills add Kali-Decoder/Midnight-skills for all
  2. Prompt — copy the example prompt and paste it into Cursor, Claude Code, or Codex
  3. Build — the agent loads this skill and scaffolds your Midnight work

Onchain Logic and State

FoundationAdvancedReviewedUnchanged since v1.0.7v1.0.0

Agent picks this when: Explain Midnight on-chain logic — runtime, pallets, and pallet-midnight

WASM runtime, FRAME pallets, pallet-midnight ledger state machine, and proof-based state transitions.

Good for

  • Polkadot SDK WASM runtime with FRAME pallets including pallet-midnight.
  • Proof verification, ZSwap and contract ops, Patricia-Merkle state commitments.

Preview in agent

Suggested prompts

Explain Midnight on-chain logic — runtime, pallets, and pallet-midnight. Use the "midnight-onchain-logic" skill from MIDSKILLS. Follow Compact smart-contract best practices, wire wallet flows where needed, and explain each step as you implement. Target Midnight Preprod unless I specify otherwise.

Loaded skill midnight-onchain-logic

What the skill guides the agent to do:

  1. Polkadot SDK WASM runtime with FRAME pallets including pallet-midnight.
  2. Proof verification, ZSwap and contract ops, Patricia-Merkle state commitments.

Illustrative — based on the skill's description, not recorded agent output.

Try it without installing: npx skills use Kali-Decoder/Midnight-skills@midnight-onchain-logic

What changed in v1.0.16

All registry changes

No changes in v1.0.16 or the releases before it that we track.

On this page · 9 sections
SKILL.md

Onchain Logic and State

The Midnight node follows the standard Polkadot SDK model: core logic (except native pre-compiles) compiles to WebAssembly (WASM) and forms the runtime — the state transition function executed identically on every node.

Runtime architecture

flowchart TB
  subgraph Runtime["WASM Runtime"]
    direction TB
    PA["pallet-aura"]
    PG["pallet-grandpa"]
    PS["pallet-partnerchains-session"]
    PVM["pallet_session_validator_management"]
    PM["pallet-midnight ★"]
    Other["Other FRAME pallets"]
  end

  Block["Incoming block + extrinsics"] --> Runtime
  Runtime --> Trie["Patricia-Merkle trie commit"]
  Trie --> DB["ParityDB persistence"]
  PM --> Ledger["Midnight Ledger state commitment"]

FRAME pallets

Each FRAME pallet encapsulates a domain of on-chain logic and may define:

  • Storage (maps, multi-maps, lists, values)
  • Events
  • Dispatchable functions (transactions)
  • Offchain workers
  • Hooks
  • Host-exposed functions
  • RPC methods

This modular design is similar in spirit to a smart contract framework, but logic is compiled ahead of time and governed at the chain level.


Key pallets on Midnight

PalletRole
pallet-auraBlock production via AURA
pallet-grandpaFinality via GRANDPA
pallet-partnerchains-sessionSession rotation in Partnerchain context
pallet_session_validator_managementValidator set coordination
pallet-midnightCore privacy-preserving transaction logic

pallet-midnight: the ledger state machine

pallet-midnight is internally maintained and encapsulates the Midnight Ledger state machine.

sequenceDiagram
  participant Tx as Ledger transaction
  participant Pool as Transaction pool
  participant PM as pallet-midnight
  participant Lib as Native proof libraries
  participant State as On-chain storage

  Tx->>Pool: Submit (unsigned, proof-embedded)
  Pool->>Pool: Well-formedness check
  Pool->>PM: Included in block
  PM->>Lib: Verify cryptographic proof
  Lib-->>PM: Valid / invalid
  PM->>State: Execute state transition
  State->>State: Commit trie + ledger commitment

What it processes

  • ZSwap asset transfers
  • Contract operations (deploy, invoke)
  • Specialized transactions from the Midnight Ledger format

Validation model

  • Not traditional signature-based dispatch for ledger txs.
  • Each transaction embeds a cryptographic proof attesting validity.
  • Native libraries verify proofs and execute corresponding state transitions.

State commitment

After execution:

  1. New state is committed on-chain.
  2. Canonical ledger state lives in a Patricia-Merkle trie backed by a key-value database.
  3. A commitment to the full Midnight Ledger state is persisted per block — tamper-proof and verifiable.

Public vs ledger state

State typeWhereVisibility
Substrate runtime storagePatricia-Merkle trieStandard on-chain queries
Midnight Ledger commitmentPersisted per blockVerifiable snapshot of ledger
Contract ledger fieldsVia disclose() in CompactSelectively public per contract design

For application-level privacy patterns, see why-midnight/ and compact/.


  • midnight-consensus/ — AURA + GRANDPA pallets
  • midnight-transactions/ — transaction pool → runtime → commit lifecycle
  • midnight-storage/ — ParityDB + trie details
  • midnight-rpc/ — querying contract and ledger state via RPC

Start in 2 steps

  1. 1. Install — one skill or the full set
  2. 2. Prompt — paste the example into your agent

Install all skills (recommended)

npx skills add Kali-Decoder/Midnight-skills

One command adds every Midnight skill to Cursor, Claude Code, and similar agents.

Install this skill only

npx skills add Kali-Decoder/Midnight-skills --skill midnight-onchain-logic

Installs only "midnight-onchain-logic" into every detected agent (Cursor, Claude Code, Codex, …).

Example agent prompt

Explain Midnight on-chain logic — runtime, pallets, and pallet-midnight. Use the "midnight-onchain-logic" skill from MIDSKILLS. Follow Compact smart-contract best practices, wire wallet flows where needed, and explain each step as you implement. Target Midnight Preprod unless I specify otherwise.

Paste into Cursor, Claude Code, or Codex after installing.

Author
Kali-Decoder
Category
Foundation
Difficulty
advanced
Version
v1.0.0

Tags

RuntimeFRAMEpallet-midnightWASM

Files included

SKILL.md
Create Social CardLive HackathonsGallery
Mock Demo
Onchain Logic and State