Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mottla/go-r1cs-compiler
A compiler to turn GO code into a zkSNARK
https://github.com/mottla/go-r1cs-compiler
arithmetic-circuit constraint gates golang groth16 language r1cs snark zk-snarks
Last synced: 12 days ago
JSON representation
A compiler to turn GO code into a zkSNARK
- Host: GitHub
- URL: https://github.com/mottla/go-r1cs-compiler
- Owner: mottla
- License: gpl-3.0
- Created: 2019-12-29T10:09:24.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-07-19T06:25:56.000Z (over 3 years ago)
- Last Synced: 2024-06-19T06:56:44.160Z (6 months ago)
- Topics: arithmetic-circuit, constraint, gates, golang, groth16, language, r1cs, snark, zk-snarks
- Language: Go
- Homepage:
- Size: 1.03 MB
- Stars: 16
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-R1CS Compiler
**UNDER CONSTRUCTION**
**Circuit Language**
A subset of Golang (with slight modifications), suitable for the creation of Non-Interactive Succinct Arguments, such as zkSNARKs.
This projects goal is to provide a compiler that translates Go-code into R1CS, which is the compilation target
and starting point for various zkSNARK constructions.-This compiler currently supports the creation of Groth16 zkSNARKs.
-Comes with JS graph rendering support to visualize the generated arithmetic circuit if needed.
# Language
## main
as in Go, every program starts with the function 'main'
```
func main(){
#this is a comment
}
```main can be fed with an arbitrary amount of single arguments and n-dimensional static size arrays of single values.
Main does not support functions as inputs.```
func main(a bool,b [2]uint32, c field, d uint64){}
```## Declare public inputs
In order to declare, which of the Main-Function inputs will be part of the public statement of the SNARK, write
```
func main(a bool,b [2][3]uint32, c field, d uint64){
public{
a,
b[1][1],
c
}
}
```## variables
Variable assignment and overloading follows the same logic as in Golang:
```
var a = 42*17 # is now a field type element
# var a = x*x -> Error- variable a already declared
# a = true -> type missmatch. Field expected, got bool
var b = uint32(235)#declare array
var c = [2]uint32{b,b+2}
#declare function. Functions can return functions or take them as arguments
var d = func(x field, b func()(bool) , c [4]bool)( func()(field)) {
return 42
}}
```## Function preloading
At this point we extended Go by this cool functionality.
One now can partially preload a function```
func main(x field){
var multiply = func(a field,b field)(field){return a*b}
var multiplyBy5 = multiply(5)
multiplyBy5(x) #is now the same as multiply(5,x)
}
```## Operations
| Operator | Description | Remark |
|----------|:-------------:|------:|
| + | addition | |
| * | multiplication | |
| - | subtraction | |
| / | division| |
| ** | exponentiation | *|
| << | left shift| * |
| >> | right-shift | * |
| <<< | rotate-left | * |
| >>> | rotate-right | * |
| & | bitwise-and | |
| | | bitwise-or | |
| ^ | bitwise-xor | |
| == | equality | |
| != | un-equality | |*rhs must be fixed at compile-time
## if-else if-else
in order to create braching conditions, write:
```
if expression1{
...
}else if expression2{
...
}else if expression3{
...
}else{
...
}
```note that we currently only support static decidable branching conditions
## arrays
tba.
# SNARK stuff
## euquality assertion gate
in order to create an equality assertion constraint write
```
equal(expression1,expression2)
```example: in order to prove knowledge of a square root of some input y, write
```
func main(x field,y field){
public{y}
equal(x*x,y)
}
```## split
to split a value into its bit representatives write
```
SPLIT(x)
```now the i'th bit of x can be accessed with x[i], where x[0] is the least significant bit