Versioned hash32 (#2672)

This commit is contained in:
Jacek Sieka 2024-10-01 19:40:37 +02:00 committed by GitHub
parent c022b29d14
commit 219b22b1f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 20 additions and 21 deletions

View File

@ -78,7 +78,7 @@ proc calculateTransactionData(
for i, t in items:
try:
let tx = distinctBase(t)
tr.put(rlp.encode(i), tx)
tr.put(rlp.encode(uint64 i), tx)
except CatchableError as e:
# tr.put interface can raise exception
raiseAssert(e.msg)
@ -97,7 +97,7 @@ proc calculateWithdrawalsRoot(items: openArray[WithdrawalV1]): Hash256 {.raises:
address: distinctBase(w.address).to(EthAddress),
amount: distinctBase(w.amount),
)
tr.put(rlp.encode(i), rlp.encode(withdrawal))
tr.put(rlp.encode(uint64 i), rlp.encode(withdrawal))
except CatchableError as e:
raiseAssert(e.msg)

View File

@ -21,7 +21,7 @@ import
func validateVersionedHashed(payload: ExecutionPayload,
expected: openArray[Web3Hash]): bool =
var versionedHashes: seq[common.Bytes32]
var versionedHashes: seq[common.VersionedHash]
for x in payload.transactions:
let tx = rlp.decode(distinctBase(x), Transaction)
versionedHashes.add tx.versionedHashes

View File

@ -41,7 +41,7 @@ const
# kzgToVersionedHash implements kzg_to_versioned_hash from EIP-4844
proc kzgToVersionedHash*(kzg: kzg.KzgCommitment): VersionedHash =
result = sha256.digest(kzg.bytes).data.to(Bytes32)
result = sha256.digest(kzg.bytes).to(Hash32)
result.data[0] = VERSIONED_HASH_VERSION_KZG
# pointEvaluation implements point_evaluation_precompile from EIP-4844

View File

@ -1323,8 +1323,7 @@ proc queryLogs(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.
proc queryGasPrice(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} =
let ctx = GraphqlContextRef(ud)
try:
{.cast(noSideEffect).}:
bigIntNode(calculateMedianGasPrice(ctx.chainDB))
bigIntNode(calculateMedianGasPrice(ctx.chainDB))
except CatchableError as em:
err("can't get gasPrice: " & em.msg)
@ -1332,7 +1331,7 @@ proc queryProtocolVersion(ud: RootRef, params: Args, parent: Node): RespResult {
let ctx = GraphqlContextRef(ud)
for n in ctx.ethNode.capabilities:
if n.name == "eth":
return ok(resp(n.version))
return bigIntNode(n.version)
err("can't get protocol version")
proc querySyncing(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} =

View File

@ -448,7 +448,7 @@ method handleAnnouncedTxsHashes*(
ctx: EthWireRef;
peer: Peer;
txTypes: seq[byte];
txSizes: openArray[int];
txSizes: openArray[uint64];
txHashes: openArray[Hash32];
): Result[void, string] =
when extraTraceMessages:

View File

@ -101,7 +101,7 @@ method handleAnnouncedTxsHashes*(
ctx: EthWireBase;
peer: Peer;
txTypes: seq[byte];
txSizes: openArray[int];
txSizes: openArray[uint64];
txHashes: openArray[Hash32];
): Result[void, string]
{.base, gcsafe.} =

View File

@ -148,7 +148,7 @@ p2pProtocol eth68(version = ethVersion,
handshake:
# User message 0x00: Status.
proc status(peer: Peer,
ethVersionArg: uint,
ethVersionArg: uint64,
networkId: NetworkId,
totalDifficulty: DifficultyInt,
bestHash: Hash32,
@ -250,7 +250,7 @@ p2pProtocol eth68(version = ethVersion,
proc newPooledTransactionHashes(
peer: Peer,
txTypes: seq[byte],
txSizes: openArray[int],
txSizes: openArray[uint64],
txHashes: openArray[Hash32]
) =
when trEthTraceGossipOk:

View File

@ -96,7 +96,7 @@ proc calculateTransactionData(
for i, t in items:
let tx = distinctBase(t)
txSize = txSize + uint64(len(tx))
tr.merge(rlp.encode(i), tx).expect "merge data"
tr.merge(rlp.encode(uint64 i), tx).expect "merge data"
txHashes.add(txOrHash toFixedBytes(keccakHash(tx)))
let rootHash = tr.state(updateOk = true).expect "hash"
(rootHash, txHashes, txSize)

View File

@ -107,10 +107,10 @@ proc fromJson*(n: JsonNode, name: string, x: var TxType) =
else:
x = hexToInt(node.getStr(), int).TxType
proc fromJson*(n: JsonNode, name: string, x: var seq[Bytes32]) =
proc fromJson*[T: Bytes32|Hash32](n: JsonNode, name: string, x: var seq[T]) =
let node = n[name]
var h: Bytes32
x = newSeqOfCap[Bytes32](node.len)
var h: T
x = newSeqOfCap[T](node.len)
for v in node:
hexToByteArray(v.getStr(), h.data)
x.add h

View File

@ -86,7 +86,7 @@ proc tx5(i: int): Transaction =
proc tx6(i: int): Transaction =
const
digest = bytes32"010657f37554c781402a22917dee2f75def7ab966d7b770905398eba3c444014"
digest = hash32"010657f37554c781402a22917dee2f75def7ab966d7b770905398eba3c444014"
Transaction(
txType: TxEip4844,
@ -101,7 +101,7 @@ proc tx6(i: int): Transaction =
proc tx7(i: int): Transaction =
const
digest = bytes32"01624652859a6e98ffc1608e2af0147ca4e86e1ce27672d8d3f3c9d4ffd6ef7e"
digest = hash32"01624652859a6e98ffc1608e2af0147ca4e86e1ce27672d8d3f3c9d4ffd6ef7e"
Transaction(
txType: TxEip4844,
@ -117,7 +117,7 @@ proc tx7(i: int): Transaction =
proc tx8(i: int): Transaction =
const
digest = bytes32"01624652859a6e98ffc1608e2af0147ca4e86e1ce27672d8d3f3c9d4ffd6ef7e"
digest = hash32"01624652859a6e98ffc1608e2af0147ca4e86e1ce27672d8d3f3c9d4ffd6ef7e"
Transaction(
txType: TxEip4844,

View File

@ -66,7 +66,7 @@ proc fromJson(T: type AccessList, n: JsonNode): AccessList =
proc fromJson(T: type VersionedHashes, list: JsonNode): VersionedHashes =
for x in list:
result.add Bytes32.fromHex(x.getStr)
result.add VersionedHash.fromHex(x.getStr)
template required(T: type, nField: string): auto =
fromJson(T, n[nField])

View File

@ -114,7 +114,7 @@ proc fromJson(T: type seq[Authorization], n: JsonNode, field: string): T =
proc fromJson(T: type VersionedHashes, n: JsonNode, field: string): VersionedHashes =
let list = n[field]
for x in list:
result.add Bytes32.fromHex(x.getStr)
result.add VersionedHash.fromHex(x.getStr)
template `gas=`(tx: var Transaction, x: GasInt) =
tx.gasLimit = x

2
vendor/nim-eth vendored

@ -1 +1 @@
Subproject commit 6bd6bae86c437a61bcd6426571204dd7cdb88123
Subproject commit 086ac68c8698386949295bf44fecc255d9854322