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

[WIP] Sonobe integration #14

Open
wants to merge 148 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
148 commits
Select commit Hold shift + click to select a range
1fd630e
Clean up Cargo.toml
pmikolajczyk41 Aug 18, 2024
6186f61
Leave code only for grayscale
pmikolajczyk41 Aug 19, 2024
4917202
Dependencies
pmikolajczyk41 Aug 20, 2024
7116e74
Remove some leftovers
pmikolajczyk41 Aug 20, 2024
537aceb
Compiling, but failing after a lot of time
pmikolajczyk41 Aug 21, 2024
4459513
Add `parallel` feature to sonobe
pmikolajczyk41 Aug 22, 2024
41ea6a5
Add toolchain and rustfmt configuration
pmikolajczyk41 Aug 22, 2024
63628c6
Run linter
pmikolajczyk41 Aug 22, 2024
3c50aa8
Bump clap, explicit dependencies
pmikolajczyk41 Aug 22, 2024
9443de1
Rework VimZ configuration
pmikolajczyk41 Aug 22, 2024
d08bb1b
Transformation and Resolution enums
pmikolajczyk41 Aug 22, 2024
0b43074
Iteration count, lint
pmikolajczyk41 Aug 22, 2024
4565cae
dev
pmikolajczyk41 Aug 30, 2024
6337388
cache decider params
pmikolajczyk41 Aug 30, 2024
4bdfad5
checkpoint
pmikolajczyk41 Sep 2, 2024
3c84c50
refactor
pmikolajczyk41 Sep 3, 2024
1198934
imports
pmikolajczyk41 Sep 3, 2024
d382d73
typos
pmikolajczyk41 Sep 9, 2024
55b0e04
fix naming
pmikolajczyk41 Sep 12, 2024
cdc99e2
light test feature
pmikolajczyk41 Sep 12, 2024
e8b037d
rework some circuits signals
pmikolajczyk41 Sep 12, 2024
cfc65b4
Hard refactor
pmikolajczyk41 Sep 16, 2024
7700368
Makefile
pmikolajczyk41 Sep 16, 2024
e06ca96
Working brightness
pmikolajczyk41 Sep 16, 2024
d43eaed
Blur
pmikolajczyk41 Sep 16, 2024
3bd6d28
Docs
pmikolajczyk41 Sep 16, 2024
bc8a643
Merge remote-tracking branch 'refs/remotes/origin/master' into sonobe…
pmikolajczyk41 Sep 16, 2024
df4384e
Update README.md
parizad1188 Sep 17, 2024
4e88fc2
Solidity verification
pmikolajczyk41 Sep 17, 2024
d5d6b3e
refactor circuits to support both sonobe and nova-snark backends
lovely-necromancer Oct 1, 2024
5af1371
bug fix
lovely-necromancer Oct 1, 2024
7c94b6b
add backend selection option to build scripts
lovely-necromancer Oct 1, 2024
8a96bec
add brightness circuit wrappers
lovely-necromancer Oct 1, 2024
3c1f47a
add wrappers for grayscale circuit
lovely-necromancer Oct 1, 2024
3bb9507
update ignore paths
lovely-necromancer Oct 1, 2024
52c13ef
add dependencies for nova-snark
lovely-necromancer Oct 1, 2024
167a613
add nova-snark backend
lovely-necromancer Oct 1, 2024
b7b5e32
Compress ignores in .gitignore
pmikolajczyk41 Oct 2, 2024
15a0ccd
revert path in Python script
pmikolajczyk41 Oct 2, 2024
c2814e6
Move package.json to main dir, adapt include paths
pmikolajczyk41 Oct 2, 2024
7a3ba05
fix dir naming, fix makefile
pmikolajczyk41 Oct 2, 2024
2c857ed
Input transformation enhancements
pmikolajczyk41 Oct 9, 2024
60e84a0
Docs
pmikolajczyk41 Oct 9, 2024
96b7c7e
Nova counterparts. Comment wrapper sections
pmikolajczyk41 Oct 9, 2024
f62e569
Add Cargo.lock to git tracking
pmikolajczyk41 Oct 9, 2024
6379721
Bump version
pmikolajczyk41 Oct 9, 2024
2ce259b
Migrate nova-snark to bn254 cycle
pmikolajczyk41 Oct 9, 2024
aa97daf
lint
pmikolajczyk41 Oct 9, 2024
31083bc
Sonobe input module
pmikolajczyk41 Oct 9, 2024
af4dbac
Move sonobe-related things to dedicated module
pmikolajczyk41 Oct 12, 2024
08196d4
Nova snark dir module
pmikolajczyk41 Oct 12, 2024
99ce2cb
Universal input structure
pmikolajczyk41 Oct 12, 2024
b1677a3
Input tests, fix optional transformed field
pmikolajczyk41 Oct 12, 2024
198baa2
Use enum's iteration count
pmikolajczyk41 Oct 12, 2024
4f0fb37
Universal start public input resolution
pmikolajczyk41 Oct 12, 2024
eeed6d4
Handle nova snark input gently
pmikolajczyk41 Oct 12, 2024
4791ca6
Inline variables
pmikolajczyk41 Oct 12, 2024
4aa0ce2
Add idea/ to gitignore
pmikolajczyk41 Oct 19, 2024
c4bf410
Improve readability of input module
pmikolajczyk41 Oct 20, 2024
f1692a7
Add test for ratio - iteration count
pmikolajczyk41 Oct 20, 2024
86e2429
Remove unnecessary argument
pmikolajczyk41 Oct 20, 2024
7a9c9f8
Big refactor in sonobe flow
pmikolajczyk41 Oct 20, 2024
03c4d4f
Fix rng in sobobe
pmikolajczyk41 Oct 20, 2024
062ce6c
Move file paths handling to config
pmikolajczyk41 Oct 20, 2024
cf928b8
Refactor novasnark module
pmikolajczyk41 Oct 20, 2024
a86c70d
Verify folding proof in Sonobe
pmikolajczyk41 Oct 20, 2024
22e609c
Fix demo length
pmikolajczyk41 Oct 20, 2024
af64f79
lint target
pmikolajczyk41 Oct 20, 2024
e2ed764
remove newtype
pmikolajczyk41 Oct 20, 2024
d6dcfcb
Save file
pmikolajczyk41 Oct 20, 2024
e2995fd
Add tracing dep
pmikolajczyk41 Oct 20, 2024
b1ff6bd
Use tracing for measuring span time
pmikolajczyk41 Oct 20, 2024
a3a8462
Add logging to nova-snark
pmikolajczyk41 Oct 20, 2024
9f27ea9
Finally format span nicely
pmikolajczyk41 Oct 22, 2024
290f659
Add support for contrast circuit
pmikolajczyk41 Oct 22, 2024
e3ef861
Refactor Makefile
pmikolajczyk41 Oct 22, 2024
1852387
Remove leftovers
pmikolajczyk41 Oct 22, 2024
00dbd70
Tiny refactor
pmikolajczyk41 Oct 22, 2024
d7d65de
Support sharpness transformation
pmikolajczyk41 Oct 22, 2024
06585e5
Fix
pmikolajczyk41 Oct 22, 2024
835b5b1
Update LICENSE: This version built by community for community :)
lovely-necromancer Nov 19, 2024
cdfef76
Delete older LICENSE.md
lovely-necromancer Nov 19, 2024
07abcd9
Refactor hash circuit
pmikolajczyk41 Oct 23, 2024
ab991c8
Hash transformation
pmikolajczyk41 Nov 30, 2024
1071d8e
Logging docs
pmikolajczyk41 Nov 30, 2024
9af84d7
Remove redundant prefix from circuit files
pmikolajczyk41 Nov 30, 2024
55366ba
Fix hash
pmikolajczyk41 Nov 30, 2024
c9dfe83
Refactor hashing in circuits
pmikolajczyk41 Nov 30, 2024
e8962cd
Remove unnamed tripe
pmikolajczyk41 Nov 30, 2024
263aeda
Demo mode
pmikolajczyk41 Nov 30, 2024
786f692
Crop transformation
pmikolajczyk41 Nov 30, 2024
be942af
Resize transformation
pmikolajczyk41 Dec 2, 2024
5944ae5
Refine build_circuits.sh
pmikolajczyk41 Dec 2, 2024
5435413
Refine clear_builds.sh
pmikolajczyk41 Dec 2, 2024
98d64fc
Rename python dir, move plotting to another module
pmikolajczyk41 Dec 2, 2024
27bc2d0
Minimize requirements.txt
pmikolajczyk41 Dec 2, 2024
2c1d35e
Refine compressing and convolution
pmikolajczyk41 Dec 2, 2024
ecc8c84
typo
pmikolajczyk41 Dec 2, 2024
1e3bd89
Allow passing image as CLI argument
pmikolajczyk41 Dec 2, 2024
5502b56
Rework main
pmikolajczyk41 Dec 2, 2024
d08f4cf
Add output dir
pmikolajczyk41 Dec 2, 2024
2f09ba9
Rename python dir
pmikolajczyk41 Dec 2, 2024
0a6bb26
Conditional rendering
pmikolajczyk41 Dec 2, 2024
59e3a9d
Non-interactive script
pmikolajczyk41 Dec 3, 2024
f7816c5
Generate input data
pmikolajczyk41 Dec 3, 2024
3792ad7
Remove data
pmikolajczyk41 Dec 3, 2024
f78d434
Rename directory with the source image
pmikolajczyk41 Dec 3, 2024
80f6156
Minor fixes to paths
pmikolajczyk41 Dec 3, 2024
343e3b9
update gitignore
pmikolajczyk41 Dec 3, 2024
ace1027
Cover hash transformation as well
pmikolajczyk41 Dec 3, 2024
b9e7ced
refactor makefile
pmikolajczyk41 Dec 3, 2024
ad8cac0
Circuit compilation made better
pmikolajczyk41 Dec 4, 2024
97342ef
Save compilation logs for circuits
pmikolajczyk41 Dec 4, 2024
e590030
Analyze circuit compilation logs
pmikolajczyk41 Dec 4, 2024
e368604
Compare reports
pmikolajczyk41 Dec 4, 2024
12778e1
Generate reports in Makefile
pmikolajczyk41 Dec 4, 2024
51d1326
Include common reports in versioning
pmikolajczyk41 Dec 4, 2024
0c18aa6
Fix tests
pmikolajczyk41 Dec 4, 2024
3b5b17b
Fix hash
pmikolajczyk41 Dec 4, 2024
e4c12f5
Optionally save proof
pmikolajczyk41 Dec 5, 2024
554fcb9
Rename crate dir
pmikolajczyk41 Dec 5, 2024
f44662e
Run all nova snark circuits and save logs
pmikolajczyk41 Dec 5, 2024
e246f89
Generate report
pmikolajczyk41 Dec 5, 2024
78f39f7
Use 10 steps in demo mode
pmikolajczyk41 Dec 5, 2024
921b161
Add --O2, but this doesn't change much
pmikolajczyk41 Dec 5, 2024
1aee719
Make ArrayHasher more efficient
pmikolajczyk41 Dec 5, 2024
cb93093
Fix hash step in sonobe
pmikolajczyk41 Dec 5, 2024
29b7c47
Restore original hashing. Prepare 3 versions of hashing in the 'lib'.
pmikolajczyk41 Dec 6, 2024
39f07ac
Numpy version
pmikolajczyk41 Dec 6, 2024
8f83b92
Use best array hashing
pmikolajczyk41 Dec 6, 2024
e54f37c
Bump rust
pmikolajczyk41 Jan 6, 2025
3ce15be
Add Cargo.lock
pmikolajczyk41 Jan 6, 2025
0898ca2
bump sonobe - checkpoint
pmikolajczyk41 Jan 7, 2025
d407bff
bump sonobe - checkpoint
pmikolajczyk41 Jan 7, 2025
acf5cd7
bump sonobe - checkpoint
pmikolajczyk41 Jan 7, 2025
5cc3dad
bump sonobe - checkpoint
pmikolajczyk41 Jan 7, 2025
bd85a3e
bump sonobe
pmikolajczyk41 Jan 7, 2025
4012498
Bump circom
pmikolajczyk41 Jan 10, 2025
0295fe7
Prepare new vimz binary
pmikolajczyk41 Jan 10, 2025
4a769d6
Generating verifier contracts
pmikolajczyk41 Jan 10, 2025
0349d50
Generate contracts
pmikolajczyk41 Jan 10, 2025
f0d5213
Consistent constants
pmikolajczyk41 Jan 27, 2025
14583df
Remove old contract leftover
pmikolajczyk41 Jan 27, 2025
2c13cc2
Save calldata
pmikolajczyk41 Jan 27, 2025
c850880
Showcase: mocked verification
pmikolajczyk41 Jan 27, 2025
c23db37
Working!
pmikolajczyk41 Jan 27, 2025
d0b9f20
E2E, docs
pmikolajczyk41 Jan 27, 2025
d319d94
README
pmikolajczyk41 Jan 27, 2025
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
20 changes: 11 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
*.jpg
.idea/
*/venv/
circom/*_cpp/
circom/*_js/
circom/*.r1cs
circom/*.sym
circom/*/*_cpp/
circom/*/*_js/
circom/*/*.r1cs
circom/*/*.sym

input_data/
runs/

*.json

circuits/**/*_cpp/
circuits/**/*_js/
circuits/**/*.r1cs
circuits/**/*.sym
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Zero Savvy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 0 additions & 2 deletions LICENSE.md

This file was deleted.

90 changes: 90 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
.PHONY: help
help: # Show help for each of the Makefile recipes.
@grep -E '^[a-zA-Z0-9 -]+:.*#' Makefile | sort | while read -r l; do printf "\033[1;32m$$(echo $$l | cut -f 1 -d':')\033[00m:$$(echo $$l | cut -f 2- -d'#')\n"; done

TRANSFORMATIONS = blur brightness contrast crop grayscale hash resize sharpness

########################################################################################################################
########################### INPUT DATA GENERATION ######################################################################
########################################################################################################################

INPUT_SOURCE = --image-path ./source_image/HD.png
INPUT_TARGET_DIR = ./input_data/
INPUT_TARGET = --output-dir $(INPUT_TARGET_DIR)

EXTRA_ARGS_brightness = --factor 1.4
EXTRA_ARGS_contrast = --factor 1.4
EXTRA_ARGS_crop = --x 200 --y 100 --crop-size HD
EXTRA_ARGS_resize = --resize-option "HD to SD"

.PHONY: generate-input-data
generate-input-data: # Prepare input data for every supported transformation.
generate-input-data: $(patsubst %, $(INPUT_TARGET_DIR)%.json, $(TRANSFORMATIONS))

$(INPUT_TARGET_DIR)%.json:
@mkdir -p $(INPUT_TARGET_DIR)
@python3 image_editor/main.py $* $(INPUT_SOURCE) $(INPUT_TARGET) $(EXTRA_ARGS_$*)

########################################################################################################################
########################### CIRCUIT COMPILATION ########################################################################
########################################################################################################################

BACKEND = sonobe nova_snark

COMPILATION_ARTIFACTS := $(foreach backend,$(BACKEND),$(foreach trans,$(TRANSFORMATIONS), \
circuits/$(backend)/$(trans)_step.r1cs \
circuits/$(backend)/$(trans)_step_js/$(trans)_step.wasm \
circuits/$(backend)/$(trans)_step.compile_log))

.PHONY: build-circuits
build-circuits: $(COMPILATION_ARTIFACTS)

circuits/%_step.r1cs circuits/%_step_js/%_step.wasm circuits/%_step.compile_log: circuits/%_step.circom
@backend=$(word 1,$(subst /, ,$*)); \
transformation=$(word 2,$(subst /, ,$*)); \
transformation_file=$$transformation\_step.circom; \
./circuits/build_circuits.sh circuits/$$backend $$transformation_file

.PHONY: report-circuit-parameters
report-circuit-parameters: build-circuits
@python3 analysis_utils/analyze_circuits.py sonobe > /dev/null
@python3 analysis_utils/analyze_circuits.py nova_snark > /dev/null

.PHONY: clean-circuits
clean-circuits:
@cd circuits && ./clear_builds.sh sonobe && ./clear_builds.sh nova_snark

########################################################################################################################
########################### BENCHMARKING ###############################################################################
########################################################################################################################

RUN_NS_ARTIFACTS := $(foreach trans,$(TRANSFORMATIONS), runs/nova_snark/$(trans).out)
RUN_SN_ARTIFACTS := $(foreach trans,$(TRANSFORMATIONS), runs/sonobe/$(trans).out)
NS_REPORT_FILE = runs/nova_snark_report.txt
SN_REPORT_FILE = runs/sonobe_report.txt

.PHONY: run-nova-snark-benchmarks
run-nova-snark-benchmarks: generate-input-data build-circuits $(RUN_NS_ARTIFACTS)
@$(call generate-report,$(RUN_NS_ARTIFACTS),$(NS_REPORT_FILE))

runs/nova_snark/%.out:
@mkdir -p runs/nova_snark
@cd vimz/ && $(MAKE) $* BACKEND=nova-snark DEMO=yes > ../$@

.PHONY: run-sonobe-benchmarks
run-sonobe-benchmarks: generate-input-data build-circuits $(RUN_SN_ARTIFACTS)
@$(call generate-report,$(RUN_SN_ARTIFACTS),$(SN_REPORT_FILE))

runs/sonobe/%.out:
@mkdir -p runs/sonobe
@cd vimz/ && $(MAKE) $* BACKEND=sonobe DEMO=yes LIGHT_TEST=yes > ../$@

define generate-report
> $2
for log in $1; do \
func=$$(grep -m1 "Selected function:" $$log | sed -E 's/.*Selected function: (.*)/\1/'); \
fold_time=$$(grep "Fold input" $$log | grep -v "completed" | awk '{print $$NF}' | tail -n1); \
echo "$$func: $$fold_time" >> $2; \
done
echo "Report saved to $2"
endef
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ build node modules:

build ZK circuits using the provided script in this directory:

`./build-circuits.sh`
`./build_circuits.sh`

## How to Use

Expand Down
44 changes: 44 additions & 0 deletions analysis_utils/analyze_circuits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import sys

import pandas as pd
from tabulate import tabulate

parameters = [
"Template Instances", "Non-Linear Constraints", "Linear Constraints",
"Public Inputs", "Private Inputs", "Public Outputs", "Wires", "Labels"
]


def parse_logs_to_dataframe(log_files):
data = []
for log_file in log_files:
base_name = log_file.split("/")[-1].removesuffix("_step.compile_log")
with open(log_file, 'r') as f:
content = f.readlines()
metrics = {"File Name": base_name} | {key: 0 for key in parameters}
for line in content:
for key in metrics.keys():
if key.lower() in line.lower():
metrics[key] = int(line.split(":")[1].strip().split(" ")[0])
data.append(metrics)
return pd.DataFrame(data)


def gather_circuit_parameters(backend):
transformations = ["blur", "brightness", "contrast", "crop", "grayscale", "hash", "resize", "sharpness"]
files = [f"circuits/{backend}/{t}_step.compile_log" for t in transformations]
return parse_logs_to_dataframe(files)


if __name__ == '__main__':
if len(sys.argv) != 2:
raise ValueError("Invalid number of arguments. Usage: python analyze_circuits.py <backend>")
backend = sys.argv[1]

if backend not in ["nova_snark", "sonobe"]:
raise ValueError("Invalid backend. Must be either 'nova_snark' or 'sonobe'.")

parameters = gather_circuit_parameters(backend)

print(tabulate(parameters, headers="keys", tablefmt="grid"))
parameters.to_csv(f"circuits/{backend}/circuit_parameters.csv", index=False)
21 changes: 21 additions & 0 deletions analysis_utils/compare_circuits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import sys

import pandas as pd
from tabulate import tabulate

from analyze_circuits import parameters

if __name__ == '__main__':
if len(sys.argv) != 3:
raise ValueError("Invalid number of arguments. Usage: python compare_circuits.py <param_file_1> <param_file_2>")
params_1, params_2 = pd.read_csv(sys.argv[1]), pd.read_csv(sys.argv[2])

comparison = pd.merge(params_1, params_2, on="File Name", suffixes=("_1", "_2"))

for col in parameters:
comparison[f"{col} Diff"] = comparison[f"{col}_1"] - comparison[f"{col}_2"]

diff_columns = ["File Name"] + [f"{col} Diff" for col in parameters]
diff_table = comparison[diff_columns]

print(tabulate(diff_table, headers="keys", tablefmt="grid"))
2 changes: 2 additions & 0 deletions analysis_utils/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pandas==2.2.3
tabulate==0.9.0
78 changes: 37 additions & 41 deletions circuits/build_circuits.sh
Original file line number Diff line number Diff line change
@@ -1,52 +1,48 @@
#!/bin/bash
#!/usr/bin/env bash

# Set the directory where you want to search for files
target_directory="."
set -eou pipefail

# Set the pattern of files you want to process
# Display usage instructions
usage() {
echo "Usage: $0 <subfolder> [specific_circuit_file]"
echo " - <subfolder>: Required. The subfolder containing the circuit files."
echo " - [specific_circuit_file]: Optional. A specific .circom file to rebuild."
exit 1
}

# Validate arguments
if [ "$#" -lt 1 ]; then
usage
fi

# Assign the first argument as the subfolder name
subfolder="$1"

# Navigate to the subfolder
cd "$subfolder" || exit

# Set the pattern for files to process
file_pattern="*.circom"

# Enable nullglob to avoid issues with empty file lists
shopt -s nullglob

# If an argument is provided, use it as the specific file
if [ "$#" -eq 1 ]; then
user_provided_file="$1"
# Check if the provided file exists
if [ -f "$user_provided_file" ]; then
file_list=("$user_provided_file")
else
echo "Error: Provided file '$user_provided_file' not found."
exit 1
fi
# Determine files to process
if [ "$#" -eq 2 ]; then
specific_file="$2"
if [ -f "$specific_file" ]; then
file_list=("$specific_file")
else
echo "Error: File '$specific_file' not found."
exit 1
fi
else
# If no argument is provided, use pattern-matching
file_list=($target_directory/$file_pattern)
file_list=($file_pattern)
fi

# Iterate over files matching the pattern and run commands
# Iterate over and process each file
for file in "${file_list[@]}"; do
# echo "$file"
if [ -f "$file" ]; then
echo " "
echo -e "\033[1;34m==================================================\033[0m"
echo -e "\033[1;34mProcessing file: $file\033[0m"
echo -e "\033[1;34m==================================================\033[0m"

# Start timing
start_time=$(date +%s.%N)

circom $file --r1cs --wasm --sym --c --prime vesta
filename=$(basename -- "$file")
filename_no_extension="${filename%.*}"
cpp_directory="${filename_no_extension}_cpp"
js_directory="${filename_no_extension}_js"
(
cd "$cpp_directory" || exit
echo -e "\033[1;32mRunning make in $cpp_directory\033[0m"
make
)
end_time=$(date +%s.%N)
elapsed_time=$(echo "$end_time - $start_time" | bc)
echo -e "\033[1;34mTime taken: $elapsed_time seconds\033[0m"
fi
echo -e "\033[1mBuilding circuit: ${file}\033[0m"
base_name=$(basename "$file" .circom)
circom "$file" --O2 --r1cs --wasm > "${base_name}.compile_log"
done
81 changes: 69 additions & 12 deletions circuits/clear_builds.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,79 @@
#!/bin/bash
#!/usr/bin/env bash

# Set the directory where you want to search for folders
target_directory="."
set -eou pipefail

# Set the patterns of folders you want to remove
folder_patterns=( )
# Display usage instructions
usage() {
echo "Usage: $0 <subfolder> [specific_circuit_file]"
echo " - <subfolder>: Required. The subfolder containing the circuit files to clean."
echo " - [specific_circuit_file]: Optional. A specific circuit to clean related files for."
exit 1
}

# Validate arguments
if [ "$#" -lt 1 ]; then
usage
fi

# Assign the first argument as the subfolder name
subfolder="$1"

# Validate the provided subfolder
if [ ! -d "$subfolder" ]; then
echo "Error: Subfolder '$subfolder' not found."
exit 1
fi

# Navigate to the subfolder
cd "$subfolder" || exit

# Define patterns for cleanup
folder_patterns=("*_js" "*_cpp")
file_patterns=("*.r1cs" "*.sym")

# Use find to locate and remove folders matching the patterns
# If a specific circuit file is provided
if [ "$#" -eq 2 ]; then
specific_file="$2"
if [ -f "$specific_file" ]; then
# Extract the base name (without extension)
base_name=$(basename "$specific_file" .circom)
folder_patterns=("${base_name}_js" "${base_name}_cpp")
file_patterns=("${base_name}.r1cs" "${base_name}.sym")
else
echo "Error: Specific circuit file '$specific_file' not found."
exit 1
fi
fi

# Function to remove folders matching patterns
remove_folders() {
local pattern="$1"
matching_folders=$(find . -type d -name "$pattern")
if [ -n "$matching_folders" ]; then
find . -type d -name "$pattern" -exec rm -r {} +
echo "Folders matching the pattern '$pattern' removed."
else
echo "No folders matching the pattern '$pattern' found."
fi
}

# Function to remove files matching patterns
remove_files() {
local pattern="$1"
matching_files=$(find . -type f -name "$pattern")
if [ -n "$matching_files" ]; then
find . -type f -name "$pattern" -exec rm {} +
echo "Files matching the pattern '$pattern' removed."
else
echo "No files matching the pattern '$pattern' found."
fi
}

# Perform cleanup
for pattern in "${folder_patterns[@]}"; do
find "$target_directory" -type d -name "$pattern" -exec rm -r {} +
echo "Folders matching the pattern '$pattern' removed."
remove_folders "$pattern"
done

# Use find to locate and remove files matching the patterns
for pattern in "${file_patterns[@]}"; do
find "$target_directory" -type f -name "$pattern" -exec rm {} +
echo "Files matching the pattern '$pattern' removed."
done
remove_files "$pattern"
done
Loading