> 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/consensus-mechanism.md).

# Consensus Mechanism

IBVM employs a hybrid consensus mechanism combining elements of Proof-of-Stake for the sequencer selection and anchoring to Bitcoin's Proof-of-Work for security.

## Sequencer Selection

Sequencers are selected through a weighted random process based on stake:

1. Sequencer candidates stake BTC in a special contract
2. Selection probability is proportional to stake amount
3. A verifiable random function (VRF) determines selection: $P(select\_i) = \frac{Stake\_i}{\sum\_{j=1}^{n} Stake\_j}$
4. Selected sequencers have exclusive rights to produce blocks for a set period

## Sequencer Responsibilities

Each selected sequencer:

1. Collects transactions from the mempool
2. Orders transactions based on gas price
3. Executes transactions and updates the state
4. Generates batch commitment and ZK proof
5. Publishes commitment to Bitcoin blockchain

## Fault Detection and Slashing

To maintain honest behavior:

1. Sequencers' stakes are locked in a slashing contract
2. Invalid state transitions can be challenged during the challenge period
3. If a fraud proof is successful, the sequencer loses part of their stake: $Slash\_{amount} = min(Stake\_i, S\_{base} + S\_{proportional} \times TxValue)$ Where:
   1. $S\_{base}$ is the base slashing amount
   2. $S\_{proportional}$ is the proportional factor
   3. $TxValue$ is the economic value of affected transactions

## Chain Reorganization Handling

In case of Bitcoin chain reorganizations:

1. Monitor the Bitcoin chain for reorganizations
2. If a reorganization affects IBVM commitments:
   1. Revert to the last valid state
   2. Reapply subsequent valid batches
   3. Update the IBVM state accordingly

The mathematical condition for reorganization: $Height(Block\_{commitment}) > Height(Block\_{fork})$

<br>
