Conversation
There was a problem hiding this comment.
Pull request overview
Adds a small standalone CLI (genesisroot) for computing and printing the genesis state root and genesis block hash for a dynamically-configured zkEVM chain, based on JSON config files in a provided directory.
Changes:
- Introduces
cmd/genesisroot/main.gocommand that loads dynamic chain/genesis config from a config directory. - Builds a genesis block via
core.GenesisToBlock(using a temporary MDBX dir) and prints the resulting state root and block hash.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| dConf := cfg_dynamic_genesis.NewDynamicGenesisConfig(chain) | ||
|
|
||
| genesis := core.DynamicGenesisBlock(chain) | ||
| genesis.Timestamp = dConf.Timestamp | ||
| genesis.GasLimit = dConf.GasLimit | ||
| genesis.Difficulty = big.NewInt(dConf.Difficulty) |
There was a problem hiding this comment.
cfg_dynamic_genesis.NewDynamicGenesisConfig(chain) and core.DynamicGenesisBlock(chain) both read the dynamic genesis conf from disk (the latter calls NewDynamicGenesisConfig internally). This means the config file is parsed twice for every run, and the explicit genesis.Timestamp = dConf.Timestamp becomes redundant. Consider avoiding the duplicate load (e.g., build the genesis struct directly using the cfg_* packages and reuse the already-loaded conf, or introduce/use a helper that returns both the genesis and the parsed dynamic conf).
| absDir, err := filepath.Abs(configDir) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "invalid config dir: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| zk_config.ZKDynamicConfigPath = absDir | ||
| zk_config.ZkUnionConfigPath = "" | ||
|
|
||
| dConf := cfg_dynamic_genesis.NewDynamicGenesisConfig(chain) | ||
|
|
||
| genesis := core.DynamicGenesisBlock(chain) |
There was a problem hiding this comment.
This command can terminate with a panic + stack trace if the config directory/files are missing or invalid, because NewDynamicGenesisConfig/NewDynamicChainConfig/NewDynamicAllocsConfig panic when they can’t find or parse the expected JSON files. It would be more robust to validate configDir exists (e.g., os.Stat) and/or wrap the main body with a defer/recover that prints a clean error message to stderr and exits non-zero.
| if len(os.Args) < 2 { | ||
| fmt.Fprintf(os.Stderr, "Usage: genesisroot <config-dir> [chain-name]\n") |
There was a problem hiding this comment.
The usage banner hard-codes the program name as genesisroot. If the binary is renamed or invoked via a different path, the message will be inaccurate. Using os.Args[0] (or filepath.Base(os.Args[0])) keeps the usage text correct.
| if len(os.Args) < 2 { | |
| fmt.Fprintf(os.Stderr, "Usage: genesisroot <config-dir> [chain-name]\n") | |
| prog := filepath.Base(os.Args[0]) | |
| if len(os.Args) < 2 { | |
| fmt.Fprintf(os.Stderr, "Usage: %s <config-dir> [chain-name]\n", prog) |
No description provided.