Skip to content

Commit

Permalink
Merge pull request vyperlang#555 from DavidKnott/add-logging-bytes-check
Browse files Browse the repository at this point in the history
Add length check to event topics
  • Loading branch information
DavidKnott authored Dec 15, 2017
2 parents af740fa + 43c8ef6 commit c5a4a7a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions tests/parser/features/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,3 +640,21 @@ def set_list():
c.set_list()
c.foo()
assert get_last_log(t, c)["_value"] == [1.33, 2.33, 3.33, 4.33]


def test_logging_fails_when_declartation_is_too_big(assert_tx_failed, get_contract_with_gas_estimation):
code = """
Bar: __log__({_value: indexed(bytes <= 33)})
"""
assert_tx_failed(lambda: get_contract_with_gas_estimation(code), VariableDeclarationException)


def test_logging_fails_when_input_is_too_big(assert_tx_failed, get_contract_with_gas_estimation):
code = """
Bar: __log__({_value: indexed(bytes <= 32)})
@public
def foo(inp: bytes <= 33):
log.Bar(inp)
"""
assert_tx_failed(lambda: get_contract_with_gas_estimation(code), TypeMismatchException)
4 changes: 2 additions & 2 deletions viper/signatures/event_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def from_declaration(cls, code):
else:
raise VariableDeclarationException("Only indexed keyword is allowed", arg)
else:
if hasattr(typ, 'left') and typ.left.id == 'bytes' and typ.comparators[0].n > 32:
raise VariableDeclarationException("Can only log a maximum of 32 bytes at a time.")
indexed_list.append(False)
if hasattr(typ, 'left') and typ.left.id == 'bytes' and typ.comparators[0].n > 32:
raise VariableDeclarationException("Can only log a maximum of 32 bytes at a time.")
if topics_count > 4:
raise VariableDeclarationException("Maximum of 3 topics {} given".format(topics_count - 1), arg)
if not isinstance(arg, str):
Expand Down

0 comments on commit c5a4a7a

Please sign in to comment.