Skip to content

Commit 50cb1b7

Browse files
rod-chapmanhanno-becker
authored andcommitted
Apply and demo --external-smt2-solver in CBMC proof of polyvec_add()
1. Adds new Z3 "wrapper" scripts z3_smt_only and z3_bv_sort in proofs/cbmc/lib 2. Update the Makefile for the proof of polyvec_add() to select "z3_bv_sort" prover wrapper. 3. Update Proof Guide to explain how --external-smt2-solver works. On r7g instance, proof time when K=4 reduces from 300 to 100s. Signed-off-by: Rod Chapman <rodchap@amazon.com> Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
1 parent 07addea commit 50cb1b7

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

proofs/cbmc/lib/z3_bv_sort

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
# Copyright (c) The mlkem-native project authors
3+
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
4+
z3 rewriter.bv_sort_ac=true "$@"

proofs/cbmc/lib/z3_smt_only

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
# Copyright (c) The mlkem-native project authors
3+
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
4+
z3 tactic.default_tactic=smt "$@"

proofs/cbmc/polyvec_add/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ USE_DYNAMIC_FRAMES=1
2626

2727
# Disable any setting of EXTERNAL_SAT_SOLVER, and choose SMT backend instead
2828
EXTERNAL_SAT_SOLVER=
29-
CBMCFLAGS=--smt2
29+
CBMCFLAGS=--external-smt2-solver $(PROOF_ROOT)/lib/z3_bv_sort --z3
3030

3131
# For this proof we tell CBMC to
3232
# - not decompose arrays into their individual cells

proofs/cbmc/proof_guide.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,40 @@ This is not helpful when trying to understand a failed proof. Bitwuzla works bet
357357
Once a proof is working OK, you may revert to Z3 to check if it _also_ passes with Z3, and perhaps faster. If it does,
358358
then keep Z3 as the selected prover. If not, then stick with Bitwuzla.
359359
360+
#### Selecting custom options for Z3 or Bitwuzla
361+
362+
By default, CBMC invokes provers with no special command-line options. If you want to pass additional flags to the prover,
363+
e.g. to improve proof performance, you can create a small wrapper script and pass it to CBMC via `--external-smt2-solver XXX` (introduced in 6.8.0).
364+
365+
An example of such a script is [lib/z3_smt_only](lib/z3_smt_only) which looks like this:
366+
367+
```
368+
#!/bin/bash
369+
z3 tactic.default_tactic=smt "$@"
370+
```
371+
372+
There is also a script [lib/z3_bv_sort](lib/z3_bv_sort) which looks like this:
373+
374+
```
375+
#!/bin/bash
376+
z3 rewriter.bv_sort_ac "$@"
377+
```
378+
379+
Both these extra options have been found to be effective in improving Z3's performance in some cases.
380+
381+
To select the special prover, we update the proof `Makefile` for a particular function, replacing the
382+
`--smt2` or `--bitwuzla` option with `--external-smt2-solver`. For example, the proof of
383+
`polyvec_add()` is much faster using the `z3_bv_sort` wrapper, so we change the `Makefile`, replacing
384+
385+
```
386+
CBMCFLAGS=--smt2
387+
```
388+
with
389+
```
390+
CBMCFLAGS=--external-smt2-solver $(PROOF_ROOT)/lib/z3_bv_sort --z3
391+
```
392+
Note that we still need the ``--z3`` option now to inform CBMC to generate SMTLib specifically for Z3.
393+
360394
### Update harness function
361395
362396
The file `XXX_harness.c` should declare a single function called `XXX_harness()` that calls `XXX` exactly once, with

0 commit comments

Comments
 (0)