From 313c33d5a83fc4c8ce7a7a521dfd2a6488918def Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Thu, 14 Nov 2024 14:59:08 +0200 Subject: [PATCH 01/17] fix: mark exported only functions that were exported from Wasm core module Close #351 --- frontend-wasm/src/module/build_ir.rs | 7 ++++++- frontend-wasm/src/module/mod.rs | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/frontend-wasm/src/module/build_ir.rs b/frontend-wasm/src/module/build_ir.rs index 2a7da134c..7aeea9701 100644 --- a/frontend-wasm/src/module/build_ir.rs +++ b/frontend-wasm/src/module/build_ir.rs @@ -124,7 +124,12 @@ pub fn build_ir_module( let func_name = &parsed_module.module.func_name(*func_index); let wasm_func_type = module_types[func_type.signature].clone(); let ir_func_type = ir_func_type(&wasm_func_type, &session.diagnostics)?; - let sig = ir_func_sig(&ir_func_type, CallConv::SystemV, Linkage::External); + let linkage = if parsed_module.module.is_exported_function(func_index) { + Linkage::External + } else { + Linkage::Internal + }; + let sig = ir_func_sig(&ir_func_type, CallConv::SystemV, linkage); let mut module_func_builder = module_builder.function(func_name.as_str(), sig.clone())?; let FunctionBodyData { validator, body } = body_data; let mut func_validator = validator.into_validator(Default::default()); diff --git a/frontend-wasm/src/module/mod.rs b/frontend-wasm/src/module/mod.rs index 58952595c..d55ec5895 100644 --- a/frontend-wasm/src/module/mod.rs +++ b/frontend-wasm/src/module/mod.rs @@ -199,6 +199,13 @@ impl Module { index.index() < self.num_imported_funcs } + pub fn is_exported_function(&self, index: &FuncIndex) -> bool { + self.exports.values().any(|export| match export { + EntityIndex::Function(func_id) => func_id == index, + _ => false, + }) + } + /// Convert a `DefinedTableIndex` into a `TableIndex`. #[inline] pub fn table_index(&self, defined_table: DefinedTableIndex) -> TableIndex { From 55f6c6e34e38cc61987cc92639eefe0674f90052 Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Thu, 14 Nov 2024 15:02:45 +0200 Subject: [PATCH 02/17] fix: refine `Component` imports and exports to reference module imports and exports and use proper Wasm CM names --- frontend-wasm/src/component/translator.rs | 53 +- hir/src/component/interface.rs | 3 +- hir/src/component/mod.rs | 78 +- sdk/stdlib-sys/src/intrinsics/felt.rs | 6 +- .../expected/rust_sdk/basic_wallet.hir | 94 ++- .../expected/rust_sdk/basic_wallet.masm | 687 +++++++++--------- .../expected/rust_sdk/basic_wallet.wat | 200 +++-- tests/integration/expected/rust_sdk/p2id.hir | 274 ++++--- tests/integration/expected/rust_sdk/p2id.wat | 276 ++++--- .../src/rust_masm_tests/components.rs | 7 +- .../src/rust_masm_tests/rust_sdk.rs | 14 +- .../src/rust_masm_tests/wit_sdk.rs | 11 +- .../rust-sdk/basic-wallet/src/bindings.rs | 242 ++++-- .../rust-sdk/basic-wallet/src/lib.rs | 14 +- .../basic-wallet/wit/basic-wallet.wit | 6 + .../rust-sdk/p2id-note/src/bindings.rs | 152 +++- .../rust-sdk/p2id-note/src/lib.rs | 10 +- .../rust-sdk/p2id-note/wit/p2id.wit | 1 + .../rust-sdk/wit-sdk/miden-core-import.wit | 2 + tools/cargo-miden/src/lib.rs | 1 + 20 files changed, 1313 insertions(+), 818 deletions(-) diff --git a/frontend-wasm/src/component/translator.rs b/frontend-wasm/src/component/translator.rs index ecb778b97..ec81c290f 100644 --- a/frontend-wasm/src/component/translator.rs +++ b/frontend-wasm/src/component/translator.rs @@ -26,7 +26,7 @@ use crate::{ module_env::ParsedModule, module_translation_state::ModuleTranslationState, types::{EntityIndex, FuncIndex}, - Module, ModuleImport, + Module, }, unsupported_diag, WasmTranslationConfig, }; @@ -117,7 +117,7 @@ impl<'a, 'data> ComponentTranslator<'a, 'data> { } } for (name, export) in &wasm_translation.component.exports { - self.build_export(export, name, &mut component_builder)?; + self.build_export(export, name, None, &mut component_builder)?; } Ok(component_builder.build()) } @@ -183,7 +183,21 @@ impl<'a, 'data> ComponentTranslator<'a, 'data> { self.config, self.session, )?; - component_builder.add_module(ir_module.into()).expect("module is already added"); + // Skip the shim and fixups core modules, they are a workaround for + // specify the core instance memory and reallod function for the lowering + + // TODO: + // Imported function from the shim has empty module name and "0" as a if name. + + if ir_module.name.as_str() != "wit-component:shim" + && ir_module.name.as_str() != "wit-component:fixups" + { + component_builder + .add_module(ir_module.into()) + .expect("module is already added"); + } else { + // dbg!(&ir_module.functions().collect::>()); + } } InstantiateModule::Import(..) => { unsupported_diag!( @@ -212,8 +226,18 @@ impl<'a, 'data> ComponentTranslator<'a, 'data> { options, } => { let module_import = module.imports.get(idx).expect("module import not found"); + let function_id = module.func_name(module_import.index.unwrap_func()).into(); + let function_id = FunctionIdent { + module: module.name(), + function: function_id, + }; + + // TODO: + // Find process_list_felt instead empty module name and "0" function name! + // Follow module_import.index through the shim modules/imports/exports? + let runtime_import_idx = self.lower_imports[index]; - let function_id = function_id_from_import(module_import); + // dbg!(&module_import); match self.translate_import( runtime_import_idx, *lower_ty, @@ -330,19 +354,25 @@ impl<'a, 'data> ComponentTranslator<'a, 'data> { &self, export: &Export, name: &String, + interface: Option, component_builder: &mut ComponentBuilder, ) -> WasmResult<()> { match export { Export::LiftedFunction { ty, func, options } => { - let export_name = Symbol::intern(name).into(); + dbg!(name); + // The inline export does no have an interface name + let interface = interface.unwrap_or_default(); + dbg!(&interface); + let export_name = InterfaceFunctionIdent::from_full(interface, name.clone()); let export = self.build_export_lifted_function(func, ty, options)?; component_builder.add_export(export_name, export); Ok(()) } Export::Instance(exports) => { + let interface = Some(name.clone()); // Flatten any(nested) interface instance exports into the IR `Component` exports - for (name, export) in exports { - self.build_export(export, name, component_builder)?; + for (export_name, export) in exports { + self.build_export(export, export_name, interface.clone(), component_builder)?; } Ok(()) } @@ -371,10 +401,10 @@ impl<'a, 'data> ComponentTranslator<'a, 'data> { ty: &TypeFuncIndex, options: &CanonicalOptions, ) -> WasmResult { - let func_ident = self.func_id_from_core_def(func)?; + let core_func_ident = self.func_id_from_core_def(func)?; let lifted_func_ty = convert_lifted_func_ty(ty, &self.component_types); let export = midenc_hir::ComponentExport { - function: func_ident, + function: core_func_ident, function_ty: lifted_func_ty, options: self.translate_canonical_options(options)?, }; @@ -444,11 +474,6 @@ impl<'a, 'data> ComponentTranslator<'a, 'data> { } } -/// Get the function id from the given Wasm core module import -fn function_id_from_import(module_import: &ModuleImport) -> FunctionIdent { - recover_imported_masm_function_id(&module_import.module, module_import.field.as_str()) -} - /// Get the function id from the given Wasm func_idx in the given Wasm core exporting_module fn function_id_from_export(exporting_module: &Module, func_idx: FuncIndex) -> FunctionIdent { let func_name = exporting_module.func_name(func_idx); diff --git a/hir/src/component/interface.rs b/hir/src/component/interface.rs index 384d358a7..c05c50d97 100644 --- a/hir/src/component/interface.rs +++ b/hir/src/component/interface.rs @@ -30,7 +30,7 @@ impl fmt::Debug for InterfaceIdent { } impl fmt::Display for InterfaceIdent { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "\"{}\"", self.full_name.as_str().escape_default()) + write!(f, "{}", self.full_name.as_str().escape_default()) } } @@ -72,7 +72,6 @@ impl PrettyPrint for InterfaceFunctionIdent { flatten( const_text("(") + display(self.interface) - + const_text(" ") + text(format!("#{}", self.function)) + const_text(")"), ) diff --git a/hir/src/component/mod.rs b/hir/src/component/mod.rs index 71ebc7c5c..cc9d25fe4 100644 --- a/hir/src/component/mod.rs +++ b/hir/src/component/mod.rs @@ -23,6 +23,27 @@ pub struct CanonicalOptions { pub post_return: Option, } +impl fmt::Display for CanonicalOptions { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.pretty_print(f) + } +} + +impl formatter::PrettyPrint for CanonicalOptions { + fn render(&self) -> formatter::Document { + use crate::formatter::*; + + let mut doc = Document::Empty; + if let Some(realloc) = self.realloc.as_ref() { + doc += const_text("(realloc ") + display(realloc) + const_text(") "); + } + if let Some(post_return) = self.post_return.as_ref() { + doc += const_text("(post-return ") + display(post_return) + const_text(") "); + } + doc + } +} + /// A component import translated from a Wasm component import that is following /// the Wasm Component Model Canonical ABI. #[derive(Debug, Clone)] @@ -118,12 +139,6 @@ impl formatter::PrettyPrint for ComponentImport { } } -/// The name of a exported function -#[derive( - Debug, Clone, Ord, PartialEq, PartialOrd, Eq, Hash, derive_more::From, derive_more::Into, -)] -pub struct FunctionExportName(Symbol); - /// A component export #[derive(Debug)] pub struct ComponentExport { @@ -135,6 +150,21 @@ pub struct ComponentExport { pub options: CanonicalOptions, } +impl formatter::PrettyPrint for ComponentExport { + fn render(&self) -> formatter::Document { + use crate::formatter::*; + + flatten( + display(self.function) + + const_text(" ") + + text(format!("{}", self.function_ty)) + + const_text(" ") + + text(format!("{}", self.options)) + + const_text(" "), + ) + } +} + /// A [Component] is a collection of [Module]s that are being compiled together as a package and /// have exports/imports. #[derive(Default)] @@ -143,11 +173,11 @@ pub struct Component { /// The modules should be stored in a topological order modules: IndexMap>, - /// A list of this component's imports, indexed by function identifier + /// A list of this component's imports, indexed by module function identifier imports: BTreeMap, /// A list of this component's exports, indexed by export name - exports: BTreeMap, + exports: BTreeMap, } impl Component { @@ -186,7 +216,7 @@ impl Component { &self.imports } - pub fn exports(&self) -> &BTreeMap { + pub fn exports(&self) -> &BTreeMap { &self.exports } @@ -239,16 +269,32 @@ impl formatter::PrettyPrint for Component { .map(|doc| const_text(";; Modules") + nl() + doc) .unwrap_or(Document::Empty); - let body = vec![imports, modules].into_iter().filter(|section| !section.is_empty()).fold( - nl(), - |a, b| { + let exports = self + .exports + .iter() + .map(|(name, export)| { + const_text("(") + + const_text("lift") + + const_text(" ") + + name.render() + + const_text(" ") + + export.render() + + const_text(")") + }) + .reduce(|acc, doc| acc + nl() + doc) + .map(|doc| const_text(";; Component Exports") + nl() + doc) + .unwrap_or(Document::Empty); + + let body = vec![imports, modules, exports] + .into_iter() + .filter(|section| !section.is_empty()) + .fold(nl(), |a, b| { if matches!(a, Document::Newline) { indent(4, a + b) } else { a + nl() + indent(4, nl() + b) } - }, - ); + }); let header = const_text("(") + const_text("component") + const_text(" "); @@ -267,7 +313,7 @@ impl formatter::PrettyPrint for Component { pub struct ComponentBuilder<'a> { modules: IndexMap>, imports: BTreeMap, - exports: BTreeMap, + exports: BTreeMap, entry: Option, diagnostics: &'a DiagnosticsHandler, } @@ -333,7 +379,7 @@ impl<'a> ComponentBuilder<'a> { self.imports.insert(function_id, import); } - pub fn add_export(&mut self, name: FunctionExportName, export: ComponentExport) { + pub fn add_export(&mut self, name: InterfaceFunctionIdent, export: ComponentExport) { self.exports.insert(name, export); } diff --git a/sdk/stdlib-sys/src/intrinsics/felt.rs b/sdk/stdlib-sys/src/intrinsics/felt.rs index 910b60517..a1abd3330 100644 --- a/sdk/stdlib-sys/src/intrinsics/felt.rs +++ b/sdk/stdlib-sys/src/intrinsics/felt.rs @@ -4,7 +4,7 @@ use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAss #[link(wasm_import_module = "miden:core-import/intrinsics-felt@1.0.0")] extern "C" { - #[link_name = "from_u64_unchecked"] + #[link_name = "from-u64-unchecked"] fn extern_from_u64_unchecked(value: u64) -> Felt; #[link_name = "as_u64"] @@ -49,7 +49,7 @@ extern "C" { #[link_name = "le"] fn extern_le(a: Felt, b: Felt) -> i32; - #[link_name = "is_odd"] + #[link_name = "is-odd"] fn extern_is_odd(a: Felt) -> i32; #[link_name = "assert"] @@ -58,7 +58,7 @@ extern "C" { #[link_name = "assertz"] fn extern_assertz(a: Felt); - #[link_name = "assert_eq"] + #[link_name = "assert-eq"] fn extern_assert_eq(a: Felt, b: Felt); } diff --git a/tests/integration/expected/rust_sdk/basic_wallet.hir b/tests/integration/expected/rust_sdk/basic_wallet.hir index 0ecee7713..c05ddb0e8 100644 --- a/tests/integration/expected/rust_sdk/basic_wallet.hir +++ b/tests/integration/expected/rust_sdk/basic_wallet.hir @@ -1,15 +1,15 @@ (component ;; Component Imports - (lower ( (type (func (abi canon) (result u32)))) (#intrinsics::mem #heap_base) - (lower ( (type (func (abi canon) (param felt) (param felt) (param felt) (param felt) (result felt felt felt felt)))) (#miden::account #add_asset) - (lower ( (type (func (abi canon) (param felt) (param felt) (param felt) (param felt) (result felt felt felt felt)))) (#miden::account #remove_asset) - (lower ( (type (func (abi canon) (param felt) (param felt) (param felt) (param felt) (param felt) (param felt) (param felt) (param felt) (param felt) (param felt) (result felt)))) (#miden::tx #create_note) - (lower ( (type (func (abi canon) (param i32) (param i32) (param i32) (param i32) (param i32) (param i32) (param i32) (param i32) (result i32 i32 i32 i32 i32 i32 i32 i32)))) (#std::crypto::hashes::blake3 #hash_1to1) + (lower ( (type (func (abi canon) (param felt) (param felt) (param felt) (param felt) (param felt) (param felt) (param felt) (param felt) (param felt) (param felt) (result felt)))) (#basic_wallet #miden_base_sys::bindings::tx::extern_tx_create_note) + (lower ( (type (func (abi canon) (param felt) (param felt) (param felt) (param felt) (result felt felt felt felt)))) (#basic_wallet #miden_base_sys::bindings::account::extern_account_add_asset) + (lower ( (type (func (abi canon) (param felt) (param felt) (param felt) (param felt) (result felt felt felt felt)))) (#basic_wallet #miden_base_sys::bindings::account::extern_account_remove_asset) + (lower ( (type (func (abi canon) (result u32)))) (#basic_wallet #miden_sdk_alloc::heap_base) + (lower ( (type (func (abi canon) (param i32) (param i32) (param i32) (param i32) (param i32) (param i32) (param i32) (param i32) (result i32 i32 i32 i32 i32 i32 i32 i32)))) (#basic_wallet #miden_stdlib_sys::stdlib::crypto::hashes::extern_blake3_hash_1to1) ;; Modules (module #basic_wallet ;; Data Segments - (data (mut) (offset 1048576) 0x010000000100000001000000010000000100000001000000010000000100000002000000) + (data (mut) (offset 1048576) 0x01000000010000000100000001000000010000000100000001000000010000000100000002000000) ;; Constants (const (id 0) 0x00100000) @@ -18,7 +18,7 @@ (global (export #__stack_pointer) (id 0) (type i32) (const 0)) ;; Functions - (func (export #__wasm_call_ctors) + (func #__wasm_call_ctors (block 0 (br (block 1))) @@ -26,7 +26,7 @@ (ret)) ) - (func (export #basic_wallet::bindings::__link_custom_section_describing_imports) + (func #basic_wallet::bindings::__link_custom_section_describing_imports (block 0 (br (block 1))) @@ -35,9 +35,9 @@ (ret)) ) - (func (export #__rust_alloc) (param i32) (param i32) (result i32) + (func #__rust_alloc (param i32) (param i32) (result i32) (block 0 (param v0 i32) (param v1 i32) - (let (v3 i32) (const.i32 1048620)) + (let (v3 i32) (const.i32 1048624)) (let (v4 i32) (call #::alloc v3 v1 v0)) (br (block 1 v4))) @@ -45,7 +45,7 @@ (ret v2)) ) - (func (export #__rust_dealloc) (param i32) (param i32) (param i32) + (func #__rust_dealloc (param i32) (param i32) (param i32) (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (br (block 1))) @@ -53,10 +53,10 @@ (ret)) ) - (func (export #__rust_realloc) + (func #__rust_realloc (param i32) (param i32) (param i32) (param i32) (result i32) (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (param v3 i32) - (let (v5 i32) (const.i32 1048620)) + (let (v5 i32) (const.i32 1048624)) (let (v6 i32) (call #::alloc v5 v2 v3)) (let (v7 i1) (eq v6 0)) (let (v8 i32) (zext v7)) @@ -85,9 +85,9 @@ (br (block 2 v6))) ) - (func (export #__rust_alloc_zeroed) (param i32) (param i32) (result i32) + (func #__rust_alloc_zeroed (param i32) (param i32) (result i32) (block 0 (param v0 i32) (param v1 i32) - (let (v3 i32) (const.i32 1048620)) + (let (v3 i32) (const.i32 1048624)) (let (v4 i32) (call #::alloc v3 v1 v0)) (let (v5 i1) (eq v4 0)) (let (v6 i32) (zext v5)) @@ -245,7 +245,7 @@ (ret)) ) - (func (export #miden:basic-wallet/basic-wallet@1.0.0#test-felt-intrinsics) + (func (export #miden:basic-wallet/aux@1.0.0#test-felt-intrinsics) (param felt) (param felt) (result felt) (block 0 (param v0 felt) (param v1 felt) (call #wit_bindgen_rt::run_ctors_once) @@ -256,7 +256,7 @@ (ret v2)) ) - (func (export #miden:basic-wallet/basic-wallet@1.0.0#test-stdlib) + (func (export #miden:basic-wallet/aux@1.0.0#test-stdlib) (param i32) (param i32) (result i32) (block 0 (param v0 i32) (param v1 i32) (let (v3 i32) (const.i32 0)) @@ -477,18 +477,27 @@ (let (v166 (ptr i64)) (inttoptr v164)) (let (v167 i64) (load v166)) (let (v168 u32) (bitcast v162)) - (let (v169 u32) (add.checked v168 1048612)) + (let (v169 u32) (add.checked v168 1048616)) (let (v170 u32) (mod.unchecked v169 4)) (assertz 250 v170) (let (v171 (ptr i64)) (inttoptr v169)) (store v171 v167) (let (v172 (ptr i32)) (global.symbol #__stack_pointer)) (store v172 v4) - (let (v173 i32) (const.i32 1048612)) + (let (v173 i32) (const.i32 1048616)) (ret v173)) ) - (func (export #cabi_post_miden:basic-wallet/basic-wallet@1.0.0#test-stdlib) + (func (export #miden:basic-wallet/aux@1.0.0#process-list-felt) + (param i32) (param i32) (result i32) + (block 0 (param v0 i32) (param v1 i32) + (call #wit_bindgen_rt::run_ctors_once) + (unreachable)) + + (block 1 (param v2 i32)) + ) + + (func (export #cabi_post_miden:basic-wallet/aux@1.0.0#process-list-felt) (param i32) (block 0 (param v0 i32) (br (block 1))) @@ -507,7 +516,7 @@ (ret v4)) ) - (func (export #wit_bindgen_rt::cabi_realloc) + (func #wit_bindgen_rt::cabi_realloc (param i32) (param i32) (param i32) (param i32) (result i32) (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (param v3 i32) (let (v5 i1) (neq v1 0)) @@ -536,7 +545,7 @@ (block 6 (let (v9 i32) (const.i32 0)) (let (v10 u32) (bitcast v9)) - (let (v11 u32) (add.checked v10 1048624)) + (let (v11 u32) (add.checked v10 1048628)) (let (v12 (ptr u8)) (inttoptr v11)) (let (v13 u8) (load v12)) (let (v14 i32) (zext v13)) @@ -547,11 +556,11 @@ (unreachable)) ) - (func (export #wit_bindgen_rt::run_ctors_once) + (func #wit_bindgen_rt::run_ctors_once (block 0 (let (v0 i32) (const.i32 0)) (let (v1 u32) (bitcast v0)) - (let (v2 u32) (add.checked v1 1048625)) + (let (v2 u32) (add.checked v1 1048629)) (let (v3 (ptr u8)) (inttoptr v2)) (let (v4 u8) (load v3)) (let (v5 i32) (zext v4)) @@ -571,13 +580,13 @@ (let (v9 u32) (bitcast v8)) (let (v10 u8) (trunc v9)) (let (v11 u32) (bitcast v7)) - (let (v12 u32) (add.checked v11 1048625)) + (let (v12 u32) (add.checked v11 1048629)) (let (v13 (ptr u8)) (inttoptr v12)) (store v13 v10) (br (block 2))) ) - (func (export #::alloc) + (func #::alloc (param i32) (param i32) (param i32) (result i32) (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (let (v4 i32) (const.i32 0)) @@ -676,7 +685,7 @@ (br (block 7 v66))) ) - (func (export #miden_base_sys::bindings::account::add_asset) + (func #miden_base_sys::bindings::account::add_asset (param i32) (param i32) (block 0 (param v0 i32) (param v1 i32) (let (v2 u32) (bitcast v1)) @@ -721,7 +730,7 @@ (ret)) ) - (func (export #miden_base_sys::bindings::account::remove_asset) + (func #miden_base_sys::bindings::account::remove_asset (param i32) (param i32) (block 0 (param v0 i32) (param v1 i32) (let (v2 u32) (bitcast v1)) @@ -766,7 +775,7 @@ (ret)) ) - (func (export #miden_base_sys::bindings::tx::create_note) + (func #miden_base_sys::bindings::tx::create_note (param i32) (param felt) (param felt) (param i32) (result felt) (block 0 (param v0 i32) @@ -826,7 +835,7 @@ (ret v4)) ) - (func (export #alloc::vec::Vec::into_boxed_slice) + (func #alloc::vec::Vec::into_boxed_slice (param i32) (param i32) (block 0 (param v0 i32) (param v1 i32) (let (v2 i32) (const.i32 0)) @@ -912,7 +921,7 @@ (br (block 3 v0 v36 v1 v5))) ) - (func (export # as core::ops::drop::Drop>::drop) + (func # as core::ops::drop::Drop>::drop (param i32) (block 0 (param v0 i32) (br (block 1))) @@ -921,7 +930,7 @@ (ret)) ) - (func (export # as core::ops::drop::Drop>::drop) + (func # as core::ops::drop::Drop>::drop (param i32) (block 0 (param v0 i32) (let (v1 i32) (const.i32 0)) @@ -953,7 +962,7 @@ (br (block 2))) ) - (func (export #alloc::raw_vec::RawVec::try_allocate_in) + (func #alloc::raw_vec::RawVec::try_allocate_in (param i32) (param i32) (param i32) (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (let (v3 i32) (const.i32 0)) @@ -1081,7 +1090,7 @@ (br (block 2 v41 v51 v69))) ) - (func (export #::allocate) + (func #::allocate (param i32) (param i32) (param i32) (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (let (v3 i32) (const.i32 0)) @@ -1127,7 +1136,7 @@ (ret)) ) - (func (export #alloc::alloc::Global::alloc_impl) + (func #alloc::alloc::Global::alloc_impl (param i32) (param i32) (param i32) (param i32) (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (param v3 i32) (let (v4 i1) (eq v2 0)) @@ -1163,7 +1172,7 @@ (block 5 (let (v8 i32) (const.i32 0)) (let (v9 u32) (bitcast v8)) - (let (v10 u32) (add.checked v9 1048624)) + (let (v10 u32) (add.checked v9 1048628)) (let (v11 (ptr u8)) (inttoptr v10)) (let (v12 u8) (load v11)) (let (v13 i32) (zext v12)) @@ -1171,7 +1180,7 @@ (br (block 2 v0 v2 v14))) ) - (func (export #alloc::raw_vec::RawVec::shrink_unchecked) + (func #alloc::raw_vec::RawVec::shrink_unchecked (param i32) (param i32) (param i32) (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (let (v3 i32) (const.i32 0)) @@ -1251,7 +1260,7 @@ (br (block 4 v1 v2 v22 v0))) ) - (func (export #::deallocate) + (func #::deallocate (param i32) (param i32) (param i32) (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (let (v3 i1) (eq v2 0)) @@ -1270,7 +1279,7 @@ (br (block 2))) ) - (func (export #alloc::raw_vec::handle_error) + (func #alloc::raw_vec::handle_error (param i32) (param i32) (block 0 (param v0 i32) (param v1 i32) (unreachable)) @@ -1300,4 +1309,11 @@ (param i32) (param i32) (param i32) (param i32) (param i32) (param i32) (param i32) (param i32) (result i32 i32 i32 i32 i32 i32 i32 i32)) ) + + ;; Component Exports + (lift (miden:basic-wallet/aux@1.0.0#process-list-felt) (#basic_wallet #miden:basic-wallet/aux@1.0.0#process-list-felt (func (abi wasm) (param (list (struct felt))) (result (list (struct felt)))) (realloc (#basic_wallet #cabi_realloc) (post-return (#basic_wallet #cabi_post_miden:basic-wallet/aux@1.0.0#process-list-felt) ) + (lift (miden:basic-wallet/aux@1.0.0#test-felt-intrinsics) (#basic_wallet #miden:basic-wallet/aux@1.0.0#test-felt-intrinsics (func (abi wasm) (param (struct felt)) (param (struct felt)) (result (struct felt))) ) + (lift (miden:basic-wallet/aux@1.0.0#test-stdlib) (#basic_wallet #miden:basic-wallet/aux@1.0.0#test-stdlib (func (abi wasm) (param (list u8)) (result (list u8))) (realloc (#basic_wallet #cabi_realloc) (post-return (#basic_wallet #cabi_post_miden:basic-wallet/aux@1.0.0#process-list-felt) ) + (lift (miden:basic-wallet/basic-wallet@1.0.0#receive-asset) (#basic_wallet #miden:basic-wallet/basic-wallet@1.0.0#receive-asset (func (abi wasm) (param (struct (struct (struct (struct felt) (struct felt) (struct felt) (struct felt)))))) ) + (lift (miden:basic-wallet/basic-wallet@1.0.0#send-asset) (#basic_wallet #miden:basic-wallet/basic-wallet@1.0.0#send-asset (func (abi wasm) (param (struct (struct (struct (struct felt) (struct felt) (struct felt) (struct felt))))) (param (struct (struct felt))) (param (struct (struct felt))) (param (struct (struct (struct (struct felt) (struct felt) (struct felt) (struct felt)))))) ) ) diff --git a/tests/integration/expected/rust_sdk/basic_wallet.masm b/tests/integration/expected/rust_sdk/basic_wallet.masm index 9b97ea36d..1bb984d41 100644 --- a/tests/integration/expected/rust_sdk/basic_wallet.masm +++ b/tests/integration/expected/rust_sdk/basic_wallet.masm @@ -5,12 +5,12 @@ use.miden::account use.miden::tx use.std::crypto::hashes::blake3 -export."basic_wallet::bindings::__link_custom_section_describing_imports" +proc."basic_wallet::bindings::__link_custom_section_describing_imports" end -export."miden_base_sys::bindings::tx::create_note" +proc."miden_base_sys::bindings::tx::create_note" dup.3 add.12 u32assert @@ -147,7 +147,7 @@ export."miden_base_sys::bindings::tx::create_note" end -export."miden_base_sys::bindings::account::remove_asset" +proc."miden_base_sys::bindings::account::remove_asset" dup.1 add.12 u32assert @@ -260,7 +260,7 @@ export."miden_base_sys::bindings::account::remove_asset" end -export."miden_base_sys::bindings::account::add_asset" +proc."miden_base_sys::bindings::account::add_asset" dup.1 add.12 u32assert @@ -373,7 +373,7 @@ export."miden_base_sys::bindings::account::add_asset" end -export."wit_bindgen_rt::cabi_realloc" +proc."wit_bindgen_rt::cabi_realloc" dup.1 neq.0 if.true @@ -408,9 +408,9 @@ export."wit_bindgen_rt::cabi_realloc" end -export."wit_bindgen_rt::run_ctors_once" +proc."wit_bindgen_rt::run_ctors_once" push.0 - add.1048625 + add.1048629 u32assert dup.0 u32mod.16 @@ -432,7 +432,7 @@ export."wit_bindgen_rt::run_ctors_once" push.128 u32and push.0 - add.1048625 + add.1048629 u32assert dup.0 u32mod.16 @@ -456,7 +456,7 @@ export."wit_bindgen_rt::run_ctors_once" end -export."alloc::vec::Vec::into_boxed_slice" +proc."alloc::vec::Vec::into_boxed_slice" dup.1 add.8 u32assert @@ -685,7 +685,7 @@ export."alloc::vec::Vec::into_boxed_slice" end -export."alloc::alloc::Global::alloc_impl" +proc."alloc::alloc::Global::alloc_impl" dup.2 eq.0 neq.0 @@ -808,12 +808,12 @@ export."alloc::alloc::Global::alloc_impl" end -export."alloc::raw_vec::handle_error" +proc."alloc::raw_vec::handle_error" push.0 assert end -export."alloc::raw_vec::RawVec::try_allocate_in" +proc."alloc::raw_vec::RawVec::try_allocate_in" mem_load.0x00011000 push.16 u32wrapping_sub @@ -1256,7 +1256,7 @@ export."alloc::raw_vec::RawVec::try_allocate_in" end -export."alloc::raw_vec::RawVec::shrink_unchecked" +proc."alloc::raw_vec::RawVec::shrink_unchecked" dup.1 dup.0 u32mod.4 @@ -1522,7 +1522,7 @@ export."alloc::raw_vec::RawVec::shrink_unchecked" end -export."::deallocate" +proc."::deallocate" dup.2 eq.0 neq.0 @@ -1534,7 +1534,7 @@ export."::deallocate" end -export."::allocate" +proc."::allocate" mem_load.0x00011000 push.16 u32wrapping_sub @@ -1641,12 +1641,12 @@ export."::allocate" end -export." as core::ops::drop::Drop>::drop" +proc." as core::ops::drop::Drop>::drop" dropw end -export." as core::ops::drop::Drop>::drop" +proc." as core::ops::drop::Drop>::drop" dup.0 dup.0 u32mod.4 @@ -1690,7 +1690,7 @@ export." as core::ops::drop::Drop>::drop" end -export."::alloc" +proc."::alloc" push.32 dup.2 push.32 @@ -1901,16 +1901,16 @@ export."::alloc" end -export."__rust_alloc" - push.1048620 +proc."__rust_alloc" + push.1048624 movup.2 swap.1 exec."::alloc" end -export."__rust_alloc_zeroed" - push.1048620 +proc."__rust_alloc_zeroed" + push.1048624 dup.1 swap.2 swap.3 @@ -1966,13 +1966,13 @@ export."__rust_alloc_zeroed" end -export."__rust_dealloc" +proc."__rust_dealloc" dropw dropw dropw end -export."__rust_realloc" - push.1048620 +proc."__rust_realloc" + push.1048624 dup.4 swap.2 swap.4 @@ -2055,12 +2055,12 @@ export."__rust_realloc" end -export."__wasm_call_ctors" +proc."__wasm_call_ctors" end -export."cabi_post_miden:basic-wallet/basic-wallet@1.0.0#test-stdlib" +export."cabi_post_miden:basic-wallet/aux@1.0.0#process-list-felt" dropw end @@ -2075,116 +2075,17 @@ export.cabi_realloc_wit_bindgen_0_28_0 end -export."miden:basic-wallet/basic-wallet@1.0.0#receive-asset" - mem_load.0x00011000 - push.64 - dup.1 - swap.1 - u32wrapping_sub - push.4294967264 - u32and - push.1114112 - dup.1 - swap.1 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::store_sw - dup.0 - add.12 - u32assert - exec."wit_bindgen_rt::run_ctors_once" - dup.1 - add.8 - u32assert - dup.1 - movup.8 - swap.1 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::store_felt - dup.2 - add.4 - u32assert - dup.1 - movup.8 - swap.1 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::store_felt - dup.3 - dup.1 - movup.8 - swap.1 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::store_felt - dup.0 - movup.7 - swap.1 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::store_felt - push.32 - dup.5 - swap.1 - u32wrapping_add - movup.5 - swap.1 - exec."miden_base_sys::bindings::account::add_asset" - push.1114112 - movup.5 - swap.1 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::store_sw - u32mod.4 - assertz.err=250 - u32mod.4 - assertz.err=250 - u32mod.4 - assertz.err=250 - u32mod.4 - assertz.err=250 +export."miden:basic-wallet/aux@1.0.0#process-list-felt" + exec."wit_bindgen_rt::run_ctors_once" push.0 assert end -export."miden:basic-wallet/basic-wallet@1.0.0#send-asset" +export."miden:basic-wallet/aux@1.0.0#test-felt-intrinsics" + exec."wit_bindgen_rt::run_ctors_once" swap.1 add +end + + +export."miden:basic-wallet/aux@1.0.0#test-stdlib" mem_load.0x00011000 push.96 dup.1 @@ -2205,102 +2106,14 @@ export."miden:basic-wallet/basic-wallet@1.0.0#send-asset" u32div.16 exec.::intrinsics::mem::store_sw dup.0 - add.12 + add.24 u32assert exec."wit_bindgen_rt::run_ctors_once" dup.1 - add.8 - u32assert - dup.1 - movup.8 - swap.1 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::store_felt - dup.2 - add.4 - u32assert - dup.1 - movup.8 - swap.1 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::store_felt - dup.3 - dup.1 - movup.8 - swap.1 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::store_felt - dup.4 - add.44 + add.20 u32assert dup.1 - movup.8 - swap.1 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::store_felt dup.5 - add.40 - u32assert - dup.1 - movup.14 - swap.1 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::store_felt - dup.6 - add.36 - u32assert - dup.1 - movup.14 - swap.1 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::store_felt - dup.7 - add.32 - u32assert - dup.1 - movup.14 swap.1 dup.0 u32mod.16 @@ -2310,122 +2123,9 @@ export."miden:basic-wallet/basic-wallet@1.0.0#send-asset" u32div.4 movup.2 u32div.16 - exec.::intrinsics::mem::store_felt - dup.0 - movup.13 - swap.1 - dup.0 - u32mod.16 + exec.::intrinsics::mem::store_sw dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::store_felt - push.64 - dup.9 - swap.1 - u32wrapping_add - dup.9 - swap.1 - exec."miden_base_sys::bindings::account::remove_asset" - push.32 - dup.9 - swap.1 - u32wrapping_add - push.64 - movup.10 - swap.1 - u32wrapping_add - movup.2 - swap.12 - movdn.2 - swap.1 - swap.3 - swap.11 - swap.1 - exec."miden_base_sys::bindings::tx::create_note" - drop - push.1114112 - movup.7 - swap.1 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::store_sw - movup.7 - u32mod.4 - assertz.err=250 - movup.6 - u32mod.4 - assertz.err=250 - u32mod.4 - assertz.err=250 - u32mod.4 - assertz.err=250 - u32mod.4 - assertz.err=250 - u32mod.4 - assertz.err=250 - u32mod.4 - assertz.err=250 - u32mod.4 - assertz.err=250 -end - - -export."miden:basic-wallet/basic-wallet@1.0.0#test-felt-intrinsics" - exec."wit_bindgen_rt::run_ctors_once" swap.1 add -end - - -export."miden:basic-wallet/basic-wallet@1.0.0#test-stdlib" - mem_load.0x00011000 - push.96 - dup.1 - swap.1 - u32wrapping_sub - push.4294967264 - u32and - push.1114112 - dup.1 - swap.1 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::store_sw - dup.0 - add.24 - u32assert - exec."wit_bindgen_rt::run_ctors_once" - dup.1 - add.20 - u32assert - dup.1 - dup.5 - swap.1 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::store_sw - dup.0 - dup.6 + dup.6 swap.1 dup.0 u32mod.16 @@ -2892,7 +2592,7 @@ export."miden:basic-wallet/basic-wallet@1.0.0#test-stdlib" u32div.16 exec.::intrinsics::mem::store_sw push.0 - add.1048612 + add.1048616 u32assert dup.9 add.8 @@ -2959,9 +2659,314 @@ export."miden:basic-wallet/basic-wallet@1.0.0#test-stdlib" assertz.err=250 u32mod.4 assertz.err=250 - push.1048612 + push.1048616 end end end +export."miden:basic-wallet/basic-wallet@1.0.0#receive-asset" + mem_load.0x00011000 + push.64 + dup.1 + swap.1 + u32wrapping_sub + push.4294967264 + u32and + push.1114112 + dup.1 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + dup.0 + add.12 + u32assert + exec."wit_bindgen_rt::run_ctors_once" + dup.1 + add.8 + u32assert + dup.1 + movup.8 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_felt + dup.2 + add.4 + u32assert + dup.1 + movup.8 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_felt + dup.3 + dup.1 + movup.8 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_felt + dup.0 + movup.7 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_felt + push.32 + dup.5 + swap.1 + u32wrapping_add + movup.5 + swap.1 + exec."miden_base_sys::bindings::account::add_asset" + push.1114112 + movup.5 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 +end + + +export."miden:basic-wallet/basic-wallet@1.0.0#send-asset" + mem_load.0x00011000 + push.96 + dup.1 + swap.1 + u32wrapping_sub + push.4294967264 + u32and + push.1114112 + dup.1 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + dup.0 + add.12 + u32assert + exec."wit_bindgen_rt::run_ctors_once" + dup.1 + add.8 + u32assert + dup.1 + movup.8 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_felt + dup.2 + add.4 + u32assert + dup.1 + movup.8 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_felt + dup.3 + dup.1 + movup.8 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_felt + dup.4 + add.44 + u32assert + dup.1 + movup.8 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_felt + dup.5 + add.40 + u32assert + dup.1 + movup.14 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_felt + dup.6 + add.36 + u32assert + dup.1 + movup.14 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_felt + dup.7 + add.32 + u32assert + dup.1 + movup.14 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_felt + dup.0 + movup.13 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_felt + push.64 + dup.9 + swap.1 + u32wrapping_add + dup.9 + swap.1 + exec."miden_base_sys::bindings::account::remove_asset" + push.32 + dup.9 + swap.1 + u32wrapping_add + push.64 + movup.10 + swap.1 + u32wrapping_add + movup.2 + swap.12 + movdn.2 + swap.1 + swap.3 + swap.11 + swap.1 + exec."miden_base_sys::bindings::tx::create_note" + drop + push.1114112 + movup.7 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + movup.7 + u32mod.4 + assertz.err=250 + movup.6 + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 +end + + diff --git a/tests/integration/expected/rust_sdk/basic_wallet.wat b/tests/integration/expected/rust_sdk/basic_wallet.wat index b9fb66bae..a9a02267c 100644 --- a/tests/integration/expected/rust_sdk/basic_wallet.wat +++ b/tests/integration/expected/rust_sdk/basic_wallet.wat @@ -79,7 +79,7 @@ (func $__wasm_call_ctors (;6;) (type 5)) (func $basic_wallet::bindings::__link_custom_section_describing_imports (;7;) (type 5)) (func $__rust_alloc (;8;) (type 6) (param i32 i32) (result i32) - i32.const 1048620 + i32.const 1048624 local.get 1 local.get 0 call $::alloc @@ -87,7 +87,7 @@ (func $__rust_dealloc (;9;) (type 7) (param i32 i32 i32)) (func $__rust_realloc (;10;) (type 8) (param i32 i32 i32 i32) (result i32) block ;; label = @1 - i32.const 1048620 + i32.const 1048624 local.get 2 local.get 3 call $::alloc @@ -108,7 +108,7 @@ ) (func $__rust_alloc_zeroed (;11;) (type 6) (param i32 i32) (result i32) block ;; label = @1 - i32.const 1048620 + i32.const 1048624 local.get 1 local.get 0 call $::alloc @@ -206,13 +206,13 @@ local.get 10 global.set $__stack_pointer ) - (func $miden:basic-wallet/basic-wallet@1.0.0#test-felt-intrinsics (;14;) (type 0) (param f32 f32) (result f32) + (func $miden:basic-wallet/aux@1.0.0#test-felt-intrinsics (;14;) (type 0) (param f32 f32) (result f32) call $wit_bindgen_rt::run_ctors_once local.get 0 local.get 1 call $miden_stdlib_sys::intrinsics::felt::extern_add ) - (func $miden:basic-wallet/basic-wallet@1.0.0#test-stdlib (;15;) (type 6) (param i32 i32) (result i32) + (func $miden:basic-wallet/aux@1.0.0#test-stdlib (;15;) (type 6) (param i32 i32) (result i32) (local i32 i32 i32 i32 i32 i32 i32 i32) global.get $__stack_pointer local.tee 2 @@ -341,10 +341,10 @@ i32.const 0 local.get 2 i64.load offset=8 - i64.store offset=1048612 align=4 + i64.store offset=1048616 align=4 local.get 3 global.set $__stack_pointer - i32.const 1048612 + i32.const 1048616 return end unreachable @@ -355,15 +355,19 @@ call $alloc::raw_vec::handle_error unreachable ) - (func $cabi_post_miden:basic-wallet/basic-wallet@1.0.0#test-stdlib (;16;) (type 11) (param i32)) - (func $cabi_realloc_wit_bindgen_0_28_0 (;17;) (type 8) (param i32 i32 i32 i32) (result i32) + (func $miden:basic-wallet/aux@1.0.0#process-list-felt (;16;) (type 6) (param i32 i32) (result i32) + call $wit_bindgen_rt::run_ctors_once + unreachable + ) + (func $cabi_post_miden:basic-wallet/aux@1.0.0#process-list-felt (;17;) (type 11) (param i32)) + (func $cabi_realloc_wit_bindgen_0_28_0 (;18;) (type 8) (param i32 i32 i32 i32) (result i32) local.get 0 local.get 1 local.get 2 local.get 3 call $wit_bindgen_rt::cabi_realloc ) - (func $wit_bindgen_rt::cabi_realloc (;18;) (type 8) (param i32 i32 i32 i32) (result i32) + (func $wit_bindgen_rt::cabi_realloc (;19;) (type 8) (param i32 i32 i32 i32) (result i32) block ;; label = @1 block ;; label = @2 block ;; label = @3 @@ -373,7 +377,7 @@ i32.eqz br_if 2 (;@1;) i32.const 0 - i32.load8_u offset=1048624 + i32.load8_u offset=1048628 drop local.get 3 local.get 2 @@ -394,18 +398,18 @@ end local.get 2 ) - (func $wit_bindgen_rt::run_ctors_once (;19;) (type 5) + (func $wit_bindgen_rt::run_ctors_once (;20;) (type 5) block ;; label = @1 i32.const 0 - i32.load8_u offset=1048625 + i32.load8_u offset=1048629 br_if 0 (;@1;) call $__wasm_call_ctors i32.const 0 i32.const 1 - i32.store8 offset=1048625 + i32.store8 offset=1048629 end ) - (func $::alloc (;20;) (type 12) (param i32 i32 i32) (result i32) + (func $::alloc (;21;) (type 12) (param i32 i32 i32) (result i32) (local i32 i32) block ;; label = @1 local.get 1 @@ -473,7 +477,7 @@ end unreachable ) - (func $miden_base_sys::bindings::account::add_asset (;21;) (type 13) (param i32 i32) + (func $miden_base_sys::bindings::account::add_asset (;22;) (type 13) (param i32 i32) local.get 1 f32.load local.get 1 @@ -485,7 +489,7 @@ local.get 0 call $miden_base_sys::bindings::account::extern_account_add_asset ) - (func $miden_base_sys::bindings::account::remove_asset (;22;) (type 13) (param i32 i32) + (func $miden_base_sys::bindings::account::remove_asset (;23;) (type 13) (param i32 i32) local.get 1 f32.load local.get 1 @@ -497,7 +501,7 @@ local.get 0 call $miden_base_sys::bindings::account::extern_account_remove_asset ) - (func $miden_base_sys::bindings::tx::create_note (;23;) (type 14) (param i32 f32 f32 i32) (result f32) + (func $miden_base_sys::bindings::tx::create_note (;24;) (type 14) (param i32 f32 f32 i32) (result f32) local.get 0 f32.load local.get 0 @@ -518,7 +522,7 @@ f32.load offset=12 call $miden_base_sys::bindings::tx::extern_tx_create_note ) - (func $alloc::vec::Vec::into_boxed_slice (;24;) (type 13) (param i32 i32) + (func $alloc::vec::Vec::into_boxed_slice (;25;) (type 13) (param i32 i32) (local i32 i32) global.get $__stack_pointer i32.const 16 @@ -564,8 +568,8 @@ end unreachable ) - (func $ as core::ops::drop::Drop>::drop (;25;) (type 11) (param i32)) - (func $ as core::ops::drop::Drop>::drop (;26;) (type 11) (param i32) + (func $ as core::ops::drop::Drop>::drop (;26;) (type 11) (param i32)) + (func $ as core::ops::drop::Drop>::drop (;27;) (type 11) (param i32) (local i32) block ;; label = @1 local.get 0 @@ -580,7 +584,7 @@ call $::deallocate end ) - (func $alloc::raw_vec::RawVec::try_allocate_in (;27;) (type 7) (param i32 i32 i32) + (func $alloc::raw_vec::RawVec::try_allocate_in (;28;) (type 7) (param i32 i32 i32) (local i32 i32) global.get $__stack_pointer i32.const 16 @@ -666,7 +670,7 @@ i32.add global.set $__stack_pointer ) - (func $::allocate (;28;) (type 7) (param i32 i32 i32) + (func $::allocate (;29;) (type 7) (param i32 i32 i32) (local i32) global.get $__stack_pointer i32.const 16 @@ -695,7 +699,7 @@ i32.add global.set $__stack_pointer ) - (func $alloc::alloc::Global::alloc_impl (;29;) (type 15) (param i32 i32 i32 i32) + (func $alloc::alloc::Global::alloc_impl (;30;) (type 15) (param i32 i32 i32 i32) block ;; label = @1 local.get 2 i32.eqz @@ -704,7 +708,7 @@ local.get 3 br_if 0 (;@2;) i32.const 0 - i32.load8_u offset=1048624 + i32.load8_u offset=1048628 drop local.get 2 local.get 1 @@ -724,7 +728,7 @@ local.get 1 i32.store ) - (func $alloc::raw_vec::RawVec::shrink_unchecked (;30;) (type 7) (param i32 i32 i32) + (func $alloc::raw_vec::RawVec::shrink_unchecked (;31;) (type 7) (param i32 i32 i32) (local i32 i32 i32 i32) i32.const -2147483647 local.set 3 @@ -776,7 +780,7 @@ local.get 3 i32.store ) - (func $::deallocate (;31;) (type 7) (param i32 i32 i32) + (func $::deallocate (;32;) (type 7) (param i32 i32 i32) block ;; label = @1 local.get 2 i32.eqz @@ -787,10 +791,10 @@ call $__rust_dealloc end ) - (func $alloc::raw_vec::handle_error (;32;) (type 13) (param i32 i32) + (func $alloc::raw_vec::handle_error (;33;) (type 13) (param i32 i32) unreachable ) - (func $cabi_realloc (;33;) (type 8) (param i32 i32 i32 i32) (result i32) + (func $cabi_realloc (;34;) (type 8) (param i32 i32 i32 i32) (result i32) local.get 0 local.get 1 local.get 2 @@ -803,13 +807,15 @@ (export "memory" (memory 0)) (export "miden:basic-wallet/basic-wallet@1.0.0#receive-asset" (func $miden:basic-wallet/basic-wallet@1.0.0#receive-asset)) (export "miden:basic-wallet/basic-wallet@1.0.0#send-asset" (func $miden:basic-wallet/basic-wallet@1.0.0#send-asset)) - (export "miden:basic-wallet/basic-wallet@1.0.0#test-felt-intrinsics" (func $miden:basic-wallet/basic-wallet@1.0.0#test-felt-intrinsics)) - (export "miden:basic-wallet/basic-wallet@1.0.0#test-stdlib" (func $miden:basic-wallet/basic-wallet@1.0.0#test-stdlib)) - (export "cabi_post_miden:basic-wallet/basic-wallet@1.0.0#test-stdlib" (func $cabi_post_miden:basic-wallet/basic-wallet@1.0.0#test-stdlib)) + (export "miden:basic-wallet/aux@1.0.0#test-felt-intrinsics" (func $miden:basic-wallet/aux@1.0.0#test-felt-intrinsics)) + (export "miden:basic-wallet/aux@1.0.0#test-stdlib" (func $miden:basic-wallet/aux@1.0.0#test-stdlib)) + (export "miden:basic-wallet/aux@1.0.0#process-list-felt" (func $miden:basic-wallet/aux@1.0.0#process-list-felt)) + (export "cabi_post_miden:basic-wallet/aux@1.0.0#process-list-felt" (func $cabi_post_miden:basic-wallet/aux@1.0.0#process-list-felt)) + (export "cabi_post_miden:basic-wallet/aux@1.0.0#test-stdlib" (func $cabi_post_miden:basic-wallet/aux@1.0.0#process-list-felt)) (export "cabi_realloc_wit_bindgen_0_28_0" (func $cabi_realloc_wit_bindgen_0_28_0)) (export "cabi_realloc" (func $cabi_realloc)) (elem (;0;) (i32.const 1) func $basic_wallet::bindings::__link_custom_section_describing_imports $cabi_realloc) - (data $.rodata (;0;) (i32.const 1048576) "\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\02\00\00\00") + (data $.rodata (;0;) (i32.const 1048576) "\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\02\00\00\00") ) (alias export 2 "add" (func (;0;))) (core func (;0;) (canon lower (func 0))) @@ -860,20 +866,11 @@ (alias core export 5 "miden:basic-wallet/basic-wallet@1.0.0#send-asset" (core func (;8;))) (func (;7;) (type 11) (canon lift (core func 8))) (alias export 0 "felt" (type (;12;))) - (type (;13;) (func (param "a" 12) (param "b" 12) (result 12))) - (alias core export 5 "miden:basic-wallet/basic-wallet@1.0.0#test-felt-intrinsics" (core func (;9;))) - (func (;8;) (type 13) (canon lift (core func 9))) - (type (;14;) (list u8)) - (type (;15;) (func (param "input" 14) (result 14))) - (alias core export 5 "miden:basic-wallet/basic-wallet@1.0.0#test-stdlib" (core func (;10;))) - (alias core export 5 "cabi_post_miden:basic-wallet/basic-wallet@1.0.0#test-stdlib" (core func (;11;))) - (func (;9;) (type 15) (canon lift (core func 10) (memory 0) (realloc 6) (post-return 11))) - (alias export 0 "felt" (type (;16;))) - (alias export 0 "word" (type (;17;))) - (alias export 0 "core-asset" (type (;18;))) - (alias export 0 "tag" (type (;19;))) - (alias export 0 "recipient" (type (;20;))) - (alias export 0 "note-type" (type (;21;))) + (alias export 0 "word" (type (;13;))) + (alias export 0 "core-asset" (type (;14;))) + (alias export 0 "tag" (type (;15;))) + (alias export 0 "recipient" (type (;16;))) + (alias export 0 "note-type" (type (;17;))) (component (;0;) (type (;0;) (record (field "inner" float32))) (import "import-type-felt" (type (;1;) (eq 0))) @@ -896,44 +893,95 @@ (import "import-type-recipient0" (type (;17;) (eq 10))) (type (;18;) (func (param "core-asset" 13) (param "tag" 15) (param "note-type" 16) (param "recipient" 17))) (import "import-func-send-asset" (func (;1;) (type 18))) - (import "import-type-felt0" (type (;19;) (eq 1))) - (type (;20;) (func (param "a" 19) (param "b" 19) (result 19))) - (import "import-func-test-felt-intrinsics" (func (;2;) (type 20))) - (type (;21;) (list u8)) - (type (;22;) (func (param "input" 21) (result 21))) - (import "import-func-test-stdlib" (func (;3;) (type 22))) - (export (;23;) "core-asset" (type 6)) - (export (;24;) "tag" (type 8)) - (export (;25;) "recipient" (type 10)) - (export (;26;) "note-type" (type 12)) - (export (;27;) "felt" (type 1)) - (type (;28;) (func (param "core-asset" 23))) - (export (;4;) "receive-asset" (func 0) (func (type 28))) - (type (;29;) (func (param "core-asset" 23) (param "tag" 24) (param "note-type" 26) (param "recipient" 25))) - (export (;5;) "send-asset" (func 1) (func (type 29))) - (type (;30;) (func (param "a" 27) (param "b" 27) (result 27))) - (export (;6;) "test-felt-intrinsics" (func 2) (func (type 30))) - (type (;31;) (list u8)) - (type (;32;) (func (param "input" 31) (result 31))) - (export (;7;) "test-stdlib" (func 3) (func (type 32))) + (export (;19;) "core-asset" (type 6)) + (export (;20;) "tag" (type 8)) + (export (;21;) "recipient" (type 10)) + (export (;22;) "note-type" (type 12)) + (export (;23;) "felt" (type 1)) + (type (;24;) (func (param "core-asset" 19))) + (export (;2;) "receive-asset" (func 0) (func (type 24))) + (type (;25;) (func (param "core-asset" 19) (param "tag" 20) (param "note-type" 22) (param "recipient" 21))) + (export (;3;) "send-asset" (func 1) (func (type 25))) ) (instance (;6;) (instantiate 0 (with "import-func-receive-asset" (func 6)) (with "import-func-send-asset" (func 7)) - (with "import-func-test-felt-intrinsics" (func 8)) - (with "import-func-test-stdlib" (func 9)) - (with "import-type-felt" (type 16)) - (with "import-type-word" (type 17)) - (with "import-type-core-asset" (type 18)) - (with "import-type-tag" (type 19)) - (with "import-type-recipient" (type 20)) - (with "import-type-note-type" (type 21)) + (with "import-type-felt" (type 12)) + (with "import-type-word" (type 13)) + (with "import-type-core-asset" (type 14)) + (with "import-type-tag" (type 15)) + (with "import-type-recipient" (type 16)) + (with "import-type-note-type" (type 17)) (with "import-type-core-asset0" (type 6)) (with "import-type-tag0" (type 8)) (with "import-type-note-type0" (type 9)) (with "import-type-recipient0" (type 10)) - (with "import-type-felt0" (type 12)) ) ) (export (;7;) "miden:basic-wallet/basic-wallet@1.0.0" (instance 6)) + (alias export 0 "felt" (type (;18;))) + (type (;19;) (func (param "a" 18) (param "b" 18) (result 18))) + (alias core export 5 "miden:basic-wallet/aux@1.0.0#test-felt-intrinsics" (core func (;9;))) + (func (;8;) (type 19) (canon lift (core func 9))) + (type (;20;) (list u8)) + (type (;21;) (func (param "input" 20) (result 20))) + (alias core export 5 "miden:basic-wallet/aux@1.0.0#test-stdlib" (core func (;10;))) + (alias core export 5 "cabi_post_miden:basic-wallet/aux@1.0.0#test-stdlib" (core func (;11;))) + (func (;9;) (type 21) (canon lift (core func 10) (memory 0) (realloc 6) (post-return 11))) + (type (;22;) (list 18)) + (type (;23;) (func (param "input" 22) (result 22))) + (alias core export 5 "miden:basic-wallet/aux@1.0.0#process-list-felt" (core func (;12;))) + (alias core export 5 "cabi_post_miden:basic-wallet/aux@1.0.0#process-list-felt" (core func (;13;))) + (func (;10;) (type 23) (canon lift (core func 12) (memory 0) (realloc 6) (post-return 13))) + (component (;1;) + (type (;0;) (record (field "inner" float32))) + (import "import-type-felt" (type (;1;) (eq 0))) + (type (;2;) (tuple 1 1 1 1)) + (type (;3;) (record (field "inner" 2))) + (import "import-type-word" (type (;4;) (eq 3))) + (type (;5;) (record (field "inner" 4))) + (import "import-type-core-asset" (type (;6;) (eq 5))) + (type (;7;) (record (field "inner" 1))) + (import "import-type-tag" (type (;8;) (eq 7))) + (type (;9;) (record (field "inner" 4))) + (import "import-type-recipient" (type (;10;) (eq 9))) + (type (;11;) (record (field "inner" 1))) + (import "import-type-note-type" (type (;12;) (eq 11))) + (import "import-type-felt0" (type (;13;) (eq 1))) + (type (;14;) (func (param "a" 13) (param "b" 13) (result 13))) + (import "import-func-test-felt-intrinsics" (func (;0;) (type 14))) + (type (;15;) (list u8)) + (type (;16;) (func (param "input" 15) (result 15))) + (import "import-func-test-stdlib" (func (;1;) (type 16))) + (type (;17;) (list 13)) + (type (;18;) (func (param "input" 17) (result 17))) + (import "import-func-process-list-felt" (func (;2;) (type 18))) + (export (;19;) "core-asset" (type 6)) + (export (;20;) "tag" (type 8)) + (export (;21;) "recipient" (type 10)) + (export (;22;) "note-type" (type 12)) + (export (;23;) "felt" (type 1)) + (type (;24;) (func (param "a" 23) (param "b" 23) (result 23))) + (export (;3;) "test-felt-intrinsics" (func 0) (func (type 24))) + (type (;25;) (list u8)) + (type (;26;) (func (param "input" 25) (result 25))) + (export (;4;) "test-stdlib" (func 1) (func (type 26))) + (type (;27;) (list 23)) + (type (;28;) (func (param "input" 27) (result 27))) + (export (;5;) "process-list-felt" (func 2) (func (type 28))) + ) + (instance (;8;) (instantiate 1 + (with "import-func-test-felt-intrinsics" (func 8)) + (with "import-func-test-stdlib" (func 9)) + (with "import-func-process-list-felt" (func 10)) + (with "import-type-felt" (type 12)) + (with "import-type-word" (type 13)) + (with "import-type-core-asset" (type 14)) + (with "import-type-tag" (type 15)) + (with "import-type-recipient" (type 16)) + (with "import-type-note-type" (type 17)) + (with "import-type-felt0" (type 18)) + ) + ) + (export (;9;) "miden:basic-wallet/aux@1.0.0" (instance 8)) ) \ No newline at end of file diff --git a/tests/integration/expected/rust_sdk/p2id.hir b/tests/integration/expected/rust_sdk/p2id.hir index 4af36233b..b4336cde3 100644 --- a/tests/integration/expected/rust_sdk/p2id.hir +++ b/tests/integration/expected/rust_sdk/p2id.hir @@ -1,14 +1,15 @@ (component ;; Component Imports - (lower ( (type (func (abi canon) (result u32)))) (#intrinsics::mem #heap_base) - (lower ( (type (func (abi canon) (result felt)))) (#miden::account #get_id) - (lower ( (type (func (abi canon) (param i32) (result i32 i32)))) (#miden::note #get_inputs) - (lower (("miden:basic-wallet/basic-wallet@1.0.0" #receive-asset) (type (func (abi wasm) (param (struct (struct (struct (struct felt) (struct felt) (struct felt) (struct felt)))))))) (#miden:basic-wallet/basic-wallet@1.0.0 #receive_asset) + (lower ( (type (func (abi canon) (param i32) (result i32 i32)))) (#p2id #miden_base_sys::bindings::note::extern_note_get_inputs) + (lower ( (type (func (abi canon) (result felt)))) (#p2id #miden_base_sys::bindings::account::extern_account_get_id) + (lower ( (type (func (abi canon) (result u32)))) (#p2id #miden_sdk_alloc::heap_base) + (lower ((miden:basic-wallet/basic-wallet@1.0.0#receive-asset) (type (func (abi wasm) (param (struct (struct (struct (struct felt) (struct felt) (struct felt) (struct felt)))))))) (#p2id #p2id::bindings::miden::basic_wallet::basic_wallet::receive_asset::wit_import) + (lower ((miden:basic-wallet/aux@1.0.0#process-list-felt) (type (func (abi wasm) (param (list (struct felt))) (result (list (struct felt)))))) (#wit-component:fixups #func0) ;; Modules (module #p2id ;; Data Segments - (data (mut) (offset 1048576) 0x01000000010000000100000001000000010000000100000001000000010000000100000002000000) + (data (mut) (offset 1048576) 0x0100000001000000010000000100000001000000010000000100000001000000010000000100000002000000) ;; Constants (const (id 0) 0x00100000) @@ -17,7 +18,7 @@ (global (export #__stack_pointer) (id 0) (type i32) (const 0)) ;; Functions - (func (export #__wasm_call_ctors) + (func #__wasm_call_ctors (block 0 (br (block 1))) @@ -25,7 +26,7 @@ (ret)) ) - (func (export #p2id::bindings::__link_custom_section_describing_imports) + (func #p2id::bindings::__link_custom_section_describing_imports (block 0 (br (block 1))) @@ -34,9 +35,9 @@ (ret)) ) - (func (export #__rust_alloc) (param i32) (param i32) (result i32) + (func #__rust_alloc (param i32) (param i32) (result i32) (block 0 (param v0 i32) (param v1 i32) - (let (v3 i32) (const.i32 1048616)) + (let (v3 i32) (const.i32 1048620)) (let (v4 i32) (call #::alloc v3 v1 v0)) (br (block 1 v4))) @@ -44,10 +45,10 @@ (ret v2)) ) - (func (export #__rust_realloc) + (func #__rust_realloc (param i32) (param i32) (param i32) (param i32) (result i32) (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (param v3 i32) - (let (v5 i32) (const.i32 1048616)) + (let (v5 i32) (const.i32 1048620)) (let (v6 i32) (call #::alloc v5 v2 v3)) (let (v7 i1) (eq v6 0)) (let (v8 i32) (zext v7)) @@ -76,9 +77,9 @@ (br (block 2 v6))) ) - (func (export #__rust_alloc_zeroed) (param i32) (param i32) (result i32) + (func #__rust_alloc_zeroed (param i32) (param i32) (result i32) (block 0 (param v0 i32) (param v1 i32) - (let (v3 i32) (const.i32 1048616)) + (let (v3 i32) (const.i32 1048620)) (let (v4 i32) (call #::alloc v3 v1 v0)) (let (v5 i1) (eq v4 0)) (let (v6 i32) (zext v5)) @@ -105,26 +106,47 @@ (block 0 (let (v0 i32) (const.i32 0)) (let (v1 felt) (const.felt 0)) - (let (v2 i32) (const.i32 0)) - (let (v3 i32) (global.load i32 (global.symbol #__stack_pointer))) - (let (v4 i32) (const.i32 32)) - (let (v5 i32) (sub.wrapping v3 v4)) - (let (v6 (ptr i32)) (global.symbol #__stack_pointer)) - (store v6 v5) + (let (v2 i32) (global.load i32 (global.symbol #__stack_pointer))) + (let (v3 i32) (const.i32 32)) + (let (v4 i32) (sub.wrapping v2 v3)) + (let (v5 (ptr i32)) (global.symbol #__stack_pointer)) + (store v5 v4) (call #wit_bindgen_rt::run_ctors_once) - (let (v7 i32) (const.i32 8)) - (let (v8 i32) (add.wrapping v5 v7)) - (call #miden_base_sys::bindings::note::get_inputs v8) - (let (v9 u32) (bitcast v5)) - (let (v10 u32) (add.checked v9 16)) - (let (v11 u32) (mod.unchecked v10 4)) - (assertz 250 v11) - (let (v12 (ptr i32)) (inttoptr v10)) - (let (v13 i32) (load v12)) - (let (v14 i1) (eq v13 0)) - (let (v15 i32) (zext v14)) - (let (v16 i1) (neq v15 0)) - (condbr v16 (block 2) (block 3))) + (let (v6 i32) (const.i32 4)) + (let (v7 i32) (add.wrapping v4 v6)) + (call #miden_base_sys::bindings::note::get_inputs v7) + (let (v8 u32) (bitcast v4)) + (let (v9 u32) (add.checked v8 12)) + (let (v10 u32) (mod.unchecked v9 4)) + (assertz 250 v10) + (let (v11 (ptr i32)) (inttoptr v9)) + (let (v12 i32) (load v11)) + (let (v13 u32) (bitcast v4)) + (let (v14 u32) (add.checked v13 8)) + (let (v15 u32) (mod.unchecked v14 4)) + (assertz 250 v15) + (let (v16 (ptr i32)) (inttoptr v14)) + (let (v17 i32) (load v16)) + (let (v18 i64) (const.i64 0)) + (let (v19 u32) (bitcast v4)) + (let (v20 u32) (add.checked v19 16)) + (let (v21 u32) (mod.unchecked v20 8)) + (assertz 250 v21) + (let (v22 (ptr i64)) (inttoptr v20)) + (store v22 v18) + (let (v23 i32) (const.i32 16)) + (let (v24 i32) (add.wrapping v4 v23)) + (call (#miden:basic-wallet/aux@1.0.0 #process_list_felt) v17 v12 v24) + (let (v25 u32) (bitcast v4)) + (let (v26 u32) (add.checked v25 20)) + (let (v27 u32) (mod.unchecked v26 4)) + (assertz 250 v27) + (let (v28 (ptr i32)) (inttoptr v26)) + (let (v29 i32) (load v28)) + (let (v30 i1) (eq v29 0)) + (let (v31 i32) (zext v30)) + (let (v32 i1) (neq v31 0)) + (condbr v32 (block 2) (block 3))) (block 1) @@ -132,92 +154,101 @@ (unreachable)) (block 3 - (let (v17 u32) (bitcast v5)) - (let (v18 u32) (add.checked v17 12)) - (let (v19 u32) (mod.unchecked v18 4)) - (assertz 250 v19) - (let (v20 (ptr i32)) (inttoptr v18)) - (let (v21 i32) (load v20)) - (let (v22 u32) (bitcast v21)) - (let (v23 u32) (mod.unchecked v22 4)) - (assertz 250 v23) - (let (v24 (ptr felt)) (inttoptr v22)) - (let (v25 felt) (load v24)) - (let (v26 felt) (call #miden_base_sys::bindings::account::get_id)) - (let (v27 i1) (eq v26 v25)) - (let (v28 i32) (cast v27)) - (let (v29 i32) (const.i32 1)) - (let (v30 i1) (neq v28 v29)) - (let (v31 i32) (zext v30)) - (let (v32 i1) (neq v31 0)) - (condbr v32 (block 2) (block 4))) + (let (v33 i1) (eq v12 0)) + (let (v34 i32) (zext v33)) + (let (v35 i1) (neq v34 0)) + (condbr v35 (block 2) (block 4))) (block 4 - (let (v33 i32) (const.i32 20)) - (let (v34 i32) (add.wrapping v5 v33)) - (call #miden_base_sys::bindings::note::get_assets v34) - (let (v35 u32) (bitcast v5)) - (let (v36 u32) (add.checked v35 28)) - (let (v37 u32) (mod.unchecked v36 4)) - (assertz 250 v37) - (let (v38 (ptr i32)) (inttoptr v36)) - (let (v39 i32) (load v38)) - (let (v40 i32) (const.i32 5)) + (let (v36 u32) (bitcast v4)) + (let (v37 u32) (add.checked v36 16)) + (let (v38 u32) (mod.unchecked v37 4)) + (assertz 250 v38) + (let (v39 (ptr i32)) (inttoptr v37)) + (let (v40 i32) (load v39)) (let (v41 u32) (bitcast v40)) - (let (v42 i32) (shl.wrapping v39 v41)) - (let (v43 u32) (bitcast v5)) - (let (v44 u32) (add.checked v43 24)) - (let (v45 u32) (mod.unchecked v44 4)) - (assertz 250 v45) - (let (v46 (ptr i32)) (inttoptr v44)) - (let (v47 i32) (load v46)) - (br (block 6 v42 v47 v5))) + (let (v42 u32) (mod.unchecked v41 4)) + (assertz 250 v42) + (let (v43 (ptr felt)) (inttoptr v41)) + (let (v44 felt) (load v43)) + (let (v45 u32) (bitcast v17)) + (let (v46 u32) (mod.unchecked v45 4)) + (assertz 250 v46) + (let (v47 (ptr felt)) (inttoptr v45)) + (let (v48 felt) (load v47)) + (assert.eq v48 v44) + (let (v49 u32) (bitcast v17)) + (let (v50 u32) (mod.unchecked v49 4)) + (assertz 250 v50) + (let (v51 (ptr felt)) (inttoptr v49)) + (let (v52 felt) (load v51)) + (let (v53 felt) (call #miden_base_sys::bindings::account::get_id)) + (assert.eq v52 v53) + (let (v54 i32) (const.i32 16)) + (let (v55 i32) (add.wrapping v4 v54)) + (call #miden_base_sys::bindings::note::get_assets v55) + (let (v56 u32) (bitcast v4)) + (let (v57 u32) (add.checked v56 24)) + (let (v58 u32) (mod.unchecked v57 4)) + (assertz 250 v58) + (let (v59 (ptr i32)) (inttoptr v57)) + (let (v60 i32) (load v59)) + (let (v61 i32) (const.i32 5)) + (let (v62 u32) (bitcast v61)) + (let (v63 i32) (shl.wrapping v60 v62)) + (let (v64 u32) (bitcast v4)) + (let (v65 u32) (add.checked v64 20)) + (let (v66 u32) (mod.unchecked v65 4)) + (assertz 250 v66) + (let (v67 (ptr i32)) (inttoptr v65)) + (let (v68 i32) (load v67)) + (br (block 6 v63 v68 v4))) (block 5 - (let (v77 i32) (const.i32 32)) - (let (v78 i32) (add.wrapping v76 v77)) - (let (v79 (ptr i32)) (global.symbol #__stack_pointer)) - (store v79 v78) + (let (v98 i32) (const.i32 32)) + (let (v99 i32) (add.wrapping v97 v98)) + (let (v100 (ptr i32)) (global.symbol #__stack_pointer)) + (store v100 v99) (ret)) - (block 6 (param v48 i32) (param v52 i32) (param v76 i32) - (let (v49 i1) (eq v48 0)) - (let (v50 i32) (zext v49)) - (let (v51 i1) (neq v50 0)) - (condbr v51 (block 5) (block 8))) + (block 6 (param v69 i32) (param v73 i32) (param v97 i32) + (let (v70 i1) (eq v69 0)) + (let (v71 i32) (zext v70)) + (let (v72 i1) (neq v71 0)) + (condbr v72 (block 5) (block 8))) (block 7) (block 8 - (let (v53 u32) (bitcast v52)) - (let (v54 u32) (mod.unchecked v53 4)) - (assertz 250 v54) - (let (v55 (ptr felt)) (inttoptr v53)) - (let (v56 felt) (load v55)) - (let (v57 u32) (bitcast v52)) - (let (v58 u32) (add.checked v57 4)) - (let (v59 u32) (mod.unchecked v58 4)) - (assertz 250 v59) - (let (v60 (ptr felt)) (inttoptr v58)) - (let (v61 felt) (load v60)) - (let (v62 u32) (bitcast v52)) - (let (v63 u32) (add.checked v62 8)) - (let (v64 u32) (mod.unchecked v63 4)) - (assertz 250 v64) - (let (v65 (ptr felt)) (inttoptr v63)) - (let (v66 felt) (load v65)) - (let (v67 u32) (bitcast v52)) - (let (v68 u32) (add.checked v67 12)) - (let (v69 u32) (mod.unchecked v68 4)) - (assertz 250 v69) - (let (v70 (ptr felt)) (inttoptr v68)) - (let (v71 felt) (load v70)) - (call (#miden:basic-wallet/basic-wallet@1.0.0 #receive_asset) v56 v61 v66 v71) - (let (v72 i32) (const.i32 -32)) - (let (v73 i32) (add.wrapping v48 v72)) - (let (v74 i32) (const.i32 32)) - (let (v75 i32) (add.wrapping v52 v74)) - (br (block 6 v73 v75 v76))) + (let (v74 u32) (bitcast v73)) + (let (v75 u32) (mod.unchecked v74 4)) + (assertz 250 v75) + (let (v76 (ptr felt)) (inttoptr v74)) + (let (v77 felt) (load v76)) + (let (v78 u32) (bitcast v73)) + (let (v79 u32) (add.checked v78 4)) + (let (v80 u32) (mod.unchecked v79 4)) + (assertz 250 v80) + (let (v81 (ptr felt)) (inttoptr v79)) + (let (v82 felt) (load v81)) + (let (v83 u32) (bitcast v73)) + (let (v84 u32) (add.checked v83 8)) + (let (v85 u32) (mod.unchecked v84 4)) + (assertz 250 v85) + (let (v86 (ptr felt)) (inttoptr v84)) + (let (v87 felt) (load v86)) + (let (v88 u32) (bitcast v73)) + (let (v89 u32) (add.checked v88 12)) + (let (v90 u32) (mod.unchecked v89 4)) + (assertz 250 v90) + (let (v91 (ptr felt)) (inttoptr v89)) + (let (v92 felt) (load v91)) + (call (#miden:basic-wallet/basic-wallet@1.0.0 #receive_asset) v77 v82 v87 v92) + (let (v93 i32) (const.i32 -32)) + (let (v94 i32) (add.wrapping v69 v93)) + (let (v95 i32) (const.i32 32)) + (let (v96 i32) (add.wrapping v73 v95)) + (br (block 6 v94 v96 v97))) ) (func (export #cabi_realloc_wit_bindgen_0_28_0) @@ -230,7 +261,7 @@ (ret v4)) ) - (func (export #wit_bindgen_rt::cabi_realloc) + (func #wit_bindgen_rt::cabi_realloc (param i32) (param i32) (param i32) (param i32) (result i32) (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (param v3 i32) (let (v5 i1) (neq v1 0)) @@ -259,7 +290,7 @@ (block 6 (let (v9 i32) (const.i32 0)) (let (v10 u32) (bitcast v9)) - (let (v11 u32) (add.checked v10 1048620)) + (let (v11 u32) (add.checked v10 1048624)) (let (v12 (ptr u8)) (inttoptr v11)) (let (v13 u8) (load v12)) (let (v14 i32) (zext v13)) @@ -270,11 +301,11 @@ (unreachable)) ) - (func (export #wit_bindgen_rt::run_ctors_once) + (func #wit_bindgen_rt::run_ctors_once (block 0 (let (v0 i32) (const.i32 0)) (let (v1 u32) (bitcast v0)) - (let (v2 u32) (add.checked v1 1048621)) + (let (v2 u32) (add.checked v1 1048625)) (let (v3 (ptr u8)) (inttoptr v2)) (let (v4 u8) (load v3)) (let (v5 i32) (zext v4)) @@ -294,13 +325,13 @@ (let (v9 u32) (bitcast v8)) (let (v10 u8) (trunc v9)) (let (v11 u32) (bitcast v7)) - (let (v12 u32) (add.checked v11 1048621)) + (let (v12 u32) (add.checked v11 1048625)) (let (v13 (ptr u8)) (inttoptr v12)) (store v13 v10) (br (block 2))) ) - (func (export #::alloc) + (func #::alloc (param i32) (param i32) (param i32) (result i32) (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (let (v4 i32) (const.i32 0)) @@ -399,7 +430,7 @@ (br (block 7 v66))) ) - (func (export #miden_base_sys::bindings::account::get_id) + (func #miden_base_sys::bindings::account::get_id (result felt) (block 0 (let (v1 felt) (call (#miden::account #get_id))) @@ -409,7 +440,7 @@ (ret v0)) ) - (func (export #miden_base_sys::bindings::note::get_inputs) + (func #miden_base_sys::bindings::note::get_inputs (param i32) (block 0 (param v0 i32) (let (v1 i32) (const.i32 0)) @@ -491,7 +522,7 @@ (unreachable)) ) - (func (export #miden_base_sys::bindings::note::get_assets) + (func #miden_base_sys::bindings::note::get_assets (param i32) (block 0 (param v0 i32) (unreachable)) @@ -499,7 +530,7 @@ (block 1) ) - (func (export #alloc::raw_vec::RawVec::try_allocate_in) + (func #alloc::raw_vec::RawVec::try_allocate_in (param i32) (param i32) (param i32) (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (let (v3 i32) (const.i32 0)) @@ -576,7 +607,7 @@ (block 10 (let (v26 i32) (const.i32 0)) (let (v27 u32) (bitcast v26)) - (let (v28 u32) (add.checked v27 1048620)) + (let (v28 u32) (add.checked v27 1048624)) (let (v29 (ptr u8)) (inttoptr v28)) (let (v30 u8) (load v29)) (let (v31 i32) (zext v30)) @@ -617,7 +648,7 @@ (br (block 2 v40 v50))) ) - (func (export #alloc::raw_vec::handle_error) + (func #alloc::raw_vec::handle_error (param i32) (param i32) (block 0 (param v0 i32) (param v1 i32) (unreachable)) @@ -639,8 +670,13 @@ (func (import #intrinsics::mem #heap_base) (result u32)) (func (import #miden::account #get_id) (result felt)) (func (import #miden::note #get_inputs) (param i32) (result i32 i32)) + (func (import #miden:basic-wallet/aux@1.0.0 #process_list_felt) + (param i32) (param i32) (param i32)) (func (import #miden:basic-wallet/basic-wallet@1.0.0 #receive_asset) (param felt) (param felt) (param felt) (param felt)) ) + + ;; Component Exports + (lift (miden:base/note-script@1.0.0#note-script) (#p2id #miden:base/note-script@1.0.0#note-script (func (abi wasm) ) ) ) diff --git a/tests/integration/expected/rust_sdk/p2id.wat b/tests/integration/expected/rust_sdk/p2id.wat index ac365a5f4..35dcfc6a4 100644 --- a/tests/integration/expected/rust_sdk/p2id.wat +++ b/tests/integration/expected/rust_sdk/p2id.wat @@ -21,63 +21,75 @@ ) ) (import "miden:basic-wallet/basic-wallet@1.0.0" (instance (;1;) (type 2))) - (type (;3;) + (alias export 0 "felt" (type (;3;))) + (type (;4;) + (instance + (alias outer 1 3 (type (;0;))) + (export (;1;) "felt" (type (eq 0))) + (type (;2;) (list 1)) + (type (;3;) (func (param "input" 2) (result 2))) + (export (;0;) "process-list-felt" (func (type 3))) + ) + ) + (import "miden:basic-wallet/aux@1.0.0" (instance (;2;) (type 4))) + (type (;5;) (instance (type (;0;) (func (result s32))) (export (;0;) "heap-base" (func (type 0))) ) ) - (import "miden:core-import/intrinsics-mem@1.0.0" (instance (;2;) (type 3))) - (type (;4;) + (import "miden:core-import/intrinsics-mem@1.0.0" (instance (;3;) (type 5))) + (type (;6;) (instance - (type (;0;) (func (param "a" float32) (param "b" float32) (result bool))) - (export (;0;) "eq" (func (type 0))) + (type (;0;) (func (param "a" float32) (param "b" float32))) + (export (;0;) "assert-eq" (func (type 0))) ) ) - (import "miden:core-import/intrinsics-felt@1.0.0" (instance (;3;) (type 4))) - (type (;5;) + (import "miden:core-import/intrinsics-felt@1.0.0" (instance (;4;) (type 6))) + (type (;7;) (instance (type (;0;) (func (result float32))) (export (;0;) "get-id" (func (type 0))) ) ) - (import "miden:core-import/account@1.0.0" (instance (;4;) (type 5))) - (type (;6;) + (import "miden:core-import/account@1.0.0" (instance (;5;) (type 7))) + (type (;8;) (instance (type (;0;) (func (param "ptr" s32) (result s32))) (export (;0;) "get-inputs" (func (type 0))) ) ) - (import "miden:core-import/note@1.0.0" (instance (;5;) (type 6))) + (import "miden:core-import/note@1.0.0" (instance (;6;) (type 8))) (core module (;0;) - (type (;0;) (func (param f32 f32) (result i32))) - (type (;1;) (func (param f32 f32 f32 f32))) - (type (;2;) (func (result i32))) - (type (;3;) (func (result f32))) - (type (;4;) (func (param i32) (result i32))) - (type (;5;) (func)) - (type (;6;) (func (param i32 i32) (result i32))) - (type (;7;) (func (param i32 i32 i32 i32) (result i32))) - (type (;8;) (func (param i32 i32 i32) (result i32))) - (type (;9;) (func (param i32))) - (type (;10;) (func (param i32 i32 i32))) + (type (;0;) (func (param i32 i32 i32))) + (type (;1;) (func (param f32 f32))) + (type (;2;) (func (param f32 f32 f32 f32))) + (type (;3;) (func (result i32))) + (type (;4;) (func (result f32))) + (type (;5;) (func (param i32) (result i32))) + (type (;6;) (func)) + (type (;7;) (func (param i32 i32) (result i32))) + (type (;8;) (func (param i32 i32 i32 i32) (result i32))) + (type (;9;) (func (param i32 i32 i32) (result i32))) + (type (;10;) (func (param i32))) (type (;11;) (func (param i32 i32))) - (import "miden:core-import/intrinsics-felt@1.0.0" "eq" (func $miden_stdlib_sys::intrinsics::felt::extern_eq (;0;) (type 0))) - (import "miden:basic-wallet/basic-wallet@1.0.0" "receive-asset" (func $p2id::bindings::miden::basic_wallet::basic_wallet::receive_asset::wit_import (;1;) (type 1))) - (import "miden:core-import/intrinsics-mem@1.0.0" "heap-base" (func $miden_sdk_alloc::heap_base (;2;) (type 2))) - (import "miden:core-import/account@1.0.0" "get-id" (func $miden_base_sys::bindings::account::extern_account_get_id (;3;) (type 3))) - (import "miden:core-import/note@1.0.0" "get-inputs" (func $miden_base_sys::bindings::note::extern_note_get_inputs (;4;) (type 4))) - (func $__wasm_call_ctors (;5;) (type 5)) - (func $p2id::bindings::__link_custom_section_describing_imports (;6;) (type 5)) - (func $__rust_alloc (;7;) (type 6) (param i32 i32) (result i32) - i32.const 1048616 + (import "miden:basic-wallet/aux@1.0.0" "process-list-felt" (func $p2id::bindings::miden::basic_wallet::aux::process_list_felt::wit_import (;0;) (type 0))) + (import "miden:core-import/intrinsics-felt@1.0.0" "assert-eq" (func $miden_stdlib_sys::intrinsics::felt::extern_assert_eq (;1;) (type 1))) + (import "miden:basic-wallet/basic-wallet@1.0.0" "receive-asset" (func $p2id::bindings::miden::basic_wallet::basic_wallet::receive_asset::wit_import (;2;) (type 2))) + (import "miden:core-import/intrinsics-mem@1.0.0" "heap-base" (func $miden_sdk_alloc::heap_base (;3;) (type 3))) + (import "miden:core-import/account@1.0.0" "get-id" (func $miden_base_sys::bindings::account::extern_account_get_id (;4;) (type 4))) + (import "miden:core-import/note@1.0.0" "get-inputs" (func $miden_base_sys::bindings::note::extern_note_get_inputs (;5;) (type 5))) + (func $__wasm_call_ctors (;6;) (type 6)) + (func $p2id::bindings::__link_custom_section_describing_imports (;7;) (type 6)) + (func $__rust_alloc (;8;) (type 7) (param i32 i32) (result i32) + i32.const 1048620 local.get 1 local.get 0 call $::alloc ) - (func $__rust_realloc (;8;) (type 7) (param i32 i32 i32 i32) (result i32) + (func $__rust_realloc (;9;) (type 8) (param i32 i32 i32 i32) (result i32) block ;; label = @1 - i32.const 1048616 + i32.const 1048620 local.get 2 local.get 3 call $::alloc @@ -96,9 +108,9 @@ end local.get 2 ) - (func $__rust_alloc_zeroed (;9;) (type 6) (param i32 i32) (result i32) + (func $__rust_alloc_zeroed (;10;) (type 7) (param i32 i32) (result i32) block ;; label = @1 - i32.const 1048616 + i32.const 1048620 local.get 1 local.get 0 call $::alloc @@ -112,8 +124,8 @@ end local.get 1 ) - (func $miden:base/note-script@1.0.0#note-script (;10;) (type 5) - (local i32 f32 i32 i32) + (func $miden:base/note-script@1.0.0#note-script (;11;) (type 6) + (local i32 i32 i32 f32) global.get $__stack_pointer i32.const 32 i32.sub @@ -121,58 +133,78 @@ global.set $__stack_pointer call $wit_bindgen_rt::run_ctors_once local.get 0 - i32.const 8 + i32.const 4 i32.add call $miden_base_sys::bindings::note::get_inputs + local.get 0 + i32.load offset=12 + local.set 1 + local.get 0 + i32.load offset=8 + local.set 2 + local.get 0 + i64.const 0 + i64.store offset=16 + local.get 2 + local.get 1 + local.get 0 + i32.const 16 + i32.add + call $p2id::bindings::miden::basic_wallet::aux::process_list_felt::wit_import block ;; label = @1 local.get 0 - i32.load offset=16 + i32.load offset=20 + i32.eqz + br_if 0 (;@1;) + local.get 1 i32.eqz br_if 0 (;@1;) local.get 0 - i32.load offset=12 + i32.load offset=16 f32.load - local.set 1 + local.get 2 + f32.load + call $miden_stdlib_sys::intrinsics::felt::extern_assert_eq + local.get 2 + f32.load + local.set 3 call $miden_base_sys::bindings::account::get_id - local.get 1 - call $miden_stdlib_sys::intrinsics::felt::extern_eq - i32.const 1 - i32.ne - br_if 0 (;@1;) + local.get 3 + call $miden_stdlib_sys::intrinsics::felt::extern_assert_eq local.get 0 - i32.const 20 + i32.const 16 i32.add call $miden_base_sys::bindings::note::get_assets local.get 0 - i32.load offset=28 + i32.load offset=24 i32.const 5 i32.shl - local.set 2 + local.set 1 local.get 0 - i32.load offset=24 - local.set 3 + i32.load offset=20 + local.set 2 block ;; label = @2 loop ;; label = @3 - local.get 2 + local.get 1 i32.eqz br_if 1 (;@2;) - local.get 3 + local.get 2 f32.load - local.get 3 + local.get 2 f32.load offset=4 - local.get 3 + local.get 2 f32.load offset=8 - local.get 3 + local.get 2 f32.load offset=12 call $p2id::bindings::miden::basic_wallet::basic_wallet::receive_asset::wit_import - local.get 2 + local.get 1 i32.const -32 i32.add - local.set 2 - local.get 3 + local.set 1 + local.get 2 i32.const 32 i32.add - local.set 3 + local.set 2 br 0 (;@3;) end end @@ -184,14 +216,14 @@ end unreachable ) - (func $cabi_realloc_wit_bindgen_0_28_0 (;11;) (type 7) (param i32 i32 i32 i32) (result i32) + (func $cabi_realloc_wit_bindgen_0_28_0 (;12;) (type 8) (param i32 i32 i32 i32) (result i32) local.get 0 local.get 1 local.get 2 local.get 3 call $wit_bindgen_rt::cabi_realloc ) - (func $wit_bindgen_rt::cabi_realloc (;12;) (type 7) (param i32 i32 i32 i32) (result i32) + (func $wit_bindgen_rt::cabi_realloc (;13;) (type 8) (param i32 i32 i32 i32) (result i32) block ;; label = @1 block ;; label = @2 block ;; label = @3 @@ -201,7 +233,7 @@ i32.eqz br_if 2 (;@1;) i32.const 0 - i32.load8_u offset=1048620 + i32.load8_u offset=1048624 drop local.get 3 local.get 2 @@ -222,18 +254,18 @@ end local.get 2 ) - (func $wit_bindgen_rt::run_ctors_once (;13;) (type 5) + (func $wit_bindgen_rt::run_ctors_once (;14;) (type 6) block ;; label = @1 i32.const 0 - i32.load8_u offset=1048621 + i32.load8_u offset=1048625 br_if 0 (;@1;) call $__wasm_call_ctors i32.const 0 i32.const 1 - i32.store8 offset=1048621 + i32.store8 offset=1048625 end ) - (func $::alloc (;14;) (type 8) (param i32 i32 i32) (result i32) + (func $::alloc (;15;) (type 9) (param i32 i32 i32) (result i32) (local i32 i32) block ;; label = @1 local.get 1 @@ -301,10 +333,10 @@ end unreachable ) - (func $miden_base_sys::bindings::account::get_id (;15;) (type 3) (result f32) + (func $miden_base_sys::bindings::account::get_id (;16;) (type 4) (result f32) call $miden_base_sys::bindings::account::extern_account_get_id ) - (func $miden_base_sys::bindings::note::get_inputs (;16;) (type 9) (param i32) + (func $miden_base_sys::bindings::note::get_inputs (;17;) (type 10) (param i32) (local i32 i32 i32) global.get $__stack_pointer i32.const 16 @@ -351,10 +383,10 @@ i32.add global.set $__stack_pointer ) - (func $miden_base_sys::bindings::note::get_assets (;17;) (type 9) (param i32) + (func $miden_base_sys::bindings::note::get_assets (;18;) (type 10) (param i32) unreachable ) - (func $alloc::raw_vec::RawVec::try_allocate_in (;18;) (type 10) (param i32 i32 i32) + (func $alloc::raw_vec::RawVec::try_allocate_in (;19;) (type 0) (param i32 i32 i32) (local i32) block ;; label = @1 block ;; label = @2 @@ -387,7 +419,7 @@ local.get 2 br_if 0 (;@4;) i32.const 0 - i32.load8_u offset=1048620 + i32.load8_u offset=1048624 drop local.get 3 i32.const 4 @@ -428,10 +460,10 @@ local.get 1 i32.store ) - (func $alloc::raw_vec::handle_error (;19;) (type 11) (param i32 i32) + (func $alloc::raw_vec::handle_error (;20;) (type 11) (param i32 i32) unreachable ) - (func $cabi_realloc (;20;) (type 7) (param i32 i32 i32 i32) (result i32) + (func $cabi_realloc (;21;) (type 8) (param i32 i32 i32 i32) (result i32) local.get 0 local.get 1 local.get 2 @@ -446,55 +478,91 @@ (export "cabi_realloc_wit_bindgen_0_28_0" (func $cabi_realloc_wit_bindgen_0_28_0)) (export "cabi_realloc" (func $cabi_realloc)) (elem (;0;) (i32.const 1) func $p2id::bindings::__link_custom_section_describing_imports $cabi_realloc) - (data $.rodata (;0;) (i32.const 1048576) "\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\02\00\00\00") + (data $.rodata (;0;) (i32.const 1048576) "\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00\02\00\00\00") + ) + (core module (;1;) + (type (;0;) (func (param i32 i32 i32))) + (func $indirect-miden:basic-wallet/aux@1.0.0-process-list-felt (;0;) (type 0) (param i32 i32 i32) + local.get 0 + local.get 1 + local.get 2 + i32.const 0 + call_indirect (type 0) + ) + (table (;0;) 1 1 funcref) + (export "0" (func $indirect-miden:basic-wallet/aux@1.0.0-process-list-felt)) + (export "$imports" (table 0)) ) - (alias export 3 "eq" (func (;0;))) - (core func (;0;) (canon lower (func 0))) - (core instance (;0;) - (export "eq" (func 0)) + (core module (;2;) + (type (;0;) (func (param i32 i32 i32))) + (import "" "0" (func (;0;) (type 0))) + (import "" "$imports" (table (;0;) 1 1 funcref)) + (elem (;0;) (i32.const 0) func 0) ) - (alias export 1 "receive-asset" (func (;1;))) - (core func (;1;) (canon lower (func 1))) + (core instance (;0;) (instantiate 1)) + (alias core export 0 "0" (core func (;0;))) (core instance (;1;) - (export "receive-asset" (func 1)) + (export "process-list-felt" (func 0)) ) - (alias export 2 "heap-base" (func (;2;))) - (core func (;2;) (canon lower (func 2))) + (alias export 4 "assert-eq" (func (;0;))) + (core func (;1;) (canon lower (func 0))) (core instance (;2;) - (export "heap-base" (func 2)) + (export "assert-eq" (func 1)) ) - (alias export 4 "get-id" (func (;3;))) - (core func (;3;) (canon lower (func 3))) + (alias export 1 "receive-asset" (func (;1;))) + (core func (;2;) (canon lower (func 1))) (core instance (;3;) - (export "get-id" (func 3)) + (export "receive-asset" (func 2)) ) - (alias export 5 "get-inputs" (func (;4;))) - (core func (;4;) (canon lower (func 4))) + (alias export 3 "heap-base" (func (;2;))) + (core func (;3;) (canon lower (func 2))) (core instance (;4;) - (export "get-inputs" (func 4)) + (export "heap-base" (func 3)) + ) + (alias export 5 "get-id" (func (;3;))) + (core func (;4;) (canon lower (func 3))) + (core instance (;5;) + (export "get-id" (func 4)) + ) + (alias export 6 "get-inputs" (func (;4;))) + (core func (;5;) (canon lower (func 4))) + (core instance (;6;) + (export "get-inputs" (func 5)) + ) + (core instance (;7;) (instantiate 0 + (with "miden:basic-wallet/aux@1.0.0" (instance 1)) + (with "miden:core-import/intrinsics-felt@1.0.0" (instance 2)) + (with "miden:basic-wallet/basic-wallet@1.0.0" (instance 3)) + (with "miden:core-import/intrinsics-mem@1.0.0" (instance 4)) + (with "miden:core-import/account@1.0.0" (instance 5)) + (with "miden:core-import/note@1.0.0" (instance 6)) + ) + ) + (alias core export 7 "memory" (core memory (;0;))) + (alias core export 7 "cabi_realloc" (core func (;6;))) + (alias core export 0 "$imports" (core table (;0;))) + (alias export 2 "process-list-felt" (func (;5;))) + (core func (;7;) (canon lower (func 5) (memory 0) (realloc 6))) + (core instance (;8;) + (export "$imports" (table 0)) + (export "0" (func 7)) ) - (core instance (;5;) (instantiate 0 - (with "miden:core-import/intrinsics-felt@1.0.0" (instance 0)) - (with "miden:basic-wallet/basic-wallet@1.0.0" (instance 1)) - (with "miden:core-import/intrinsics-mem@1.0.0" (instance 2)) - (with "miden:core-import/account@1.0.0" (instance 3)) - (with "miden:core-import/note@1.0.0" (instance 4)) + (core instance (;9;) (instantiate 2 + (with "" (instance 8)) ) ) - (alias core export 5 "memory" (core memory (;0;))) - (alias core export 5 "cabi_realloc" (core func (;5;))) - (type (;7;) (func)) - (alias core export 5 "miden:base/note-script@1.0.0#note-script" (core func (;6;))) - (func (;5;) (type 7) (canon lift (core func 6))) + (type (;9;) (func)) + (alias core export 7 "miden:base/note-script@1.0.0#note-script" (core func (;8;))) + (func (;6;) (type 9) (canon lift (core func 8))) (component (;0;) (type (;0;) (func)) (import "import-func-note-script" (func (;0;) (type 0))) (type (;1;) (func)) (export (;1;) "note-script" (func 0) (func (type 1))) ) - (instance (;6;) (instantiate 0 - (with "import-func-note-script" (func 5)) + (instance (;7;) (instantiate 0 + (with "import-func-note-script" (func 6)) ) ) - (export (;7;) "miden:base/note-script@1.0.0" (instance 6)) + (export (;8;) "miden:base/note-script@1.0.0" (instance 7)) ) \ No newline at end of file diff --git a/tests/integration/src/rust_masm_tests/components.rs b/tests/integration/src/rust_masm_tests/components.rs index cce078f93..8a41f9f1f 100644 --- a/tests/integration/src/rust_masm_tests/components.rs +++ b/tests/integration/src/rust_masm_tests/components.rs @@ -193,11 +193,12 @@ fn wcm_import() { assert!(!ir_component.modules().is_empty()); let export_name_sym = Symbol::intern("inc"); - let export = ir_component.exports().get(&export_name_sym.into()).unwrap(); - assert_eq!(export.function.function.as_symbol(), export_name_sym); + todo!("restore these checks"); + // let export = ir_component.exports().get(&export_name_sym.into()).unwrap(); + // assert_eq!(export.function.function.as_symbol(), export_name_sym); let expected_export_func_ty = FunctionType::new_wasm(vec![Type::U32], vec![Type::U32]); - assert_eq!(export.function_ty, expected_export_func_ty); + // assert_eq!(export.function_ty, expected_export_func_ty); let module = ir_component.modules().first().unwrap().1; dbg!(&module.imports()); let import_info = module.imports(); diff --git a/tests/integration/src/rust_masm_tests/rust_sdk.rs b/tests/integration/src/rust_masm_tests/rust_sdk.rs index 9cf468567..3733e4620 100644 --- a/tests/integration/src/rust_masm_tests/rust_sdk.rs +++ b/tests/integration/src/rust_masm_tests/rust_sdk.rs @@ -41,6 +41,18 @@ fn rust_sdk_basic_wallet() { test.expect_wasm(expect_file![format!("../../expected/rust_sdk/{artifact_name}.wat")]); test.expect_ir(expect_file![format!("../../expected/rust_sdk/{artifact_name}.hir")]); test.expect_masm(expect_file![format!("../../expected/rust_sdk/{artifact_name}.masm")]); + let package = test.compiled_package(); + let lib = package.unwrap_library(); + let expected_module = "basic_wallet::miden:basic-wallet/basic-wallet@1.0.0"; + let expected_function = "receive-asset"; + let exports = lib + .exports() + .map(|e| (e.module.to_string(), e.name.as_str())) + .collect::>(); + // dbg!(&exports); + assert!(lib.exports().any(|export| { + export.module.to_string() == expected_module && export.name.as_str() == expected_function + })); } #[test] @@ -87,5 +99,5 @@ fn rust_sdk_p2id_note_script() { let artifact_name = test.artifact_name().to_string(); test.expect_wasm(expect_file![format!("../../expected/rust_sdk/{artifact_name}.wat")]); test.expect_ir(expect_file![format!("../../expected/rust_sdk/{artifact_name}.hir")]); - // test.expect_masm(expect_file![format!("../../expected/rust_sdk/{artifact_name}.masm")]); + test.expect_masm(expect_file![format!("../../expected/rust_sdk/{artifact_name}.masm")]); } diff --git a/tests/integration/src/rust_masm_tests/wit_sdk.rs b/tests/integration/src/rust_masm_tests/wit_sdk.rs index 72e6cf2d2..71dc285fc 100644 --- a/tests/integration/src/rust_masm_tests/wit_sdk.rs +++ b/tests/integration/src/rust_masm_tests/wit_sdk.rs @@ -7,7 +7,7 @@ use std::{ use expect_test::expect_file; use miden_core::crypto::hash::RpoDigest; use midenc_frontend_wasm::WasmTranslationConfig; -use midenc_hir::{FunctionExportName, InterfaceFunctionIdent, InterfaceIdent, Symbol}; +use midenc_hir::{InterfaceFunctionIdent, InterfaceIdent, Symbol}; use crate::CompilerTest; @@ -41,8 +41,6 @@ fn sdk_basic_wallet() { }; let expected_imports: HashSet = [create_note_ident, remove_asset_ident, add_asset_ident].into_iter().collect(); - let expected_exports: Vec = - vec![Symbol::intern("send-asset").into(), Symbol::intern("receive-asset").into()]; let config = WasmTranslationConfig::default(); let mut test = CompilerTest::rust_source_cargo_component("../rust-apps-wasm/wit-sdk/basic-wallet", config); @@ -57,9 +55,6 @@ fn sdk_basic_wallet() { for import in ir.imports().values() { assert!(expected_imports.contains(&import.unwrap_canon_abi_import().interface_function)); } - for name in expected_exports { - assert!(ir.exports().contains_key(&name)); - } } #[test] @@ -92,7 +87,6 @@ fn sdk_basic_wallet_p2id_note() { ] .into_iter() .collect(); - let expected_exports: Vec = vec![Symbol::intern("note-script").into()]; let config = WasmTranslationConfig::default(); let mut test = CompilerTest::rust_source_cargo_component("../rust-apps-wasm/wit-sdk/p2id-note", config); @@ -113,7 +107,4 @@ fn sdk_basic_wallet_p2id_note() { assert!(canon_abi_import.options.realloc.is_some()); } } - for name in expected_exports { - assert!(ir.exports().contains_key(&name)); - } } diff --git a/tests/rust-apps-wasm/rust-sdk/basic-wallet/src/bindings.rs b/tests/rust-apps-wasm/rust-sdk/basic-wallet/src/bindings.rs index 5f865ea79..54bc572b8 100644 --- a/tests/rust-apps-wasm/rust-sdk/basic-wallet/src/bindings.rs +++ b/tests/rust-apps-wasm/rust-sdk/basic-wallet/src/bindings.rs @@ -42,6 +42,43 @@ pub mod miden { _rt::bool_lift(ret as u8) } } + #[allow(unused_unsafe, clippy::all)] + pub fn from_u64_unchecked(a: u64) -> f32 { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link( + wasm_import_module = "miden:core-import/intrinsics-felt@1.0.0" + )] + extern "C" { + #[link_name = "from-u64-unchecked"] + fn wit_import(_: i64) -> f32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i64) -> f32 { + unreachable!() + } + let ret = wit_import(_rt::as_i64(&a)); + ret + } + } + #[allow(unused_unsafe, clippy::all)] + pub fn assert_eq(a: f32, b: f32) { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link( + wasm_import_module = "miden:core-import/intrinsics-felt@1.0.0" + )] + extern "C" { + #[link_name = "assert-eq"] + fn wit_import(_: f32, _: f32); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: f32, _: f32) { + unreachable!() + } + wit_import(_rt::as_f32(&a), _rt::as_f32(&b)); + } + } } #[allow(dead_code, clippy::all)] pub mod stdlib_crypto_hashes_blake3 { @@ -200,6 +237,41 @@ pub mod exports { }, ); } + pub trait Guest { + fn receive_asset(core_asset: miden::CoreAsset); + fn send_asset( + core_asset: miden::CoreAsset, + tag: miden::Tag, + note_type: miden::NoteType, + recipient: miden::Recipient, + ); + } + #[doc(hidden)] + macro_rules! __export_miden_basic_wallet_basic_wallet_1_0_0_cabi { + ($ty:ident with_types_in $($path_to_types:tt)*) => { + const _ : () = { #[export_name = + "miden:basic-wallet/basic-wallet@1.0.0#receive-asset"] unsafe + extern "C" fn export_receive_asset(arg0 : f32, arg1 : f32, arg2 : + f32, arg3 : f32,) { $($path_to_types)*:: + _export_receive_asset_cabi::<$ty > (arg0, arg1, arg2, arg3) } + #[export_name = + "miden:basic-wallet/basic-wallet@1.0.0#send-asset"] unsafe extern + "C" fn export_send_asset(arg0 : f32, arg1 : f32, arg2 : f32, arg3 + : f32, arg4 : f32, arg5 : f32, arg6 : f32, arg7 : f32, arg8 : + f32, arg9 : f32,) { $($path_to_types)*:: + _export_send_asset_cabi::<$ty > (arg0, arg1, arg2, arg3, arg4, + arg5, arg6, arg7, arg8, arg9) } }; + }; + } + #[doc(hidden)] + pub(crate) use __export_miden_basic_wallet_basic_wallet_1_0_0_cabi; + } + #[allow(dead_code, clippy::all)] + pub mod aux { + #[used] + #[doc(hidden)] + static __FORCE_SECTION_REF: fn() = super::super::super::super::__link_custom_section_describing_imports; + use super::super::super::super::_rt; #[doc(hidden)] #[allow(non_snake_case)] pub unsafe fn _export_test_felt_intrinsics_cabi( @@ -243,52 +315,73 @@ pub mod exports { let len2 = l1; _rt::cabi_dealloc(base2, len2 * 1, 1); } - pub trait Guest { - fn receive_asset(core_asset: miden::CoreAsset); - fn send_asset( - core_asset: miden::CoreAsset, - tag: miden::Tag, - note_type: miden::NoteType, - recipient: miden::Recipient, + #[doc(hidden)] + #[allow(non_snake_case)] + pub unsafe fn _export_process_list_felt_cabi( + arg0: *mut u8, + arg1: usize, + ) -> *mut u8 { + #[cfg(target_arch = "wasm32")] _rt::run_ctors_once(); + let len0 = arg1; + let result1 = T::process_list_felt( + _rt::Vec::from_raw_parts(arg0.cast(), len0, len0), ); + let ptr2 = _RET_AREA.0.as_mut_ptr().cast::(); + let vec3 = (result1).into_boxed_slice(); + let ptr3 = vec3.as_ptr().cast::(); + let len3 = vec3.len(); + ::core::mem::forget(vec3); + *ptr2.add(4).cast::() = len3; + *ptr2.add(0).cast::<*mut u8>() = ptr3.cast_mut(); + ptr2 + } + #[doc(hidden)] + #[allow(non_snake_case)] + pub unsafe fn __post_return_process_list_felt(arg0: *mut u8) { + let l0 = *arg0.add(0).cast::<*mut u8>(); + let l1 = *arg0.add(4).cast::(); + let base2 = l0; + let len2 = l1; + _rt::cabi_dealloc(base2, len2 * 4, 4); + } + pub trait Guest { fn test_felt_intrinsics( a: miden::Felt, b: miden::Felt, ) -> miden::Felt; fn test_stdlib(input: _rt::Vec) -> _rt::Vec; + fn process_list_felt( + input: _rt::Vec, + ) -> _rt::Vec; } #[doc(hidden)] - macro_rules! __export_miden_basic_wallet_basic_wallet_1_0_0_cabi { + macro_rules! __export_miden_basic_wallet_aux_1_0_0_cabi { ($ty:ident with_types_in $($path_to_types:tt)*) => { const _ : () = { #[export_name = - "miden:basic-wallet/basic-wallet@1.0.0#receive-asset"] unsafe - extern "C" fn export_receive_asset(arg0 : f32, arg1 : f32, arg2 : - f32, arg3 : f32,) { $($path_to_types)*:: - _export_receive_asset_cabi::<$ty > (arg0, arg1, arg2, arg3) } - #[export_name = - "miden:basic-wallet/basic-wallet@1.0.0#send-asset"] unsafe extern - "C" fn export_send_asset(arg0 : f32, arg1 : f32, arg2 : f32, arg3 - : f32, arg4 : f32, arg5 : f32, arg6 : f32, arg7 : f32, arg8 : - f32, arg9 : f32,) { $($path_to_types)*:: - _export_send_asset_cabi::<$ty > (arg0, arg1, arg2, arg3, arg4, - arg5, arg6, arg7, arg8, arg9) } #[export_name = - "miden:basic-wallet/basic-wallet@1.0.0#test-felt-intrinsics"] - unsafe extern "C" fn export_test_felt_intrinsics(arg0 : f32, arg1 - : f32,) -> f32 { $($path_to_types)*:: + "miden:basic-wallet/aux@1.0.0#test-felt-intrinsics"] unsafe + extern "C" fn export_test_felt_intrinsics(arg0 : f32, arg1 : + f32,) -> f32 { $($path_to_types)*:: _export_test_felt_intrinsics_cabi::<$ty > (arg0, arg1) } - #[export_name = - "miden:basic-wallet/basic-wallet@1.0.0#test-stdlib"] unsafe - extern "C" fn export_test_stdlib(arg0 : * mut u8, arg1 : usize,) - -> * mut u8 { $($path_to_types)*:: _export_test_stdlib_cabi::<$ty - > (arg0, arg1) } #[export_name = - "cabi_post_miden:basic-wallet/basic-wallet@1.0.0#test-stdlib"] - unsafe extern "C" fn _post_return_test_stdlib(arg0 : * mut u8,) { + #[export_name = "miden:basic-wallet/aux@1.0.0#test-stdlib"] + unsafe extern "C" fn export_test_stdlib(arg0 : * mut u8, arg1 : + usize,) -> * mut u8 { $($path_to_types)*:: + _export_test_stdlib_cabi::<$ty > (arg0, arg1) } #[export_name = + "cabi_post_miden:basic-wallet/aux@1.0.0#test-stdlib"] unsafe + extern "C" fn _post_return_test_stdlib(arg0 : * mut u8,) { $($path_to_types)*:: __post_return_test_stdlib::<$ty > (arg0) } - }; + #[export_name = "miden:basic-wallet/aux@1.0.0#process-list-felt"] + unsafe extern "C" fn export_process_list_felt(arg0 : * mut u8, + arg1 : usize,) -> * mut u8 { $($path_to_types)*:: + _export_process_list_felt_cabi::<$ty > (arg0, arg1) } + #[export_name = + "cabi_post_miden:basic-wallet/aux@1.0.0#process-list-felt"] + unsafe extern "C" fn _post_return_process_list_felt(arg0 : * mut + u8,) { $($path_to_types)*:: __post_return_process_list_felt::<$ty + > (arg0) } }; }; } #[doc(hidden)] - pub(crate) use __export_miden_basic_wallet_basic_wallet_1_0_0_cabi; + pub(crate) use __export_miden_basic_wallet_aux_1_0_0_cabi; #[repr(align(4))] struct _RetArea([::core::mem::MaybeUninit; 8]); static mut _RET_AREA: _RetArea = _RetArea( @@ -327,6 +420,29 @@ mod _rt { val != 0 } } + pub fn as_i64(t: T) -> i64 { + t.as_i64() + } + pub trait AsI64 { + fn as_i64(self) -> i64; + } + impl<'a, T: Copy + AsI64> AsI64 for &'a T { + fn as_i64(self) -> i64 { + (*self).as_i64() + } + } + impl AsI64 for i64 { + #[inline] + fn as_i64(self) -> i64 { + self as i64 + } + } + impl AsI64 for u64 { + #[inline] + fn as_i64(self) -> i64 { + self as i64 + } + } pub fn as_i32(t: T) -> i32 { t.as_i32() } @@ -427,7 +543,9 @@ macro_rules! __export_basic_wallet_world_impl { $($path_to_types_root)*:: exports::miden::basic_wallet::basic_wallet::__export_miden_basic_wallet_basic_wallet_1_0_0_cabi!($ty with_types_in $($path_to_types_root)*:: - exports::miden::basic_wallet::basic_wallet); + exports::miden::basic_wallet::basic_wallet); $($path_to_types_root)*:: + exports::miden::basic_wallet::aux::__export_miden_basic_wallet_aux_1_0_0_cabi!($ty + with_types_in $($path_to_types_root)*:: exports::miden::basic_wallet::aux); }; } #[doc(inline)] @@ -435,9 +553,9 @@ pub(crate) use __export_basic_wallet_world_impl as export; #[cfg(target_arch = "wasm32")] #[link_section = "component-type:wit-bindgen:0.31.0:miden:basic-wallet@1.0.0:basic-wallet-world:encoded world"] #[doc(hidden)] -pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 1609] = *b"\ -\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xc0\x0b\x01A\x02\x01\ -A\x15\x01B\x1f\x01r\x01\x05innerv\x04\0\x04felt\x03\0\0\x01o\x04\x01\x01\x01\x01\ +pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 1828] = *b"\ +\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\x9b\x0d\x01A\x02\x01\ +A\x17\x01B\x1f\x01r\x01\x05innerv\x04\0\x04felt\x03\0\0\x01o\x04\x01\x01\x01\x01\ \x01r\x01\x05inner\x02\x04\0\x04word\x03\0\x03\x01r\x01\x05inner\x01\x04\0\x0aac\ count-id\x03\0\x05\x01r\x01\x05inner\x04\x04\0\x09recipient\x03\0\x07\x01r\x01\x05\ inner\x01\x04\0\x03tag\x03\0\x09\x01r\x01\x05inner\x04\x04\0\x0acore-asset\x03\0\ @@ -448,30 +566,36 @@ orage-root\x03\0\x15\x01r\x01\x05inner\x04\x04\0\x11account-code-root\x03\0\x17\ r\x01\x05inner\x04\x04\0\x10vault-commitment\x03\0\x19\x01r\x01\x05inner\x01\x04\ \0\x07note-id\x03\0\x1b\x01r\x01\x05inner\x01\x04\0\x09note-type\x03\0\x1d\x03\x01\ \x1bmiden:base/core-types@1.0.0\x05\0\x01B\x02\x01@\0\0z\x04\0\x09heap-base\x01\0\ -\x03\x01&miden:core-import/intrinsics-mem@1.0.0\x05\x01\x01B\x04\x01@\x02\x01av\x01\ -bv\0v\x04\0\x03add\x01\0\x01@\x02\x01av\x01bv\0\x7f\x04\0\x02eq\x01\x01\x03\x01'\ -miden:core-import/intrinsics-felt@1.0.0\x05\x02\x01B\x02\x01@\x09\x02a0z\x02a1z\x02\ -a2z\x02a3z\x02a4z\x02a5z\x02a6z\x02a7z\x0aresult-ptrz\x01\0\x04\0\x0fhash-one-to\ --one\x01\0\x03\x013miden:core-import/stdlib-crypto-hashes-blake3@1.0.0\x05\x03\x01\ -B\x05\x01@\x05\x06asset0v\x06asset1v\x06asset2v\x06asset3v\x0aresult-ptrz\x01\0\x04\ -\0\x09add-asset\x01\0\x04\0\x0cremove-asset\x01\0\x01@\0\0v\x04\0\x06get-id\x01\x01\ -\x03\x01\x1fmiden:core-import/account@1.0.0\x05\x04\x01B\x03\x01@\x01\x03ptrz\0z\ -\x04\0\x0aget-inputs\x01\0\x04\0\x0aget-assets\x01\0\x03\x01\x1cmiden:core-impor\ -t/note@1.0.0\x05\x05\x01B\x02\x01@\x0a\x06asset0v\x06asset1v\x06asset2v\x06asset\ -3v\x03tagv\x09note-typev\x0arecipient0v\x0arecipient1v\x0arecipient2v\x0arecipie\ -nt3v\0v\x04\0\x0bcreate-note\x01\0\x03\x01\x1amiden:core-import/tx@1.0.0\x05\x06\ -\x02\x03\0\0\x0acore-asset\x02\x03\0\0\x03tag\x02\x03\0\0\x09recipient\x02\x03\0\ -\0\x09note-type\x02\x03\0\0\x04felt\x01B\x13\x02\x03\x02\x01\x07\x04\0\x0acore-a\ -sset\x03\0\0\x02\x03\x02\x01\x08\x04\0\x03tag\x03\0\x02\x02\x03\x02\x01\x09\x04\0\ -\x09recipient\x03\0\x04\x02\x03\x02\x01\x0a\x04\0\x09note-type\x03\0\x06\x02\x03\ -\x02\x01\x0b\x04\0\x04felt\x03\0\x08\x01@\x01\x0acore-asset\x01\x01\0\x04\0\x0dr\ -eceive-asset\x01\x0a\x01@\x04\x0acore-asset\x01\x03tag\x03\x09note-type\x07\x09r\ -ecipient\x05\x01\0\x04\0\x0asend-asset\x01\x0b\x01@\x02\x01a\x09\x01b\x09\0\x09\x04\ -\0\x14test-felt-intrinsics\x01\x0c\x01p}\x01@\x01\x05input\x0d\0\x0d\x04\0\x0bte\ -st-stdlib\x01\x0e\x04\x01%miden:basic-wallet/basic-wallet@1.0.0\x05\x0c\x04\x01+\ -miden:basic-wallet/basic-wallet-world@1.0.0\x04\0\x0b\x18\x01\0\x12basic-wallet-\ -world\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x070.216.\ -0\x10wit-bindgen-rust\x060.31.0"; +\x03\x01&miden:core-import/intrinsics-mem@1.0.0\x05\x01\x01B\x08\x01@\x02\x01av\x01\ +bv\0v\x04\0\x03add\x01\0\x01@\x02\x01av\x01bv\0\x7f\x04\0\x02eq\x01\x01\x01@\x01\ +\x01aw\0v\x04\0\x12from-u64-unchecked\x01\x02\x01@\x02\x01av\x01bv\x01\0\x04\0\x09\ +assert-eq\x01\x03\x03\x01'miden:core-import/intrinsics-felt@1.0.0\x05\x02\x01B\x02\ +\x01@\x09\x02a0z\x02a1z\x02a2z\x02a3z\x02a4z\x02a5z\x02a6z\x02a7z\x0aresult-ptrz\ +\x01\0\x04\0\x0fhash-one-to-one\x01\0\x03\x013miden:core-import/stdlib-crypto-ha\ +shes-blake3@1.0.0\x05\x03\x01B\x05\x01@\x05\x06asset0v\x06asset1v\x06asset2v\x06\ +asset3v\x0aresult-ptrz\x01\0\x04\0\x09add-asset\x01\0\x04\0\x0cremove-asset\x01\0\ +\x01@\0\0v\x04\0\x06get-id\x01\x01\x03\x01\x1fmiden:core-import/account@1.0.0\x05\ +\x04\x01B\x03\x01@\x01\x03ptrz\0z\x04\0\x0aget-inputs\x01\0\x04\0\x0aget-assets\x01\ +\0\x03\x01\x1cmiden:core-import/note@1.0.0\x05\x05\x01B\x02\x01@\x0a\x06asset0v\x06\ +asset1v\x06asset2v\x06asset3v\x03tagv\x09note-typev\x0arecipient0v\x0arecipient1\ +v\x0arecipient2v\x0arecipient3v\0v\x04\0\x0bcreate-note\x01\0\x03\x01\x1amiden:c\ +ore-import/tx@1.0.0\x05\x06\x02\x03\0\0\x0acore-asset\x02\x03\0\0\x03tag\x02\x03\ +\0\0\x09recipient\x02\x03\0\0\x09note-type\x02\x03\0\0\x04felt\x01B\x0e\x02\x03\x02\ +\x01\x07\x04\0\x0acore-asset\x03\0\0\x02\x03\x02\x01\x08\x04\0\x03tag\x03\0\x02\x02\ +\x03\x02\x01\x09\x04\0\x09recipient\x03\0\x04\x02\x03\x02\x01\x0a\x04\0\x09note-\ +type\x03\0\x06\x02\x03\x02\x01\x0b\x04\0\x04felt\x03\0\x08\x01@\x01\x0acore-asse\ +t\x01\x01\0\x04\0\x0dreceive-asset\x01\x0a\x01@\x04\x0acore-asset\x01\x03tag\x03\ +\x09note-type\x07\x09recipient\x05\x01\0\x04\0\x0asend-asset\x01\x0b\x04\x01%mid\ +en:basic-wallet/basic-wallet@1.0.0\x05\x0c\x01B\x12\x02\x03\x02\x01\x07\x04\0\x0a\ +core-asset\x03\0\0\x02\x03\x02\x01\x08\x04\0\x03tag\x03\0\x02\x02\x03\x02\x01\x09\ +\x04\0\x09recipient\x03\0\x04\x02\x03\x02\x01\x0a\x04\0\x09note-type\x03\0\x06\x02\ +\x03\x02\x01\x0b\x04\0\x04felt\x03\0\x08\x01@\x02\x01a\x09\x01b\x09\0\x09\x04\0\x14\ +test-felt-intrinsics\x01\x0a\x01p}\x01@\x01\x05input\x0b\0\x0b\x04\0\x0btest-std\ +lib\x01\x0c\x01p\x09\x01@\x01\x05input\x0d\0\x0d\x04\0\x11process-list-felt\x01\x0e\ +\x04\x01\x1cmiden:basic-wallet/aux@1.0.0\x05\x0d\x04\x01+miden:basic-wallet/basi\ +c-wallet-world@1.0.0\x04\0\x0b\x18\x01\0\x12basic-wallet-world\x03\0\0\0G\x09pro\ +ducers\x01\x0cprocessed-by\x02\x0dwit-component\x070.216.0\x10wit-bindgen-rust\x06\ +0.31.0"; #[inline(never)] #[doc(hidden)] pub fn __link_custom_section_describing_imports() { diff --git a/tests/rust-apps-wasm/rust-sdk/basic-wallet/src/lib.rs b/tests/rust-apps-wasm/rust-sdk/basic-wallet/src/lib.rs index 1ed7a98df..ec82c7a87 100644 --- a/tests/rust-apps-wasm/rust-sdk/basic-wallet/src/lib.rs +++ b/tests/rust-apps-wasm/rust-sdk/basic-wallet/src/lib.rs @@ -17,16 +17,17 @@ fn my_panic(_info: &core::panic::PanicInfo) -> ! { loop {} } +use bindings::exports::miden::basic_wallet::*; + bindings::export!(MyAccount with_types_in bindings); mod bindings; -use bindings::exports::miden::basic_wallet::basic_wallet::Guest; -use miden::{blake3_hash_1to1, CoreAsset, Felt, NoteType, Recipient, Tag}; +use miden::{blake3_hash_1to1, felt, CoreAsset, Felt, NoteType, Recipient, Tag}; struct MyAccount; -impl Guest for MyAccount { +impl basic_wallet::Guest for MyAccount { fn receive_asset(asset: CoreAsset) { miden::account::add_asset(asset); } @@ -35,7 +36,9 @@ impl Guest for MyAccount { let asset = miden::account::remove_asset(asset); miden::tx::create_note(asset, tag, note_type, recipient); } +} +impl aux::Guest for MyAccount { fn test_felt_intrinsics(a: Felt, b: Felt) -> Felt { a + b } @@ -44,4 +47,9 @@ impl Guest for MyAccount { let input: [u8; 32] = input.try_into().unwrap(); blake3_hash_1to1(input).to_vec() } + + fn process_list_felt(input: Vec) -> Vec { + // input.into_iter().map(|felt| felt + felt!(1)).collect() + todo!() + } } diff --git a/tests/rust-apps-wasm/rust-sdk/basic-wallet/wit/basic-wallet.wit b/tests/rust-apps-wasm/rust-sdk/basic-wallet/wit/basic-wallet.wit index 21ae5a4c4..e69b8339b 100644 --- a/tests/rust-apps-wasm/rust-sdk/basic-wallet/wit/basic-wallet.wit +++ b/tests/rust-apps-wasm/rust-sdk/basic-wallet/wit/basic-wallet.wit @@ -7,13 +7,19 @@ interface basic-wallet { receive-asset: func(core-asset: core-asset); send-asset: func(core-asset: core-asset, tag: tag, note-type: note-type, recipient: recipient); +} +interface aux { + use core-types.{core-asset, tag, recipient, note-type, felt}; test-felt-intrinsics: func(a: felt, b: felt) -> felt; test-stdlib: func(input: list) -> list; + process-list-felt: func(input: list) -> list; } + world basic-wallet-world { include miden:core-import/all@1.0.0; export basic-wallet; + export aux; } \ No newline at end of file diff --git a/tests/rust-apps-wasm/rust-sdk/p2id-note/src/bindings.rs b/tests/rust-apps-wasm/rust-sdk/p2id-note/src/bindings.rs index df2be688c..b27fe652f 100644 --- a/tests/rust-apps-wasm/rust-sdk/p2id-note/src/bindings.rs +++ b/tests/rust-apps-wasm/rust-sdk/p2id-note/src/bindings.rs @@ -117,13 +117,20 @@ pub mod miden { ); } } + } + #[allow(dead_code, clippy::all)] + pub mod aux { + #[used] + #[doc(hidden)] + static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; + use super::super::super::_rt; #[allow(unused_unsafe, clippy::all)] pub fn test_felt_intrinsics(a: miden::Felt, b: miden::Felt) -> miden::Felt { unsafe { let miden::Felt { inner: inner0 } = a; let miden::Felt { inner: inner1 } = b; #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "miden:basic-wallet/basic-wallet@1.0.0")] + #[link(wasm_import_module = "miden:basic-wallet/aux@1.0.0")] extern "C" { #[link_name = "test-felt-intrinsics"] fn wit_import(_: f32, _: f32) -> f32; @@ -147,7 +154,7 @@ pub mod miden { let len0 = vec0.len(); let ptr1 = ret_area.0.as_mut_ptr().cast::(); #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "miden:basic-wallet/basic-wallet@1.0.0")] + #[link(wasm_import_module = "miden:basic-wallet/aux@1.0.0")] extern "C" { #[link_name = "test-stdlib"] fn wit_import(_: *mut u8, _: usize, _: *mut u8); @@ -163,6 +170,33 @@ pub mod miden { _rt::Vec::from_raw_parts(l2.cast(), len4, len4) } } + #[allow(unused_unsafe, clippy::all)] + pub fn process_list_felt(input: &[miden::Felt]) -> _rt::Vec { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 8]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); + let vec0 = input; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + let ptr1 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "miden:basic-wallet/aux@1.0.0")] + extern "C" { + #[link_name = "process-list-felt"] + fn wit_import(_: *mut u8, _: usize, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: *mut u8, _: usize, _: *mut u8) { + unreachable!() + } + wit_import(ptr0.cast_mut(), len0, ptr1); + let l2 = *ptr1.add(0).cast::<*mut u8>(); + let l3 = *ptr1.add(4).cast::(); + let len4 = l3; + _rt::Vec::from_raw_parts(l2.cast(), len4, len4) + } + } } } #[allow(dead_code)] @@ -198,6 +232,43 @@ pub mod miden { _rt::bool_lift(ret as u8) } } + #[allow(unused_unsafe, clippy::all)] + pub fn from_u64_unchecked(a: u64) -> f32 { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link( + wasm_import_module = "miden:core-import/intrinsics-felt@1.0.0" + )] + extern "C" { + #[link_name = "from-u64-unchecked"] + fn wit_import(_: i64) -> f32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i64) -> f32 { + unreachable!() + } + let ret = wit_import(_rt::as_i64(&a)); + ret + } + } + #[allow(unused_unsafe, clippy::all)] + pub fn assert_eq(a: f32, b: f32) { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link( + wasm_import_module = "miden:core-import/intrinsics-felt@1.0.0" + )] + extern "C" { + #[link_name = "assert-eq"] + fn wit_import(_: f32, _: f32); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: f32, _: f32) { + unreachable!() + } + wit_import(_rt::as_f32(&a), _rt::as_f32(&b)); + } + } } #[allow(dead_code, clippy::all)] pub mod stdlib_crypto_hashes_blake3 { @@ -346,6 +417,29 @@ mod _rt { val != 0 } } + pub fn as_i64(t: T) -> i64 { + t.as_i64() + } + pub trait AsI64 { + fn as_i64(self) -> i64; + } + impl<'a, T: Copy + AsI64> AsI64 for &'a T { + fn as_i64(self) -> i64 { + (*self).as_i64() + } + } + impl AsI64 for i64 { + #[inline] + fn as_i64(self) -> i64 { + self as i64 + } + } + impl AsI64 for u64 { + #[inline] + fn as_i64(self) -> i64 { + self as i64 + } + } pub fn as_i32(t: T) -> i32 { t.as_i32() } @@ -444,9 +538,9 @@ pub(crate) use __export_p2id_world_impl as export; #[cfg(target_arch = "wasm32")] #[link_section = "component-type:wit-bindgen:0.31.0:miden:p2id@1.0.0:p2id-world:encoded world"] #[doc(hidden)] -pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 1642] = *b"\ -\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xe9\x0b\x01A\x02\x01\ -A\x17\x01B\x1f\x01r\x01\x05innerv\x04\0\x04felt\x03\0\0\x01o\x04\x01\x01\x01\x01\ +pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 1861] = *b"\ +\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xc4\x0d\x01A\x02\x01\ +A\x19\x01B\x1f\x01r\x01\x05innerv\x04\0\x04felt\x03\0\0\x01o\x04\x01\x01\x01\x01\ \x01r\x01\x05inner\x02\x04\0\x04word\x03\0\x03\x01r\x01\x05inner\x01\x04\0\x0aac\ count-id\x03\0\x05\x01r\x01\x05inner\x04\x04\0\x09recipient\x03\0\x07\x01r\x01\x05\ inner\x01\x04\0\x03tag\x03\0\x09\x01r\x01\x05inner\x04\x04\0\x0acore-asset\x03\0\ @@ -457,31 +551,37 @@ orage-root\x03\0\x15\x01r\x01\x05inner\x04\x04\0\x11account-code-root\x03\0\x17\ r\x01\x05inner\x04\x04\0\x10vault-commitment\x03\0\x19\x01r\x01\x05inner\x01\x04\ \0\x07note-id\x03\0\x1b\x01r\x01\x05inner\x01\x04\0\x09note-type\x03\0\x1d\x03\x01\ \x1bmiden:base/core-types@1.0.0\x05\0\x02\x03\0\0\x0acore-asset\x02\x03\0\0\x03t\ -ag\x02\x03\0\0\x09recipient\x02\x03\0\0\x09note-type\x02\x03\0\0\x04felt\x01B\x13\ +ag\x02\x03\0\0\x09recipient\x02\x03\0\0\x09note-type\x02\x03\0\0\x04felt\x01B\x0e\ \x02\x03\x02\x01\x01\x04\0\x0acore-asset\x03\0\0\x02\x03\x02\x01\x02\x04\0\x03ta\ g\x03\0\x02\x02\x03\x02\x01\x03\x04\0\x09recipient\x03\0\x04\x02\x03\x02\x01\x04\ \x04\0\x09note-type\x03\0\x06\x02\x03\x02\x01\x05\x04\0\x04felt\x03\0\x08\x01@\x01\ \x0acore-asset\x01\x01\0\x04\0\x0dreceive-asset\x01\x0a\x01@\x04\x0acore-asset\x01\ -\x03tag\x03\x09note-type\x07\x09recipient\x05\x01\0\x04\0\x0asend-asset\x01\x0b\x01\ -@\x02\x01a\x09\x01b\x09\0\x09\x04\0\x14test-felt-intrinsics\x01\x0c\x01p}\x01@\x01\ -\x05input\x0d\0\x0d\x04\0\x0btest-stdlib\x01\x0e\x03\x01%miden:basic-wallet/basi\ -c-wallet@1.0.0\x05\x06\x01B\x02\x01@\0\0z\x04\0\x09heap-base\x01\0\x03\x01&miden\ -:core-import/intrinsics-mem@1.0.0\x05\x07\x01B\x04\x01@\x02\x01av\x01bv\0v\x04\0\ -\x03add\x01\0\x01@\x02\x01av\x01bv\0\x7f\x04\0\x02eq\x01\x01\x03\x01'miden:core-\ -import/intrinsics-felt@1.0.0\x05\x08\x01B\x02\x01@\x09\x02a0z\x02a1z\x02a2z\x02a\ -3z\x02a4z\x02a5z\x02a6z\x02a7z\x0aresult-ptrz\x01\0\x04\0\x0fhash-one-to-one\x01\ -\0\x03\x013miden:core-import/stdlib-crypto-hashes-blake3@1.0.0\x05\x09\x01B\x05\x01\ -@\x05\x06asset0v\x06asset1v\x06asset2v\x06asset3v\x0aresult-ptrz\x01\0\x04\0\x09\ -add-asset\x01\0\x04\0\x0cremove-asset\x01\0\x01@\0\0v\x04\0\x06get-id\x01\x01\x03\ -\x01\x1fmiden:core-import/account@1.0.0\x05\x0a\x01B\x03\x01@\x01\x03ptrz\0z\x04\ -\0\x0aget-inputs\x01\0\x04\0\x0aget-assets\x01\0\x03\x01\x1cmiden:core-import/no\ -te@1.0.0\x05\x0b\x01B\x02\x01@\x0a\x06asset0v\x06asset1v\x06asset2v\x06asset3v\x03\ -tagv\x09note-typev\x0arecipient0v\x0arecipient1v\x0arecipient2v\x0arecipient3v\0\ -v\x04\0\x0bcreate-note\x01\0\x03\x01\x1amiden:core-import/tx@1.0.0\x05\x0c\x01B\x02\ -\x01@\0\x01\0\x04\0\x0bnote-script\x01\0\x04\x01\x1cmiden:base/note-script@1.0.0\ -\x05\x0d\x04\x01\x1bmiden:p2id/p2id-world@1.0.0\x04\0\x0b\x10\x01\0\x0ap2id-worl\ -d\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x070.216.0\x10\ -wit-bindgen-rust\x060.31.0"; +\x03tag\x03\x09note-type\x07\x09recipient\x05\x01\0\x04\0\x0asend-asset\x01\x0b\x03\ +\x01%miden:basic-wallet/basic-wallet@1.0.0\x05\x06\x01B\x12\x02\x03\x02\x01\x01\x04\ +\0\x0acore-asset\x03\0\0\x02\x03\x02\x01\x02\x04\0\x03tag\x03\0\x02\x02\x03\x02\x01\ +\x03\x04\0\x09recipient\x03\0\x04\x02\x03\x02\x01\x04\x04\0\x09note-type\x03\0\x06\ +\x02\x03\x02\x01\x05\x04\0\x04felt\x03\0\x08\x01@\x02\x01a\x09\x01b\x09\0\x09\x04\ +\0\x14test-felt-intrinsics\x01\x0a\x01p}\x01@\x01\x05input\x0b\0\x0b\x04\0\x0bte\ +st-stdlib\x01\x0c\x01p\x09\x01@\x01\x05input\x0d\0\x0d\x04\0\x11process-list-fel\ +t\x01\x0e\x03\x01\x1cmiden:basic-wallet/aux@1.0.0\x05\x07\x01B\x02\x01@\0\0z\x04\ +\0\x09heap-base\x01\0\x03\x01&miden:core-import/intrinsics-mem@1.0.0\x05\x08\x01\ +B\x08\x01@\x02\x01av\x01bv\0v\x04\0\x03add\x01\0\x01@\x02\x01av\x01bv\0\x7f\x04\0\ +\x02eq\x01\x01\x01@\x01\x01aw\0v\x04\0\x12from-u64-unchecked\x01\x02\x01@\x02\x01\ +av\x01bv\x01\0\x04\0\x09assert-eq\x01\x03\x03\x01'miden:core-import/intrinsics-f\ +elt@1.0.0\x05\x09\x01B\x02\x01@\x09\x02a0z\x02a1z\x02a2z\x02a3z\x02a4z\x02a5z\x02\ +a6z\x02a7z\x0aresult-ptrz\x01\0\x04\0\x0fhash-one-to-one\x01\0\x03\x013miden:cor\ +e-import/stdlib-crypto-hashes-blake3@1.0.0\x05\x0a\x01B\x05\x01@\x05\x06asset0v\x06\ +asset1v\x06asset2v\x06asset3v\x0aresult-ptrz\x01\0\x04\0\x09add-asset\x01\0\x04\0\ +\x0cremove-asset\x01\0\x01@\0\0v\x04\0\x06get-id\x01\x01\x03\x01\x1fmiden:core-i\ +mport/account@1.0.0\x05\x0b\x01B\x03\x01@\x01\x03ptrz\0z\x04\0\x0aget-inputs\x01\ +\0\x04\0\x0aget-assets\x01\0\x03\x01\x1cmiden:core-import/note@1.0.0\x05\x0c\x01\ +B\x02\x01@\x0a\x06asset0v\x06asset1v\x06asset2v\x06asset3v\x03tagv\x09note-typev\ +\x0arecipient0v\x0arecipient1v\x0arecipient2v\x0arecipient3v\0v\x04\0\x0bcreate-\ +note\x01\0\x03\x01\x1amiden:core-import/tx@1.0.0\x05\x0d\x01B\x02\x01@\0\x01\0\x04\ +\0\x0bnote-script\x01\0\x04\x01\x1cmiden:base/note-script@1.0.0\x05\x0e\x04\x01\x1b\ +miden:p2id/p2id-world@1.0.0\x04\0\x0b\x10\x01\0\x0ap2id-world\x03\0\0\0G\x09prod\ +ucers\x01\x0cprocessed-by\x02\x0dwit-component\x070.216.0\x10wit-bindgen-rust\x06\ +0.31.0"; #[inline(never)] #[doc(hidden)] pub fn __link_custom_section_describing_imports() { diff --git a/tests/rust-apps-wasm/rust-sdk/p2id-note/src/lib.rs b/tests/rust-apps-wasm/rust-sdk/p2id-note/src/lib.rs index 50a63137a..f6e295003 100644 --- a/tests/rust-apps-wasm/rust-sdk/p2id-note/src/lib.rs +++ b/tests/rust-apps-wasm/rust-sdk/p2id-note/src/lib.rs @@ -22,17 +22,23 @@ bindings::export!(MyNote with_types_in bindings); mod bindings; use bindings::{ - exports::miden::base::note_script::Guest, miden::basic_wallet::basic_wallet::receive_asset, + exports::miden::base::note_script::Guest, + miden::basic_wallet::{aux::process_list_felt, basic_wallet::receive_asset}, }; +use miden::*; struct MyNote; impl Guest for MyNote { fn note_script() { let inputs = miden::note::get_inputs(); + + let outs = process_list_felt(&inputs); + assert_eq(outs[0], inputs[0]); + let target_account_id_felt = inputs[0]; let account_id = miden::account::get_id(); - assert_eq!(account_id.as_felt(), target_account_id_felt); + assert_eq(account_id.as_felt(), target_account_id_felt); let assets = miden::note::get_assets(); for asset in assets { receive_asset(asset); diff --git a/tests/rust-apps-wasm/rust-sdk/p2id-note/wit/p2id.wit b/tests/rust-apps-wasm/rust-sdk/p2id-note/wit/p2id.wit index 53962aebe..4628ae486 100644 --- a/tests/rust-apps-wasm/rust-sdk/p2id-note/wit/p2id.wit +++ b/tests/rust-apps-wasm/rust-sdk/p2id-note/wit/p2id.wit @@ -4,5 +4,6 @@ world p2id-world { include miden:core-import/all@1.0.0; import miden:basic-wallet/basic-wallet@1.0.0; + import miden:basic-wallet/aux@1.0.0; export miden:base/note-script@1.0.0; } \ No newline at end of file diff --git a/tests/rust-apps-wasm/rust-sdk/wit-sdk/miden-core-import.wit b/tests/rust-apps-wasm/rust-sdk/wit-sdk/miden-core-import.wit index dc58ce812..386d8b294 100644 --- a/tests/rust-apps-wasm/rust-sdk/wit-sdk/miden-core-import.wit +++ b/tests/rust-apps-wasm/rust-sdk/wit-sdk/miden-core-import.wit @@ -12,6 +12,8 @@ interface intrinsics-felt { add: func(a: f32, b: f32) -> f32; eq: func(a: f32, b: f32) -> bool; + from-u64-unchecked: func(a: u64) -> f32; + assert-eq: func(a: f32, b: f32); } interface stdlib-crypto-hashes-blake3 { diff --git a/tools/cargo-miden/src/lib.rs b/tools/cargo-miden/src/lib.rs index d42cdce15..fb2c5261e 100644 --- a/tools/cargo-miden/src/lib.rs +++ b/tools/cargo-miden/src/lib.rs @@ -197,6 +197,7 @@ where "hash-two-to-one", "add-asset", "add", + "unchecked-from-u64", ] .into_iter() .map(|s| s.to_string()) From 61652e1051a9a20ca9fbb03d8a49a2dc35142c74 Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Tue, 19 Nov 2024 13:29:25 +0200 Subject: [PATCH 03/17] add `process_core_asset` to test passing and returning a struct --- .../expected/rust_sdk/basic_wallet.hir | 28 ++++-- .../expected/rust_sdk/basic_wallet.masm | 15 ++- .../expected/rust_sdk/basic_wallet.wat | 96 +++++++++++-------- .../rust-sdk/basic-wallet/src/bindings.rs | 59 ++++++++++-- .../rust-sdk/basic-wallet/src/lib.rs | 4 + .../basic-wallet/wit/basic-wallet.wit | 3 +- .../rust-sdk/p2id-note/src/bindings.rs | 91 +++++++++++++----- 7 files changed, 211 insertions(+), 85 deletions(-) diff --git a/tests/integration/expected/rust_sdk/basic_wallet.hir b/tests/integration/expected/rust_sdk/basic_wallet.hir index c05ddb0e8..08ca08226 100644 --- a/tests/integration/expected/rust_sdk/basic_wallet.hir +++ b/tests/integration/expected/rust_sdk/basic_wallet.hir @@ -37,7 +37,7 @@ (func #__rust_alloc (param i32) (param i32) (result i32) (block 0 (param v0 i32) (param v1 i32) - (let (v3 i32) (const.i32 1048624)) + (let (v3 i32) (const.i32 1048632)) (let (v4 i32) (call #::alloc v3 v1 v0)) (br (block 1 v4))) @@ -56,7 +56,7 @@ (func #__rust_realloc (param i32) (param i32) (param i32) (param i32) (result i32) (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (param v3 i32) - (let (v5 i32) (const.i32 1048624)) + (let (v5 i32) (const.i32 1048632)) (let (v6 i32) (call #::alloc v5 v2 v3)) (let (v7 i1) (eq v6 0)) (let (v8 i32) (zext v7)) @@ -87,7 +87,7 @@ (func #__rust_alloc_zeroed (param i32) (param i32) (result i32) (block 0 (param v0 i32) (param v1 i32) - (let (v3 i32) (const.i32 1048624)) + (let (v3 i32) (const.i32 1048632)) (let (v4 i32) (call #::alloc v3 v1 v0)) (let (v5 i1) (eq v4 0)) (let (v6 i32) (zext v5)) @@ -506,6 +506,19 @@ (ret)) ) + (func (export #miden:basic-wallet/aux@1.0.0#process-core-asset) + (param felt) (param felt) (param felt) (param felt) (result i32) + (block 0 + (param v0 felt) + (param v1 felt) + (param v2 felt) + (param v3 felt) + (call #wit_bindgen_rt::run_ctors_once) + (unreachable)) + + (block 1 (param v4 i32)) + ) + (func (export #cabi_realloc_wit_bindgen_0_28_0) (param i32) (param i32) (param i32) (param i32) (result i32) (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (param v3 i32) @@ -545,7 +558,7 @@ (block 6 (let (v9 i32) (const.i32 0)) (let (v10 u32) (bitcast v9)) - (let (v11 u32) (add.checked v10 1048628)) + (let (v11 u32) (add.checked v10 1048636)) (let (v12 (ptr u8)) (inttoptr v11)) (let (v13 u8) (load v12)) (let (v14 i32) (zext v13)) @@ -560,7 +573,7 @@ (block 0 (let (v0 i32) (const.i32 0)) (let (v1 u32) (bitcast v0)) - (let (v2 u32) (add.checked v1 1048629)) + (let (v2 u32) (add.checked v1 1048637)) (let (v3 (ptr u8)) (inttoptr v2)) (let (v4 u8) (load v3)) (let (v5 i32) (zext v4)) @@ -580,7 +593,7 @@ (let (v9 u32) (bitcast v8)) (let (v10 u8) (trunc v9)) (let (v11 u32) (bitcast v7)) - (let (v12 u32) (add.checked v11 1048629)) + (let (v12 u32) (add.checked v11 1048637)) (let (v13 (ptr u8)) (inttoptr v12)) (store v13 v10) (br (block 2))) @@ -1172,7 +1185,7 @@ (block 5 (let (v8 i32) (const.i32 0)) (let (v9 u32) (bitcast v8)) - (let (v10 u32) (add.checked v9 1048628)) + (let (v10 u32) (add.checked v9 1048636)) (let (v11 (ptr u8)) (inttoptr v10)) (let (v12 u8) (load v11)) (let (v13 i32) (zext v12)) @@ -1311,6 +1324,7 @@ ;; Component Exports + (lift (miden:basic-wallet/aux@1.0.0#process-core-asset) (#basic_wallet #miden:basic-wallet/aux@1.0.0#process-core-asset (func (abi wasm) (param (struct (struct (struct (struct felt) (struct felt) (struct felt) (struct felt))))) (result (struct (struct (struct (struct felt) (struct felt) (struct felt) (struct felt)))))) ) (lift (miden:basic-wallet/aux@1.0.0#process-list-felt) (#basic_wallet #miden:basic-wallet/aux@1.0.0#process-list-felt (func (abi wasm) (param (list (struct felt))) (result (list (struct felt)))) (realloc (#basic_wallet #cabi_realloc) (post-return (#basic_wallet #cabi_post_miden:basic-wallet/aux@1.0.0#process-list-felt) ) (lift (miden:basic-wallet/aux@1.0.0#test-felt-intrinsics) (#basic_wallet #miden:basic-wallet/aux@1.0.0#test-felt-intrinsics (func (abi wasm) (param (struct felt)) (param (struct felt)) (result (struct felt))) ) (lift (miden:basic-wallet/aux@1.0.0#test-stdlib) (#basic_wallet #miden:basic-wallet/aux@1.0.0#test-stdlib (func (abi wasm) (param (list u8)) (result (list u8))) (realloc (#basic_wallet #cabi_realloc) (post-return (#basic_wallet #cabi_post_miden:basic-wallet/aux@1.0.0#process-list-felt) ) diff --git a/tests/integration/expected/rust_sdk/basic_wallet.masm b/tests/integration/expected/rust_sdk/basic_wallet.masm index 1bb984d41..40539122a 100644 --- a/tests/integration/expected/rust_sdk/basic_wallet.masm +++ b/tests/integration/expected/rust_sdk/basic_wallet.masm @@ -410,7 +410,7 @@ end proc."wit_bindgen_rt::run_ctors_once" push.0 - add.1048629 + add.1048637 u32assert dup.0 u32mod.16 @@ -432,7 +432,7 @@ proc."wit_bindgen_rt::run_ctors_once" push.128 u32and push.0 - add.1048629 + add.1048637 u32assert dup.0 u32mod.16 @@ -1902,7 +1902,7 @@ end proc."__rust_alloc" - push.1048624 + push.1048632 movup.2 swap.1 exec."::alloc" @@ -1910,7 +1910,7 @@ end proc."__rust_alloc_zeroed" - push.1048624 + push.1048632 dup.1 swap.2 swap.3 @@ -1972,7 +1972,7 @@ end proc."__rust_realloc" - push.1048624 + push.1048632 dup.4 swap.2 swap.4 @@ -2075,6 +2075,11 @@ export.cabi_realloc_wit_bindgen_0_28_0 end +export."miden:basic-wallet/aux@1.0.0#process-core-asset" + exec."wit_bindgen_rt::run_ctors_once" push.0 assert +end + + export."miden:basic-wallet/aux@1.0.0#process-list-felt" exec."wit_bindgen_rt::run_ctors_once" push.0 assert end diff --git a/tests/integration/expected/rust_sdk/basic_wallet.wat b/tests/integration/expected/rust_sdk/basic_wallet.wat index a9a02267c..8c21a7417 100644 --- a/tests/integration/expected/rust_sdk/basic_wallet.wat +++ b/tests/integration/expected/rust_sdk/basic_wallet.wat @@ -66,10 +66,11 @@ (type (;9;) (func (param f32 f32 f32 f32))) (type (;10;) (func (param f32 f32 f32 f32 f32 f32 f32 f32 f32 f32))) (type (;11;) (func (param i32))) - (type (;12;) (func (param i32 i32 i32) (result i32))) - (type (;13;) (func (param i32 i32))) - (type (;14;) (func (param i32 f32 f32 i32) (result f32))) - (type (;15;) (func (param i32 i32 i32 i32))) + (type (;12;) (func (param f32 f32 f32 f32) (result i32))) + (type (;13;) (func (param i32 i32 i32) (result i32))) + (type (;14;) (func (param i32 i32))) + (type (;15;) (func (param i32 f32 f32 i32) (result f32))) + (type (;16;) (func (param i32 i32 i32 i32))) (import "miden:core-import/intrinsics-felt@1.0.0" "add" (func $miden_stdlib_sys::intrinsics::felt::extern_add (;0;) (type 0))) (import "miden:core-import/stdlib-crypto-hashes-blake3@1.0.0" "hash-one-to-one" (func $miden_stdlib_sys::stdlib::crypto::hashes::extern_blake3_hash_1to1 (;1;) (type 1))) (import "miden:core-import/intrinsics-mem@1.0.0" "heap-base" (func $miden_sdk_alloc::heap_base (;2;) (type 2))) @@ -79,7 +80,7 @@ (func $__wasm_call_ctors (;6;) (type 5)) (func $basic_wallet::bindings::__link_custom_section_describing_imports (;7;) (type 5)) (func $__rust_alloc (;8;) (type 6) (param i32 i32) (result i32) - i32.const 1048624 + i32.const 1048632 local.get 1 local.get 0 call $::alloc @@ -87,7 +88,7 @@ (func $__rust_dealloc (;9;) (type 7) (param i32 i32 i32)) (func $__rust_realloc (;10;) (type 8) (param i32 i32 i32 i32) (result i32) block ;; label = @1 - i32.const 1048624 + i32.const 1048632 local.get 2 local.get 3 call $::alloc @@ -108,7 +109,7 @@ ) (func $__rust_alloc_zeroed (;11;) (type 6) (param i32 i32) (result i32) block ;; label = @1 - i32.const 1048624 + i32.const 1048632 local.get 1 local.get 0 call $::alloc @@ -360,14 +361,18 @@ unreachable ) (func $cabi_post_miden:basic-wallet/aux@1.0.0#process-list-felt (;17;) (type 11) (param i32)) - (func $cabi_realloc_wit_bindgen_0_28_0 (;18;) (type 8) (param i32 i32 i32 i32) (result i32) + (func $miden:basic-wallet/aux@1.0.0#process-core-asset (;18;) (type 12) (param f32 f32 f32 f32) (result i32) + call $wit_bindgen_rt::run_ctors_once + unreachable + ) + (func $cabi_realloc_wit_bindgen_0_28_0 (;19;) (type 8) (param i32 i32 i32 i32) (result i32) local.get 0 local.get 1 local.get 2 local.get 3 call $wit_bindgen_rt::cabi_realloc ) - (func $wit_bindgen_rt::cabi_realloc (;19;) (type 8) (param i32 i32 i32 i32) (result i32) + (func $wit_bindgen_rt::cabi_realloc (;20;) (type 8) (param i32 i32 i32 i32) (result i32) block ;; label = @1 block ;; label = @2 block ;; label = @3 @@ -377,7 +382,7 @@ i32.eqz br_if 2 (;@1;) i32.const 0 - i32.load8_u offset=1048628 + i32.load8_u offset=1048636 drop local.get 3 local.get 2 @@ -398,18 +403,18 @@ end local.get 2 ) - (func $wit_bindgen_rt::run_ctors_once (;20;) (type 5) + (func $wit_bindgen_rt::run_ctors_once (;21;) (type 5) block ;; label = @1 i32.const 0 - i32.load8_u offset=1048629 + i32.load8_u offset=1048637 br_if 0 (;@1;) call $__wasm_call_ctors i32.const 0 i32.const 1 - i32.store8 offset=1048629 + i32.store8 offset=1048637 end ) - (func $::alloc (;21;) (type 12) (param i32 i32 i32) (result i32) + (func $::alloc (;22;) (type 13) (param i32 i32 i32) (result i32) (local i32 i32) block ;; label = @1 local.get 1 @@ -477,7 +482,7 @@ end unreachable ) - (func $miden_base_sys::bindings::account::add_asset (;22;) (type 13) (param i32 i32) + (func $miden_base_sys::bindings::account::add_asset (;23;) (type 14) (param i32 i32) local.get 1 f32.load local.get 1 @@ -489,7 +494,7 @@ local.get 0 call $miden_base_sys::bindings::account::extern_account_add_asset ) - (func $miden_base_sys::bindings::account::remove_asset (;23;) (type 13) (param i32 i32) + (func $miden_base_sys::bindings::account::remove_asset (;24;) (type 14) (param i32 i32) local.get 1 f32.load local.get 1 @@ -501,7 +506,7 @@ local.get 0 call $miden_base_sys::bindings::account::extern_account_remove_asset ) - (func $miden_base_sys::bindings::tx::create_note (;24;) (type 14) (param i32 f32 f32 i32) (result f32) + (func $miden_base_sys::bindings::tx::create_note (;25;) (type 15) (param i32 f32 f32 i32) (result f32) local.get 0 f32.load local.get 0 @@ -522,7 +527,7 @@ f32.load offset=12 call $miden_base_sys::bindings::tx::extern_tx_create_note ) - (func $alloc::vec::Vec::into_boxed_slice (;25;) (type 13) (param i32 i32) + (func $alloc::vec::Vec::into_boxed_slice (;26;) (type 14) (param i32 i32) (local i32 i32) global.get $__stack_pointer i32.const 16 @@ -568,8 +573,8 @@ end unreachable ) - (func $ as core::ops::drop::Drop>::drop (;26;) (type 11) (param i32)) - (func $ as core::ops::drop::Drop>::drop (;27;) (type 11) (param i32) + (func $ as core::ops::drop::Drop>::drop (;27;) (type 11) (param i32)) + (func $ as core::ops::drop::Drop>::drop (;28;) (type 11) (param i32) (local i32) block ;; label = @1 local.get 0 @@ -584,7 +589,7 @@ call $::deallocate end ) - (func $alloc::raw_vec::RawVec::try_allocate_in (;28;) (type 7) (param i32 i32 i32) + (func $alloc::raw_vec::RawVec::try_allocate_in (;29;) (type 7) (param i32 i32 i32) (local i32 i32) global.get $__stack_pointer i32.const 16 @@ -670,7 +675,7 @@ i32.add global.set $__stack_pointer ) - (func $::allocate (;29;) (type 7) (param i32 i32 i32) + (func $::allocate (;30;) (type 7) (param i32 i32 i32) (local i32) global.get $__stack_pointer i32.const 16 @@ -699,7 +704,7 @@ i32.add global.set $__stack_pointer ) - (func $alloc::alloc::Global::alloc_impl (;30;) (type 15) (param i32 i32 i32 i32) + (func $alloc::alloc::Global::alloc_impl (;31;) (type 16) (param i32 i32 i32 i32) block ;; label = @1 local.get 2 i32.eqz @@ -708,7 +713,7 @@ local.get 3 br_if 0 (;@2;) i32.const 0 - i32.load8_u offset=1048628 + i32.load8_u offset=1048636 drop local.get 2 local.get 1 @@ -728,7 +733,7 @@ local.get 1 i32.store ) - (func $alloc::raw_vec::RawVec::shrink_unchecked (;31;) (type 7) (param i32 i32 i32) + (func $alloc::raw_vec::RawVec::shrink_unchecked (;32;) (type 7) (param i32 i32 i32) (local i32 i32 i32 i32) i32.const -2147483647 local.set 3 @@ -780,7 +785,7 @@ local.get 3 i32.store ) - (func $::deallocate (;32;) (type 7) (param i32 i32 i32) + (func $::deallocate (;33;) (type 7) (param i32 i32 i32) block ;; label = @1 local.get 2 i32.eqz @@ -791,10 +796,10 @@ call $__rust_dealloc end ) - (func $alloc::raw_vec::handle_error (;33;) (type 13) (param i32 i32) + (func $alloc::raw_vec::handle_error (;34;) (type 14) (param i32 i32) unreachable ) - (func $cabi_realloc (;34;) (type 8) (param i32 i32 i32 i32) (result i32) + (func $cabi_realloc (;35;) (type 8) (param i32 i32 i32 i32) (result i32) local.get 0 local.get 1 local.get 2 @@ -811,6 +816,7 @@ (export "miden:basic-wallet/aux@1.0.0#test-stdlib" (func $miden:basic-wallet/aux@1.0.0#test-stdlib)) (export "miden:basic-wallet/aux@1.0.0#process-list-felt" (func $miden:basic-wallet/aux@1.0.0#process-list-felt)) (export "cabi_post_miden:basic-wallet/aux@1.0.0#process-list-felt" (func $cabi_post_miden:basic-wallet/aux@1.0.0#process-list-felt)) + (export "miden:basic-wallet/aux@1.0.0#process-core-asset" (func $miden:basic-wallet/aux@1.0.0#process-core-asset)) (export "cabi_post_miden:basic-wallet/aux@1.0.0#test-stdlib" (func $cabi_post_miden:basic-wallet/aux@1.0.0#process-list-felt)) (export "cabi_realloc_wit_bindgen_0_28_0" (func $cabi_realloc_wit_bindgen_0_28_0)) (export "cabi_realloc" (func $cabi_realloc)) @@ -933,6 +939,9 @@ (alias core export 5 "miden:basic-wallet/aux@1.0.0#process-list-felt" (core func (;12;))) (alias core export 5 "cabi_post_miden:basic-wallet/aux@1.0.0#process-list-felt" (core func (;13;))) (func (;10;) (type 23) (canon lift (core func 12) (memory 0) (realloc 6) (post-return 13))) + (type (;24;) (func (param "input" 6) (result 6))) + (alias core export 5 "miden:basic-wallet/aux@1.0.0#process-core-asset" (core func (;14;))) + (func (;11;) (type 24) (canon lift (core func 14) (memory 0))) (component (;1;) (type (;0;) (record (field "inner" float32))) (import "import-type-felt" (type (;1;) (eq 0))) @@ -956,24 +965,30 @@ (type (;17;) (list 13)) (type (;18;) (func (param "input" 17) (result 17))) (import "import-func-process-list-felt" (func (;2;) (type 18))) - (export (;19;) "core-asset" (type 6)) - (export (;20;) "tag" (type 8)) - (export (;21;) "recipient" (type 10)) - (export (;22;) "note-type" (type 12)) - (export (;23;) "felt" (type 1)) - (type (;24;) (func (param "a" 23) (param "b" 23) (result 23))) - (export (;3;) "test-felt-intrinsics" (func 0) (func (type 24))) - (type (;25;) (list u8)) - (type (;26;) (func (param "input" 25) (result 25))) - (export (;4;) "test-stdlib" (func 1) (func (type 26))) - (type (;27;) (list 23)) + (import "import-type-core-asset0" (type (;19;) (eq 6))) + (type (;20;) (func (param "input" 19) (result 19))) + (import "import-func-process-core-asset" (func (;3;) (type 20))) + (export (;21;) "core-asset" (type 6)) + (export (;22;) "tag" (type 8)) + (export (;23;) "recipient" (type 10)) + (export (;24;) "note-type" (type 12)) + (export (;25;) "felt" (type 1)) + (type (;26;) (func (param "a" 25) (param "b" 25) (result 25))) + (export (;4;) "test-felt-intrinsics" (func 0) (func (type 26))) + (type (;27;) (list u8)) (type (;28;) (func (param "input" 27) (result 27))) - (export (;5;) "process-list-felt" (func 2) (func (type 28))) + (export (;5;) "test-stdlib" (func 1) (func (type 28))) + (type (;29;) (list 25)) + (type (;30;) (func (param "input" 29) (result 29))) + (export (;6;) "process-list-felt" (func 2) (func (type 30))) + (type (;31;) (func (param "input" 21) (result 21))) + (export (;7;) "process-core-asset" (func 3) (func (type 31))) ) (instance (;8;) (instantiate 1 (with "import-func-test-felt-intrinsics" (func 8)) (with "import-func-test-stdlib" (func 9)) (with "import-func-process-list-felt" (func 10)) + (with "import-func-process-core-asset" (func 11)) (with "import-type-felt" (type 12)) (with "import-type-word" (type 13)) (with "import-type-core-asset" (type 14)) @@ -981,6 +996,7 @@ (with "import-type-recipient" (type 16)) (with "import-type-note-type" (type 17)) (with "import-type-felt0" (type 18)) + (with "import-type-core-asset0" (type 6)) ) ) (export (;9;) "miden:basic-wallet/aux@1.0.0" (instance 8)) diff --git a/tests/rust-apps-wasm/rust-sdk/basic-wallet/src/bindings.rs b/tests/rust-apps-wasm/rust-sdk/basic-wallet/src/bindings.rs index 54bc572b8..f51ea85fa 100644 --- a/tests/rust-apps-wasm/rust-sdk/basic-wallet/src/bindings.rs +++ b/tests/rust-apps-wasm/rust-sdk/basic-wallet/src/bindings.rs @@ -344,6 +344,39 @@ pub mod exports { let len2 = l1; _rt::cabi_dealloc(base2, len2 * 4, 4); } + #[doc(hidden)] + #[allow(non_snake_case)] + pub unsafe fn _export_process_core_asset_cabi( + arg0: f32, + arg1: f32, + arg2: f32, + arg3: f32, + ) -> *mut u8 { + #[cfg(target_arch = "wasm32")] _rt::run_ctors_once(); + let result0 = T::process_core_asset(miden::CoreAsset { + inner: miden::Word { + inner: ( + miden::Felt { inner: arg0 }, + miden::Felt { inner: arg1 }, + miden::Felt { inner: arg2 }, + miden::Felt { inner: arg3 }, + ), + }, + }); + let ptr1 = _RET_AREA.0.as_mut_ptr().cast::(); + let miden::CoreAsset { inner: inner2 } = result0; + let miden::Word { inner: inner3 } = inner2; + let (t4_0, t4_1, t4_2, t4_3) = inner3; + let miden::Felt { inner: inner5 } = t4_0; + *ptr1.add(0).cast::() = _rt::as_f32(inner5); + let miden::Felt { inner: inner6 } = t4_1; + *ptr1.add(4).cast::() = _rt::as_f32(inner6); + let miden::Felt { inner: inner7 } = t4_2; + *ptr1.add(8).cast::() = _rt::as_f32(inner7); + let miden::Felt { inner: inner8 } = t4_3; + *ptr1.add(12).cast::() = _rt::as_f32(inner8); + ptr1 + } pub trait Guest { fn test_felt_intrinsics( a: miden::Felt, @@ -353,6 +386,7 @@ pub mod exports { fn process_list_felt( input: _rt::Vec, ) -> _rt::Vec; + fn process_core_asset(input: miden::CoreAsset) -> miden::CoreAsset; } #[doc(hidden)] macro_rules! __export_miden_basic_wallet_aux_1_0_0_cabi { @@ -377,15 +411,20 @@ pub mod exports { "cabi_post_miden:basic-wallet/aux@1.0.0#process-list-felt"] unsafe extern "C" fn _post_return_process_list_felt(arg0 : * mut u8,) { $($path_to_types)*:: __post_return_process_list_felt::<$ty - > (arg0) } }; + > (arg0) } #[export_name = + "miden:basic-wallet/aux@1.0.0#process-core-asset"] unsafe extern + "C" fn export_process_core_asset(arg0 : f32, arg1 : f32, arg2 : + f32, arg3 : f32,) -> * mut u8 { $($path_to_types)*:: + _export_process_core_asset_cabi::<$ty > (arg0, arg1, arg2, arg3) + } }; }; } #[doc(hidden)] pub(crate) use __export_miden_basic_wallet_aux_1_0_0_cabi; #[repr(align(4))] - struct _RetArea([::core::mem::MaybeUninit; 8]); + struct _RetArea([::core::mem::MaybeUninit; 16]); static mut _RET_AREA: _RetArea = _RetArea( - [::core::mem::MaybeUninit::uninit(); 8], + [::core::mem::MaybeUninit::uninit(); 16], ); } } @@ -553,8 +592,8 @@ pub(crate) use __export_basic_wallet_world_impl as export; #[cfg(target_arch = "wasm32")] #[link_section = "component-type:wit-bindgen:0.31.0:miden:basic-wallet@1.0.0:basic-wallet-world:encoded world"] #[doc(hidden)] -pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 1828] = *b"\ -\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\x9b\x0d\x01A\x02\x01\ +pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 1863] = *b"\ +\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xbe\x0d\x01A\x02\x01\ A\x17\x01B\x1f\x01r\x01\x05innerv\x04\0\x04felt\x03\0\0\x01o\x04\x01\x01\x01\x01\ \x01r\x01\x05inner\x02\x04\0\x04word\x03\0\x03\x01r\x01\x05inner\x01\x04\0\x0aac\ count-id\x03\0\x05\x01r\x01\x05inner\x04\x04\0\x09recipient\x03\0\x07\x01r\x01\x05\ @@ -586,16 +625,16 @@ ore-import/tx@1.0.0\x05\x06\x02\x03\0\0\x0acore-asset\x02\x03\0\0\x03tag\x02\x03 type\x03\0\x06\x02\x03\x02\x01\x0b\x04\0\x04felt\x03\0\x08\x01@\x01\x0acore-asse\ t\x01\x01\0\x04\0\x0dreceive-asset\x01\x0a\x01@\x04\x0acore-asset\x01\x03tag\x03\ \x09note-type\x07\x09recipient\x05\x01\0\x04\0\x0asend-asset\x01\x0b\x04\x01%mid\ -en:basic-wallet/basic-wallet@1.0.0\x05\x0c\x01B\x12\x02\x03\x02\x01\x07\x04\0\x0a\ +en:basic-wallet/basic-wallet@1.0.0\x05\x0c\x01B\x14\x02\x03\x02\x01\x07\x04\0\x0a\ core-asset\x03\0\0\x02\x03\x02\x01\x08\x04\0\x03tag\x03\0\x02\x02\x03\x02\x01\x09\ \x04\0\x09recipient\x03\0\x04\x02\x03\x02\x01\x0a\x04\0\x09note-type\x03\0\x06\x02\ \x03\x02\x01\x0b\x04\0\x04felt\x03\0\x08\x01@\x02\x01a\x09\x01b\x09\0\x09\x04\0\x14\ test-felt-intrinsics\x01\x0a\x01p}\x01@\x01\x05input\x0b\0\x0b\x04\0\x0btest-std\ lib\x01\x0c\x01p\x09\x01@\x01\x05input\x0d\0\x0d\x04\0\x11process-list-felt\x01\x0e\ -\x04\x01\x1cmiden:basic-wallet/aux@1.0.0\x05\x0d\x04\x01+miden:basic-wallet/basi\ -c-wallet-world@1.0.0\x04\0\x0b\x18\x01\0\x12basic-wallet-world\x03\0\0\0G\x09pro\ -ducers\x01\x0cprocessed-by\x02\x0dwit-component\x070.216.0\x10wit-bindgen-rust\x06\ -0.31.0"; +\x01@\x01\x05input\x01\0\x01\x04\0\x12process-core-asset\x01\x0f\x04\x01\x1cmide\ +n:basic-wallet/aux@1.0.0\x05\x0d\x04\x01+miden:basic-wallet/basic-wallet-world@1\ +.0.0\x04\0\x0b\x18\x01\0\x12basic-wallet-world\x03\0\0\0G\x09producers\x01\x0cpr\ +ocessed-by\x02\x0dwit-component\x070.216.0\x10wit-bindgen-rust\x060.31.0"; #[inline(never)] #[doc(hidden)] pub fn __link_custom_section_describing_imports() { diff --git a/tests/rust-apps-wasm/rust-sdk/basic-wallet/src/lib.rs b/tests/rust-apps-wasm/rust-sdk/basic-wallet/src/lib.rs index ec82c7a87..8e9ba9b7e 100644 --- a/tests/rust-apps-wasm/rust-sdk/basic-wallet/src/lib.rs +++ b/tests/rust-apps-wasm/rust-sdk/basic-wallet/src/lib.rs @@ -52,4 +52,8 @@ impl aux::Guest for MyAccount { // input.into_iter().map(|felt| felt + felt!(1)).collect() todo!() } + + fn process_core_asset(input: CoreAsset) -> CoreAsset { + todo!() + } } diff --git a/tests/rust-apps-wasm/rust-sdk/basic-wallet/wit/basic-wallet.wit b/tests/rust-apps-wasm/rust-sdk/basic-wallet/wit/basic-wallet.wit index e69b8339b..0e88e800d 100644 --- a/tests/rust-apps-wasm/rust-sdk/basic-wallet/wit/basic-wallet.wit +++ b/tests/rust-apps-wasm/rust-sdk/basic-wallet/wit/basic-wallet.wit @@ -14,6 +14,7 @@ interface aux { test-felt-intrinsics: func(a: felt, b: felt) -> felt; test-stdlib: func(input: list) -> list; process-list-felt: func(input: list) -> list; + process-core-asset: func(input: core-asset) -> core-asset; } @@ -22,4 +23,4 @@ world basic-wallet-world { export basic-wallet; export aux; -} \ No newline at end of file +} diff --git a/tests/rust-apps-wasm/rust-sdk/p2id-note/src/bindings.rs b/tests/rust-apps-wasm/rust-sdk/p2id-note/src/bindings.rs index b27fe652f..d687c2cf8 100644 --- a/tests/rust-apps-wasm/rust-sdk/p2id-note/src/bindings.rs +++ b/tests/rust-apps-wasm/rust-sdk/p2id-note/src/bindings.rs @@ -197,6 +197,53 @@ pub mod miden { _rt::Vec::from_raw_parts(l2.cast(), len4, len4) } } + #[allow(unused_unsafe, clippy::all)] + pub fn process_core_asset(input: miden::CoreAsset) -> miden::CoreAsset { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 16]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 16]); + let miden::CoreAsset { inner: inner0 } = input; + let miden::Word { inner: inner1 } = inner0; + let (t2_0, t2_1, t2_2, t2_3) = inner1; + let miden::Felt { inner: inner3 } = t2_0; + let miden::Felt { inner: inner4 } = t2_1; + let miden::Felt { inner: inner5 } = t2_2; + let miden::Felt { inner: inner6 } = t2_3; + let ptr7 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "miden:basic-wallet/aux@1.0.0")] + extern "C" { + #[link_name = "process-core-asset"] + fn wit_import(_: f32, _: f32, _: f32, _: f32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: f32, _: f32, _: f32, _: f32, _: *mut u8) { + unreachable!() + } + wit_import( + _rt::as_f32(inner3), + _rt::as_f32(inner4), + _rt::as_f32(inner5), + _rt::as_f32(inner6), + ptr7, + ); + let l8 = *ptr7.add(0).cast::(); + let l9 = *ptr7.add(4).cast::(); + let l10 = *ptr7.add(8).cast::(); + let l11 = *ptr7.add(12).cast::(); + miden::CoreAsset { + inner: miden::Word { + inner: ( + miden::Felt { inner: l8 }, + miden::Felt { inner: l9 }, + miden::Felt { inner: l10 }, + miden::Felt { inner: l11 }, + ), + }, + } + } + } } } #[allow(dead_code)] @@ -538,8 +585,8 @@ pub(crate) use __export_p2id_world_impl as export; #[cfg(target_arch = "wasm32")] #[link_section = "component-type:wit-bindgen:0.31.0:miden:p2id@1.0.0:p2id-world:encoded world"] #[doc(hidden)] -pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 1861] = *b"\ -\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xc4\x0d\x01A\x02\x01\ +pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 1896] = *b"\ +\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xe7\x0d\x01A\x02\x01\ A\x19\x01B\x1f\x01r\x01\x05innerv\x04\0\x04felt\x03\0\0\x01o\x04\x01\x01\x01\x01\ \x01r\x01\x05inner\x02\x04\0\x04word\x03\0\x03\x01r\x01\x05inner\x01\x04\0\x0aac\ count-id\x03\0\x05\x01r\x01\x05inner\x04\x04\0\x09recipient\x03\0\x07\x01r\x01\x05\ @@ -557,31 +604,31 @@ g\x03\0\x02\x02\x03\x02\x01\x03\x04\0\x09recipient\x03\0\x04\x02\x03\x02\x01\x04 \x04\0\x09note-type\x03\0\x06\x02\x03\x02\x01\x05\x04\0\x04felt\x03\0\x08\x01@\x01\ \x0acore-asset\x01\x01\0\x04\0\x0dreceive-asset\x01\x0a\x01@\x04\x0acore-asset\x01\ \x03tag\x03\x09note-type\x07\x09recipient\x05\x01\0\x04\0\x0asend-asset\x01\x0b\x03\ -\x01%miden:basic-wallet/basic-wallet@1.0.0\x05\x06\x01B\x12\x02\x03\x02\x01\x01\x04\ +\x01%miden:basic-wallet/basic-wallet@1.0.0\x05\x06\x01B\x14\x02\x03\x02\x01\x01\x04\ \0\x0acore-asset\x03\0\0\x02\x03\x02\x01\x02\x04\0\x03tag\x03\0\x02\x02\x03\x02\x01\ \x03\x04\0\x09recipient\x03\0\x04\x02\x03\x02\x01\x04\x04\0\x09note-type\x03\0\x06\ \x02\x03\x02\x01\x05\x04\0\x04felt\x03\0\x08\x01@\x02\x01a\x09\x01b\x09\0\x09\x04\ \0\x14test-felt-intrinsics\x01\x0a\x01p}\x01@\x01\x05input\x0b\0\x0b\x04\0\x0bte\ st-stdlib\x01\x0c\x01p\x09\x01@\x01\x05input\x0d\0\x0d\x04\0\x11process-list-fel\ -t\x01\x0e\x03\x01\x1cmiden:basic-wallet/aux@1.0.0\x05\x07\x01B\x02\x01@\0\0z\x04\ -\0\x09heap-base\x01\0\x03\x01&miden:core-import/intrinsics-mem@1.0.0\x05\x08\x01\ -B\x08\x01@\x02\x01av\x01bv\0v\x04\0\x03add\x01\0\x01@\x02\x01av\x01bv\0\x7f\x04\0\ -\x02eq\x01\x01\x01@\x01\x01aw\0v\x04\0\x12from-u64-unchecked\x01\x02\x01@\x02\x01\ -av\x01bv\x01\0\x04\0\x09assert-eq\x01\x03\x03\x01'miden:core-import/intrinsics-f\ -elt@1.0.0\x05\x09\x01B\x02\x01@\x09\x02a0z\x02a1z\x02a2z\x02a3z\x02a4z\x02a5z\x02\ -a6z\x02a7z\x0aresult-ptrz\x01\0\x04\0\x0fhash-one-to-one\x01\0\x03\x013miden:cor\ -e-import/stdlib-crypto-hashes-blake3@1.0.0\x05\x0a\x01B\x05\x01@\x05\x06asset0v\x06\ -asset1v\x06asset2v\x06asset3v\x0aresult-ptrz\x01\0\x04\0\x09add-asset\x01\0\x04\0\ -\x0cremove-asset\x01\0\x01@\0\0v\x04\0\x06get-id\x01\x01\x03\x01\x1fmiden:core-i\ -mport/account@1.0.0\x05\x0b\x01B\x03\x01@\x01\x03ptrz\0z\x04\0\x0aget-inputs\x01\ -\0\x04\0\x0aget-assets\x01\0\x03\x01\x1cmiden:core-import/note@1.0.0\x05\x0c\x01\ -B\x02\x01@\x0a\x06asset0v\x06asset1v\x06asset2v\x06asset3v\x03tagv\x09note-typev\ -\x0arecipient0v\x0arecipient1v\x0arecipient2v\x0arecipient3v\0v\x04\0\x0bcreate-\ -note\x01\0\x03\x01\x1amiden:core-import/tx@1.0.0\x05\x0d\x01B\x02\x01@\0\x01\0\x04\ -\0\x0bnote-script\x01\0\x04\x01\x1cmiden:base/note-script@1.0.0\x05\x0e\x04\x01\x1b\ -miden:p2id/p2id-world@1.0.0\x04\0\x0b\x10\x01\0\x0ap2id-world\x03\0\0\0G\x09prod\ -ucers\x01\x0cprocessed-by\x02\x0dwit-component\x070.216.0\x10wit-bindgen-rust\x06\ -0.31.0"; +t\x01\x0e\x01@\x01\x05input\x01\0\x01\x04\0\x12process-core-asset\x01\x0f\x03\x01\ +\x1cmiden:basic-wallet/aux@1.0.0\x05\x07\x01B\x02\x01@\0\0z\x04\0\x09heap-base\x01\ +\0\x03\x01&miden:core-import/intrinsics-mem@1.0.0\x05\x08\x01B\x08\x01@\x02\x01a\ +v\x01bv\0v\x04\0\x03add\x01\0\x01@\x02\x01av\x01bv\0\x7f\x04\0\x02eq\x01\x01\x01\ +@\x01\x01aw\0v\x04\0\x12from-u64-unchecked\x01\x02\x01@\x02\x01av\x01bv\x01\0\x04\ +\0\x09assert-eq\x01\x03\x03\x01'miden:core-import/intrinsics-felt@1.0.0\x05\x09\x01\ +B\x02\x01@\x09\x02a0z\x02a1z\x02a2z\x02a3z\x02a4z\x02a5z\x02a6z\x02a7z\x0aresult\ +-ptrz\x01\0\x04\0\x0fhash-one-to-one\x01\0\x03\x013miden:core-import/stdlib-cryp\ +to-hashes-blake3@1.0.0\x05\x0a\x01B\x05\x01@\x05\x06asset0v\x06asset1v\x06asset2\ +v\x06asset3v\x0aresult-ptrz\x01\0\x04\0\x09add-asset\x01\0\x04\0\x0cremove-asset\ +\x01\0\x01@\0\0v\x04\0\x06get-id\x01\x01\x03\x01\x1fmiden:core-import/account@1.\ +0.0\x05\x0b\x01B\x03\x01@\x01\x03ptrz\0z\x04\0\x0aget-inputs\x01\0\x04\0\x0aget-\ +assets\x01\0\x03\x01\x1cmiden:core-import/note@1.0.0\x05\x0c\x01B\x02\x01@\x0a\x06\ +asset0v\x06asset1v\x06asset2v\x06asset3v\x03tagv\x09note-typev\x0arecipient0v\x0a\ +recipient1v\x0arecipient2v\x0arecipient3v\0v\x04\0\x0bcreate-note\x01\0\x03\x01\x1a\ +miden:core-import/tx@1.0.0\x05\x0d\x01B\x02\x01@\0\x01\0\x04\0\x0bnote-script\x01\ +\0\x04\x01\x1cmiden:base/note-script@1.0.0\x05\x0e\x04\x01\x1bmiden:p2id/p2id-wo\ +rld@1.0.0\x04\0\x0b\x10\x01\0\x0ap2id-world\x03\0\0\0G\x09producers\x01\x0cproce\ +ssed-by\x02\x0dwit-component\x070.216.0\x10wit-bindgen-rust\x060.31.0"; #[inline(never)] #[doc(hidden)] pub fn __link_custom_section_describing_imports() { From 682d00b74f07c88acc8ba335077beea34818b315 Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Thu, 21 Nov 2024 18:03:15 +0200 Subject: [PATCH 04/17] fix: fallback to `LibraryPath` unchecked ctor (Wasm CM styles names) --- codegen/masm/src/masm/module.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/codegen/masm/src/masm/module.rs b/codegen/masm/src/masm/module.rs index aada58942..437cda1a0 100644 --- a/codegen/masm/src/masm/module.rs +++ b/codegen/masm/src/masm/module.rs @@ -3,7 +3,7 @@ use std::{collections::BTreeSet, fmt, path::Path, sync::Arc}; use intrusive_collections::{intrusive_adapter, RBTree, RBTreeAtomicLink}; use miden_assembly::{ ast::{self, ModuleKind}, - LibraryPath, + LibraryNamespace, LibraryPath, }; use midenc_hir::{ diagnostics::{Report, SourceFile, SourceSpan, Span, Spanned}, @@ -166,9 +166,15 @@ impl Module { // Create module import table for ir_import in self.imports.iter() { let span = ir_import.span; - let name = - ast::Ident::new_with_span(span, ir_import.alias.as_str()).map_err(Report::msg)?; - let path = LibraryPath::new(ir_import.name.as_str()).expect("invalid import path"); + let name = ast::Ident::new_unchecked(Span::new(span, ir_import.alias.as_str().into())); + let module_name = ir_import.name.as_str(); + let path = LibraryPath::new(module_name).unwrap_or_else(|_| { + let module_id = ast::Ident::new_unchecked(Span::new( + span, + Arc::from(module_name.to_string().into_boxed_str()), + )); + LibraryPath::new_from_components(LibraryNamespace::Anon, [module_id]) + }); let import = ast::Import { span, name, From 5ca9e93007579ad73e7acc35d1f8c2da24e6494f Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Thu, 21 Nov 2024 18:05:15 +0200 Subject: [PATCH 05/17] chore: remove stale expected artifact --- .../rust_sdk_basic_wallet.masm | 802 ------------------ 1 file changed, 802 deletions(-) delete mode 100644 tests/integration/expected/rust_sdk_basic_wallet/rust_sdk_basic_wallet.masm diff --git a/tests/integration/expected/rust_sdk_basic_wallet/rust_sdk_basic_wallet.masm b/tests/integration/expected/rust_sdk_basic_wallet/rust_sdk_basic_wallet.masm deleted file mode 100644 index 69e62dea0..000000000 --- a/tests/integration/expected/rust_sdk_basic_wallet/rust_sdk_basic_wallet.masm +++ /dev/null @@ -1,802 +0,0 @@ -mod rust_sdk_basic_wallet - -use.miden:tx_kernel/account -use.miden:tx_kernel/tx - -export.receive_asset - mem_load.0x00000000 - push.32 - u32wrapping_sub - push.32 - dup.1 - swap.1 - u32wrapping_add - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_sw - dup.0 - swap.1 - swap.2 - swap.1 - exec."_ZN19miden_sdk_tx_kernel9add_asset17h6f4cff304c095ffcE" - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_sw -end - - -export.send_asset - mem_load.0x00000000 - push.32 - u32wrapping_sub - dup.0 - movup.2 - swap.4 - movdn.2 - swap.1 - swap.5 - swap.3 - swap.1 - exec."_ZN19miden_sdk_tx_kernel11create_note17h99477639e0ff4f18E" - push.32 - dup.3 - swap.1 - u32wrapping_add - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_sw - dup.2 - swap.1 - swap.2 - swap.1 - exec."_ZN19miden_sdk_tx_kernel12remove_asset17hf5f373d8386f7b96E" - movup.2 - swap.1 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_sw - dropw -end - - -export."_ZN19miden_sdk_tx_kernel9add_asset17h6f4cff304c095ffcE" - mem_load.0x00000000 - push.32 - u32wrapping_sub - dup.0 - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - dup.3 - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - add.24 - u32assert - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_felt - dup.4 - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - add.16 - u32assert - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_felt - dup.5 - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - add.8 - u32assert - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_felt - movup.6 - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_felt - exec.miden:tx_kernel/account::add_asset - push.32 - dup.6 - swap.1 - u32wrapping_add - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_sw - dup.5 - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_dw - dup.8 - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_dw - push.8 - dup.6 - swap.1 - u32wrapping_add - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_dw - push.8 - dup.9 - swap.1 - u32wrapping_add - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_dw - push.16 - dup.6 - swap.1 - u32wrapping_add - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_dw - push.16 - dup.9 - swap.1 - u32wrapping_add - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_dw - push.24 - dup.6 - swap.1 - u32wrapping_add - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_dw - push.24 - movup.9 - swap.1 - u32wrapping_add - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_dw - dup.4 - add.24 - u32assert - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_felt - dup.3 - add.16 - u32assert - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_felt - dup.2 - add.8 - u32assert - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_felt - swap.1 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_felt - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_sw -end - - -export."_ZN19miden_sdk_tx_kernel12remove_asset17hf5f373d8386f7b96E" - mem_load.0x00000000 - push.32 - u32wrapping_sub - dup.0 - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - dup.3 - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - add.24 - u32assert - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_felt - dup.4 - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - add.16 - u32assert - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_felt - dup.5 - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - add.8 - u32assert - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_felt - movup.6 - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_felt - exec.miden:tx_kernel/account::remove_asset - push.32 - dup.6 - swap.1 - u32wrapping_add - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_sw - dup.5 - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_dw - dup.8 - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_dw - push.8 - dup.6 - swap.1 - u32wrapping_add - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_dw - push.8 - dup.9 - swap.1 - u32wrapping_add - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_dw - push.16 - dup.6 - swap.1 - u32wrapping_add - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_dw - push.16 - dup.9 - swap.1 - u32wrapping_add - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_dw - push.24 - dup.6 - swap.1 - u32wrapping_add - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_dw - push.24 - movup.9 - swap.1 - u32wrapping_add - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_dw - dup.4 - add.24 - u32assert - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_felt - dup.3 - add.16 - u32assert - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_felt - dup.2 - add.8 - u32assert - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_felt - swap.1 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_felt - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::store_sw -end - - -export."_ZN19miden_sdk_tx_kernel11create_note17h99477639e0ff4f18E" - dup.3 - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - add.24 - u32assert - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_felt - dup.4 - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - add.16 - u32assert - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_felt - dup.5 - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - add.8 - u32assert - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_felt - movup.6 - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_felt - dup.4 - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - add.24 - u32assert - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_felt - dup.5 - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - add.16 - u32assert - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_felt - dup.6 - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - add.8 - u32assert - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_felt - movup.7 - dup.0 - push.2147483648 - u32and - eq.2147483648 - assertz - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.intrinsics::mem::load_felt - movup.5 - swap.7 - swap.9 - movdn.5 - movup.4 - swap.6 - swap.8 - movdn.4 - exec.miden:tx_kernel/tx::create_note -end - - From 19521489952e6f168c69449897c1f6c57469f606 Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Thu, 21 Nov 2024 18:05:55 +0200 Subject: [PATCH 06/17] fix: skip registering already registered modules in Assembler --- codegen/masm/src/masm/program.rs | 34 ++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/codegen/masm/src/masm/program.rs b/codegen/masm/src/masm/program.rs index c7c565e73..06f265501 100644 --- a/codegen/masm/src/masm/program.rs +++ b/codegen/masm/src/masm/program.rs @@ -251,18 +251,26 @@ impl Program { let mut assembler = Assembler::new(session.source_manager.clone()).with_debug_mode(debug_mode); + let mut lib_modules = Vec::new(); // Link extra libraries for library in self.library.libraries.iter() { - if log::log_enabled!(log::Level::Debug) { - for module in library.module_infos() { - log::debug!("registering '{}' with assembler", module.path()); - } + for module in library.module_infos() { + log::debug!("registering '{}' with assembler", module.path()); + lib_modules.push(module.path().to_string()); } assembler.add_library(library)?; } // Assemble library for module in self.library.modules.iter() { + if lib_modules.contains(&module.id.to_string()) { + log::warn!( + "module '{}' is already registered with the assembler as library's module, \ + skipping", + module.id + ); + continue; + } log::debug!("adding '{}' to assembler", module.id.as_str()); let kind = module.kind; let module = module.to_ast(debug_mode).map(Box::new)?; @@ -476,12 +484,12 @@ impl Library { let mut assembler = Assembler::new(session.source_manager.clone()).with_debug_mode(debug_mode); + let mut lib_modules = Vec::new(); // Link extra libraries for library in self.libraries.iter() { - if log::log_enabled!(log::Level::Debug) { - for module in library.module_infos() { - log::debug!("registering '{}' with assembler", module.path()); - } + for module in library.module_infos() { + log::debug!("registering '{}' with assembler", module.path()); + lib_modules.push(module.path().to_string()); } assembler.add_library(library)?; } @@ -489,10 +497,20 @@ impl Library { // Assemble library let mut modules = Vec::with_capacity(self.modules.len()); for module in self.modules.iter() { + let module_id = module.id.as_str(); + if lib_modules.contains(&module_id.to_string()) { + log::warn!( + "module '{}' is already registered with the assembler as library's module, \ + skipping", + module_id + ); + continue; + } log::debug!("adding '{}' to assembler", module.id.as_str()); let module = module.to_ast(debug_mode).map(Box::new)?; modules.push(module); } + // dbg!(&modules); let lib = assembler.assemble_library(modules)?; let advice_map: AdviceMap = self .rodatas() From b237327c4d7512ad8d154048896dbd50c8101e9b Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Thu, 21 Nov 2024 18:08:15 +0200 Subject: [PATCH 07/17] test: link stdlib when building p2id note script test --- tests/integration/src/rust_masm_tests/rust_sdk.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/integration/src/rust_masm_tests/rust_sdk.rs b/tests/integration/src/rust_masm_tests/rust_sdk.rs index 3733e4620..8c94e3be8 100644 --- a/tests/integration/src/rust_masm_tests/rust_sdk.rs +++ b/tests/integration/src/rust_masm_tests/rust_sdk.rs @@ -92,6 +92,8 @@ fn rust_sdk_p2id_note_script() { "../rust-apps-wasm/rust-sdk/p2id-note", config, [ + "-l".into(), + "std".into(), "--link-library".into(), masp_path.into_os_string().into_string().unwrap().into(), ], From 7f7ebe2706f5ffa6ee4ed89d6915e052fdc4dae1 Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Fri, 22 Nov 2024 17:55:38 +0200 Subject: [PATCH 08/17] fix: don't convert kebab case for unrecognized modules when recovering Wasm CM names for intrinsics, stdlib, tx kernel. --- frontend-wasm/src/miden_abi/mod.rs | 6 +++++- tests/integration/expected/rust_sdk/p2id.hir | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/frontend-wasm/src/miden_abi/mod.rs b/frontend-wasm/src/miden_abi/mod.rs index 4a1517762..5e34f6804 100644 --- a/frontend-wasm/src/miden_abi/mod.rs +++ b/frontend-wasm/src/miden_abi/mod.rs @@ -92,7 +92,11 @@ pub fn recover_imported_masm_function_id( {wasm_function_id}" ) } else { - wasm_module_id + // Unrecognized module ID, return as is + return FunctionIdent { + module: Ident::from(wasm_module_id), + function: Ident::from(wasm_function_id), + }; }; // Since `hash-1to1` is an invalid name in Wasm CM (dashed part cannot start with a digit), // we need to translate the CM name to the one that is expected at the linking stage diff --git a/tests/integration/expected/rust_sdk/p2id.hir b/tests/integration/expected/rust_sdk/p2id.hir index b4336cde3..c04e5ae6f 100644 --- a/tests/integration/expected/rust_sdk/p2id.hir +++ b/tests/integration/expected/rust_sdk/p2id.hir @@ -136,7 +136,7 @@ (store v22 v18) (let (v23 i32) (const.i32 16)) (let (v24 i32) (add.wrapping v4 v23)) - (call (#miden:basic-wallet/aux@1.0.0 #process_list_felt) v17 v12 v24) + (call (#miden:basic-wallet/aux@1.0.0 #process-list-felt) v17 v12 v24) (let (v25 u32) (bitcast v4)) (let (v26 u32) (add.checked v25 20)) (let (v27 u32) (mod.unchecked v26 4)) @@ -243,7 +243,7 @@ (assertz 250 v90) (let (v91 (ptr felt)) (inttoptr v89)) (let (v92 felt) (load v91)) - (call (#miden:basic-wallet/basic-wallet@1.0.0 #receive_asset) v77 v82 v87 v92) + (call (#miden:basic-wallet/basic-wallet@1.0.0 #receive-asset) v77 v82 v87 v92) (let (v93 i32) (const.i32 -32)) (let (v94 i32) (add.wrapping v69 v93)) (let (v95 i32) (const.i32 32)) @@ -670,9 +670,9 @@ (func (import #intrinsics::mem #heap_base) (result u32)) (func (import #miden::account #get_id) (result felt)) (func (import #miden::note #get_inputs) (param i32) (result i32 i32)) - (func (import #miden:basic-wallet/aux@1.0.0 #process_list_felt) + (func (import #miden:basic-wallet/aux@1.0.0 #process-list-felt) (param i32) (param i32) (param i32)) - (func (import #miden:basic-wallet/basic-wallet@1.0.0 #receive_asset) + (func (import #miden:basic-wallet/basic-wallet@1.0.0 #receive-asset) (param felt) (param felt) (param felt) (param felt)) ) From 32f5845f3a139f43b1fa67a759c57900222551ba Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Fri, 22 Nov 2024 17:58:46 +0200 Subject: [PATCH 09/17] chore: remove unused expect artifacts --- .../rust_sdk_basic_wallet.hir | 217 ------------------ .../rust_sdk_basic_wallet.wat | 100 -------- 2 files changed, 317 deletions(-) delete mode 100644 tests/integration/expected/rust_sdk_basic_wallet/rust_sdk_basic_wallet.hir delete mode 100644 tests/integration/expected/rust_sdk_basic_wallet/rust_sdk_basic_wallet.wat diff --git a/tests/integration/expected/rust_sdk_basic_wallet/rust_sdk_basic_wallet.hir b/tests/integration/expected/rust_sdk_basic_wallet/rust_sdk_basic_wallet.hir deleted file mode 100644 index cd5e29cac..000000000 --- a/tests/integration/expected/rust_sdk_basic_wallet/rust_sdk_basic_wallet.hir +++ /dev/null @@ -1,217 +0,0 @@ -(component - ;; Component Imports - (lower ((digest 0x0000000000000000000000000000000000000000000000000000000000000000) (type (func (abi canon) (param felt) (param felt) (param felt) (param felt) (result felt felt felt felt)))) (#miden::account #remove_asset) - - ;; Modules - (module #rust_sdk_basic_wallet - ;; Constants - (const (id 0) 0x00100000) - - ;; Global Variables - (global (export #__stack_pointer) (id 0) (type i32) (const 0)) - - ;; Functions - (func (export #receive_asset) (param i32) - (block 0 (param v0 i32) - (let (v1 i32) (const.i32 0)) - (let (v2 i32) (global.load i32 (global.symbol #__stack_pointer))) - (let (v3 i32) (const.i32 32)) - (let (v4 i32) (sub.wrapping v2 v3)) - (let (v5 i32) (const.i32 -32)) - (let (v6 i32) (band v4 v5)) - (let (v7 (ptr i32)) (global.symbol #__stack_pointer)) - (store v7 v6) - (call #miden_base_sys::bindings::tx::add_asset v6 v0) - (let (v8 (ptr i32)) (global.symbol #__stack_pointer)) - (store v8 v2) - (br (block 1))) - - (block 1 - (ret)) - ) - - (func (export #send_asset) - (param i32) (param felt) (param felt) (param i32) - (block 0 - (param v0 i32) - (param v1 felt) - (param v2 felt) - (param v3 i32) - (let (v4 i32) (const.i32 0)) - (let (v5 i32) (global.load i32 (global.symbol #__stack_pointer))) - (let (v6 i32) (const.i32 32)) - (let (v7 i32) (sub.wrapping v5 v6)) - (let (v8 i32) (const.i32 -32)) - (let (v9 i32) (band v7 v8)) - (let (v10 (ptr i32)) (global.symbol #__stack_pointer)) - (store v10 v9) - (call #miden_base_sys::bindings::tx::remove_asset v9 v0) - (let (v11 felt) (call #miden_base_sys::bindings::tx::create_note v9 v1 v2 v3)) - (let (v12 (ptr i32)) (global.symbol #__stack_pointer)) - (store v12 v5) - (br (block 1))) - - (block 1 - (ret)) - ) - - (func (export #miden_base_sys::bindings::tx::add_asset) - (param i32) (param i32) - (block 0 (param v0 i32) (param v1 i32) - (let (v2 u32) (bitcast v1)) - (let (v3 u32) (mod.unchecked v2 4)) - (assertz 250 v3) - (let (v4 (ptr felt)) (inttoptr v2)) - (let (v5 felt) (load v4)) - (let (v6 u32) (bitcast v1)) - (let (v7 u32) (add.checked v6 4)) - (let (v8 u32) (mod.unchecked v7 4)) - (assertz 250 v8) - (let (v9 (ptr felt)) (inttoptr v7)) - (let (v10 felt) (load v9)) - (let (v11 u32) (bitcast v1)) - (let (v12 u32) (add.checked v11 8)) - (let (v13 u32) (mod.unchecked v12 4)) - (assertz 250 v13) - (let (v14 (ptr felt)) (inttoptr v12)) - (let (v15 felt) (load v14)) - (let (v16 u32) (bitcast v1)) - (let (v17 u32) (add.checked v16 12)) - (let (v18 u32) (mod.unchecked v17 4)) - (assertz 250 v18) - (let (v19 (ptr felt)) (inttoptr v17)) - (let (v20 felt) (load v19)) - (let [(v21 felt) (v22 felt) (v23 felt) (v24 felt)] (call (#miden::account #add_asset) v5 v10 v15 v20)) - (let (v25 u32) (bitcast v0)) - (let (v26 (ptr felt)) (inttoptr v25)) - (store v26 v21) - (let (v27 u32) (add.checked v25 4)) - (let (v28 (ptr felt)) (inttoptr v27)) - (store v28 v22) - (let (v29 u32) (add.checked v25 8)) - (let (v30 (ptr felt)) (inttoptr v29)) - (store v30 v23) - (let (v31 u32) (add.checked v25 12)) - (let (v32 (ptr felt)) (inttoptr v31)) - (store v32 v24) - (br (block 1))) - - (block 1 - (ret)) - ) - - (func (export #miden_base_sys::bindings::tx::remove_asset) - (param i32) (param i32) - (block 0 (param v0 i32) (param v1 i32) - (let (v2 u32) (bitcast v1)) - (let (v3 u32) (mod.unchecked v2 4)) - (assertz 250 v3) - (let (v4 (ptr felt)) (inttoptr v2)) - (let (v5 felt) (load v4)) - (let (v6 u32) (bitcast v1)) - (let (v7 u32) (add.checked v6 4)) - (let (v8 u32) (mod.unchecked v7 4)) - (assertz 250 v8) - (let (v9 (ptr felt)) (inttoptr v7)) - (let (v10 felt) (load v9)) - (let (v11 u32) (bitcast v1)) - (let (v12 u32) (add.checked v11 8)) - (let (v13 u32) (mod.unchecked v12 4)) - (assertz 250 v13) - (let (v14 (ptr felt)) (inttoptr v12)) - (let (v15 felt) (load v14)) - (let (v16 u32) (bitcast v1)) - (let (v17 u32) (add.checked v16 12)) - (let (v18 u32) (mod.unchecked v17 4)) - (assertz 250 v18) - (let (v19 (ptr felt)) (inttoptr v17)) - (let (v20 felt) (load v19)) - (let [(v21 felt) (v22 felt) (v23 felt) (v24 felt)] (call (#miden::account #remove_asset) v5 v10 v15 v20)) - (let (v25 u32) (bitcast v0)) - (let (v26 (ptr felt)) (inttoptr v25)) - (store v26 v21) - (let (v27 u32) (add.checked v25 4)) - (let (v28 (ptr felt)) (inttoptr v27)) - (store v28 v22) - (let (v29 u32) (add.checked v25 8)) - (let (v30 (ptr felt)) (inttoptr v29)) - (store v30 v23) - (let (v31 u32) (add.checked v25 12)) - (let (v32 (ptr felt)) (inttoptr v31)) - (store v32 v24) - (br (block 1))) - - (block 1 - (ret)) - ) - - (func (export #miden_base_sys::bindings::tx::create_note) - (param i32) (param felt) (param felt) (param i32) (result felt) - (block 0 - (param v0 i32) - (param v1 felt) - (param v2 felt) - (param v3 i32) - (let (v5 u32) (bitcast v0)) - (let (v6 u32) (mod.unchecked v5 4)) - (assertz 250 v6) - (let (v7 (ptr felt)) (inttoptr v5)) - (let (v8 felt) (load v7)) - (let (v9 u32) (bitcast v0)) - (let (v10 u32) (add.checked v9 4)) - (let (v11 u32) (mod.unchecked v10 4)) - (assertz 250 v11) - (let (v12 (ptr felt)) (inttoptr v10)) - (let (v13 felt) (load v12)) - (let (v14 u32) (bitcast v0)) - (let (v15 u32) (add.checked v14 8)) - (let (v16 u32) (mod.unchecked v15 4)) - (assertz 250 v16) - (let (v17 (ptr felt)) (inttoptr v15)) - (let (v18 felt) (load v17)) - (let (v19 u32) (bitcast v0)) - (let (v20 u32) (add.checked v19 12)) - (let (v21 u32) (mod.unchecked v20 4)) - (assertz 250 v21) - (let (v22 (ptr felt)) (inttoptr v20)) - (let (v23 felt) (load v22)) - (let (v24 u32) (bitcast v3)) - (let (v25 u32) (mod.unchecked v24 4)) - (assertz 250 v25) - (let (v26 (ptr felt)) (inttoptr v24)) - (let (v27 felt) (load v26)) - (let (v28 u32) (bitcast v3)) - (let (v29 u32) (add.checked v28 4)) - (let (v30 u32) (mod.unchecked v29 4)) - (assertz 250 v30) - (let (v31 (ptr felt)) (inttoptr v29)) - (let (v32 felt) (load v31)) - (let (v33 u32) (bitcast v3)) - (let (v34 u32) (add.checked v33 8)) - (let (v35 u32) (mod.unchecked v34 4)) - (assertz 250 v35) - (let (v36 (ptr felt)) (inttoptr v34)) - (let (v37 felt) (load v36)) - (let (v38 u32) (bitcast v3)) - (let (v39 u32) (add.checked v38 12)) - (let (v40 u32) (mod.unchecked v39 4)) - (assertz 250 v40) - (let (v41 (ptr felt)) (inttoptr v39)) - (let (v42 felt) (load v41)) - (let (v43 felt) (call (#miden::tx #create_note) v8 v13 v18 v23 v1 v2 v27 v32 v37 v42)) - (br (block 1 v43))) - - (block 1 (param v4 felt) - (ret v4)) - ) - - ;; Imports - (func (import #miden::account #add_asset) - (param felt) (param felt) (param felt) (param felt) (result felt felt felt felt)) - (func (import #miden::account #remove_asset) - (param felt) (param felt) (param felt) (param felt) (result felt felt felt felt)) - (func (import #miden::tx #create_note) - (param felt) (param felt) (param felt) (param felt) (param felt) (param felt) (param felt) (param felt) (param felt) (param felt) (result felt)) - ) - -) diff --git a/tests/integration/expected/rust_sdk_basic_wallet/rust_sdk_basic_wallet.wat b/tests/integration/expected/rust_sdk_basic_wallet/rust_sdk_basic_wallet.wat deleted file mode 100644 index 77d9de8bc..000000000 --- a/tests/integration/expected/rust_sdk_basic_wallet/rust_sdk_basic_wallet.wat +++ /dev/null @@ -1,100 +0,0 @@ -(module $rust_sdk_basic_wallet.wasm - (type (;0;) (func (param f32 f32 f32 f32 i32))) - (type (;1;) (func (param f32 f32 f32 f32 f32 f32 f32 f32 f32 f32) (result f32))) - (type (;2;) (func (param i32))) - (type (;3;) (func (param i32 f32 f32 i32))) - (type (;4;) (func (param i32 i32))) - (type (;5;) (func (param i32 f32 f32 i32) (result f32))) - (import "miden::account" "add_asset<0x0000000000000000000000000000000000000000000000000000000000000000>" (func $miden_base_sys::bindings::tx::externs::extern_account_add_asset (;0;) (type 0))) - (import "miden::account" "remove_asset<0x0000000000000000000000000000000000000000000000000000000000000000>" (func $miden_base_sys::bindings::tx::externs::extern_account_remove_asset (;1;) (type 0))) - (import "miden::tx" "create_note<0x0000000000000000000000000000000000000000000000000000000000000000>" (func $miden_base_sys::bindings::tx::externs::extern_tx_create_note (;2;) (type 1))) - (func $receive_asset (;3;) (type 2) (param i32) - (local i32 i32) - global.get $__stack_pointer - local.tee 1 - i32.const 32 - i32.sub - i32.const -32 - i32.and - local.tee 2 - global.set $__stack_pointer - local.get 2 - local.get 0 - call $miden_base_sys::bindings::tx::add_asset - local.get 1 - global.set $__stack_pointer - ) - (func $send_asset (;4;) (type 3) (param i32 f32 f32 i32) - (local i32 i32) - global.get $__stack_pointer - local.tee 4 - i32.const 32 - i32.sub - i32.const -32 - i32.and - local.tee 5 - global.set $__stack_pointer - local.get 5 - local.get 0 - call $miden_base_sys::bindings::tx::remove_asset - local.get 5 - local.get 1 - local.get 2 - local.get 3 - call $miden_base_sys::bindings::tx::create_note - drop - local.get 4 - global.set $__stack_pointer - ) - (func $miden_base_sys::bindings::tx::add_asset (;5;) (type 4) (param i32 i32) - local.get 1 - f32.load - local.get 1 - f32.load offset=4 - local.get 1 - f32.load offset=8 - local.get 1 - f32.load offset=12 - local.get 0 - call $miden_base_sys::bindings::tx::externs::extern_account_add_asset - ) - (func $miden_base_sys::bindings::tx::remove_asset (;6;) (type 4) (param i32 i32) - local.get 1 - f32.load - local.get 1 - f32.load offset=4 - local.get 1 - f32.load offset=8 - local.get 1 - f32.load offset=12 - local.get 0 - call $miden_base_sys::bindings::tx::externs::extern_account_remove_asset - ) - (func $miden_base_sys::bindings::tx::create_note (;7;) (type 5) (param i32 f32 f32 i32) (result f32) - local.get 0 - f32.load - local.get 0 - f32.load offset=4 - local.get 0 - f32.load offset=8 - local.get 0 - f32.load offset=12 - local.get 1 - local.get 2 - local.get 3 - f32.load - local.get 3 - f32.load offset=4 - local.get 3 - f32.load offset=8 - local.get 3 - f32.load offset=12 - call $miden_base_sys::bindings::tx::externs::extern_tx_create_note - ) - (table (;0;) 1 1 funcref) - (memory (;0;) 16) - (global $__stack_pointer (;0;) (mut i32) i32.const 1048576) - (export "memory" (memory 0)) - (export "receive_asset" (func $receive_asset)) - (export "send_asset" (func $send_asset)) -) \ No newline at end of file From bdefce9a154ced3ef1372d3fdfb5782f0c55ea04 Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Fri, 22 Nov 2024 17:59:23 +0200 Subject: [PATCH 10/17] test: add missing functions in miden::account, miden:note tx kernel stubs --- sdk/base-sys/masm/miden/account.masm | 11 ++++++++--- sdk/base-sys/masm/miden/note.masm | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 sdk/base-sys/masm/miden/note.masm diff --git a/sdk/base-sys/masm/miden/account.masm b/sdk/base-sys/masm/miden/account.masm index 47229ce03..2655e49f8 100644 --- a/sdk/base-sys/masm/miden/account.masm +++ b/sdk/base-sys/masm/miden/account.masm @@ -1,11 +1,16 @@ # Stubs for miden::account tx kernel module export.remove_asset - push.1 + push.1 assertz end export.add_asset - push.1 + push.1 assertz -end \ No newline at end of file +end + +export.get_id + push.1 + assertz +end diff --git a/sdk/base-sys/masm/miden/note.masm b/sdk/base-sys/masm/miden/note.masm new file mode 100644 index 000000000..98afe4a9e --- /dev/null +++ b/sdk/base-sys/masm/miden/note.masm @@ -0,0 +1,6 @@ +# Stubs for miden::note tx kernel module + +export.get_inputs + push.1 + assertz +end From 5b3911a664ff4d8bac0d8a595d5486675c239601 Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Mon, 25 Nov 2024 16:40:14 +0200 Subject: [PATCH 11/17] fix: recover Wasm CM interfaces as module names in exports after assembling Library --- codegen/masm/src/masm/program.rs | 55 +++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/codegen/masm/src/masm/program.rs b/codegen/masm/src/masm/program.rs index 06f265501..0af20494d 100644 --- a/codegen/masm/src/masm/program.rs +++ b/codegen/masm/src/masm/program.rs @@ -1,9 +1,9 @@ -use std::{fmt, path::Path, sync::Arc}; +use std::{collections::BTreeMap, fmt, path::Path, sync::Arc}; use hir::{Signature, Symbol}; use miden_assembly::{ - ast::{ModuleKind, ProcedureName}, - KernelLibrary, Library as CompiledLibrary, LibraryNamespace, + ast::{self, ModuleKind, ProcedureName, QualifiedProcedureName}, + KernelLibrary, Library as CompiledLibrary, LibraryNamespace, LibraryPath, Span, }; use miden_core::{crypto::hash::Rpo256, AdviceMap}; use midenc_hir::{ @@ -510,17 +510,62 @@ impl Library { let module = module.to_ast(debug_mode).map(Box::new)?; modules.push(module); } - // dbg!(&modules); let lib = assembler.assemble_library(modules)?; let advice_map: AdviceMap = self .rodatas() .iter() .map(|rodata| (rodata.digest, rodata.to_elements())) .collect(); - Ok(Arc::new(lib.with_advice_map(advice_map))) + let mut mast_forest = lib.mast_forest().as_ref().clone(); + mast_forest.advice_map_mut().extend(advice_map); + let converted_exports = recover_wasm_cm_interfaces(&lib); + let lib = CompiledLibrary::new(Arc::new(mast_forest), converted_exports)?; + Ok(Arc::new(lib)) } } +/// Try to recognize Wasm CM interfaces and transform those exports to have Wasm interface +/// encoded as module name. +/// Temporary workaround for: +/// 1. Temporary exporting multiple interfaces from the same(Wasm core) module (an interface is encoded +/// in the function name); +/// 2. Assembler using the current module name to generate exports. +fn recover_wasm_cm_interfaces( + lib: &CompiledLibrary, +) -> BTreeMap { + let mut exports = BTreeMap::new(); + for export in lib.exports() { + let export_node_id = lib.get_export_node_id(export); + if export.module.to_string().starts_with("intrinsics") + || export.name.as_str().starts_with("cabi") + { + // Preserve intrinsics modules and internal Wasm CM `cabi_*` functions + exports.insert(export.clone(), export_node_id); + continue; + } + + if export.name.as_str().contains("/") { + // Wasm CM interface + let parts = export.name.as_str().split('#').collect::>(); + assert_eq!(parts.len(), 2); + let module = + ast::Ident::new_unchecked(Span::new(SourceSpan::default(), parts[0].into())); + let name = parts[1]; + let path = LibraryPath::new_from_components(LibraryNamespace::Anon, [module]); + let name = ast::ProcedureName::new_unchecked(ast::Ident::new_unchecked(Span::new( + SourceSpan::default(), + Arc::from(name), + ))); + let new_export = QualifiedProcedureName::new(path, name); + exports.insert(new_export, export_node_id); + } else { + // Non-Wasm CM interface, preserve as is + exports.insert(export.clone(), export_node_id); + } + } + exports +} + impl fmt::Display for Library { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { for module in self.modules.iter() { From 9d3816d9b5509db4b1b85eb4368a10e80d7ee195 Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Mon, 25 Nov 2024 16:41:03 +0200 Subject: [PATCH 12/17] fix: populate `Linker::allow_missing` with linked library exports --- hir/src/program/linker.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/hir/src/program/linker.rs b/hir/src/program/linker.rs index 5aba0cf82..ca3bc4dce 100644 --- a/hir/src/program/linker.rs +++ b/hir/src/program/linker.rs @@ -3,7 +3,7 @@ use std::{ collections::{BTreeMap, BTreeSet}, }; -use miden_assembly::Library as CompiledLibrary; +use miden_assembly::{Library as CompiledLibrary, LibraryNamespace}; use petgraph::{prelude::DiGraphMap, Direction}; use crate::{ @@ -21,6 +21,7 @@ enum Node { } /// Represents an object input to the [Linker] +#[derive(Debug)] pub enum Object { /// The object is an HIR module Hir(Box), @@ -226,10 +227,25 @@ impl<'a> Linker<'a> { pub fn add_library(&mut self, lib: CompiledLibrary) { // Add all of the exported objects to the callgraph for export in lib.exports() { - let module = Ident::with_empty_span(Symbol::intern(export.module.path())); - let name: &str = export.name.as_ref(); - let function = Ident::with_empty_span(Symbol::intern(name)); - self.callgraph.add_node(FunctionIdent { module, function }); + let module_str = export.module.path().to_string(); + let name_str: &str = export.name.as_ref(); + let function = Ident::with_empty_span(Symbol::intern(name_str)); + if let Some(striped) = + module_str.strip_prefix(format!("{}::", LibraryNamespace::ANON_PATH).as_str()) + { + // Strip the anonymous namespace and use the rest of the path as the module name + dbg!(striped); + self.callgraph.add_node(FunctionIdent { + module: Ident::with_empty_span(Symbol::intern(striped)), + function, + }); + self.allow_missing.insert(striped.to_string().into()); + } else { + // dbg!(export.to_string()); + let module = Ident::with_empty_span(Symbol::intern(module_str.clone())); + self.callgraph.add_node(FunctionIdent { module, function }); + self.allow_missing.insert(module_str.into()); + } } self.program.add_library(lib); } From 665bf88014771b14e40b0828456238d06df3841c Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Mon, 25 Nov 2024 16:42:10 +0200 Subject: [PATCH 13/17] test: link miden tx kernel in p2id note script test, check library exports in basic wallet test --- tests/integration/src/rust_masm_tests/rust_sdk.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/integration/src/rust_masm_tests/rust_sdk.rs b/tests/integration/src/rust_masm_tests/rust_sdk.rs index 8c94e3be8..8f35e6c4a 100644 --- a/tests/integration/src/rust_masm_tests/rust_sdk.rs +++ b/tests/integration/src/rust_masm_tests/rust_sdk.rs @@ -43,13 +43,14 @@ fn rust_sdk_basic_wallet() { test.expect_masm(expect_file![format!("../../expected/rust_sdk/{artifact_name}.masm")]); let package = test.compiled_package(); let lib = package.unwrap_library(); - let expected_module = "basic_wallet::miden:basic-wallet/basic-wallet@1.0.0"; + let expected_module = "#anon::miden:basic-wallet/basic-wallet@1.0.0"; let expected_function = "receive-asset"; let exports = lib .exports() - .map(|e| (e.module.to_string(), e.name.as_str())) + .filter(|e| !e.module.to_string().starts_with("intrinsics")) + .map(|e| format!("{}::{}", e.module, e.name.as_str())) .collect::>(); - // dbg!(&exports); + dbg!(&exports); assert!(lib.exports().any(|export| { export.module.to_string() == expected_module && export.name.as_str() == expected_function })); @@ -94,6 +95,8 @@ fn rust_sdk_p2id_note_script() { [ "-l".into(), "std".into(), + "-l".into(), + "base".into(), "--link-library".into(), masp_path.into_os_string().into_string().unwrap().into(), ], From 090e5add09551d191d4616e6ea86d706cf5b6810 Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Mon, 25 Nov 2024 16:43:06 +0200 Subject: [PATCH 14/17] test: update expected artifacts --- .../abi_transform_tx_kernel_get_inputs_4.hir | 12 +- .../abi_transform_tx_kernel_get_inputs_4.masm | 12 +- tests/integration/expected/rust_sdk/p2id.masm | 1362 ++++++++++++++--- .../miden_sdk_account_test.hir | 56 +- .../miden_sdk_account_test.wat | 6 +- 5 files changed, 1157 insertions(+), 291 deletions(-) diff --git a/tests/integration/expected/abi_transform_tx_kernel_get_inputs_4.hir b/tests/integration/expected/abi_transform_tx_kernel_get_inputs_4.hir index 5218e876d..a278d7694 100644 --- a/tests/integration/expected/abi_transform_tx_kernel_get_inputs_4.hir +++ b/tests/integration/expected/abi_transform_tx_kernel_get_inputs_4.hir @@ -17,7 +17,7 @@ (ret)) ) - (func (export #__rust_alloc) (param i32) (param i32) (result i32) + (func #__rust_alloc (param i32) (param i32) (result i32) (block 0 (param v0 i32) (param v1 i32) (let (v3 i32) (const.i32 1048576)) (let (v4 i32) (call #::alloc v3 v1 v0)) @@ -27,7 +27,7 @@ (ret v2)) ) - (func (export #__rust_alloc_zeroed) (param i32) (param i32) (result i32) + (func #__rust_alloc_zeroed (param i32) (param i32) (result i32) (block 0 (param v0 i32) (param v1 i32) (let (v3 i32) (const.i32 1048576)) (let (v4 i32) (call #::alloc v3 v1 v0)) @@ -52,7 +52,7 @@ (br (block 2 v4))) ) - (func (export #::alloc) + (func #::alloc (param i32) (param i32) (param i32) (result i32) (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (let (v4 i32) (const.i32 0)) @@ -151,7 +151,7 @@ (br (block 7 v66))) ) - (func (export #miden_base_sys::bindings::note::get_inputs) + (func #miden_base_sys::bindings::note::get_inputs (param i32) (block 0 (param v0 i32) (let (v1 i32) (const.i32 0)) @@ -233,7 +233,7 @@ (unreachable)) ) - (func (export #alloc::raw_vec::RawVec::try_allocate_in) + (func #alloc::raw_vec::RawVec::try_allocate_in (param i32) (param i32) (param i32) (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (let (v3 i32) (const.i32 0)) @@ -351,7 +351,7 @@ (br (block 2 v40 v50))) ) - (func (export #alloc::raw_vec::handle_error) + (func #alloc::raw_vec::handle_error (param i32) (param i32) (block 0 (param v0 i32) (param v1 i32) (unreachable)) diff --git a/tests/integration/expected/abi_transform_tx_kernel_get_inputs_4.masm b/tests/integration/expected/abi_transform_tx_kernel_get_inputs_4.masm index 594bc375c..1af61b6ca 100644 --- a/tests/integration/expected/abi_transform_tx_kernel_get_inputs_4.masm +++ b/tests/integration/expected/abi_transform_tx_kernel_get_inputs_4.masm @@ -3,7 +3,7 @@ use.intrinsics::mem use.miden::note -export."miden_base_sys::bindings::note::get_inputs" +proc."miden_base_sys::bindings::note::get_inputs" mem_load.0x00011000 push.16 u32wrapping_sub @@ -172,12 +172,12 @@ export."miden_base_sys::bindings::note::get_inputs" end -export."alloc::raw_vec::handle_error" +proc."alloc::raw_vec::handle_error" push.0 assert end -export."alloc::raw_vec::RawVec::try_allocate_in" +proc."alloc::raw_vec::RawVec::try_allocate_in" dup.1 neq.0 if.true @@ -494,7 +494,7 @@ export."alloc::raw_vec::RawVec::try_allocate_in" end -export."::alloc" +proc."::alloc" push.32 dup.2 push.32 @@ -705,7 +705,7 @@ export."::alloc" end -export."__rust_alloc" +proc."__rust_alloc" push.1048576 movup.2 swap.1 @@ -713,7 +713,7 @@ export."__rust_alloc" end -export."__rust_alloc_zeroed" +proc."__rust_alloc_zeroed" push.1048576 dup.1 swap.2 diff --git a/tests/integration/expected/rust_sdk/p2id.masm b/tests/integration/expected/rust_sdk/p2id.masm index bbb9009ec..f030a6598 100644 --- a/tests/integration/expected/rust_sdk/p2id.masm +++ b/tests/integration/expected/rust_sdk/p2id.masm @@ -1,18 +1,191 @@ # mod p2id use.intrinsics::mem +use.miden::account +use.miden::note +use.miden:basic-wallet/aux@1.0.0 +use.miden:basic-wallet/basic-wallet@1.0.0 -export.cabi_realloc - exec.cabi_realloc_wit_bindgen_0_28_0 +proc."miden_base_sys::bindings::note::get_assets" + push.0 assert end -export.cabi_realloc_wit_bindgen_0_28_0 - exec."wit_bindgen_rt::cabi_realloc" +proc."miden_base_sys::bindings::note::get_inputs" + mem_load.0x00011000 + push.16 + u32wrapping_sub + push.1114112 + dup.1 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + dup.0 + add.4 + u32assert + dup.1 + add.8 + u32assert + push.0 + push.256 + push.4 + dup.5 + swap.1 + u32wrapping_add + exec."alloc::raw_vec::RawVec::try_allocate_in" + dup.1 + u32mod.4 + assertz.err=250 + dup.0 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_sw + swap.1 + u32mod.4 + assertz.err=250 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_sw + push.1 + neq + neq.0 + if.true + dup.1 + add.12 + u32assert + dup.0 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_sw + dup.4 + add.8 + u32assert + dup.1 + push.4 + u32shr + exec.::miden::note::get_inputs + swap.1 + drop + dup.6 + add.4 + u32assert + dup.2 + movup.2 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + movup.6 + dup.1 + movup.4 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + dup.0 + movup.5 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + push.16 + movup.5 + swap.1 + u32wrapping_add + push.1114112 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 + else + movup.2 + drop + swap.1 + add.12 + u32assert + dup.0 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_sw + movup.2 + exec."alloc::raw_vec::handle_error" + u32mod.4 + assertz.err=250 + push.0 + assert + end +end + + +proc."miden_base_sys::bindings::account::get_id" + exec.::miden::account::get_id end -export."wit_bindgen_rt::cabi_realloc" +proc."wit_bindgen_rt::cabi_realloc" dup.1 neq.0 if.true @@ -47,14 +220,9 @@ export."wit_bindgen_rt::cabi_realloc" end -export."miden:base/note-script@1.0.0#note-script" - exec."wit_bindgen_rt::run_ctors_once" -end - - -export."wit_bindgen_rt::run_ctors_once" +proc."wit_bindgen_rt::run_ctors_once" push.0 - add.1048617 + add.1048625 u32assert dup.0 u32mod.16 @@ -76,7 +244,7 @@ export."wit_bindgen_rt::run_ctors_once" push.128 u32and push.0 - add.1048617 + add.1048625 u32assert dup.0 u32mod.16 @@ -100,125 +268,22 @@ export."wit_bindgen_rt::run_ctors_once" end -export."__rust_realloc" - push.1048612 - dup.4 - swap.2 - swap.4 - swap.1 - exec."::alloc" - dup.0 - eq.0 - neq.0 - if.true - movdn.3 drop drop drop - else - dup.1 - dup.4 - u32lt - push.0 - push.0 - push.4294967294 - movup.2 - cdrop - u32or - neq.0 - swap.1 - swap.4 - swap.2 - swap.1 - cdrop - dup.2 - movup.2 - push.0 - dup.3 - gte.0 - while.true - dup.2 - dup.1 - push.1 - u32overflowing_madd - assertz - dup.2 - dup.2 - push.1 - u32overflowing_madd - assertz - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::load_sw - push.128 - u32and - swap.1 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - dup.2 - dup.2 - dup.2 - exec.::intrinsics::mem::load_sw - push.4294967040 - u32and - movup.5 - u32or - movdn.4 - exec.::intrinsics::mem::store_sw - u32wrapping_add.1 - dup.0 - dup.4 - u32gte - end - dropw - end +proc."p2id::bindings::__link_custom_section_describing_imports" + end -export."__rust_alloc" - push.1048612 - movup.2 - swap.1 - exec."::alloc" +proc."alloc::raw_vec::handle_error" + push.0 assert end -export."::alloc" - push.32 - dup.2 - push.32 - u32gt - push.0 - push.0 - push.4294967294 - movup.2 - cdrop - u32or - neq.0 - movup.3 - swap.1 - cdrop - dup.0 - u32popcnt - push.1 - neq +proc."alloc::raw_vec::RawVec::try_allocate_in" + dup.1 neq.0 if.true - push.0 assert - else - push.2147483648 dup.1 - u32wrapping_sub - dup.3 + push.536870912 u32lt push.0 push.0 @@ -228,79 +293,96 @@ export."::alloc" u32or neq.0 if.true - push.0 assert - else - dup.1 - dup.0 - u32mod.4 - assertz.err=250 - dup.1 - swap.1 - swap.4 - u32wrapping_add - push.4294967295 - u32wrapping_add - push.0 + push.2 dup.2 - u32wrapping_sub - u32and - push.0 - movup.4 - dup.0 - u32mod.16 - dup.0 - u32mod.4 swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::load_sw + u32shl + movup.3 neq.0 if.true - dup.3 - dup.0 - u32mod.4 - assertz.err=250 - push.268435456 - swap.1 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::load_sw + push.4 + dup.1 + exec."__rust_alloc_zeroed" dup.0 - swap.1 - swap.2 - swap.1 - u32wrapping_sub - dup.3 - u32lt - push.0 - push.0 - push.4294967294 - movup.2 - cdrop - u32or + eq.0 neq.0 if.true - drop - movdn.3 - drop + movup.3 + swap.1 drop drop + dup.1 + add.8 + u32assert + dup.2 + add.4 + u32assert + dup.1 + movup.3 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + movup.2 + push.4 + dup.2 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + push.1 + dup.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 else swap.1 drop + dup.1 + add.8 + u32assert + dup.2 + add.4 + u32assert + dup.1 movup.3 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + movup.2 dup.1 + movup.4 swap.1 - swap.3 - u32wrapping_add - dup.2 dup.0 u32mod.16 dup.0 @@ -310,78 +392,108 @@ export."::alloc" movup.2 u32div.16 exec.::intrinsics::mem::store_sw + push.0 + dup.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 u32mod.4 assertz.err=250 - swap.1 - u32wrapping_add end else - dup.3 - exec.::intrinsics::mem::heap_base - dup.5 - exec.::intrinsics::mem::memory_size - push.16 - u32shl - movup.2 - swap.1 - u32wrapping_add - dup.2 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::store_sw - dup.0 - u32mod.4 - assertz.err=250 - swap.1 - u32mod.4 - assertz.err=250 - push.268435456 - swap.1 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::load_sw + push.4 + dup.1 + exec."__rust_alloc" dup.0 - swap.1 - swap.2 - swap.1 - u32wrapping_sub - dup.3 - u32lt - push.0 - push.0 - push.4294967294 - movup.2 - cdrop - u32or + eq.0 neq.0 if.true - drop - movdn.3 - drop + movup.3 + swap.1 drop drop + dup.1 + add.8 + u32assert + dup.2 + add.4 + u32assert + dup.1 + movup.3 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + movup.2 + push.4 + dup.2 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + push.1 + dup.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 else swap.1 drop + dup.1 + add.8 + u32assert + dup.2 + add.4 + u32assert + dup.1 movup.3 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + movup.2 dup.1 + movup.4 swap.1 - swap.3 - u32wrapping_add - dup.2 dup.0 u32mod.16 dup.0 @@ -391,25 +503,781 @@ export."::alloc" movup.2 u32div.16 exec.::intrinsics::mem::store_sw + push.0 + dup.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 u32mod.4 assertz.err=250 - swap.1 - u32wrapping_add end end - end - end -end - - -export."p2id::bindings::__link_custom_section_describing_imports" - + else + movdn.2 + drop + drop + dup.0 + add.4 + u32assert + swap.1 + push.0 + dup.2 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + push.1 + dup.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 + end + else + movdn.2 + drop + drop + dup.0 + add.4 + u32assert + swap.1 + push.4.0 + dup.3 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_dw + push.0 + dup.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 + end +end + + +proc."::alloc" + push.32 + dup.2 + push.32 + u32gt + push.0 + push.0 + push.4294967294 + movup.2 + cdrop + u32or + neq.0 + movup.3 + swap.1 + cdrop + dup.0 + u32popcnt + push.1 + neq + neq.0 + if.true + push.0 assert + else + push.2147483648 + dup.1 + u32wrapping_sub + dup.3 + u32lt + push.0 + push.0 + push.4294967294 + movup.2 + cdrop + u32or + neq.0 + if.true + push.0 assert + else + dup.1 + dup.0 + u32mod.4 + assertz.err=250 + dup.1 + swap.1 + swap.4 + u32wrapping_add + push.4294967295 + u32wrapping_add + push.0 + dup.2 + u32wrapping_sub + u32and + push.0 + movup.4 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_sw + neq.0 + if.true + dup.3 + dup.0 + u32mod.4 + assertz.err=250 + push.268435456 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_sw + dup.0 + swap.1 + swap.2 + swap.1 + u32wrapping_sub + dup.3 + u32lt + push.0 + push.0 + push.4294967294 + movup.2 + cdrop + u32or + neq.0 + if.true + drop + movdn.3 + drop + drop + drop + else + swap.1 + drop + movup.3 + dup.1 + swap.1 + swap.3 + u32wrapping_add + dup.2 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + swap.1 + u32mod.4 + assertz.err=250 + swap.1 + u32wrapping_add + end + else + dup.3 + exec.::intrinsics::mem::heap_base + dup.5 + exec.::intrinsics::mem::memory_size + push.16 + u32shl + movup.2 + swap.1 + u32wrapping_add + dup.2 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + dup.0 + u32mod.4 + assertz.err=250 + swap.1 + u32mod.4 + assertz.err=250 + push.268435456 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_sw + dup.0 + swap.1 + swap.2 + swap.1 + u32wrapping_sub + dup.3 + u32lt + push.0 + push.0 + push.4294967294 + movup.2 + cdrop + u32or + neq.0 + if.true + drop + movdn.3 + drop + drop + drop + else + swap.1 + drop + movup.3 + dup.1 + swap.1 + swap.3 + u32wrapping_add + dup.2 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + swap.1 + u32mod.4 + assertz.err=250 + swap.1 + u32wrapping_add + end + end + end + end +end + + +proc."__rust_alloc" + push.1048620 + movup.2 + swap.1 + exec."::alloc" +end + + +proc."__rust_alloc_zeroed" + push.1048620 + dup.1 + swap.2 + swap.3 + swap.1 + exec."::alloc" + dup.0 + eq.0 + neq.0 + if.true + swap.1 drop + else + push.0 + push.128 + u32and + movup.2 + dup.2 + push.0 + dup.2 + gte.0 + while.true + dup.1 + dup.1 + push.1 + u32overflowing_madd + assertz + dup.4 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + dup.2 + dup.2 + dup.2 + exec.::intrinsics::mem::load_sw + push.4294967040 + u32and + movup.5 + u32or + movdn.4 + exec.::intrinsics::mem::store_sw + u32wrapping_add.1 + dup.0 + dup.3 + u32gte + end + dropw + end +end + + +proc."__rust_realloc" + push.1048620 + dup.4 + swap.2 + swap.4 + swap.1 + exec."::alloc" + dup.0 + eq.0 + neq.0 + if.true + movdn.3 drop drop drop + else + dup.1 + dup.4 + u32lt + push.0 + push.0 + push.4294967294 + movup.2 + cdrop + u32or + neq.0 + swap.1 + swap.4 + swap.2 + swap.1 + cdrop + dup.2 + movup.2 + push.0 + dup.3 + gte.0 + while.true + dup.2 + dup.1 + push.1 + u32overflowing_madd + assertz + dup.2 + dup.2 + push.1 + u32overflowing_madd + assertz + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_sw + push.128 + u32and + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + dup.2 + dup.2 + dup.2 + exec.::intrinsics::mem::load_sw + push.4294967040 + u32and + movup.5 + u32or + movdn.4 + exec.::intrinsics::mem::store_sw + u32wrapping_add.1 + dup.0 + dup.4 + u32gte + end + dropw + end +end + + +proc."__wasm_call_ctors" + +end + + +export.cabi_realloc + exec.cabi_realloc_wit_bindgen_0_28_0 end -export."__wasm_call_ctors" +export.cabi_realloc_wit_bindgen_0_28_0 + exec."wit_bindgen_rt::cabi_realloc" +end + +export."miden:base/note-script@1.0.0#note-script" + mem_load.0x00011000 + push.32 + u32wrapping_sub + push.1114112 + dup.1 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + exec."wit_bindgen_rt::run_ctors_once" + dup.0 + add.16 + u32assert + push.4 + dup.2 + swap.1 + u32wrapping_add + exec."miden_base_sys::bindings::note::get_inputs" + dup.1 + add.8 + u32assert + dup.2 + add.12 + u32assert + push.0.0 + dup.4 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_dw + dup.3 + add.20 + u32assert + push.16 + dup.5 + swap.1 + u32wrapping_add + dup.2 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_sw + dup.4 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_sw + dup.0 + dup.2 + movup.2 + swap.4 + movdn.2 + swap.1 + exec.::miden:basic-wallet/aux@1.0.0::"process-list-felt" + dup.2 + u32mod.4 + assertz.err=250 + movup.5 + u32mod.8 + assertz.err=250 + movup.4 + u32mod.4 + assertz.err=250 + movup.3 + u32mod.4 + assertz.err=250 + movup.2 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_sw + eq.0 + neq.0 + if.true + push.0 assert + else + eq.0 + neq.0 + if.true + push.0 assert + else + dup.1 + add.16 + u32assert + exec."miden_base_sys::bindings::account::get_id" + dup.3 + add.20 + u32assert + dup.4 + add.24 + u32assert + dup.4 + movup.5 + dup.5 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_sw + push.16 + dup.8 + swap.1 + u32wrapping_add + exec."miden_base_sys::bindings::note::get_assets" + dup.4 + u32mod.4 + assertz.err=250 + dup.3 + u32mod.4 + assertz.err=250 + dup.2 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_felt + movup.6 + swap.1 + assert_eq + movup.2 + u32mod.4 + assertz.err=250 + dup.0 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_felt + dup.2 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_felt + assert_eq + swap.1 + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 + movup.2 + u32mod.4 + assertz.err=250 + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_sw + swap.1 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_sw + push.5 + u32shl + dup.0 + eq.0 + neq.0 + push.1 + while.true + if.true + drop + drop + push.32 + u32wrapping_add + push.1114112 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + push.0 + else + dup.1 + add.12 + u32assert + dup.2 + add.8 + u32assert + dup.3 + add.4 + u32assert + dup.4 + dup.3 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_felt + dup.3 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_felt + dup.3 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_felt + dup.3 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_felt + exec.::miden:basic-wallet/basic-wallet@1.0.0::"receive-asset" + movup.3 + u32mod.4 + assertz.err=250 + movup.2 + u32mod.4 + assertz.err=250 + swap.1 + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 + push.32 + movup.2 + swap.1 + u32wrapping_add + push.4294967264 + movup.2 + swap.1 + u32wrapping_add + dup.0 + eq.0 + neq.0 + push.1 + end + end + end + end end diff --git a/tests/integration/expected/rust_sdk_account_test/miden_sdk_account_test.hir b/tests/integration/expected/rust_sdk_account_test/miden_sdk_account_test.hir index 7b37eaf25..1b9c635e4 100644 --- a/tests/integration/expected/rust_sdk_account_test/miden_sdk_account_test.hir +++ b/tests/integration/expected/rust_sdk_account_test/miden_sdk_account_test.hir @@ -14,7 +14,7 @@ (global (export #__stack_pointer) (id 0) (type i32) (const 0)) ;; Functions - (func (export #core::alloc::global::GlobalAlloc::alloc_zeroed) + (func #core::alloc::global::GlobalAlloc::alloc_zeroed (param i32) (param i32) (param i32) (result i32) (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (let (v4 i32) (call #::alloc v0 v1 v2)) @@ -39,7 +39,7 @@ (br (block 2 v4))) ) - (func (export #get_wallet_magic_number) (result felt) + (func #get_wallet_magic_number (result felt) (block 0 (let (v1 felt) (const.felt 0)) (let (v2 felt) (call #miden_base_sys::bindings::account::get_id)) @@ -52,7 +52,7 @@ (ret v0)) ) - (func (export #test_add_asset) (result felt) + (func #test_add_asset (result felt) (block 0 (let (v1 i32) (const.i32 0)) (let (v2 felt) (const.felt 0)) @@ -111,8 +111,7 @@ (ret v0)) ) - (func (export #test_felt_ops_smoke) - (param felt) (param felt) (result felt) + (func #test_felt_ops_smoke (param felt) (param felt) (result felt) (block 0 (param v0 felt) (param v1 felt) (let (v3 i64) (const.i64 0)) (let (v4 i64) (cast v0)) @@ -204,7 +203,7 @@ (ret v0)) ) - (func (export #note_script) (result felt) + (func #note_script (result felt) (block 0 (let (v1 i32) (const.i32 0)) (let (v2 felt) (const.felt 0)) @@ -269,7 +268,7 @@ (ret v32)) ) - (func (export #test_blake3_hash_1to1) (param i32) (param i32) + (func #test_blake3_hash_1to1 (param i32) (param i32) (block 0 (param v0 i32) (param v1 i32) (let (v2 i32) (const.i32 0)) (let (v3 i32) (global.load i32 (global.symbol #__stack_pointer))) @@ -384,7 +383,7 @@ (ret)) ) - (func (export #test_blake3_hash_2to1) (param i32) (param i32) + (func #test_blake3_hash_2to1 (param i32) (param i32) (block 0 (param v0 i32) (param v1 i32) (let (v2 u32) (bitcast v1)) (let (v3 (ptr i32)) (inttoptr v2)) @@ -480,7 +479,7 @@ (ret)) ) - (func (export #test_rpo_falcon512_verify) (param i32) (param i32) + (func #test_rpo_falcon512_verify (param i32) (param i32) (block 0 (param v0 i32) (param v1 i32) (let (v2 u32) (bitcast v0)) (let (v3 u32) (mod.unchecked v2 4)) @@ -535,7 +534,7 @@ (ret)) ) - (func (export #test_pipe_words_to_memory) (param i32) (param felt) + (func #test_pipe_words_to_memory (param i32) (param felt) (block 0 (param v0 i32) (param v1 felt) (call #miden_stdlib_sys::stdlib::mem::pipe_words_to_memory v0 v1) (br (block 1))) @@ -544,8 +543,7 @@ (ret)) ) - (func (export #test_pipe_double_words_to_memory) - (param i32) (param felt) + (func #test_pipe_double_words_to_memory (param i32) (param felt) (block 0 (param v0 i32) (param v1 felt) (call #miden_stdlib_sys::stdlib::mem::pipe_double_words_to_memory v0 v1) (br (block 1))) @@ -554,7 +552,7 @@ (ret)) ) - (func (export #test_remove_asset) (param i32) (result felt) + (func #test_remove_asset (param i32) (result felt) (block 0 (param v0 i32) (let (v2 i32) (const.i32 0)) (let (v3 felt) (const.felt 0)) @@ -579,7 +577,7 @@ (ret v1)) ) - (func (export #test_create_note) + (func #test_create_note (param i32) (param felt) (param felt) (param i32) (result felt) (block 0 (param v0 i32) @@ -593,7 +591,7 @@ (ret v4)) ) - (func (export #__rust_alloc) (param i32) (param i32) (result i32) + (func #__rust_alloc (param i32) (param i32) (result i32) (block 0 (param v0 i32) (param v1 i32) (let (v3 i32) (const.i32 1048576)) (let (v4 i32) (call #::alloc v3 v1 v0)) @@ -603,7 +601,7 @@ (ret v2)) ) - (func (export #__rust_alloc_zeroed) (param i32) (param i32) (result i32) + (func #__rust_alloc_zeroed (param i32) (param i32) (result i32) (block 0 (param v0 i32) (param v1 i32) (let (v3 i32) (const.i32 1048576)) (let (v4 i32) (call #core::alloc::global::GlobalAlloc::alloc_zeroed v3 v1 v0)) @@ -613,7 +611,7 @@ (ret v2)) ) - (func (export #::alloc) + (func #::alloc (param i32) (param i32) (param i32) (result i32) (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (let (v4 i32) (const.i32 0)) @@ -712,7 +710,7 @@ (br (block 7 v66))) ) - (func (export #miden_base_sys::bindings::account::get_id) + (func #miden_base_sys::bindings::account::get_id (result felt) (block 0 (let (v1 felt) (call (#miden::account #get_id))) @@ -722,7 +720,7 @@ (ret v0)) ) - (func (export #miden_base_sys::bindings::account::add_asset) + (func #miden_base_sys::bindings::account::add_asset (param i32) (param i32) (block 0 (param v0 i32) (param v1 i32) (let (v2 u32) (bitcast v1)) @@ -767,7 +765,7 @@ (ret)) ) - (func (export #miden_base_sys::bindings::account::remove_asset) + (func #miden_base_sys::bindings::account::remove_asset (param i32) (param i32) (block 0 (param v0 i32) (param v1 i32) (let (v2 u32) (bitcast v1)) @@ -812,7 +810,7 @@ (ret)) ) - (func (export #miden_base_sys::bindings::note::get_inputs) + (func #miden_base_sys::bindings::note::get_inputs (param i32) (block 0 (param v0 i32) (let (v1 i32) (const.i32 0)) @@ -894,7 +892,7 @@ (unreachable)) ) - (func (export #miden_base_sys::bindings::tx::create_note) + (func #miden_base_sys::bindings::tx::create_note (param i32) (param felt) (param felt) (param i32) (result felt) (block 0 (param v0 i32) @@ -954,7 +952,7 @@ (ret v4)) ) - (func (export #alloc::vec::Vec::with_capacity) + (func #alloc::vec::Vec::with_capacity (param i32) (param i32) (block 0 (param v0 i32) (param v1 i32) (let (v2 i32) (const.i32 0)) @@ -1030,7 +1028,7 @@ (unreachable)) ) - (func (export #alloc::raw_vec::RawVec::try_allocate_in) + (func #alloc::raw_vec::RawVec::try_allocate_in (param i32) (param i32) (param i32) (block 0 (param v0 i32) (param v1 i32) (param v2 i32) (let (v3 i32) (const.i32 0)) @@ -1148,7 +1146,7 @@ (br (block 2 v40 v50))) ) - (func (export #miden_stdlib_sys::stdlib::mem::pipe_words_to_memory) + (func #miden_stdlib_sys::stdlib::mem::pipe_words_to_memory (param i32) (param felt) (block 0 (param v0 i32) (param v1 felt) (let (v2 i32) (const.i32 0)) @@ -1277,7 +1275,7 @@ (ret)) ) - (func (export #miden_stdlib_sys::stdlib::mem::pipe_double_words_to_memory) + (func #miden_stdlib_sys::stdlib::mem::pipe_double_words_to_memory (param i32) (param felt) (block 0 (param v0 i32) (param v1 felt) (let (v2 i32) (const.i32 0)) @@ -1441,7 +1439,7 @@ (ret)) ) - (func (export #dummy) + (func #dummy (block 0 (br (block 1))) @@ -1449,7 +1447,7 @@ (ret)) ) - (func (export #__wasm_call_dtors) + (func #__wasm_call_dtors (block 0 (call #dummy) (call #dummy) @@ -1459,7 +1457,7 @@ (ret)) ) - (func (export #alloc::raw_vec::handle_error) + (func #alloc::raw_vec::handle_error (param i32) (param i32) (block 0 (param v0 i32) (param v1 i32) (unreachable)) diff --git a/tests/integration/expected/rust_sdk_account_test/miden_sdk_account_test.wat b/tests/integration/expected/rust_sdk_account_test/miden_sdk_account_test.wat index 6aca8e422..af033ceaa 100644 --- a/tests/integration/expected/rust_sdk_account_test/miden_sdk_account_test.wat +++ b/tests/integration/expected/rust_sdk_account_test/miden_sdk_account_test.wat @@ -26,7 +26,7 @@ (type (;24;) (func (param i32))) (type (;25;) (func (param i32 i32 i32))) (type (;26;) (func)) - (import "miden:core-import/intrinsics-felt@1.0.0" "from_u64_unchecked" (func $miden_stdlib_sys::intrinsics::felt::extern_from_u64_unchecked (;0;) (type 0))) + (import "miden:core-import/intrinsics-felt@1.0.0" "from-u64-unchecked" (func $miden_stdlib_sys::intrinsics::felt::extern_from_u64_unchecked (;0;) (type 0))) (import "miden:core-import/intrinsics-felt@1.0.0" "add" (func $miden_stdlib_sys::intrinsics::felt::extern_add (;1;) (type 1))) (import "miden:core-import/intrinsics-felt@1.0.0" "as_u64" (func $miden_stdlib_sys::intrinsics::felt::extern_as_u64 (;2;) (type 2))) (import "miden:core-import/intrinsics-felt@1.0.0" "gt" (func $miden_stdlib_sys::intrinsics::felt::extern_gt (;3;) (type 3))) @@ -34,7 +34,7 @@ (import "miden:core-import/intrinsics-felt@1.0.0" "le" (func $miden_stdlib_sys::intrinsics::felt::extern_le (;5;) (type 3))) (import "miden:core-import/intrinsics-felt@1.0.0" "ge" (func $miden_stdlib_sys::intrinsics::felt::extern_ge (;6;) (type 3))) (import "miden:core-import/intrinsics-felt@1.0.0" "eq" (func $miden_stdlib_sys::intrinsics::felt::extern_eq (;7;) (type 3))) - (import "miden:core-import/intrinsics-felt@1.0.0" "is_odd" (func $miden_stdlib_sys::intrinsics::felt::extern_is_odd (;8;) (type 4))) + (import "miden:core-import/intrinsics-felt@1.0.0" "is-odd" (func $miden_stdlib_sys::intrinsics::felt::extern_is_odd (;8;) (type 4))) (import "miden:core-import/intrinsics-felt@1.0.0" "assertz" (func $miden_stdlib_sys::intrinsics::felt::extern_assertz (;9;) (type 5))) (import "miden:core-import/intrinsics-felt@1.0.0" "assert" (func $miden_stdlib_sys::intrinsics::felt::extern_assert (;10;) (type 5))) (import "miden:core-import/intrinsics-felt@1.0.0" "inv" (func $miden_stdlib_sys::intrinsics::felt::extern_inv (;11;) (type 6))) @@ -43,7 +43,7 @@ (import "miden:core-import/intrinsics-felt@1.0.0" "pow2" (func $miden_stdlib_sys::intrinsics::felt::extern_pow2 (;14;) (type 6))) (import "miden:core-import/intrinsics-felt@1.0.0" "mul" (func $miden_stdlib_sys::intrinsics::felt::extern_mul (;15;) (type 1))) (import "miden:core-import/intrinsics-felt@1.0.0" "div" (func $miden_stdlib_sys::intrinsics::felt::extern_div (;16;) (type 1))) - (import "miden:core-import/intrinsics-felt@1.0.0" "assert_eq" (func $miden_stdlib_sys::intrinsics::felt::extern_assert_eq (;17;) (type 7))) + (import "miden:core-import/intrinsics-felt@1.0.0" "assert-eq" (func $miden_stdlib_sys::intrinsics::felt::extern_assert_eq (;17;) (type 7))) (import "miden:core-import/intrinsics-felt@1.0.0" "neg" (func $miden_stdlib_sys::intrinsics::felt::extern_neg (;18;) (type 6))) (import "miden:core-import/stdlib-crypto-hashes-blake3@1.0.0" "hash-one-to-one" (func $miden_stdlib_sys::stdlib::crypto::hashes::extern_blake3_hash_1to1 (;19;) (type 8))) (import "miden:core-import/stdlib-crypto-hashes-blake3@1.0.0" "hash-two-to-one" (func $miden_stdlib_sys::stdlib::crypto::hashes::extern_blake3_hash_2to1 (;20;) (type 9))) From 6179d5558d1eb4f7cdcb7c946444e27b9d3a92ba Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Mon, 25 Nov 2024 16:43:20 +0200 Subject: [PATCH 15/17] chore: update VM --- Cargo.lock | 12 ++++++------ Cargo.toml | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 51e53471d..78d9a18a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2974,7 +2974,7 @@ dependencies = [ [[package]] name = "miden-air" version = "0.11.0" -source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=fe4afa2ad655772cd1ef1c30d014c383731ab293#fe4afa2ad655772cd1ef1c30d014c383731ab293" +source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=75bd636a6b83fd6cb134b0981663aa28e49a811c#75bd636a6b83fd6cb134b0981663aa28e49a811c" dependencies = [ "miden-core", "miden-thiserror", @@ -2985,7 +2985,7 @@ dependencies = [ [[package]] name = "miden-assembly" version = "0.11.0" -source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=fe4afa2ad655772cd1ef1c30d014c383731ab293#fe4afa2ad655772cd1ef1c30d014c383731ab293" +source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=75bd636a6b83fd6cb134b0981663aa28e49a811c#75bd636a6b83fd6cb134b0981663aa28e49a811c" dependencies = [ "aho-corasick", "lalrpop", @@ -3011,7 +3011,7 @@ dependencies = [ [[package]] name = "miden-core" version = "0.11.0" -source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=fe4afa2ad655772cd1ef1c30d014c383731ab293#fe4afa2ad655772cd1ef1c30d014c383731ab293" +source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=75bd636a6b83fd6cb134b0981663aa28e49a811c#75bd636a6b83fd6cb134b0981663aa28e49a811c" dependencies = [ "lock_api", "loom", @@ -3139,7 +3139,7 @@ dependencies = [ [[package]] name = "miden-package" version = "0.11.0" -source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=fe4afa2ad655772cd1ef1c30d014c383731ab293#fe4afa2ad655772cd1ef1c30d014c383731ab293" +source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=75bd636a6b83fd6cb134b0981663aa28e49a811c#75bd636a6b83fd6cb134b0981663aa28e49a811c" dependencies = [ "bitcode", "miden-assembly", @@ -3152,7 +3152,7 @@ dependencies = [ [[package]] name = "miden-processor" version = "0.11.0" -source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=fe4afa2ad655772cd1ef1c30d014c383731ab293#fe4afa2ad655772cd1ef1c30d014c383731ab293" +source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=75bd636a6b83fd6cb134b0981663aa28e49a811c#75bd636a6b83fd6cb134b0981663aa28e49a811c" dependencies = [ "miden-air", "miden-core", @@ -3168,7 +3168,7 @@ version = "0.0.7" [[package]] name = "miden-stdlib" version = "0.11.0" -source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=fe4afa2ad655772cd1ef1c30d014c383731ab293#fe4afa2ad655772cd1ef1c30d014c383731ab293" +source = "git+https://github.com/0xPolygonMiden/miden-vm?rev=75bd636a6b83fd6cb134b0981663aa28e49a811c#75bd636a6b83fd6cb134b0981663aa28e49a811c" dependencies = [ "miden-assembly", ] diff --git a/Cargo.toml b/Cargo.toml index 8ad5f7648..5e14a164e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -95,13 +95,13 @@ miden-parsing = "0.1" # miden-stdlib = { version = "0.11.0", path = "../vm-aux/stdlib" } # miden-package = { version = "0.11.0", path = "../vm-aux/package" } -miden-assembly = { version = "0.11.0", git = "https://github.com/0xPolygonMiden/miden-vm", rev = "fe4afa2ad655772cd1ef1c30d014c383731ab293" } -miden-core = { version = "0.11.0", git = "https://github.com/0xPolygonMiden/miden-vm", rev = "fe4afa2ad655772cd1ef1c30d014c383731ab293" } -miden-processor = { version = "0.11.0", git = "https://github.com/0xPolygonMiden/miden-vm", rev = "fe4afa2ad655772cd1ef1c30d014c383731ab293" } -miden-stdlib = { version = "0.11.0", git = "https://github.com/0xPolygonMiden/miden-vm", rev = "fe4afa2ad655772cd1ef1c30d014c383731ab293", features = [ +miden-assembly = { version = "0.11.0", git = "https://github.com/0xPolygonMiden/miden-vm", rev = "75bd636a6b83fd6cb134b0981663aa28e49a811c" } +miden-core = { version = "0.11.0", git = "https://github.com/0xPolygonMiden/miden-vm", rev = "75bd636a6b83fd6cb134b0981663aa28e49a811c" } +miden-processor = { version = "0.11.0", git = "https://github.com/0xPolygonMiden/miden-vm", rev = "75bd636a6b83fd6cb134b0981663aa28e49a811c" } +miden-stdlib = { version = "0.11.0", git = "https://github.com/0xPolygonMiden/miden-vm", rev = "75bd636a6b83fd6cb134b0981663aa28e49a811c", features = [ "with-debug-info", ] } -miden-package = { version = "0.11.0", git = "https://github.com/0xPolygonMiden/miden-vm", rev = "fe4afa2ad655772cd1ef1c30d014c383731ab293" } +miden-package = { version = "0.11.0", git = "https://github.com/0xPolygonMiden/miden-vm", rev = "75bd636a6b83fd6cb134b0981663aa28e49a811c" } #miden-assembly = { git = "https://github.com/0xPolygonMiden/miden-vm", rev = "828557c28ca1d159bfe42195e7ea73256ce4aa06" } #miden-core = { git = "https://github.com/0xPolygonMiden/miden-vm", rev = "828557c28ca1d159bfe42195e7ea73256ce4aa06" } From 0140596c466ff749d4c574825601dafd886ab8bd Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Tue, 26 Nov 2024 11:16:19 +0200 Subject: [PATCH 16/17] test: fix sharing target dir between basic wallet and p2id tests When building a basic wallet Miden package in the p2id test. --- tests/integration/src/rust_masm_tests/rust_sdk.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/integration/src/rust_masm_tests/rust_sdk.rs b/tests/integration/src/rust_masm_tests/rust_sdk.rs index 8f35e6c4a..3cc99949b 100644 --- a/tests/integration/src/rust_masm_tests/rust_sdk.rs +++ b/tests/integration/src/rust_masm_tests/rust_sdk.rs @@ -66,6 +66,10 @@ fn rust_sdk_p2id_note_script() { "--manifest-path", "../rust-apps-wasm/rust-sdk/basic-wallet/Cargo.toml", "--release", + // Use the target dir of this test's cargo project to avoid issues running tests in parallel + // i.e. avoid using the same target dir as the basic-wallet test (see above) + "--target-dir", + "../rust-apps-wasm/rust-sdk/p2id-note/target", ] .iter() .map(|s| s.to_string()) From 6745c3f33f1ec0c7a5f064ffed7c919c95b33314 Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Tue, 26 Nov 2024 11:17:40 +0200 Subject: [PATCH 17/17] chore: fix doc test false positive --- midenc-debug/src/felt.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/midenc-debug/src/felt.rs b/midenc-debug/src/felt.rs index ac77d4d97..24248c38e 100644 --- a/midenc-debug/src/felt.rs +++ b/midenc-debug/src/felt.rs @@ -282,11 +282,11 @@ impl PopFromStack for [u8; N] { /// /// Given a byte slice laid out like so: /// -/// [b0, b1, b2, b3, b4, b5, b6, b7, .., b31] +/// [b0, b1, b2, b3, b4, b5, b6, b7, .., b31] /// /// This will produce a vector of words laid out like so: /// -/// [[{b0, ..b3}, {b4, ..b7}, {b8..b11}, {b12, ..b15}], ..] +/// [[{b0, ..b3}, {b4, ..b7}, {b8..b11}, {b12, ..b15}], ..] /// /// In other words, it produces words that when placed on the stack and written to memory /// word-by-word, that memory will be laid out in the correct byte order.