# Segregated Witness ###### tags: `Study` `Lab` ## Reference * [SegWit-Medium](https://medium.com/@jimmysong/understanding-segwit-block-size-fd901b87c9d4) * [不可不知 擴容與隔離見證](https://blockcast.it/2017/04/24/what-is-scalability-issue-and-segregated-witness/) * [Benefit of SegWit](https://bitcoincore.org/en/2016/01/26/segwit-benefits/) * [What's Segwit](https://www.buybitcoinworldwide.com/segwit/) * [Bitcoin Transaction](https://en.bitcoin.it/wiki/Transaction) * [Swgwit 交易容量增長](https://blog.bitmex.com/zh_cn-the-segwit-transaction-capacity-increase-part-1/) * [Transaction Malleability Explained](https://bitcointechtalk.com/transaction-malleability-explained-b7e240236fc7) ## Problem 1. Transaction Malleability : * Bitcoin 的交易是由其他的 UTXO 來當作 input 後產生另外一組 UTXO 來作為 output ,要能使用 input 上的 UTXO 需要提供 `scriptSig` 來解鎖該筆 UTXO 的 `scriptPubkey` , `scriptSig` 上只要有稍微被改動(所做的行為相同, output 不變),則該筆交易所產生的 `txid` 便會截然不同。 * 攻擊手法 * 假設 A 發送交易 `tx1` 給 B , B 再發 `tx2` 給 C 。 * A 發送 `tx1` 以外,還發送修改過且做同樣事情的 `tx1'` 。 * `tx1` 與 `tx1'` 的 `txid` 截然不同,因為 `scriptSig` 不一樣。 * B 繼續使用 `tx1` 的 `txid` 來作為 `tx2` 的 input 。 * 倘若 `tx1'` 比較早上鏈,則 `tx1` 被視為不合法。 * `tx2` input 中的 `tx1` 的 `txid` 無法使用,故 C 收不到錢,因而找 B 求償。 * A 與 C 是同一人。 2. Capacity Limits : * 由於交易裡頭最佔空間的是**數位簽章**的部分,所以 Segwit 透過把數位簽章移出至 coinbase transaction 的部分來達到縮減空間的效果。 * coinbase transaction 是指礦工在挖出區塊時用來領取獎勵的交易,此交易不會算在 Bitcoin 區塊大小上限的 1MB 裡面。 ## Solution * Segwit 的作法相當於把數位簽章移到交易的最後面,稱之為 witness data。 * 提出了 block weight 的概念,==有別於 block size 大小最多 1MB , block weight 的計算方式是只算去掉簽章後剩下的部分==,因此 block weight 可容納原本 block size 的四倍的交易量。 * 為軟分岔 (Soft-fork) : * 未升級成 Segwit 的交易仍可以使用。 * 所有節點不需要因此修改 block size 的上限,只需要大部分(95%)節點支援 Segwit。 * 不支援 Segwit 的節點會將 wintness data 捨棄,因為這是他不知道的部分,所以不會驗證成功。 * 支援 Segwit 的節點會以 block weight 的方式去看區塊,如果是舊的區塊(數位簽章沒移出來),節點仍舊會可以驗證該區塊。 * Segwit 的區塊去掉 witness data 後仍是不超過 1MB 。 * 圖解: * 一般 Bitcoin 交易 :  * Segwit 交易 : 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up