From ed2e58365fcca12fc452aac990eee0b3c60c0d2f Mon Sep 17 00:00:00 2001 From: cyberthirst Date: Fri, 26 Apr 2024 15:58:25 +0200 Subject: [PATCH 1/5] fix unwrap of args in raw_log --- vyper/builtins/functions.py | 1 + 1 file changed, 1 insertion(+) diff --git a/vyper/builtins/functions.py b/vyper/builtins/functions.py index 35cbbe648d..33f8f25bcf 100644 --- a/vyper/builtins/functions.py +++ b/vyper/builtins/functions.py @@ -1263,6 +1263,7 @@ def infer_arg_types(self, node, expected_return_typ=None): def build_IR(self, expr, args, kwargs, context): topics_length = len(expr.args[0].elements) topics = args[0].args + topics = [unwrap_location(topic) for topic in topics] # sanity check topics is a literal list assert args[0].value in ("~empty", "multi") From d111a30d2879a0f949fc8e7250c68475eabdbbe4 Mon Sep 17 00:00:00 2001 From: cyberthirst Date: Fri, 26 Apr 2024 15:58:35 +0200 Subject: [PATCH 2/5] add tests for raw_log --- .../codegen/features/test_logging.py | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tests/functional/codegen/features/test_logging.py b/tests/functional/codegen/features/test_logging.py index f8d30429a8..e5d0665e36 100644 --- a/tests/functional/codegen/features/test_logging.py +++ b/tests/functional/codegen/features/test_logging.py @@ -789,6 +789,63 @@ def ioo(inp: Bytes[100]): print("Passed raw log tests") +def test_raw_log_with_topics_in_storage_locs(w3, tester, get_contract): + t1 = '0x1111111111111111111111111111111111111111111111111111111111111111' + t2 = '0x2222222222222222222222222222222222222222222222222222222222222222' + code = f""" +x: bytes32 + +@external +def foo(): + self.x = {t1} + raw_log([self.x], b"") + + y: bytes32 = {t2} + raw_log([y], b"") + """ + + c = get_contract(code) + + tx_hash = c.foo(transact={}) + receipt = tester.get_transaction_receipt(tx_hash.hex()) + logs = receipt["logs"] + + assert len(logs) == 2 + assert logs[0]["topics"] == (t1,) + assert logs[1]["topics"] == (t2,) + + +def test_raw_log_with_topics_in_storage_locs2(w3, tester, get_contract): + t1 = '0x1111111111111111111111111111111111111111111111111111111111111111' + t2 = '0x2222222222222222222222222222222222222222222222222222222222222222' + t3 = '0x3333333333333333333333333333333333333333333333333333333333333333' + t4 = '0x4444444444444444444444444444444444444444444444444444444444444444' + code = f""" +x: bytes32 +x2: bytes32 + +@external +def foo(): + self.x = {t1} + self.x2 = {t2} + y: bytes32 = {t3} + y2: bytes32 = {t4} + raw_log([self.x, y, self.x2, y2], b"") + + raw_log([y, self.x], b"") + """ + + c = get_contract(code) + + tx_hash = c.foo(transact={}) + receipt = tester.get_transaction_receipt(tx_hash.hex()) + logs = receipt["logs"] + + assert len(logs) == 2 + assert logs[0]["topics"] == (t1, t3, t2, t4) + assert logs[1]["topics"] == (t3, t1) + + def test_raw_call_bytes32_data(w3, tester, get_contract_with_gas_estimation): code = """ b: uint256 From f35ec845b1e258e5d30589b8ffe0686c9a003f79 Mon Sep 17 00:00:00 2001 From: cyberthirst Date: Sun, 12 May 2024 15:09:51 +0200 Subject: [PATCH 3/5] remove w3 reference --- .../codegen/features/test_logging.py | 44 +++++++++---------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/tests/functional/codegen/features/test_logging.py b/tests/functional/codegen/features/test_logging.py index 015895f8d0..d3258ed02a 100644 --- a/tests/functional/codegen/features/test_logging.py +++ b/tests/functional/codegen/features/test_logging.py @@ -749,37 +749,35 @@ def ioo(inp: Bytes[100]): print("Passed raw log tests") -def test_raw_log_with_topics_in_storage_locs(w3, tester, get_contract): - t1 = '0x1111111111111111111111111111111111111111111111111111111111111111' - t2 = '0x2222222222222222222222222222222222222222222222222222222222222222' +def test_raw_log_with_topics_in_storage_locs(get_contract, get_logs): + t1 = "0x1111111111111111111111111111111111111111111111111111111111111111" + t2 = "0x2222222222222222222222222222222222222222222222222222222222222222" code = f""" x: bytes32 @external def foo(): self.x = {t1} - raw_log([self.x], b"") + raw_log([self.x], b"") y: bytes32 = {t2} - raw_log([y], b"") + raw_log([y], b"") """ c = get_contract(code) - - tx_hash = c.foo(transact={}) - receipt = tester.get_transaction_receipt(tx_hash.hex()) - logs = receipt["logs"] + c.foo() + logs = get_logs(c, raw=True) assert len(logs) == 2 - assert logs[0]["topics"] == (t1,) - assert logs[1]["topics"] == (t2,) + assert logs[0][0][0] == int(t1, 16).to_bytes(32, "big") + assert logs[1][0][0] == int(t2, 16).to_bytes(32, "big") -def test_raw_log_with_topics_in_storage_locs2(w3, tester, get_contract): - t1 = '0x1111111111111111111111111111111111111111111111111111111111111111' - t2 = '0x2222222222222222222222222222222222222222222222222222222222222222' - t3 = '0x3333333333333333333333333333333333333333333333333333333333333333' - t4 = '0x4444444444444444444444444444444444444444444444444444444444444444' +def test_raw_log_with_topics_in_storage_locs2(get_contract, get_logs): + t1 = "0x1111111111111111111111111111111111111111111111111111111111111111" + t2 = "0x2222222222222222222222222222222222222222222222222222222222222222" + t3 = "0x3333333333333333333333333333333333333333333333333333333333333333" + t4 = "0x4444444444444444444444444444444444444444444444444444444444444444" code = f""" x: bytes32 x2: bytes32 @@ -790,20 +788,18 @@ def foo(): self.x2 = {t2} y: bytes32 = {t3} y2: bytes32 = {t4} - raw_log([self.x, y, self.x2, y2], b"") + raw_log([self.x, y, self.x2, y2], b"") - raw_log([y, self.x], b"") + raw_log([y, self.x], b"") """ c = get_contract(code) - - tx_hash = c.foo(transact={}) - receipt = tester.get_transaction_receipt(tx_hash.hex()) - logs = receipt["logs"] + c.foo() + logs = get_logs(c, raw=True) assert len(logs) == 2 - assert logs[0]["topics"] == (t1, t3, t2, t4) - assert logs[1]["topics"] == (t3, t1) + assert logs[0][0] == [int(t, 16).to_bytes(32, "big") for t in [t1, t3, t2, t4]] + assert logs[1][0] == [int(t, 16).to_bytes(32, "big") for t in [t3, t1]] def test_raw_call_bytes32_data(get_logs, get_contract): From 6283586b8e23df65e86930b3d35f1bd829822566 Mon Sep 17 00:00:00 2001 From: cyberthirst Date: Sun, 12 May 2024 15:28:32 +0200 Subject: [PATCH 4/5] use make_setter in raw log --- vyper/builtins/functions.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/vyper/builtins/functions.py b/vyper/builtins/functions.py index 0e4bc26b3a..3fd6d1bc97 100644 --- a/vyper/builtins/functions.py +++ b/vyper/builtins/functions.py @@ -1284,12 +1284,7 @@ def build_IR(self, expr, args, kwargs, context): placeholder = context.new_internal_variable(BYTES32_T) log_ir = [log_op, placeholder, 32] + topics return IRnode.from_list( - [ - "seq", - # TODO use make_setter - ["mstore", placeholder, unwrap_location(data)], - ensure_eval_once("raw_log", log_ir), - ] + ["seq", make_setter(placeholder, data), ensure_eval_once("raw_log", log_ir)] ) input_buf = ensure_in_memory(data, context) From b155e64bdc107c70c1e68392cd79d3546af0a773 Mon Sep 17 00:00:00 2001 From: cyberthirst Date: Sun, 12 May 2024 15:33:52 +0200 Subject: [PATCH 5/5] add double eval test for topics --- .../codegen/features/test_logging.py | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/functional/codegen/features/test_logging.py b/tests/functional/codegen/features/test_logging.py index d3258ed02a..c741ab9b18 100644 --- a/tests/functional/codegen/features/test_logging.py +++ b/tests/functional/codegen/features/test_logging.py @@ -749,17 +749,39 @@ def ioo(inp: Bytes[100]): print("Passed raw log tests") +def test_raw_log_topic_double_eval(get_contract, get_logs): + t1 = "0x1111111111111111111111111111111111111111111111111111111111111111" + code = f""" +x: bytes32 +c: public(uint256) + +@internal +def bar() -> bytes32: + self.c += 1 + return {t1} + +@external +def foo(): + self.x = {t1} + raw_log([self.bar(), self.bar()], b"") + + """ + + c = get_contract(code) + c.foo() + + assert c.c() == 2 + + def test_raw_log_with_topics_in_storage_locs(get_contract, get_logs): t1 = "0x1111111111111111111111111111111111111111111111111111111111111111" t2 = "0x2222222222222222222222222222222222222222222222222222222222222222" code = f""" x: bytes32 - @external def foo(): self.x = {t1} raw_log([self.x], b"") - y: bytes32 = {t2} raw_log([y], b"") """