2023-11-01 03:32:09 +00:00
|
|
|
# Nimbus
|
2024-03-20 07:35:38 +00:00
|
|
|
# Copyright (c) 2019-2024 Status Research & Development GmbH
|
2023-11-01 03:32:09 +00:00
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
|
|
# http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except
|
|
|
|
# according to those terms.
|
|
|
|
|
2019-01-30 12:29:04 +00:00
|
|
|
import
|
2023-03-22 11:18:37 +00:00
|
|
|
macro_assembler,
|
|
|
|
unittest2,
|
|
|
|
eth/common
|
2019-01-30 12:29:04 +00:00
|
|
|
|
2019-09-21 05:45:23 +00:00
|
|
|
proc opMiscMain*() =
|
|
|
|
suite "Misc Opcodes":
|
2024-03-20 07:35:38 +00:00
|
|
|
assembler: # Log0 OP
|
2019-09-21 05:45:23 +00:00
|
|
|
title: "Log0"
|
|
|
|
code:
|
2024-03-20 07:35:38 +00:00
|
|
|
Push2 "0x1234"
|
|
|
|
Push1 "0x00"
|
|
|
|
Mstore
|
|
|
|
Push1 "0x20"
|
|
|
|
Push1 "0x00"
|
|
|
|
Log0
|
2019-09-21 05:45:23 +00:00
|
|
|
memory:
|
|
|
|
"0x1234"
|
|
|
|
logs:
|
|
|
|
(
|
2021-10-14 08:00:02 +00:00
|
|
|
address: "0x460121576cc7df020759730751f92bd62fd78dd6",
|
2019-09-21 05:45:23 +00:00
|
|
|
data: "0x0000000000000000000000000000000000000000000000000000000000001234"
|
|
|
|
)
|
2019-01-30 12:29:04 +00:00
|
|
|
|
2024-03-20 07:35:38 +00:00
|
|
|
assembler: # Log1 OP
|
2019-09-21 05:45:23 +00:00
|
|
|
title: "Log1"
|
|
|
|
code:
|
2024-03-20 07:35:38 +00:00
|
|
|
Push2 "0x1234"
|
|
|
|
Push1 "0x00"
|
|
|
|
Mstore
|
|
|
|
Push2 "0x9999"
|
|
|
|
Push1 "0x20"
|
|
|
|
Push1 "0x00"
|
|
|
|
Log1
|
2019-09-21 05:45:23 +00:00
|
|
|
memory:
|
|
|
|
"0x1234"
|
|
|
|
logs:
|
|
|
|
(
|
2021-10-14 08:00:02 +00:00
|
|
|
address: "0x460121576cc7df020759730751f92bd62fd78dd6",
|
2019-09-21 05:45:23 +00:00
|
|
|
topics: ["0x9999"],
|
|
|
|
data: "0x0000000000000000000000000000000000000000000000000000000000001234"
|
|
|
|
)
|
2019-01-30 12:29:04 +00:00
|
|
|
|
2024-03-20 07:35:38 +00:00
|
|
|
assembler: # Log2 OP
|
2019-09-21 05:45:23 +00:00
|
|
|
title: "Log2"
|
|
|
|
code:
|
2024-03-20 07:35:38 +00:00
|
|
|
Push2 "0x1234"
|
|
|
|
Push1 "0x00"
|
|
|
|
Mstore
|
|
|
|
Push2 "0x9999"
|
|
|
|
Push2 "0x6666"
|
|
|
|
Push1 "0x20"
|
|
|
|
Push1 "0x00"
|
|
|
|
Log2
|
2019-09-21 05:45:23 +00:00
|
|
|
memory:
|
|
|
|
"0x1234"
|
|
|
|
logs:
|
|
|
|
(
|
2021-10-14 08:00:02 +00:00
|
|
|
address: "0x460121576cc7df020759730751f92bd62fd78dd6",
|
2019-09-21 05:45:23 +00:00
|
|
|
topics: ["0x6666", "0x9999"],
|
|
|
|
data: "0x0000000000000000000000000000000000000000000000000000000000001234"
|
|
|
|
)
|
2019-01-30 12:29:04 +00:00
|
|
|
|
2024-03-20 07:35:38 +00:00
|
|
|
assembler: # Log3 OP
|
2019-09-21 05:45:23 +00:00
|
|
|
title: "Log3"
|
|
|
|
code:
|
2024-03-20 07:35:38 +00:00
|
|
|
Push2 "0x1234"
|
|
|
|
Push1 "0x00"
|
|
|
|
Mstore
|
|
|
|
Push2 "0x9999"
|
|
|
|
Push2 "0x6666"
|
|
|
|
Push2 "0x3333"
|
|
|
|
Push1 "0x20"
|
|
|
|
Push1 "0x00"
|
|
|
|
Log3
|
2019-09-21 05:45:23 +00:00
|
|
|
memory:
|
|
|
|
"0x1234"
|
|
|
|
logs:
|
|
|
|
(
|
2021-10-14 08:00:02 +00:00
|
|
|
address: "0x460121576cc7df020759730751f92bd62fd78dd6",
|
2019-09-21 05:45:23 +00:00
|
|
|
topics: ["0x3333", "0x6666", "0x9999"],
|
|
|
|
data: "0x0000000000000000000000000000000000000000000000000000000000001234"
|
|
|
|
)
|
2019-01-30 12:29:04 +00:00
|
|
|
|
2024-03-20 07:35:38 +00:00
|
|
|
assembler: # Log4 OP
|
2019-09-21 05:45:23 +00:00
|
|
|
title: "Log4"
|
|
|
|
code:
|
2024-03-20 07:35:38 +00:00
|
|
|
Push2 "0x1234"
|
|
|
|
Push1 "0x00"
|
|
|
|
Mstore
|
|
|
|
Push2 "0x9999"
|
|
|
|
Push2 "0x6666"
|
|
|
|
Push2 "0x3333"
|
|
|
|
Push2 "0x5555"
|
|
|
|
Push1 "0x20"
|
|
|
|
Push1 "0x00"
|
|
|
|
Log4
|
2019-09-21 05:45:23 +00:00
|
|
|
memory:
|
|
|
|
"0x1234"
|
|
|
|
logs:
|
|
|
|
(
|
2021-10-14 08:00:02 +00:00
|
|
|
address: "0x460121576cc7df020759730751f92bd62fd78dd6",
|
2019-09-21 05:45:23 +00:00
|
|
|
topics: ["0x5555", "0x3333", "0x6666", "0x9999"],
|
|
|
|
data: "0x0000000000000000000000000000000000000000000000000000000000001234"
|
|
|
|
)
|
2019-01-30 12:29:04 +00:00
|
|
|
|
2024-03-20 07:35:38 +00:00
|
|
|
assembler: # Stop OP
|
|
|
|
title: "Stop_1"
|
2019-09-21 05:45:23 +00:00
|
|
|
code:
|
2024-03-20 07:35:38 +00:00
|
|
|
Push1 "0x20"
|
|
|
|
Push1 "0x30"
|
|
|
|
Push1 "0x10"
|
|
|
|
Push1 "0x30"
|
|
|
|
Push1 "0x11"
|
|
|
|
Push1 "0x23"
|
|
|
|
Stop
|
2019-09-21 05:45:23 +00:00
|
|
|
stack:
|
|
|
|
"0x20"
|
|
|
|
"0x30"
|
|
|
|
"0x10"
|
|
|
|
"0x30"
|
|
|
|
"0x11"
|
|
|
|
"0x23"
|
2019-01-30 12:29:04 +00:00
|
|
|
|
2024-03-20 07:35:38 +00:00
|
|
|
assembler: # Return OP
|
|
|
|
title: "Return_1"
|
2019-09-21 05:45:23 +00:00
|
|
|
code:
|
2024-03-20 07:35:38 +00:00
|
|
|
Push2 "0x1234"
|
|
|
|
Push1 "0x00"
|
|
|
|
Mstore
|
|
|
|
Push1 "0x20"
|
|
|
|
Push1 "0x00"
|
|
|
|
Return
|
2019-09-21 05:45:23 +00:00
|
|
|
memory: "0x1234"
|
|
|
|
output: "0x0000000000000000000000000000000000000000000000000000000000001234"
|
2019-01-30 12:29:04 +00:00
|
|
|
|
2024-03-20 07:35:38 +00:00
|
|
|
assembler: # Return OP
|
|
|
|
title: "Return_2"
|
2019-09-21 05:45:23 +00:00
|
|
|
code:
|
2024-03-20 07:35:38 +00:00
|
|
|
Push2 "0x1234"
|
|
|
|
Push1 "0x00"
|
|
|
|
Mstore
|
|
|
|
Push1 "0x20"
|
|
|
|
Push1 "0x1F"
|
|
|
|
Return
|
2019-09-21 05:45:23 +00:00
|
|
|
memory:
|
|
|
|
"0x1234"
|
|
|
|
"0x00"
|
|
|
|
output: "0x3400000000000000000000000000000000000000000000000000000000000000"
|
2019-01-30 12:29:04 +00:00
|
|
|
|
2024-03-20 07:35:38 +00:00
|
|
|
assembler: # Return OP
|
|
|
|
title: "Return_3"
|
2019-09-21 05:45:23 +00:00
|
|
|
code:
|
2024-03-20 07:35:38 +00:00
|
|
|
Push32 "0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B1"
|
|
|
|
Push1 "0x00"
|
|
|
|
Mstore
|
|
|
|
Push1 "0x20"
|
|
|
|
Push1 "0x00"
|
|
|
|
Return
|
2019-09-21 05:45:23 +00:00
|
|
|
memory: "0xa0b0c0d0e0f0a1b1c1d1e1f1a2b2c2d2e2f2a3b3c3d3e3f3a4b4c4d4e4f4a1b1"
|
|
|
|
output: "0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B1"
|
2019-01-30 12:29:04 +00:00
|
|
|
|
2024-03-20 07:35:38 +00:00
|
|
|
assembler: # Return OP
|
|
|
|
title: "Return_4"
|
2019-09-21 05:45:23 +00:00
|
|
|
code:
|
2024-03-20 07:35:38 +00:00
|
|
|
Push32 "0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B1"
|
|
|
|
Push1 "0x00"
|
|
|
|
Mstore
|
|
|
|
Push1 "0x20"
|
|
|
|
Push1 "0x10"
|
|
|
|
Return
|
2019-09-21 05:45:23 +00:00
|
|
|
output: "0xE2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B100000000000000000000000000000000"
|
|
|
|
memory:
|
|
|
|
"0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B1"
|
|
|
|
"0x00"
|
2021-05-16 12:31:13 +00:00
|
|
|
#[
|
|
|
|
EIP-2315: Simple Subroutines for the EVM
|
|
|
|
disabled reason: not included in Berlin hard fork
|
2020-11-25 11:23:02 +00:00
|
|
|
assembler:
|
|
|
|
title: "Simple routine"
|
|
|
|
code:
|
2024-03-20 07:35:38 +00:00
|
|
|
Push1 "0x04"
|
2020-11-25 11:23:02 +00:00
|
|
|
JUMPSUB
|
2024-03-20 07:35:38 +00:00
|
|
|
Stop
|
2020-11-25 11:23:02 +00:00
|
|
|
BEGINSUB
|
2024-03-20 07:35:38 +00:00
|
|
|
ReturnSUB
|
2020-11-25 11:23:02 +00:00
|
|
|
gasUsed: 18
|
2020-11-27 08:50:28 +00:00
|
|
|
fork: berlin
|
2020-11-25 11:23:02 +00:00
|
|
|
|
|
|
|
assembler:
|
|
|
|
title: "Two levels of subroutines"
|
|
|
|
code:
|
2024-03-20 07:35:38 +00:00
|
|
|
Push9 "0x00000000000000000C"
|
2020-11-25 11:23:02 +00:00
|
|
|
JUMPSUB
|
2024-03-20 07:35:38 +00:00
|
|
|
Stop
|
2020-11-25 11:23:02 +00:00
|
|
|
BEGINSUB
|
2024-03-20 07:35:38 +00:00
|
|
|
Push1 "0x11"
|
2020-11-25 11:23:02 +00:00
|
|
|
JUMPSUB
|
2024-03-20 07:35:38 +00:00
|
|
|
ReturnSUB
|
2020-11-25 11:23:02 +00:00
|
|
|
BEGINSUB
|
2024-03-20 07:35:38 +00:00
|
|
|
ReturnSUB
|
2020-11-25 11:23:02 +00:00
|
|
|
gasUsed: 36
|
2020-11-27 08:50:28 +00:00
|
|
|
fork: berlin
|
2020-11-25 11:23:02 +00:00
|
|
|
|
|
|
|
assembler:
|
|
|
|
title: "Failure 1: invalid jump"
|
|
|
|
code:
|
2024-03-20 07:35:38 +00:00
|
|
|
Push9 "0x01000000000000000C"
|
2020-11-25 11:23:02 +00:00
|
|
|
JUMPSUB
|
2024-03-20 07:35:38 +00:00
|
|
|
Stop
|
2020-11-25 11:23:02 +00:00
|
|
|
BEGINSUB
|
2024-03-20 07:35:38 +00:00
|
|
|
Push1 "0x11"
|
2020-11-25 11:23:02 +00:00
|
|
|
JUMPSUB
|
2024-03-20 07:35:38 +00:00
|
|
|
ReturnSUB
|
2020-11-25 11:23:02 +00:00
|
|
|
BEGINSUB
|
2024-03-20 07:35:38 +00:00
|
|
|
ReturnSUB
|
2020-11-25 11:23:02 +00:00
|
|
|
success: false
|
2020-11-27 08:50:28 +00:00
|
|
|
fork: berlin
|
2020-11-25 11:23:02 +00:00
|
|
|
|
|
|
|
assembler:
|
|
|
|
title: "Failure 2: shallow return stack"
|
|
|
|
code:
|
2024-03-20 07:35:38 +00:00
|
|
|
ReturnSUB
|
2020-11-25 11:23:02 +00:00
|
|
|
PC
|
|
|
|
PC
|
|
|
|
success: false
|
2020-11-27 08:50:28 +00:00
|
|
|
fork: berlin
|
2020-11-25 11:23:02 +00:00
|
|
|
|
|
|
|
assembler:
|
|
|
|
title: "Subroutine at end of code"
|
|
|
|
code:
|
2024-03-20 07:35:38 +00:00
|
|
|
Push1 "0x05"
|
2020-11-25 11:23:02 +00:00
|
|
|
JUMP
|
|
|
|
BEGINSUB
|
2024-03-20 07:35:38 +00:00
|
|
|
ReturnSUB
|
2020-11-25 11:23:02 +00:00
|
|
|
JUMPDEST
|
2024-03-20 07:35:38 +00:00
|
|
|
Push1 "0x03"
|
2020-11-25 11:23:02 +00:00
|
|
|
JUMPSUB
|
|
|
|
gasUsed: 30
|
2020-11-27 08:50:28 +00:00
|
|
|
fork: berlin
|
2020-11-25 11:23:02 +00:00
|
|
|
|
|
|
|
assembler:
|
|
|
|
title: "Error on 'walk-into-subroutine'"
|
|
|
|
code:
|
|
|
|
BEGINSUB
|
2024-03-20 07:35:38 +00:00
|
|
|
ReturnSUB
|
|
|
|
Stop
|
2020-11-25 11:23:02 +00:00
|
|
|
success: false
|
2020-11-27 08:50:28 +00:00
|
|
|
fork: berlin
|
2020-11-25 11:23:02 +00:00
|
|
|
|
|
|
|
assembler:
|
|
|
|
title: "sol test"
|
|
|
|
code:
|
2024-03-20 07:35:38 +00:00
|
|
|
Push1 "0x02"
|
|
|
|
Push1 "0x03"
|
|
|
|
Push1 "0x08" # jumpdest
|
2020-11-25 11:23:02 +00:00
|
|
|
JUMPSUB
|
2024-03-20 07:35:38 +00:00
|
|
|
Stop
|
2020-11-25 11:23:02 +00:00
|
|
|
|
|
|
|
# 0x08
|
|
|
|
BEGINSUB
|
2024-03-20 07:35:38 +00:00
|
|
|
Push1 "0x0D" # jumpdest
|
2020-11-25 11:23:02 +00:00
|
|
|
JUMPSUB
|
2024-03-20 07:35:38 +00:00
|
|
|
ReturnSUB
|
2020-11-25 11:23:02 +00:00
|
|
|
|
|
|
|
# 0x0D
|
|
|
|
BEGINSUB
|
|
|
|
MUL
|
2024-03-20 07:35:38 +00:00
|
|
|
ReturnSUB
|
2020-11-25 11:23:02 +00:00
|
|
|
gasUsed: 47
|
2020-11-27 08:50:28 +00:00
|
|
|
fork: berlin
|
2020-11-25 11:23:02 +00:00
|
|
|
stack:
|
|
|
|
"0x06"
|
2021-05-16 12:31:13 +00:00
|
|
|
]#
|
2020-11-25 11:23:02 +00:00
|
|
|
|
|
|
|
when isMainModule:
|
|
|
|
opMiscMain()
|