diff --git a/frontend-wasm/src/component/build_ir.rs b/frontend-wasm/src/component/build_ir.rs index 73bb9355..879f0e01 100644 --- a/frontend-wasm/src/component/build_ir.rs +++ b/frontend-wasm/src/component/build_ir.rs @@ -64,12 +64,11 @@ fn inline( #[cfg(test)] mod tests { - use miden_core::crypto::hash::RpoDigest; use midenc_hir::{FunctionType, Ident, InterfaceFunctionIdent, InterfaceIdent, Symbol}; use midenc_hir_type::Type; use super::*; - use crate::{component::StaticModuleIndex, config::ImportMetadata, test_utils::test_context}; + use crate::{component::StaticModuleIndex, test_utils::test_context}; #[test] fn translate_simple() { @@ -182,19 +181,8 @@ mod tests { interface: InterfaceIdent::from_full_ident("miden:add/add@1.0.0"), function: Symbol::intern("add"), }; - let import_metadata = [( - interface_function_ident, - ImportMetadata { - digest: RpoDigest::default(), - }, - )] - .into_iter() - .collect(); - let config = WasmTranslationConfig { - import_metadata, - ..Default::default() - }; + let config = WasmTranslationConfig::default(); let (mut component_types_builder, parsed_component) = parse(&config, &wasm, &context.session).unwrap(); let component_translation = diff --git a/frontend-wasm/src/component/translator.rs b/frontend-wasm/src/component/translator.rs index 40de62ac..ecb778b9 100644 --- a/frontend-wasm/src/component/translator.rs +++ b/frontend-wasm/src/component/translator.rs @@ -314,24 +314,11 @@ impl<'a, 'data> ComponentTranslator<'a, 'data> { interface: InterfaceIdent::from_full_ident(&full_interface_name), function: Symbol::intern(import_func_name), }; - let Some(import_metadata) = self.config.import_metadata.get(&interface_function) else { - return Err(self - .session - .diagnostics - .diagnostic(Severity::Error) - .with_message(format!( - "wasm error: import metadata for interface function \ - {interface_function:?} not found" - )) - .into_report()); - }; let lifted_func_ty = convert_lifted_func_ty(&signature, &self.component_types); - let component_import = midenc_hir::ComponentImport::CanonAbiImport(CanonAbiImport::new( interface_function, lifted_func_ty, - import_metadata.digest, self.translate_canonical_options(options)?, )); Ok(Some(component_import)) diff --git a/frontend-wasm/src/config.rs b/frontend-wasm/src/config.rs index 62e6c171..3fec9d6d 100644 --- a/frontend-wasm/src/config.rs +++ b/frontend-wasm/src/config.rs @@ -1,21 +1,4 @@ -use alloc::{borrow::Cow, collections::BTreeMap, fmt}; - -use miden_core::crypto::hash::RpoDigest; -use midenc_hir::InterfaceFunctionIdent; - -/// Represents Miden VM codegen metadata for a function import. -/// This struct will have more fields in the future e.g. where the function -/// for this MAST hash is located (to be loaded by the VM) -#[derive(Clone)] -pub struct ImportMetadata { - /// The MAST root hash of the function to be used in codegen - pub digest: RpoDigest, -} -impl fmt::Debug for ImportMetadata { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_map().entry(&"digest", &self.digest.to_hex()).finish() - } -} +use alloc::borrow::Cow; /// Configuration for the WASM translation. #[derive(Debug)] @@ -33,11 +16,6 @@ pub struct WasmTranslationConfig { /// Whether or not to retain DWARF sections in compiled modules. pub parse_wasm_debuginfo: bool, - - /// Import metadata for MAST hashes, calling convention, of - /// each imported function. Having it here might be a temporary solution, - /// later we might want to move it to Wasm custom section. - pub import_metadata: BTreeMap, } impl Default for WasmTranslationConfig { @@ -47,7 +25,6 @@ impl Default for WasmTranslationConfig { override_name: None, generate_native_debuginfo: false, parse_wasm_debuginfo: true, - import_metadata: Default::default(), } } } diff --git a/hir/src/component/mod.rs b/hir/src/component/mod.rs index 8707ffdb..71ebc7c5 100644 --- a/hir/src/component/mod.rs +++ b/hir/src/component/mod.rs @@ -2,7 +2,6 @@ use alloc::collections::BTreeMap; use core::ops::{Deref, DerefMut}; use indexmap::IndexMap; -use miden_core::crypto::hash::RpoDigest; use midenc_hir_type::Abi; use self::formatter::PrettyPrint; @@ -32,8 +31,6 @@ pub struct CanonAbiImport { pub interface_function: InterfaceFunctionIdent, /// The component(lifted) type of the imported function function_ty: FunctionType, - /// The MAST root hash of the function to be used in codegen - pub digest: RpoDigest, /// Any options associated with this import pub options: CanonicalOptions, } @@ -42,14 +39,12 @@ impl CanonAbiImport { pub fn new( interface_function: InterfaceFunctionIdent, function_ty: FunctionType, - digest: RpoDigest, options: CanonicalOptions, ) -> Self { assert_eq!(function_ty.abi, Abi::Wasm, "expected Abi::Wasm function type ABI"); Self { interface_function, function_ty, - digest, options, } } @@ -111,13 +106,8 @@ impl formatter::PrettyPrint for ComponentImport { ComponentImport::MidenAbiImport(_import) => "".to_string(), }; - let digest = match self { - ComponentImport::CanonAbiImport(import) => format!("(digest {})", import.digest), - ComponentImport::MidenAbiImport(_) => "".to_string(), - }; const_text("(") + text(name) - + text(digest) + const_text(" ") + const_text("(") + const_text("type") diff --git a/midenc-session/src/libs.rs b/midenc-session/src/libs.rs index e55847fb..20b26526 100644 --- a/midenc-session/src/libs.rs +++ b/midenc-session/src/libs.rs @@ -31,12 +31,15 @@ pub enum LibraryKind { Mast, /// A source-form MASM library, using the standard project layout Masm, + // A Miden package (MASP) + Masp, } impl fmt::Display for LibraryKind { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Mast => f.write_str("mast"), Self::Masm => f.write_str("masm"), + Self::Masp => f.write_str("masp"), } } } @@ -47,6 +50,7 @@ impl FromStr for LibraryKind { match s { "mast" | "masl" => Ok(Self::Mast), "masm" => Ok(Self::Masm), + "masp" => Ok(Self::Masp), _ => Err(()), } } @@ -107,6 +111,9 @@ impl LinkLibrary { path.display() )) }), + LibraryKind::Masp => { + todo!("Should be implemented as part of the https://github.com/0xPolygonMiden/compiler/issues/346") + } } } @@ -149,6 +156,14 @@ impl LinkLibrary { ))); } } + LibraryKind::Masp => { + if !path.is_file() { + return Err(Report::msg(format!( + "unable to load Miden Assembly package from '{}': not a file", + path.display() + ))); + } + } } return Ok(path); } diff --git a/sdk/base-sys/src/bindings/note.rs b/sdk/base-sys/src/bindings/note.rs index 149e040a..5b750d13 100644 --- a/sdk/base-sys/src/bindings/note.rs +++ b/sdk/base-sys/src/bindings/note.rs @@ -3,6 +3,8 @@ use alloc::vec::Vec; use miden_stdlib_sys::Felt; +use super::CoreAsset; + #[link(wasm_import_module = "miden:core-import/note@1.0.0")] extern "C" { #[link_name = "get-inputs"] @@ -39,3 +41,7 @@ pub fn get_inputs() -> Vec { } inputs } + +pub fn get_assets() -> Vec { + todo!() +} diff --git a/sdk/base-sys/src/bindings/types.rs b/sdk/base-sys/src/bindings/types.rs index ded6fb46..b1bfcfd5 100644 --- a/sdk/base-sys/src/bindings/types.rs +++ b/sdk/base-sys/src/bindings/types.rs @@ -4,6 +4,12 @@ use miden_stdlib_sys::{Felt, Word}; #[derive(Copy, Clone)] pub struct AccountId(Felt); +impl AccountId { + pub fn as_felt(&self) -> Felt { + self.0 + } +} + impl From for Felt { fn from(account_id: AccountId) -> Felt { account_id.0 diff --git a/tests/integration/expected/components/inc_wasm_component.hir b/tests/integration/expected/components/inc_wasm_component.hir index 646e15ba..4eb1ecd6 100644 --- a/tests/integration/expected/components/inc_wasm_component.hir +++ b/tests/integration/expected/components/inc_wasm_component.hir @@ -1,6 +1,6 @@ (component ;; Component Imports - (lower (("miden:add-package/add-interface@1.0.0" #add) (digest 0x0000000000000000000000000000000000000000000000000000000000000000) (type (func (abi wasm) (param u32) (param u32) (result u32)))) (#miden:add-package/add-interface@1.0.0 #add) + (lower (("miden:add-package/add-interface@1.0.0" #add) (type (func (abi wasm) (param u32) (param u32) (result u32)))) (#miden:add-package/add-interface@1.0.0 #add) ;; Modules (module #inc_wasm_component diff --git a/tests/integration/expected/rust_sdk/basic_wallet.hir b/tests/integration/expected/rust_sdk/basic_wallet.hir index 14d68fe5..0ecee771 100644 --- a/tests/integration/expected/rust_sdk/basic_wallet.hir +++ b/tests/integration/expected/rust_sdk/basic_wallet.hir @@ -9,7 +9,7 @@ ;; Modules (module #basic_wallet ;; Data Segments - (data (mut) (offset 1048576) 0x0100000001000000010000000100000001000000010000000100000002000000) + (data (mut) (offset 1048576) 0x010000000100000001000000010000000100000001000000010000000100000002000000) ;; Constants (const (id 0) 0x00100000) @@ -37,7 +37,7 @@ (func (export #__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))) @@ -56,7 +56,7 @@ (func (export #__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)) @@ -87,7 +87,7 @@ (func (export #__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)) @@ -477,14 +477,14 @@ (let (v166 (ptr i64)) (inttoptr v164)) (let (v167 i64) (load v166)) (let (v168 u32) (bitcast v162)) - (let (v169 u32) (add.checked v168 1048608)) + (let (v169 u32) (add.checked v168 1048612)) (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 1048608)) + (let (v173 i32) (const.i32 1048612)) (ret v173)) ) @@ -536,7 +536,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)) @@ -551,7 +551,7 @@ (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)) @@ -571,7 +571,7 @@ (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))) @@ -1163,7 +1163,7 @@ (block 5 (let (v8 i32) (const.i32 0)) (let (v9 u32) (bitcast v8)) - (let (v10 u32) (add.checked v9 1048620)) + (let (v10 u32) (add.checked v9 1048624)) (let (v11 (ptr u8)) (inttoptr v10)) (let (v12 u8) (load v11)) (let (v13 i32) (zext v12)) diff --git a/tests/integration/expected/rust_sdk/basic_wallet.masm b/tests/integration/expected/rust_sdk/basic_wallet.masm index e815020a..a4f297aa 100644 --- a/tests/integration/expected/rust_sdk/basic_wallet.masm +++ b/tests/integration/expected/rust_sdk/basic_wallet.masm @@ -1,9 +1,9 @@ # mod basic_wallet -use.intrinsics::mem +use.std::crypto::hashes::blake3 use.miden::tx +use.intrinsics::mem use.miden::account -use.std::crypto::hashes::blake3 export.cabi_realloc exec.cabi_realloc_wit_bindgen_0_28_0 @@ -562,7 +562,7 @@ export."miden:basic-wallet/basic-wallet@1.0.0#test-stdlib" u32div.16 exec.::intrinsics::mem::store_sw push.0 - add.1048608 + add.1048612 u32assert dup.9 add.8 @@ -629,22 +629,13 @@ export."miden:basic-wallet/basic-wallet@1.0.0#test-stdlib" assertz.err=250 u32mod.4 assertz.err=250 - push.1048608 + push.1048612 end end end -export." as core::ops::drop::Drop>::drop" - dropw -end - - -export."alloc::vec::Vec::into_boxed_slice" - dup.1 - add.8 - u32assert - dup.2 +export."alloc::raw_vec::RawVec::try_allocate_in" mem_load.0x00011000 push.16 u32wrapping_sub @@ -661,503 +652,12 @@ export."alloc::vec::Vec::into_boxed_slice" u32div.16 exec.::intrinsics::mem::store_sw dup.2 - u32mod.4 - assertz.err=250 - dup.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 - movup.2 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::load_sw - dup.0 - movup.2 - swap.1 - u32lte - push.0 - push.0 - push.4294967294 - movup.2 - cdrop - u32or neq.0 if.true - dup.2 - add.4 - u32assert - movup.3 - movup.4 - add.4 - u32assert - dup.2 - 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 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::load_sw - dup.2 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::store_sw - push.16 - movup.4 - 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 - swap.1 - u32mod.4 - assertz.err=250 - u32mod.4 - assertz.err=250 - u32mod.4 - assertz.err=250 - else - dup.1 - add.8 - u32assert - push.8 + push.4294967295 dup.3 swap.1 - u32wrapping_add - dup.5 - movup.2 - swap.3 - movdn.2 - swap.1 - exec."alloc::raw_vec::RawVec::shrink_unchecked" - dup.0 - u32mod.4 - assertz.err=250 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::load_sw - push.2147483649 - neq - neq.0 - if.true - push.0 assert - else - dup.1 - add.4 - u32assert - dup.3 - add.8 - u32assert - movup.3 - movup.4 - add.4 - u32assert - 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::store_sw - dup.0 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::load_sw - dup.2 - 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 - swap.1 - u32mod.4 - assertz.err=250 - u32mod.4 - assertz.err=250 - swap.1 - u32mod.4 - assertz.err=250 - u32mod.4 - assertz.err=250 - end - end -end - - -export."alloc::raw_vec::RawVec::shrink_unchecked" - dup.1 - dup.0 - u32mod.4 - assertz.err=250 - push.2147483649 - 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 - eq.0 - neq.0 - if.true - movup.3 - swap.1 - drop - drop - dup.1 - add.4 - u32assert - movup.2 - 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.3 - 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 - else - swap.1 - drop - dup.2 - add.4 - u32assert - 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 - dup.4 - neq.0 - if.true - push.1 - push.1 - dup.6 - swap.1 - swap.2 - swap.4 - swap.1 - swap.3 - exec."__rust_realloc" - dup.0 - eq.0 - neq.0 - if.true - movup.3 - swap.1 - drop - drop - dup.1 - add.4 - u32assert - movup.2 - 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.3 - 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 - else - swap.1 - drop - dup.2 - movup.3 - add.4 - 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.3 - add.4 - u32assert - 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 - movup.3 - dup.1 - 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.2147483649 - 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 - u32mod.4 - assertz.err=250 - end - else - dup.3 - push.1 - movdn.2 - movdn.3 - exec."::deallocate" - movup.2 - add.4 - u32assert - dup.1 - dup.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.2 - add.4 - u32assert - push.1 - dup.2 - dup.0 - u32mod.16 - dup.0 - u32mod.4 - swap.1 - u32div.4 - movup.2 - u32div.16 - exec.::intrinsics::mem::store_sw - movup.3 - dup.1 - 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.2147483649 - 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 - u32mod.4 - assertz.err=250 - end - end -end - - -export."alloc::raw_vec::RawVec::try_allocate_in" - 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.2 - neq.0 - if.true - push.4294967295 - dup.3 - swap.1 - exec.::intrinsics::i32::is_gt + exec.::intrinsics::i32::is_gt dup.0 neq.0 if.true @@ -1808,8 +1308,508 @@ export."alloc::alloc::Global::alloc_impl" end -export."alloc::raw_vec::handle_error" - push.0 assert +export."alloc::vec::Vec::into_boxed_slice" + dup.1 + add.8 + u32assert + dup.2 + 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.2 + u32mod.4 + assertz.err=250 + dup.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 + movup.2 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_sw + dup.0 + movup.2 + swap.1 + u32lte + push.0 + push.0 + push.4294967294 + movup.2 + cdrop + u32or + neq.0 + if.true + dup.2 + add.4 + u32assert + movup.3 + movup.4 + add.4 + u32assert + dup.2 + 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 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_sw + dup.2 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + push.16 + movup.4 + 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 + swap.1 + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 + else + dup.1 + add.8 + u32assert + push.8 + dup.3 + swap.1 + u32wrapping_add + dup.5 + movup.2 + swap.3 + movdn.2 + swap.1 + exec."alloc::raw_vec::RawVec::shrink_unchecked" + dup.0 + u32mod.4 + assertz.err=250 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_sw + push.2147483649 + neq + neq.0 + if.true + push.0 assert + else + dup.1 + add.4 + u32assert + dup.3 + add.8 + u32assert + movup.3 + movup.4 + add.4 + u32assert + 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::store_sw + dup.0 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_sw + dup.2 + 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 + swap.1 + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 + swap.1 + u32mod.4 + assertz.err=250 + u32mod.4 + assertz.err=250 + end + end +end + + +export."alloc::raw_vec::RawVec::shrink_unchecked" + dup.1 + dup.0 + u32mod.4 + assertz.err=250 + push.2147483649 + 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 + eq.0 + neq.0 + if.true + movup.3 + swap.1 + drop + drop + dup.1 + add.4 + u32assert + movup.2 + 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.3 + 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 + else + swap.1 + drop + dup.2 + add.4 + u32assert + 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 + dup.4 + neq.0 + if.true + push.1 + push.1 + dup.6 + swap.1 + swap.2 + swap.4 + swap.1 + swap.3 + exec."__rust_realloc" + dup.0 + eq.0 + neq.0 + if.true + movup.3 + swap.1 + drop + drop + dup.1 + add.4 + u32assert + movup.2 + 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.3 + 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 + else + swap.1 + drop + dup.2 + movup.3 + add.4 + 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.3 + add.4 + u32assert + 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 + movup.3 + dup.1 + 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.2147483649 + 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 + u32mod.4 + assertz.err=250 + end + else + dup.3 + push.1 + movdn.2 + movdn.3 + exec."::deallocate" + movup.2 + add.4 + u32assert + dup.1 + dup.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.2 + add.4 + u32assert + push.1 + dup.2 + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::store_sw + movup.3 + dup.1 + 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.2147483649 + 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 + u32mod.4 + assertz.err=250 + end + end +end + + +export." as core::ops::drop::Drop>::drop" + dropw +end + + +export."alloc::raw_vec::handle_error" + push.0 assert end @@ -2070,19 +2070,52 @@ export."miden:basic-wallet/basic-wallet@1.0.0#send-asset" end -export."miden_base_sys::bindings::account::remove_asset" - dup.1 +export."miden_base_sys::bindings::tx::create_note" + dup.3 add.12 u32assert - dup.2 + dup.4 add.8 u32assert - dup.3 + dup.5 add.4 u32assert - movup.4 - movup.4 + movup.6 + dup.4 + add.12 + u32assert + dup.5 + add.8 + u32assert + dup.6 + add.4 + u32assert + movup.7 + dup.7 + u32mod.4 + assertz.err=250 + dup.6 + u32mod.4 + assertz.err=250 + dup.5 + u32mod.4 + assertz.err=250 dup.4 + u32mod.4 + assertz.err=250 + dup.3 + u32mod.4 + assertz.err=250 + dup.2 + u32mod.4 + assertz.err=250 + dup.1 + u32mod.4 + assertz.err=250 + dup.0 + u32mod.4 + assertz.err=250 + movup.7 dup.0 u32mod.16 dup.0 @@ -2092,7 +2125,7 @@ export."miden_base_sys::bindings::account::remove_asset" movup.2 u32div.16 exec.::intrinsics::mem::load_felt - dup.4 + movup.7 dup.0 u32mod.16 dup.0 @@ -2102,7 +2135,7 @@ export."miden_base_sys::bindings::account::remove_asset" movup.2 u32div.16 exec.::intrinsics::mem::load_felt - dup.4 + movup.7 dup.0 u32mod.16 dup.0 @@ -2112,7 +2145,7 @@ export."miden_base_sys::bindings::account::remove_asset" movup.2 u32div.16 exec.::intrinsics::mem::load_felt - dup.4 + movup.7 dup.0 u32mod.16 dup.0 @@ -2122,8 +2155,7 @@ export."miden_base_sys::bindings::account::remove_asset" movup.2 u32div.16 exec.::intrinsics::mem::load_felt - exec.::miden::account::remove_asset - dup.4 + movup.7 dup.0 u32mod.16 dup.0 @@ -2132,10 +2164,8 @@ export."miden_base_sys::bindings::account::remove_asset" u32div.4 movup.2 u32div.16 - exec.::intrinsics::mem::store_felt - dup.3 - add.4 - u32assert + exec.::intrinsics::mem::load_felt + movup.7 dup.0 u32mod.16 dup.0 @@ -2144,10 +2174,8 @@ export."miden_base_sys::bindings::account::remove_asset" u32div.4 movup.2 u32div.16 - exec.::intrinsics::mem::store_felt - dup.2 - add.8 - u32assert + exec.::intrinsics::mem::load_felt + movup.7 dup.0 u32mod.16 dup.0 @@ -2156,10 +2184,8 @@ export."miden_base_sys::bindings::account::remove_asset" u32div.4 movup.2 u32div.16 - exec.::intrinsics::mem::store_felt - swap.1 - add.12 - u32assert + exec.::intrinsics::mem::load_felt + movup.7 dup.0 u32mod.16 dup.0 @@ -2168,67 +2194,32 @@ export."miden_base_sys::bindings::account::remove_asset" u32div.4 movup.2 u32div.16 - exec.::intrinsics::mem::store_felt - 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 + exec.::intrinsics::mem::load_felt + movup.5 + swap.7 + swap.9 + movdn.5 + movup.4 + swap.6 + swap.8 + movdn.4 + exec.::miden::tx::create_note end -export."miden_base_sys::bindings::tx::create_note" - dup.3 - add.12 - u32assert - dup.4 - add.8 - u32assert - dup.5 - add.4 - u32assert - movup.6 - dup.4 +export."miden_base_sys::bindings::account::remove_asset" + dup.1 add.12 u32assert - dup.5 + dup.2 add.8 u32assert - dup.6 + dup.3 add.4 u32assert - movup.7 - dup.7 - u32mod.4 - assertz.err=250 - dup.6 - u32mod.4 - assertz.err=250 - dup.5 - u32mod.4 - assertz.err=250 + movup.4 + movup.4 dup.4 - u32mod.4 - assertz.err=250 - dup.3 - u32mod.4 - assertz.err=250 - dup.2 - u32mod.4 - assertz.err=250 - dup.1 - u32mod.4 - assertz.err=250 - dup.0 - u32mod.4 - assertz.err=250 - movup.7 dup.0 u32mod.16 dup.0 @@ -2238,7 +2229,7 @@ export."miden_base_sys::bindings::tx::create_note" movup.2 u32div.16 exec.::intrinsics::mem::load_felt - movup.7 + dup.4 dup.0 u32mod.16 dup.0 @@ -2248,7 +2239,7 @@ export."miden_base_sys::bindings::tx::create_note" movup.2 u32div.16 exec.::intrinsics::mem::load_felt - movup.7 + dup.4 dup.0 u32mod.16 dup.0 @@ -2258,7 +2249,7 @@ export."miden_base_sys::bindings::tx::create_note" movup.2 u32div.16 exec.::intrinsics::mem::load_felt - movup.7 + dup.4 dup.0 u32mod.16 dup.0 @@ -2268,7 +2259,8 @@ export."miden_base_sys::bindings::tx::create_note" movup.2 u32div.16 exec.::intrinsics::mem::load_felt - movup.7 + exec.::miden::account::remove_asset + dup.4 dup.0 u32mod.16 dup.0 @@ -2277,8 +2269,10 @@ export."miden_base_sys::bindings::tx::create_note" u32div.4 movup.2 u32div.16 - exec.::intrinsics::mem::load_felt - movup.7 + exec.::intrinsics::mem::store_felt + dup.3 + add.4 + u32assert dup.0 u32mod.16 dup.0 @@ -2287,8 +2281,10 @@ export."miden_base_sys::bindings::tx::create_note" u32div.4 movup.2 u32div.16 - exec.::intrinsics::mem::load_felt - movup.7 + exec.::intrinsics::mem::store_felt + dup.2 + add.8 + u32assert dup.0 u32mod.16 dup.0 @@ -2297,8 +2293,10 @@ export."miden_base_sys::bindings::tx::create_note" u32div.4 movup.2 u32div.16 - exec.::intrinsics::mem::load_felt - movup.7 + exec.::intrinsics::mem::store_felt + swap.1 + add.12 + u32assert dup.0 u32mod.16 dup.0 @@ -2307,16 +2305,18 @@ export."miden_base_sys::bindings::tx::create_note" 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::create_note + exec.::intrinsics::mem::store_felt + 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 end @@ -2544,7 +2544,7 @@ end export."wit_bindgen_rt::run_ctors_once" push.0 - add.1048621 + add.1048625 u32assert dup.0 u32mod.16 @@ -2566,7 +2566,7 @@ export."wit_bindgen_rt::run_ctors_once" push.128 u32and push.0 - add.1048621 + add.1048625 u32assert dup.0 u32mod.16 @@ -2591,7 +2591,7 @@ end export."__rust_alloc_zeroed" - push.1048616 + push.1048620 dup.1 swap.2 swap.3 @@ -2648,7 +2648,7 @@ end export."__rust_realloc" - push.1048616 + push.1048620 dup.4 swap.2 swap.4 @@ -2737,7 +2737,7 @@ end export."__rust_alloc" - push.1048616 + push.1048620 movup.2 swap.1 exec."::alloc" diff --git a/tests/integration/expected/rust_sdk/basic_wallet.wat b/tests/integration/expected/rust_sdk/basic_wallet.wat index b4493287..b9fb66ba 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 1048616 + i32.const 1048620 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 1048616 + i32.const 1048620 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 1048616 + i32.const 1048620 local.get 1 local.get 0 call $::alloc @@ -341,10 +341,10 @@ i32.const 0 local.get 2 i64.load offset=8 - i64.store offset=1048608 align=4 + i64.store offset=1048612 align=4 local.get 3 global.set $__stack_pointer - i32.const 1048608 + i32.const 1048612 return end unreachable @@ -373,7 +373,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 @@ -397,12 +397,12 @@ (func $wit_bindgen_rt::run_ctors_once (;19;) (type 5) 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 (;20;) (type 12) (param i32 i32 i32) (result i32) @@ -704,7 +704,7 @@ local.get 3 br_if 0 (;@2;) i32.const 0 - i32.load8_u offset=1048620 + i32.load8_u offset=1048624 drop local.get 2 local.get 1 @@ -809,7 +809,7 @@ (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\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\02\00\00\00") ) (alias export 2 "add" (func (;0;))) (core func (;0;) (canon lower (func 0))) diff --git a/tests/integration/expected/rust_sdk/p2id.hir b/tests/integration/expected/rust_sdk/p2id.hir new file mode 100644 index 00000000..4af36233 --- /dev/null +++ b/tests/integration/expected/rust_sdk/p2id.hir @@ -0,0 +1,646 @@ +(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) + + ;; Modules + (module #p2id + ;; Data Segments + (data (mut) (offset 1048576) 0x01000000010000000100000001000000010000000100000001000000010000000100000002000000) + + ;; Constants + (const (id 0) 0x00100000) + + ;; Global Variables + (global (export #__stack_pointer) (id 0) (type i32) (const 0)) + + ;; Functions + (func (export #__wasm_call_ctors) + (block 0 + (br (block 1))) + + (block 1 + (ret)) + ) + + (func (export #p2id::bindings::__link_custom_section_describing_imports) + + (block 0 + (br (block 1))) + + (block 1 + (ret)) + ) + + (func (export #__rust_alloc) (param i32) (param i32) (result i32) + (block 0 (param v0 i32) (param v1 i32) + (let (v3 i32) (const.i32 1048616)) + (let (v4 i32) (call #::alloc v3 v1 v0)) + (br (block 1 v4))) + + (block 1 (param v2 i32) + (ret v2)) + ) + + (func (export #__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 (v6 i32) (call #::alloc v5 v2 v3)) + (let (v7 i1) (eq v6 0)) + (let (v8 i32) (zext v7)) + (let (v9 i1) (neq v8 0)) + (condbr v9 (block 2 v6) (block 3))) + + (block 1 (param v4 i32) + (ret v4)) + + (block 2 (param v21 i32) + (br (block 1 v21))) + + (block 3 + (let (v10 u32) (bitcast v1)) + (let (v11 u32) (bitcast v3)) + (let (v12 i1) (lt v10 v11)) + (let (v13 i32) (sext v12)) + (let (v14 i1) (neq v13 0)) + (let (v15 i32) (select v14 v1 v3)) + (let (v16 u32) (bitcast v15)) + (let (v17 u32) (bitcast v6)) + (let (v18 (ptr u8)) (inttoptr v17)) + (let (v19 u32) (bitcast v0)) + (let (v20 (ptr u8)) (inttoptr v19)) + (memcpy v20 v18 v16) + (br (block 2 v6))) + ) + + (func (export #__rust_alloc_zeroed) (param i32) (param i32) (result i32) + (block 0 (param v0 i32) (param v1 i32) + (let (v3 i32) (const.i32 1048616)) + (let (v4 i32) (call #::alloc v3 v1 v0)) + (let (v5 i1) (eq v4 0)) + (let (v6 i32) (zext v5)) + (let (v7 i1) (neq v6 0)) + (condbr v7 (block 2 v4) (block 3))) + + (block 1 (param v2 i32) + (ret v2)) + + (block 2 (param v13 i32) + (br (block 1 v13))) + + (block 3 + (let (v8 i32) (const.i32 0)) + (let (v9 u8) (trunc v8)) + (let (v10 u32) (bitcast v0)) + (let (v11 u32) (bitcast v4)) + (let (v12 (ptr u8)) (inttoptr v11)) + (memset v12 v10 v9) + (br (block 2 v4))) + ) + + (func (export #miden:base/note-script@1.0.0#note-script) + (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) + (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))) + + (block 1) + + (block 2 + (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))) + + (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 (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))) + + (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) + (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 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))) + ) + + (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) + (let (v5 i32) (call #wit_bindgen_rt::cabi_realloc v0 v1 v2 v3)) + (br (block 1 v5))) + + (block 1 (param v4 i32) + (ret v4)) + ) + + (func (export #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)) + (condbr v5 (block 4) (block 5))) + + (block 1 (param v4 i32) + (ret v4)) + + (block 2 (param v19 i32) + (br (block 1 v19))) + + (block 3 (param v17 i32) + (let (v18 i1) (neq v17 0)) + (condbr v18 (block 2 v17) (block 7))) + + (block 4 + (let (v16 i32) (call #__rust_realloc v0 v1 v2 v3)) + (br (block 3 v16))) + + (block 5 + (let (v6 i1) (eq v3 0)) + (let (v7 i32) (zext v6)) + (let (v8 i1) (neq v7 0)) + (condbr v8 (block 2 v2) (block 6))) + + (block 6 + (let (v9 i32) (const.i32 0)) + (let (v10 u32) (bitcast v9)) + (let (v11 u32) (add.checked v10 1048620)) + (let (v12 (ptr u8)) (inttoptr v11)) + (let (v13 u8) (load v12)) + (let (v14 i32) (zext v13)) + (let (v15 i32) (call #__rust_alloc v3 v2)) + (br (block 3 v15))) + + (block 7 + (unreachable)) + ) + + (func (export #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 (v3 (ptr u8)) (inttoptr v2)) + (let (v4 u8) (load v3)) + (let (v5 i32) (zext v4)) + (let (v6 i1) (neq v5 0)) + (condbr v6 (block 2) (block 3))) + + (block 1 + (ret)) + + (block 2 + (br (block 1))) + + (block 3 + (call #__wasm_call_ctors) + (let (v7 i32) (const.i32 0)) + (let (v8 i32) (const.i32 1)) + (let (v9 u32) (bitcast v8)) + (let (v10 u8) (trunc v9)) + (let (v11 u32) (bitcast v7)) + (let (v12 u32) (add.checked v11 1048621)) + (let (v13 (ptr u8)) (inttoptr v12)) + (store v13 v10) + (br (block 2))) + ) + + (func (export #::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)) + (let (v5 i32) (const.i32 32)) + (let (v6 i32) (const.i32 32)) + (let (v7 u32) (bitcast v1)) + (let (v8 u32) (bitcast v6)) + (let (v9 i1) (gt v7 v8)) + (let (v10 i32) (sext v9)) + (let (v11 i1) (neq v10 0)) + (let (v12 i32) (select v11 v1 v5)) + (let (v13 u32) (popcnt v12)) + (let (v14 i32) (bitcast v13)) + (let (v15 i32) (const.i32 1)) + (let (v16 i1) (neq v14 v15)) + (let (v17 i32) (zext v16)) + (let (v18 i1) (neq v17 0)) + (condbr v18 (block 2) (block 3))) + + (block 1 (param v3 i32)) + + (block 2 + (unreachable)) + + (block 3 + (let (v19 i32) (const.i32 -2147483648)) + (let (v20 i32) (sub.wrapping v19 v12)) + (let (v21 u32) (bitcast v20)) + (let (v22 u32) (bitcast v2)) + (let (v23 i1) (lt v21 v22)) + (let (v24 i32) (sext v23)) + (let (v25 i1) (neq v24 0)) + (condbr v25 (block 2) (block 4))) + + (block 4 + (let (v26 i32) (const.i32 0)) + (let (v27 i32) (add.wrapping v12 v2)) + (let (v28 i32) (const.i32 -1)) + (let (v29 i32) (add.wrapping v27 v28)) + (let (v30 i32) (const.i32 0)) + (let (v31 i32) (sub.wrapping v30 v12)) + (let (v32 i32) (band v29 v31)) + (let (v33 u32) (bitcast v0)) + (let (v34 u32) (mod.unchecked v33 4)) + (assertz 250 v34) + (let (v35 (ptr i32)) (inttoptr v33)) + (let (v36 i32) (load v35)) + (let (v37 i1) (neq v36 0)) + (condbr v37 (block 5 v0 v32 v12 v26) (block 6))) + + (block 5 + (param v49 i32) + (param v55 i32) + (param v65 i32) + (param v68 i32) + (let (v48 i32) (const.i32 268435456)) + (let (v50 u32) (bitcast v49)) + (let (v51 u32) (mod.unchecked v50 4)) + (assertz 250 v51) + (let (v52 (ptr i32)) (inttoptr v50)) + (let (v53 i32) (load v52)) + (let (v54 i32) (sub.wrapping v48 v53)) + (let (v56 u32) (bitcast v54)) + (let (v57 u32) (bitcast v55)) + (let (v58 i1) (lt v56 v57)) + (let (v59 i32) (sext v58)) + (let (v60 i1) (neq v59 0)) + (condbr v60 (block 7 v68) (block 8))) + + (block 6 + (let (v38 u32) (call (#intrinsics::mem #heap_base))) + (let (v39 u32) (memory.size)) + (let (v40 i32) (const.i32 16)) + (let (v41 u32) (bitcast v40)) + (let (v42 u32) (shl.wrapping v39 v41)) + (let (v43 u32) (add.wrapping v38 v42)) + (let (v44 i32) (bitcast v43)) + (let (v45 u32) (bitcast v0)) + (let (v46 u32) (mod.unchecked v45 4)) + (assertz 250 v46) + (let (v47 (ptr i32)) (inttoptr v45)) + (store v47 v44) + (br (block 5 v0 v32 v12 v26))) + + (block 7 (param v67 i32) + (ret v67)) + + (block 8 + (let (v61 i32) (add.wrapping v53 v55)) + (let (v62 u32) (bitcast v49)) + (let (v63 u32) (mod.unchecked v62 4)) + (assertz 250 v63) + (let (v64 (ptr i32)) (inttoptr v62)) + (store v64 v61) + (let (v66 i32) (add.wrapping v53 v65)) + (br (block 7 v66))) + ) + + (func (export #miden_base_sys::bindings::account::get_id) + (result felt) + (block 0 + (let (v1 felt) (call (#miden::account #get_id))) + (br (block 1 v1))) + + (block 1 (param v0 felt) + (ret v0)) + ) + + (func (export #miden_base_sys::bindings::note::get_inputs) + (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 16)) + (let (v4 i32) (sub.wrapping v2 v3)) + (let (v5 (ptr i32)) (global.symbol #__stack_pointer)) + (store v5 v4) + (let (v6 i32) (const.i32 4)) + (let (v7 i32) (add.wrapping v4 v6)) + (let (v8 i32) (const.i32 256)) + (let (v9 i32) (const.i32 0)) + (call #alloc::raw_vec::RawVec::try_allocate_in v7 v8 v9) + (let (v10 u32) (bitcast v4)) + (let (v11 u32) (add.checked v10 8)) + (let (v12 u32) (mod.unchecked v11 4)) + (assertz 250 v12) + (let (v13 (ptr i32)) (inttoptr v11)) + (let (v14 i32) (load v13)) + (let (v15 u32) (bitcast v4)) + (let (v16 u32) (add.checked v15 4)) + (let (v17 u32) (mod.unchecked v16 4)) + (assertz 250 v17) + (let (v18 (ptr i32)) (inttoptr v16)) + (let (v19 i32) (load v18)) + (let (v20 i32) (const.i32 1)) + (let (v21 i1) (neq v19 v20)) + (let (v22 i32) (zext v21)) + (let (v23 i1) (neq v22 0)) + (condbr v23 (block 2) (block 3))) + + (block 1 + (ret)) + + (block 2 + (let (v29 u32) (bitcast v4)) + (let (v30 u32) (add.checked v29 12)) + (let (v31 u32) (mod.unchecked v30 4)) + (assertz 250 v31) + (let (v32 (ptr i32)) (inttoptr v30)) + (let (v33 i32) (load v32)) + (let (v34 i32) (const.i32 4)) + (let (v35 u32) (bitcast v33)) + (let (v36 u32) (bitcast v34)) + (let (v37 u32) (shr.wrapping v35 v36)) + (let (v38 i32) (bitcast v37)) + (let [(v39 i32) (v40 i32)] (call (#miden::note #get_inputs) v38)) + (let (v41 u32) (bitcast v0)) + (let (v42 u32) (add.checked v41 8)) + (let (v43 u32) (mod.unchecked v42 4)) + (assertz 250 v43) + (let (v44 (ptr i32)) (inttoptr v42)) + (store v44 v39) + (let (v45 u32) (bitcast v0)) + (let (v46 u32) (add.checked v45 4)) + (let (v47 u32) (mod.unchecked v46 4)) + (assertz 250 v47) + (let (v48 (ptr i32)) (inttoptr v46)) + (store v48 v33) + (let (v49 u32) (bitcast v0)) + (let (v50 u32) (mod.unchecked v49 4)) + (assertz 250 v50) + (let (v51 (ptr i32)) (inttoptr v49)) + (store v51 v14) + (let (v52 i32) (const.i32 16)) + (let (v53 i32) (add.wrapping v4 v52)) + (let (v54 (ptr i32)) (global.symbol #__stack_pointer)) + (store v54 v53) + (br (block 1))) + + (block 3 + (let (v24 u32) (bitcast v4)) + (let (v25 u32) (add.checked v24 12)) + (let (v26 u32) (mod.unchecked v25 4)) + (assertz 250 v26) + (let (v27 (ptr i32)) (inttoptr v25)) + (let (v28 i32) (load v27)) + (call #alloc::raw_vec::handle_error v14 v28) + (unreachable)) + ) + + (func (export #miden_base_sys::bindings::note::get_assets) + (param i32) + (block 0 (param v0 i32) + (unreachable)) + + (block 1) + ) + + (func (export #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)) + (let (v4 i1) (neq v1 0)) + (condbr v4 (block 3) (block 4))) + + (block 1 + (ret)) + + (block 2 (param v62 i32) (param v64 i32) + (let (v65 u32) (bitcast v62)) + (let (v66 u32) (mod.unchecked v65 4)) + (assertz 250 v66) + (let (v67 (ptr i32)) (inttoptr v65)) + (store v67 v64) + (br (block 1))) + + (block 3 + (let (v11 i32) (const.i32 536870912)) + (let (v12 u32) (bitcast v1)) + (let (v13 u32) (bitcast v11)) + (let (v14 i1) (lt v12 v13)) + (let (v15 i32) (sext v14)) + (let (v16 i1) (neq v15 0)) + (condbr v16 (block 6) (block 7))) + + (block 4 + (let (v5 i64) (const.i64 17179869184)) + (let (v6 u32) (bitcast v0)) + (let (v7 u32) (add.checked v6 4)) + (let (v8 u32) (mod.unchecked v7 4)) + (assertz 250 v8) + (let (v9 (ptr i64)) (inttoptr v7)) + (store v9 v5) + (let (v10 i32) (const.i32 0)) + (br (block 2 v0 v10))) + + (block 5 (param v63 i32) + (let (v61 i32) (const.i32 1)) + (br (block 2 v63 v61))) + + (block 6 + (let (v22 i32) (const.i32 2)) + (let (v23 u32) (bitcast v22)) + (let (v24 i32) (shl.wrapping v1 v23)) + (let (v25 i1) (neq v2 0)) + (condbr v25 (block 9) (block 10))) + + (block 7 + (let (v17 i32) (const.i32 0)) + (let (v18 u32) (bitcast v0)) + (let (v19 u32) (add.checked v18 4)) + (let (v20 u32) (mod.unchecked v19 4)) + (assertz 250 v20) + (let (v21 (ptr i32)) (inttoptr v19)) + (store v21 v17) + (br (block 5 v0))) + + (block 8 + (param v36 i32) + (param v40 i32) + (param v45 i32) + (param v51 i32) + (let (v37 i1) (eq v36 0)) + (let (v38 i32) (zext v37)) + (let (v39 i1) (neq v38 0)) + (condbr v39 (block 11) (block 12))) + + (block 9 + (let (v34 i32) (const.i32 4)) + (let (v35 i32) (call #__rust_alloc_zeroed v24 v34)) + (br (block 8 v35 v0 v1 v24))) + + (block 10 + (let (v26 i32) (const.i32 0)) + (let (v27 u32) (bitcast v26)) + (let (v28 u32) (add.checked v27 1048620)) + (let (v29 (ptr u8)) (inttoptr v28)) + (let (v30 u8) (load v29)) + (let (v31 i32) (zext v30)) + (let (v32 i32) (const.i32 4)) + (let (v33 i32) (call #__rust_alloc v24 v32)) + (br (block 8 v33 v0 v1 v24))) + + (block 11 + (let (v52 u32) (bitcast v40)) + (let (v53 u32) (add.checked v52 8)) + (let (v54 u32) (mod.unchecked v53 4)) + (assertz 250 v54) + (let (v55 (ptr i32)) (inttoptr v53)) + (store v55 v51) + (let (v56 i32) (const.i32 4)) + (let (v57 u32) (bitcast v40)) + (let (v58 u32) (add.checked v57 4)) + (let (v59 u32) (mod.unchecked v58 4)) + (assertz 250 v59) + (let (v60 (ptr i32)) (inttoptr v58)) + (store v60 v56) + (br (block 5 v40))) + + (block 12 + (let (v41 u32) (bitcast v40)) + (let (v42 u32) (add.checked v41 8)) + (let (v43 u32) (mod.unchecked v42 4)) + (assertz 250 v43) + (let (v44 (ptr i32)) (inttoptr v42)) + (store v44 v36) + (let (v46 u32) (bitcast v40)) + (let (v47 u32) (add.checked v46 4)) + (let (v48 u32) (mod.unchecked v47 4)) + (assertz 250 v48) + (let (v49 (ptr i32)) (inttoptr v47)) + (store v49 v45) + (let (v50 i32) (const.i32 0)) + (br (block 2 v40 v50))) + ) + + (func (export #alloc::raw_vec::handle_error) + (param i32) (param i32) + (block 0 (param v0 i32) (param v1 i32) + (unreachable)) + + (block 1) + ) + + (func (export #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 i32) (call #cabi_realloc_wit_bindgen_0_28_0 v0 v1 v2 v3)) + (br (block 1 v5))) + + (block 1 (param v4 i32) + (ret v4)) + ) + + ;; Imports + (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/basic-wallet@1.0.0 #receive_asset) + (param felt) (param felt) (param felt) (param felt)) + ) + +) diff --git a/tests/integration/expected/rust_sdk/p2id.masm b/tests/integration/expected/rust_sdk/p2id.masm new file mode 100644 index 00000000..bbb9009e --- /dev/null +++ b/tests/integration/expected/rust_sdk/p2id.masm @@ -0,0 +1,415 @@ +# mod p2id + +use.intrinsics::mem + +export.cabi_realloc + exec.cabi_realloc_wit_bindgen_0_28_0 +end + + +export.cabi_realloc_wit_bindgen_0_28_0 + exec."wit_bindgen_rt::cabi_realloc" +end + + +export."wit_bindgen_rt::cabi_realloc" + dup.1 + neq.0 + if.true + exec."__rust_realloc" + dup.0 + neq.0 + if.true + + else + push.0 assert + end + else + drop + drop + dup.1 + eq.0 + neq.0 + if.true + swap.1 drop + else + swap.1 + exec."__rust_alloc" + dup.0 + neq.0 + if.true + + else + push.0 assert + end + end + end +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" + push.0 + add.1048617 + u32assert + dup.0 + u32mod.16 + dup.0 + u32mod.4 + swap.1 + u32div.4 + movup.2 + u32div.16 + exec.::intrinsics::mem::load_sw + push.128 + u32and + neq.0 + if.true + + else + exec."__wasm_call_ctors" + push.1 + push.128 + u32and + push.0 + add.1048617 + u32assert + 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 + end +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 +end + + +export."__rust_alloc" + push.1048612 + movup.2 + swap.1 + exec."::alloc" +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 + 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 + + +export."p2id::bindings::__link_custom_section_describing_imports" + +end + + +export."__wasm_call_ctors" + +end + + diff --git a/tests/integration/expected/rust_sdk/p2id.wat b/tests/integration/expected/rust_sdk/p2id.wat new file mode 100644 index 00000000..ac365a5f --- /dev/null +++ b/tests/integration/expected/rust_sdk/p2id.wat @@ -0,0 +1,500 @@ +(component + (type (;0;) + (instance + (type (;0;) (record (field "inner" float32))) + (export (;1;) "felt" (type (eq 0))) + (type (;2;) (tuple 1 1 1 1)) + (type (;3;) (record (field "inner" 2))) + (export (;4;) "word" (type (eq 3))) + (type (;5;) (record (field "inner" 4))) + (export (;6;) "core-asset" (type (eq 5))) + ) + ) + (import "miden:base/core-types@1.0.0" (instance (;0;) (type 0))) + (alias export 0 "core-asset" (type (;1;))) + (type (;2;) + (instance + (alias outer 1 1 (type (;0;))) + (export (;1;) "core-asset" (type (eq 0))) + (type (;2;) (func (param "core-asset" 1))) + (export (;0;) "receive-asset" (func (type 2))) + ) + ) + (import "miden:basic-wallet/basic-wallet@1.0.0" (instance (;1;) (type 2))) + (type (;3;) + (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;) + (instance + (type (;0;) (func (param "a" float32) (param "b" float32) (result bool))) + (export (;0;) "eq" (func (type 0))) + ) + ) + (import "miden:core-import/intrinsics-felt@1.0.0" (instance (;3;) (type 4))) + (type (;5;) + (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;) + (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))) + (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 (;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 + local.get 1 + local.get 0 + call $::alloc + ) + (func $__rust_realloc (;8;) (type 7) (param i32 i32 i32 i32) (result i32) + block ;; label = @1 + i32.const 1048616 + local.get 2 + local.get 3 + call $::alloc + local.tee 2 + i32.eqz + br_if 0 (;@1;) + local.get 2 + local.get 0 + local.get 1 + local.get 3 + local.get 1 + local.get 3 + i32.lt_u + select + memory.copy + end + local.get 2 + ) + (func $__rust_alloc_zeroed (;9;) (type 6) (param i32 i32) (result i32) + block ;; label = @1 + i32.const 1048616 + local.get 1 + local.get 0 + call $::alloc + local.tee 1 + i32.eqz + br_if 0 (;@1;) + local.get 1 + i32.const 0 + local.get 0 + memory.fill + end + local.get 1 + ) + (func $miden:base/note-script@1.0.0#note-script (;10;) (type 5) + (local i32 f32 i32 i32) + global.get $__stack_pointer + i32.const 32 + i32.sub + local.tee 0 + global.set $__stack_pointer + call $wit_bindgen_rt::run_ctors_once + local.get 0 + i32.const 8 + i32.add + call $miden_base_sys::bindings::note::get_inputs + block ;; label = @1 + local.get 0 + i32.load offset=16 + i32.eqz + br_if 0 (;@1;) + local.get 0 + i32.load offset=12 + f32.load + local.set 1 + 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 0 + i32.const 20 + i32.add + call $miden_base_sys::bindings::note::get_assets + local.get 0 + i32.load offset=28 + i32.const 5 + i32.shl + local.set 2 + local.get 0 + i32.load offset=24 + local.set 3 + block ;; label = @2 + loop ;; label = @3 + local.get 2 + i32.eqz + br_if 1 (;@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 $p2id::bindings::miden::basic_wallet::basic_wallet::receive_asset::wit_import + local.get 2 + i32.const -32 + i32.add + local.set 2 + local.get 3 + i32.const 32 + i32.add + local.set 3 + br 0 (;@3;) + end + end + local.get 0 + i32.const 32 + i32.add + global.set $__stack_pointer + return + end + unreachable + ) + (func $cabi_realloc_wit_bindgen_0_28_0 (;11;) (type 7) (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) + block ;; label = @1 + block ;; label = @2 + block ;; label = @3 + local.get 1 + br_if 0 (;@3;) + local.get 3 + i32.eqz + br_if 2 (;@1;) + i32.const 0 + i32.load8_u offset=1048620 + drop + local.get 3 + local.get 2 + call $__rust_alloc + local.set 2 + br 1 (;@2;) + end + local.get 0 + local.get 1 + local.get 2 + local.get 3 + call $__rust_realloc + local.set 2 + end + local.get 2 + br_if 0 (;@1;) + unreachable + end + local.get 2 + ) + (func $wit_bindgen_rt::run_ctors_once (;13;) (type 5) + block ;; label = @1 + i32.const 0 + i32.load8_u offset=1048621 + br_if 0 (;@1;) + call $__wasm_call_ctors + i32.const 0 + i32.const 1 + i32.store8 offset=1048621 + end + ) + (func $::alloc (;14;) (type 8) (param i32 i32 i32) (result i32) + (local i32 i32) + block ;; label = @1 + local.get 1 + i32.const 32 + local.get 1 + i32.const 32 + i32.gt_u + select + local.tee 1 + i32.popcnt + i32.const 1 + i32.ne + br_if 0 (;@1;) + i32.const -2147483648 + local.get 1 + i32.sub + local.get 2 + i32.lt_u + br_if 0 (;@1;) + i32.const 0 + local.set 3 + local.get 1 + local.get 2 + i32.add + i32.const -1 + i32.add + i32.const 0 + local.get 1 + i32.sub + i32.and + local.set 2 + block ;; label = @2 + local.get 0 + i32.load + br_if 0 (;@2;) + local.get 0 + call $miden_sdk_alloc::heap_base + memory.size + i32.const 16 + i32.shl + i32.add + i32.store + end + block ;; label = @2 + i32.const 268435456 + local.get 0 + i32.load + local.tee 4 + i32.sub + local.get 2 + i32.lt_u + br_if 0 (;@2;) + local.get 0 + local.get 4 + local.get 2 + i32.add + i32.store + local.get 4 + local.get 1 + i32.add + local.set 3 + end + local.get 3 + return + end + unreachable + ) + (func $miden_base_sys::bindings::account::get_id (;15;) (type 3) (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) + (local i32 i32 i32) + global.get $__stack_pointer + i32.const 16 + i32.sub + local.tee 1 + global.set $__stack_pointer + local.get 1 + i32.const 4 + i32.add + i32.const 256 + i32.const 0 + call $alloc::raw_vec::RawVec::try_allocate_in + local.get 1 + i32.load offset=8 + local.set 2 + block ;; label = @1 + local.get 1 + i32.load offset=4 + i32.const 1 + i32.ne + br_if 0 (;@1;) + local.get 2 + local.get 1 + i32.load offset=12 + call $alloc::raw_vec::handle_error + unreachable + end + local.get 0 + local.get 1 + i32.load offset=12 + local.tee 3 + i32.const 4 + i32.shr_u + call $miden_base_sys::bindings::note::extern_note_get_inputs + i32.store offset=8 + local.get 0 + local.get 3 + i32.store offset=4 + local.get 0 + local.get 2 + i32.store + local.get 1 + i32.const 16 + i32.add + global.set $__stack_pointer + ) + (func $miden_base_sys::bindings::note::get_assets (;17;) (type 9) (param i32) + unreachable + ) + (func $alloc::raw_vec::RawVec::try_allocate_in (;18;) (type 10) (param i32 i32 i32) + (local i32) + block ;; label = @1 + block ;; label = @2 + local.get 1 + br_if 0 (;@2;) + local.get 0 + i64.const 17179869184 + i64.store offset=4 align=4 + i32.const 0 + local.set 1 + br 1 (;@1;) + end + block ;; label = @2 + block ;; label = @3 + local.get 1 + i32.const 536870912 + i32.lt_u + br_if 0 (;@3;) + local.get 0 + i32.const 0 + i32.store offset=4 + br 1 (;@2;) + end + local.get 1 + i32.const 2 + i32.shl + local.set 3 + block ;; label = @3 + block ;; label = @4 + local.get 2 + br_if 0 (;@4;) + i32.const 0 + i32.load8_u offset=1048620 + drop + local.get 3 + i32.const 4 + call $__rust_alloc + local.set 2 + br 1 (;@3;) + end + local.get 3 + i32.const 4 + call $__rust_alloc_zeroed + local.set 2 + end + block ;; label = @3 + local.get 2 + i32.eqz + br_if 0 (;@3;) + local.get 0 + local.get 2 + i32.store offset=8 + local.get 0 + local.get 1 + i32.store offset=4 + i32.const 0 + local.set 1 + br 2 (;@1;) + end + local.get 0 + local.get 3 + i32.store offset=8 + local.get 0 + i32.const 4 + i32.store offset=4 + end + i32.const 1 + local.set 1 + end + local.get 0 + local.get 1 + i32.store + ) + (func $alloc::raw_vec::handle_error (;19;) (type 11) (param i32 i32) + unreachable + ) + (func $cabi_realloc (;20;) (type 7) (param i32 i32 i32 i32) (result i32) + local.get 0 + local.get 1 + local.get 2 + local.get 3 + call $cabi_realloc_wit_bindgen_0_28_0 + ) + (table (;0;) 3 3 funcref) + (memory (;0;) 17) + (global $__stack_pointer (;0;) (mut i32) i32.const 1048576) + (export "memory" (memory 0)) + (export "miden:base/note-script@1.0.0#note-script" (func $miden:base/note-script@1.0.0#note-script)) + (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") + ) + (alias export 3 "eq" (func (;0;))) + (core func (;0;) (canon lower (func 0))) + (core instance (;0;) + (export "eq" (func 0)) + ) + (alias export 1 "receive-asset" (func (;1;))) + (core func (;1;) (canon lower (func 1))) + (core instance (;1;) + (export "receive-asset" (func 1)) + ) + (alias export 2 "heap-base" (func (;2;))) + (core func (;2;) (canon lower (func 2))) + (core instance (;2;) + (export "heap-base" (func 2)) + ) + (alias export 4 "get-id" (func (;3;))) + (core func (;3;) (canon lower (func 3))) + (core instance (;3;) + (export "get-id" (func 3)) + ) + (alias export 5 "get-inputs" (func (;4;))) + (core func (;4;) (canon lower (func 4))) + (core instance (;4;) + (export "get-inputs" (func 4)) + ) + (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)) + ) + ) + (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))) + (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)) + ) + ) + (export (;7;) "miden:base/note-script@1.0.0" (instance 6)) +) \ No newline at end of file diff --git a/tests/integration/expected/wit_sdk_basic_wallet/basic_wallet.hir b/tests/integration/expected/wit_sdk_basic_wallet/basic_wallet.hir index 9f9082ee..a1e883b3 100644 --- a/tests/integration/expected/wit_sdk_basic_wallet/basic_wallet.hir +++ b/tests/integration/expected/wit_sdk_basic_wallet/basic_wallet.hir @@ -1,8 +1,8 @@ (component ;; Component Imports - (lower (("miden:base/account@1.0.0" #add-asset) (digest 0x0000000000000000000000000000000000000000000000000000000000000000) (type (func (abi wasm) (param (struct (struct (struct u64) (struct u64) (struct u64) (struct u64)))) (result (struct (struct (struct u64) (struct u64) (struct u64) (struct u64))))))) (# #0) - (lower (("miden:base/account@1.0.0" #remove-asset) (digest 0x0000000000000000000000000000000000000000000000000000000000000000) (type (func (abi wasm) (param (struct (struct (struct u64) (struct u64) (struct u64) (struct u64)))) (result (struct (struct (struct u64) (struct u64) (struct u64) (struct u64))))))) (# #1) - (lower (("miden:base/tx@1.0.0" #create-note) (digest 0x0000000000000000000000000000000000000000000000000000000000000000) (type (func (abi wasm) (param (struct (struct (struct u64) (struct u64) (struct u64) (struct u64)))) (param (struct (struct u64))) (param (struct (struct (struct u64) (struct u64) (struct u64) (struct u64)))) (result (struct (struct u64)))))) (#miden:base/tx@1.0.0 #create_note) + (lower (("miden:base/account@1.0.0" #add-asset) (type (func (abi wasm) (param (struct (struct (struct u64) (struct u64) (struct u64) (struct u64)))) (result (struct (struct (struct u64) (struct u64) (struct u64) (struct u64))))))) (# #0) + (lower (("miden:base/account@1.0.0" #remove-asset) (type (func (abi wasm) (param (struct (struct (struct u64) (struct u64) (struct u64) (struct u64)))) (result (struct (struct (struct u64) (struct u64) (struct u64) (struct u64))))))) (# #1) + (lower (("miden:base/tx@1.0.0" #create-note) (type (func (abi wasm) (param (struct (struct (struct u64) (struct u64) (struct u64) (struct u64)))) (param (struct (struct u64))) (param (struct (struct (struct u64) (struct u64) (struct u64) (struct u64)))) (result (struct (struct u64)))))) (#miden:base/tx@1.0.0 #create_note) ;; Modules (module #wit-component:shim diff --git a/tests/integration/expected/wit_sdk_basic_wallet/basic_wallet_p2id_note.hir b/tests/integration/expected/wit_sdk_basic_wallet/basic_wallet_p2id_note.hir index 19a1ff71..14b86027 100644 --- a/tests/integration/expected/wit_sdk_basic_wallet/basic_wallet_p2id_note.hir +++ b/tests/integration/expected/wit_sdk_basic_wallet/basic_wallet_p2id_note.hir @@ -1,10 +1,10 @@ (component ;; Component Imports - (lower (("miden:base/note@1.0.0" #get-inputs) (digest 0x0000000000000000000000000000000000000000000000000000000000000000) (type (func (abi wasm) (result (list (struct u64)))))) (# #0) - (lower (("miden:base/note@1.0.0" #get-assets) (digest 0x0000000000000000000000000000000000000000000000000000000000000000) (type (func (abi wasm) (result (list (struct (struct (struct u64) (struct u64) (struct u64) (struct u64)))))))) (# #1) - (lower (("miden:base/account@1.0.0" #get-id) (digest 0x0000000000000000000000000000000000000000000000000000000000000000) (type (func (abi wasm) (result (struct (struct u64)))))) (#miden:base/account@1.0.0 #get_id) - (lower (("miden:base/core-types@1.0.0" #account-id-from-felt) (digest 0x0000000000000000000000000000000000000000000000000000000000000000) (type (func (abi wasm) (param (struct u64)) (result (struct (struct u64)))))) (#miden:base/core-types@1.0.0 #account_id_from_felt) - (lower (("miden:basic-wallet/basic-wallet@1.0.0" #receive-asset) (digest 0x0000000000000000000000000000000000000000000000000000000000000000) (type (func (abi wasm) (param (struct (struct (struct u64) (struct u64) (struct u64) (struct u64))))))) (#miden:basic-wallet/basic-wallet@1.0.0 #receive_asset) + (lower (("miden:base/note@1.0.0" #get-inputs) (type (func (abi wasm) (result (list (struct u64)))))) (# #0) + (lower (("miden:base/note@1.0.0" #get-assets) (type (func (abi wasm) (result (list (struct (struct (struct u64) (struct u64) (struct u64) (struct u64)))))))) (# #1) + (lower (("miden:base/account@1.0.0" #get-id) (type (func (abi wasm) (result (struct (struct u64)))))) (#miden:base/account@1.0.0 #get_id) + (lower (("miden:base/core-types@1.0.0" #account-id-from-felt) (type (func (abi wasm) (param (struct u64)) (result (struct (struct u64)))))) (#miden:base/core-types@1.0.0 #account_id_from_felt) + (lower (("miden:basic-wallet/basic-wallet@1.0.0" #receive-asset) (type (func (abi wasm) (param (struct (struct (struct u64) (struct u64) (struct u64) (struct u64))))))) (#miden:basic-wallet/basic-wallet@1.0.0 #receive_asset) ;; Modules (module #wit-component:shim diff --git a/tests/integration/src/compiler_test.rs b/tests/integration/src/compiler_test.rs index 35946e2b..3a78726c 100644 --- a/tests/integration/src/compiler_test.rs +++ b/tests/integration/src/compiler_test.rs @@ -447,6 +447,7 @@ impl CompilerTestBuilder { args.extend(cmd_args); let wasm_artifacts = cargo_miden::run(args.into_iter(), cargo_miden::OutputType::Wasm).unwrap(); + assert_eq!(wasm_artifacts.len(), 1); let wasm_comp_path = &wasm_artifacts.first().unwrap(); let artifact_name = wasm_comp_path.file_stem().unwrap().to_str().unwrap().to_string(); @@ -462,6 +463,7 @@ impl CompilerTestBuilder { }, ) })); + dbg!(&inputs); CompilerTest { config: self.config, @@ -649,6 +651,7 @@ impl CompilerTestBuilder { pub fn rust_source_cargo_miden( cargo_project_folder: impl AsRef, config: WasmTranslationConfig, + midenc_flags: impl IntoIterator>, ) -> Self { let name = cargo_project_folder .as_ref() @@ -660,6 +663,7 @@ impl CompilerTestBuilder { )); builder.with_wasm_translation_config(config); builder.with_midenc_flags(["--target".into(), "rollup".into()]); + builder.with_midenc_flags(midenc_flags); builder } @@ -1018,8 +1022,10 @@ impl CompilerTest { pub fn rust_source_cargo_miden( cargo_project_folder: impl AsRef, config: WasmTranslationConfig, + midenc_flags: impl IntoIterator>, ) -> Self { - CompilerTestBuilder::rust_source_cargo_miden(cargo_project_folder, config).build() + CompilerTestBuilder::rust_source_cargo_miden(cargo_project_folder, config, midenc_flags) + .build() } /// Set the Rust source code to compile a library Cargo project to Wasm module diff --git a/tests/integration/src/rust_masm_tests/components.rs b/tests/integration/src/rust_masm_tests/components.rs index b214eac8..cce078f9 100644 --- a/tests/integration/src/rust_masm_tests/components.rs +++ b/tests/integration/src/rust_masm_tests/components.rs @@ -1,6 +1,6 @@ use expect_test::expect_file; use miden_core::crypto::hash::RpoDigest; -use midenc_frontend_wasm::{ImportMetadata, WasmTranslationConfig}; +use midenc_frontend_wasm::WasmTranslationConfig; use midenc_hir::{FunctionType, Ident, InterfaceFunctionIdent, InterfaceIdent, Symbol, Type}; use crate::{cargo_proj::project, CompilerTest}; @@ -90,19 +90,8 @@ fn wcm_import() { interface: InterfaceIdent::from_full_ident("miden:add-package/add-interface@1.0.0"), function: Symbol::intern("add"), }; - let import_metadata = [( - interface_function_ident, - ImportMetadata { - digest: RpoDigest::default(), - }, - )] - .into_iter() - .collect(); - - let config = WasmTranslationConfig { - import_metadata, - ..Default::default() - }; + + let config = WasmTranslationConfig::default(); // Create the add component that will be imported in the wcm_import project let _add_proj_dep = project("wcm_import_add") diff --git a/tests/integration/src/rust_masm_tests/rust_sdk.rs b/tests/integration/src/rust_masm_tests/rust_sdk.rs index 6889db49..f2c1216d 100644 --- a/tests/integration/src/rust_masm_tests/rust_sdk.rs +++ b/tests/integration/src/rust_masm_tests/rust_sdk.rs @@ -1,8 +1,9 @@ -use std::{collections::BTreeMap, path::PathBuf}; +use std::{collections::BTreeMap, env, path::PathBuf}; use expect_test::expect_file; use miden_core::crypto::hash::RpoDigest; -use midenc_frontend_wasm::{ImportMetadata, WasmTranslationConfig}; +use midenc_codegen_masm::Package; +use midenc_frontend_wasm::WasmTranslationConfig; use midenc_hir::{InterfaceFunctionIdent, InterfaceIdent, Symbol}; use crate::{cargo_proj::project, compiler_test::sdk_crate_path, CompilerTest}; @@ -31,12 +32,61 @@ fn account() { #[test] fn rust_sdk_basic_wallet() { let _ = env_logger::builder().is_test(true).try_init(); - let project_name = "rust_sdk_basic_wallet"; let config = WasmTranslationConfig::default(); - let mut test = - CompilerTest::rust_source_cargo_miden("../rust-apps-wasm/rust-sdk/basic-wallet", config); + let mut test = CompilerTest::rust_source_cargo_miden( + "../rust-apps-wasm/rust-sdk/basic-wallet", + config, + [], + ); 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] +fn rust_sdk_p2id_note_script() { + // Build basic-wallet package + let args: Vec = [ + "cargo", + "miden", + "build", + "--manifest-path", + "../rust-apps-wasm/rust-sdk/basic-wallet/Cargo.toml", + "--release", + ] + .iter() + .map(|s| s.to_string()) + .collect(); + dbg!(env::current_dir().unwrap().display()); + let outputs = cargo_miden::run(args.into_iter(), cargo_miden::OutputType::Masm) + .expect("Failed to compile the basic-wallet package"); + let masp_path: PathBuf = outputs.first().unwrap().clone(); + dbg!(&masp_path); + + // + // let masp = Package::read_from_file(masp_path.clone()).unwrap(); + // let basic_wallet_lib = match masp.mast { + // midenc_codegen_masm::MastArtifact::Executable(arc) => panic!("expected library"), + // midenc_codegen_masm::MastArtifact::Library(arc) => arc.clone(), + // }; + // let mut masl_path = masp_path.clone(); + // masl_path.set_extension("masl"); + // basic_wallet_lib.write_to_file(masl_path.clone()).unwrap(); + + let _ = env_logger::builder().is_test(true).try_init(); + + let config = WasmTranslationConfig::default(); + let mut test = CompilerTest::rust_source_cargo_miden( + "../rust-apps-wasm/rust-sdk/p2id-note", + config, + [ + // "--link-library".into(), + // masl_path.into_os_string().into_string().unwrap().into(), + ], + ); + 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")]); +} diff --git a/tests/integration/src/rust_masm_tests/wit_sdk.rs b/tests/integration/src/rust_masm_tests/wit_sdk.rs index 084428aa..72e6cf2d 100644 --- a/tests/integration/src/rust_masm_tests/wit_sdk.rs +++ b/tests/integration/src/rust_masm_tests/wit_sdk.rs @@ -1,8 +1,12 @@ -use std::{collections::BTreeMap, path::PathBuf, str::FromStr}; +use std::{ + collections::{BTreeMap, HashSet}, + path::PathBuf, + str::FromStr, +}; use expect_test::expect_file; use miden_core::crypto::hash::RpoDigest; -use midenc_frontend_wasm::{ImportMetadata, WasmTranslationConfig}; +use midenc_frontend_wasm::WasmTranslationConfig; use midenc_hir::{FunctionExportName, InterfaceFunctionIdent, InterfaceIdent, Symbol}; use crate::CompilerTest; @@ -35,34 +39,11 @@ fn sdk_basic_wallet() { interface: interface_account, function: Symbol::intern("remove-asset"), }; - let import_metadata: BTreeMap = [ - ( - create_note_ident, - ImportMetadata { - digest: RpoDigest::default(), - }, - ), - ( - remove_asset_ident, - ImportMetadata { - digest: RpoDigest::default(), - }, - ), - ( - add_asset_ident, - ImportMetadata { - digest: RpoDigest::default(), - }, - ), - ] - .into_iter() - .collect(); + 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 { - import_metadata: import_metadata.clone(), - ..Default::default() - }; + let config = WasmTranslationConfig::default(); let mut test = CompilerTest::rust_source_cargo_component("../rust-apps-wasm/wit-sdk/basic-wallet", config); let artifact_name = test.artifact_name(); @@ -74,7 +55,7 @@ fn sdk_basic_wallet() { )]); let ir = test.hir().unwrap_component(); for import in ir.imports().values() { - assert!(import_metadata.contains_key(&import.unwrap_canon_abi_import().interface_function)); + assert!(expected_imports.contains(&import.unwrap_canon_abi_import().interface_function)); } for name in expected_exports { assert!(ir.exports().contains_key(&name)); @@ -87,60 +68,32 @@ fn sdk_basic_wallet_p2id_note() { let basic_wallet = InterfaceIdent::from_full_ident("miden:basic-wallet/basic-wallet@1.0.0"); let core_types = InterfaceIdent::from_full_ident("miden:base/core-types@1.0.0"); let note = InterfaceIdent::from_full_ident("miden:base/note@1.0.0"); - let import_metadata: BTreeMap = [ - ( - InterfaceFunctionIdent { - interface: interface_account, - function: Symbol::intern("get-id"), - }, - ImportMetadata { - digest: RpoDigest::default(), - }, - ), - ( - InterfaceFunctionIdent { - interface: core_types, - function: Symbol::intern("account-id-from-felt"), - }, - ImportMetadata { - digest: RpoDigest::default(), - }, - ), - ( - InterfaceFunctionIdent { - interface: basic_wallet, - function: Symbol::intern("receive-asset"), - }, - ImportMetadata { - digest: RpoDigest::default(), - }, - ), - ( - InterfaceFunctionIdent { - interface: note, - function: Symbol::intern("get-assets"), - }, - ImportMetadata { - digest: RpoDigest::default(), - }, - ), - ( - InterfaceFunctionIdent { - interface: note, - function: Symbol::intern("get-inputs"), - }, - ImportMetadata { - digest: RpoDigest::default(), - }, - ), + let expected_imports: HashSet = [ + InterfaceFunctionIdent { + interface: interface_account, + function: Symbol::intern("get-id"), + }, + InterfaceFunctionIdent { + interface: core_types, + function: Symbol::intern("account-id-from-felt"), + }, + InterfaceFunctionIdent { + interface: basic_wallet, + function: Symbol::intern("receive-asset"), + }, + InterfaceFunctionIdent { + interface: note, + function: Symbol::intern("get-assets"), + }, + InterfaceFunctionIdent { + interface: note, + function: Symbol::intern("get-inputs"), + }, ] .into_iter() .collect(); let expected_exports: Vec = vec![Symbol::intern("note-script").into()]; - let config = WasmTranslationConfig { - import_metadata: import_metadata.clone(), - ..Default::default() - }; + let config = WasmTranslationConfig::default(); let mut test = CompilerTest::rust_source_cargo_component("../rust-apps-wasm/wit-sdk/p2id-note", config); let artifact_name = test.artifact_name(); @@ -153,7 +106,7 @@ fn sdk_basic_wallet_p2id_note() { let ir = test.hir().unwrap_component(); for import in ir.imports().values() { let canon_abi_import = import.unwrap_canon_abi_import(); - assert!(import_metadata.contains_key(&canon_abi_import.interface_function)); + assert!(expected_imports.contains(&canon_abi_import.interface_function)); if ["get-assets", "get-inputs"] .contains(&canon_abi_import.interface_function.function.as_str()) { diff --git a/tests/rust-apps-wasm/rust-sdk/basic-wallet/Cargo.toml b/tests/rust-apps-wasm/rust-sdk/basic-wallet/Cargo.toml index 56f8d6ab..3f4e9e99 100644 --- a/tests/rust-apps-wasm/rust-sdk/basic-wallet/Cargo.toml +++ b/tests/rust-apps-wasm/rust-sdk/basic-wallet/Cargo.toml @@ -40,5 +40,5 @@ debug = true package = "miden:basic-wallet" [package.metadata.component.target.dependencies] -"miden:base" = { path = "wit-sdk/miden.wit" } -"miden:core-import" = { path = "wit-sdk/miden-core-import.wit" } \ No newline at end of file +"miden:base" = { path = "../wit-sdk/miden.wit" } +"miden:core-import" = { path = "../wit-sdk/miden-core-import.wit" } \ No newline at end of file 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 012d5d8a..5f865ea7 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 @@ -22,6 +22,26 @@ pub mod miden { #[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 eq(a: f32, b: f32) -> bool { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link( + wasm_import_module = "miden:core-import/intrinsics-felt@1.0.0" + )] + extern "C" { + #[link_name = "eq"] + fn wit_import(_: f32, _: f32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: f32, _: f32) -> i32 { + unreachable!() + } + let ret = wit_import(_rt::as_f32(&a), _rt::as_f32(&b)); + _rt::bool_lift(ret as u8) + } + } } #[allow(dead_code, clippy::all)] pub mod stdlib_crypto_hashes_blake3 { @@ -34,6 +54,67 @@ pub mod miden { #[used] #[doc(hidden)] static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; + #[allow(unused_unsafe, clippy::all)] + /// Get the id of the currently executing account + pub fn get_id() -> f32 { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "miden:core-import/account@1.0.0")] + extern "C" { + #[link_name = "get-id"] + fn wit_import() -> f32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import() -> f32 { + unreachable!() + } + let ret = wit_import(); + ret + } + } + } + #[allow(dead_code, clippy::all)] + pub mod note { + #[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)] + /// Get the inputs of the currently executed note + pub fn get_inputs(ptr: i32) -> i32 { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "miden:core-import/note@1.0.0")] + extern "C" { + #[link_name = "get-inputs"] + fn wit_import(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import(_rt::as_i32(&ptr)); + ret + } + } + #[allow(unused_unsafe, clippy::all)] + /// Get the assets of the currently executing note + pub fn get_assets(ptr: i32) -> i32 { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "miden:core-import/note@1.0.0")] + extern "C" { + #[link_name = "get-assets"] + fn wit_import(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import(_rt::as_i32(&ptr)); + ret + } + } } #[allow(dead_code, clippy::all)] pub mod tx { @@ -218,10 +299,6 @@ pub mod exports { } } mod _rt { - #[cfg(target_arch = "wasm32")] - pub fn run_ctors_once() { - wit_bindgen_rt::run_ctors_once(); - } pub fn as_f32(t: T) -> f32 { t.as_f32() } @@ -239,6 +316,80 @@ mod _rt { self as f32 } } + pub unsafe fn bool_lift(val: u8) -> bool { + if cfg!(debug_assertions) { + match val { + 0 => false, + 1 => true, + _ => panic!("invalid bool discriminant"), + } + } else { + val != 0 + } + } + pub fn as_i32(t: T) -> i32 { + t.as_i32() + } + pub trait AsI32 { + fn as_i32(self) -> i32; + } + impl<'a, T: Copy + AsI32> AsI32 for &'a T { + fn as_i32(self) -> i32 { + (*self).as_i32() + } + } + impl AsI32 for i32 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for u32 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for i16 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for u16 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for i8 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for u8 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for char { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for usize { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + #[cfg(target_arch = "wasm32")] + pub fn run_ctors_once() { + wit_bindgen_rt::run_ctors_once(); + } pub use alloc_crate::vec::Vec; pub unsafe fn cabi_dealloc(ptr: *mut u8, size: usize, align: usize) { if size == 0 { @@ -284,9 +435,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; 1499] = *b"\ -\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xd2\x0a\x01A\x02\x01\ -A\x13\x01B\x1f\x01r\x01\x05innerv\x04\0\x04felt\x03\0\0\x01o\x04\x01\x01\x01\x01\ +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\ \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\ @@ -297,27 +448,30 @@ 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\x02\x01@\x02\x01av\x01\ -bv\0v\x04\0\x03add\x01\0\x03\x01'miden:core-import/intrinsics-felt@1.0.0\x05\x02\ -\x01B\x02\x01@\x09\x02a0z\x02a1z\x02a2z\x02a3z\x02a4z\x02a5z\x02a6z\x02a7z\x0are\ -sult-ptrz\x01\0\x04\0\x0fhash-one-to-one\x01\0\x03\x013miden:core-import/stdlib-\ -crypto-hashes-blake3@1.0.0\x05\x03\x01B\x03\x01@\x05\x06asset0v\x06asset1v\x06as\ -set2v\x06asset3v\x0aresult-ptrz\x01\0\x04\0\x09add-asset\x01\0\x04\0\x0cremove-a\ -sset\x01\0\x03\x01\x1fmiden:core-import/account@1.0.0\x05\x04\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\x05\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\x06\x04\0\x0acore-asset\x03\0\0\x02\x03\x02\x01\x07\x04\0\x03tag\x03\0\x02\ -\x02\x03\x02\x01\x08\x04\0\x09recipient\x03\0\x04\x02\x03\x02\x01\x09\x04\0\x09n\ -ote-type\x03\0\x06\x02\x03\x02\x01\x0a\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\x05\ -input\x0d\0\x0d\x04\0\x0btest-stdlib\x01\x0e\x04\x01%miden:basic-wallet/basic-wa\ -llet@1.0.0\x05\x0b\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\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"; #[inline(never)] #[doc(hidden)] pub fn __link_custom_section_describing_imports() { diff --git a/tests/rust-apps-wasm/rust-sdk/p2id-note/.gitignore b/tests/rust-apps-wasm/rust-sdk/p2id-note/.gitignore new file mode 100644 index 00000000..c41cc9e3 --- /dev/null +++ b/tests/rust-apps-wasm/rust-sdk/p2id-note/.gitignore @@ -0,0 +1 @@ +/target \ No newline at end of file diff --git a/tests/rust-apps-wasm/rust-sdk/p2id-note/Cargo.lock b/tests/rust-apps-wasm/rust-sdk/p2id-note/Cargo.lock new file mode 100644 index 00000000..3dde7e37 --- /dev/null +++ b/tests/rust-apps-wasm/rust-sdk/p2id-note/Cargo.lock @@ -0,0 +1,41 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "miden" +version = "0.0.7" +dependencies = [ + "miden-base-sys", + "miden-sdk-alloc", + "miden-stdlib-sys", +] + +[[package]] +name = "miden-base-sys" +version = "0.0.7" +dependencies = [ + "miden-stdlib-sys", +] + +[[package]] +name = "miden-sdk-alloc" +version = "0.0.7" + +[[package]] +name = "miden-stdlib-sys" +version = "0.0.7" + +[[package]] +name = "p2id" +version = "0.1.0" +dependencies = [ + "miden", + "wit-bindgen-rt", +] + +[[package]] +name = "wit-bindgen-rt" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7a37bd9274cb2d4754b915d624447ec0dce9105d174361841c0826efc79ceb9" diff --git a/tests/rust-apps-wasm/rust-sdk/p2id-note/Cargo.toml b/tests/rust-apps-wasm/rust-sdk/p2id-note/Cargo.toml new file mode 100644 index 00000000..3a021204 --- /dev/null +++ b/tests/rust-apps-wasm/rust-sdk/p2id-note/Cargo.toml @@ -0,0 +1,45 @@ +[package] +name = "p2id" +version = "0.1.0" +edition = "2021" + +[lib] +# Build this crate as a self-contained, C-style dynamic library +# This is required to emit the proper Wasm module type +crate-type = ["cdylib"] + +[dependencies] +# Miden SDK consists of a stdlib (intrinsic functions for VM ops, stdlib functions and types) +# and transaction kernel API for the Miden rollup +miden = { path = "../../../../sdk/sdk" } +wit-bindgen-rt = "0.28" + + +[profile.release] +# optimize the output for size +opt-level = "z" +# Explicitly disable panic infrastructure on Wasm, as +# there is no proper support for them anyway, and it +# ensures that panics do not pull in a bunch of standard +# library code unintentionally +panic = "abort" + +[profile.dev] +# Explicitly disable panic infrastructure on Wasm, as +# there is no proper support for them anyway, and it +# ensures that panics do not pull in a bunch of standard +# library code unintentionally +panic = "abort" +opt-level = 1 +debug-assertions = false +overflow-checks = false +debug = true + +# TODO: switch to miden table +[package.metadata.component] +package = "miden:p2id" + +[package.metadata.component.target.dependencies] +"miden:base" = { path = "../wit-sdk/miden.wit" } +"miden:core-import" = { path = "../wit-sdk/miden-core-import.wit" } +"miden:basic-wallet" = { path = "../basic-wallet/wit/basic-wallet.wit" } \ 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 new file mode 100644 index 00000000..df2be688 --- /dev/null +++ b/tests/rust-apps-wasm/rust-sdk/p2id-note/src/bindings.rs @@ -0,0 +1,489 @@ +#[allow(dead_code)] +pub mod miden { + #[allow(dead_code)] + pub mod base { + #[allow(dead_code, clippy::all)] + pub mod core_types { + #[used] + #[doc(hidden)] + static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; + } + } + #[allow(dead_code)] + pub mod basic_wallet { + #[allow(dead_code, clippy::all)] + pub mod basic_wallet { + #[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 receive_asset(core_asset: miden::CoreAsset) { + unsafe { + let miden::CoreAsset { inner: inner0 } = core_asset; + 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; + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "miden:basic-wallet/basic-wallet@1.0.0")] + extern "C" { + #[link_name = "receive-asset"] + fn wit_import(_: f32, _: f32, _: f32, _: f32); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: f32, _: f32, _: f32, _: f32) { + unreachable!() + } + wit_import( + _rt::as_f32(inner3), + _rt::as_f32(inner4), + _rt::as_f32(inner5), + _rt::as_f32(inner6), + ); + } + } + #[allow(unused_unsafe, clippy::all)] + pub fn send_asset( + core_asset: miden::CoreAsset, + tag: miden::Tag, + note_type: miden::NoteType, + recipient: miden::Recipient, + ) { + unsafe { + let miden::CoreAsset { inner: inner0 } = core_asset; + 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 miden::Tag { inner: inner7 } = tag; + let miden::Felt { inner: inner8 } = inner7; + let miden::NoteType { inner: inner9 } = note_type; + let miden::Felt { inner: inner10 } = inner9; + let miden::Recipient { inner: inner11 } = recipient; + let miden::Word { inner: inner12 } = inner11; + let (t13_0, t13_1, t13_2, t13_3) = inner12; + let miden::Felt { inner: inner14 } = t13_0; + let miden::Felt { inner: inner15 } = t13_1; + let miden::Felt { inner: inner16 } = t13_2; + let miden::Felt { inner: inner17 } = t13_3; + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "miden:basic-wallet/basic-wallet@1.0.0")] + extern "C" { + #[link_name = "send-asset"] + fn wit_import( + _: f32, + _: f32, + _: f32, + _: f32, + _: f32, + _: f32, + _: f32, + _: f32, + _: f32, + _: f32, + ); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import( + _: f32, + _: f32, + _: f32, + _: f32, + _: f32, + _: f32, + _: f32, + _: f32, + _: f32, + _: f32, + ) { + unreachable!() + } + wit_import( + _rt::as_f32(inner3), + _rt::as_f32(inner4), + _rt::as_f32(inner5), + _rt::as_f32(inner6), + _rt::as_f32(inner8), + _rt::as_f32(inner10), + _rt::as_f32(inner14), + _rt::as_f32(inner15), + _rt::as_f32(inner16), + _rt::as_f32(inner17), + ); + } + } + #[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")] + extern "C" { + #[link_name = "test-felt-intrinsics"] + fn wit_import(_: f32, _: f32) -> f32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: f32, _: f32) -> f32 { + unreachable!() + } + let ret = wit_import(_rt::as_f32(inner0), _rt::as_f32(inner1)); + miden::Felt { inner: ret } + } + } + #[allow(unused_unsafe, clippy::all)] + pub fn test_stdlib(input: &[u8]) -> _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/basic-wallet@1.0.0")] + extern "C" { + #[link_name = "test-stdlib"] + 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)] + pub mod core_import { + #[allow(dead_code, clippy::all)] + pub mod intrinsics_mem { + #[used] + #[doc(hidden)] + static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; + } + #[allow(dead_code, clippy::all)] + pub mod intrinsics_felt { + #[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 eq(a: f32, b: f32) -> bool { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link( + wasm_import_module = "miden:core-import/intrinsics-felt@1.0.0" + )] + extern "C" { + #[link_name = "eq"] + fn wit_import(_: f32, _: f32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: f32, _: f32) -> i32 { + unreachable!() + } + let ret = wit_import(_rt::as_f32(&a), _rt::as_f32(&b)); + _rt::bool_lift(ret as u8) + } + } + } + #[allow(dead_code, clippy::all)] + pub mod stdlib_crypto_hashes_blake3 { + #[used] + #[doc(hidden)] + static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; + } + #[allow(dead_code, clippy::all)] + pub mod account { + #[used] + #[doc(hidden)] + static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; + #[allow(unused_unsafe, clippy::all)] + /// Get the id of the currently executing account + pub fn get_id() -> f32 { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "miden:core-import/account@1.0.0")] + extern "C" { + #[link_name = "get-id"] + fn wit_import() -> f32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import() -> f32 { + unreachable!() + } + let ret = wit_import(); + ret + } + } + } + #[allow(dead_code, clippy::all)] + pub mod note { + #[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)] + /// Get the inputs of the currently executed note + pub fn get_inputs(ptr: i32) -> i32 { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "miden:core-import/note@1.0.0")] + extern "C" { + #[link_name = "get-inputs"] + fn wit_import(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import(_rt::as_i32(&ptr)); + ret + } + } + #[allow(unused_unsafe, clippy::all)] + /// Get the assets of the currently executing note + pub fn get_assets(ptr: i32) -> i32 { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "miden:core-import/note@1.0.0")] + extern "C" { + #[link_name = "get-assets"] + fn wit_import(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import(_rt::as_i32(&ptr)); + ret + } + } + } + #[allow(dead_code, clippy::all)] + pub mod tx { + #[used] + #[doc(hidden)] + static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; + } + } +} +#[allow(dead_code)] +pub mod exports { + #[allow(dead_code)] + pub mod miden { + #[allow(dead_code)] + pub mod base { + #[allow(dead_code, clippy::all)] + pub mod note_script { + #[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_note_script_cabi() { + #[cfg(target_arch = "wasm32")] _rt::run_ctors_once(); + T::note_script(); + } + pub trait Guest { + fn note_script(); + } + #[doc(hidden)] + macro_rules! __export_miden_base_note_script_1_0_0_cabi { + ($ty:ident with_types_in $($path_to_types:tt)*) => { + const _ : () = { #[export_name = + "miden:base/note-script@1.0.0#note-script"] unsafe extern "C" fn + export_note_script() { $($path_to_types)*:: + _export_note_script_cabi::<$ty > () } }; + }; + } + #[doc(hidden)] + pub(crate) use __export_miden_base_note_script_1_0_0_cabi; + } + } + } +} +mod _rt { + pub fn as_f32(t: T) -> f32 { + t.as_f32() + } + pub trait AsF32 { + fn as_f32(self) -> f32; + } + impl<'a, T: Copy + AsF32> AsF32 for &'a T { + fn as_f32(self) -> f32 { + (*self).as_f32() + } + } + impl AsF32 for f32 { + #[inline] + fn as_f32(self) -> f32 { + self as f32 + } + } + pub use alloc_crate::vec::Vec; + pub unsafe fn bool_lift(val: u8) -> bool { + if cfg!(debug_assertions) { + match val { + 0 => false, + 1 => true, + _ => panic!("invalid bool discriminant"), + } + } else { + val != 0 + } + } + pub fn as_i32(t: T) -> i32 { + t.as_i32() + } + pub trait AsI32 { + fn as_i32(self) -> i32; + } + impl<'a, T: Copy + AsI32> AsI32 for &'a T { + fn as_i32(self) -> i32 { + (*self).as_i32() + } + } + impl AsI32 for i32 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for u32 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for i16 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for u16 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for i8 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for u8 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for char { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for usize { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + #[cfg(target_arch = "wasm32")] + pub fn run_ctors_once() { + wit_bindgen_rt::run_ctors_once(); + } + extern crate alloc as alloc_crate; +} +/// Generates `#[no_mangle]` functions to export the specified type as the +/// root implementation of all generated traits. +/// +/// For more information see the documentation of `wit_bindgen::generate!`. +/// +/// ```rust +/// # macro_rules! export{ ($($t:tt)*) => (); } +/// # trait Guest {} +/// struct MyType; +/// +/// impl Guest for MyType { +/// // ... +/// } +/// +/// export!(MyType); +/// ``` +#[allow(unused_macros)] +#[doc(hidden)] +macro_rules! __export_p2id_world_impl { + ($ty:ident) => { + self::export!($ty with_types_in self); + }; + ($ty:ident with_types_in $($path_to_types_root:tt)*) => { + $($path_to_types_root)*:: + exports::miden::base::note_script::__export_miden_base_note_script_1_0_0_cabi!($ty + with_types_in $($path_to_types_root)*:: exports::miden::base::note_script); + }; +} +#[doc(inline)] +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\ +\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\ +\x0b\x01r\x01\x05inner\x01\x04\0\x05nonce\x03\0\x0d\x01r\x01\x05inner\x04\x04\0\x0c\ +account-hash\x03\0\x0f\x01r\x01\x05inner\x04\x04\0\x0ablock-hash\x03\0\x11\x01r\x01\ +\x05inner\x04\x04\0\x0dstorage-value\x03\0\x13\x01r\x01\x05inner\x04\x04\0\x0cst\ +orage-root\x03\0\x15\x01r\x01\x05inner\x04\x04\0\x11account-code-root\x03\0\x17\x01\ +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\ +\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"; +#[inline(never)] +#[doc(hidden)] +pub fn __link_custom_section_describing_imports() { + wit_bindgen_rt::maybe_link_cabi_realloc(); +} 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 new file mode 100644 index 00000000..50a63137 --- /dev/null +++ b/tests/rust-apps-wasm/rust-sdk/p2id-note/src/lib.rs @@ -0,0 +1,41 @@ +// Do not link against libstd (i.e. anything defined in `std::`) +#![no_std] + +// However, we could still use some standard library types while +// remaining no-std compatible, if we uncommented the following lines: +// +// extern crate alloc; +// use alloc::vec::Vec; + +// Global allocator to use heap memory in no-std environment +#[global_allocator] +static ALLOC: miden::BumpAlloc = miden::BumpAlloc::new(); + +// Required for no-std crates +#[panic_handler] +fn my_panic(_info: &core::panic::PanicInfo) -> ! { + loop {} +} + +bindings::export!(MyNote with_types_in bindings); + +mod bindings; + +use bindings::{ + exports::miden::base::note_script::Guest, miden::basic_wallet::basic_wallet::receive_asset, +}; + +struct MyNote; + +impl Guest for MyNote { + fn note_script() { + let inputs = miden::note::get_inputs(); + let target_account_id_felt = inputs[0]; + let account_id = miden::account::get_id(); + 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 new file mode 100644 index 00000000..53962aeb --- /dev/null +++ b/tests/rust-apps-wasm/rust-sdk/p2id-note/wit/p2id.wit @@ -0,0 +1,8 @@ +package miden:p2id@1.0.0; + +world p2id-world { + include miden:core-import/all@1.0.0; + + import miden:basic-wallet/basic-wallet@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/basic-wallet/wit-sdk/miden-core-import.wit b/tests/rust-apps-wasm/rust-sdk/wit-sdk/miden-core-import.wit similarity index 77% rename from tests/rust-apps-wasm/rust-sdk/basic-wallet/wit-sdk/miden-core-import.wit rename to tests/rust-apps-wasm/rust-sdk/wit-sdk/miden-core-import.wit index c64dac04..dc58ce81 100644 --- a/tests/rust-apps-wasm/rust-sdk/basic-wallet/wit-sdk/miden-core-import.wit +++ b/tests/rust-apps-wasm/rust-sdk/wit-sdk/miden-core-import.wit @@ -1,5 +1,8 @@ package miden:core-import@1.0.0; +// The function signatures should be kept in sync with the signatures in the +// Rust SDK `extern` functions (see `/sdk`); + interface intrinsics-mem { heap-base: func() -> s32; @@ -8,6 +11,7 @@ interface intrinsics-mem { interface intrinsics-felt { add: func(a: f32, b: f32) -> f32; + eq: func(a: f32, b: f32) -> bool; } interface stdlib-crypto-hashes-blake3 { @@ -25,6 +29,17 @@ interface account { add-asset: func(asset0: f32, asset1: f32, asset2: f32, asset3: f32, result-ptr: s32); /// Remove the specified asset from the vault remove-asset: func(asset0: f32, asset1: f32, asset2: f32, asset3: f32, result-ptr: s32); + /// Get the id of the currently executing account + get-id: func() -> f32; +} + + +interface note { + + /// Get the inputs of the currently executed note + get-inputs: func(ptr: s32) -> s32; + /// Get the assets of the currently executing note + get-assets: func(ptr: s32) -> s32; } interface tx { @@ -54,6 +69,7 @@ world all { import intrinsics-felt; import stdlib-crypto-hashes-blake3; import account; + import note; import tx; } \ No newline at end of file diff --git a/tests/rust-apps-wasm/rust-sdk/basic-wallet/wit-sdk/miden.wit b/tests/rust-apps-wasm/rust-sdk/wit-sdk/miden.wit similarity index 96% rename from tests/rust-apps-wasm/rust-sdk/basic-wallet/wit-sdk/miden.wit rename to tests/rust-apps-wasm/rust-sdk/wit-sdk/miden.wit index ed6d4192..ebcf6569 100644 --- a/tests/rust-apps-wasm/rust-sdk/basic-wallet/wit-sdk/miden.wit +++ b/tests/rust-apps-wasm/rust-sdk/wit-sdk/miden.wit @@ -138,6 +138,13 @@ interface core-types { } + +/// Note script interface that is expected to be implemented by the note script. +interface note-script { + note-script: func(); +} + world base-world { export core-types; + export note-script; } diff --git a/tools/cargo-miden/src/lib.rs b/tools/cargo-miden/src/lib.rs index 44c7290d..51f2f86c 100644 --- a/tools/cargo-miden/src/lib.rs +++ b/tools/cargo-miden/src/lib.rs @@ -240,6 +240,7 @@ where ) .await })?; + dbg!(&wasm_outputs); if wasm_outputs.is_empty() { // crates that don't have a WIT component are ignored by the // `cargo-component` run_cargo_command and return no outputs. @@ -252,7 +253,6 @@ where &env_vars, )?; } - // dbg!(&wasm_outputs); match build_output_type { OutputType::Wasm => wasm_outputs, OutputType::Masm => {