summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.mediawiki62
-rw-r--r--bip-0009.mediawiki2
-rw-r--r--bip-0018.mediawiki2
-rw-r--r--bip-0021.mediawiki3
-rw-r--r--bip-0039.mediawiki5
-rw-r--r--bip-0043.mediawiki2
-rw-r--r--bip-0044.mediawiki2
-rw-r--r--bip-0045.mediawiki2
-rw-r--r--bip-0067.mediawiki2
-rw-r--r--bip-0069.mediawiki2
-rw-r--r--bip-0080.mediawiki2
-rw-r--r--bip-0081.mediawiki2
-rw-r--r--bip-0111.mediawiki2
-rw-r--r--bip-0114.mediawiki344
-rw-r--r--bip-0114/mastexample.pngbin0 -> 26798 bytes
-rw-r--r--bip-0125.mediawiki2
-rw-r--r--bip-0130.mediawiki2
-rw-r--r--bip-0132.mediawiki2
-rw-r--r--bip-0146.mediawiki79
-rw-r--r--bip-0150.mediawiki174
-rw-r--r--bip-0151.mediawiki4
21 files changed, 556 insertions, 141 deletions
diff --git a/README.mediawiki b/README.mediawiki
index 239294f..8b48af1 100644
--- a/README.mediawiki
+++ b/README.mediawiki
@@ -24,12 +24,12 @@ Those proposing changes should consider that ultimately consent may rest with th
| Luke Dashjr
| Process
| Deferred
-|-
+|- style="background-color: #cfffcf"
| [[bip-0009.mediawiki|9]]
| Version bits with timeout and delay
| Pieter Wuille, Peter Todd, Greg Maxwell, Rusty Russell
| Informational
-| Draft
+| Final
|- style="background-color: #ffcfcf"
| [[bip-0010.mediawiki|10]]
| Multi-Sig Transaction Distribution
@@ -78,12 +78,12 @@ Those proposing changes should consider that ultimately consent may rest with th
| Luke Dashjr
| Standard
| Withdrawn
-|-
+|- style="background-color: #ffffcf"
| [[bip-0018.mediawiki|18]]
| hashScriptCheck
| Luke Dashjr
| Standard
-| Draft
+| Accepted
|-
| [[bip-0019.mediawiki|19]]
| M-of-N Standard Transactions (Low SigOp)
@@ -168,12 +168,12 @@ Those proposing changes should consider that ultimately consent may rest with th
| Mike Caldwell, Aaron Voisine
| Standard
| Draft
-|-
+|- style="background-color: #ffffcf"
| [[bip-0039.mediawiki|39]]
| Mnemonic code for generating deterministic keys
| Marek Palatinus, Pavol Rusnak, Aaron Voisine, Sean Bowe
| Standard
-| Draft
+| Accepted
|-
| 40
| Stratum wire protocol
@@ -196,20 +196,20 @@ Those proposing changes should consider that ultimately consent may rest with th
| [[bip-0043.mediawiki|43]]
| Purpose Field for Deterministic Wallets
| Marek Palatinus, Pavol Rusnak
-| Standard
+| Informational
| Draft
-|-
+|- style="background-color: #ffffcf"
| [[bip-0044.mediawiki|44]]
| Multi-Account Hierarchy for Deterministic Wallets
| Marek Palatinus, Pavol Rusnak
| Standard
-| Draft
-|-
+| Accepted
+|- style="background-color: #ffffcf"
| [[bip-0045.mediawiki|45]]
| Structure for Deterministic P2SH Multisignature Wallets
| Manuel Araoz, Ryan X. Charles, Matias Alejo Garcia
| Standard
-| Draft
+| Accepted
|-
| [[bip-0047.mediawiki|47]]
| Reusable Payment Codes for Hierarchical Deterministic Wallets
@@ -265,24 +265,24 @@ Those proposing changes should consider that ultimately consent may rest with th
| Pieter Wuille
| Standard
| Final
-|-
+|- style="background-color: #ffffcf"
| [[bip-0067.mediawiki|67]]
| Deterministic Pay-to-script-hash multi-signature addresses through public key sorting
| Thomas Kerin, Jean-Pierre Rupp, Ruben de Vries
| Standard
-| Draft
+| Accepted
|- style="background-color: #cfffcf"
| [[bip-0068.mediawiki|68]]
| Relative lock-time using consensus-enforced sequence numbers
| Mark Friedenbach, BtcDrak, Nicolas Dorier, kinoshitajona
| Standard
| Final
-|-
+|- style="background-color: #ffffcf"
| [[bip-0069.mediawiki|69]]
| Lexicographical Indexing of Transaction Inputs and Outputs
| Kristov Atlas
| Informational
-| Draft
+| Accepted
|- style="background-color: #cfffcf"
| [[bip-0070.mediawiki|70]]
| Payment Protocol
@@ -324,13 +324,13 @@ Those proposing changes should consider that ultimately consent may rest with th
| Hierarchy for Non-Colored Voting Pool Deterministic Multisig Wallets
| Justus Ranvier, Jimmy Song
| Informational
-| Draft
+| Deferred
|-
| [[bip-0081.mediawiki|81]]
| Hierarchy for Colored Voting Pool Deterministic Multisig Wallets
| Justus Ranvier, Jimmy Song
| Informational
-| Draft
+| Deferred
|-
| [[bip-0083.mediawiki|83]]
| Dynamic Hierarchical Deterministic Key Trees
@@ -385,12 +385,12 @@ Those proposing changes should consider that ultimately consent may rest with th
| Gavin Andresen
| Standard
| Draft
-|-
+|- style="background-color: #ffffcf"
| [[bip-0111.mediawiki|111]]
| NODE_BLOOM service bit
| Matt Corallo, Peter Todd
| Standard
-| Draft
+| Accepted
|- style="background-color: #cfffcf"
| [[bip-0112.mediawiki|112]]
| CHECKSEQUENCEVERIFY
@@ -439,36 +439,36 @@ Those proposing changes should consider that ultimately consent may rest with th
| Eric Lombrozo, William Swanson
| Informational
| Draft
-|-
+|- style="background-color: #ffffcf"
| [[bip-0125.mediawiki|125]]
| Opt-in Full Replace-by-Fee Signaling
| David A. Harding, Peter Todd
| Standard
-| Draft
+| Accepted
|-
| [[bip-0126.mediawiki|126]]
| Best Practices for Heterogeneous Input Script Transactions
| Kristov Atlas
| Informational
| Draft
-|-
+|- style="background-color: #ffffcf"
| [[bip-0130.mediawiki|130]]
| sendheaders message
| Suhas Daftuar
| Standard
-| Draft
+| Accepted
|-
| [[bip-0131.mediawiki|131]]
| "Coalescing Transaction" Specification (wildcard inputs)
| Chris Priest
| Standard
| Draft
-|-
+|- style="background-color: #ffcfcf"
| [[bip-0132.mediawiki|132]]
| Committee-based BIP Acceptance Process
| Andy Chase
| Process
-| Draft
+| Withdrawn
|-
| [[bip-0133.mediawiki|133]]
| feefilter message
@@ -512,6 +512,18 @@ Those proposing changes should consider that ultimately consent may rest with th
| Standard
| Draft
|-
+| [[bip-0146.mediawiki|146]]
+| Dealing with signature malleability
+| Pieter Wuille, Johnson Lau
+| Standard
+| Draft
+|-
+| [[bip-0150.mediawiki|150]]
+| Peer Authentication
+| Jonas Schnelli
+| Standard
+| Draft
+|-
| [[bip-0151.mediawiki|151]]
| Peer-to-Peer Communication Encryption
| Jonas Schnelli
diff --git a/bip-0009.mediawiki b/bip-0009.mediawiki
index 7270abd..536ef1f 100644
--- a/bip-0009.mediawiki
+++ b/bip-0009.mediawiki
@@ -5,7 +5,7 @@
Peter Todd <pete@petertodd.org>
Greg Maxwell <greg@xiph.org>
Rusty Russell <rusty@rustcorp.com.au>
- Status: Draft
+ Status: Final
Type: Informational
Created: 2015-10-04
</pre>
diff --git a/bip-0018.mediawiki b/bip-0018.mediawiki
index 023b2bf..fce4200 100644
--- a/bip-0018.mediawiki
+++ b/bip-0018.mediawiki
@@ -2,7 +2,7 @@
BIP: 18
Title: hashScriptCheck
Author: Luke Dashjr <luke+bip17@dashjr.org>
- Status: Draft
+ Status: Accepted
Type: Standards Track
Created: 2012-01-27
</pre>
diff --git a/bip-0021.mediawiki b/bip-0021.mediawiki
index daf4cf8..513b8bb 100644
--- a/bip-0021.mediawiki
+++ b/bip-0021.mediawiki
@@ -124,4 +124,5 @@ Characters must be URI encoded properly.
=== Libraries ===
* Javascript - https://github.com/bitcoinjs/bip21
-* https://github.com/SandroMachado/BitcoinPaymentURI Java library to process and generate Bitcoin payment URI's.
+* Java - https://github.com/SandroMachado/BitcoinPaymentURI
+* Swift - https://github.com/SandroMachado/BitcoinPaymentURISwift
diff --git a/bip-0039.mediawiki b/bip-0039.mediawiki
index 0d05d81..3c95d4d 100644
--- a/bip-0039.mediawiki
+++ b/bip-0039.mediawiki
@@ -5,7 +5,7 @@
Pavol Rusnak <stick@satoshilabs.com>
Aaron Voisine <voisine@gmail.com>
Sean Bowe <ewillbefull@gmail.com>
- Status: Draft
+ Status: Accepted
Type: Standards Track
Created: 2013-09-10
</pre>
@@ -146,3 +146,6 @@ Haskell:
JavaScript:
* https://github.com/bitpay/bitcore-mnemonic
* https://github.com/bitcoinjs/bip39 (used by [[https://github.com/blockchain/My-Wallet-V3/blob/v3.8.0/src/hd-wallet.js#L121-L146|blockchain.info]])
+
+Ruby:
+* https://github.com/sreekanthgs/bip_mnemonic
diff --git a/bip-0043.mediawiki b/bip-0043.mediawiki
index 4c57935..686221a 100644
--- a/bip-0043.mediawiki
+++ b/bip-0043.mediawiki
@@ -4,7 +4,7 @@
Author: Marek Palatinus <slush@satoshilabs.com>
Pavol Rusnak <stick@satoshilabs.com>
Status: Draft
- Type: Standards Track
+ Type: Informational
Created: 2014-04-24
</pre>
diff --git a/bip-0044.mediawiki b/bip-0044.mediawiki
index 883677a..e17c73d 100644
--- a/bip-0044.mediawiki
+++ b/bip-0044.mediawiki
@@ -3,7 +3,7 @@
Title: Multi-Account Hierarchy for Deterministic Wallets
Author: Marek Palatinus <slush@satoshilabs.com>
Pavol Rusnak <stick@satoshilabs.com>
- Status: Draft
+ Status: Accepted
Type: Standards Track
Created: 2014-04-24
</pre>
diff --git a/bip-0045.mediawiki b/bip-0045.mediawiki
index 1550467..757fc7f 100644
--- a/bip-0045.mediawiki
+++ b/bip-0045.mediawiki
@@ -4,7 +4,7 @@
Author: Manuel Araoz <manu@bitpay.com>
Ryan X. Charles <ryan@bitpay.com>
Matias Alejo Garcia <matias@bitpay.com>
- Status: Draft
+ Status: Accepted
Type: Standards Track
Created: 2014-04-25
</pre>
diff --git a/bip-0067.mediawiki b/bip-0067.mediawiki
index 3864c63..13e2ed9 100644
--- a/bip-0067.mediawiki
+++ b/bip-0067.mediawiki
@@ -4,7 +4,7 @@
Author: Thomas Kerin <me@thomaskerin.io>
Jean-Pierre Rupp <root@haskoin.com>
Ruben de Vries <ruben@rubensayshi.com>
- Status: Draft
+ Status: Accepted
Type: Standards Track
Created: 2015-02-08
</pre>
diff --git a/bip-0069.mediawiki b/bip-0069.mediawiki
index 4094126..832438c 100644
--- a/bip-0069.mediawiki
+++ b/bip-0069.mediawiki
@@ -3,7 +3,7 @@
Title: Lexicographical Indexing of Transaction Inputs and Outputs
Author: Kristov Atlas <kristov@openbitcoinprivacyproject.org>
Editor: Daniel Cousens <bips@dcousens.com>
- Status: Draft
+ Status: Accepted
Type: Informational
Created: 2015-06-12
</pre>
diff --git a/bip-0080.mediawiki b/bip-0080.mediawiki
index 13d8597..05322e0 100644
--- a/bip-0080.mediawiki
+++ b/bip-0080.mediawiki
@@ -3,7 +3,7 @@
Title: Hierarchy for Non-Colored Voting Pool Deterministic Multisig Wallets
Author: Justus Ranvier <justus@opentransactions.org>
Jimmy Song <jimmy@monetas.net>
- Status: Draft
+ Status: Deferred
Type: Informational
Created: 2014-08-11
</pre>
diff --git a/bip-0081.mediawiki b/bip-0081.mediawiki
index b306075..713cb57 100644
--- a/bip-0081.mediawiki
+++ b/bip-0081.mediawiki
@@ -3,7 +3,7 @@
Title: Hierarchy for Colored Voting Pool Deterministic Multisig Wallets
Author: Justus Ranvier <justus@opentransactions.org>
Jimmy Song <jimmy@monetas.net>
- Status: Draft
+ Status: Deferred
Type: Informational
Created: 2014-08-11
</pre>
diff --git a/bip-0111.mediawiki b/bip-0111.mediawiki
index f759f5c..4557832 100644
--- a/bip-0111.mediawiki
+++ b/bip-0111.mediawiki
@@ -3,7 +3,7 @@
Title: NODE_BLOOM service bit
Author: Matt Corallo <bip111@bluematt.me>
Peter Todd <pete@petertodd.org>
- Status: Draft
+ Status: Accepted
Type: Standards Track
Created: 2015-08-20
</pre>
diff --git a/bip-0114.mediawiki b/bip-0114.mediawiki
index aee8646..cb9aea7 100644
--- a/bip-0114.mediawiki
+++ b/bip-0114.mediawiki
@@ -24,71 +24,172 @@ The [[bip-0016.mediawiki|BIP16]] (Pay-to-script-hash, "P2SH") fixes the first 3
The [[bip-0141.mediawiki|BIP141]] defines 2 new types of scripts that support segregated witness. The pay-to-witness-script-hash (P2WSH) is similar to P2SH is many ways. By supplying the script in witness, P2WSH restores the original 10,000 byte script limit. However, it still requires publishing of unexecuted branches.
===Merkelized Abstract Syntax Tree===
-The idea of Merkelized Abstract Syntax Tree (MAST) is to use a Merkle tree to encode mutually exclusive branches in a script. When spending, the redeemer may provide only the branch they are executing, and hashes that connect the branch to the fixed size Merkel root. This reduces the size of redemption stack from O(n) to O(log n) (n as the number of mutually exclusive branches). This enables complicated redemption conditions that is currently not possible due to the script size and op code limit, improves privacy by hiding unexecuted branches, and allows inclusion of non-consensus enforced data with very low or no additional cost.
+The idea of Merkelized Abstract Syntax Tree (MAST) is to use a Merkle tree to encode branches in a script. When spending, users may provide only the branches they are executing, and hashes that connect the branches to the fixed size Merkel root. This reduces the size of redemption stack from O(n) to O(log n) (n as the number of branches). This enables complicated redemption conditions that is currently not possible due to the script size and opcode limit, improves privacy by hiding unexecuted branches, and allows inclusion of non-consensus enforced data with very low or no additional cost.
==Specification==
-In [[bip-0141.mediawiki|BIP141]], witness programs with a version byte of 1 or larger are considered to be anyone-can-spend scripts. The following new validation rules are applied if the witness program version byte is 1 and the program size is 32 bytes. The witness program is the <code>MAST Root</code>.
+In [[bip-0141.mediawiki|BIP141]], witness programs with a version byte of 1 or larger are considered to be anyone-can-spend scripts. The following new validation rules are applied if the witness program version byte is 1 and the program size is 32 bytes.<ref>If the version byte is 1, but the witness program is not 32 bytes, no further interpretation of the witness program or witness stack happens. This is reserved for future extensions.</ref> The witness program is the <code>MAST Root</code>.
-To redeem an output of this kind, the witness must consist of an input stack to feed to the script, followed by a <code>Postion</code> value, a serialized Merkle path (<code>Path</code>), and a serialized script (<code>MAST Script</code>).
+To redeem an output of this kind, the witness must consist of the following items:
-The <code>Position</code>, <code>Path</code>, and <code>MAST Script</code> are popped off the initial witness stack.
-The double-SHA256 of the MAST Script (≤ TBD bytes) must be correctly connected to the <code>MAST Root</code> with the <code>ComputeMerkleRootFromBranch</code> function, with the specified <code>Path</code> and <code>Position</code>.
+ Script_stack_1
+ Script_stack_2
+ .
+ .
+ Script_stack_X (X ≥ 0)
+ Subscript_1
+ Subscript_2
+ .
+ .
+ Subscript_Y (1 ≤ Y ≤ 255)
+ Position
+ Path
+ Metadata (Y|MAST Version)
-<code>Path</code> is the serialized Merkle path for the <code>MAST Script</code>. Size of <code>Path</code> must be a multiple of 32 bytes, and not more than 1024 bytes (which allows 32 levels). Each 32 byte word is a double-SHA256 merkle node in the merkle branch connecting to the <code> MAST Root</code>. If the size of <code>Path</code> is zero, the double-SHA256 of the <code>MAST Script</code> must match the <code>MAST Root</code>.
-<code>Position</code> indicates the location of the <code>MAST Script</code> in the Merkle tree, with zero indicating the leftmost position. It is an unsigned little-endian integer with not more than 4 bytes. It must be encoded in the most parsimonious way possible, with no leading zero and not larger than the maximum number of items allowed by the depth of the tree (as implied by the size of <code>Path</code>).
+<code>Metadata</code> is the last witness item. It is a vector of 1 to 5 bytes. The first byte is an unsigned integer between 1 to 255 denoting the number of <code>Subscript</code> (defined hereinafter). The following 0 to 4 byte(s) is an unsigned little-endian integer denoting the <code>MAST version</code>. <code>MAST Version</code> must be minimally encoded (the most significant byte must not be 0).
-The <code>MAST Script</code> is then deserialized, and executed after normal script evaluation with the remaining witness stack (≤ TBD bytes for each stack item). The script must not fail, and result in exactly a single TRUE on the stack.
+<code>Path</code> is the second last witness item. It is a serialized Merkle path of the <code>Script Hash</code> (defined hereinafter). Size of <code>Path</code> must be a multiple of 32 bytes, and not more than 1024 bytes. Each 32 byte word is a double-SHA256 merkle node in the merkle branch connecting to the <code>Script Root</code> (defined hereinafter). <code>Depth</code> of the tree (0 to 32) is the size of <code>Path</code> divided by 32.
-Sigops in MAST program are counted to the block sigop limit in the same way as the version 0 witness program (see BIP141).
+<code>Position</code> is the third last witness item. It indicates the location of the <code>Script Hash</code> in the Merkle tree, with zero indicating the leftmost position. It is an unsigned little-endian integer with not more than 4 bytes. It must be minimally encoded: the value must not be larger than the maximum number of items allowed by the <code>Depth</code> of the tree, and the most significant byte must not be 0. For example, if <code>Depth</code> is 4, the valid range of <code>Position</code> is 0 to 15 (2<sup>4</sup>-1).
-If the version byte is 1, but the witness program is not 32 bytes, the script must fail.
+Depends on the first byte of <code>Metadata</code>, there should be 1 to 255 <code>Subscript</code> witness item(s) before <code>Position</code>.
+
+<code>Script Hash</code> is defined as:
+
+ Script Hash = H(Y|H(Subscript_1)|H(Subscript_2)|...|H(Subscript_Y))
+ H() = SHA256(SHA256())
+
+where <code>Y</code> is a 1-byte value denoting number of <code>Subscript</code>, followed by the hash of each <code>Subscript</code>
+
+<code>Script Root</code> is the Merkle root calculated by the <code>ComputeMerkleRootFromBranch</code> function, using <code>Script Hash</code>, <code>Path</code> and <code>Position</code>.
+
+<code>MAST Root</code> is <code>H(MAST Version|Script Root)</code>. The pre-image has a fixed size of 36 bytes: 4 bytes for <code>MAST Version</code> (unsigned little-endian integer) and 32 bytes for <code>Script Root</code>.
+
+The script evaluation fails if <code>MAST Root</code> does not match the witness program.
+
+If the <code>MAST Root</code> matches the witness program and <code>MAST Version</code> is greater than 0, the script returns a success without further evaluation. <code>SigOpsCost</code> is counted as 0. This is reserved for future script upgrades.
+
+If the <code>MAST Version</code> is 0, the <code>Subscript</code>(s) are serialized to form the final <code>MAST Script</code>, beginning with </code>Subscript_1</code>. The unused witness item(s) before the </code>Subscript_1</code> are used as <code>Input Stack</code> to feed to the <code>MASTScript</code>. (Similar to P2WSH in BIP141)
+
+The script fails with one of the following conditions:
+* <code>MAST Script</code> is malformed (i.e. not enough data provided for the last push operation). Individual <code>Subscript</code> might be malformed, as long as they are serialized into a valid <code>MAST Script</code>
+* Size of <code>MAST Script</code> is larger than 10,000 bytes
+* Size of any one of the <code>Input Stack</code> item is larger than 520 bytes
+* Number of non-push operations (<code>nOpCount</code>) is more than 201. <code>nOpCount</code> is the sum of the number of non-push operations in <code>MAST Script</code> (counted in the same way as P2WSH <code>witnessScript</code>), number of <code>Subscript</code> (Y), and <code>Depth</code> of the Merkle tree.
+
+The <code>MAST Script</code> is then evaluated with the <code>Input Stack</code> (with some new or redefined opcodes described in BIPXXX). The evaluation must not fail, and result in an exactly empty stack.
+
+Counting of <code>SigOpsCost</code> is based on the <code>MAST Script</code>, described in BIPYYY.
+
+== Rationale ==
+=== MAST Structure ===
+This proposal is a restricted case of more general MAST. In a general MAST design, users may freely assign one or more script branches for execution. In this proposal, only one branch is allowed for execution, and users are required to transform a complicated condition into several mutually exclusive branches. For example, if the desired redeem condition is:
+
+ (A or B) and (C or D or E) and (F or G)
+
+In a general MAST design, the 7 branches (A to G) will form a 3-level Merkle tree, plus an "overall condition" describing the relationship of different branches. In redemption, the "overall condition", executed branches (e.g. B, D, F), and Merkle path data will be provided for validation.
+
+In the current proposal, the user has to transform the redeem condition into 12 mutually exclusive branches and form a 4-level Merkle tree, and present only one branch in redemption:
+
+
+ A and C and F
+ B and C and F
+ A and D and F
+ .
+ .
+ B and E and G
+
+One way to implement the general MAST design is using a combination of <code>OP_EVAL</code>, <code>OP_CAT</code>, and <code>OP_HASH256</code>. However, that will suffer from the problems of <code>OP_EVAL</code>, including risks of indefinite program loop and inability to do static program analysis. A complicated implementation is required to fix these problems and is difficult to review.
+
+The advantages of the current proposal are:
+* <code>Subscript</code> are located at a fixed position in the witness stack. This allows static program analysis, such as static <code>SigOpsCost</code> counting and early termination of scripts with disabled opcodes.
+* If different parties in a contract do not want to expose their scripts to each other, they may provide only <code>H(Subscript)</code> and keep the <code>Subscript</code> private until redemption.
+* If they are willing to share the actual scripts, they may combine them into one <code>Subscript</code> for each branch, saving some <code>nOpCount</code> and a few bytes of witness space.
+
+The are some disadvantages, but only when the redemption condition is very complicated:
+* It may require more branches than a general MAST design (as shown in the previous example) and take more witness space in redemption
+* Creation and storage of the MAST structure may take more time and space. However, such additional costs affect only the related parties in the contract but not any other Bitcoin users.
+
+=== MAST Version ===
+This proposal allows users to indicate the version of scripting language in the witness, which is cheaper than doing that in <code>scriptPubKey</code> or <code>scriptSig</code>. Undefined versions remain anyone-can-spend and are reserved for future expansions. A new version could be used for relaxing constraints (e.g. the 10,000 bytes size limit of <code>MAST Script</code>), adding or redefining opcodes, or even introducing a completely novel scripting system.
+
+=== nOpCount limit ===
+In version 0 MAST, the extra hashing operations in calculating the <code>MAST Root</code> are counted towards the 201 <code>nOpCount</code> limit to prevent abusive use. This limitation is not applied to undefined <code>MAST Version</code> for flexibility, but it is constrained by the 255 <code>Subscript</code> and 32 <code>Depth</code> limits.
+
+=== Script evaluation ===
+This proposal requires script evaluation resulting in an empty stack, instead of a single <code>TRUE</code> value as in P2WSH. This allows each party in a contract to provide its own <code>Subscript</code>, and demonstrate the required <code>Input Stack</code> to clean up its own <code>Subscript</code>. In this case, order of the <code>Subscript</code> is not important since the overall objective is to clean up the stack after evaluation.
== Examples ==
=== Calculation of MAST Root ===
-To calculate the MAST Root for 4 branches, the double-SHA256 of each branch is first calculated:
- <1> EQUAL (0x5187), HASH256=3b647cb856a965fa6feffb4621eb2a4f4c2453693b2f64e021383ccbd80a1abb
- <2> EQUAL (0x5287), HASH256=37772654bdce9b3d59e1169ea16ddbaa8a2ae8ee265db64863d0b76f02c882fa
- <3> EQUAL (0x5387), HASH256=2e972642436151cd96e4b0868077b6362ffb5eb30b420a6f1c5e1c6fff02bc33
- <4> EQUAL (0x5487), HASH256=4c954fc1e635ce8417341465f85b59d700806f6e57bb96b2a25bec5ca3f9f154
-Serialize the hashes of the first pair and calculate the hash. Same for the other pair:
- HASH256(HASH256(5187)|HASH256(5287)) = 64fbdfc0a82ecc3b33434bfea63440e9a5275fa5e533200d2eaf18281e8b28b6
- HASH256(HASH256(5387)|HASH256(5487)) = aeadea837d5e640a1444208f7aca3be63bc8ab3c6b28a19878a00cc9c631ac31
+<img src=bip-0114/mastexample.png></img>
+
+
+ Subscript:
+ SA = 1 EQUALVERIFY (0x5188)
+ SB = 2 EQUALVERIFY (0x5288)
+ SC = 3 EQUALVERIFY (0x5388)
+ SD = 4 EQUALVERIFY (0x5488)
+ SE = 5 EQUALVERIFY (0x5588)
+ SF = 6 EQUALVERIFY (0x5688)
+ SG = 7 EQUALVERIFY (0x5788)
+ SH = 8 EQUALVERIFY (0x5888)
+ M = RETURN "Hello" (0x6a0548656c6c6f)
+ Hash:
+ HA = H(0x01|H(SA)) = H(0x015acb54166e0db370cd1b05a29120373568dacea2abc3748459ec3da2106e4b4e) = 0xd385d7268ad7e1ec51660f833d54787d2d8d79b6b1809d9c1d06c9e71f7be204
+ HB = H(0x02|H(SB)|H(SC)) = 0x7cbfa08e44ea9f4f996873be95d9bffd97d4b91a5af32cc5f64efb8461727cdd
+ HF = H(0x03|H(SD)|H(SE)|H(SF)) = 0x4611414355945a7c2fcc62a53a0004821b87e68f93048ffba7a55a3cb1e9783b
+ HG = H(0x01|H(SG)) = 0xaa5fbdf58264650eadec33691ba1e7606d0a62f570eea348a465c55bc86ffc10
+ HC = H(0x01|H(M)) = 0x70426d480d5b28d93c5be54803681f99abf4e8df4eab4dc87aaa543f0d138159
+ HD = H(0x0x|H(SH)) = 0x8482f6c9c3fe90dd4d533b4efedb6a241b95ec9267d1bd5aaaee36d2ce2dd6da
+ HE = H(HA|HB) = 0x049b9f2f94f0a9bdea624e39cd7d6b27a365c6a0545bf0e9d88d86eff4894210
+ HH = H(HC|HD) = 0xc709fdc632f370f3367da45378d1cf430c5fda6805e731ad5761c213cf2d276e
+ HI = H(HE|HF) = 0xead5e1a1e7e41b77b794f091df9be3f0e9f41d47304eb43dece90688f69843b7
+ HJ = H(HG|HH) = 0xd00fc690c4700d0f983f9700740066531ea826b21a4cbc62f80317261723d477
+ Script Root = H(HI|HJ) = 0x26d5235d20daf1440a15a248f5b5b4f201392128072c55afa64a26ccc6f56bd9
+ MAST Root = H(MAST Version|Script Root) = H(0x0000000026d5235d20daf1440a15a248f5b5b4f201392128072c55afa64a26ccc6f56bd9) = 0xb4b706e0c02eab9aba58419eb7ea2a286fb1c01d7406105fc12742bf8a3f97c9
-Serialize the 2 hashes from the previous step and calculate the hash, which is the <code>MAST Root</code>:
- MAST Root = 6746003b5c9d342b2c210d406802c351e7eb5943412dcfc4718be625a8a59c0e
The scriptPubKey with native witness program is:
- <1> <0x6746003b5c9d342b2c210d406802c351e7eb5943412dcfc4718be625a8a59c0e>
- (0x51206746003b5c9d342b2c210d406802c351e7eb5943412dcfc4718be625a8a59c0e)
-To redeem with the <code><4> EQUAL</code> branch, the witness is
- 04 (Stack for evaluation)
- 03 (Position)
- 2e972642436151cd96e4b0868077b6362ffb5eb30b420a6f1c5e1c6fff02bc3364fbdfc0a82ecc3b33434bfea63440e9a5275fa5e533200d2eaf18281e8b28b6 (Path)
- 5487 (MAST Script)
+ 1 <0xb4b706e0c02eab9aba58419eb7ea2a286fb1c01d7406105fc12742bf8a3f97c9>
+ (0x5120b4b706e0c02eab9aba58419eb7ea2a286fb1c01d7406105fc12742bf8a3f97c9)
+
+
+To redeem with the <code>SD|SE|SF</code> branch, the witness is
+
+ Script_stack_1: 0x06
+ Script_stack_2: 0x05
+ Script_stack_3: 0x04
+ Subscript_1: 0x5488
+ Subscript_2: 0x5588
+ Subscript_3: 0x5688
+ Position: 0x01 (HF is the second hash in its level)
+ Path (HE|HJ): 0x049b9f2f94f0a9bdea624e39cd7d6b27a365c6a0545bf0e9d88d86eff4894210d00fc690c4700d0f983f9700740066531ea826b21a4cbc62f80317261723d477
+ Metadata: 0x03 (3 Subscript)
+
+
=== Imbalance MAST ===
-When constructing a MAST, if the user believes that some of the branches are more likely to be executed, they may put them closer to the <code>MAST Root</code>. It will save some witness space when the preferred branches are actually executed.
+When constructing a MAST, if the user believes that some of the branches are more likely to be executed, they may put them closer to the <code>Script Root</code>. It will save some witness space when the preferred branches are actually executed.
=== Escrow with Timeout ===
The following is the "Escrow with Timeout" example in [[bip-0112.mediawiki|BIP112]]:
IF
- 2 <Alice's pubkey> <Bob's pubkey> <Escrow's pubkey> 3 CHECKMULTISIGVERIFY
+ 2 <Alice's pubkey> <Bob's pubkey> <Escrow's pubkey> 3 CHECKMULTISIG
ELSE
"30d" CHECKSEQUENCEVERIFY DROP
- <Alice's pubkey> CHECKSIGVERIFY
+ <Alice's pubkey> CHECKSIG
ENDIF
Using compressed public key, the size of this script is 150 bytes.
-With MAST, this script could be broken down into 2 mutually exclusive branches:
+With MAST, this script could be broken down into 2 mutually exclusive branches:<ref>In BIPXXX, it is proposed that CHECKLOCKTIMEVERIFY and CHECKSEQUENCEVERIFY will pop the top stack item</ref>
2 <Alice's pubkey> <Bob's pubkey> <Escrow's pubkey> 3 CHECKMULTISIGVERIFY (105 bytes)
- "30d" CHECKSEQUENCEVERIFY DROP <Alice's pubkey> CHECKSIGVERIFY (42 bytes)
+ "30d" CHECKSEQUENCEVERIFY <Alice's pubkey> CHECKSIGVERIFY (42 bytes)
-With 2 branches, the <code>Path</code> will be 32 bytes (as the hash of the unexecuted branch), and the <code>Position</code> will be 1 byte as either 0 or 1. Since only one branch will be published, it is more difficult for a blockchain analyst to determine the details of the escrow.
+Since only one branch will be published, it is more difficult for a blockchain analyst to determine the details of the escrow.
=== Hashed Time-Lock Contract ===
The following is the "Hashed TIme-Lock Contract" example in [[bip-0112.mediawiki|BIP112]]:
@@ -107,16 +208,16 @@ The following is the "Hashed TIme-Lock Contract" example in [[bip-0112.mediawiki
CHECKSIG
To create a MAST Root, it is flattened to 3 mutually exclusive branches:
- HASH160 <R-HASH> EQUALVERIFY "24h" CHECKSEQUENCEVERIFY DROP <Alice's pubkey> CHECKSIG
- HASH160 <Commit-Revocation-Hash> EQUALVERIFY <Bob's pubkey> CHECKSIG
- "Timestamp" CHECKLOCKTIMEVERIFY DROP <Bob's pubkey> CHECKSIG
+ HASH160 <R-HASH> EQUALVERIFY "24h" CHECKSEQUENCEVERIFY <Alice's pubkey> CHECKSIGVERIFY
+ HASH160 <Commit-Revocation-Hash> EQUALVERIFY <Bob's pubkey> CHECKSIGVERIFY
+ "Timestamp" CHECKLOCKTIMEVERIFY <Bob's pubkey> CHECKSIGVERIFY
which significantly improves readability and reduces the witness size when it is redeemed.
=== Large multi-signature constructs ===
-The current CHECKMULTISIG supports up to 20 public keys. Although it is possible to extend it beyond 20 keys by using multiple CHECKSIGs and IF/ELSE conditions, the construction could be very complicated and soon use up the 10,000 bytes and 201 op codes limit.
+The current CHECKMULTISIG supports up to 20 public keys. Although it is possible to extend it beyond 20 keys by using multiple CHECKSIGs and IF/ELSE conditions, the construction could be very complicated and soon use up the 10,000 bytes and 201 <code>nOpCount</code> limit.
-With MAST, large and complex multi-signature constructs could be flattened to many simple CHECKMULTISIG conditions. For example, a 3-of-2000 multi-signature scheme could be expressed as 1,331,334,000 3-of-3 CHECKMULTISIGs, which forms a 31-level MAST. The scriptPubKey still maintains a fixed size of 34 bytes, and the redemption witness will be very compact, with less than 1,500 bytes.
+With MAST, large and complex multi-signature constructs could be flattened to many simple CHECKMULTISIGVERIFY conditions. For example, a 3-of-2000 multi-signature scheme could be expressed as 1,331,334,000 3-of-3 CHECKMULTISIGVERIFY, which forms a 31-level MAST. The scriptPubKey still maintains a fixed size of 34 bytes, and the redemption witness will be very compact, with less than 1,500 bytes.
=== Commitment of non-consensus enforced data ===
Currently, committing non-consensus enforced data in the scriptPubKey requires the use of OP_RETURN which occupies additional block space. With MAST, users may commit such data as a branch. Depends on the number of executable branches, inclusion of such a commitment may incur no extra witness space, or 32 bytes at most.
@@ -133,76 +234,121 @@ This BIP depends on [[bip-0141.mediawiki|BIP141]] and will be deployed by versio
The idea of MAST originates from Russell O’Connor, Pieter Wuille, and [https://bitcointalk.org/index.php?topic=255145.msg2757327#msg2757327 Peter Todd].
== Reference Implementation ==
-https://github.com/jl2012/bitcoin/tree/segwit_mast
+https://github.com/jl2012/bitcoin/tree/bip114v2 (WIP)
<source lang="cpp">
//New rules apply if version byte is 1 and witness program size is 32 bytes
-if (witversion == 1) {
- if (program.size() == 32) {
-
- //Witness stack must have at least 3 items
- if (witness.stack.size() < 3)
- return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH);
-
- //Script is the last witness stack item
- scriptPubKey = CScript(witness.stack.back().begin(), witness.stack.back().end());
- uint256 hashScriptPubKey;
- CHash256().Write(&scriptPubKey[0], scriptPubKey.size()).Finalize(hashScriptPubKey.begin());
-
- //Path is the second last witness stack item
- std::vector<unsigned char> pathdata = witness.stack.at(witness.stack.size() - 2);
-
- // Size of Path must be a multiple of 32 bytes (0 byte is allowed)
- if (pathdata.size() & 0x1F)
- return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH);
-
- // Depth of the tree is size of Path divided by 32
- unsigned int depth = pathdata.size() >> 5;
-
- // Maximum allowed depth is 32
- if (depth > 32)
- return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH);
- std::vector<uint256> path;
- path.resize(depth);
- for (unsigned int i = 0; i < depth; i++)
- memcpy(path[i].begin(), &pathdata[32 * i], 32);
-
- //Position is the third last witness stack item
- std::vector<unsigned char> positiondata = witness.stack.at(witness.stack.size() - 3);
-
- //Position may have 4 bytes at most
- if (positiondata.size() > 4)
- return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH);
-
- uint32_t position = 0;
-
- //Position is an unsigned little-endian integer with no leading zero byte
- if (positiondata.size() > 0) {
- if (positiondata.back() == 0x00)
- return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH);
- for (size_t i = 0; i != positiondata.size(); ++i)
- position |= static_cast<uint32_t>(positiondata[i]) << 8 * i;
- }
+if (witversion == 1 && program.size() == 32 && (flags & SCRIPT_VERIFY_MAST)) {
+ CHashWriter sRoot(SER_GETHASH, 0);
+ CHashWriter sScriptHash(SER_GETHASH, 0);
+ uint32_t nMASTVersion = 0;
+ size_t stacksize = witness.stack.size();
+ if (stacksize < 4)
+ return set_error(serror, SCRIPT_ERR_INVALID_MAST_STACK);
+ std::vector<unsigned char> metadata = witness.stack.back(); // The last witness stack item is metadata
+ if (metadata.size() < 1 || metadata.size() > 5)
+ return set_error(serror, SCRIPT_ERR_INVALID_MAST_STACK);
+
+ // The first byte of metadata is the number of subscripts (1 to 255)
+ uint32_t nSubscript = static_cast<uint32_t>(metadata[0]);
+ if (nSubscript == 0 || stacksize < nSubscript + 3)
+ return set_error(serror, SCRIPT_ERR_INVALID_MAST_STACK);
+ int nOpCount = nSubscript; // Each condition consumes a nOpCount
+ sScriptHash << metadata[0];
+
+ // The rest of metadata is MAST version in minimally-coded unsigned little endian int
+ if (metadata.back() == 0)
+ return set_error(serror, SCRIPT_ERR_INVALID_MAST_STACK);
+ if (metadata.size() > 1) {
+ for (size_t i = 1; i != metadata.size(); ++i)
+ nMASTVersion |= static_cast<uint32_t>(metadata[i]) << 8 * (i - 1);
+ }
- //Position must not be larger than the maximum number of items allowed by the depth of tree
- if (depth < 32) {
- if (position >= (1U << depth))
- return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH);
- }
+ // Unknown MAST version is non-standard
+ if (nMASTVersion > 0 && flags & SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM)
+ return set_error(serror, SCRIPT_ERR_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM);
+
+ sRoot << nMASTVersion;
+
+ // The second last witness stack item is the pathdata
+ // Size of pathdata must be divisible by 32 (0 is allowed)
+ // Depth of the Merkle tree is implied by the size of pathdata, and must not be greater than 32
+ std::vector<unsigned char> pathdata = witness.stack.at(stacksize - 2);
+ if (pathdata.size() & 0x1F)
+ return set_error(serror, SCRIPT_ERR_INVALID_MAST_STACK);
+ unsigned int depth = pathdata.size() >> 5;
+ if (depth > 32)
+ return set_error(serror, SCRIPT_ERR_INVALID_MAST_STACK);
+
+ // Each level of Merkle tree consumes a nOpCount
+ // Evaluation of version 0 MAST terminates early if there are too many nOpCount
+ // Not enforced in unknown MAST version for upgrade flexibility
+ nOpCount = nOpCount + depth;
+ if (nMASTVersion == 0 && nOpCount > MAX_OPS_PER_SCRIPT)
+ return set_error(serror, SCRIPT_ERR_OP_COUNT);
+
+ // path is a vector of 32-byte hashes
+ std::vector <uint256> path;
+ path.resize(depth);
+ for (unsigned int j = 0; j < depth; j++)
+ memcpy(path[j].begin(), &pathdata[32 * j], 32);
+
+ // The third last witness stack item is the positiondata
+ // Position is in minimally-coded unsigned little endian int
+ std::vector<unsigned char> positiondata = witness.stack.at(stacksize - 3);
+ if (positiondata.size() > 4)
+ return set_error(serror, SCRIPT_ERR_INVALID_MAST_STACK);
+ uint32_t position = 0;
+ if (positiondata.size() > 0) {
+ if (positiondata.back() == 0)
+ return set_error(serror, SCRIPT_ERR_INVALID_MAST_STACK);
+ for (size_t k = 0; k != positiondata.size(); ++k)
+ position |= static_cast<uint32_t>(positiondata[k]) << 8 * k;
+ }
- //Calculate the Merkle Root and compare with the witness program
- uint256 root = ComputeMerkleRootFromBranch(hashScriptPubKey, path, position);
- if (memcmp(root.begin(), &program[0], 32))
- return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH);
+ // Position value must not exceed the number of leaves at the depth
+ if (depth < 32) {
+ if (position >= (1U << depth))
+ return set_error(serror, SCRIPT_ERR_INVALID_MAST_STACK);
+ }
- //Remaining stack items used for evaluation
- stack = std::vector<std::vector<unsigned char> >(witness.stack.begin(), witness.stack.end() - 3);
+ // Sub-scripts are located before positiondata
+ for (size_t i = stacksize - nSubscript - 3; i <= stacksize - 4; i++) {
+ CScript subscript(witness.stack.at(i).begin(), witness.stack.at(i).end());
+
+ // Evaluation of version 0 MAST terminates early if script is oversize
+ // Not enforced in unknown MAST version for upgrade flexibility
+ if (nMASTVersion == 0 && (scriptPubKey.size() + subscript.size()) > MAX_SCRIPT_SIZE)
+ return set_error(serror, SCRIPT_ERR_SCRIPT_SIZE);
+ uint256 hashSubScript;
+ CHash256().Write(&subscript[0], subscript.size()).Finalize(hashSubScript.begin());
+ sScriptHash << hashSubScript;
+ scriptPubKey = scriptPubKey + subscript; // Final scriptPubKey is a serialization of subscripts
}
+ uint256 hashScript = sScriptHash.GetHash();
+
+ // Calculate MAST Root and compare against witness program
+ uint256 rootScript = ComputeMerkleRootFromBranch(hashScript, path, position);
+ sRoot << rootScript;
+ uint256 rootMAST = sRoot.GetHash();
+ if (memcmp(rootMAST.begin(), &program[0], 32))
+ return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH);
+
+ if (nMASTVersion == 0) {
+ stack = std::vector<std::vector<unsigned char> >(witness.stack.begin(), witness.stack.end() - 3 - nSubscript);
+ for (unsigned int i = 0; i < stack.size(); i++) {
+ if (stack.at(i).size() > MAX_SCRIPT_ELEMENT_SIZE)
+ return set_error(serror, SCRIPT_ERR_PUSH_SIZE);
+ }
- else {
- //Invalid if version byte is 1 but witness program size is not 32 bytes
- return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_WRONG_LENGTH);
+ // Script evaluation must not fail, and return an empty stack
+ if (!EvalScript(stack, scriptPubKey, flags, checker, SIGVERSION_WITNESS_V1, nOpCount, serror))
+ return false;
+ if (stack.size() != 0)
+ return set_error(serror, SCRIPT_ERR_EVAL_FALSE);
}
+
+ return set_success(serror);
}
</source>
diff --git a/bip-0114/mastexample.png b/bip-0114/mastexample.png
new file mode 100644
index 0000000..9bff7b9
--- /dev/null
+++ b/bip-0114/mastexample.png
Binary files differ
diff --git a/bip-0125.mediawiki b/bip-0125.mediawiki
index 7d88469..52dfe40 100644
--- a/bip-0125.mediawiki
+++ b/bip-0125.mediawiki
@@ -3,7 +3,7 @@
Title: Opt-in Full Replace-by-Fee Signaling
Author: David A. Harding <dave@dtrt.org>
Peter Todd <pete@petertodd.org>
- Status: Draft
+ Status: Accepted
Type: Standards Track
Created: 2015-12-04
</pre>
diff --git a/bip-0130.mediawiki b/bip-0130.mediawiki
index 56184e3..ae1e602 100644
--- a/bip-0130.mediawiki
+++ b/bip-0130.mediawiki
@@ -2,7 +2,7 @@
BIP: 130
Title: sendheaders message
Author: Suhas Daftuar <sdaftuar@chaincode.com>
- Status: Draft
+ Status: Accepted
Type: Standards Track
Created: 2015-05-08
</pre>
diff --git a/bip-0132.mediawiki b/bip-0132.mediawiki
index 90c09b1..03cc834 100644
--- a/bip-0132.mediawiki
+++ b/bip-0132.mediawiki
@@ -2,7 +2,7 @@
BIP: 132
Title: Committee-based BIP Acceptance Process
Author: Andy Chase <theandychase@gmail.com>
- Status: Draft
+ Status: Withdrawn
Type: Process
Created: 2015-08-31
</pre>
diff --git a/bip-0146.mediawiki b/bip-0146.mediawiki
new file mode 100644
index 0000000..c92c54e
--- /dev/null
+++ b/bip-0146.mediawiki
@@ -0,0 +1,79 @@
+<pre>
+ BIP: 146
+ Title: Dealing with signature malleability
+ Author: Pieter Wuille <pieter.wuille@gmail.com>
+ Johnson Lau <jl2012@xbt.hk>
+ Status: Draft
+ Type: Standards Track
+ Created: 2016-08-16
+</pre>
+
+==Abstract==
+
+This document specifies proposed changes to the Bitcoin transaction validity rules to fix signature malleability for common transaction types.
+
+
+==Motivation==
+
+Signature malleability refers to the ability of any relay node on the network to transform the signature in transactions, with no access to the relevant private keys required. For non-segregated witness transactions, signature malleability will change the <code>txid</code> and invalidate any unconfirmed child transactions. Although the <code>txid</code> of segregated witness ([https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki BIP141]) transactions is not third party malleable, this malleability vector will change the <code>wtxid</code> and may reduce the efficiency of compact block relay ([https://github.com/bitcoin/bips/blob/master/bip-0152.mediawiki BIP152]).
+
+Since the enforcement of Strict DER signatures ([https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki BIP66]), there are 2 remaining known sources of malleability in the signature passed to ECDSA verification opcodes:
+
+# '''Inherent ECDSA signature malleability''': ECDSA signatures are inherently malleable as taking the negative of the number S inside (modulo the curve order) does not invalidate it.
+
+# '''Inputs ignored by scripts''': The (unnecessary) extra stack element consumed by <code>OP_CHECKMULTISIG</code> and <code>OP_CHECKMULTISIGVERIFY</code> is not inspected in any manner, and could be replaced with any value.
+
+This document specifies new rules to fix the aforesaid signature malleability.
+
+
+==Specification==
+
+To fix signature malleability, the following new rules are applied:
+
+
+===LOW_S===
+
+We require that the S value inside ECDSA signatures is at most the curve order divided by 2 (essentially restricting this value to its lower half range). Every signature passed to <code>OP_CHECKSIG</code><ref>Including pay-to-witness-public-key-hash (P2WPKH) described in BIP141</ref>, <code>OP_CHECKSIGVERIFY</code>, <code>OP_CHECKMULTISIG</code>, or <code>OP_CHECKMULTISIGVERIFY</code>, to which ECDSA verification is applied, MUST use a S value between <code>0x1</code> and <code>0x7FFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF 5D576E73 57A4501D DFE92F46 681B20A0</code> (inclusive) with strict DER encoding (see [https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki BIP66]).
+
+These operators all perform ECDSA verifications on pubkey/signature pairs, iterating from the top of the stack backwards. For each such verification, if the signature does not pass the Low S value check, the entire script evaluates to false immediately. If the signature is valid DER with low S value, but does not pass ECDSA verification, opcode execution continues as it used to, causing opcode execution to stop and push false on the stack (but not immediately fail the script) in some cases, which potentially skips further signatures (and thus does not subject them to Low S value check).
+
+A high S value in signature could be trivially replaced by <code>S' = 0xFFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE BAAEDCE6 AF48A03B BFD25E8C D0364141 - S</code>.
+
+
+===NULLDUMMY===
+
+The extra stack element consumed by <code>OP_CHECKMULTISIG</code> and <code>OP_CHECKMULTISIGVERIFY</code> MUST be the empty byte array (the result of <code>OP_0</code>). Anything else makes the script evaluate to false immediately.
+
+
+==Deployment==
+
+This BIP will be deployed by "version bits" [https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki BIP9] using the same parameters for BIP141 and BIP143, with the name "segwit" and using bit 1.
+
+For Bitcoin mainnet, the BIP9 starttime will be midnight TBD UTC (Epoch timestamp TBD) and BIP9 timeout will be midnight TBD UTC (Epoch timestamp TBD).
+
+For Bitcoin testnet, the BIP9 starttime will be midnight 1 May 2016 UTC (Epoch timestamp 1462060800) and BIP9 timeout will be midnight 1 May 2017 UTC (Epoch timestamp 1493596800).
+
+
+==Compatibility==
+
+The reference client has produced compatible signatures since v0.9.0, and NULLDUMMY and LOW_S have been enforced as relay policy by the reference client since v0.10.0 and v0.11.1 respectively. As of August 2016, very few transactions violating the requirement are being added to the chain. In addition, every non-compliant signature can trivially be converted into a compliant one, so there is no loss of functionality by this requirement.
+
+
+==Implementation==
+
+An implementation for the reference client is available at https://github.com/bitcoin/bitcoin/pull/8533
+
+
+==Footnotes==
+
+<references />
+
+
+==Acknowledgements==
+
+This document is extracted from the previous [https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki BIP62] proposal which had input from various people.
+
+
+==Copyright==
+
+This document is placed in the public domain.
diff --git a/bip-0150.mediawiki b/bip-0150.mediawiki
new file mode 100644
index 0000000..b1d46c1
--- /dev/null
+++ b/bip-0150.mediawiki
@@ -0,0 +1,174 @@
+<pre>
+ BIP: 150
+ Title: Peer Authentication
+ Author: Jonas Schnelli <dev@jonasschnelli.ch>
+ Status: Draft
+ Type: Standards Track
+ Created: 2016-03-23
+</pre>
+
+== Abstract ==
+
+This BIP describes a way for peers to authenticate to other peers to guarantee node ownership and/or allow peers to access additional or limited node services, without the possibility of fingerprinting.
+
+== Motivation ==
+
+We assume peer operators want to limit the access of different node services or increase datastream priorities to a selective subset of peers. Also we assume that peers want to connect to specific peers to broadcast or filter transactions (or similar actions that reveal sensitive informations) and therefore operators want to authenticate the remote peer and ensure that they have not connected to a MITM (man-in-the-middle) attacker.
+
+Benefits of peer authentication:
+* Peers can detect MITM attacks when connecting to known peers
+* Peers can allow resource hungry transaction filtering only to specific peers
+* Peers can allow access to sensitive information that can lead to node fingerprinting (fee estimation)
+* Peers can allow custom message types (private extensions) to authenticated peers
+
+A simple authentication scheme based on elliptic cryptography will allow peers to identify each other and selectively allow access to restricted services or reject the connection if the peer identity cannot be verified.
+
+== Specification ==
+
+The authentication scheme proposed in this BIP uses ECDSA, '''secrets will never be transmitted'''.
+
+'''Authentication initialization must only happen if encrypted channels have been established (according to BIP-151 [1]).'''
+
+The '''encryption-session-ID''' is available once channels are encrypted (according to BIP-151 [1]).
+
+The identity-public-keys used for the authentication must be pre-shared over a different channel (mail/PGP, physical paper exchange, etc.). This BIP does not cover a "trust on first use" (TOFU) concept.
+
+The authentication state must be kept until the encryption/connection terminates.
+
+Only one authentication process is allowed per connection. Re-authentication require re-establishing the connection.
+
+=== Known-peers and authorized-peers database ===
+Each peer that supports p2p authentication must provide two user-editable "databases".
+
+# '''known-peers''' contains known identity-public-keys together with a network identifier (IP & port), similar to the "known-host" file supported by openssh.
+# '''authorized-peers''' contains authorized identity-public-keys
+
+=== Local identity key management ===
+Each peer can configure multiple identity-keys (ECC, 32 bytes). Peers should make sure that each network interface (IPv4, IPv6, tor) has its own identity-key (otherwise it would be possible to link a tor address to a IPvX address).
+The identity-public-key(s) can be shared over a different channel with other node-operators (or non-validating clients) to grant authorized access.
+
+=== Authentication procedure ===
+Authentication based on this BIP will require both sides to authenticate. Signatures/public-keys will only be revealed if the remote peer can prove that they already know the remote identity-public-key.
+
+# -> Requesting peer sends <code>AUTHCHALLENGE</code> (hash)
+# <- Responding peer sends <code>AUTHREPLY</code> (signature)
+# -> Requesting peer sends <code>AUTHPROPOSE</code> (hash)
+# <- Responding peer sends <code>AUTHCHALLENGE</code> (hash)
+# -> Requesting peer sends <code>AUTHREPLY</code> (signature)
+
+For privacy reasons, dropping the connection or aborting during the authentication process must not be allowed.
+
+=== <code>AUTHCHALLENGE</code> message ===
+A peer can send an authentication challenge to see if the responding peer can produce a valid signature with the expected responding peer's identity-public-key by sending an <code>AUTHCHALLENGE</code>-message to the remote peer.
+
+The responding peer needs to check if the hash matches the hash calculated with his own local identity-public-key. Fingerprinting the requesting peer is not possible.
+
+{|class="wikitable"
+! Field Size !! Description !! Data type !! Comments
+|-
+| 32bytes || challenge-hash || hash || <code>hash(encryption-session-ID || challenge_type || remote-peers-expected-identity-public-key)</code>
+|}
+
+
+<code>challenge_type</code> is a single character. <code>i</code> if the <code>AUTHCHALLENGE</code>-message is the first, requesting challenge or <code>r</code> if it's the second, remote peers challenge message.
+
+=== <code>AUTHREPLY</code> message ===
+A peer must reply an <code>AUTHCHALLENGE</code>-message with an <code>AUTHREPLY</code>-message.
+
+{|class="wikitable"
+! Field Size !! Description !! Data type !! Comments
+|-
+| 64bytes || signature || normalized comp.-signature || A signature of the encryption-session-ID done with the identity-key
+|}
+
+If the challenge-hash from the <code>AUTHCHALLENGE</code>-message did not match the local authentication public-key, the signature must contain 64 bytes of zeros.
+
+The requesting peer can check the responding peer's identity by checking the validity of the sent signature against with the pre-shared remote peers identity-public-key.
+
+If the signature was invalid, the requesting peer must still proceed with the authentication by sending an <code>AUTHPROPOSE</code>-message with 32 random bytes.
+
+=== <code>AUTHPROPOSE</code> message ===
+A peer can propose authentication of the channel by sending an <code>AUTHPROPOSE</code>-message to the remote peer.
+
+If the signature sent in <code>AUTHREPLY</code> was invalid, the peer must still send an <code>AUTHPROPOSE</code>-message containing 32 random bytes.
+
+The <code>AUTHPROPOSE</code> message must be answered with an <code>AUTHCHALLENGE</code>-message - even if the proposed requesting-peers identity-public-key has not been found in the authorized-peers database. In case of no match, the responding <code>AUTHCHALLENGE</code>-message must contains 32 bytes of zeros.
+
+{|class="wikitable"
+! Field Size !! Description !! Data type !! Comments
+|-
+| 32bytes || auth-propose-hash || hash || <code>hash(encryption-session-ID || "p" || identity-public-key)</code>
+|}
+
+== Post-Authentication Re-Keying ==
+
+After the second <code>AUTHREPLY</code> message (requesting peer's signature -> responding peer), both clients must re-key the symmetric encryption according to BIP151 while using '''a slightly different re-key key derivation hash'''.
+
+Both peers re-key with <code>hash(encryption-session-ID || old_symmetric_cipher_key || requesting-peer-identity-public-key || responding-peer-identity-public-key)</code>
+
+== Identity-Addresses ==
+The peers should display/log the identity-public-key as an identity-address to the users, which is a base58-check encoded ripemd160(sha256) hash. The purpose of this is for better visual comparison (logs, accept-dialogs).
+The base58check identity byte is <code>0x0F</code> followed by an identity-address version number (=<code>0xFF01</code>).
+
+An identity address would look like <code>TfG4ScDgysrSpodWD4Re5UtXmcLbY5CiUHA</code> and can be interpreted as a remote peer's fingerprint.
+
+== Compatibility ==
+
+This proposal is backward compatible. Non-supporting peers will ignore the new <code>AUTH*</code> messages.
+
+== Example of an auth interaction ==
+
+Before authentication (once during peer setup or upgrade)
+# Requesting peer and responding peer create each an identity-keypair (standard ECC priv/pubkey)
+# Requesting and responding peer share the identity-public-key over a different channel (mail/PGP, physical paper exchange, etc.)
+# Responding peer stores requesting peers identity-public-key in its authorized-peers database (A)
+# Requesting peer stores responding peers identity-public-key in its known-peers database together with its IP and port (B)
+
+Encryption
+# Encrypted channels must be established (according to BIP-151 [1])
+
+Authentication
+# Requesting peer sends an <code>AUTHCHALLENGE</code> message
+ AUTHCHALLENGE:
+ [32 bytes, hash(encryption-session-ID || "i" || <remote-peers-expected-identity-public-key>)]
+
+# Responding peer does create the same hash <code>(encryption-session-ID || "i" || <remote-peers-expected-identity-public-key>)</code> with its local identity-public-key
+# If the hash does not match, response with an <code>AUTHREPLY</code> message containing 64bytes of zeros.
+# In case of a match, response with an <code>AUTHREPLY</code> message
+ AUTHREPLY:
+ [64 bytes normalized compact ECDSA signature (H)] (sig of the encryption-session-ID done with the identity-key)
+
+# Requesting peer does verify the signature with the <code>remote-peers-identity-public-key</code>
+# If the signature is invalid, requesting peer answers with an <code>AUTHREPLY</code> message containing 32 random bytes
+# In case of a valid signature, requesting peer sends an <code>AUTHPROPOSE</code> message
+ AUTHPROPOSE:
+ [32 bytes, hash(encryption-session-ID || "p" || <client-identity-public-key>)]
+
+# Responding peer iterates over authorized-peers database (A), hashes the identical data and looks for a match.
+# If the hash does not match, responding peer answer with an <code>AUTHCHALLENGE</code> message containing 32 bytes of zeros.
+# In case of a match, responding peer sends an <code>AUTHCHALLENGE</code> message with the hashed client public-key
+ AUTHCHALLENGE:
+ [32 bytes, hash(encryption-session-ID || "r" || <client-identity-public-key>)]
+# Requesting peer sends an <code>AUTHREPLY</code> message containing 64 bytes of zeros if server failed to authenticate
+# Otherwise, response with signature in the <code>AUTHREPLY</code> message
+ AUTHREPLY:
+ [64 bytes normalized compact ECDSA signature (H)] (sig of the encryption-session-ID done with the identity-key)
+# Responding peer must verify the signature and can grant access to restricted services.
+# Both peers re-key the encryption after BIP151 including the requesting-peer-identity-public-key and responding-peer-identity-public-key
+
+== Disadvantages ==
+
+The protocol may be slow if a peer has a large authorized-peers database due to the requirement of iterating and hashing over all available authorized peer identity-public-keys.
+
+== Reference implementation ==
+
+== References ==
+
+* [1] [[bip-0151.mediawiki|BIP 151: Peer-to-Peer Communication Encryption]]
+
+== Acknowledgements ==
+* Gregory Maxwell and Pieter Wuille for most of the ideas in this BIP.
+* Bryan Bishop for editing.
+
+== Copyright ==
+This work is placed in the public domain.
diff --git a/bip-0151.mediawiki b/bip-0151.mediawiki
index a4c8b8e..cf221f2 100644
--- a/bip-0151.mediawiki
+++ b/bip-0151.mediawiki
@@ -39,7 +39,7 @@ Encryption initialization must happen before sending any other messages to the r
The symmetric encryption cipher keys will be calculated with ECDH/HKDF by sharing the pubkeys of a ephemeral key. Once the ECDH secret is calculated on each side, the symmetric encryption cipher keys must be derived with HKDF [2] after the following specification:
1. HKDF extraction
-<code>PRK = HKDF_EXTRACT(hash=SHA256, salt="bitcoinechd", ikm=ecdh_secret|cipher-type)</code>.
+<code>PRK = HKDF_EXTRACT(hash=SHA256, salt="bitcoinecdh", ikm=ecdh_secret|cipher-type)</code>.
2. Derive Key1
<code>K_1 = HKDF_EXPAND(prk=PRK, hash=SHA256, info="BitcoinK1", L=32)</code>
@@ -148,7 +148,7 @@ If more data is present, another message must be deserialized. There is no expli
A responding peer can inform the requesting peer over a re-keying with a <code>encack</code> message containing 33byte of zeros to indicate that all encrypted message following after this <code>encack</code> message will be encrypted with ''the next symmetric cipher key''.
-The new symmetric cipher key will be calculated by <code>SHA256(SHA256(old_symetric_cipher_key))</code>.
+The new symmetric cipher key will be calculated by <code>SHA256(SHA256(session_id || old_symmetric_cipher_key))</code>.
Re-Keying interval is a peer policy with a minimum timespan of 10 seconds.