From 4b8f1e989f3b969dc628b0801d5c31ebd373719c Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Tue, 14 Jan 2020 13:23:24 -0500 Subject: [PATCH 1/2] IsUsedDestination shouldn't use key id as script id for ScriptHash --- src/wallet/wallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index d3968eaea1f..cc6eebba977 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -734,7 +734,7 @@ bool CWallet::IsUsedDestination(const uint256& hash, unsigned int n) const if (GetDestData(wpkh_dest, "used", nullptr)) { return true; } - ScriptHash sh_wpkh_dest(wpkh_dest); + ScriptHash sh_wpkh_dest(GetScriptForDestination(wpkh_dest)); if (GetDestData(sh_wpkh_dest, "used", nullptr)) { return true; } From 6dd59d2e491bc11ab26498668543e65440a3a931 Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Tue, 14 Jan 2020 15:05:53 -0500 Subject: [PATCH 2/2] Don't allow implementers to think ScriptHash(Witness*()) results in nesting computation --- src/script/standard.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/script/standard.h b/src/script/standard.h index 350a5603d59..5c73c7fad44 100644 --- a/src/script/standard.h +++ b/src/script/standard.h @@ -80,9 +80,14 @@ struct PKHash : public uint160 using uint160::uint160; }; +struct WitnessV0KeyHash; struct ScriptHash : public uint160 { ScriptHash() : uint160() {} + // These don't do what you'd expect. + // Use ScriptHash(GetScriptForDestination(...)) instead. + explicit ScriptHash(const WitnessV0KeyHash& hash) = delete; + explicit ScriptHash(const PKHash& hash) = delete; explicit ScriptHash(const uint160& hash) : uint160(hash) {} explicit ScriptHash(const CScript& script); using uint160::uint160;