> 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/evm-compatibility-layer.md).

# EVM Compatibility Layer

The EVM Compatibility Layer implements the Ethereum Virtual Machine specification to enable Solidity smart contracts to run on IBVM.

## EVM Implementation

IBVM implements the full EVM instruction set as specified in the Ethereum Yellow Paper, with the following modifications:

1. Gas costs denominated in BTC (satoshis) instead of ETH
2. Block gas limit calibrated for Bitcoin block times
3. Modified precompiled contracts for Bitcoin-specific operations

### **Instruction Set Support**

The EVM implementation supports all standard EVM opcodes including:

* Stack manipulation (PUSH, POP, DUP, SWAP)
* Arithmetic operations (ADD, MUL, SUB, DIV, etc.)
* Bitwise operations (AND, OR, XOR, NOT)
* Comparison operations (LT, GT, EQ, etc.)
* Environmental information (CALLER, CALLVALUE, etc.)
* Block information (BLOCKHASH, COINBASE, etc.)
* Memory operations (MLOAD, MSTORE, etc.)
* Storage operations (SLOAD, SSTORE)
* Program control flow (JUMP, JUMPI, etc.)
* System operations (CREATE, CALL, etc.)

### **Gas Computation**

Gas cost in IBVM is calculated similarly to Ethereum but denominated in satoshis:

$gas\_cost = \sum\_{op \in tx} gas(op) \times gas\_price$

Where:

* $gas(op)$ is the base gas cost of each operation
* $gas\_price$ is the user-specified gas price in satoshis/gas unit

## State Representation

The IBVM state is organized as a Merkle Patricia Trie, similar to Ethereum:

1. Account State: A mapping of addresses to account states
   1. Each account has: nonce, balance, storageRoot, codeHash
   2. $AccountState = (nonce, balance, storageRoot, codeHash)$
2. Storage Trie: For each account, a separate trie maps 256-bit keys to 256-bit values
   1. $Storage: 2^{256} \rightarrow 2^{256}$
3. State Root: A 256-bit hash that uniquely identifies the entire state
   1. $StateRoot = H(AccountState\_1 || AccountState\_2 || ... || AccountState\_n)$

## Account Representation

Each account in IBVM is represented as:

$Account = (nonce, balance, storageRoot, codeHash)$

Where:

* $nonce$: Counter used to ensure each transaction is processed only once
* $balance$: Amount of BTC held by the account (in satoshis)
* $storageRoot$: Root hash of the storage trie
* $codeHash$: Hash of the account's contract code (or 0 if not a contract)
