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.

154 lines
2.7 KiB

6 years ago
  1. const bigInt = require("big-integer");
  2. const __P__ = new bigInt("21888242871839275222246405745257275088696311157297823662689037894645226208583");
  3. const __MASK__ = new bigInt(2).pow(253).minus(1);
  4. const circuit = {};
  5. module.exports = circuit;
  6. circuit.signals={
  7. "one": {
  8. "fullName": "one",
  9. "value": "1",
  10. "equivalence": "",
  11. "direction": "",
  12. "id": 0
  13. },
  14. "main.s1": {
  15. "fullName": "main.s1",
  16. "direction": "IN",
  17. "component": "main",
  18. "equivalence": "",
  19. "alias": [
  20. "main.s1"
  21. ],
  22. "id": 1
  23. },
  24. "main.s2": {
  25. "fullName": "main.s2",
  26. "direction": "IN",
  27. "component": "main",
  28. "equivalence": "",
  29. "alias": [
  30. "main.s2"
  31. ],
  32. "id": 2
  33. },
  34. "main.s3": {
  35. "fullName": "main.s3",
  36. "direction": "OUT",
  37. "component": "main",
  38. "equivalence": "",
  39. "alias": [
  40. "main.s3"
  41. ],
  42. "id": 3
  43. }
  44. };
  45. circuit.components={
  46. "main": {
  47. "signals": [
  48. "main.s1",
  49. "main.s2",
  50. "main.s3"
  51. ],
  52. "params": {},
  53. "template": "AND",
  54. "inputSignals": 2
  55. }
  56. };
  57. circuit.signalConstrains=[
  58. {
  59. "type": "QEQ",
  60. "a": {
  61. "type": "LINEARCOMBINATION",
  62. "values": {
  63. "main.s1": "21888242871839275222246405745257275088696311157297823662689037894645226208582"
  64. }
  65. },
  66. "b": {
  67. "type": "LINEARCOMBINATION",
  68. "values": {
  69. "main.s2": "1"
  70. }
  71. },
  72. "c": {
  73. "type": "LINEARCOMBINATION",
  74. "values": {
  75. "main.s3": "1"
  76. }
  77. }
  78. },
  79. {
  80. "type": "QEQ",
  81. "a": {
  82. "type": "LINEARCOMBINATION",
  83. "values": {
  84. "main.s1": "1"
  85. }
  86. },
  87. "b": {
  88. "type": "LINEARCOMBINATION",
  89. "values": {
  90. "main.s1": "1",
  91. "one": "21888242871839275222246405745257275088696311157297823662689037894645226208582"
  92. }
  93. },
  94. "c": {
  95. "type": "LINEARCOMBINATION",
  96. "values": {}
  97. }
  98. },
  99. {
  100. "type": "QEQ",
  101. "a": {
  102. "type": "LINEARCOMBINATION",
  103. "values": {
  104. "main.s2": "1"
  105. }
  106. },
  107. "b": {
  108. "type": "LINEARCOMBINATION",
  109. "values": {
  110. "main.s2": "1",
  111. "one": "21888242871839275222246405745257275088696311157297823662689037894645226208582"
  112. }
  113. },
  114. "c": {
  115. "type": "LINEARCOMBINATION",
  116. "values": {}
  117. }
  118. }
  119. ];
  120. circuit.witnessNames=[
  121. [
  122. "one"
  123. ],
  124. [
  125. "main.s1"
  126. ],
  127. [
  128. "main.s2"
  129. ],
  130. [
  131. "main.s3"
  132. ]
  133. ];
  134. {
  135. }
  136. circuit.templates = {};
  137. circuit.templates["AND"] = function(ctx) {
  138. ctx.setSignal("s3", [], bigInt(ctx.getSignal("s1", [])).times(ctx.getSignal("s2", [])).mod(__P__));
  139. ctx.assert(ctx.getSignal("s3", []), bigInt(ctx.getSignal("s1", [])).times(ctx.getSignal("s2", [])).mod(__P__));
  140. ctx.assert(bigInt(ctx.getSignal("s1", [])).times(bigInt(ctx.getSignal("s1", [])).add(__P__).minus("1").mod(__P__)).mod(__P__), "0");
  141. ctx.assert(bigInt(ctx.getSignal("s2", [])).times(bigInt(ctx.getSignal("s2", [])).add(__P__).minus("1").mod(__P__)).mod(__P__), "0");
  142. }
  143. ;
  144. circuit.functionParams={};
  145. circuit.functions = {};