跳至主要內容
高級

Penalty Transactions 懲罰交易

了解懲罰交易如何保護閃電網路通道免受欺詐,當一方廣播舊狀態時沒收其全部資金。

15 分鐘

什麼是懲罰交易?

懲罰交易(Penalty Transaction,也稱為 Justice Transaction 或 Breach Remedy Transaction) 是閃電網路的核心安全機制。當通道一方試圖通過廣播舊的承諾交易來欺詐時, 受害方可以使用懲罰交易沒收作弊者在通道中的全部資金。

威懾機制: 懲罰交易的存在使得作弊成為「全輸」的行為。理性的參與者不會冒著失去所有資金的風險 去嘗試廣播舊狀態,這就是閃電網路無需信任的安全基礎。

欺詐場景

Fraud Attempt Example:

Channel History:
State #0: Alice 1.0 BTC, Bob 0 BTC      (channel open)
State #1: Alice 0.8 BTC, Bob 0.2 BTC    (Alice pays Bob)
State #2: Alice 0.5 BTC, Bob 0.5 BTC    (Alice pays 0.3 more)
State #3: Alice 0.3 BTC, Bob 0.7 BTC    (current state)

Alice attempts to cheat:
• Alice broadcasts State #1 commitment tx
• Trying to get 0.8 BTC instead of current 0.3 BTC

Result:
• Bob detects old state
• Bob uses penalty tx to seize all of Alice's funds
• Alice loses entire 1.0 BTC channel capacity!

Lesson:
• Alice tried to gain 0.5 BTC (0.8 - 0.3)
• Alice instead loses all 1.0 BTC
• Expected return of cheating is negative!

撤銷密鑰機制

How Revocation Keys Work:

On each state update:
1. Both parties create new commitment tx
2. Both parties exchange revocation keys for old state
3. Old state is "revoked", new state becomes valid

Revocation Key Generation (simplified):
Each party has:
• revocation_basepoint
• per_commitment_point

revocation_pubkey = f(revocation_basepoint,
                      per_commitment_point)

Only knowing the corresponding private key allows spending the revocation output

Key Exchange Flow (State N -> State N+1):

Alice                           Bob
  |                              |
  |---- commit_sig (N+1) ------->|
  |                              |
  |<--- revoke_and_ack (N) ------|  Bob revokes State N
  |                              |
  |<--- commit_sig (N+1) --------|
  |                              |
  |---- revoke_and_ack (N) ----->|  Alice revokes State N
  |                              |

After this, broadcasting State N can be penalized

懲罰交易結構

Commitment tx to_local output script:

OP_IF
    <revocationpubkey>
OP_ELSE
    <to_self_delay>
    OP_CHECKSEQUENCEVERIFY
    OP_DROP
    <local_delayedpubkey>
OP_ENDIF
OP_CHECKSIG

Explanation:
• Path 1 (IF): Holder of revocation key can spend immediately
• Path 2 (ELSE): Owner must wait to_self_delay blocks

Penalty Transaction Construction:

After Alice broadcasts old commitment tx...

Old commitment tx outputs:
• to_local_alice (delayed)
• to_remote_bob (Bob can spend directly)
• HTLCs (if any)

Bob's penalty transaction:

Inputs:
  to_local_alice (using revocation key, no wait needed)

Outputs:
  Bob's address (minus fees)

Witness:
  <signature> <revocation_privkey> 1

時間窗口競賽

Penalty Time Window:

to_self_delay parameter (e.g., 144 blocks ~ 1 day)

Timeline:
T0: Alice broadcasts old commitment tx
    |
    | Block confirmation
    v
T1: Commitment tx confirmed
    |
    | to_self_delay begins
    | (Bob has 144 blocks to execute penalty)
    |
    +-- Bob online: detects fraud, broadcasts penalty tx
    |   Result: Bob gets all of Alice's funds
    |
    |   OR
    |
    +-- Bob offline: but Watchtower monitoring
    |   Result: Watchtower broadcasts penalty tx
    |
    |   OR
    |
    +-- T1 + 144 blocks: delay ends
        Result: Alice can spend to_local output
                (If Bob doesn't respond, Alice succeeds)

Key Points:
• Victim must respond within delay period
• Longer delay = more secure but slower channel close
• Common settings: 144-2016 blocks (1 day to 2 weeks)

懲罰 HTLC

HTLC outputs can also be penalized:

HTLC output script in old commitment tx (simplified):

Offered HTLC (from Alice):
OP_IF
    # Revocation path
    <revocationpubkey>
OP_ELSE
    OP_IF
        # Success path (Bob provides preimage)
        <remote_htlcpubkey>
        OP_CHECKSIGVERIFY
        OP_HASH160 <payment_hash> OP_EQUALVERIFY
    OP_ELSE
        # Timeout path (Alice reclaims)
        <to_self_delay> OP_CSV OP_DROP
        <local_htlcpubkey>
    OP_ENDIF
OP_ENDIF
OP_CHECKSIG

All outputs from old commitment tx have revocation paths:

• to_local        -> can be penalized
• Offered HTLCs   -> can be penalized
• Received HTLCs  -> can be penalized
• to_remote       -> owned by Bob directly, no penalty needed

Bob needs to create multiple penalty transactions:
• Penalize to_local
• Penalize each Offered HTLC
• Penalize each Received HTLC (second-stage tx)

Watchtower 角色

為什麼需要 Watchtower

用戶不可能 24/7 在線監控。Watchtower 代為監控區塊鏈, 發現欺詐時自動廣播預簽的懲罰交易。

Watchtower 數據

Watchtower 只存儲加密的懲罰交易和觸發器(txid 的哈希)。 只有當舊承諾交易出現在鏈上時才能解密並廣播。

Watchtower Workflow:

Setup Phase:
1. User creates penalty tx for each old state
2. Encrypt penalty tx:
   encrypted_blob = encrypt(penalty_tx, breach_txid[:16])
3. Send to Watchtower:
   (breach_hint, encrypted_blob)
   breach_hint = sha256(breach_txid)[:16]

Monitoring Phase:
Watchtower monitors each new block:
for each tx in block:
    hint = sha256(tx.txid)[:16]
    if hint in stored_hints:
        # Potential fraud detected!
        key = tx.txid[:16]
        penalty_tx = decrypt(stored_blob, key)
        broadcast(penalty_tx)

Privacy Protection:
• Watchtower doesn't know user identity
• Watchtower doesn't know channel details
• Can only decrypt when fraud occurs
• Even if Watchtower is compromised, no info is leaked

懲罰交易費用

Penalty Transaction Fee Considerations:

Problem: Pre-signed penalty tx fee rate may become outdated

Case 1: Fee rate too low
• Penalty tx may not confirm in time
• Cheater may win the time race
• Funds could be lost!

Case 2: Fee rate too high
• Deducts too much from penalty amount
• Small channels may not be worth penalizing
• Economically inefficient

Solutions:

1. CPFP (Child-Pays-For-Parent)
   Use additional UTXO to boost fee rate

2. Anchor Outputs
   Specifically designed for CPFP acceleration

3. Dynamic Fee Estimation
   Watchtower decides fee rate at broadcast time

4. Pre-sign Multiple Fee Versions
   Low/medium/high fee rate penalty transactions

Modern Implementation (with Anchor Outputs):
• Penalty tx fee rate = minimum fee rate
• Actual fee adjusted dynamically via CPFP
• Requires additional UTXO for CPFP

懲罰機制的局限

數據丟失風險

如果你丟失了撤銷密鑰,就無法懲罰作弊者。這就是為什麼通道備份和 Watchtower 很重要。

離線風險

如果你在整個延遲期間都離線,作弊者可能成功。必須在 to_self_delay 內響應。

意外廣播

如果因為軟件錯誤或數據恢復問題意外廣播了舊狀態,你自己會被懲罰! 這是 通道備份 需要小心的原因。

Eltoo 替代方案

Eltoo (LN-Symmetry) Mode:

Uses state replacement instead of penalties:

Traditional Penalty Mode:
State N (old) -> broadcast -> penalty -> cheater loses all

Eltoo Mode:
State N (old) -> broadcast -> State N+1 overwrites -> correct settlement
                                 ^
                            No penalty needed

Advantages:
• Simpler, no need to store all revocation keys
• Accidentally broadcasting old state won't be penalized
• Better suited for multi-party channels
• More efficient state updates

Disadvantages:
• Requires SIGHASH_ANYPREVOUT (not yet activated)
• Cheater has no economic loss (except fees)
• May encourage more cheating attempts?

See: /tech/lightning/eltoo

實現狀態

所有實現 核心功能

懲罰機制是 LN-Penalty(當前閃電網路)的核心。所有實現(LND、CLN、Eclair、LDK) 都完整支持懲罰交易的創建和廣播。

Watchtower 可用

LND 內建 Watchtower 客戶端和服務器。Eye of Satoshi 是開源的第三方 Watchtower。

相關資源

下一步: 了解 通道再平衡 如何優化流動性分佈。

已複製連結
已複製到剪貼簿