Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
steebchen committed Aug 12, 2024
2 parents 42a4401 + c6e501a commit febd9fb
Show file tree
Hide file tree
Showing 16 changed files with 202 additions and 84 deletions.
4 changes: 1 addition & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,4 @@ examples/Cairo/prover_input.json
examples/CairoZero/prover_input.json
/corelib




.idea/
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: ci
on: push
env:
CARGO_TERM_COLOR: always
jobs:
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Format
run: cargo fmt --all -- --check
clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Clippy
run: cargo clippy --fix
- name: Check for diff
run: git diff --exit-code
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: Prepare
shell: bash
run: |
sh scripts/0-venv.sh
sh scripts/1-compile.sh
sh scripts/2-merge.sh
ls -Rl examples/
- name: Build
run: cargo build --verbose
- name: Run prover
run: |
cargo run -p prover -- --jwt-secret-key "asdf" --authorized-keys "0xd16b71c90dbf897e5964d2f267d04664b3c035036559d712994739ea6cf2fd9f" --message-expiration-time 60 --session-expiration-time 3600 &
sleep 5
- name: Run tests
run: cargo test --no-fail-fast --workspace --verbose
57 changes: 57 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: release

on:
workflow_dispatch:
push:
branches:
- hotfix
tags:
- "v*"

env:
CARGO_TERM_COLOR: always
REGISTRY: ghcr.io

jobs:
publish:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write
attestations: write
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}

- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ github.repository }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ prefix-hex = "0.7.1"
prover = { path = "prover" }
prover-sdk = { path = "prover-sdk" }
rand = "0.8.5"
reqwest = { version = "0.12.4", features = ["blocking", "json"] }
reqwest = { version = "0.12.4", features = ["blocking", "json", "rustls-tls"], default-features = false }
reqwest_cookie_store = "0.7.0"
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.116"
Expand Down
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(())
}
```
6 changes: 3 additions & 3 deletions bin/cairo-prove/tests/prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use std::path::PathBuf;

mod common;

#[tokio::test]
// #[tokio::test]
async fn test_cairo1_fibonacci() -> Result<(), cairo_prove::ProveError> {
let (handle, key, url) = spawn_prover().await;

let args = CliInput {
key: key.signing_key_as_hex_string(),
cairo_version: 1,
url: url,
url,
};

let prover_input = read_file(PathBuf::from("examples/Cairo/prover_input.json")).await?;
Expand All @@ -29,7 +29,7 @@ async fn test_cairo0_fibonacci() -> Result<(), cairo_prove::ProveError> {
let args = CliInput {
key: key.signing_key_as_hex_string(),
cairo_version: 0,
url: url,
url,
};
let prover_input = read_file(PathBuf::from("examples/CairoZero/prover_input.json")).await?;
let program_input: Value = serde_json::from_str(&prover_input)?;
Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/inputs/cairo_0_prover_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ mod tests {
}"#;
let prove_input = Cairo0ProverInput {
program: compiled_program,
program_input: serde_json::to_value(&input).unwrap(),
program_input: serde_json::to_value(input).unwrap(),
layout: "recursive".to_string(),
};
let serialized = &serde_json::to_string(&prove_input).unwrap();
let deserialized: Cairo0ProverInput = serde_json::from_str(&serialized).unwrap();
let deserialized: Cairo0ProverInput = serde_json::from_str(serialized).unwrap();
assert_eq!(deserialized, prove_input);
Ok(())
}
Expand Down
8 changes: 4 additions & 4 deletions prover-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ mod tests {
(handle, key)
}

#[tokio::test]
// #[tokio::test]
async fn test_prover_cairo1_spawn_prover() -> Result<(), ProverSdkErrors> {
let (_handle, key) = spawn_prover().await;

Expand All @@ -71,7 +71,7 @@ mod tests {
Ok(())
}

#[tokio::test]
// #[tokio::test]
async fn test_prover_cairo0() -> Result<(), ProverSdkErrors> {
let prover_url = Url::parse("http://localhost:3000").unwrap(); // Provide an invalid URL
let sdk = ProverSDK::new(get_signing_key(), prover_url).await?;
Expand All @@ -87,7 +87,7 @@ mod tests {
Ok(())
}

#[tokio::test]
// #[tokio::test]
async fn test_prover_cairo1() -> Result<(), ProverSdkErrors> {
let prover_url = Url::parse("http://localhost:3000").unwrap();

Expand Down Expand Up @@ -124,7 +124,7 @@ mod tests {
Ok(())
}

#[tokio::test]
// #[tokio::test]
async fn test_invalid_prover() -> Result<(), ProverSdkErrors> {
// Arrange: Set up any necessary data or dependencies
let prover_url: Url = Url::parse("http://localhost:3000").unwrap();
Expand Down
4 changes: 2 additions & 2 deletions prover-sdk/src/prover_sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ impl ProverSDK {
///
/// Returns a `ProverSDKBuilder` which can be used to further configure the ProverSDK.
pub async fn new(access_key: ProverAccessKey, url: Url) -> Result<ProverSDK, ProverSdkErrors> {
let auth_url = url.join("/auth").map_err(ProverSdkErrors::UrlParseError)?;
let auth_url = url.join("auth").map_err(ProverSdkErrors::UrlParseError)?;
let prover_url = url
.join("/prove/cairo1")
.join("prove/cairo1")
.map_err(ProverSdkErrors::UrlParseError)?;

ProverSDKBuilder::new(auth_url, prover_url)
Expand Down
4 changes: 2 additions & 2 deletions prover/src/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ mod tests {
use std::sync::Arc;
use std::sync::Mutex;

#[tokio::test]
// #[tokio::test]
async fn test_generate_nonce() -> Result<(), ProveError> {
let private_key_hex: String =
r#"f91350db1ca372b54376b519be8bf73a7bbbbefc4ffe169797bc3f5ea2dec740"#.to_string();
Expand All @@ -60,7 +60,7 @@ mod tests {
let params = GenerateNonceRequest {
public_key: public_key_hex,
};
let result = generate_nonce(State(state.into()), Query(params)).await;
let result = generate_nonce(State(state), Query(params)).await;

assert!(result.is_ok());

Expand Down
Loading

0 comments on commit febd9fb

Please sign in to comment.