You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
624 B

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