{"number":144,"title":"Segregated Witness (Peer Services)","authors":["Eric Lombrozo","Pieter Wuille"],"status":"Deployed","type":"Specification","layer":"Peer Services","created":"2016-01-08","license":"PD","requires":[],"replaces":[],"replacedBy":[],"discussion":[],"abstract":"This BIP defines new messages and serialization formats for propagation of transactions and blocks committing to segregated witness structures.","eli5":"Specifies the network messages nodes use to pass SegWit transactions and blocks to one another, including the separate signature data. It lets upgraded nodes share full witness data while older nodes can still receive a version they understand.","categories":["segwit","consensus","validation","encoding"],"filename":"bip-0144.mediawiki","githubUrl":"https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki","format":"mediawiki","readingMinutes":3,"inbound":3,"revisions":23,"impact":83,"core":false,"references":[],"lastModified":"2025-10-08","html":"<h2 id=\"abstract\">Abstract</h2>\n<p>This BIP defines new messages and serialization formats for propagation of transactions and blocks committing to segregated witness structures.</p>\n<h2 id=\"motivation\">Motivation</h2>\n<p>In addition to defining witness structures and requiring commitments in future blocks (<a href=\"https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki\">BIP141</a> - Consensus segwit BIP), new mechanisms must be defined to allow peers to advertise support for segregated witness and to relay the witness structures and request them from other peers without breaking compatibility with older nodes.</p>\n<h2 id=\"specification\">Specification</h2>\n<h3 id=\"serialization\">Serialization</h3>\n<p>A new serialization format for tx messages is added to the peer-to-peer protocol.</p>\n<p>The serialization has the following structure:</p>\n<div class=\"table-wrap\"><table><tbody><tr><th>Field Size</th><th>Name</th><th>Type</th><th>Description</th></tr><tr><td>4</td><td>version</td><td>int32_t</td><td>Transaction data format version</td></tr><tr><td>1</td><td>marker</td><td>char</td><td>Must be zero</td></tr><tr><td>1</td><td>flag</td><td>char</td><td>Must be nonzero</td></tr><tr><td>1+</td><td>txin_count</td><td>var_int</td><td>Number of transaction inputs</td></tr><tr><td>41+</td><td>txins</td><td>txin[]</td><td>A list of one or more transaction inputs</td></tr><tr><td>1+</td><td>txout_count</td><td>var_int</td><td>Number of transaction outputs</td></tr><tr><td>9+</td><td>txouts</td><td>txouts[]</td><td>A list of one or more transaction outputs</td></tr><tr><td>1+</td><td>script_witnesses</td><td>script_witnesses[]</td><td>The witness structure as a serialized byte array</td></tr><tr><td>4</td><td>lock_time</td><td>uint32_t</td><td>The block number or timestamp until which the transaction is locked</td></tr></tbody></table></div>\n<p>Parsers supporting this BIP will be able to distinguish between the old serialization format (without the witness) and this one. The marker byte is set to zero so that this structure will never parse as a valid transaction in a parser that does not support this BIP. If parsing were to succeed, such a transaction would contain no inputs and a single output.</p>\n<p>If the witness is empty, the old serialization format must be used.</p>\n<p>Currently, the only witness objects type supported are script witnesses which consist of a stack of byte arrays. It is encoded as a var_int item count followed by each item encoded as a var_int length followed by a string of bytes. Each txin has its own script witness. The number of script witnesses is not explicitly encoded as it is implied by txin_count. Empty script witnesses are encoded as a zero byte. The order of the script witnesses follows the same order as the associated txins.</p>\n<ul><li>\n<strong>Rationale for not having an independent message type with its own serialization</strong>: this would require separate \"tx\" and \"block\" messages, and all RPC calls operating on raw transactions would need to be duplicated, or need inefficient or nondeterministic guesswork to know which type is to be used.\n</li></ul>\n<ul><li>\n<strong>Rationale for not using just a single 0x00 byte as marker</strong>: that would lead to empty transactions (no inputs, no outputs, which are used in some tests) to be interpreted as new serialized data.\n</li></ul>\n<ul><li>\n<strong>Rationale for the 0x01 flag byte in between</strong>: this will allow us to easily add more extra non-committed data to transactions (like txouts being spent, ...). It can be interpreted as a bitvector.\n</li></ul>\n<h3 id=\"handshake\">Handshake</h3>\n<p>A node will signal that it can provide witnesses using the following service bit</p>\n<p>NODE_WITNESS = (1 << 3)</p>\n<h3 id=\"hashes\">Hashes</h3>\n<p>Transaction hashes used in the transaction merkle tree and txin outpoints are always computed using the old non-witness serialization.</p>\n<p>Support for a new hash including the witness data is added that is computed from the new witness serialization. (Note that transactions with an empty witness always use the old serialization, and therefore, they have witness hash equal to normal hash.)</p>\n<img src=\"https://raw.githubusercontent.com/bitcoin/bips/master/bip-0144/witnesstx.png\"></img>\n<h3 id=\"relay\">Relay</h3>\n<p>New inv types MSG_WITNESS_TX (0x40000001, or (1<<30)+MSG_TX) and MSG_WITNESS_BLOCK (0x40000002, or (1<<30)+MSG_BLOCK) are added, only for use in getdata. Inventory messages themselves still use just MSG_TX and MSG_BLOCK, similar to MSG_FILTERED_BLOCK. A further inv type MSG_FILTERED_WITNESS_BLOCK (0x40000003, or (1<<30)+MSG_FILTERED_BLOCK) is reserved for future use.</p>\n<ul><li>\n<strong>Rationale for not advertizing witnessness in invs</strong>: we don't always use invs anymore (with 'sendheaders' BIP 130), plus it's not useful: implicitly, every transaction and block have a witness, old ones just have empty ones.\n</li></ul>\n<p>MSG_WITNESS_TX getdata requests should use the non-witness serialized hash. The peer shall respond with a tx message, and if the witness structure is nonempty, the witness serialization shall be used.</p>\n<p>MSG_WITNESS_BLOCK requests will return a block message with transactions that have a witness using witness serialization.</p>\n<h2 id=\"credits\">Credits</h2>\n<p>Special thanks to Gregory Maxwell for originating many of the ideas in this BIP and Luke-Jr for figuring out how to deploy this as a soft fork.</p>\n<h2 id=\"reference-implementation\">Reference Implementation</h2>\n<p><a href=\"https://github.com/bitcoin/bitcoin/pull/8149\">https://github.com/bitcoin/bitcoin/pull/8149</a></p>\n<h2 id=\"copyright\">Copyright</h2>\n<p>This document is placed in the public domain.</p>","toc":[{"id":"abstract","title":"Abstract","level":2},{"id":"motivation","title":"Motivation","level":2},{"id":"specification","title":"Specification","level":2},{"id":"serialization","title":"Serialization","level":3},{"id":"handshake","title":"Handshake","level":3},{"id":"hashes","title":"Hashes","level":3},{"id":"relay","title":"Relay","level":3},{"id":"credits","title":"Credits","level":2},{"id":"reference-implementation","title":"Reference Implementation","level":2},{"id":"copyright","title":"Copyright","level":2}],"history":{"totalCommits":23,"firstCommit":"2016-01-08T17:59:36+00:00","lastUpdated":"2025-10-08T14:59:36-07:00","events":[{"sha":"24e96e870fffaa257b465ce1f0370c14aac588e8","date":"2025-10-08T14:59:36-07:00","author":"Murch","message":"process: Created ↦ Assigned","url":"https://github.com/bitcoin/bips/commit/24e96e870fffaa257b465ce1f0370c14aac588e8","kind":"edit"},{"sha":"5207ef92a52d0b8902895b0dbb40823a4d698ec9","date":"2025-04-11T20:08:17-07:00","author":"Murch","message":"process: Author ↦ Authors","url":"https://github.com/bitcoin/bips/commit/5207ef92a52d0b8902895b0dbb40823a4d698ec9","kind":"edit"},{"sha":"59730dec4fb641a41589aa1b91d3c452f13e0e36","date":"2025-04-11T20:05:13-07:00","author":"Murch","message":"process: Remove Comments-URI and -Summary","url":"https://github.com/bitcoin/bips/commit/59730dec4fb641a41589aa1b91d3c452f13e0e36","kind":"edit"},{"sha":"a233bde4af52c6a11269e2e6dd9707abce441ffe","date":"2025-04-11T18:19:21-07:00","author":"Murch","message":"process: Standards Track ↦ Specification","url":"https://github.com/bitcoin/bips/commit/a233bde4af52c6a11269e2e6dd9707abce441ffe","kind":"edit"},{"sha":"5d3ceb37734f80b2ec206fc94245e3bfd6d5b0f0","date":"2025-04-11T18:08:44-07:00","author":"Murch","message":"process: Final/Active ↦ Deployed","url":"https://github.com/bitcoin/bips/commit/5d3ceb37734f80b2ec206fc94245e3bfd6d5b0f0","kind":"status"},{"sha":"9a56d3544eac1f949a747c251810f7a440d63fb9","date":"2024-07-25T18:35:39+03:00","author":"Orfeas Stefanos Thyfronitis Litos","message":"Remove trailing whitespace from all BIPs","url":"https://github.com/bitcoin/bips/commit/9a56d3544eac1f949a747c251810f7a440d63fb9","kind":"edit"},{"sha":"d8dea4ef095e5ce8a12f7956a9951cb5cddf8964","date":"2019-05-13T18:24:52-04:00","author":"MarcoFalke","message":"BIP 144: Old serialization format must be used on empty witness","url":"https://github.com/bitcoin/bips/commit/d8dea4ef095e5ce8a12f7956a9951cb5cddf8964","kind":"edit"},{"sha":"0402dd2b846e962125db4150d9c20ec43bb171dc","date":"2017-10-29T04:22:13+00:00","author":"Luke Dashjr","message":"Update status of BIPs 141, 143, 144, and 147 to Proposed","url":"https://github.com/bitcoin/bips/commit/0402dd2b846e962125db4150d9c20ec43bb171dc","kind":"status"},{"sha":"824ce9da50158497ebd33057fbf8c4bc3a642c60","date":"2017-08-30T15:37:48+08:00","author":"Johnson Lau","message":"Update status for segwit related BIPs","url":"https://github.com/bitcoin/bips/commit/824ce9da50158497ebd33057fbf8c4bc3a642c60","kind":"status"},{"sha":"bf85f3002464bf8423379e6584ce8dcadaa52540","date":"2017-08-24T09:58:28+12:00","author":"MeshCollider","message":"Change \"inefficinent\" => \"inefficient\" in BIP 144","url":"https://github.com/bitcoin/bips/commit/bf85f3002464bf8423379e6584ce8dcadaa52540","kind":"edit"},{"sha":"959fecc15bdad070afa63455468b1dba54655fa6","date":"2016-11-30T09:47:31+00:00","author":"Luke Dashjr","message":"Promote BIP 2 Draft->Active, and implement it","url":"https://github.com/bitcoin/bips/commit/959fecc15bdad070afa63455468b1dba54655fa6","kind":"status"},{"sha":"72f18918a8ae655212ea2700b30f0dc4d758b843","date":"2016-11-30T09:45:33+00:00","author":"Luke Dashjr","message":"Promote BIP 123 Draft->Active, and implement it","url":"https://github.com/bitcoin/bips/commit/72f18918a8ae655212ea2700b30f0dc4d758b843","kind":"status"},{"sha":"3f59ccdddc84f309dd8268706ac8240e3e42dc2b","date":"2016-10-05T17:33:02+08:00","author":"Johnson Lau","message":"Add policy descriptions to BIP141 and 143 and address some nits.","url":"https://github.com/bitcoin/bips/commit/3f59ccdddc84f309dd8268706ac8240e3e42dc2b","kind":"edit"},{"sha":"9fc3cf52c6d0dcb58b806c7a1f727083b7e49607","date":"2016-10-05T13:39:49+02:00","author":"Wladimir J. van der Laan","message":"bip-0144: Add enum values for MSG_WITNESS_{BLOCK,TX}, MSG_FILTERED_WITNESS_BLOCK","url":"https://github.com/bitcoin/bips/commit/9fc3cf52c6d0dcb58b806c7a1f727083b7e49607","kind":"edit"},{"sha":"dde47fc973b015c6cc91a0ed28fb3aca57add5e6","date":"2016-04-28T17:47:36-04:00","author":"Andrew Chow","message":"Update to NODE_WITNESS service bit","url":"https://github.com/bitcoin/bips/commit/dde47fc973b015c6cc91a0ed28fb3aca57add5e6","kind":"edit"},{"sha":"4edd6d2badd9a6ad2ff09bb6792fe0d0e365a7de","date":"2016-02-03T07:02:36+00:00","author":"Luke Dashjr","message":"Lots of formatting fixes","url":"https://github.com/bitcoin/bips/commit/4edd6d2badd9a6ad2ff09bb6792fe0d0e365a7de","kind":"edit"},{"sha":"ecdfa0a029b7dc25a1a10dbf773e73f8c2b01769","date":"2016-01-24T04:41:29-08:00","author":"Eric Lombrozo","message":"Script witness encoding.","url":"https://github.com/bitcoin/bips/commit/ecdfa0a029b7dc25a1a10dbf773e73f8c2b01769","kind":"edit"},{"sha":"7e4dec0d9368a3b8c795fa25fe813932e16a57fb","date":"2016-01-21T22:53:32+08:00","author":"Johnson Lau","message":"Links to reference implementation","url":"https://github.com/bitcoin/bips/commit/7e4dec0d9368a3b8c795fa25fe813932e16a57fb","kind":"edit"},{"sha":"9d99270419bd9ce114ac19a1f77886077f0b50aa","date":"2016-01-19T21:37:47-08:00","author":"Sam Wood","message":"Adds a missing BIP 141 segwit BIP reference","url":"https://github.com/bitcoin/bips/commit/9d99270419bd9ce114ac19a1f77886077f0b50aa","kind":"edit"},{"sha":"4ee32820b9da4e1c4aee43187ecc54e1835291e8","date":"2016-01-19T14:38:09+01:00","author":"Andreas Schildbach","message":"Fix typo in proposed BIP144.","url":"https://github.com/bitcoin/bips/commit/4ee32820b9da4e1c4aee43187ecc54e1835291e8","kind":"status"},{"sha":"8e22af1d0a5de646b8f6cf4e9a78aa5792fcf7a5","date":"2016-01-14T13:15:10+08:00","author":"Johnson Lau","message":"Title change and links update","url":"https://github.com/bitcoin/bips/commit/8e22af1d0a5de646b8f6cf4e9a78aa5792fcf7a5","kind":"edit"},{"sha":"ae529c3f0488fec6ebc335f2bdb0e623af6a6a5c","date":"2016-01-12T03:09:50+08:00","author":"Johnson Lau","message":"Fix links in BIP142-144. Corrections in BIP142.","url":"https://github.com/bitcoin/bips/commit/ae529c3f0488fec6ebc335f2bdb0e623af6a6a5c","kind":"edit"},{"sha":"8084782fa5d3143555db1e8ac13eda5a4ae82c52","date":"2016-01-08T17:59:36+00:00","author":"Luke Dashjr","message":"Assign BIP 144","url":"https://github.com/bitcoin/bips/commit/8084782fa5d3143555db1e8ac13eda5a4ae82c52","kind":"edit"}]}}