From 02c4b7caa48e19166e0a2998dcd5d48ad99a5178 Mon Sep 17 00:00:00 2001 From: batzor <32958247+batzor@users.noreply.github.com> Date: Thu, 24 Oct 2024 14:50:28 +0900 Subject: [PATCH] feat(circom): add Dockerfile for circom --- docker/Dockerfile.circom.jammy | 45 ++++++++++++++++++++++++++++++++++ vendors/circom/README.md | 17 +++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 docker/Dockerfile.circom.jammy diff --git a/docker/Dockerfile.circom.jammy b/docker/Dockerfile.circom.jammy new file mode 100644 index 000000000..eb2f88698 --- /dev/null +++ b/docker/Dockerfile.circom.jammy @@ -0,0 +1,45 @@ +FROM zktachyon/base:jammy-latest AS builder +LABEL maintainer="The Tachyon Authors " + +# 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 diff --git a/vendors/circom/README.md b/vendors/circom/README.md index eb8fdc6ba..fc8fea8b3 100644 --- a/vendors/circom/README.md +++ b/vendors/circom/README.md @@ -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