Skip to content

Commit d4d3459

Browse files
authored
chore(l1,l2): ordered genesis files (#2713)
**Motivation** Ordered genesis files make it easy to diff with one another. **Description** - Add function to write a Genesis json file with its keys ordered. - Genesis files are now ordered by key. Closes #2706.
1 parent 6efc889 commit d4d3459

20 files changed

+5570
-2135
lines changed

Cargo.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ members = [
2424
"crates/storage",
2525
"crates/vm",
2626
"crates/vm/levm",
27-
"crates/vm/levm/bench/revm_comparison",
27+
"crates/vm/levm/bench/revm_comparison"
2828
]
2929
resolver = "2"
3030

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ WORKDIR /ethrex
1313

1414
FROM chef AS planner
1515
COPY crates ./crates
16+
COPY tools ./tools
1617
COPY cmd ./cmd
1718
COPY Cargo.* .
1819
# Determine the crates that need to be built from dependencies

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,6 @@ rm-test-db: ## 🛑 Removes the DB used by the ethrex client used for testing
178178

179179
test_data/ERC20/ERC20.bin: ## 🔨 Build the ERC20 contract for the load test
180180
solc ./test_data/ERC20.sol -o $@
181+
182+
sort-genesis-files:
183+
cd ./tools && cargo run

crates/common/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ rayon = "1.5"
3131
[dev-dependencies]
3232
hex-literal.workspace = true
3333

34+
3435
[features]
3536
default = []
3637
c-kzg = ["dep:c-kzg"]

crates/common/types/genesis.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ impl ChainConfig {
292292
}
293293

294294
#[allow(unused)]
295-
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
295+
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
296296
pub struct GenesisAccount {
297297
#[serde(default, with = "crate::serde_utils::bytes")]
298298
pub code: Bytes,
@@ -372,7 +372,6 @@ impl Genesis {
372372
Trie::compute_hash_from_unsorted_iter(iter)
373373
}
374374
}
375-
376375
#[cfg(test)]
377376
mod tests {
378377
use std::str::FromStr;

crates/l2/contracts/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ ethrex-l2 = { path = "../../l2" }
2626
ethrex-sdk = { path = "../../l2/sdk" }
2727
ethrex-common = { path = "../../common" }
2828
ethrex-rpc = { path = "../../networking/rpc" }
29+
tools = { path = "../../../tools" }
2930

3031
[[bin]]
3132
name = "ethrex_l2_l1_deployer"

crates/l2/contracts/bin/system_contracts_updater/main.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::collections::HashMap;
2-
31
use bytes::Bytes;
42
use clap::Parser;
53
use cli::SystemContractsUpdaterOptions;
@@ -8,7 +6,8 @@ use ethrex_common::types::GenesisAccount;
86
use ethrex_common::U256;
97
use ethrex_l2::utils::test_data_io::read_genesis_file;
108
use ethrex_l2_sdk::{compile_contract, COMMON_BRIDGE_L2_ADDRESS};
11-
9+
use std::{collections::HashMap, io::ErrorKind, path::Path};
10+
use tools::genesis::write_genesis_as_json;
1211
mod cli;
1312
mod error;
1413

@@ -34,9 +33,8 @@ fn update_genesis_file(l2_genesis_path: &str) -> Result<(), SystemContractsUpdat
3433
},
3534
);
3635

37-
let modified_genesis = serde_json::to_string(&genesis)?;
38-
39-
std::fs::write(l2_genesis_path, modified_genesis)?;
36+
write_genesis_as_json(genesis, Path::new(l2_genesis_path))
37+
.map_err(|err_msg| std::io::Error::new(ErrorKind::Other, err_msg))?;
4038

4139
println!("Updated L2 genesis file.");
4240

test_data/genesis-execution-api.json

Lines changed: 153 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"config": {
3-
"ethash": {},
43
"chainId": 3503995874084926,
54
"homesteadBlock": 0,
5+
"daoForkSupport": false,
66
"eip150Block": 0,
77
"eip155Block": 0,
88
"eip158Block": 0,
@@ -15,11 +15,12 @@
1515
"londonBlock": 0,
1616
"arrowGlacierBlock": 0,
1717
"grayGlacierBlock": 0,
18-
"mergeNetsplitBlock": 0,
1918
"terminalTotalDifficulty": 131072,
19+
"terminalTotalDifficultyPassed": false,
2020
"shanghaiTime": 0,
2121
"cancunTime": 0,
2222
"pragueTime": 0,
23+
"depositContractAddress": "0x00000000219ab540356cbb839cbe05303d7705fa",
2324
"blobSchedule": {
2425
"cancun": {
2526
"target": 3,
@@ -32,110 +33,176 @@
3233
"baseFeeUpdateFraction": 5007716
3334
}
3435
},
35-
"depositContractAddress": "0x00000000219ab540356cBB839Cbe05303d7705Fa"
36+
"mergeNetsplitBlock": 0
3637
},
3738
"nonce": "0x0",
38-
"timestamp": "0x0",
39+
"timestamp": "0",
3940
"extraData": "0x68697665636861696e",
4041
"gasLimit": "0x23f3e20",
4142
"difficulty": "0x20000",
4243
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
4344
"coinbase": "0x0000000000000000000000000000000000000000",
4445
"alloc": {
45-
"00000961ef480eb55e80d19ad83579a64c007002": {
46+
"0x00000961ef480eb55e80d19ad83579a64c007002": {
4647
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe1460cb5760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff146101f457600182026001905f5b5f82111560685781019083028483029004916001019190604d565b909390049250505036603814608857366101f457346101f4575f5260205ff35b34106101f457600154600101600155600354806003026004013381556001015f35815560010160203590553360601b5f5260385f601437604c5fa0600101600355005b6003546002548082038060101160df575060105b5f5b8181146101835782810160030260040181604c02815460601b8152601401816001015481526020019060020154807fffffffffffffffffffffffffffffffff00000000000000000000000000000000168252906010019060401c908160381c81600701538160301c81600601538160281c81600501538160201c81600401538160181c81600301538160101c81600201538160081c81600101535360010160e1565b910180921461019557906002556101a0565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14156101cd57505f5b6001546002828201116101e25750505f6101e8565b01600290035b5f555f600155604c025ff35b5f5ffd",
47-
"balance": "0x1"
48+
"storage": {},
49+
"balance": "0x1",
50+
"nonce": "0x0"
4851
},
49-
"0000bbddc7ce488642fb579f8b00f3a590007251": {
52+
"0x0000bbddc7ce488642fb579f8b00f3a590007251": {
5053
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe1460d35760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1461019a57600182026001905f5b5f82111560685781019083028483029004916001019190604d565b9093900492505050366060146088573661019a573461019a575f5260205ff35b341061019a57600154600101600155600354806004026004013381556001015f358155600101602035815560010160403590553360601b5f5260605f60143760745fa0600101600355005b6003546002548082038060021160e7575060025b5f5b8181146101295782810160040260040181607402815460601b815260140181600101548152602001816002015481526020019060030154905260010160e9565b910180921461013b5790600255610146565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff141561017357505f5b6001546001828201116101885750505f61018e565b01600190035b5f555f6001556074025ff35b5f5ffd",
51-
"balance": "0x1"
54+
"storage": {},
55+
"balance": "0x1",
56+
"nonce": "0x0"
5257
},
53-
"0000f90827f1c53a10cb7a02335b175320002935": {
58+
"0x0000f90827f1c53a10cb7a02335b175320002935": {
5459
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe14604657602036036042575f35600143038111604257611fff81430311604257611fff9006545f5260205ff35b5f5ffd5b5f35611fff60014303065500",
55-
"balance": "0x1"
60+
"storage": {},
61+
"balance": "0x1",
62+
"nonce": "0x0"
5663
},
57-
"000f3df6d732807ef1319fb7b8bb8522d0beac02": {
64+
"0x000f3df6d732807ef1319fb7b8bb8522d0beac02": {
5865
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500",
59-
"balance": "0x2a"
60-
},
61-
"0c2c51a0990aee1d73c1228de158688341557508": {
62-
"balance": "0xc097ce7bc90715b34b9f1000000000"
63-
},
64-
"14e46043e63d0e3cdcf2530519f4cfaf35058cb2": {
65-
"balance": "0xc097ce7bc90715b34b9f1000000000"
66-
},
67-
"16c57edf7fa9d9525378b0b81bf8a3ced0620c1c": {
68-
"balance": "0xc097ce7bc90715b34b9f1000000000"
69-
},
70-
"1f4924b14f34e24159387c0a4cdbaa32f3ddb0cf": {
71-
"balance": "0xc097ce7bc90715b34b9f1000000000"
72-
},
73-
"1f5bde34b4afc686f136c7a3cb6ec376f7357759": {
74-
"balance": "0xc097ce7bc90715b34b9f1000000000"
75-
},
76-
"2d389075be5be9f2246ad654ce152cf05990b209": {
77-
"balance": "0xc097ce7bc90715b34b9f1000000000"
78-
},
79-
"3ae75c08b4c907eb63a8960c45b86e1e9ab6123c": {
80-
"balance": "0xc097ce7bc90715b34b9f1000000000"
81-
},
82-
"4340ee1b812acb40a1eb561c019c327b243b92df": {
83-
"balance": "0xc097ce7bc90715b34b9f1000000000"
84-
},
85-
"4a0f1452281bcec5bd90c3dce6162a5995bfe9df": {
86-
"balance": "0xc097ce7bc90715b34b9f1000000000"
87-
},
88-
"4dde844b71bcdf95512fb4dc94e84fb67b512ed8": {
89-
"balance": "0xc097ce7bc90715b34b9f1000000000"
90-
},
91-
"5f552da00dfb4d3749d9e62dcee3c918855a86a0": {
92-
"balance": "0xc097ce7bc90715b34b9f1000000000"
93-
},
94-
"654aa64f5fbefb84c270ec74211b81ca8c44a72e": {
95-
"balance": "0xc097ce7bc90715b34b9f1000000000"
96-
},
97-
"717f8aa2b982bee0e29f573d31df288663e1ce16": {
98-
"balance": "0xc097ce7bc90715b34b9f1000000000"
99-
},
100-
"7435ed30a8b4aeb0877cef0c6e8cffe834eb865f": {
101-
"balance": "0xc097ce7bc90715b34b9f1000000000"
102-
},
103-
"7dcd17433742f4c0ca53122ab541d0ba67fc27df": {
66+
"storage": {},
67+
"balance": "0x2a",
68+
"nonce": "0x0"
69+
},
70+
"0x0c2c51a0990aee1d73c1228de158688341557508": {
71+
"code": "0x",
72+
"storage": {},
73+
"balance": "0xc097ce7bc90715b34b9f1000000000",
74+
"nonce": "0x0"
75+
},
76+
"0x14e46043e63d0e3cdcf2530519f4cfaf35058cb2": {
77+
"code": "0x",
78+
"storage": {},
79+
"balance": "0xc097ce7bc90715b34b9f1000000000",
80+
"nonce": "0x0"
81+
},
82+
"0x16c57edf7fa9d9525378b0b81bf8a3ced0620c1c": {
83+
"code": "0x",
84+
"storage": {},
85+
"balance": "0xc097ce7bc90715b34b9f1000000000",
86+
"nonce": "0x0"
87+
},
88+
"0x1f4924b14f34e24159387c0a4cdbaa32f3ddb0cf": {
89+
"code": "0x",
90+
"storage": {},
91+
"balance": "0xc097ce7bc90715b34b9f1000000000",
92+
"nonce": "0x0"
93+
},
94+
"0x1f5bde34b4afc686f136c7a3cb6ec376f7357759": {
95+
"code": "0x",
96+
"storage": {},
97+
"balance": "0xc097ce7bc90715b34b9f1000000000",
98+
"nonce": "0x0"
99+
},
100+
"0x2d389075be5be9f2246ad654ce152cf05990b209": {
101+
"code": "0x",
102+
"storage": {},
103+
"balance": "0xc097ce7bc90715b34b9f1000000000",
104+
"nonce": "0x0"
105+
},
106+
"0x3ae75c08b4c907eb63a8960c45b86e1e9ab6123c": {
107+
"code": "0x",
108+
"storage": {},
109+
"balance": "0xc097ce7bc90715b34b9f1000000000",
110+
"nonce": "0x0"
111+
},
112+
"0x4340ee1b812acb40a1eb561c019c327b243b92df": {
113+
"code": "0x",
114+
"storage": {},
115+
"balance": "0xc097ce7bc90715b34b9f1000000000",
116+
"nonce": "0x0"
117+
},
118+
"0x4a0f1452281bcec5bd90c3dce6162a5995bfe9df": {
119+
"code": "0x",
120+
"storage": {},
121+
"balance": "0xc097ce7bc90715b34b9f1000000000",
122+
"nonce": "0x0"
123+
},
124+
"0x4dde844b71bcdf95512fb4dc94e84fb67b512ed8": {
125+
"code": "0x",
126+
"storage": {},
127+
"balance": "0xc097ce7bc90715b34b9f1000000000",
128+
"nonce": "0x0"
129+
},
130+
"0x5f552da00dfb4d3749d9e62dcee3c918855a86a0": {
131+
"code": "0x",
132+
"storage": {},
133+
"balance": "0xc097ce7bc90715b34b9f1000000000",
134+
"nonce": "0x0"
135+
},
136+
"0x654aa64f5fbefb84c270ec74211b81ca8c44a72e": {
137+
"code": "0x",
138+
"storage": {},
139+
"balance": "0xc097ce7bc90715b34b9f1000000000",
140+
"nonce": "0x0"
141+
},
142+
"0x717f8aa2b982bee0e29f573d31df288663e1ce16": {
143+
"code": "0x",
144+
"storage": {},
145+
"balance": "0xc097ce7bc90715b34b9f1000000000",
146+
"nonce": "0x0"
147+
},
148+
"0x7435ed30a8b4aeb0877cef0c6e8cffe834eb865f": {
149+
"code": "0x",
150+
"storage": {},
151+
"balance": "0xc097ce7bc90715b34b9f1000000000",
152+
"nonce": "0x0"
153+
},
154+
"0x7dcd17433742f4c0ca53122ab541d0ba67fc27df": {
104155
"code": "0x3680600080376000206000548082558060010160005560005263656d697460206000a2",
105-
"balance": "0x0"
106-
},
107-
"83c7e323d189f18725ac510004fdc2941f8c4a78": {
108-
"balance": "0xc097ce7bc90715b34b9f1000000000"
109-
},
110-
"84e75c28348fb86acea1a93a39426d7d60f4cc46": {
111-
"balance": "0xc097ce7bc90715b34b9f1000000000"
112-
},
113-
"8bebc8ba651aee624937e7d897853ac30c95a067": {
156+
"storage": {},
157+
"balance": "0x0",
158+
"nonce": "0x0"
159+
},
160+
"0x83c7e323d189f18725ac510004fdc2941f8c4a78": {
161+
"code": "0x",
162+
"storage": {},
163+
"balance": "0xc097ce7bc90715b34b9f1000000000",
164+
"nonce": "0x0"
165+
},
166+
"0x84e75c28348fb86acea1a93a39426d7d60f4cc46": {
167+
"code": "0x",
168+
"storage": {},
169+
"balance": "0xc097ce7bc90715b34b9f1000000000",
170+
"nonce": "0x0"
171+
},
172+
"0x8bebc8ba651aee624937e7d897853ac30c95a067": {
173+
"code": "0x",
114174
"storage": {
115-
"0x0000000000000000000000000000000000000000000000000000000000000001": "0x0000000000000000000000000000000000000000000000000000000000000001",
116-
"0x0000000000000000000000000000000000000000000000000000000000000002": "0x0000000000000000000000000000000000000000000000000000000000000002",
117-
"0x0000000000000000000000000000000000000000000000000000000000000003": "0x0000000000000000000000000000000000000000000000000000000000000003"
175+
"0x1": "0x1",
176+
"0x2": "0x2",
177+
"0x3": "0x3"
118178
},
119179
"balance": "0x1",
120180
"nonce": "0x1"
121181
},
122-
"c7b99a164efd027a93f147376cc7da7c67c6bbe0": {
123-
"balance": "0xc097ce7bc90715b34b9f1000000000"
124-
},
125-
"d803681e487e6ac18053afc5a6cd813c86ec3e4d": {
126-
"balance": "0xc097ce7bc90715b34b9f1000000000"
127-
},
128-
"e7d13f7aa2a838d24c59b40186a0aca1e21cffcc": {
129-
"balance": "0xc097ce7bc90715b34b9f1000000000"
130-
},
131-
"eda8645ba6948855e3b3cd596bbb07596d59c603": {
132-
"balance": "0xc097ce7bc90715b34b9f1000000000"
182+
"0xc7b99a164efd027a93f147376cc7da7c67c6bbe0": {
183+
"code": "0x",
184+
"storage": {},
185+
"balance": "0xc097ce7bc90715b34b9f1000000000",
186+
"nonce": "0x0"
187+
},
188+
"0xd803681e487e6ac18053afc5a6cd813c86ec3e4d": {
189+
"code": "0x",
190+
"storage": {},
191+
"balance": "0xc097ce7bc90715b34b9f1000000000",
192+
"nonce": "0x0"
193+
},
194+
"0xe7d13f7aa2a838d24c59b40186a0aca1e21cffcc": {
195+
"code": "0x",
196+
"storage": {},
197+
"balance": "0xc097ce7bc90715b34b9f1000000000",
198+
"nonce": "0x0"
199+
},
200+
"0xeda8645ba6948855e3b3cd596bbb07596d59c603": {
201+
"code": "0x",
202+
"storage": {},
203+
"balance": "0xc097ce7bc90715b34b9f1000000000",
204+
"nonce": "0x0"
133205
}
134206
},
135-
"number": "0x0",
136-
"gasUsed": "0x0",
137-
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
138-
"baseFeePerGas": "0x3b9aca00",
139-
"excessBlobGas": null,
140-
"blobGasUsed": null
141-
}
207+
"baseFeePerGas": "0x3b9aca00"
208+
}

0 commit comments

Comments
 (0)