Skip to content

Comments

Add Impact VM wasm-ffi example#27

Open
ecioppettini wants to merge 3 commits intomainfrom
impact-vm-static-linking-example
Open

Add Impact VM wasm-ffi example#27
ecioppettini wants to merge 3 commits intomainfrom
impact-vm-static-linking-example

Conversation

@ecioppettini
Copy link
Contributor

This example statically links an FFI version of https://docs.midnight.network/develop/how-midnight-works/impact

The library is included in object form, which is composed of wasm object files: https://github.com/WebAssembly/tool-conventions/blob/main/Linking.md , generated by the rust compiler for wasm32-unknown-unknown and with a crate-type of staticlib.

NOTE: there are some non-wasm objects included too, but I think those are unused and are just included in case you link to C libraries.

The library is also built with the rust standard library, which is kind of unfortunate since it makes linking harder. For example, I couldn't make the example work with #[no_std] neither (which is kind of annoying since then we are linking the std twice, although in different versions).

The other consequence of this is that the library is quite big. Normally there are ways of trimming this, but I'm not aware of any tool that works with wasm object files though. This doesn't necessarily matter for the final binary though, since unused symbols should be removed on link time, and the proof size/time shouldn't depend on unused code.

Future work

Dynamic loading

I think it would be interesting to have the same example but with a dynamically loaded lib. This would probably require a cdylib (a .wasm) instead of a staticlib. The problem is that then the memory can't be shared, so it can't be persisted easily in the utxo.

Instead I think the dynamic module has to be instantiated as some form of anonymous utxo? Or we need to serialize the state back and forth and have some sort of channel abstraction to send things back.

Bindgen?

Build the static library here

I'll add the code somewhere later I guess. The thing is that it can't be compiled without access to the private repos. In general the approach should work with opaque blobs though, but it would be nice to version control the bindings too.

@ecioppettini ecioppettini requested a review from SpaceManiac May 13, 2025 19:59
@ecioppettini ecioppettini self-assigned this May 13, 2025
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big binary file. Is there an alternative way to obtain it? Or at least instructions on how it's built?

@SpaceManiac SpaceManiac changed the title impact vm wasm-ffi example Add Impact VM wasm-ffi example Jun 27, 2025
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

Successfully merging this pull request may close these issues.

2 participants