Giter Site home page Giter Site logo

truebitfoundation / webasm-solidity Goto Github PK

View Code? Open in Web Editor NEW
66.0 16.0 12.0 990 KB

[DEPRECATED] On-chain interpreter for WebAssembly written in Solidity

License: MIT License

HTML 2.92% JavaScript 44.86% Shell 1.17% C 5.27% WebAssembly 0.41% Solidity 45.08% Dockerfile 0.29%
ethereum interpreter wasm solidity truebit

webasm-solidity's People

Contributors

hswick avatar mrsmkl avatar terminaldweller avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webasm-solidity's Issues

deleteChallenge is public

Noticed that the deleteChallenge method in interactive is public and doesn't include any requires. need to change this.

Setting VM parameters

The task giver needs to be able to set the VM parameters like how much memory is available, stack size etc.
Then there has to be a way to build the initial state from these parameters.

Dispute Resolution support preprocessing pipeline task

Before a normal wasm task is submitted there can also be a preprocessing step. This preprocessing can involve a pipeline

Pipeline

-Preprocess code (initialize wasm task)
-Floating point
-Metering
-Linking (Optional)

Each of these steps could use their own verification games, or they can be combined into one game (aka the pipeline task). This single pipeline task can simply return the root hash of the preprocessed files.

In the case where a verifier challenges a task, and that task uses the preprocessing step, a verifier will dispute the preprocessing task first. Then once that passes, the game will carry on to the normal wasm task dispute.

Use abi.encodePacked for inputs to keccak256

Solidity compiler gives this type of warning quite a bit.
fs.sol:52:20: Warning: This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.

I believe this is a breaking change in 0.5.0, so it would be good to change this sooner than later.

Merkle computer should take interpreter path as input

Right now the wasmInterpreterPath is expected to be ../ from the cwd. It would be best to be able to input the path as a parameter somewhere.

Perhaps splitting up the merkle-computer file into compute, and utils might make this easier.

Handle final state

Making sure that the state posted by the solver is really final, or execution ended with error.

Add CI

Add automated testing.

More tests

Need to test the following cases:

  • solver and verifier have different number of steps
  • solver and verifier disagree whether the state is final
  • solver and verifier disagree whether an runtime error has happened in the execution

Native execution of wasm files

What is blocking this at the moment:

  • verified initialization: TrueBitFoundation/ocaml-offchain#39
  • the result will have to be just the hash of output, when the challenge is posted, the solver will have to submit the initial and final state with proofs that they are compatible with the posted initial code, input and output
  • also have to post the number of steps at that time

FPU Emulation

Each floating point opcode should be changed into a function call. These functions implement the floating point ops with integer ops and use a fixed amount of steps, so they can be skipped by the interpreter.

Perhaps first it will be easiest to just pre-process it and always run the functions without skipping.

how to get result for giver?

for example, when i run

./wasm -m  -memory-size 16 -stack-size 14 -table-size 8 -globals-size 8 -call-stack-size 10 -case 0 ./factorial.wast -output

off-chain, it may show that

{"vm": { "code": "0x4ce57322d69eb9f405acdc0d13174b14595414a75df8c458a5e7c68739bb5f78", "stack": "0xd37da133d3b660a1aa6bdfe5f7f7a805c1ce5ce693da5138065878648e015319", "memory": "0x2733e50f526ec2fa19a22b31e8ed50f23cd1fdf94c9154ed3a7609a2f1ff981f", "input_size": "0xf9dc3e7fe016e050eff260334f18a5d4fe391d82092319f5964f2e2eb7c1c3a5", "input_name": "0xf9dc3e7fe016e050eff260334f18a5d4fe391d82092319f5964f2e2eb7c1c3a5", "input_data": "0xe026cc5a4aed3c22a58cbd3d2ac754c9352c5436f638042dca99034e83636516", "call_stack": "0x6b2a56fef280042cd8f791b2b1d47198ee5a21cfb40cc8c13e7adb5dab2db3b7", "globals": "0x9867cc5f7f196b93bae1e27e6320742445d290f2263827498b54fec539f756af", "calltable": "0x9dc25e3b944260e342d33236a1c3aba8c451c07733651c561e0a53b843757217", "calltypes": "0x9867cc5f7f196b93bae1e27e6320742445d290f2263827498b54fec539f756af", "pc": 1099511627775, "stack_ptr": 1, "call_ptr": 0, "memsize": 0 }, "hash": "0xb54475a73855987df7992919637f0bcbc8a434a03d77f903960f269f8b254ee7", "steps": 499, "files": []}

how can i get the task output result? thanks a log

ERR_OUT_OF_RANGE when executing '$node deploy-tasks.js > config.json

RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= 0 and <= 4294967295. Received -1362828628
at checkInt (internal/buffer.js:35:11)
at writeU_Int32BE (internal/buffer.js:625:3)
at Buffer.writeUInt32BE (internal/buffer.js:638:10)
at WebSocketFrame.toBuffer (D:\HJ\Projects\WAGON\webasm-solidity-master\node_modules\websocket\lib\WebSocketFrame.js:257:24)
at WebSocketConnection.sendFrame (D:\HJ\Projects\WAGON\webasm-solidity-master\node_modules\websocket\lib\WebSocketConnection.js:852:43)
at WebSocketConnection.fragmentAndSend (D:\HJ\Projects\WAGON\webasm-solidity-master\node_modules\websocket\lib\WebSocketConnection.js:788:14)
at WebSocketConnection.sendUTF (D:\HJ\Projects\WAGON\webasm-solidity-master\node_modules\websocket\lib\WebSocketConnection.js:728:10)
at W3CWebSocket.send (D:\HJ\Projects\WAGON\webasm-solidity-master\node_modules\websocket\lib\W3CWebSocket.js:116:26)
at WebsocketProvider.send (D:\HJ\Projects\WAGON\webasm-solidity-master\node_modules\web3-providers-ws\src\index.js:223:21)
at Timeout._onTimeout (D:\HJ\Projects\WAGON\webasm-solidity-master\node_modules\web3-providers-ws\src\index.js:203:19)
at ontimeout (timers.js:427:11)
at tryOnTimeout (timers.js:289:5)
at listOnTimeout (timers.js:252:5)
at Timer.processTimers (timers.js:212:10)

this error occured with createContract("Judge")
Judge.bin file is to heavy
how can I finish this work?

Judges as external functions

There could be some kind of instruction that would trigger another verification game. For example there could be a function to execute another wasm program inside the wasm programs.

Error and warnings when compiling contracts

when running sh compile.sh with solc 0.4.19 i get the following error and warnings:

fs.sol:126:43: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
   function debug_forwardData(bytes32 id, address a) public returns (uint) {
                                          ^-------^
fs.sol:126:4: Warning: Function state mutability can be restricted to view
   function debug_forwardData(bytes32 id, address a) public returns (uint) {
   ^
Spanning multiple lines.
Error: Documented parameter "limit
@param" not found in the parameter list of the function.

popcnt, ctz, clz

Implement popcnt, ctz and clz operations in Solidity.
Also other operations have to be checked properly.

JSON error with app.js

Was running through the README and was able to run deploy-tasks.js with parity chain dev to create the config.json. But when I try to run app.js it gives a JSON error.

This is because deploy-tasks.js is outputting two json objects, instead of one, like app.js expects.

{ "interactive": "0x4d06047ed426e2a2f0bbe86cee268200d20b8d62", "tasks" : "0xcfa55b9b5c1c05e81a7f306a841ae6f3b489d057" }
{ "interactive": "0x7a0d30234e146a88cd65f0714ab7603b0568b16a", "tasks" : "0x6ec4905ff2bfbb1ee8f4c11006ef528df4d30b80" }

I can go in the file and delete the second object and then the app works.

finalizeBundleIPFS not used/expensive

finalizeBundleIPFS returns a merkle root of the input files for a task. It is meant to be used by another smart contract, however there seem to be 2 issues with it:

  1. It is not clear how an offchain solver is supposed to recreate the merkle root when initializing the challenge, as the data being used is different. This problem manifests itself at https://github.com/TrueBitFoundation/webasm-solidity/blob/master/contracts/interactive.sol#L125

  2. The call is unoptimized. At only two files the call costs 1.5 mil gas

JS Runtime

To run our wasm files with nodejs, we need to have a JS version of the runtime. Hardest part is figuring out generic system calls, and then we just need the input/output commands and getTotalMemory.

Task data input

Reading data from the blockchain.
A new merkle root will have to be added.

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.