t(22788903)
'0x1338f27ed74ec2766875e2db65ca08b79fd2ce67a4f800acac4fa264e99a1984'
```
<a id="block_header"></a>
### `block_header`
`BlockOracle.block_header(arg0: uint256) -> tuple: view`
Getter for the block header for a specific block number.
| Input | Type | Description |
| --- | --- | --- |
| `arg0` | `uint256` | Block number |
Returns: block header tuple containing (block\_hash, parent\_hash, state\_root, receipt\_root, block\_number, timestamp) (`tuple`).
**<>Source code▼**
```vyper
block_header: public(HashMap[uint256, bh_rlp.BlockHeader]) # block_number => header
```
**▶Example▼**
```shell
>>> BlockOracle.block_header(22788903)
0xc215221221dd6673ae7ed2e50f47f6d020034657bb4a08010b5677a1f9d06d6d, 0x1338f27ed74ec2766875e2db65ca08b79fd2ce67a4f800acac4fa264e99a1984, 0x168986623a9cca07db8e17253b119dc1e93d68c2838e59c8cb5a10a88f5ad7a7, 0x46a8b05c582e75b876b106621e02542c6a9b3608d10d3e1973f3bf5aae9639a1,22788903,1750944347
```
<a id="last_confirmed_header"></a>
### `last_confirmed_header`
`BlockOracle.last_confirmed_header() -> tuple: view`
Getter for the last confirmed header.
Returns: block header tuple of the most recently confirmed header (`tuple`).
**<>Source code▼**
```vyper
last_confirmed_header: public(bh_rlp.BlockHeader) # last confirmed header
```
**▶Example▼**
```shell
>>> BlockOracle.last_confirmed_header()
0xc215221221dd6673ae7ed2e50f47f6d020034657bb4a08010b5677a1f9d06d6d, 0x1338f27ed74ec2766875e2db65ca08b79fd2ce67a4f800acac4fa264e99a1984, 0x168986623a9cca07db8e17253b119dc1e93d68c2838e59c8cb5a10a88f5ad7a7, 0x46a8b05c582e75b876b106621e02542c6a9b3608d10d3e1973f3bf5aae9639a1,22788903,1750944347
```
* * *
<a id="verifier"></a>
## Verifier
Owner-only functions for setting and querying the verifier contract address. The verifier is responsible for submitting RLP-encoded block headers. Proper verifier management is essential for the integrity of header submissions and downstream state proof operations.
<a id="set_header_verifier"></a>
### `set_header_verifier`
`BlockOracle.set_header_verifier(_verifier: address)`
Guarded Method by [Snekmate](https://github.com/pcaversaccio/snekmate)
This contract makes use of a Snekmate module to manage roles and permissions. This specific function can only be called by the current `owner` of the contract.
Function to set the block header verifier.
| Input | Type | Description |
| --- | --- | --- |
| `_verifier` | `address` | Block verifier address |
Emits: `SetHeaderVerifier` event.
**<>Source code▼**
```vyper
event SetHeaderVerifier:
old_verifier: indexed(address)
new_verifier: indexed(address)
header_verifier: public(address) # address of the header verifier
@external
def set_header_verifier(_verifier: address):
"""
@notice Set the block header verifier
@dev Emits SetHeaderVerifier event
@param _verifier Address of the block header verifier
"""
ownable._check_owner()
old_verifier: address = self.header_verifier
self.header_verifier = _verifier
log SetHeaderVerifier(old_verifier=old_verifier, new_verifier=_verifier)
```
```vyper
@internal
def _check_owner():
"""
@dev Throws if the sender is not the owner.
"""
assert msg.sender == self.owner, "ownable: caller is not the owner"
```
**▶Example▼**
```shell
>>> BlockOracle.set_header_verifier('0x1234567890123456789012345678901234567890')
```
<a id="header_verifier"></a>
### `header_verifier`
`BlockOracle.header_verifier() -> address: view`
Getter for the block header verifier.
Returns: verifier (`address`).
**<>Source code▼**
```vyper
header_verifier: public(address) # address of the header verifier
```
**▶Example▼**
```shell
>>> BlockOracle.header_verifier()
'0xb10CdEc0dE69a227307053bEbBFd80864B71ec27'
```
* * *
<a id="ownership"></a>
## Ownership
Standard Ownable interface for querying the current owner and transferring or renouncing ownership. Ownership controls all privileged operations, including committer management, threshold updates, and verifier assignment. Owner of the contract is the DAO.
---
# HeaderVerifier
Source: [https://docs.curve.finance/developer/block-oracle/header-verifier](https://docs.curve.finance/developer/block-oracle/header-verifier)
The `HeaderVerifier` contract decodes RLP-encoded Ethereum block headers and forwards the extracted data to oracle contracts. It uses the `BlockHeaderRLPDecoder` module to parse block headers and extract key information such as block hash, parent hash, state root, receipt root, block number, and timestamp. The contract serves as a bridge between raw block header data and oracle systems, enabling cross-chain verification and data availability without implementing security checks or validation logic.
`HeaderVerifier.vy`
The source code for the `HeaderVerifier.vy` contract can be found on [GitHub](https://github.com/curvefi/blockhash-oracle/blob/main/contracts/HeaderVerifier.vy). The contract is written using [Vyper](https://github.com/vyperlang/vyper) version `0.4.3`.
The contract is deployed on all supported chains at `0xb10CdEc0dE69a227307053bEbBFd80864B71ec27`.
**{ }Contract ABI▼**
```json
[{"inputs":[{"name":"encoded_header","type":"bytes"}],"name":"decode_block_header","outputs":[{"components":[{"name":"block_hash","type":"bytes32"},{"name":"parent_hash","type":"bytes32"},{"name":"state_root","type":"bytes32"},{"name":"receipt_root","type":"bytes32"},{"name":"block_number","type":"uint256"},{"name":"timestamp","type":"uint256"}],"name":"","type":"tuple"}],"stateMutability":"pure","type":"function"},{"inputs":[{"name":"_oracle_address","type":"address"},{"name":"_encoded_header","type":"bytes"}],"name":"submit_block_header","outputs":[],"stateMutability":"nonpayable","type":"function"}]
```
<a id="decode_block_header"></a>
### `decode_block_header`
`HeaderVerifier.decode_block_header(encoded_header: Bytes[BLOCK_HEADER_SIZE]) -> BlockHeader: pure`
Function to decode RLP encoded block header into a BlockHeader struct.
| Input | Type | Description |
| --- | --- | --- |
| `encoded_header` | `Bytes[BLOCK_HEADER_SIZE]` | RLP encoded header data |
Returns: a `BlockHeader` struct containing decoded block data (`BlockHeader`).
**<>Source code▼**
```vyper
from modules import BlockHeaderRLPDecoder as bh_rlp
exports: (bh_rlp.decode_block_header,)
```
```vyper
# BlockHeaderRLPDecoder.vy
# Source code of this Vyper module can be found here:
# https://github.com/curvefi/blockhash-oracle/blob/main/contracts/modules/BlockHeaderRLPDecoder.vy
# pragma version 0.4.3
"""
@title Block Header RLP Decoder Vyper Module
@author curve.fi
@license Copyright (c) Curve.Fi, 2025 - all rights reserved
@notice Decodes RLP-encoded Ethereum block header and stores key fields
@dev Extracts block number from RLP and uses it as storage key
"""
################################################################
# CONSTANTS #
################################################################
# Block header size upper limit
BLOCK_HEADER_SIZE: constant(uint256) = 1024
# RLP decoding constants
RLP_SHORT_START: constant(uint256) = 128 # 0x80
RLP_LONG_START: constant(uint256) = 183 # 0xb7
RLP_LIST_SHORT_START: constant(uint256) = 192 # 0xc0
RLP_LIST_LONG_START: constant(uint256) = 247 # 0xf7
################################################################
# STRUCTS #
################################################################
struct BlockHeader:
block_hash: bytes32
parent_hash: bytes32
state_root: bytes32
receipt_root: bytes32
block_number: uint256
timestamp: uint256
################################################################
# CONSTRUCTOR #
################################################################
@deploy
def __init__():
pass
################################################################
# EXTERNAL FUNCTIONS #
################################################################
# can be exposed optionally, or used in testing
@pure
@external
def calculate_block_hash(encoded_header: Bytes[BLOCK_HEADER_SIZE]) -> bytes32:
"""
@notice Calculates block hash from RLP encoded header
@param encoded_header RLP encoded header data
@return Block hash
"""
return keccak256(encoded_header)
@pure
@external
def decode_block_header(encoded_header: Bytes[BLOCK_HEADER_SIZE]) -> BlockHeader:
"""
@notice Decodes RLP encoded block header into BlockHeader struct
@param encoded_header RLP encoded header data
@return BlockHeader struct containing decoded block data
"""
return self._decode_block_header(encoded_header)
################################################################
# CORE FUNCTIONS #
################################################################
@pure
@internal
def _decode_block_header(encoded_header: Bytes[BLOCK_HEADER_SIZE]) -> BlockHeader:
"""
@notice Decodes key fields from RLP-encoded Ethereum block header
@dev RLP encoding rules:
- Single byte values (< 0x80) are encoded as themselves
- Short strings (length < 56) start with 0x80 + length
- Long strings (length >= 56) start with 0xb7 + length_of_length, followed by length
- Lists follow similar rules but with 0xc0 and 0xf7 as starting points
Makes use of utility functions to parse the RLP encoded header,
and passes entire header to them which is not optimal in terms of gas, but
makes code more readable.
@param encoded_header RLP encoded block header
@return BlockHeader(block_hash, parent_hash, state_root, block_number, timestamp)
"""
# Placeholder variables
tmp_int: uint256 = 0
tmp_bytes: bytes32 = empty(bytes32)
# Current position in the encoded header
current_pos: uint256 = 0
# 1. Skip RLP list length
current_pos = self._skip_rlp_list_header(encoded_header, current_pos)
# 2. Extract hashes
parent_hash: bytes32 = empty(bytes32)
parent_hash, current_pos = self._read_hash32(encoded_header, current_pos) # parent hash
tmp_bytes, current_pos = self._read_hash32(encoded_header, current_pos) # skip uncle hash
# 3. Skip miner address (20 bytes + 0x94)
assert convert(slice(encoded_header, current_pos, 1), bytes1) == 0x94
current_pos += 21
# 4. Read state root
state_root: bytes32 = empty(bytes32)
state_root, current_pos = self._read_hash32(encoded_header, current_pos)
# 5. Skip transaction root
tmp_bytes, current_pos = self._read_hash32(encoded_header, current_pos) # skip tx root
# 6. Read receipt root
receipt_root: bytes32 = empty(bytes32)
receipt_root, current_pos = self._read_hash32(encoded_header, current_pos)
# 7. Skip logs bloom
current_pos = self._skip_rlp_string(encoded_header, current_pos)
# 8. Skip difficulty
tmp_int, current_pos = self._read_rlp_number(encoded_header, current_pos)
# 9. Read block number
block_number: uint256 = 0
block_number, current_pos = self._read_rlp_number(encoded_header, current_pos)
# 10. Skip gas fields
tmp_int, current_pos = self._read_rlp_number(encoded_header, current_pos) # skip gas limit
tmp_int, current_pos = self._read_rlp_number(encoded_header, current_pos) # skip gas used
# 11. Read timestamp
timestamp: uint256 = 0
timestamp, current_pos = self._read_rlp_number(encoded_header, current_pos)
return BlockHeader(
block_hash=keccak256(encoded_header),
parent_hash=parent_hash,
state_root=state_root,
receipt_root=receipt_root,
block_number=block_number,
timestamp=timestamp,
)
################################################################
# UTILITY FUNCTIONS #
################################################################
@pure
@internal
def _skip_rlp_list_header(encoded: Bytes[BLOCK_HEADER_SIZE], pos: uint256) -> uint256:
"""@dev Returns position after list header"""
first_byte: uint256 = convert(slice(encoded, 0, 1), uint256)
assert first_byte >= RLP_LIST_SHORT_START, "Not a list"
if first_byte <= RLP_LIST_LONG_START:
return pos + 1
else:
return pos + 1 + (first_byte - RLP_LIST_LONG_START)
@pure
@internal
def _skip_rlp_string(encoded: Bytes[BLOCK_HEADER_SIZE], pos: uint256) -> uint256:
"""@dev Skip RLP string field, returns next_pos"""
prefix: uint256 = convert(slice(encoded, pos, 1), uint256)
if prefix < RLP_SHORT_START:
return pos + 1
elif prefix <= RLP_LONG_START:
return pos + 1 + (prefix - RLP_SHORT_START)
else:
# Sanity check: ensure this is a string, not a list
assert prefix < RLP_LIST_SHORT_START, "Expected string, found list prefix"
len_of_len: uint256 = prefix - RLP_LONG_START
data_length: uint256 = convert(
abi_decode(abi_encode(slice(encoded, pos + 1, len_of_len)), (Bytes[32])), uint256
)
return pos + 1 + len_of_len + data_length
@pure
@internal
def _read_hash32(encoded: Bytes[BLOCK_HEADER_SIZE], pos: uint256) -> (bytes32, uint256):
"""@dev Read 32-byte hash field, returns (hash, next_pos)"""
assert convert(slice(encoded, pos, 1), uint256) == 160 # RLP_SHORT_START + 32
return extract32(encoded, pos + 1), pos + 33
@pure
@internal
def _read_rlp_number(encoded: Bytes[BLOCK_HEADER_SIZE], pos: uint256) -> (uint256, uint256):
"""@dev Read RLP-encoded number, returns (value, next_pos)"""
prefix: uint256 = convert(slice(encoded, pos, 1), uint256)
if prefix < RLP_SHORT_START:
return prefix, pos + 1
# Sanity check: ensure this is a short string (not a long string or list)
assert prefix <= RLP_LONG_START, "Invalid RLP number encoding"
length: uint256 = prefix - RLP_SHORT_START
value: uint256 = convert(
abi_decode(abi_encode(slice(encoded, pos + 1, length)), (Bytes[32])), uint256
)
# abi_decode(abi_encode(bytesA), bytesB) is needed to unsafe cast bytesA to bytesB
return value, pos + 1 + length
```
**▶Example▼**
```shell
>>> HeaderVerifier.decode_block_header(rlp_encoded_header)
(0xc215221221dd6673ae7ed2e50f47f6d020034657bb4a08010b5677a1f9d06d6d, 0x..., 0x..., 0x..., 22788903, 1750944347)
```
<a id="submit_block_header"></a>
### `submit_block_header`
`HeaderVerifier.submit_block_header(_oracle_address: address, _encoded_header: Bytes[bh_rlp.BLOCK_HEADER_SIZE])`
Function to submit a block header. Decodes the RLP-encoded header and forwards it to the specified oracle contract.
| Input | Type | Description |
| --- | --- | --- |
| `_oracle_address` | `address` | The address of the oracle contract to submit the decoded header to |
| `_encoded_header` | `Bytes[bh_rlp.BLOCK_HEADER_SIZE]` | RLP-encoded block header data |
**<>Source code▼**
```vyper
interface IBlockOracle:
def submit_block_header(block_header: bh_rlp.BlockHeader): nonpayable
from modules import BlockHeaderRLPDecoder as bh_rlp
exports: (bh_rlp.decode_block_header,)
@external
def submit_block_header(_oracle_address: address, _encoded_header: Bytes[bh_rlp.BLOCK_HEADER_SIZE]):
"""
@notice Submit a block header. If it's correct and blockhash is applied, store it.
@param _oracle_address The address of the oracle contract
@param _encoded_header The block header to submit
"""
# Decode whatever is submitted
decoded_header: bh_rlp.BlockHeader = bh_rlp._decode_block_header(_encoded_header)
# Submit decoded header to oracle
extcall IBlockOracle(_oracle_address).submit_block_header(decoded_header)
```
```vyper
# BlockOracle.vy
@external
def submit_block_header(_header_data: bh_rlp.BlockHeader):
"""
@notice Submit block header. Available only to whitelisted verifier contract.
@param _header_data The block header to submit
"""
assert msg.sender == self.header_verifier, "Not authorized"
# Safety checks
assert _header_data.block_hash != empty(bytes32), "Invalid block hash"
assert self.block_hash[_header_data.block_number] != empty(bytes32), "Blockhash not applied"
assert _header_data.block_hash == self.block_hash[_header_data.block_number], "Blockhash does not match"
assert self.block_header[_header_data.block_number].block_hash == empty(bytes32), "Header already submitted"
# Store decoded header
self.block_header[_header_data.block_number] = _header_data
# Update last confirmed header if new
if _header_data.block_number > self.last_confirmed_header.block_number:
self.last_confirmed_header = _header_data
log SubmitBlockHeader(
block_number=_header_data.block_number,
block_hash=_header_data.block_hash,
)
```
**▶Example▼**
```shell
>>> HeaderVerifier.submit_block_header('0xb10cface698eBbEeda6Fd1aC3e1687a8a3f5c5Df', rlp_encoded_header)
```
---
# LZBlockRelay
Source: [https://docs.curve.finance/developer/block-oracle/lz-block-relay](https://docs.curve.finance/developer/block-oracle/lz-block-relay)
The `LZBlockRelay` contract is a cross-chain block hash relay built on LayerZero's messaging protocol, designed for deployment on multiple EVM-compatible chains alongside the `BlockOracle` and `MainnetBlockView` contracts. Its core function is to securely and efficiently relay recent Ethereum mainnet block hashes to other chains, enabling trust-minimized cross-chain state proofs and interoperability.
Operating in two modes — **read-enabled** (which can request and broadcast block hashes) and **broadcast-only** (which only receives broadcasts) — the contract verifies incoming LayerZero messages, commits block hashes to the local `BlockOracle`, and, when appropriate, rebroadcasts them to additional chains. All LayerZero peer and channel configurations are owner-controlled to ensure only trusted sources are permitted, supporting robust, decentralized, and secure cross-chain communication.
`LZBlockRelay.vy`
The source code for the `LZBlockRelay.vy` contract can be found on [GitHub](https://github.com/curvefi/blockhash-oracle/blob/main/contracts/messengers/LZBlockRelay.vy). The contract is written using [Vyper](https://github.com/vyperlang/vyper) version `0.4.3`.
The contract is deployed on all supported chains at `0xfacefeed69e0eb9dB6Ad8Cb0883fC45Df7561Dc2`.
**{ }Contract ABI▼**
```json
[{"anonymous":false,"inputs":[{"indexed":true,"name":"block_number","type":"uint256"},{"indexed":true,"name":"block_hash","type":"bytes32"},{"components":[{"name":"eid","type":"uint32"},{"name":"fee","type":"uint256"}],"indexed":false,"name":"targets","type":"tuple[]"}],"name":"BlockHashBroadcast","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previous_owner","type":"address"},{"indexed":true,"name":"new_owner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"eid","type":"uint32"},{"indexed":false,"name":"peer","type":"bytes32"}],"name":"PeerSet","type":"event"},{"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"name":"new_owner","type":"address"}],"name":"transfer_ownership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounce_ownership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"endpoint","outputs":[{"name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"name":"arg0","type":"uint32"}],"name":"peers","outputs":[{"name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"name":"_eid","type":"uint32"},{"name":"_peer","type":"bytes32"}],"name":"setPeer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"_delegate","type":"address"}],"name":"setDelegate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"name":"srcEid","type":"uint32"},{"name":"sender","type":"bytes32"},{"name":"nonce","type":"uint64"}],"name":"_origin","type":"tuple"},{"name":"_message","type":"bytes"},{"name":"_sender","type":"address"}],"name":"isComposeMsgSender","outputs":[{"name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"name":"srcEid","type":"uint32"},{"name":"sender","type":"bytes32"},{"name":"nonce","type":"uint64"}],"name":"_origin","type":"tuple"}],"name":"allowInitializePath","outputs":[{"name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"name":"_srcEid","type":"uint32"},{"name":"_sender","type":"bytes32"}],"name":"nextNonce","outputs":[{"name":"","type":"uint64"}],"stateMutability":"pure","type":"function프로젝트로 돌아가기