这是indexloc提供的服务,不要输入任何密码
Skip to content

bitcoinsSG/Qafray-Vaults

Repository files navigation

Qafray Vaults: A Quantum-Resistant Bitcoin Ownership Proof Mechanism

Qafray Vaults Logo

Overview

Qafray Vaults is a tool designed to provide a proactive, quantum-resistant mechanism for Bitcoin users to safeguard their coins against potential quantum computing attacks. By leveraging SPHINCS+, a hash-based, post-quantum cryptographic signature scheme, Qafray Vaults enables users to embed a quantum-resistant public key in Bitcoin transactions via an OP_RETURN output. This facilitates proof of ownership for unspent transaction outputs (UTXOs) at a specified block height in the event of a quantum attack, without requiring modifications to Bitcoin’s consensus rules or core codebase. The tool integrates with Electrum, a lightweight Bitcoin wallet, to streamline wallet creation, address generation, and transaction construction, ensuring accessibility for users to adopt immediately.

This repository presents an initial implementation for community evaluation, prioritizing ease of use to gather feedback on the proposed mechanism. It aims to enhance Bitcoin’s resilience against quantum threats, specifically addressing scenarios where an adversary employs Shor’s algorithm to compromise ECDSA signatures and advanced quantum techniques to challenge SHA-256-based Proof-of-Work (PoW).

Inspiration

The development of Qafray Vaults is inspired by a concept attributed to Satoshi Nakamoto, who suggested that the Bitcoin community could collectively agree on a “last honest block” to recover from a significant attack, such as a 51% attack. This approach was notably applied in 2010 to address an overflow bug that created 184 billion BTC. In a quantum attack scenario, where an adversary could derive ECDSA private keys from exposed public keys and potentially dominate mining through quantum-accelerated SHA-256 preimage attacks, traditional ECDSA-based ownership proofs become invalid. Moreover, identity-based or social-layer solutions to establish ownership violate Bitcoin’s trustless ethos. Qafray Vaults addresses this challenge by enabling users to embed a SPHINCS+ public key in an OP_RETURN output, providing a cryptographic, non-identity-based proof of ownership that remains secure against quantum adversaries.

Technical Logic

Problem Statement

Quantum computing poses significant threats to Bitcoin’s cryptographic foundations:

  1. Shor’s Algorithm: Enables the derivation of ECDSA private keys from public keys exposed in Bitcoin transactions (e.g., P2PKH addresses after spending), compromising funds in affected addresses.
  2. Advanced Quantum Attacks: Potential quantum algorithms could find SHA-256 preimages, allowing an attacker to dominate Bitcoin’s PoW mining process, disrupt consensus, or reorganize the blockchain.

In a worst-case scenario, a quantum attacker with exceptional capabilities could:

  • Derive private keys for all addresses with exposed public keys, enabling the theft of UTXOs.
  • Overpower mining by efficiently finding SHA-256 nonces, creating blocks or forks at will.

If the Bitcoin community agrees on a “last honest block” to recover from such an attack, users must prove ownership of their UTXOs at that block height. However, ECDSA signatures are compromised, and identity-based solutions are incompatible with Bitcoin’s decentralized principles. Qafray Vaults proposes a mechanism to enable quantum-resistant ownership proofs without altering Bitcoin’s consensus rules.

Proposed Mechanism

Qafray Vaults enables users to proactively secure their Bitcoin by embedding a SPHINCS+ public key in a transaction’s OP_RETURN output. The process is as follows:

  1. SPHINCS+ Key Generation:

    • Users generate a SPHINCS+ key pair using Qafray Vaults, employing the sphincssha2192fsimple algorithm (192-bit security, fast variant). SPHINCS+ is a hash-based signature scheme, resistant to quantum attacks due to its reliance on the one-wayness of hash functions.
    • Command: ./qafray-vault.sh genkey -a sphincssha2192fsimple -o mykey.key
    • Output: mykey.key (private key) and mykey.pub (public key) in the pqc-data directory.
  2. Electrum Wallet Creation:

    • Users create an Electrum wallet (testnet for safety) to manage Bitcoin addresses and transactions. The wallet generates a seed phrase and derives hierarchical deterministic (HD) addresses using the BIP-44 path (e.g., m/44'/1'/0'/0 for testnet).
    • Command: ./qafray-vault.sh create_wallet -o my-wallet
    • Output: Seed phrase and private key for the first address (index 0, path m/44'/1'/0'/0/0).
  3. Receive Address Generation:

    • Users obtain a receive address (index 0) from the Electrum wallet to receive Bitcoin.
    • Command: ./qafray-vault.sh get_address -w my-wallet -i 0
    • Output: A Bitcoin testnet address (e.g., tb1q...).
  4. Transaction with OP_RETURN:

    • Users send their Bitcoin (a UTXO) from the receive address (index 0) to a second address (index 1, path m/44'/1'/0'/0/1) derived from the same seed. The transaction includes an OP_RETURN output containing the SPHINCS+ public key.
    • Command: ./qafray-vault.sh gentx -k mykey.key -p mykey.pub -w my-wallet -u txid:0 -d 1 -o tx.hex
    • The transaction is signed with the ECDSA private key (standard Bitcoin requirement) and broadcast to the network.
    • Output: A raw transaction (tx.hex) with an OP_RETURN embedding the SPHINCS+ public key.
  5. Post-Attack Ownership Proof:

    • In a quantum attack scenario, the community agrees on a “last honest block” before the attack. Users must prove ownership of their UTXOs at this block height.
    • The user provides the transaction ID (txid) of the transaction that included the OP_RETURN with their SPHINCS+ public key.
    • They sign a challenge (e.g., the txid) with their SPHINCS+ private key using ./qafray-vault.sh prove -k mykey.key -i challenge.txt -o proof.sig.
    • The community verifies the signature against the OP_RETURN public key using ./qafray-vault.sh verify -p mykey.pub -i challenge.txt -s proof.sig.
    • Since SPHINCS+ is quantum-resistant, the attacker cannot forge the signature, ensuring only the legitimate owner can reclaim the funds.

Security Analysis

  • Quantum Resistance:

    • SPHINCS+ relies on hash-based cryptography, secure against Shor’s algorithm and quantum preimage attacks on SHA-256. The 192-bit security of sphincssha2192fsimple provides robust protection against both classical and quantum adversaries.
    • The OP_RETURN embeds the SPHINCS+ public key, which cannot be used to derive the private key, even with quantum capabilities.
  • No Consensus Changes:

    • The solution uses standard Bitcoin transactions with OP_RETURN outputs, compatible with the current protocol. No changes to consensus rules or core code are required for adoption.
  • Protection Against Worst-Case Attack:

    • ECDSA Break (Shor’s Algorithm): If an attacker derives ECDSA private keys, funds in the second address (index 1) are safe, as the ownership proof relies on SPHINCS+ signatures.
    • Mining Attack (Advanced Quantum Attacks): Even if the attacker dominates mining by finding SHA-256 preimages, they cannot forge SPHINCS+ signatures, ensuring valid ownership proofs.
    • UTXO Sniping: Funds moved to the second address before the attack are protected, as the attacker cannot forge the SPHINCS+ signature required for proof.
  • Trustless Ethos:

    • The solution avoids identity-based or social-layer dependencies, relying solely on cryptographic proofs verifiable by the community.

Limitations and Future Work

  • Adoption Timeline: Users must proactively send funds to the second address with an OP_RETURN before a quantum attack occurs. Community education is critical to encourage early adoption.
  • Transaction Fees: Including an OP_RETURN output incurs additional fees, which may deter some users.
  • Post-Attack Recovery: The community must agree on a recovery process (e.g., a soft fork to recognize SPHINCS+ signatures or a new chain). Qafray Vaults provides the proof mechanism but relies on community consensus for implementation.
  • Signature Size: SPHINCS+ signatures are larger than ECDSA, limiting their use in direct transaction signing without protocol changes. The OP_RETURN approach mitigates this by using ECDSA for transaction signing.

Future enhancements could include:

  • A graphical user interface (GUI) for non-technical users.
  • Support for SPHINCS+ transaction signing via a custom script (requires a soft fork).
  • Integration with blockchain platforms for broader adoption.

Installation

Prerequisites

  • Docker: Required for running the SPHINCS+ key generation container.
  • Electrum: Install via pip3 install electrum.
  • Bitcoin Testnet: Recommended for testing to avoid risking real funds.

Setup

  1. Clone the repository:

    git clone git@github.com:bitcoinsSG/Qafray-Vaults.git
    cd Qafray-Vaults
  2. Build the Docker image:

    docker build --progress=plain -t qafray-vault .
  3. Install Electrum:

    sudo apt-get update
    sudo apt-get install -y python3-pip
    pip3 install electrum
    electrum --testnet daemon start
  4. Create the data directory:

    mkdir pqc-data
    chmod 700 pqc-data
    chown $(id -u):$(id -g) pqc-data

Usage

  1. Generate SPHINCS+ Key Pair:

    ./qafray-vault.sh genkey -a sphincssha2192fsimple -o mykey.key
  2. Create Electrum Wallet:

    ./qafray-vault.sh create_wallet -o my-wallet
    • Back up the displayed seed phrase and private key securely.
  3. Get Receive Address:

    ./qafray-vault.sh get_address -w my-wallet -i 0
    • Send testnet Bitcoin to this address (e.g., via testnet-faucet.mempool.co).
  4. Generate Transaction with OP_RETURN:

    ./qafray-vault.sh gentx -k mykey.key -p mykey.pub -w my-wallet -u txid:0 -d 1 -o tx.hex
    • Broadcast the transaction:
      electrum --testnet broadcast $(cat pqc-data/tx.hex)
  5. Prove Ownership:

    echo "<txid>" > pqc-data/challenge.txt
    ./qafray-vault.sh prove -k mykey.key -i challenge.txt -o proof.sig
    ./qafray-vault.sh verify -p mykey.pub -i challenge.txt -s proof.sig
  6. List SPHINCS+ Algorithms:

    ./qafray-vault.sh list

Real World Example:

-----BEGIN PUBLIC KEY-----

MD0wCAYGK84PBgUKAzEAO6b2ewf0qubKTi1X7Zc9sCdRcbf8SdxM9BmHlGUSFXE5 eFwOCDrCDuDvN/whyOxU

-----END PUBLIC KEY-----

Hex:

303d300806062bce0f06050a0331003ba6f67b07f4aae6ca4e2d57ed973db0275171b7fc49dc4cf41987946512157139785c0e083ac20ee0ef37fc21c8ec54

Transaction on Bitcoin's timechain with Qafray Vault designation

https://mempool.space/tx/ec10e8ad5e57bfe671789c7f5b35fbcf6d5216a8e2224adc990df53c9f74979a

Community Feedback

This implementation is an initial prototype to gather community feedback on the proposed quantum-resistant ownership proof mechanism. Please test the tool, review the logic, and provide feedback via GitHub issues or discussions. Key questions for evaluation:

  • Is the SPHINCS+ OP_RETURN approach effective for proving ownership post-quantum attack?
  • How can usability be improved for non-technical Bitcoin users?
  • What are the practical challenges of adopting this mechanism at scale?

License

MIT License

Acknowledgments

This work is inspired by Satoshi Nakamoto’s vision of community-driven recovery and ongoing efforts in the Bitcoin community to address quantum computing threats, including proposals like P2QRH.

About

A last resort safety net for a quantum compromised timechain

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published