Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide WIT interfaces for Rust Miden SDK in the user's Rust projects #343

Open
greenhat opened this issue Oct 15, 2024 · 0 comments
Open
Milestone

Comments

@greenhat
Copy link
Contributor

Discovered in #329

Why

To pass Miden SDK functions through the Wasm CM we need to define all low-level Miden SDK functions in a WIT interface that would be imported to the user's WIT world.
Here is how it is drafted:

package miden:core-import@1.0.0;
interface intrinsics-mem {
heap-base: func() -> s32;
}
interface intrinsics-felt {
add: func(a: f32, b: f32) -> f32;
}
interface stdlib-crypto-hashes-blake3 {
hash-one-to-one: func(a0: s32, a1: s32, a2: s32, a3: s32, a4: s32, a5: s32, a6: s32, a7: s32, result-ptr: s32);
}
interface account {
/// Add the specified asset to the vault. Panics under various conditions.
/// Returns the final asset in the account vault defined as follows: If asset is
/// a non-fungible asset, then returns the same as asset. If asset is a
/// fungible asset, then returns the total fungible asset in the account
/// vault after asset was added to it.
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);
}
interface tx {
/// Creates a new note.
/// asset is the asset to be included in the note.
/// tag is the tag to be included in the note.
/// recipient is the recipient of the note.
/// Returns the id of the created note.
create-note: func(
asset0: f32,
asset1: f32,
asset2: f32,
asset3: f32,
tag: f32,
note-type: f32,
recipient0: f32,
recipient1: f32,
recipient2: f32,
recipient3: f32,
) -> f32;
}
world all {
import intrinsics-mem;
import intrinsics-felt;
import stdlib-crypto-hashes-blake3;
import account;
import tx;
}

In the user's WIT file it should be imported in the world:

How

Option 1

Hard-code the Miden SDK WIT interfaces in cargo-miden and save as a WIT file in the new project template generation.

Option 2

Generate the WIT interface from the Miden SDK public API.

Keep in mind that all the functions in Miden SDK WIT interface should be skipped during the Rust binding generation (via wit-bindgen). See #341 for details. If we could cover that in Option 2 this might make it worth the effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant