How BitVM2 works

The bitvm2 paper describe a simpler way to achieve bridging bitcoin to l2. By looking into its codebase as of the commit 834199a, here are some notes on the key concepts from both the paper and the implementations.

emulating covenant

Covenant is a way to enforce the rules of how the UTXOs can be spent. Bitcoin doesn't have native covenant. BitVM relies on multi-signatures make agreements on the set of the possible transactions that guide the possible routes of where the UTXOs can be.

Screenshot 2025-01-17 at 21.00.17.png

Take this diagram for example.

  1. The outputs of the Claim tx are multi signed.
  2. They can be only consumed by either the Challenge tx or PayoutOptimistic, as the multi sigs is an agreement on this restriction.
  3. If it is consumed by the Challenge tx, then the route to the PayoutOptimistic tx is disabled, because that output is consumed.
  4. Otherwise, after a certain period of time, the operator can unlock it for PayoutOptimistic tx.

The taproot script makes it passible to achieve this, as it makes a single UTXO spendable by multiple paths.

emulating statefulness

To enable large amount of calculation on bitcoin blockchain, one idea is to chunk a program to sub-programs, each of which is embedded in a unspent output script, such that:

zi=fi(zi1)

The sub programs be wired up by their inputs and outputs, and eventually results in the last output zi that represents the output of the original program.

However, the current bitcoin transaction script is stateless. There is no native way to pass the calculated state like zi from an input to the output through a transaction.

One time signature like lamport signature enables statefulness on bitcoin blockchain. In bitvm2 codebase, it uses winternitz.

emulating general computation

BitVM2 relies on snark verifier to prove the validity of a program execution. This makes it more succinct than executing the actual program on chain, such that the commitment data is small enough to post on chain for the challengers to review off-chain.

The snark verifier can be chunked into sub programs, which are the same for different transactions. The witnesses posted on chain can be used as intermediate states to verify with these sub programs in order to identify the fraudulent witness off-chain if any.

bitvm1 vs bitvm2

Compared with BitVM1, BitVM2 doesn't verify every opcodes and memory of the program execution directly, instead it verifies the intermediate results representing a verification of a snark proof.

bitvm1

bitvm2

statefulness via one time signature

zi=fi(zi1)zi+1=fi+1(zi)

implementation

The implementation of the bitvm2 consists of the following key components.

BitVMClient

BitVMClient seems to be synchronizer for the bitvm2. I think one of its purposes is to achieve the covenant.

When it needs to require multiple signatures and other parties to sign it, it would rely on this synchronizer to broadcast the un-finalized transaction, and manage the status and ongoing workflow.

Screenshot 2025-01-17 at 21.56.11.png

Screenshot 2025-01-17 at 21.56.31.png

transaction graphs

A transaction graph is a set of transactions for a particular workflow. Some of these transactions are pre-signed for the covenant purpose.

The connections between the transactions are made by connectors.

connectors

Connectors encapsulates both the lock and unlock script for a specific type of UTXO.

For example:

Screenshot 2025-01-17 at 22.04.39.png

How deposit works

When the depositors want to top up their asset in the L2, they initiate a peg in graph which consists of the following transactions:

The workflow is:

  1. the depositor sign and broadcast the PegInTransaction.
  2. the L2 system detected the transaction, sign PegInConfirmTransaction and broadcast it.
  3. at this point, the depositor can complete the multi signature and broadcast it to confirm the deposit.
  4. also the depositor can withdraw the money by making a refund transaction after the time lock, if the PegInConfirmTransaction is not finalized.

The path to either refund or confirm is achieved by the ConnectorZ:

Screenshot 2025-01-17 at 22.10.30.png

As this workflow involve multi-sign and broadcasting un-finalized transaction, it is guided through the BitVMClient.

program chunkers

The snark verifier is chunked into segments (sub programs), each of which can be executed on chain to verify an intermediate state, both the input and result in order to do the following check:

zi=fi(zi1)

If this check fails, a corresponding taproot UTXO can be spent with the fraud witness in a disprove transaction.

There are a number of different chunkers for chunking different parts of the snark verifier. I think this is one of the most complication part in the codebase.

codebase evaluation

Overall the codebase seems still in its early stage. The transaction graphs doesn't match up with the bitvm2 paper. some are added, some are renamed.