Skip to content

Conversation

@riemannulus
Copy link
Contributor

Usage:

mitosisd genesis add-contract [address] [artifact-file]

Examples:

mitosisd genesis add-contract 0x1234567890123456789012345678901234567890 /protocol/out/ValidatorManager.sol/ValidatorManager.json

- Replaced `add-genesis-validator` command with `add-validator` for consistency across the codebase.
- Updated initialization scripts in `init.sh` and `setup.sh` to reflect the new command structure.
- Enhanced the `initRootCmd` function to properly integrate the updated genesis validator command, ensuring seamless command execution during initialization.

These changes improve the clarity and usability of the command-line interface for managing genesis validators in the Mitosis chain.
- Introduced `add-contract` command to allow users to add smart contracts to the genesis file using Foundry compilation artifacts.
- Updated `README.md` to include detailed usage instructions for the new command, including examples and flags for initial balance and bytecode options.
- Enhanced `AllocatedAccount` struct to accommodate contract code and storage in the genesis configuration.

These changes improve the functionality of the Mitosis chain by enabling seamless integration of smart contracts during the genesis setup process.
@riemannulus riemannulus self-assigned this Jul 31, 2025
Copilot AI review requested due to automatic review settings July 31, 2025 20:23
Copy link
Contributor

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

This PR refactors the genesis validator command structure and adds support for pre-deploying smart contracts to the Ethereum genesis block. The changes introduce a new command hierarchy where validator-related commands are grouped under the genesis subcommand, and adds a new add-contract command for deploying contracts from Foundry artifacts.

Key changes:

  • Restructures the add-genesis-validator command to be genesis add-validator
  • Adds a new genesis add-contract command for deploying smart contracts to genesis
  • Updates Ethereum genesis specification to support contract code and storage

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
x/evmvalidator/client/cli/genesis.go Updates command name and example usage for validator addition
infra/localnet/mitosisd/setup.sh Updates script to use new validator command structure
infra/devnet/mitosisd/init.sh Updates script to use new validator command structure
cmd/mitosisd/cmd/eth_genesis.go Extends AllocatedAccount struct to support contract code and storage
cmd/mitosisd/cmd/commands.go Refactors command structure to group genesis commands and adds contract command
cmd/mitosisd/cmd/add_contract.go Implements new command for adding smart contracts to genesis from Foundry artifacts
cmd/mitosisd/README.md Adds comprehensive documentation for the new contract deployment feature
Comments suppressed due to low confidence (1)

cmd/mitosisd/cmd/add_contract.go:88

  • The new contract addition functionality lacks test coverage. Consider adding unit tests to verify artifact parsing, bytecode extraction, and genesis file modification behavior.
	bytecode, err := readBytecodeFromArtifact(artifactFile, useCreationCode)  

@codecov
Copy link

codecov bot commented Jul 31, 2025

Codecov Report

❌ Patch coverage is 59.75610% with 99 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/mitosisd/cmd/add_contract.go 50.69% 67 Missing and 4 partials ⚠️
cmd/mitosisd/cmd/util.go 76.28% 16 Missing and 7 partials ⚠️
cmd/mitosisd/cmd/commands.go 0.00% 3 Missing ⚠️
x/evmvalidator/client/cli/genesis.go 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@riemannulus riemannulus marked this pull request as draft July 31, 2025 20:32
- Improved the `runAddContract` function to validate and sanitize artifact file paths, enhancing security against path traversal attacks.
- Introduced `validateFilePath` and `validateArtifactFile` functions to ensure proper file handling and size limits for artifact and genesis files.
- Updated the `writeGenesisFile` function to include path validation and secure file permissions, ensuring safer file operations.
- Added a new utility file `util.go` containing helper functions for file validation and safe copying, promoting code reusability and maintainability.

These changes strengthen the security and reliability of the contract addition process in the Mitosis chain, ensuring safer interactions with file systems.
@riemannulus riemannulus force-pushed the feat/mitosisd/support-pre-deploy-sc branch from 0ca40a9 to 85509e0 Compare August 1, 2025 18:32
- Improved path validation in `readBytecodeFromArtifact` and `readGenesisFile` functions to prevent path traversal attacks by sanitizing input paths.
- Updated directory creation permissions in `safeCopyFile` to restrict access to owner only, enhancing security for file operations.
- These changes strengthen the security posture of the Mitosis chain by ensuring safer file handling practices.
… file validation

- Introduced new test files `add_contract_test.go` and `util_test.go` to validate the functionality of contract addition and file handling.
- Implemented tests for `NewAddContractCmd`, `readBytecodeFromArtifact`, and `readGenesisFile` functions, ensuring robust error handling and validation.
- Enhanced file validation tests to cover various scenarios, including path traversal attempts and invalid file formats, improving security and reliability.
- These additions strengthen the testing framework for the Mitosis chain, ensuring safer interactions with smart contracts and file systems.
@riemannulus riemannulus force-pushed the feat/mitosisd/support-pre-deploy-sc branch from 5c45d4b to 6e44117 Compare August 1, 2025 19:14
@riemannulus riemannulus marked this pull request as ready for review August 1, 2025 19:20
@riemannulus riemannulus closed this Aug 7, 2025
@riemannulus riemannulus reopened this Aug 7, 2025
@riemannulus riemannulus merged commit 062c639 into main Aug 7, 2025
15 of 16 checks passed
@riemannulus riemannulus deleted the feat/mitosisd/support-pre-deploy-sc branch August 7, 2025 20:08
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