Skip to content

Fix #70: Add threshold validation to __restore_secret - #71

Open
sysop1984 wants to merge 1 commit into
bitaps-com:masterfrom
sysop1984:fix/70-shamir-threshold-validation
Open

Fix #70: Add threshold validation to __restore_secret#71
sysop1984 wants to merge 1 commit into
bitaps-com:masterfrom
sysop1984:fix/70-shamir-threshold-validation

Conversation

@sysop1984

Copy link
Copy Markdown

Summary

Fixes #70 — Silent Recovery of Wrong Secret With Fewer Than Threshold Shares

Problem

The __restore_secret function in src/functions/shamir_secret_sharing.js performed Lagrange interpolation unconditionally over whatever shares were supplied. When fewer than threshold shares were provided, it silently returned a wrong secret with no error.

For a wallet-recovery use case, this is a serious security defect: a user may believe they have recovered their seed phrase when they have not, leading to irrecoverable loss of funds.

Fix

Added a required threshold parameter and validation that at least threshold shares are present before performing interpolation:

S.__restore_secret = (shares, threshold) => {
  if (threshold === undefined) {
    throw new Error("Threshold parameter is required. Call __restore_secret(shares, threshold)");
  }
  const shareCount = Object.keys(shares).length;
  if (shareCount < threshold) {
    throw new Error(`Need at least ${threshold} shares to recover the secret, but only ${shareCount} provided`);
  }
  // ... rest of function unchanged ...
};

Testing

  • Verified that calling __restore_secret(shares) without threshold throws a clear error
  • Verified that calling __restore_secret(shares, threshold) with insufficient shares throws a clear error
  • Verified that calling __restore_secret(shares, threshold) with sufficient shares works correctly

Bounty

This PR addresses the bug described in issue #70, which is eligible for the 0.1 BTC bounty: "Any bug in the implementation of the presented secret sharing scheme that can lead to loss of access and the inability to recover the original mnemonic phrase."

Reward address: bc1q4szfp7e44rvvedyvxvypuwhtrch68zg0gcsf9j

Fixes: #70

The __restore_secret function performed Lagrange interpolation
unconditionally over whatever shares were supplied. When fewer than
threshold shares were provided, it silently returned a wrong secret
with no error, leading to loss of access in wallet-recovery use cases.

This fix adds a required threshold parameter and validates that at
least threshold shares are present before performing interpolation.

Fixes: bitaps-com#70
@sysop1984

Copy link
Copy Markdown
Author

Reward Address

Please send the 0.1 BTC bug bounty to:

bc1q4szfp7e44rvvedyvxvypuwhtrch68zg0gcsf9j

This address is specified in issue #70. Thank you for the bounty opportunity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug Bounty] Silent Incorrect Recovery When Fewer Than Threshold Shares Are Provided

1 participant