Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
This article examines ERC8002, which specifies an SPV gateway that stores Bitcoin block headers on Ethereum and verifies transaction inclusion using Merkle proofs.
This article explains the proposal linked below.
Overview
ERC8002 defines the ISPVGateway interface for verifying Bitcoin transactions on Ethereum.
The proposal is a draft, so its deployment address remains a placeholder.
Key points
The proposal allows anyone to submit valid Bitcoin block headers on-chain, track the main chain by cumulative proof of work, and query checkTxInclusion with a Merkle proof to determine whether a given txId is included in a particular block.
Wallets and off-chain helpers submit headers, while consuming protocols choose their own confirmation thresholds.
| Item | Details |
|---|---|
| Official name | Simplified Payment Verification Gateway |
| Status | Draft |
| Core contract | Singleton SPVGateway (implements ISPVGateway) |
| Input | Anyone can submit a valid Bitcoin block header (80 bytes) via addBlockHeader |
| Main chain | Updates the head to the branch with the greatest cumulative PoW |
| Transaction verification | checkTxInclusion checks inclusion using a txId, Merkle proof, blockHash, and other inputs |
Simplified Payment Verification (SPV)
SPV is an approach for lightweight Bitcoin clients to verify the existence of a payment using block headers and Merkle proofs, rather than retaining all transactions as a full node does. ERC8002 provides a gateway for sharing this verification logic through an Ethereum contract.
Why a singleton?
The proposal introduces a singleton for verifying Bitcoin transactions on-chain. Its proposed deployment address remains a placeholder. As a trustless SPV gateway, it allows anyone to submit Bitcoin block headers, tracks the main chain, and uses Merkle proofs to verify transaction inclusion.
Architecture
The diagram below shows how Bitcoin block headers are submitted and how Ethereum protocols use functions such as checkTxInclusion to verify transactions.

Motivation
Background
The proposal cites Ethereum smart contracts' ability to decentralize systems, remove reliance on trusted intermediaries, and make value programmable. It also points to the resurgence of DeFi and developments in real-world assets (RWAs) and privacy protocols. Bitcoin, in contrast, has extremely limited programmability. Its trustless use cases therefore tend to be restricted to holding and transferring BTC, making it difficult to integrate native BTC directly into Ethereum DeFi.
Potential use cases
The proposal aims to provide infrastructure to bridge that gap. It describes use cases that are already possible, such as borrowing stablecoins against native BTC as collateral. It also discusses how combining this infrastructure with developments such as BitVM could enable ownerless two-way bridges and BTC issuance on Ethereum without wrapping.
Specification
The proposal first establishes the relevant concepts: Bitcoin block headers, difficulty, validation, Merkle trees, and main-chain selection. It then specifies the events and functions of ISPVGateway, implemented by the Ethereum singleton SPVGateway.
The following sections follow that order.
Bitcoin block header structure
Each block header consists of fixed-length fields totaling 80 bytes. The proposal defines them as follows.
| Field | Size | Byte order | Description |
|---|---|---|---|
| Version | 4 bytes | Little-endian | Block version number |
| Previous Block | 32 bytes | Natural byte order | Hash of the block to which this block connects |
| Merkle Root | 32 bytes | Natural byte order | Fingerprint of the transactions included in the block (root of the Merkle tree) |
| Time | 4 bytes | Little-endian | Unix timestamp |
| Bits | 4 bytes | Little-endian | Compact representation of the difficulty target |
| Nonce | 4 bytes | Little-endian | 32-bit value varied during mining |
The fields appear in the order shown in the table.
Their byte boundaries are arranged as follows (80 bytes in total).
flowchart LR V["Version<br/>4B LE"] P["Previous<br/>32B"] M["Merkle Root<br/>32B"] T["Time<br/>4B LE"] B["Bits<br/>4B LE"] N["Nonce<br/>4B LE"] V --> P --> M --> T --> B --> N
Byte order (LE and natural byte order)
"LE" in the diagram stands for little-endian. Four-byte fields such as Version, Time, Bits, and Nonce are interpreted as numeric values. Bitcoin block headers conventionally encode them with the least significant byte first.
By contrast, Previous Block and Merkle Root are 32-byte hash values. Rather than reversing their endianness as for four-byte integers, the header stores the raw byte sequence produced by hashing algorithms such as SHA256. "Natural byte order" in the table refers to leaving those raw hash bytes in their original order.
Difficulty adjustment
Bitcoin's proof of work relies on probabilistic finality and uses a dynamically adjusted difficulty target.
According to the proposal, the initial target is 0x00000000ffff0000000000000000000000000000000000000000000000000000, which also defines the minimum difficulty threshold.
The target is recalculated approximately every 2016 blocks. This interval is called the difficulty adjustment period.
With an expected block time of 10 minutes, 2016 blocks correspond to 1,209,600 seconds.
The new target is calculated by multiplying the current target by the ratio of the actual time taken to mine the preceding 2016 blocks to the expected duration (1,209,600 seconds).
To prevent abrupt changes, this multiplier is clamped to a maximum of 4 times and a minimum of 1/4.
The following diagram summarizes the process.
flowchart TD A[約2016ブロック分<br/>難易度調整期間] --> B[実際の経過時間を計測] B --> C[期待時間 1,209,600秒との比で<br/>targetを更新] C --> D[倍率に上限<br/>最大4倍・最小1/4倍]
The proposal specifies the details of the adjustment, including how the exponent and coefficient are rounded.
Block header validation rules
The proposal identifies three conditions a header must meet to be accepted into the chain: Chain Cohesion, Timestamp Rules, and the PoW Constraint.
The following diagram shows how they relate. The numbered list explains each rule in more detail.

All three checks must pass before the header can be integrated into the chain.
-
Chain Cohesion The
Previous Blockhash must refer to a valid block in the existing set of headers. -
Timestamp Rules
Timemust be greater than the Median Time Past (MTP) of the preceding 11 blocks. It must also be no more than 2 hours in the future relative to the validating node's network-adjusted time. -
PoW Constraint The result of applying SHA256 twice to the header must be less than or equal to the current
targetderived from the difficulty adjustment.
Transaction Merkle trees and inclusion verification
The Merkle Root in each block header is the root of the Merkle tree of transactions included in that block.
The proposal describes the construction: the leaves are double-SHA256 hashes of raw transaction bytes, adjacent nodes are recursively hashed together, and a node without a neighbor is paired with itself.
To verify transaction inclusion, the verifier reconstructs the Merkle root using the Merkle proof, txId, and other inputs, then compares it with the Merkle Root stored in the header. The proposal notes that the Merkle path and hash-direction bits can be obtained by querying a Bitcoin full node.
The tree's depth varies with the number of transactions. When there is an odd number of leaves, the last leaf is paired with itself, as specified in the proposal. The following diagram illustrates how hashes are combined from the leaves up to the root.
flowchart BT R[Merkleルート] H12[H12] H34[H34] T1[tx1 hash] T2[tx2 hash] T3[tx3 hash] T4[tx4 hash] T1 --> H12 T2 --> H12 T3 --> H34 T4 --> H34 H12 --> R H34 --> R
Main chain and cumulative PoW
Bitcoin's main chain is not simply the longest chain. It is the branch with the greatest cumulative proof of work.
The amount of work for a block is inversely proportional to its target. The proposal expresses this as (2**256 - 1) / (target + 1).
The target is derived from the Bits field. The proposal describes the first byte as indicating the left-shift amount and the remaining three bytes as representing the value used to derive the actual target.
The compact encoding used by Bitcoin can be understood through a numerical example.
Bitsis four bytes in little-endian order. Interpreted as a 32-bit integer, the most significant byte is the exponent (which corresponds to a left shift), and the remaining three bytes are the coefficient used to construct the actualtarget.- For example, if the four bytes on the wire are
ff ff 00 1d(LE), the integer value is0x1d00ffff. With exponent0x1dand coefficient0x00ffff, it expands into the 256-bittargetastarget = 0x00ffff × 2^(8×(0x1d−3)).
The chain's cumulative work is the sum of the work of its individual blocks. Blocks belonging to the branch with the greatest cumulative PoW are on the main chain.
When a fork occurs, the branches are compared by cumulative PoW rather than length.

Real nodes handle many more forks, but the selection criterion remains the same: the branch with the greatest cumulative PoW.
Mandatory initialization requirements for SPVGateway
SPVGateway must provide permissionless initialization.
This mechanism must allow anyone to submit a valid Bitcoin block header, its corresponding block height, and the cumulative PoW up to that block, without special privileges.
The diagram illustrates how anyone can supply the initial state.
flowchart LR U[任意のアクター] U --> X[有効ヘッダ・高さ・<br/>累積PoWを提出] X --> G[SPVGateway<br/>初期状態の確立]
The proposal assumes that anyone can establish the starting state rather than restricting initialization to an administrator key.
The ISPVGateway interface
The following sections cover the elements of ISPVGateway listed in the proposal.
For each struct, event, or function, the signature is followed by a table describing the fields, parameters, or return values.
Submission functions update the state, while getter functions and checkTxInclusion read it. The following diagram illustrates that division of responsibilities.

The conditions under which events must be emitted are described in each function's section.
Read functions do not modify state, and checkTxInclusion is the only one responsible for the computationally heavier inclusion verification.
BlockHeaderData
A struct representing a Bitcoin block header within the contract. The proposal converts all fields into big-endian internal representations for EVM efficiency. This differs from the little-endian encoding of Bitcoin's integer fields.
struct BlockHeaderData {
bytes32 prevBlockHash;
bytes32 merkleRoot;
uint32 version;
uint32 time;
uint32 nonce;
bytes4 bits;
}| Field | Type | Description |
|---|---|---|
prevBlockHash |
bytes32 |
Hash of the previous block. |
merkleRoot |
bytes32 |
Merkle root of transactions in the block. |
version |
uint32 |
Block version. |
time |
uint32 |
Timestamp. |
nonce |
uint32 |
Mining nonce. |
bits |
bytes4 |
Compact representation of the difficulty target. |
MainchainHeadUpdated
An event emitted when the main-chain head changes.
The proposal requires this event whenever a change occurs through addBlockHeader, addBlockHeaderBatch, or similar operations.
event MainchainHeadUpdated(
uint64 indexed newMainchainHeight,
bytes32 indexed newMainchainHead
);| Parameter | Description |
|---|---|
newMainchainHeight |
Height of the new main-chain head. |
newMainchainHead |
Block hash of the new main-chain head. |
BlockHeaderAdded
An event emitted when a new block header is added to the contract's state.
The proposal requires this event whenever a header is added through addBlockHeader, addBlockHeaderBatch, or similar operations.
event BlockHeaderAdded(uint64 indexed blockHeight, bytes32 blockHash);| Parameter | Description |
|---|---|
blockHeight |
Height of the added block. |
blockHash |
Hash of the added block. |
addBlockHeader
Adds one raw 80-byte block header. The header is validated before being added.
function addBlockHeader(bytes calldata blockHeaderRaw) external| Category | Name | Type | Description |
|---|---|---|---|
| Parameter | blockHeaderRaw |
bytes calldata |
Raw block header bytes (must be 80 bytes). |
| Return value | — | — | The proposed interface specifies no return value. |
The proposal requires addBlockHeader to perform the following operations (in the order listed in the proposal).
- PoW Constraint: Verify that applying SHA256 twice to the header produces a value less than or equal to the current
targetderived from the difficulty adjustment (the same check as 3. PoW Constraint under Block header validation rules). - Verify that the submitted raw header is 80 bytes long.
- Verify Chain Cohesion and Timestamp Rules as described under Block header validation rules.
- When integrating the new header into the known chain, calculate cumulative PoW and handle chain reorganizations in accordance with Main chain and cumulative PoW.
- Emit
BlockHeaderAddedafter successfully adding the header. - Emit
MainchainHeadUpdatedif the main chain is updated.
The following diagram illustrates those steps.
flowchart TD
IN[生ヘッダ] --> V[PoW・80バイト・<br/>Chain/Timeの検証]
V -->|失敗| X[拒否]
V -->|成功| P[累積PoW更新と<br/>リオーグ処理]
P --> E1[BlockHeaderAddedをemit]
P --> H{先端が変わったか}
H -->|はい| E2[MainchainHeadUpdatedをemit]
H -->|いいえ| OK[完了]
E2 --> OK
If any validation check fails, the header is not integrated into the chain.
If the contract merely tracks a branch without changing the main-chain head, MainchainHeadUpdated is not required.
addBlockHeaderBatch
An optional function that adds multiple block headers sequentially. Each header is validated and added in order.
function addBlockHeaderBatch(bytes[] calldata blockHeaderRawArray) external| Category | Name | Type | Description |
|---|---|---|---|
| Parameter | blockHeaderRawArray |
bytes[] calldata |
Array of raw headers. |
| Return value | — | — | The proposed interface specifies no return value. |
The proposal's Rationale explains that for batches of more than 11 blocks, timestamps from calldata can be used to calculate MTP. This reduces storage reads and can substantially lower gas usage and transaction costs.
checkTxInclusion
A view function that checks whether the specified txId is included in the specified block's Merkle tree, whether the block is on the main chain, and whether it has sufficient confirmations.
function checkTxInclusion(
bytes32[] memory merkleProof,
bytes32 blockHash,
bytes32 txId,
uint256 txIndex,
uint256 minConfirmationsCount
) external view returns (bool)| Name | Type | Description |
|---|---|---|
merkleProof |
bytes32[] memory |
Array of hashes used to reconstruct the Merkle root. |
blockHash |
bytes32 |
Hash of the block being verified. |
txId |
bytes32 |
ID of the transaction to verify. |
txIndex |
uint256 |
Index of the transaction in the block's Merkle tree. |
minConfirmationsCount |
uint256 |
Minimum number of confirmations required. |
| Return type | Description |
|---|---|
bool |
true if the conditions are met; false otherwise. |
The proposal requires checkTxInclusion to perform the following steps.
- Verify that
blockHashis part of the main chain and that the block has at leastminConfirmationsCountconfirmations. Returnfalseif either check fails. - Calculate the Merkle root using
merkleProof,txId, andtxIndex. - Compare the calculated Merkle root with the
Merkle Rootstored in the header identified byblockHash. - Return
trueif the roots match, orfalseotherwise.
The following diagram illustrates the process.
flowchart TD
A[入力のblockHashとminConfirmations] --> B{メインチェーン上かつ確認数は足りるか}
B -->|いいえ| Z[falseを返す]
B -->|はい| C[Merkle証明とtxIdとtxIndexから<br/>Merkleルートを計算]
C --> D{Merkleルートがヘッダの<br/>Merkle Rootと一致するか}
D -->|いいえ| Z
D -->|はい| E[trueを返す]
The branches in the diagram correspond to the required order of operations. The function first rejects blocks that fail the main-chain or confirmation checks, then reconstructs the Merkle root and checks for a match.
Read-only view functions
These view functions read the main-chain head or metadata for individual blocks. None of them modifies state.
Main-chain head
getMainchainHead returns the hash of the head block of the branch with the greatest cumulative PoW.
getMainchainHeight returns its height.
getBlockHash returns the hash of the block on the main chain at the specified height.
Individual block queries
getBlockHeader returns the stored BlockHeaderData.
getBlockHeight looks up the height from blockHash.
getBlockMerkleRoot returns the Merkle root stored in the header.
blockExists indicates whether the contract stores that blockHash.
getBlockStatus
getBlockStatus returns both whether the block is on the main chain (isInMainchain) and the confirmation count (confirmationsCount), corresponding to the number of blocks built on top of it.
This function is useful when a consumer wants to check those preconditions independently before calling checkTxInclusion.
The following table summarizes the main functions and their outputs.
| Function | Information returned |
|---|---|
getMainchainHead |
Block hash of the head of the main chain with the greatest cumulative PoW |
getMainchainHeight |
Height of the head block of the main chain with the greatest cumulative PoW |
getBlockHeader |
BlockHeaderData corresponding to the specified blockHash |
getBlockStatus |
Whether the block is on the main chain (isInMainchain) and the confirmation count corresponding to the blocks built on top of it |
getBlockMerkleRoot |
Merkle root stored in the header |
getBlockHeight |
Block height of a known blockHash |
getBlockHash |
Hash of the main-chain block at the specified height |
blockExists |
Whether the given blockHash is registered in storage |
The signatures below follow the interface definition in the proposal. The parameters and return values correspond to the information in the preceding table.
function getMainchainHead() external view returns (bytes32);
function getMainchainHeight() external view returns (uint64);
function getBlockHeader(bytes32 blockHash) external view returns (BlockHeaderData memory);
function getBlockStatus(bytes32 blockHash) external view returns (bool isInMainchain, uint64 confirmationsCount);
function getBlockMerkleRoot(bytes32 blockHash) external view returns (bytes32);
function getBlockHeight(bytes32 blockHash) external view returns (uint64);
function getBlockHash(uint64 blockHeight) external view returns (bytes32);
function blockExists(bytes32 blockHash) external view returns (bool);Reference implementation
The proposal links to a reference implementation, SPVGateway.sol, on the same EIP page, along with TargetsHelper.sol, which handles conversions between difficulty Bits and target.
The proposal also specifies the versions of its library dependencies.
Rationale
EIPs and ERCs use the Rationale section to explain the reasons and trade-offs behind their design choices. The following sections summarize the proposal's rationale.
Initialization options
The proposal considers three approaches to initialization.
The diagram below compares the three options and shows that the proposal adopts the second.

-
Hardcode the Bitcoin genesis block This provides the most trustless starting point for deployment, but full synchronization is expensive. The proposal estimates that a full sync would cost about 100 ETH at a gas price of 1 gwei.
-
Bootstrap from an arbitrary height The initial cumulative work and block height must be trusted. However, this is a common way to initialize light clients, and off-chain verification can supplement it through community-verified checkpoints.
-
Prove the historical chain's validity using a zero-knowledge proof This is a sophisticated approach, but it can prove the entire history up to a particular block at once.
The current proposal adopts option 2.
Endianness
After a raw header is submitted, the fields of BlockHeaderData are normalized to big-endian representations.
This prioritizes EVM efficiency and reverses the encoding used by Bitcoin for its little-endian integers.
The following diagram illustrates the difference between Bitcoin's header encoding on the wire and the contract's internal struct representation.
flowchart LR B[Bitcoin 生80バイト<br/>整数フィールドはLE] B --> P[パースと正規化] P --> D[BlockHeaderData<br/>EVM向けにBE]
Byte order is less of an issue for bytes32 hash values. The conversion mainly concerns integer fields such as version and time.
Finality
SPVGateway does not define a finality rule that determines the level of certainty required by consuming protocols.
Each consumer sets its own threshold.
Batch submission and gas costs
The optional addBlockHeaderBatch function is included to optimize gas usage. For batches of more than 11 blocks, MTP can be calculated using timestamps from calldata, substantially reducing storage reads and costs.
The diagram shows multiple headers processed sequentially. Each element is validated and added individually.
flowchart LR H1[ヘッダ1] --> H2[ヘッダ2] H2 --> H3[ヘッダn] H3 --> V[各ステップで<br/>検証して追加]
The function is intended to synchronize a large number of headers in one transaction. Internally, it repeats the single-header addition procedure.
Security
Dependence on Bitcoin's PoW
The gateway's security depends directly on Bitcoin's proof-of-work consensus. If a 51% attack succeeds, fraudulent headers submitted by the attacker may be accepted, compromising the gateway's state.
Omission of the two-hour future timestamp check
Bitcoin nodes check that timestamps are no more than two hours ahead of network-adjusted time. SPVGateway does not implement this check because it cannot obtain network-adjusted time.
Probabilistic finality and reorganizations
Bitcoin has probabilistic finality. SPVGateway should be designed to accommodate reorganizations of arbitrary depth, but it cannot prevent them from occurring.
A transaction included in a block is not necessarily finalized permanently. Consuming dApps and protocols must therefore choose a sufficient number of confirmations according to their own security policies.
Trust assumptions in the initial state
addBlockHeader is permissionless and cryptographically verifies each header. However, the initial block header, height, and cumulative PoW form a starting point of trust.
The design permits flexible bootstrapping, while leaving verification of that initial state to the community and the dApps that choose to use a particular deployment.
Reference implementation
The Solidity reference implementation is available in the ethereum/ERCs repository.
TargetsHelper is a helper library that converts between Bitcoin's difficulty target and Bits representations and calculates new targets for difficulty adjustment periods.
The proposal lists @openzeppelin/contracts v5.2.0, @solarity/solidity-lib v3.2.0, and solady v0.1.23 as dependencies.
Discussion and status
The Ethereum Magicians discussion thread is available at the following URL.
The proposal is a draft, and its deployment address, test cases, and deployment procedure still contain unresolved placeholders. Even if the proposal describes backward compatibility, consult the relevant section of the original text to establish what it is compatible with (for example, existing Ethereum upgrades or other standards). Always check the latest version of the proposal and implementation before using them in production.
Conclusion
This article examined ERC8002.
We covered Bitcoin header layout, difficulty adjustment, the three validation conditions (Chain Cohesion, MTP, and PoW), and main-chain selection by cumulative PoW. We then followed the proposal through the required addBlockHeader steps, the branches of checkTxInclusion, the initialization trade-offs in the rationale, and the security assumptions concerning PoW, the omitted two-hour rule, and bootstrap trust.
The read-only functions were grouped by main-chain head, individual block queries, and getBlockStatus, with tables and signatures outlining the complete API.
I also publish articles on other platforms:





