Conversation
__restore_secret() ran Lagrange interpolation over whatever shares were supplied and returned the result unconditionally. With fewer than threshold shares it fits a lower-degree polynomial and silently returns a WRONG secret -- for wallet recovery this means a user can import an incorrect mnemonic with no error and lose access to funds. Add an optional threshold parameter to __restore_secret() and thread it through combineMnemonic (A.threshold) and the internal split verification. When the share count is below threshold, throw instead of returning a plausible-but-wrong secret. Behaviour is unchanged when threshold is not supplied (backward compatible) and for correct recoveries. Closes bitaps-com#70
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #70.
__restore_secret()performed Lagrange interpolation over whatever shares were supplied and returned the result unconditionally. With fewer thanthresholdshares it fits a lower-degree polynomial and silently returns a wrong secret — for wallet recovery a user can import an incorrect mnemonic with no error and lose access to funds. This matches the stated bounty category (0.1 BTC).Root cause
S.__restore_secret(shares)only validated share index range and buffer lengths — no threshold/consistency check — then returned the interpolation result.Fix
thresholdparameter to__restore_secret(shares, threshold); when the number of supplied shares is belowthreshold, throw instead of returning a plausible-but-wrong secret.combineMnemonic(shares, {threshold})and the internal split-verification call insplitMnemonic.Backward compatibility
When
thresholdis not supplied, behaviour is unchanged (no throw), so existing callers are unaffected; correct recoveries with enough shares also behave as before.Verification
node --checkpasses on both modified files.threshold=3→ rejected; no-threshold call → works (backward compatible); enough shares → works.Note: the strongest fix (SLIP-39-style embedded digest, Option B in the issue) would additionally detect inconsistent shares, but requires changing the share format; this PR implements the non-breaking threshold guard (Option A). Happy to extend toward Option B if preferred.
Closes #70