Skip to content

Commit 0a12ad0

Browse files
committed
Restructure mdBook docs into sectioned chapters
1 parent 41bc5c4 commit 0a12ad0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1648
-254
lines changed

docs/book.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ authors = ["Okm165"]
33
language = "en"
44
multilingual = false
55
src = "src"
6-
title = "Herodotus Data Processor Documentation"
6+
title = "HDP Cairo Documentation"
7+
description = "Provable historical blockchain data in Cairo"
78

89
[output.html]
910
git-repository-url = "https://github.com/HerodotusDev/hdp-cairo"

docs/src/SUMMARY.md

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,69 @@
1-
- [Introduction](./introduction.md)
2-
- [Getting Started](./getting_started.md)
3-
- [Architecture](./architecture.md)
4-
- [Debugging](./debugging.md)
1+
# Summary
2+
3+
[Introduction](introduction.md)
4+
[Getting Started](getting_started.md)
5+
6+
# Architecture
7+
8+
- [Overview](architecture/overview.md)
9+
- [Rust Crates](architecture/crates.md)
10+
- [Rust-Cairo Integration](architecture/rust_cairo_integration.md)
11+
12+
# Pipeline
13+
14+
- [Overview](pipeline/overview.md)
15+
- [Stage 1: Dry Run](pipeline/dry_run.md)
16+
- [Stage 2: Fetcher](pipeline/fetcher.md)
17+
- [Stage 3: Sound Run](pipeline/sound_run.md)
18+
19+
# Verification
20+
21+
- [Overview](verification/overview.md)
22+
- [MPT Proofs](verification/mpt_proofs.md)
23+
- [MMR Proofs](verification/mmr_proofs.md)
24+
25+
# Syscall Handlers
26+
27+
- [Overview](syscall_handlers/overview.md)
28+
- [Dry vs Sound](syscall_handlers/dry_vs_sound.md)
29+
- [EVM Handlers](syscall_handlers/evm_handlers.md)
30+
- [Starknet Handlers](syscall_handlers/starknet_handlers.md)
31+
32+
# State Management
33+
34+
- [Memorizers](state/memorizers.md)
35+
- [Injected State](state/injected_state.md)
36+
- [Unconstrained Data](state/unconstrained.md)
37+
38+
# Output
39+
40+
- [Overview](output/overview.md)
41+
- [Task Hash](output/task_hash.md)
42+
- [Output Root](output/output_root.md)
43+
44+
# Cairo Library
45+
46+
- [Overview](cairo_library/overview.md)
47+
- [EVM API](cairo_library/evm.md)
48+
- [Starknet API](cairo_library/starknet.md)
49+
- [Injected State API](cairo_library/injected_state.md)
50+
- [eth_call](cairo_library/eth_call.md)
51+
52+
# Proving
53+
54+
- [STWO Integration](proving/stwo_integration.md)
55+
56+
# Examples
57+
58+
- [StarkGate Solvency](examples/starkgate_solvency.md)
59+
- [Multi-Chain](examples/multichain.md)
60+
- [Injected State](examples/injected_state_example.md)
61+
62+
# Reference
63+
64+
- [CLI](reference/cli.md)
65+
- [Configuration](reference/configuration.md)
66+
- [Types](reference/types.md)
67+
68+
[Glossary](glossary.md)
69+
[Debugging](debugging.md)

docs/src/architecture.md

Lines changed: 0 additions & 44 deletions
This file was deleted.

docs/src/architecture/crates.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Rust Crates
2+
3+
This repository is organized into focused Rust crates. The most important ones are listed below.
4+
5+
| Crate | Purpose | Notes |
6+
| --- | --- | --- |
7+
| `cli` | User-facing CLI (`hdp`) | Subcommands: dry-run, fetch-proofs, sound-run |
8+
| `dry_run` | Stage 1 execution | Runs Cairo VM with RPC-backed handlers |
9+
| `fetcher` | Stage 2 proof collection | Builds `ProofsData` from key sets |
10+
| `sound_run` | Stage 3 execution | Offline run with verified proofs |
11+
| `dry_hint_processor` | Dry-run syscall handlers | RPC reads and key collection |
12+
| `sound_hint_processor` | Sound-run syscall handlers | Reads from memorizers |
13+
| `syscall_handler` | Shared syscall dispatch | Routes to EVM/Starknet/injected state |
14+
| `hints` | Cairo hint implementations | 250+ hints for VM integration |
15+
| `types` | Shared types and schemas | Inputs/outputs, keys, proofs |
16+
| `indexer_client` | Herodotus Indexer API client | MMR proof requests |
17+
| `state_server` | Injected state server | Patricia trie + proof API |
18+
19+
If you are new to the codebase, start with `cli`, `dry_run`, `fetcher`, and `sound_run`, then follow their dependencies.

docs/src/architecture/overview.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Architecture Overview
2+
3+
HDP Cairo is a layered system that combines Cairo0 verifiers, Cairo1 user modules, and Rust-based hint processors. The goal is to make historical blockchain data verifiable and deterministic.
4+
5+
## Layers
6+
7+
- **Cairo1 user layer**: your module uses the `hdp_cairo` library to request data.
8+
- **Bootloader layer (Cairo0)**: loads the compiled Cairo1 class and executes it.
9+
- **Verification layer (Cairo0)**: validates MMR/MPT/Patricia proofs before data is used.
10+
- **Hint processors (Rust)**: bridge the Cairo VM with external data structures.
11+
- **Orchestration (Rust)**: CLI commands for dry run, fetcher, and sound run.
12+
13+
## Data flow
14+
15+
```
16+
+-----------+ +-----------+ +-----------+
17+
| Dry Run | -> | Fetcher | -> | Sound Run |
18+
| RPC keys | | Proofs | | Verify run|
19+
+-----------+ +-----------+ +-----------+
20+
21+
dry_run_output.json -> proofs.json -> outputs
22+
```
23+
24+
## Cairo0 vs Cairo1 boundary
25+
26+
- Cairo1 code calls `call_contract_syscall` via the `hdp_cairo` library.
27+
- The Cairo VM forwards syscalls to the Rust `SyscallHandler`.
28+
- The handler either performs RPC reads (dry run) or memorizer reads (sound run).
29+
30+
## Entry points
31+
32+
- `hdp dry-run`: stage 1, generates `dry_run_output.json`
33+
- `hdp fetch-proofs`: stage 2, generates `proofs.json`
34+
- `hdp sound-run`: stage 3, returns `task_hash`, `output_root`, and `mmr_metas`
35+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Rust-Cairo Integration
2+
3+
HDP uses the Cairo VM syscall interface to connect Cairo1 code to Rust logic. The same Cairo1 module runs in both dry run and sound run; only the Rust handlers change.
4+
5+
## Call flow
6+
7+
1. A Cairo1 module calls a method from `hdp_cairo`, which internally uses `call_contract_syscall`.
8+
2. The Cairo VM forwards the syscall to the Rust `SyscallHandler`.
9+
3. The handler decodes a `CallContractRequest`, routes it, and writes a `CallContractResponse`.
10+
4. The result is decoded back in Cairo1 and returned to the caller.
11+
12+
## Syscall selectors
13+
14+
HDP handles two syscall selectors:
15+
16+
- `CallContract` for all data access paths.
17+
- `Keccak` for Cairo keccak hashing.
18+
19+
The `Keccak` selector is handled by `KeccakHandler` inside the Rust `SyscallHandler`.
20+
21+
## Routing logic
22+
23+
The Rust `SyscallHandler` dispatches requests based on:
24+
25+
- **Contract address** for special handlers (debug, injected_state, unconstrained).
26+
- **Chain ID** in calldata for EVM vs Starknet routing.
27+
28+
Relevant code paths:
29+
30+
- `crates/syscall_handler/src/lib.rs` (routing and execution)
31+
- `crates/types/src/cairo/new_syscalls.rs` (request/response layout)
32+
- `hdp_cairo/src/evm/*.cairo` and `hdp_cairo/src/starknet/*.cairo` (Cairo API)
33+
34+
## Dict manager and hints
35+
36+
The Cairo VM uses a shared `DictManager` for memorizers. During execution:
37+
38+
- Cairo hints can read/write dicts via the manager.
39+
- Rust hint processors populate dicts during verification.
40+
41+
This is how verified data becomes available to Cairo1 calls without network access.
42+
43+
## Dry vs sound
44+
45+
- **Dry run** uses `dry_hint_processor` handlers that make RPC calls and collect keys.
46+
- **Sound run** uses `sound_hint_processor` handlers that read from memorizers filled during verification.
47+
48+
This separation keeps Cairo code deterministic and identical across stages.

docs/src/cairo_library/eth_call.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# eth_call
2+
3+
HDP includes a provable EVM interpreter that can execute `eth_call`-style requests inside Cairo.
4+
5+
## Entry point
6+
7+
`hdp_cairo` re-exports the helper:
8+
9+
- `execute_eth_call(hdp, time_and_space, sender, target, calldata)`
10+
11+
Source: `hdp_cairo/src/eth_call/execute_call.cairo`
12+
13+
## What it does
14+
15+
- Builds an EIP-1559 transaction wrapper for the call
16+
- Executes an EVM interpreter in Cairo
17+
- Reads required state through HDP memorizers
18+
- Returns a `TransactionResult` with success flag and return data
19+
20+
## Supported instructions
21+
22+
The interpreter is implemented in `hdp_cairo/src/eth_call/evm/instructions/`. If you need to verify opcode coverage, start there and in `hdp_cairo/src/eth_call/evm/instructions.cairo`.
23+
24+
## Limitations
25+
26+
- The interpreter is designed for `eth_call`-style execution (no state mutation).
27+
- Opcode coverage is intentionally scoped; check the instruction modules for details.
28+
29+
## Example
30+
31+
```cairo
32+
use hdp_cairo::{HDP, execute_eth_call};
33+
use hdp_cairo::eth_call::hdp_backend::TimeAndSpace;
34+
use starknet::EthAddress;
35+
36+
let time_and_space = TimeAndSpace { chain_id: 0x1, block_number: 18_500_000 };
37+
let result = execute_eth_call(
38+
@hdp,
39+
@time_and_space,
40+
EthAddress::from(0x01),
41+
EthAddress::from(0x02),
42+
array![0x12, 0x34].span(),
43+
);
44+
```

0 commit comments

Comments
 (0)