From e412c93580e9146293c48a25440ac20bd2d4e695 Mon Sep 17 00:00:00 2001 From: jangko Date: Fri, 9 Jun 2023 15:45:18 +0700 Subject: [PATCH] bump stint to v2.0: new array backend --- fluffy/content_db.nim | 12 ++++++------ fluffy/fluffy.nim | 2 +- .../beacon_light_client_db.nim | 4 ++-- fluffy/network/state/state_content.nim | 2 +- fluffy/network/wire/messages.nim | 2 +- fluffy/network/wire/portal_protocol.nim | 2 +- fluffy/network/wire/portal_stream.nim | 2 +- fluffy/seed_db.nim | 6 +++--- fluffy/tools/utp_testing/utp_rpc_types.nim | 2 +- fluffy/tools/utp_testing/utp_test_app.nim | 2 +- nimbus/common/chain_config.nim | 2 +- nimbus/common/genesis.nim | 2 +- nimbus/common/hardforks.nim | 3 ++- nimbus/core/executor/executor_helpers.nim | 4 ++-- nimbus/core/pow.nim | 1 + nimbus/db/accounts_cache.nim | 2 +- .../aristo_desc/aristo_types_identifiers.nim | 2 +- .../db/aristo/aristo_init/aristo_rocksdb.nim | 2 +- .../aristo_init/aristo_rocksdb/rdb_desc.nim | 1 + .../aristo_init/aristo_rocksdb/rdb_walk.nim | 1 + nimbus/db/aristo/aristo_transcode.nim | 2 +- nimbus/db/distinct_tries.nim | 2 +- nimbus/db/state_db.nim | 4 ++-- nimbus/evm/computation.nim | 4 ++-- nimbus/evm/evmc_helpers.nim | 2 +- .../op_handlers/oph_arithmetic.nim | 19 +++++++++++++------ .../interpreter/op_handlers/oph_memory.nim | 4 ++-- .../evm/interpreter/utils/utils_numeric.nim | 5 ++--- nimbus/evm/interpreter_dispatch.nim | 4 ++-- nimbus/evm/memory.nim | 2 +- nimbus/evm/stack.nim | 8 ++++---- nimbus/evm/state.nim | 2 +- nimbus/evm/transaction_tracer.nim | 2 +- nimbus/rpc/hexstrings.nim | 3 ++- nimbus/rpc/merge/mergeutils.nim | 2 +- nimbus/sync/handlers/eth.nim | 1 + nimbus/sync/snap/worker/db/hexary_desc.nim | 1 + nimbus/transaction.nim | 4 ++-- nimbus/transaction/evmc_vm_glue.nim | 4 ++-- nimbus/transaction/host_call_nested.nim | 2 +- nimbus/transaction/host_services.nim | 2 +- nimbus/transaction/host_trace.nim | 2 +- nimbus/transaction/host_types.nim | 2 +- nimbus/utils/ec_recover.nim | 4 ++-- premix/hunter.nim | 2 +- tests/test_aristo/test_delete.nim | 2 +- tests/test_aristo/test_transcode.nim | 2 +- tests/test_pow.nim | 1 + vendor/nim-stint | 2 +- vendor/nimbus-eth2 | 2 +- 50 files changed, 84 insertions(+), 70 deletions(-) diff --git a/fluffy/content_db.nim b/fluffy/content_db.nim index fa8cc2f461..c4c706fe77 100644 --- a/fluffy/content_db.nim +++ b/fluffy/content_db.nim @@ -232,19 +232,19 @@ proc contentSize*(db: ContentDB): int64 = proc get*(db: ContentDB, key: ContentId): Opt[seq[byte]] = # TODO: Here it is unfortunate that ContentId is a uint256 instead of Digest256. - db.get(key.toByteArrayBE()) + db.get(key.toBytesBE()) proc put*(db: ContentDB, key: ContentId, value: openArray[byte]) = - db.put(key.toByteArrayBE(), value) + db.put(key.toBytesBE(), value) proc contains*(db: ContentDB, key: ContentId): bool = - db.contains(key.toByteArrayBE()) + db.contains(key.toBytesBE()) proc del*(db: ContentDB, key: ContentId) = - db.del(key.toByteArrayBE()) + db.del(key.toBytesBE()) proc getSszDecoded*(db: ContentDB, key: ContentId, T: type auto): Opt[T] = - db.getSszDecoded(key.toByteArrayBE(), T) + db.getSszDecoded(key.toBytesBE(), T) proc deleteContentFraction( db: ContentDB, @@ -264,7 +264,7 @@ proc deleteContentFraction( var ri: RowInfo var bytesDeleted: int64 = 0 - let targetBytes = target.toByteArrayBE() + let targetBytes = target.toBytesBE() for e in db.getAllOrderedByDistanceStmt.exec(targetBytes, ri): if bytesDeleted + ri.payloadLength < bytesToDelete: db.del(ri.contentId) diff --git a/fluffy/fluffy.nim b/fluffy/fluffy.nim index 58ddfa9df7..e79a970d33 100644 --- a/fluffy/fluffy.nim +++ b/fluffy/fluffy.nim @@ -160,7 +160,7 @@ proc run(config: PortalConf) {.raises: [CatchableError].} = # the selected `Radius`. let db = ContentDB.new(config.dataDir / "db" / "contentdb_" & - d.localNode.id.toByteArrayBE().toOpenArray(0, 8).toHex(), maxSize = config.storageSize) + d.localNode.id.toBytesBE().toOpenArray(0, 8).toHex(), maxSize = config.storageSize) portalConfig = PortalProtocolConfig.init( config.tableIpLimit, diff --git a/fluffy/network/beacon_light_client/beacon_light_client_db.nim b/fluffy/network/beacon_light_client/beacon_light_client_db.nim index 750249cee0..4273f2e140 100644 --- a/fluffy/network/beacon_light_client/beacon_light_client_db.nim +++ b/fluffy/network/beacon_light_client/beacon_light_client_db.nim @@ -122,10 +122,10 @@ proc put(db: LightClientDb, key, value: openArray[byte]) = proc get*(db: LightClientDb, key: ContentId): results.Opt[seq[byte]] = # TODO: Here it is unfortunate that ContentId is a uint256 instead of Digest256. - db.get(key.toByteArrayBE()) + db.get(key.toBytesBE()) proc put*(db: LightClientDb, key: ContentId, value: openArray[byte]) = - db.put(key.toByteArrayBE(), value) + db.put(key.toBytesBE(), value) proc createGetHandler*(db: LightClientDb): DbGetHandler = return ( diff --git a/fluffy/network/state/state_content.nim b/fluffy/network/state/state_content.nim index 175ada3ed0..b604aed4cb 100644 --- a/fluffy/network/state/state_content.nim +++ b/fluffy/network/state/state_content.nim @@ -11,7 +11,7 @@ {.push raises: [].} import - nimcrypto/[hash, sha2, keccak], stew/[objects, results], stint, + nimcrypto/[hash, sha2, keccak], stew/[objects, results, endians2], stint, ssz_serialization, ../../common/common_types diff --git a/fluffy/network/wire/messages.nim b/fluffy/network/wire/messages.nim index e49d3d20f4..0c786c43e3 100644 --- a/fluffy/network/wire/messages.nim +++ b/fluffy/network/wire/messages.nim @@ -11,7 +11,7 @@ {.push raises: [].} import - stint, stew/[results, objects], + stint, stew/[results, objects, endians2], ssz_serialization, ../../common/common_types diff --git a/fluffy/network/wire/portal_protocol.nim b/fluffy/network/wire/portal_protocol.nim index 3b14d8b522..9680f06202 100644 --- a/fluffy/network/wire/portal_protocol.nim +++ b/fluffy/network/wire/portal_protocol.nim @@ -12,7 +12,7 @@ import std/[sequtils, sets, algorithm], - stew/[results, byteutils, leb128], chronicles, chronos, nimcrypto/hash, + stew/[results, byteutils, leb128, endians2], chronicles, chronos, nimcrypto/hash, bearssl, ssz_serialization, metrics, faststreams, eth/rlp, eth/p2p/discoveryv5/[protocol, node, enr, routing_table, random2, nodes_verification, lru], diff --git a/fluffy/network/wire/portal_stream.nim b/fluffy/network/wire/portal_stream.nim index 102a0d4525..3de1b9a6dc 100644 --- a/fluffy/network/wire/portal_stream.nim +++ b/fluffy/network/wire/portal_stream.nim @@ -9,7 +9,7 @@ import std/sequtils, - chronos, stew/[byteutils, leb128], chronicles, + chronos, stew/[byteutils, leb128, endians2], chronicles, eth/utp/utp_discv5_protocol, # even though utp_discv5_protocol exports this, import is still needed, # perhaps protocol.Protocol type of usage? diff --git a/fluffy/seed_db.nim b/fluffy/seed_db.nim index 87f1ab87f7..1f4e56b88c 100644 --- a/fluffy/seed_db.nim +++ b/fluffy/seed_db.nim @@ -125,7 +125,7 @@ proc put*(db: SeedDb, contentId: array[32, byte], contentKey: seq[byte], content db.putStmt.exec((contentId, contentKey, content)).expectDb() proc put*(db: SeedDb, contentId: UInt256, contentKey: seq[byte], content: seq[byte]): void = - db.put(contentId.toByteArrayBE(), contentKey, content) + db.put(contentId.toBytesBE(), contentKey, content) proc get*(db: SeedDb, contentId: array[32, byte]): Option[ContentData] = var res = none[ContentData]() @@ -133,7 +133,7 @@ proc get*(db: SeedDb, contentId: array[32, byte]): Option[ContentData] = return res proc get*(db: SeedDb, contentId: UInt256): Option[ContentData] = - db.get(contentId.toByteArrayBE()) + db.get(contentId.toBytesBE()) proc getContentInRange*( db: SeedDb, @@ -147,7 +147,7 @@ proc getContentInRange*( var res: seq[ContentDataDist] = @[] var cd: ContentDataDist - for e in db.getInRangeStmt.exec((nodeId.toByteArrayBE(), nodeRadius.toByteArrayBE(), max, offset), cd): + for e in db.getInRangeStmt.exec((nodeId.toBytesBE(), nodeRadius.toBytesBE(), max, offset), cd): res.add(cd) return res diff --git a/fluffy/tools/utp_testing/utp_rpc_types.nim b/fluffy/tools/utp_testing/utp_rpc_types.nim index 2ca412332e..7d6fca25e9 100644 --- a/fluffy/tools/utp_testing/utp_rpc_types.nim +++ b/fluffy/tools/utp_testing/utp_rpc_types.nim @@ -10,7 +10,7 @@ import std/hashes, json_rpc/jsonmarshal, - stew/byteutils, + stew/[byteutils, endians2], eth/p2p/discoveryv5/node, eth/utp/[utp_discv5_protocol, utp_router] diff --git a/fluffy/tools/utp_testing/utp_test_app.nim b/fluffy/tools/utp_testing/utp_test_app.nim index fd204c04af..f619ec11bc 100644 --- a/fluffy/tools/utp_testing/utp_test_app.nim +++ b/fluffy/tools/utp_testing/utp_test_app.nim @@ -10,7 +10,7 @@ import std/[hashes, tables], chronos, chronicles, confutils, confutils/std/net as confNet, - stew/byteutils, + stew/[byteutils, endians2], stew/shims/net, json_rpc/servers/httpserver, eth/p2p/discoveryv5/protocol, diff --git a/nimbus/common/chain_config.nim b/nimbus/common/chain_config.nim index 878430b5dc..854d545006 100644 --- a/nimbus/common/chain_config.nim +++ b/nimbus/common/chain_config.nim @@ -83,7 +83,7 @@ const proc read(rlp: var Rlp, x: var AddressBalance, _: type EthAddress): EthAddress {.gcsafe, raises: [RlpError].} = - let val = rlp.read(UInt256).toByteArrayBE() + let val = rlp.read(UInt256).toBytesBE() result[0 .. ^1] = val.toOpenArray(12, val.high) proc read(rlp: var Rlp, x: var AddressBalance, _: type GenesisAccount): GenesisAccount diff --git a/nimbus/common/genesis.nim b/nimbus/common/genesis.nim index 7da265aace..cbc21dee8d 100644 --- a/nimbus/common/genesis.nim +++ b/nimbus/common/genesis.nim @@ -88,7 +88,7 @@ proc toGenesisHeader*( elif fork >= London: result.baseFee = EIP1559_INITIAL_BASE_FEE.u256 - if g.gasLimit.isZero: + if g.gasLimit == 0: result.gasLimit = GENESIS_GAS_LIMIT if g.difficulty.isZero and fork <= London: diff --git a/nimbus/common/hardforks.nim b/nimbus/common/hardforks.nim index 5f58c313a6..0344c21ef6 100644 --- a/nimbus/common/hardforks.nim +++ b/nimbus/common/hardforks.nim @@ -10,6 +10,7 @@ import std/[options, times], eth/common, + stew/endians2, json_serialization, ../utils/utils, ./evmforks @@ -258,7 +259,7 @@ proc populateFromForkTransitionTable*(conf: ChainConfig, t: ForkTransitionTable) conf.mergeForkBlock = t.mergeForkTransitionThreshold.blockNumber conf.terminalTotalDifficulty = t.mergeForkTransitionThreshold.ttd - + conf.shanghaiTime = t.timeThresholds[HardFork.Shanghai] conf.cancunTime = t.timeThresholds[HardFork.Cancun] diff --git a/nimbus/core/executor/executor_helpers.nim b/nimbus/core/executor/executor_helpers.nim index 711e63e3f0..7843dda582 100644 --- a/nimbus/core/executor/executor_helpers.nim +++ b/nimbus/core/executor/executor_helpers.nim @@ -44,7 +44,7 @@ func createBloom*(receipts: openArray[Receipt]): Bloom = var bloom: LogsBloom for rec in receipts: bloom.value = bloom.value or logsBloom(rec.logs).value - result = bloom.value.toByteArrayBE + result = bloom.value.toBytesBE proc makeReceipt*(vmState: BaseVMState; txType: TxType): Receipt = @@ -61,7 +61,7 @@ proc makeReceipt*(vmState: BaseVMState; txType: TxType): Receipt = rec.receiptType = txType rec.cumulativeGasUsed = vmState.cumulativeGasUsed rec.logs = vmState.getAndClearLogEntries() - rec.bloom = logsBloom(rec.logs).value.toByteArrayBE + rec.bloom = logsBloom(rec.logs).value.toBytesBE rec # ------------------------------------------------------------------------------ diff --git a/nimbus/core/pow.nim b/nimbus/core/pow.nim index b848c7bdb8..de2818fc48 100644 --- a/nimbus/core/pow.nim +++ b/nimbus/core/pow.nim @@ -17,6 +17,7 @@ import ../utils/utils, ./pow/[pow_cache, pow_dataset], eth/[common, keys, p2p, rlp], + stew/endians2, ethash, stint diff --git a/nimbus/db/accounts_cache.nim b/nimbus/db/accounts_cache.nim index cf3749a0b7..896ed08080 100644 --- a/nimbus/db/accounts_cache.nim +++ b/nimbus/db/accounts_cache.nim @@ -240,7 +240,7 @@ template createTrieKeyFromSlot(slot: UInt256): auto = # XXX: This is too expensive. Similar to `createRangeFromAddress` # Converts a number to hex big-endian representation including # prefix and leading zeros: - slot.toByteArrayBE + slot.toBytesBE # Original py-evm code: # pad32(int_to_big_endian(slot)) # morally equivalent to toByteRange_Unnecessary but with different types diff --git a/nimbus/db/aristo/aristo_desc/aristo_types_identifiers.nim b/nimbus/db/aristo/aristo_desc/aristo_types_identifiers.nim index 9c5f178afe..c8caa73217 100644 --- a/nimbus/db/aristo/aristo_desc/aristo_types_identifiers.nim +++ b/nimbus/db/aristo/aristo_desc/aristo_types_identifiers.nim @@ -107,7 +107,7 @@ func cmp*(x, y: HashID): int = cmp(x.UInt256, y.UInt256) func to*(hid: HashID; T: type Hash256): T = result.data = hid.UInt256.toBytesBE -func to*(hid: HashID; T: type HashKey): T = +proc to*(hid: HashID; T: type HashKey): T = hid.UInt256.toBytesBE.T func to*(key: HashKey; T: type HashID): T = diff --git a/nimbus/db/aristo/aristo_init/aristo_rocksdb.nim b/nimbus/db/aristo/aristo_init/aristo_rocksdb.nim index 8a12a1b7fc..cfb7399098 100644 --- a/nimbus/db/aristo/aristo_init/aristo_rocksdb.nim +++ b/nimbus/db/aristo/aristo_init/aristo_rocksdb.nim @@ -172,7 +172,7 @@ proc putKeyFn(db: RdbBackendRef): PutKeyFn = hdl.cache[KeyPfx][vid] = key.to(Blob) else: hdl.cache[KeyPfx][vid] = EmptyBlob - + proc putIdgFn(db: RdbBackendRef): PutIdgFn = result = diff --git a/nimbus/db/aristo/aristo_init/aristo_rocksdb/rdb_desc.nim b/nimbus/db/aristo/aristo_init/aristo_rocksdb/rdb_desc.nim index d9b3d40da7..223abef6ae 100644 --- a/nimbus/db/aristo/aristo_init/aristo_rocksdb/rdb_desc.nim +++ b/nimbus/db/aristo/aristo_init/aristo_rocksdb/rdb_desc.nim @@ -18,6 +18,7 @@ import eth/common, rocksdb, stint, + stew/endians2, ../../aristo_desc, ../aristo_init_common.nim diff --git a/nimbus/db/aristo/aristo_init/aristo_rocksdb/rdb_walk.nim b/nimbus/db/aristo/aristo_init/aristo_rocksdb/rdb_walk.nim index e776a41305..13b07d91b0 100644 --- a/nimbus/db/aristo/aristo_init/aristo_rocksdb/rdb_walk.nim +++ b/nimbus/db/aristo/aristo_init/aristo_rocksdb/rdb_walk.nim @@ -16,6 +16,7 @@ import std/sequtils, eth/common, + stew/endians2, rocksdb, ../../aristo_desc, ../aristo_init_common, diff --git a/nimbus/db/aristo/aristo_transcode.nim b/nimbus/db/aristo/aristo_transcode.nim index 1b37eb4644..d987a8105f 100644 --- a/nimbus/db/aristo/aristo_transcode.nim +++ b/nimbus/db/aristo/aristo_transcode.nim @@ -13,7 +13,7 @@ import std/[bitops, sequtils], eth/[common, trie/nibbles], - stew/results, + stew/[results, endians2], "."/[aristo_constants, aristo_desc] # ------------------------------------------------------------------------------ diff --git a/nimbus/db/distinct_tries.nim b/nimbus/db/distinct_tries.nim index aec32ba5f8..f0f6787203 100644 --- a/nimbus/db/distinct_tries.nim +++ b/nimbus/db/distinct_tries.nim @@ -56,7 +56,7 @@ template createTrieKeyFromSlot*(slot: UInt256): auto = # XXX: This is too expensive. Similar to `createRangeFromAddress` # Converts a number to hex big-endian representation including # prefix and leading zeros: - slot.toByteArrayBE + slot.toBytesBE # Original py-evm code: # pad32(int_to_big_endian(slot)) # morally equivalent to toByteRange_Unnecessary but with different types diff --git a/nimbus/db/state_db.nim b/nimbus/db/state_db.nim index 4596c8dc10..47347d16c0 100644 --- a/nimbus/db/state_db.nim +++ b/nimbus/db/state_db.nim @@ -120,7 +120,7 @@ proc subBalance*(db: AccountStateDB, address: EthAddress, delta: UInt256) = template createTrieKeyFromSlot(slot: UInt256): auto = # Converts a number to hex big-endian representation including # prefix and leading zeros: - slot.toByteArrayBE + slot.toBytesBE # Original py-evm code: # pad32(int_to_big_endian(slot)) # morally equivalent to toByteRange_Unnecessary but with different types @@ -157,7 +157,7 @@ proc setStorage*(db: AccountStateDB, var triedb = trieDB(db) # slotHash can be obtained from accountTrie.put? - slotHash = keccakHash(slot.toByteArrayBE) + slotHash = keccakHash(slot.toBytesBE) triedb.put(slotHashToSlotKey(slotHash.data).toOpenArray, rlp.encode(slot)) account.storageRoot = accountTrie.rootHash diff --git a/nimbus/evm/computation.nim b/nimbus/evm/computation.nim index 46ffd7abe9..66c1c3a7bb 100644 --- a/nimbus/evm/computation.nim +++ b/nimbus/evm/computation.nim @@ -35,13 +35,13 @@ when defined(evmc_enabled): evmc/evmc, evmc_helpers, evmc_api, - stew/ranges/ptr_arith + stew/ptrops export evmc, evmc_helpers, evmc_api, - ptr_arith + ptrops const evmc_enabled* = defined(evmc_enabled) diff --git a/nimbus/evm/evmc_helpers.nim b/nimbus/evm/evmc_helpers.nim index 4a5349eff8..b329267fc6 100644 --- a/nimbus/evm/evmc_helpers.nim +++ b/nimbus/evm/evmc_helpers.nim @@ -18,7 +18,7 @@ func toEvmc*(n: UInt256): evmc_uint256be {.inline.} = when evmc_native: cast[evmc_uint256be](n) else: - cast[evmc_uint256be](n.toByteArrayBE) + cast[evmc_uint256be](n.toBytesBE) func fromEvmc*(T: type, n: evmc_bytes32): T {.inline.} = when T is Hash256 | ContractSalt: diff --git a/nimbus/evm/interpreter/op_handlers/oph_arithmetic.nim b/nimbus/evm/interpreter/op_handlers/oph_arithmetic.nim index b0b723493d..a88cae7585 100644 --- a/nimbus/evm/interpreter/op_handlers/oph_arithmetic.nim +++ b/nimbus/evm/interpreter/op_handlers/oph_arithmetic.nim @@ -25,6 +25,12 @@ import ./oph_defs, eth/common +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 + {.push raises: [CatchableError].} # basically the annotation type of a `Vm2OpFn` # ------------------------------------------------------------------------------ @@ -185,16 +191,17 @@ const ## 0x12, Signed less-than comparison let (lhs, rhs) = k.cpt.stack.popInt(2) k.cpt.stack.push: - (cast[Int256](lhs) < cast[Int256](rhs)).uint.u256 + slt(lhs, rhs).uint.u256 sgtOp: Vm2OpFn = proc(k: var Vm2Ctx) = - ## 0x14, Signed greater-than comparison + ## 0x13, Signed greater-than comparison let (lhs, rhs) = k.cpt.stack.popInt(2) k.cpt.stack.push: - (cast[Int256](lhs) > cast[Int256](rhs)).uint.u256 + # Arguments are swapped and SLT is used. + slt(rhs, lhs).uint.u256 eqOp: Vm2OpFn = proc(k: var Vm2Ctx) = - ## 0x14, Signed greater-than comparison + ## 0x14, Equality comparison let (lhs, rhs) = k.cpt.stack.popInt(2) k.cpt.stack.push: (lhs == rhs).uint.u256 @@ -231,7 +238,7 @@ const byteOp: Vm2OpFn = proc(k: var Vm2Ctx) = ## 0x20, Retrieve single byte from word. - let (position, value) = k.cpt.stack.popInt(2) + let (position, value) = k.cpt.stack.popInt(2) k.cpt.stack.push: if position >= 32.u256: zero(UInt256) @@ -273,7 +280,7 @@ const k.cpt.stack.push: cast[UInt256]((-1).i256) else: - k.cpt.stack. push: + k.cpt.stack. push: 0 else: # int version of `shr` then force the result diff --git a/nimbus/evm/interpreter/op_handlers/oph_memory.nim b/nimbus/evm/interpreter/op_handlers/oph_memory.nim index d3d0d06658..517ac85b56 100644 --- a/nimbus/evm/interpreter/op_handlers/oph_memory.nim +++ b/nimbus/evm/interpreter/op_handlers/oph_memory.nim @@ -147,7 +147,7 @@ const reason = "MSTORE: GasVeryLow + memory expansion") k.cpt.memory.extend(memPos, 32) - k.cpt.memory.write(memPos, value.toByteArrayBE) + k.cpt.memory.write(memPos, value.toBytesBE) mstore8Op: Vm2OpFn = proc (k: var Vm2Ctx) = @@ -160,7 +160,7 @@ const reason = "MSTORE8: GasVeryLow + memory expansion") k.cpt.memory.extend(memPos, 1) - k.cpt.memory.write(memPos, [value.toByteArrayBE[31]]) + k.cpt.memory.write(memPos, [value.toBytesBE[31]]) # ------- diff --git a/nimbus/evm/interpreter/utils/utils_numeric.nim b/nimbus/evm/interpreter/utils/utils_numeric.nim index 3e46586af9..a24c38c9a9 100644 --- a/nimbus/evm/interpreter/utils/utils_numeric.nim +++ b/nimbus/evm/interpreter/utils/utils_numeric.nim @@ -74,8 +74,7 @@ proc rangeToPadded*[T: StUint](x: openArray[byte], first, last, size: int): T = var temp: array[N, byte] temp[0..hi-lo] = x.toOpenArray(lo, hi) result = T.fromBytesBE( - temp.toOpenArray(0, size-1), - allowPadding = true + temp.toOpenArray(0, size-1) ) proc rangeToPadded*(x: openArray[byte], first, size: int): seq[byte] = @@ -90,7 +89,7 @@ proc rangeToPadded*(x: openArray[byte], first, size: int): seq[byte] = # calculates the memory size required for a step func calcMemSize*(offset, length: int): int {.inline.} = - if length.isZero: return 0 + if length == 0: return 0 result = offset + length func safeInt*(x: UInt256): int {.inline.} = diff --git a/nimbus/evm/interpreter_dispatch.nim b/nimbus/evm/interpreter_dispatch.nim index 47cbc149fa..4e069fb64b 100644 --- a/nimbus/evm/interpreter_dispatch.nim +++ b/nimbus/evm/interpreter_dispatch.nim @@ -16,7 +16,7 @@ const import std/[macros, strformat], pkg/[chronicles, chronos, stew/byteutils], - ".."/[constants, utils/utils, db/accounts_cache], + ".."/[constants, db/accounts_cache], "."/[code_stream, computation], "."/[message, precompiles, state, types], ./async/operations, @@ -306,7 +306,7 @@ proc asyncExecCallOrCreate*(c: Computation): Future[void] {.async.} = defer: c.dispose() await ifNecessaryGetCode(c.vmState, c.msg.contractAddress) - + if c.beforeExec(): return c.executeOpcodes() diff --git a/nimbus/evm/memory.nim b/nimbus/evm/memory.nim index bbe0100746..8596855af6 100644 --- a/nimbus/evm/memory.nim +++ b/nimbus/evm/memory.nim @@ -6,7 +6,7 @@ # at your option. This file may not be copied, modified, or distributed except according to those terms. import - chronicles, eth/common/eth_types, + chronicles, ./validation, ./interpreter/utils/utils_numeric diff --git a/nimbus/evm/stack.nim b/nimbus/evm/stack.nim index 08e8de5950..4981fdf496 100644 --- a/nimbus/evm/stack.nim +++ b/nimbus/evm/stack.nim @@ -29,12 +29,12 @@ proc len*(stack: Stack): int {.inline.} = proc toStackElement(v: UInt256, elem: var StackElement) {.inline.} = elem = v proc toStackElement(v: uint | int | GasInt, elem: var StackElement) {.inline.} = elem = v.u256 proc toStackElement(v: EthAddress, elem: var StackElement) {.inline.} = elem.initFromBytesBE(v) -proc toStackElement(v: MDigest, elem: var StackElement) {.inline.} = elem.initFromBytesBE(v.data, allowPadding = false) +proc toStackElement(v: MDigest, elem: var StackElement) {.inline.} = elem.initFromBytesBE(v.data) proc fromStackElement(elem: StackElement, v: var UInt256) {.inline.} = v = elem -proc fromStackElement(elem: StackElement, v: var EthAddress) {.inline.} = v[0 .. ^1] = elem.toByteArrayBE().toOpenArray(12, 31) -proc fromStackElement(elem: StackElement, v: var Hash256) {.inline.} = v.data = elem.toByteArrayBE() -proc fromStackElement(elem: StackElement, v: var Topic) {.inline.} = v = elem.toByteArrayBE() +proc fromStackElement(elem: StackElement, v: var EthAddress) {.inline.} = v[0 .. ^1] = elem.toBytesBE().toOpenArray(12, 31) +proc fromStackElement(elem: StackElement, v: var Hash256) {.inline.} = v.data = elem.toBytesBE() +proc fromStackElement(elem: StackElement, v: var Topic) {.inline.} = v = elem.toBytesBE() proc toStackElement(v: openArray[byte], elem: var StackElement) {.inline.} = # TODO: This needs to go diff --git a/nimbus/evm/state.nim b/nimbus/evm/state.nim index aab009539f..c16f0eea06 100644 --- a/nimbus/evm/state.nim +++ b/nimbus/evm/state.nim @@ -304,7 +304,7 @@ method blockNumber*(vmState: BaseVMState): BlockNumber {.base, gcsafe.} = method difficulty*(vmState: BaseVMState): UInt256 {.base, gcsafe.} = if vmState.com.consensus == ConsensusType.POS: # EIP-4399/EIP-3675 - UInt256.fromBytesBE(vmState.prevRandao.data, allowPadding = false) + UInt256.fromBytesBE(vmState.prevRandao.data) else: vmState.blockDifficulty diff --git a/nimbus/evm/transaction_tracer.nim b/nimbus/evm/transaction_tracer.nim index ce573a1db6..14a01b4936 100644 --- a/nimbus/evm/transaction_tracer.nim +++ b/nimbus/evm/transaction_tracer.nim @@ -19,7 +19,7 @@ logScope: topics = "vm opcode" proc hash*(x: UInt256): Hash = - result = hash(x.toByteArrayBE) + result = hash(x.toBytesBE) proc initTracer*(tracer: var TransactionTracer, flags: set[TracerFlags] = {}) = tracer.trace = newJObject() diff --git a/nimbus/rpc/hexstrings.nim b/nimbus/rpc/hexstrings.nim index d173fb286f..038303ad0a 100644 --- a/nimbus/rpc/hexstrings.nim +++ b/nimbus/rpc/hexstrings.nim @@ -28,7 +28,8 @@ import std/strutils, - stint, stew/byteutils, eth/keys, + stint, stew/[byteutils], + eth/keys, eth/common/eth_types, json_serialization diff --git a/nimbus/rpc/merge/mergeutils.nim b/nimbus/rpc/merge/mergeutils.nim index c5113dbb25..4d108a7184 100644 --- a/nimbus/rpc/merge/mergeutils.nim +++ b/nimbus/rpc/merge/mergeutils.nim @@ -13,7 +13,7 @@ import web3/engine_api_types, json_rpc/errors, eth/[trie, rlp, common, common/eth_types, trie/db], - stew/[results, byteutils], + stew/[results, byteutils, endians2], ../../constants, ./mergetypes diff --git a/nimbus/sync/handlers/eth.nim b/nimbus/sync/handlers/eth.nim index 9217c0b313..14b6de2646 100644 --- a/nimbus/sync/handlers/eth.nim +++ b/nimbus/sync/handlers/eth.nim @@ -13,6 +13,7 @@ import std/[tables, times, hashes, sets], chronicles, chronos, + stew/endians2, eth/p2p, eth/p2p/peer_pool, ".."/[types, protocol], diff --git a/nimbus/sync/snap/worker/db/hexary_desc.nim b/nimbus/sync/snap/worker/db/hexary_desc.nim index 931dfda996..0bb2fe9ed1 100644 --- a/nimbus/sync/snap/worker/db/hexary_desc.nim +++ b/nimbus/sync/snap/worker/db/hexary_desc.nim @@ -13,6 +13,7 @@ import std/[hashes, sets, tables], eth/[common, trie/nibbles], + stew/endians2, stint, "../.."/[constants, range_desc], ./hexary_error diff --git a/nimbus/transaction.nim b/nimbus/transaction.nim index 92e3e70265..a1c71ddfb1 100644 --- a/nimbus/transaction.nim +++ b/nimbus/transaction.nim @@ -50,8 +50,8 @@ proc intrinsicGas*(tx: Transaction, fork: EVMFork): GasInt = proc getSignature*(tx: Transaction, output: var Signature): bool = var bytes: array[65, byte] - bytes[0..31] = tx.R.toByteArrayBE() - bytes[32..63] = tx.S.toByteArrayBE() + bytes[0..31] = tx.R.toBytesBE() + bytes[32..63] = tx.S.toBytesBE() if tx.txType == TxLegacy: var v = tx.V diff --git a/nimbus/transaction/evmc_vm_glue.nim b/nimbus/transaction/evmc_vm_glue.nim index c8fab8f359..d4dd2e0ebe 100644 --- a/nimbus/transaction/evmc_vm_glue.nim +++ b/nimbus/transaction/evmc_vm_glue.nim @@ -9,7 +9,7 @@ {.push raises: [].} import - ./host_types, evmc/evmc, stew/ranges/ptr_arith, + ./host_types, evmc/evmc, ".."/[vm_types, vm_computation, vm_state_transactions] proc evmcReleaseResult(result: var evmc_result) {.cdecl.} = @@ -71,7 +71,7 @@ proc evmcExecute(vm: ptr evmc_vm, hostInterface: ptr evmc_host_interface, # Nim defaults are fine for `create_address` and `padding`, zero bytes. ) -const evmcName = "Nimbus EVM (vm2)" +const evmcName = "Nimbus EVM" const evmcVersion = "0.0.1" proc evmcGetCapabilities(vm: ptr evmc_vm): evmc_capabilities {.cdecl.} = diff --git a/nimbus/transaction/host_call_nested.nim b/nimbus/transaction/host_call_nested.nim index 9971725045..a40dbc2bd7 100644 --- a/nimbus/transaction/host_call_nested.nim +++ b/nimbus/transaction/host_call_nested.nim @@ -10,7 +10,7 @@ import eth/common/eth_types, - stew/ranges/ptr_arith, + stew/ptrops, stint, ".."/[vm_types, vm_computation], ../utils/utils, diff --git a/nimbus/transaction/host_services.nim b/nimbus/transaction/host_services.nim index 468787909d..400a52f021 100644 --- a/nimbus/transaction/host_services.nim +++ b/nimbus/transaction/host_services.nim @@ -9,7 +9,7 @@ #{.push raises: [].} import - sets, times, stint, chronicles, + times, stint, chronicles, eth/common/eth_types, ../db/accounts_cache, ../common/[evmforks, common], ".."/[vm_state, vm_computation, vm_internals, vm_gas_costs], diff --git a/nimbus/transaction/host_trace.nim b/nimbus/transaction/host_trace.nim index 576a1d496c..b9a0756c4c 100644 --- a/nimbus/transaction/host_trace.nim +++ b/nimbus/transaction/host_trace.nim @@ -10,7 +10,7 @@ import macros, strformat, strutils, stint, chronicles, - stew/byteutils, stew/ranges/ptr_arith, + stew/byteutils, stew/ptrops, ./host_types # Set `true` or `false` to control host call tracing. diff --git a/nimbus/transaction/host_types.nim b/nimbus/transaction/host_types.nim index 83723b3ac6..83dfe4c3a4 100644 --- a/nimbus/transaction/host_types.nim +++ b/nimbus/transaction/host_types.nim @@ -83,7 +83,7 @@ template fromEvmc*(address: evmc_address): EthAddress = cast[EthAddress](address) template flip256*(word256: evmc_uint256be): evmc_uint256be = - cast[evmc_uint256be](UInt256.fromBytesBe(word256.bytes).toBytes) + cast[evmc_uint256be](UInt256.fromBytesBE(word256.bytes).toBytes(cpuEndian)) template isCreate*(kind: EvmcCallKind): bool = kind in {EVMC_CREATE, EVMC_CREATE2} diff --git a/nimbus/utils/ec_recover.nim b/nimbus/utils/ec_recover.nim index 12abe2d88a..6d035269a8 100644 --- a/nimbus/utils/ec_recover.nim +++ b/nimbus/utils/ec_recover.nim @@ -54,8 +54,8 @@ type proc vrsSerialised(tx: Transaction): Result[array[65,byte],UtilsError] = ## Parts copied from `transaction.getSignature`. var data: array[65,byte] - data[0..31] = tx.R.toByteArrayBE - data[32..63] = tx.S.toByteArrayBE + data[0..31] = tx.R.toBytesBE + data[32..63] = tx.S.toBytesBE if tx.txType != TxLegacy: data[64] = tx.V.byte diff --git a/premix/hunter.nim b/premix/hunter.nim index 36c6806e2b..65fb3431f4 100644 --- a/premix/hunter.nim +++ b/premix/hunter.nim @@ -65,7 +65,7 @@ type headers: Table[BlockNumber, BlockHeader] proc hash*(x: UInt256): Hash = - result = hash(x.toByteArrayBE) + result = hash(x.toBytesBE) proc new(T: type HunterVMState; parent, header: BlockHeader, com: CommonRef): T = new result diff --git a/tests/test_aristo/test_delete.nim b/tests/test_aristo/test_delete.nim index 9410959a8b..2b28fd4f50 100644 --- a/tests/test_aristo/test_delete.nim +++ b/tests/test_aristo/test_delete.nim @@ -14,7 +14,7 @@ import std/[algorithm, bitops, sequtils], eth/common, - stew/results, + stew/[results, endians2], unittest2, ../../nimbus/db/aristo/[ aristo_desc, aristo_debug, aristo_delete, aristo_hashify, aristo_init, diff --git a/tests/test_aristo/test_transcode.nim b/tests/test_aristo/test_transcode.nim index 569ea842af..56e19883b1 100644 --- a/tests/test_aristo/test_transcode.nim +++ b/tests/test_aristo/test_transcode.nim @@ -14,7 +14,7 @@ import std/sequtils, eth/common, - stew/byteutils, + stew/[byteutils, endians2], unittest2, ../../nimbus/db/kvstore_rocksdb, ../../nimbus/db/aristo/[ diff --git a/tests/test_pow.nim b/tests/test_pow.nim index 31d720c91b..4aa8e76b60 100644 --- a/tests/test_pow.nim +++ b/tests/test_pow.nim @@ -13,6 +13,7 @@ import ./replay/[pp, gunzip], ../nimbus/core/[pow, pow/pow_cache, pow/pow_dataset], eth/[common], + stew/endians2, unittest2 const diff --git a/vendor/nim-stint b/vendor/nim-stint index 94fc521ee0..7fc30a8f1c 160000 --- a/vendor/nim-stint +++ b/vendor/nim-stint @@ -1 +1 @@ -Subproject commit 94fc521ee0f1e113d09ceeaa3568d4d7a6c0b67d +Subproject commit 7fc30a8f1cf6c8f4fe1dec1c3de01b150747a8c8 diff --git a/vendor/nimbus-eth2 b/vendor/nimbus-eth2 index 22208836b1..7a476dd4cd 160000 --- a/vendor/nimbus-eth2 +++ b/vendor/nimbus-eth2 @@ -1 +1 @@ -Subproject commit 22208836b18aaafaafd7c6308ea15b08ff64e323 +Subproject commit 7a476dd4cd1d150c70380112015c8aa3ddf463a0