Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change VersionedHash to Hash32 #738

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions eth/common/eth_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion eth/common/eth_types_json_serialization.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions eth/common/hashes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 0 additions & 2 deletions eth/common/headers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions eth/common/transactions.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

{.push raises: [].}

import "."/addresses, base
import "."/[addresses, base, hashes]

export addresses, base
export addresses, base, hashes

type
AccessPair* = object
Expand All @@ -18,8 +18,6 @@ type

AccessList* = seq[AccessPair]

VersionedHash* = Bytes32

Authorization* = object
chainId*: ChainId
address*: Address
Expand Down
4 changes: 2 additions & 2 deletions eth/common/transactions_rlp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions tests/common/test_eip4844.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import
unittest2,
../../eth/common,
../../eth/rlp,
../../eth/common/transaction
../../eth/common/transactions_rlp

const
recipient = address"095e7baea6a6c7c4c2dfeb977efac326af552d87"
Expand Down Expand Up @@ -94,7 +94,7 @@ proc tx5(i: int): PooledTransaction =

proc tx6(i: int): PooledTransaction =
const
digest = bytes32"010657f37554c781402a22917dee2f75def7ab966d7b770905398eba3c444014"
digest = hash32"010657f37554c781402a22917dee2f75def7ab966d7b770905398eba3c444014"

PooledTransaction(
tx: Transaction(
Expand All @@ -113,7 +113,7 @@ proc tx6(i: int): PooledTransaction =

proc tx7(i: int): PooledTransaction =
const
digest = bytes32"01624652859a6e98ffc1608e2af0147ca4e86e1ce27672d8d3f3c9d4ffd6ef7e"
digest = hash32"01624652859a6e98ffc1608e2af0147ca4e86e1ce27672d8d3f3c9d4ffd6ef7e"

PooledTransaction(
tx: Transaction(
Expand All @@ -129,7 +129,7 @@ proc tx7(i: int): PooledTransaction =

proc tx8(i: int): PooledTransaction =
const
digest = bytes32"01624652859a6e98ffc1608e2af0147ca4e86e1ce27672d8d3f3c9d4ffd6ef7e"
digest = hash32"01624652859a6e98ffc1608e2af0147ca4e86e1ce27672d8d3f3c9d4ffd6ef7e"

PooledTransaction(
tx: Transaction(
Expand Down