Zilliqa / scilla-rtl

Execute Scilla code compiled by the Scilla -> LLVM compiler.
GNU General Public License v3.0
8 stars 3 forks source link
runtime-library scilla scilla-compiler scilla-rtl

Scilla Runtime Library

Build Status License

The Scilla Runtime Library provides two main functionalities

  1. An entry point to execute Scilla contracts. The contract to be executed must be compiled by the Scilla LLVM compiler, and linked into a shared library object.
  2. A collection of functions that implement various common (i.e., not specific to a contract) Scilla operations and enable the compiled binary to interact with the blockchain during execution.

Build and install

Ubuntu:

MacOSX:

We suggest building ScillaRTL in a directory that is not the source directory.

Run

While ScillaRTL is intended to be primarily used as a library from the Zilliqa blockchain, we provide two wrapper executables for development, debugging and simply trying it out. expr-runner takes as input, a compiled pure Scilla expression and executes it, by calling a wrapper function scilla_main generated by the compiler. If the expression is printable, the compiler also generates a call to print it. scilla-runner takes a compiled Scilla contract, a message JSON, an initial state for execution and a contract info JSON (obtrained by running scilla-checker with the -contractinfo flag). With these inputs, the transition specified in the message JSON is executed. The output state is printed.

$build/bin/expr-runner -g 1000 testsuite/expr/lit-pair-list-int.ll

$build/bin/scilla-runner -g 10000 --input-contract testsuite/contr/simple-map.ll --message testsuite/contr/simple-map.message_Increment.json --contract-info testsuite/contr/simple-map.contrinfo.json --state testsuite/contr/simple-map.state_00.json --init testsuite/contr/empty_init.json --blockchain testsuite/contr/blockchain_default.json

Developer Notes

All public headers are placed in include. The library implementation resides in libScillaRTL. Executable wrappers are defined in runners. The tests sources are confined to testsuite.

Coding Standards

This project uses the LLVM coding standards.

For convenience, the naming convention is summarized below. All names (with allowed exceptions) must be in camel case

A few other points to note

To conform to the coding style and good programming practices, CMake targets clang-format and clang-tidy are provided, which when run as make clang-format and make clang-tidy in the build directory, will auto format all source files.

They can also be manually run from the command line:

Testsuite

The testsuite, built by default (but not installed), is based on boost_unit_framework and can be run from the project root as

build/testsuite/scilla-testsuite -- testsuite_dir

A few command line options are provided below for quick reference. See --help for all options provided by boost. These options must all be provided prior to -- in the command line.

The testsuite_dir argument following -- is a custom argument that tells the testsuite where to find the tests and their inputs. The custom flag --update-result can be provided to update test results instead of comparing.

For convenience a CMake target runtests has been provided to run the testsuite. This can be executed as make runtests in the build directory.

Expression execution tests

The directory testsuite/expr contains text LLVM-IR files, all generated by expr-compiler. We maintain the following conventions:

Contract execution tests

The directory testsuite/contr contains text LLVM-IR files, all generated by scilla-compiler. The directory also contains the supporting JSONs required for executing transitions in these compiled contracts. Each LLVM-IR file foo.ll also has foo.dbg.ll that is a compiled version of the same contract with debuginfo. These LLVM-IR files can be updated from the Scilla LLVM compiler using the scripts/update_contrs.sh. This script updates both the debug and non-debug LLVM-IR modules and also the contract info for that contract.