2021-04-12 17:13:30 +00:00
|
|
|
|
# Nimbus
|
|
|
|
|
# Copyright (c) 2018 Status Research & Development GmbH
|
|
|
|
|
# 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
|
|
|
|
|
## ===================================================
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
import
|
2021-04-21 17:04:54 +00:00
|
|
|
|
../../../constants,
|
2021-04-26 16:00:46 +00:00
|
|
|
|
../../computation,
|
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,
|
|
|
|
|
../gas_meter,
|
2021-04-22 16:05:58 +00:00
|
|
|
|
../utils/utils_numeric,
|
2021-04-12 17:13:30 +00:00
|
|
|
|
./oph_defs,
|
2021-04-21 17:04:54 +00:00
|
|
|
|
chronicles,
|
|
|
|
|
eth/common,
|
|
|
|
|
options,
|
|
|
|
|
sets,
|
2021-04-12 17:13:30 +00:00
|
|
|
|
stint
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
# Private, op handlers implementation
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
const
|
2021-04-20 12:07:01 +00:00
|
|
|
|
addOp: Vm2OpFn = proc (k: var Vm2Ctx) =
|
2021-04-14 09:53:30 +00:00
|
|
|
|
## 0x01, Addition
|
2021-04-12 17:13:30 +00:00
|
|
|
|
let (lhs, rhs) = k.cpt.stack.popInt(2)
|
|
|
|
|
k.cpt.stack.push:
|
|
|
|
|
lhs + rhs
|
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
mulOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-14 09:53:30 +00:00
|
|
|
|
## 0x02, Multiplication
|
2021-04-12 17:13:30 +00:00
|
|
|
|
let (lhs, rhs) = k.cpt.stack.popInt(2)
|
|
|
|
|
k.cpt.stack.push:
|
|
|
|
|
lhs * rhs
|
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
subOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-14 09:53:30 +00:00
|
|
|
|
## 0x03, Substraction
|
2021-04-12 17:13:30 +00:00
|
|
|
|
let (lhs, rhs) = k.cpt.stack.popInt(2)
|
|
|
|
|
k.cpt.stack.push:
|
|
|
|
|
lhs - rhs
|
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
divideOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-14 09:53:30 +00:00
|
|
|
|
## 0x04, Division
|
2021-04-12 17:13:30 +00:00
|
|
|
|
let (lhs, rhs) = k.cpt.stack.popInt(2)
|
|
|
|
|
k.cpt.stack.push:
|
|
|
|
|
if rhs == 0:
|
2021-04-13 16:23:39 +00:00
|
|
|
|
# EVM special casing of div by 0
|
2022-04-08 04:54:11 +00:00
|
|
|
|
zero(UInt256)
|
2021-04-12 17:13:30 +00:00
|
|
|
|
else:
|
|
|
|
|
lhs div rhs
|
|
|
|
|
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
sdivOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-14 09:53:30 +00:00
|
|
|
|
## 0x05, Signed division
|
2021-04-12 17:13:30 +00:00
|
|
|
|
let (lhs, rhs) = k.cpt.stack.popInt(2)
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
var r: UInt256
|
|
|
|
|
if rhs != 0:
|
|
|
|
|
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-14 09:53:30 +00:00
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
moduloOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-14 09:53:30 +00:00
|
|
|
|
## 0x06, Modulo
|
2021-04-12 17:13:30 +00:00
|
|
|
|
let (lhs, rhs) = k.cpt.stack.popInt(2)
|
|
|
|
|
k.cpt.stack.push:
|
|
|
|
|
if rhs == 0:
|
2022-04-08 04:54:11 +00:00
|
|
|
|
zero(UInt256)
|
2021-04-12 17:13:30 +00:00
|
|
|
|
else:
|
|
|
|
|
lhs mod rhs
|
|
|
|
|
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
smodOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-14 09:53:30 +00:00
|
|
|
|
## 0x07, Signed modulo
|
2021-04-12 17:13:30 +00:00
|
|
|
|
let (lhs, rhs) = k.cpt.stack.popInt(2)
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
var r: UInt256
|
|
|
|
|
if rhs != 0:
|
|
|
|
|
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-14 09:53:30 +00:00
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
addmodOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-14 09:53:30 +00:00
|
|
|
|
## 0x08, Modulo addition
|
|
|
|
|
## Intermediate computations do not roll over at 2^256
|
2021-04-12 17:13:30 +00:00
|
|
|
|
let (lhs, rhs, modulus) = k.cpt.stack.popInt(3)
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
k.cpt.stack.push:
|
|
|
|
|
if modulus == 0:
|
|
|
|
|
zero(UInt256)
|
|
|
|
|
else:
|
|
|
|
|
addmod(lhs, rhs, modulus)
|
|
|
|
|
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
mulmodOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-14 09:53:30 +00:00
|
|
|
|
## 0x09, Modulo multiplication
|
|
|
|
|
## Intermediate computations do not roll over at 2^256
|
2021-04-12 17:13:30 +00:00
|
|
|
|
let (lhs, rhs, modulus) = k.cpt.stack.popInt(3)
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
k.cpt.stack.push:
|
|
|
|
|
if modulus == 0:
|
|
|
|
|
zero(UInt256)
|
|
|
|
|
else:
|
|
|
|
|
mulmod(lhs, rhs, modulus)
|
|
|
|
|
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
expOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-14 09:53:30 +00:00
|
|
|
|
## 0x0A, Exponentiation
|
2021-04-12 17:13:30 +00:00
|
|
|
|
let (base, exponent) = k.cpt.stack.popInt(2)
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2021-04-14 16:51:54 +00:00
|
|
|
|
k.cpt.gasMeter.consumeGas(
|
|
|
|
|
k.cpt.gasCosts[Exp].d_handler(exponent),
|
|
|
|
|
reason = "EXP: exponent bytes")
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
k.cpt.stack.push:
|
|
|
|
|
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)
|
|
|
|
|
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
signExtendOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-14 09:53:30 +00:00
|
|
|
|
## 0x0B, Sign extend
|
|
|
|
|
## Extend length of two’s complement signed integer.
|
2021-04-12 17:13:30 +00:00
|
|
|
|
let (bits, value) = k.cpt.stack.popInt(2)
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
|
var res: UInt256
|
|
|
|
|
if bits <= 31.u256:
|
|
|
|
|
let
|
|
|
|
|
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
|
|
|
|
|
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
ltOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-14 09:53:30 +00:00
|
|
|
|
## 0x10, Less-than comparison
|
2021-04-12 17:13:30 +00:00
|
|
|
|
let (lhs, rhs) = k.cpt.stack.popInt(2)
|
|
|
|
|
k.cpt.stack.push:
|
|
|
|
|
(lhs < rhs).uint.u256
|
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
gtOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-14 09:53:30 +00:00
|
|
|
|
## 0x11, Greater-than comparison
|
2021-04-12 17:13:30 +00:00
|
|
|
|
let (lhs, rhs) = k.cpt.stack.popInt(2)
|
|
|
|
|
k.cpt.stack.push:
|
|
|
|
|
(lhs > rhs).uint.u256
|
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
sltOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-14 09:53:30 +00:00
|
|
|
|
## 0x12, Signed less-than comparison
|
2021-04-12 17:13:30 +00:00
|
|
|
|
let (lhs, rhs) = k.cpt.stack.popInt(2)
|
|
|
|
|
k.cpt.stack.push:
|
|
|
|
|
(cast[Int256](lhs) < cast[Int256](rhs)).uint.u256
|
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
sgtOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-14 09:53:30 +00:00
|
|
|
|
## 0x14, Signed greater-than comparison
|
2021-04-12 17:13:30 +00:00
|
|
|
|
let (lhs, rhs) = k.cpt.stack.popInt(2)
|
|
|
|
|
k.cpt.stack.push:
|
|
|
|
|
(cast[Int256](lhs) > cast[Int256](rhs)).uint.u256
|
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
eqOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-14 09:53:30 +00:00
|
|
|
|
## 0x14, Signed greater-than comparison
|
2021-04-12 17:13:30 +00:00
|
|
|
|
let (lhs, rhs) = k.cpt.stack.popInt(2)
|
|
|
|
|
k.cpt.stack.push:
|
|
|
|
|
(lhs == rhs).uint.u256
|
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
isZeroOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-14 09:53:30 +00:00
|
|
|
|
## 0x15, Check if zero
|
2021-04-12 17:13:30 +00:00
|
|
|
|
let (value) = k.cpt.stack.popInt(1)
|
|
|
|
|
k.cpt.stack.push:
|
|
|
|
|
value.isZero.uint.u256
|
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
andOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-14 09:53:30 +00:00
|
|
|
|
## 0x16, Bitwise AND
|
2021-04-12 17:13:30 +00:00
|
|
|
|
let (lhs, rhs) = k.cpt.stack.popInt(2)
|
|
|
|
|
k.cpt.stack.push:
|
|
|
|
|
lhs and rhs
|
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
orOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-14 09:53:30 +00:00
|
|
|
|
## 0x17, Bitwise OR
|
2021-04-12 17:13:30 +00:00
|
|
|
|
let (lhs, rhs) = k.cpt.stack.popInt(2)
|
|
|
|
|
k.cpt.stack.push:
|
|
|
|
|
lhs or rhs
|
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
xorOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-14 09:53:30 +00:00
|
|
|
|
## 0x18, Bitwise XOR
|
2021-04-12 17:13:30 +00:00
|
|
|
|
let (lhs, rhs) = k.cpt.stack.popInt(2)
|
|
|
|
|
k.cpt.stack.push:
|
|
|
|
|
lhs xor rhs
|
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
notOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-14 09:53:30 +00:00
|
|
|
|
## 0x19, Check if zero
|
2021-04-12 17:13:30 +00:00
|
|
|
|
let (value) = k.cpt.stack.popInt(1)
|
|
|
|
|
k.cpt.stack.push:
|
|
|
|
|
value.not
|
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
byteOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-14 09:53:30 +00:00
|
|
|
|
## 0x20, Retrieve single byte from word.
|
2021-04-12 17:13:30 +00:00
|
|
|
|
let (position, value) = k.cpt.stack.popInt(2)
|
|
|
|
|
let pos = position.truncate(int)
|
|
|
|
|
k.cpt.stack.push:
|
|
|
|
|
if pos >= 32 or pos < 0:
|
2022-04-08 04:54:11 +00:00
|
|
|
|
zero(UInt256)
|
2021-04-12 17:13:30 +00:00
|
|
|
|
else:
|
|
|
|
|
when system.cpuEndian == bigEndian:
|
|
|
|
|
cast[array[32, byte]](value)[pos].u256
|
|
|
|
|
else:
|
|
|
|
|
cast[array[32, byte]](value)[31 - pos].u256
|
|
|
|
|
|
|
|
|
|
# Constantinople's new opcodes
|
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
shlOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-12 17:13:30 +00:00
|
|
|
|
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
|
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
shrOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-12 17:13:30 +00:00
|
|
|
|
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
|
|
|
|
|
|
2021-04-20 12:07:01 +00:00
|
|
|
|
sarOp: Vm2OpFn = proc(k: var Vm2Ctx) =
|
2021-04-12 17:13:30 +00:00
|
|
|
|
let shiftLen = k.cpt.stack.popInt().safeInt
|
|
|
|
|
let num = cast[Int256](k.cpt.stack.popInt())
|
|
|
|
|
if shiftLen >= 256:
|
|
|
|
|
if num.isNegative:
|
|
|
|
|
k.cpt.stack.push:
|
2022-04-08 04:54:11 +00:00
|
|
|
|
cast[UInt256]((-1).i256)
|
2021-04-12 17:13:30 +00:00
|
|
|
|
else:
|
|
|
|
|
k.cpt.stack. push:
|
|
|
|
|
0
|
|
|
|
|
else:
|
|
|
|
|
# int version of `shr` then force the result
|
|
|
|
|
# into uint256
|
|
|
|
|
k.cpt.stack.push:
|
2022-04-08 04:54:11 +00:00
|
|
|
|
cast[UInt256](num shr shiftLen)
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
# Public, op exec table entries
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
const
|
|
|
|
|
vm2OpExecArithmetic*: seq[Vm2OpExec] = @[
|
|
|
|
|
|
|
|
|
|
(opCode: Add, ## 0x01, Addition
|
|
|
|
|
forks: Vm2OpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "add",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Addition operation",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: addOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
|
|
|
|
(opCode: Mul, ## 0x02, Multiplication
|
|
|
|
|
forks: Vm2OpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "mul",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Multiplication operation",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: mulOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
|
|
|
|
(opCode: Sub, ## 0x03, Subtraction
|
|
|
|
|
forks: Vm2OpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "sub",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Subtraction operation",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: subOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
|
|
|
|
(opCode: Div, ## 0x04, Division
|
|
|
|
|
forks: Vm2OpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "divide",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Integer division operation",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: divideOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
|
|
|
|
(opCode: Sdiv, ## 0x05, Signed division
|
|
|
|
|
forks: Vm2OpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "sdiv",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Signed integer division operation (truncated)",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: sdivOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
|
|
|
|
(opCode: Mod, ## 0x06, Modulo
|
|
|
|
|
forks: Vm2OpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "modulo",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Modulo remainder operation",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: moduloOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
|
|
|
|
(opCode: Smod, ## 0x07, Signed modulo
|
|
|
|
|
forks: Vm2OpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "smod",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Signed modulo remainder operation",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: smodOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
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
|
|
|
|
|
forks: Vm2OpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "addmod",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Modulo addition operation",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: addmodOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
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
|
|
|
|
|
forks: Vm2OpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "mulmod",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Modulo multiplication operation",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: mulmodOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
|
|
|
|
(opCode: Exp, ## 0x0a, Exponentiation
|
|
|
|
|
forks: Vm2OpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "exp",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Exponentiation operation",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: expOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
|
|
|
|
(opCode: SignExtend, ## 0x0b, Extend 2's complemet length
|
|
|
|
|
forks: Vm2OpAllForks,
|
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",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: signExtendOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
|
|
|
|
(opCode: Lt, ## 0x10, Less-than
|
|
|
|
|
forks: Vm2OpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "lt",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Less-than comparison",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: ltOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
|
|
|
|
(opCode: Gt, ## 0x11, Greater-than
|
|
|
|
|
forks: Vm2OpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "gt",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Greater-than comparison",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: gtOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
|
|
|
|
(opCode: Slt, ## 0x12, Signed less-than
|
|
|
|
|
forks: Vm2OpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "slt",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Signed less-than comparison",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: sltOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
|
|
|
|
(opCode: Sgt, ## 0x13, Signed greater-than
|
|
|
|
|
forks: Vm2OpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "sgt",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Signed greater-than comparison",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: sgtOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
|
|
|
|
(opCode: Eq, ## 0x14, Equality
|
|
|
|
|
forks: Vm2OpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "eq",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Equality comparison",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: eqOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
|
|
|
|
(opCode: IsZero, ## 0x15, Not operator
|
|
|
|
|
forks: Vm2OpAllForks,
|
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)",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: isZeroOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
|
|
|
|
(opCode: And, ## 0x16, AND
|
|
|
|
|
forks: Vm2OpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "andOp",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Bitwise AND operation",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: andOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
|
|
|
|
(opCode: Or, ## 0x17, OR
|
|
|
|
|
forks: Vm2OpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "orOp",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Bitwise OR operation",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: orOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
|
|
|
|
(opCode: Xor, ## 0x18, XOR
|
|
|
|
|
forks: Vm2OpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "xorOp",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Bitwise XOR operation",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: xorOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
|
|
|
|
(opCode: Not, ## 0x19, NOT
|
|
|
|
|
forks: Vm2OpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "notOp",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Bitwise NOT operation",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: notOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
|
|
|
|
(opCode: Byte, ## 0x1a, Retrieve byte
|
|
|
|
|
forks: Vm2OpAllForks,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "byteOp",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Retrieve single byte from word",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: byteOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
|
|
|
|
# Constantinople's new opcodes
|
|
|
|
|
|
|
|
|
|
(opCode: Shl, ## 0x1b, Shift left
|
|
|
|
|
forks: Vm2OpConstantinopleAndLater,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "shlOp",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Shift left",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: shlOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
|
|
|
|
(opCode: Shr, ## 0x1c, Shift right logical
|
|
|
|
|
forks: Vm2OpConstantinopleAndLater,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "shrOp",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Logical shift right",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: shrOp,
|
|
|
|
|
post: vm2OpIgnore)),
|
|
|
|
|
|
|
|
|
|
(opCode: Sar, ## 0x1d, Shift right arithmetic
|
|
|
|
|
forks: Vm2OpConstantinopleAndLater,
|
2021-04-19 09:15:35 +00:00
|
|
|
|
name: "sarOp",
|
2021-04-12 17:13:30 +00:00
|
|
|
|
info: "Arithmetic shift right",
|
|
|
|
|
exec: (prep: vm2OpIgnore,
|
|
|
|
|
run: sarOp,
|
|
|
|
|
post: vm2OpIgnore))]
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
# End
|
|
|
|
|
# ------------------------------------------------------------------------------
|