From 55fcd6e687854321fb450cf8f385112028e875a5 Mon Sep 17 00:00:00 2001 From: user Date: Wed, 3 Apr 2024 14:53:02 +0800 Subject: [PATCH 1/3] add dencun new mcopy instr --- pyevmasm/evmasm.py | 16 +++++++++++++--- tests/test_EVMAssembler.py | 8 ++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/pyevmasm/evmasm.py b/pyevmasm/evmasm.py index 668b4ba..f722818 100644 --- a/pyevmasm/evmasm.py +++ b/pyevmasm/evmasm.py @@ -5,7 +5,7 @@ from future.builtins import next, bytes # type: ignore import copy -DEFAULT_FORK = "shanghai" +DEFAULT_FORK = "dencun" """ Example use:: @@ -1095,12 +1095,20 @@ def __repr__(self): london_instruction_table, previous_fork=istanbul_instruction_table ) -shanghai_instruction_table = {0x5f: ("PUSH", 0, 0, 1, 2, "Place 0 constant byte item on stack.")} +shanghai_instruction_table = { + 0x5F: ("PUSH", 0, 0, 1, 2, "Place 0 constant byte item on stack.") +} shanghai_instruction_table = InstructionTable( # type: ignore shanghai_instruction_table, previous_fork=london_instruction_table ) +dencun_instruction_table = {0x5E: ("MCOPY", 0, 3, 0, 3, "Copy memory areas.")} + +dencun_instruction_table = InstructionTable( # type: ignore + dencun_instruction_table, previous_fork=shanghai_instruction_table +) + accepted_forks = ( "frontier", "homestead", @@ -1112,7 +1120,8 @@ def __repr__(self): "serenity", "istanbul", "london", - "shanghai" + "shanghai", + "dencun", ) @@ -1128,6 +1137,7 @@ def __repr__(self): "istanbul": istanbul_instruction_table, "london": london_instruction_table, "shanghai": shanghai_instruction_table, + "dencun": dencun_instruction_table, } diff --git a/tests/test_EVMAssembler.py b/tests/test_EVMAssembler.py index 1a44b68..78e587f 100644 --- a/tests/test_EVMAssembler.py +++ b/tests/test_EVMAssembler.py @@ -135,6 +135,14 @@ def test_shanghai_fork(self): self.assertTrue(insn.pops == 0) self.assertTrue(insn.pushes == 1) self.assertTrue(insn.operand_size == 0) + + def test_dencun_fork(self): + insn = EVMAsm.disassemble_one(b"\x5e", fork="dencun") + self.assertTrue(insn.mnemonic == "MCOPY") + self.assertTrue(insn.fee == 3) + self.assertTrue(insn.pops == 3) + self.assertTrue(insn.pushes == 0) + self.assertTrue(insn.operand_size == 0) def test_assemble_DUP1_regression(self): insn = EVMAsm.assemble_one("DUP1") From 35491baf3f3d48f601084e31a27ae2ac017fd6e8 Mon Sep 17 00:00:00 2001 From: user Date: Wed, 3 Apr 2024 14:53:10 +0800 Subject: [PATCH 2/3] add __init__ in tests --- tests/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/__init__.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 From e2813d363e2b93aa660683441a860435fe0b3879 Mon Sep 17 00:00:00 2001 From: user Date: Wed, 3 Apr 2024 15:11:29 +0800 Subject: [PATCH 3/3] add blobhash, blobbasefee, tload, tstore instrs --- pyevmasm/evmasm.py | 15 ++++++++++++++- tests/test_EVMAssembler.py | 12 ++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/pyevmasm/evmasm.py b/pyevmasm/evmasm.py index f722818..fbce7ab 100644 --- a/pyevmasm/evmasm.py +++ b/pyevmasm/evmasm.py @@ -1103,7 +1103,20 @@ def __repr__(self): shanghai_instruction_table, previous_fork=london_instruction_table ) -dencun_instruction_table = {0x5E: ("MCOPY", 0, 3, 0, 3, "Copy memory areas.")} +dencun_instruction_table = { + 0x5E: ("MCOPY", 0, 3, 0, 3, "Copy memory areas."), + 0x49: ("BLOBHASH", 0, 1, 1, 1, "Get versioned hashes."), + 0x4A: ( + "BLOBBASEFEE", + 0, + 0, + 1, + 2, + "Returns the value of the blob base-fee of the current block.", + ), + 0x5C: ("TLOAD", 0, 1, 1, 100, "Load word from transient storage."), + 0x5D: ("TSTORE", 0, 2, 0, 100, "Save word to transient storage."), +} dencun_instruction_table = InstructionTable( # type: ignore dencun_instruction_table, previous_fork=shanghai_instruction_table diff --git a/tests/test_EVMAssembler.py b/tests/test_EVMAssembler.py index 78e587f..caf832c 100644 --- a/tests/test_EVMAssembler.py +++ b/tests/test_EVMAssembler.py @@ -144,6 +144,18 @@ def test_dencun_fork(self): self.assertTrue(insn.pushes == 0) self.assertTrue(insn.operand_size == 0) + insn = EVMAsm.disassemble_one(b"\x49", fork="dencun") + self.assertTrue(insn.mnemonic == "BLOBHASH") + + insn = EVMAsm.disassemble_one(b"\x4a", fork="dencun") + self.assertTrue(insn.mnemonic == "BLOBBASEFEE") + + insn = EVMAsm.disassemble_one(b"\x5c", fork="dencun") + self.assertTrue(insn.mnemonic=="TLOAD") + + insn = EVMAsm.disassemble_one(b"\x5d", fork="dencun") + self.assertTrue(insn.mnemonic=="TSTORE") + def test_assemble_DUP1_regression(self): insn = EVMAsm.assemble_one("DUP1") self.assertEqual(insn.mnemonic, "DUP1")