โš›๏ธ Quantum Computing Playground

Explore quantum algorithms in your browser!

๐Ÿ”— Bell State - Quantum Entanglement

Create maximally entangled qubits and observe the mysterious quantum correlation!

๐Ÿ“š Show Theory & Explanation

๐Ÿง  What is a Bell State?

A Bell state is one of four specific maximally entangled quantum states of two qubits. The most famous is called ฮฆ+ (Phi-plus), which we create in this experiment.

|ฮฆ+โŸฉ = (|00โŸฉ + |11โŸฉ) / โˆš2

This notation means the two qubits exist in a superposition where they are simultaneously in states |00โŸฉ and |11โŸฉ with equal probability (50% each).

๐Ÿ”— What is Entanglement?

Entanglement is a quantum phenomenon where two or more particles become correlated in such a way that the quantum state of one particle cannot be described independently of the others, even when separated by large distances.

Key Insight: When you measure the first qubit, you instantly know what the second qubit will be! If qubit 1 is |0โŸฉ, qubit 2 will also be |0โŸฉ. If qubit 1 is |1โŸฉ, qubit 2 will be |1โŸฉ. This correlation happens faster than light could travel between them!

๐Ÿ”ง How the Circuit Works

We create the Bell state using just two quantum gates:

  • Hadamard Gate (H): Applied to the first qubit, creating superposition:
    |0โŸฉ โ†’ (|0โŸฉ + |1โŸฉ) / โˆš2
  • CNOT Gate (Controlled-NOT): Creates entanglement between the qubits. If the first qubit (control) is |1โŸฉ, it flips the second qubit (target).

๐Ÿ“Š What You'll Observe

After many measurements (shots), you should see:

  • ~50% |00โŸฉ: Both qubits measured as 0
  • ~50% |11โŸฉ: Both qubits measured as 1
  • ~0% |01โŸฉ or |10โŸฉ: The qubits are never in different states!
Why This Matters: This "spooky action at a distance" (as Einstein called it) is the foundation of quantum computing, quantum cryptography, and quantum teleportation!

๐ŸŒŠ Quantum Superposition

Create qubits in multiple states simultaneously - quantum parallelism in action!

๐Ÿ“š Show Theory & Explanation

๐Ÿง  What is Quantum Superposition?

Superposition is one of the most fundamental principles in quantum mechanics. It means that a quantum system can exist in multiple states at the same time until it is measured.

Classical vs Quantum: A classical bit is either 0 OR 1. A qubit in superposition is 0 AND 1 simultaneously! Only when you measure it does it "collapse" to one value.

๐ŸŽฏ Single Qubit Superposition

For a single qubit, we can write its state as:

|ฯˆโŸฉ = ฮฑ|0โŸฉ + ฮฒ|1โŸฉ

Where ฮฑ and ฮฒ are complex numbers (amplitudes) that determine the probability of measuring |0โŸฉ or |1โŸฉ. The probabilities are |ฮฑ|ยฒ and |ฮฒ|ยฒ, and they must sum to 1.

๐ŸŽฒ Equal Superposition

In this experiment, we create an equal superposition using the Hadamard gate:

|ฯˆโŸฉ = (|0โŸฉ + |1โŸฉ) / โˆš2

This means: 50% probability of measuring 0, and 50% probability of measuring 1.

๐Ÿš€ Exponential Growth with Multiple Qubits

The real power comes when we have multiple qubits in superposition. With n qubits, we can represent 2n states simultaneously!

  • 1 qubit: 2 states (|0โŸฉ, |1โŸฉ)
  • 2 qubits: 4 states (|00โŸฉ, |01โŸฉ, |10โŸฉ, |11โŸฉ)
  • 3 qubits: 8 states
  • 4 qubits: 16 states
  • 5 qubits: 32 states
  • 6 qubits: 64 states - all at once!
Quantum Parallelism: This exponential scaling is why quantum computers are so powerful! They can process all these states in parallel, which would require 2n classical computers running simultaneously.

๐Ÿ”ง How It Works

We apply the Hadamard gate (H) to each qubit:

  • Each H gate puts one qubit into equal superposition
  • When combined, they create a superposition of all possible bit strings
  • All 2n states exist simultaneously until measurement

๐Ÿ“Š What You'll Observe

After measurement, each of the 2n possible states should appear with approximately equal probability (1/2n or about 100/2n percent).

Try increasing the number of qubits and watch how the number of possible outcomes grows exponentially!

Why This Matters: Superposition enables quantum algorithms to explore many solutions simultaneously, giving quantum computers their computational advantage for certain problems.

๐Ÿ” Grover's Search Algorithm

Search for an item with quantum speedup - demonstrating real quantum advantage!

๐Ÿ“š Show Theory & Explanation

๐Ÿง  What is Grover's Algorithm?

Grover's algorithm, discovered by Lov Grover in 1996, is a quantum search algorithm that finds a specific item in an unsorted database. It provides a quadratic speedup over any classical algorithm.

The Speedup: Classical search requires checking N/2 items on average (or N in worst case). Grover's algorithm needs only about โˆšN queries!

๐Ÿ“Š Speedup Comparison

See how the advantage grows with database size:

  • 4 items: Classical: ~2 queries, Quantum: 1 query (2x faster)
  • 16 items: Classical: ~8 queries, Quantum: 3 queries (2.7x faster)
  • 64 items: Classical: ~32 queries, Quantum: 6 queries (5.3x faster)
  • 1000 items: Classical: ~500 queries, Quantum: 25 queries (20x faster!)
  • 1,000,000 items: Classical: ~500,000 queries, Quantum: 1,000 queries (500x faster!)

๐ŸŽฏ The Problem

Imagine you have an unsorted database (like a phone book in random order) and you need to find one specific entry. Classically, you'd have to check entries one by one until you find it.

โšก The Quantum Solution

Grover's algorithm works through two main operations repeated in a loop:

1๏ธโƒฃ The Oracle

A quantum circuit that "marks" the target item by flipping its phase. It doesn't tell us which item is the target, but it changes its quantum amplitude in a way we can exploit.

Oracle: |xโŸฉ โ†’ (-1)f(x)|xโŸฉ

Where f(x) = 1 for the target item and 0 for all others.

2๏ธโƒฃ The Diffusion Operator (Amplitude Amplification)

This operation amplifies the amplitude of the marked item while reducing the amplitudes of all other items. It's like making the target "brighter" and the rest "dimmer" in the quantum superposition.

How It Works: Think of it like searching in a dark room with a flashlight that gets brighter each time you swing it. After โˆšN swings, the target item is so bright you can't miss it!

๐Ÿ”„ Iteration Count

The optimal number of iterations is approximately ฯ€/4 ร— โˆšN. Too few iterations and you won't find the target. Too many and the probability actually decreases!

  • 4 items (2 qubits): 1 iteration โ†’ ~100% success
  • 8 items (3 qubits): 2 iterations โ†’ ~95% success
  • 16 items (4 qubits): 3 iterations โ†’ ~100% success

๐Ÿ”ง Circuit Structure

The algorithm follows these steps:

  1. Initialize: Create equal superposition of all states using Hadamard gates
  2. Repeat โˆšN times:
    • Apply Oracle (mark the target)
    • Apply Diffusion operator (amplify the target)
  3. Measure: The target state has very high probability!

๐Ÿ“Š What You'll Observe

After running the circuit, you should see the target item measured with very high probability (~90-100%), while all other items appear much less frequently.

The green bar in the chart highlights the target item you're searching for.

Why This Matters: Grover's algorithm proves that quantum computers can solve certain problems faster than classical computers. It has applications in database search, cryptography, optimization, and machine learning!

๐ŸŽ“ Fun Fact

While โˆšN speedup might not sound as impressive as the exponential speedups in some other quantum algorithms, it's actually provably optimal for unstructured search. No quantum algorithm can do better than Grover's!

๐Ÿ” Hash Breaking with Grover's Algorithm

Demonstrate how Grover's algorithm could theoretically attack hash functions!

๐Ÿ“š Show Theory & Explanation

๐Ÿง  What is Hash Breaking?

A preimage attack on a hash function means finding an input that produces a specific hash output. This is "reversing" or "breaking" the hash.

Given: hash value h
Find: input x where hash(x) = h
Important: This demonstration uses a TOY 2-4 bit hash function, not real SHA-256! Real SHA-256 would require billions of qubits and is still secure against quantum attacks.

๐ŸŽฏ The Problem

Hash functions are designed to be one-way:

  • Easy: Computing hash(x) is fast
  • Hard: Finding x given hash(x) should be impossible

โšก Quantum Attack with Grover's

Grover's algorithm can speed up the search for preimages:

  • Classical brute force: Try N/2 inputs on average
  • Grover's algorithm: Try โˆšN inputs
  • Speedup: Quadratic (not exponential!)

๐Ÿ”ข Example: 2-bit Hash

With a 2-bit hash, there are only 4 possible outputs (0, 1, 2, 3). Given target hash = 3:

  • Search space: 4 possible inputs (with 2-bit inputs)
  • Classical: Try ~2 inputs on average
  • Grover's: 1 iteration to find the answer!

๐Ÿ›ก๏ธ Why SHA-256 Stays Safe

Real SHA-256 has 256 bits of output:

Classical attack: 2256 โ‰ˆ 1077 tries
Grover's attack: 2128 โ‰ˆ 1038 tries

Even with quantum speedup, 1038 operations is still:

  • Billions of years on perfect quantum computer
  • Requires billions of qubits (we have ~1,000 today)
  • More energy than the sun produces
Security Reduction: SHA-256 loses half its bit security (256 โ†’ 128 bits), but 128 bits is STILL computationally secure!

๐Ÿ“Š Scaling Comparison

Hash Bits Classical Tries Grover Tries Status
2 2 1 Trivial
64 1018 4ร—109 Hard
128 1037 1019 Secure
256 (SHA-256) 1076 1038 Very Secure

๐ŸŽ“ What You'll Learn

This demonstration shows:

  • How to encode hash functions as quantum oracles
  • Grover's algorithm applied to preimage attacks
  • Why quadratic speedup isn't enough to break strong hashes
  • The difference between theoretical and practical attacks
Bottom Line: While Grover's algorithm CAN theoretically attack hashes, SHA-256 remains quantum-resistant due to its large output space. The real quantum threat is to public-key cryptography (RSA, ECC) which is completely broken by Shor's algorithm!

Bitcoin Address Attack with Quantum Algorithms

Analyze quantum threats to Bitcoin and see why addresses remain secure!

๐Ÿ“š Show Theory & Explanation

How Bitcoin Cryptography Works:

Private Key (256 bits, secret)
        โ†“
    [ECDSA Elliptic Curve Math]
        โ†“
Public Key (512 bits, derived from private)
        โ†“
    [SHA-256 โ†’ RIPEMD-160]
        โ†“
Bitcoin Address (160 bits, public)

Two Quantum Attack Vectors:

Aspect Grover's on Address Shor's on Public Key
Target Bitcoin Address (hash) Public Key (ECDSA)
Speedup Quadratic (โˆšN) Exponential
Security 2^256 โ†’ 2^128 (still secure) ~2^128 โ†’ BROKEN!
Qubits Needed Billions ~4,000 error-corrected
Threat Level โœ… Low โŒ CRITICAL

The Real Threat Timeline:

  • 2025 (Current): ~1,000 noisy qubits - Bitcoin safe
  • 2030-2035: Estimated 4,000+ error-corrected qubits - DANGER ZONE for signatures
  • 2040: Large-scale quantum computers likely - Bitcoin must be upgraded

๐Ÿ” Minimum Bits Grover's Can Break:

Key Size Search Space Qubits Grover Iterations Status
4 bits 16 4 ~3 โœ… TRIVIAL (this demo!)
8 bits 256 8 ~12 โœ… EASY (educational)
16 bits 65,536 16 ~201 โš ๏ธ POSSIBLE (2025 tech)
32 bits 4.3 billion 32 ~51,000 โš ๏ธ THEORETICAL
64 bits 18 quintillion 64 ~3.4 billion ๐Ÿ”’ HARD
128 bits 3.4 ร— 10ยณโธ 128 ~10ยนโน ๐Ÿ”’ QUANTUM SECURE
256 bits 1.16 ร— 10โทโท 256 ~10ยณโธ ๐Ÿ”’ BITCOIN SECURE!
๐Ÿ’ก Why This Demo Uses 4-8 Bits:
  • 4 bits: Only 4 qubits, 3 iterations โ†’ runs instantly!
  • 8 bits: 8 qubits, 12 iterations โ†’ perfect for learning
  • 256 bits (Bitcoin): Would take billions of years โ†’ completely secure!
Even with quantum speedup, Bitcoin's 2ยฒโตโถ โ†’ 2ยนยฒโธ is still impossible!
โš ๏ธ Key Insight: Bitcoin addresses (hashes) remain safe, but ECDSA signatures will be vulnerable. Bitcoin needs to upgrade to post-quantum signatures (like CRYSTALS-Dilithium) before 2030-2040.

๐Ÿ” Bitcoin Address Analysis

Enter a Bitcoin address to analyze quantum attack feasibility (or use an example):

๐Ÿ’ฐ DeFi Arbitrage Optimizer with Quantum QAOA

Find optimal multi-hop swap paths across decentralized exchanges using quantum optimization!

๐Ÿ“š Show Theory & Explanation

๐ŸŽฏ What is DeFi Arbitrage?

DeFi arbitrage is the practice of profiting from price differences across decentralized exchanges (DEXs). A trader might swap ETH โ†’ USDC โ†’ DAI โ†’ WBTC โ†’ ETH, ending with more ETH than they started with!

The Challenge: With N tokens and K hops, there are exponentially many possible paths to check. For 10 tokens and 5 hops, that's over 100,000 combinations!

โš›๏ธ How Quantum Helps: QAOA

QAOA (Quantum Approximate Optimization Algorithm) is specifically designed for combinatorial optimization problems like finding the best arbitrage path.

How QAOA Works:

  1. Encode the Problem: Convert the arbitrage problem into a quantum Hamiltonian (energy function)
  2. Quantum Superposition: Create a superposition of ALL possible paths simultaneously
  3. Optimize Parameters: Use alternating Cost and Mixer Hamiltonians to evolve toward optimal solutions
  4. Measure Results: Collapse the quantum state to find high-profit paths
|ฯˆ(ฮณ,ฮฒ)โŸฉ = e^(-iฮฒH_M) e^(-iฮณH_C) |+โŸฉ^โŠ—n

Where H_C encodes profitability (Cost Hamiltonian) and H_M allows exploration (Mixer Hamiltonian)

๐Ÿ’ผ Real-World Usage in Finance

Quantum optimization is ALREADY being used by financial institutions:
Institution Application Technology
BBVA (Bank) Portfolio optimization QAOA on AWS Braket
JPMorgan Chase Portfolio risk analysis Quantum annealing
Goldman Sachs Options pricing Quantum Monte Carlo
QAIT Platform MEV & arbitrage optimization D-Wave Advantage-2

๐Ÿ“Š Why Quantum Wins for DeFi Optimization

Comparison: Bitcoin Breaking vs DeFi Optimization

Problem Type Bitcoin Breaking DeFi Arbitrage
Problem Class Unique search (needle in haystack) โœ… Optimization (find best)
Quantum Algorithm Grover's (limited speedup) โœ… QAOA (polynomial advantage)
Qubits Needed Millions (impractical) โœ… 10-50 (available today!)
Works on Current Hardware? โŒ No (needs FTQC ~2040) โœ… Yes (working now!)
Real-World Use โŒ Theoretical only โœ… Banks using it today
Key Insight: While quantum can't break Bitcoin's cryptography (yet), it CAN optimize DeFi strategies RIGHT NOW! This is because optimization problems have structure that quantum computers exploit, while hash functions are intentionally structureless.

๐Ÿš€ The Future: Quantum DeFi Trading

By 2028-2030, quantum-enhanced DeFi bots may:

  • Find arbitrage opportunities in milliseconds instead of seconds
  • Optimize cross-chain paths (Ethereum โ†” Polygon โ†” Arbitrum)
  • Calculate optimal MEV strategies (Maximal Extractable Value)
  • Dynamically adjust to gas prices and slippage

Timeline Estimate: Quantum advantage for simple arbitrage is achievable with ~100 qubits (available by 2026). For complex multi-chain strategies, we'll need ~1000 qubits (estimated 2028-2030).

๐Ÿ”ง DeFi Arbitrage Configuration

โ„น๏ธ Note: This demo uses mock DEX prices. In production, you'd fetch real-time prices from Uniswap, SushiSwap, Curve, etc.