From 65401334041ec6da24f2e1bec11b71dce254682a Mon Sep 17 00:00:00 2001 From: trocher <43437004+trocher@users.noreply.github.com> Date: Thu, 18 Jan 2024 10:09:01 +0100 Subject: [PATCH 1/2] fix opcodes and opcodes_runtime output --- tests/unit/compiler/test_opcodes.py | 12 ++++++++++++ vyper/compiler/output.py | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/unit/compiler/test_opcodes.py b/tests/unit/compiler/test_opcodes.py index 15d2a617ba..17cc00477e 100644 --- a/tests/unit/compiler/test_opcodes.py +++ b/tests/unit/compiler/test_opcodes.py @@ -1,6 +1,7 @@ import pytest import vyper +from vyper.compiler.output import _build_opcodes from vyper.evm import opcodes from vyper.exceptions import CompilerPanic @@ -64,3 +65,14 @@ def test_get_opcodes(evm_version): else: for op in ("TLOAD", "TSTORE", "MCOPY"): assert op not in ops + + +def test_build_opcodes(): + assert _build_opcodes(bytes.fromhex("610100")) == "PUSH2 0x0100" + assert _build_opcodes(bytes.fromhex("62010300")) == "PUSH3 0x010300" + assert ( + _build_opcodes( + bytes.fromhex("7f6100000000000000000000000000000000000000000000000000000000000000") + ) + == "PUSH32 0x6100000000000000000000000000000000000000000000000000000000000000" + ) diff --git a/vyper/compiler/output.py b/vyper/compiler/output.py index 5e11a20139..b9ce39ff08 100644 --- a/vyper/compiler/output.py +++ b/vyper/compiler/output.py @@ -330,7 +330,7 @@ def _build_opcodes(bytecode: bytes) -> str: # (instead of code) at end of contract # CMC 2023-07-13 maybe just strip known data segments? push_len = min(push_len, len(bytecode_sequence)) - push_values = [hex(bytecode_sequence.popleft())[2:] for i in range(push_len)] - opcode_output.append(f"0x{''.join(push_values).upper()}") + push_values = [f"{bytecode_sequence.popleft():0>2X}" for i in range(push_len)] + opcode_output.append(f"0x{''.join(push_values)}") return " ".join(opcode_output) From 5744d71e80f500c1a3095855ecce6e1a4e1912a0 Mon Sep 17 00:00:00 2001 From: trocher <43437004+trocher@users.noreply.github.com> Date: Thu, 18 Jan 2024 14:34:09 +0100 Subject: [PATCH 2/2] add more ambiguous tests --- tests/unit/compiler/test_opcodes.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/compiler/test_opcodes.py b/tests/unit/compiler/test_opcodes.py index 17cc00477e..ed64f343c4 100644 --- a/tests/unit/compiler/test_opcodes.py +++ b/tests/unit/compiler/test_opcodes.py @@ -68,7 +68,10 @@ def test_get_opcodes(evm_version): def test_build_opcodes(): + assert _build_opcodes(bytes.fromhex("610250")) == "PUSH2 0x0250" + assert _build_opcodes(bytes.fromhex("612500")) == "PUSH2 0x2500" assert _build_opcodes(bytes.fromhex("610100")) == "PUSH2 0x0100" + assert _build_opcodes(bytes.fromhex("611000")) == "PUSH2 0x1000" assert _build_opcodes(bytes.fromhex("62010300")) == "PUSH3 0x010300" assert ( _build_opcodes(