Bug: IsUsedDestination shouldn’t use key id as script id for ScriptHash #17924

pull instagibbs wants to merge 2 commits into bitcoin:master from instagibbs:reuse_regression changing 2 files +6 −1
  1. instagibbs commented at 6:30 pm on January 14, 2020: 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.

  2. IsUsedDestination shouldn't use key id as script id for ScriptHash 4b8f1e989f
  3. MarcoFalke commented at 6:40 pm on January 14, 2020: member

    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 (review)

  4. instagibbs renamed this:
    IsUsedDestination shouldn't use key id as script id for ScriptHash
    Bug: IsUsedDestination shouldn't use key id as script id for ScriptHash
    on Jan 14, 2020
  5. instagibbs commented at 6:48 pm on January 14, 2020: member
    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.
  6. DrahtBot added the label Wallet on Jan 14, 2020
  7. instagibbs commented at 8:07 pm on January 14, 2020: member

    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.

  8. in src/script/standard.h:91 in 6fe6e0c5c0 outdated
    86 {
    87     ScriptHash() : uint160() {}
    88+    // These don't do what you'd expect.
    89+    // Use ScriptHash(GetScriptForDestination(...)) instead.
    90+    explicit ScriptHash(const WitnessV0KeyHash& hash) = delete;
    91+    explicit ScriptHash(const WitnessV0ScriptHash& hash) = delete;
    


    MarcoFalke commented at 8:33 pm on January 14, 2020:
    Instead of deleting them, couldn’t you just call GetScriptForDestination in the constructor?

    instagibbs commented at 8:46 pm on January 14, 2020:

    Yes, but that means I have to think more if we want to support more conversions, like ScriptHash(PKHash()) etc.

    Like, is this a general tool for generating output scripts, or what?


    MarcoFalke commented at 9:03 pm on January 14, 2020:
    Yeah, I guess highest priority is fixing the sharp edge. One way or another.

    luke-jr commented at 9:48 pm on January 14, 2020:

    Instead of deleting them, couldn’t you just call GetScriptForDestination in the constructor?

    Sounds like begging for sharp edges in backporting…


    luke-jr commented at 9:50 pm on January 14, 2020:
    Not sure the second one is needed… WitnessV0ScriptHash is a uint256, which has no constructor?

    instagibbs commented at 10:11 pm on January 14, 2020:
    fixed, added PKHash instead since that is possible

    mccoy45 commented at 10:46 am on January 20, 2020:
    Thank you
  9. Don't allow implementers to think ScriptHash(Witness*()) results in nesting computation 6dd59d2e49
  10. instagibbs force-pushed on Jan 14, 2020
  11. luke-jr referenced this in commit 54db35ee4f on Jan 14, 2020
  12. fanquake requested review from meshcollider on Jan 14, 2020
  13. fanquake requested review from achow101 on Jan 15, 2020
  14. fanquake added the label Needs backport (0.19) on Jan 15, 2020
  15. meshcollider commented at 9:22 am on January 15, 2020: contributor

    Code review ACK 6dd59d2e491bc11ab26498668543e65440a3a931

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

  16. in src/script/standard.h:89 in 6dd59d2e49
    84 struct ScriptHash : public uint160
    85 {
    86     ScriptHash() : uint160() {}
    87+    // These don't do what you'd expect.
    88+    // Use ScriptHash(GetScriptForDestination(...)) instead.
    89+    explicit ScriptHash(const WitnessV0KeyHash& hash) = delete;
    


    promag commented at 9:39 am on January 15, 2020:
    Why explicit here?

    instagibbs commented at 7:35 pm on January 15, 2020:
    I was going back and forth on how to fix this and left that there :) I think this is a no-op
  17. promag referenced this in commit e2c45d89f7 on Jan 15, 2020
  18. promag referenced this in commit eac49073eb on Jan 15, 2020
  19. achow101 commented at 6:59 pm on January 15, 2020: member
    ACK 6dd59d2e491bc11ab26498668543e65440a3a931
  20. MarcoFalke commented at 7:41 pm on January 15, 2020: member
    ACK 6dd59d2
  21. MarcoFalke commented at 7:47 pm on January 15, 2020: member
    I guess this is less likely to happen, but should CKeyID also be deleted?
  22. instagibbs commented at 7:52 pm on January 15, 2020: member
    I think that’s way less likely, and we might be able to do something smarter to be more generally robust as a followup?
  23. luke-jr commented at 11:04 pm on January 15, 2020: member
    Maybe we should just make the inheritance private?
  24. Empact commented at 0:55 am on January 16, 2020: member
    I took a swing at it here: #17938
  25. fanquake added this to the "Bugfixes" column in a project

  26. instagibbs commented at 3:23 pm on January 16, 2020: member
    @Empact looks much more comprehensive. If people agree we can merge this, then rebase and work on reviewing something like that?
  27. laanwj commented at 6:19 pm on January 16, 2020: member

    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.

  28. laanwj referenced this in commit f018d0c9cd on Jan 16, 2020
  29. laanwj merged this on Jan 16, 2020
  30. laanwj closed this on Jan 16, 2020

  31. laanwj removed this from the "Bugfixes" column in a project

  32. fanquake commented at 2:32 am on January 17, 2020: member
    Being backported in 17792.
  33. fanquake removed the label Needs backport (0.19) on Jan 17, 2020
  34. laanwj referenced this in commit 98159132c3 on Jan 20, 2020
  35. MarkLTZ referenced this in commit d99bc96496 on Feb 13, 2020
  36. meshcollider referenced this in commit bd331bd745 on Jun 21, 2020
  37. jasonbcox referenced this in commit affe4ede9e on Oct 7, 2020
  38. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-17 06:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me