Isekai (https://github.com/sikoba/isekai) is a verifiable computation framework that will allow to work with several programming languages and verifiable computation systems while using a single code-to-circuit module. This article provides a quick and basic intro to installing isekai on Windows.

Install Ubuntu on Windows

isekai is written in Crystal, which has not yet been ported to Windows. Therefore, the first step is to install a Linux subsystem.

To enable the “Windows Subsystem for Linux” feature (as described here), open Windows PowerShell as Administrator and run:

PS C:\>Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

You will be asked to restart Windows.

Next, install “Ubuntu 18.04 LTS” which can be found in the Microsoft Store. There are actually three Ubuntu apps in the store, one of which is simply called “Ubuntu” (I also installed it but was unable to complete the isekai installation on it) and “Ubuntu 16.04 LTS” (which I have not tried).

NB1: This install was done on a laptop running Windows 10.

NB2: Another option is to install a Ubuntu virtual machine image, these are available for VitrualBox and VMWare. I have a working install on VirtualBox, which is free, but getting Ubuntu to work properly was tricky and the performance is not great, so I’ve mostly stopped using it.

Install Crystal

Installing Crystal is straightforward, just follow the official instructions for Debian and Ubuntu.

$ curl -sL "https://keybase.io/crystal/pgp_keys.asc" | sudo apt-key add - $ echo "deb https://dist.crystal-lang.org/apt crystal main" | sudo tee /etc/apt/sources.list.d/crystal.list $ sudo apt-get update $ sudo apt install crystal

Then install the recommended packages (only libgmp-dev is actually required for isekai):

$ sudo apt install libssl-dev

$ sudo apt install libxml2-dev

$ sudo apt install libyaml-dev

$ sudo apt install libgmp-dev

$ sudo apt install libreadline-dev

$ sudo apt install libz-dev

Install packages required by isekai

Install some additional packages that are required by isekai

$ sudo apt install clang-7

$ sudo apt install libclang-7-dev

$ sudo apt-get install libprocps-dev

Clone isekai

Clone isekai from https://github.com/sikoba/isekai to a local directory. In Windows, this is most easily done using GitHub Desktop. Note that the default branch is called develop, the master branch is currently not used.

Let’s assume that isekai was cloned to the local directory C:\isekai. In the Ubuntu subsystem, this corresponds to /mnt/c/isekai/. Let’s cd into that directory and verify that the repository is up to date — if it is, the message should be “Already up to date.”

$ git pull

Apply libclang patch

Next we must apply a libclang patch which has not yet been merged into libclang. This is done from the docker subdirectory.

$ cd docker/

$ cp bin/libclang.so.gz /tmp/libclang.so.gz

$ gzip -d /tmp/libclang.so.gz

$ sudo cp /tmp/libclang.so /usr/lib/x86_64-linux-gnu/libclang-7.so.1

$ sudo cp /tmp/libclang.so /usr/lib/libclang.so.7

$ cd ..

Install isekai

Now we’re ready to actually install isekai.

$ cd /mnt/c/isekai/

$ make

$ make test

The result of make test should end with something resembling this:

...

Finished in 800.85 milliseconds

9 examples, 0 failures, 0 errors, 0 pending

Some tests with isekai

To test isekai, we need a C program and some input values. Let’s take the following very simple program zkex.c:

#include "zkex.h" void outsource(struct Input *input, struct NzikInput *nzik, struct Output *output)

{

output->x = input->d + nzik->a + 5 - nzik->b * 2;

}

It references the header file zkex.h:

#pragma once struct Input {

int d;

}; struct NzikInput {

int a, b;

}; struct Output {

int x;

}; void outsource(struct Input *input, struct NzikInput *nzik, struct Output *output);

We also need the file zkex.c.in which contains the input values, first the public input (struct Inputs), then the hidden inputs (struct NzikInputs):

11

5

17

We can now generate the arithmetic circuit corresponding to our C program. Let’s output it to zkex.arith:

$ ../isekai --arith=zkex.arith zkex.c

This will generate the file zkex.arith which, for small programs, can be inspected visually and compared to the source code:

total 12

input 0 # one-input

nizkinput 1 # input

input 2 # input

nizkinput 3 # input

const-mul-0 in 1 <0> out 1 <4> # zero

const-mul-2 in 1 <3> out 1 <5> # multiply-by-constant 2

const-mul-ffffffff in 1 <5> out 1 <6> # multiply-by-constant 4294967295

const-mul-5 in 1 <0> out 1 <7> # constant 5

add in 2 <2 1> out 1 <8> # #<Isekai::ArithAddReq:0x7f46e1d7eb40>

add in 2 <8 7> out 1 <9> # #<Isekai::ArithAddReq:0x7f46e1d7ed80>

add in 2 <9 6> out 1 <10> # #<Isekai::ArithAddReq:0x7f46e1d7edc0>

mul in 2 <0 10> out 1 <11> # output-cast

output 11 #

It will also generate the file zkex.arith.in which contains, in order: the public input value (line 0), the value 1 which always has to be present (line 1), then the hidden values (lines 2 and 3). Note that these values are in hexadecimal:

0 b

1 1

2 5

3 11

Next, we can generate the R1CS, which we can for example output to the file zkex.j1 (this will implicitly use inputs from zkex.c.in):

$ ../isekai --r1cs=zkex.j1 zkex.c

In addition to zkex.j1, this will also generate zkex.j1.in which contains the inputs. Note that isekai generates the artithmetic circuit in order to create the R1CS, but it does not save it to the filesystem unless the “--arith” flag is used.

Now we are ready to generate a snark proof for zkex.j1. Let’s call this proof zkex.snark:

$ ../isekai --snark=zkex.snark zkex.j1

This will generate zkex.snark.s which is the trusted setup file, and the proof file zkex.snark.p. (In a real-world scenario we would of course not generate a trusted setup at this stage… but isekai is still under development and not yet intended for production use)

To verify the proof, we can run:

../isekai --verif=zkex.snark zkex.j1.in

The resulting output messages should end with:

...

* The verification result2 is: PASS

Congratulations, the proof is correct!

This is not very useful, however, because the hidden “witness” variables are actually included in zkex.j1.in. To verify the proof in zero knowledge, what we need to do is create zkex.j1.public.in containing only the private inputs, then run:

../isekai --verif=zkex.snark zkex.j1.private.in

Finally, you can try to modify one of the inputs and check that the verification fails: