Skip to content

Latest commit

 

History

History
59 lines (52 loc) · 5.39 KB

README.md

File metadata and controls

59 lines (52 loc) · 5.39 KB

Code Previews

For illustration purposes, this file includes snapshots from the examples currently implemented in the framework. The sample_generated_intermediate_code directory shows examples of the intermediate java files that xJsnark generates after processing the code below.

Examples

SHA-256 (Unpadded)

This is a high-level code for SHA-256. Compared to manually-developed circuit in low-level libraries such as libsnark gadget libraries or jsnark, in which the programmer has to take care of the range of the variables, and write optimizations for maj and ch computations, xJsnark aims to produce optimized circuits from the high-level code, whenever possible. The back end applies several techniques to minimize the number of constraints which leads to an optimized implementation. alt text

RSA Secret Key Knowledge

This example illustrates the support for long integer types and operations by xJsnark. alt text

RSA Modular Exponentiation

This example shows how to use the long integer modular arithmetic supported by xJsnark to implement modular exponentiation for RSA. This is supported through a type for the multiplicative group of integers modulo N. See the code for more notes. This version includes examples for fixed modulus fixed exponent and fixed modulus variable exponent. Support for types with variable modulus has not been pushed to the front end of this version yet. Note that Jsnark has implementations that can support all these cases and includes the optimizations of xJsnark.

Fixed modulus and fixed exponent: alt text

Fixed modulus and variable exponent: alt text

EC Secret Key Knowledge

This example illustrates the parameterized field types that can be defined by the user. Even, if the circuit operates in a non-native zk-SNARK field, the complexity of the code does not change. These field types are not only for making programming easier, but also the back end utilizes these information to make much better decisions.

Field Definition

alt text

EC Secret Key Knowledge Circuit

alt text

AES 128

This example applies an improved technique for S-Box implementation in the back end. To use random access memories in xJsnark, where the index accessed is a circuit variable, the programmer can use the RAM type. Internally, the back end explores the different techniques available for representing the memory accesses and chooses the most efficient implementation based on the workload and several other factors (more optimizations will be added to the memory implementation in the future). alt text

Sudoku 9x9

This example illustrates the usage of native finite field types/constraints and builti-in permutation verification to build a zk-SNARK circuit that proves the knowledge of a valid Sudoku solution. alt text

Sorting

This example illustrates how to use the external code blocks for non-determinism (setting the values of the external witnesses provided by the prover), and the usage of the permutation verification native instruction which could enable writing more optimized circuits for some applications, like sorting, or pointer chasing. alt text

ZeroCash Pour Circuit

High-level implementation of the Pour circuit in the ZeroCash paper, that results into an optimized circuit similar to the manually-optimized circuit.

Helper Classes

These are structures that are used within the Pour circuit. Each structure can only have xJsnark types, and can have methods. However, inheritance and polymorphism are not supported for xJsnark's structs.

Coin Information

alt text

Merkle Authentication Path

alt text

Keys

alt text

Digest

alt text

Pour Circuit

alt text