Skip to content

Commit

Permalink
fix: disallow value= passing for delegate and static raw_calls (#3755)
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Jan 31, 2024
1 parent 768b3e9 commit a2df088
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
16 changes: 16 additions & 0 deletions tests/functional/builtins/codegen/test_raw_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,22 @@ def foo(_addr: address):
(
"""
@external
def foo(_addr: address):
raw_call(_addr, method_id("foo()"), is_delegate_call=True, value=1)
""",
ArgumentException,
),
(
"""
@external
def foo(_addr: address):
raw_call(_addr, method_id("foo()"), is_static_call=True, value=1)
""",
ArgumentException,
),
(
"""
@external
@view
def foo(_addr: address):
raw_call(_addr, 256)
Expand Down
9 changes: 6 additions & 3 deletions vyper/builtins/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,13 +1114,16 @@ def build_IR(self, expr, args, kwargs, context):

if delegate_call and static_call:
raise ArgumentException(
"Call may use one of `is_delegate_call` or `is_static_call`, not both", expr
"Call may use one of `is_delegate_call` or `is_static_call`, not both"
)

if (delegate_call or static_call) and value.value != 0:
raise ArgumentException("value= may not be passed for static or delegate calls!")

if not static_call and context.is_constant():
raise StateAccessViolation(
f"Cannot make modifying calls from {context.pp_constancy()},"
" use `is_static_call=True` to perform this action",
expr,
" use `is_static_call=True` to perform this action"
)

if data.value == "~calldata":
Expand Down

0 comments on commit a2df088

Please sign in to comment.