Git Product home page Git Product logo

ocamlpro / liquidity Goto Github PK

View Code? Open in Web Editor NEW
158.0 18.0 33.0 3.63 MB

A high-level language for Dune Network (and Tezos) with OCaml and ReasonML syntaxes, with a decompiler from Michelson

Home Page: https://www.liquidity-lang.org

License: GNU General Public License v3.0

OCaml 93.10% Makefile 0.29% Standard ML 0.17% C 5.19% Shell 1.25%
tezos liquidity michelson smart-contracts blockchain ocaml

liquidity's Introduction

next master
Travis-CI Build Status Travis-CI Build Status

Liquidity Logo

Liquidity: a Smart Contract Language for Dune Network

Liquidity is a language to program Smart Contracts for Dune Network (and Tezos). It uses the syntax of OCaml (and ReasonML), and strictly complies to Michelson security restrictions. Liquidity is distributed under the terms of the GPLv3 license.

The Liquidity Project

The Liquidity project contains:

  • A compiler from Liquidity files (.liq extension) to Michelson
  • A de-compiler from Michelson files (.tz extension) to Liquidity
  • A Tezos client to deploy and interact with Liquidity contracts

The Liquidity Language

The Liquidity language provides the following features:

  • Full coverage of the Michelson language: anything that can be written in Michelson can be written in Liquidity.

  • Local variables instead of stack manipulations: values can be stored in local variables.

  • High-level types: types like sum-types and record-types can be defined and used in Liquidity programs.

Branches

The master branch contains the latest stable release. The next branch contains the upcoming version: the language on the next branch is for experimentation, and features may be modified before the next release.

Installation and Usage

See installation instructions and usage documentation.

Documentation

Documentation can be found in the reference and many examples are in the tests and tests/others directories.

Status

All features of Michelson are supported in Liquidity. All tests from https://github.com/dune-network/dune-network/tree/mainnet/test/contracts can be decompiled to Liquidity and recompiled to Michelson.

liquidity's People

Contributors

andrewl33 avatar ddeclerck avatar lefessan avatar marcoonroad avatar martinpospech avatar mebsout avatar pierre-michard avatar steven-de-oliveira avatar stevendeo avatar tomjack 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  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  avatar  avatar

liquidity's Issues

Issue when calling a contract inside a Map.fold

Try-liquidity translate the code below to michelson without reporting any issue. But I get the following error when I try to test (on try-liquidity website):

Error
Request error: In run:
- permanent: illTypedContractTypeError
- permanent: badStackTypeError
[%%version 0.15]

let%entry main
    (parameter : (unit, unit) contract)
    (storage : (int, tez) map)
  : unit * (int, tez) map =
  let foo = storage in
  let storage =
    Map.fold (fun ((i, j), storage) ->
        let _, storage = Contract.call parameter j storage () in
        storage
      ) foo storage
  in
  (), storage

xor doesnt seem to work

Trying to use the xor operator gives me a "unbound variable xor". If I replace it with other operators like >> && or ||, it works.

Is there a different notation I should use?

feature request: show full error description

Right now, the liquidity editor only shows the id field.

Error
Request error: In run:
- permanent: illTypedContractTypeError
- permanent: invalidContractTypeError

Searching the tezos repo for invalidContractTypeError gives us this:

  register_error_kind
    `Permanent
    ~id:"invalidContractTypeError"
    ~title: "Invalid contract (typechecking error)"
    ~description:
      "A script or data expression references a contract that does not \
       exist or assumes a wrong type for an existing contract."
    (located (obj1 (req "contract" Contract.encoding)))

Tezos/Fi

When the smart contract language for Tezos 'Fi programming' is to be ready in Online compiler?

Invalid `List.size` for list type

In current tezos alphanet, the SIZE operator cannot be applied to list type data.
So List.size should be compiled to a loop operation with counting process.

record fields with identical names

Right now records can't have fields with identical names.
This makes record types ugly.

Here's how it looks:

type foo = {
  baz : key;
}

type bar = {
  baz2 : key;
}

Is this by design and/or is there a better way to do this?

Cannot use tz1.. constant as contract

If the code is like this:

   let default_contract = (tz1gwUGqecXACueijvMYXNG8XdTNiz2nu2fW : (unit, unit) contract) in

Will get a Error: Type error: constant type mismatch, expected (unit, unit) contract, got key_hash

But it actually can be the (unit, unit) contract type.

@mebsout

docs have wrong type for Account.default argument

DEFAULT_ACCOUNT : Account.default key. Returns the default contract (of type (unit,unit) contract) associated with a key.

Should be:

DEFAULT_ACCOUNT : Account.default key_hash.

It seems that the instruction HASH_KEY which makes a key_hash from key doesn't exist in Liquidity. Is there another way to do it?

Tezos node

I'm running the tezos node more than one day but it not synchronize with the testnet

Syntactic sugar

Add syntactic sugar:

(fun (x:t1, y:t2) -> BODY)

for

(fun (xy : t1 * t2) ->
   let x = xy.(0) in
   let y = xy.(1) in
   BODY)

And

(let (x,y) = EXP in BODY)

for

(let xy = EXP in
 let x = xy.(0) in
 let y = xy.(1) in
 BODY)

build fail

I ran this way but build failed. How can I fix this?

sudo apt-get update && sudo apt-get -y upgrade
sudo apt-get install pandoc opam -y
opam init --comp 4.06.1 -y
opam update && opam upgrade
sudo opam depext conf-m4.1
opam install -y ocp-build
git clone https://github.com/OCamlPro/liquidity.git
make

...

0.01s _obuild/ocplib-fake-lwt/lwt_io.cmo [failed]
[60.1] Command failed: '/home/test/.opam/tezos/bin/ocamlc.opt' '-bin-annot' '-c' '-o' '_obuild/RULE-4b283007ccd391a759c46ccf2b32c651/lwt_io.cmo' '-I' './_obuild/ocplib-fake-lwt' '-I' './libs/deps-michelson' './libs/deps-michelson/lwt_io.ml'
-- stderr for ./_obuild/ocplib-fake-lwt/lwt_io.cmo --
File "./libs/deps-michelson/lwt_io.ml", line 26, characters 40-41:
Error: This expression has type bytes but an expression was expected of type
string
0.02s _obuild/ocplib-liquidity-documentation/liquidDoc.cmo [ done ]
0.03s _obuild/ocplib-fake-lwt/lwt_stream.cmx [ done ]
3 errors in 0.37s. 20 jobs (parallelism 1.6x), 37 files generated.
Error log:
Error:

Add annotation for FAIL

Recently the new version of Michelson can contain annotations in code

please add annotation for FAIL instruction

Tezos with liquidtity

1-I have some program but I need explanation for how to write methods and how to return different data types then explain how to pass different number of (or) different types of arguments in parameters .
2-how I use tokens in tezos
3-we need step by step tutorial for create testnetwork and how to deploy the contracts

Support for DEFAULT_ACCOUNT?

I can't find a way to support the DEFAULT_ACCOUNT primitive, neither in the doc nor through a cursory look at the sources. Is it missing? For a legitimate reason?

This example is not well typed, but liquidity only sees it when testing

[%%version 0.15]

type storage = { c : tez list ; d : int} (* here field c has type tez list *)
  
let%init storage _ =
  {c = ([] : int list) ; d = 0} (* here field c is initialized with type int list *)
  
let%entry main
    (parameter : unit)
    (storage : storage)
  : unit * storage =
  (), storage

pls add support for `key_hash` type

The alphanet version of tezos has added key_hash type and HASH_KEY operator.
And the newest version (2017-10-14) seems doesn't support (key, xxx) map type.

confusing error message "not a variant type"

Errors (such as missing variable to bind to after Some) in match statement make the compiler emit this message.

Something else like "error in match statement" would work better.

confusing error on non comparable key in map

[%%version 0.165]

type s = ((unit, unit) contract, tez) map

let%init storage =
  let c = Account.default tz1fRRxhWysv9rumaaXrSggbukXrbiYmeB1m in
  (Map [(c, 0tz)])

let%entry main
    (parameter : unit)
    (storage : s)
  : unit * s =
  ((), storage)

and the error message we get:

Unexpected syntax unknown constructor : Map

Something like Non-comparable map key: (unit, unit) contract would work better.

How to Activate wallet in Localhost and Zeronet test network

Hello sir,

  1. As i was gone on Liquidity online editor in that there is a settings and i was chosen zeronet. it was opened some option below the option there is a link to download json file. i was downloaded browsed by option and i chosen file .its shows Activating but not activating in online editor

  2. how do i deploy other contracts in testnetwork of (Zeronet). when i code and compile it compiler compiles and converted into Michelson languge ok. and its runs but i couldn't deploy in network

Is the contract inheritance planned?

Is solidity, inheritance is like contract HTLC is ReentrancyGuard {

In Scala (sorry not OCaml), multiple inheritance is like

trait Drawable {
    def draw() { }
}

trait Cowboy extends Drawable {
    override def draw() {
        println("Bang!")
    }
}

trait Artist extends Drawable {
    override def draw() {
        println("A pretty painting")
    }
}
// Note: the "with" keyword goes between type names for multiple inheritance
// You can chain on multiple "with X" clauses to mix in more traits. If a
// class is to be part of the extended type, it must be specified _before_
// the first "with X" clause.

class CowboyArtist extends Cowboy with Artist 

object Main extends App {
    (new CowboyArtist()).draw() //=>"A pretty painting!,"
}

If we could add multiple inheritance in Scala way, it's very big advantage with Solidity.

How do you think about it?

Issue in creating wallet Account

In Liquidity when the online compiler is ready to work , since it has some problems such as deployment for one program only and so on.

Can't use / between tez and tez

Using the latest next branch

Error: Type error:  Bad 2 args for primitive "/":
    tez
    tez

But Michelson support this operation between tez and tez.

Issue with multiplications of tezzies ?

The examples below are translated using try-liquidity to michelson without issuing an error. However, I get errrors when I try to test the first and the second one (still using try-liquiditty). The error I get is the following:

Error
Request error: In run:
- permanent: illTypedContractTypeError
- permanent: undefinedBinopTypeError
  [%%version 0.15]

  let%entry main (parameter : unit) (storage : tez) : unit * tez =
    (), (2 * storage)
[%%version 0.15]

  let%entry main (parameter : unit) (storage : tez) : unit * tez =
    (), (2tz * storage)
  [%%version 0.15]

  let%entry main (parameter : unit) (storage : tez) : unit * tez =
    (), (storage + storage)

Fatal error: Michelson_v1_printer.unparse.

The compiled Michelson file with --compact will cause an Fatal error: Michelson_v1_printer.unparse. error when originating the contract.

Sample files here: sample.zip
Originate with command:

tezos-client originate contract testA for my_account2 transferring 2.01 from my_account2 running ./compiled.liq.tz -init '(Pair None (Pair None (Pair "tz1bRxJhqoFHJs9j1z8dKVFdveE2TQ4QtiVp" (Pair "TZ1WjYw9YuD4aAj2ATtvmxNzwnURFsUT61ti" (Pair "TZ1hm1T5XCBkukJaFVyZyQCCM6Bh1o4SYZFh" (Pair {} (Pair 0 {})))))))'

This command will get a success with the compiled.liq.tz file, but not compiled-compact.liq.tz file.

Version: 0.164 mini

@mebsout

Generation of a ill-typed program

with commit 439c479

This contract:

let contract
  	(amount: tez)
	(parameter: int)
	(storage: unit)
	(return: int) =
  parameter + (1:int), ()

compiles fine:

$ liquidity.asm add1.liq
File "add1.liq.tz" generated
Typecheck with:
  tezos-client typecheck program add1.liq.tz

But generates ill-typed Michelson:

$ tezos-client typecheck program add1.liq.tz
Ill typed contract:
  storage unit ;
  parameter int ;
  return int ;
  code
    { /* [ pair int unit ] */
      DUP ;
      /* [ pair int unit : pair int unit ] */
      DIP { /* [ pair int unit ] */
            CDR
            /* [ unit ] */ } ;
      /* [ pair int unit : unit ] */
      DIP { /* [ unit ] */
            DROP
            /* [] */ } ;
      /* [ pair int unit ] */
      CAR ;
      CDR /* 1 */ ;
      PUSH unit Unit ;
      PUSH int 1 ;
      { DIP { DIP { DUP } ;
              SWAP } ;
        SWAP }
      { DIP { DIP { DIP { DROP } } } }
      ADD ;
      PAIR }
At mark /* 1 */, wrong stack type for instruction CDR: [ int ].
Fatal error: ill-typed program

That's actually the case with every program I've tried to compile, I just gave the simplest example I had.

I tried to run you suit test:

  • there's a path hard-coded in check.sh line 8;
  • all of them fail as well.

tezos-client is compiled on Ubuntu 16.04 from commit tezos/tezos@49fea59, but it doesn't seem to be the issue, when looking at generated Michelson code there's actually a type error.

Fail to build

I have no right in [email protected]:tezos/tezos.git, so I use https://github.com/tezos/tezos.git for replacement.

The build info is

0.09s _obuild/ocplib-liquidity-ocaml/liquidOCamlParser.cmo             [failed]
[205.1] Command failed: '/Users/qd/.opam/tezos/bin/ocamlc.opt' '-bin-annot' '-c' '-o' '_obuild/e612bd2de14f72c4789721c0e76035fd/liquidOCamlParser.cmo' '-I' './_obuild/ocplib-liquidity-ocaml' '-I' './tools/liquidity' '-I' './_obuild/ocplib-liquidity' '-I' '/Users/qd/.opam/tezos/lib/ocaml/compiler-libs' '-I' './_obuild/ocplib-dot' '-I' './libs/ocplib-dot' './_obuild/ocplib-liquidity-ocaml/_temp/liquidOCamlParser.ml'
-- stderr for ...liquidity-ocaml/liquidOCamlParser.cmo --
File "./tools/liquidity/ocaml/liquidOCamlParser.mly", line 229, characters 34-57:
Error: Unbound value Typ.varify_constructors
2 errors in 5.33s. 111 jobs (parallelism 0.9x), 166 files generated.
Error log:
Error:
[205.1] '/Users/qd/.opam/tezos/bin/ocamlc.opt' '-bin-annot' '-c' '-o' '_obuild/e612bd2de14f72c4789721c0e76035fd/liquidOCamlParser.cmo' '-I' './_obuild/ocplib-liquidity-ocaml' '-I' './tools/liquidity' '-I' './_obuild/ocplib-liquidity' '-I' '/Users/qd/.opam/tezos/lib/ocaml/compiler-libs' '-I' './_obuild/ocplib-dot' '-I' './libs/ocplib-dot' './_obuild/ocplib-liquidity-ocaml/_temp/liquidOCamlParser.ml'

File "./tools/liquidity/ocaml/liquidOCamlParser.mly", line 229, characters 34-57:
Error: Unbound value Typ.varify_constructors

Error:
Target ./_obuild/ocplib-liquidity-ocaml/liquidOCamlParser.cmo not built
make: *** [build] Error 2

Add Micheline output

Generating JSON representation of Michelson can enable people deploy contract though website.

code generated is too large for function definition

If I defined a function for Map.reduce like this:

  let odds_reduce (x : ((odd_index * token) * token)) =
    let curr_odd_index = x.(0).(0) in
    let token = x.(0).(1) in
    let acc_token = x.(1) in
    if curr_odd_index <> 1p then
      acc_token + token
    else
      acc_token
  in

The generated code is already over 16kb which is larger than the restriction of current alphanet.

Restore alphanet node and deployment

Even though the main site still lists "TRY ON ALPHANET" and "TRY ON ZERONET", seems like both link to "betanet" and under Settings the alphanet node was removed.

Is it possible to re-enable the alphanet node so that we can deploy to alphanet from this tool?

the compiled .tz file from liquidity is ill-typed

https://github.com/catsigma/bettingwin/blob/master/contracts/bet/bet_report.liq

This file can be compiled in liquidity without failure, but it cannot pass the typecheck of alphanet.

..................................................
..................................................
..................................................
                                                   (list
                                                      (pair
                                                         key_hash
                                                         (pair nat nat))))
                                                (pair
                                                   (map key_hash nat)
                                                   (map key_hash nat))))))))))) ] */ } ;
          DIP
            { DROP /* 1 */ ;
              DROP ;
              DROP ;
              DROP } }
        { { DIP
              { DIP
                  { DIP
                      { DIP
                          { DUP } ;
                        SWAP } ;
                    SWAP } ;
                SWAP } ;
            SWAP }
          PUSH
            string
            "the source key has reported" ;
          RIGHT
            nat ;
          RIGHT
            unit ;
          PAIR } }
At mark /* 1 */, wrong stack type for instruction DROP: [].

Random number + no string operations except concat?

Hi,

I'm experimenting with Liquidity, writing some example smart contracts for myself for now but didn't find a way to generate a random number. Is it possible? An example would be greatly appreciated. I read all the info I could find but didn't find any examples with a random value. (Maybe Current.time can help)

Another issue I encountered was trying to get the length of a string but I'm not sure it's possible. The only operation I found in the Michelson pdf was concat.

liquidity.asm: not found

Build Successful in 3.74s. 51 jobs (parallelism 1.7x), 101 files generated.
Build is Fine.
But liquidity-mini.asm: not found

test@test-VirtualBox:~/tmp/master/liquidity$ ./check.sh
[check.sh] test =
./_obuild/liquidity/liquidity.asm --verbose tests/.liq
./check.sh: 17: ./check.sh: ./_obuild/liquidity/liquidity.asm: not found
1+MKMFT
04:09

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.