From 774807fab8aeb73e4afb30a6c74fe2d334bd3c3f Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Mon, 30 Sep 2024 20:30:58 +0200 Subject: [PATCH 1/3] Change `VersionedHash` to `Hash32` This is closer to both the exeuction spec and api --- eth/common/hashes.nim | 5 +++++ eth/common/transactions.nim | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/eth/common/hashes.nim b/eth/common/hashes.nim index 3013aeea..0575ab68 100644 --- a/eth/common/hashes.nim +++ b/eth/common/hashes.nim @@ -24,6 +24,11 @@ type Root* = Hash32 ## Alias used for MPT roots + VersionedHash* = Hash32 + ## Alias used for blob hashes whose first byte indicates what the payload + ## actually is - primarily used with KZG commitments at the time of writing + ## https://github.com/ethereum/execution-specs/blob/9b95554a88d2a8485f8180254d0f6a493a593fda/src/ethereum/crypto/kzg.py#L74C1-L74C38 + const zeroHash32* = system.default(Hash32) ## Hash32 value consisting of all zeroes template to*(v: array[32, byte], _: type Hash32): Hash32 = diff --git a/eth/common/transactions.nim b/eth/common/transactions.nim index 751f0d7e..9285d6e4 100644 --- a/eth/common/transactions.nim +++ b/eth/common/transactions.nim @@ -18,8 +18,6 @@ type AccessList* = seq[AccessPair] - VersionedHash* = Bytes32 - Authorization* = object chainId*: ChainId address*: Address From 6d0c46f98afd023b4549151a5f0913b060d90e75 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Mon, 30 Sep 2024 20:54:43 +0200 Subject: [PATCH 2/3] missing imports --- eth/common/transactions.nim | 4 ++-- eth/common/transactions_rlp.nim | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/eth/common/transactions.nim b/eth/common/transactions.nim index 9285d6e4..e6b35dde 100644 --- a/eth/common/transactions.nim +++ b/eth/common/transactions.nim @@ -7,9 +7,9 @@ {.push raises: [].} -import "."/addresses, base +import "."/[addresses, base, hashes] -export addresses, base +export addresses, base, hashes type AccessPair* = object diff --git a/eth/common/transactions_rlp.nim b/eth/common/transactions_rlp.nim index 69d8f249..e130643a 100644 --- a/eth/common/transactions_rlp.nim +++ b/eth/common/transactions_rlp.nim @@ -7,11 +7,11 @@ {.push raises: [].} -import "."/[addresses_rlp, base_rlp, transactions], ../rlp +import "."/[addresses_rlp, base_rlp, hashes_rlp, transactions], ../rlp from stew/objects import checkedEnumAssign -export addresses_rlp, base_rlp, transactions, rlp +export addresses_rlp, base_rlp, hashes_rlp, transactions, rlp proc appendTxLegacy(w: var RlpWriter, tx: Transaction) = w.startList(9) From bfd1c956b259fd5f5cab1ba481ed7ac6d3feb437 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Tue, 1 Oct 2024 10:04:33 +0200 Subject: [PATCH 3/3] tests, header cleanups --- eth/common/eth_types.nim | 5 +++-- eth/common/eth_types_json_serialization.nim | 5 ++++- eth/common/headers.nim | 2 -- tests/common/test_eip4844.nim | 8 ++++---- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/eth/common/eth_types.nim b/eth/common/eth_types.nim index ab79b403..3d00c813 100644 --- a/eth/common/eth_types.nim +++ b/eth/common/eth_types.nim @@ -70,11 +70,12 @@ export eth_hash type # Names that don't appear in the spec and have no particular purpose any more - # just use the underlying type directly + Blob* {.deprecated.} = seq[byte] + BlockHeader*{.deprecated: "Header".} = Header + BlockNonce* {.deprecated.} = Bytes8 BloomFilter* {.deprecated.} = Bloom StorageKey* {.deprecated.} = Bytes32 - Blob* {.deprecated.} = seq[byte] VersionedHashes* {.deprecated.} = seq[VersionedHash] - BlockNonce* {.deprecated.} = Bytes8 func toBlockNonce*(n: uint64): BlockNonce {.deprecated.} = n.to(BlockNonce) diff --git a/eth/common/eth_types_json_serialization.nim b/eth/common/eth_types_json_serialization.nim index 32d09929..974ba07c 100644 --- a/eth/common/eth_types_json_serialization.nim +++ b/eth/common/eth_types_json_serialization.nim @@ -8,7 +8,10 @@ import std/typetraits, json_serialization, ./eth_types -export json_serialization, eth_types +export json_serialization + +export eth_types + except BlockHeader, BlockNumber, BlockNonce, BloomFilter, Hash256, StorageKey # This module contains "convenience formatting" for logging `eth_types` - this # formatting does not conform to any particular Ethereum-based standard - in diff --git a/eth/common/headers.nim b/eth/common/headers.nim index 65e69cbf..b0d08ce4 100644 --- a/eth/common/headers.nim +++ b/eth/common/headers.nim @@ -38,8 +38,6 @@ type parentBeaconBlockRoot*: Opt[Hash32] # EIP-4788 requestsRoot*: Opt[Hash32] # EIP-7685 - BlockHeader*{.deprecated: "Header".} = Header - # starting from EIP-4399, `mixDigest` field is called `prevRandao` template prevRandao*(h: Header): Hash32 = h.mixHash diff --git a/tests/common/test_eip4844.nim b/tests/common/test_eip4844.nim index 3097a042..57335289 100644 --- a/tests/common/test_eip4844.nim +++ b/tests/common/test_eip4844.nim @@ -14,7 +14,7 @@ import unittest2, ../../eth/common, ../../eth/rlp, - ../../eth/common/transaction + ../../eth/common/transactions_rlp const recipient = address"095e7baea6a6c7c4c2dfeb977efac326af552d87" @@ -94,7 +94,7 @@ proc tx5(i: int): PooledTransaction = proc tx6(i: int): PooledTransaction = const - digest = bytes32"010657f37554c781402a22917dee2f75def7ab966d7b770905398eba3c444014" + digest = hash32"010657f37554c781402a22917dee2f75def7ab966d7b770905398eba3c444014" PooledTransaction( tx: Transaction( @@ -113,7 +113,7 @@ proc tx6(i: int): PooledTransaction = proc tx7(i: int): PooledTransaction = const - digest = bytes32"01624652859a6e98ffc1608e2af0147ca4e86e1ce27672d8d3f3c9d4ffd6ef7e" + digest = hash32"01624652859a6e98ffc1608e2af0147ca4e86e1ce27672d8d3f3c9d4ffd6ef7e" PooledTransaction( tx: Transaction( @@ -129,7 +129,7 @@ proc tx7(i: int): PooledTransaction = proc tx8(i: int): PooledTransaction = const - digest = bytes32"01624652859a6e98ffc1608e2af0147ca4e86e1ce27672d8d3f3c9d4ffd6ef7e" + digest = hash32"01624652859a6e98ffc1608e2af0147ca4e86e1ce27672d8d3f3c9d4ffd6ef7e" PooledTransaction( tx: Transaction(