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.

128 lines
3.1 KiB

  1. package circuitcompiler
  2. import (
  3. //"fmt"
  4. ////"math/big"
  5. //"strings"
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestXor(t *testing.T) {
  10. assert.Equal(t, false, Xor(true, true))
  11. assert.Equal(t, true, Xor(true, false))
  12. assert.Equal(t, true, Xor(false, true))
  13. assert.Equal(t, false, Xor(false, false))
  14. }
  15. func TestCircuitParser(t *testing.T) {
  16. //flat := `
  17. //func main(a,b):
  18. // c = a / b
  19. // d = c * b
  20. // e = d - c
  21. // f = c * 55
  22. // out = f / e
  23. //`
  24. //flat := `
  25. //func test(a,b):
  26. // d = a / b
  27. // c = a + d
  28. // f = a * 55
  29. // g = a / d
  30. // h = g + f
  31. // i = c + h
  32. // out = i / c
  33. //`
  34. //parser := NewParser(strings.NewReader(flat))
  35. //programm, err := parser.Parse()
  36. //circuit := programm.getMainCircut()
  37. //assert.Nil(t, err)
  38. //fmt.Println("\n unreduced")
  39. //fmt.Println(flat)
  40. //fmt.Println("generating R1CS from flat code")
  41. //a, b, c := circuit.GenerateR1CS()
  42. //fmt.Println(a)
  43. //fmt.Println(b)
  44. //fmt.Println(c)
  45. //
  46. //a1 := big.NewInt(int64(6))
  47. //a2 := big.NewInt(int64(5))
  48. //inputs := []*big.Int{a1, a2}
  49. //// Calculate Witness
  50. //w, err := circuit.CalculateWitness(inputs)
  51. //assert.Nil(t, err)
  52. //fmt.Println("w", w)
  53. //fmt.Printf("inputs %s", circuit.Inputs)
  54. //fmt.Printf("signals %s", circuit.Signals)
  55. //
  56. //fmt.Println("Reduced Tree Parsing")
  57. //r := circuit.BuildConstraintTree()
  58. //constraintReduced := ReduceTree(r)
  59. //fmt.Printf("depth %v, mGates %v \n", printDepth(r, 0), CountMultiplicationGates(r))
  60. //printTree(r, 0)
  61. //
  62. //a,b,c,w = circuit.GenerateReducedR1CSandWitness(inputs,constraintReduced)
  63. //fmt.Println("\ngenerating R1CS from reduced flat code")
  64. //fmt.Println("\nR1CS:")
  65. //fmt.Println("a:", a)
  66. //fmt.Println("b:", b)
  67. //fmt.Println("c:", c)
  68. //fmt.Println("w", w)
  69. //// R1CS to QAP
  70. //alphas, betas, gammas, zxQAP := fields.R1CSToQAP(a, b, c)
  71. //fmt.Println("qap")
  72. //fmt.Println("alphas", len(alphas))
  73. //fmt.Println("alphas", alphas[0])
  74. //fmt.Println("betas", len(betas))
  75. //fmt.Println("gammas", len(gammas))
  76. //fmt.Println("zx length", len(zxQAP))
  77. //circuit.reduceAdditionGates()
  78. //
  79. //fmt.Println(circuit)
  80. //fmt.Println("generating R1CS from flat code")
  81. //a, b, c = circuit.GenerateR1CS()
  82. //
  83. //fmt.Println(a)
  84. //fmt.Println(b)
  85. //fmt.Println(c)
  86. //
  87. //// Calculate Witness
  88. //w, err = circuit.CalculateWitness(inputs)
  89. //assert.Nil(t, err)
  90. //fmt.Println("w", w)
  91. //// expected result
  92. //b0 := big.NewInt(int64(0))
  93. //b1 := big.NewInt(int64(1))
  94. //b5 := big.NewInt(int64(5))
  95. //aExpected := [][]*big.Int{
  96. // []*big.Int{b0, b0, b1, b0, b0, b0},
  97. // []*big.Int{b0, b0, b0, b1, b0, b0},
  98. // []*big.Int{b0, b0, b1, b0, b1, b0},
  99. // []*big.Int{b5, b0, b0, b0, b0, b1},
  100. //}
  101. //bExpected := [][]*big.Int{
  102. // []*big.Int{b0, b0, b1, b0, b0, b0},
  103. // []*big.Int{b0, b0, b1, b0, b0, b0},
  104. // []*big.Int{b1, b0, b0, b0, b0, b0},
  105. // []*big.Int{b1, b0, b0, b0, b0, b0},
  106. //}
  107. //cExpected := [][]*big.Int{
  108. // []*big.Int{b0, b0, b0, b1, b0, b0},
  109. // []*big.Int{b0, b0, b0, b0, b1, b0},
  110. // []*big.Int{b0, b0, b0, b0, b0, b1},
  111. // []*big.Int{b0, b1, b0, b0, b0, b0},
  112. //}
  113. //assert.Equal(t, aExpected, a)
  114. //assert.Equal(t, bExpected, b)
  115. //assert.Equal(t, cExpected, c)
  116. }