Recover the MASM module path and function names from the Wasm CM interface
- Lingua principale
- Rust
- Stelle
- 115
- Fork
- 84
- Merge medio
- 1g 8h
- PR unite (30g)
- 15
Descrizione
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`.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
L'issue si trova in frontend/wasm/src/miden_abi/mod.rs. Inizia comprendendo l'attuale mapping hardcoded dai nomi delle interfacce Wasm CM agli ID dei moduli MASM. Ricerca il formato dell'interfaccia WIT e progetta un parser per convertire genericamente nomi come 'miden:core-import/account@1.0.0#add-asset' in 'miden::account::add_asset', gestendo i casi speciali per gli underscore e le cifre. Controlla i test esistenti attorno a questo modulo per garantire la compatibilità.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- rust, wasm
- Ambito
- backend, compilers
- Tipo di issue
- Refactoring
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 45/100