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

Make prover work without docker dependency #8

Merged
merged 44 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
2e0a43d
CairoZero docker remove
piotr-stec Aug 4, 2024
a970261
cairo0 paths changes
piotr-stec Aug 5, 2024
b21319e
Cairo1 docker removed
piotr-stec Aug 5, 2024
ad589c1
changed comments
piotr-stec Aug 6, 2024
b4a1c3e
Dockerfile changes
piotr-stec Aug 7, 2024
d16695d
Podman Crate deleted
piotr-stec Aug 7, 2024
dd52579
cairo1-compile
piotr-stec Aug 9, 2024
f00b245
Removing files
piotr-stec Aug 9, 2024
cd0e335
Docker file updates
piotr-stec Aug 9, 2024
2affee5
cairo-lang dependencies
piotr-stec Aug 9, 2024
98a4b88
fibonacci examples changes
piotr-stec Aug 9, 2024
ea3585f
gitignore update
piotr-stec Aug 9, 2024
2ea6523
updates
piotr-stec Aug 9, 2024
42a4401
corelib installation script
piotr-stec Aug 9, 2024
febd9fb
merge
steebchen Aug 12, 2024
1983d88
fmt
steebchen Aug 12, 2024
7a74838
wait for prover and curl
steebchen Aug 12, 2024
bdca0c8
wait for prover
steebchen Aug 12, 2024
c80352e
test fix
chudkowsky Aug 14, 2024
db585e1
test workflow trigger
chudkowsky Aug 14, 2024
1368680
check error
chudkowsky Aug 14, 2024
e48b2f5
automated tests in ci
chudkowsky Aug 14, 2024
efa1b89
fmt, clippy
chudkowsky Aug 14, 2024
53db8fc
verifier in docker
chudkowsky Aug 15, 2024
f6978d4
script update, check corectness of build and run
chudkowsky Aug 15, 2024
99107e2
fix docker image
steebchen Aug 15, 2024
ead4059
fix clippy
steebchen Aug 15, 2024
6a8a04b
publish ci
steebchen Aug 15, 2024
8f101d2
run on 32 core
steebchen Aug 15, 2024
ee2a677
remove docker
steebchen Aug 15, 2024
b51ecee
test all
steebchen Aug 15, 2024
a0f7526
test serially
steebchen Aug 15, 2024
1b779f1
script update, check corectness of build and run
chudkowsky Aug 15, 2024
630bae0
fix docker image
steebchen Aug 15, 2024
7e8bb58
fix clippy
steebchen Aug 15, 2024
2deb415
publish ci
steebchen Aug 15, 2024
d016e90
run on 32 core
steebchen Aug 15, 2024
d997832
remove docker
steebchen Aug 15, 2024
8d7a62d
test all
steebchen Aug 15, 2024
bcf2a90
test serially
steebchen Aug 15, 2024
52827b9
proof verification on tests, using cpu_air_verifier
chudkowsky Aug 16, 2024
f30c19c
Port in tests as env, container_engine variable
chudkowsky Aug 16, 2024
17f9bdf
Merge branch 'remove-docker' into verifier
chudkowsky Aug 16, 2024
b7ec5cc
Merge pull request #10 from cartridge-gg/verifier
chudkowsky Aug 16, 2024
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
46 changes: 44 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
# Generated by Cargo
# will have compiled files and executables
**/debug/
**/target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
**/Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# Scarb
**/Scarb.lock

# vscode
**/.vscode/

# Git
**/.git

# Docker
**/Dockerfile

# Ignores
**/.gitignore
**/.dockerignore

# Envs
**/*.cargo

# Venvs
**/.venv


/resources
output.json
examples/Cairo/prover_input.json
examples/CairoZero/prover_input.json
/corelib

.idea/
.git/
target/
8 changes: 2 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Build
run: cargo build --verbose
test:
runs-on: ubuntu-latest
runs-on: ubuntu-latest-32-core
steps:
- uses: actions/checkout@v4
- uses: asdf-vm/actions/install@v3
Expand All @@ -37,9 +37,5 @@ jobs:
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
run: ./scripts/e2e_test.sh
15 changes: 12 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,18 @@
# vscode
**/.vscode/

# Git
**/.git

# Envs
**/*.cargo

# Venvs
**/.venv

/resources
/.cargo
.venv
output.json
examples/Cairo/prover_input.json
examples/CairoZero/prover_input.json
examples/CairoZero/prover_input.json
/corelib

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ members = [
"bin/keygen",
"bin/register",
"crates/common",
"crates/podman",
"crates/utils",
"prover",
"prover-sdk",
"cairo1-compile",
]

[workspace.package]
Expand All @@ -30,13 +30,12 @@ http = "1.1.0"
hyper-util = "0.1.3"
jsonwebtoken = "9.3.0"
lazy_static = "1.4.0"
podman = { path = "crates/podman" }
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", "rustls-tls"], default-features = false }
reqwest_cookie_store = "0.7.0"
prover-sdk = { path = "prover-sdk" }
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.116"
serde_with = "3.8.1"
Expand All @@ -54,3 +53,6 @@ tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
url = { version = "2.5.0", features = ["serde"] }
utils = { path = "crates/utils" }
config-generator = { git = "https://github.com/piotr-stec/genereate-config.git" }
cairo-lang-compiler = { git = "https://github.com/starkware-libs/cairo", tag = "v2.7.0-rc.3", default-features = false }
cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo", tag = "v2.7.0-rc.3", default-features = false }
35 changes: 32 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,38 @@ COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
# Build application
COPY . .
ENV PATH="/root/.cargo/bin:${PATH}"

RUN cargo build --release -p prover
RUN cargo install --git https://github.com/lambdaclass/cairo-vm --rev 37ea72977dccbc2b90b8b7534c1edabd2e2fef79 cairo1-run


FROM docker.io/piotr439/prover AS prover


FROM python:3.9.18-slim-bookworm AS final
WORKDIR /
RUN apt update && apt install -y build-essential libgmp-dev elfutils jq git
RUN pip install --upgrade pip

COPY --from=builder /app/target/release/prover /usr/local/bin/prover
COPY --from=builder /usr/local/cargo/bin/cairo1-run /usr/local/bin/cairo1-run
COPY --from=prover /usr/bin/cpu_air_prover /usr/local/bin/cpu_air_prover
COPY --from=prover /usr/bin/cpu_air_verifier /usr/local/bin/cpu_air_verifier

COPY --from=builder /app/config/cpu_air_prover_config.json /config/cpu_air_prover_config.json
RUN git clone --depth=1 -b v2.7.0-rc.3 https://github.com/starkware-libs/cairo.git
RUN mv cairo/corelib/ .

RUN rm -rf cairo

RUN pip install cairo-lang==0.13.1
RUN pip install sympy==1.12.1

RUN mkdir resources/
RUN mkdir resources/cairo/
RUN mkdir resources/cairoZero/

EXPOSE 3000

# We do not need the Rust toolchain to run the binary!
FROM alpine AS runtime
COPY --from=builder /app/target/release/prover /usr/local/bin
ENTRYPOINT [ "prover" ]
3 changes: 2 additions & 1 deletion bin/cairo-prove/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
cargo run --bin cairo-prove -- --key <your secret key for sdk> --cairo-version <1/0> --url <url for prover> your_input.json > output.json
```

By default cairo version is set to cairo 1
By default cairo version is set to cairo 1
test workflow

## Input format

Expand Down
39 changes: 0 additions & 39 deletions bin/cairo-prove/tests/common.rs
Original file line number Diff line number Diff line change
@@ -1,45 +1,6 @@
use std::path::PathBuf;

use prover::server::start;
use prover::Args;
use prover_sdk::ProverAccessKey;
use tokio::fs::File;
use tokio::io::AsyncReadExt;
use tokio::net::TcpListener;
use tokio::task::JoinHandle;
use url::Url;

pub async fn spawn_prover() -> (JoinHandle<()>, ProverAccessKey, Url) {
use url::Url;

let port = TcpListener::bind("127.0.0.1:0")
.await
.unwrap()
.local_addr()
.unwrap()
.port();

let key = ProverAccessKey::generate();
let encoded_key = prefix_hex::encode(key.0.verifying_key().to_bytes());

let args = Args {
host: "0.0.0.0".to_string(),
port,
jwt_secret_key: "placeholder".to_string(),
message_expiration_time: 60,
session_expiration_time: 3600,
authorized_keys: Some(vec![encoded_key]),
authorized_keys_path: None,
};

let handle = tokio::spawn(async move {
start(args).await.unwrap();
});

let url = Url::parse(&format!("http://localhost:{}", port)).unwrap();

(handle, key, url)
}

pub async fn read_file(path: PathBuf) -> Result<String, std::io::Error> {
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
Expand Down
33 changes: 16 additions & 17 deletions bin/cairo-prove/tests/prove.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
use crate::common::{read_file, spawn_prover};
use crate::common::read_file;
use cairo_proof_parser::output::{extract_output, ExtractOutputResult};
use cairo_prove::{prove, CliInput};
use serde_json::Value;
use std::path::PathBuf;

use std::{env, path::PathBuf};
use url::Url;
mod common;

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

let key = "0x5883b0e30b008e48af3d0bf5cfc138fb6093496da6f87d24b65def88470356d3";
let port = env::var("PORT").unwrap();
let prover_url = Url::parse(&format!("http://localhost:{}", port)).unwrap();
let args = CliInput {
key: key.signing_key_as_hex_string(),
key: key.to_string(),
cairo_version: 1,
url,
url: prover_url,
};

let prover_input = read_file(PathBuf::from("examples/Cairo/prover_input.json")).await?;
let prover_input =
read_file(PathBuf::from("examples/Cairo/fibonacci_prover_input.json")).await?;
let proof = prove(args, prover_input).await?;
assert!(extract_output(&proof).is_ok());
handle.abort();
Ok(())
}
#[tokio::test]
async fn test_cairo0_fibonacci() -> Result<(), cairo_prove::ProveError> {
let (handle, key, url) = spawn_prover().await;

let key = "0x5883b0e30b008e48af3d0bf5cfc138fb6093496da6f87d24b65def88470356d3";
let port = env::var("PORT").unwrap();
let prover_url = Url::parse(&format!("http://localhost:{}", port)).unwrap();
let args = CliInput {
key: key.signing_key_as_hex_string(),
key: key.to_string(),
cairo_version: 0,
url,
url: prover_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 All @@ -49,8 +51,5 @@ async fn test_cairo0_fibonacci() -> Result<(), cairo_prove::ProveError> {
expected_input, fibonacci_claim_index,
"Fibonacci index mismatch."
);

handle.abort();

Ok(())
}
9 changes: 6 additions & 3 deletions crates/podman/Cargo.toml → cairo1-compile/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
[package]
name = "podman"
name = "cairo1-compile"
version.workspace = true
edition.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
thiserror.workspace = true
tokio.workspace = true
cairo-lang-compiler.workspace = true
cairo-lang-sierra.workspace = true
clap.workspace = true
serde.workspace = true
serde_json.workspace = true
26 changes: 26 additions & 0 deletions cairo1-compile/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

# Installation Guide

Follow the steps below to install `cairo1-compile` and `cairo1-run`.

## Install `cairo1-compile`

To install `cairo1-compile`, run the following command:

```sh
cargo install --path cairo1-compile
```

## Install `cairo1-run`

To install `cairo1-run` from the repository, run the following command:

```sh
cargo install --git https://github.com/lambdaclass/cairo-vm cairo1-run
```


`cairo1-compile compile --output resources/fibonacci_compiled.sierra.json e2e_test/Cairo/fibonacci.cairo`
`cairo1-compile merge -o resources/fibonacci_prover_input.json resources/fibonacci_compiled.sierra.json e2e_test/Cairo/input.json`
`podman build -t stone5-cairo1:recursive -f Dockerfile .`
`podman run -i --rm stone5-cairo1:recursive < resources/fibonacci_prover_input.json > resources/proof.json`
Loading