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

chore: trusted setup coordinator scripts #1157

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
Binary file added ceremony/16.ph1
Binary file not shown.
5 changes: 5 additions & 0 deletions ceremony/contribute/outputs/alice_CONTRIBUTION_0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
inclusion_26_1 Current #Contributions := 0
Sampling toxic parameters Delta
Processing DeltaG1 and DeltaG2
Contirbution has been successful!
Contribution Hash := ec5c11ecb949540719aa66d55314f0881e92156d02de019ad88a259f70755bb6
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added ceremony/r1cs/combined_26_1_1.r1cs
Binary file not shown.
Binary file added ceremony/r1cs/combined_26_1_2.r1cs
Binary file not shown.
Binary file added ceremony/r1cs/combined_26_2_1.r1cs
Binary file not shown.
Binary file added ceremony/r1cs/combined_26_2_2.r1cs
Binary file not shown.
Binary file added ceremony/r1cs/combined_26_3_1.r1cs
Binary file not shown.
Binary file added ceremony/r1cs/combined_26_3_2.r1cs
Binary file not shown.
Binary file added ceremony/r1cs/combined_26_4_1.r1cs
Binary file not shown.
Binary file added ceremony/r1cs/combined_26_4_2.r1cs
Binary file not shown.
Binary file added ceremony/r1cs/inclusion_26_1.r1cs
Binary file not shown.
Binary file added ceremony/r1cs/inclusion_26_2.r1cs
Binary file not shown.
Binary file added ceremony/r1cs/inclusion_26_3.r1cs
Binary file not shown.
Binary file added ceremony/r1cs/inclusion_26_4.r1cs
Binary file not shown.
Binary file added ceremony/r1cs/inclusion_26_8.r1cs
Binary file not shown.
Binary file added ceremony/r1cs/non-inclusion_26_1.r1cs
Binary file not shown.
Binary file added ceremony/r1cs/non-inclusion_26_2.r1cs
Binary file not shown.
Binary file added evals
Binary file not shown.
108 changes: 108 additions & 0 deletions scripts/tsc-contribute.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/bin/bash

set -e

# Usage:
# ./scripts/tsc-contribute.sh <contribution_number> "<contributor_name>" "url1" "url2" ...

# 18
if [ $# -lt 1 ]; then
echo "Error: Incorrect number of arguments. Usage: $0 <contribution_number> <contributor_name> <url1> <url2> ..."
exit 1
fi

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
REPO_ROOT="$( cd "$SCRIPT_DIR/.." && pwd )"
cd "$REPO_ROOT"

if [ -d "ceremony/contribute" ]; then
echo "Error: ceremony/contribute directory already exists. Please remove it before running this script."
exit 1
fi

CONTRIBUTION_NUMBER=$1
CONTRIBUTOR_NAME=$2
shift 2

PH2_FILES=(
"inclusion_26_1.ph2"
# "inclusion_26_2.ph2"
# "inclusion_26_3.ph2"
# "inclusion_26_4.ph2"
# "inclusion_26_8.ph2"
# "non-inclusion_26_1.ph2"
# "non-inclusion_26_2.ph2"
# "combined_26_1_1.ph2"
# "combined_26_1_2.ph2"
# "combined_26_2_1.ph2"
# "combined_26_2_2.ph2"
# "combined_26_3_1.ph2"
# "combined_26_3_2.ph2"
# "combined_26_4_1.ph2"
# "combined_26_4_2.ph2"
)

INPUT_DIR="$REPO_ROOT/ceremony/contribute/ph2-files"
OUTPUT_DIR="$REPO_ROOT/ceremony/contribute/outputs"
mkdir -p "$INPUT_DIR" "$OUTPUT_DIR"

echo "Downloading files..."
for i in "${!PH2_FILES[@]}"; do
file="${PH2_FILES[$i]}"
url="$1"
shift
output_file="$INPUT_DIR/${file%.ph2}_${CONTRIBUTOR_NAME}_contribution_${CONTRIBUTION_NUMBER}.ph2"
echo "Downloading $file from $url"
curl -f -S -o "$output_file" "$url"
echo "Successfully downloaded $file"
done

cd "$REPO_ROOT"
if [ ! -d "semaphore-mtb-setup" ]; then
git clone https://github.com/worldcoin/semaphore-mtb-setup
cd semaphore-mtb-setup
go build -v
else
cd semaphore-mtb-setup
fi
cd "$REPO_ROOT"
CONTRIB_FILE="$OUTPUT_DIR/${CONTRIBUTOR_NAME}_CONTRIBUTION_${CONTRIBUTION_NUMBER}.txt"
> "$CONTRIB_FILE"

for ph2_file in "$INPUT_DIR"/*_${CONTRIBUTOR_NAME}_contribution_${CONTRIBUTION_NUMBER}.ph2; do
base_name=$(basename "$ph2_file" "_${CONTRIBUTOR_NAME}_contribution_${CONTRIBUTION_NUMBER}.ph2")
new_contribution=$((CONTRIBUTION_NUMBER + 1))
output_file="${base_name}_${CONTRIBUTOR_NAME}_contribution_${new_contribution}.ph2"

echo "Contributing to $ph2_file"
contribution_hash=$(./semaphore-mtb-setup/semaphore-mtb-setup p2c "$ph2_file" "$OUTPUT_DIR/$output_file")

echo "$base_name $contribution_hash" >> "$CONTRIB_FILE"
echo "Contribution hash for $base_name: $contribution_hash"
done

echo "All contributions completed. Hashes stored in $CONTRIB_FILE"
echo "Uploading new .ph2 files..."
for file in "${PH2_FILES[@]}"; do
url="$1"
shift
ph2_file="$OUTPUT_DIR/${file%.ph2}_${CONTRIBUTOR_NAME}_contribution_$((CONTRIBUTION_NUMBER + 1)).ph2"
echo "Uploading $(basename "$ph2_file")..."
echo "URL: $url"
curl -v -f -S -X PUT -T "$ph2_file" "$url"
if [ $? -ne 0 ]; then
echo "Error uploading $(basename "$ph2_file"). Exiting."
exit 1
fi
done

echo "Uploading contribution file..."
contrib_url="$1"
echo "Contribution URL: $contrib_url"
curl -v -f -S -X PUT -T "$CONTRIB_FILE" "$contrib_url"
if [ $? -ne 0 ]; then
echo "Error uploading contribution file. Exiting."
exit 1
fi

echo "All files uploaded successfully."
95 changes: 95 additions & 0 deletions scripts/tsc-create-r1cs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash

# Ensure we're working from the root directory of the monorepo
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
REPO_ROOT="$( cd "$SCRIPT_DIR/.." && pwd )"
SEMAPHORE_MTB_SETUP="../semaphore-mtb-setup/semaphore-mtb-setup"

cd "$REPO_ROOT"

# Get phase 1 ptau file.
echo "Performing pre-steps..."
cd ..
git clone https://github.com/worldcoin/semaphore-mtb-setup
cd semaphore-mtb-setup && go build -v
wget https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final_16.ptau 16.ptau
mkdir -p "$REPO_ROOT/ceremony"

$SEMAPHORE_MTB_SETUP p1i 16.ptau "$REPO_ROOT/ceremony/16.ph1"

cd "$REPO_ROOT"

# Set the output directory
OUTPUT_DIR="$REPO_ROOT/ceremony/r1cs"

# Delete prior contents if the directory exists
if [ -d "$OUTPUT_DIR" ]; then
rm -rf "$OUTPUT_DIR"/*
fi

# Create the r1cs directory
mkdir -p "$OUTPUT_DIR"

# Function to generate R1CS for a given circuit type and parameters
generate_r1cs() {
local circuit=$1
local inclusion_accounts=$2
local non_inclusion_accounts=$3
local depth=$4
local output_file=$5

./light-prover/light-prover r1cs \
--circuit "$circuit" \
--inclusion-compressed-accounts "$inclusion_accounts" \
--non-inclusion-compressed-accounts "$non_inclusion_accounts" \
--inclusion-tree-depth "$depth" \
--non-inclusion-tree-depth "$depth" \
--output "$OUTPUT_DIR/$output_file"

echo "Generated $output_file"
}

# Generate R1CS for inclusion circuits
for accounts in 1 2 3 4 8; do
generate_r1cs "inclusion" "$accounts" "0" "26" "inclusion_26_${accounts}_contribution_0.r1cs"
done

# Generate R1CS for non-inclusion circuits
for accounts in 1 2; do
generate_r1cs "non-inclusion" "0" "$accounts" "26" "non-inclusion_26_${accounts}_contribution_0.r1cs"
done

# Generate R1CS for combined circuits
for inclusion_accounts in 1 2 3 4; do
for non_inclusion_accounts in 1 2; do
generate_r1cs "combined" "$inclusion_accounts" "$non_inclusion_accounts" "26" "combined_26_${inclusion_accounts}_${non_inclusion_accounts}_contribution_0.r1cs"
done
done

echo "All R1CS files have been generated in $OUTPUT_DIR"

# Run semaphore-mtb-setup for each R1CS file
PH2_OUTPUT_DIR="$REPO_ROOT/ceremony/ph2-files"
PH1_FILE="$REPO_ROOT/ceremony/16.ph1"

# Create the ph2-files directory if it doesn't exist
mkdir -p "$PH2_OUTPUT_DIR"

# Function to process each R1CS file
process_r1cs() {
local r1cs_file=$1
local base_name=$(basename "$r1cs_file" .r1cs)
local ph2_file="$PH2_OUTPUT_DIR/${base_name}.ph2"

$SEMAPHORE_MTB_SETUP p2n "$PH1_FILE" "$r1cs_file" "$ph2_file"
echo "Processed $r1cs_file -> $ph2_file"
}

# Process all R1CS files
for r1cs_file in "$OUTPUT_DIR"/*.r1cs; do
process_r1cs "$r1cs_file"
done

echo "All .ph2 files have been generated in $PH2_OUTPUT_DIR"


66 changes: 66 additions & 0 deletions scripts/tsc-create-urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python3

import sys
import boto3
from botocore.exceptions import ClientError

def create_presigned_url(bucket_name, object_key, expiration, http_method='GET'):
s3_client = boto3.client('s3', region_name='eu-central-1')
try:
return s3_client.generate_presigned_url(
'get_object' if http_method == 'GET' else 'put_object',
Params={'Bucket': bucket_name, 'Key': object_key},
ExpiresIn=expiration,
HttpMethod=http_method
)
except ClientError as e:
print(f"Error creating presigned URL: {e}")
return None

if len(sys.argv) < 4:
print("Usage: python3 tsc-create-urls.py <bucket_name> <current_user> <current_number> [next_user]")
sys.exit(1)

bucket_name = sys.argv[1]
current_user = sys.argv[2]
current_number = int(sys.argv[3])
next_user = sys.argv[4] if len(sys.argv) > 4 else None
next_number = current_number + 1
expiration = 3600

PH2_FILES = [
"inclusion_26_1",
# "inclusion_26_2",
# "inclusion_26_3",
# "inclusion_26_4",
# "inclusion_26_8",
# "non-inclusion_26_1",
# "non-inclusion_26_2",
# "combined_26_1_1",
# "combined_26_1_2",
# "combined_26_2_1",
# "combined_26_2_2",
# "combined_26_3_1",
# "combined_26_3_2",
# "combined_26_4_1",
# "combined_26_4_2",
]

print(f"./scripts/tsc-contribute.sh {current_number} \"{current_user}\"", end=" ")

# Download URLs for current number
for file in PH2_FILES:
download_file = f"{file}_{current_user}_contribution_{current_number}.ph2"
url = create_presigned_url(bucket_name, download_file, expiration)
print(f"\"{url}\"", end=" ")

# Upload URLs for next number
for file in PH2_FILES:
upload_file = f"{file}_{current_user}_contribution_{next_number}.ph2"
url = create_presigned_url(bucket_name, upload_file, expiration, http_method='PUT')
print(f"\"{url}\"", end=" ")

# Add URL for contribution file (assuming this is an upload)
contrib_file = f"{current_user}_CONTRIBUTION_{current_number}.txt"
url = create_presigned_url(bucket_name, contrib_file, expiration, http_method='PUT')
print(f"\"{url}\"")
3 changes: 3 additions & 0 deletions scripts/tsc-create-urls.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
export GO111MODULE=off
go run scripts/tsc-create-urls.go "$@"
1 change: 1 addition & 0 deletions semaphore-mtb-setup
Submodule semaphore-mtb-setup added at 29d5b2
Binary file added srs.lag
Binary file not shown.
Loading