Skip to content

Commit

Permalink
revamp
Browse files Browse the repository at this point in the history
  • Loading branch information
steebchen committed Jul 18, 2024
1 parent 7d00b05 commit 0368625
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 66 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/
.git/
target/
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: ci
on: push
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: asdf-vm/actions/install@v3
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --workspace --verbose
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python 3.9.18
108 changes: 53 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The Prover SDK is a Rust library for interacting with the Prover service. It pro
Before using the prover key has to be authorized by the prover operator. To generate the key use:

```bash
cargo run --bin keygen
cargo run --bin keygen
```

It will output 2 keys.
Expand All @@ -20,26 +20,24 @@ It will output 2 keys.
First parse a private key corresponding to an authorized public key.

```rust
ProverAccessKey::from_hex_string(
"0xf91350db1ca372b54376b519be8bf73a7bbbbefc4ffe169797bc3f5ea2dec740",
)
.unwrap()

ProverAccessKey::from_hex_string(
"0xf91350db1ca372b54376b519be8bf73a7bbbbefc4ffe169797bc3f5ea2dec740",
)
.unwrap()
```

Then construct an instance with

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

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

Then you can use below to prove an execution

```rust
let data = load_cairo1(PathBuf::from("../prover/resources/input_cairo1.json")).await?;
let proof = sdk.prove_cairo1(data).await;
let data = load_cairo1(PathBuf::from("../prover/resources/input_cairo1.json")).await?;
let proof = sdk.prove_cairo1(data).await;
```

# Operating a prover
Expand All @@ -49,7 +47,7 @@ To run the sdk first make sure prover/authorized_keys.json contains your public_
Run the following command in your terminal:

```bash
cargo run -p prover -- --jwt-secret-key <ENV_VAR_JWT_SECRET_KEY> --message-expiration-time <MESSAGE_EXPIRATION_TIME> --session-expiration-time <SESSION_EXPIRATION_TIME> --authorized-keys <AUTHORIZED_KEY>,<ANOTHER_KEY>
cargo run -p prover -- --jwt-secret-key <ENV_VAR_JWT_SECRET_KEY> --message-expiration-time <MESSAGE_EXPIRATION_TIME> --session-expiration-time <SESSION_EXPIRATION_TIME> --authorized-keys <AUTHORIZED_KEY>,<ANOTHER_KEY>
```

Alternatively use the flag `--authorized-keys-path authorized_keys.json` instead of `--authorized-keys` to load keys from a json file. It needs to have the format below
Expand All @@ -75,59 +73,59 @@ To use the SDK, follow these steps:

Authenticate with the Prover service using your private key and the authentication URL:

```
#[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/cairo1";
let result = ProverSDK::new(url_auth, url_prover)
.auth(&private_key_hex)
.await?;
// Handle authentication result
Ok(())
}
```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/cairo1";

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

// Handle authentication result
Ok(())
}
```

Use the SDK to prove data:

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

let sdk = result.build()?;
let data = read_json_file("resources/input.json").await?;
let proof = sdk.prove(data).await?;
let sdk = result.build()?;
let data = read_json_file("resources/input.json").await?;
let proof = sdk.prove(data).await?;

// Handle proof result
Ok(())
}
// Handle proof result
Ok(())
}
```

Handle errors using the provided error types:

```
#[tokio::main]
async fn main() -> Result<(), ProverSdkErrors> {
// 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);
}
}
```rust
#[tokio::main]
async fn main() -> Result<(), ProverSdkErrors> {
// Authentication code goes here...

Ok(())
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(())
}
```
13 changes: 8 additions & 5 deletions scripts/0-venv.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
#!/usr/bin/env bash

set -eux

# Define the name of the virtual environment
VENV_NAME=".venv"

# Check if the virtual environment already exists
if [ ! -d "$VENV_NAME" ]; then
# If it doesn't exist, create the virtual environment
python -m venv $VENV_NAME && \
python -m venv $VENV_NAME

# Activate the virtual environment
source $VENV_NAME/bin/activate && \
source $VENV_NAME/bin/activate

# Upgrade pip to the latest version
pip install --upgrade pip && \
pip install --upgrade pip

# Install the required packages from the requirements.txt file
pip install cairo-lang==0.13.1 && \
pip install sympy==1.12.1
pip install cairo-lang==0.13.1

# Deactivate the virtual environment
deactivate
else
# If it does exist, print a message indicating that it already exists
echo "Virtual environment $VENV_NAME already exists."
fi
fi
12 changes: 9 additions & 3 deletions scripts/1-compile.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#!/usr/bin/env bash

source .venv/bin/activate && \
set -eux

source .venv/bin/activate

mkdir -p resources

cairo-compile \
examples/CairoZero/fibonacci.cairo \
--output resources/fibonacci_compiled.json \
--proof_mode && \
deactivate
--proof_mode

deactivate
2 changes: 2 additions & 0 deletions scripts/2-merge.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

set -eux

# This script assumes Python is installed and accessible from the command line as 'python'

# Variables for JSON files and output
Expand Down
6 changes: 3 additions & 3 deletions scripts/combine_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
def combine_json_files(file1, file2, layout, output_file):
with open(file1, 'r') as f:
data1 = json.load(f)

with open(file2, 'r') as f:
data2 = json.load(f)

combined_data = {
"program_input": data2,
"layout": layout,
"program": data1
}

with open(output_file, 'w') as f:
json.dump(combined_data, f, indent=4)

Expand Down

0 comments on commit 0368625

Please sign in to comment.