go-snark/circuitcompiler/circuit_test.go
circuitcompiler/circuit_test.goRaw
1package circuitcompiler
2
3import (
4 "fmt"
5 "strings"
6 "testing"
7
8 "github.com/stretchr/testify/assert"
9)
10
11func TestCircuitParser(t *testing.T) {
12 /*
13 input:
14 def test():
15 y = x**3
16 return x + y + 5
17
18 flattened:
19 m1 = s1 * s1
20 m2 = m1 * s1
21 m3 = m2 + s1
22 out = m3 + 5
23 */
24
25 // flat code
26 flat := `
27 func test(x):
28 aux = x*x
29 y = aux*x
30 z = x + y
31 out = z + 5
32 `
33 parser := NewParser(strings.NewReader(flat))
34 circuit, err := parser.Parse()
35 assert.Nil(t, err)
36 fmt.Println(circuit)
37
38 // flat code to R1CS
39 fmt.Println("generating R1CS from flat code")
40 circuit.GenerateR1CS()
41 fmt.Println(circuit.Inputs)
42}