diff --git a/src/test/sigencoding_tests.cpp b/src/test/sigencoding_tests.cpp --- a/src/test/sigencoding_tests.cpp +++ b/src/test/sigencoding_tests.cpp @@ -16,20 +16,6 @@ return vchSig; } -static void -CheckSignatureErrorForAllSigHashType(const valtype &vchSig, uint32_t flags, - const ScriptError expected_error) { - ScriptError err = SCRIPT_ERR_OK; - BOOST_CHECK(!CheckDataSignatureEncoding(vchSig, flags, &err)); - BOOST_CHECK_EQUAL(err, expected_error); - - for (int i = 0; i <= 0xff; i++) { - valtype sig = SignatureWithHashType(vchSig, SigHashType(i)); - BOOST_CHECK(!CheckTransactionSignatureEncoding(sig, flags, &err)); - BOOST_CHECK_EQUAL(err, expected_error); - } -} - static void CheckSignatureEncodingWithSigHashType(const valtype &vchSig, uint32_t flags) { ScriptError err = SCRIPT_ERR_OK; @@ -160,6 +146,8 @@ // Invalid R and S types. {0x30, 0x06, 0x42, 0x01, 0x01, 0x02, 0x01, 0x01}, {0x30, 0x06, 0x02, 0x01, 0x01, 0x42, 0x01, 0x01}, + // S out of bounds. + {0x30, 0x06, 0x02, 0x01, 0x01, 0x02, 0x02, 0x00}, // Too long. {0x30, 0x47, 0x02, 0x21, 0x00, 0x8e, 0x45, 0x16, 0xda, 0x72, 0x53, 0xcf, 0x06, 0x8e, 0xff, 0xec, 0x6b, 0x95, 0xc4, 0x12, 0x21, 0xc0, @@ -184,8 +172,8 @@ if (flags & SCRIPT_VERIFY_LOW_S) { // If we do enforce low S, then high S sigs are rejected. - CheckSignatureErrorForAllSigHashType(highSSig, flags, - SCRIPT_ERR_SIG_HIGH_S); + BOOST_CHECK(!CheckDataSignatureEncoding(highSSig, flags, &err)); + BOOST_CHECK_EQUAL(err, SCRIPT_ERR_SIG_HIGH_S); } else { // If we do not enforce low S, then high S sigs are accepted. CheckSignatureEncodingWithSigHashType(highSSig, flags); @@ -196,25 +184,26 @@ SCRIPT_VERIFY_STRICTENC)) { // If we get any of the dersig flags, the non canonical dersig // signature fails. - CheckSignatureErrorForAllSigHashType(nonDERSig, flags, - SCRIPT_ERR_SIG_DER); + BOOST_CHECK( + !CheckDataSignatureEncoding(nonDERSig, flags, &err)); + BOOST_CHECK_EQUAL(err, SCRIPT_ERR_SIG_DER); } else { // If we do not check, then it is accepted. - CheckSignatureEncodingWithSigHashType(nonDERSig, flags); + BOOST_CHECK(CheckDataSignatureEncoding(nonDERSig, flags, &err)); } } for (const valtype &nonDERSig : nonParsableSigs) { if (flags & (SCRIPT_VERIFY_DERSIG | SCRIPT_VERIFY_LOW_S | SCRIPT_VERIFY_STRICTENC)) { - // If we get any of the dersig flags, the invalid signature - // fails. - CheckSignatureErrorForAllSigHashType(nonDERSig, flags, - SCRIPT_ERR_SIG_DER); + // If we get any of the dersig flags, the high S but non dersig + // signature fails. + BOOST_CHECK( + !CheckDataSignatureEncoding(nonDERSig, flags, &err)); + BOOST_CHECK_EQUAL(err, SCRIPT_ERR_SIG_DER); } else { - // If we do not check, then it is accepted even though it cannot - // even be parsed. - CheckSignatureEncodingWithSigHashType(nonDERSig, flags); + // If we do not check, then it is accepted. + BOOST_CHECK(CheckDataSignatureEncoding(nonDERSig, flags, &err)); } } }