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.

174 lines
5.2 KiB

  1. package parsers
  2. import (
  3. "io/ioutil"
  4. "os"
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/stretchr/testify/require"
  8. )
  9. func TestParseArrayG1(t *testing.T) {
  10. aS := [][]string{
  11. {
  12. "16145916318196730299582072104388453231952213805668281741813587224450782397538",
  13. "4434505318477484327659527264104806919103674231447634885054368605283938696207",
  14. "1",
  15. },
  16. {
  17. "10618406967550056457559358662746625591602641004174976323307214433994084907915",
  18. "1843236360452735081347085412539192450068665510574800388201121698908391533923",
  19. "1",
  20. },
  21. {
  22. "1208972877970123411566574123860641832032384890981476033353526096830198333194",
  23. "777503551507025252294438107100944741641946695980350712141258191590862204805",
  24. "1",
  25. },
  26. {
  27. "0",
  28. "1",
  29. "0",
  30. },
  31. }
  32. a, err := arrayStringToG1(aS)
  33. assert.Nil(t, err)
  34. assert.Equal(t, "bn256.G1(23b243c928ce40c4cc2dad366e9f61723aef65866e1c66f42a08697f2f030462, 09cdd7500688fb487ec9f27b5a732d68fa0f3ddca5c2c790e330fdfb03b77c0f)", a[0].String())
  35. assert.Equal(t, "bn256.G1(1779ce2c586b5fc523e72e755d969a63473052aaad7c11eb5bf0ecdcfdfefb8b, 04133c1c74206dace57cd3d76ce59be381bbf08f51a5b3edc2b0c183d43eed63)", a[1].String())
  36. assert.Equal(t, "bn256.G1(02ac4120598d2f2bb81bc09b8df596403360577b0c5ff52485d1ef2200f23f0a, 01b80d298de75f867d6484c55c3da02c042bb4eb9a1734d3386786aaa669af85)", a[2].String())
  37. assert.Equal(t, "bn256.G1(0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000000000000001)", a[3].String())
  38. }
  39. func TestParseG2(t *testing.T) {
  40. aS := [][]string{
  41. {
  42. "9283666785342556550467669770956850930982548182701254051508520248901282197973",
  43. "11369378229277445316894458966429873744779877313900506577160370623273013178252",
  44. },
  45. {
  46. "10625777544326349817513295021482494426101347915428005055375725845993157551870",
  47. "21401790227434807639472120486932615400751346915707967674912972446672152512583",
  48. },
  49. {
  50. "1",
  51. "0",
  52. },
  53. }
  54. a, err := stringToG2(aS)
  55. assert.Nil(t, err)
  56. assert.Equal(t, "bn256.G2((1922d70c934543aa655ec3277f7fa10a25ec973a4f001a7c54ce4954b4916f8c, 14865e836947c42cf35b47d30e06535fff9dab319c4296e28afde368960671d5), (2f50fbe77925b0a9d718c9ab38638bafa7c65f43f0d09035e518df97ad294847, 177dfa1a3b8627faf0425d9511bcb4c6ca986ea05e3803b5c643c35b94a7e6fe))", a.String())
  57. aS = [][]string{
  58. {
  59. "13973091636763944887728510851169742544309374663995476311690518173988838518856",
  60. "12903946180439304546475897520537621821375470264150438270817301786763517825250",
  61. },
  62. {
  63. "370374369234123593044872519351942112043402224488849374153134091815693350697",
  64. "17423079115073430837335625309232513526393852743032331213038909731579295753224",
  65. },
  66. {
  67. "1",
  68. "0",
  69. },
  70. }
  71. a, err = stringToG2(aS)
  72. assert.Nil(t, err)
  73. assert.Equal(t, "bn256.G2((1c875fed67fff3b35f115b03706ec45f281b5f6cc71a99107240e09fce4910e2, 1ee47d566e9a099626b9860bcd96f6d4a1ed65f115d3efa8e05e5f42cc793048), (26851d022ce9961df65a430811824aaf3118710ac03b0614a50c05ee27d8e408, 00d19fdce25b0d78fb317a5f1789823b7ed76274b0d1be9c685792c73b347729))", a.String())
  74. }
  75. func TestParseArrayG2(t *testing.T) {
  76. aS := [][][]string{
  77. {
  78. {
  79. "0",
  80. "0",
  81. },
  82. {
  83. "1",
  84. "0",
  85. },
  86. {
  87. "0",
  88. "0",
  89. },
  90. },
  91. {
  92. {
  93. "0",
  94. "0",
  95. },
  96. {
  97. "1",
  98. "0",
  99. },
  100. {
  101. "0",
  102. "0",
  103. },
  104. },
  105. {
  106. {
  107. "0",
  108. "0",
  109. },
  110. {
  111. "1",
  112. "0",
  113. },
  114. {
  115. "0",
  116. "0",
  117. },
  118. },
  119. {
  120. {
  121. "9283666785342556550467669770956850930982548182701254051508520248901282197973",
  122. "11369378229277445316894458966429873744779877313900506577160370623273013178252",
  123. },
  124. {
  125. "10625777544326349817513295021482494426101347915428005055375725845993157551870",
  126. "21401790227434807639472120486932615400751346915707967674912972446672152512583",
  127. },
  128. {
  129. "1",
  130. "0",
  131. },
  132. },
  133. }
  134. a, err := arrayStringToG2(aS)
  135. assert.Nil(t, err)
  136. assert.Equal(t, "bn256.G2((0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000000000000000), (0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000000000000001))", a[0].String())
  137. assert.Equal(t, "bn256.G2((1922d70c934543aa655ec3277f7fa10a25ec973a4f001a7c54ce4954b4916f8c, 14865e836947c42cf35b47d30e06535fff9dab319c4296e28afde368960671d5), (2f50fbe77925b0a9d718c9ab38638bafa7c65f43f0d09035e518df97ad294847, 177dfa1a3b8627faf0425d9511bcb4c6ca986ea05e3803b5c643c35b94a7e6fe))", a[3].String())
  138. }
  139. func testCircuitParseWitnessBin(t *testing.T, circuit string) {
  140. witnessBinFile, err := os.Open("../testdata/" + circuit + "/witness.bin")
  141. require.Nil(t, err)
  142. defer witnessBinFile.Close()
  143. witness, err := ParseWitnessBin(witnessBinFile)
  144. require.Nil(t, err)
  145. witnessJson, err := ioutil.ReadFile("../testdata/" + circuit + "/witness.json")
  146. require.Nil(t, err)
  147. w, err := ParseWitness(witnessJson)
  148. require.Nil(t, err)
  149. assert.Equal(t, len(w), len(witness))
  150. assert.Equal(t, w[0], witness[0])
  151. assert.Equal(t, w[1], witness[1])
  152. assert.Equal(t, w[10], witness[10])
  153. assert.Equal(t, w[len(w)-3], witness[len(w)-3])
  154. assert.Equal(t, w[len(w)-2], witness[len(w)-2])
  155. assert.Equal(t, w[len(w)-1], witness[len(w)-1])
  156. }
  157. func TestParseWitnessBin(t *testing.T) {
  158. testCircuitParseWitnessBin(t, "circuit1k")
  159. testCircuitParseWitnessBin(t, "circuit5k")
  160. }