ToolszkEVMSpecIndex

Compiling Using Pilcom

This document describes how Polynomial Identity Language programs are compiled by PILCOM. Depending on the language used in implementation, every PIL code can b

This document describes how Polynomial Identity Language programs are compiled by PILCOM.

Depending on the language used in implementation, every PIL code can be compiled into either a JSON\texttt{JSON} file or a C++\texttt{C++} code by using a compiler called pilcom.

The pilcom compiler package can be found at this Github repository here. Setup can be fired up at the command line with the usual clone\texttt{clone}, install\texttt{install} and build\texttt{build} CLI commands.

Any PIL code can be compiled into a JSON\texttt{JSON} file with the command,

node src/pil.js <input.pil> -o <output.pil.json>

which is a basic JSON\texttt{JSON} representation of the PIL program (with some extra metadata) to be later consumed on by the pil-stark package in order to generate a STARK proof.

Similarly, any PIL code can be compiled into C++ code with this command,

node src/pil.js <input.pil> -c -n namespace

in which case the corresponding header files (.hpp) will be generated in the ./pols_generated folder.

Restriction on polynomial degrees

The current version of PIL can only handle quadratics. That is, given any set of polynomials; a\texttt{a}, b\texttt{b} and c\texttt{c}; PIL can only handle products of two polynomials at a time,

aa,  ab  and  ac\mathtt{a * a},\ \ \mathtt{a * b}\ \ \text{and}\ \ \mathtt{a * c}

but not higher degrees such as,

aaa,  abb,  (1a)bc   or   abcc\mathtt{a * a * a},\ \ \mathtt{a * b * b},\ \ \mathtt{(1-a) * b * c}\ \ \text{ or }\ \ \mathtt{a * b * c * c}

These higher degree products are handled via an intermediate\texttt{intermediate} polynomial, conveniently dubbed carry\texttt{carry}. Consider again the constraint of the optimized Multiplier program:

out=RESETfreeIn + (1RESET)(freeInout)(Eqn. 6)\texttt{out}' = \texttt{RESET} * \texttt{freeIn}\ +\ (1 - \texttt{RESET}) (\texttt{freeIn} * \texttt{out}) \tag{Eqn. 6}

which involves the trinomial,

(1RESET)(freeInout).(1 - \texttt{RESET}) (\texttt{freeIn} * \texttt{out}) .

A carry\texttt{carry} can be used in Eqn. 6\text{Eqn. 6} as follows,

out=RESETfreeIn + (1RESET)carry(Eqn. 7)\texttt{out}' = \texttt{RESET} * \texttt{freeIn}\ +\ (1 - \texttt{RESET})* \texttt{carry} \tag{Eqn. 7}

where in this case, carry=freeInout\texttt{carry} = \texttt{freeIn} * \texttt{out}.

In the same sense that keywords commit\texttt{commit} and constant\texttt{constant} can be thought of as types\text{types} of polynomials, intermediate\texttt{intermediate} can also be regarded as a third type of polynomial in PIL.

PIL compilation

In order to compile the above PIL code to a JSON file, follow the following steps.

  • Create a subdirectory/folder for the Multiplier SM and call it multiplier_sm.

  • Switch directory to the new subdirectory multiplier_sm, and open a new file. Name it multiplier.pil , copy in it the text below and save;

    namespace Multiplier(2**10); 
    
    // Constant Polynomials
    pol constant RESET;
    
    // Committed Polynomials
    pol commit freeIn;
    pol commit out;
    
    // Intermediate Polynomials
    pol carry = out*freeIn; 
    
    // Constraints
    out' = RESET*freeIn + (1-RESET)*carry;
  • Switch directory to pilcom/\texttt{pilcom}/ and run the below command,

    node src/pil.js ~/multiplier_sm/multiplier.pil -o multiplier-1st.json

If compilation is successful, the following debug message will be printed on the command line,

Input Pol Commitments: 2
Q Pol Commitmets: 1
Constant Pols: 1
Im Pols: 1
plookupIdentities: 0
permutationIdentities: 0
connectionIdentities: 0
polIdentities: 1

The debug message reflects the numbers of;

  • Input committed polynomials, denoted by Input Pol Commitments\texttt{Input Pol Commitments}.
  • Quadratic polynomials, denoted by Q Pol Commitmets\texttt{Q Pol Commitmets}.
  • Constant polynomials, denoted by Constant Pols\texttt{Constant Pols}.
  • Intermediate polynomials, denoted by Im Pols\texttt{Im Pols}.
  • The various identities that can be checked; the Plookup\texttt{Plookup}, the Permutation\texttt{Permutation}, the connection\texttt{connection} and the Polynomial\texttt{Polynomial} identities.

The resulting JSON\texttt{JSON} file into which the multiplier.pil code is compiled looks like this:

{
  "name": "multiplier_sm",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

This JSON\texttt{JSON} file contains all the information needed by the proof/verification package called pil-stark\texttt{pil-stark} for processing.

Edit on GitHub

Last updated on