# Accessing Block Hash

Block hashes are cryptographic fingerprints of a block's content, encapsulating the entirety of a block's information, primarily its header. In the context of storage proofs, accessing the relevant block hash is the critical first step in affirming the integrity and authenticity of any on-chain data. It lays the foundation for all subsequent verification processes in the storage proof workflow.

Smart contracts can retrieve these block hashes through various methods, each with its own trade-offs and considerations. Let's explore these approaches in detail:

#### **Direct Access using EVM opcode** <a href="#direct-access-using-evm-opcode" id="direct-access-using-evm-opcode"></a>

<figure><img src="https://docs.herodotus.dev/~gitbook/image?url=https%3A%2F%2F1694265157-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F3TBwtPMEVIGQI1B6u4Ii%252Fuploads%252FDvXQj3eY6uuC64jwEXJo%252FScreenshot%25202023-10-09%2520at%25201.43.10%2520AM.png%3Falt%3Dmedia%26token%3Da4d9e559-d3e3-4de1-b2ca-f8c33046b311&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=90ad466b&#x26;sv=1" alt=""><figcaption><p>Ethereum Yellow Paper (<a href="https://ethereum.github.io/yellowpaper/paper.pdf">https://ethereum.github.io/yellowpaper/paper.pdf</a>)</p></figcaption></figure>

Smart contracts can natively utilize the **`BLOCKHASH`** opcode to fetch hashes of the most recent 256 blocks in the Ethereum Virtual Machine (EVM). While straightforward, this method is restricted to a limited timeframe, and accessing older blocks becomes challenging.

This limitation prevents developers from injecting proofs of arbitrary on-chain data into their smart contracts, as they cannot easily verify inclusion proofs against historical block hashes.

#### **Utilizing Third-Party Providers** <a href="#utilizing-third-party-providers" id="utilizing-third-party-providers"></a>

Alternately, an off-chain actor could forward block hashes on-chain. However, this approach introduces latency and usually requires trusting a third party, a committee or similar. Additionally, it potentially introduces vulnerabilities tied to economic incentives or adversarial behaviours.

#### [**Historical Block Hash Accumulator**](https://docs.herodotus.dev/herodotus-docs/protocol-design/historical-block-hash-accumulator) <a href="#historical-block-hash-accumulator" id="historical-block-hash-accumulator"></a>

<figure><img src="https://docs.herodotus.dev/~gitbook/image?url=https%3A%2F%2F1694265157-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F3TBwtPMEVIGQI1B6u4Ii%252Fuploads%252FWsP07xycUKn3DHYTjc5e%252FGraphs%2520for%2520Documentation-37.png%3Falt%3Dmedia%26token%3Dac589352-623c-4f49-a62f-5a971aca37a9&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=47814790&#x26;sv=1" alt=""><figcaption><p>Root of Merkle Mountain Range Accumulator</p></figcaption></figure>

The Historical Block Hash Accumulator can be used to circumvent these issues. It enables on-chain smart contracts to derive older block hashes by validating them against a stored accumulator root (MMR Root). The methodology eliminates the need to trust external actors and widens the accessible range of block hashes without sacrificing security.

This approach uses a Merkle Mountain Range (MMR) data structure where block hashes are continuously added, and the MMR root is periodically committed on-chain. Smart contracts can then verify any historical block hash against this root, maintaining the trustless nature of blockchain interactions while providing efficient access to historical data.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.storageproofs.com/storage-proofs/accessing-block-hash.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
