Skip to content

Commit

Permalink
Add Worldchain support (#8044)
Browse files Browse the repository at this point in the history
  • Loading branch information
deffrian authored Jan 15, 2025
1 parent c5f6fe8 commit b743908
Show file tree
Hide file tree
Showing 9 changed files with 27,985 additions and 6 deletions.
13,905 changes: 13,905 additions & 0 deletions src/Nethermind/Chains/worldchain-mainnet.json

Large diffs are not rendered by default.

13,902 changes: 13,902 additions & 0 deletions src/Nethermind/Chains/worldchain-sepolia.json

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions src/Nethermind/Nethermind.Runner/configs/worldchain-mainnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"$schema": "https://raw.githubusercontent.com/NethermindEth/core-scripts/refs/heads/main/schemas/config.json",
"Init": {
"ChainSpecPath": "chainspec/worldchain-mainnet.json",
"GenesisHash": "0x70d316d2e0973b62332ba2e9768dd7854298d7ffe77f0409ffdb8d859f2d3fa3",
"BaseDbPath": "nethermind_db/worldchain-mainnet",
"LogFileName": "worldchain-mainnet.logs.txt",
"DisableGcOnNewPayload": false
},
"TxPool": {
"BlobsSupport": "Disabled"
},
"Sync": {
"FastSync": true,
"SnapSync": true,
"FastSyncCatchUpHeightDelta": "10000000000"
},
"Discovery": {
"DiscoveryVersion": "V5"
},
"JsonRpc": {
"Enabled": true,
"Port": 8545,
"EnginePort": 8551
},
"Pruning": {
"PruningBoundary": 192
},
"Blocks": {
"SecondsPerSlot": 2,
"TargetBlockGasLimit": 30000000
},
"Merge": {
"Enabled": true
},
"Optimism": {
"SequencerUrl": "https://worldchain-mainnet-sequencer.g.alchemy.com"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "https://raw.githubusercontent.com/NethermindEth/core-scripts/refs/heads/main/schemas/config.json",
"Init": {
"ChainSpecPath": "chainspec/worldchain-mainnet.json",
"GenesisHash": "0x70d316d2e0973b62332ba2e9768dd7854298d7ffe77f0409ffdb8d859f2d3fa3",
"BaseDbPath": "nethermind_db/worldchain-mainnet-archive",
"LogFileName": "worldchain-mainnet-archive.logs.txt",
"DisableGcOnNewPayload": false
},
"TxPool": {
"BlobsSupport": "Disabled"
},
"Discovery": {
"DiscoveryVersion": "V5"
},
"Receipt": {
"TxLookupLimit": 0
},
"Pruning": {
"Mode": "None"
},
"JsonRpc": {
"Enabled": true,
"Port": 8545,
"EnginePort": 8551
},
"Optimism": {
"SequencerUrl": "https://worldchain-mainnet-sequencer.g.alchemy.com"
}
}
39 changes: 39 additions & 0 deletions src/Nethermind/Nethermind.Runner/configs/worldchain-sepolia.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"$schema": "https://raw.githubusercontent.com/NethermindEth/core-scripts/refs/heads/main/schemas/config.json",
"Init": {
"ChainSpecPath": "chainspec/worldchain-sepolia.json",
"GenesisHash": "0xf1deb67ee953f94d8545d2647918687fa8ba1f30fa6103771f11b7c483984070",
"BaseDbPath": "nethermind_db/worldchain-sepolia",
"LogFileName": "worldchain-sepolia.logs.txt",
"DisableGcOnNewPayload": false
},
"TxPool": {
"BlobsSupport": "Disabled"
},
"Sync": {
"FastSync": true,
"SnapSync": true,
"FastSyncCatchUpHeightDelta": "10000000000"
},
"Discovery": {
"DiscoveryVersion": "V5"
},
"JsonRpc": {
"Enabled": true,
"Port": 8545,
"EnginePort": 8551
},
"Pruning": {
"PruningBoundary": 192
},
"Blocks": {
"SecondsPerSlot": 2,
"TargetBlockGasLimit": 30000000
},
"Merge": {
"Enabled": true
},
"Optimism": {
"SequencerUrl": "https://worldchain-sepolia-sequencer.g.alchemy.com"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "https://raw.githubusercontent.com/NethermindEth/core-scripts/refs/heads/main/schemas/config.json",
"Init": {
"ChainSpecPath": "chainspec/worldchain-sepolia.json",
"GenesisHash": "0xf1deb67ee953f94d8545d2647918687fa8ba1f30fa6103771f11b7c483984070",
"BaseDbPath": "nethermind_db/worldchain-archive",
"LogFileName": "worldchain-archive.logs.txt",
"DisableGcOnNewPayload": false
},
"TxPool": {
"BlobsSupport": "Disabled"
},
"Discovery": {
"DiscoveryVersion": "V5"
},
"Receipt": {
"TxLookupLimit": 0
},
"Pruning": {
"Mode": "None"
},
"JsonRpc": {
"Enabled": true,
"Port": 8545,
"EnginePort": 8551
},
"Optimism": {
"SequencerUrl": "https://worldchain-sepolia-sequencer.g.alchemy.com"
}
}
42 changes: 36 additions & 6 deletions src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,15 @@ private static void LoadAllocations(ChainSpecJson chainSpecJson, ChainSpec chain
return;
}

if (chainSpecJson.CodeHashes is not null)
{
foreach (KeyValuePair<string, byte[]> codeHash in chainSpecJson.CodeHashes)
{
if (ValueKeccak.Compute(codeHash.Value) != new ValueHash256(codeHash.Key)) throw new ArgumentException($"Unexpected code {codeHash.Key}");
}
chainSpecJson.CodeHashes[Hash256.Zero.ToString()] = [];
}

chainSpec.Allocations = new Dictionary<Address, ChainSpecAllocation>();
foreach (KeyValuePair<string, AllocationJson> account in chainSpecJson.Accounts)
{
Expand All @@ -363,12 +372,33 @@ private static void LoadAllocations(ChainSpecJson chainSpecJson, ChainSpec chain
continue;
}

chainSpec.Allocations[new Address(account.Key)] = new ChainSpecAllocation(
account.Value.Balance ?? UInt256.Zero,
account.Value.Nonce,
account.Value.Code,
account.Value.Constructor,
account.Value.GetConvertedStorage());
if (account.Value.CodeHash is not null && account.Value.Code is not null)
{
throw new ArgumentException("CodeHash and Code are both not null");
}

Address address = new(account.Key);

if (account.Value.CodeHash is not null)
{
string codeHashString = account.Value.CodeHash.ToString();
if (chainSpecJson.CodeHashes is null || !chainSpecJson.CodeHashes.ContainsKey(codeHashString)) throw new ArgumentException($"CodeHash {account.Value.CodeHash} is not found");
chainSpec.Allocations[address] = new ChainSpecAllocation(
account.Value.Balance ?? UInt256.Zero,
account.Value.Nonce,
chainSpecJson.CodeHashes[codeHashString],
account.Value.Constructor,
account.Value.GetConvertedStorage());
}
else
{
chainSpec.Allocations[address] = new ChainSpecAllocation(
account.Value.Balance ?? UInt256.Zero,
account.Value.Nonce,
account.Value.Code,
account.Value.Constructor,
account.Value.GetConvertedStorage());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections.Generic;
using System.Linq;
using Nethermind.Core.Crypto;
using Nethermind.Core.Extensions;
using Nethermind.Int256;

Expand All @@ -21,6 +22,8 @@ internal class AllocationJson
public byte[] Constructor { get; set; }
public Dictionary<string, string> Storage { get; set; }

public Hash256? CodeHash { get; set; }

public Dictionary<UInt256, byte[]> GetConvertedStorage()
{
return Storage?.ToDictionary(static s => Bytes.FromHexString(s.Key).ToUInt256(), static s => Bytes.FromHexString(s.Value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal class ChainSpecJson
public string[] Nodes { get; set; }
[JsonPropertyName("accounts")]
public Dictionary<string, AllocationJson> Accounts { get; set; }
public Dictionary<string, byte[]>? CodeHashes { get; set; }

internal class EngineJson
{
Expand Down

0 comments on commit b743908

Please sign in to comment.