fix macro assembler and reenable disabled tests

now macro assembler support merge fork, shanghai, etc without using ugly hack.
also each assembler test have their own `setup` section that can access
`vmState` and perform various custom setup.
This commit is contained in:
jangko 2023-03-22 18:18:37 +07:00
parent 0b97f5a2e6
commit 34adb86167
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
11 changed files with 208 additions and 244 deletions

View File

@ -9,7 +9,6 @@
# according to those terms.
import
std/sets,
chronos,
eth/common/eth_types,
../constants,

View File

@ -27,9 +27,9 @@ cliBuilder:
./test_filters,
./test_op_arith,
./test_op_bit,
# ./test_op_env,
./test_op_env,
./test_op_memory,
# ./test_op_misc,
./test_op_misc,
./test_op_custom,
./test_state_db,
./test_difficulty,
@ -45,5 +45,5 @@ cliBuilder:
./test_pow,
./test_configuration,
./test_keyed_queue_rlp,
# ./test_txpool,
./test_txpool,
./test_merge

View File

@ -1,20 +1,20 @@
import
macrocache, strutils, sequtils, unittest2, times,
stew/byteutils, chronicles, eth/keys,
std/[macrocache, strutils, times],
eth/keys,
unittest2,
chronicles,
eth/trie/hexary,
stew/byteutils,
stew/shims/macros
import
eth/trie/hexary,
../nimbus/db/[accounts_cache, distinct_tries],
../nimbus/evm/types,
../nimbus/vm_internals,
../nimbus/transaction/[call_common, call_evm],
../nimbus/[vm_types, vm_state],
../nimbus/core/pow/difficulty
# Need to exclude ServerCommand because it contains something
# called Stop that interferes with the EVM operation named Stop.
import chronos except ServerCommand
../nimbus/core/pow/difficulty,
../tools/common/helpers
# Ditto, for GasPrice.
import ../nimbus/transaction except GasPrice
@ -35,25 +35,22 @@ type
Storage* = tuple[key, val: VMWord]
Assembler* = object
title*: string
chainDBIdentName*: string
vmStateIdentName*: string
stack*: seq[VMWord]
memory*: seq[VMWord]
initialStorage*: seq[Storage]
storage*: seq[Storage]
code*: seq[byte]
logs*: seq[Log]
success*: bool
title* : string
stack* : seq[VMWord]
memory* : seq[VMWord]
storage* : seq[Storage]
code* : seq[byte]
logs* : seq[Log]
success* : bool
gasLimit*: GasInt
gasUsed*: GasInt
data*: seq[byte]
output*: seq[byte]
fork*: EVMFork
gasUsed* : GasInt
data* : seq[byte]
output* : seq[byte]
ConcurrencyTest* = object
title*: string
assemblers*: seq[Assembler]
MacroAssembler = object
setup : NimNode
asmBlock : Assembler
forkStr : string
const
idToOpcode = CacheTable"NimbusMacroAssembler"
@ -101,11 +98,6 @@ proc parseStringLiteral(node: NimNode): string =
strNode.expectKind(nnkStrLit)
strNode.strVal
proc parseIdent(node: NimNode): string =
let identNode = node[0]
identNode.expectKind(nnkIdent)
identNode.strVal
proc parseSuccess(list: NimNode): bool =
list.expectKind nnkStmtList
list[0].expectKind(nnkIdent)
@ -119,7 +111,7 @@ proc parseData(list: NimNode): seq[byte] =
result.add hexToSeqByte(n.strVal)
proc parseLog(node: NimNode): Log =
node.expectKind(nnkPar)
node.expectKind({nnkPar, nnkTupleConstr})
for item in node:
item.expectKind(nnkExprColonExpr)
let label = item[0].strVal
@ -195,70 +187,62 @@ proc parseCode(codes: NimNode): seq[byte] =
else:
error("unknown syntax: " & line.toStrLit.strVal, line)
proc parseFork(fork: NimNode): EVMFork =
proc parseFork(fork: NimNode): string =
fork[0].expectKind({nnkIdent, nnkStrLit})
# Normalise whitespace and uppercase each word because `parseEnum` matches
# enum string values not symbols, and the strings are uppercase in `EVMFork`.
parseEnum[EVMFork]("EVMC_" & fork[0].strVal.splitWhitespace().map(toUpperAscii).join("_"))
fork[0].strVal
proc parseGasUsed(gas: NimNode): GasInt =
gas[0].expectKind(nnkIntLit)
result = gas[0].intVal
proc parseAssembler(list: NimNode): Assembler =
result.success = true
result.fork = FkFrontier
result.gasUsed = -1
proc parseAssembler(list: NimNode): MacroAssembler =
result.forkStr = "Frontier"
result.asmBlock.success = true
result.asmBlock.gasUsed = -1
list.expectKind nnkStmtList
for callSection in list:
callSection.expectKind(nnkCall)
let label = callSection[0].strVal
let body = callSection[1]
case label.normalize
of "title": result.title = parseStringLiteral(body)
of "vmstate": result.vmStateIdentName = parseIdent(body)
of "chaindb": result.chainDBIdentName = parseIdent(body)
of "code" : result.code = parseCode(body)
of "memory": result.memory = parseVMWords(body)
of "stack" : result.stack = parseVMWords(body)
of "storage": result.storage = parseStorage(body)
of "initialstorage": result.initialStorage = parseStorage(body)
of "logs": result.logs = parseLogs(body)
of "success": result.success = parseSuccess(body)
of "data": result.data = parseData(body)
of "output": result.output = parseData(body)
of "fork": result.fork = parseFork(body)
of "gasused": result.gasUsed = parseGasUsed(body)
of "title" : result.asmBlock.title = parseStringLiteral(body)
of "code" : result.asmBlock.code = parseCode(body)
of "memory" : result.asmBlock.memory = parseVMWords(body)
of "stack" : result.asmBlock.stack = parseVMWords(body)
of "storage": result.asmBlock.storage = parseStorage(body)
of "logs" : result.asmBlock.logs = parseLogs(body)
of "success": result.asmBlock.success = parseSuccess(body)
of "data" : result.asmBlock.data = parseData(body)
of "output" : result.asmBlock.output = parseData(body)
of "gasused": result.asmBlock.gasUsed = parseGasUsed(body)
of "fork" : result.forkStr = parseFork(body)
of "setup" : result.setup = body
else: error("unknown section '" & label & "'", callSection[0])
proc parseAssemblers(list: NimNode): seq[Assembler] =
result = @[]
list.expectKind nnkStmtList
for callSection in list:
# Should we do something with the label? Or is the
# assembler's "title" section good enough?
# let label = callSection[0].strVal
let body = callSection[1]
result.add parseAssembler(body)
type VMProxy = tuple[sym: NimNode, pr: NimNode]
proc generateVMProxy(boa: Assembler): VMProxy =
proc generateVMProxy(masm: MacroAssembler): VMProxy =
let
vmProxySym = genSym(nskProc, "vmProxy")
chainDB = ident(if boa.chainDBIdentName == "": "chainDB" else: boa.chainDBIdentName)
vmState = ident(if boa.vmStateIdentName == "": "vmState" else: boa.vmStateIdentName)
body = newLitFixed(boa)
body = newLitFixed(masm.asmBlock)
setup = if masm.setup.isNil:
newEmptyNode()
else:
masm.setup
vmState = ident("vmState")
fork = masm.forkStr
vmProxyProc = quote do:
proc `vmProxySym`(): bool =
let `vmState` = initVMEnv(`fork`)
`setup`
let boa = `body`
runVM(`vmState`, `chainDB`, boa)
runVM(`vmState`, boa)
(vmProxySym, vmProxyProc)
proc generateAssemblerTest(boa: Assembler): NimNode =
proc generateAssemblerTest(masm: MacroAssembler): NimNode =
let
(vmProxySym, vmProxyProc) = generateVMProxy(boa)
title: string = boa.title
(vmProxySym, vmProxyProc) = generateVMProxy(masm)
title: string = masm.asmBlock.title
result = quote do:
test `title`:
@ -269,30 +253,35 @@ proc generateAssemblerTest(boa: Assembler): NimNode =
when defined(macro_assembler_debug):
echo result.toStrLit.strVal
proc initDatabase*(networkId = MainNet): (BaseVMState, CommonRef) =
let com = CommonRef.new(newMemoryDB(), false, networkId, networkParams(networkId))
com.initializeEmptyDb()
const
codeAddress = hexToByteArray[20]("460121576cc7df020759730751f92bd62fd78dd6")
coinbase = hexToByteArray[20]("bb7b8287f3f0a933474a79eae42cbca977791171")
proc initVMEnv*(network: string): BaseVMState =
let
parent = getCanonicalHead(com.db)
coinbase = hexToByteArray[20]("bb7b8287f3f0a933474a79eae42cbca977791171")
timestamp = parent.timestamp + initDuration(seconds = 1)
conf = getChainConfig(network)
com = CommonRef.new(
newMemoryDB(),
conf,
false,
conf.chainId.NetworkId)
parent = BlockHeader(stateRoot: EMPTY_ROOT_HASH)
parentHash = rlpHash(parent)
header = BlockHeader(
blockNumber: 1.u256,
stateRoot: parent.stateRoot,
parentHash: parent.blockHash,
stateRoot: EMPTY_ROOT_HASH,
parentHash: parentHash,
coinbase: coinbase,
timestamp: timestamp,
difficulty: com.calcDifficulty(timestamp, parent),
timestamp: fromUnix(0x1234),
difficulty: 1003.u256,
gasLimit: 100_000
)
vmState = BaseVMState.new(header, com)
(vmState, com)
com.initializeEmptyDb()
BaseVMState.new(parent, header, com)
const codeAddress = hexToByteArray[20]("460121576cc7df020759730751f92bd62fd78dd6")
proc verifyAsmResult(vmState: BaseVMState, com: CommonRef, boa: Assembler, asmResult: CallResult): bool =
proc verifyAsmResult(vmState: BaseVMState, boa: Assembler, asmResult: CallResult): bool =
let com = vmState.com
if not asmResult.isError:
if boa.success == false:
error "different success value", expected=boa.success, actual=true
@ -385,7 +374,7 @@ proc verifyAsmResult(vmState: BaseVMState, com: CommonRef, boa: Assembler, asmRe
result = true
proc createSignedTx(boaData: Blob, chainId: ChainId): Transaction =
proc createSignedTx(payload: Blob, chainId: ChainId): Transaction =
let privateKey = PrivateKey.fromHex("7a28b5ba57c53603b0b07b56bba752f7784bf506fa95edc395f5cf6c7514fe9d")[]
let unsignedTx = Transaction(
txType: TxLegacy,
@ -394,17 +383,20 @@ proc createSignedTx(boaData: Blob, chainId: ChainId): Transaction =
gasLimit: 500_000_000.GasInt,
to: codeAddress.some,
value: 500.u256,
payload: boaData
payload: payload
)
signTransaction(unsignedTx, privateKey, chainId, false)
proc runVM*(vmState: BaseVMState, com: CommonRef, boa: Assembler): bool =
proc runVM*(vmState: BaseVMState, boa: Assembler): bool =
let
com = vmState.com
fork = com.toEVMFork()
vmState.mutateStateDB:
db.setCode(codeAddress, boa.code)
db.setBalance(codeAddress, 1_000_000.u256)
let tx = createSignedTx(boa.data, com.chainId)
let asmResult = testCallEvm(tx, tx.getSender, vmState, boa.fork)
verifyAsmResult(vmState, com, boa, asmResult)
let asmResult = testCallEvm(tx, tx.getSender, vmState, fork)
verifyAsmResult(vmState, boa, asmResult)
macro assembler*(list: untyped): untyped =
result = parseAssembler(list).generateAssemblerTest()

View File

@ -2,8 +2,6 @@ import macro_assembler, unittest2
proc opArithMain*() =
suite "Arithmetic Opcodes":
let (vmState, chainDB) = initDatabase()
assembler:
title: "ADD_1"
code:
@ -297,7 +295,7 @@ proc opArithMain*() =
SDIV
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000000000000000" # half of the hi bits are set
fork: constantinople
fork: Constantinople
assembler: # SUB OP
title: "SUB_1"

View File

@ -2,8 +2,6 @@ import macro_assembler, unittest2
proc opBitMain*() =
suite "Bitwise Opcodes":
let (vmState, chainDB) = initDatabase()
assembler: # AND OP
title: "AND_1"
code:
@ -114,7 +112,7 @@ proc opBitMain*() =
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000001"
PUSH1 "0x00"
SHL
fork: constantinople
fork: Constantinople
stack: "0x0000000000000000000000000000000000000000000000000000000000000001"
assembler: # SHL OP
@ -123,7 +121,7 @@ proc opBitMain*() =
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000001"
PUSH1 "0x01"
SHL
fork: constantinople
fork: Constantinople
stack: "0x0000000000000000000000000000000000000000000000000000000000000002"
assembler: # SHL OP
@ -132,7 +130,7 @@ proc opBitMain*() =
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000001"
PUSH1 "0xff"
SHL
fork: constantinople
fork: Constantinople
stack: "0x8000000000000000000000000000000000000000000000000000000000000000"
assembler: # SHL OP
@ -141,7 +139,7 @@ proc opBitMain*() =
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000001"
PUSH2 "0x0100"
SHL
fork: constantinople
fork: Constantinople
stack: "0x0000000000000000000000000000000000000000000000000000000000000000"
assembler: # SHL OP
@ -150,7 +148,7 @@ proc opBitMain*() =
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000001"
PUSH2 "0x0101"
SHL
fork: constantinople
fork: Constantinople
stack: "0x0000000000000000000000000000000000000000000000000000000000000000"
assembler: # SHL OP
@ -159,7 +157,7 @@ proc opBitMain*() =
PUSH32 "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
PUSH1 "0x00"
SHL
fork: constantinople
fork: Constantinople
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
assembler: # SHL OP
@ -168,7 +166,7 @@ proc opBitMain*() =
PUSH32 "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
PUSH1 "0x01"
SHL
fork: constantinople
fork: Constantinople
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE"
assembler: # SHL OP
@ -177,7 +175,7 @@ proc opBitMain*() =
PUSH32 "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
PUSH1 "0xff"
SHL
fork: constantinople
fork: Constantinople
stack: "0x8000000000000000000000000000000000000000000000000000000000000000"
assembler: # SHL OP
@ -186,7 +184,7 @@ proc opBitMain*() =
PUSH32 "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
PUSH2 "0x0100"
SHL
fork: constantinople
fork: Constantinople
stack: "0x0000000000000000000000000000000000000000000000000000000000000000"
assembler: # SHL OP
@ -195,7 +193,7 @@ proc opBitMain*() =
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000000"
PUSH1 "0x01"
SHL
fork: constantinople
fork: Constantinople
stack: "0x0000000000000000000000000000000000000000000000000000000000000000"
assembler: # SHL OP
@ -204,7 +202,7 @@ proc opBitMain*() =
PUSH32 "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
PUSH1 "0x01"
SHL
fork: constantinople
fork: Constantinople
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE"
assembler: # SHR OP
@ -213,7 +211,7 @@ proc opBitMain*() =
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000001"
PUSH1 "0x00"
SHR
fork: constantinople
fork: Constantinople
stack: "0x0000000000000000000000000000000000000000000000000000000000000001"
assembler: # SHR OP
@ -222,7 +220,7 @@ proc opBitMain*() =
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000001"
PUSH1 "0x01"
SHR
fork: constantinople
fork: Constantinople
stack: "0x0000000000000000000000000000000000000000000000000000000000000000"
assembler: # SHR OP
@ -231,7 +229,7 @@ proc opBitMain*() =
PUSH32 "0x8000000000000000000000000000000000000000000000000000000000000000"
PUSH1 "0x01"
SHR
fork: constantinople
fork: Constantinople
stack: "0x4000000000000000000000000000000000000000000000000000000000000000"
assembler: # SHR OP
@ -240,7 +238,7 @@ proc opBitMain*() =
PUSH32 "0x8000000000000000000000000000000000000000000000000000000000000000"
PUSH1 "0xff"
SHR
fork: constantinople
fork: Constantinople
stack: "0x0000000000000000000000000000000000000000000000000000000000000001"
assembler: # SHR OP
@ -249,7 +247,7 @@ proc opBitMain*() =
PUSH32 "0x8000000000000000000000000000000000000000000000000000000000000000"
PUSH2 "0x0100"
SHR
fork: constantinople
fork: Constantinople
stack: "0x0000000000000000000000000000000000000000000000000000000000000000"
assembler: # SHR OP
@ -258,7 +256,7 @@ proc opBitMain*() =
PUSH32 "0x8000000000000000000000000000000000000000000000000000000000000000"
PUSH2 "0x0101"
SHR
fork: constantinople
fork: Constantinople
stack: "0x0000000000000000000000000000000000000000000000000000000000000000"
assembler: # SHR OP
@ -267,7 +265,7 @@ proc opBitMain*() =
PUSH32 "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
PUSH1 "0x00"
SHR
fork: constantinople
fork: Constantinople
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
assembler: # SHR OP
@ -276,7 +274,7 @@ proc opBitMain*() =
PUSH32 "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
PUSH1 "0x01"
SHR
fork: constantinople
fork: Constantinople
stack: "0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
assembler: # SHR OP
@ -285,7 +283,7 @@ proc opBitMain*() =
PUSH32 "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
PUSH1 "0xff"
SHR
fork: constantinople
fork: Constantinople
stack: "0x0000000000000000000000000000000000000000000000000000000000000001"
assembler: # SHR OP
@ -294,7 +292,7 @@ proc opBitMain*() =
PUSH32 "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
PUSH2 "0x0100"
SHR
fork: constantinople
fork: Constantinople
stack: "0x0000000000000000000000000000000000000000000000000000000000000000"
assembler: # SHR OP
@ -303,7 +301,7 @@ proc opBitMain*() =
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000000"
PUSH1 "0x01"
SHR
fork: constantinople
fork: Constantinople
stack: "0x0000000000000000000000000000000000000000000000000000000000000000"
assembler: # SAR OP
@ -312,7 +310,7 @@ proc opBitMain*() =
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000001"
PUSH1 "0x00"
SAR
fork: constantinople
fork: Constantinople
stack: "0x0000000000000000000000000000000000000000000000000000000000000001"
assembler: # SAR OP
@ -321,7 +319,7 @@ proc opBitMain*() =
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000001"
PUSH1 "0x01"
SAR
fork: constantinople
fork: Constantinople
stack: "0x0000000000000000000000000000000000000000000000000000000000000000"
assembler: # SAR OP
@ -330,7 +328,7 @@ proc opBitMain*() =
PUSH32 "0x8000000000000000000000000000000000000000000000000000000000000000"
PUSH1 "0x01"
SAR
fork: constantinople
fork: Constantinople
stack: "0xC000000000000000000000000000000000000000000000000000000000000000"
assembler: # SAR OP
@ -339,7 +337,7 @@ proc opBitMain*() =
PUSH32 "0x8000000000000000000000000000000000000000000000000000000000000000"
PUSH1 "0xff"
SAR
fork: constantinople
fork: Constantinople
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
assembler: # SAR OP
@ -348,7 +346,7 @@ proc opBitMain*() =
PUSH32 "0x8000000000000000000000000000000000000000000000000000000000000000"
PUSH2 "0x0100"
SAR
fork: constantinople
fork: Constantinople
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
assembler: # SAR OP
@ -357,7 +355,7 @@ proc opBitMain*() =
PUSH32 "0x8000000000000000000000000000000000000000000000000000000000000000"
PUSH2 "0x0101"
SAR
fork: constantinople
fork: Constantinople
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
assembler: # SAR OP
@ -366,7 +364,7 @@ proc opBitMain*() =
PUSH32 "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
PUSH1 "0x00"
SAR
fork: constantinople
fork: Constantinople
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
assembler: # SAR OP
@ -375,7 +373,7 @@ proc opBitMain*() =
PUSH32 "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
PUSH1 "0x01"
SAR
fork: constantinople
fork: Constantinople
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
assembler: # SAR OP
@ -384,7 +382,7 @@ proc opBitMain*() =
PUSH32 "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
PUSH1 "0xff"
SAR
fork: constantinople
fork: Constantinople
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
assembler: # SAR OP
@ -393,7 +391,7 @@ proc opBitMain*() =
PUSH32 "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
PUSH2 "0x0100"
SAR
fork: constantinople
fork: Constantinople
stack: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
assembler: # SAR OP
@ -402,7 +400,7 @@ proc opBitMain*() =
PUSH32 "0x0000000000000000000000000000000000000000000000000000000000000000"
PUSH1 "0x01"
SAR
fork: constantinople
fork: Constantinople
stack: "0x0000000000000000000000000000000000000000000000000000000000000000"
assembler: # SAR OP
@ -411,7 +409,7 @@ proc opBitMain*() =
PUSH32 "0x4000000000000000000000000000000000000000000000000000000000000000"
PUSH1 "0xfe"
SAR
fork: constantinople
fork: Constantinople
stack: "0x0000000000000000000000000000000000000000000000000000000000000001"
assembler: # SAR OP
@ -420,7 +418,7 @@ proc opBitMain*() =
PUSH32 "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
PUSH1 "0xf8"
SAR
fork: constantinople
fork: Constantinople
stack: "0x000000000000000000000000000000000000000000000000000000000000007F"
assembler: # SAR OP
@ -429,7 +427,7 @@ proc opBitMain*() =
PUSH32 "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
PUSH1 "0xfe"
SAR
fork: constantinople
fork: Constantinople
stack: "0x0000000000000000000000000000000000000000000000000000000000000001"
assembler: # SAR OP
@ -438,7 +436,7 @@ proc opBitMain*() =
PUSH32 "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
PUSH1 "0xff"
SAR
fork: constantinople
fork: Constantinople
stack: "0x0000000000000000000000000000000000000000000000000000000000000000"
assembler: # SAR OP
@ -447,7 +445,7 @@ proc opBitMain*() =
PUSH32 "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
PUSH2 "0x0100"
SAR
fork: constantinople
fork: Constantinople
stack: "0x0000000000000000000000000000000000000000000000000000000000000000"
assembler: # ISZERO OP
@ -657,4 +655,3 @@ proc opBitMain*() =
when isMainModule:
opBitMain()

View File

@ -1,11 +1,10 @@
import
macro_assembler, unittest2,
macro_assembler,
unittest2,
eth/common
proc opCustomMain*() =
suite "Custom Opcodes Test":
let (vmState, chainDB) = initDatabase()
assembler: # CALLDATASIZE OP
title: "CALLDATASIZE_1"
data:
@ -192,7 +191,7 @@ proc opCustomMain*() =
Address
Balance
stack: "0x00000000000000000000000000000000000000000000000000000000000f4434"
fork: berlin
fork: Berlin
gasused: 102
assembler: # ORIGIN OP
@ -254,7 +253,7 @@ proc opCustomMain*() =
code:
Push1 "0x00"
Blockhash
stack: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"
stack: "0xc3bd2d00745c03048a5616146a96f5ff78e54efb9e5b04af208cdaff6f3830ee"
# current block coinbase/miner
assembler: # COINBASE OP
@ -268,7 +267,7 @@ proc opCustomMain*() =
title: "TIMESTAMP_1"
code:
TimeStamp
stack: "0x0000000000000000000000000000000000000000000000000000000000000001"
stack: "0x0000000000000000000000000000000000000000000000000000000000001234"
# current block number
assembler: # NUMBER OP
@ -282,7 +281,7 @@ proc opCustomMain*() =
title: "DIFFICULTY_1"
code:
Difficulty
stack: "0x0000000000000000000000000000000000000000000000000000000400800000"
stack: "0x00000000000000000000000000000000000000000000000000000000000003eb"
# tx gas price
assembler: # GASPRICE OP

View File

@ -1,13 +1,11 @@
import
macro_assembler, unittest2, macros,
macro_assembler, unittest2,
stew/byteutils, ../nimbus/common/common,
../nimbus/[vm_state, constants],
../nimbus/db/accounts_cache
proc opEnvMain*() =
suite "Environmental Information Opcodes":
let (vmState, chainDB) = initDatabase()
assembler: # EVM bug reported in discord
title: "stack's operator [] bug"
code:
@ -19,7 +17,7 @@ proc opEnvMain*() =
GAS
STATICCALL
CALL
fork: london
fork: London
success: false
memory: "0x0000000000000000000000000000000000000000000000000000000000000000"
@ -194,7 +192,6 @@ proc opEnvMain*() =
suite "Environmental Information Opcodes 2":
let
(vmState, chainDB) = initDatabase()
acc = hexToByteArray[20]("0xfbe0afcd7658ba86be41922059dd879c192d4c73")
code = hexToSeqByte("0x0102030405060708090A0B0C0D0E0F" &
"611234600054615566602054603E6000602073471FD3AD3E9EEADEEC4608B92D" &
@ -202,11 +199,11 @@ proc opEnvMain*() =
"51602001600a5254516040016014525451606001601e52545160800160285254" &
"60a052546016604860003960166000f26000603f556103e756600054600053602002351234")
vmState.mutateStateDB:
db.setCode(acc, code)
assembler: # EXTCODECOPY OP
title: "EXTCODECOPY_1"
setup:
vmState.mutateStateDB:
db.setCode(acc, code)
code:
Push1 "0x04" # size
Push1 "0x07" # code pos
@ -222,6 +219,9 @@ proc opEnvMain*() =
assembler: # EXTCODECOPY OP
title: "EXTCODECOPY_2"
setup:
vmState.mutateStateDB:
db.setCode(acc, code)
code:
Push1 "0x3E"
Push1 "0x07"
@ -239,6 +239,9 @@ proc opEnvMain*() =
assembler: # EXTCODECOPY OP
title: "EXTCODECOPY_3"
setup:
vmState.mutateStateDB:
db.setCode(acc, code)
code:
Push1 "0x5E"
Push1 "0x07"
@ -257,6 +260,9 @@ proc opEnvMain*() =
assembler: # EXTCODECOPY OP
title: "EXTCODECOPY_4"
setup:
vmState.mutateStateDB:
db.setCode(acc, code)
code:
Push2 "0x1234"
Push1 "0x00"
@ -308,6 +314,9 @@ proc opEnvMain*() =
# 0x94 == 148 bytes
assembler: # EXTCODESIZE OP
title: "EXTCODESIZE_1"
setup:
vmState.mutateStateDB:
db.setCode(acc, code)
code:
Push20 "0xfbe0afcd7658ba86be41922059dd879c192d4c73"
ExtCodeSize
@ -320,29 +329,31 @@ proc opEnvMain*() =
assembler: # EIP2929 EXTCODESIZE OP
title: "EIP2929 EXTCODESIZE_1"
setup:
vmState.mutateStateDB:
db.setCode(acc, code)
code:
Push20 "0xfbe0afcd7658ba86be41922059dd879c192d4c73"
ExtCodeSize
STOP
stack: "0x94"
fork: berlin
fork: Berlin
gasused: 2603
assembler: # EIP2929 EXTCODEHASH OP
title: "EIP2929 EXTCODEHASH_1"
setup:
vmState.mutateStateDB:
db.setCode(acc, code)
code:
Push20 "0xfbe0afcd7658ba86be41922059dd879c192d4c73"
ExtCodeHash
STOP
stack:
"0xc862129bffb73168481c6a51fd36afb8342887fbc5314c763ac731c732d7310c"
fork: berlin
fork: Berlin
gasused: 2603
#[
## TODO: Fixme using MergeFork
## properly rather than using hacky wacky
vmState.ttdReached = true
assembler:
title: "EIP-4399 PrevRandao 0"
code:
@ -350,20 +361,18 @@ proc opEnvMain*() =
STOP
stack:
"0x0000000000000000000000000000000000000000000000000000000000000000"
fork: london
fork: Merge
vmState.prevRandao = EMPTY_UNCLE_HASH
assembler:
title: "EIP-4399 PrevRandao: EMPTY_UNCLE_HASH"
setup:
vmState.prevRandao = EMPTY_UNCLE_HASH
code:
PrevRandao
STOP
stack:
"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
fork: london
vmState.ttdReached = false
]#
fork: Merge
when isMainModule:
opEnvMain()

View File

@ -1,9 +1,9 @@
import macro_assembler, unittest2, macros, strutils
import
std/[macros, strutils],
macro_assembler, unittest2
proc opMemoryMain*() =
suite "Memory Opcodes":
let (vmState, chainDB) = initDatabase()
assembler: # PUSH1 OP
title: "PUSH1"
code:
@ -516,152 +516,124 @@ proc opMemoryMain*() =
SSTORE
success: false
stack: "0x22"
#[
assembler: # SSTORE EIP1283
title: "SSTORE_NET_1"
code: "60006000556000600055"
fork: constantinople
# assertEquals(412, program.getResult().getGasUsed())
# assertEquals(0, program.getResult().getFutureRefund())
fork: Constantinople
gasUsed: 412
assembler: # SSTORE EIP1283
title: "SSTORE_NET_2"
code: "60006000556001600055"
fork: constantinople
# assertEquals(20212, program.getResult().getGasUsed())
# assertEquals(0, program.getResult().getFutureRefund())
fork: Constantinople
gasUsed: 20212
assembler: # SSTORE EIP1283
title: "SSTORE_NET_3"
code: "60016000556000600055"
fork: constantinople
# assertEquals(20212, program.getResult().getGasUsed())
# assertEquals(19800, program.getResult().getFutureRefund())
fork: Constantinople
gasUsed: 20212
assembler: # SSTORE EIP1283
title: "SSTORE_NET_4"
code: "60016000556002600055"
fork: constantinople
# assertEquals(20212, program.getResult().getGasUsed())
# assertEquals(0, program.getResult().getFutureRefund())
fork: Constantinople
gasUsed: 20212
assembler: # SSTORE EIP1283
title: "SSTORE_NET_5"
code: "60016000556001600055"
fork: constantinople
# assertEquals(20212, program.getResult().getGasUsed())
# assertEquals(0, program.getResult().getFutureRefund())
fork: Constantinople
gasUsed: 20212
#[
# Sets Storage row on "cow" address:
# 0: 1
# private void setStorageToOne(VM vm) {
# # Sets storage value to 1 and commits
# code: "60006000556001600055"
# fork: constantinople
# fork: Constantinople
# invoke.getRepository().commit()
# invoke.setOrigRepository(invoke.getRepository())
setStorageToOne(vm)
assembler: # SSTORE EIP1283
title: "SSTORE_NET_6"
code: "60006000556000600055"
fork: constantinople
# assertEquals(5212, program.getResult().getGasUsed())
# assertEquals(15000, program.getResult().getFutureRefund())
fork: Constantinople
gasUsed: 5212
setStorageToOne(vm)
assembler: # SSTORE EIP1283
title: "SSTORE_NET_7"
code: "60006000556001600055"
fork: constantinople
# assertEquals(5212, program.getResult().getGasUsed())
# assertEquals(4800, program.getResult().getFutureRefund())
fork: Constantinople
gasUsed: 5212
setStorageToOne(vm)
assembler: # SSTORE EIP1283
title: "SSTORE_NET_8"
code: "60006000556002600055"
fork: constantinople
# assertEquals(5212, program.getResult().getGasUsed())
# assertEquals(0, program.getResult().getFutureRefund())
fork: Constantinople
gasUsed: 5212
setStorageToOne(vm)
assembler: # SSTORE EIP1283
title: "SSTORE_NET_9"
code: "60026000556000600055"
fork: constantinople
# assertEquals(5212, program.getResult().getGasUsed())
# assertEquals(15000, program.getResult().getFutureRefund())
fork: Constantinople
gasUsed: 5212
setStorageToOne(vm)
assembler: # SSTORE EIP1283
title: "SSTORE_NET_10"
code: "60026000556003600055"
fork: constantinople
# assertEquals(5212, program.getResult().getGasUsed())
# assertEquals(0, program.getResult().getFutureRefund())
fork: Constantinople
gasUsed: 5212
setStorageToOne(vm)
assembler: # SSTORE EIP1283
title: "SSTORE_NET_11"
code: "60026000556001600055"
fork: constantinople
# assertEquals(5212, program.getResult().getGasUsed())
# assertEquals(4800, program.getResult().getFutureRefund())
fork: Constantinople
gasUsed: 5212
setStorageToOne(vm)
assembler: # SSTORE EIP1283
title: "SSTORE_NET_12"
code: "60026000556002600055"
fork: constantinople
# assertEquals(5212, program.getResult().getGasUsed())
# assertEquals(0, program.getResult().getFutureRefund())
fork: Constantinople
gasUsed: 5212
setStorageToOne(vm)
assembler: # SSTORE EIP1283
title: "SSTORE_NET_13"
code: "60016000556000600055"
fork: constantinople
# assertEquals(5212, program.getResult().getGasUsed())
# assertEquals(15000, program.getResult().getFutureRefund())
fork: Constantinople
gasUsed: 5212
setStorageToOne(vm)
assembler: # SSTORE EIP1283
title: "SSTORE_NET_14"
code: "60016000556002600055"
fork: constantinople
# assertEquals(5212, program.getResult().getGasUsed())
# assertEquals(0, program.getResult().getFutureRefund())
fork: Constantinople
gasUsed: 5212
setStorageToOne(vm)
assembler: # SSTORE EIP1283
title: "SSTORE_NET_15"
code: "60016000556001600055"
fork: constantinople
# assertEquals(412, program.getResult().getGasUsed())
# assertEquals(0, program.getResult().getFutureRefund())
fork: Constantinople
gasUsed: 412
assembler: # SSTORE EIP1283
title: "SSTORE_NET_16"
code: "600160005560006000556001600055"
fork: constantinople
# assertEquals(40218, program.getResult().getGasUsed())
# assertEquals(19800, program.getResult().getFutureRefund())
fork: Constantinople
gasUsed: 40218
setStorageToOne(vm)
assembler: # SSTORE EIP1283
title: "SSTORE_NET_17"
code: "600060005560016000556000600055"
fork: constantinople
# assertEquals(10218, program.getResult().getGasUsed())
# assertEquals(19800, program.getResult().getFutureRefund())
]#
fork: Constantinople
gasUsed: 10218
]#
assembler: # SLOAD OP
title: "SLOAD_1"
code:
PUSH1 "0xAA"
SLOAD
stack: "0x0000000000000000000000000000000000000000000000000000000000000022"
stack: "0x0000000000000000000000000000000000000000000000000000000000000000"
assembler: # SLOAD OP
title: "SLOAD_2"
@ -707,7 +679,7 @@ proc opMemoryMain*() =
SLOAD
PC
stack:
"0x0000000000000000000000000000000000000000000000000000000000000022"
"0x0000000000000000000000000000000000000000000000000000000000000000"
"0x0000000000000000000000000000000000000000000000000000000000000008"
memory:
"0x00"

View File

@ -1,11 +1,10 @@
import
macro_assembler, unittest2, macros,
stew/byteutils, eth/common
macro_assembler,
unittest2,
eth/common
proc opMiscMain*() =
suite "Misc Opcodes":
let (vmState, chainDB) = initDatabase()
assembler: # LOG0 OP
title: "Log0"
code:

View File

@ -39,7 +39,6 @@ export
tx_packer.packerVmExec,
tx_recover.recoverItem,
tx_tabs.TxTabsRef,
tx_tabs.any,
tx_tabs.decAccount,
tx_tabs.dispose,
tx_tabs.eq,

View File

@ -1,6 +1,6 @@
import
std/[strutils, math, tables, times],
eth/[keys, trie/hexary],
std/[math, tables, times],
eth/[keys],
stew/[byteutils, results], unittest2,
../nimbus/db/state_db,
../nimbus/core/chain,