Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions docs/plans/2026-01-09-image-id-storage-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Image ID Storage Design

Store RISC0 image IDs (state and recursive) in node storage and expose them via Node methods.

## Background

Currently, image IDs are computed on-demand from ELF code during recursive proof generation but not persisted. This design adds persistent storage and retrieval methods.

## Requirements

- Store state and recursive image IDs as `[u8; 32]`
- Compute and store at node startup when ELF codes are provided
- Support both Db (SQLite) and Memory storage backends
- Expose via two methods: `get_state_image_id()` and `get_recursive_image_id()`

## Design

### Database Schema

New file: `node/sql/create/image_ids.sql`

```sql
CREATE TABLE IF NOT EXISTS image_ids (
id INTEGER PRIMARY KEY,
state_image_id BLOB NOT NULL,
recursive_image_id BLOB NOT NULL
)
```

Single row table holding both image IDs.

### Storage Layer

**`node/src/db.rs`** - Add methods:

```rust
pub async fn set_image_ids(&self, state: [u8; 32], recursive: [u8; 32])
pub async fn get_state_image_id(&self) -> Option<[u8; 32]>
pub async fn get_recursive_image_id(&self) -> Option<[u8; 32]>
```

**`node/src/memory.rs`** - Add fields to `MemoryInner`:

```rust
state_image_id: Option<[u8; 32]>,
recursive_image_id: Option<[u8; 32]>,
```

With matching setter and getter methods on `Memory`.

**`node/src/storage.rs`** - Add delegation on `Storage` enum:

```rust
pub async fn set_image_ids(&self, state: [u8; 32], recursive: [u8; 32])
pub async fn get_state_image_id(&self) -> Option<[u8; 32]>
pub async fn get_recursive_image_id(&self) -> Option<[u8; 32]>
```

### Node API

**`node/src/lib.rs`** - Add methods on `Node`:

```rust
pub async fn get_state_image_id(&self) -> Option<[u8; 32]> {
self.storage.get_state_image_id().await
}

pub async fn get_recursive_image_id(&self) -> Option<[u8; 32]> {
self.storage.get_recursive_image_id().await
}
```

### Initialization

In the ZK publisher flow (`run_zk_publisher_stream`), at startup when `ElfCode` is available:

```rust
let state_image_id: [u8; 32] = risc0_zkvm::compute_image_id(&elf_code.state_elf_code)?.into();
let recursive_image_id: [u8; 32] = risc0_zkvm::compute_image_id(&elf_code.recursive_elf_code)?.into();
storage.set_image_ids(state_image_id, recursive_image_id).await;
```

This runs once at startup before the main processing loop.

## Files Changed

| File | Change |
|------|--------|
| `node/sql/create/image_ids.sql` | New table schema |
| `node/src/db.rs` | Add set/get methods for image IDs |
| `node/src/memory.rs` | Add fields and methods to MemoryInner/Memory |
| `node/src/storage.rs` | Add delegation methods on Storage enum |
| `node/src/lib.rs` | Add Node methods and initialization logic |

## Not In Scope

- HTTP endpoints for image IDs (can be added later if needed)
- Storing full ELF code bytes
- Changes to proof storage or retrieval
Loading
Loading