bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 13쪽 중 10쪽
.hemi.xyz/address/0xeC9fa5daC1118963933e1A675a4EEA0009b7f215)
{% endhint %}
***
## 🌐 Overview
* The **Hemi Virtual Machine (hVM)** and **Hemi Bitcoin Kit (hBK)** power Hemi’s Bitcoin Interoperability, empowering dApp developers to build novel Bitcoin dApps and robust interoperability infrastructure in a trustless, secure, and gas-efficient manner.
* **hVM:** An indexed Bitcoin full node directly accessible inside the EVM, exposing data including transactions, address balances, UTXOs, and chain metadata to smart contracts on Hemi via custom precompiles.
* **hBK:** A smart contract library running on Hemi that utilizes hVM and makes Hemi’s Bitcoin awareness easier to use by exposing higher-level functions that perform the precompile calls and handle the data marshaling, returning simple data structures developers can use in their dApps.
***
{% hint style="warning" %}
#### 👷♂️ In Development:
* hVM and Bitcoin Kit are in development and experimental.
* hVM’s precompile calls and Bitcoin Kit’s functions are subject to change in future versions of the Hemi Testnet.
* Prior to mainnet launch, the protocols will ossify and future upgrades will only add new hVM precompiles and Bitcoin Kit functions, ensuring full backwards compatibility.
{% endhint %}
***
### 📋 Latest Version
* Because new versions of hBK are being developed and tested, this document will always contain the latest “stable” contract available on Hemi’s testnet.
* In Mainnet, Bitcoin Kit contracts will be deployed as predeploys with special addresses like 0x8400000000000000000000000000000000000001, with new versions offering additional features being deployed at incremented addresses.
> **Latest Bitcoin Kit release on Hemi Testnet:**
>
> [0xeC9fa5daC1118963933e1A675a4EEA0009b7f215](https://testnet.explorer.hemi.xyz/address/0xeC9fa5daC1118963933e1A675a4EEA0009b7f215) (Updated October 11th, 2024)
# Hemi Virtual Machine (hVM)
{% hint style="warning" %}
This documentation page is outdated and may not reflect current information.
{% endhint %}
{% hint style="info" %}
## 📜 **TL;DR:**
* Hemi’s hVM is an **EVM upgraded with Bitcoin awareness.**
* The Hemi network maintains an EVM-visible Bitcoin node using Hemi’s custom **“Tiny Bitcoin” (TBC)** daemon. 
* A **“Processed Bitcoin View”** synchronizes all Hemi nodes as part of the EVM state transition.
{% endhint %}
***
## 🌐 Overview
* Hemi’s hVM is an **EVM upgraded with Bitcoin awareness** via new precompile contracts that smart contracts can call to get data from the Bitcoin node embedded in the EVM.
***
## 🔍 Tiny Bitcoin Daemon (TBC)
* The Hemi network maintains an EVM-visible Bitcoin node using Hemi’s custom **“Tiny Bitcoin” (TBC)** daemon. TBC syncs with the regular Bitcoin network over P2P and **indexes Bitcoin blocks** up to the height specified by the protocol. 
* When a Hemi Sequencer creates a block, they can optionally include an additional “Bitcoin Attributes Deposited” transaction communicating one or more new Bitcoin headers to the Hemi protocol. 
***
## 🎚️ Processed Bitcoin View
* When these transactions occur, all nodes on the Hemi network process these Bitcoin blocks at the same Hemi block height creating a **“Processed Bitcoin View”** synchronized across all Hemi nodes as part of the EVM state transition. 
* This synchronization ensures execution of all Bitcoin-aware smart contracts are **deterministic** across all nodes.
***
> To expose Bitcoin data to smart contracts, hVM introduces a number of new precompile contracts accessible in the EVM which fetch the latest data from the Processed Bitcoin View maintained by the embedded TBC node at the time the request is made.
***
<figure><img src="https://3063395300-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBrGAUP9hcnvqWQvHZlN0%2Fuploads%2F4rp239cmSUueUyOrysfM%2FScreenshot%202024-07-05%20at%2018.48.59.png?alt=media&token=81d9200b-3cab-482a-810f-d9bb6862b095" alt=""><figcaption></figcaption></figure>
# Motivation
{% hint style="warning" %}
This documentation page is outdated and may not reflect current information.
{% endhint %}
{% hint style="info" %}
## 📜 **TL;DR:**
* Current Bitcoin interoperability systems like BTC header relays exist, but come with significant limitations.
* By embedding a full indexed Bitcoin node directly inside the EVM, hVM allows **anyone** to access Bitcoin's processed state efficiently and without introducing any trust assumptions.
* dApp developers can now build all kinds of Bitcoin-aware dApps and custom Bitcoin interoperability infrastructure directly on hVM.
{% endhint %}
***
## 🚧 Limitations of Existing Approaches
Various Bitcoin header relay systems have been available on Ethereum as a primitive Bitcoin interoperability technology for nearly a decade. This approach has third-party relayers communicate new Bitcoin headers to a smart contract which maintains a lightweight view of Bitcoin consensus. Smart contracts can then verify a Merkle proof to verify that a specific Bitcoin transaction exists in the canonical Bitcoin chain.
However, this approach has significant limitations:
* Relies on third-party relayers
* Requires large inclusion proofs with expensive validation
* Can only prove a transaction exists in Bitcoin (no UTXO set proofs, no balance proofs, etc.)
Recently, other protocols have designed alternate Bitcoin interoperability primitives like 3-way noncustodial escrow systems validated with zk proofs, or smart-contract-controlled wallets run by the network validator set where network Sequencers facilitate UTXO queries.
However, these other approaches are only designed to serve specific use cases, and still don't provide smart contracts with a complete view of Bitcoin's state. Developers building on these primitives are also forced to accept the governance/security models that these one-off primitives provide, such as trusting a Sequencer doesn't withhold data from a UTXO query.
***
> 💡 With hVM, we set out to create something much more powerful and flexible that enabled anyone to build custom Bitcoin interoperability infrastructure directly in the EVM with complete access to Bitcoin state.
***
## 🔍 How?
By embedding a full indexed Bitcoin node directly inside the EVM, hVM:
* Does not involve any relayer system or trust assumption
* Does not require validation of any expensive proofs
* Supports secure queries for Bitcoin information that requires processing the entire chain like UTXOs, balances, and eventually popular Bitcoin metaprotocols
***
## 🏗️ Use Cases
hVM enables dApp developers to build all kinds of Bitcoin-aware dApps and custom Bitcoin interoperability infrastructure which was previously infeasible or outright impossible on other networks.
**Some use cases of hVM include:**
* Non-custodial BTC<->ETH asset exchanges
* Bitcoin MEV marketplaces
* Bitcoin lending markets
* Bitcoin staking systems
* Custom smart-wallets with configurable validator sets and signing technology
* Custom Bitcoin tunnels (Hemi’s own standard Bitcoin tunnel is being built entirely on hVM)
# Feature Summary
{% hint style="warning" %}
This documentation page is outdated and may not reflect current information.
{% endhint %}
{% hint style="info" %}
## 📜 **TL;DR:**
* Smart contracts on Hemi can access Bitcoin data by calling the hVM precompile contract.
* Future protocol upgrades will add additional precompile calls to provide additional information.
{% endhint %}
***
## 🌐 Overview
* Smart contracts on Hemi can access Bitcoin data by calling the hVM precompile contract addresses, which query the deterministic TBC node running inside the EVM. 
* Future protocol upgrades will add additional precompile calls to provide additional information like Bitcoin fee levels, Bitcoin block construction information, and popular metaprotocols like Ordinals, BRC-20s, and Runes.
***
## ℹ️ "Phase 0" Precompile Summary <a href="#hvm-precompile-addresses" id="hvm-precompile-addresses"></a>
<table><thead><tr><th>Name</th><th width="125">Address</th><th>Description</th></tr></thead><tbody><tr><td>BtcBalAddr</td><td>0x40</td><td>Gets the balance of an address in satoshis. Supports all address formats: P2PKH, P2SH, P2WPKH, P2WSH, P2TR.</td></tr><tr><td>BtcUtxosAddrList</td><td>0x41</td><td>Gets the list of Unspent Transaction Outputs (UTXOs) for an address. Supports pagination.</td></tr><tr><td>BtcTxByTxid</td><td>0x42</td><td>Gets parts of a Bitcoin transaction by its TxID. The caller can specify which part(s) of the transaction to return using packed bitflags to increase gas efficiency by dropping unnecessary data.</td></tr><tr><td>BtxTxConfirmations</td><td>0x43</td><td>Gets the number of confirmations a specified transaction by TxID has.</td></tr><tr><td>BtcLastHeader</td><td>0x44</td><td>Gets the most recent Bitcoin header known by hVM.</td></tr><tr><td>BtcHeaderN</td><td>0x45</td><td>Gets the canonical Bitcoin header at height N.</td></tr><tr><td>BtcAddrToScript</td><td>0x46</td><td>Converts a Bitcoin address to its corresponding script representation. Supports all address formats: P2PKH, P2SH, P2WPKH, P2WSH, P2TR.</td></tr></tbody></table>
# Deploy on hVM
{% hint style="warning" %}
This documentation page is outdated and may not reflect current information.
{% endhint %}
{% hint style="info" %}
## 📜 **TL;DR:**
* To use hVM directly, you will have to call the appropriate precompile address with the appropriate serialized bytes to pass parameters to the function. 
* Most dApp developers will use the Hemi Bitcoin Kit (hBK) **rather** than hVM directly. 
{% endhint %}
***
## 🌐 Overview
* To use hVM directly, you will have to call the appropriate precompile address with the appropriate serialized bytes to pass parameters to the function. 
* Each successful precompile call will return serialized bytes according to the precompile’s return data specification.
***
## 🟨 Developer Tip
> **Most dApp developers will use the Hemi Bitcoin Kit (hBK) rather than hVM directly.** 
* If you’re looking for an easy way to get started developing Bitcoin-aware dApps on Hemi, check out the “Hemi Bitcoin Kit (hBK)” section. Understanding how Bitcoin Kit uses hVM under-the-hood may be helpful, and dApp developers looking to maximize gas efficiency may benefit from using hVM directly to avoid paying overhead for unmarshalling data they don’t need for a specific use case.
###
# Hemi Bitcoin Kit (hBK)
{% hint style="warning" %}
This documentation page is outdated and may not reflect current information.
{% endhint %}
{% hint style="info" %}
#### 📜 **TL;DR:**
* The Hemi Bitcoin Kit (hBK) is a library of smart contracts for developers to use to build Bitcoin-aware smart contracts.
* The hBK abstracts away the complications of interacting directly with the hVM Precompiles; parsing query results into data structures that are easy to understand and use.
* **Latest hBK release on Hemi:** [0x7007dd1C09527B92AEcd8Ae6570B73d09E0B8F12](https://explorer.hemi.xyz/address/0x7007dd1C09527B92AEcd8Ae6570B73d09E0B8F12)
* **Latest hBK release on Hemi testnet:** [0xeC9fa5daC1118963933e1A675a4EEA0009b7f215](https://testnet.explorer.hemi.xyz/address/0xeC9fa5daC1118963933e1A675a4EEA0009b7f215)
* **Bitcoin Kit Demo/Editor app :** <https://bitcoin-kit.hemi.xyz/code-editor>
{% endhint %}
***
## 🌐 Overview
* The Hemi Bitcoin Kit (hBK) is a set of smart contracts designed to bridge the Ethereum and Bitcoin blockchains, enabling developers to build Bitcoin-aware dApps on an EVM with full access to Ethereum assets and the cross-chain data calls that ETH L2s provide.
* The hBK abstracts away the complexities of dealing directly with hVM's low-level precompile contracts.
***
## 🧑💻 How is hBK Unique?
* The hVM is based on the Ethereum Virtual Machine (EVM) and comes stocked with built-in precompiles to interact with the embedded Bitcoin full node.
* Unlike other Bitcoin interoperability solutions, Bitcoin-aware smart contracts built using hBK don't rely on any external relayers, require gas-intensive proof validation, or suffer from limited views of Bitcoin's state.
* Performing a query for Bitcoin data is just as easy as reading the state of other contracts in the EVM. No need to design complex smart contracts that register requests to handle after the requested data is relayed.
* Pre-validated data directly available in the EVM significantly reduces both the complexity and cost of developing and maintaining Bitcoin-related applications
{% hint style="success" %}
The Hemi Bitcoin Kit brings five benefits to developers:
* **Easier development:** Access to a wide range of Bitcoin data is just one smart contract call away.
* **Rich data:** Access Bitcoin state like UTXOs and balances that is impractical or outright impossible to get with other solutions.
* **Security and reliability:** dApps get immediate information about any relevant events on the Bitcoin blockchain without having to rely on third-party relayers or trusted oracles.
* **Composability:** Anyone can design new layers of Bitcoin DeFi infrastructure for others on which to build.
* **Cost-effectiveness:** The hVM uses far less gas than other approaches and there's no need to incentivize third-party bots to watch for and relay events.
{% endhint %}
***
## 🏗️ Use Cases
Some examples of unique applications that the Hemi Bitcoin Kit enables:
* **Custom Bitcoin tunnels:** Connect chains to the Bitcoin network using customized security, cost, and speed settings.
* **Trustless BTC staking and re-staking protocols:** 99% of BTC is unbridged and/or unproductive. With Hemi, BTC can be used to secure networks and earn yield.
* **Bitcoin-authenticated AI-model marketplaces:** As an example of an AI use case, model owners can publish Bitcoin-secure hashes of their model weights, timestamping them to the Bitcoin blockchain.
* **Multichain DAOs:** Hemi DAOs operate across both Bitcoin and Ethereum, making decisions based on the collective input of stakeholders from both communities.
***
## 🛠️ Bitcoin Kit Demo
The [Hemi Bitcoin Kit Demo](https://bitcoin-kit.hemi.xyz/code-editor) provides developers with an interactive code editor and execution environment featuring six essential Bitcoin blockchain functions. Users can do the following: 
* Retrieve address balances
* Access the latest block headers
* Query block headers by specific height
* Get detailed transaction information
* Check transaction confirmations
* List unspent transaction outputs (UTXOs) for any address
Each function comes with pre-written, well-documented code that demonstrates how to interact with Bitcoin's blockchain through smart contract calls, making it easy for developers to understand and implement Bitcoin functionality in their own applications. The demo serves as both a learning tool and a practical reference for app development, allowing users to execute real Bitcoin queries and see immediate results without needing to set up their own development environment.
# Overview
{% hint style="warning" %}
This documentation page is outdated and may not reflect current information.
{% endhint %}
{% hint style="info" %}
### 📜 **TL;DR:**
* The Hemi Bitcoin Kit (hBK) enables direct interaction with Bitcoin blockchain data within Ethereum’s environment.
* hBK utilizes Hemi Virtual Machine (hVM) to embed a fully indexed Bitcoin node inside the Ethereum Virtual Machine (EVM).
* hBK allows Ethereum smart contracts to query Bitcoin data using precompiled calls, ensuring efficient, trustless data access.
{% endhint %}
***
## ⚙️ How It Works
#### Hemi Virtual Machine (hVM)
The hVM is the backbone of the hBK’s interoperability features, embedding a Bitcoin node within the EVM. This setup allows Ethereum smart contracts to directly query Bitcoin data without relying on external bridges or third-party oracles, ensuring trustless, efficient, and secure access to Bitcoin data.
* Direct Access: Smart contracts can communicate with Bitcoin data embedded in the EVM, enabling them to make queries and receive data via precompiled calls.
* Indexed Data: The fully indexed Bitcoin node maintains transaction history, UTXOs, and meta-protocols like Ordinals and BRC-20 tokens.
#### Developer Interface: Simplified Interaction with Bitcoin
The hBK abstracts technical complexities, offering developers straightforward methods for accessing Bitcoin data, allowing them to:
1. Directly Pass Data to Precompiled Calls: Simple data serialization/deserialization processes provide a transparent gateway to precompiled Bitcoin calls.
2. Enhanced Query Functions (Upcoming): hBK is set to introduce enhanced functions, combining multiple precompile calls and additional processing steps for advanced operations.
This dual approach ensures developers can create Bitcoin-aware applications without managing low-level integration details, focusing instead on innovation and functionality.
***
## 🔑 Key Features
* **Embedded Node Access:** hBK integrates a fully indexed Bitcoin node within Hemi’s EVM environment, exposing robust Bitcoin data for smart contract use.
* **Precompiled Calls for Direct Data Retrieval:** Passthrough functions facilitate Bitcoin data queries with direct calls, automatically handling the data structures.
* **Enhanced Functions for Advanced Queries:** Future upgrades will introduce enhanced functions, combining multiple calls and added processing to support more complex queries and data requirements.
# hBK Smart Contract
{% hint style="warning" %}
This documentation page is outdated and may not reflect current information.
{% endhint %}
## 🌐 Overview
* The Hemi Bitcoin Kit smart contract provides utilities for interacting with Bitcoin data on the Hemi blockchain.
* It includes methods to retrieve Bitcoin address balances, UTXOs, transaction details, and block headers.
* The contract leverages hVM's new precompiles to perform Bitcoin-related queries.
* **Latest hBK release on Hemi:** [0x7007dd1C09527B92AEcd8Ae6570B73d09E0B8F12](https://explorer.hemi.xyz/address/0x7007dd1C09527B92AEcd8Ae6570B73d09E0B8F12)
* **Latest hBK release on Hemi testnet:** [0xeC9fa5daC1118963933e1A675a4EEA0009b7f215](https://testnet.explorer.hemi.xyz/address/0xeC9fa5daC1118963933e1A675a4EEA0009b7f215)
***
## 🚧 Phase 0 - Essentials
This initial phase is focused on core Bitcoin protocol data:
* Script/Address Balances
* UTXO Set
* Full Transactions w/ Output Availability
* Transaction Confirmations
* BTC Headers (Last and N)
***
## 🏗️ Struct Definitions
#### UTXO
Represents an unspent transaction output (UTXO).
```
struct UTXO {
bytes32 txId; // Transaction ID
uint256 index; // Index of the UTXO
uint256 value; // Value in satoshis
bytes scriptPubKey; // Script public key
}
```
***
#### Transaction
Represents a Bitcoin transaction.
```
struct Transaction {
bytes32 containingBlockHash; // Hash of the containing block
uint256 transactionVersion; // Transaction version
uint256 size; // Transaction size
uint256 vSize; // Virtual size of the transaction
uint256 lockTime; // Lock time
Input[] inputs; // Array of inputs
Output[] outputs; // Array of outputs
uint256 totalInputs; // Total number of inputs in the original transaction
uint256 totalOutputs; // Total number of outputs in the original transaction
bool containsAllInputs; // Indicates if all inputs are contained
bool containsAllOutputs; // Indicates if all outputs are contained
}
```
***
#### Input
Represents a Bitcoin transaction input.
```
struct Input {
uint256 inValue; // Value spent by the input in satoshis
bytes32 inputTxId; // Transaction ID of the input source
uint256 sourceIndex; // Index of the input in its transaction
bytes scriptSig; // Script signature
uint256 sequence; // Sequence number
uint256 fullScriptSigLength; // Full length of the script signature
bool containsFullScriptSig; // Indicates if the full script signature is contained
}
```
***
###프로젝트로 돌아가기