Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
66 changes: 0 additions & 66 deletions .github/workflows/formal-verification.yml

This file was deleted.

64 changes: 64 additions & 0 deletions .github/workflows/fv-certora.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Formal verification - Certora

on:
# Runs in the context of the base repository so that the CERTORAKEY secret is available to pull
# requests opened from forks. Access is gated by the `certora` environment, which requires a
# manual approval from a reviewer before the job starts. Reviewers MUST check the diff for
# anything that could exfiltrate the key before approving.
pull_request_target:
types:
- opened
- reopened
- synchronize
- labeled
workflow_dispatch: {}

Comment thread
Amxx marked this conversation as resolved.
Resolved
# `github.ref` is the base branch under `pull_request_target`, so key on the pull request number
concurrency: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}

jobs:
verify:
runs-on: ubuntu-latest
environment: certora
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')
steps:
- uses: actions/checkout@v7
Comment thread
Amxx marked this conversation as resolved.
Resolved
with:
# `pull_request_target` checks out the base by default. This runs the contributor's code,
# which is why the environment approval above is required.
ref: ${{ github.event.pull_request.head.sha || github.ref }}
fetch-depth: 0 # Include history so the diff against the PR base resolves
Comment thread
james-toussaint marked this conversation as resolved.
Resolved
- name: Set up environment
uses: ./.github/actions/setup
with:
solc: 'on'
java: 'on'
python: 'on'
python-requirements: 'fv-requirements.txt'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Might be safer to

  • checkout base
  • install requirements
  • checkout user branch
  • run tests

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That will cause issues if the user branch updates the dependencies. We would get the one from the base branch.

For example: there is a new version of certora, and we want to make a PR that updates the fv-requirements.txt and update the specs at the same time. That PR would not work because the FV flow would install the old requirements.

We are going to manually approve everytime anyway.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes in that case we need to push anything related to the config to a branch on the base repo, which I think is compatible with what we want to achieve: "run fv tests on untrusted/external contributor code"

- name: identify specs that need to be run
id: arguments
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: |
if [[ ${{ github.event_name }} = 'pull_request_target' && ${{ contains(github.event.pull_request.labels.*.name, 'formal-verification-force-all') }} = 'false' ]];
then
# Spec names come from the file names of a pull request that may be untrusted, and end
# up on a command line downstream. Anything that is not a plain name is dropped here.
RESULT=$(git diff "$HEAD_SHA".."$BASE_SHA" --name-only -- 'fv/specs/*.spec' | while IFS= read -r file; do
[[ -f $file ]] || continue
name=$(basename "${file%.spec}")
[[ $name =~ ^[A-Za-z0-9_-]+$ ]] && echo "$name" || echo "Ignoring spec with unexpected name: $name" >&2
done | tr "\n" " ")
else
RESULT='--all'
fi
Comment thread
Amxx marked this conversation as resolved.
Resolved
echo "result=$RESULT" >> "$GITHUB_OUTPUT"
- name: Verify specification
env:
SPEC_ARGUMENTS: ${{ steps.arguments.outputs.result }}
CERTORAKEY: ${{ secrets.CERTORAKEY }}
run: |
make -C fv apply
read -r -a specs <<< "$SPEC_ARGUMENTS"
node fv/run.js "${specs[@]}" -p 1 -v >> "$GITHUB_STEP_SUMMARY"
28 changes: 28 additions & 0 deletions .github/workflows/fv-halmos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Formal verification - Halmos

on:
pull_request:
types:
- opened
- reopened
- synchronize
- labeled
workflow_dispatch: {}

concurrency: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}

jobs:
halmos:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Set up environment
uses: ./.github/actions/setup
with:
foundry: 'on'
python: 'on'
python-requirements: 'fv-requirements.txt'
- name: Run Halmos
run: halmos --match-test '^symbolic|^testSymbolic' -vv
env:
HALMOS_ALLOW_DOWNLOAD: 1
6 changes: 4 additions & 2 deletions fv/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import fs from 'fs';
import pLimit from 'p-limit';
import { hideBin } from 'yargs/helpers';
import yargs from 'yargs/yargs';
import { exec } from 'child_process';
import { execFile } from 'child_process';

const { argv } = yargs(hideBin(process.argv))
.env('')
Expand Down Expand Up @@ -46,7 +46,9 @@ if (argv._.length == 0 && !argv.all) {
() =>
new Promise(resolve => {
if (argv.verbose) console.log(`[${i + 1}/${length}] Running ${conf}`);
exec(`certoraRun ${conf}`, (error, stdout, stderr) => {
// execFile (and not exec) so that the config name is passed as an argument and never
// interpreted by a shell: it may come from an untrusted pull request.
execFile('certoraRun', [conf], (error, stdout, stderr) => {
const match = stdout.match(
'https://prover.certora.com/output/[a-z0-9]+/[a-z0-9]+[?]anonymousKey=[a-z0-9]+',
);
Expand Down