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

Trust Contracts - POC for a WebAssembly engine #1648

Open
hewison-chris opened this issue Feb 17, 2021 · 3 comments · May be fixed by #2132
Open

Trust Contracts - POC for a WebAssembly engine #1648

hewison-chris opened this issue Feb 17, 2021 · 3 comments · May be fixed by #2132

Comments

@hewison-chris
Copy link
Contributor

To get started we need a working proof of concept WebAssembly engine integrated into Agora.

@hewison-chris
Copy link
Contributor Author

Status update:-
Currently the source/agora/node/WasmEngine.d unit tests run locally on either Ubuntu or MacOs.
In ci the build fails for MacOs so the install of wasmer needs to be fixed.
I managed to fix the linux build in Github workflow by using the bash installer. However currently one of the network unit tests fail.
For running wasmer in Alpine linux there is a challenge to get wasmer installed and working as the normal bash installer does not work. Wasmer should support linux musl so it is just a matter of finding a way to install it.

@hewison-chris
Copy link
Contributor Author

hewison-chris commented Jun 29, 2021

@Geod24
Copy link
Collaborator

Geod24 commented Mar 25, 2022

We worked a bit on that issue, and managed to get a function that accessed the Ledger called from WAT (WebAssembly Text) 💥

Key findings:

  • Binding is done outside of WebAssembly, essentially module_.instantiate(array_of_functions_that_matches_exports);
  • import "module" "function" => module is provided when using Function.asExtern;
  • We couldn't use the Function ctor that takes a delegate, had to provide the function type explicitly;
  • There's two types of functions, one with "environment" (context) and one without: Another way to provide context is also to use the global scope of the module (we did that with log for example);

Rough list of steps to take:

  • Get a simple, self contained WASM example to compile and run;
  • Pass arguments to and get values from a WASM function;
  • Have a WASM function call a D function and return blockchain data;
  • Define list of primitives we want to expose;
  • Define types we want to expose;
  • Get a sample C / C++ / JS code to compile to WASM and use it in Agora;
  • Integrate contract code in Blocks;
  • ...
  • Profit

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

Successfully merging a pull request may close this issue.

3 participants
@Geod24 @hewison-chris and others