Skip to content
This repository was archived by the owner on Aug 5, 2025. It is now read-only.

Commit aebc267

Browse files
committed
init circuits
0 parents  commit aebc267

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+6976
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
name: 'Prepare Rust environment'
3+
description: >
4+
Installs Rust toolchain, authenticates with SSH (in order to access Github private repos)
5+
inputs:
6+
ssh-private-key:
7+
description: 'SSH private key to authenticate with'
8+
required: true
9+
runs:
10+
using: composite
11+
steps:
12+
- uses: webfactory/ssh-agent@v0.9.0
13+
with:
14+
ssh-private-key: ${{ inputs.ssh-private-key }}
15+
16+
- name: Install Rust toolchain
17+
uses: Cardinal-Cryptography/github-actions/install-rust-toolchain@v7
18+
with:
19+
channel: nightly
20+
21+
- name: Install sccache
22+
shell: bash
23+
run: scripts/install-sccache
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import re
2+
3+
import pandas as pd
4+
from jinja2 import Template
5+
6+
7+
def parse_file(file_path):
8+
data = []
9+
current_circuit = None
10+
with open(file_path, 'r') as file:
11+
for line in file:
12+
line = line.strip()
13+
if 'PhantomData' in line:
14+
continue
15+
if line.startswith('`'):
16+
current_circuit = re.match(r"`(.*?)`", line).group(1)
17+
if ': ' in line and current_circuit:
18+
key, value = map(str.strip, line.split(': ', 1))
19+
20+
key = key.removeprefix(f'`{current_circuit}`').strip()
21+
value = value.removesuffix(',')
22+
23+
data.append({
24+
'Circuit': current_circuit,
25+
'Metric': key,
26+
'Value': value
27+
})
28+
return pd.DataFrame(data)
29+
30+
31+
def highlight_diff(val, diff_flag):
32+
"""Highlight the differences with HTML color formatting"""
33+
if diff_flag:
34+
return f'<span style="color: red;">{val}</span>'
35+
return val
36+
37+
38+
def generate_diff_html(file1, file2):
39+
df1 = parse_file(file1).set_index(['Circuit', 'Metric'])
40+
df2 = parse_file(file2).set_index(['Circuit', 'Metric'])
41+
42+
# Merge the two dataframes and compute the 'Different' flag
43+
diff = df1.merge(df2, how='outer', left_index=True, right_index=True, suffixes=('_MainBranch', '_NewCode'))
44+
diff['Different'] = diff.apply(lambda row: row['Value_MainBranch'] != row['Value_NewCode'], axis=1)
45+
46+
# Filter out rows that are not different
47+
diff = diff[diff['Different']]
48+
49+
# If there are no differences, handle gracefully
50+
if diff.empty:
51+
print("No differences found.")
52+
return
53+
54+
# Function to calculate percentage change and return formatted HTML string
55+
def calculate_percentage_change(value1, value2):
56+
try:
57+
v1 = float(value1.replace('KB', '').replace('MB', '').strip())
58+
v2 = float(value2.replace('KB', '').replace('MB', '').strip())
59+
if v1 == 0:
60+
return "N/A" # Avoid division by zero
61+
change = ((v2 - v1) / v1) * 100
62+
color = 'red' if change > 0 else 'green'
63+
return f'$${{\color{{{color}}}{change:.2f}\%}}$$'
64+
except (ValueError, TypeError, AttributeError):
65+
return "N/A" # If calculation isn't possible, return "N/A"
66+
67+
# Function to highlight values based on comparison
68+
def highlight_diff(value1, value2):
69+
try:
70+
v1 = float(value1.replace('KB', '').replace('MB', '').strip())
71+
v2 = float(value2.replace('KB', '').replace('MB', '').strip())
72+
if v1 > v2:
73+
return f'<span>$${{\color{{red}}{value1}}}$$</span>'
74+
elif v1 < v2:
75+
return f'<span>$${{\color{{green}}{value1}}}$$</span>'
76+
except (ValueError, TypeError, AttributeError):
77+
pass
78+
return value1
79+
80+
# Apply the highlighting function and percentage change calculation
81+
diff.reset_index(inplace=True) # Make 'Circuit' and 'Metric' columns regular columns for display
82+
diff['Main branch'] = diff.apply(lambda row: highlight_diff(row['Value_MainBranch'], row['Value_NewCode']), axis=1)
83+
diff['New code'] = diff.apply(lambda row: highlight_diff(row['Value_NewCode'], row['Value_MainBranch']), axis=1)
84+
diff['% Change'] = diff.apply(
85+
lambda row: calculate_percentage_change(row['Value_MainBranch'], row['Value_NewCode']), axis=1)
86+
87+
# Drop the original columns and 'Different' column
88+
diff = diff[['Circuit', 'Metric', 'Main branch', 'New code', '% Change']]
89+
90+
# Create HTML table
91+
html = diff.to_html(escape=False, index=False)
92+
93+
# HTML template with some styles
94+
template = Template("""<html><body>
95+
{{ table|safe }}
96+
</body></html>""")
97+
98+
# Render the template
99+
html_content = template.render(table=html)
100+
101+
# Save to file
102+
with open('comparison_diff.html', 'w') as f:
103+
f.write(html_content)
104+
print("Diff generated in 'comparison_diff.html'")
105+
106+
107+
generate_diff_html('main-report.txt', 'current-report.txt')
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
# This workflow checks if vars and secrets are present and fails if one is empty.
3+
# It should be included as a first step in all the workflows.
4+
name: Check vars and secrets
5+
on:
6+
workflow_call:
7+
8+
jobs:
9+
main:
10+
name: Check available vars and secrets
11+
runs-on: ubuntu-20.04
12+
steps:
13+
# - name: Check vars
14+
# run: |
15+
# if [[ \
16+
# -z '${{ vars.SHIELDER_CONTRACT_ADDRESS }}' || \
17+
# -z '${{ vars.KUSTOMIZE_VERSION }}' || \
18+
# -z '${{ vars.CI_TESTNET_ALICE_PUBLIC_KEY }} }}' || \
19+
# -z '${{ vars.CI_TESTNET_BOB_PUBLIC_KEY }} }}' || \
20+
# -z '${{ vars.CI_TESTNET_CHARLIE_PUBLIC_KEY }} }}' || \
21+
# -z '${{ vars.CI_TESTNET_RELAYER_SIGNER_ADDRESSES }} }}' || \
22+
# -z '${{ vars.CI_TESTNET_FEE_DESTINATION }} }}'
23+
# ]]; then
24+
# echo '!!! Some repository variables are either missing or empty.'
25+
# echo '!!! Please check either repository or organization settings.'
26+
# exit 1
27+
# fi
28+
29+
- name: Check secrets
30+
run: |
31+
if [[ \
32+
-z '${{ secrets.SSH_PRIVATE_KEY }}' || \
33+
# -z '${{ secrets.VERCEL_ORG_ID }}' || \
34+
# -z '${{ secrets.VERCEL_PROJECT_ID }}' || \
35+
# -z '${{ secrets.VERCEL_TOKEN }}' || \
36+
# -z '${{ secrets.AWS_MAINNET_ECR_ACCESS_KEY_ID }}' || \
37+
# -z '${{ secrets.AWS_MAINNET_ECR_ACCESS_KEY }}' || \
38+
# -z '${{ secrets.ECR_PRIVATE_HOST }}' || \
39+
-z '${{ secrets.AUTOCOMMIT_AUTHOR }}' || \
40+
-z '${{ secrets.AUTOCOMMIT_EMAIL }}' || \
41+
-z '${{ secrets.CI_GH_TOKEN }}' || \
42+
-z '${{ secrets.SLACK_WEBHOOK_ZKOS }}'
43+
]]; then
44+
echo '!!! Some repository secrets are either missing or empty.'
45+
echo '!!! Please check either repository or organization settings.'
46+
exit 1
47+
fi
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
name: Measure circuits
3+
4+
on:
5+
workflow_call:
6+
7+
jobs:
8+
main:
9+
name: Measure circuits
10+
# runs-on: [self-hosted, Linux, X64, large]
11+
runs-on: ubuntu-20.04
12+
timeout-minutes: 10
13+
14+
steps:
15+
- name: Checkout code (from the current branch)
16+
uses: actions/checkout@v4
17+
18+
- name: Prepare Rust env
19+
uses: ./.github/actions/prepare-rust-env
20+
with:
21+
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
22+
23+
#################### Run measurements on main branch ####################
24+
25+
- name: Checkout repository from `main`
26+
uses: actions/checkout@v4
27+
with:
28+
ref: main
29+
path: main
30+
31+
- name: Build measure-circuits binary from `main`
32+
run: cd main && make build
33+
34+
- name: Run measure-circuits binary from `main`
35+
run: ./main/target/release/measure-circuits > main-report.txt
36+
37+
- name: Log measurements from `main`
38+
run: cat main-report.txt
39+
40+
#################### Run measurements on the current branch ####################
41+
42+
- name: Download measure-circuits binary from the current branch
43+
uses: actions/download-artifact@v4
44+
with:
45+
name: measure-circuits
46+
47+
- name: Make binary executable
48+
run: chmod +x ./measure-circuits
49+
50+
- name: Run measure-circuits binary from the current branch
51+
run: ./measure-circuits > current-report.txt
52+
53+
- name: Log measurements from the current branch
54+
run: cat current-report.txt
55+
56+
#################### Compare measurements ####################
57+
58+
- name: Install Python 3.10
59+
uses: actions/setup-python@v5
60+
with:
61+
python-version: '3.10'
62+
63+
- name: Install python deps
64+
run: pip install pandas jinja2
65+
66+
- name: Run metrics-diff-presenter script
67+
run: python3 .github/scripts/metrics-diff-presenter.py
68+
69+
- name: Post measurements difference
70+
if: ${{ hashFiles('comparison_diff.html') != '' }}
71+
uses: thollander/actions-comment-pull-request@v3
72+
with:
73+
file-path: comparison_diff.html
74+
comment-tag: measurements-diff
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
name: Run linter and tests for all Rust crates
3+
4+
on:
5+
workflow_call:
6+
workflow_dispatch:
7+
8+
jobs:
9+
# Run formatter and linter for all crates, and unit tests for all simple crates, that,
10+
# in particular, do not require anvil node to be running.
11+
# For shielder-circuit crate, we run tests and build the binary for measuring circuits.
12+
rust-checks-and-unit-tests:
13+
name: Run lints and tests
14+
# runs-on: [self-hosted, Linux, X64, large]
15+
runs-on: ubuntu-20.04
16+
timeout-minutes: 60
17+
env:
18+
RUSTC_WRAPPER: sccache
19+
steps:
20+
- name: Checkout source code
21+
uses: actions/checkout@v4
22+
23+
- name: Prepare Rust env
24+
uses: ./.github/actions/prepare-rust-env
25+
with:
26+
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
27+
28+
- name: Run linter and formatter
29+
run: |
30+
make lint
31+
32+
# Shielder-circuits part
33+
- name: Build shielder-circuits package
34+
run: make build && make test
35+
36+
- name: Upload circuit measurements binary
37+
uses: actions/upload-artifact@v4
38+
with:
39+
path: target/release/measure-circuits
40+
name: measure-circuits
41+
retention-days: 1

.github/workflows/nightly-benches.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
name: Nightly E2E tests run on testnet
3+
4+
on:
5+
schedule:
6+
- cron: '00 23 * * *'
7+
workflow_dispatch:
8+
9+
concurrency:
10+
group: "${{ github.ref }}-${{ github.workflow }}"
11+
cancel-in-progress: true
12+
13+
jobs:
14+
circuits-benches:
15+
name: Run benches for shielder-circuits crate
16+
# runs-on: [self-hosted, Linux, X64, large]
17+
runs-on: ubuntu-20.04
18+
timeout-minutes: 10
19+
env:
20+
RUSTC_WRAPPER: sccache
21+
steps:
22+
- name: Checkout source code
23+
uses: actions/checkout@v4
24+
25+
- name: Prepare Rust env
26+
uses: ./.github/actions/prepare-rust-env
27+
with:
28+
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
29+
30+
- name: Run benches for shielder-circuits
31+
run: make bench
32+
33+
slack-notification:
34+
name: Slack notification
35+
runs-on: ubuntu-22.04
36+
needs: [circuits-benches]
37+
if: >
38+
!cancelled() &&
39+
github.event_name != 'workflow_dispatch'
40+
steps:
41+
- name: Send Slack message
42+
uses: Cardinal-Cryptography/github-actions/slack-notification@v7
43+
with:
44+
notify-on: "failure"
45+
env:
46+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_ZKOS }}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: Main branch push or pull_request
3+
4+
on:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
workflow_dispatch:
10+
11+
concurrency:
12+
group: "${{ github.ref }}-${{ github.workflow }}"
13+
cancel-in-progress: true
14+
15+
jobs:
16+
17+
check-vars-and-secrets:
18+
name: Check vars and secrets
19+
uses: ./.github/workflows/_check-vars-and-secrets.yml
20+
secrets: inherit
21+
22+
rust-crates-checks:
23+
name: Rust crates checks
24+
uses: ./.github/workflows/_rust-crates-checks.yml
25+
secrets: inherit
26+
27+
measure-circuits:
28+
name: Measure circuits
29+
needs: [rust-crates-checks]
30+
uses: ./.github/workflows/_measure-circuits.yml
31+
secrets: inherit

.github/workflows/yaml-lint.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: GH Action YAML linter
3+
4+
on:
5+
pull_request:
6+
paths:
7+
- '.github/**.yml'
8+
- '.github/**.yaml'
9+
10+
concurrency:
11+
group: ${{ github.ref }}-${{ github.workflow }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
main:
16+
name: YAML Lint
17+
runs-on: ubuntu-22.04
18+
steps:
19+
- name: LINT | Execute YAML linter
20+
uses: Cardinal-Cryptography/github-actions/yaml-lint@v7

0 commit comments

Comments
 (0)