diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..f0ca1e7 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/README.md b/README.md index d6a33a5..6c274fa 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/prover-service/.dockerignore b/prover-service/.dockerignore new file mode 100644 index 0000000..8c6bdbd --- /dev/null +++ b/prover-service/.dockerignore @@ -0,0 +1,4 @@ +target +Dockerfile +.dockerignore +.gitignore diff --git a/prover-service/Cargo.toml b/prover-service/Cargo.toml index 2a4b8d3..b250abf 100644 --- a/prover-service/Cargo.toml +++ b/prover-service/Cargo.toml @@ -5,7 +5,7 @@ version = "0.0.1" edition = "2021" [[bin]] -name = "prover-server" +name = "server" path = "src/bin/server.rs" [dependencies] diff --git a/prover-service/Dockerfile b/prover-service/Dockerfile new file mode 100644 index 0000000..401c0e9 --- /dev/null +++ b/prover-service/Dockerfile @@ -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"] diff --git a/prover-service/src/lib.rs b/prover-service/src/lib.rs index 1d5ba85..a403f83 100644 --- a/prover-service/src/lib.rs +++ b/prover-service/src/lib.rs @@ -6,6 +6,6 @@ pub mod proto { } pub mod service; - +pub mod utils; // Re-export common types pub use proto::prover::{ProofSystem, ProveRequest, ProveResponse}; diff --git a/prover-service/src/service.rs b/prover-service/src/service.rs index 895941d..6f6a868 100644 --- a/prover-service/src/service.rs +++ b/prover-service/src/service.rs @@ -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, @@ -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( diff --git a/prover-service/src/utils/hex.rs b/prover-service/src/utils/hex.rs new file mode 100644 index 0000000..c8223f8 --- /dev/null +++ b/prover-service/src/utils/hex.rs @@ -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()) +} diff --git a/prover-service/src/utils/mod.rs b/prover-service/src/utils/mod.rs new file mode 100644 index 0000000..ce02e67 --- /dev/null +++ b/prover-service/src/utils/mod.rs @@ -0,0 +1 @@ +pub mod hex;