Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Cardinal-Cryptography/zkOS-monorepo…
Browse files Browse the repository at this point in the history
… into sync-tests
  • Loading branch information
guspiel committed Jan 2, 2025
2 parents ab3ed18 + 29addb1 commit c12fe6b
Show file tree
Hide file tree
Showing 100 changed files with 4,003 additions and 6,176 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# required by oz-foundry-upgrades. See https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades/tree/main?tab=readme-ov-file#optional-custom-output-directory
FOUNDRY_OUT=artifacts
16 changes: 13 additions & 3 deletions .github/actions/shielder-relayer/deploy/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ inputs:
environment:
type: choice
options:
- testnet-dev
- testnet
- mainnet
- dev
- stage
- prod
required: true
overwrite-shielder-address:
description: Shielder address to replace the exist one
required: false

runs:
using: composite
Expand All @@ -44,6 +47,13 @@ runs:
with:
kustomize-version: ${{ inputs.kustomize-version }}

- name: Modify shielder address in the config map
if: ${{ inputs.overwrite-shielder-address != '' }}
shell: bash
run: |
yq -i '.data.SHIELDER_CONTRACT_ADDRESS="${{ inputs.overwrite-shielder-address }}"' \
aleph-apps/shielder-relayer/overlays/${{ inputs.environment }}/eu-central-1/configmap.yaml
- name: KUSTOMIZE | Update docker image tag
shell: bash
env:
Expand Down
49 changes: 49 additions & 0 deletions .github/scripts/gas_diff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import re

def parse_report(file_path):
data = {}
with open(file_path, 'r') as file:
for line in file:
match = re.match(r'(\w+):\s*(\d+)', line)
if match:
name, value = match.groups()
data[name] = int(value)
return data

def calculate_differences(main_data, current_data):
differences = []
for name in main_data:
main_value = main_data[name]
current_value = current_data.get(name, 0)
if main_value > 0:
difference = ((current_value - main_value) / main_value) * 100
else:
difference = 0 # handle case where main value is zero
differences.append((name, main_value, current_value, difference))
return differences

def generate_html_report(differences):
# Generate single-line HTML content without formatting
html_content = "<table><tr><th>Transaction Name</th><th>Main</th><th>Current</th><th>Difference (%)</th></tr>"
for name, main, current, diff in differences:
sign = '+' if diff > 0 else '-' if diff < 0 else ''
diff_value = f"{sign}{abs(diff):.5f}%"
html_content += f"<tr><td>{name}</td><td>{main}</td><td>{current}</td><td>{diff_value}</td></tr>"
html_content += "</table>"
return html_content

def main():
main_report_path = 'main-report.txt'
current_report_path = 'current-report.txt'

main_data = parse_report(main_report_path)
current_data = parse_report(current_report_path)
differences = calculate_differences(main_data, current_data)

html_report = generate_html_report(differences)

with open('report.html', 'w') as report_file:
report_file.write(html_report)

if __name__ == "__main__":
main()
7 changes: 7 additions & 0 deletions .github/workflows/_build-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,10 @@ jobs:
name: contract-artifacts
path: artifacts
retention-days: 1

- name: Upload generated build cache
uses: actions/upload-artifact@v4
with:
name: generated-build-cache
path: cache
retention-days: 1
54 changes: 34 additions & 20 deletions .github/workflows/_check-vars-and-secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ jobs:
- name: Check vars
run: |
if [[ \
-z '${{ vars.SHIELDER_CONTRACT_ADDRESS }}' || \
-z '${{ vars.KUSTOMIZE_VERSION }}' || \
-z '${{ vars.CI_TESTNET_ALICE_PUBLIC_KEY }} }}' || \
-z '${{ vars.CI_TESTNET_BOB_PUBLIC_KEY }} }}' || \
-z '${{ vars.CI_TESTNET_CHARLIE_PUBLIC_KEY }} }}' || \
-z '${{ vars.CI_TESTNET_TS_SDK_PUBLIC_KEY }} }}' || \
-z '${{ vars.CI_TESTNET_RELAYER_SIGNER_ADDRESSES }} }}' || \
-z '${{ vars.CI_TESTNET_FEE_DESTINATION }} }}'
-z '${{ vars.CI_TESTNET_ALICE_PUBLIC_KEY }}' || \
-z '${{ vars.CI_TESTNET_BOB_PUBLIC_KEY }}' || \
-z '${{ vars.CI_TESTNET_CHARLIE_PUBLIC_KEY }}' || \
-z '${{ vars.CI_TESTNET_FEE_DESTINATION }}' || \
-z '${{ vars.CI_TESTNET_RELAYER_SIGNER_ADDRESSES }}' || \
-z '${{ vars.CI_TESTNET_STAGE_OWNER_ADDRESS }}' || \
-z '${{ vars.CI_TESTNET_TS_SDK_PUBLIC_KEY }}' || \
-z '${{ vars.MAINNET_PROD_OWNER_ADDRESS }}' || \
-z '${{ vars.SHIELDER_CONTRACT_ADDRESS }}'
]]; then
echo '!!! Some repository variables are either missing or empty.'
echo '!!! Please check either repository or organization settings.'
Expand All @@ -30,26 +32,38 @@ jobs:
- name: Check secrets
run: |
if [[ \
-z '${{ secrets.ZKOS_CIRCUITS_SSH_PRIVATE_KEY }}' || \
-z '${{ secrets.SSH_PRIVATE_KEY }}' || \
-z '${{ secrets.VERCEL_ORG_ID }}' || \
-z '${{ secrets.VERCEL_PROJECT_ID }}' || \
-z '${{ secrets.VERCEL_TOKEN }}' || \
-z '${{ secrets.AWS_MAINNET_ECR_ACCESS_KEY_ID }}' || \
-z '${{ secrets.AWS_MAINNET_ECR_ACCESS_KEY }}' || \
-z '${{ secrets.ECR_PRIVATE_HOST }}' || \
-z '${{ secrets.AUTOCOMMIT_AUTHOR }}' || \
-z '${{ secrets.AUTOCOMMIT_EMAIL }}' || \
-z '${{ secrets.AWS_MAINNET_ECR_ACCESS_KEY_ID }}' || \
-z '${{ secrets.CI_GH_TOKEN }}' || \
-z '${{ secrets.SLACK_WEBHOOK_ZKOS }}' || \
-z '${{ secrets.CI_TESTNET_DEPLOYER_PRIVATE_KEY }}' || \
-z '${{ secrets.CI_MAINNET_DEPLOYER_PRIVATE_KEY }}' || \
-z '${{ secrets.CI_TESTNET_ALICE_PRIVATE_KEY }}' || \
-z '${{ secrets.CI_TESTNET_BOB_PRIVATE_KEY }}' || \
-z '${{ secrets.CI_TESTNET_CHARLIE_PRIVATE_KEY }}' || \
-z '${{ secrets.CI_TESTNET_TS_SDK_PRIVATE_KEY }}' || \
-z '${{ secrets.CI_TESTNET_DEPLOYER_PRIVATE_KEY }}' || \
-z '${{ secrets.CI_TESTNET_FEE_DESTINATION_KEY }}' || \
-z '${{ secrets.CI_TESTNET_RELAYER_SIGNING_KEYS }}' || \
-z '${{ secrets.NPM_PUBLISHING_KEY }}'
-z '${{ secrets.CI_TESTNET_TS_SDK_PRIVATE_KEY }}' || \
-z '${{ secrets.NPM_PUBLISHING_KEY }}' || \
-z '${{ secrets.SLACK_WEBHOOK_ZKOS }}' || \
-z '${{ secrets.VERCEL_ORG_ID }}' || \
-z '${{ secrets.VERCEL_PROJECT_ID }}' || \
-z '${{ secrets.VERCEL_TOKEN }}' || \
-z '${{ secrets.ZKOS_CIRCUITS_SSH_PRIVATE_KEY }}' || \
-z '${{ secrets.AUTOCOMMIT_AUTHOR }}' || \
-z '${{ secrets.AUTOCOMMIT_EMAIL }}' || \
-z '${{ secrets.CONTRACTS_S3BUCKET_NAME }}' || \
-z '${{ secrets.CONTRACTS_S3BUCKET_REGION }}' || \
-z '${{ secrets.CONTRACTS_ZKOS_ADDRESSES_MAINNET_PROD_RW_AWS_ACCESS_KEY_ID }}' || \
-z '${{ secrets.CONTRACTS_ZKOS_ADDRESSES_MAINNET_PROD_RW_AWS_SECRET_ACCESS_KEY }}' || \
-z '${{ secrets.CONTRACTS_ZKOS_ADDRESSES_TESTNET_DEV_RW_AWS_ACCESS_KEY_ID }}' || \
-z '${{ secrets.CONTRACTS_ZKOS_ADDRESSES_TESTNET_DEV_RW_AWS_SECRET_ACCESS_KEY }}' || \
-z '${{ secrets.CONTRACTS_ZKOS_ADDRESSES_TESTNET_STAGE_RW_AWS_ACCESS_KEY_ID }}' || \
-z '${{ secrets.CONTRACTS_ZKOS_ADDRESSES_TESTNET_STAGE_RW_AWS_SECRET_ACCESS_KEY }}' || \
-z '${{ secrets.CONTRACTS_ZKOS_ARTIFACTS_RW_AWS_ACCESS_KEY_ID }}' || \
-z '${{ secrets.CONTRACTS_ZKOS_ARTIFACTS_RW_AWS_SECRET_ACCESS_KEY }}' || \
-z '${{ secrets.ECR_PRIVATE_HOST }}' || \
-z '${{ secrets.SSH_PRIVATE_KEY }}'
]]; then
echo '!!! Some repository secrets are either missing or empty.'
echo '!!! Please check either repository or organization settings.'
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/_deploy-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ jobs:
name: contract-artifacts
path: artifacts

- name: Download generated build cache
uses: actions/download-artifact@v4
with:
name: generated-build-cache
path: cache

- name: deploy eth contracts
shell: bash
run: NETWORK=anvil make deploy-contracts
100 changes: 100 additions & 0 deletions .github/workflows/_measure-gas.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
name: Measure gas

on:
workflow_dispatch:
workflow_call:

jobs:
main:
name: Measure circuits
runs-on: [self-hosted, Linux, X64, large]
timeout-minutes: 20
steps:

- name: Checkout code (from the current branch)
uses: actions/checkout@v4

- name: Prepare Rust env
uses: ./.github/actions/prepare-rust-env
with:
poseidon-gadget-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
zkos-circuits-private-key: ${{ secrets.ZKOS_CIRCUITS_SSH_PRIVATE_KEY }}

- name: Setup node
uses: asdf-vm/actions/install@v3

- name: Install solc compiler
uses: ./.github/actions/install-solc
with:
solc-version: 0.8.26

- name: Build binary
run: cargo build -p integration-tests --bin gas-consumption --release

#################### Run measurements on the current branch ####################

- name: Install dependencies
run: make deps

- name: Generate all contracts
run: make generate-contracts

- name: Run measure-circuits binary on the current branch
run: |
export CONTRACTS_DIR="contracts"
export CARGO_MANIFEST_DIR=./Cargo.toml
./target/release/gas-consumption current-report.txt
- name: Print gas measured on the current branch
run: cat current-report.txt

#################### Run measurements on the main branch ####################

- name: Checkout repository from `main`
uses: actions/checkout@v4
with:
ref: main
path: main

- name: Install dependencies
run: |
cd main
make deps
- name: Generate all contracts
run: |
cd main
make generate-contracts
- name: Run measure-circuits on the `main` branch
run: |
export CONTRACTS_DIR="main/contracts"
export CARGO_MANIFEST_DIR=./main/Cargo.toml
./target/release/gas-consumption main-report.txt
- name: Print gas measured on the `main` branch
run: cat main-report.txt

#################### Generate report ####################

- name: Install Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install python deps
run: pip install prettytable

- name: Run metrics-diff-presenter script
run: python3 .github/scripts/gas_diff.py > report.html

- name: Print gas report with diff
run: cat report.html

- name: Post measurements difference
uses: thollander/actions-comment-pull-request@v3
with:
file-path: report.html
comment-tag: hashFiles('report.html')

12 changes: 12 additions & 0 deletions .github/workflows/_rust-crates-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ jobs:
name: contract-artifacts
path: artifacts

- name: Download generated build cache
uses: actions/download-artifact@v4
with:
name: generated-build-cache
path: cache

- name: Prepare Rust env
uses: ./.github/actions/prepare-rust-env
with:
Expand Down Expand Up @@ -86,6 +92,12 @@ jobs:
name: contract-artifacts
path: artifacts

- name: Download generated build cache
uses: actions/download-artifact@v4
with:
name: generated-build-cache
path: cache

- name: Prepare Rust env
uses: ./.github/actions/prepare-rust-env
with:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/_ts-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ jobs:
name: crates-shielder-wasm-pkg
path: crates/shielder-wasm/pkg

- name: Download generated build cache
uses: actions/download-artifact@v4
with:
name: generated-build-cache
path: cache

- name: Install Node.js
uses: actions/setup-node@v4
with:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/_ts-sdk-playwright-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ jobs:
name: crates-shielder-wasm-pkg
path: crates/shielder-wasm/pkg

- name: Download generated build cache
uses: actions/download-artifact@v4
with:
name: generated-build-cache
path: cache

- name: Download binary from artifacts
uses: actions/download-artifact@v4
with:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
name: "[PROD] Build and deploy shielder-relayer"

on:
workflow_dispatch:
inputs:
overwrite-shielder-address:
type: string
required: false
default: ''
description: Overwrite shielder address - if empty it's not changed

jobs:
build-and-push:
name: Build and push shielder-relayer
runs-on: [self-hosted, Linux, X64, medium]
steps:
- name: GIT | Checkout
uses: actions/checkout@v4

- name: Prepare Rust env
uses: ./.github/actions/prepare-rust-env
with:
poseidon-gadget-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
zkos-circuits-private-key: ${{ secrets.ZKOS_CIRCUITS_SSH_PRIVATE_KEY }}

- name: Build relayer
run: cd crates/shielder-relayer && make build

- name: DOCKER | Build and push
uses: ./.github/actions/shielder-relayer/build-and-push
id: build_shielder_relayer
with:
aws-mainnet-ecr-access-key-id: ${{ secrets.AWS_MAINNET_ECR_ACCESS_KEY_ID }}
aws-mainnet-ecr-access-key: ${{ secrets.AWS_MAINNET_ECR_ACCESS_KEY }}
ecr-private-host: ${{ secrets.ECR_PRIVATE_HOST }}
outputs:
image_tag: ${{ steps.build_shielder_relayer.outputs.image_tag }}

deploy:
name: Deploy shielder-relayer
needs: [build-and-push]
runs-on: [self-hosted, Linux, X64, medium]
steps:
- name: GIT | Checkout
uses: actions/checkout@v4

- name: KUSTOMIZE | Deploy
uses: ./.github/actions/shielder-relayer/deploy
id: deploy_shielder_relayer
with:
environment: prod
image-tag: ${{ needs.build-and-push.outputs.image_tag }}
autocommit-author: ${{ secrets.AUTOCOMMIT_AUTHOR }}
autocommit-email: ${{ secrets.AUTOCOMMIT_EMAIL }}
github-token: ${{ secrets.CI_GH_TOKEN }}
kustomize-version: ${{ vars.KUSTOMIZE_VERSION }}
ecr-private-host: ${{ secrets.ECR_PRIVATE_HOST }}
overwrite-shielder-address: ${{ inputs.overwrite-shielder-address }}
Loading

0 comments on commit c12fe6b

Please sign in to comment.