From 18641b77930d4c3c4e0c35f6933e667f59bf7c29 Mon Sep 17 00:00:00 2001 From: Aditya Bisht Date: Sun, 13 Oct 2024 06:00:49 +0000 Subject: [PATCH] chore: update prover --- .gitignore | 1 + packages/prover/Dockerfile | 66 ++++++++++++++++++------------ packages/prover/circom_proofgen.sh | 34 ++++----------- packages/prover/modal_server.py | 2 +- 4 files changed, 49 insertions(+), 54 deletions(-) diff --git a/.gitignore b/.gitignore index 51f54cd..c4d1745 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ # dist +__pycache__ # dependencies /node_modules diff --git a/packages/prover/Dockerfile b/packages/prover/Dockerfile index 9268ba8..ea48d61 100644 --- a/packages/prover/Dockerfile +++ b/packages/prover/Dockerfile @@ -1,53 +1,67 @@ -FROM python:3.10 - +FROM ubuntu:22.04 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 + DEBIAN_FRONTEND=noninteractive apt install -y --no-install-recommends \ + cmake \ + build-essential \ + pkg-config \ + libssl-dev \ + libgmp-dev \ + libffi-dev \ + libsodium-dev \ + nasm \ + git \ + awscli \ + gcc \ + nodejs \ + npm \ + curl \ + m4 \ + python3 \ + python3-pip \ + python3-dev \ + wget \ + software-properties-common \ + unzip \ + && rm -rf /var/lib/apt/lists/* + +# Set Python 3 as the default python version +RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1 \ + && update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1 # Node install RUN npm install -g n -RUN n 18 +RUN n 22 RUN npm install -g yarn snarkjs -RUN git clone -b feat/prover https://github.com/zkemail/zk-jwt.git +RUN git clone -b feat/refactor https://github.com/zkemail/zk-jwt.git WORKDIR /zk-jwt/packages/prover RUN pip install -r requirements.txt RUN cp ./circom_proofgen.sh /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=1vpXh7w2YRzYK1rNdoKAI4Zu857MFml_R" -# RUN unzip upload-file.zip -# RUN mv upload-file/* /root/params RUN curl https://storage.googleapis.com/zk-jwt-params/jwt-verifier.zkey --output ./jwt-verifier.zkey -RUN curl https://storage.googleapis.com/zk-jwt-params/jwt-verifier_js/jwt-verifier.wasm --output ./jwt-verifier.wasm +RUN curl https://storage.googleapis.com/zk-jwt-params/jwt-verifier_js/jwt-verifier --output ./jwt-verifier 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/iden3/rapidsnark 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 +WORKDIR /root/rapidsnark/build_prover +RUN cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package +RUN make -j$(nproc) && make install +RUN chmod +x ../package/bin/prover WORKDIR /root \ No newline at end of file diff --git a/packages/prover/circom_proofgen.sh b/packages/prover/circom_proofgen.sh index 738f2e2..6399eca 100755 --- a/packages/prover/circom_proofgen.sh +++ b/packages/prover/circom_proofgen.sh @@ -21,21 +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 +${paramsDir}/${circuitName} "${input_path}" "${witness_path}" | tee /dev/stderr status_jswitgen=$? -echo "✓ Finished witness generation with js! ${status_jswitgen}" - -# TODO: Get C-based witness gen to work -# echo "/${build_dir}/${CIRCUIT_NAME}_cpp/${CIRCUIT_NAME} ${input_wallet_path} ${witness_path}" -# "/${build_dir}/${CIRCUIT_NAME}_cpp/${CIRCUIT_NAME}" "${input_wallet_path}" "${witness_path}" -# status_c_wit=$? - -# echo "Finished C witness gen! Status: ${status_c_wit}" -# if [ $status_c_wit -ne 0 ]; then -# echo "C based witness gen failed with status (might be on machine specs diff than compilation): ${status_c_wit}" -# exit 1 -# fi +echo "✓ Finished witness generation with cpp! ${status_jswitgen}" if [ $isLocal = 1 ]; then # DEFAULT SNARKJS PROVER (SLOW) @@ -43,24 +31,16 @@ 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" + ldd "${SCRIPT_DIR}/rapidsnark/package/bin/prover" 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 ${paramsDir}/${circuitName}.zkey ${witness_path} ${proof_path} ${public_path}" + "${SCRIPT_DIR}/rapidsnark/package/bin/prover" "${paramsDir}/${circuitName}.zkey" "${witness_path}" "${proof_path}" "${public_path}" | tee /dev/stderr status_prover=$? echo "✓ Finished rapid proofgen! Status: ${status_prover}" fi - - -# TODO: Upgrade debug -> release and edit dockerfile to use release -# echo "${HOME}/relayer/target/release/relayer chain false ${prover_output_path} ${nonce}" -# "${HOME}/relayer/target/release/relayer" chain false "${prover_output_path}" "${nonce}" 2>&1 | tee /dev/stderr -# status_chain=$? -# echo "✓ Finished send to chain! Status: ${status_chain}" - exit 0 \ No newline at end of file diff --git a/packages/prover/modal_server.py b/packages/prover/modal_server.py index 08fa296..164c13c 100644 --- a/packages/prover/modal_server.py +++ b/packages/prover/modal_server.py @@ -5,7 +5,7 @@ from google.cloud.logging_v2.handlers import setup_logging from google.oauth2 import service_account -app = modal.App("jwt-prover-v0.1.0") +app = modal.App("jwt-prover-v0.1.4") image = modal.Image.from_dockerfile("Dockerfile")