-
Notifications
You must be signed in to change notification settings - Fork 6
feat(cmd/mitosisd): add pre compiled contract on eth genesis #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- 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.
There was a problem hiding this 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-validatorcommand to begenesis add-validator - Adds a new
genesis add-contractcommand 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 Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
- 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.
0ca40a9 to
85509e0
Compare
- 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.
5c45d4b to
6e44117
Compare
Usage:
mitosisd genesis add-contract [address] [artifact-file]Examples:
mitosisd genesis add-contract 0x1234567890123456789012345678901234567890 /protocol/out/ValidatorManager.sol/ValidatorManager.json