2021-04-15 13:40:31 +00:00
|
|
|
# Nimbus
|
2024-06-07 08:24:32 +00:00
|
|
|
# Copyright (c) 2018-2024 Status Research & Development GmbH
|
2021-04-15 13:40:31 +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.
|
|
|
|
|
|
|
|
## EVM Opcode Handlers: Push Operations
|
|
|
|
## ====================================
|
|
|
|
##
|
|
|
|
|
2024-06-07 08:24:32 +00:00
|
|
|
{.push raises: [].}
|
|
|
|
|
2021-04-15 13:40:31 +00:00
|
|
|
import
|
2024-06-07 08:24:32 +00:00
|
|
|
std/[sequtils],
|
2021-04-21 17:04:54 +00:00
|
|
|
../../code_stream,
|
|
|
|
../../stack,
|
2024-06-07 08:24:32 +00:00
|
|
|
../../evm_errors,
|
2021-04-21 17:04:54 +00:00
|
|
|
../op_codes,
|
2021-04-15 13:40:31 +00:00
|
|
|
./oph_defs,
|
2023-01-31 12:38:08 +00:00
|
|
|
./oph_gen_handlers
|
2021-04-15 13:40:31 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Private helpers
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc fnName(n: int): string {.compileTime.} =
|
2024-06-07 08:24:32 +00:00
|
|
|
"push" & $n & "Op"
|
2021-04-15 13:40:31 +00:00
|
|
|
|
|
|
|
proc opName(n: int): string {.compileTime.} =
|
2024-06-07 08:24:32 +00:00
|
|
|
"Push" & $n
|
2021-04-15 13:40:31 +00:00
|
|
|
|
|
|
|
proc fnInfo(n: int): string {.compileTime.} =
|
|
|
|
var blurb = case n
|
|
|
|
of 1: "byte"
|
2024-06-07 08:24:32 +00:00
|
|
|
else: $n & " bytes"
|
|
|
|
"Push " & blurb & " on the stack"
|
2021-04-15 13:40:31 +00:00
|
|
|
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
template pushImpl(cpt: VmCpt; n: static int): EvmResultVoid =
|
|
|
|
cpt.stack.push cpt.code.readVmWord(n)
|
2021-04-15 13:40:31 +00:00
|
|
|
|
|
|
|
const
|
|
|
|
inxRange = toSeq(1 .. 32)
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Private, op handlers implementation
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
genOphHandlers fnName, fnInfo, inxRange, pushImpl
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public, op exec table entries
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2024-06-15 16:18:53 +00:00
|
|
|
genOphList fnName, fnInfo, inxRange, "VmOpExecPush", opName
|
2021-04-15 13:40:31 +00:00
|
|
|
|
2023-01-04 13:11:33 +00:00
|
|
|
|
|
|
|
# Push0 needs to be slightly different because it's only available after
|
|
|
|
# Shanghai (EIP-3855). But it still seems like it belongs in this file.
|
|
|
|
# (Alternatively, we could make genOphList accept some more information
|
|
|
|
# about which opcodes are for which forks, but that seems uglier than
|
|
|
|
# just adding Push0 here as a special case.)
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
proc push0Op(cpt: VmCpt): EvmResultVoid =
|
2024-06-17 16:13:38 +00:00
|
|
|
## 0x5f, push 0 onto the stack
|
2024-07-19 01:44:01 +00:00
|
|
|
cpt.stack.push(0)
|
2024-06-07 08:24:32 +00:00
|
|
|
|
2024-06-17 16:13:38 +00:00
|
|
|
const
|
2024-06-15 16:18:53 +00:00
|
|
|
VmOpExecPushZero*: seq[VmOpExec] = @[
|
2023-01-04 13:11:33 +00:00
|
|
|
|
|
|
|
(opCode: Push0, ## 0x5f, push 0 onto the stack
|
2024-06-15 16:18:53 +00:00
|
|
|
forks: VmOpShanghaiAndLater,
|
2023-01-04 13:11:33 +00:00
|
|
|
name: "Push0",
|
|
|
|
info: "Push 0 on the stack",
|
2024-06-24 05:58:15 +00:00
|
|
|
exec: push0Op)]
|
2023-01-04 13:11:33 +00:00
|
|
|
|
2021-04-15 13:40:31 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|