Skip to content
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

Recover the MASM module path and function names from the Wasm CM interface #342

Open
greenhat opened this issue Oct 11, 2024 · 0 comments
Open
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Milestone

Comments

@greenhat
Copy link
Contributor

Introduced in #329

Why

To pull the Rust Miden SDK through the Wasm CM, we have to provide the WIT interface with Wasm CM style names. E.g. miden::account::add_asset became miden:core-import/[email protected]#add-asset, etc. In the frontend, we need to recover the original MASM module path from the Wasm CM interface and function names.

How

The current "quick and dirty" hard-coded way is error-prone.
https://github.com/0xPolygonMiden/compiler/blob/next/frontend-wasm/src/miden_abi/mod.rs

    let module_id = if wasm_module_id.starts_with("miden:core-import/intrinsics-mem") {
        intrinsics::mem::MODULE_ID
    } else if wasm_module_id.starts_with("miden:core-import/intrinsics-felt") {
        intrinsics::felt::MODULE_ID
    } else if wasm_module_id.starts_with("miden:core-import/account") {
        tx_kernel::account::MODULE_ID
    } else if wasm_module_id.starts_with("miden:core-import/note") {
        note::MODULE_ID
    } else if wasm_module_id.starts_with("miden:core-import/tx") {
        tx_kernel::tx::MODULE_ID
    } else if wasm_module_id.starts_with("miden:core-import/stdlib-mem") {
        stdlib::mem::MODULE_ID
    } else if wasm_module_id.starts_with("miden:core-import/stdlib-crypto-dsa-rpo-falcon") {
        stdlib::crypto::dsa::rpo_falcon::MODULE_ID
    } else if wasm_module_id.starts_with("miden:core-import/stdlib-crypto-hashes-blake3") {
        stdlib::crypto::hashes::blake3::MODULE_ID
    } else if wasm_module_id.starts_with("miden:core-import") {
        panic!(
            "unrecovered intrinsics or Miden SDK import module ID: {wasm_module_id}, function: \
             {wasm_function_id}"
        )
    } else {
        wasm_module_id
    };

I suggest parsing the WIT interface name and constructing the MASM module in a generic way. E.g. for miden:core-import/[email protected]#add-asset we need to construct miden::account::add_asset in the frontend.
We have more complicated case where the module name has underscores in it, e.g. miden:core-import/stdlib-crypto-dsa-rpo-falcon which should be converted to stdlib::crypto::dsa::rpo_falcon. We can encode the underscores as -underscore- in the WIT names.
For function names, besides converting - to _ we need to handle the inability to define a function name where the dashed part starts with a digit (e.g. hash-1to1, etc.). In this case, we can encode the hash_1to1 as hash-digit1to1 in the WIT names, digit1 to 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant