aboutsummaryrefslogtreecommitdiff
path: root/src/script/sign.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2017-11-30 16:48:31 -0800
committerPieter Wuille <pieter.wuille@gmail.com>2018-01-03 05:32:00 -0800
commit0c8ea6380c9f402ed9777fd015b117ba13125a35 (patch)
tree23dc52dd8456f356328dca4de4dc030d19428f43 /src/script/sign.cpp
parent22149540f9e74ddff84973d9818ec9a34a533764 (diff)
downloadbitcoin-0c8ea6380c9f402ed9777fd015b117ba13125a35.tar.xz
Abstract out IsSolvable from Witnessifier
Diffstat (limited to 'src/script/sign.cpp')
-rw-r--r--src/script/sign.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/script/sign.cpp b/src/script/sign.cpp
index 117a4d8a52..49099bf7b0 100644
--- a/src/script/sign.cpp
+++ b/src/script/sign.cpp
@@ -422,3 +422,22 @@ bool DummySignatureCreator::CreateSig(std::vector<unsigned char>& vchSig, const
vchSig[6 + 33 + 32] = SIGHASH_ALL;
return true;
}
+
+bool IsSolvable(const CKeyStore& store, const CScript& script)
+{
+ // This check is to make sure that the script we created can actually be solved for and signed by us
+ // if we were to have the private keys. This is just to make sure that the script is valid and that,
+ // if found in a transaction, we would still accept and relay that transaction. In particular,
+ // it will reject witness outputs that require signing with an uncompressed public key.
+ DummySignatureCreator creator(&store);
+ SignatureData sigs;
+ // Make sure that STANDARD_SCRIPT_VERIFY_FLAGS includes SCRIPT_VERIFY_WITNESS_PUBKEYTYPE, the most
+ // important property this function is designed to test for.
+ static_assert(STANDARD_SCRIPT_VERIFY_FLAGS & SCRIPT_VERIFY_WITNESS_PUBKEYTYPE, "IsSolvable requires standard script flags to include WITNESS_PUBKEYTYPE");
+ if (ProduceSignature(creator, script, sigs)) {
+ // VerifyScript check is just defensive, and should never fail.
+ assert(VerifyScript(sigs.scriptSig, script, &sigs.scriptWitness, STANDARD_SCRIPT_VERIFY_FLAGS, creator.Checker()));
+ return true;
+ }
+ return false;
+}