Skip to content

Commit

Permalink
feat: use GPU for proving
Browse files Browse the repository at this point in the history
  • Loading branch information
Bisht13 committed Sep 24, 2024
1 parent 1bb0f61 commit 1ed3203
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Relayer.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use the base image
FROM us-central1-docker.pkg.dev/zkairdrop/ether-email-auth/relayer-base:v1
FROM bisht13/relayer-base

# Copy the project files
COPY packages/relayer /relayer/packages/relayer
Expand Down
18 changes: 8 additions & 10 deletions libs/rapidsnark.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@

FROM ubuntu:20.04
FROM ubuntu:22.04

ARG DEBIAN_FRONTEND=noninteractive

# Install Node.js, Yarn and required dependencies
RUN apt-get update \
&& apt-get install -y curl git gnupg build-essential cmake libgmp-dev libsodium-dev nasm \
&& apt-get install -y curl git gnupg build-essential cmake libgmp-dev libsodium-dev nasm curl m4 \
&& curl --silent --location https://deb.nodesource.com/setup_12.x | bash - \
&& apt-get install -y nodejs

RUN git clone https://github.com/iden3/rapidsnark.git /rapidsnark
RUN git clone https://github.com/Orbiter-Finance/rapidsnark.git /rapidsnark
WORKDIR /rapidsnark
RUN npm install
RUN git submodule init
RUN git submodule update
RUN npx task createFieldSources
RUN npx task buildPistache
RUN apt-get install -y
RUN npx task buildProver
./build_gmp.sh host
mkdir build_prover && cd build_prover
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package
make -j$(nproc) && make install

ENTRYPOINT ["/rapidsnark/build/prover"]
ENTRYPOINT ["/rapidsnark/package/build/prover_cuda"]
30 changes: 10 additions & 20 deletions packages/prover/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,37 @@ FROM python:3.10
RUN apt-get update && apt-get upgrade -y
# Update the package list and install necessary dependencies
RUN apt-get update && \
apt install -y cmake build-essential pkg-config libssl-dev libgmp-dev libsodium-dev nasm git awscli gcc nodejs npm
apt install -y cmake build-essential pkg-config libssl-dev libgmp-dev libsodium-dev nasm git awscli gcc nodejs npm curl m4

# Node install
RUN npm install -g n
RUN n 18
RUN n 22
RUN npm install -g yarn snarkjs
RUN git clone -b feat/body-parsing-circuit https://github.com/zkemail/ether-email-auth.git
RUN git clone -b feat/body-parsing-with-audit-fix https://github.com/zkemail/ether-email-auth.git
WORKDIR /ether-email-auth/packages/prover
RUN pip install -r requirements.txt
RUN cp ./circom_proofgen.sh /root
RUN cp ./email_auth_with_body_parsing_with_qp_encoding /root
WORKDIR /root
RUN ls /root
# RUN mkdir params
# RUN cp /email-wallet/packages/prover/params/account_creation.wasm /root/params
# RUN cp /email-wallet/packages/prover/params/account_init.wasm /root/params
# RUN cp /email-wallet/packages/prover/params/account_transport.wasm /root/params
# RUN cp /email-wallet/packages/prover/params/claim.wasm /root/params
# RUN cp /email-wallet/packages/prover/params/email_sender.wasm /root/params
RUN mkdir params
WORKDIR /root/params
RUN gdown "https://drive.google.com/uc?id=1XDPFIL5YK8JzLGoTjmHLXO9zMDjSQcJH"
RUN unzip params.zip
RUN mv params/* /root/params
WORKDIR /root
RUN ls params
# RUN mv build params
# RUN curl https://email-wallet-trusted-setup-ceremony-pse-p0tion-production.s3.eu-central-1.amazonaws.com/circuits/emailwallet-account-creation/contributions/emailwallet-account-creation_00019.zkey --output ./params/account_creation.zkey
# RUN curl https://email-wallet-trusted-setup-ceremony-pse-p0tion-production.s3.eu-central-1.amazonaws.com/circuits/emailwallet-account-init/contributions/emailwallet-account-init_00007.zkey --output ./params/account_init.zkey
# RUN curl https://email-wallet-trusted-setup-ceremony-pse-p0tion-production.s3.eu-central-1.amazonaws.com/circuits/emailwallet-account-transport/contributions/emailwallet-account-transport_00005.zkey --output ./params/account_transport.zkey
# RUN curl https://email-wallet-trusted-setup-ceremony-pse-p0tion-production.s3.eu-central-1.amazonaws.com/circuits/emailwallet-claim/contributions/emailwallet-claim_00006.zkey --output ./params/claim.zkey
# RUN curl https://email-wallet-trusted-setup-ceremony-pse-p0tion-production.s3.eu-central-1.amazonaws.com/circuits/emailwallet-email-sender/contributions/emailwallet-email-sender_00006.zkey --output ./params/email_sender.zkey
RUN chmod +x circom_proofgen.sh
RUN mkdir build

RUN git clone https://github.com/iden3/rapidsnark-old.git rapidsnark
RUN git clone https://github.com/Orbiter-Finance/rapidsnark.git rapidsnark
WORKDIR /root/rapidsnark
RUN yarn
RUN git submodule init
RUN git submodule update
RUN npx task createFieldSources
RUN npx task buildPistache
RUN npx task buildProver
RUN chmod +x build/prover
RUN ./build_gmp.sh host
RUN mkdir build_prover && cd build_prover
RUN cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package
RUN make -j$(nproc) && make install
RUN chmod +x package/bin/prover_cuda
WORKDIR /root
15 changes: 7 additions & 8 deletions packages/prover/circom_proofgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ public_path="${buildDir}/rapidsnark_public_${circuitName}_${nonce}.json"
cd "${SCRIPT_DIR}"
echo "entered zk email path: ${SCRIPT_DIR}"

echo "NODE_OPTIONS='--max-old-space-size=644000' snarkjs wc "${paramsDir}/${circuitName}.wasm" "${input_path}" "${witness_path}""
NODE_OPTIONS='--max-old-space-size=644000' snarkjs wc "${paramsDir}/${circuitName}.wasm" "${input_path}" "${witness_path}" | tee /dev/stderr
./email_auth_with_body_parsing_with_qp_encoding "${input_path}" "${witness_path}" | tee /dev/stderr
status_jswitgen=$?
echo "✓ Finished witness generation with js! ${status_jswitgen}"
echo "✓ Finished witness generation with cpp! ${status_jswitgen}"

# TODO: Get C-based witness gen to work
# echo "/${build_dir}/${CIRCUIT_NAME}_cpp/${CIRCUIT_NAME} ${input_wallet_path} ${witness_path}"
Expand All @@ -43,14 +42,14 @@ if [ $isLocal = 1 ]; then
status_prover=$?
echo "✓ Finished slow proofgen! Status: ${status_prover}"
else
# RAPIDSNARK PROVER (10x FASTER)
echo "ldd ${SCRIPT_DIR}/rapidsnark/build/prover"
ldd "${SCRIPT_DIR}/rapidsnark/build/prover"
# RAPIDSNARK PROVER GPU
echo "ldd ${SCRIPT_DIR}/rapidsnark/package/bin/prover_cuda"
ldd "${SCRIPT_DIR}/rapidsnark/package/bin/prover_cuda"
status_lld=$?
echo "✓ lld prover dependencies present! ${status_lld}"

echo "${SCRIPT_DIR}/rapidsnark/build/prover ${paramsDir}/${circuitName}.zkey ${witness_path} ${proof_path} ${public_path}"
"${SCRIPT_DIR}/rapidsnark/build/prover" "${paramsDir}/${circuitName}.zkey" "${witness_path}" "${proof_path}" "${public_path}" | tee /dev/stderr
echo "${SCRIPT_DIR}/rapidsnark/package/bin/prover_cuda ${paramsDir}/${circuitName}.zkey ${witness_path} ${proof_path} ${public_path}"
"${SCRIPT_DIR}/rapidsnark/package/bin/prover_cuda" "${paramsDir}/${circuitName}.zkey" "${witness_path}" "${proof_path}" "${public_path}" | tee /dev/stderr
status_prover=$?
echo "✓ Finished rapid proofgen! Status: ${status_prover}"
fi
Expand Down
Binary file not shown.
5 changes: 0 additions & 5 deletions packages/prover/local_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,4 @@ pip install -r requirements.txt
mkdir build && cd build
gdown "https://drive.google.com/uc?id=1XDPFIL5YK8JzLGoTjmHLXO9zMDjSQcJH"
unzip params.zip
# curl https://email-wallet-trusted-setup-ceremony-pse-p0tion-production.s3.eu-central-1.amazonaws.com/circuits/emailwallet-account-creation/contributions/emailwallet-account-creation_00019.zkey --output /root/params/account_creation.zkey
# curl https://email-wallet-trusted-setup-ceremony-pse-p0tion-production.s3.eu-central-1.amazonaws.com/circuits/emailwallet-account-init/contributions/emailwallet-account-init_00007.zkey --output /root/params/account_init.zkey
# curl https://email-wallet-trusted-setup-ceremony-pse-p0tion-production.s3.eu-central-1.amazonaws.com/circuits/emailwallet-account-transport/contributions/emailwallet-account-transport_00005.zkey --output /root/params/account_transport.zkey
# curl https://email-wallet-trusted-setup-ceremony-pse-p0tion-production.s3.eu-central-1.amazonaws.com/circuits/emailwallet-claim/contributions/emailwallet-claim_00006.zkey --output /root/params/claim.zkey
# curl https://email-wallet-trusted-setup-ceremony-pse-p0tion-production.s3.eu-central-1.amazonaws.com/circuits/emailwallet-email-sender/contributions/emailwallet-email-sender_00006.zkey --output /root/params/email_sender.zkey
chmod +x circom_proofgen.sh
5 changes: 3 additions & 2 deletions packages/prover/modal_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from google.cloud.logging_v2.handlers import setup_logging
from google.oauth2 import service_account

app = modal.App("email-auth-prover-v1.3.0")
app = modal.App("email-auth-prover-v1.4.0")

image = modal.Image.from_dockerfile("Dockerfile")

Expand All @@ -15,7 +15,8 @@
mounts=[
modal.Mount.from_local_python_packages("core"),
],
cpu=14,
cpu=16,
gpu="any",
secrets=[modal.Secret.from_name("gc-ether-email-auth-prover")],
)
@modal.wsgi_app()
Expand Down

0 comments on commit 1ed3203

Please sign in to comment.