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

Integrate risc0-ethereum on CI #1525

Merged
merged 56 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
a2ff808
add risc0-ethereum CI workflow
capossele Mar 7, 2024
1f13d64
fix typo
capossele Mar 7, 2024
f512624
update base filter
capossele Mar 7, 2024
35bb77f
fix CI
capossele Mar 7, 2024
0d3ec77
add foundry-template test on CI
capossele Mar 7, 2024
bcecdc1
add workflow_dispatch
capossele Mar 7, 2024
739638b
Merge remote-tracking branch 'origin/main' into capossele/risc0-ether…
capossele Mar 8, 2024
f3c30f4
use local override
capossele Mar 8, 2024
bf95f0b
setup python
capossele Mar 8, 2024
e8b32c1
revert lib/risc0-ethereum
capossele Mar 8, 2024
e45518d
add FEATURE env
capossele Mar 8, 2024
9ac02ed
fix strategy
capossele Mar 8, 2024
88a9ae0
add local_override script
capossele Mar 8, 2024
6e6f25b
testing risc0-ethereum/capossele/risc0-CI
capossele Mar 8, 2024
28bce1a
update workflow
capossele Mar 8, 2024
45eea52
clean Cargo.locks
capossele Mar 8, 2024
d311fe3
cargo update
capossele Mar 8, 2024
991f8e2
use cargo test
capossele Mar 8, 2024
7f54cf2
unset RISC0_BUILD_LOCKED
capossele Mar 8, 2024
dc217f2
drop RISC0_BUILD_LOCKED
capossele Mar 8, 2024
694f3ca
patch lib/risc0-ethereum
capossele Mar 8, 2024
4134207
patch lib/risc0-ethereum
capossele Mar 11, 2024
a57b263
fix risczero toolchain
capossele Mar 11, 2024
774db5e
fix typo
capossele Mar 11, 2024
d506f33
refactor bootstrap-groth16
capossele Mar 11, 2024
024066b
add verifier contract check
capossele Mar 11, 2024
a86a8c0
drop ethereum
capossele Mar 11, 2024
760d628
update bonsai Cargo.lcok
capossele Mar 11, 2024
134959e
Merge branch 'main' into capossele/risc0-ethereum-CI
capossele Mar 11, 2024
b769ee3
drop old ethereum checks
capossele Mar 11, 2024
fe8d128
revert dropping foundry from website-test 0.20
capossele Mar 12, 2024
4e0cc5a
pin governance links to 0.20
capossele Mar 12, 2024
ef8c545
fix ceremony
capossele Mar 14, 2024
dcd0dd9
use dep mapping
capossele Mar 14, 2024
b96a6d4
Merge remote-tracking branch 'origin/main' into capossele/risc0-ether…
capossele Mar 14, 2024
37e5a95
update Cargo locks
capossele Mar 14, 2024
6820353
update toolchain
capossele Mar 14, 2024
5b137a8
rename
capossele Mar 14, 2024
4592a59
use main as default
capossele Mar 14, 2024
6eae739
make cargo_local_patch script more reliable
capossele Mar 15, 2024
035304d
reorganize risc0-ethereum CI workflow
capossele Mar 15, 2024
7df2fb4
remove default value for risc0_ethereum_path
capossele Mar 15, 2024
bb3ee8f
fix typo
capossele Mar 15, 2024
edf5618
Apply suggestions from code review
capossele Mar 15, 2024
f553639
testing
capossele Mar 15, 2024
50c3afd
testing
capossele Mar 15, 2024
a402420
testing
capossele Mar 15, 2024
ba6a787
fix foundry dep
capossele Mar 18, 2024
323889e
Merge branch 'main' into capossele/risc0-ethereum-CI
capossele Mar 18, 2024
c47c239
add paths
capossele Mar 18, 2024
75c3c8a
fix typo
capossele Mar 18, 2024
378ab67
fix typo
capossele Mar 18, 2024
8a5f764
fix working directory
capossele Mar 18, 2024
384c801
use main as default
capossele Mar 18, 2024
58050b3
Update .github/cargo_local_patch.py
capossele Mar 19, 2024
8c3c9fe
Merge branch 'main' into capossele/risc0-ethereum-CI
capossele Mar 19, 2024
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
109 changes: 109 additions & 0 deletions .github/cargo_local_patch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import argparse
import toml
import os
import fnmatch

def find_cargo_toml_files(start_path):
matches = []
for root, _, filenames in os.walk(start_path):
for filename in fnmatch.filter(filenames, 'Cargo.toml'):
matches.append(os.path.join(root, filename))
return matches

def is_subdirectory(path, of_directory):
absolute_path = os.path.abspath(path)
absolute_of_directory = os.path.abspath(of_directory)
return absolute_path.startswith(absolute_of_directory)

def modify_dependency(details, new_path, start_directory):
# If details is a string, it's in the simple format. Convert it to a dictionary.
if isinstance(details, str):
details = {'version': details} # Convert to dictionary with version key
# Now details is guaranteed to be a dictionary
# Skip if the depdendency uses the workspace definition
if details.get('workspace') is not True:
current_path = details.get('path')
if current_path and is_subdirectory(current_path, start_directory):
# If the current path is a subdirectory of the start_directory, do not modify it.
return details

details['path'] = new_path
details.pop('version', None)
details.pop('git', None)
details.pop('rev', None)
details.pop('branch', None)
return details

# Modify the list of dependencies in-place, setting a path reference for those in the mapping.
def process_dependencies(dependencies, base_path, dep_path_mapping, start_directory):
for dep, details in dependencies.items():
# Check if a dep starts with "risc0-" or "bonsai-" and is not in the mapping.
# This should make sure to patch all the dependencies or fail if new are found.
if (dep.startswith("risc0-") or dep.startswith("bonsai-")) and dep not in dep_path_mapping:
raise ValueError(f"Dependency '{dep}' starts with 'risc0-' or 'bonsai-' but is not in dep_path_mapping.")
if dep in dep_path_mapping:
new_path = os.path.join(base_path, dep_path_mapping[dep])
if not os.path.exists(new_path):
raise FileNotFoundError(f"The path {new_path} does not exist.")
new_details = modify_dependency(details, new_path, start_directory)
dependencies[dep] = new_details

def process_cargo_file(cargo_toml_path, dep_path_mapping, start_directory):
base_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../")

with open(cargo_toml_path, 'r') as file:
data = toml.load(file)

# Process regular dependencies
if 'dependencies' in data:
nategraf marked this conversation as resolved.
Show resolved Hide resolved
process_dependencies(data['dependencies'], base_path, dep_path_mapping, start_directory)
# Process development dependencies
if 'dev-dependencies' in data:
process_dependencies(data['dev-dependencies'], base_path, dep_path_mapping, start_directory)
# Process build dependencies
if 'build-dependencies' in data:
process_dependencies(data['build-dependencies'], base_path, dep_path_mapping, start_directory)
# Process workspace dependencies, if present
if 'workspace' in data and 'dependencies' in data['workspace']:
process_dependencies(data['workspace']['dependencies'], base_path, dep_path_mapping, start_directory)

with open(cargo_toml_path, 'w') as file:
toml.dump(data, file)

def main(directory, dep_path_mapping):
cargo_toml_files = find_cargo_toml_files(directory)
for cargo_toml_path in cargo_toml_files:
process_cargo_file(cargo_toml_path, dep_path_mapping, directory)

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Modify dependencies in Cargo.toml files within a directory.")
parser.add_argument("directory", help="Directory to search for Cargo.toml files")
args = parser.parse_args()

# Define risc0, risc0-ethereum and bonsai dependencies and their paths here
# Add more dependencies and paths as needed
dep_path_mapping = {
"bonsai-rest-api-mock": "risc0/bonsai/rest-api-mock",
"bonsai-sdk": "risc0/bonsai/sdk",
"risc0-binfmt": "risc0/risc0/binfmt",
"risc0-build": "risc0/risc0/build",
"risc0-build-kernel": "risc0/risc0/build_kernel",
"risc0-circuit-recursion": "risc0/risc0/circuit/recursion",
"risc0-circuit-recursion-sys": "risc0/risc0/circuit/recursion-sys",
"risc0-circuit-rv32im": "risc0/risc0/circuit/rv32im",
"risc0-circuit-rv32im-sys": "risc0/risc0/circuit/rv32im-sys",
"risc0-core": "risc0/risc0/core",
"risc0-groth16": "risc0/risc0/groth16",
"risc0-r0vm": "risc0/risc0/r0vm",
"risc0-sys": "risc0/risc0/sys",
"risc0-zkp": "risc0/risc0/zkp",
"risc0-zkvm": "risc0/risc0/zkvm",
"risc0-zkvm-platform": "risc0/risc0/zkvm/platform",
"risc0-ethereum-contracts": "risc0-ethereum/contracts",
"risc0-build-ethereum": "risc0-ethereum/build",
"risc0-forge-ffi": "risc0-ethereum/ffi",
"risc0-ethereum-relay": "risc0-ethereum/relay",
"risc0-ethereum-relay-test-methods": "risc0-ethereum/relay/tests/methods",
}

main(os.path.normpath(args.directory), dep_path_mapping)
35 changes: 0 additions & 35 deletions .github/workflows/bonsai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,56 +53,21 @@ jobs:
uses: actions/checkout@v4
with:
lfs: true
submodules: recursive

# Install dependencies.
- uses: ./.github/actions/rustup
- uses: ./.github/actions/sccache
with:
key: Linux-default

- name: Install Foundry
nategraf marked this conversation as resolved.
Show resolved Hide resolved
uses: risc0/foundry-toolchain@2fe7e70b520f62368a0e3c464f997df07ede420f
with:
version: nightly-09fe3e041369a816365a020f715ad6f94dbce9f2

- name: Cargo install cargo-risczero
run: cargo install --force --path risc0/cargo-risczero

- run: cargo risczero install --version $RISC0_TOOLCHAIN_VERSION

# Lint
- name: check solidity code formatting in bonsai/ethereum
run: forge fmt --check
working-directory: bonsai/ethereum

- name: check solidity code formatting in bonsai/examples/governance
run: forge fmt --check
working-directory: bonsai/examples/governance

# Test
- name: run cargo tests in bonsai
run: cargo test --locked -- --include-ignored --nocapture
working-directory: bonsai

- name: run cargo tests in bonsai/examples/governance
run: cargo test --locked
working-directory: bonsai/examples/governance

- name: run forge tests in bonsai/ethereum
run: forge test -vvv
working-directory: bonsai/ethereum

- name: run forge tests without the zkVM in bonsai/examples/governance
env:
TEST_USE_ZKVM: false
run: forge test -vvv
working-directory: bonsai/examples/governance

- name: run forge tests with the zkvm in bonsai/examples/governance
env:
TEST_USE_ZKVM: true
run: forge test -vvv
working-directory: bonsai/examples/governance

- run: sccache --show-stats
11 changes: 0 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,12 @@ jobs:
- run: cargo fmt --all --check
- run: cargo fmt --all --check --manifest-path benchmarks/Cargo.toml
- run: cargo fmt --all --check --manifest-path bonsai/Cargo.toml
- run: cargo fmt --all --check --manifest-path bonsai/examples/governance/Cargo.toml
- run: cargo fmt --all --check --manifest-path examples/Cargo.toml
- run: cargo fmt --all --check --manifest-path tools/crates-validator/Cargo.toml
- run: cargo clippy -p risc0-zkvm
- run: cargo sort --workspace --check
- run: cargo sort --workspace --check benchmarks
- run: cargo sort --workspace --check bonsai
- run: cargo sort --workspace --check bonsai/examples/governance
- run: cargo sort --workspace --check examples
- run: cargo sort --workspace --check tools/crates-validator
- run: cargo rdme -c
Expand Down Expand Up @@ -189,15 +187,11 @@ jobs:
run: |
cargo test -F $FEATURE -F prove --workspace --timings --no-run \
--exclude doc-test \
--exclude bonsai-ethereum-contracts \
--exclude bonsai-ethereum-relay \
--exclude bonsai-rest-api-mock
- name: test workspace
run: |
cargo test -F $FEATURE -F prove --workspace --timings \
--exclude doc-test \
--exclude bonsai-ethereum-contracts \
--exclude bonsai-ethereum-relay \
--exclude bonsai-rest-api-mock
- uses: actions/upload-artifact@v3
with:
Expand All @@ -213,8 +207,6 @@ jobs:
- run: |
cargo check -F $FEATURE --benches --workspace \
--exclude doc-test \
--exclude bonsai-ethereum-contracts \
--exclude bonsai-ethereum-relay \
--exclude bonsai-rest-api-mock
- run: cargo check -p risc0-build
if: matrix.device == 'cpu'
Expand Down Expand Up @@ -283,9 +275,6 @@ jobs:
- run: "git checkout -f $(git -c user.name=x -c user.email=x@x commit-tree $(git hash-object -t tree /dev/null) < /dev/null) || :"
- uses: actions/checkout@v4
- uses: ./.github/actions/rustup
- uses: risc0/foundry-toolchain@2fe7e70b520f62368a0e3c464f997df07ede420f
with:
version: nightly-09fe3e041369a816365a020f715ad6f94dbce9f2
- uses: ./.github/actions/sccache
with:
key: macOS-default
Expand Down
157 changes: 157 additions & 0 deletions .github/workflows/risc0-ethereum.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
name: risc0-ethereum CI

on:
merge_group:
pull_request:
branches: [main, "release-*"]
workflow_dispatch:
inputs:
risc0-ethereum-branch:
description: "risc0-ethereum branch to checkout"
required: false
default: 'main'
bonsai-foundry-template-branch:
description: "bonsai-foundry-template branch to checkout"
required: false
default: 'main'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

# this is needed to gain access via OIDC to the S3 bucket for caching
permissions:
id-token: write
contents: read

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RISC0_TOOLCHAIN_VERSION: v2024-02-08.1
RISC0_PATH: ${{ github.workspace }}/risc0
RISC0_ETHEREUM_PATH: ${{ github.workspace }}/risc0-ethereum
BONSAI_FOUNDRY_TEMPLATE_PATH: ${{ github.workspace }}/bonsai-foundry-template

jobs:
changes:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
test: ${{ steps.filter.outputs.test }}
steps:
- uses: actions/checkout@v4
- uses: risc0/paths-filter@4067d885736b84de7c414f582ac45897079b0a78
id: filter
with:
filters: |
base: &base
- .github/actions/**
- .github/workflows/risc0-ethereum.yml
- Cargo.toml
- rust-toolchain.toml
- Cargo.lock
test:
- *base
- bonsai/**
- risc0/**

# see: https://github.com/orgs/community/discussions/26822
risc0-ethereum-status-check:
if: always()
needs:
- test
runs-on: ubuntu-latest
steps:
- name: Check all job status
# see https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#needs-context
# see https://stackoverflow.com/a/67532120/4907315
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
run: exit 1

test:
if: ${{ needs.changes.outputs.test == 'true' || github.event_name == 'workflow_dispatch'}}
needs: changes
runs-on: [self-hosted, prod, Linux, cpu, docker]
env:
RUST_BACKTRACE: full
steps:
# This is a workaround from: https://github.com/actions/checkout/issues/590#issuecomment-970586842
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another comment, no action needed at this time: so now that we don't have any sub-modules in risc0, we could consider dropping this workaround. We can still keep it around though

- run: "git checkout -f $(git -c user.name=x -c user.email=x@x commit-tree $(git hash-object -t tree /dev/null) < /dev/null) || :"
# Checkout risc0
- uses: actions/checkout@v4
with:
path: 'risc0'
# Checkout risc0-ethereum
- name: Checkout risc0-ethereum
uses: actions/checkout@v4
with:
repository: 'risc0/risc0-ethereum'
token: ${{ secrets.GITHUB_TOKEN }}
submodules: recursive
path: 'risc0-ethereum'
ref: ${{ github.event.inputs.risc0-ethereum-branch || 'main' }}
# Checkout bonsai-foundry-template
- name: Checkout foundry-template
uses: actions/checkout@v4
with:
repository: 'risc0/bonsai-foundry-template'
token: ${{ secrets.GITHUB_TOKEN }}
submodules: recursive
path: 'bonsai-foundry-template'
ref: ${{ github.event.inputs.bonsai-foundry-template-branch || 'main' }}
- uses: ./risc0/.github/actions/rustup
- uses: ./risc0/.github/actions/sccache
with:
key: Linux-default
# Installing dev tooling
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install python dependencies
run: python -m pip install --upgrade toml
- name: Install risczero toolchain
run: |
cargo install --force --path risc0/cargo-risczero
cargo risczero install --version $RISC0_TOOLCHAIN_VERSION
working-directory: risc0
- uses: risc0/foundry-toolchain@2fe7e70b520f62368a0e3c464f997df07ede420f
with:
version: nightly-09fe3e041369a816365a020f715ad6f94dbce9f2
# Apply local patch
- name: Local patch on risc0-ethereum
run: python ${{ env.RISC0_PATH }}/.github/cargo_local_patch.py .
working-directory: ${{ env.RISC0_ETHEREUM_PATH }}
- name: Local patch on bonsai-foundry-template
run: python ${{ env.RISC0_PATH }}/.github/cargo_local_patch.py .
working-directory: ${{ env.BONSAI_FOUNDRY_TEMPLATE_PATH }}
# Run Bootstrap-groth16 to update test receipt for checking
# the latest groth16 prover against the solidity verifier on risc0-ethereum
- name: Bootstrap-groth16 test receipt
run: cargo xtask bootstrap-groth16 --test-receipt-only
nategraf marked this conversation as resolved.
Show resolved Hide resolved
env:
RISC0_ETHEREUM_PATH: ${{ env.RISC0_ETHEREUM_PATH }}
working-directory: ${{ env.RISC0_PATH }}
# Build and test risc0-ethereum
- name: build risc0-ethereum
run: cargo test --workspace --no-run
working-directory: ${{ env.RISC0_ETHEREUM_PATH }}
- name: test risc0-ethereum
run: cargo test --workspace
working-directory: ${{ env.RISC0_ETHEREUM_PATH }}
- name: forge test on risc0-ethereum
run: forge test -vvv
working-directory: ${{ env.RISC0_ETHEREUM_PATH }}/contracts
# Build and test bonsai-foundry-template
- name: build bonsai-foundry-template
run: cargo build
working-directory: ${{ env.BONSAI_FOUNDRY_TEMPLATE_PATH }}
- name: build bonsai-foundry-template contracts
run: forge build
working-directory: ${{ env.BONSAI_FOUNDRY_TEMPLATE_PATH }}
- name: run foundry tests in dev mode
env:
RISC0_DEV_MODE: true
run: forge test -vvv
working-directory: ${{ env.BONSAI_FOUNDRY_TEMPLATE_PATH }}
- run: sccache --show-stats
Loading
Loading