Skip to content

Commit

Permalink
last scripts changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmenendez committed Nov 14, 2023
1 parent 838636d commit 9b9853c
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/create-ceremony.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ on:
create
jobs:
compile-and-prepare:
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'ceremony/') }}
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/finish-ceremony.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
types: [ closed ]
jobs:
finish-ceremony:
if: ${{ github.event.pull_request.merged == false && github.actor == github.event.pull_request.user.login && contains(github.event.pull_request.labels.*.name, 'on-going-ceremony') }}
if: ${{ github.event.pull_request.merged == false && github.actor == github.event.pull_request.user.login && contains(github.event.pull_request.labels.*.name, 'on-going-ceremony') && startsWith(github.ref, 'ceremony/') }}
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
Expand All @@ -23,4 +23,4 @@ jobs:
with:
commit_message: Finish '${{ github.event.pull_request.head.ref }}' ceremony
commit_options: '--no-verify'
commit_user_name: Voceremony Bot
commit_user_name: ${{ github.actor }}
16 changes: 16 additions & 0 deletions .github/workflows/verify-contribution.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Create ceremony
on: push
jobs:
compile-and-prepare:
if: ${{ startsWith(github.ref, 'ceremony/') }}
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
lfs: true
ref: ${{ github.ref }}
- name: Checkout LFS objects
run: git lfs checkout
- name: Run toolkit
run: make verify-locally
30 changes: 8 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,13 @@ clean-creation:
$(info Cleaning up...)
@docker rmi zk-voceremony-creator-image -f

pull-to-contribute:
$(info Pulling latest changes...)
@git fetch origin $(CEREMONY_BRANCH)
@git checkout $(CEREMONY_BRANCH)
@git pull origin $(CEREMONY_BRANCH)
@git lfs pull

launch-contribution:
$(info Starting docker container...)
@docker build -q -t zk-voceremony-contributor-image -f ./dockerfiles/contribute-ceremony.dockerfile .
@docker run --rm --name zk-voceremony-contributor -qit -v ./:/app --env-file ./ceremony.env zk-voceremony-contributor-image

push-contribution:
$(info Pushing changes...)
@git add $(CONTRIBUTIONS_PATH)/CONTRIBUTIONS.md ./$(CONTRIBUTIONS_PATH)/*.zkey
@git commit -m "New contribution"
@git push origin $(CEREMONY_BRANCH)
verify-last-contribution:
@docker build -q -t zk-voceremony-verifier-image -f ./dockerfiles/verify-contribution.dockerfile .
@docker run --rm --name zk-voceremony-verifier -qt --env-file ./ceremony.env zk-voceremony-verifier-image

clean-contribution:
clean-last-verify:
$(info Cleaning up...)
@docker rmi zk-voceremony-contributor-image -f
@docker rmi zk-voceremony-verifier-image -f

launch-finish-ceremony:
$(info Starting docker container...)
Expand All @@ -96,8 +82,8 @@ create-locally: global-checks on-going-ceremony-check launch-creation clean-crea
finish: global-checks on-going-ceremony-check launch-finish-ceremony clean-finish-ceremony push-finish-ceremony
$(info Done!)

finish-locally: global-checks on-going-ceremony-check launch-finish-ceremony clean-finish-ceremony
verify-locally: global-checks on-going-ceremony-check verify-last-contribution clean-last-verify
$(info Done!)

contribute: global-checks on-going-ceremony-check check-contribute-dependencies pull-to-contribute launch-contribution push-contribution clean-contribution
$(info Done! Thanks for contributing! You can remove this repo.)
finish-locally: global-checks on-going-ceremony-check launch-finish-ceremony clean-finish-ceremony
$(info Done!)
10 changes: 10 additions & 0 deletions dockerfiles/verify-contribution.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM node

WORKDIR /app

COPY . /app

RUN npm config set update-notifier false && \
npm install -g snarkjs

CMD [ "bash", "/app/scripts/verify-contribution.sh" ]
1 change: 0 additions & 1 deletion scripts/contribute-ceremony.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ prompt_env_inputs() {
if [ -n "$REPO_URL" ]; then
GITHUB_REPO_URL=$REPO_URL
fi

# get the access token
gh auth login -p https -h github.com -w
# clone the ceremony branch
Expand Down
2 changes: 2 additions & 0 deletions scripts/create-ceremony.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ check_create_env() {

compile_circuit() {
log "compile the target citcuit to get the r1cs file"
# include the npm global modules in the node_modules folder support circom
# imports from root
ln -s "$(npm root -g)" /node_modules
# compilling the circuit
$CIRCOM $CIRCUIT_PATH --r1cs --wasm -o $CONTRIBUTIONS_PATH
Expand Down
8 changes: 4 additions & 4 deletions scripts/create-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ CEREMONY_BRANCH=ceremony/$ceremony_branch
CONTRIBUTIONS_PATH=$contributions_path
OUTPUT_PATH=$output_path" > ceremony.env

git checkout -b ceremony/$ceremony_branch
git add -f ceremony.env $input_folder/$circuit_file $input_folder/$ptau_file
git commit -m "Initialize ceremony"
git push origin $ceremony_branch
# git checkout -b ceremony/$ceremony_branch
# git add -f ceremony.env $input_folder/$circuit_file $input_folder/$ptau_file
# git commit -m "Initialize ceremony"
# git push origin $ceremony_branch
8 changes: 8 additions & 0 deletions scripts/finish-ceremony.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ check_finish_env() {
}

finish_and_verify() {
if [ "$(get_file_hash "$LAST_CONTRIBUTION_FILE")" == "<check CONTRIBUTIONS.md file>" ]; then
error "no contributions"
exit 1
fi
if [ "$(get_file_hash "$LAST_CONTRIBUTION_FILE")" != "$LAST_CONTRIBUTION_HASH" ]; then
error "the last contribution file has been modified, please check the CONTRIBUTIONS.md file"
exit 1
fi
$SNARKJS zkey beacon $LAST_CONTRIBUTION_FILE $OUTPUT_PATH/${CIRCUIT_FILENAME}_proving_key.zkey 0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f 10 -n="Final Beacon phase2"
$SNARKJS zkey verify $CONTRIBUTIONS_PATH/$CIRCUIT_FILENAME.r1cs $INPUT_PTAU_PATH $OUTPUT_PATH/${CIRCUIT_FILENAME}_proving_key.zkey
$SNARKJS zkey export verificationkey $OUTPUT_PATH/${CIRCUIT_FILENAME}_proving_key.zkey $OUTPUT_PATH/${CIRCUIT_FILENAME}_verification_key.json
Expand Down
39 changes: 39 additions & 0 deletions scripts/verify-contribution.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

. scripts/tools.sh

check_last_contribution_env() {
# get the last contribution zkey file from the contributions file
if [ ! -f "$CONTRIBUTIONS_FILE" ]; then
error "contribution file does not exists, is the ceremony initialized?"
exit 1
else
LAST_CONTRIBUTION_FILE=$(get_last_contribution_file_path)
LAST_CONTRIBUTION_HASH=$(get_last_contribution_hash)
fi

mkdir -p $OUTPUT_PATH
}

verify() {
if [ "$(get_file_hash "$LAST_CONTRIBUTION_FILE")" == "<check CONTRIBUTIONS.md file>" ]; then
error "no contributions"
exit 1
fi
if [ "$(get_file_hash "$LAST_CONTRIBUTION_FILE")" != "$LAST_CONTRIBUTION_HASH" ]; then
error "the last contribution file has been modified, please check the CONTRIBUTIONS.md file"
exit 1
fi
$SNARKJS zkey verify $CONTRIBUTIONS_PATH/$CIRCUIT_FILENAME.r1cs $INPUT_PTAU_PATH $LAST_CONTRIBUTION_FILE
# prune temporally files
rm -rf $OUTPUT_PATH
}

verify_last_contribution() {
# check the environment
check_last_contribution_env || error "error checking the environment"
# verify the result of last contribution
verify || error "verifying the last contribution"
}

verify_last_contribution

0 comments on commit 9b9853c

Please sign in to comment.