0xMiden / 0xMiden/compiler

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

Abierto
#342 4 comentarios 0 reacciones 1 asignado Reclamado por @bitwalker Ver en GitHub
Lenguaje dominante
Rust
Estrellas
115
Forks
84
Merge medio
1 d 8 h
PR fusionados (30 d)
15

Descripción

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/account@1.0.0#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

```rust
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/account@1.0.0#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`.

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

The issue is in frontend/wasm/src/miden_abi/mod.rs. Start by understanding the current hard-coded mapping from Wasm CM interface names to MASM module IDs. Research the WIT interface format and design a parser to generically convert names like 'miden:core-import/account@1.0.0#add-asset' to 'miden::account::add_asset', handling special cases for underscores and digits. Check for existing tests around this module to ensure compatibility.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
rust, wasm
Área
backend, compilers
Tipo de issue
Refactorización
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.