Code Monkey home page Code Monkey logo

masala's Introduction

Masala: Pure Ethereum VM and RPC with flexible backends, gas model

Implementation of Ethereum VM, to support investigations into hosting EVM and bytecode in a pure consensus-backed ledger such as Juno.

VM/Bytecode interpreter

Masala.VM houses the main interpreter, which sports a tight dispatch driven by the yellow paper spec ensuring that the stack interop is correct.

Showcases Haskell's superior numeric flexibility by leveraging Word256, Int256, Word8 and Word160 to represent the main EVM datatypes, with the respective newtypes U256, S256, U8 and Address supporting automatic JSON conversion.

Gas Models

Supports ethereum's complex gas model, as well as a FixedGasModel of one-unit-per-instruction.

Backend Polymorphism

VM Backend is represented as the MonadExt typeclass, with a basic implementation. This can easily be extended to write to a database, etc.

Because it's a transformer typeclass, it easily hoists into the RPC monad or runs standalone. Note however the transformer implementations only allow it to be the "inner" monad on the stack.

REPL/RPC

To run repl in GHCI, load module 'Masala.Repl', issue _repl, and enter RPC JSON calls.

Solidity code:
contract SimpleStorage2 {
   uint storedData;
   function set(uint x) {
       storedData = x;
   }
   function get() constant returns (uint retVal) {
       return storedData;
   }
}
ghci> :load Masala.Repl
Ok, modules loaded: Masala.VM, Masala.Instruction, Masala.Word, Masala.Ext.Simple, Masala.VM.Types, Masala.VM.Dispatch, Masala.VM.Memory, Masala.VM.Gas, Masala.RPC, Masala.Repl.
ghci> _repl
> {"method":"eth_sendTransaction","params":[{"from":"1e240","data":"0x606060405260908060106000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806360fe47b11460415780636d4ce63c14605257603f565b005b60506004803590602001506071565b005b605b600450607f565b6040518082815260200191505060405180910390f35b806000600050819055505b50565b60006000600050549050608d565b9056"}]}
sendTransaction: SendTran {stfrom = 1e240, stto = Nothing, stgas = Nothing, stgasPrice = Nothing, stvalue = Nothing, stdata = Just 0x606060405260908060106000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806360fe47b11460415780636d4ce63c14605257603f565b005b60506004803590602001506071565b005b605b600450607f565b6040518082815260200191505060405180910390f35b806000600050819055505b50565b60006000600050549050608d565b9056, stnonce = Nothing}
[...]
sendTransaction: Success, addr=1e241, output=[60,60,60,40,52,60,0,35,7c,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,90,4,80,63,60,fe,47,b1,14,60,41,57,80,63,6d,4c,e6,3c,14,60,52,57,60,3f,56,5b,0,5b,60,50,60,4,80,35,90,60,20,1,50,60,71,56,5b,0,5b,60,5b,60,4,50,60,7f,56,5b,60,40,51,80,82,81,52,60,20,1,91,50,50,60,40,51,80,91,3,90,f3,5b,80,60,0,60,0,50,81,90,55,50,5b,50,56,5b,60,0,60,0,60,0,50,54,90,50,60,8d,56,5b,90,56]
"Success, addr=1e241, acct=Just ExtAccount {code=*bytecode*, bal=0, addy=1e241, store=fromList []"
> {"method":"eth_call","params":[{"to":"1e241","data":"0x60fe47b1000000000000000000000000000000000000000000000000000000000000cafe"},"0x0"]}
[...]
call: Success, output=
> {"method":"eth_call","params":[{"to":"1e241","data":"0x6d4ce63c00000000000000000000000000000000000000000000000000000000"},"0x0"]}
[...]
call: Success, output=000000000000000000000000000000000000000000000000000000000000cafe

The repl implements an IORef state model suitable for plugging into a consensus state machine like Juno.

JSON Test Suite

A subset of the go and cpp tests (circa December 2015) are included, which are executed as an HSpec test.

Note that I extended the JSON format to include a "skip" key, for the tests which are intentionally unsupported. This includes some quirks of the go code test fixture, i.e. creating accounts on overflow, etc.

masala's People

Contributors

bts avatar jmcardon avatar buckie avatar ggrieco-tob avatar

Stargazers

Andres Ojamaa avatar Nir Zilberman avatar  avatar Allan Lukwago avatar Michalis Papadopoullos avatar Jeremy Bae avatar Kareem Moussa avatar Marcin Bielak avatar Edison Austria avatar Will Owens avatar Max Levy avatar Tim Kersey avatar Steven Shaw avatar Matt Piatkowski avatar piliponful avatar Volodymyr Kyrylov avatar Joseph Kiniry avatar Wang avatar Yufan Lou avatar Luke Meyers avatar Badr bellaj avatar Konstantinos avatar Chris Dituri avatar James Anaipakos avatar  avatar Ademar Gonzalez avatar  avatar Choucri FAHED avatar zhangsoledad avatar Zekun Shi avatar Yang Ye avatar Christopher Gilbert avatar  avatar  avatar Mikkel Christiansen avatar Sajith Sasidharan avatar Fredrik Harrysson avatar William Wolf avatar libby kent avatar Simon Burns avatar  avatar Allan Jorge avatar Alfredo Di Napoli avatar Brian McKenna avatar Samuel Gélineau avatar  avatar Vivitsu Maharaja avatar Drew Hess avatar  avatar A. F. Dudley avatar

Watchers

Doug Beardsley avatar Abhik Khanra avatar Carlos López avatar Matt Piatkowski avatar James Cloos avatar Greg Hale avatar Lars Kuhtz avatar  avatar Stuart Popejoy avatar  avatar piliponful avatar  avatar  avatar  avatar

masala's Issues

nest call bug

in VM.hs line 68:

            launchVM vm' env (Just $ Resume 1 o action)

should be :

            launchVM vm env (Just $ Resume 1 o action)

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.