Skip to content

Commit 1f3247e

Browse files
committed
CI: allow formal verification to run on pull requests from forks
Secrets are never passed to a workflow triggered by `pull_request` from a forked repository, so the Certora job could not run on external contributions: CERTORAKEY was always empty. Split the formal verification workflow in two: - `fv-certora.yml` runs the Certora job on `pull_request_target`, which executes in the context of the base repository and therefore has access to the secret. Access is gated behind the `certora` environment: with required reviewers configured, the job waits for a manual approval before it starts. Because the job checks out and runs the contributor's code, that approval is the security boundary and reviewers must check the diff for anything that could exfiltrate the key. Approval is requested again on every push to the pull request. - `fv-checks.yml` keeps `apply-diff` and `halmos` on plain `pull_request`. Neither needs a secret, so they should not sit behind an approval gate. Requires, on the repository settings side: a `certora` environment with required reviewers, holding CERTORAKEY as an environment secret, and removal of the repository-level CERTORAKEY so that other workflows can no longer reach it.
1 parent f646874 commit 1f3247e

3 files changed

Lines changed: 81 additions & 66 deletions

File tree

‎.github/workflows/formal-verification.yml‎

Lines changed: 0 additions & 66 deletions
This file was deleted.

‎.github/workflows/fv-certora.yml‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Formal verification - Certora
2+
3+
on:
4+
# Runs in the context of the base repository so that the CERTORAKEY secret is available to pull
5+
# requests opened from forks. Access is gated by the `certora` environment, which requires a
6+
# manual approval from a reviewer before the job starts. Reviewers MUST check the diff for
7+
# anything that could exfiltrate the key before approving.
8+
pull_request_target:
9+
types:
10+
- opened
11+
- reopened
12+
- synchronize
13+
- labeled
14+
workflow_dispatch: {}
15+
16+
# `github.ref` is the base branch under `pull_request_target`, so key on the pull request number
17+
concurrency: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
18+
19+
jobs:
20+
verify:
21+
runs-on: ubuntu-latest
22+
environment: certora
23+
if: github.event_name != 'pull_request_target' || contains(github.event.pull_request.labels.*.name, 'formal-verification') || contains(github.event.pull_request.labels.*.name, 'formal-verification-force-all')
24+
steps:
25+
- uses: actions/checkout@v7
26+
with:
27+
# `pull_request_target` checks out the base by default. This runs the contributor's code,
28+
# which is why the environment approval above is required.
29+
ref: ${{ github.event.pull_request.head.sha || github.ref }}
30+
fetch-depth: 0 # Include history so the diff against the PR base resolves
31+
- name: Set up environment
32+
uses: ./.github/actions/setup
33+
with:
34+
solc: 'on'
35+
java: 'on'
36+
python: 'on'
37+
python-requirements: 'fv-requirements.txt'
38+
- name: identify specs that need to be run
39+
id: arguments
40+
run: |
41+
if [[ ${{ github.event_name }} = 'pull_request_target' && ${{ contains(github.event.pull_request.labels.*.name, 'formal-verification-force-all') }} = 'false' ]];
42+
then
43+
RESULT=$(git diff ${{ github.event.pull_request.head.sha }}..${{ github.event.pull_request.base.sha }} --name-only fv/specs/*.spec | while IFS= read -r file; do [[ -f $file ]] && basename "${file%.spec}"; done | tr "\n" " ")
44+
else
45+
RESULT='--all'
46+
fi
47+
echo "result=$RESULT" >> "$GITHUB_OUTPUT"
48+
- name: Verify specification
49+
run: |
50+
make -C fv apply
51+
node fv/run.js ${{ steps.arguments.outputs.result }} -p 1 -v >> "$GITHUB_STEP_SUMMARY"
52+
env:
53+
CERTORAKEY: ${{ secrets.CERTORAKEY }}

‎.github/workflows/fv-halmos.yml‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Formal verification - Halmos
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- reopened
8+
- synchronize
9+
- labeled
10+
workflow_dispatch: {}
11+
12+
concurrency: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
13+
14+
jobs:
15+
halmos:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v7
19+
- name: Set up environment
20+
uses: ./.github/actions/setup
21+
with:
22+
foundry: 'on'
23+
python: 'on'
24+
python-requirements: 'fv-requirements.txt'
25+
- name: Run Halmos
26+
run: halmos --match-test '^symbolic|^testSymbolic' -vv
27+
env:
28+
HALMOS_ALLOW_DOWNLOAD: 1

0 commit comments

Comments
 (0)