midnight-transactions

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Transactions

交易

The Midnight node supports the standard Polkadot SDK transaction format, but default Substrate-style signed extrinsics are uncommon in practice. Midnight relies on a proof-based verification model tightly coupled with the Midnight Ledger.
Midnight节点支持标准的Polkadot SDK交易格式,但默认Substrate风格的签名外部交易在实际中并不常见。Midnight依赖与Midnight Ledger紧密结合的基于证明的验证模型

Lifecycle overview

生命周期概述

mermaid
flowchart TB
  Build["Build transaction + ZK proof<br/>(wallet / SDK)"]
  Submit["Submit to node RPC / P2P"]
  Pool["Transaction pool<br/>well-formedness check"]
  Block["Included in block"]
  Verify["Runtime verifies embedded proof"]
  Execute["Execute state transition"]
  Commit["Commit to trie + ledger commitment"]

  Build --> Submit --> Pool
  Pool -->|Valid structure| Block
  Pool -->|Reject| Reject["Dropped from pool"]
  Block --> Verify
  Verify -->|Invalid proof| Fail["Transaction fails"]
  Verify -->|Valid| Execute --> Commit

mermaid
flowchart TB
  Build["Build transaction + ZK proof<br/>(wallet / SDK)"]
  Submit["Submit to node RPC / P2P"]
  Pool["Transaction pool<br/>well-formedness check"]
  Block["Included in block"]
  Verify["Runtime verifies embedded proof"]
  Execute["Execute state transition"]
  Commit["Commit to trie + ledger commitment"]

  Build --> Submit --> Pool
  Pool -->|Valid structure| Block
  Pool -->|Reject| Reject["Dropped from pool"]
  Block --> Verify
  Verify -->|Invalid proof| Fail["Transaction fails"]
  Verify -->|Valid| Execute --> Commit

Proof-based model

基于证明的模型

Most Midnight transactions are unsigned and follow the Midnight Ledger format.
Traditional chainMidnight
Signature authorizes actionCryptographic proof attests validity
Public signer identitySensitive data stays off-chain / in proof
Standard extrinsic formatLedger-specific transaction envelope
The proof lets the network validate state transitions without exposing sensitive data or raw signatures directly.
大多数Midnight交易是无签名的,且遵循Midnight Ledger格式。
传统区块链Midnight
签名授权操作密码学证明证明有效性
公开签名者身份敏感数据保留在链下/证明中
标准外部交易格式账本专属交易信封
该证明允许网络在直接暴露敏感数据或原始签名的情况下验证状态转换。

Transaction types

交易类型

  • Contract deployment
  • Contract invocation (circuit calls)
  • ZSwap asset transfers

  • 合约部署
  • 合约调用(电路调用)
  • ZSwap资产转移

Processing stages

处理阶段

1. Submission

1. 提交

Client (wallet, SDK, dApp) submits a transaction to a node's RPC or propagates via P2P gossip.
客户端(钱包、SDK、去中心化应用)将交易提交至节点的RPC,或通过P2P gossip传播。

2. Transaction pool validation

2. 交易池验证

The pool checks well-formedness:
  • Structural requirements per runtime and ledger specification
  • Logical preconditions (format, size, basic validity)
  • Not full proof verification yet (that happens at block execution)
mermaid
sequenceDiagram
  participant Client
  participant Pool as Tx pool
  participant Block as Block author
  participant RT as Runtime (pallet-midnight)

  Client->>Pool: Submit unsigned proof tx
  Pool->>Pool: Well-formedness validation
  alt Invalid
    Pool-->>Client: Reject
  else Valid
    Pool->>Block: Candidate for inclusion
    Block->>RT: Execute in block
    RT->>RT: Full proof verification
    RT->>RT: State transition + commit
  end
交易池检查格式合规性
  • 符合运行时和账本规范的结构要求
  • 逻辑前置条件(格式、大小、基本有效性)
  • 尚未进行完整的证明验证(该步骤在区块执行时进行)
mermaid
sequenceDiagram
  participant Client
  participant Pool as Tx pool
  participant Block as Block author
  participant RT as Runtime (pallet-midnight)

  Client->>Pool: Submit unsigned proof tx
  Pool->>Pool: Well-formedness validation
  alt Invalid
    Pool-->>Client: Reject
  else Valid
    Pool->>Block: Candidate for inclusion
    Block->>RT: Execute in block
    RT->>RT: Full proof verification
    RT->>RT: State transition + commit
  end

3. Block inclusion

3. 区块纳入

A block producer (AURA validator) includes the transaction in a new block.
区块生产者(AURA验证者)将交易纳入新区块。

4. Runtime verification and execution

4. 运行时验证与执行

pallet-midnight
:
  1. Fully verifies the embedded cryptographic proof (native libraries).
  2. If valid, executes the corresponding state transition.
  3. Commits the updated state to on-chain storage.
pallet-midnight
:
  1. 完整验证嵌入的密码学证明(原生库)。
  2. 若证明有效,则执行对应的状态转换。
  3. 将更新后的状态提交至链上存储。

5. Finality

5. 最终性

Block may be finalized asynchronously via GRANDPA after inclusion.

区块纳入后,可通过GRANDPA异步完成最终确认

Comparison: pool vs runtime checks

对比:交易池与运行时检查

CheckWhereWhat
Well-formednessTransaction poolStructure, basic validity
Proof verificationRuntime (
pallet-midnight
)
Full cryptographic validation
State transitionRuntimeZSwap / contract state update
PersistenceStorage layerTrie + ledger commitment

检查项执行位置检查内容
格式合规性交易池结构、基本有效性
证明验证运行时(
pallet-midnight
完整密码学验证
状态转换运行时ZSwap / 合约状态更新
持久化存储层前缀树 + 账本提交

Building and submitting txs (dApp context)

构建与提交交易(去中心化应用场景)

For application developers:
LayerSkill
Prove + submit txs
midnight-js/
,
1am-wallet/
Contract logic
compact/
Read results
midnight-indexer/
,
midnight-rpc/
Node operators care about pool sizing, block limits, and RPC submission endpoints.

面向应用开发者:
层级技能组件
生成证明 + 提交交易
midnight-js/
,
1am-wallet/
合约逻辑
compact/
读取结果
midnight-indexer/
,
midnight-rpc/
节点运营商关注交易池规模、区块限制以及RPC提交端点。

Related skills

相关技能组件

  • midnight-onchain-logic/
    pallet-midnight
    execution
  • midnight-storage/
    — how commits are persisted
  • midnight-consensus/
    — who includes txs in blocks
  • midnight-rpc/
    — submission and state query endpoints
  • compact/
    — what proofs attest to at the contract level
  • midnight-onchain-logic/
    pallet-midnight
    执行逻辑
  • midnight-storage/
    — 提交内容的持久化方式
  • midnight-consensus/
    — 负责将交易纳入区块的角色
  • midnight-rpc/
    — 提交与状态查询端点
  • compact/
    — 证明在合约层面所验证的内容