Skip to content

Commit 6c3ab4d

Browse files
committed
check borrow equality in suitableAP, update sha512_mr_solver.saw
1 parent 10fafea commit 6c3ab4d

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

heapster-saw/examples/sha512_mr_solver.saw

+12-12
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ heapster_typecheck_fun env "round_16_80"
2828
\ arg2:int64_ptr<>, arg3:int64_ptr<>, arg4:int64_ptr<>, arg5:int64_ptr<>, \
2929
\ arg6:int64_ptr<>, arg7:int64_ptr<>, arg8:int64_ptr<>, arg9:int64_ptr<>, \
3030
\ arg10:array(W,0,<16,*8,fieldsh(int64<>)), \
31-
\ arg11:int64_ptr<>, arg12:int64_ptr<>, arg13:int64_ptr<> -o \
31+
\ arg11:ptr((W,0) |-> true), arg12:ptr((W,0) |-> true), arg13:int64_ptr<> -o \
3232
\ arg2:int64_ptr<>, arg3:int64_ptr<>, arg4:int64_ptr<>, arg5:int64_ptr<>, \
3333
\ arg6:int64_ptr<>, arg7:int64_ptr<>, arg8:int64_ptr<>, arg9:int64_ptr<>, \
3434
\ arg10:array(W,0,<16,*8,fieldsh(int64<>)), \
@@ -38,8 +38,6 @@ heapster_typecheck_fun env "return_X"
3838
"(). arg0:array(W,0,<16,*8,fieldsh(int64<>)) -o \
3939
\ arg0:array(W,0,<16,*8,fieldsh(int64<>))";
4040

41-
heapster_set_debug_level env 1;
42-
4341
heapster_set_translation_checks env false;
4442
heapster_typecheck_fun env "processBlock"
4543
"(num:bv 64). arg0:int64_ptr<>, arg1:int64_ptr<>, arg2:int64_ptr<>, \
@@ -51,9 +49,7 @@ heapster_typecheck_fun env "processBlock"
5149
\ arg6:int64_ptr<>, arg7:int64_ptr<>, \
5250
\ arg8:array(R,0,<16*num,*8,fieldsh(int64<>)), ret:true";
5351

54-
heapster_export_coq env "sha512_mr_solver_gen.v";
55-
56-
/*
52+
// FIXME: This translation contains errors
5753
heapster_set_translation_checks env false;
5854
heapster_typecheck_fun env "processBlocks"
5955
"(num:bv 64). arg0:array(W,0,<8,*8,fieldsh(int64<>)), \
@@ -63,6 +59,8 @@ heapster_typecheck_fun env "processBlocks"
6359
\ arg1:array(R,0,<16*num,*8,fieldsh(int64<>)), \
6460
\ arg2:true, ret:true";
6561

62+
heapster_export_coq env "sha512_mr_solver_gen.v";
63+
6664
// Mr. Solver
6765

6866
let eq_bool b1 b2 =
@@ -81,13 +79,14 @@ let run_test name test expected =
8179

8280
round_00_15 <- parse_core_mod "SHA512" "round_00_15";
8381
round_16_80 <- parse_core_mod "SHA512" "round_16_80";
84-
// processBlock <- parse_core_mod "SHA512" "processBlock";
85-
// processBlocks <- parse_core_mod "SHA512" "processBlocks";
82+
processBlock <- parse_core_mod "SHA512" "processBlock";
83+
processBlocks <- parse_core_mod "SHA512" "processBlocks";
8684

8785
// Test that every function refines itself
88-
// run_test "processBlocks |= processBlocks" (mr_solver processBlocks processBlocks) true;
86+
run_test "processBlocks |= processBlocks" (mr_solver processBlocks processBlocks) true;
87+
// FIXME: Why does this hang?
8988
// run_test "processBlock |= processBlock" (mr_solver processBlock processBlock) true;
90-
// run_test "round_16_80 |= round_16_80" (mr_solver round_16_80 round_16_80) true;
89+
run_test "round_16_80 |= round_16_80" (mr_solver round_16_80 round_16_80) true;
9190
// run_test "round_00_15 |= round_00_15" (mr_solver round_00_15 round_00_15) true;
9291

9392
import "sha512.cry";
@@ -105,5 +104,6 @@ monadify_term {{ Maj }};
105104
monadify_term {{ round_00_15_spec }};
106105

107106
run_test "round_00_15 |= round_00_15_spec" (mr_solver round_00_15 {{ round_00_15_spec }}) true;
108-
run_test "round_16_80 |= round_16_80_spec" (mr_solver_debug 0 round_16_80 {{ round_16_80_spec }}) true;
109-
*/
107+
108+
// FIXME: Need to add heterogenous equality on output types for this to work
109+
// run_test "round_16_80 |= round_16_80_spec" (mr_solver_debug 0 round_16_80 {{ round_16_80_spec }}) true;

heapster-saw/src/Verifier/SAW/Heapster/Implication.hs

+18-13
Original file line numberDiff line numberDiff line change
@@ -6734,15 +6734,16 @@ proveVarLLVMArrayH x psubst ps mb_ap
67346734
, Just len <- partialSubst psubst $ mbLLVMArrayLen mb_ap
67356735
, Just lenBytes <- partialSubst psubst $ mbLLVMArrayLenBytes mb_ap
67366736
, stride <- mbLLVMArrayStride mb_ap
6737-
, Just i <- findIndex (suitableAP off lenBytes stride) ps
6737+
, Just bs <- partialSubst psubst $ mbLLVMArrayBorrows mb_ap
6738+
, Just i <- findIndex (suitableAP off lenBytes stride bs) ps
67386739
, Perm_LLVMArray ap_lhs <- ps!!i =
67396740
implVerbTraceM (\info -> pretty "proveVarLLVMArrayH case 1: using" <+>
67406741
permPretty info ap_lhs) >>>
67416742
implGetConjM x ps i >>>= \ps' ->
67426743
recombinePerm x (ValPerm_Conj ps') >>>
67436744

67446745
partialSubstForceM (mbLLVMArrayBorrows mb_ap)
6745-
"proveVarLLVMArrayH: incomplete array borrows" >>>= \bs ->
6746+
"proveVarLLVMArrayH: incomplete array borrows" >>>
67466747

67476748
if bvEq off (llvmArrayOffset ap_lhs) && bvEq len (llvmArrayLen ap_lhs) then
67486749
proveVarLLVMArray_FromArray x ap_lhs len bs mb_ap
@@ -6752,22 +6753,26 @@ proveVarLLVMArrayH x psubst ps mb_ap
67526753
proveVarLLVMArray_FromArray x (llvmMakeSubArray ap_lhs off len) len bs mb_ap
67536754
where
67546755
-- Test if an atomic permission is a "suitable" array permission for the
6755-
-- given offset, length, and stride, meaning that it has the required
6756-
-- stride, could contain the offset and length, and does not have all of the
6757-
-- offset and length borrowed
6756+
-- given offset, length, stride, and borrows, meaning that it has the
6757+
-- given stride, could contain the given offset and length, and either
6758+
-- has exactly the given borrows or at least does not have all of the
6759+
-- given offset and length borrowed
67586760
suitableAP ::
67596761
(1 <= w, KnownNat w) =>
67606762
PermExpr (BVType w) -> PermExpr (BVType w) -> Bytes ->
6761-
AtomicPerm (LLVMPointerType w) -> Bool
6762-
suitableAP off len stride (Perm_LLVMArray ap) =
6763+
[LLVMArrayBorrow w] -> AtomicPerm (LLVMPointerType w) -> Bool
6764+
suitableAP off len stride bs (Perm_LLVMArray ap) =
67636765
-- Test that the strides are equal
67646766
llvmArrayStride ap == stride &&
6765-
-- Make sure the range [off,len) is not fully borrowed
6766-
not (llvmArrayRangeIsBorrowed ap (BVRange off len)) &&
67676767
-- Test if this permission *could* cover the desired off/len
67686768
all bvPropCouldHold (bvPropRangeSubset (BVRange off len)
6769-
(llvmArrayAbsOffsets ap))
6770-
suitableAP _ _ _ _ = False
6769+
(llvmArrayAbsOffsets ap)) &&
6770+
-- Test that either the sets of borrows are equal ...
6771+
(all (flip elem bs) (llvmArrayBorrows ap) &&
6772+
all (flip elem (llvmArrayBorrows ap)) bs) ||
6773+
-- ...or the range [off,len) is not fully borrowed
6774+
not (llvmArrayRangeIsBorrowed ap (BVRange off len))
6775+
suitableAP _ _ _ _ _ = False
67716776

67726777
-- Check if there is a block that contains the required offset and length, in
67736778
-- which case eliminate it, allowing us to either satisfy way 4 (eliminate a
@@ -6809,8 +6814,8 @@ proveVarLLVMArrayH x psubst ps mb_ap
68096814
, len <- llvmArrayLen ap
68106815
, lhs_cells@(lhs_cell_rng:_) <- concatMap (permCells ap) ps
68116816
, rhs_cells <- map llvmArrayBorrowCells (llvmArrayBorrows ap)
6812-
, Just cells <- gatherCoveringRanges (llvmArrayCells ap) (lhs_cells ++
6813-
rhs_cells)
6817+
, Just cells <- gatherCoveringRanges (llvmArrayCells ap) (rhs_cells ++
6818+
lhs_cells)
68146819
, bs <- map cellRangeToBorrow cells
68156820
, ap_borrowed <- ap { llvmArrayBorrows = bs }
68166821
, cell_bp <- blockForCell ap (bvRangeOffset lhs_cell_rng) =

0 commit comments

Comments
 (0)