Skip to content

Optimize nonpayable checks#2172

Merged
fubuloubu merged 3 commits into
vyperlang:masterfrom
iamdefinitelyahuman:optimize-nonpayable
Sep 30, 2020
Merged

Optimize nonpayable checks#2172
fubuloubu merged 3 commits into
vyperlang:masterfrom
iamdefinitelyahuman:optimize-nonpayable

Conversation

@iamdefinitelyahuman

@iamdefinitelyahuman iamdefinitelyahuman commented Sep 29, 2020

Copy link
Copy Markdown
Contributor

What I did

When a contract contains no payable functions, only perform a single ASSERT CALLVALUE ISZERO at the beginning of the bytecode instead of at the start of each function.

Closes #1776

How I did it

  • In parser.parser::parse_tree_to_lll, prior to parsing the individual functions, check the signature of every function to see if any are payable.
  • Pass the result of this check to parser.function_definitions.parse_external_function::parse_external_function, so the per-function check may be omitted.
  • If required, insert the check at the start of the LLL once it has been generated.

How to verify it

Run the tests. I added some new test cases to verify that this behavior works as expected.

Cute Animal Picture

image

@codecov-commenter

codecov-commenter commented Sep 29, 2020

Copy link
Copy Markdown

Codecov Report

Merging #2172 into master will increase coverage by 0.90%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2172      +/-   ##
==========================================
+ Coverage   84.33%   85.23%   +0.90%     
==========================================
  Files          83       83              
  Lines        8367     8370       +3     
  Branches     2019     2021       +2     
==========================================
+ Hits         7056     7134      +78     
+ Misses        808      733      -75     
  Partials      503      503              
Impacted Files Coverage Δ
...er/function_definitions/parse_external_function.py 95.78% <100.00%> (ø)
...yper/parser/function_definitions/parse_function.py 95.83% <100.00%> (ø)
vyper/parser/parser.py 87.23% <100.00%> (+0.42%) ⬆️
vyper/parser/lll_node.py 81.99% <0.00%> (-0.95%) ⬇️
vyper/ast/nodes.py 93.84% <0.00%> (+1.53%) ⬆️
vyper/parser/expr.py 77.04% <0.00%> (+4.91%) ⬆️
vyper/functions/functions.py 89.71% <0.00%> (+5.34%) ⬆️
vyper/context/types/value/numeric.py 84.14% <0.00%> (+6.09%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0b5669d...198cf36. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimization - remove multiple CALLVALUE checks if a contract has no payable functions

3 participants