Skip to content

Conversation

instagibbs
Copy link
Member

Regression introduced in #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.

@instagibbs instagibbs mentioned this pull request Jan 14, 2020
@maflcko
Copy link
Member

maflcko commented Jan 14, 2020

Tests are only failing in 0.19 branch, likely because that release still uses p2sh-segwit addresses rather than bech32 by default.

All wallet tests should probably be run on all possible address types. See also #17199 (comment)

@instagibbs instagibbs changed the title IsUsedDestination shouldn't use key id as script id for ScriptHash Bug: IsUsedDestination shouldn't use key id as script id for ScriptHash Jan 14, 2020
@instagibbs
Copy link
Member Author

It should ideally not be possible to footgun like this either by what I did. There's no situation I can think of that you'd want that conversion.

@instagibbs
Copy link
Member Author

pushed a very non-comprehensive commit that would have stopped me in my tracks if I thought "nesting" worked with ScriptHash destination.

I can keep poking at something more comprehensive, but I felt this was unobtrusive enough to be a non-controversial start.

luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Jan 14, 2020
Copy link
Contributor

@meshcollider meshcollider left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK 6dd59d2

I like the fact this reduces the chance of a similar future mistake. It certainly isn't obvious at a glance.

struct ScriptHash : public uint160
{
ScriptHash() : uint160() {}
// These don't do what you'd expect.
// Use ScriptHash(GetScriptForDestination(...)) instead.
explicit ScriptHash(const WitnessV0KeyHash& hash) = delete;
Copy link
Contributor

@promag promag Jan 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why explicit here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going back and forth on how to fix this and left that there :) I think this is a no-op

promag pushed a commit to promag/bitcoin that referenced this pull request Jan 15, 2020
promag pushed a commit to promag/bitcoin that referenced this pull request Jan 15, 2020
@achow101
Copy link
Member

ACK 6dd59d2

@maflcko
Copy link
Member

maflcko commented Jan 15, 2020

ACK 6dd59d2

@maflcko
Copy link
Member

maflcko commented Jan 15, 2020

I guess this is less likely to happen, but should CKeyID also be deleted?

@instagibbs
Copy link
Member Author

I think that's way less likely, and we might be able to do something smarter to be more generally robust as a followup?

@luke-jr
Copy link
Member

luke-jr commented Jan 15, 2020

Maybe we should just make the inheritance private?

@Empact
Copy link
Contributor

Empact commented Jan 16, 2020

I took a swing at it here: #17938

@instagibbs
Copy link
Member Author

@Empact looks much more comprehensive. If people agree we can merge this, then rebase and work on reviewing something like that?

@laanwj
Copy link
Member

laanwj commented Jan 16, 2020

Maybe we should just make the inheritance private?

In that case, why not go all the way, and use composition instead of inheritance.

But let's do this fix for 0.19 then maybe do something more comprehensive for 0.20.

laanwj added a commit that referenced this pull request Jan 16, 2020
…d 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 #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
@laanwj laanwj merged commit 6dd59d2 into bitcoin:master Jan 16, 2020
@fanquake
Copy link
Member

Being backported in 17792.

laanwj added a commit that referenced this pull request Jan 20, 2020
cd67b1d Use correct C++11 header for std::swap() (Hennadii Stepanov)
b8101fb Fix comparison function signature (Hennadii Stepanov)
eac4907 Don't allow implementers to think ScriptHash(Witness*()) results in nesting computation (Gregory Sanders)
e2c45d8 IsUsedDestination shouldn't use key id as script id for ScriptHash (Gregory Sanders)
a5489c9 IsUsedDestination should count any known single-key address (Gregory Sanders)
88729d8 Fix issue with conflicted mempool tx in listsinceblock (Adam Jonas)
eafcea7 gui: Fix duplicate wallet showing up (João Barbosa)
7e66d04 Drop signal CClientUIInterface::LoadWallet (Russell Yanofsky)
179d55f zmq: Fix due to invalid argument and multiple notifiers (João Barbosa)

Pull request description:

  Backports
   - #16963
   - #17445
   - #17258
   - #17621
   - #17924
   - #17634

ACKs for top commit:
  laanwj:
    ACK cd67b1d, checked that I got more or less the same result (including conflict resolution) backporting these commits

Tree-SHA512: 645786267cfb10a01a56f7cfd91ddead5f1475df5714595ae480237e04d40c5cfb7460b40532279cacd83e4b775a4ace68a258ec2184b8ad0e997a690a9245e5
MarkLTZ added a commit to litecoinz-core/litecoinz that referenced this pull request Feb 13, 2020
- [0.19] wallet: Reset reused transactions cache bitcoin#18083
- 0.19: Backports bitcoin#17792
- psbt: handle unspendable psbts bitcoin#17524
- qt: Fix comparison function signature bitcoin#17634
- psbt: check that various indexes and amounts are within bounds bitcoin#17156
- [0.19] psbt: check that various indexes and amounts are within bounds bitcoin#18079
- [0.19] Final backports for 0.19.1 bitcoin#17988
- Bug: IsUsedDestination shouldn't use key id as script id for ScriptHash bitcoin#17924
- qt: Fix deprecated QCharRef usage bitcoin#18101
- gui: Throttle GUI update pace when -reindex bitcoin#18121
- gui: Fix race in WalletModel::pollBalanceChanged bitcoin#18123
- gui: Fix unintialized WalletView::progressDialog bitcoin#18062
- Bugfix: GUI: Hide the HD/encrypt icons earlier so they get re-shown if another wallet is open bitcoin#18007
- bug-fix macos: give free bytes to F_PREALLOCATE bitcoin#17887
- test: add missing #include to fix compiler errors bitcoin#17980
- zmq: Fix due to invalid argument and multiple notifiers bitcoin#17445
meshcollider added a commit that referenced this pull request Jun 21, 2020
4d73691 Disallow automatic conversion between hash types (Ben Woosley)
fa9ef2c Remove an apparently unnecessary conversion (Ben Woosley)
966a22d Explicitly support conversion between equivalent hash types (Ben Woosley)
f32c1e0 Use explicit conversion from WitnessV0KeyHash -> CKeyID (Ben Woosley)
2c54217 Use explicit conversion from PKHash -> CKeyID (Ben Woosley)
a9e451f Convert CPubKey to WitnessV0KeyHash directly (Ben Woosley)
3fcc468 Prefer explicit CScriptID construction (Ben Woosley)
0a5ea32 Prefer explicit uint160 conversion (Ben Woosley)

Pull request description:

  This bases the script/standard hash types, TxDestination-related and CScriptID on a base template which does not silently convert the underlying `uintN` type.

  Inspired by and built on #17924. Commits are small and focused to ease review.

  Note some of these changes may be relative to existing bugs of the same sort as #17924. See particularly "Convert CPubKey to WitnessV0KeyHash directly" and "Remove an apparently unnecessary conversion".

ACKs for top commit:
  achow101:
    ACK 4d73691
  meshcollider:
    re-utACK 4d73691

Tree-SHA512: f1b3284ddc6fb6c6e726f2c22668b6d732d45eb5418262ed2b9c728f60be7be43dfb414b6ddd9915025c8dcd7f360dc3b46e997a945a2feb95b0e5c4f05d6b54
jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 7, 2020
…t id for ScriptHash

Summary:
6dd59d2e491bc11ab26498668543e65440a3a931 Don't allow implementers to think ScriptHash(Witness*()) results in nesting computation (Gregory Sanders)
4b8f1e989f3b969dc628b0801d5c31ebd373719c 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.

---

Backport of Core [[bitcoin/bitcoin#17924 | PR17924]]

Test Plan:
  ninja all check check-functional

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D7800
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.