Skip to content
This repository has been 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 opened this issue Apr 14, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@jewelzms
Copy link

🐛 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())
            }
        ...
    }
@jewelzms jewelzms added the bug Something isn't working label Apr 14, 2023
@ksolana
Copy link
Contributor

ksolana commented Aug 25, 2023

can you provide a full reproducer. how did you point run_hello.move file to the move compiler?

jewelzms added a commit to jewelzms/move that referenced this issue Aug 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants