Skip to content

Commit

Permalink
chore: Verify by file (#62)
Browse files Browse the repository at this point in the history
The Dafny process does not
parallelize very well.

The vcsCores option controls
the number of Z3 processes,
not the number of processes handling parsing.

As such the MPL spends a long time
chewing processing files.
Breaking this up is less efficient,
but may be faster.
  • Loading branch information
seebees authored Oct 12, 2023
1 parent 554ee57 commit e941bcc
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/library_dafny_verification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ jobs:
strategy:
matrix:
library: [
TestVectorsAwsCryptographicMaterialProviders,
AwsCryptographyPrimitives,
ComAmazonawsKms,
ComAmazonawsDynamodb,
AwsCryptographicMaterialProviders,
TestVectorsAwsCryptographicMaterialProviders,
StandardLibrary,
]
os: [ macos-latest ]
os: [ macos-latest-large ]
runs-on: ${{ matrix.os }}
env:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
Expand All @@ -40,6 +40,13 @@ jobs:
with:
dafny-version: ${{ inputs.dafny }}

# dafny-reportgenerator requires next6
# but only 7.0 is installed on macos-latest-large
- name: Setup .NET Core SDK '6.0.x'
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'

- name: Verify ${{ matrix.library }} Dafny code
shell: bash
working-directory: ./${{ matrix.library }}
Expand All @@ -49,6 +56,7 @@ jobs:
make verify CORES=$CORES
- name: Check solver resource use
if: success() || failure()
shell: bash
working-directory: ./${{ matrix.library }}
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ module AwsKmsMrkKeyring {
message := "No Configured KMS Key was able to decrypt the Data Key. The list of encountered Exceptions is available via `list`."));

assert decryptClosure.Ensures(Last(attempts).input, Success(SealedDecryptionMaterials), DropLast(attempts));
assert Last(attempts).input in input.encryptedDataKeys;

return Success(Types.OnDecryptOutput(
materials := SealedDecryptionMaterials
Expand Down
21 changes: 17 additions & 4 deletions SharedMakefileV2.mk
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,24 @@ COMPILE_SUFFIX_OPTION := -compileSuffix:1

########################## Dafny targets

# Proof of correctness for the math below
# function Z3_PROCESSES(cpus:nat): nat
# { if cpus >= 3 then 2 else 1 }

# function DAFNY_PROCESSES(cpus: nat): nat
# requires 0 < cpus // 0 cpus would do no work!
# { (cpus - 1 )/Z3_PROCESSES(cpus) }

# lemma Correct(cpus:nat)
# ensures DAFNY_PROCESSES(cpus) * Z3_PROCESSES(cpus) <= cpus
# {}

# Verify the entire project
verify:Z3_PROCESSES=$(shell echo $$(( $(CORES) >= 3 ? 2 : 1 )))
verify:DAFNY_PROCESSES=$(shell echo $$(( ($(CORES) - 1 ) / ($(CORES) >= 3 ? 2 : 1))))
verify:
dafny \
-vcsCores:$(CORES) \
find . -name '*.dfy' | xargs -n 1 -P $(DAFNY_PROCESSES) -I % dafny \
-vcsCores:$(Z3_PROCESSES) \
-compile:0 \
-definiteAssignment:3 \
-quantifierSyntax:3 \
Expand All @@ -75,13 +89,12 @@ verify:
-verificationLogger:csv \
-timeLimit:100 \
-trace \
`find . -name *.dfy`
%

# Verify single file FILE with text logger.
# This is useful for debugging resource count usage within a file.
# Use PROC to further scope the verification
verify_single:
@: $(if ${CORES},,CORES=2);
dafny \
-vcsCores:$(CORES) \
-compile:0 \
Expand Down
1 change: 1 addition & 0 deletions StandardLibrary/src/Base64.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ module Base64 {
if s == [] {
} else if Is1Padding(suffix) {
assert !Is2Padding(suffix);
assert |prefix| % 4 == 0;
var x, y := DecodeUnpadded(prefix), Decode1Padding(suffix);
assert b == x + y;
assert |x| == |x| / 3 * 3 && |y| == 2;
Expand Down
5 changes: 4 additions & 1 deletion StandardLibrary/src/Base64Lemmas.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ module Base64Lemmas {
Encode(DecodeValid(s));
==
assert |DecodeValid(s)| % 3 == 2;
assert 2 <= |DecodeValid(s)|;
EncodeUnpadded(DecodeValid(s)[..(|DecodeValid(s)| - 2)]) + Encode1Padding(DecodeValid(s)[(|DecodeValid(s)| - 2)..]);
== { DecodeValidUnpaddedPartialFrom1PaddedSeq(s); }
assert IsUnpaddedBase64String(s[..(|s| - 4)]);
assert IsUnpaddedBase64String(s[..(|s| - 4)]) by {
assert |s| % 4 == 0;
}
EncodeUnpadded(DecodeUnpadded(s[..(|s| - 4)])) + Encode1Padding(DecodeValid(s)[(|DecodeValid(s)| - 2)..]);
== { DecodeEncodeUnpadded(s[..(|s| - 4)]); }
s[..(|s| - 4)] + Encode1Padding(DecodeValid(s)[(|DecodeValid(s)| - 2)..]);
Expand Down

0 comments on commit e941bcc

Please sign in to comment.