Skip to content

Verification crashes or gives wrong answer when using external SAT solver #1962

Description

@aaronbembenek-aws

Verification either crashes or gives a wrong answer when using Kani/CBMC with an external SAT solver.

I tried this code:

#[kani::proof]
fn ok_harness() {
    Vec::<u8>::with_capacity(0);
}

#[kani::proof]
fn failing_harness() {
    Vec::<u8>::with_capacity(1);
}

using the following command line invocations:

kani file.rs --harness failing_harness
kani file.rs --harness failing_harness --enable-unstable --cbmc-args --external-sat-solver cryptominisat5
kani file.rs --harness failing_harness --enable-unstable --cbmc-args --external-sat-solver kissat

with Kani version: 0.16.0 (886618c)
CBMC version: 5.71.0
cryptominisat version: 5.11.4
kissat version: 3.0.0

I expected to see this happen: get the same result as when running without setting an external solver. That is, verification succeeds with this result:

Checking harness failing_harness...
CBMC 5.71.0 (cbmc-5.71.0-80-gfc535f5794)
CBMC version 5.71.0 (cbmc-5.71.0-80-gfc535f5794) 64-bit arm64 macos
Reading GOTO program from file src/lib.for-failing_harness.out
Generating GOTO Program
Adding CPROVER library (arm64)
Removal of function pointers and virtual functions
Generic Property Instrumentation
Running with 16 object bits, 48 offset bits (user-specified)
Starting Bounded Model Checking
Unwinding loop _RNvNvMNtNtCsjQj7SZ039iX_4core5alloc6layoutNtB4_6Layout5array5innerCseZu4mTrUShQ_3lib.0 iteration 1 file /Users/aaronbem/.rustup/toolchains/nightly-2022-11-20-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/alloc/layout.rs line 438 column 16 function std::alloc::Layout::array::inner thread 0
Unwinding loop _ZN4core6option15Option$LT$T$GT$5ok_or17hed45a4caf2c9dfa2E.1 iteration 1 file /Users/aaronbem/.rustup/toolchains/nightly-2022-11-20-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs line 1055 column 5 function std::option::Option::<std::ptr::NonNull<u8>>::ok_or::<std::alloc::AllocError> thread 0
Unwinding loop _ZN4core6option15Option$LT$T$GT$5ok_or17hed45a4caf2c9dfa2E.0 iteration 1 file /Users/aaronbem/.rustup/toolchains/nightly-2022-11-20-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs line 1055 column 5 function std::option::Option::<std::ptr::NonNull<u8>>::ok_or::<std::alloc::AllocError> thread 0
Unwinding loop _RNvNvMNtNtCsjQj7SZ039iX_4core5alloc6layoutNtB4_6Layout5array5innerCseZu4mTrUShQ_3lib.0 iteration 1 file /Users/aaronbem/.rustup/toolchains/nightly-2022-11-20-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/alloc/layout.rs line 438 column 16 function std::alloc::Layout::array::inner thread 0
Unwinding loop _ZN4core3ptr46drop_in_place$LT$alloc..vec..Vec$LT$u8$GT$$GT$17h8590e91d633fcb3cE.0 iteration 1 file /Users/aaronbem/.rustup/toolchains/nightly-2022-11-20-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs line 490 column 1 function std::ptr::drop_in_place::<std::vec::Vec<u8>> thread 0
Runtime Symex: 0.0597774s
size of program expression: 2270 steps
slicing removed 1593 assignments
Generated 126 VCC(s), 33 remaining after simplification
Runtime Postprocess Equation: 0.000234417s
Passing problem to propositional reduction
converting SSA
Runtime Convert SSA: 0.00316779s
Running propositional reduction
Post-processing
Runtime Post-process: 5.875e-06s
Solving with MiniSAT 2.2.1 with simplifier
5104 variables, 5259 clauses
SAT checker: instance is SATISFIABLE
Runtime Solver: 0.00150542s
Runtime decision procedure: 0.00475575s
Running propositional reduction
Solving with MiniSAT 2.2.1 with simplifier
5104 variables, 23 clauses
SAT checker: instance is UNSATISFIABLE
Runtime Solver: 3.1125e-05s
Runtime decision procedure: 4.6834e-05s

RESULTS:
...
SUMMARY:
 ** 0 of 101 failed (1 unreachable)

VERIFICATION:- SUCCESSFUL
Verification Time: 0.11889492s

Instead, this happened:

When using cryptominisat, CBMC crashes with an invariant violation:

Checking harness failing_harness...
CBMC 5.71.0 (cbmc-5.71.0)
CBMC version 5.71.0 (cbmc-5.71.0) 64-bit arm64 macos
Reading GOTO program from file src/lib.for-failing_harness.out
Generating GOTO Program
Adding CPROVER library (arm64)
Removal of function pointers and virtual functions
Generic Property Instrumentation
Running with 16 object bits, 48 offset bits (user-specified)
Starting Bounded Model Checking
Unwinding loop _RNvNvMNtNtCsjQj7SZ039iX_4core5alloc6layoutNtB4_6Layout5array5innerCseZu4mTrUShQ_3lib.0 iteration 1 file /Users/aaronbem/.rustup/toolchains/nightly-2022-11-20-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/alloc/layout.rs line 438 column 16 function std::alloc::Layout::array::inner thread 0
Unwinding loop _ZN4core6option15Option$LT$T$GT$5ok_or17hed45a4caf2c9dfa2E.1 iteration 1 file /Users/aaronbem/.rustup/toolchains/nightly-2022-11-20-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs line 1055 column 5 function std::option::Option::<std::ptr::NonNull<u8>>::ok_or::<std::alloc::AllocError> thread 0
Unwinding loop _ZN4core6option15Option$LT$T$GT$5ok_or17hed45a4caf2c9dfa2E.0 iteration 1 file /Users/aaronbem/.rustup/toolchains/nightly-2022-11-20-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs line 1055 column 5 function std::option::Option::<std::ptr::NonNull<u8>>::ok_or::<std::alloc::AllocError> thread 0
Unwinding loop _RNvNvMNtNtCsjQj7SZ039iX_4core5alloc6layoutNtB4_6Layout5array5innerCseZu4mTrUShQ_3lib.0 iteration 1 file /Users/aaronbem/.rustup/toolchains/nightly-2022-11-20-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/alloc/layout.rs line 438 column 16 function std::alloc::Layout::array::inner thread 0
Unwinding loop _ZN4core3ptr46drop_in_place$LT$alloc..vec..Vec$LT$u8$GT$$GT$17h8590e91d633fcb3cE.0 iteration 1 file /Users/aaronbem/.rustup/toolchains/nightly-2022-11-20-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs line 490 column 1 function std::ptr::drop_in_place::<std::vec::Vec<u8>> thread 0
Runtime Symex: 0.0625649s
size of program expression: 2270 steps
slicing removed 1593 assignments
Generated 126 VCC(s), 33 remaining after simplification
Runtime Postprocess Equation: 0.000220167s
Passing problem to propositional reduction
converting SSA
Runtime Convert SSA: 0.00216713s
Running propositional reduction
Post-processing
Runtime Post-process: 5.041e-06s
Solving with External SAT solver
Writing temporary CNF
Invoking SAT solver
Solver returned code: 10
result:SATISFIABLE
Runtime Solver: 0.0288152s
Runtime decision procedure: 0.0310769s
Running propositional reduction
Solving with External SAT solver
Writing temporary CNF
Invoking SAT solver
Solver returned code: 10
result:SATISFIABLE
Runtime Solver: 0.0155117s
--- begin invariant violation report ---
Invariant check failed
File: /tmp/cbmc-20221124-3566-1xvskin/src/goto-checker/goto_trace_storage.cpp:29 function: insert
Condition: emplace_result.second
Reason: cannot associate more than one error trace with property __rust_dealloc.precondition_instance.1
Backtrace:
0   cbmc                                0x000000010343cb18 _Z15print_backtraceRNSt3__113basic_ostreamIcNS_11char_traitsIcEEEE + 120
1   cbmc                                0x000000010343ced0 _Z13get_backtracev + 44
2   cbmc                                0x0000000102fc6728 _Z29invariant_violated_structuredI17invariant_failedtJRKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEEENS1_9enable_ifIXsr3std10is_base_ofIS0_T_EE5valueEvE4typeES9_S9_iS9_DpOT0_ + 52
3   cbmc                                0x0000000102fc6658 _ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEC1IDnEEPKc + 0
4   cbmc                                0x0000000102fde74c _ZN19goto_trace_storaget6insertEO11goto_tracet + 392
5   cbmc                                0x0000000102fd5988 _ZN43all_properties_verifier_with_trace_storagetI25multi_path_symex_checkertEclEv + 228
6   cbmc                                0x0000000102fcdd80 _ZN19cbmc_parse_optionst4doitEv + 2788
7   cbmc                                0x0000000103467088 _ZN19parse_options_baset4mainEv + 180
8   cbmc                                0x0000000102fc6008 main + 48
9   dyld                                0x0000000103ad908c start + 520


--- end invariant violation report ---
Runtime decision procedure: 0.0155494s

CBMC failed with status 134
VERIFICATION:- FAILED

When using kissat, CBMC does not crash but Kani reports that some verification conditions fail:

SUMMARY:
 ** 13 of 101 failed (1 unreachable)
Failed Checks: free argument must be NULL or valid pointer
 File: "/Users/aaronbem/kani/library/kani/kani_lib.c", line 88, in __rust_dealloc
Failed Checks: dereference failure: dead object
 File: "/Users/aaronbem/.rustup/toolchains/nightly-2022-11-20-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/alloc.rs", line 178, in std::alloc::Global::alloc_impl
Failed Checks: dereference failure: dead object
 File: "/Users/aaronbem/.rustup/toolchains/nightly-2022-11-20-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/raw_vec.rs", line 478, in <alloc::raw_vec::RawVec<u8> as std::ops::Drop>::drop
Failed Checks: dereference failure: dead object
 File: "/Users/aaronbem/.rustup/toolchains/nightly-2022-11-20-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mut_ptr.rs", line 38, in std::ptr::mut_ptr::<impl *mut u8>::is_null
Failed Checks: dereference failure: dead object
 File: "/Users/aaronbem/.rustup/toolchains/nightly-2022-11-20-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/result.rs", line 1533, in std::result::Result::<std::alloc::Layout, std::alloc::LayoutError>::unwrap_unchecked
Failed Checks: dereference failure: dead object
 File: "/Users/aaronbem/.rustup/toolchains/nightly-2022-11-20-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/result.rs", line 1538, in std::result::Result::<std::alloc::Layout, std::alloc::LayoutError>::unwrap_unchecked
Failed Checks: dereference failure: dead object
 File: "/Users/aaronbem/.rustup/toolchains/nightly-2022-11-20-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs", line 3029, in <std::vec::Vec<u8> as std::ops::Drop>::drop
Failed Checks: dereference failure: dead object
 File: "/Users/aaronbem/.rustup/toolchains/nightly-2022-11-20-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/raw_vec.rs", line 241, in alloc::raw_vec::RawVec::<u8>::current_memory
Failed Checks: dereference failure: dead object
 File: "/Users/aaronbem/.rustup/toolchains/nightly-2022-11-20-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/raw_vec.rs", line 247, in alloc::raw_vec::RawVec::<u8>::current_memory
Failed Checks: dereference failure: dead object
 File: "/Users/aaronbem/.rustup/toolchains/nightly-2022-11-20-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/raw_vec.rs", line 248, in alloc::raw_vec::RawVec::<u8>::current_memory
Failed Checks: dereference failure: dead object
 File: "/Users/aaronbem/.rustup/toolchains/nightly-2022-11-20-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/raw_vec.rs", line 188, in alloc::raw_vec::RawVec::<u8>::allocate_in
Failed Checks: dereference failure: dead object
 File: "/Users/aaronbem/.rustup/toolchains/nightly-2022-11-20-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/alloc/layout.rs", line 140, in std::alloc::Layout::align
Failed Checks: dereference failure: dead object
 File: "/Users/aaronbem/.rustup/toolchains/nightly-2022-11-20-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/alloc/layout.rs", line 129, in std::alloc::Layout::size

VERIFICATION:- FAILED
Verification Time: 0.26683158s

On the other hand, ok_harness verifies fine using both cryptominisat5 and kissat.

Activity

  1. added
    [C] Bug
    [F] Crash
    [F] Spurious Failure
    on Dec 5, 2022
  2. aaronbembenek-aws commented on Dec 5, 2022

    @aaronbembenek-aws
    ContributorAuthor

    Looping in @tautschnig as I suspect this is an issue with CBMC...

  3. added
    T-CBMC
    on Dec 7, 2022
  4. zhassan-aws commented on Dec 9, 2022

    @zhassan-aws
    Contributor

    I was able to reproduce similar behavior on a C program, and I filed diffblue/cbmc#7424.

  5. zhassan-aws commented on Dec 9, 2022

    @zhassan-aws
    Contributor

    Whoops, just noticed that you've already filed diffblue/cbmc#7416 two days ago.

  6. YoshikiTakashima commented on Dec 10, 2022

    @YoshikiTakashima
    Contributor

    @aaronbembenek-aws If you want to circumvent this and use a faster solver while it's getting fixed, It was not difficult to get CBMC to compile with with Cadical as the default solver. Although I don't think there is a kissat option.

       # checkout the tag you want.
        cmake -S . -Bbuild -Dsat_impl=cadical -DWITH_JBMC=OFF
        cd build
        make -j $(nproc)
        sudo make install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-CBMC[C] Bug[F] Crash[F] Spurious Failure

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions