diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2018-05-01 13:18:51 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2018-05-03 11:02:01 -0700 |
commit | a53f0feff8d42b7a40d417f77dc8de682dd88fd9 (patch) | |
tree | 70fce341383d70b5d056dcba4b8b45a7315f53c5 | |
parent | b5802a9f5f69815d3290361fd8c96d76a037832f (diff) |
Add some checks for invalid recursion in IsMine
-rw-r--r-- | src/script/ismine.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/script/ismine.cpp b/src/script/ismine.cpp index bebaf9ea82..2f710782fb 100644 --- a/src/script/ismine.cpp +++ b/src/script/ismine.cpp @@ -76,6 +76,11 @@ isminetype IsMineInner(const CKeyStore& keystore, const CScript& scriptPubKey, b break; case TX_WITNESS_V0_KEYHASH: { + if (sigversion == IsMineSigVersion::WITNESS_V0) { + // P2WPKH inside P2WSH is invalid. + isInvalid = true; + return ISMINE_NO; + } if (sigversion == IsMineSigVersion::TOP && !keystore.HaveCScript(CScriptID(CScript() << OP_0 << vSolutions[0]))) { // We do not support bare witness outputs unless the P2SH version of it would be // acceptable as well. This protects against matching before segwit activates. @@ -100,6 +105,11 @@ isminetype IsMineInner(const CKeyStore& keystore, const CScript& scriptPubKey, b break; case TX_SCRIPTHASH: { + if (sigversion != IsMineSigVersion::TOP) { + // P2SH inside P2WSH or P2SH is invalid. + isInvalid = true; + return ISMINE_NO; + } CScriptID scriptID = CScriptID(uint160(vSolutions[0])); CScript subscript; if (keystore.GetCScript(scriptID, subscript)) { @@ -109,6 +119,11 @@ isminetype IsMineInner(const CKeyStore& keystore, const CScript& scriptPubKey, b } case TX_WITNESS_V0_SCRIPTHASH: { + if (sigversion == IsMineSigVersion::WITNESS_V0) { + // P2WSH inside P2WSH is invalid. + isInvalid = true; + return ISMINE_NO; + } if (sigversion == IsMineSigVersion::TOP && !keystore.HaveCScript(CScriptID(CScript() << OP_0 << vSolutions[0]))) { break; } |