Skip to content
This repository was archived by the owner on May 4, 2024. It is now read-only.
This repository was archived by the owner on May 4, 2024. It is now read-only.

[Bug] Abi cannot be generated when the script function name is different from the file name #1037

Open
@jewelzms

Description

@jewelzms

🐛 Bug

Description

  1. Abi cannot be generated when the script function name is different from the file name
  2. When multiple functions exist in one file, all function ABI content is the ABI content of the function with the same file name.

To reproduce

build generate ABI

# move build --abi

sample code
filename: run_hello.move, function: main

// scripts/run_hello.move
script {
    use std::debug;
    fun main() {
        debug::print<u8>(&10);
    }
}

Stack trace/error message

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', language/move-prover/move-abigen/src/abigen.rs:238:20
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected Behavior

Generate ABI file successfully, path: build/hello_world/abis/main.abi

Reason

Wrong way to get function bytecode by script file name, the script function bytecode should be obtained using the module name.

Error code segment

// language/move-prover/move-abigen/src/abigen.rs
    fn load_compiled_bytes(&self, module_env: &ModuleEnv<'env>) -> anyhow::Result<Vec<u8>> {
        match &self.options.in_memory_bytes {
            Some(map) => {
                let path =
                    PathBuf::from(module_env.get_source_path().to_string_lossy().to_string())
                        .file_stem()
                        .expect("file stem")
                        .to_string_lossy()
                        .to_string();
                Ok(map.get(&path).unwrap().clone())
        ...
    }

Fix suggestion

    fn load_compiled_bytes(&self, module_env: &ModuleEnv<'env>) -> anyhow::Result<Vec<u8>> {
        match &self.options.in_memory_bytes {
            Some(map) => {
                let name = module_env.get_full_name_str();
                Ok(map.get(&name).unwrap().clone())
            }
        ...
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions