Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readme update #44

Merged
merged 1 commit into from
Sep 9, 2024
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
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

This repository contains a comprehensive toolset for proving computations using the Cairo language. The repository includes a server, an SDK for interacting with the server, a binary `cairo-prove` for executing proofs, and helper binaries such as `keygen` and `register`.

## Pipeline for Key Generation and Proving

1. **Generate Public and Private Keys**:
- Start by generating a pair of cryptographic keys (public and private) using an appropriate library or tool. This step ensures secure communication and validation in future steps.

2. **Start the Server / Send Public Key to Server Operator**:
- Once the keys are generated, the **public key** is sent to the server or server operator to register and authenticate the user/device/app. This allows the server to verify the authenticity of the data coming from the client.
- The **private key** remains securely stored on the client side and should never be shared.

3. **Use Cairo-Prove Binary or SDK for Proving**:
- Use either the **Cairo-Prove binary** or integrate **SDK** into your app. These tools will send compiled programs and input to server, which will return job id, which can be fetched, by polling or by using **SSE** endopint

## Table of Contents

- [Overview](#overview)
Expand Down Expand Up @@ -84,4 +96,3 @@ Helper scripts are included in the `scripts` directory for tasks like running en
## Getting Started

To get started with the Cairo Proving System, please refer to the individual READMEs linked above for detailed instructions on building, configuring, and running each component.

9 changes: 7 additions & 2 deletions bin/cairo-prove/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ cargo install --git https://github.com/cartridge-gg/http-prover.git cairo-prove
`--prover-access-key` (PROVER_ACCESS_KEY): Provides the access key required to authenticate with the prover service. This argument must be private key in hex format

`--wait` (WAIT, default: false): A flag that determines whether the application should wait for the prover's response synchronously. If set to true, the application will block until the prover completes its task, if set to false it ends and returns job, which can be retrived with `get-job` endpoint
`--sse ` (SSE, default: false): A flag which determines if we want to poll for result or use SSE endpoint, by default it polls.

Each of these arguments can be set via command-line flags or environment variables, allowing for flexible configuration depending on your deployment environment and needs.

Expand Down Expand Up @@ -74,8 +75,12 @@ The output of the application depends on --wait flag,it can be job id or the gen

**Basic Example:**

To generate a proof from an input file and print the result to the console:
To generate a proof from an input file and save proof to output file

```bash
cairo-prove --prover-url http://localhost:3000 --layout recursive --program-path examples/cairo/fibonacci_compiled.json --program-input-path examples/cairo/input.json --wait --program-output proof.json --prover-access-key 0xf5061793648ab019cc27d6c9a2bd8a2b651f9224ae9ae2c0990fd32ed2172f48
cairo-prove --prover-url http://localhost:3000 --layout recursive --program-path examples/cairo/fibonacci_compiled.json --program-input-path examples/cairo/input.json --wait --program-output proof.json --prover-access-key 0xf5061793648ab019cc27d6c9a2bd8a2b651f9224ae9ae2c0990fd32ed2172f48 --sse
```
Or alternatively
```bash
cargo run -p cairo-prove -- --prover-url http://localhost:3000 --layout recursive --program-path examples/cairo/fibonacci_compiled.json --program-input-path examples/cairo/input.json --wait --program-output proof.json --prover-access-key 0xf5061793648ab019cc27d6c9a2bd8a2b651f9224ae9ae2c0990fd32ed2172f48 --sse
```
67 changes: 29 additions & 38 deletions prover-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ It will output 2 keys.
First parse a private key corresponding to an authorized public key.

```rust
ProverAccessKey::from_hex_string(
let access_key = ProverAccessKey::from_hex_string(
"0xf91350db1ca372b54376b519be8bf73a7bbbbefc4ffe169797bc3f5ea2dec740",
)
.unwrap()
Expand All @@ -30,18 +30,37 @@ Then construct an instance with

```rust
let prover_url = Url::parse("http://localhost:3000").unwrap();
let sdk = ProverSDK::new(key, prover_url).await?;
let sdk = ProverSDK::new(prover_url, access_key).await?;

```

Then you can use below to prove an execution

```rust
#[derive(Deserialize)]
pub struct JobId {
pub job_id: u64,
}

data = CairoProverInput{
program, //CairoCompiledProgram,
program_input, //Vec<Felt>,
layout, //String,
}
let proof = sdk.prove_cairo1(data).await;
let job_id = sdk.prove_cairo(data).await;
let job: JobId = serde_json::from_str(&job_id)?;
sdk.sse(job.job_id).await?;
let response = sdk.get_job(job.job_id).await?;
if let Some(status) = json_response.get("status").and_then(Value::as_str) {
if status == "Completed" {
return Ok(json_response
.get("result")
.and_then(Value::as_str)
.unwrap_or("No result found")
.to_string());
}
}

```
## Examples

Expand All @@ -52,15 +71,7 @@ Authenticate with the Prover service using your private key and the authenticati
```rust
#[tokio::main]
async fn main() -> Result<(), ProverSdkErrors> {
let private_key_hex : String= env::var("PRIVATE_KEY")?;
let url_auth = "http://localhost:3000/auth";
let url_prover = "http://localhost:3000/prove/cairo";

let result = ProverSDK::new(url_auth, url_prover)
.auth(&private_key_hex)
.await?;

// Handle authentication result
let sdk = ProverSDK::new(prover_url, access_key).await?;
Ok(())
}
```
Expand All @@ -72,34 +83,14 @@ Use the SDK to prove data:
async fn main() -> Result<(), SdkErrors> {
// Authentication code goes here...

let sdk = result.build()?;
let data = read_json_file("resources/input.json").await?;
let sdk = ProverSDK::new(prover_url, access_key).await?;
data = CairoProverInput{
program, //CairoCompiledProgram,
program_input, //Vec<Felt>,
layout, //String,
}
let job_id = sdk.prove(data).await?; //return job id in json format
// Handle job id
Ok(())
}
```

Handle errors using the provided error types:

```rust
#[tokio::main]
async fn main() -> Result<(), SdkErrors> {
// Authentication code goes here...

let result = ProverSDK::new(url_auth, url_prover)
.auth(&private_key_hex)
.await;

match result {
Ok(sdk) => {
// Continue with SDK usage...
}
Err(err) => {
// Handle authentication error
println!("Authentication failed: {}", err);
}
}

Ok(())
}
8 changes: 6 additions & 2 deletions prover/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ The Cairo Proving Server is the core component responsible for managing and veri

Here is an example of running the server with custom settings:

**Note: Using podman with Dockerfile instead of cargo run -p prover is important because it ensures that all necessary binaries and dependencies are bundled within a container.**
You can run it with cargo run -p prover but its neccesery to have all binaries used in server crate. It's highly recommended to use Dockerfile.
```sh
cairo-prover-server --host 127.0.0.1 --port 8080 --message-expiration-time 7200 --session-expiration-time 14400 --jwt-secret-key "my_super_secret_key" --authorized-keys-path /path/to/authorized_keys.json --authorized-keys key1,key2,key3 --num-workers 8 --admin-key "admin_super_secret_key"
podman build . -t http-prover

podman run --replace --name http-prover -p 8080:3000 http-prover --host 127.0.0.1 --port 8080 --message-expiration-time 7200 --session-expiration-time 14400 --jwt-secret-key "my_super_secret_key" --authorized-keys-path /path/to/authorized_keys.json --authorized-keys key1,key2,key3 --num-workers 2 --admin-key "admin_super_secret_key"
```
## Command-Line Options

Expand Down Expand Up @@ -122,7 +126,7 @@ In this example, the server is configured to:
- Use a session expiration time of `14400` seconds.
- Sign JWTs with the provided `jwt-secret-key`.
- Load authorized keys from the specified file path and directly from the command line.
- Use `8` worker threads.
- Use `2` worker threads.
- Use the provided `admin-key` for administrative tasks.

## Environment Variables
Expand Down