avoid intermediate const in opcodes (#2381)

The extra layer of `const` makes the function name harder to see a
debugger / profiler
This commit is contained in:
Jacek Sieka 2024-06-17 18:13:38 +02:00 committed by GitHub
parent 2aaab1cb4a
commit 135ef222a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 1123 additions and 1130 deletions

View File

@ -37,23 +37,22 @@ func slt(x, y: UInt256): bool =
# Private, op handlers implementation
# ------------------------------------------------------------------------------
const
addOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc addOp (k: var VmCtx): EvmResultVoid =
## 0x01, Addition
let (lhs, rhs) = ? k.cpt.stack.popInt(2)
k.cpt.stack.push(lhs + rhs)
mulOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc mulOp(k: var VmCtx): EvmResultVoid =
## 0x02, Multiplication
let (lhs, rhs) = ? k.cpt.stack.popInt(2)
k.cpt.stack.push(lhs * rhs)
subOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc subOp(k: var VmCtx): EvmResultVoid =
## 0x03, Substraction
let (lhs, rhs) = ? k.cpt.stack.popInt(2)
k.cpt.stack.push(lhs - rhs)
divideOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc divideOp(k: var VmCtx): EvmResultVoid =
## 0x04, Division
let
(lhs, rhs) = ? k.cpt.stack.popInt(2)
@ -66,7 +65,7 @@ const
k.cpt.stack.push value
sdivOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc sdivOp(k: var VmCtx): EvmResultVoid =
## 0x05, Signed division
let (lhs, rhs) = ? k.cpt.stack.popInt(2)
@ -82,7 +81,7 @@ const
k.cpt.stack.push(r)
moduloOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc moduloOp(k: var VmCtx): EvmResultVoid =
## 0x06, Modulo
let
(lhs, rhs) = ? k.cpt.stack.popInt(2)
@ -94,7 +93,7 @@ const
k.cpt.stack.push value
smodOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc smodOp(k: var VmCtx): EvmResultVoid =
## 0x07, Signed modulo
let (lhs, rhs) = ? k.cpt.stack.popInt(2)
@ -110,7 +109,7 @@ const
k.cpt.stack.push(r)
addmodOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc addmodOp(k: var VmCtx): EvmResultVoid =
## 0x08, Modulo addition
## Intermediate computations do not roll over at 2^256
let
@ -123,7 +122,7 @@ const
k.cpt.stack.push value
mulmodOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc mulmodOp(k: var VmCtx): EvmResultVoid =
## 0x09, Modulo multiplication
## Intermediate computations do not roll over at 2^256
let
@ -136,7 +135,7 @@ const
k.cpt.stack.push value
expOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc expOp(k: var VmCtx): EvmResultVoid =
## 0x0A, Exponentiation
let (base, exponent) = ? k.cpt.stack.popInt(2)
@ -157,7 +156,7 @@ const
k.cpt.stack.push value
signExtendOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc signExtendOp(k: var VmCtx): EvmResultVoid =
## 0x0B, Sign extend
## Extend length of twos complement signed integer.
let (bits, value) = ? k.cpt.stack.popInt(2)
@ -178,58 +177,58 @@ const
k.cpt.stack.push res
ltOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
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)
gtOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
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)
sltOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
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)
sgtOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
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)
eqOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
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)
isZeroOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc isZeroOp(k: var VmCtx): EvmResultVoid =
## 0x15, Check if zero
let value = ? k.cpt.stack.popInt()
k.cpt.stack.push(value.isZero.uint.u256)
andOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc andOp(k: var VmCtx): EvmResultVoid =
## 0x16, Bitwise AND
let (lhs, rhs) = ? k.cpt.stack.popInt(2)
k.cpt.stack.push(lhs and rhs)
orOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc orOp(k: var VmCtx): EvmResultVoid =
## 0x17, Bitwise OR
let (lhs, rhs) = ? k.cpt.stack.popInt(2)
k.cpt.stack.push(lhs or rhs)
xorOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc xorOp(k: var VmCtx): EvmResultVoid =
## 0x18, Bitwise XOR
let (lhs, rhs) = ? k.cpt.stack.popInt(2)
k.cpt.stack.push(lhs xor rhs)
notOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc notOp(k: var VmCtx): EvmResultVoid =
## 0x19, Check if zero
let value = ? k.cpt.stack.popInt()
k.cpt.stack.push(value.not)
byteOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc byteOp(k: var VmCtx): EvmResultVoid =
## 0x20, Retrieve single byte from word.
let
(position, value) = ? k.cpt.stack.popInt(2)
@ -245,9 +244,9 @@ const
k.cpt.stack.push val
# Constantinople's new opcodes
# Constantinople's new opcodes
shlOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc shlOp(k: var VmCtx): EvmResultVoid =
let (shift, num) = ? k.cpt.stack.popInt(2)
let shiftLen = shift.safeInt
if shiftLen >= 256:
@ -255,7 +254,7 @@ const
else:
k.cpt.stack.push(num shl shiftLen)
shrOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc shrOp(k: var VmCtx): EvmResultVoid =
let (shift, num) = ? k.cpt.stack.popInt(2)
let shiftLen = shift.safeInt
if shiftLen >= 256:
@ -264,7 +263,7 @@ const
# uint version of `shr`
k.cpt.stack.push(num shr shiftLen)
sarOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc sarOp(k: var VmCtx): EvmResultVoid =
let
shiftLen = ? k.cpt.stack.popSafeInt()
num256 = ? k.cpt.stack.popInt()
@ -292,7 +291,7 @@ const
name: "add",
info: "Addition operation",
exec: (prep: VmOpIgnore,
run: addOp,
run: VmOpFn addOp,
post: VmOpIgnore)),
(opCode: Mul, ## 0x02, Multiplication

View File

@ -29,8 +29,7 @@ when not defined(evmc_enabled):
# Private, op handlers implementation
# ------------------------------------------------------------------------------
const
blockhashOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc blockhashOp (k: var VmCtx): EvmResultVoid =
## 0x40, Get the hash of one of the 256 most recent complete blocks.
let
cpt = k.cpt
@ -39,40 +38,40 @@ const
cpt.stack.push blockHash
coinBaseOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc coinBaseOp (k: var VmCtx): EvmResultVoid =
## 0x41, Get the block's beneficiary address.
k.cpt.stack.push k.cpt.getCoinbase
timestampOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc timestampOp (k: var VmCtx): EvmResultVoid =
## 0x42, Get the block's timestamp.
k.cpt.stack.push k.cpt.getTimestamp
blocknumberOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc blocknumberOp (k: var VmCtx): EvmResultVoid =
## 0x43, Get the block's number.
k.cpt.stack.push k.cpt.getBlockNumber
difficultyOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc difficultyOp (k: var VmCtx): EvmResultVoid =
## 0x44, Get the block's difficulty
k.cpt.stack.push k.cpt.getDifficulty
gasLimitOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc gasLimitOp (k: var VmCtx): EvmResultVoid =
## 0x45, Get the block's gas limit
k.cpt.stack.push k.cpt.getGasLimit
chainIdOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc chainIdOp (k: var VmCtx): EvmResultVoid =
## 0x46, Get current chains EIP-155 unique identifier.
k.cpt.stack.push k.cpt.getChainId
selfBalanceOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc selfBalanceOp (k: var VmCtx): EvmResultVoid =
## 0x47, Get current contract's balance.
let cpt = k.cpt
cpt.stack.push cpt.getBalance(cpt.msg.contractAddress)
baseFeeOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc baseFeeOp (k: var VmCtx): EvmResultVoid =
## 0x48, Get the block's base fee.
k.cpt.stack.push k.cpt.getBaseFee
blobHashOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc blobHashOp (k: var VmCtx): EvmResultVoid =
## 0x49, Get current transaction's EIP-4844 versioned hash.
let
index = ? k.cpt.stack.popSafeInt()
@ -83,7 +82,7 @@ const
else:
k.cpt.stack.push 0
blobBaseFeeOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc blobBaseFeeOp (k: var VmCtx): EvmResultVoid =
## 0x4a, Get the block's base fee.
k.cpt.stack.push k.cpt.getBlobBaseFee

View File

@ -198,8 +198,7 @@ else:
# Private, op handlers implementation
# ------------------------------------------------------------------------------
const
callOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc callOp(k: var VmCtx): EvmResultVoid =
## 0xf1, Message-Call into an account
let cpt = k.cpt
@ -281,9 +280,9 @@ const
flags: p.flags))
ok()
# ---------------------
# ---------------------
callCodeOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc callCodeOp(k: var VmCtx): EvmResultVoid =
## 0xf2, Message-call into this account with an alternative account's code.
let
cpt = k.cpt
@ -358,9 +357,9 @@ const
flags: p.flags))
ok()
# ---------------------
# ---------------------
delegateCallOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc delegateCallOp(k: var VmCtx): EvmResultVoid =
## 0xf4, Message-call into this account with an alternative account's
## code, but persisting the current values for sender and value.
let
@ -430,9 +429,9 @@ const
flags: p.flags))
ok()
# ---------------------
# ---------------------
staticCallOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc staticCallOp(k: var VmCtx): EvmResultVoid =
## 0xfa, Static message-call into an account.
let

View File

@ -81,8 +81,8 @@ else:
# Private, op handlers implementation
# ------------------------------------------------------------------------------
const
createOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc createOp(k: var VmCtx): EvmResultVoid =
## 0xf0, Create a new account with associated code
? checkInStaticContext(k.cpt)
@ -159,9 +159,9 @@ const
data: cpt.memory.read(memPos, memLen)))
ok()
# ---------------------
# ---------------------
create2Op: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc create2Op(k: var VmCtx): EvmResultVoid =
## 0xf5, Behaves identically to CREATE, except using keccak256
? checkInStaticContext(k.cpt)

View File

@ -35,21 +35,20 @@ when not defined(evmc_enabled):
# Private, op handlers implementation
# ------------------------------------------------------------------------------
const
addressOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc addressOp (k: var VmCtx): EvmResultVoid =
## 0x30, Get address of currently executing account.
k.cpt.stack.push k.cpt.msg.contractAddress
# ------------------
# ------------------
balanceOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc balanceOp (k: var VmCtx): EvmResultVoid =
## 0x31, Get balance of the given account.
let
cpt = k.cpt
address = ? cpt.stack.popAddress
cpt.stack.push cpt.getBalance(address)
balanceEIP2929Op: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc balanceEIP2929Op (k: var VmCtx): EvmResultVoid =
## 0x31, EIP292: Get balance of the given account for Berlin and later
let
cpt = k.cpt
@ -59,22 +58,22 @@ const
? cpt.opcodeGastCost(Balance, gasCost, reason = "Balance EIP2929")
cpt.stack.push cpt.getBalance(address)
# ------------------
# ------------------
originOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc originOp (k: var VmCtx): EvmResultVoid =
## 0x32, Get execution origination address.
k.cpt.stack.push k.cpt.getOrigin()
callerOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc callerOp (k: var VmCtx): EvmResultVoid =
## 0x33, Get caller address.
k.cpt.stack.push k.cpt.msg.sender
callValueOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc callValueOp (k: var VmCtx): EvmResultVoid =
## 0x34, Get deposited value by the instruction/transaction
## responsible for this execution
k.cpt.stack.push k.cpt.msg.value
callDataLoadOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc callDataLoadOp (k: var VmCtx): EvmResultVoid =
## 0x35, Get input data of current environment
let
startPos = ? k.cpt.stack.popInt()
@ -94,12 +93,12 @@ const
k.cpt.stack.push value
callDataSizeOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc callDataSizeOp (k: var VmCtx): EvmResultVoid =
## 0x36, Get size of input data in current environment.
k.cpt.stack.push k.cpt.msg.data.len.u256
callDataCopyOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc callDataCopyOp (k: var VmCtx): EvmResultVoid =
## 0x37, Copy input data in current environment to memory.
let (memStartPos, copyStartPos, size) = ? k.cpt.stack.popInt(3)
@ -115,13 +114,13 @@ const
ok()
codeSizeOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc codeSizeOp (k: var VmCtx): EvmResultVoid =
## 0x38, Get size of code running in current environment.
let cpt = k.cpt
cpt.stack.push cpt.code.len
codeCopyOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc codeCopyOp (k: var VmCtx): EvmResultVoid =
## 0x39, Copy code running in current environment to memory.
let
cpt = k.cpt
@ -138,13 +137,13 @@ const
cpt.memory.writePadded(cpt.code.bytes, memPos, copyPos, len)
ok()
gasPriceOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc gasPriceOp (k: var VmCtx): EvmResultVoid =
## 0x3A, Get price of gas in current environment.
k.cpt.stack.push k.cpt.getGasPrice()
# -----------
# -----------
extCodeSizeOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc extCodeSizeOp (k: var VmCtx): EvmResultVoid =
## 0x3b, Get size of an account's code
let
cpt = k.cpt
@ -152,7 +151,7 @@ const
cpt.stack.push cpt.getCodeSize(address)
extCodeSizeEIP2929Op: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc extCodeSizeEIP2929Op (k: var VmCtx): EvmResultVoid =
## 0x3b, Get size of an account's code
let
cpt = k.cpt
@ -162,9 +161,9 @@ const
? cpt.opcodeGastCost(ExtCodeSize, gasCost, reason = "ExtCodeSize EIP2929")
cpt.stack.push cpt.getCodeSize(address)
# -----------
# -----------
extCodeCopyOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc extCodeCopyOp (k: var VmCtx): EvmResultVoid =
## 0x3c, Copy an account's code to memory.
let
cpt = k.cpt
@ -182,7 +181,7 @@ const
ok()
extCodeCopyEIP2929Op: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc extCodeCopyEIP2929Op (k: var VmCtx): EvmResultVoid =
## 0x3c, Copy an account's code to memory.
let
cpt = k.cpt
@ -199,15 +198,15 @@ const
cpt.memory.writePadded(codeBytes, memPos, codePos, len)
ok()
# -----------
# -----------
returnDataSizeOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc returnDataSizeOp (k: var VmCtx): EvmResultVoid =
## 0x3d, Get size of output data from the previous call from the
## current environment.
k.cpt.stack.push k.cpt.returnData.len
returnDataCopyOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc returnDataCopyOp (k: var VmCtx): EvmResultVoid =
## 0x3e, Copy output data from the previous call to memory.
let
(memStartPos, copyStartPos, size) = ? k.cpt.stack.popInt(3)
@ -223,9 +222,9 @@ const
k.cpt.memory.writePadded(k.cpt.returnData, memPos, copyPos, len)
ok()
# ---------------
# ---------------
extCodeHashOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc extCodeHashOp (k: var VmCtx): EvmResultVoid =
## 0x3f, Returns the keccak256 hash of a contracts code
let
cpt = k.cpt
@ -233,7 +232,7 @@ const
cpt.stack.push cpt.getCodeHash(address)
extCodeHashEIP2929Op: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc extCodeHashEIP2929Op (k: var VmCtx): EvmResultVoid =
## 0x3f, EIP2929: Returns the keccak256 hash of a contracts code
let
cpt = k.cpt
@ -255,7 +254,7 @@ const
name: "address",
info: "Get address of currently executing account",
exec: (prep: VmOpIgnore,
run: addressOp,
run: VmOpFn addressOp,
post: VmOpIgnore)),
(opCode: Balance, ## 0x31, Balance

View File

@ -30,8 +30,7 @@ import
# Private, op handlers implementation
# ------------------------------------------------------------------------------
const
sha3Op: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc sha3Op(k: var VmCtx): EvmResultVoid =
## 0x20, Compute Keccak-256 hash.
let
(startPos, length) = ? k.cpt.stack.popInt(2)

View File

@ -122,14 +122,13 @@ func jumpImpl(c: Computation; jumpTarget: UInt256): EvmResultVoid =
# Private, op handlers implementation
# ------------------------------------------------------------------------------
const
popOp: VmOpFn = func (k: var VmCtx): EvmResultVoid =
proc popOp(k: var VmCtx): EvmResultVoid =
## 0x50, Remove item from stack.
k.cpt.stack.popInt.isOkOr:
return err(error)
ok()
mloadOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc mloadOp (k: var VmCtx): EvmResultVoid =
## 0x51, Load word from memory
let memStartPos = ? k.cpt.stack.popInt()
@ -142,7 +141,7 @@ const
k.cpt.stack.push k.cpt.memory.read32Bytes(memPos)
mstoreOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc mstoreOp (k: var VmCtx): EvmResultVoid =
## 0x52, Save word to memory
let (memStartPos, value) = ? k.cpt.stack.popInt(2)
@ -155,7 +154,7 @@ const
k.cpt.memory.write(memPos, value.toBytesBE)
mstore8Op: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc mstore8Op (k: var VmCtx): EvmResultVoid =
## 0x53, Save byte to memory
let (memStartPos, value) = ? k.cpt.stack.popInt(2)
@ -168,16 +167,16 @@ const
k.cpt.memory.write(memPos, value.toByteArrayBE[31])
# -------
# -------
sloadOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc sloadOp (k: var VmCtx): EvmResultVoid =
## 0x54, Load word from storage.
let
cpt = k.cpt
slot = ? cpt.stack.popInt()
cpt.stack.push cpt.getStorage(slot)
sloadEIP2929Op: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc sloadEIP2929Op (k: var VmCtx): EvmResultVoid =
## 0x54, EIP2929: Load word from storage for Berlin and later
let
cpt = k.cpt
@ -186,9 +185,9 @@ const
? cpt.opcodeGastCost(Sload, gasCost, reason = "sloadEIP2929")
cpt.stack.push cpt.getStorage(slot)
# -------
# -------
sstoreOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc sstoreOp (k: var VmCtx): EvmResultVoid =
## 0x55, Save word to storage.
let
cpt = k.cpt
@ -198,7 +197,7 @@ const
sstoreEvmcOrSstore(cpt, slot, newValue)
sstoreEIP1283Op: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc sstoreEIP1283Op (k: var VmCtx): EvmResultVoid =
## 0x55, EIP1283: sstore for Constantinople and later
let
cpt = k.cpt
@ -208,7 +207,7 @@ const
sstoreEvmcOrNetGasMetering(cpt, slot, newValue)
sstoreEIP2200Op: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc sstoreEIP2200Op (k: var VmCtx): EvmResultVoid =
## 0x55, EIP2200: sstore for Istanbul and later
let
cpt = k.cpt
@ -223,7 +222,7 @@ const
sstoreEvmcOrNetGasMetering(cpt, slot, newValue)
sstoreEIP2929Op: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc sstoreEIP2929Op (k: var VmCtx): EvmResultVoid =
## 0x55, EIP2929: sstore for Berlin and later
let
cpt = k.cpt
@ -249,48 +248,48 @@ const
sstoreEvmcOrNetGasMetering(cpt, slot, newValue, coldAccessGas)
# -------
# -------
jumpOp: VmOpFn = func (k: var VmCtx): EvmResultVoid =
proc jumpOp (k: var VmCtx): EvmResultVoid =
## 0x56, Alter the program counter
let jumpTarget = ? k.cpt.stack.popInt()
jumpImpl(k.cpt, jumpTarget)
jumpIOp: VmOpFn = func (k: var VmCtx): EvmResultVoid =
proc jumpIOp (k: var VmCtx): EvmResultVoid =
## 0x57, Conditionally alter the program counter.
let (jumpTarget, testedValue) = ? k.cpt.stack.popInt(2)
if testedValue.isZero:
return ok()
jumpImpl(k.cpt, jumpTarget)
pcOp: VmOpFn = func (k: var VmCtx): EvmResultVoid =
proc pcOp (k: var VmCtx): EvmResultVoid =
## 0x58, Get the value of the program counter prior to the increment
## corresponding to this instruction.
k.cpt.stack.push max(k.cpt.code.pc - 1, 0)
msizeOp: VmOpFn = func (k: var VmCtx): EvmResultVoid =
proc msizeOp (k: var VmCtx): EvmResultVoid =
## 0x59, Get the size of active memory in bytes.
k.cpt.stack.push k.cpt.memory.len
gasOp: VmOpFn = func (k: var VmCtx): EvmResultVoid =
proc gasOp (k: var VmCtx): EvmResultVoid =
## 0x5a, Get the amount of available gas, including the corresponding
## reduction for the cost of this instruction.
k.cpt.stack.push k.cpt.gasMeter.gasRemaining
jumpDestOp: VmOpFn = func (k: var VmCtx): EvmResultVoid =
proc jumpDestOp (k: var VmCtx): EvmResultVoid =
## 0x5b, Mark a valid destination for jumps. This operation has no effect
## on machine state during execution.
ok()
tloadOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc tloadOp (k: var VmCtx): EvmResultVoid =
## 0x5c, Load word from transient storage.
let
slot = ? k.cpt.stack.popInt()
val = k.cpt.getTransientStorage(slot)
k.cpt.stack.push val
tstoreOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc tstoreOp (k: var VmCtx): EvmResultVoid =
## 0x5d, Save word to transient storage.
? checkInStaticContext(k.cpt)
@ -300,7 +299,7 @@ const
k.cpt.setTransientStorage(slot, val)
ok()
mCopyOp: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc mCopyOp (k: var VmCtx): EvmResultVoid =
## 0x5e, Copy memory
let (dst, src, size) = ? k.cpt.stack.popInt(3)
@ -326,7 +325,7 @@ const
name: "pop",
info: "Remove item from stack",
exec: (prep: VmOpIgnore,
run: popOp,
run: VmOpFn popOp,
post: VmOpIgnore)),
(opCode: Mload, ## 0x51, Load word from memory

View File

@ -65,11 +65,11 @@ genOphList fnName, fnInfo, inxRange, "VmOpExecPush", opName
# about which opcodes are for which forks, but that seems uglier than
# just adding Push0 here as a special case.)
const
push0Op: VmOpFn = proc (k: var VmCtx): EvmResultVoid =
proc push0Op(k: var VmCtx): EvmResultVoid =
## 0x5f, push 0 onto the stack
k.cpt.stack.push(0)
const
VmOpExecPushZero*: seq[VmOpExec] = @[
(opCode: Push0, ## 0x5f, push 0 onto the stack

View File

@ -37,8 +37,7 @@ when not defined(evmc_enabled):
# Private
# ------------------------------------------------------------------------------
const
returnOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc returnOp(k: var VmCtx): EvmResultVoid =
## 0xf3, Halt execution returning output data.
let (startPos, size) = ? k.cpt.stack.popInt(2)
@ -51,7 +50,7 @@ const
ok()
revertOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc revertOp(k: var VmCtx): EvmResultVoid =
## 0xfd, Halt execution reverting state changes but returning data
## and remaining gas.
let (startPos, size) = ? k.cpt.stack.popInt(2)
@ -67,12 +66,12 @@ const
k.cpt.setError(EVMC_REVERT, "REVERT opcode executed", false)
ok()
invalidOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc invalidOp(k: var VmCtx): EvmResultVoid =
err(opErr(InvalidInstruction))
# -----------
# -----------
selfDestructOp: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc selfDestructOp(k: var VmCtx): EvmResultVoid =
## 0xff, Halt execution and register account for later deletion.
let cpt = k.cpt
let beneficiary = ? cpt.stack.popAddress()
@ -84,7 +83,7 @@ const
cpt.selfDestruct(beneficiary)
ok()
selfDestructEIP150Op: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc selfDestructEIP150Op(k: var VmCtx): EvmResultVoid =
## selfDestructEip150 (auto generated comment)
let cpt = k.cpt
let beneficiary = ? cpt.stack.popAddress()
@ -99,7 +98,7 @@ const
cpt.selfDestruct(beneficiary)
ok()
selfDestructEIP161Op: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc selfDestructEIP161Op(k: var VmCtx): EvmResultVoid =
## selfDestructEip161 (auto generated comment)
let cpt = k.cpt
? checkInStaticContext(cpt)
@ -120,7 +119,7 @@ const
cpt.selfDestruct(beneficiary)
ok()
selfDestructEIP2929Op: VmOpFn = proc(k: var VmCtx): EvmResultVoid =
proc selfDestructEIP2929Op(k: var VmCtx): EvmResultVoid =
## selfDestructEIP2929 (auto generated comment)
let cpt = k.cpt
? checkInStaticContext(cpt)