GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||
GeezerVison is showing github.com — Error instead of overflowing depth byte when deriving past BIP32 max depth by SachinMeier · Pull Request #130 · RiverFinancial/bitcoinex Conversation
|
| @spec derive_public_child(t(), non_neg_integer) :: {:ok, t()} | {:error, String.t()} | ||
| def derive_public_child(xkey, idx) do | ||
| cond do | ||
| xkey.depth == @max_depth -> |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Any value in >= vs. ==?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The depth-255 check compared against the literal <<255>> binary, so a key whose depth binary had already carried past one byte slipped through (James' review on #130). The unified `next_depth_valid/1` guard now matches on the binary representation: a depth is derivable only if it is exactly one byte and not <<0xFF>>. Anything longer is already above max, which is the shape incr/1 produces once it carries past 255. Guarding on `depth >>> 8` does not work here since depth is a binary, not an integer -- the shift raises inside the guard, which silently fails the clause and disables the check. Test coverage for the above-max case builds the multi-byte depth directly; such a depth cannot round-trip through serialize/parse, and <<256>> truncates to <<0>>. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The depth-255 check compared against the literal <<255>> binary, so a key whose depth binary had already carried past one byte slipped through (James' review on #130). The unified `next_depth_valid/1` guard now matches on the binary representation: a depth is derivable only if it is exactly one byte and not <<0xFF>>. Anything longer is already above max, which is the shape incr/1 produces once it carries past 255. Guarding on `depth >>> 8` does not work here since depth is a binary, not an integer -- the shift raises inside the guard, which silently fails the clause and disables the check. Test coverage for the above-max case builds the multi-byte depth directly; such a depth cannot round-trip through serialize/parse, and <<256>> truncates to <<0>>. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
a652a10 to
f91aea2
Compare
BIP32 depth is a single byte. Deriving a child of a depth-255 key overflowed incr/1 into a 2-byte depth encoding, producing an unparseable serialization and the misleading error "error parsing key". Guard both derivation paths and return a clear error instead. Co-Authored-By: Claude Fable 5 <[email protected]>
The depth-255 check compared against the literal <<255>> binary, so a key whose depth binary had already carried past one byte slipped through (James' review on #130). The unified `next_depth_valid/1` guard now matches on the binary representation: a depth is derivable only if it is exactly one byte and not <<0xFF>>. Anything longer is already above max, which is the shape incr/1 produces once it carries past 255. Guarding on `depth >>> 8` does not work here since depth is a binary, not an integer -- the shift raises inside the guard, which silently fails the clause and disables the check. Test coverage for the above-max case builds the multi-byte depth directly; such a depth cannot round-trip through serialize/parse, and <<256>> truncates to <<0>>. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
next_depth_valid/1 and idx_valid/1 are internal-only; defguard exported them as public macros in the module API. Co-Authored-By: Claude Fable 5 <[email protected]>
fe74943 to
740b031
Compare
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.