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).
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.
Quantum computing poses significant threats to Bitcoin’s cryptographic foundations:
- 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.
- 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.
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:
-
SPHINCS+ Key Generation:
- Users generate a SPHINCS+ key pair using Qafray Vaults, employing the
sphincssha2192fsimplealgorithm (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) andmykey.pub(public key) in thepqc-datadirectory.
- Users generate a SPHINCS+ key pair using Qafray Vaults, employing the
-
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'/0for 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).
- 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.,
-
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...).
-
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 anOP_RETURNoutput 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 anOP_RETURNembedding the SPHINCS+ public key.
- Users send their Bitcoin (a UTXO) from the receive address (index 0) to a second address (index 1, path
-
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_RETURNwith 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_RETURNpublic 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.
-
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
sphincssha2192fsimpleprovides robust protection against both classical and quantum adversaries. - The
OP_RETURNembeds the SPHINCS+ public key, which cannot be used to derive the private key, even with quantum capabilities.
- SPHINCS+ relies on hash-based cryptography, secure against Shor’s algorithm and quantum preimage attacks on SHA-256. The 192-bit security of
-
No Consensus Changes:
- The solution uses standard Bitcoin transactions with
OP_RETURNoutputs, compatible with the current protocol. No changes to consensus rules or core code are required for adoption.
- The solution uses standard Bitcoin transactions with
-
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.
- Adoption Timeline: Users must proactively send funds to the second address with an
OP_RETURNbefore a quantum attack occurs. Community education is critical to encourage early adoption. - Transaction Fees: Including an
OP_RETURNoutput 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_RETURNapproach 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.
- 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.
-
Clone the repository:
git clone git@github.com:bitcoinsSG/Qafray-Vaults.git cd Qafray-Vaults -
Build the Docker image:
docker build --progress=plain -t qafray-vault . -
Install Electrum:
sudo apt-get update sudo apt-get install -y python3-pip pip3 install electrum electrum --testnet daemon start
-
Create the data directory:
mkdir pqc-data chmod 700 pqc-data chown $(id -u):$(id -g) pqc-data
-
Generate SPHINCS+ Key Pair:
./qafray-vault.sh genkey -a sphincssha2192fsimple -o mykey.key
-
Create Electrum Wallet:
./qafray-vault.sh create_wallet -o my-wallet
- Back up the displayed seed phrase and private key securely.
-
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).
- Send testnet Bitcoin to this address (e.g., via
-
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)
- Broadcast the transaction:
-
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
-
List SPHINCS+ Algorithms:
./qafray-vault.sh list
-----BEGIN PUBLIC KEY-----
MD0wCAYGK84PBgUKAzEAO6b2ewf0qubKTi1X7Zc9sCdRcbf8SdxM9BmHlGUSFXE5 eFwOCDrCDuDvN/whyOxU
-----END PUBLIC KEY-----
303d300806062bce0f06050a0331003ba6f67b07f4aae6ca4e2d57ed973db0275171b7fc49dc4cf41987946512157139785c0e083ac20ee0ef37fc21c8ec54
https://mempool.space/tx/ec10e8ad5e57bfe671789c7f5b35fbcf6d5216a8e2224adc990df53c9f74979a
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_RETURNapproach 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?
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.