Skip to content

Commit f018d0c

Browse files
committed
Merge #17924: Bug: IsUsedDestination shouldn't use key id as script id for ScriptHash
6dd59d2 Don't allow implementers to think ScriptHash(Witness*()) results in nesting computation (Gregory Sanders) 4b8f1e9 IsUsedDestination shouldn't use key id as script id for ScriptHash (Gregory Sanders) Pull request description: Regression introduced in bitcoin/bitcoin#17621 which causes p2sh-segwit addresses to be erroneously missed. Tests are only failing in 0.19 branch, likely because that release still uses p2sh-segwit addresses rather than bech32 by default. I'll devise a test case to catch this going forward. ACKs for top commit: achow101: ACK 6dd59d2 MarcoFalke: ACK 6dd59d2 meshcollider: Code review ACK 6dd59d2 Tree-SHA512: b3e0f320c97b8c1f814cc386840240cbde2761fee9711617b713d3f75a4a5dce2dff2df573d80873df42a1f4b74e816ab8552a573fa1d62c344997fbb6af9950
2 parents a9c789e + 6dd59d2 commit f018d0c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/script/standard.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,14 @@ struct PKHash : public uint160
8080
using uint160::uint160;
8181
};
8282

83+
struct WitnessV0KeyHash;
8384
struct ScriptHash : public uint160
8485
{
8586
ScriptHash() : uint160() {}
87+
// These don't do what you'd expect.
88+
// Use ScriptHash(GetScriptForDestination(...)) instead.
89+
explicit ScriptHash(const WitnessV0KeyHash& hash) = delete;
90+
explicit ScriptHash(const PKHash& hash) = delete;
8691
explicit ScriptHash(const uint160& hash) : uint160(hash) {}
8792
explicit ScriptHash(const CScript& script);
8893
using uint160::uint160;

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ bool CWallet::IsUsedDestination(const uint256& hash, unsigned int n) const
744744
if (GetDestData(wpkh_dest, "used", nullptr)) {
745745
return true;
746746
}
747-
ScriptHash sh_wpkh_dest(wpkh_dest);
747+
ScriptHash sh_wpkh_dest(GetScriptForDestination(wpkh_dest));
748748
if (GetDestData(sh_wpkh_dest, "used", nullptr)) {
749749
return true;
750750
}

0 commit comments

Comments
 (0)