diff --git a/src/script/sigencoding.cpp b/src/script/sigencoding.cpp --- a/src/script/sigencoding.cpp +++ b/src/script/sigencoding.cpp @@ -22,9 +22,9 @@ * * This function is consensus-critical since BIP66. */ -static bool IsValidSignatureEncoding(const valtype &sig) { +static bool +IsValidSignatureEncoding(const boost::sliced_range &sig) { // Format: 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S] - // [sighash] // * total-length: 1-byte length descriptor of everything that follows, // excluding the sighash byte. // * R-length: 1-byte length descriptor of the R value that follows. @@ -34,11 +34,9 @@ // highest bit set). // * S-length: 1-byte length descriptor of the S value that follows. // * S: arbitrary-length big-endian encoded S value. The same rules apply. - // * sighash: 1-byte value indicating what data is hashed (not part of the - // DER signature) // Minimum and maximum size constraints. - if (sig.size() < 9 || sig.size() > 73) { + if (sig.size() < 8 || sig.size() > 72) { return false; } @@ -55,8 +53,7 @@ // Remove: // * 1 byte for the coupound type. // * 1 byte for the length of the signature. - // * 1 byte for the sighash type. - if (sig[1] != sig.size() - 3) { + if (sig[1] != sig.size() - 2) { return false; } @@ -90,8 +87,7 @@ // * 2 bytes for the integer type of R and S. // * 2 bytes for the size of R and S. // * 1 byte for S itself. - // * 1 byte for the sighash type. - if (lenR > (sig.size() - 8)) { + if (lenR > (sig.size() - 7)) { return false; } @@ -139,8 +135,7 @@ // including metadatas: // * 1 byte for the integer type of S. // * 1 byte for the size of S. - // * 1 byte for the sighash type. - if (size_t(startS + lenS + 3) != sig.size()) { + if (size_t(startS + lenS + 2) != sig.size()) { return false; } @@ -175,7 +170,8 @@ } if ((flags & (SCRIPT_VERIFY_DERSIG | SCRIPT_VERIFY_LOW_S | SCRIPT_VERIFY_STRICTENC)) != 0 && - !IsValidSignatureEncoding(vchSig)) { + !IsValidSignatureEncoding( + vchSig | boost::adaptors::sliced(0, vchSig.size() - 1))) { return set_error(serror, SCRIPT_ERR_SIG_DER); } if ((flags & SCRIPT_VERIFY_LOW_S) != 0 &&