> For the complete documentation index, see [llms.txt](https://ibvm.gitbook.io/ibvm-doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ibvm.gitbook.io/ibvm-doc/bitcoin-integration-layer.md).

# Bitcoin Integration Layer

The Bitcoin Integration Layer is responsible for anchoring IBVM state to the Bitcoin blockchain and managing the movement of BTC between the base layer and IBVM.

## BTC Bridge Protocol

The bridge protocol uses a combination of threshold signatures and time-locked contracts to enable secure deposits and withdrawals.

### **Deposit Process**

1. User initiates deposit by sending BTC to a special bridge address
2. Bridge monitors for deposit transactions on the Bitcoin blockchain
3. Upon confirmation (typically 6 blocks), the bridge contract mints equivalent BTC tokens on IBVM
4. The deposit is recorded in the IBVM state with a reference to the Bitcoin transaction

### Mathematical representation:

* Let $TX\_{BTC}$ be the Bitcoin transaction
* Let $Addr\_{bridge}$ be the bridge address
* Let $Amount\_{BTC}$ be the deposit amount
* Let $User\_{addr}$ be the user's IBVM address

The bridge contract executes: $IBVM.mint(User\_{addr}, Amount\_{BTC}) \iff TX\_{BTC}.recipient = Addr\_{bridge} \land TX\_{BTC}.confirmations \geq 6$

### **Withdrawal Process**

1. User initiates withdrawal from IBVM
2. System burns the equivalent BTC tokens on IBVM
3. Bridge validators sign a multi-signature transaction
4. After the challenge period expires, BTC is released to the user's Bitcoin address

### Mathematical representation:

* Let $H\_s$ be the IBVM state root before withdrawal
* Let $H\_{s'}$ be the IBVM state root after withdrawal
* Let $Proof\_w$ be the validity proof for the withdrawal
* Let $Addr\_{BTC}$ be the recipient's Bitcoin address

The bridge validators verify: $Verify(H\_s, H\_{s'}, Proof\_w) = true$

Then execute: $TX\_{withdrawal} = Sign\_{threshold}(Addr\_{BTC}, Amount\_{BTC})$

## Commitment Scheme

The commitment scheme anchors IBVM state roots to the Bitcoin blockchain, using an efficient representation to minimize on-chain data.

1. The state root $H\_s$ is a Merkle root of all accounts and their states in IBVM
2. For each batch of transactions, a new state root $H\_{s'}$ is computed
3. A ZK-SNARK proof $\pi$ is generated that verifies the correctness of the state transition from $H\_s$ to $H\_{s'}$
4. The commitment $C = Hash(H\_{s'} || \pi)$ is stored on the Bitcoin blockchain

This commitment uses OP\_RETURN or Taproot to store the minimal footprint on Bitcoin:

OP\_RETURN \<IBVM\_IDENTIFIER> \<BATCH\_ID> \<STATE\_ROOT\_HASH> \<VALIDITY\_PROOF\_HASH>
