Skip to content

Installs a wrapper to emscripten modules that can be used to record data needed for verified computations.

License

Notifications You must be signed in to change notification settings

TrueBitFoundation/emscripten-module-wrapper

Repository files navigation

emscripten module wrapper

This is a wrapper to collect information needed to run WebAssembly modules generated by emscripten.

The idea is that we should be able to run any emscripten generated wasm module, and then post the results as a verified computation using TrueBit. First the script prepare.js adds the wrapper to the js file that was generated by emscripten. Then this file can be ran using Node.js. This will collect the information about calls and memory changes that can be recorded, and used for verified computations. The script first uses the ocaml interpreter to generate a wasm file that has our runtime linked in. Now this file can be ran using the ocaml off-chain interpreter.

Installation instructions

Install npm dependencies

npm install

Install emscripten:

#You can place this wherever, root directory is recommended
git clone https://github.com/juj/emsdk.git

cd emsdk

LLVM_CMAKE_ARGS="-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly" 
./emsdk install sdk-tag-1.37.28-64bit
./emsdk activate sdk-tag-1.37.28-64bit
source ./emsdk_env.sh #this sets up necessary path variables for current terminal session

For more instructions for running emscripten to compile wasm see https://gist.github.com/nolash/910ac3892d48d2e70232c997ffa9d55e and Dockerfile at https://hub.docker.com/r/mrsmkl/coindrop/

Follow installation instructions for the ocaml-offchain interpreter here

If necessary edit prepare.js to include the correct path for wasm interpreter (default: ../ocaml-offchain/interpreter/wasm). Also edit the IPFS host.

Usage

node prepare.js file.js

You can also follow along with this tutorial

Options:

  • --file fname: add the file to the IO block of the task
  • --arg arg: add command line argument
  • --float: add floating point emulation
  • --out: the directory to store the results in, can be tmp if using ipfs.
  • --upload-ipfs: upload to ipfs
  • --ipfs-host: default is localhost

A successful output will look like this:

{
  "ipfshash": "QmaDMzoEE51eNJCc1dMsxUKQGp41qvCsgbv3PHhcbKbAKe",
  "codehash": "0xcc0d89e2f7ad0f720cdc6521ab698c1053dac534cd770fb6531d935975ee5d7e",
  "info": {
    "vm": {
      "code": "0xcc0d89e2f7ad0f720cdc6521ab698c1053dac534cd770fb6531d935975ee5d7e",
      "stack": "0xb4c11951957c6f8f642c4af61cd6b24640fec6dc7fc607ee8206a99e92410d30",
      "memory": "0xb4c11951957c6f8f642c4af61cd6b24640fec6dc7fc607ee8206a99e92410d30",
      "input_size": "0x593e5b969fbeac1646d534f40aeeb6d440f1b60353267ff7a67bb53a3a8f1125",
      "input_name": "0x9f9a605ee9da9ebd0f0a58d289c2345d279c3e11baafdefe72bb5aa2ead36e38",
      "input_data": "0x066ccee69369f2589250d208feef82cd3e06356124c01b9e9e8d56c9393e0e85",
      "call_stack": "0xb4c11951957c6f8f642c4af61cd6b24640fec6dc7fc607ee8206a99e92410d30",
      "globals": "0xb4c11951957c6f8f642c4af61cd6b24640fec6dc7fc607ee8206a99e92410d30",
      "calltable": "0x7bf9aa8e0ce11d87877e8b7a304e8e7105531771dbff77d1b00366ecb1549624",
      "calltypes": "0xb4c11951957c6f8f642c4af61cd6b24640fec6dc7fc607ee8206a99e92410d30",
      "pc": 0,
      "stack_ptr": 0,
      "call_ptr": 0,
      "memsize": 0
    },
    "hash": "0x9e10c72398fc17ba4fa0163ea8da8d1401abfe4ef93335b122df18498cac5da7"
  },
  "memsize": "25"
}

About

Installs a wrapper to emscripten modules that can be used to record data needed for verified computations.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published