vyper
vyper copied to clipboard
feat: protect external calls with `await` keyword
What I did
implement https://github.com/vyperlang/vyper/issues/2856
(note: wait until after v0.3.4)
How I did it
How to verify it
tbd new tests note to self:
interface Foo:
def foo(): nonpayable
@internal
def bar():
pass
@external
def foo():
await Foo(msg.sender).foo()
# bad:
#Foo(msg.sender).foo()
#await self.bar()
#await 1 + 1
Commit message
Commit message for the final, squashed PR. (Optional, but reviewers will appreciate it! Please see our commit message style guide for what we would ideally like to see in a commit message.)
Description for the changelog
Cute Animal Picture
Codecov Report
Attention: Patch coverage is 97.16312% with 4 lines in your changes are missing coverage. Please review.
Project coverage is 85.36%. Comparing base (
45c6b6a) to head (b625c04).
| Files | Patch % | Lines |
|---|---|---|
| vyper/codegen/expr.py | 91.89% | 1 Missing and 2 partials :warning: |
| vyper/ast/parse.py | 92.30% | 0 Missing and 1 partial :warning: |
:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@ Coverage Diff @@
## master #2938 +/- ##
==========================================
+ Coverage 85.23% 85.36% +0.12%
==========================================
Files 92 92
Lines 13949 14031 +82
Branches 3130 3141 +11
==========================================
+ Hits 11889 11977 +88
+ Misses 1565 1560 -5
+ Partials 495 494 -1
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
breaking change, wait until 0.4.0
for now i'm putting in the behavior as warning instead of an exception
compiling
@external
def foo():
s: String[2] = staticcall staticcall concat('a', 'b')
return
yields:
File "<unknown>", line 4
s: String[2] = await await concat('a', 'b')
^^^^^
SyntaxError: invalid syntax
The above exception was the direct cause of the following exception:
vyper.exceptions.SyntaxException: invalid syntax (<unknown>, line 4)
line 4:31
3 def foo():
---> 4 s: String[2] = staticcall staticcall concat('a', 'b')
--------------------------------------^
5 return
see: s: String[2] = await await concat('a', 'b')
also: File "<unknown>", line 4
I assume this is the type of err that the description is alluding to:
interface I:
def foo() -> uint256: view
def bar(a: uint256): payable
event E:
a: uint256
@external
@payable
def foo(_target: address) -> uint256:
log E(staticcall I(_target).foo())
return 1
yields:
IndexError: list index out of rang
compiling:
d: DynArray[uint256, 10]
interface I:
def foo() -> DynArray[uint256, 10]: view
@external
def bar(t: address) -> uint256:
for i: uint256 in staticcall I(t).foo():
self.d.append(i)
return 1
yields:
Error compiling: tests/custom/test5.vy
AssertionError: non-unique symbols {'I(t).foo()2'}
compiling:
d: DynArray[uint256, 10]
interface I:
def foo() -> DynArray[uint256, 10]: view
def bar() -> uint256: payable
@external
def bar(t: address) -> uint256:
for i: uint256 in range(extcall I(t).bar(), bound=10):
self.d.append(i)
return 1
yields:
Error compiling: tests/custom/test5.vy
vyper.exceptions.CodegenPanic: unhandled exception typechecker missed this, parse_ExtCall
contract "tests/custom/test5.vy:10", function "bar", line 10:28
9 def bar(t: address) -> uint256:
---> 10 for i: uint256 in range(extcall I(t).bar(), bound=10):
------------------------------------^
11 self.d.append(i)
This is an unhandled internal compiler error. Please create an issue on Github to notify the developers!
https://github.com/vyperlang/vyper/issues/new?template=bug.md
compiling:
d: DynArray[uint256, 10] interface I: def foo() -> DynArray[uint256, 10]: view @external def bar(t: address) -> uint256: for i: uint256 in staticcall I(t).foo(): self.d.append(i) return 1yields:
Error compiling: tests/custom/test5.vy AssertionError: non-unique symbols {'I(t).foo()2'}
related:
interface I:
def ohfak() -> decimal: view
@external
def bar(t: address):
k: decimal = sqrt(staticcall I(t).ohfak())
return
yields:
Error compiling: tests/custom/test4.vy
AssertionError: non-unique symbols {'I(t).ohfak()18'}
see:
s: String[2] = await await concat('a', 'b')also:File "<unknown>", line 4
seems unrelated -- there's a raise SyntaxException(...) from e in vyper/ast/parse.py; we could remove the from e
compiling:
d: DynArray[uint256, 10] interface I: def foo() -> DynArray[uint256, 10]: view def bar() -> uint256: payable @external def bar(t: address) -> uint256: for i: uint256 in range(extcall I(t).bar(), bound=10): self.d.append(i) return 1yields:
Error compiling: tests/custom/test5.vy vyper.exceptions.CodegenPanic: unhandled exception typechecker missed this, parse_ExtCall contract "tests/custom/test5.vy:10", function "bar", line 10:28 9 def bar(t: address) -> uint256: ---> 10 for i: uint256 in range(extcall I(t).bar(), bound=10): ------------------------------------^ 11 self.d.append(i) This is an unhandled internal compiler error. Please create an issue on Github to notify the developers! https://github.com/vyperlang/vyper/issues/new?template=bug.md
this is a bug on master too, not a regression in this PR
the non-unique symbol panics are related to known bugs i think, not regressions