Giter Site home page Giter Site logo

truebitfoundation / ocaml-offchain Goto Github PK

View Code? Open in Web Editor NEW
44.0 13.0 10.0 8.3 MB

Fork of WebAssembly reference interpreter with support for generating proofs needed for blockchain verification

License: Apache License 2.0

Makefile 0.11% Python 0.37% Batchfile 0.47% Shell 0.35% OCaml 14.63% Standard ML 0.09% WebAssembly 79.85% JavaScript 2.97% C 0.82% Dockerfile 0.01% C++ 0.32%
ethereum wasm interpreter truebit

ocaml-offchain's Introduction

Build Status

Installation of the off-chain interpreter

These instructions were tested on Ubuntu 17.04.

First install dependencies

apt-get install -y wget gcc ocaml opam libzarith-ocaml-dev m4 pkg-config zlib1g-dev
opam init -y
eval $(opam config env)
opam install cryptokit yojson

Then go to the interpreter directory of the repo

cd interpreter
make

If the build fails it may be due to an outdated version of ocaml. To upgrade simply run opam switch 4.06.0, and then follow the steps above starting with eval $(opam config env).

This should generate the executable wasm in the interpreter directory.

Testing the off-chain interpreter

./wasm -m ../test/core/fac.wast

If there are no errors, it means that the tests were passed.

./wasm -t -m ../test/core/fac.wast

This command will print the trace messages, it will basically output every instruction that the interpreter runs.

Outputting proofs:

./wasm -case 0 -step 4 -m ../test/core/fac.wast

This will make a proof for step 4 in the computation. Because there are many test cases, one of them has to be selected, so for example -case 0 will select the first test case.

Using the JSON-RPC Server

cd server
npm install
node index.js

A client can communicate with the server like this:

var jayson = require('jayson');

// create a client
var client = jayson.client.http({
  port: 3000
});

// invoke *command* with *args*
client.request('*command*', [*args*], function(err, response) {
  if(err) throw err;
  console.log(response.result);
});

Docker

If you want to run these tests inside of a Docker container you can pull the latest docker image and try it out.

docker run --name tb-offchain -ti hswick/ocaml-offchain:latest`
cd webasm/interpreter
./wasm -t -m ../test/core/fac.wast

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.