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 Issues

Repo License

We need to license the repo properly.
The original repo's license for the interpreter and test folder are Apache V 2.0. i guess it should be fine to relicense it to MIT since its Apache. any thoughts?

Filesystem: output instructions

Add instructions for output. Should be quite similar to input instructions. But there might have to be an instruction that creates a new file with a given size.

System calls: simple stubs

The following system calls just need simple stubs. They could be handled using the generic system calls, but it will be more efficient to add stubs.
29. Pause:nothing to implement
34. Nice: nothing to implement
35. Sync: nothing to implement
42. Pipe: nothing to implement
51. Acct: nothing to implement, but what is it?
66. Setsid: nothing to implement
75. Setrlimit: nothing to implement
96. Getpriority: nothing to implement
97. Setpriority: nothing to implement
104. Setitimer: nothing to implement
114. Wait4: nothing to implement
118. Fsync: nothing to implement?
121. setdomainname: nothing to implement
125. Mprotect: nothing to implement
148. Fdatasync: Nothing
150. Mlock: nothing
151. Munlock: nothing
152. Mlockall: nothing
153. Munlockall: nothing
163. Mremap: nothing
199, 200, 201, 202: getuid32, getgid32, geteuid32, getgid32: nothing
203, 204, 213, 214. Setreuid32, setregid32, setuid32, getuid32: nothing
218. Mincore: nothing
219. Madvise: nothing
265. Clock_nanosleep: nothing
272. Fadvise64: nothing
299. Futimesat: nothing
303. Linkat: nothing
308. Pselect: nothing
331. Pipe2: nothing

Skipped syscalls

These are the syscalls that should not be implemented, the output from recorded system calls can be used instead.
20. Getpid: skip
55. Setpgid: skip
64. Getpid: skip
65. Getpgrp: skip
77. Getrusage: skip
102. Socketcall: skip?
122. Uname: skip?
132. Getpgid: skip
147. Getsid: skip
191. Ugetrlimit: skip
195. Stat64: skip?
196. Lstat64: skip?
197. Fstat64: skip?
205. Getgroups32: skip
208, 210. Setresuid32, setresguid32: skip
209, 211. Getresuid, getresgid: skip
268. Statfs64: skip?
269. Fstatfs64: skip?
300. Fstatat: skip?
340. Prlimit64: skip
320. Utimensat: skip

But for example in stat, we should perhaps check that the file exists, and has correct size.

Initialization and initial state

Currently the specification of the task is the hash of the initial state. Because of this, when a task is posted as wasm file, it has to be associated with an initial state hash. Then the solvers and verifiers can check if the wasm file and the initial state match.
There is a problem if the wasm file and the initial state do not match. The whole initial state could be posted instead, but it might be several times larger than the wasm file (if decoding the instructions is not implemented in solidity).
Solution alternatives:

  1. Implement preprocessing in solidity
  2. Implement preprocessor as wasm module

The second alternative is easier, for example the ocaml runtime can be compiled into wasm: https://github.com/sebmarkbage/ocamlrun-wasm

Loading WASM files

We have to be able to load these binary files, and then run them, for example main function or something.

Basic input and output

Some of these already have initial implementations
3. Read
4. Write
5. Open
6. Close
41. Dup: just open with new descriptor
63. Dup2: what does it do?
140. Llseek
145. Readv
146. Writev
180. Pread64
181. Pwrite64
295. Openat
330. Dup3
333. Preadv
334. Pwrited

File permissions

These can probably be skipped for now
15. Chmod. Should we store file owners etc? At least not in input block, perhaps in a configuration file
94. Fchmod
198. Lchown
207. Fchown32
212. Chown32
298. Chownat
306. Fchmodat

JIT

This would increase performance

Compiler tool-chain

Find out how to compile something from C or Rust to webasm, and then test if it works with the interpreter.

Generic external calls

Link in the generic external calls and make them work. Also in the file system calls, we have to skip the external calls.

Adding initialized memory

Add some memory elements. Perhaps can be done at the same time as configuring globals.
This is needed because the emscripten JS runtime does some memory initialization.

Polling

Hopefully can be skipped
142. Newselect: do we have to implement something?
168. Poll: do we have to implement?

Error when building Wasm on OSX

i went through similar instructions on High Sierra:

brew install opam ocaml
opam init -y
eval $(opam config env)
opam install cryptokit yojson

Then encountered this error when executing make to build wasm:

# Error: This expression has type bytes but an expression was expected of type
#          string

Windows CI

Do we wanna do a windows CI for the repo as well?

Managing files and directories

Some of these might be easy to implement, but directory handling might be complex.
9. Link (not implemented?)
10. Unlink (remove files?)
12. Chdir, perhaps need something for keeping track of current directory, it will be similar to command line arguments
38. Rename
39. Mkdir: how to implement directories?
40. Rmdir
83. Symlink: how to handle?
133. Fchdir
183. Getcwd
220. Getdents
296. Mkdirat
301. Unlinkat
302. Renameat
304. Symlinkat

Filesystem: importing filesystem.c

wasdk seems to compile filesystem.c to a simple wasm file. This file should be merged to the actual file to be executed, also some linking has to be done when importing builtins.

The interpreter should throw better error messages

I unsuccessfully tried running a .wasm file using the interpreter. The error messages could be more helpful.
running-wasm-on-its-own

I then tried running the .js file using our emscripten-module-wrapper and got more cryptic error messages.
emscripten-module-wrapper

Turns out the latter was due to me having an older node version.

Add CI

Add automated testing.

Make this a RPC Server

Had the idea of turning this into a JSON RPC Server like Parity or Geth.
Then we write software that can act as a client.

Benefits:
Easier installation for other projects that depend on this (webasm-solidity, coindrop, etc)
Allow us to write client in any language(s) we want
Easier to document the API

Truncating files

Probably these too have to be implemented:
193. Truncate64
194. Ftruncate64

VM configuration

Get the VM memory size etc. from command line or a configuration file instead of hard coded parameter.

Emscripten: find out how the filesystem works

There seems to be some kind of .data file.
Probably what needs to be done is that there are builtin functions for keeping track of file descriptors, and instructions that can be used to read and write to some kind of data block.

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.