# Optimistic rollups

## **Introduction**

By bringing smart contracts to Bitcoin, Bitcoin Virtual Machine lets developers create DEX, DAO, tokens, data storage, and many other use cases on Bitcoin. However, the biggest challenge is Bitcoin's 10-min block time.

> Increasing Bitcoin capability in terms of speed is fundamental to the mass adoption of decentralized applications on Bitcoin.&#x20;

The main goal of NOS (or "Nitrous Oxide") is to turbocharge Bitcoin transactions (reduce transaction latency) without sacrificing decentralization or security.

## **Architecture**

NOS reuses the battle-tested [Optimism](https://www.optimism.io) codebase. It is a modified version of the OP Stack that adds support for Bitcoin.

Like Optimism, NOS uses [Optimistic Rollup](https://ethereum.org/en/developers/docs/scaling/optimistic-rollups/), a fancy way of describing a blockchain that piggybacks off the security of another blockchain.&#x20;

In this case, NOS takes advantage of the consensus mechanism of Bitcoin instead of its own. This is possible thanks to the Bitcoin Virtual Machine protocol, which brings smart contract capability to Bitcoin.

<figure><img src="https://824077807-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4LrpKdKCJA4rekyqoMPj%2Fuploads%2FJbQASGEOMUA9F6bHm3xS%2Fimage.png?alt=media&#x26;token=7691456e-779a-4718-bb80-5a455e16f7d1" alt=""><figcaption><p>Figure 1. The NOS software stack.</p></figcaption></figure>

## **LAYER 1**

### **Data Validation**

{% hint style="info" %}
Implementation: [The Bitcoin Network](https://bitcoin.org)
{% endhint %}

The foundation of the NOS software stack is the Data Validation component. This component significantly impacts the security model of the whole stack. Everything else in the entire stack is derived from the Data Validation component.

### **Data Availability**

{% hint style="info" %}
Implementation: [The Polygon Network](https://polygon.technology)
{% endhint %}

For pragmatic reasons, NOS currently stores data on both Bitcoin and Polygon. Bitcoin is arguably the most secure blockchain. NOS stores the data hash on Bitcoin. Polygon is the most cost-effective storage solution. NOS stores the data (compressed transactions) on Polygon.

### **Smart Contract Platform**

{% hint style="info" %}
Implementation: Bitcoin Virtual Machine #0 [Trustless Computer #0](https://docs.bvm.network/bvm/l1-scaling-solutions/case-studies-wip/shard_bvm/bitcoin-virtual-machine-0)
{% endhint %}

Bitcoin Virtual Machine #0 is a special computer. It is a modified version of the EVM that adds smart contracts to Bitcoin. Bitcoin Virtual Machine #0 is used to glue all the components of the NOS software stack together.

## **LAYER 2**

### **Sequencer**

{% hint style="info" %}
Implementation: [op-batcher](https://github.com/TrustlessComputer/optimism-tc/tree/master/op-batcher)
{% endhint %}

A sequencer (block producer) determines how transactions are collected and published to Layer 1. The sequencer compresses transactions into batches and writes these batches to Polygon, and writes the hash to Bitcoin via Bitcoin Virtual Machine to ensure data availability and integrity.

NOS blocks are currently produced every 2 seconds.

<figure><img src="https://824077807-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4LrpKdKCJA4rekyqoMPj%2Fuploads%2FXZKkDcyiBwMMBdRSMeSh%2Fimage.png?alt=media&#x26;token=71a2584c-aa8d-4716-83ff-eed2b5319c0e" alt=""><figcaption><p>Figure 2. The transaction flow of writing the transactions to L1 </p></figcaption></figure>

### **Rollup Node**

{% hint style="info" %}
Implementation: [op-node](https://github.com/TrustlessComputer/optimism-tc/tree/master/op-node)
{% endhint %}

The Rollup node defines how the raw data stored in the Data Availability component (Polygon) is processed to form the inputs for the Execution Engine.

This is also referred to as the Derivation component, which derives the L2 blocks from the L1 blocks.

### **Execution Engine**

{% hint style="info" %}
Implementation: [op-geth](https://github.com/TrustlessComputer/opgeth-tc)
{% endhint %}

The Execution Engine defines the state transition function. It takes inputs from the Rollup node, executes on the current state, and outputs the new state.

op-geth is a modified version of the EVM that adds support for L2 transactions.

### **Settlement**

{% hint style="info" %}
Implementation: [op-proposer](https://github.com/TrustlessComputer/optimism-tc/tree/master/op-proposer)
{% endhint %}

The Settlement component commits the Merkle root of the new state (the output from the Execution Engine) to Bitcoin.

Note that the state roots are not immediately valid. In an optimistic rollup setup, state commitments are published onto Bitcoin as pending validity for a period (currently, set as 7 days) and subject to challenge.

The Optimism team is developing the fault-proof process. Once it’s completed, we’ll add it to NOS.

<figure><img src="https://824077807-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4LrpKdKCJA4rekyqoMPj%2Fuploads%2FiMcszCz483LaPJ8e8or4%2Fimage.png?alt=media&#x26;token=75033363-1b28-4f72-9a2b-cc62f911e44b" alt=""><figcaption><p>Figure 3. The transaction flow of state processing.</p></figcaption></figure>

### Bridges

{% hint style="info" %}
Implementation: [Trustless Bridge](https://trustlessbridge.io/), [L1StandardBridge](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/contracts/L1/L1StandardBridge.sol)
{% endhint %}

Users can deposit Bitcoin assets (BTC and BRC-20 tokens) from Bitcoin to NOS and, vice versa, withdraw them back.

For example, to deposit BTC from Bitcoin to NOS

1. Wrap BTC to WBTC via Trustless Bridge
2. Deposit WBTC to NOS via [L1StandardBridge](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/contracts/L1/L1StandardBridge.sol) contract

To withdraw BTC from NOS to Bitcoin

1. Initiate a withdrawal on NOS
2. Wait for the next Merkle root to be committed to Bitcoin
3. Submit the withdrawal proof
4. After the fault challenge period ends, withdraw your WBTC
5. Unwrap WBTC to BTC via Trustless Bridge

## GOVERNANCE LAYER

### **Token**

{% hint style="info" %}
Implementation: NOS as a BRC-20 token
{% endhint %}

NOS is the governance token to decentralize decision-making.

### **DAO**

{% hint style="info" %}
Implementation: Under development
{% endhint %}

The NOS DAO manages NOS configurations, upgrades, design decisions, development grants, etc.
