|
| 1 | +name: Kani |
| 2 | + |
| 3 | +# Formal-verification proofs (https://github.com/model-checking/kani) for the |
| 4 | +# finance/ example programs. Each <program>/kani-proofs crate models its |
| 5 | +# program's pure money-math and lets the Kani model checker prove the invariants |
| 6 | +# exhaustively, in the spirit of aeyakovenko/percolator. |
| 7 | +# |
| 8 | +# WHY THIS RUNS ON A WEEKLY SCHEDULE, NOT ON EVERY PUSH/PR |
| 9 | +# ------------------------------------------------------- |
| 10 | +# Most of the finance proofs verify NONLINEAR 128-bit arithmetic (constant- |
| 11 | +# product curves, mul_div with a symbolic divisor, integer sqrt, pari-mutuel |
| 12 | +# payouts, share exchange rates). Kani is a bit-precise model checker: it |
| 13 | +# bit-blasts that arithmetic into SAT, and nonlinear / symbolic-divisor terms |
| 14 | +# are the worst case for the solver. Even with bounded inputs, individual |
| 15 | +# harnesses take tens of seconds and a full crate runs for minutes; the whole |
| 16 | +# finance suite is far too slow to gate every push/PR. So the heavy |
| 17 | +# `cargo kani` verification runs once a week (and on demand via |
| 18 | +# workflow_dispatch), while a fast unit-test job still runs on every push/PR to |
| 19 | +# catch model regressions early. See each finance/<program>/kani-proofs/README.md |
| 20 | +# for the per-harness bounds and timings. |
| 21 | + |
| 22 | +on: |
| 23 | + schedule: |
| 24 | + # Mondays at 06:00 UTC. Weekly because the proofs are slow (see header). |
| 25 | + - cron: "0 6 * * 1" |
| 26 | + workflow_dispatch: {} |
| 27 | + # Fast feedback only: the unit-test job below is gated to these events; the |
| 28 | + # slow `verify` job is gated to schedule / manual dispatch. |
| 29 | + push: |
| 30 | + branches: |
| 31 | + - main |
| 32 | + pull_request: |
| 33 | + types: [opened, synchronize, reopened] |
| 34 | + branches: |
| 35 | + - main |
| 36 | + |
| 37 | +concurrency: |
| 38 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 39 | + cancel-in-progress: true |
| 40 | + |
| 41 | +env: |
| 42 | + # See https://github.blog/changelog/2025-09-19-deprecation-of-node-20-on-github-actions-runners/ |
| 43 | + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true |
| 44 | + |
| 45 | +jobs: |
| 46 | + # Fast feedback on every push/PR: the proof crates compile and their plain |
| 47 | + # unit tests pass on stable, independently of the (slow) Kani toolchain. This |
| 48 | + # catches model regressions without paying for full verification. |
| 49 | + unit-tests: |
| 50 | + name: Proof unit tests (${{ matrix.program }}) |
| 51 | + runs-on: ubuntu-latest |
| 52 | + strategy: |
| 53 | + fail-fast: false |
| 54 | + matrix: |
| 55 | + program: |
| 56 | + - escrow |
| 57 | + - token-swap |
| 58 | + - order-book |
| 59 | + - lending |
| 60 | + - betting-market |
| 61 | + - vault-strategy |
| 62 | + - token-fundraiser |
| 63 | + steps: |
| 64 | + - uses: actions/checkout@v5 |
| 65 | + - uses: dtolnay/rust-toolchain@stable |
| 66 | + - name: Run unit tests |
| 67 | + working-directory: finance/${{ matrix.program }}/kani-proofs |
| 68 | + run: cargo test |
| 69 | + |
| 70 | + # The formal verification itself. SLOW (minutes per crate), so it only runs on |
| 71 | + # the weekly schedule or when triggered manually — never on push/PR. The |
| 72 | + # official Kani action installs the verifier + CBMC toolchain (with caching) |
| 73 | + # and runs `cargo kani` in each proof crate; any failed proof fails the job. |
| 74 | + verify: |
| 75 | + name: Kani proofs (${{ matrix.program }}) |
| 76 | + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' |
| 77 | + runs-on: ubuntu-latest |
| 78 | + strategy: |
| 79 | + fail-fast: false |
| 80 | + matrix: |
| 81 | + program: |
| 82 | + - escrow |
| 83 | + - token-swap |
| 84 | + - order-book |
| 85 | + - lending |
| 86 | + - betting-market |
| 87 | + - vault-strategy |
| 88 | + - token-fundraiser |
| 89 | + steps: |
| 90 | + - uses: actions/checkout@v5 |
| 91 | + - name: Run Kani |
| 92 | + uses: model-checking/kani-github-action@v1 |
| 93 | + with: |
| 94 | + working-directory: finance/${{ matrix.program }}/kani-proofs |
0 commit comments