Warning: This software is experimental and should not be used in production.
First, install Risc0
toolchain. You can refer to here.
To build Risc0 guests deterministically, run the following command:
BITCOIN_NETWORK=mainnet REPR_GUEST_BUILD=1 cargo build --release
To prove Bitcoin headers, first download the Bitcoin headers and rename it to "mainnet-headers.bin":
wget https://static.testnet.citrea.xyz/conf/headers.bin -O mainnet-headers.bin
./target/release/core None first_10.bin 10
- The first argument is the previous proof file path (
None
if starting from genesis). - The second argument is the output proof file path.
- The third argument is the number of headers to prove.
Example: To verify the previous proof and prove the next 90 Bitcoin headers, run the following command:
./target/release/core first_10.bin first_100.bin 90
BitVM requires a Groth16 proof (preferably with one public input). We have implemented the necessary functionalities to support this.
First download the STARK Verify Circom circuit:
git lfs pull
To build the prover:
cd groth16_proof
docker build -f docker/prover.Dockerfile . -t risc0-groth16-prover
cd ..
To test the setup, use:
cargo test -r --package core --bin core -- tests --show-output
Our goal is to be able to (optimistically) prove any computation inside BitVM. Overall system is as follows:
⬇️
ZK Proof 1: Succinct STARK Proof via Risc0 ZKVM
⬇️
ZK Proof 2: With constant-sized (32 bytes) digest of the journal of the previous proof (Succinct STARK Proof via Risc0 ZKVM)
⬇️
Groth16 Proof: Single public output binding the previous circuits with Blake3 hashing
(via Risc0's STARK Verifier Circom circuit + our Circom circuit for end-to-end binding)
⬇️
BitVM
Here, the journals with non-constant sizes of the general-purpose circuits will be digested (etc. hashing using Blake3) with the circuit constants (
general_purpose_circuit_method_id
,final_circuit_method_id
,pre_state
,post_state
, etc.) in BitVM to ensure the correctness of the claims.
In the case of Bitcoin, the main computations we want to prove are the bridge operations (PegIn/PegOut). This requires the proving of the Bitcoin block headers. With header-chain-circuit
, one can prove the current state of the Bitcoin given the block headers. It does not necessarily prevent the malicious actors to generate proofs for their private forks, but the calculation of the ChainState
is the basis for the conflict resolution. For more, see:
Proof of work.
With a small modification to final-circuit
, anyone can prove the inclusion of a transaction inside a block on the header chain.
- Risc0: This repository is built using the technology stack of Risc0, more specifically Risc0 ZKVM and their STARK verifier Circom circuit.
- Blake3 Circom: The Circom circuit of the Blake3 hash function implementation is taken from here.
- Bitcoin Header Chain Proof: Our Bitcoin header chain proof circuit implementation is inspired by the Bitcoin Core implementation and ZeroSync's header chain proof circuit.