Skip to content

fix(shamir): position-based polynomial evaluation; uniform coefficient sampling - #74

Open
DaBaoAgent wants to merge 1 commit into
bitaps-com:masterfrom
DaBaoAgent:fix/shamir-indexof-bias
Open

fix(shamir): position-based polynomial evaluation; uniform coefficient sampling#74
DaBaoAgent wants to merge 1 commit into
bitaps-com:masterfrom
DaBaoAgent:fix/shamir-indexof-bias

Conversation

@DaBaoAgent

Copy link
Copy Markdown

Fixes #73

Bug

__shamirFn used q.indexOf(a) to derive each coefficient's exponent. indexOf returns the first occurrence of a value, so whenever coefficient values repeat the wrong exponent is used and evaluation is corrupted.

To paper over that, __split_secret forced all coefficients to be distinct from each other and from the secret byte via while (q.includes(w)). This samples coefficients without replacement, violating the uniform i.i.d. sampling Shamir's perfect-secrecy proof requires:

  • For t = 3, exactly 3 values per byte are rejected (256 → 253 candidates) → ~0.272 bits of entropy leaked across 16 bytes.
  • The leak grows quadratically with threshold t and causes total breakdown at t >= 30.

Fix

  1. __shamirFn: evaluate with Horner's method, using the coefficient position as the exponent — identical results for distinct coefficients (verified), correct results for repeated ones.
  2. __split_secret: remove the rejection filter; coefficients are now sampled uniformly i.i.d. from GF(256), as required by the security proof.

Verification

  • npm test (full suite): 86 passing, 0 failing (includes the existing Secret splitting test, 2000+ iterations).
  • New regression tests:
    • position-based evaluation with repeated coefficient values (vs explicit $\sum q_i x^i$),
    • round-trips at thresholds 30–100 (previously broken).
  • Backward compatible: shares generated by the old code restore correctly with the new code.
  • Issue PoC replicated: old sampling rejects exactly 3 of 256 secrets per byte (t=3); new sampling rejects 0.

…t sampling

__shamirFn used q.indexOf(a) to derive the exponent, which returns the
first occurrence of a value and corrupts evaluation whenever coefficients
repeat. Evaluate with Horner's method, using the coefficient position as
the exponent (issue bitaps-com#73).

__split_secret forced all coefficients distinct from each other and from
the secret byte (while (q.includes(w))), violating Shamir's perfect-
secrecy guarantee by sampling without replacement: for t=3 exactly 3
values per byte are rejected (256 -> 253 candidates), leaking ~0.272 bits
across 16 bytes and breaking down at t >= 30. Coefficients are now
sampled uniformly i.i.d. from GF(256).

Adds regression tests: position-based evaluation with repeated
coefficients, and round-trips at thresholds up to 100.
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] Biased Polynomial Coefficients Due to indexOf-Based Evaluation in __shamirFn

1 participant