Skip to content

Commit

Permalink
feat(circom): add Dockerfile for circom
Browse files Browse the repository at this point in the history
  • Loading branch information
batzor committed Oct 24, 2024
1 parent 8f51ef6 commit 02c4b7c
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
45 changes: 45 additions & 0 deletions docker/Dockerfile.circom.jammy
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM zktachyon/base:jammy-latest AS builder
LABEL maintainer="The Tachyon Authors <[email protected]>"

# Install python dependencies
RUN apt update && apt install -y --no-install-recommends python3-pip
RUN python3 -m pip install numpy

# Set the working directory
WORKDIR /tachyon

# Copy the entire project
COPY . .

# Build circom prover
RUN cd vendors/circom && CARGO_BAZEL_REPIN=true bazel build --@kroma_network_tachyon//:has_openmp --config maxopt //:prover_main

# Build compile tool for witness generator
RUN cd vendors/circom && bazel build --config opt //circomlib/build:compile_witness_generator

# Use the CUDA base image
FROM nvidia/cuda:12.5.0-devel-ubuntu22.04 AS builder-cuda

# Set the working directory
WORKDIR /tachyon

# Copy the entire project
COPY . .

COPY --from=builder /usr /usr
COPY --from=builder /root/.pyenv /root/.pyenv

RUN echo 'export PYENV_ROOT="/root/.pyenv"' >> ~/.bash_profile && \
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile && \
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
RUN echo 'export PYENV_ROOT="/root/.pyenv"' >> ~/.bashrc && \
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc && \
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
ENV PYENV_ROOT="/root/.pyenv"
ENV PATH="${PYENV_ROOT}/shims:${PYENV_ROOT}/bin:${PATH}"

# Build circom prover with CUDA acceleration
RUN cd vendors/circom && CARGO_BAZEL_REPIN=true bazel build --@kroma_network_tachyon//:has_openmp --config maxopt --config cuda //:prover_main

# Build compile tool for witness generator
RUN cd vendors/circom && bazel build --config opt //circomlib/build:compile_witness_generator
17 changes: 17 additions & 0 deletions vendors/circom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ bazel build --@kroma_network_tachyon//:has_openmp --config maxopt --config cuda
bazel build --@kroma_network_tachyon//:has_openmp --config maxopt //:prover_main
```

### With Docker

For the CUDA build, you need to [setup the NVIDIA Container toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html).

```shell
# These commands should be run in the base folder
cd ../..
# Build without CUDA
docker build -f docker/Dockerfile.circom.jammy -t tachyon:cpu --target builder .
docker run -it tachyon:cpu
# Build with CUDA
docker build -f docker/Dockerfile.circom.jammy -t tachyon:cuda --target builder-cuda .
docker run -it --runtime nvidia --gpus all tachyon:cuda
```

NOTE: To use external files for proving or compiling, you need to mount or copy them to the tachyon folder to use it within docker.

## How to run

```shell
Expand Down

0 comments on commit 02c4b7c

Please sign in to comment.