Skip to content

feat(initia move cli): add decode cli & add docker image to use cli in docker container #208

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

djm07073
Copy link
Contributor

@djm07073 djm07073 commented May 26, 2025

  • add missed feature: add decoding feature in initia-move-cli
  • add docker image to use cli in docker container

Summary by CodeRabbit

  • New Features

    • Introduced a Decode subcommand for reading and decoding Move modules and scripts, outputting info and ABI in JSON.
    • Added a Dockerfile for containerized deployment of the CLI tool.
    • Integrated Docker image build and push into the release workflow.
  • Improvements

    • Improved command-line help formatting for clarity.
    • Expanded internal dependencies to support new functionality.
  • Documentation

    • Updated documentation to include Docker usage instructions, examples, and setup tips.

@djm07073 djm07073 requested a review from a team as a code owner May 26, 2025 05:56
Copy link

coderabbitai bot commented May 26, 2025

Walkthrough

This update adds a Docker build and push job to the CI workflow, integrates the libmovevm crate into the workspace, makes several libmovevm APIs public, and introduces a new decode subcommand in the initia-move-cli tool for decoding Move bytecode. It also adds a Dockerfile for the CLI tool and refines command handling and dependencies.

Changes

File(s) Change Summary
.github/workflows/move-cli.yml Added docker-build-push job to build and push Docker image after Linux build
Cargo.toml Added movevm as a workspace dependency
libmovevm/src/lib.rs Made move_api module public
libmovevm/src/move_api/handler.rs Changed visibility of decoding functions from pub(crate) to pub
tools/initia-move-cli/Cargo.toml Added workspace dependencies: movevm, serde, serde_json
tools/initia-move-cli/Dockerfile Added new Dockerfile for initia-move-cli tool
tools/initia-move-cli/src/decode.rs Added new decode module with CLI commands to read and decode Move bytecode
tools/initia-move-cli/src/execute.rs Simplified execute method signature and added unreachable match arm
tools/initia-move-cli/src/main.rs Added Decode subcommand, reordered and updated CLI struct fields and main error handling
tools/initia-move-cli/README.md Added Docker usage instructions section and reorganized CLI usage documentation

Poem

🐇 In code we hop, with bytes to crack,
New commands to read, no byte we lack.
Docker images rise, in workflows they fly,
MoveVM’s secrets now public and nigh.
CLI grows strong, with decode in sight,
Building and pushing, all day and night! 🚀🐰

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@djm07073 djm07073 changed the title feat(initia move cli): add decode cli && add docker image to use cli in docker container feat(initia move cli): add decode cli & add docker image to use cli in docker container May 26, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (2)
tools/initia-move-cli/Dockerfile (1)

7-11: Enhance container security by using a non-root user
For better security posture, consider creating a dedicated non-root user and switching to it before setting the ENTRYPOINT.
Example diff:

 RUN chmod +x initia-move-cli
+
+RUN addgroup --system app && adduser --system --ingroup app app \
+  && chown app:app initia-move-cli
+
+USER app
.github/workflows/move-cli.yml (1)

144-144: Add a newline at end of file
YAML linter warns about missing end-of-line character. Please ensure a newline is present at the end of the file.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 144-144: no new line character at the end of file

(new-line-at-end-of-file)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 06343d8 and 8def282.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (9)
  • .github/workflows/move-cli.yml (1 hunks)
  • Cargo.toml (1 hunks)
  • libmovevm/src/lib.rs (2 hunks)
  • libmovevm/src/move_api/handler.rs (5 hunks)
  • tools/initia-move-cli/Cargo.toml (1 hunks)
  • tools/initia-move-cli/Dockerfile (1 hunks)
  • tools/initia-move-cli/src/decode.rs (1 hunks)
  • tools/initia-move-cli/src/execute.rs (2 hunks)
  • tools/initia-move-cli/src/main.rs (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
libmovevm/src/lib.rs (1)
libmovevm/src/memory.rs (2)
  • destroy_unmanaged_vector (275-277)
  • new_unmanaged_vector (256-272)
tools/initia-move-cli/src/main.rs (1)
tools/initia-move-cli/src/decode.rs (2)
  • decode (58-58)
  • decode (68-120)
🪛 YAMLlint (1.37.1)
.github/workflows/move-cli.yml

[error] 144-144: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (18)
tools/initia-move-cli/Dockerfile (1)

1-11: Minimalist Dockerfile is well-structured
The base image and package installs are lean, and the entrypoint is correctly set.

Cargo.toml (1)

66-66: Root workspace dependency added correctly
The movevm crate is now included under [workspace.dependencies] matching the workspace member in Cargo.toml. No version conflicts detected.

.github/workflows/move-cli.yml (1)

106-144: CI workflow step docker-build-push looks correct
The job correctly downloads the AMD64 artifact, extracts the binary, and builds/pushes the Docker image.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 144-144: no new line character at the end of file

(new-line-at-end-of-file)

tools/initia-move-cli/Cargo.toml (1)

24-27: New CLI dependencies integrated correctly
The movevm, serde, and serde_json workspace dependencies are added in alignment with the decoding feature. Dependency ordering is consistent.

libmovevm/src/lib.rs (1)

3-4: Reordered modules and exports improve clarity
The move_api module is now public, and key APIs are cleanly re-exported. This enhances discoverability without altering functionality.

Also applies to: 19-26

tools/initia-move-cli/src/execute.rs (3)

1-1: LGTM: Import simplification

The removal of explicit anyhow::Error import is appropriate since anyhow::Result<()> is equivalent to anyhow::Result<(), Error>.


10-10: LGTM: Return type simplification

The simplified return type anyhow::Result<()> is cleaner and equivalent to the previous explicit error type.


17-17: LGTM: Defensive programming with unreachable arm

The unreachable!() arm is appropriate here since the Decode commands are now handled separately in the main function's dispatch logic, ensuring this match only receives the commands it's designed to handle.

libmovevm/src/move_api/handler.rs (3)

20-31: LGTM: Appropriate API exposure for CLI integration

Making read_module_info public enables the CLI decode functionality. The function provides safe module information extraction with proper error handling.


84-90: LGTM: Script decoding API made public

The decode_script_bytes function is appropriately made public to support CLI script decoding operations with proper error handling.


92-98: LGTM: Module decoding API made public

The decode_module_bytes function is correctly exposed for CLI module decoding functionality with consistent error handling patterns.

tools/initia-move-cli/src/main.rs (3)

2-2: LGTM: Clean module integration

The decode module import properly integrates the new functionality into the CLI structure.


17-35: LGTM: Well-structured command enum extension

The addition of the Decode command variant and consistent flatten_help = true attributes across all commands improve the CLI help system's consistency.


49-56: LGTM: Clean command dispatch logic

The main function properly separates decode operations from other commands, providing clear separation of concerns. The pattern matching handles all command variants appropriately.

tools/initia-move-cli/src/decode.rs (4)

7-16: LGTM: Well-structured command definition

The Decode struct and command configuration provide clear documentation and proper CLI structure for the decode functionality.


18-55: LGTM: Comprehensive subcommand definitions

The DecodeCommands enum provides well-documented subcommands with helpful examples and clear argument specifications.


61-65: LGTM: Robust file reading with proper error context

The read_file function correctly handles path resolution and provides meaningful error messages using with_context.


118-118: LGTM: Appropriate use of unreachable

The unreachable!() arm is justified here since the main function's dispatch logic ensures only Decode commands reach this method.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (4)
tools/initia-move-cli/src/decode.rs (4)

103-105: Address the identified path traversal vulnerability.

The path construction using user-provided package_name and module_name still lacks input validation, which was previously flagged as a security concern.


129-132: Apply consistent input validation for script subcommand.

The path construction for the Script subcommand also needs the same input validation as identified in previous reviews.


143-144: Apply consistent input validation for module subcommand.

The Module subcommand path construction requires the same security validation as previously identified.


115-117: Fix the hex conversion type casting bug.

The hex conversion logic still has the type casting issue where as_u64() is called on byte values that should be cast to u8.

🧹 Nitpick comments (3)
tools/initia-move-cli/src/decode.rs (3)

153-153: Consider removing unreachable!() or improving error handling.

The unreachable!() statement suggests this method should only be called with Decode commands, but this constraint isn't enforced by the type system. Consider either making this a more specific method or handling unexpected cases more gracefully.

-            _ => unreachable!(),
+            _ => Err(anyhow::anyhow!("decode() called with non-Decode command")),

109-121: Extract address conversion logic into a helper function.

The address conversion logic could be extracted to reduce code complexity and improve reusability.

+fn convert_address_to_hex(json: &mut serde_json::Value) {
+    if let Some(address) = json.get_mut("address") {
+        if let serde_json::Value::Array(bytes) = address {
+            let hex = format!(
+                "0x{}",
+                bytes
+                    .iter()
+                    .filter_map(|b| b.as_u64().map(|n| n as u8))
+                    .map(|b| format!("{:02x}", b))
+                    .collect::<String>()
+            );
+            *address = serde_json::json!(hex);
+        }
+    }
+}

                        let mut json: serde_json::Value = serde_json::from_slice(&result)?;
-                        if let Some(address) = json.get_mut("address") {
-                            if let serde_json::Value::Array(bytes) = address {
-                                let hex = format!(
-                                    "0x{}",
-                                    bytes
-                                        .iter()
-                                        .filter_map(|b| b.as_u64())
-                                        .map(|b| format!("{:02x}", b))
-                                        .collect::<String>()
-                                );
-                                *address = serde_json::json!(hex);
-                            }
-                        }
+                        convert_address_to_hex(&mut json);

98-149: Consider consolidating similar decode operations.

The Read and Module commands have very similar logic except for the address conversion step. Consider extracting common functionality to reduce duplication.

You could create a helper function like:

fn decode_module_with_options(
    package_name: &str,
    module_name: &str, 
    package_path: &Option<PathBuf>,
    convert_address: bool
) -> anyhow::Result<()> {
    let path = format!("build/{}/bytecode_modules/{}.mv", package_name, module_name);
    let bytes = read_file(package_path, &path)?;
    
    let result = if convert_address {
        read_module_info(&bytes)?
    } else {
        decode_module_bytes(bytes)?
    };
    
    let mut json: serde_json::Value = serde_json::from_slice(&result)?;
    
    if convert_address {
        convert_address_to_hex(&mut json);
    }
    
    println!("{}", serde_json::to_string_pretty(&json)?);
    Ok(())
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8cb4952 and b461ee2.

📒 Files selected for processing (1)
  • tools/initia-move-cli/src/decode.rs (1 hunks)

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