Open
Description
Describe the bug
A clear and concise description of what the bug is. The implementation of Shamir Secret Sharing (SSSS) by Bitaps contains a critical flaw: Prime Modulus (p) is not used, nor is it shared with the shares. Instead, a Non-Prime Modulus (2²⁵⁶) is used, which is mathematically insecure. This leads to:
- The inability to recover the original mnemonic (secret) from the shares without the Prime Modulus.
- The use of 2²⁵⁶ (a composite number) allows for collisions and multiple solutions in polynomial equations, breaking the mathematical guarantees of SSSS.
2. Impact:
- This flaw completely breaks the scheme, as the shares are meaningless without the Prime Modulus.
- It is possible to recover the original mnemonic from the given two shares, which violates the mathematical security of SSSS.
3. Proof-of-Concept (PoC):
Using the Python code below, the original mnemonic can be recovered from the two provided shares:
from bip_utils import Bip39MnemonicDecoder, Bip39SeedGenerator
import hashlib
# Decode the shares
share1 = "session cigar grape merry useful churn fatal thought very any arm unaware"
share2 = "clock fresh security field caution effort gorilla speed plastic common tomato echo"
def mnemonic_to_bits(mnemonic):
decoder = Bip39MnemonicDecoder()
entropy = decoder.Decode(mnemonic)
return entropy.ToBytes()
# Extract y1 and y2 (first 16 bytes)
y1 = int.from_bytes(mnemonic_to_bits(share1)[:16], byteorder='big')
y2 = int.from_bytes(mnemonic_to_bits(share2)[:16], byteorder='big')
# Brute-Force Attack (Theoretical)
for s_candidate in range(0, 2**128):
a2_candidate = (s_candidate - 2*y1 + y2) // 2
if 0 <= a2_candidate < 2**256:
# Checksum Validation
s_bytes = s_candidate.to_bytes(16, byteorder='big')
checksum = hashlib.sha256(s_bytes).digest()[:1]
if (checksum[0] >> 4) == (s_candidate & 0xF):
print("Recovered Secret:", s_candidate)
mnemonic = Bip39MnemonicEncoder().Encode(s_bytes)
print("Mnemonic:", mnemonic)
break
4. Attack Methodology:
- Step 1: Decode the shares and extract
y1
andy2
. - Step 2: Set up polynomial equations and brute-force
s
. - Step 3: Use checksum validation to find the correct
s
. - Step 4: Convert
s
to a mnemonic and generate the Bitcoin address.
5. Recommendations:
- Use a Prime Modulus (p) in the Shamir Secret Sharing Scheme.
- Share
p
along with the shares to enable secret recovery.
Metadata
Metadata
Assignees
Labels
No labels