Skip to content

Commit b20f1ba

Browse files
authored
Update nim-eth types (#6583)
Minimal changes needed for compatiblity with status-im/nim-eth#733 which aligns core types with execution spec.
1 parent 2e64fdf commit b20f1ba

File tree

7 files changed

+82
-75
lines changed

7 files changed

+82
-75
lines changed

beacon_chain/conf.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,8 @@ type
11331133

11341134
AnyConf* = BeaconNodeConf | ValidatorClientConf | SigningNodeConf
11351135

1136+
Address = primitives.Address
1137+
11361138
proc defaultDataDir*[Conf](config: Conf): string =
11371139
let dataDir = when defined(windows):
11381140
"AppData" / "Roaming" / "Nimbus"

beacon_chain/el/el_manager.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ logScope:
3535
topics = "elman"
3636

3737
type
38+
FixedBytes[N: static int] = web3.FixedBytes[N]
3839
PubKeyBytes = DynamicBytes[48, 48]
3940
WithdrawalCredentialsBytes = DynamicBytes[32, 32]
4041
SignatureBytes = DynamicBytes[96, 96]
4142
Int64LeBytes = DynamicBytes[8, 8]
4243
WithoutTimeout* = distinct int
44+
Address = web3.Address
4345

4446
SomeEnginePayloadWithValue =
4547
BellatrixExecutionPayloadWithValue |

beacon_chain/libnimbus_lc/libnimbus_lc.nim

Lines changed: 52 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,25 +1282,25 @@ proc ETHExecutionBlockHeaderCreateFromJson(
12821282
if data.nonce.isNone:
12831283
return nil
12841284
let blockHeader = ExecutionBlockHeader(
1285-
parentHash: data.parentHash.asEth2Digest,
1286-
ommersHash: data.sha3Uncles.asEth2Digest,
1287-
coinbase: distinctBase(data.miner),
1288-
stateRoot: data.stateRoot.asEth2Digest,
1289-
txRoot: data.transactionsRoot.asEth2Digest,
1290-
receiptsRoot: data.receiptsRoot.asEth2Digest,
1291-
logsBloom: distinctBase(data.logsBloom),
1285+
parentHash: data.parentHash.asEth2Digest.to(Hash32),
1286+
ommersHash: data.sha3Uncles.asEth2Digest.to(Hash32),
1287+
coinbase: distinctBase(data.miner).to(EthAddress),
1288+
stateRoot: data.stateRoot.asEth2Digest.to(Hash32),
1289+
transactionsRoot: data.transactionsRoot.asEth2Digest.to(Hash32),
1290+
receiptsRoot: data.receiptsRoot.asEth2Digest.to(Hash32),
1291+
logsBloom: distinctBase(data.logsBloom).to(Bloom),
12921292
difficulty: data.difficulty,
12931293
number: distinctBase(data.number),
12941294
gasLimit: distinctBase(data.gasLimit),
12951295
gasUsed: distinctBase(data.gasUsed),
12961296
timestamp: EthTime(distinctBase(data.timestamp)),
12971297
extraData: distinctBase(data.extraData),
1298-
mixHash: data.mixHash.asEth2Digest,
1299-
nonce: distinctBase(data.nonce.get),
1298+
mixHash: data.mixHash.asEth2Digest.to(Hash32),
1299+
nonce: distinctBase(data.nonce.get).to(Bytes8),
13001300
baseFeePerGas: data.baseFeePerGas,
13011301
withdrawalsRoot:
13021302
if data.withdrawalsRoot.isSome:
1303-
Opt.some(data.withdrawalsRoot.get.asEth2Digest)
1303+
Opt.some(data.withdrawalsRoot.get.asEth2Digest.to(Hash32))
13041304
else:
13051305
Opt.none(ExecutionHash256),
13061306
blobGasUsed:
@@ -1315,12 +1315,12 @@ proc ETHExecutionBlockHeaderCreateFromJson(
13151315
Opt.none(uint64),
13161316
parentBeaconBlockRoot:
13171317
if data.parentBeaconBlockRoot.isSome:
1318-
Opt.some distinctBase(data.parentBeaconBlockRoot.get.asEth2Digest)
1318+
Opt.some data.parentBeaconBlockRoot.get.asEth2Digest.to(Hash32)
13191319
else:
13201320
Opt.none(ExecutionHash256),
13211321
requestsRoot:
13221322
if data.requestsRoot.isSome:
1323-
Opt.some(data.requestsRoot.get.asEth2Digest)
1323+
Opt.some(data.requestsRoot.get.asEth2Digest.to(Hash32))
13241324
else:
13251325
Opt.none(ExecutionHash256))
13261326
if rlpHash(blockHeader) != executionHash[]:
@@ -1342,7 +1342,7 @@ proc ETHExecutionBlockHeaderCreateFromJson(
13421342
wd = ExecutionWithdrawal(
13431343
index: distinctBase(data.index),
13441344
validatorIndex: distinctBase(data.validatorIndex),
1345-
address: distinctBase(data.address),
1345+
address: distinctBase(data.address).to(EthAddress),
13461346
amount: distinctBase(data.amount))
13471347
rlpBytes =
13481348
try:
@@ -1353,7 +1353,7 @@ proc ETHExecutionBlockHeaderCreateFromJson(
13531353
wds.add ETHWithdrawal(
13541354
index: wd.index,
13551355
validatorIndex: wd.validatorIndex,
1356-
address: ExecutionAddress(data: wd.address),
1356+
address: ExecutionAddress(data: wd.address.data),
13571357
amount: wd.amount,
13581358
bytes: rlpBytes)
13591359

@@ -1379,10 +1379,10 @@ proc ETHExecutionBlockHeaderCreateFromJson(
13791379
# Construct deposit request
13801380
let
13811381
req = ExecutionDepositRequest(
1382-
pubkey: distinctBase(data.pubkey),
1383-
withdrawalCredentials: distinctBase(data.withdrawalCredentials),
1382+
pubkey: distinctBase(data.pubkey).to(Bytes48),
1383+
withdrawalCredentials: distinctBase(data.withdrawalCredentials).to(Bytes32),
13841384
amount: distinctBase(data.amount),
1385-
signature: distinctBase(data.signature),
1385+
signature: distinctBase(data.signature).to(Bytes96),
13861386
index: distinctBase(data.index))
13871387
rlpBytes =
13881388
try:
@@ -1391,10 +1391,10 @@ proc ETHExecutionBlockHeaderCreateFromJson(
13911391
raiseAssert "Unreachable"
13921392

13931393
depositRequests.add ETHDepositRequest(
1394-
pubkey: ValidatorPubKey(blob: req.pubkey),
1395-
withdrawalCredentials: req.withdrawalCredentials,
1394+
pubkey: ValidatorPubKey(blob: req.pubkey.data),
1395+
withdrawalCredentials: req.withdrawalCredentials.data,
13961396
amount: req.amount,
1397-
signature: ValidatorSig(blob: req.signature),
1397+
signature: ValidatorSig(blob: req.signature.data),
13981398
index: req.index,
13991399
bytes: rlpBytes)
14001400

@@ -1411,8 +1411,8 @@ proc ETHExecutionBlockHeaderCreateFromJson(
14111411
# Construct withdrawal request
14121412
let
14131413
req = ExecutionWithdrawalRequest(
1414-
sourceAddress: distinctBase(data.sourceAddress),
1415-
validatorPubkey: distinctBase(data.validatorPubkey),
1414+
sourceAddress: distinctBase(data.sourceAddress).to(EthAddress),
1415+
validatorPubkey: distinctBase(data.validatorPubkey).to(Bytes48),
14161416
amount: distinctBase(data.amount))
14171417
rlpBytes =
14181418
try:
@@ -1421,8 +1421,8 @@ proc ETHExecutionBlockHeaderCreateFromJson(
14211421
raiseAssert "Unreachable"
14221422

14231423
withdrawalRequests.add ETHWithdrawalRequest(
1424-
sourceAddress: ExecutionAddress(data: req.sourceAddress),
1425-
validatorPubkey: ValidatorPubKey(blob: req.validatorPubkey),
1424+
sourceAddress: ExecutionAddress(data: req.sourceAddress.data),
1425+
validatorPubkey: ValidatorPubKey(blob: req.validatorPubkey.data),
14261426
amount: req.amount,
14271427
bytes: rlpBytes)
14281428

@@ -1439,19 +1439,19 @@ proc ETHExecutionBlockHeaderCreateFromJson(
14391439
# Construct consolidation request
14401440
let
14411441
req = ExecutionConsolidationRequest(
1442-
sourceAddress: distinctBase(data.sourceAddress),
1443-
sourcePubkey: distinctBase(data.sourcePubkey),
1444-
targetPubkey: distinctBase(data.targetPubkey))
1442+
sourceAddress: distinctBase(data.sourceAddress).to(EthAddress),
1443+
sourcePubkey: distinctBase(data.sourcePubkey).to(Bytes48),
1444+
targetPubkey: distinctBase(data.targetPubkey).to(Bytes48))
14451445
rlpBytes =
14461446
try:
14471447
rlp.encode(req)
14481448
except RlpError:
14491449
raiseAssert "Unreachable"
14501450

14511451
consolidationRequests.add ETHConsolidationRequest(
1452-
sourceAddress: ExecutionAddress(data: req.sourceAddress),
1453-
sourcePubkey: ValidatorPubKey(blob: req.sourcePubkey),
1454-
targetPubkey: ValidatorPubKey(blob: req.targetPubkey),
1452+
sourceAddress: ExecutionAddress(data: req.sourceAddress.data),
1453+
sourcePubkey: ValidatorPubKey(blob: req.sourcePubkey.data),
1454+
targetPubkey: ValidatorPubKey(blob: req.targetPubkey.data),
14551455
bytes: rlpBytes)
14561456

14571457
# Verify requests root
@@ -1487,9 +1487,9 @@ proc ETHExecutionBlockHeaderCreateFromJson(
14871487
let executionBlockHeader = ETHExecutionBlockHeader.new()
14881488
executionBlockHeader[] = ETHExecutionBlockHeader(
14891489
transactionsRoot: blockHeader.txRoot,
1490-
withdrawalsRoot: blockHeader.withdrawalsRoot.get(ZERO_HASH),
1490+
withdrawalsRoot: blockHeader.withdrawalsRoot.get(zeroHash32),
14911491
withdrawals: wds,
1492-
requestsRoot: blockHeader.requestsRoot.get(ZERO_HASH),
1492+
requestsRoot: blockHeader.requestsRoot.get(zeroHash32),
14931493
depositRequests: depositRequests,
14941494
withdrawalRequests: withdrawalRequests,
14951495
consolidationRequests: consolidationRequests)
@@ -1776,31 +1776,31 @@ proc ETHTransactionsCreateFromJson(
17761776
gasLimit: distinctBase(data.gas).GasInt,
17771777
to:
17781778
if data.to.isSome:
1779-
Opt.some(distinctBase(data.to.get))
1779+
Opt.some(distinctBase(data.to.get).to(EthAddress))
17801780
else:
17811781
Opt.none(EthAddress),
17821782
value: data.value,
17831783
payload: data.input,
17841784
accessList:
17851785
if data.accessList.isSome:
17861786
data.accessList.get.mapIt(AccessPair(
1787-
address: distinctBase(it.address),
1788-
storageKeys: it.storageKeys.mapIt(distinctBase(it))))
1787+
address: distinctBase(it.address).to(EthAddress),
1788+
storageKeys: it.storageKeys.mapIt(distinctBase(it).to(Bytes32))))
17891789
else:
17901790
@[],
17911791
maxFeePerBlobGas:
17921792
data.maxFeePerBlobGas.get(0.u256),
17931793
versionedHashes:
17941794
if data.blobVersionedHashes.isSome:
17951795
data.blobVersionedHashes.get.mapIt(
1796-
ExecutionHash256(data: distinctBase(it)))
1796+
Bytes32(distinctBase(it)))
17971797
else:
17981798
@[],
17991799
authorizationList:
18001800
if data.authorizationList.isSome:
18011801
data.authorizationList.get.mapIt(Authorization(
18021802
chainId: it.chainId.ChainId,
1803-
address: distinctBase(it.address),
1803+
address: distinctBase(it.address).to(EthAddress),
18041804
nonce: distinctBase(it.nonce),
18051805
yParity: distinctBase(it.yParity),
18061806
R: it.R,
@@ -1834,7 +1834,7 @@ proc ETHTransactionsCreateFromJson(
18341834
return Opt.none(array[20, byte])
18351835
pubkey = sig.recover(sigHash).valueOr:
18361836
return Opt.none(array[20, byte])
1837-
Opt.some keys.PublicKey(pubkey).toCanonicalAddress()
1837+
Opt.some keys.PublicKey(pubkey).toCanonicalAddress().data
18381838

18391839
# Compute from execution address
18401840
let
@@ -1861,10 +1861,8 @@ proc ETHTransactionsCreateFromJson(
18611861
of DestinationType.Regular:
18621862
tx.to.get
18631863
of DestinationType.Create:
1864-
var res {.noinit.}: array[20, byte]
1865-
res[0 ..< 20] = keccakHash(rlp.encodeList(fromAddress, tx.nonce))
1866-
.data.toOpenArray(12, 31)
1867-
res
1864+
let hash = keccakHash(rlp.encodeList(fromAddress, tx.nonce))
1865+
hash.to(EthAddress)
18681866

18691867
# Compute authorizations
18701868
var authorizationList = newSeqOfCap[ETHAuthorizationTuple](
@@ -1876,7 +1874,7 @@ proc ETHTransactionsCreateFromJson(
18761874
return nil
18771875
authorizationList.add ETHAuthorizationTuple(
18781876
chainId: distinctBase(auth.chainId).u256,
1879-
address: ExecutionAddress(data: auth.address),
1877+
address: ExecutionAddress(data: auth.address.data),
18801878
nonce: auth.nonce,
18811879
authority: ExecutionAddress(data: authority),
18821880
signature: @signature)
@@ -1890,14 +1888,14 @@ proc ETHTransactionsCreateFromJson(
18901888
maxFeePerGas: tx.maxFeePerGas.uint64,
18911889
gas: tx.gasLimit.uint64,
18921890
destinationType: destinationType,
1893-
to: ExecutionAddress(data: toAddress),
1891+
to: ExecutionAddress(data: toAddress.data),
18941892
value: tx.value,
18951893
input: tx.payload,
18961894
accessList: tx.accessList.mapIt(ETHAccessTuple(
1897-
address: ExecutionAddress(data: it.address),
1898-
storageKeys: it.storageKeys.mapIt(Eth2Digest(data: it)))),
1895+
address: ExecutionAddress(data: it.address.data),
1896+
storageKeys: it.storageKeys.mapIt(Eth2Digest(data: it.data)))),
18991897
maxFeePerBlobGas: tx.maxFeePerBlobGas,
1900-
blobVersionedHashes: tx.versionedHashes,
1898+
blobVersionedHashes: tx.versionedHashes.mapIt(Eth2Digest(data: it.data)),
19011899
authorizationList: authorizationList,
19021900
signature: @rawSig,
19031901
bytes: rlpBytes.TypedTransaction)
@@ -2581,14 +2579,14 @@ proc ETHReceiptsCreateFromJson(
25812579
status: distinctBase(data.status.get(1.Quantity)) != 0'u64,
25822580
hash:
25832581
if data.root.isSome:
2584-
ExecutionHash256(data: distinctBase(data.root.get))
2582+
ExecutionHash256(distinctBase(data.root.get))
25852583
else:
25862584
default(ExecutionHash256),
25872585
cumulativeGasUsed: distinctBase(data.cumulativeGasUsed).GasInt,
2588-
logsBloom: distinctBase(data.logsBloom),
2586+
logsBloom: distinctBase(data.logsBloom).to(Bloom),
25892587
logs: data.logs.mapIt(Log(
2590-
address: distinctBase(it.address),
2591-
topics: it.topics.mapIt(distinctBase(it)),
2588+
address: distinctBase(it.address).to(EthAddress),
2589+
topics: it.topics.mapIt(distinctBase(it).to(Bytes32)),
25922590
data: it.data)))
25932591
rlpBytes =
25942592
try:
@@ -2605,10 +2603,10 @@ proc ETHReceiptsCreateFromJson(
26052603
root: rec.hash,
26062604
status: rec.status,
26072605
gasUsed: distinctBase(data.gasUsed), # Validated during sanity checks.
2608-
logsBloom: BloomLogs(data: rec.logsBloom),
2606+
logsBloom: BloomLogs(data: rec.logsBloom.data),
26092607
logs: rec.logs.mapIt(ETHLog(
2610-
address: ExecutionAddress(data: it.address),
2611-
topics: it.topics.mapIt(Eth2Digest(data: it)),
2608+
address: ExecutionAddress(data: it.address.data),
2609+
topics: it.topics.mapIt(Eth2Digest(data: it.data)),
26122610
data: it.data)),
26132611
bytes: rlpBytes)
26142612

0 commit comments

Comments
 (0)