Skip to content

Commit

Permalink
migrate zkvdb
Browse files Browse the repository at this point in the history
  • Loading branch information
erhant committed Oct 26, 2024
1 parent ff601d8 commit 2c91cd4
Show file tree
Hide file tree
Showing 18 changed files with 8,759 additions and 178 deletions.
48 changes: 48 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
[workspace]
members = [
"lib",
"program",
"script",
]
members = ["lib", "program", "script", "embedder"]
resolver = "2"

[workspace.dependencies]
alloy-sol-types = "0.7.7"
alloy-sol-types = "0.7.7"
92 changes: 92 additions & 0 deletions LEGACY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# SP1 Project Template

This is a template for creating an end-to-end [SP1](https://github.com/succinctlabs/sp1) project
that can generate a proof of any RISC-V program.

## Requirements

- [Rust](https://rustup.rs/)
- [SP1](https://docs.succinct.xyz/getting-started/install.html)

## Running the Project

There are four main ways to run this project: build a program, execute a program, generate a core proof, and
generate an EVM-compatible proof.

### Build the Program

To build the program, run the following command:

```sh
cd program
cargo prove build
```

### Execute the Program

To run the program without generating a proof:

```sh
cd script
cargo run --release -- --execute
```

This will execute the program and display the output.

### Generate a Core Proof

To generate a core proof for your program:

```sh
cd script
cargo run --release -- --prove
```

### Generate an EVM-Compatible Proof

> [!WARNING]
> You will need at least 128GB RAM to generate a Groth16 or PLONK proof.
To generate a proof that is small enough to be verified on-chain and verifiable by the EVM:

```sh
cd script
cargo run --release --bin evm -- --system groth16
```

this will generate a Groth16 proof. If you want to generate a PLONK proof, run the following command:

```sh
cargo run --release --bin evm -- --system plonk
```

These commands will also generate fixtures that can be used to test the verification of SP1 zkVM proofs
inside Solidity.

### Retrieve the Verification Key

To retrieve your `programVKey` for your on-chain contract, run the following command:

```sh
cargo prove vkey --elf elf/riscv32im-succinct-zkvm-elf
```

## Using the Prover Network

We highly recommend using the Succinct prover network for any non-trivial programs or benchmarking purposes. For more information, see the [setup guide](https://docs.succinct.xyz/generating-proofs/prover-network.html).

To get started, copy the example environment file:

```sh
cp .env.example .env
```

Then, set the `SP1_PROVER` environment variable to `network` and set the `SP1_PRIVATE_KEY`
environment variable to your whitelisted private key.

For example, to generate an EVM-compatible proof using the prover network, run the following
command:

```sh
SP1_PROVER=network SP1_PRIVATE_KEY=... cargo run --release --bin evm
```
62 changes: 16 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# SP1 Project Template
# Zero-Knowledge VectorDB

This is a template for creating an end-to-end [SP1](https://github.com/succinctlabs/sp1) project
that can generate a proof of any RISC-V program.
A verifiable HNSW query program, powered by [SP1](https://github.com/succinctlabs/sp1).

## Requirements
## Installation

You need the following:

- [Rust](https://rustup.rs/)
- [SP1](https://docs.succinct.xyz/getting-started/install.html)
- [Ollama](https://ollama.com/)

## Running the Project

There are four main ways to run this project: build a program, execute a program, generate a core proof, and
generate an EVM-compatible proof.
## Usage

### Build the Program

Expand Down Expand Up @@ -42,51 +41,22 @@ cd script
cargo run --release -- --prove
```

### Generate an EVM-Compatible Proof

> [!WARNING]
> You will need at least 128GB RAM to generate a Groth16 or PLONK proof.
To generate a proof that is small enough to be verified on-chain and verifiable by the EVM:

```sh
cd script
cargo run --release --bin evm -- --system groth16
```
### Wallet Generation

this will generate a Groth16 proof. If you want to generate a PLONK proof, run the following command:
You can create a new wallet & store it directly in a random file with:

```sh
cargo run --release --bin evm -- --system plonk
```

These commands will also generate fixtures that can be used to test the verification of SP1 zkVM proofs
inside Solidity.
PRIV_KEY=$(cast wallet new | grep "Private key" | cut -d ' ' -f 3)

### Retrieve the Verification Key

To retrieve your `programVKey` for your on-chain contract, run the following command:

```sh
cargo prove vkey --elf elf/riscv32im-succinct-zkvm-elf
```

## Using the Prover Network

We highly recommend using the Succinct prover network for any non-trivial programs or benchmarking purposes. For more information, see the [setup guide](https://docs.succinct.xyz/generating-proofs/prover-network.html).

To get started, copy the example environment file:

```sh
cp .env.example .env
# will prompt for a password, can be left empty
cast wallet import --private-key $PRIV_KEY -k ./secrets/ $RANDOM.json
```

Then, set the `SP1_PROVER` environment variable to `network` and set the `SP1_PRIVATE_KEY`
environment variable to your whitelisted private key.
It will prompt for a password, and then output the keystore under [`secrets`](./secrets/) folder.

For example, to generate an EVM-compatible proof using the prover network, run the following
command:
You can view the respective address of a keystore file with:

```sh
SP1_PROVER=network SP1_PRIVATE_KEY=... cargo run --release --bin evm
# will prompt for the password
cast wallet address --keystore ./secrets/wallet.json
```
1 change: 1 addition & 0 deletions data/foods-med.index.json

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions data/foods-med.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[
{
"name": "Spaghetti Bolognese",
"description": "Italian pasta with minced meat and tomato sauce, rich and savory"
},
{
"name": "Sushi",
"description": "Japanese vinegared rice with raw fish, light and fresh"
},
{
"name": "Tacos",
"description": "Mexican tortilla with spicy meat, cheese, and vegetables"
},
{
"name": "Apple Pie",
"description": "Classic American dessert, sweet with cinnamon and baked apples"
},
{ "name": "Croissant", "description": "French pastry, flaky and buttery" },
{
"name": "Caesar Salad",
"description": "Salad with romaine lettuce, croutons, parmesan, and creamy dressing"
},
{
"name": "Miso Soup",
"description": "Japanese broth made with fermented soy, light and savory"
},
{
"name": "Cheeseburger",
"description": "Grilled beef patty with melted cheese, savory and juicy"
},
{
"name": "Falafel",
"description": "Middle Eastern fried chickpea balls, crispy and spiced"
},
{
"name": "Pad Thai",
"description": "Thai stir-fried noodles with peanuts, tangy and sweet"
}
]
Loading

0 comments on commit 2c91cd4

Please sign in to comment.