Skip to content

Commit

Permalink
Merge pull request #26 from zk-email-verify/solidity
Browse files Browse the repository at this point in the history
[WIP] Twitter verification in Solidity
  • Loading branch information
Divide-By-0 authored Jan 29, 2023
2 parents 7a6cf46 + d9213a5 commit 4967dc9
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 910 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ generate_input_log.txt
*email_proof.json
*aayush_constants.ts
*.debug
*.env
78 changes: 78 additions & 0 deletions dizkus-scripts/3_gen_both_zkeys.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash
# Tries to generate a chunked and non-chunked zkey
# You need to set entropy.env for this to work

CIRCUIT_NAME=email
BUILD_DIR="../build/$CIRCUIT_NAME"
R1CS_FILE="$BUILD_DIR/$CIRCUIT_NAME.r1cs"
PARTIAL_ZKEYS="$BUILD_DIR"/partial_zkeys
PHASE1=../circuits/powersOfTau28_hez_final_22.ptau
source entropy.env

if [ ! -d "$BUILD_DIR"/partial_zkeys ]; then
echo "No partial_zkeys directory found. Creating partial_zkeys directory..."
mkdir -p "$BUILD_DIR"/partial_zkeys
fi

# First, chunked snarkjs
yarn remove snarkjs
yarn add snarkjs@git+https://github.com/vb7401/snarkjs.git#24981febe8826b6ab76ae4d76cf7f9142919d2b8

echo "****GENERATING ZKEY 0****"
start=$(date +%s)
set -x
NODE_OPTIONS='--max-old-space-size=56000' node ../node_modules/.bin/snarkjs groth16 setup "$R1CS_FILE" "$PHASE1" "$PARTIAL_ZKEYS"/"$CIRCUIT_NAME"_0.zkey -e $ENTROPY1
{ set +x; } 2>/dev/null
end=$(date +%s)
echo "DONE ($((end - start))s)"
echo

echo "****GENERATING ZKEY 1****"
start=$(date +%s)
set -x
NODE_OPTIONS='--max-old-space-size=56000' node ../node_modules/.bin/snarkjs zkey contribute "$PARTIAL_ZKEYS"/"$CIRCUIT_NAME"_0.zkey "$PARTIAL_ZKEYS"/"$CIRCUIT_NAME"_1.zkey --name="1st Contributor Name" -v $ENTROPY2
{ set +x; } 2>/dev/null
end=$(date +%s)
echo "DONE ($((end - start))s)"
echo

echo "****GENERATING FINAL ZKEY****"
start=$(date +%s)
set -x
# hashlib.sha256(b"sampritiaayush").hexdigest().upper()
NODE_OPTIONS='--max-old-space-size=56000' node ../node_modules/.bin/snarkjs zkey beacon "$PARTIAL_ZKEYS"/"$CIRCUIT_NAME"_1.zkey "$BUILD_DIR"/"$CIRCUIT_NAME".zkey AFAE5390CE7790A5EFA03DD74189A4C56DDA1AB8D3D322142C4AE3A14858D6E0 10 -n="Final Beacon phase2"
{ set +x; } 2>/dev/null
end=$(date +%s)
echo "DONE ($((end - start))s)"
echo

# Then, nonchunked snarkjs
yarn remove snarkjs
yarn add snarkjs@latest

echo "****GENERATING ZKEY NONCHUNKED 0****"
start=$(date +%s)
set -x
NODE_OPTIONS='--max-old-space-size=56000' node ../node_modules/.bin/snarkjs groth16 setup "$R1CS_FILE" "$PHASE1" "$PARTIAL_ZKEYS"/"$CIRCUIT_NAME"_0.zkey -e $ENTROPY1
{ set +x; } 2>/dev/null
end=$(date +%s)
echo "DONE ($((end - start))s)"
echo

echo "****GENERATING ZKEY NONCHUNKED 1****"
start=$(date +%s)
set -x
NODE_OPTIONS='--max-old-space-size=56000' node ../node_modules/.bin/snarkjs zkey contribute "$PARTIAL_ZKEYS"/"$CIRCUIT_NAME"_0.zkey "$PARTIAL_ZKEYS"/"$CIRCUIT_NAME"_1.zkey --name="1st Contributor Name" -v -e $ENTROPY2
{ set +x; } 2>/dev/null
end=$(date +%s)
echo "DONE ($((end - start))s)"
echo

echo "****GENERATING ZKEY NONCHUNKED FINAL****"
start=$(date +%s)
set -x
NODE_OPTIONS='--max-old-space-size=56000' node ../node_modules/.bin/snarkjs zkey beacon "$PARTIAL_ZKEYS"/"$CIRCUIT_NAME"_1.zkey "$BUILD_DIR"/"$CIRCUIT_NAME"_nonchunked.zkey AFAE5390CE7790A5EFA03DD74189A4C56DDA1AB8D3D322142C4AE3A14858D6E0 10 -n="Final Beacon phase2"
{ set +x; } 2>/dev/null
end=$(date +%s)
echo "DONE ($((end - start))s)"
echo
2 changes: 2 additions & 0 deletions dizkus-scripts/entropy.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ENTROPY1=
ENTROPY2=
10 changes: 5 additions & 5 deletions dizkus-scripts/upload_to_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

# Set the name of the remote directory and the AWS bucket
source = '~/Documents/projects/zk-email-verify'
source = '~/zk-email-verify-old'
zkey_dir = source + '/build/email/'
wasm_dir = source + '/build/email/email_js/'
source = '.'
zkey_dir = source + '/chunked_build/email/'
wasm_dir = source + '/chunked_build/email/email_js/'
bucket_name = 'zkemail-zkey-chunks' # us-east-1


Expand All @@ -19,15 +19,15 @@ def upload_to_s3(filename, dir=""):
print("Starting upload...")
s3.upload_fileobj(file, bucket_name, filename, ExtraArgs={
'ACL': 'public-read', 'ContentType': 'binary/octet-stream'})
print("Done uploading!")
print("Done uploading ", filename, "!")


# Loop through the files in the remote directory
for dir in [zkey_dir, wasm_dir]:
for file in os.listdir(dir):
# Check if the file matches the pattern
if file.startswith('email.zkey'):
# upload_to_s3(file, dir) # Uncompressed file
upload_to_s3(file, dir) # Uncompressed file

# Create a zip file for the file
tar_file_name = file + '.tar.gz'
Expand Down
Loading

0 comments on commit 4967dc9

Please sign in to comment.