Skip to content

Commit

Permalink
ci: Fix CI by downloading artifacts (#23)
Browse files Browse the repository at this point in the history
* ci: Fix CI by downloading artifacts

Use a separate prepare-ci.sh script to download artifacts,
as opposed to compiling and running trusted setup every time

* ci: Add back compile step

Once zkey is integrated can remove this again
  • Loading branch information
oskarth authored Oct 28, 2023
1 parent 170d007 commit a92ea40
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
cd circom
cargo build --release
cargo install --path circom
- name: Prepare
run: ./scripts/prepare.sh
- name: Prepare CI
run: ./scripts/prepare_ci.sh
- name: Build
run: ./scripts/build_ios.sh simulator debug
- name: Run core tests
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ To update bindings, run `./script/update_bindings.sh simulator|device debug|rele

## Acknowledgements

This work is sponsored by a joint grant from [PSE](https://pse.dev/) and [0xPARC](https://0xparc.org/).
This work is sponsored by a joint grant from [PSE](https://pse.dev/) and [0xPARC](https://0xparc.org/).
140 changes: 140 additions & 0 deletions scripts/prepare_ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#!/bin/bash

# Deal with errors
set -euo pipefail

# Color definitions
DEFAULT='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
GREY='\033[0;90m'

# Coloring the -x output (commands)
# DEBUG_COLOR="${DEFAULT}"
# trap 'echo -e ${DEBUG_COLOR}${BASH_COMMAND}${DEFAULT}' DEBUG

# Function to handle exit
handle_exit() {
# $? is a special variable that holds the exit code of the last command executed
if [ $? -ne 0 ]; then
echo -e "\n${RED}Script did not finish successfully!${DEFAULT}"
fi
}

# Set the trap
trap handle_exit EXIT

print_action() {
printf "\n${GREEN}$1${DEFAULT}\n"
}

print_warning() {
printf "\n${YELLOW}$1${DEFAULT}\n"
}

# Assert we're in the project root
if [[ ! -d "mopro-ffi" || ! -d "mopro-core" || ! -d "mopro-ios" ]]; then
echo -e "${RED}Error: This script must be run from the project root directory that contains mopro-ffi, mopro-core, and mopro-ios folders.${DEFAULT}"
exit 1
fi

PROJECT_DIR=$(pwd)
CIRCOM_DIR="${PROJECT_DIR}/mopro-core/examples/circom"

compile_circuit() {
local circuit_dir=$1
local circuit_file=$2
local target_file="$circuit_dir/target/$(basename $circuit_file .circom).r1cs"

print_action "[core/circom] Compiling $circuit_file example circuit..."
if [ ! -f "$target_file" ]; then
./scripts/compile.sh $circuit_dir $circuit_file
else
echo "File $target_file already exists, skipping compilation."
fi
}

npm_install() {
local circuit_dir=$1

if [[ ! -d "$circuit_dir/node_modules" ]]; then
echo "Installing npm dependencies for $circuit_dir..."
(cd $circuit_dir && npm install)
fi
}

# Check for target support
check_target_support() {
rustup target list | grep installed | grep -q "$1"
}

download_files() {
local dir=$1
local circuit=$2
local target_dir="${CIRCOM_DIR}/${dir}/target"
local js_target_dir="${target_dir}/${circuit}_js"

# Create directories if they don't exist
mkdir -p "$target_dir" "$js_target_dir"

# Download files to the specified directories
wget -P "$target_dir" "https://zkstuff.ams3.cdn.digitaloceanspaces.com/mopro/circom-examples-artifacts/${dir}/${circuit}_final.zkey"
wget -P "$js_target_dir" "https://zkstuff.ams3.cdn.digitaloceanspaces.com/mopro/circom-examples-artifacts/${dir}/${circuit}.wasm"
}

# TODO: Comment out compile_circuit stuff again once zkey is integrated and we don't need r1cs file anymore

# NOTE: On CI instead of compiling circuits and running trusted setup
# We just download test artifacts and use these
# We thus skip all of the below steps that are run locally in `prepare.sh`
print_action "[core/circom] Downloading artifacts for example circuits..."

# Build Circom circuits in mopro-core and run trusted setup
print_action "[core/circom] Compiling example circuits..."
cd $CIRCOM_DIR

# Compile multiplier2
compile_circuit multiplier2 multiplier2.circom

# Setup and compile keccak256
npm_install keccak256
compile_circuit keccak256 keccak256_256_test.circom

# # Run trusted setup for multiplier2
# print_action "[core/circom] Running trusted setup for multiplier2..."
# ./scripts/trusted_setup.sh multiplier2 08 multiplier2
#
# # Run trusted setup for keccak256
# print_action "[core/circom] Running trusted setup for keccak256..."
# ./scripts/trusted_setup.sh keccak256 18 keccak256_256_test

print_action "[core/circom] Downloading artifacts for multiplier2..."
download_files "multiplier2" "multiplier2"

print_action "[core/circom] Downloading artifacts for keccak256..."
download_files "keccak256" "keccak256_256_test"

# Add support for target architectures
print_action "[ffi] Adding support for target architectures..."
cd ${PROJECT_DIR}/mopro-ffi

for target in x86_64-apple-ios aarch64-apple-ios aarch64-apple-ios-sim; do
if ! check_target_support $target; then
rustup target add $target
else
echo "Target $target already installed, skipping."
fi
done

# Install uniffi-bindgen binary in mopro-ffi
print_action "[ffi] Installing uniffi-bindgen..."
if ! command -v uniffi-bindgen &> /dev/null
then
cargo install --bin uniffi-bindgen --path .
else
echo "uniffi-bindgen already installed, skipping."
fi

print_action "Done! Please run ./scripts/buld_ios.sh to build for iOS."

0 comments on commit a92ea40

Please sign in to comment.