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-07-19 01:44:01 +00:00
|
|
|
|
proc addOp(cpt: VmCpt): EvmResultVoid =
|
2024-06-17 16:13:38 +00:00
|
|
|
|
## 0x01, Addition
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.binaryOp(`+`)
|
2024-06-17 16:13:38 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc mulOp(cpt: VmCpt): EvmResultVoid =
|
2024-06-17 16:13:38 +00:00
|
|
|
|
## 0x02, Multiplication
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.binaryOp(`*`)
|
2024-06-17 16:13:38 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc subOp(cpt: VmCpt): EvmResultVoid =
|
2024-06-17 16:13:38 +00:00
|
|
|
|
## 0x03, Substraction
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.binaryOp(`-`)
|
2024-06-17 16:13:38 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc divideOp(cpt: VmCpt): EvmResultVoid =
|
2024-06-17 16:13:38 +00:00
|
|
|
|
## 0x04, Division
|
2024-07-18 11:59:53 +00:00
|
|
|
|
template div256(top, lhs, rhs) =
|
|
|
|
|
if rhs.isZero:
|
|
|
|
|
# EVM special casing of div by 0
|
|
|
|
|
top = zero(UInt256)
|
|
|
|
|
else:
|
|
|
|
|
top = lhs div rhs
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.binaryWithTop(div256)
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc sdivOp(cpt: VmCpt): EvmResultVoid =
|
2024-06-17 16:13:38 +00:00
|
|
|
|
## 0x05, Signed division
|
2024-07-18 11:59:53 +00:00
|
|
|
|
template sdiv256(top, lhs, rhs) =
|
|
|
|
|
if rhs.isZero.not:
|
|
|
|
|
var signA, signB: bool
|
|
|
|
|
extractSign(lhs, signA)
|
|
|
|
|
extractSign(rhs, signB)
|
|
|
|
|
top = lhs div rhs
|
|
|
|
|
setSign(top, signA xor signB)
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.binaryWithTop(sdiv256)
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc moduloOp(cpt: VmCpt): EvmResultVoid =
|
2024-06-17 16:13:38 +00:00
|
|
|
|
## 0x06, Modulo
|
2024-07-18 11:59:53 +00:00
|
|
|
|
template mod256(top, lhs, rhs) =
|
|
|
|
|
if rhs.isZero:
|
|
|
|
|
top = zero(UInt256)
|
|
|
|
|
else:
|
|
|
|
|
top = lhs mod rhs
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.binaryWithTop(mod256)
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc smodOp(cpt: VmCpt): EvmResultVoid =
|
2024-06-17 16:13:38 +00:00
|
|
|
|
## 0x07, Signed modulo
|
2024-07-18 11:59:53 +00:00
|
|
|
|
template smod256(top, lhs, rhs) =
|
|
|
|
|
if rhs.isZero.not:
|
|
|
|
|
var sign: bool
|
|
|
|
|
extractSign(rhs, sign)
|
|
|
|
|
extractSign(lhs, sign)
|
|
|
|
|
top = lhs mod rhs
|
|
|
|
|
setSign(top, sign)
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.binaryWithTop(smod256)
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc addmodOp(cpt: VmCpt): EvmResultVoid =
|
2024-06-17 16:13:38 +00:00
|
|
|
|
## 0x08, Modulo addition
|
|
|
|
|
## Intermediate computations do not roll over at 2^256
|
2024-07-19 01:44:01 +00:00
|
|
|
|
? cpt.stack.lsCheck(3)
|
2024-06-17 16:13:38 +00:00
|
|
|
|
let
|
2024-07-19 01:44:01 +00:00
|
|
|
|
lhs = cpt.stack.lsPeekInt(^1)
|
|
|
|
|
rhs = cpt.stack.lsPeekInt(^2)
|
|
|
|
|
modulus = cpt.stack.lsPeekInt(^3)
|
2024-06-17 16:13:38 +00:00
|
|
|
|
value = if modulus.isZero:
|
|
|
|
|
zero(UInt256)
|
|
|
|
|
else:
|
|
|
|
|
addmod(lhs, rhs, modulus)
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.lsShrink(2)
|
|
|
|
|
cpt.stack.lsTop value
|
2024-07-18 11:59:53 +00:00
|
|
|
|
ok()
|
2021-04-14 09:53:30 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc mulmodOp(cpt: VmCpt): EvmResultVoid =
|
2024-06-17 16:13:38 +00:00
|
|
|
|
## 0x09, Modulo multiplication
|
|
|
|
|
## Intermediate computations do not roll over at 2^256
|
2024-07-19 01:44:01 +00:00
|
|
|
|
? cpt.stack.lsCheck(3)
|
2024-06-17 16:13:38 +00:00
|
|
|
|
let
|
2024-07-19 01:44:01 +00:00
|
|
|
|
lhs = cpt.stack.lsPeekInt(^1)
|
|
|
|
|
rhs = cpt.stack.lsPeekInt(^2)
|
|
|
|
|
modulus = cpt.stack.lsPeekInt(^3)
|
2024-06-17 16:13:38 +00:00
|
|
|
|
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-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.lsShrink(2)
|
|
|
|
|
cpt.stack.lsTop value
|
2024-07-18 11:59:53 +00:00
|
|
|
|
ok()
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc expOp(cpt: VmCpt): EvmResultVoid =
|
2024-06-17 16:13:38 +00:00
|
|
|
|
## 0x0A, Exponentiation
|
2024-07-18 11:59:53 +00:00
|
|
|
|
template exp256(top, base, exponent) =
|
2024-07-19 01:44:01 +00:00
|
|
|
|
? cpt.opcodeGasCost(Exp,
|
|
|
|
|
cpt.gasCosts[Exp].d_handler(exponent),
|
2024-07-18 11:59:53 +00:00
|
|
|
|
reason = "EXP: exponent bytes")
|
|
|
|
|
|
|
|
|
|
if not base.isZero:
|
|
|
|
|
top = 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
|
|
|
|
|
top = 1.u256
|
|
|
|
|
else:
|
|
|
|
|
top = zero(UInt256)
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.binaryWithTop(exp256)
|
2024-06-07 08:24:32 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc signExtendOp(cpt: VmCpt): EvmResultVoid =
|
2024-06-17 16:13:38 +00:00
|
|
|
|
## 0x0B, Sign extend
|
|
|
|
|
## Extend length of two’s complement signed integer.
|
2024-07-18 11:59:53 +00:00
|
|
|
|
template se256(top, bits, value) =
|
|
|
|
|
const one = 1.u256
|
|
|
|
|
if bits <= 31.u256:
|
|
|
|
|
let
|
|
|
|
|
testBit = bits.truncate(int) * 8 + 7
|
|
|
|
|
bitPos = one shl testBit
|
|
|
|
|
mask = bitPos - one
|
|
|
|
|
if not isZero(value and bitPos):
|
|
|
|
|
top = value or (not mask)
|
|
|
|
|
else:
|
|
|
|
|
top = value and mask
|
2024-06-17 16:13:38 +00:00
|
|
|
|
else:
|
2024-07-18 11:59:53 +00:00
|
|
|
|
top = value
|
2024-06-17 16:13:38 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.binaryWithTop(se256)
|
2024-06-17 16:13:38 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc ltOp(cpt: VmCpt): EvmResultVoid =
|
2024-06-17 16:13:38 +00:00
|
|
|
|
## 0x10, Less-than comparison
|
2024-07-18 11:59:53 +00:00
|
|
|
|
template lt256(lhs, rhs): auto =
|
|
|
|
|
(lhs < rhs).uint.u256
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.binaryOp(lt256)
|
2024-06-17 16:13:38 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc gtOp(cpt: VmCpt): EvmResultVoid =
|
2024-06-17 16:13:38 +00:00
|
|
|
|
## 0x11, Greater-than comparison
|
2024-07-18 11:59:53 +00:00
|
|
|
|
template gt256(lhs, rhs): auto =
|
|
|
|
|
(lhs > rhs).uint.u256
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.binaryOp(gt256)
|
2024-06-17 16:13:38 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc sltOp(cpt: VmCpt): EvmResultVoid =
|
2024-06-17 16:13:38 +00:00
|
|
|
|
## 0x12, Signed less-than comparison
|
2024-07-18 11:59:53 +00:00
|
|
|
|
template slt256(lhs, rhs): auto =
|
|
|
|
|
slt(lhs, rhs).uint.u256
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.binaryOp(slt256)
|
2024-06-17 16:13:38 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc sgtOp(cpt: VmCpt): EvmResultVoid =
|
2024-06-17 16:13:38 +00:00
|
|
|
|
## 0x13, Signed greater-than comparison
|
|
|
|
|
# Arguments are swapped and SLT is used.
|
2024-07-18 11:59:53 +00:00
|
|
|
|
template sgt256(lhs, rhs): auto =
|
|
|
|
|
slt(rhs, lhs).uint.u256
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.binaryOp(sgt256)
|
2024-06-17 16:13:38 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc eqOp(cpt: VmCpt): EvmResultVoid =
|
2024-06-17 16:13:38 +00:00
|
|
|
|
## 0x14, Equality comparison
|
2024-07-18 11:59:53 +00:00
|
|
|
|
template eq256(lhs, rhs): auto =
|
|
|
|
|
(lhs == rhs).uint.u256
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.binaryOp(eq256)
|
2024-06-17 16:13:38 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc isZeroOp(cpt: VmCpt): EvmResultVoid =
|
2024-06-17 16:13:38 +00:00
|
|
|
|
## 0x15, Check if zero
|
2024-07-18 11:59:53 +00:00
|
|
|
|
template zero256(value): auto =
|
|
|
|
|
value.isZero.uint.u256
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.unaryOp(zero256)
|
2024-06-17 16:13:38 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc andOp(cpt: VmCpt): EvmResultVoid =
|
2024-06-17 16:13:38 +00:00
|
|
|
|
## 0x16, Bitwise AND
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.binaryOp(`and`)
|
2024-06-17 16:13:38 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc orOp(cpt: VmCpt): EvmResultVoid =
|
2024-06-17 16:13:38 +00:00
|
|
|
|
## 0x17, Bitwise OR
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.binaryOp(`or`)
|
2024-06-17 16:13:38 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc xorOp(cpt: VmCpt): EvmResultVoid =
|
2024-06-17 16:13:38 +00:00
|
|
|
|
## 0x18, Bitwise XOR
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.binaryOp(`xor`)
|
2024-06-17 16:13:38 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc notOp(cpt: VmCpt): EvmResultVoid =
|
2024-06-17 16:13:38 +00:00
|
|
|
|
## 0x19, Check if zero
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.unaryOp(`not`)
|
2024-06-17 16:13:38 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc byteOp(cpt: VmCpt): EvmResultVoid =
|
2024-06-17 16:13:38 +00:00
|
|
|
|
## 0x20, Retrieve single byte from word.
|
2024-07-18 11:59:53 +00:00
|
|
|
|
template byte256(top, position, value) =
|
|
|
|
|
if position >= 32.u256:
|
|
|
|
|
top = zero(UInt256)
|
|
|
|
|
else:
|
|
|
|
|
let pos = position.truncate(int)
|
|
|
|
|
when system.cpuEndian == bigEndian:
|
|
|
|
|
top = cast[array[32, byte]](value)[pos].u256
|
|
|
|
|
else:
|
|
|
|
|
top = cast[array[32, byte]](value)[31 - pos].u256
|
2024-06-17 16:13:38 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.binaryWithTop(byte256)
|
2024-06-17 16:13:38 +00:00
|
|
|
|
|
|
|
|
|
# Constantinople's new opcodes
|
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc shlOp(cpt: VmCpt): EvmResultVoid =
|
2024-07-18 11:59:53 +00:00
|
|
|
|
## 0x1b, Shift left
|
|
|
|
|
template shl256(top, lhs, num) =
|
|
|
|
|
let shiftLen = lhs.safeInt
|
|
|
|
|
if shiftLen >= 256:
|
|
|
|
|
top = 0.u256
|
|
|
|
|
else:
|
|
|
|
|
top = num shl shiftLen
|
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.binaryWithTop(shl256)
|
2024-06-17 16:13:38 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc shrOp(cpt: VmCpt): EvmResultVoid =
|
2024-07-18 11:59:53 +00:00
|
|
|
|
## 0x1c, Shift right logical
|
|
|
|
|
template shr256(top, lhs, num) =
|
|
|
|
|
let shiftLen = lhs.safeInt
|
|
|
|
|
if shiftLen >= 256:
|
|
|
|
|
top = 0.u256
|
|
|
|
|
else:
|
|
|
|
|
# uint version of `shr`
|
|
|
|
|
top = num shr shiftLen
|
2024-06-17 16:13:38 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.binaryWithTop(shr256)
|
2024-06-17 16:13:38 +00:00
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
proc sarOp(cpt: VmCpt): EvmResultVoid =
|
2024-07-18 11:59:53 +00:00
|
|
|
|
## 0x1d, Shift right arithmetic
|
|
|
|
|
template sar256(top, lhs, num256) =
|
|
|
|
|
let
|
|
|
|
|
shiftLen = lhs.safeInt
|
|
|
|
|
num = cast[Int256](num256)
|
|
|
|
|
|
|
|
|
|
if shiftLen >= 256:
|
|
|
|
|
if num.isNegative:
|
|
|
|
|
top = cast[UInt256]((-1).i256)
|
|
|
|
|
else:
|
|
|
|
|
top = 0.u256
|
2021-04-12 17:13:30 +00:00
|
|
|
|
else:
|
2024-07-18 11:59:53 +00:00
|
|
|
|
# int version of `shr` then force the result
|
|
|
|
|
# into uint256
|
|
|
|
|
top = cast[UInt256](num shr shiftLen)
|
|
|
|
|
|
2024-07-19 01:44:01 +00:00
|
|
|
|
cpt.stack.binaryWithTop(sar256)
|
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
|
|
|
|
|
# ------------------------------------------------------------------------------
|