Skip to content

Commit

Permalink
fix: implements check for indexed event arguments
Browse files Browse the repository at this point in the history
prior to this commit, implementing an interface with wrong indexed
arguments for an event would pass the implements check. this commit
fixes the behavior.

chainsec june 2023 review 5.12
  • Loading branch information
charles-cooper committed Aug 28, 2023
1 parent 43c8d85 commit 3f5e703
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions vyper/semantics/types/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def __init__(self, name: str, arguments: dict, indexed: list) -> None:
super().__init__(members=arguments)
self.name = name
self.indexed = indexed
assert len(self.indexed) == len(self.arguments)
self.event_id = int(keccak256(self.signature.encode()).hex(), 16)

# backward compatible
Expand All @@ -172,8 +173,13 @@ def arguments(self):
return self.members

def __repr__(self):
arg_types = ",".join(repr(a) for a in self.arguments.values())
return f"event {self.name}({arg_types})"
args = []
for is_indexed, (_, argtype) in zip(self.indexed, self.arguments.items()):
argtype_str = repr(argtype)
if is_indexed:
argtype_str = f"indexed({argtype_str})"
args.append(f"{argtype_str}")
return f"event {self.name}({','.join(args)})"

# TODO rename to abi_signature
@property
Expand Down Expand Up @@ -337,12 +343,12 @@ def _is_function_implemented(fn_name, fn_type):

# check for missing events
for name, event in self.events.items():
if (
name not in namespace
or not isinstance(namespace[name], EventT)
or namespace[name].event_id != event.event_id
):
if ( name not in namespace):
unimplemented.append(name)
if not isinstance(namespace[name], EventT):
unimplemented.append(f"{name} is not an event!")
if namespace[name].event_id != event.event_id or namespace[name].indexed != event.indexed:
unimplemented.append(f"{name} is not implemented! (should be {event})")

if len(unimplemented) > 0:
# TODO: improve the error message for cases where the
Expand Down

0 comments on commit 3f5e703

Please sign in to comment.