Skip to content

Conversation

darosior
Copy link
Member

@darosior darosior commented Jul 19, 2022

We would previously silently wrap the derived child's depth back to 0. Instead, explicitly fail when trying to derive an impossible depth, and handle the error in callers.

An extended fuzzing corpus of descriptor_parse triggered this behaviour, which was reported by MarcoFalke.

Fixes #25751.

@luke-jr
Copy link
Member

luke-jr commented Jul 27, 2022

Is the wrap actually harmful?

In any case, current code will never do this, right?

@darosior
Copy link
Member Author

darosior commented Jul 27, 2022

It is harmful in the sense that this behaviour is not specified by BIP32. We could accept an invalid descriptor or xpub that another software would refuse (or worse, treat differently).

In any case, current code will never do this, right?

Well, it was triggered by current code.

@achow101
Copy link
Member

achow101 commented Aug 2, 2022

ACK 84f86dc

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

left a nit

In some cases we asserted it succeeded, in others we were just ignoring it
It might already fail, and we'll add another failure case.
This issue was reported to me by Marco Falke, and found with the
descriptor_parse fuzz target.
@achow101
Copy link
Member

achow101 commented Aug 9, 2022

re-ACK fb9faff

@fanquake fanquake requested a review from instagibbs August 9, 2022 21:00
@instagibbs
Copy link
Member

Hadn't occurred to me this implicit limit due to the encoding of xpub/xprv.

utACK fb9faff

@achow101 achow101 merged commit 93999a5 into bitcoin:master Aug 10, 2022
@darosior darosior deleted the ext_key_derive_wrap_around branch August 10, 2022 21:39
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 11, 2022
…at a too large depth

fb9faff extended keys: fail to derive too large depth instead of wrapping around (Antoine Poinsot)
8dc6670 descriptor: don't assert success of extended key derivation (Antoine Poinsot)
50cfc9e (pubk)key: mark Derive() as nodiscard (Antoine Poinsot)
0ca258a descriptor: never ignore the return value when deriving an extended key (Antoine Poinsot)
d3599c2 spkman: don't ignore the return value when deriving an extended key (Antoine Poinsot)

Pull request description:

  We would previously  silently wrap the derived child's depth back to `0`. Instead, explicitly fail when trying to derive an impossible depth, and handle the error in callers.

  An extended fuzzing corpus of `descriptor_parse` triggered this behaviour, which was reported by MarcoFalke.

  Fixes bitcoin#25751.

ACKs for top commit:
  achow101:
    re-ACK fb9faff
  instagibbs:
    utACK  bitcoin@fb9faff

Tree-SHA512: 9f75c23572ce847239bd15e5497df2960b6bd63c61ea72347959d968b5c4c9a4bfeee284e76bdcd7bacbf9eeb70feee85ffd3e316f353ca6eca30e93aafad343
@bitcoin bitcoin locked and limited conversation to collaborators Aug 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
5 participants