Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/alloc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ fn main() {

// Link for dependents of this crate
println!("cargo:rustc-link-search=native={}", out_dir.display());
println!("cargo:rustc-link-lib=static=miden_alloc_intrinsics");
println!("cargo:rustc-link-lib=static:+whole-archive=miden_alloc_intrinsics");
}
2 changes: 2 additions & 0 deletions sdk/alloc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![no_std]
#![cfg_attr(target_family = "wasm", feature(linkage))]
#![deny(warnings)]

extern crate alloc;
Expand Down Expand Up @@ -128,6 +129,7 @@ unsafe impl GlobalAlloc for BumpAlloc {

#[cfg(target_family = "wasm")]
unsafe extern "C" {
#[linkage = "extern_weak"]
#[link_name = "intrinsics::mem::heap_base"]
fn heap_base() -> *mut u8;
}
4 changes: 4 additions & 0 deletions sdk/alloc/stubs/heap_base.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#![no_std]
#![feature(optimize_attribute)]

// Provide a local definition for the allocator to link against, and export it
// under the MASM intrinsic path so the frontend recognizes and lowers it.

/// Unreachable stub for `intrinsics::mem::heap_base`.
#[unsafe(export_name = "intrinsics::mem::heap_base")]
#[optimize(none)]
#[inline(never)]
pub extern "C" fn __intrinsics_mem_heap_base_stub() -> *mut u8 {
unsafe { core::hint::unreachable_unchecked() }
}
2 changes: 1 addition & 1 deletion sdk/base-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,5 @@ fn main() {
// Emit link directives for dependents
println!("cargo:rustc-link-search=native={}", out_dir.display());
// `lib` prefix is adde by the linker automatically when it searches for the file
println!("cargo:rustc-link-lib=miden_base_sys_stubs");
println!("cargo:rustc-link-lib=static:+whole-archive=miden_base_sys_stubs");
}
17 changes: 17 additions & 0 deletions sdk/base-sys/src/bindings/active_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@ use super::types::{AccountId, Asset, RawAccountId};

#[allow(improper_ctypes)]
unsafe extern "C" {
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_account::get_id"]
fn extern_active_account_get_id(ptr: *mut RawAccountId);
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_account::get_nonce"]
fn extern_active_account_get_nonce() -> Felt;
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_account::get_initial_commitment"]
fn extern_active_account_get_initial_commitment(ptr: *mut Word);
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_account::compute_commitment"]
fn extern_active_account_compute_commitment(ptr: *mut Word);
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_account::get_code_commitment"]
fn extern_active_account_get_code_commitment(ptr: *mut Word);
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_account::get_initial_storage_commitment"]
fn extern_active_account_get_initial_storage_commitment(ptr: *mut Word);
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_account::compute_storage_commitment"]
fn extern_active_account_compute_storage_commitment(ptr: *mut Word);
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_account::get_asset"]
fn extern_active_account_get_asset(
asset_key_0: Felt,
Expand All @@ -26,6 +34,7 @@ unsafe extern "C" {
asset_key_3: Felt,
ptr: *mut Word,
);
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_account::get_initial_asset"]
fn extern_active_account_get_initial_asset(
asset_key_0: Felt,
Expand All @@ -34,28 +43,36 @@ unsafe extern "C" {
asset_key_3: Felt,
ptr: *mut Word,
);
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_account::get_balance"]
fn extern_active_account_get_balance(faucet_id_suffix: Felt, faucet_id_prefix: Felt) -> Felt;
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_account::get_initial_balance"]
fn extern_active_account_get_initial_balance(
faucet_id_suffix: Felt,
faucet_id_prefix: Felt,
) -> Felt;
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_account::has_non_fungible_asset"]
fn extern_active_account_has_non_fungible_asset(
asset_0: Felt,
asset_1: Felt,
asset_2: Felt,
asset_3: Felt,
) -> Felt;
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_account::get_initial_vault_root"]
fn extern_active_account_get_initial_vault_root(ptr: *mut Word);
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_account::get_vault_root"]
fn extern_active_account_get_vault_root(ptr: *mut Word);
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_account::get_num_procedures"]
fn extern_active_account_get_num_procedures() -> Felt;
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_account::get_procedure_root"]
fn extern_active_account_get_procedure_root(index: Felt, ptr: *mut Word);
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_account::has_procedure"]
fn extern_active_account_has_procedure(
proc_root_0: Felt,
Expand Down
7 changes: 7 additions & 0 deletions sdk/base-sys/src/bindings/active_note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,25 @@ use super::{AccountId, Asset, NoteMetadata, RawAccountId, Recipient};
#[allow(improper_ctypes)]
unsafe extern "C" {
// NOTE: In protocol v0.14, note "inputs" are exposed via `active_note::get_storage`.
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_note::get_storage"]
fn extern_note_get_storage(ptr: *mut Felt) -> usize;
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_note::get_assets"]
fn extern_note_get_assets(ptr: *mut Felt) -> usize;
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_note::get_sender"]
fn extern_note_get_sender(ptr: *mut RawAccountId);
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_note::get_recipient"]
fn extern_note_get_recipient(ptr: *mut Recipient);
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_note::get_script_root"]
fn extern_note_get_script_root(ptr: *mut Word);
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_note::get_serial_number"]
fn extern_note_get_serial_number(ptr: *mut Word);
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_note::get_metadata"]
fn extern_note_get_metadata(ptr: *mut NoteMetadata);
}
Expand Down
3 changes: 2 additions & 1 deletion sdk/base-sys/src/bindings/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ use super::types::{AccountId, Asset};

#[allow(improper_ctypes)]
unsafe extern "C" {
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::asset::create_fungible_asset"]
pub fn extern_asset_create_fungible_asset(
faucet_id_suffix: Felt,
faucet_id_prefix: Felt,
amount: Felt,
ptr: *mut Asset,
);

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::asset::create_non_fungible_asset"]
pub fn extern_asset_create_non_fungible_asset(
faucet_id_suffix: Felt,
Expand Down
7 changes: 4 additions & 3 deletions sdk/base-sys/src/bindings/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use super::types::Asset;

#[allow(improper_ctypes)]
unsafe extern "C" {
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::faucet::create_fungible_asset"]
pub fn extern_faucet_create_fungible_asset(amount: Felt, ptr: *mut Asset);

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::faucet::create_non_fungible_asset"]
pub fn extern_faucet_create_non_fungible_asset(
data_hash_0: Felt,
Expand All @@ -15,7 +16,7 @@ unsafe extern "C" {
data_hash_3: Felt,
ptr: *mut Asset,
);

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::faucet::mint"]
pub fn extern_faucet_mint(
asset_key_0: Felt,
Expand All @@ -28,7 +29,7 @@ unsafe extern "C" {
asset_value_3: Felt,
ptr: *mut Word,
);

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::faucet::burn"]
pub fn extern_faucet_burn(
asset_key_0: Felt,
Expand Down
15 changes: 8 additions & 7 deletions sdk/base-sys/src/bindings/input_note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@ use super::types::{AccountId, Asset, NoteIdx, NoteMetadata, RawAccountId, Recipi

#[allow(improper_ctypes)]
unsafe extern "C" {
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::input_note::get_assets_info"]
fn extern_input_note_get_assets_info(note_index: Felt, ptr: *mut (Word, Felt));

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::input_note::get_assets"]
fn extern_input_note_get_assets(dest_ptr: *mut Felt, note_index: Felt) -> usize;

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::input_note::get_recipient"]
fn extern_input_note_get_recipient(note_index: Felt, ptr: *mut Recipient);

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::input_note::get_metadata"]
fn extern_input_note_get_metadata(note_index: Felt, ptr: *mut NoteMetadata);

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::input_note::get_sender"]
fn extern_input_note_get_sender(note_index: Felt, ptr: *mut RawAccountId);

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::input_note::get_storage_info"]
fn extern_input_note_get_storage_info(note_index: Felt, ptr: *mut (Word, Felt));

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::input_note::get_script_root"]
fn extern_input_note_get_script_root(note_index: Felt, ptr: *mut Word);

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::input_note::get_serial_number"]
fn extern_input_note_get_serial_number(note_index: Felt, ptr: *mut Word);
}
Expand Down
5 changes: 5 additions & 0 deletions sdk/base-sys/src/bindings/native_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::types::Asset;

#[allow(improper_ctypes)]
unsafe extern "C" {
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::native_account::add_asset"]
fn extern_native_account_add_asset(
asset_key_0: Felt,
Expand All @@ -16,6 +17,7 @@ unsafe extern "C" {
asset_value_3: Felt,
ptr: *mut Word,
);
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::native_account::remove_asset"]
fn extern_native_account_remove_asset(
asset_key_0: Felt,
Expand All @@ -28,10 +30,13 @@ unsafe extern "C" {
asset_value_3: Felt,
ptr: *mut Word,
);
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::native_account::incr_nonce"]
fn extern_native_account_incr_nonce() -> Felt;
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::native_account::compute_delta_commitment"]
fn extern_native_account_compute_delta_commitment(ptr: *mut Word);
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::native_account::was_procedure_called"]
fn extern_native_account_was_procedure_called(
proc_root_0: Felt,
Expand Down
1 change: 1 addition & 0 deletions sdk/base-sys/src/bindings/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const MAX_NOTE_STORAGE_ITEMS: usize = 1024;

#[allow(improper_ctypes)]
unsafe extern "C" {
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::note::build_recipient"]
fn extern_note_build_recipient(
storage_ptr: *mut Felt,
Expand Down
17 changes: 9 additions & 8 deletions sdk/base-sys/src/bindings/output_note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use super::types::{Asset, NoteIdx, NoteMetadata, NoteType, Recipient, Tag};

#[allow(improper_ctypes)]
unsafe extern "C" {
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::output_note::create"]
pub fn extern_output_note_create(
tag: Tag,
Expand All @@ -16,7 +17,7 @@ unsafe extern "C" {
recipient_f2: Felt,
recipient_f3: Felt,
) -> NoteIdx;

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::output_note::add_asset"]
pub fn extern_output_note_add_asset(
asset_key_f0: Felt,
Expand All @@ -29,19 +30,19 @@ unsafe extern "C" {
asset_value_f3: Felt,
note_idx: NoteIdx,
);

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::output_note::get_assets_info"]
pub fn extern_output_note_get_assets_info(note_index: Felt, ptr: *mut (Word, Felt));

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::output_note::get_assets"]
pub fn extern_output_note_get_assets(dest_ptr: *mut Felt, note_index: Felt) -> usize;

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::output_note::get_recipient"]
pub fn extern_output_note_get_recipient(note_index: Felt, ptr: *mut Recipient);

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::output_note::get_metadata"]
pub fn extern_output_note_get_metadata(note_index: Felt, ptr: *mut NoteMetadata);

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::output_note::set_attachment"]
pub fn extern_output_note_set_attachment(
note_idx: NoteIdx,
Expand All @@ -52,7 +53,7 @@ unsafe extern "C" {
attachment_f2: Felt,
attachment_f3: Felt,
);

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::output_note::set_word_attachment"]
pub fn extern_output_note_set_word_attachment(
note_idx: NoteIdx,
Expand All @@ -62,7 +63,7 @@ unsafe extern "C" {
attachment_f2: Felt,
attachment_f3: Felt,
);

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::output_note::set_array_attachment"]
pub fn extern_output_note_set_array_attachment(
note_idx: NoteIdx,
Expand Down
11 changes: 6 additions & 5 deletions sdk/base-sys/src/bindings/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ use super::StorageSlotId;
unsafe extern "C" {
// The public SDK models storage slots as `(prefix, suffix)`, but the host ABI expects the slot
// coordinates in storage order: `(suffix, prefix)`.
#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_account::get_item"]
pub fn extern_get_storage_item(index_suffix: Felt, index_prefix: Felt, ptr: *mut Word);

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_account::get_initial_item"]
pub fn extern_get_initial_storage_item(index_suffix: Felt, index_prefix: Felt, ptr: *mut Word);

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::native_account::set_item"]
pub fn extern_set_storage_item(
index_suffix: Felt,
Expand All @@ -22,7 +23,7 @@ unsafe extern "C" {
v3: Felt,
ptr: *mut Word,
);

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_account::get_map_item"]
pub fn extern_get_storage_map_item(
index_suffix: Felt,
Expand All @@ -33,7 +34,7 @@ unsafe extern "C" {
k3: Felt,
ptr: *mut Word,
);

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::active_account::get_initial_map_item"]
pub fn extern_get_initial_storage_map_item(
index_suffix: Felt,
Expand All @@ -44,7 +45,7 @@ unsafe extern "C" {
k3: Felt,
ptr: *mut Word,
);

#[cfg_attr(target_family = "wasm", linkage = "extern_weak")]
#[link_name = "miden::protocol::native_account::set_map_item"]
pub fn extern_set_storage_map_item(
index_suffix: Felt,
Expand Down
Loading
Loading