Creating a Quantum Bitcoin Seed Phrase using IBM's 127-Qubit Sherbrooke Quantum Computer

This experiment uses IBM’s 127-Qubit quantum computer 'Sherbrooke', with Qiskit, to generate a Bitcoin seed phrase consisting of 24 words from the BIP-39 standard list. Quantum computers harness key quantum mechanical properties such as superposition and entanglement, enhancing the system's randomness and security. Initially, each qubit is set in a superposition state, ensuring that its measurement outcome is entirely random. These random outcomes directly select words from the BIP-39 list, effectively increasing the entropy and thereby boosting the cryptographic security of the generated seed phrase.

Code Walkthrough
1. Quantum Circuit Initialization:
The quantum circuit is initialized with 24 qubits. Each qubit corresponds to a potential word in the Bitcoin seed phrase. The initialization process involves setting each qubit into a basic state, denoted as ∣0⟩.

2. Superposition:
Each qubit is then put into a state of superposition using Hadamard gates. The Hadamard gate (H) is applied to each qubit, transforming the initial state ∣0⟩ to (∣0⟩ + ∣1⟩)/sqrt(2)​. This operation ensures that each qubit has an equal probability of being measured as either 0 or 1.

H∣0⟩ = 1/sqrt(2) * ​(∣0⟩ + ∣1⟩)

3. Measurement:
After applying the Hadamard gates, all qubits are measured. The quantum measurement collapses each qubit's superposition state to either 0 or 1 with equal probability. The outcome for the 24 qubits collectively forms a binary string.

4. Conversion to Indices:
The binary string from the measurements is then interpreted as a sequence of numbers. Since the BIP-39 standard consists of 2048 words, each group of qubits must represent a number from 0 to 2047 (which requires at least 11 bits per number since 2^11=2048). Depending on the length of the measurement string and the bit requirements, the binary string is divided accordingly.

Index = int(binary string, 2)mod2048

5. Word Selection:
Each index obtained from the binary string is used to select a word from the BIP-39 text file. The selected words collectively form the Bitcoin seed phrase.

6. Compilation and Execution on Quantum Backend:
The quantum circuit is compiled for IBM's Sherbrooke backend. The compiled circuit is then executed. To achieve reliable results, 4000 shots are performed during the execution. This high number of shots helps in achieving statistical significance, ensuring that the probabilistic outcomes of quantum measurements are accurately represented. More shots provide a larger dataset, reducing the impact of quantum noise and operational errors on the final measurement outcomes.

7. Output:
The final output is a 24-word Bitcoin seed phrase, generated from true quantum randomness.

Results:

Generated Bitcoin Seed Phrase:

day margin rough nasty attract sample conduct scheme seat defy advance kind mammal hybrid good beauty laundry speak type cousin spike outdoor city fit

This experiment effectively demonstrates the use of quantum mechanics to achieve cryptographic security in generating a correctly formatted BIP-39 Bitcoin seed phrase. The approach capitalizes on the inherent randomness of quantum mechanics, providing a potential advantage over classical random number generators in terms of unpredictability and increased entropy.

Sherbrooke Backend and Run:

The Entropy Heatmap above reflects two key parameters - qubit count and gate fidelity. The horizontal axis represents different levels of gate fidelity from 90% to 99%. Higher fidelity generally leads to more accurate quantum operations. The vertical axis varies from 5 to 24 qubits. More qubits increase the complexity and potential for higher entropy, assuming effective management of decoherence and errors. The color intensity in each cell indicates the entropy level, with brighter colors denoting higher entropy. This visually captures how entropy changes with varying qubit counts and gate fidelities. The heatmap can identify optimal regions where both the number of qubits and the accuracy of quantum operations balance to produce the highest entropy, which is critical for secure quantum cryptographic applications like seed phrase generation.

The 2D heatmap above represents the probabilities of quantum states for a slice of 12 qubits from this experiment. The x-axis represents the different quantum states of the last 12 qubits. The y-axis represents different bins of probability values associated with these states. Each cell in the heatmap corresponds to a particular quantum state (on the x-axis) and a probability range (on the y-axis). The color of each cell indicates the frequency of occurrence of that state within the specified probability range. A color closer to yellow or white signifies a higher frequency, while darker colors like blue indicate a lower frequency. White text inside each cell provides the exact count of occurrences for that specific state and probability bin. On the right, a color bar that maps colors to their corresponding counts. This bar helps in understanding which colors represent higher or lower frequencies.

Code:

# imports
import json
from qiskit import QuantumCircuit
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit_ibm_runtime import QiskitRuntimeService, RuntimeOptions
import numpy as np

# Setup IBMQ account
API_KEY = 'Your_IBMQ_Key_Here_O-`'  # Replace with IBMQ API key
service = QiskitRuntimeService(channel='ibm_quantum', token=API_KEY)

backend = service.backend('ibm_sherbrooke')  # IBM backend 

# Load BIP-39 words from text file
with open('/Users/Documents/BIPwords.txt', 'r') as file:
    bip39_words = file. read().splitlines()

def generate_seed_phrase(num_qubits, backend):
    circ = QuantumCircuit(num_qubits)
    for i in range(num_qubits):
        circ.h(i)  # Apply Hadamard gate to create superposition
    circ.measure_all()

    # Transpile the circuit for backend
    pm = generate_preset_pass_manager(optimization_level=1, target=backend. target)
    transpiled_circuits = pm. run([circ])

    # Execute the circuit with Qiskit Runtime
    options = RuntimeOptions(backend=backend. name)
    job = service. run(program_id="sampler", inputs={'circuits': transpiled_circuits}, options=options)
    result = job.result()

    # Accessing quasi-probabilities from SamplerResult
    quasi_probs = result.quasi_dists[0]  # Get the quasi-probability distribution of the first (and only) circuit
    # Check if quasi_probs is empty or contains zero probabilities
    if not quasi_probs or all(prob == 0 for prob in quasi_probs.values()):
        raise ValueError("Invalid or zero quasi-probabilities obtained from the quantum computation.")

    # Extract probabilities and normalize them
    probabilities = list(quasi_probs.values())
    normalized_probabilities = np.array(probabilities) / np.sum(probabilities)
    # Randomly choose indices based on the normalized probabilities
    indices = np.random.choice(len(normalized_probabilities), size=num_qubits, p=normalized_probabilities)
    seed_words = [bip39_words[i % 2048] for i in indices]

    return seed_words

# Generate the seed phrase using the quantum computer
seed_phrase = generate_seed_phrase(24, backend)

# Print the generated seed phrase
print("Generated Bitcoin Seed Phrase:", ' '.join(seed_phrase))
    
# end