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

feat: AES NIVC + build #24

Merged
merged 21 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 18 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
60 changes: 25 additions & 35 deletions .github/workflows/artifacts.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: build-circuits
name: build-artifacts

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -17,21 +17,19 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2 # Fetch two commits to get the base branch
fetch-depth: 2

- name: Fetch main branch
run: |
git fetch origin main

- name: Compare package.json version with main
id: version_check
run: |
# Extract version from package.json in PR branch
PR_VERSION=$(jq -r .version package.json)
# Extract version from package.json in main branch
MAIN_VERSION=$(git show origin/main:package.json | jq -r .version)
echo "PR version: $PR_VERSION"
echo "Main version: $MAIN_VERSION"
# Fail if versions match
if [ "$PR_VERSION" == "$MAIN_VERSION" ]; then
echo "Error: package.json version has not been updated in this PR."
exit 1
Expand All @@ -41,12 +39,13 @@ jobs:

build:
runs-on: ubuntu-latest
needs: check-version

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Need full history to compare with previous release
fetch-depth: 0

- name: Install Protocol Buffers
run: |
Expand All @@ -70,13 +69,6 @@ jobs:
sudo mv circom /usr/local/bin/
circom --version

- name: Install circom-witnesscalc
run: |
cd .. && git clone https://github.com/pluto/circom-witnesscalc.git
cd circom-witnesscalc
cargo install --path .
echo $(which build-circuit)

- name: Install Node.js dependencies
run: |
npm ci
Expand All @@ -87,36 +79,34 @@ jobs:
VERSION=$(node -p "require('./package.json').version")
echo "VERSION=$VERSION" >> $GITHUB_ENV

- name: Compile Circom circuits
- name: Build circuits using Makefile
run: |
mkdir -p artifacts
for circuit in circuits/*.circom; do
if [ -f "$circuit" ]; then
filename=$(basename "$circuit" .circom)
output_dir="artifacts/$filename"
mkdir -p "$output_dir"

echo "Processing $filename..."

# Run circom compilation
circom "$circuit" --r1cs --wasm -o "$output_dir" -l node_modules
make debug # Show what will be processed
make build # Build the circuits

# Run witness calculator build
build-circuit "$circuit" "$output_dir/$filename.bin" -l node_modules
- name: Create release artifacts
run: |
# Get the list of target directories
for target_dir in builds/target_*b; do
if [ -d "$target_dir/artifacts" ]; then
# Extract the target size from the directory name
target_size=$(basename "$target_dir")

echo "Creating archive for $target_size"
# Create zip file for this target size
( cd "$target_dir/artifacts" && \
zip -r "../../../circom-artifacts-${target_size}-v${{ env.VERSION }}.zip" . )
fi
done

- name: Create release artifacts
run: |
cd artifacts
zip -r ../circom-artifacts-v${{ env.VERSION }}.zip ./*
cd ..
- name: Clean build artifacts
if: always()
run: make clean

# Upload artifacts for PR
- name: Upload artifacts for PR
- name: Upload artifacts
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
with:
name: circom-artifacts-v${{ env.VERSION }}
path: circom-artifacts-v${{ env.VERSION }}.zip
path: circom-artifacts-*-v${{ env.VERSION }}.zip
retention-days: 5
23 changes: 14 additions & 9 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# .github/workflows/release.yml
name: Release

on:
Expand Down Expand Up @@ -50,20 +49,26 @@ jobs:
uses: actions/download-artifact@v4
with:
name: circom-artifacts-v${{ env.VERSION }}
path: .
path: ./artifacts
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ env.run_id }}

- name: Prepare Release Notes
run: |
echo "Automated release of compiled Circom circuits" > release_notes.md
echo "Version: ${{ env.VERSION }}" >> release_notes.md
echo "Commit: ${{ github.sha }}" >> release_notes.md
echo "\nArtifacts included:" >> release_notes.md
for zip in artifacts/circom-artifacts-*-v${{ env.VERSION }}.zip; do
basename "$zip" >> release_notes.md
done

# Add artifacts to existing release
- name: Upload Release Asset
# Create release with all artifact files
- name: Upload Release Assets
uses: softprops/action-gh-release@v2
with:
files: circom-artifacts-v${{ env.VERSION }}.zip
files: artifacts/circom-artifacts-*-v${{ env.VERSION }}.zip
tag_name: v${{ env.VERSION }}
body: |
Automated release of compiled Circom circuits
Version: ${{ env.VERSION }}
Commit: ${{ github.sha }}
body_path: release_notes.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15 changes: 13 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
branches: [ main ]

jobs:
circom:
test:
runs-on: ubuntu-latest

steps:
Expand All @@ -36,4 +36,15 @@ jobs:
circom --version

- name: Run tests
run: npm run test
run: npm run test

- name: Install circom-witnesscalc
run: |
cd .. && git clone https://github.com/pluto/circom-witnesscalc.git
cd circom-witnesscalc
cargo install --path .
echo $(which build-circuit)

- name: Run build-circuit on target files
run: |
build-circuit builds/target_256b/*.circom
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ ir_log/*
log_input_signals.txt
*.bin
*.r1cs
builds/**/*.bin
builds/**/*.r1cs
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Find all target directories
TARGET_DIRS := $(wildcard builds/target_*b)

# Find all .circom files in those directories
CIRCOM_FILES := $(wildcard $(addsuffix /*_*b.circom,$(TARGET_DIRS)))

# Create artifacts directories
$(shell mkdir -p $(addsuffix /artifacts,$(TARGET_DIRS)))

# Default target
.PHONY: all clean
all: build

# Build target
.PHONY: build
build:
@for circuit in $(CIRCOM_FILES); do \
echo "Processing $${circuit}..."; \
circom "$${circuit}" --r1cs -o "$$(dirname $${circuit})/artifacts" -l node_modules; \
build-circuit "$${circuit}" "$$(dirname $${circuit})/artifacts/$$(basename $${circuit} .circom).bin" -l node_modules; \
done

# Clean target
clean:
rm -rf $(addsuffix /artifacts,$(TARGET_DIRS))

# Debug target to show what files were found
.PHONY: debug
debug:
@echo "Found directories:"
@echo $(TARGET_DIRS)
@echo "\nFound circom files:"
@echo $(CIRCOM_FILES)
@echo "\nArtifacts will be generated in:"
@echo $(addsuffix /artifacts,$(TARGET_DIRS))
6 changes: 6 additions & 0 deletions builds/target_1024b/aes_gctr_nivc_1024b.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pragma circom 2.1.9;

include "../../circuits/aes-gcm/nivc/aes-gctr-nivc.circom";

// the circomkit tests become unhappy when there is a main.
component main { public [step_in] } = AESGCTRFOLD(1024, 10);
6 changes: 6 additions & 0 deletions builds/target_1024b/http_body_mask_1024b.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pragma circom 2.1.9;

include "../../circuits/http/nivc/body_mask.circom";

component main { public [step_in] } = HTTPMaskBodyNIVC(1024, 10);

5 changes: 5 additions & 0 deletions builds/target_1024b/http_lock_header_1024b.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../../circuits/http/nivc/lock_header.circom";

component main { public [step_in] } = LockHeader(1024, 10, 50, 100);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../../circuits/http/nivc/parse_and_lock_start_line.circom";

component main { public [step_in] } = ParseAndLockStartLine(1024, 10, 20, 20, 20);
5 changes: 5 additions & 0 deletions builds/target_1024b/json_extract_value_1024b.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../../circuits/json/nivc/extractor.circom";

component main { public [step_in] } = MaskExtractFinal(1024, 10, 50);
5 changes: 5 additions & 0 deletions builds/target_1024b/json_mask_array_index_1024b.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../../circuits/json/nivc/masker.circom";

component main { public [step_in] } = JsonMaskArrayIndexNIVC(1024, 10);
5 changes: 5 additions & 0 deletions builds/target_1024b/json_mask_object_1024b.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../../circuits/json/nivc/masker.circom";

component main { public [step_in] } = JsonMaskObjectNIVC(1024, 10, 10);
6 changes: 6 additions & 0 deletions builds/target_1024b/json_parse_1024b.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pragma circom 2.1.9;

include "../../circuits/json/nivc/parse.circom";

component main { public [step_in] } = JsonParseNIVC(1024, 10);

6 changes: 6 additions & 0 deletions builds/target_256b/aes_gctr_nivc_256b.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pragma circom 2.1.9;

include "../../circuits/aes-gcm/nivc/aes-gctr-nivc.circom";

// the circomkit tests become unhappy when there is a main.
component main { public [step_in] } = AESGCTRFOLD(256, 10);
6 changes: 6 additions & 0 deletions builds/target_256b/http_body_mask_256b.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pragma circom 2.1.9;

include "../../circuits/http/nivc/body_mask.circom";

component main { public [step_in] } = HTTPMaskBodyNIVC(512, 10);

5 changes: 5 additions & 0 deletions builds/target_256b/http_lock_header_256b.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../../circuits/http/nivc/lock_header.circom";

component main { public [step_in] } = LockHeader(512, 10, 50, 100);
5 changes: 5 additions & 0 deletions builds/target_256b/http_parse_and_lock_start_line_256b.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../../circuits/http/nivc/parse_and_lock_start_line.circom";

component main { public [step_in] } = ParseAndLockStartLine(512, 10, 20, 20, 20);
5 changes: 5 additions & 0 deletions builds/target_256b/json_extract_value_256b.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../../circuits/json/nivc/extractor.circom";

component main { public [step_in] } = MaskExtractFinal(256, 10, 50);
5 changes: 5 additions & 0 deletions builds/target_256b/json_mask_array_index_256b.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../../circuits/json/nivc/masker.circom";

component main { public [step_in] } = JsonMaskArrayIndexNIVC(256, 10);
5 changes: 5 additions & 0 deletions builds/target_256b/json_mask_object_256b.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../../circuits/json/nivc/masker.circom";

component main { public [step_in] } = JsonMaskObjectNIVC(256, 10, 10);
6 changes: 6 additions & 0 deletions builds/target_256b/json_parse_256b.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pragma circom 2.1.9;

include "../../circuits/json/nivc/parse.circom";

component main { public [step_in] } = JsonParseNIVC(256, 10);

6 changes: 6 additions & 0 deletions builds/target_512b/aes_gctr_nivc_512b.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pragma circom 2.1.9;

include "../../circuits/aes-gcm/nivc/aes-gctr-nivc.circom";

// the circomkit tests become unhappy when there is a main.
component main { public [step_in] } = AESGCTRFOLD(512, 10);
6 changes: 6 additions & 0 deletions builds/target_512b/http_body_mask_512b.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pragma circom 2.1.9;

include "../../circuits/http/nivc/body_mask.circom";

component main { public [step_in] } = HTTPMaskBodyNIVC(512, 10);

5 changes: 5 additions & 0 deletions builds/target_512b/http_lock_header_512b.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../../circuits/http/nivc/lock_header.circom";

component main { public [step_in] } = LockHeader(512, 10, 50, 100);
5 changes: 5 additions & 0 deletions builds/target_512b/http_parse_and_lock_start_line_512b.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../../circuits/http/nivc/parse_and_lock_start_line.circom";

component main { public [step_in] } = ParseAndLockStartLine(512, 10, 20, 20, 20);
5 changes: 5 additions & 0 deletions builds/target_512b/json_extract_value_512b.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../../circuits/json/nivc/extractor.circom";

component main { public [step_in] } = MaskExtractFinal(512, 10, 50);
5 changes: 5 additions & 0 deletions builds/target_512b/json_mask_array_index_512b.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../../circuits/json/nivc/masker.circom";

component main { public [step_in] } = JsonMaskArrayIndexNIVC(512, 10);
5 changes: 5 additions & 0 deletions builds/target_512b/json_mask_object_512b.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../../circuits/json/nivc/masker.circom";

component main { public [step_in] } = JsonMaskObjectNIVC(512, 10, 10);
6 changes: 6 additions & 0 deletions builds/target_512b/json_parse_512b.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pragma circom 2.1.9;

include "../../circuits/json/nivc/parse.circom";

component main { public [step_in] } = JsonParseNIVC(512, 10);

Loading
Loading