Home

Awesome

CI codecov

ErgoScript compiler and ErgoTree interpreter

This repository contains implementations of ErgoScript compiler and ErgoTree Interpreter for a family of Sigma-protocol based authentication languages (or simply Sigma language).

This library is used internally in Ergo Node and ergo-wallet, the public interfaces are subject to change.

For development of Ergo applications using JVM languages (Java/Scala/Kotlin/etc) a better alternative is to use Appkit.

The library is cross-compiled to JS using Scala.js and the main abstractions can be used from JS directly by importing NPM module. See README for details.

Sigma Language Background

Every coin in Bitcoin is protected by a program in the stack-based Script language. An interpreter for the language is evaluating the program against a context (few variables containing information about a spending transaction and the blockchain), producing a single boolean value as a result. While Bitcoin Script allows for some contracts to be programmed, its abilities are limited. Also, to add new cryptographic primitives, for example, ring signatures, a hard-fork is required.

Generalizing the Bitcoin Script, ErgoScript compiler and ErgoTree interpreter implement an authentication language which allows to express coin spending conditions. The ErgoScript Compiler compiles the source code into ErgoTree byte code, which can be saved in UTXO coins to protect their spending (same as in Bitcoin).

ErgoTree, in turn, is a bytecode language and memory representation which can be deterministically interpreted in the given blockchain context. ErgoTree defines guarding proposition for a coin as a logic formula which combines predicates over a context and cryptographic statements provable via Σ-protocols with AND, OR, k-out-of-n connectives.

An interacting party willing to spend the coin first constructs a prover with a set of secrets it knows and then the prover is executed in two steps:

To allow valid coin spending a verifier is running the ErgoTree interpreter with the following three inputs:

The verifier is executed as part of transaction validation for each input and is executed in tree steps:

Getting Started

This library is publishied on Maven repository and can be added to the SBT configuration of Scala project.

libraryDependencies += "org.scorexfoundation" %% "sigma-state" % "5.0.14"

Repository Organization

sub-moduledescription
corecontains core classes of Sigma library
datacontains classes for working with ErgoTree, addresses and all related serializers
docsCollection of documents
interpretercontains an implementation of ErgoTree Interpreter
sdkcontains and implementation of transaction reduction and signing
parserscontains an implementation of ErgoScript parsers using FastParse library
sccontains an implementation of ErgoScript compiler
sigma-jsroot directory of sigmastate-js JS module (see package.json)

Contributing

We welcome contributions to this project! If you are interested in contributing, here are a few ways to get started:

Report bugs: If you have found a bug please open an issue on the issue tracker.

Fix bugs or implement features: If you would like to fix a bug or implement a new feature, please fork the repository and open a pull request with your changes. Please make sure to include a clear description of the changes you have made and why you think they should be included in the project.

Improve documentation: If you notice that the documentation could be improved, please feel free to make changes and open a pull request.

Review pull requests: If you would like to help review pull requests, please take a look at the open pull requests and leave comments on any that you would like to review.

Before you start working on a contribution, please make sure to read the contributing guidelines. These documents outline the expectations for contributions to this project.

Thank you for your interest in contributing to this project! Your help is always appreciated!

Please submit a pull request or create an issue to add a new cryptographic primitives or better implementations.

Acknowledgments

We thank JetBrains for supporting this project since 2021 by providing All Products Pack subscription.

<img src="https://www.yourkit.com/images/yklogo.png"/>

We thank YourKit for support of open source projects with its full-featured Java Profiler. YourKit, LLC is the creator of <a href="https://www.yourkit.com/java/profiler/">YourKit Java Profiler</a> and <a href="https://www.yourkit.com/.net/profiler/">YourKit .NET Profiler</a>, innovative and intelligent tools for profiling Java and .NET applications.

References