-
Notifications
You must be signed in to change notification settings - Fork 998
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
[Proposal] An attempt to remove assert
from the core specs
#2045
Conversation
This is great, and agree assertions are some weird hack, but for testing they do what they do really well, tooling understands the evaluation of them, gives more meaningful exceptions, etc. If we're going for something like Nagini, I'd rather not redefine the functions in the beacon-spec phase0 doc, and move it to some separate doc, focused at just these types of helper functions. Especially if we want to expand it with invariants, and maybe go into detail in spec assumptions that apply globally (index lookups, no wrap-arounds, no integer under/overflows, etc.). |
What's the status here @hwwhww. Is this something you'd like to still consider? |
I think it's important to clarify semantics of such assertions/declarations.
Let's consider some examples:
Based on the above and that intention of the proposal differs from verification, I think that it's perhaps best to follow the Solidity semantics of require/assert/revert. They however, can be adapted to pyspecs, based on Nagini declarations:
I'd summarize proposed semantics:
One concern here is that There are also some tricky semantic issues, when combining input/state validation semantics with pre-condition semantics. Basically, pre-conditions should hold before a method is invoked. While input/state validating can be interleaved with other computations (including state updates). So, such combined semantics cannot be typically used to communicate pre-conditions to formal method tools, at least directly, without some processing. For example
It would be great if such annotations can be used as an input to formal method tools too. Basically, code annotating is perhaps the biggest problem when applying formal methods. So, reducing efforts and simplifying synchronization of pyspecs and pyspecs verification code is an important problem. However, full annotation can easily render pyspecs unreadable. |
A few questions:
|
Yes, this is the key distinction. Basically, it is about distinguishing run-time and verification-time contexts.
The assert should never fail during runtime. So, turning off the check doesn't change behavior. Another example,
In Python, such annotations are not enforced during run-time. But they can be enforced via a static checker. One can also imagine a Python interpreter which does check them during run-time. One can imagine more complex example, i.e.
So, the post-condition cab be a goal for a prover to verify. One can also use post-conditions (together with pre-conditions) to abstract a method away during symbolic execution. E.g. if there is a call
which basically means "for all It's also true that one can perform verification during runtime - i.e. leave In general, however, not every condition can be checked during run-time, but some of them can be checked symbolically. For example. So, the idea basically is to be able to communicate some stuff to provers (of various kinds, including human inspectors, runtime verifiers, static analysis tools or full blown formal methods), while not being obliged to keep it during runtime. |
There are advantages (like more expressive conditions, e.g. the
Yes. However, there are semantic differences too:
|
The latter one. |
I'd also add that the simplest change would be to replace In this case, I'd also explicitly clarify that:
|
Re-thinking the discussion, I have a suggestion to split the PR in two parts:
The rationale is that the issues are rather orthogonal (though related) and can be implemented separately. Additionally, there is a confusion between expressing pre-conditions and input validation logic, discussed above. They are indeed quire similar, but distinct things. I assume that most of A solution to #1945 is more involved, since one need to write actual pre-conditions for methods in addition to inventing appropriate words for expressing pre/post-conditions. There is some interference between two aspects: |
Agreed. 👍 I think it’s good to start with addressing #1797 first. We can add a "message" field, e.g., In that case, naming it
Right, understand. I'm open to other new ideas. :) |
I personally like
👍 Choosing wording is more like a matter of taste. I don't think it should stop us from going on. |
Issue
An attempt to address #1945 and #1797.
Proposed solutions
Thank @ericsson49 for pointing out Nagini. Although I have some concerns about using Nagini directly, we can implement similar declarations without overhauling the spec.
Note that this PR is not meant to formally verify the spec. Dafny team is working on FV spec separately.
Proposed solution
Replace
assert
withRequires
andEnsures
helpers. See declarations. The helpers will raiseValidationError
if the conditions are not satisfied.TBD
Pros:
deposit-cli
audit) recently, assertions are ignored in optimized mode.Cons:
/cc @franck44