Skip to content

[WIP] Specification language for Liquidity #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 33 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
fb852c2
match%abs for forcing handling of negative case
mebsout Oct 17, 2017
d798409
Allow transfers in condition of if / match
mebsout Oct 18, 2017
2d1696e
Recognize match%abs compilation pattern when decompiling
mebsout Oct 18, 2017
91cd261
Rename match%abs to match%nat
mebsout Oct 18, 2017
45a2fee
Translate match%nat to if-then-else in OCaml
mebsout Oct 18, 2017
4be55fd
abs is now int -> int
mebsout Oct 18, 2017
be9b733
Minimal version accepted is 0.12
mebsout Oct 18, 2017
5f19e6a
Merge pull request #33 from mebsout/match_nat
lefessan Oct 19, 2017
0820d08
Prepare lexer for more literals
lefessan Oct 18, 2017
1885f10
Merge pull request #32 from lefessan/2017-10-18-constant-literals
lefessan Oct 19, 2017
de5fcc8
Fix bug in compilation of pattern matching with contract calls
mebsout Oct 24, 2017
e5b19ab
More flexible Contract.call
mebsout Oct 24, 2017
16fbd10
Fix bug in compilation of pattern matching with contract calls
mebsout Oct 24, 2017
2c7623e
More flexible Contract.call
mebsout Oct 24, 2017
dbe7ac1
Deconstruct tuples in pattern matching
mebsout Oct 24, 2017
496a6f8
Merge remote-tracking branch 'upstream/next' into deconstruct2
mebsout Nov 3, 2017
3cc5a65
Merge pull request #41 from mebsout/deconstruct2
lefessan Nov 3, 2017
bbc7797
Cleanup
lefessan Nov 3, 2017
71f14eb
Merge pull request #40 from lefessan/2017-11-03-cleanup
lefessan Nov 4, 2017
ed2a490
argument ~only_typecheck, to do only typechecking without encoding
mebsout Nov 3, 2017
29dc6d3
Command line options --parse-only and --type-only
mebsout Nov 3, 2017
f7d3c68
Better printing of Liquidity types in error messages
mebsout Nov 3, 2017
78ae969
Keep record and sum types in the Liquidity AST
mebsout Nov 6, 2017
3a6e4b7
Record / Sum type constants
mebsout Nov 7, 2017
1221864
split typechecking and encoding
mebsout Nov 9, 2017
0a41824
phantom type for encoded ast
mebsout Nov 13, 2017
6aac394
type "lambda" as arrow in liquidity
mebsout Nov 13, 2017
816482a
Bug fix compare types
mebsout Nov 13, 2017
e198856
WIP: spec language for liquidity
mebsout Nov 13, 2017
ea2d2b0
Forbid transfers and failures in specs
mebsout Nov 13, 2017
27a65a3
bug fix encoding closures + compare types
mebsout Nov 14, 2017
92ef68d
Allow old in post_conditions
mebsout Nov 14, 2017
2931199
Draft simple multisig contract
mebsout Nov 14, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ distclean: clean

# All of these tests must be run with with_tezos=true

NTESTS=20
NTESTS=32
NTESTS=21
NREVTESTS=6
SIMPLE_TESTS= `seq -f 'test%.0f' 0 $(NTESTS)`
MORE_TESTS=test_ifcons test_if test_loop test_option test_transfer test_left \
test_extfun test_left_constr test_closure test_closure2 test_closure3 \
test_map test_rev test_reduce_closure test_map_closure test_mapreduce_closure \
test_mapmap_closure test_setreduce_closure test_left_match
OTHER_TESTS=others/broker others/demo others/auction
REV_TESTS=`seq -f 'test%.0f' 0 5`
REV_TESTS=`seq -f 'test%.0f' 0 $(NREVTESTS)`

NEW_TEZOS_TESTS= fail weather_insurance
FAILING_TEZOS_TESTS= originator
Expand Down
30 changes: 17 additions & 13 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,32 @@ test=$1
echo "\n[check.sh] test = $test"

LIQUIDITY=liquidity
TEZOS_FULL_PATH=./tezos/_obuild/tezos-client/tezos-client.asm
LIQUID_FULL_PATH=./_obuild/${LIQUIDITY}/${LIQUIDITY}.asm
LIQARGS=--verbose
LIQEXEC="${LIQUID_FULL_PATH} ${LIQARGS}"

echo ./_obuild/${LIQUIDITY}/${LIQUIDITY}.asm tests/$test.liq
./_obuild/${LIQUIDITY}/${LIQUIDITY}.asm tests/$test.liq || exit 2
echo ${LIQEXEC} tests/$test.liq
${LIQEXEC} tests/$test.liq || exit 2

if [ -f ./tezos/_obuild/tezos-client/tezos-client.asm ] ; then
./tezos/_obuild/tezos-client/tezos-client.asm typecheck program tests/$test.liq.tz || exit 2
if [ -f ${TEZOS_FULL_PATH} ] ; then
${TEZOS_FULL_PATH} typecheck program tests/$test.liq.tz || exit 2
else
echo "\n${RED}./tezos/_obuild/tezos-client/tezos-client.asm not present ! typechecking of tests/$test.liq.tz skipped${DEFAULT}\n"
echo "\n${RED}${TEZOS_FULL_PATH} not present ! typechecking of tests/$test.liq.tz skipped${DEFAULT}\n"
fi

echo ./_obuild/${LIQUIDITY}/${LIQUIDITY}.asm tests/$test.liq.tz
./_obuild/${LIQUIDITY}/${LIQUIDITY}.asm tests/$test.liq.tz || exit 2
echo ${LIQEXEC} tests/$test.liq.tz
${LIQEXEC} tests/$test.liq.tz || exit 2

echo ./_obuild/${LIQUIDITY}/${LIQUIDITY}.asm tests/$test.liq.tz.liq
./_obuild/${LIQUIDITY}/${LIQUIDITY}.asm tests/$test.liq.tz.liq || exit 2
echo ${LIQEXEC} tests/$test.liq.tz.liq
${LIQEXEC} tests/$test.liq.tz.liq || exit 2

if [ -f ./tezos/_obuild/tezos-client/tezos-client.asm ] ; then
./tezos/_obuild/tezos-client/tezos-client.asm typecheck program tests/$test.liq.tz.liq.tz || exit 2
if [ -f ${TEZOS_FULL_PATH} ] ; then
${TEZOS_FULL_PATH} typecheck program tests/$test.liq.tz.liq.tz || exit 2
else
echo "\n${RED}./tezos/_obuild/tezos-client/tezos-client.asm not present ! typechecking of tests/$test.liq.tz.liq.tz skipped${DEFAULT}\n"
echo "\n${RED}${TEZOS_FULL_PATH} not present ! typechecking of tests/$test.liq.tz.liq.tz skipped${DEFAULT}\n"
fi

echo ./_obuild/ocp-liquidity-comp/ocp-liquidity-comp.asm -I +../zarith zarith.cma -I _obuild/liquidity-env ./_obuild/liquidity-env/liquidity-env.cma -impl tests/$test.liq
./_obuild/ocp-liquidity-comp/ocp-liquidity-comp.asm -I +../zarith zarith.cma -I _obuild/liquidity-env ./_obuild/liquidity-env/liquidity-env.cma -dsource -impl tests/$test.liq
./_obuild/ocp-liquidity-comp/ocp-liquidity-comp.asm -I +../zarith zarith.cma -I _obuild/liquidity-env unix.cma ./_obuild/liquidity-env/liquidity-env.cma -dsource -impl tests/$test.liq || exit 2
rm -f a.out
25 changes: 18 additions & 7 deletions libs/deps-michelson/build.ocp2
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
(* This part of the library is made to create a minimal set of dependencies
to be able to run code that was directly extracted from Tezos *)

if( with_tezos ) {

OCaml.library("michelson-deps", ocaml + {
bytelink = [ "-custom" ];
files = [
OCaml.library("ocplib-blockchain-crypto", ocaml + {
bytelink = [ "-custom" ];
files = [

"sha256.c"; (* from Polar SSL *)
"sha256-stubs.c";

"tweetnacl.c";
"blake2b-ref.c"; (* from BLAKE/BLAKE *)
"blake2b-stubs.c";
Expand All @@ -32,6 +31,18 @@ OCaml.library("michelson-deps", ocaml + {
"mBytes.ml";
"hex_encode.ml";
"nocrypto.ml";
];
requires = [
"ocplib-endian";
];
cclib = [ "-lsecp256k1" ]
});

if( with_tezos ) {

OCaml.library("michelson-deps", ocaml + {
files = [


"sodium.ml";

Expand All @@ -50,9 +61,9 @@ OCaml.library("michelson-deps", ocaml + {
"updater.ml";
];
requires = [
"ocplib-endian"; (* mBytes *)

"ocplib-blockchain-crypto";
];
cclib = [ "-lsecp256k1" ]
});

}
4 changes: 2 additions & 2 deletions libs/deps-michelson/mBytes.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type t = bytes

let create = String.create
let create = Bytes.create
let length = String.length
let compare = compare

Expand All @@ -11,7 +11,7 @@ let of_string s = s
let blit = String.blit
let blit_from_string = String.blit
let blit_to_bytes = String.blit
let copy = String.copy
let copy = Bytes.copy
let sub = String.sub
let substring = String.sub
let concat = (^)
73 changes: 1 addition & 72 deletions libs/deps-michelson/mBytes.mli
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
(**************************************************************************)
(* *)
(* Copyright (c) 2014 - 2016. *)
(* Dynamic Ledger Solutions, Inc. <[email protected]> *)
(* *)
(* All rights reserved. No warranty, explicit or implicit, provided. *)
(* *)
(**************************************************************************)

type t = bytes

Expand All @@ -14,12 +6,6 @@ val create: int -> t
val length: t -> int

val compare : t -> t -> int
(*

open Bigarray

type t = (char, int8_unsigned_elt, c_layout) Array1.t
*)

val copy: t -> t

Expand All @@ -28,22 +14,13 @@ val sub: t -> int -> int -> t
and of length [len]. No copying of elements is involved: the
sub-array and the original array share the same storage space. *)

(*

val shift: t -> int -> t
(** [shift src ofs] is equivalent to [sub src ofs (length src - ofs)] *)
*)

val blit: t -> int -> t -> int -> int -> unit
(** [blit src ofs_src dst ofs_dst len] copy [len] bytes from [src]
starting at [ofs_src] into [dst] starting at [ofs_dst].] *)

val blit_from_string: string -> int -> t -> int -> int -> unit
(** See [blit] *)

val blit_to_bytes: t -> int -> bytes -> int -> int -> unit
(** See [blit] *)

val of_string: string -> t
(** [of_string s] create an byte array filled with the same content than [s]. *)

Expand Down Expand Up @@ -74,7 +51,6 @@ val set_int8: t -> int -> int -> unit
(** [set_int8 buff i v] writes the least significant 8 bits of [v]
to [buff] at offset [i] *)

(** Functions reading according to Big Endian byte order *)

val get_uint16: t -> int -> int
(** [get_uint16 buff i] reads 2 bytes at offset i as an unsigned int
Expand All @@ -90,9 +66,6 @@ val get_int32: t -> int -> int32
val get_int64: t -> int -> int64
(** [get_int64 buff i] reads 8 bytes at offset i as an int64. *)

val get_float: t -> int -> float
(** [get_float buff i] reads 4 bytes at offset i as an IEEE754 float. *)

val get_double: t -> int -> float
(** [get_float buff i] reads 8 bytes at offset i as an IEEE754 double. *)

Expand All @@ -106,52 +79,8 @@ val set_int32: t -> int -> int32 -> unit
val set_int64: t -> int -> int64 -> unit
(** [set_int64 buff i v] writes [v] to [buff] at offset [i] *)


val set_double: t -> int -> float -> unit
(** [set_double buff i v] writes [v] to [buff] at offset [i] *)

(*

val set_float: t -> int -> float -> unit
(** [set_float buff i v] writes [v] to [buff] at offset [i] *)
val of_float: float -> t

module LE: sig

(** Functions reading according to Little Endian byte order *)

val get_uint16: t -> int -> int
(** [get_uint16 buff i] reads 2 bytes at offset i as an unsigned int
of 16 bits. i.e. It returns a value between 0 and 2^16-1 *)

val get_int16: t -> int -> int
(** [get_int16 buff i] reads 2 byte at offset i as a signed int of
16 bits. i.e. It returns a value between -2^15 and 2^15-1 *)

val get_int32: t -> int -> int32
(** [get_int32 buff i] reads 4 bytes at offset i as an int32. *)

val get_int64: t -> int -> int64
(** [get_int64 buff i] reads 8 bytes at offset i as an int64. *)

val set_int16: t -> int -> int -> unit
(** [set_int16 buff i v] writes the least significant 16 bits of [v]
to [buff] at offset [i] *)

val set_int32: t -> int -> int32 -> unit
(** [set_int32 buff i v] writes [v] to [buff] at offset [i] *)

val set_int64: t -> int -> int64 -> unit
(** [set_int64 buff i v] writes [v] to [buff] at offset [i] *)

end

val (=) : t -> t -> bool
val (<>) : t -> t -> bool
val (<) : t -> t -> bool
val (<=) : t -> t -> bool
val (>=) : t -> t -> bool
val (>) : t -> t -> bool
val compare : t -> t -> int
*)

val concat: t -> t -> t
4 changes: 2 additions & 2 deletions libs/deps-michelson/secp256k1-stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ value secp256k1_ec_pubkey_create_ml
const secp256k1_context* ctx =
(const secp256k1_context*)
String_val(ctx_v);
const secp256k1_pubkey *pubkey =
(const secp256k1_pubkey *)
secp256k1_pubkey *pubkey =
(secp256k1_pubkey *)
String_val(pubkey_v);
const unsigned char *seckey =
(const unsigned char *)
Expand Down
1 change: 1 addition & 0 deletions libs/michelson/base58.ml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

#include "../../tezos/src/utils/base58.ml"
2 changes: 2 additions & 0 deletions libs/michelson/seed_storage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ open Hash
open Utils
open Tezos_data

open Storage.Seed
open Level_repr
#include "../../tezos/src/proto/alpha/seed_storage.ml"
2 changes: 2 additions & 0 deletions libs/michelson/vote_storage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ open Hash
open Utils
open Tezos_data

open Vote_repr
open Voting_period_repr
#include "../../tezos/src/proto/alpha/vote_storage.ml"
9 changes: 6 additions & 3 deletions tests/others/auction.liq
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* Auction contract from https://www.michelson-lang.com/contract-a-day.html *)

[%%version 0.11]
[%%version 0.13]

type storage = {
auction_end : timestamp;
Expand All @@ -11,11 +11,14 @@ type storage = {
let%entry main
(parameter : key_hash)
(storage : storage)
: unit * storage =
: unit * storage
[@requires storage.highest_bid < Current.balance () ]
[@ensures @storage.highest_bid < Current.balance () ]
=

(* Check if auction has ended *)
if Current.time () > storage.auction_end then Current.fail ();

let new_bid = Current.amount () in
let new_bidder = parameter in
(* Check if new bid is higher that the last *)
Expand Down
2 changes: 1 addition & 1 deletion tests/others/broker.liq
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

[%%version 0.11]
[%%version 0.13]

type storage = {
state : string;
Expand Down
2 changes: 1 addition & 1 deletion tests/others/demo.liq
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

[%%version 0.11]
[%%version 0.13]

let%entry main
(parameter : string)
Expand Down
Loading