Skip to content
BIP ATLAS

BIPs 0066 · 0146

Why must a signature have exactly one encoding?

An ECDSA signature is two numbers written as bytes. If the same numbers can be written in more than one way, anyone relaying a transaction can change its bytes, and with them its ID. BIP 66 allows one encoding; BIP 146 proposed closing the gaps that remained.

An ECDSA signature in a Bitcoin transaction is two numbers, R and S, written in DER, a standard binary encoding. When BIP 66 was written in 2015, the reference client checked signatures with OpenSSL, whose releases had until then accepted various deviations from DER as valid. The same two numbers could be written in more than one way, and which ways a node accepted depended on its OpenSSL version.123

That caused two problems. When OpenSSL tightened its parsing, some nodes rejected the chain. And anyone relaying a transaction could rewrite a signature's bytes without the private key, changing the transaction's ID. BIP 66 makes exactly one encoding valid. BIP 146 proposed closing the two gaps that strict encoding leaves open.234567

Source revision
bitcoin/bips @ 3a10b5b
Source checked
8 November 2026
Review state
Technical review applied, awaiting sign-off
Source details

This chapter is an independent explanation, not the proposal itself. Preamble fields are shown as the pinned files record them, without author e-mail addresses. Status is the proposal’s own field. It is not an endorsement or a sign of consensus.

BIP 66: Strict DER signatures

BIP
66
Layer
Consensus (soft fork)
Title
Strict DER signatures
Authors
Pieter Wuille
Status
Deployed
Type
Specification
Assigned
2015-01-10
License
BSD-2-Clause

Pinned source · Reader view on bips.dev
SHA-256 c42d25a3aa18341212c53065131d415f6ed3bb10166a63def9002f300c98a3be
Git blob aa41b75713e0b4e7fe22318237ca568d34920cbc

BIP 146: Dealing with signature encoding malleability

BIP
146
Layer
Consensus (soft fork)
Title
Dealing with signature encoding malleability
Authors
Johnson Lau
Pieter Wuille
Status
Closed
Type
Specification
Assigned
2016-08-16
License
PD

Pinned source · Reader view on bips.dev
SHA-256 51f5279263a3d2948acaa669021f8b220224df09cd1d28576ff5a7cd4332a698
Git blob 5d1c4418fd08e1faa28251209cdf63b1fb6d79df

Fig. A23.1 One signature, four changes

Static view: the signature as published. With JavaScript you can try four changes to its bytes.

One signature through BIP 66 and BIP 146Input 0's signature in BIP 143's example: 30450221008b9d1dc26ba6a9cb62127b02742fa9d754cd3bebf337f7a55d114c8e5cdd30be022040529b194ba3f9281a99f2b1c0a19c0489bc22ede944ccf4ecbab4cc618ef3ed01. Fields: sequence (0x30) 30, total length 45, integer (0x02) 02, R length 21, R 008b9d1dc26ba6a9cb62127b02742fa9d754cd3bebf337f7a55d114c8e5cdd30be, integer (0x02) 02, S length 20, S 40529b194ba3f9281a99f2b1c0a19c0489bc22ede944ccf4ecbab4cc618ef3ed, sighash type 01. BIP 66's checks: line 55, at least 9 bytes: passes; line 56, at most 73 bytes: passes; line 59, starts with 0x30: passes; line 62, length byte covers the rest: passes; line 68, S's length byte is inside: passes; line 75, R and S lengths add up: passes; line 78, R is an integer (0x02): passes; line 81, R is not empty: passes; line 84, R is not negative: passes; line 88, R has no extra leading zero: passes; line 91, S is an integer (0x02): passes; line 94, S is not empty: passes; line 97, S is not negative: passes; line 101, S has no extra leading zero: passes. BIP 146 LOW_S: passes. ECDSA: verifies. As published: 72 bytes. R and S are the same numbers as published. Strict DER, a valid signature, and S in the lower half: accepted.BIP 143 EXAMPLE · INPUT 0 (P2PK) · SIGNATURE IN THE scriptSig · 72 BYTESAS PUBLISHED3045022100 8b9d1dc26ba6…R · 33 B022040529b194ba3…S · 32 B01BIP 66 · IsValidSignatureEncoding, IN ORDER✓L55at least 9 bytes✓L56at most 73 bytes✓L59starts with 0x30✓L62length byte covers the rest✓L68S's length byte is inside✓L75R and S lengths add up✓L78R is an integer (0x02)✓L81R is not empty✓L84R is not negative✓L88R has no extra leading zero✓L91S is an integer (0x02)✓L94S is not empty✓L97S is not negative✓L101S has no extra leading zero✓LOW_S (BIP 146, PROPOSED)S ≤ n / 2✓ECDSA VERIFYVALID SIGNATURER, S: SAME NUMBERS AS PUBLISHEDtxid e8151a2af3…strict DER, a valid signature,and S in the lower half:accepted
One signature through BIP 66 and BIP 146Input 0's signature in BIP 143's example: 30450221008b9d1dc26ba6a9cb62127b02742fa9d754cd3bebf337f7a55d114c8e5cdd30be022040529b194ba3f9281a99f2b1c0a19c0489bc22ede944ccf4ecbab4cc618ef3ed01. Fields: sequence (0x30) 30, total length 45, integer (0x02) 02, R length 21, R 008b9d1dc26ba6a9cb62127b02742fa9d754cd3bebf337f7a55d114c8e5cdd30be, integer (0x02) 02, S length 20, S 40529b194ba3f9281a99f2b1c0a19c0489bc22ede944ccf4ecbab4cc618ef3ed, sighash type 01. BIP 66's checks: line 55, at least 9 bytes: passes; line 56, at most 73 bytes: passes; line 59, starts with 0x30: passes; line 62, length byte covers the rest: passes; line 68, S's length byte is inside: passes; line 75, R and S lengths add up: passes; line 78, R is an integer (0x02): passes; line 81, R is not empty: passes; line 84, R is not negative: passes; line 88, R has no extra leading zero: passes; line 91, S is an integer (0x02): passes; line 94, S is not empty: passes; line 97, S is not negative: passes; line 101, S has no extra leading zero: passes. BIP 146 LOW_S: passes. ECDSA: verifies. As published: 72 bytes. R and S are the same numbers as published. Strict DER, a valid signature, and S in the lower half: accepted.BIP 143 · INPUT 0 · scriptSig · 72 BYTESAS PUBLISHED3045022100 8b9d1d…R · 33 B022040529b…S · 32 B01BIP 66 · IsValidSignatureEncoding, IN ORDER✓L55at least 9 bytes✓L56at most 73 bytes✓L59starts with 0x30✓L62length byte covers the rest✓L68S's length byte is inside✓L75R and S lengths add up✓L78R is an integer (0x02)✓L81R is not empty✓L84R is not negative✓L88R has no extra leading zero✓L91S is an integer (0x02)✓L94S is not empty✓L97S is not negative✓L101S has no extra leading zero✓LOW_S (BIP 146, PROPOSED)S ≤ n / 2✓ECDSA VERIFYVALID SIGNATURER, S: SAME NUMBERS AS PUBLISHEDtxid e8151a2af3…strict DER, a valid signature, and S in the lowerhalf: accepted

As published: 72 bytes. R and S are the same numbers as published. Strict DER, a valid signature, and S in the lower half: accepted.

Exact values
Signature (72 bytes, sighash byte last)
30450221008b9d1dc26ba6a9cb62127b02742fa9d754cd3bebf337f7a55d114c8e5cdd30be022040529b194ba3f9281a99f2b1c0a19c0489bc22ede944ccf4ecbab4cc618ef3ed01
R
8b9d1dc26ba6a9cb62127b02742fa9d754cd3bebf337f7a55d114c8e5cdd30be
S
40529b194ba3f9281a99f2b1c0a19c0489bc22ede944ccf4ecbab4cc618ef3ed
Signed digest (legacy, computed)
63cec688ee06a91e913875356dd4dea2f8e0f2a2659885372da2a37e32c7532e
txid with this signature (display order)
e8151a2af31c368a35053ddd4bdb285a8595c769a3ad83e0fa02314a602d4609

BIP 143 line 195 (input 0's scriptSig in its signed example, line 190). The four changes are computed by the model from those bytes; BIP 66's checks are lines 55–101 of its reference function. The example's keys are printed in BIP 143: test material only.

Input 0's signature from BIP 143's signed example. Choose a change. The first three write the same digits of R and S in different bytes, and BIP 66 rejects each at a different check. The last replaces S by n − S: still strict DER and still a valid signature, so only BIP 146's proposed LOW_S rule would reject it. The model computes every result; ECDSA verification is audited noble.89101112

One encoding

BIP 66 applies to every signature passed to OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY for ECDSA verification. It must be strict DER, as a short reference function in the BIP checks. If that check fails, the whole script fails at once. A strict signature that is simply wrong behaves as it did before.1314

The format is 0x30, the length of everything after it except the sighash byte, then R and S, each as 0x02, a length and the number in big-endian bytes. A number may not start with a zero byte, except one zero when the next byte has its top bit set, or it would read as negative. The sighash byte Bitcoin appends sits outside DER. BIP 66 does not run its check on an empty signature, which stays a short, deliberately invalid one.115

Fig. A23.2 A DER signature, field by field

A DER signature, field by fieldBIP 143's example, input 0: a P2PK spend, signature in the scriptSig, 72 bytes: sequence (0x30) 30, total length 45, integer (0x02) 02, R length 21, R 008b9d1dc26ba6a9cb62127b02742fa9d754cd3bebf337f7a55d114c8e5cdd30be, integer (0x02) 02, S length 20, S 40529b194ba3f9281a99f2b1c0a19c0489bc22ede944ccf4ecbab4cc618ef3ed, sighash type 01. R is 33 bytes: a 0x00 pad, because its first value byte 8b has its top bit set and would otherwise read as negative. BIP 143's example, input 1: a P2WPKH spend, signature in the witness, 71 bytes: sequence (0x30) 30, total length 44, integer (0x02) 02, R length 20, R 3609e17b84f6a7d30c80bfa610b5b4542f32a8a0d5447a12fb1366d7f01cc44a, integer (0x02) 02, S length 20, S 573a954c4518331561406f90300e8f3358f51928d43c212a8caed02de67eebee, sighash type 01. R is 32 bytes with no pad: its first byte 36 has its top bit clear.0x30 [TOTAL] 0x02 [LEN R] R 0x02 [LEN S] S [SIGHASH]INPUT 0 · SCRIPTSIG · 72 BYTES3045022100 8b9d1d…R · 33 B022040529b…S · 32 B01TOTAL 0x45 = 69: EVERY BYTE AFTER IT, EXCEPT THE SIGHASHR STARTS 00 8b: 8B HAS ITS TOP BIT SET, SO ONE 00 IS REQUIREDINPUT 1 · WITNESS · 71 BYTES304402203609e1…R · 32 B0220573a95…S · 32 B01TOTAL 0x44 = 68: EVERY BYTE AFTER IT, EXCEPT THE SIGHASHR STARTS 36: TOP BIT CLEAR, SO NO PAD IS ALLOWED
Both signatures in BIP 143's example. Input 0's R begins with 0x8b, whose top bit is set, so it carries one zero byte and is 33 bytes long. Input 1's R begins with 0x36 and carries none.111

The rule only adds failures, so it could be deployed as a soft fork. It reused BIP 34's mechanism with block version 3. The rule was enforced in version 3 blocks once 750 of the previous 1,000 had version 3, and version 2 blocks became invalid once 950 did. The reference client had already refused to relay non-DER signatures since version 0.8.0, and any such signature could be rewritten in strict form.161718

The twin signature

Strict DER fixes the bytes, not the numbers. ECDSA has a symmetry: if (R, S) is a valid signature, so is (R, n − S), where n is the order of the curve. Anyone can compute that twin without the private key.719

BIP 146's LOW_S rule keeps only the lower half: S must lie between 1 and n / 2. Under the rule, a signature outside that range makes the script fail at once. Of S and its twin, exactly one is in that half, so for the script types in actual use a signer can always provide a compliant signature.102021

Fig. A23.3 Each S and its twin

S and its twin n − SA line from 0 to the secp256k1 order n, with n / 2 (0x7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0) in the middle. BIP 143's example, input 0: a P2PK spend, signature in the scriptSig: S is 25.1% of the way to n, in the lower half; n − S is at 74.9%, in the upper half, and verifies just as well. BIP 143's example, input 1: a P2WPKH spend, signature in the witness: S is 34.1% of the way to n, in the lower half; n − S is at 65.9%, in the upper half, and verifies just as well. BIP 146's LOW_S rule accepts only S from 1 to n / 2.EVERY S HAS A TWIN n − S THAT ALSO VERIFIESLOW S · ALLOWEDHIGH S · LOW_S FAILS0n / 2nINPUT 0: Sn − SMIRROR ABOUT n / 2INPUT 1: Sn − SMIRROR ABOUT n / 2n / 2 = 7FFFFFFF … 681B20A0 (BIP 146)
Both published S values lie in the lower half. Each twin n − S lies at the mirror point in the upper half and verifies just as well.101920

BIP 146's NULLFAIL rule addresses the other gap. A failing signature check leaves FALSE on the stack and lets the script continue. As BIP 146 points out, the failing signature can therefore be any bytes that pass BIP 66. Under NULLFAIL, a check that returns false must have been given an empty signature (for OP_CHECKMULTISIG, every signature); otherwise the script fails.722

What the identifier hashes

A txid hashes every scriptSig, so changing a signature there changes the txid and breaks any unconfirmed transaction that spends its outputs. SegWit's txid leaves the witness out. A witness signature can still be flipped, but that changes only the wtxid.42324

Fig. A23.4 What a flipped S changes

  1. What a flipped S changes, step 1 of 3BIP 143's example transaction: txid e8151a2af31c368a35053ddd4bdb285a8595c769a3ad83e0fa02314a602d4609, wtxid c36c38370907df2324d9ce9d149d191192f338b37665a82e78e76a12c909b762 (display order). Input 0's signature is in its scriptSig, which the txid hashes; input 1's is in the witness, which only the wtxid hashes.VER00 01IN 0 · SIGIN 1OUTPUTSWITNESS · SIGLOCKWTXID HASHES EVERY BYTETXID HASHES THE MARKED PARTS ONLYtxid e8151a2af31c368a…wtxid c36c38370907df23…

    As published: input 0 signs in its scriptSig, input 1 in its witness.

  2. What a flipped S changes, step 2 of 3With input 0's S replaced by n − S the signature still verifies, and the transaction gets txid d1cfba03fcf676e36932864dde6d682ba4b1ad3158473a1cfa24b2a557f451ae and wtxid 15a47744bde5462976ffcfd2c422970bcebb852d2765be96f4cb19d6f5df92f1: both differ from the published ones.VER00 01n − SIN 1OUTPUTSWITNESS · SIGLOCKWTXID HASHES EVERY BYTETXID HASHES THE MARKED PARTS ONLYtxid d1cfba03fcf676e3…CHANGEDwtxid 15a47744bde54629…CHANGED

    Input 0's S replaced by n − S: the txid and the wtxid both change.

  3. What a flipped S changes, step 3 of 3With input 1's S replaced by n − S, the txid stays e8151a2af31c368a35053ddd4bdb285a8595c769a3ad83e0fa02314a602d4609 and the wtxid becomes 05a2eb2eb45a327a60ce6f9cada2ec9841c537e9d47468aa3237d369c88b9678.VER00 01IN 0 · SIGIN 1OUTPUTSn − SLOCKWTXID HASHES EVERY BYTETXID HASHES THE MARKED PARTS ONLYtxid e8151a2af31c368a…SAMEwtxid 05a2eb2eb45a327a…CHANGED

    Input 1's S replaced instead: only the wtxid changes.

Exact identifiers (display order)
Published txid
e8151a2af31c368a35053ddd4bdb285a8595c769a3ad83e0fa02314a602d4609
Published wtxid
c36c38370907df2324d9ce9d149d191192f338b37665a82e78e76a12c909b762
Input 0 flipped: txid
d1cfba03fcf676e36932864dde6d682ba4b1ad3158473a1cfa24b2a557f451ae
Input 0 flipped: wtxid
15a47744bde5462976ffcfd2c422970bcebb852d2765be96f4cb19d6f5df92f1
Input 1 flipped: txid
e8151a2af31c368a35053ddd4bdb285a8595c769a3ad83e0fa02314a602d4609
Input 1 flipped: wtxid
05a2eb2eb45a327a60ce6f9cada2ec9841c537e9d47468aa3237d369c88b9678
BIP 143's example transaction with one S flipped at a time. Both flipped transactions still verify; the model recomputes each identifier.2324

BIP 66 is recorded as Deployed. BIP 146 is recorded as Closed, and its deployment section was left as "Details TBD". Its rules cover legacy and SegWit scripts alike. It records LOW_S and NULLFAIL as relay policy in the reference client as of 2016, so it did not make either one a consensus rule. A high-S signature is not made invalid by BIP 146. It also says users MUST pay extra attention to these rules when designing exotic scripts.6122125262728

Note

Both BIPs were extracted from BIP 62, an earlier proposal against malleability that is now recorded as Closed.29

A consensus bug, fixed in passing

OpenSSL's stricter parsing arrived in versions 1.0.0p and 1.0.1k. After BIP 66 was adopted and enforced across the network, its author disclosed that strict DER signatures had also indirectly fixed a consensus bug he had found earlier.230

Evidence

Each numbered marker in the text points here, and the ↩ links lead back to the text. Quotes are verbatim from the BIP files at commit 3a10b5b, wiki markup included. Links open the exact lines. Labels say what kind of statement each entry is: a rule, the author’s rationale, history, a test vector, or our own inference.

  1. ↩ a b c Rule The format is 0x30, a total length, then 0x02, R's length and R, 0x02, S's length and S, then the sighash byte; R and S are big-endian and must use the shortest encoding of a positive integer, with no leading zero bytes except one when the next byte has its top bit set.

    Quoted source text (2)

    // Format: 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S] [sighash]

    BIP 66, line 42

    // * R: arbitrary-length big-endian encoded R value. It must use the shortest // possible encoding for a positive integers (which means no null bytes at // the start, except a single one when the next byte has its highest bit set).

    BIP 66, lines 46–48
  2. ↩ a b c History When BIP 66 was written, the reference implementation relied on OpenSSL to validate signatures, so OpenSSL implicitly defined block validity; OpenSSL had accepted various deviations from DER, and when that changed in versions 1.0.0p and 1.0.1k some nodes rejected the chain.

    Quoted source text (2)

    Bitcoin's reference implementation currently relies on OpenSSL for signature validation, which means it is implicitly defining Bitcoin's block validity rules.

    BIP 66, line 22

    Until recently, OpenSSL's releases would accept various deviations from the DER standard and accept signatures as valid. When this changed in OpenSSL 1.0.0p and 1.0.1k, it made some nodes reject the chain.

    BIP 66, line 24
  3. ↩ a b History BIP 62 listed non-DER signatures as a source of malleability, because OpenSSL accepted more than strict DER serializations.

    Quoted source text (1)

    As OpenSSL accepts more than serializations that strictly adhere to the DER standard, this is a source of malleability.

    BIP 62, line 33
  4. ↩ a b Author’s rationale Signature malleability is the ability of any relay node to transform a transaction's signatures without the private keys; for non-SegWit transactions it changes the txid and invalidates unconfirmed children, and for SegWit transactions, whose txid is not third-party malleable, it changes the wtxid and may make compact block relay less efficient.

    Quoted source text (1)

    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

    BIP 146, line 20
  5. ↩ Rule BIP 66 proposes restricting signatures to strict DER encoding in the transaction validity rules.

    Quoted source text (1)

    This document specifies proposed changes to the Bitcoin transaction validity rules to restrict signatures to strict DER encoding.

    BIP 66, line 14
  6. ↩ a b Rule BIP 146 proposes rules against signature malleability related to ECDSA encoding, applied to legacy and SegWit scripts alike.

    Quoted source text (2)

    This document specifies proposed changes to the Bitcoin transaction validity rules to fix signature malleability related to ECDSA signature encoding.

    BIP 146, line 15

    To fix signature encoding malleability, the following new rules are applied to pre-segregated witness and segregated witness scripts:

    BIP 146, line 33
  7. ↩ a b c Author’s rationale The authors note that after BIP 66 two known sources of ECDSA signature malleability remained: negating S modulo the curve order leaves a signature valid, and a failing signature can be any BIP 66-compliant value, since the failure only pushes FALSE and the script continues.

    Quoted source text (1)

    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 ECDSA signatures: # '''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. # '''Malleability of failing signature''': If a signature failed to validate in <code>OP_CHECKSIG</code> or <code>OP_CHECKMULTISIG</code>, a <code>FALSE</code> would be returned to the stack and the script evaluation would continue. The failing signature may take any value, as long as it follows all the rules described in BIP66.

    BIP 146, lines 22–26
  8. ↩ Rule BIP 66's reference function checks, in order: 9 to 73 bytes, a 0x30 start, a total length covering the signature, the R and S lengths, each element marked 0x02, non-empty, not negative, and without extra leading zeros.

    Quoted source text (4)

    // Minimum and maximum size constraints. if (sig.size() < 9) return false; if (sig.size() > 73) return false;

    BIP 66, lines 54–56

    // Make sure the length covers the entire signature. if (sig[1] != sig.size() - 3) return false;

    BIP 66, lines 61–62

    // Negative numbers are not allowed for R. if (sig[4] & 0x80) return false;

    BIP 66, lines 83–84

    // Null bytes at the start of S are not allowed, unless S would otherwise be // interpreted as a negative number. if (lenS > 1 && (sig[lenR + 6] == 0x00) && !(sig[lenR + 7] & 0x80)) return false;

    BIP 66, lines 99–101
  9. ↩ Test vector In the model, three changes to input 0's signature write the same digits of R and S in different bytes and fail BIP 66: without its zero pad R's bytes read as a negative number (line 84), an extra zero in front of S fails line 101, and a total length one too large fails line 62.

    Quoted source text (3)

    // Negative numbers are not allowed for R. if (sig[4] & 0x80) return false;

    BIP 66, lines 83–84

    // Null bytes at the start of S are not allowed

    BIP 66, lines 99–101

    // Make sure the length covers the entire signature.

    BIP 66, lines 61–62
  10. ↩ a b c Test vector In the model, replacing S by n − S gives a strict DER signature that still verifies (ECDSA with low-S checking off) but fails LOW_S; for input 0 it is 73 bytes, BIP 66's maximum, because n − S needs a zero pad. Exactly one of S and n − S is in the lower half.

    Quoted source text (2)

    A high S value in signature could be trivially replaced by

    BIP 146, line 42

    if (sig.size() > 73) return false;

    BIP 66, line 56
  11. ↩ a b Test vector In the model, BIP 143's signed native P2WPKH example carries two ECDSA signatures: input 0's, spending a P2PK output, in its scriptSig (72 bytes, R padded to 33 bytes), and input 1's, spending a P2WPKH output, in its witness (71 bytes). Both are strict DER with low S and verify, input 1's against the published digest and input 0's against the legacy digest the model computes.

    Quoted source text (4)

    The first input comes from an ordinary P2PK: scriptPubKey : 2103c9f4836b9a4f77fc0d81f7bcb01b7f1b35916864b9476c241ce9fc198bd25432ac value: 6.25

    BIP 143, lines 151–152

    The second input comes from a P2WPKH witness program:

    BIP 143, lines 155–156

    sigHash: c37af31116d1b27caf68aae9e3ac82f1477929014d5b917657d0eb49478cb670

    BIP 143, lines 187–188

    The serialized signed transaction is:

    BIP 143, line 190
  12. ↩ a b Editorial inference By these texts, BIP 146 did not make LOW_S or NULLFAIL consensus rules: the BIP is Closed, its deployment was never specified, and it records both as relay policy of the reference client. A high-S signature is not made invalid by BIP 146.

    Quoted source text (4)

    Status: Closed

    BIP 146, line 7

    Details TBD.

    BIP 146, line 98

    the LOW_S rule has been enforced as relay policy by the reference client since v0.11.1.

    BIP 146, line 107

    The NULLFAIL rule has been enforced as relay policy by the reference client since v0.13.1.

    BIP 146, line 109
  13. ↩ Rule Every signature passed to OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY for ECDSA verification must be strict DER; a signature that fails the IsValidSignatureEncoding check makes the whole script false immediately, while a valid DER signature that fails ECDSA verification behaves as before.

    Quoted source text (2)

    Every signature passed to OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKMULTISIG, or OP_CHECKMULTISIGVERIFY, to which ECDSA verification is applied, must be encoded using strict DER encoding (see further).

    BIP 66, line 30

    For each such verification, if the signature does not pass the <code>IsValidSignatureEncoding</code> check below, the entire script evaluates to false immediately. If the signature is valid DER, but does not pass ECDSA verification, opcode execution continues as it used to

    BIP 66, line 32
  14. ↩ Author’s rationale The author's aim: restrict valid signatures to exactly what DER mandates, so the consensus rules no longer depend on OpenSSL's signature parsing.

    Quoted source text (1)

    This document proposes to restrict valid signatures to exactly what is mandated by DER, to make the consensus rules not depend on OpenSSL's signature parsing.

    BIP 66, line 26
  15. ↩ Rule The check runs on the signature bytes including Bitcoin's 1-byte sighash flag, which is outside DER and unaffected; it is not called for an empty signature, kept as a short encoding of a deliberately invalid signature.

    Quoted source text (1)

    Note that this function tests a signature byte vector which includes the 1-byte sighash flag that Bitcoin adds, even though that flag falls outside of the DER specification, and is unaffected by this proposal. The function is also not called for cases where the length of sig is 0, in order to provide a simple, short and efficiently-verifiable encoding for deliberately invalid signatures.

    BIP 66, line 36
  16. ↩ Author’s rationale BIP 66's examples show the change only adds failures, as a soft fork requires.

    Quoted source text (1)

    Note that the examples above show that only additional failures are required by this change, as required for a soft forking change.

    BIP 66, line 125
  17. ↩ History BIP 66 reused BIP 34's double-threshold switchover for block version 3: the rules apply to version 3 blocks once 750 of the previous 1000 blocks are version 3, and once 950 are, version 2 blocks become invalid.

    Quoted source text (1)

    We reuse the double-threshold switchover mechanism from BIP 34, with the same thresholds, but for nVersion = 3. The new rules are in effect for every block (at height H) with nVersion = 3 and at least 750 out of 1000 blocks preceding it (with heights H-1000..H-1) also have nVersion = 3. Furthermore, when 950 out of the 1000 blocks preceding a block do have nVersion = 3, nVersion = 2 blocks become invalid, and all further blocks enforce the new rules.

    BIP 66, line 129
  18. ↩ History Strict DER had been relay policy in the reference client since v0.8.0, any non-compliant signature can be converted to a compliant one, and the BIP notes the added benefit of reducing malleability.

    Quoted source text (1)

    The requirement to have signatures that comply strictly with DER has been enforced as a relay policy by the reference client since v0.8.0, and very few transactions violating it are being added to the chain as of January 2015. In addition, every non-compliant signature can trivially be converted into a compliant one, so there is no loss of functionality by this requirement. This proposal has the added benefit of reducing transaction malleability (see BIP 62).

    BIP 66, line 133
  19. ↩ a b Rule A high S can be trivially replaced by S' = n − S, with n = 0xFFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE BAAEDCE6 AF48A03B BFD25E8C D0364141.

    Quoted source text (1)

    A high S value in signature could be trivially replaced by <code>S' = 0xFFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE BAAEDCE6 AF48A03B BFD25E8C D0364141 - S</code>.

    BIP 146, line 42
  20. ↩ a b Rule LOW_S: every signature passed to an ECDSA signature opcode, including P2WPKH, MUST have S between 0x1 and 0x7FFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF 5D576E73 57A4501D DFE92F46 681B20A0, the curve order divided by 2; a non-empty signature that fails makes the script false immediately.

    Quoted source text (3)

    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).

    BIP 146, line 38

    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

    BIP 146, line 38

    If a signature passing to ECDSA verification does not pass the Low S value check and is not an empty byte array, the entire script evaluates to false immediately.

    BIP 146, line 40
  21. ↩ a b History BIP 146 records the reference client producing low-S signatures since v0.9.0, enforcing LOW_S as relay policy since v0.11.1 and NULLFAIL since v0.13.1, and very few violations reaching the chain as of August 2016.

    Quoted source text (2)

    The reference client has produced LOW_S compatible signatures since v0.9.0, and the LOW_S rule has been enforced as relay policy by the reference client since v0.11.1. As of August 2016, very few transactions violating the requirement are being added to the chain. For all scriptPubKey types in actual use, non-compliant signatures can trivially be converted into compliant ones, so there is no loss of functionality by these requirements.

    BIP 146, line 107

    The NULLFAIL rule has been enforced as relay policy by the reference client since v0.13.1.

    BIP 146, line 109
  22. ↩ Rule NULLFAIL: when OP_CHECKSIG would return FALSE its signature must be empty, and when OP_CHECKMULTISIG would, every signature passed to it must be empty, even ones it skipped; otherwise the script fails immediately.

    Quoted source text (1)

    If an <code>OP_CHECKSIG</code> is trying to return a <code>FALSE</code> value to the stack, we require that the relevant signature must be an empty byte array. If an <code>OP_CHECKMULTISIG</code> is trying to return a <code>FALSE</code> value to the stack, we require that all signatures passing to this <code>OP_CHECKMULTISIG</code> must be empty byte arrays, even the processing of some signatures might have been skipped due to early termination of the signature verification. Otherwise, the entire script evaluates to false immediately.

    BIP 146, lines 47–51
  23. ↩ a b Rule BIP 141 keeps the txid as the double SHA-256 of the traditional serialization, without witness data, and defines the wtxid over the serialization with it.

    Quoted source text (2)

    Definition of <code>txid</code> remains unchanged: the double SHA256 of the traditional serialization format: [nVersion][txins][txouts][nLockTime]

    BIP 141, lines 43–45

    A new <code>wtxid</code> is defined: the double SHA256 of the new serialization with witness data: [nVersion][marker][flag][txins][txouts][witness][nLockTime]

    BIP 141, lines 47–49
  24. ↩ a b Test vector In the model, flipping input 0's S changes both the txid and the wtxid of BIP 143's example; flipping input 1's leaves the txid and changes the wtxid. The flipped transactions still verify.

    Quoted source text (2)

    For non-segregated witness transactions, signature malleability will change the <code>txid</code>

    BIP 146, line 20

    Definition of <code>txid</code> remains unchanged: the double SHA256 of the traditional serialization format:

    BIP 141, line 43
  25. ↩ History BIP 66 (Pieter Wuille), Strict DER signatures, a consensus soft fork assigned in 2015, is recorded as Deployed.

    Quoted source text (1)

    Layer: Consensus (soft fork) Title: Strict DER signatures Authors: Pieter Wuille <pieter.wuille@gmail.com> Status: Deployed Type: Specification Assigned: 2015-01-10

    BIP 66, lines 3–8
  26. ↩ History BIP 146 (Johnson Lau and Pieter Wuille), Dealing with signature encoding malleability, a consensus soft fork assigned in 2016, is recorded as Closed.

    Quoted source text (1)

    Layer: Consensus (soft fork) Title: Dealing with signature encoding malleability Authors: Johnson Lau <jl2012@xbt.hk> Pieter Wuille <pieter.wuille@gmail.com> Status: Closed Type: Specification Assigned: 2016-08-16

    BIP 146, lines 3–9
  27. ↩ History BIP 146's deployment section says it would use BIP 9 version bits and leaves the details, start time and timeout as TBD.

    Quoted source text (2)

    This BIP will be deployed by "version bits" [https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki BIP9]. Details TBD.

    BIP 146, line 98

    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).

    BIP 146, line 100
  28. ↩ Rule BIP 146 says users MUST pay extra attention to these rules when designing exotic scripts.

    Quoted source text (1)

    Users MUST pay extra attention to these new rules when designing exotic scripts.

    BIP 146, line 111
  29. ↩ History Both BIPs were extracted from BIP 62, an earlier proposal on malleability by Pieter Wuille that is recorded as Closed.

    Quoted source text (3)

    Title: Dealing with malleability Authors: Pieter Wuille <pieter.wuille@gmail.com> Status: Closed

    BIP 62, lines 6–8

    This document is extracted from the previous BIP62 proposal

    BIP 66, line 141

    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.

    BIP 146, line 132
  30. ↩ History After BIP 66 was adopted and enforced network-wide, its author disclosed that strict DER signatures had indirectly fixed a consensus bug he had found earlier.

    Quoted source text (1)

    that strict DER signatures provided an indirect solution to a consensus bug he had previously discovered.

    BIP 66, line 145