Skip to content

fix: generate L2 genesis allocs before op-node genesis l2#389

Merged
theo-learner merged 1 commit into
mainfrom
fix/generate-l2-allocs-for-genesis
Mar 17, 2026
Merged

fix: generate L2 genesis allocs before op-node genesis l2#389
theo-learner merged 1 commit into
mainfrom
fix/generate-l2-allocs-for-genesis

Conversation

@theo-learner
Copy link
Copy Markdown
Member

Summary

  • generateL2Genesis in start-deploy.sh was calling op-node genesis l2 without the required --l2-allocs flag, causing genesis generation to fail with a missing flag error
  • Added a forge script scripts/L2Genesis.s.sol:L2Genesis step that generates the L2 genesis state dump (state-dump-{l2ChainID}.json) using deployed L1 contract addresses
  • Passes the generated allocs file via --l2-allocs to op-node genesis l2

Root Cause

The current version of op-node genesis l2 requires --l2-allocs (path to L2 genesis state dump), but the generateL2Genesis function did not generate this file or pass it to the command.

Changes

  • Run forge script scripts/L2Genesis.s.sol:L2Genesis with CONTRACT_ADDRESSES_PATH pointing to the deploy result JSON before calling op-node genesis l2
  • Extract l2ChainID from the deploy config to locate the generated state dump at state-dump-{l2ChainID}.json
  • Add --l2-allocs flag to the op-node genesis l2 invocation

Test plan

  • Run start-deploy.sh generate -e .env -c deploy-config.json against Sepolia testnet
  • Verify build/genesis.json and build/rollup.json are generated successfully

🤖 Generated with Claude Code

The generateL2Genesis function in start-deploy.sh was calling
'op-node genesis l2' without the required --l2-allocs flag,
causing genesis generation to fail.

This fix adds a forge script step that runs L2Genesis.s.sol to
generate the L2 genesis state dump (state-dump-{l2ChainID}.json),
then passes the resulting file via --l2-allocs to op-node genesis l2.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical issue in the L2 genesis generation process, which previously failed due to a missing required flag. By introducing an explicit step to generate the necessary L2 genesis allocations using a forge script and then correctly supplying these allocations to the op-node genesis l2 command, the change ensures the successful and robust creation of L2 genesis and rollup configurations.

Highlights

  • L2 Genesis Allocation Generation: Implemented a new step using forge script to generate the L2 genesis state dump (state-dump-{l2ChainID}.json) before calling op-node genesis l2.
  • Missing Flag Resolution: Resolved the op-node genesis l2 failure by correctly passing the generated L2 genesis allocations via the --l2-allocs flag.
  • L2 Chain ID Extraction: Added logic to extract the l2ChainID from the deploy configuration to dynamically locate the generated state dump file.
Changelog
  • packages/tokamak/contracts-bedrock/scripts/start-deploy.sh
    • Added a new section to generate L2 genesis allocs using forge script scripts/L2Genesis.s.sol:L2Genesis.
    • Included logic to extract the l2ChainID from the deploy configuration to determine the path for the state dump file.
    • Implemented a check to verify the existence of the generated state dump file, returning an error if not found.
    • Modified the op-node genesis l2 command to include the --l2-allocs flag, pointing to the newly generated state dump file.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@theo-learner theo-learner merged commit c9d8d16 into main Mar 17, 2026
6 of 14 checks passed
@theo-learner theo-learner deleted the fix/generate-l2-allocs-for-genesis branch March 17, 2026 02:39
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses a bug in L2 genesis generation by adding the required --l2-allocs flag. The changes introduce a new step to generate the necessary allocation file using a forge script before calling op-node genesis l2. The implementation looks solid. I've added a few suggestions to improve the robustness and maintainability of the shell script.


# Generate L2 genesis allocs using forge script
echo "Generating L2 genesis allocs via forge script..."
cd $projectRoot/packages/tokamak/contracts-bedrock
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

It's good practice to add error handling for cd commands, especially when the script is not run with set -e. If this directory change fails, subsequent commands would execute in an incorrect directory, potentially leading to confusing errors.

Suggested change
cd $projectRoot/packages/tokamak/contracts-bedrock
cd "$projectRoot/packages/tokamak/contracts-bedrock" || { echo "❌ Error: could not change directory to contracts-bedrock"; return 1; }

forge script scripts/L2Genesis.s.sol:L2Genesis \
--rpc-url $L1_RPC_URL; then
echo "❌ Error: Failed to generate L2 genesis allocs"
cd $currentPWD
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This function has multiple exit points where you restore the original working directory with cd $currentPWD. To reduce repetition and ensure the directory is always restored correctly, you could use a trap at the beginning of the function:

function generateL2Genesis() {
  trap 'cd "$currentPWD"' RETURN
  # ... function body ...
}

This will execute cd "$currentPWD" whenever the function returns, regardless of the exit point. You could then remove all the individual cd $currentPWD calls before each return statement, simplifying the error handling logic and making the function more robust.

fi

# Determine state dump path: uses l2ChainID from deploy config
l2ChainID=$(jq -r '.l2ChainID' $DEPLOY_CONFIG_PATH)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

It's a good practice to validate the output of the jq command. If jq fails (e.g., it's not installed, the JSON is invalid, or the key is not found), $l2ChainID could be empty. This would lead to a confusing file-not-found error on line 413. Checking if $l2ChainID has a value before using it would make the script more robust.

Suggested change
l2ChainID=$(jq -r '.l2ChainID' $DEPLOY_CONFIG_PATH)
l2ChainID=$(jq -r '.l2ChainID' $DEPLOY_CONFIG_PATH)
if [ -z "$l2ChainID" ]; then
echo "❌ Error: Failed to get l2ChainID from $DEPLOY_CONFIG_PATH"
cd $currentPWD
return 1
fi

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.

1 participant