A lightweight, fully on-chain database system built with Anchor on Solana.
This program allows you to create table structures, store data as transactions, and record immutable edit history through a rolling hash mechanism — enabling verifiable state tracking even hundreds of years later.
- Initializes the root database object.
- Stores
table_names: Vec<Vec<u8>>, which acts as the catalog of all tables created by a user. - Designed for dynamic updates — adding or editing tables will update this root structure.
- With table name length ≤ 15, 100 tables can be stored for ~0.012 SOL rent.
- Creates a new table PDA with the following seeds:
b"iqdb-table",
crate::ID.as_ref(),
root.key().as_ref(),
table_name.as_ref(),
- Adds the table name to
root.table_names. - Stores column definitions as
Vec<Vec<u8>>inside the table PDA. - Also initializes an instruction table PDA (table_name +
b"instruction") for tracking edit operations.
- Writes data into the table PDA.
- Uses the rolling hash system to keep a verifiable chain of updates in
tx_ref.
- Handles Update and Delete operations on table data.
- Records changes in both:
- Table PDA (actual data change)
- Instruction PDA (operation log)
This ensures the data change and its context are both on-chain.
Every change updates a lightweight rolling hash stored in a TxRef PDA:
keccak(domain || prev_hash || new_tx)seq: Sequential counter for each updatelast_tx: The most recent transaction IDrolling: 32-byte keccak hash chaining all changes together
This creates a permanent, tamper-evident on-chain record of all updates.
Even 300 years later, the entire DB history can be verified by re-hashing transactions in order.
| PDA Type | Seeds |
|---|---|
| Root | ["iqdb-root", program_id, user_pubkey] |
| Table | ["iqdb-table", program_id, root_pubkey, table_name] |
| Instruction Table | ["iqdb-table", program_id, root_pubkey, table_name, "instruction"] |
| TxRef (content) | ["iqdb-txref", program_id, user_pubkey] |
| TxRef (target) | ["iqdb-txref", program_id, user_pubkey, "target"] |
| Function | Purpose |
|---|---|
initialize_root |
Initialize the root PDA for a user |
create_table |
Create a table PDA and register it in the root |
write_data |
Insert new row data into a table |
database_instruction |
Perform Update/Delete and log in instruction PDA |
pub struct Root {
pub creator: Pubkey,
pub table_names: Vec<Vec<u8>>,
}pub struct Table {
pub column_names: Vec<Vec<u8>>,
}pub struct TxRef {
pub seq: u64,
pub last_tx: Vec<u8>,
pub rolling: [u8; 32],
}Make sure Solana test validator is running:
solana-test-validatorThen deploy with Anchor:
anchor deploy# 1. Initialize root
anchor test -- --nocapture
# 2. Create a table with columns
# (Use your TS or Rust client to call create_table)
# 3. Write data (insert rows)
# 4. Use database_instruction to update/delete rows
# 5. Verify history by reading TxRef rolling hash chainThis system is designed for long-term, trustless data preservation.
Unlike typical off-chain DBs, here every change is cryptographically chained and stored on Solana, making your application’s history verifiable even in centuries to come.
🧠 Author: Zo & SpaceBun
⚡ Solana + Anchor + Rolling Hash DB