From a2df08888c318713742c57f71465f32a1c27ed72 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Wed, 31 Jan 2024 10:05:40 -0800 Subject: [PATCH] fix: disallow `value=` passing for delegate and static raw_calls (#3755) --- .../functional/builtins/codegen/test_raw_call.py | 16 ++++++++++++++++ vyper/builtins/functions.py | 9 ++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/tests/functional/builtins/codegen/test_raw_call.py b/tests/functional/builtins/codegen/test_raw_call.py index 4d37176cf8..b75b5da89b 100644 --- a/tests/functional/builtins/codegen/test_raw_call.py +++ b/tests/functional/builtins/codegen/test_raw_call.py @@ -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) diff --git a/vyper/builtins/functions.py b/vyper/builtins/functions.py index 8ee6f5fd76..50ab4dacd8 100644 --- a/vyper/builtins/functions.py +++ b/vyper/builtins/functions.py @@ -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":