Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect and report use of mixing options that change semantics #3556

Open
davidcok opened this issue Feb 16, 2023 · 4 comments
Open

Detect and report use of mixing options that change semantics #3556

davidcok opened this issue Feb 16, 2023 · 4 comments
Assignees
Labels
crash Dafny crashes on this input, or generates malformed code that can not be executed during 3: execution of incorrect program An bug in the verifier that allows Dafny to run a program that does not correctly implement its spec introduced: pre-2012 invalid translated code The compiler generates invalid code, making the the target language infrastructure crash kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny logic An inconsistency in Dafny's logic (e.g. in the Boogie prelude) priority: not yet Will reconsider working on this when we're looking for work

Comments

@davidcok
Copy link
Collaborator

davidcok commented Feb 16, 2023

Summary

Mixing code that has been verified or compiled with values of certain options that modify the semantics of Dafny, such as --unicode-char, could lead to soundness problems.

Background and Motivation

Dafny 4 has a default of unicode-char:true, previous versions had unicode-char:false

Proposed Feature

Detect whether modules are setting different values -- ideally only where it actually matters.

Alternatives

No response

@davidcok davidcok added kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny during 4: bad execution of correct program A bug in the Dafny compiler that causes a correct Dafny program to execute incorrectly invalid translated code The compiler generates invalid code, making the the target language infrastructure crash labels Feb 16, 2023
@robin-aws robin-aws added this to the Library support milestone Feb 17, 2023
@atomb atomb changed the title Detect and report mixed use of unicode-char true and false Detect and report use of mixing options that change semantics Feb 17, 2023
@atomb
Copy link
Member

atomb commented Feb 17, 2023

I updated the text to generalize it a bit to any option that changes language semantics.

@atomb atomb added logic An inconsistency in Dafny's logic (e.g. in the Boogie prelude) and removed during 4: bad execution of correct program A bug in the Dafny compiler that causes a correct Dafny program to execute incorrectly labels Feb 17, 2023
@robin-aws
Copy link
Member

robin-aws commented Apr 18, 2023

To me the root cause here is not having any mechanisms to enforce sound separate verification and compilation of Dafny code. I say the best solution is to define some kind of build artifact for Dafny that attaches metadata to the Dafny source, so that when consuming a library, rather than trusting the code was previously verified and assuming the details of how it was verified, the Dafny tooling can look for hard evidence and metadata about how the library was built, and fail if the consuming environment is not compatible.

To that end, I propose the following:

  1. Define a file type similar to *.dll or *.jar to contain the results of successful verification.

    • Likely an alias for a compressed archive in the style of *.jar or *.nupkg etc.
    • Would contain:
      • The source for the Dafny program, embedded in a similar style to how the C# backend adds the DafnySourceAttribute.
      • The version of Dafny used to verify the program, and the identity/version of the solver
      • The options passed when verifying (possibly convenient to use a dfyconfig.toml file)
      • (maybe, if useful?) Metrics such as verification time or resource count
      • (future versions) Some kind of verification certificate a solver can use to quickly re-verify
      • A version number for the format of this metadata (so we can improve it over time, for example to store the verified program more efficiently than in source text)
    • I cheekily propose using the *.doo extension, for Dafny Output Object (or Dafny Object, Obviously?)
  2. Change the dafny tooling in general to produce a *.doo file unless verification is skipped

    • Even better, discourage the use of --no-verify entirely. The flag is often used (especially in our own test suite) to avoid re-verifying repeatedly when (for example) compiling the same source to multiple backends. We can instead encourage calling dafny translate on the *.doo result of a previous dafny verify call.
  3. Support passing *.doo files directly to dafny as well as *.dfy files.

    • Fail if the options used to produce the *.doo file are incompatible with the current options/Dafny version. We can start conservative and reject ANY mismatch, but then allow-list mismatches that are known to be safe.
  4. Deprecate features that unsafely skip verification, such as:

    • include without --verify-included-files (users are often surprised that included files are not verified by default)
    • --library <*.dfy> as opposed to --library <*.doo>
      • Or perhaps even deprecate --library in favor of directly passing *.doo files.

*.doo files would become the standard artifact for distributing Dafny projects, independently of how these artifacts are identified and distributed. It implies that #3007 should not be satisfied by just git cloning the source of a Dafny library, unless such a repository regularly checked-in *.doo files, which is not the best practice. Such a library could attach a *.doo file to GitHub releases, however, which would be easily downloadable via URLs like https://github.com/dafny-lang/libraries/releases/download/v0.1.0/wrappers.doo.

*.doo files could also be embedded inside the compiled and assembled artifacts for any target language Dafny supports, e.g. as a META-INF entry in a Java .jar file. Kotlin does something similar in embedding a *.kotlin_module in jars compiled from Kotlin source, so that other Kotlin projects can link with them using Kotlin signatures: https://blog.jetbrains.com/kotlin/2015/06/improving-java-interop-top-level-functions-and-properties/#Asmallbitonmetadata

@robin-aws
Copy link
Member

Note that although a URL pointing to a *.doo file is technically enough for a remote dependency, I still wouldn't recommend that as a production-grade solution, since GitHub releases don't have any standards for including checksums or signatures. This makes building on top of existing systems like Maven/Gradle via plugins like #3169 appealing: https://docs.gradle.org/current/userguide/dependency_verification.html

fabiomadge pushed a commit that referenced this issue Apr 29, 2023
Provides a build artifact for outputting after successful verification,
with enough metadata attached to support safe consumption as a library,
as loosely described in this comment:
#3556 (comment)

Also refactors the functionality used by `dafny audit` to ensure the
library backend rejects `assume` statements as the other backends do,
without having to implement a proper SinglePassCompiler subclass.

Also hides the internal "Simple Dafny" backend, which isn't intended to
be publicly documented, while the new library backend is.

Provides a solution for #3556, but I'm not calling that resolved until
we at least deprecate separate verification features that don't use .doo
files (which isn't in scope for this PR).
@keyboardDrummer keyboardDrummer added crash Dafny crashes on this input, or generates malformed code that can not be executed during 3: execution of incorrect program An bug in the verifier that allows Dafny to run a program that does not correctly implement its spec labels Feb 2, 2024
@keyboardDrummer
Copy link
Member

keyboardDrummer commented Feb 21, 2024

The introduction of .doo files has I think mostly resolved this issue.

What I think is left, is to let --library=<nonDooFile> emit a warning, saying that the referenced file might have been verified with other options, or might not even have been verified at all.

@keyboardDrummer keyboardDrummer added the priority: not yet Will reconsider working on this when we're looking for work label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Dafny crashes on this input, or generates malformed code that can not be executed during 3: execution of incorrect program An bug in the verifier that allows Dafny to run a program that does not correctly implement its spec introduced: pre-2012 invalid translated code The compiler generates invalid code, making the the target language infrastructure crash kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny logic An inconsistency in Dafny's logic (e.g. in the Boogie prelude) priority: not yet Will reconsider working on this when we're looking for work
Projects
None yet
Development

No branches or pull requests

4 participants