Skip to content

create cmd for dynamic genesis root#2097

Open
elliothllm wants to merge 1 commit intozkevmfrom
feat/genesisroot
Open

create cmd for dynamic genesis root#2097
elliothllm wants to merge 1 commit intozkevmfrom
feat/genesisroot

Conversation

@elliothllm
Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings March 5, 2026 10:28
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.go command 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.

Comment on lines +38 to +43
dConf := cfg_dynamic_genesis.NewDynamicGenesisConfig(chain)

genesis := core.DynamicGenesisBlock(chain)
genesis.Timestamp = dConf.Timestamp
genesis.GasLimit = dConf.GasLimit
genesis.Difficulty = big.NewInt(dConf.Difficulty)
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment on lines +29 to +40
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)
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +16 to +17
if len(os.Args) < 2 {
fmt.Fprintf(os.Stderr, "Usage: genesisroot <config-dir> [chain-name]\n")
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants