From 0b276315d27c63a10c1fe4bd9723d1b19a3d508b Mon Sep 17 00:00:00 2001 From: andri lim Date: Sun, 7 Jul 2024 03:25:31 +0700 Subject: [PATCH] Bump nim-eth: Convert GasInt to uint64 (#6415) * Bump nim-eth: Convert GasInt to uint64 * Fixes * Fix libnimbus_lc --- beacon_chain/libnimbus_lc/libnimbus_lc.nim | 29 ++++++---------------- beacon_chain/spec/helpers.nim | 6 ++--- tests/testblockutil.nim | 6 ++--- vendor/nim-eth | 2 +- 4 files changed, 14 insertions(+), 29 deletions(-) diff --git a/beacon_chain/libnimbus_lc/libnimbus_lc.nim b/beacon_chain/libnimbus_lc/libnimbus_lc.nim index 1e4fbc5fa..71d266d04 100644 --- a/beacon_chain/libnimbus_lc/libnimbus_lc.nim +++ b/beacon_chain/libnimbus_lc/libnimbus_lc.nim @@ -9,7 +9,6 @@ import std/[json, sequtils, times], - stew/saturation_arith, eth/common/[eth_types_rlp, transaction], eth/keys, eth/p2p/discoveryv5/random2, @@ -1242,10 +1241,8 @@ proc ETHExecutionBlockHeaderCreateFromJson( # Construct block header static: # `GasInt` is signed. We only use it for hashing. - doAssert sizeof(int64) == sizeof(data.gasLimit) - doAssert sizeof(int64) == sizeof(data.gasUsed) - if distinctBase(data.timestamp) > int64.high.uint64: - return nil + doAssert sizeof(uint64) == sizeof(data.gasLimit) + doAssert sizeof(uint64) == sizeof(data.gasUsed) if data.nonce.isNone: return nil let blockHeader = ExecutionBlockHeader( @@ -1258,8 +1255,8 @@ proc ETHExecutionBlockHeaderCreateFromJson( logsBloom: distinctBase(data.logsBloom), difficulty: data.difficulty, number: distinctBase(data.number), - gasLimit: GasInt.saturate distinctBase(data.gasLimit), - gasUsed: GasInt.saturate distinctBase(data.gasUsed), + gasLimit: distinctBase(data.gasLimit), + gasUsed: distinctBase(data.gasUsed), timestamp: EthTime(distinctBase(data.timestamp)), extraData: distinctBase(data.extraData), mixHash: data.mixHash.asEth2Digest, @@ -1497,25 +1494,15 @@ proc ETHTransactionsCreateFromJson( # Construct transaction static: doAssert sizeof(uint64) == sizeof(ChainId) - doAssert sizeof(int64) == sizeof(data.gasPrice) - doAssert sizeof(int64) == sizeof(data.maxPriorityFeePerGas.get) + doAssert sizeof(uint64) == sizeof(data.gas) + doAssert sizeof(uint64) == sizeof(data.gasPrice) + doAssert sizeof(uint64) == sizeof(data.maxPriorityFeePerGas.get) doAssert sizeof(UInt256) == sizeof(data.maxFeePerBlobGas.get) if distinctBase(data.chainId.get(0.Quantity)) > distinctBase(ChainId.high): return nil - if distinctBase(data.gasPrice) > int64.high.uint64: - return nil - if distinctBase(data.maxFeePerGas.get(0.Quantity)) > int64.high.uint64: - return nil - if distinctBase(data.maxPriorityFeePerGas.get(0.Quantity)) > - int64.high.uint64: - return nil if data.maxFeePerBlobGas.get(0.u256) > uint64.high.u256: return nil - if distinctBase(data.gas) > int64.high.uint64: - return nil - if distinctBase(data.v) > int64.high.uint64: - return nil if data.yParity.isSome: # This is not always included, but if it is, make sure it's correct let yParity = data.yParity.get @@ -1555,7 +1542,7 @@ proc ETHTransactionsCreateFromJson( ExecutionHash256(data: distinctBase(it))) else: @[], - V: data.v.uint64, + V: distinctBase(data.v), R: data.r, S: data.s) rlpBytes = diff --git a/beacon_chain/spec/helpers.nim b/beacon_chain/spec/helpers.nim index db86ab3f2..63d54a9d6 100644 --- a/beacon_chain/spec/helpers.nim +++ b/beacon_chain/spec/helpers.nim @@ -11,7 +11,7 @@ import # Status libraries - stew/[byteutils, endians2, objects, saturation_arith], + stew/[byteutils, endians2, objects], chronicles, eth/common/[eth_types, eth_types_rlp], eth/rlp, eth/trie/[db, hexary], @@ -590,8 +590,8 @@ proc blockToBlockHeader*(blck: ForkyBeaconBlock): ExecutionBlockHeader = logsBloom : payload.logs_bloom.data, difficulty : default(DifficultyInt), number : payload.block_number, - gasLimit : GasInt.saturate(payload.gas_limit), - gasUsed : GasInt.saturate(payload.gas_used), + gasLimit : payload.gas_limit, + gasUsed : payload.gas_used, timestamp : EthTime(payload.timestamp), extraData : payload.extra_data.asSeq, mixHash : payload.prev_randao, # EIP-4399 `mixHash` -> `prevRandao` diff --git a/tests/testblockutil.nim b/tests/testblockutil.nim index 3b5fc267a..c541a3396 100644 --- a/tests/testblockutil.nim +++ b/tests/testblockutil.nim @@ -118,8 +118,6 @@ proc build_empty_merge_execution_payload(state: bellatrix.BeaconState): bellatrix.ExecutionPayloadForSigning(executionPayload: payload, blockValue: Wei.zero) -from stew/saturating_arith import saturate - proc build_empty_execution_payload( state: bellatrix.BeaconState, feeRecipient: Eth1Address): bellatrix.ExecutionPayloadForSigning = @@ -129,8 +127,8 @@ proc build_empty_execution_payload( latest = state.latest_execution_payload_header timestamp = compute_timestamp_at_slot(state, state.slot) randao_mix = get_randao_mix(state, get_current_epoch(state)) - base_fee = calcEip1599BaseFee(GasInt.saturate latest.gas_limit, - GasInt.saturate latest.gas_used, + base_fee = calcEip1599BaseFee(latest.gas_limit, + latest.gas_used, latest.base_fee_per_gas) var payload = bellatrix.ExecutionPayloadForSigning( diff --git a/vendor/nim-eth b/vendor/nim-eth index d8fda55c7..ebfe63b9b 160000 --- a/vendor/nim-eth +++ b/vendor/nim-eth @@ -1 +1 @@ -Subproject commit d8fda55c79dd48ba564f3cb540b968f4a1c1aae6 +Subproject commit ebfe63b9b6523a1823e4505f0972d81047a77cf5