-
-
Notifications
You must be signed in to change notification settings - Fork 819
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat[lang]: protect external calls with keyword (#2938)
this commit adds `extcall` and `staticcall` keywords to the vyper language. these are now a requirement for the user to add to distinguish internal calls from: 1) external calls which can have side effects (`extcall`), and 2) external calls which are guaranteed by the EVM to not have side effects (`staticcall`). `extcall` is used for `nonpayable` or `payable` functions (which emit the `CALL` opcode), while `staticcall` is used for `view` and `pure` functions (which emit the `STATICCALL` opcode). the motivation for this is laid out more in the linked GH issue, but it is primarily to make it easier to read, audit and analyze vyper contracts, since you can find the locations of external calls in source code using text-only techniques, and do not need to analyze (or have access to the results of an analysis) in order to find where external calls are. (note that this has become a larger concern with with the introduction of modules in vyper, since you can no longer distinguish between internal and external calls just by looking for the `self.` prefix). an analysis of some production contracts indicates that the frequency of external calls has somewhat high variability, but is in the range of one `extcall` (or `staticcall`) per 10-25 (logical) sloc, with `staticcalls` being about twice as common. therefore, based on the semantic vs write load of the keyword, the keyword should be somewhat easy to type, but it also needs to be long enough and unusual enough to stand out in a text editor. the differentiation between `extcall` and `staticcall` was added because, during testing of the feature, it was found that being able to additionally infer at the call site whether the external call can have side effects or not (without needing to reference the function definition) substantially enhanced readability. refactoring/misc updates: - update and clean up the grammar, especially the `variable_access` rule (cf. https://github.com/lark-parser/lark/blob/706190849ee/lark/grammars/python.lark#L192) - add a proper .parent property to VyperNodes - add tokenizer changes to make source locations are correct - ban standalone staticcalls - update tests -- in some cases, because standalone staticcalls are now banned, either an enclosing assignment was added or the mutability of the interface was changed. - rewrite some assert_compile_failed to pytest.raises() along the way - remove some dead functions cf. GH issue / VIP 2856 --------- Co-authored-by: tserg <[email protected]>
- Loading branch information
1 parent
327e95a
commit 2d232eb
Showing
54 changed files
with
946 additions
and
478 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.