From de8666b7286a9e1df748dfd7b646905f9d1c6a36 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Tue, 26 Sep 2023 12:25:27 -0400 Subject: [PATCH 1/3] fix: type check abi_decode arguments currently, the following code will trigger a compiler panic: ```vyper @external def foo(j: uint256) -> bool: s: bool = _abi_decode(j, bool, unwrap_tuple= False) return s ``` --- vyper/builtins/functions.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vyper/builtins/functions.py b/vyper/builtins/functions.py index 95759372a6..9646b92141 100644 --- a/vyper/builtins/functions.py +++ b/vyper/builtins/functions.py @@ -2494,6 +2494,8 @@ def fetch_call_return(self, node): return output_type.typedef def infer_arg_types(self, node): + self._validate_arg_types(node) + validate_call_args(node, 2, ["unwrap_tuple"]) data_type = get_exact_type_from_node(node.args[0]) From 8f2a9692a033e987e1c2079f96b38dbbb6f49d8f Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Tue, 26 Sep 2023 18:31:25 -0400 Subject: [PATCH 2/3] add syntax tests for abi decode --- tests/parser/syntax/test_abi_decode.py | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/parser/syntax/test_abi_decode.py diff --git a/tests/parser/syntax/test_abi_decode.py b/tests/parser/syntax/test_abi_decode.py new file mode 100644 index 0000000000..e2ddedd6a4 --- /dev/null +++ b/tests/parser/syntax/test_abi_decode.py @@ -0,0 +1,45 @@ +import pytest + +from vyper import compiler +from vyper.exceptions import InvalidType, TypeMismatch + +fail_list = [ + ( + """ +@external +def foo(j: uint256) -> bool: + s: bool = _abi_decode(j, bool, unwrap_tuple= False) + return s + """, + TypeMismatch, + ), + ( + """ +@external +def bar(j: String[32]) -> bool: + s: bool = _abi_decode(j, bool, unwrap_tuple= False) + return s + """, + TypeMismatch, + ), +] + + +@pytest.mark.parametrize("bad_code,exc", fail_list) +def test_abi_encode_fail(bad_code, exc): + with pytest.raises(exc): + compiler.compile_code(bad_code) + + +valid_list = [ + """ +@external +def foo(x: Bytes[32]) -> uint256: + return _abi_decode(x, uint256) + """, +] + + +@pytest.mark.parametrize("good_code", valid_list) +def test_abi_encode_success(good_code): + assert compiler.compile_code(good_code) is not None From 335da2eb4796bc3ae2a3e354c3b59b8e82f5b1fb Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Tue, 26 Sep 2023 18:31:58 -0400 Subject: [PATCH 3/3] fix lint --- tests/parser/syntax/test_abi_decode.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/parser/syntax/test_abi_decode.py b/tests/parser/syntax/test_abi_decode.py index e2ddedd6a4..f05ff429cd 100644 --- a/tests/parser/syntax/test_abi_decode.py +++ b/tests/parser/syntax/test_abi_decode.py @@ -1,7 +1,7 @@ import pytest from vyper import compiler -from vyper.exceptions import InvalidType, TypeMismatch +from vyper.exceptions import TypeMismatch fail_list = [ ( @@ -36,7 +36,7 @@ def test_abi_encode_fail(bad_code, exc): @external def foo(x: Bytes[32]) -> uint256: return _abi_decode(x, uint256) - """, + """ ]