2021-04-12 17:13:30 +00:00
|
|
|
|
# Nimbus
|
2024-06-07 08:24:32 +00:00
|
|
|
|
# Copyright (c) 2018-2024 Status Research & Development GmbH
|
2021-04-12 17:13:30 +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: Arithmetic and Logic Operators
|
|
|
|
|
## ===================================================
|
|
|
|
|
##
|
|
|
|
|
|
2024-06-07 08:24:32 +00:00
|
|
|
|
{.push raises: [].}
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
import
|
2023-01-31 12:38:08 +00:00
|
|
|
|
std/options,
|
2021-04-21 17:04:54 +00:00
|
|
|
|
../../../constants,
|
2021-04-26 16:00:46 +00:00
|
|
|
|
../../computation,
|
2024-06-07 08:24:32 +00:00
|
|
|
|
../../evm_errors,
|
2021-04-21 17:04:54 +00:00
|
|
|
|
../../stack,
|
2021-04-22 16:05:58 +00:00
|
|
|
|
../../types,
|
2021-04-21 17:04:54 +00:00
|
|
|
|
../op_codes,
|
|
|
|
|
../gas_costs,
|
2021-04-22 16:05:58 +00:00
|
|
|
|
../utils/utils_numeric,
|
2021-04-12 17:13:30 +00:00
|
|
|
|
./oph_defs,
|
2023-01-31 12:38:08 +00:00
|
|
|
|
eth/common
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
2023-09-13 02:32:38 +00:00
|
|
|
|
func slt(x, y: UInt256): bool =
|
|
|
|
|
type SignedWord = signedWordType(UInt256)
|
|
|
|
|
let x_neg = cast[SignedWord](x.mostSignificantWord) < 0
|
|
|
|
|
let y_neg = cast[SignedWord](y.mostSignificantWord) < 0
|
|
|
|
|
if x_neg xor y_neg: x_neg else: x < y
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
# Private, op handlers implementation
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
2024-06-17 16:13:38 +00:00
|
|
|
|
proc addOp (k: var VmCtx): EvmResultVoid =
|
|
|
|
|
## 0x01, Addition
|
|
|
|
|
let (lhs, rhs) = ? k.cpt.stack.popInt(2)
|
|
|
|
|
k.cpt.stack.push(lhs + rhs)
|
|
|
|
|
|
|
|
|
|
proc mulOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
## 0x02, Multiplication
|
|
|
|
|
let (lhs, rhs) = ? k.cpt.stack.popInt(2)
|
|
|
|
|
k.cpt.stack.push(lhs * rhs)
|
|
|
|
|
|
|
|
|
|
proc subOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
## 0x03, Substraction
|
|
|
|
|
let (lhs, rhs) = ? k.cpt.stack.popInt(2)
|
|
|
|
|
k.cpt.stack.push(lhs - rhs)
|
|
|
|
|
|
|
|
|
|
proc divideOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
## 0x04, Division
|
|
|
|
|
let
|
|
|
|
|
(lhs, rhs) = ? k.cpt.stack.popInt(2)
|
|
|
|
|
value = if rhs.isZero:
|
|
|
|
|
# EVM special casing of div by 0
|
|
|
|
|
zero(UInt256)
|
|
|
|
|
else:
|
|
|
|
|
lhs div rhs
|
2024-06-07 08:24:32 +00:00
|
|
|
|
|
2024-06-17 16:13:38 +00:00
|
|
|
|
k.cpt.stack.push value
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2024-06-17 16:13:38 +00:00
|
|
|
|
proc sdivOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
## 0x05, Signed division
|
|
|
|
|
let (lhs, rhs) = ? k.cpt.stack.popInt(2)
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2024-06-17 16:13:38 +00:00
|
|
|
|
var r: UInt256
|
|
|
|
|
if rhs.isZero.not:
|
|
|
|
|
var a = lhs
|
|
|
|
|
var b = rhs
|
|
|
|
|
var signA, signB: bool
|
|
|
|
|
extractSign(a, signA)
|
|
|
|
|
extractSign(b, signB)
|
|
|
|
|
r = a div b
|
|
|
|
|
setSign(r, signA xor signB)
|
|
|
|
|
k.cpt.stack.push(r)
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2024-06-17 16:13:38 +00:00
|
|
|
|
proc moduloOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
## 0x06, Modulo
|
|
|
|
|
let
|
|
|
|
|
(lhs, rhs) = ? k.cpt.stack.popInt(2)
|
|
|
|
|
value = if rhs.isZero:
|
|
|
|
|
zero(UInt256)
|
|
|
|
|
else:
|
|
|
|
|
lhs mod rhs
|
2024-06-07 08:24:32 +00:00
|
|
|
|
|
2024-06-17 16:13:38 +00:00
|
|
|
|
k.cpt.stack.push value
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2024-06-17 16:13:38 +00:00
|
|
|
|
proc smodOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
## 0x07, Signed modulo
|
|
|
|
|
let (lhs, rhs) = ? k.cpt.stack.popInt(2)
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2024-06-17 16:13:38 +00:00
|
|
|
|
var r: UInt256
|
|
|
|
|
if rhs.isZero.not:
|
|
|
|
|
var sign: bool
|
|
|
|
|
var v = lhs
|
|
|
|
|
var m = rhs
|
|
|
|
|
extractSign(m, sign)
|
|
|
|
|
extractSign(v, sign)
|
|
|
|
|
r = v mod m
|
|
|
|
|
setSign(r, sign)
|
|
|
|
|
k.cpt.stack.push(r)
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2024-06-17 16:13:38 +00:00
|
|
|
|
proc addmodOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
## 0x08, Modulo addition
|
|
|
|
|
## Intermediate computations do not roll over at 2^256
|
|
|
|
|
let
|
|
|
|
|
(lhs, rhs, modulus) = ? k.cpt.stack.popInt(3)
|
|
|
|
|
value = if modulus.isZero:
|
|
|
|
|
zero(UInt256)
|
|
|
|
|
else:
|
|
|
|
|
addmod(lhs, rhs, modulus)
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2024-06-17 16:13:38 +00:00
|
|
|
|
k.cpt.stack.push value
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2024-06-17 16:13:38 +00:00
|
|
|
|
proc mulmodOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
## 0x09, Modulo multiplication
|
|
|
|
|
## Intermediate computations do not roll over at 2^256
|
|
|
|
|
let
|
|
|
|
|
(lhs, rhs, modulus) = ? k.cpt.stack.popInt(3)
|
|
|
|
|
value = if modulus.isZero:
|
2024-06-07 08:24:32 +00:00
|
|
|
|
zero(UInt256)
|
|
|
|
|
else:
|
2024-06-17 16:13:38 +00:00
|
|
|
|
mulmod(lhs, rhs, modulus)
|
2024-06-07 08:24:32 +00:00
|
|
|
|
|
2024-06-17 16:13:38 +00:00
|
|
|
|
k.cpt.stack.push value
|
2024-06-07 08:24:32 +00:00
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
2024-06-17 16:13:38 +00:00
|
|
|
|
proc expOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
## 0x0A, Exponentiation
|
|
|
|
|
let (base, exponent) = ? k.cpt.stack.popInt(2)
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
2024-07-13 18:42:49 +00:00
|
|
|
|
? k.cpt.opcodeGasCost(Exp,
|
2024-06-17 16:13:38 +00:00
|
|
|
|
k.cpt.gasCosts[Exp].d_handler(exponent),
|
|
|
|
|
reason = "EXP: exponent bytes")
|
|
|
|
|
|
|
|
|
|
let value = if not base.isZero:
|
|
|
|
|
base.pow(exponent)
|
|
|
|
|
elif exponent.isZero:
|
|
|
|
|
# https://github.com/ethereum/yellowpaper/issues/257
|
|
|
|
|
# https://github.com/ethereum/tests/pull/460
|
|
|
|
|
# https://github.com/ewasm/evm2wasm/issues/137
|
|
|
|
|
1.u256
|
|
|
|
|
else:
|
|
|
|
|
zero(UInt256)
|
|
|
|
|
|
|
|
|
|
k.cpt.stack.push value
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
2024-06-07 08:24:32 +00:00
|
|
|
|
|
2024-06-17 16:13:38 +00:00
|
|
|
|
proc signExtendOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
## 0x0B, Sign extend
|
|
|
|
|
## Extend length of two’s complement signed integer.
|
|
|
|
|
let (bits, value) = ? k.cpt.stack.popInt(2)
|
|
|
|
|
|
|
|
|
|
var res: UInt256
|
|
|
|
|
if bits <= 31.u256:
|
2024-06-07 08:24:32 +00:00
|
|
|
|
let
|
2024-06-17 16:13:38 +00:00
|
|
|
|
one = 1.u256
|
|
|
|
|
testBit = bits.truncate(int) * 8 + 7
|
|
|
|
|
bitPos = one shl testBit
|
|
|
|
|
mask = bitPos - one
|
|
|
|
|
if not isZero(value and bitPos):
|
|
|
|
|
res = value or (not mask)
|
|
|
|
|
else:
|
|
|
|
|
res = value and mask
|
|
|
|
|
else:
|
|
|
|
|
res = value
|
|
|
|
|
k.cpt.stack.push res
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ltOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
## 0x10, Less-than comparison
|
|
|
|
|
let (lhs, rhs) = ? k.cpt.stack.popInt(2)
|
|
|
|
|
k.cpt.stack.push((lhs < rhs).uint.u256)
|
|
|
|
|
|
|
|
|
|
proc gtOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
## 0x11, Greater-than comparison
|
|
|
|
|
let (lhs, rhs) = ? k.cpt.stack.popInt(2)
|
|
|
|
|
k.cpt.stack.push((lhs > rhs).uint.u256)
|
|
|
|
|
|
|
|
|
|
proc sltOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
## 0x12, Signed less-than comparison
|
|
|
|
|
let (lhs, rhs) = ? k.cpt.stack.popInt(2)
|
|
|
|
|
k.cpt.stack.push(slt(lhs, rhs).uint.u256)
|
|
|
|
|
|
|
|
|
|
proc sgtOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
## 0x13, Signed greater-than comparison
|
|
|
|
|
let (lhs, rhs) = ? k.cpt.stack.popInt(2)
|
|
|
|
|
# Arguments are swapped and SLT is used.
|
|
|
|
|
k.cpt.stack.push(slt(rhs, lhs).uint.u256)
|
|
|
|
|
|
|
|
|
|
proc eqOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
## 0x14, Equality comparison
|
|
|
|
|
let (lhs, rhs) = ? k.cpt.stack.popInt(2)
|
|
|
|
|
k.cpt.stack.push((lhs == rhs).uint.u256)
|
|
|
|
|
|
|
|
|
|
proc isZeroOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
## 0x15, Check if zero
|
|
|
|
|
let value = ? k.cpt.stack.popInt()
|
|
|
|
|
k.cpt.stack.push(value.isZero.uint.u256)
|
|
|
|
|
|
|
|
|
|
proc andOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
## 0x16, Bitwise AND
|
|
|
|
|
let (lhs, rhs) = ? k.cpt.stack.popInt(2)
|
|
|
|
|
k.cpt.stack.push(lhs and rhs)
|
|
|
|
|
|
|
|
|
|
proc orOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
## 0x17, Bitwise OR
|
|
|
|
|
let (lhs, rhs) = ? k.cpt.stack.popInt(2)
|
|
|
|
|
k.cpt.stack.push(lhs or rhs)
|
|
|
|
|
|
|
|
|
|
proc xorOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
## 0x18, Bitwise XOR
|
|
|
|
|
let (lhs, rhs) = ? k.cpt.stack.popInt(2)
|
|
|
|
|
k.cpt.stack.push(lhs xor rhs)
|
|
|
|
|
|
|
|
|
|
proc notOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
## 0x19, Check if zero
|
|
|
|
|
let value = ? k.cpt.stack.popInt()
|
|
|
|
|
k.cpt.stack.push(value.not)
|
|
|
|
|
|
|
|
|
|
proc byteOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
## 0x20, Retrieve single byte from word.
|
|
|
|
|
let
|
|
|
|
|
(position, value) = ? k.cpt.stack.popInt(2)
|
|
|
|
|
val = if position >= 32.u256:
|
|
|
|
|
zero(UInt256)
|
|
|
|
|
else:
|
|
|
|
|
let pos = position.truncate(int)
|
|
|
|
|
when system.cpuEndian == bigEndian:
|
|
|
|
|
cast[array[32, byte]](value)[pos].u256
|
|
|
|
|
else:
|
|
|
|
|
cast[array[32, byte]](value)[31 - pos].u256
|
|
|
|
|
|
|
|
|
|
k.cpt.stack.push val
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Constantinople's new opcodes
|
|
|
|
|
|
|
|
|
|
proc shlOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
let (shift, num) = ? k.cpt.stack.popInt(2)
|
|
|
|
|
let shiftLen = shift.safeInt
|
|
|
|
|
if shiftLen >= 256:
|
|
|
|
|
k.cpt.stack.push 0
|
|
|
|
|
else:
|
|
|
|
|
k.cpt.stack.push(num shl shiftLen)
|
|
|
|
|
|
|
|
|
|
proc shrOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
let (shift, num) = ? k.cpt.stack.popInt(2)
|
|
|
|
|
let shiftLen = shift.safeInt
|
|
|
|
|
if shiftLen >= 256:
|
|
|
|
|
k.cpt.stack.push 0
|
|
|
|
|
else:
|
|
|
|
|
# uint version of `shr`
|
|
|
|
|
k.cpt.stack.push(num shr shiftLen)
|
|
|
|
|
|
|
|
|
|
proc sarOp(k: var VmCtx): EvmResultVoid =
|
|
|
|
|
let
|
|
|
|
|
shiftLen = ? k.cpt.stack.popSafeInt()
|
|
|
|
|
num256 = ? k.cpt.stack.popInt()
|
|
|
|
|
num = cast[Int256](num256)
|
|
|
|
|
|
|
|
|
|
if shiftLen >= 256:
|
|
|
|
|
if num.isNegative:
|
|
|
|
|
k.cpt.stack.push(cast[UInt256]((-1).i256))
|
2021-04-12 17:13:30 +00:00
|
|
|
|
else:
|
2024-06-17 16:13:38 +00:00
|
|
|
|
k.cpt.stack. push 0
|
|
|
|
|
else:
|
|
|
|
|
# int version of `shr` then force the result
|
|
|
|
|
# into uint256
|
|
|
|
|
k.cpt.stack.push(cast[UInt256](num shr shiftLen))
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
# Public, op exec table entries
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
const
|
2024-06-15 16:18:53 +00:00
|
|
|
|
VmOpExecArithmetic*: seq[VmOpExec] = @[
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
(opCode: Add, ## 0x01, Addition
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "add",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Addition operation",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: VmOpFn addOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
(opCode: Mul, ## 0x02, Multiplication
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "mul",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Multiplication operation",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: mulOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
(opCode: Sub, ## 0x03, Subtraction
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "sub",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Subtraction operation",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: subOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
(opCode: Div, ## 0x04, Division
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "divide",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Integer division operation",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: divideOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
(opCode: Sdiv, ## 0x05, Signed division
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "sdiv",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Signed integer division operation (truncated)",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: sdivOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
(opCode: Mod, ## 0x06, Modulo
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "modulo",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Modulo remainder operation",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: moduloOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
(opCode: Smod, ## 0x07, Signed modulo
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "smod",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Signed modulo remainder operation",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: smodOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
2022-04-08 04:54:11 +00:00
|
|
|
|
(opCode: Addmod, ## 0x08, Modulo addition, Intermediate
|
2021-04-12 17:13:30 +00:00
|
|
|
|
## computations do not roll over at 2^256
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "addmod",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Modulo addition operation",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: addmodOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
2022-04-08 04:54:11 +00:00
|
|
|
|
(opCode: Mulmod, ## 0x09, Modulo multiplication, Intermediate
|
2021-04-12 17:13:30 +00:00
|
|
|
|
## computations do not roll over at 2^256
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "mulmod",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Modulo multiplication operation",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: mulmodOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
(opCode: Exp, ## 0x0a, Exponentiation
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "exp",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Exponentiation operation",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: expOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
(opCode: SignExtend, ## 0x0b, Extend 2's complemet length
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "signExtend",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Extend length of two’s complement signed integer",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: signExtendOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
(opCode: Lt, ## 0x10, Less-than
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "lt",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Less-than comparison",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: ltOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
(opCode: Gt, ## 0x11, Greater-than
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "gt",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Greater-than comparison",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: gtOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
(opCode: Slt, ## 0x12, Signed less-than
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "slt",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Signed less-than comparison",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: sltOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
(opCode: Sgt, ## 0x13, Signed greater-than
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "sgt",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Signed greater-than comparison",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: sgtOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
(opCode: Eq, ## 0x14, Equality
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "eq",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Equality comparison",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: eqOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
(opCode: IsZero, ## 0x15, Not operator
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "isZero",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Simple not operator (Note: real Yellow Paper description)",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: isZeroOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
(opCode: And, ## 0x16, AND
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "andOp",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Bitwise AND operation",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: andOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
(opCode: Or, ## 0x17, OR
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "orOp",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Bitwise OR operation",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: orOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
(opCode: Xor, ## 0x18, XOR
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "xorOp",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Bitwise XOR operation",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: xorOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
(opCode: Not, ## 0x19, NOT
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "notOp",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Bitwise NOT operation",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: notOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
(opCode: Byte, ## 0x1a, Retrieve byte
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "byteOp",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Retrieve single byte from word",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: byteOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
# Constantinople's new opcodes
|
|
|
|
|
|
|
|
|
|
(opCode: Shl, ## 0x1b, Shift left
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpConstantinopleAndLater,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "shlOp",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Shift left",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: shlOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
(opCode: Shr, ## 0x1c, Shift right logical
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpConstantinopleAndLater,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "shrOp",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Logical shift right",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: shrOp),
|
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
(opCode: Sar, ## 0x1d, Shift right arithmetic
|
2024-06-15 16:18:53 +00:00
|
|
|
|
forks: VmOpConstantinopleAndLater,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "sarOp",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Arithmetic shift right",
|
2024-06-24 05:58:15 +00:00
|
|
|
|
exec: sarOp)]
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
# End
|
|
|
|
|
# ------------------------------------------------------------------------------
|