Skip to content

Commit

Permalink
Merge branch 'master' into perf-benchmarks
Browse files Browse the repository at this point in the history
* master:
  Fix bug/typo to check patterns in transitions (Zilliqa#752)
  Scilla runner refactoring + a small bug fix (Zilliqa#749)
  Fix Schnorr (Zilliqa#746)
  Fix init JSON validation checks for libraries (Zilliqa#748)
  Rearranging lib test files (Zilliqa#747)
  INSTALL.md formatting: add foldable sections (Zilliqa#744)
  Remove unused tests (Zilliqa#741)
  Disallow duplicate _extlib entries and updates to library import tests (Zilliqa#743)
  Use domt4 homebrew tap (Zilliqa#742)
  • Loading branch information
vyorkin committed Jan 13, 2020
2 parents 4e65c1f + 382192d commit 1b4f594
Show file tree
Hide file tree
Showing 59 changed files with 438 additions and 692 deletions.
4 changes: 2 additions & 2 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# To install the compatible version of `secp256k1` package, one needs to add the following tap:
tap "anton-trunov/crypto"
tap "domt4/crypto"

brew "gcc"
brew "ocaml"
Expand All @@ -9,5 +9,5 @@ brew "libffi"
brew "openssl"
brew "boost"
brew "pcre"
brew "anton-trunov/crypto/secp256k1", args: ["with-enable-module-recovery"]
brew "domt4/crypto/secp256k1", args: ["with-enable-module-recovery"]
brew "cmake"
38 changes: 36 additions & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The recommended installation process is comprised of two separate steps:

Please make sure you install opam v2.0 or greater (this can be checked by running `opam --version`).

Scilla requires OpenSSL 1.0.2 and if your platform does not have packages for this, you may need to build OpenSSL
Scilla requires OpenSSL 1.1.1 and if your platform does not have packages for this, you may need to build OpenSSL
yourself and set `PKG_CONFIG_PATH` environment variable accordingly
(if you install OpenSSL in a non-default path):
```shell
Expand All @@ -16,6 +16,8 @@ export PKG_CONFIG_PATH="_OpenSSL_prefix_/lib/pkgconfig:$PKG_CONFIG_PATH"

## OS-specific setup for building Scilla

<details><summary>openSUSE</summary>

### openSUSE

- Install `libsecp256k1-devel` from
Expand All @@ -36,6 +38,10 @@ export PKG_CONFIG_PATH="_OpenSSL_prefix_/lib/pkgconfig:$PKG_CONFIG_PATH"
sudo zypper install -y curl m4 opam2 pkg-config zlib-devel gmp-devel libffi-devel libopenssl-devel boost-devel
```

</details>

<details><summary>Ubuntu</summary>

### Ubuntu

On machines with Ubuntu strictly older than 18.04, run these additional commands first:
Expand All @@ -50,9 +56,13 @@ Required Ubuntu packages can be installed as below:
```shell
sudo add-apt-repository -y ppa:avsm/ppa
sudo apt-get update
sudo apt-get install -y curl build-essential m4 ocaml opam pkg-config zlib1g-dev libgmp-dev libffi-dev libssl-dev libboost-system-dev libsecp256k1-dev libpcre3-dev
sudo apt-get install -y curl build-essential m4 ocaml opam pkg-config zlib1g-dev libgmp-dev libffi-dev libssl-dev libboost-system-dev libsecp256k1-dev libpcre3-dev cmake
```

</details>

<details><summary>macOS</summary>

### macOS

The dependencies (listed in [Brewfile](Brewfile)) can be installed via [Homebrew](https://brew.sh/) as follows.
Expand All @@ -76,12 +86,20 @@ the maximum number of open file descriptors as `Makefile`'s `test` target does:
ulimit -n 1024
```

</details>

<details><summary>Nix and NixOS</summary>

### Nix and NixOS

There is a `shell.nix` for Nix users, so running the `nix-shell`
should drop you into and isolated environment with all the
necessary dependencies available.

</details>

<details><summary>Windows</summary>

### Windows 10 Pro/Home Edition (Creators Update & later) via WSL

1. Enable [Windows Subsystem for Linux](https://youtu.be/epZOKY83t8g) (Choose Ubuntu 18.04 LTS)
Expand Down Expand Up @@ -176,11 +194,15 @@ The binaries (`eval-runner`, `scilla-checker`, `scilla-runner` & `type-checker`)
[x -> (Int32 42)] }
```

</details>




## Installing opam packages

<details><summary>Fresh opam installation (recommended for novice opam users)</summary>

### If you just installed opam package manager

#### Initialize opam
Expand All @@ -205,6 +227,11 @@ The above commands can, alternatively, be run using the make target `opamdep`:
make opamdep
```

</details>


<details><summary>Local opam switch to avoid conflicts with already installed global opam switches</summary>

### If you have opam package manager already installed
You can try installing the Scilla dependencies using the instructions above, but skipping the initialization step.
If `opam` reports a dependency conflict, one way out might be creating yet another opam switch and
Expand All @@ -230,9 +257,14 @@ We suggest using `make clean` command or keeping `_opam` directory like so:
git clean -dfX --exclude=\!_opam/**
```

</details>

## Using OCaml with Emacs

Please, read the instructions below if you intend to hack on Scilla implementation.

<details><summary>Instructions</summary>

Scilla is written in [OCaml](https://ocaml.org/).
You can read about how to setup your OCaml development environment [here](https://dev.realworldocaml.org/install.html).
The following extensions would be useful for working on this codebase:
Expand All @@ -250,3 +282,5 @@ Additionally, you might want to install a nice OCaml REPL called [utop](https://

To enable flycheck mode (integration of `scilla-checker` with Emacs for editing Scilla files), install
flycheck for Emacs. See installation instructions [here](http://www.flycheck.org/en/latest/user/installation.html).

</details>
2 changes: 1 addition & 1 deletion scripts/build_openssl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fi

git clone https://github.com/openssl/openssl.git ~/openssl/src
cd ~/openssl/src
git checkout tags/OpenSSL_1_0_2n
git checkout tags/OpenSSL_1_1_1
./config --prefix=${HOME}/openssl/install --openssldir=${HOME}/openssl/ssl
make -j4
make install
4 changes: 2 additions & 2 deletions src/base/cpp/Schnorr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ bool Schnorr::Sign(const bytes& message, unsigned int offset, unsigned int size,
}

err = (BN_nnmod(result.m_r.get(), result.m_r.get(), m_curve.m_order.get(),
NULL) == 0);
ctx.get()) == 0);
if (err) {
LOG_GENERAL(WARNING, "BIGNUM NNmod failed");
return false;
Expand Down Expand Up @@ -370,7 +370,7 @@ bool Schnorr::Verify(const bytes& message, unsigned int offset,
}

err2 = (BN_nnmod(challenge_built.get(), challenge_built.get(),
m_curve.m_order.get(), NULL) == 0);
m_curve.m_order.get(), ctx.get()) == 0);
err = err || err2;
if (err2) {
LOG_GENERAL(WARNING, "Challenge rebuild mod failed");
Expand Down
2 changes: 1 addition & 1 deletion src/checkers/PatternChecker.ml
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ module ScillaPatternchecker
) in
let checked_comps = List.rev c_comps in

if emsgs'' = []
if emsgs''' = []
(* Return pure environment *)
then pure ( {CheckedPatternSyntax.smver = mod_smver;
CheckedPatternSyntax.cname = mod_cname;
Expand Down
8 changes: 7 additions & 1 deletion src/runners/RunnerUtil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ let get_init_extlibs filename =
then
(plog (sprintf "Invalid init json %s file" filename); [])
else
try JSON.ContractState.get_init_extlibs filename with
try
let name_addr_pairs = JSON.ContractState.get_init_extlibs filename in
if List.contains_dup ~compare:(fun a b -> String.compare (fst a) (fst b)) name_addr_pairs
then fatal_error @@
mk_error0 (sprintf "Duplicate extlib map entries in init JSON file %s." filename)
else name_addr_pairs
with
| Invalid_json s ->
(* Inability to fetch extlibs info from init json shouldn't be fatal error. *)
plog (scilla_error_to_string s);
Expand Down
70 changes: 39 additions & 31 deletions src/runners/cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
scilla. If not, see <http://www.gnu.org/licenses/>.
*)

open Core_kernel


let f_input_init = ref ""
let f_input_state = ref ""
let f_input_message = ref ""
Expand All @@ -42,7 +45,7 @@ let process_trace () =
| _ -> ()

let process_pplit () =
if !b_pp_lit then GlobalConfig.set_pp_lit true else GlobalConfig.set_pp_lit false
GlobalConfig.set_pp_lit !b_pp_lit

let process_json_errors () =
GlobalConfig.set_use_json_errors !b_json_errors
Expand All @@ -51,40 +54,45 @@ let process_json_validation () =
GlobalConfig.set_validate_json !b_validate_json

let validate_main usage =
let msg =
(* not mandatory file name input, but if provided, should be valid *)
let invalid_optional_fname fname =
not (String.is_empty fname || Sys.file_exists fname)
in
let msg = "" in
let msg =
(* init.json is mandatory *)
(if not (Sys.file_exists !f_input_init)
then "Invalid initialization file\n" else "") in
let msg1 =
if not @@ Sys.file_exists !f_input_init
then "Invalid initialization file\n" else msg in
let msg =
(* input_state.json is not mandatory, but if provided, should be valid *)
(if ((!f_input_state <> "") && not (Sys.file_exists !f_input_state))
then msg ^ "Invalid input contract state\n" else msg) in
let msg2 =
if invalid_optional_fname !f_input_state
then msg ^ "Invalid input contract state\n" else msg in
let msg =
(* input_message.json is not mandatory, but if provided, should be valid *)
(if ((!f_input_message <> "") && not (Sys.file_exists !f_input_message))
then msg1 ^ "Invalid input message\n" else msg1) in
let msg3 =
if invalid_optional_fname !f_input_message
then msg ^ "Invalid input message\n" else msg in
let msg =
(* input_blockchain.json is mandatory *)
(if not (Sys.file_exists !f_input_blockchain)
then msg2 ^ "Invalid input blockchain state\n" else msg2) in
let msg4 =
if not @@ Sys.file_exists !f_input_blockchain
then msg ^ "Invalid input blockchain state\n" else msg in
let msg =
(* input file is mandatory *)
(if not ((Sys.file_exists !f_input))
then msg3 ^ "Invalid input contract file\n" else msg3) in
let msg5 =
(* output file is mandatory *)
(if !f_output = "" then msg4 ^ "Output file not specified\n" else msg4) in
let msg6 =
if not @@ Sys.file_exists !f_input
then msg ^ "Invalid input contract file\n" else msg in
(* Note: output file is optional, if it's missing we will output to stdout *)
let msg =
(* input_message.json and input_state.json / i_ipc_address+balance can either both be there or both absent *)
if (!f_input_message <> "") &&
((!f_input_state <> "") && ((!i_ipc_address <> "") || (Core_kernel.is_some !v_balance)) ||
(!f_input_state = "" && (!i_ipc_address = "" || Core_kernel.is_none !v_balance)))
then msg5 ^ "Input message provided, but either none or both of input state / (IPC address and balance) provided\n"
else msg5 in
if msg6 <> ""
if String.(
!f_input_message <> "" &&
((!f_input_state <> "") && (!i_ipc_address <> "" || Option.is_some !v_balance) ||
(!f_input_state = "") && (!i_ipc_address = "" || Option.is_none !v_balance))
)
then msg ^ "Input message provided, but either none or both of input state / (IPC address and balance) provided\n"
else msg in
if msg <> ""
then
PrettyPrinters.fatal_error_noformat (usage ^ (Printf.sprintf "%s\n" msg6))
else
PrettyPrinters.fatal_error_noformat (usage ^ (Printf.sprintf "%s\n" msg))
else
()

type ioFiles = {
Expand Down Expand Up @@ -150,10 +158,10 @@ let parse () =

let mandatory_usage = "Usage:\n" ^ Sys.argv.(0) ^ " -init init.json [-istate input_state.json]" ^
" -iblockchain input_blockchain.json [-imessage input_message.json]" ^
" -o output.json -i input.scilla -libdir /path/to/stdlib" ^
" [-o output.json] -i input.scilla -libdir /path/to/stdlib" ^
" -gaslimit limit" ^ "\n" in
let optional_usage = String.concat "\n "
(List.map (fun (flag, _, desc) -> flag ^ " " ^ desc) speclist) in
let optional_usage = String.concat ~sep:"\n " @@
List.map speclist ~f:(fun (flag, _, desc) -> flag ^ " " ^ desc) in
let usage = mandatory_usage ^ "\n " ^ optional_usage ^ "\n" in

let ignore_anon _ = () in
Expand Down
Loading

0 comments on commit 1b4f594

Please sign in to comment.