Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tachyon to speed up witness and proofgen #75 #102

Merged
merged 5 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions libs/rapidsnark.Dockerfile

This file was deleted.

28 changes: 28 additions & 0 deletions libs/tachyon.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM ubuntu:22.04

ARG DEBIAN_FRONTEND=noninteractive

# Install required dependencies
RUN apt-get update && \
apt-get install -y curl gnupg git libgmp-dev libomp-dev python3 python3-pip zip


RUN pip install numpy

# Install Bazel
RUN curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg && \
mv bazel.gpg /etc/apt/trusted.gpg.d/ && \
echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list && \
apt-get update && \
apt-get install -y bazel-6.3.0 && \
ln -s /usr/bin/bazel-6.3.0 /usr/local/bin/bazel

# Set Python 3 as the default python
RUN ln -s /usr/bin/python3 /usr/bin/python

# Clone and build Tachyon
RUN git clone --branch v0.3.0 https://github.com/kroma-network/tachyon /tachyon
WORKDIR /tachyon/vendors/circom
RUN CARGO_BAZEL_REPIN=1 bazel sync --only=crate_index && bazel build --@kroma_network_tachyon//:has_openmp -c opt --config linux //:prover_main

ENTRYPOINT ["/tachyon/vendors/circom/bazel-bin/prover_main"]
44 changes: 29 additions & 15 deletions packages/prover/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,52 +1,66 @@
FROM python:3.10
# FROM aayushg0/rapidsnark:latest AS rapidsnark
# FROM whoisgautxm/tachyon:latest AS tachyon
# FROM rust:latest
# FROM node:18


RUN apt-get update && apt-get upgrade -y
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 pkg-config gnupg libssl-dev libgmp-dev libsodium-dev python3 python3-pip zip git awscli gcc nodejs npm build-essential

# Node install
RUN npm install -g n
RUN npm install -g n
RUN n 18
RUN npm install -g yarn snarkjs

# Set Python 3 as the default python
RUN ln -s /usr/bin/python3 /usr/bin/python

RUN pip install numpy

RUN git clone https://github.com/zkemail/email-wallet.git
WORKDIR /email-wallet/packages/prover
RUN pip install -r requirements.txt
RUN cp ./circom_proofgen.sh /root
WORKDIR /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=1F1cw9eTlgJwPcXR4wF8kQrWPMhRsFnIy"
RUN gdown "https://drive.google.com/uc?id=1T1VvuaZhm1pSQoUkjaZptRbjq1XX8aT8"
RUN unzip params.zip
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
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
WORKDIR /root


# Install Bazel
RUN curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg && \
mv bazel.gpg /etc/apt/trusted.gpg.d/ && \
echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list && \
apt-get update && \
apt-get install -y bazel-6.3.0 && \
ln -s /usr/bin/bazel-6.3.0 /usr/local/bin/bazel


# Clone and build Tachyon

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RUN git clone https://github.com/kroma-network/tachyon /tachyon
RUN git clone --branch v0.3.0 https://github.com/kroma-network/tachyon /tachyon

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SoraSuegami I think perhaps you are missing this!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SoraSuegami I think perhaps you are missing this!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much!
I could build the docker image on modal!

RUN git clone https://github.com/kroma-network/tachyon /tachyon
WORKDIR /tachyon/vendors/circom
RUN CARGO_BAZEL_REPIN=1 bazel sync --only=crate_index && bazel build --@kroma_network_tachyon//:has_openmp -c opt --config linux //:prover_main
14 changes: 7 additions & 7 deletions packages/prover/circom_proofgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ SCRIPT_DIR=$(cd $(dirname $0); pwd)
# build_dir="${zk_email_path}/build/${CIRCUIT_NAME}"
input_path="${buildDir}/input_${circuitName}_${nonce}.json"
witness_path="${buildDir}/witness_${circuitName}_${nonce}.wtns"
proof_path="${buildDir}/rapidsnark_proof_${circuitName}_${nonce}.json"
public_path="${buildDir}/rapidsnark_public_${circuitName}_${nonce}.json"
proof_path="${buildDir}/tachyon_proof_${circuitName}_${nonce}.json"
public_path="${buildDir}/tachyon_public_${circuitName}_${nonce}.json"

cd "${SCRIPT_DIR}"
echo "entered zk email path: ${SCRIPT_DIR}"
Expand All @@ -50,14 +50,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"
# TACHYON PROVER
echo "ldd ${SCRIPT_DIR}/tachyon/vendors/circom"
ldd "${SCRIPT_DIR}/tachyon/vendors/circom"
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}/tachyon/vendors/circom/bazel-bin/prover_main ${paramsDir}/${circuitName}.zkey ${witness_path} ${proof_path} ${public_path}"
"${SCRIPT_DIR}/tachyon/vendors/circom/bazel-bin/prover_main" "${paramsDir}/${circuitName}.zkey" "${witness_path}" "${proof_path}" "${public_path}" | tee /dev/stderr
status_prover=$?
echo "✓ Finished rapid proofgen! Status: ${status_prover}"
fi
Expand Down
4 changes: 2 additions & 2 deletions packages/prover/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def load_proof(circuit_name: str, nonce: str) -> dict:
cur_dir = get_cur_dir()
build_dir = os.path.join(cur_dir, "build")
json_file_path = os.path.join(
build_dir, "rapidsnark_proof_" + circuit_name + "_" + nonce + ".json"
build_dir, "tachyon_public_" + circuit_name + "_" + nonce + ".json"
)
with open(json_file_path, "r") as json_file:
return json.loads(json_file.read())
Expand All @@ -76,7 +76,7 @@ def load_pub_signals(circuit_name: str, nonce: str) -> dict:
cur_dir = get_cur_dir()
build_dir = os.path.join(cur_dir, "build")
json_file_path = os.path.join(
build_dir, "rapidsnark_public_" + circuit_name + "_" + nonce + ".json"
build_dir, "tachyon_public_" + circuit_name + "_" + nonce + ".json"
)
with open(json_file_path, "r") as json_file:
return json.loads(json_file.read())
Expand Down
2 changes: 1 addition & 1 deletion packages/prover/modal_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)


app = modal.App("email-wallet-relayer-v1.1.2")
app = modal.App("email-wallet-relayer-v1.2")

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

Expand Down
Loading