From 1a439c553083f6b8316365dcf4675d47d0d5195b Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Fri, 23 Feb 2024 18:19:02 +0800 Subject: [PATCH 1/6] add payable check --- vyper/semantics/types/function.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vyper/semantics/types/function.py b/vyper/semantics/types/function.py index 43d553288e..b381a5a217 100644 --- a/vyper/semantics/types/function.py +++ b/vyper/semantics/types/function.py @@ -483,6 +483,9 @@ def implements(self, other: "ContractFunctionT") -> bool: if self.mutability > other.mutability: return False + if other.is_payable and not self.is_payable: + return False + return True @cached_property From f557b9e02f468b9e35cab7320880e278a076c773 Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Fri, 23 Feb 2024 18:19:07 +0800 Subject: [PATCH 2/6] add test --- tests/functional/syntax/test_interfaces.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/functional/syntax/test_interfaces.py b/tests/functional/syntax/test_interfaces.py index a07ec4e3dc..8631df34c0 100644 --- a/tests/functional/syntax/test_interfaces.py +++ b/tests/functional/syntax/test_interfaces.py @@ -210,6 +210,20 @@ def approve(_spender : address, _value : uint256) -> bool: """, InterfaceViolation, ), + ( + # `payable` decorator not implemented + """ +interface testI: + def foo() -> uint256: payable + +implements: testI + +@external +def foo() -> uint256: + return 0 + """, + InterfaceViolation, + ) ] From 0e0f6ef790ea4b277a599924af6613ff0ea0adba Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Fri, 23 Feb 2024 18:24:08 +0800 Subject: [PATCH 3/6] fix lint --- tests/functional/syntax/test_interfaces.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/syntax/test_interfaces.py b/tests/functional/syntax/test_interfaces.py index 8631df34c0..b211253b66 100644 --- a/tests/functional/syntax/test_interfaces.py +++ b/tests/functional/syntax/test_interfaces.py @@ -223,7 +223,7 @@ def foo() -> uint256: return 0 """, InterfaceViolation, - ) + ), ] From a04453e333164d51946486a785c70f5701510ed8 Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Sun, 25 Feb 2024 12:34:03 +0800 Subject: [PATCH 4/6] apply suggestion --- vyper/semantics/types/function.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/vyper/semantics/types/function.py b/vyper/semantics/types/function.py index b381a5a217..895f098c56 100644 --- a/vyper/semantics/types/function.py +++ b/vyper/semantics/types/function.py @@ -480,13 +480,7 @@ def implements(self, other: "ContractFunctionT") -> bool: if return_type and not return_type.compare_type(other_return_type): # type: ignore return False - if self.mutability > other.mutability: - return False - - if other.is_payable and not self.is_payable: - return False - - return True + return self.mutability == other.mutability @cached_property def default_values(self) -> dict[str, vy_ast.VyperNode]: From 4e5f416fe4d255632ba2b7db61e7c8a94cc7c3b5 Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Sun, 25 Feb 2024 12:36:23 +0800 Subject: [PATCH 5/6] add tests --- tests/functional/syntax/test_interfaces.py | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/functional/syntax/test_interfaces.py b/tests/functional/syntax/test_interfaces.py index b211253b66..15a90602fc 100644 --- a/tests/functional/syntax/test_interfaces.py +++ b/tests/functional/syntax/test_interfaces.py @@ -224,6 +224,36 @@ def foo() -> uint256: """, InterfaceViolation, ), + ( + # decorators must be strictly identical + """ +interface Self: + def protected_view_fn() -> String[100]: nonpayable + +implements: Self + +@external +@pure +def protected_view_fn() -> String[100]: + return empty(String[100]) + """, + InterfaceViolation, + ), + ( + # decorators must be strictly identical + """ +interface Self: + def protected_view_fn() -> String[100]: view + +implements: Self + +@external +@pure +def protected_view_fn() -> String[100]: + return empty(String[100]) + """, + InterfaceViolation, + ), ] From f6458c238daf7f6b1a71bcfa6da3f94498fcc09b Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Sun, 25 Feb 2024 15:53:58 +0800 Subject: [PATCH 6/6] fix erc165 in examples --- examples/tokens/ERC1155ownable.vy | 2 +- examples/tokens/ERC721.vy | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/tokens/ERC1155ownable.vy b/examples/tokens/ERC1155ownable.vy index 9e07234fc8..b8513243d4 100644 --- a/examples/tokens/ERC1155ownable.vy +++ b/examples/tokens/ERC1155ownable.vy @@ -393,7 +393,7 @@ def setContractURI(contractUri: String[MAX_URI_LENGTH]): self.contractURI = contractUri log URI(contractUri, 0) -@pure +@view @external def supportsInterface(interfaceId: bytes4) -> bool: """ diff --git a/examples/tokens/ERC721.vy b/examples/tokens/ERC721.vy index 31a1353924..2399f31947 100644 --- a/examples/tokens/ERC721.vy +++ b/examples/tokens/ERC721.vy @@ -93,7 +93,7 @@ def __init__(): self.baseURL = "https://api.babby.xyz/metadata/" -@pure +@view @external def supportsInterface(interface_id: bytes4) -> bool: """