Skip to content

Commit

Permalink
chore(prover-service): setup dockerfile and ci workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
oyyblin committed Nov 20, 2024
1 parent decc72f commit f7c1ca0
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 16 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: ci

on:
push:
branches:
- "main"
tags:
- "v*"
pull_request:
branches:
- "main"

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/prover-service

jobs:
build-and-push-image:
runs-on: ubuntu-latest
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
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@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
id: push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: prover-service
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)."
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ A raffle system powered by SP1 zero-knowledge proofs and Galxe Raffle smart cont

- `zk/`: Contains the SP1 RISC-V program and proof generation scripts.
- `contracts/`: Contains the Raffle smart contract.
- `prover-service/`: Contains a GRPC server for generating zero-knowledge proofs using the Prover Network.
- `go/`: Contains the Golang bindings for the Raffle smart contract, as well as a library for running the raffle offchain.

## 🔑 ZK
Expand Down
4 changes: 4 additions & 0 deletions prover-service/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target
Dockerfile
.dockerignore
.gitignore
2 changes: 1 addition & 1 deletion prover-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version = "0.0.1"
edition = "2021"

[[bin]]
name = "prover-server"
name = "server"
path = "src/bin/server.rs"

[dependencies]
Expand Down
22 changes: 22 additions & 0 deletions prover-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Build stage
FROM rust:1-slim as builder

WORKDIR /usr/src/app

RUN apt-get update && apt-get install -y \
libssl3 \
ca-certificates \
pkg-config \
libssl-dev \
protobuf-compiler

COPY . .

RUN cargo build --release

# Runtime stage
FROM debian:bookworm-slim

RUN apt-get update && apt-get install -y libssl3 ca-certificates
COPY --from=builder /usr/src/app/target/release/server /usr/local/bin/server
CMD ["server"]
2 changes: 1 addition & 1 deletion prover-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ pub mod proto {
}

pub mod service;

pub mod utils;
// Re-export common types
pub use proto::prover::{ProofSystem, ProveRequest, ProveResponse};
15 changes: 1 addition & 14 deletions prover-service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use tonic::{Request, Response, Status};

use crate::proto::prover::prover_service_server::ProverService;
use crate::proto::prover::{ProofSystem, ProveRequest, ProveResponse};
use crate::utils::hex::parse_hex_string;

pub struct ProverServiceImpl {
elf: Vec<u8>,
Expand Down Expand Up @@ -37,20 +38,6 @@ sol! {
}
}

/// Parse a hex string into a 32-byte array
fn parse_hex_string(s: &str) -> Result<[u8; 32], String> {
let s = s.strip_prefix("0x").unwrap_or(s);
if s.len() != 64 {
return Err("Randomness must be a 32-byte (64 character) hex string".to_string());
}

let bytes = hex::decode(s).map_err(|e| format!("Failed to decode hex string: {}", e))?;

bytes
.try_into()
.map_err(|_| "Failed to convert to 32 byte array".to_string())
}

#[tonic::async_trait]
impl ProverService for ProverServiceImpl {
async fn prove(
Expand Down
13 changes: 13 additions & 0 deletions prover-service/src/utils/hex.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/// Parse a hex string into a 32-byte array
pub fn parse_hex_string(s: &str) -> Result<[u8; 32], String> {
let s = s.strip_prefix("0x").unwrap_or(s);
if s.len() != 64 {
return Err("Randomness must be a 32-byte (64 character) hex string".to_string());
}

let bytes = hex::decode(s).map_err(|e| format!("Failed to decode hex string: {}", e))?;

bytes
.try_into()
.map_err(|_| "Failed to convert to 32 byte array".to_string())
}
1 change: 1 addition & 0 deletions prover-service/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod hex;

0 comments on commit f7c1ca0

Please sign in to comment.