From 88b14069129d28f52a5c0cf44af6c17573bd309f Mon Sep 17 00:00:00 2001 From: tersec Date: Thu, 6 Jun 2024 15:38:14 +0000 Subject: [PATCH 1/3] rm withdrawn EIP-2315 --- nimbus/config.nim | 18 ---- .../interpreter/op_handlers/oph_memory.nim | 92 ++----------------- nimbus/evm/state_transactions.nim | 7 +- tests/amphora/.gitignore | 1 - tests/amphora/amphora-interop-genesis-m1.json | 41 --------- tests/amphora/check-merge-test-vectors.sh | 32 ------- tests/amphora/connect-to-hacknet-v2.sh | 26 ------ tests/amphora/launch-nimbus.sh | 28 ------ tests/amphora/signer-key.txt | 1 - tests/test_helpers.nim | 3 +- 10 files changed, 13 insertions(+), 236 deletions(-) delete mode 100644 tests/amphora/.gitignore delete mode 100644 tests/amphora/amphora-interop-genesis-m1.json delete mode 100755 tests/amphora/check-merge-test-vectors.sh delete mode 100755 tests/amphora/connect-to-hacknet-v2.sh delete mode 100755 tests/amphora/launch-nimbus.sh delete mode 100644 tests/amphora/signer-key.txt diff --git a/nimbus/config.nim b/nimbus/config.nim index c4e07c7b0..ec867a624 100644 --- a/nimbus/config.nim +++ b/nimbus/config.nim @@ -21,7 +21,6 @@ import chronicles, confutils, confutils/defs, - stew/byteutils, confutils/std/net ], eth/[common, net/utils, net/nat, p2p/bootnodes, p2p/enode, p2p/discoveryv5/enr], @@ -532,23 +531,6 @@ func parseCmdArg(T: type NetworkId, p: string): T func completeCmdArg(T: type NetworkId, val: string): seq[string] = return @[] -func parseCmdArg(T: type UInt256, p: string): T - {.gcsafe, raises: [ValueError].} = - parse(p, T) - -func completeCmdArg(T: type UInt256, val: string): seq[string] = - return @[] - -func parseCmdArg(T: type EthAddress, p: string): T - {.gcsafe, raises: [ValueError].}= - try: - result = hexToByteArray(p, 20) - except CatchableError: - raise newException(ValueError, "failed to parse EthAddress") - -func completeCmdArg(T: type EthAddress, val: string): seq[string] = - return @[] - func parseCmdArg*(T: type enr.Record, p: string): T {.raises: [ValueError].} = if not fromURI(result, p): raise newException(ValueError, "Invalid ENR") diff --git a/nimbus/evm/interpreter/op_handlers/oph_memory.nim b/nimbus/evm/interpreter/op_handlers/oph_memory.nim index 9dda1086c..3ce0cb24b 100644 --- a/nimbus/evm/interpreter/op_handlers/oph_memory.nim +++ b/nimbus/evm/interpreter/op_handlers/oph_memory.nim @@ -104,7 +104,7 @@ template sstoreEvmcOrNetGasMetering(cpt, slot, newValue: untyped, coldAccess = 0 else: sstoreNetGasMeteringImpl(cpt, slot, newValue, coldAccess) -proc jumpImpl(c: Computation; jumpTarget: UInt256) {.catchRaise.} = +func jumpImpl(c: Computation; jumpTarget: UInt256) {.catchRaise.} = if jumpTarget >= c.code.len.u256: raise newException( InvalidJumpDestination, "Invalid Jump Destination") @@ -126,7 +126,7 @@ proc jumpImpl(c: Computation; jumpTarget: UInt256) {.catchRaise.} = # ------------------------------------------------------------------------------ const - popOp: Vm2OpFn = proc (k: var Vm2Ctx) {.catchRaise.} = + popOp: Vm2OpFn = func (k: var Vm2Ctx) {.catchRaise.} = ## 0x50, Remove item from stack. discard k.cpt.stack.popInt @@ -256,47 +256,47 @@ const # ------- - jumpOp: Vm2OpFn = proc (k: var Vm2Ctx) {.catchRaise.} = + jumpOp: Vm2OpFn = func (k: var Vm2Ctx) {.catchRaise.} = ## 0x56, Alter the program counter let (jumpTarget) = k.cpt.stack.popInt(1) jumpImpl(k.cpt, jumpTarget) - jumpIOp: Vm2OpFn = proc (k: var Vm2Ctx) {.catchRaise.} = + jumpIOp: Vm2OpFn = func (k: var Vm2Ctx) {.catchRaise.} = ## 0x57, Conditionally alter the program counter. let (jumpTarget, testedValue) = k.cpt.stack.popInt(2) if testedValue.isZero.not: jumpImpl(k.cpt, jumpTarget) - pcOp: Vm2OpFn = proc (k: var Vm2Ctx) {.catchRaise.} = + pcOp: Vm2OpFn = func (k: var Vm2Ctx) {.catchRaise.} = ## 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: Vm2OpFn = proc (k: var Vm2Ctx) {.catchRaise.} = + msizeOp: Vm2OpFn = func (k: var Vm2Ctx) {.catchRaise.} = ## 0x59, Get the size of active memory in bytes. k.cpt.stack.push: k.cpt.memory.len - gasOp: Vm2OpFn = proc (k: var Vm2Ctx) {.catchRaise.} = + gasOp: Vm2OpFn = func (k: var Vm2Ctx) {.catchRaise.} = ## 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: Vm2OpFn = proc (k: var Vm2Ctx) = + jumpDestOp: Vm2OpFn = func (k: var Vm2Ctx) = ## 0x5b, Mark a valid destination for jumps. This operation has no effect ## on machine state during execution. discard - tloadOp: Vm2OpFn = proc (k: var Vm2Ctx) {.catchRaise.} = + tloadOp: Vm2OpFn = func (k: var Vm2Ctx) {.catchRaise.} = ## 0x5c, Load word from transient storage. let slot = k.cpt.stack.popInt() val = k.cpt.getTransientStorage(slot) k.cpt.stack.push: val - tstoreOp: Vm2OpFn = proc (k: var Vm2Ctx) {.catchRaise.} = + tstoreOp: Vm2OpFn = func (k: var Vm2Ctx) {.catchRaise.} = ## 0x5d, Save word to transient storage. checkInStaticContext(k.cpt) @@ -318,50 +318,6 @@ const k.cpt.memory.copy(dstPos, srcPos, len) -#[ - EIP-2315: temporary disabled - Reason : not included in berlin hard fork - beginSubOp: Vm2OpFn = proc (k: var Vm2Ctx) = - ## 0x5c, Marks the entry point to a subroutine - raise newException( - OutOfGas, - "Abort: Attempt to execute BeginSub opcode") - - - returnSubOp: Vm2OpFn = proc (k: var Vm2Ctx) = - ## 0x5d, Returns control to the caller of a subroutine. - if k.cpt.returnStack.len == 0: - raise newException( - OutOfGas, - "Abort: invalid returnStack during ReturnSub") - k.cpt.code.pc = k.cpt.returnStack.pop() - - - jumpSubOp: Vm2OpFn = proc (k: var Vm2Ctx) = - ## 0x5e, Transfers control to a subroutine. - let (jumpTarget) = k.cpt.stack.popInt(1) - - if jumpTarget >= k.cpt.code.len.u256: - raise newException( - InvalidJumpDestination, "JumpSub destination exceeds code len") - - let returnPC = k.cpt.code.pc - let jt = jumpTarget.truncate(int) - k.cpt.code.pc = jt - - let nextOpcode = k.cpt.code.peek - if nextOpcode != BeginSub: - raise newException( - InvalidJumpDestination, "Invalid JumpSub destination") - - if k.cpt.returnStack.len == 1023: - raise newException( - FullStack, "Out of returnStack") - - k.cpt.returnStack.add returnPC - inc k.cpt.code.pc -]# - # ------------------------------------------------------------------------------ # Public, op exec table entries # ------------------------------------------------------------------------------ @@ -532,34 +488,6 @@ const run: mCopyOp, post: vm2OpIgnore))] -#[ - EIP-2315: temporary disabled - Reason : not included in berlin hard fork - (opCode: BeginSub, ## 0x5c, Begin subroutine - forks: Vm2OpBerlinAndLater, - name: "beginSub", - info: " Marks the entry point to a subroutine", - exec: (prep: vm2OpIgnore, - run: beginSubOp, - post: vm2OpIgnore)), - - (opCode: ReturnSub, ## 0x5d, Return - forks: Vm2OpBerlinAndLater, - name: "returnSub", - info: "Returns control to the caller of a subroutine", - exec: (prep: vm2OpIgnore, - run: returnSubOp, - post: vm2OpIgnore)), - - (opCode: JumpSub, ## 0x5e, Call subroutine - forks: Vm2OpBerlinAndLater, - name: "jumpSub", - info: "Transfers control to a subroutine", - exec: (prep: vm2OpIgnore, - run: jumpSubOp, - post: vm2OpIgnore))] -]# - # ------------------------------------------------------------------------------ # End # ------------------------------------------------------------------------------ diff --git a/nimbus/evm/state_transactions.nim b/nimbus/evm/state_transactions.nim index f7b3d579a..b53b42a26 100644 --- a/nimbus/evm/state_transactions.nim +++ b/nimbus/evm/state_transactions.nim @@ -35,17 +35,12 @@ proc setupTxContext*(vmState: BaseVMState, vmState.determineFork vmState.gasCosts = vmState.fork.forkToSchedule -# FIXME-awkwardFactoring: the factoring out of the pre and -# post parts feels awkward to me, but for now I'd really like -# not to have too much duplicated code between sync and async. -# --Adam - proc preExecComputation(c: Computation) = if not c.msg.isCreate: c.vmState.mutateStateDB: db.incNonce(c.msg.sender) -proc postExecComputation(c: Computation) = +func postExecComputation(c: Computation) = if c.isSuccess: if c.fork < FkLondon: # EIP-3529: Reduction in refunds diff --git a/tests/amphora/.gitignore b/tests/amphora/.gitignore deleted file mode 100644 index b189e585f..000000000 --- a/tests/amphora/.gitignore +++ /dev/null @@ -1 +0,0 @@ -hacknet/ diff --git a/tests/amphora/amphora-interop-genesis-m1.json b/tests/amphora/amphora-interop-genesis-m1.json deleted file mode 100644 index 3c7b19f26..000000000 --- a/tests/amphora/amphora-interop-genesis-m1.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "config": { - "chainId": 1, - "homesteadBlock": 0, - "daoForkBlock": 0, - "daoForkSupport": true, - "eip150Block": 0, - "eip155Block": 0, - "eip158Block": 0, - "byzantiumBlock": 0, - "constantinopleBlock": 0, - "petersburgBlock": 0, - "istanbulBlock": 0, - "muirGlacierBlock": 0, - "berlinBlock": 0, - "londonBlock": 0, - "clique": { - "period": 5, - "epoch": 30000 - }, - "terminalTotalDifficulty": 0 - }, - "genesis": { - "nonce": "0x42", - "timestamp": "0x0", - "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "gasLimit": "0x1C9C380", - "difficulty": "0x400000000", - "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "coinbase": "0x0000000000000000000000000000000000000000", - "alloc": { - "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { - "balance": "0x6d6172697573766477000000" - } - }, - "number": "0x0", - "gasUsed": "0x0", - "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "baseFeePerGas": "0x7" - } -} diff --git a/tests/amphora/check-merge-test-vectors.sh b/tests/amphora/check-merge-test-vectors.sh deleted file mode 100755 index e3106f45a..000000000 --- a/tests/amphora/check-merge-test-vectors.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bash -set -Eeuo pipefail - -# https://notes.ethereum.org/@9AeMAlpyQYaAAyuj47BzRw/rkwW3ceVY -# -# git clone --branch merge-interop-spec https://github.com/MariusVanDerWijden/go-ethereum.git -# -# Last checked against geth as of -# commit d6b04900423634d27be1178edf46622394085bb9 (HEAD -> merge-interop-spec, origin/merge-interop-spec) -# Author: Marius van der Wijden -# Date: Wed Sep 29 19:24:56 2021 +0200 -# -# eth/catalyst: fix random in payload, payloadid as hexutil - -# Get the payload -resp_get_payload=$(curl -sX POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"engine_getPayloadV1","params":["0x0"],"id":67}' http://localhost:8550) -echo "engine_getPayloadV1 response: ${resp_get_payload}" - -expected_resp_get_payload='{"jsonrpc":"2.0","id":67,"result":{"blockHash":"0xb084c10440f05f5a23a55d1d7ebcb1b3892935fb56f23cdc9a7f42c348eed174","parentHash":"0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131","coinbase":"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b","stateRoot":"0xca3149fa9e37db08d1cd49c9061db1002ef1cd58db2210f2115c8c989b2bdf45","receiptRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","random":"0x0000000000000000000000000000000000000000000000000000000000000000","blockNumber":"0x1","gasLimit":"0x989680","gasUsed":"0x0","timestamp":"0x5","extraData":"0x","baseFeePerGas":"0x0","transactions":[]}}' -empirical_resp_get_payload='{"jsonrpc":"2.0","id":67,"result":{"blockHash":"0x7a694c5e6e372e6f865b073c101c2fba01f899f16480eb13f7e333a3b7e015bc","parentHash":"0xa0513a503d5bd6e89a144c3268e5b7e9da9dbf63df125a360e3950a7d0d67131","coinbase":"0x0000000000000000000000000000000000000000","stateRoot":"0xca3149fa9e37db08d1cd49c9061db1002ef1cd58db2210f2115c8c989b2bdf45","receiptRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","random":"0x0000000000000000000000000000000000000000000000000000000000000000","blockNumber":"0x1","gasLimit":"0x989680","gasUsed":"0x0","timestamp":"0x5","extraData":"0x","baseFeePerGas":"0x0","transactions":[]}}' -[[ ${resp_get_payload} == ${expected_resp_get_payload} ]] || [[ ${resp_get_payload} == ${empirical_resp_get_payload} ]] || (echo "Unexpected response to engine_getPayloadV1"; false) - -# Execute the payload -# Needed two tweaks vs upstream note: (a) add blockNumber field and (b) switch receiptRoots to receiptRoot -resp_execute_payload=$(curl -sX POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"engine_executePayloadV1","params":[{"blockHash":"0x3559e851470f6e7bbed1db474980683e8c315bfce99b2a6ef47c057c04de7858","parentHash":"0x3b8fb240d288781d4aac94d3fd16809ee413bc99294a085798a589dae51ddd4a","coinbase":"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b","stateRoot":"0xca3149fa9e37db08d1cd49c9061db1002ef1cd58db2210f2115c8c989b2bdf45","receiptRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","random":"0x0000000000000000000000000000000000000000000000000000000000000000","blockNumber":"0x1","gasLimit":"0x1c9c380","gasUsed":"0x0","timestamp":"0x5","extraData":"0x","baseFeePerGas":"0x7","transactions":[]}],"id":67}' http://localhost:8550) -[[ ${resp_execute_payload} == '{"jsonrpc":"2.0","id":67,"result":{"status":"VALID"}}' ]] || (echo "Unexpected response to engine_executePayloadV1"; false) - -# Update the fork choice -resp_fork_choice_updated=$(curl -sX POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"engine_forkchoiceUpdatedV1","params":[{"headBlockHash":"0x3559e851470f6e7bbed1db474980683e8c315bfce99b2a6ef47c057c04de7858", "finalizedBlockHash":"0x3559e851470f6e7bbed1db474980683e8c315bfce99b2a6ef47c057c04de7858"}],"id":67}' http://localhost:8550) -[[ ${resp_consensus_validated} == '{"jsonrpc":"2.0","id":67,"result":null}' ]] || (echo "Unexpected response to engine_forkchoiceUpdatedV1"; false) - -echo "Execution test vectors for Merge passed" diff --git a/tests/amphora/connect-to-hacknet-v2.sh b/tests/amphora/connect-to-hacknet-v2.sh deleted file mode 100755 index caa3548e3..000000000 --- a/tests/amphora/connect-to-hacknet-v2.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -set -eu - -SCRIPT_DIR=$(cd $(dirname "$0") && pwd) - -cd "$SCRIPT_DIR" - -if [[ ! -d hacknet ]]; then - git clone https://github.com/karalabe/hacknet/ -fi - -DATA_DIR=hacknet/data/nimbus-eth1 -mkdir -p $DATA_DIR - -BOOT_NODE=enode://e95870e55cf62fd3d7091d7e0254d10ead007a1ac64ea071296a603d94694b8d92b49f9a3d3851d9aa95ee1452de8b854e0d5e095ef58cc25e7291e7588f4dfc@35.178.114.73:30303 - -$SCRIPT_DIR/../../build/nimbus \ - --log-level:DEBUG \ - --data-dir:"$SCRIPT_DIR/$DATA_DIR" \ - --custom-network:"$SCRIPT_DIR/hacknet/v2/genesis.json" \ - --bootstrap-node:$BOOT_NODE \ - --network:1337002 \ - --engine-api \ - --rpc - diff --git a/tests/amphora/launch-nimbus.sh b/tests/amphora/launch-nimbus.sh deleted file mode 100755 index 71d012594..000000000 --- a/tests/amphora/launch-nimbus.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash -# set -Eeuo pipefail - -# https://notes.ethereum.org/@9AeMAlpyQYaAAyuj47BzRw/rkwW3ceVY - -# To increase verbosity: debug.verbosity(4) -# MetaMask seed phrase for address with balance is: -# lecture manual soon title cloth uncle gesture cereal common fruit tooth crater - -set -eu - -SCRIPT_DIR=$(cd $(dirname "$0") && pwd) - -DATA_DIR=$(mktemp -d) -echo Using data dir ${DATA_DIR} - -$SCRIPT_DIR/../../build/nimbus \ - --log-level:TRACE \ - --data-dir:"${DATA_DIR}" \ - --custom-network:"$SCRIPT_DIR/amphora-interop-genesis-m1.json" \ - --network:0 \ - --engine-api \ - --engine-api-port:8545 \ - --rpc \ - --nat:none --discovery:none \ - --import-key:"$SCRIPT_DIR/signer-key.txt" \ - --engine-signer:0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b - diff --git a/tests/amphora/signer-key.txt b/tests/amphora/signer-key.txt deleted file mode 100644 index da79bfa4c..000000000 --- a/tests/amphora/signer-key.txt +++ /dev/null @@ -1 +0,0 @@ -0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8 diff --git a/tests/test_helpers.nim b/tests/test_helpers.nim index 4b0a4b61a..48daa4afe 100644 --- a/tests/test_helpers.nim +++ b/tests/test_helpers.nim @@ -31,7 +31,8 @@ const FkIstanbul: "Istanbul", FkBerlin: "Berlin", FkLondon: "London", - FkParis: "Merge" + FkParis: "Merge", + FkPrague: "Prague", }.toTable nameToFork* = revmap(forkNames) From 66fd6df876999186f4317da928d849963be5c996 Mon Sep 17 00:00:00 2001 From: tersec Date: Thu, 6 Jun 2024 17:59:25 +0000 Subject: [PATCH 2/3] copyright year linting --- tests/test_helpers.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_helpers.nim b/tests/test_helpers.nim index 48daa4afe..4c97f4278 100644 --- a/tests/test_helpers.nim +++ b/tests/test_helpers.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2018-2023 Status Research & Development GmbH +# Copyright (c) 2018-2024 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) From acec06653b8df4adce0cbb88b1f97994ab031b53 Mon Sep 17 00:00:00 2001 From: tersec Date: Thu, 6 Jun 2024 18:19:41 +0000 Subject: [PATCH 3/3] EVMC --- nimbus/evm/interpreter/op_handlers/oph_memory.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nimbus/evm/interpreter/op_handlers/oph_memory.nim b/nimbus/evm/interpreter/op_handlers/oph_memory.nim index 3ce0cb24b..0bc901159 100644 --- a/nimbus/evm/interpreter/op_handlers/oph_memory.nim +++ b/nimbus/evm/interpreter/op_handlers/oph_memory.nim @@ -289,14 +289,14 @@ const ## on machine state during execution. discard - tloadOp: Vm2OpFn = func (k: var Vm2Ctx) {.catchRaise.} = + tloadOp: Vm2OpFn = proc (k: var Vm2Ctx) {.catchRaise.} = ## 0x5c, Load word from transient storage. let slot = k.cpt.stack.popInt() val = k.cpt.getTransientStorage(slot) k.cpt.stack.push: val - tstoreOp: Vm2OpFn = func (k: var Vm2Ctx) {.catchRaise.} = + tstoreOp: Vm2OpFn = proc (k: var Vm2Ctx) {.catchRaise.} = ## 0x5d, Save word to transient storage. checkInStaticContext(k.cpt)