# 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>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ibvm.gitbook.io/ibvm-doc/consensus-mechanism.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
