UTXO

什麼是 UTXO?

This article introduces the UTXO mechanism of Bitcoin, including its definition, working principle, and application examples, and explains the important role of UTXO in the Bitcoin network. UTXO is the core of the Bitcoin ledger model, and each transaction needs to reference previous UTXOs, and must satisfy that the total value of inputs is greater than the total value of the transfer amount plus mining fees for it to be valid.

UTXO 的定義

UTXO,全稱為未花費的交易輸出(Unspent Transaction Output)。 與傳統的帳戶模型不同,當交易被廣播到比特幣網路時,該交易的輸出(Output)會被認為是未花費的 UTXO,直到其被其他交易消耗。 每個 UTXO 都包含了一個地址(Address)和一個金額(Value),這些資訊會儲存在比特幣的區塊鏈上。

UTXO 的工作原理

當用戶發送比特幣時,必須選擇一些未使用的 UTXO 作為輸入,然後建立新的 UTXO 作為輸出。 每筆交易都會消耗未使用的 UTXO,並且新的 UTXO 將被創建並記錄到區塊鏈上,以防止雙花問題。 比特幣網路中的每個交易都必須引用先前的交易,而且必須保證輸入 UTXO 總價值大於轉帳金額 + 礦工費的總價值,否則這筆交易就是無效的。

舉個例子,Alice 在區塊高度 77963 時收到含有 1 BTC 和 2 BTC 的 2 筆 UTXO。

如果 Alice 在區塊高度 78001 時向 Bob 轉帳 0.5 BTC,那麼 Alice 只需消耗含有 1 BTC 的 UTXO 就能滿足轉帳條件,剩餘資產會作為新的 UTXO 轉移到新的零點地址。

註:找零位址是在 UTXO 被消耗後,用於儲存剩餘資產的,其由主位址管理。 當用 imKey 在比特幣網路轉帳時,imKey 會自動為用戶產生新的找零地址,這樣做的好處是增強匿名性和節省礦工費。

(便於更能理解 UTXO 機制,圖中忽略礦工費)

如果 Alice 在區塊高度 78001 時向 Bob 轉帳 2.5 BTC,那麼 Alice 需要消耗兩筆 UTXO 才能滿足轉帳條件,剩餘資產會作為新的 UTXO 轉移到新的找零位址。

 

(便於更能理解 UTXO 機制,圖中忽略礦工費)