-
-
Notifications
You must be signed in to change notification settings - Fork 804
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
VIP: Enable Dynamic Analysis/Symbolic Execution Checks #711
Comments
Pinging @daejunpark and @ehildenb. |
We were talking about this a few months back. The only difference is we were talking about a special comment type for analysis. I think everyone was on board with the concept, but this particular implementation is interesting. I think a more succinct way to do it is to include valid Python syntax that basically won't compile to anything in "normal" mode, and in static analysis mode would add extra asserts to the bytecode used for analysis, throwing the special opcode as you pointed out. We would love to leverage this kind of analysis as a tool for our compiler. Perhaps this specification can be leveraged as a standard for any EVM language, and we can build toolsets that make this kind of analysis easier within a language-agnostic framework? I think with all of our langauges targeting the EVM, we should be thinking much more about toolsets that leverage that layer so we're not duplicating work in every compiler. |
Yes, a common convention would save work. Solidity took the approach "
|
I'm in favor of the Alternative is making some explicit Another alternative is using some unused opcode as the de-facto |
Yeah, that's a toughy. Perhaps the code gets added when compiled for FV mode (in either language) and the json assests file contains a listing of those bytecode locations that should trigger analysis failures if reached. That would start to get into the need to formalize the assets file spec to leverage in different tools (e.g. |
What's wrong with just generating I don't see the need for reading extra metadata, the tools can just analyze "is |
(I saw |
@ehildenb It's a suggestion. Some peoople don't want extra code to pollute their contracts, hence having a separate FV-only statement that would get dropped in normal compilation because you've "proved" it's not possible. We could definitely argue whether to give the person the option to include them in their final bytecode. As far as metadata, it's more a UI thing. Yes the execution engine can tell when it hits a certain statement, but "there's a problem" is more opaque than "there's a problem L17, C40" or "your FVassert statement on line 17 failed" |
@fubuloubu well, programmers have the choice whether or not to use the new |
If some programmers go for
that's their choice.
|
Well, in that case, wouldn't it make sense to have
|
@fubuloubu well, |
@fubuloubu I won't believe that the FV mode and non-FV mode behave the same, so if I analyze the FV mode code, I would just deploy the FV mode code. |
@fubuloubu so, I think it's safer to have |
Then you have two copies of the same code (one with the statement and one without), and that's a no-no to me. I think maybe make it more obvious that they're different, and that |
Well actually, I screwed that up. |
I will only have one copy of the code with |
I'm not going to use |
@fubuloubu if |
So I'm against any mode thing. That ambiguates the semantics of Vyper. |
If a programmer doesn't like |
Hmm, that's a good counterargument re: style. Don't make it complicated right? So people use it correctly.
|
That sounds like the ultimate right thing to do. The proposal here is made for impatient developers of static analyzers who want to try out their techniques today. |
Well, I'm not sure extra meta-data will be necessary. @pirapira is it the case that Solidity will only generate But, I think either way, we should move forward with generated |
@fubuloubu by the way, never-failing Yes, the runtime cost of The deployment cost is cheaper with |
Interesting discussion, so I prefer only having a single assert type statement in the base language. It feels like we are altering the base language just to accommodate static analysers? If that is the case, I opt for perhaps a secondary parameter to assert that convert the assert to use invalid opcode. Something like |
I think this misses the point though. The |
@ehildenb I am probably missing something (very very likely 😜), but as far as I understand these never-to-be-reached if statement could just as well use assert? |
@jacqueswww good point. There have been confusions around |
I like the word |
@jacqueswww thanks for the suggestion. I updated the description. |
I think it's less violent haha, but I like @pirapira I see your point now about |
From meeting: Create an experimental keyword (warning in compiler 'NOTE: you are using experimental features' ) |
@fubuloubu I think it was you who previously suggested I suggest both |
Would like to note the use cases of this for defining invariant conditions inside code for property-based testing (more here), and checks SMT/SAT solvers and other symbolic analyses and formal verifications |
Note: most tools use the |
Yep that's the plan. |
Actually will put this on my queue now :) |
TODO Document new functionality, and give an overview of how it may be used effectively. |
As discussed onthe Bi-Weekly meeting I prupose we instead extend assert instead
def test(a: ):
assert self.cond != 1, UNREACHABLE # Uses INVALID opcode. @fubuloubu @charles-cooper I will leave this here for 24 hours, so we can make sure we have made a good call, and then I will amend my previous PR to use the above syntax instead. |
That looks like a nice feature! I am not entirely sure about the So something like It would be nice also to have a compilation mode where these properties do emit bytecode. Typically, if I can prove that all my properties are safe, I would want the compiler to not produce code for them. |
Preamble
Simple Summary
Add a special type of assertion that should never ever fail. When a static analyzer can fire it, the program surely has a bug.
Abstract
Static analyzers can detect bugs, but only when the desired properties are specified. The easiest way is to insert a "never-to-fail" assertions in the program.
Motivation
Mythril has a feature to detect when 0xfe is somehow reachable. KEVM can soon do that.
assert
in vyper is expected to fail sometimes, and it is compiled toREVERT
.REVERT
might indicate a mistake of the caller, a mistake of the programmer, or a mistake of the compiler. So, static analyzers cannot shout "this is a bug".Instead, if Vyper has a never-to-fail assertion that translates to
INVALID (0xfe)
, static analyzers can confidently shout "this is a bug. See, this execution reachesINVALID
".Alternatives are specially formatted comments like ACSL or JML, but they are hard to learn.
Specification
Add a additional custom constant to the
assert
statement:as well as
Backwards Compatibility
A program containing a name
assure
will cause compillation errors.Copyright
Copyright and related rights waived via CC0
The text was updated successfully, but these errors were encountered: