zkevm-rom 0.0.1-security → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of zkevm-rom might be problematic. Click here for more details.

Files changed (232) hide show
  1. package/.eslintrc.js +33 -0
  2. package/.github/CODEOWNERS +14 -0
  3. package/.github/ISSUE_TEMPLATE/bug.yml +38 -0
  4. package/.github/ISSUE_TEMPLATE/feature.yml +26 -0
  5. package/.github/ISSUE_TEMPLATE/question.yml +26 -0
  6. package/.github/workflows/main.yaml +40 -0
  7. package/LICENSE +636 -0
  8. package/README.md +23 -5
  9. package/audits/Hexens_Polygon_zkEVM_PUBLIC_27.02.23.pdf +0 -0
  10. package/audits/Polygon-zkEVM-Public-v1.1-verichains-19-03-2024.pdf +0 -0
  11. package/audits/zkEVM-ROM-upgrade-1-Spearbit-30-May.pdf +0 -0
  12. package/audits/zkEVM-ROM-upgrade-2-Spearbit-21-August.pdf +0 -0
  13. package/audits/zkEVM-engagement-1-Spearbit-27-March.pdf +0 -0
  14. package/audits/zkEVM-engagement-2-Spearbit-27-March.pdf +0 -0
  15. package/audits/zkEVM-engagement-3-Spearbit-6-April.pdf +0 -0
  16. package/counters/README.md +45 -0
  17. package/counters/counters-executor.js +80 -0
  18. package/counters/countersConstants.zkasm +370 -0
  19. package/counters/endIncludes.zkasm +18 -0
  20. package/counters/initIncludes.zkasm +2 -0
  21. package/counters/tests/MLOAD32.zkasm +27 -0
  22. package/counters/tests/MLOADX.zkasm +30 -0
  23. package/counters/tests/MSTORE32.zkasm +32 -0
  24. package/counters/tests/MSTOREX.zkasm +36 -0
  25. package/counters/tests/SHLarith.zkasm +28 -0
  26. package/counters/tests/SHLarithBit.zkasm +28 -0
  27. package/counters/tests/SHRarith.zkasm +28 -0
  28. package/counters/tests/SHRarithBit.zkasm +28 -0
  29. package/counters/tests/abs.zkasm +29 -0
  30. package/counters/tests/addBatchHashByteByByte.zkasm +31 -0
  31. package/counters/tests/computeGasSendCall.zkasm +30 -0
  32. package/counters/tests/divArith.zkasm +27 -0
  33. package/counters/tests/expAD.zkasm +30 -0
  34. package/counters/tests/getLenBits.zkasm +30 -0
  35. package/counters/tests/getLenBytes.zkasm +32 -0
  36. package/counters/tests/isEmptyAccount.zkasm +30 -0
  37. package/counters/tests/mulARITH.zkasm +28 -0
  38. package/counters/tests/offsetUtil.zkasm +29 -0
  39. package/counters/tests/opADDMOD.zkasm +28 -0
  40. package/counters/tests/opAdd.zkasm +27 -0
  41. package/counters/tests/opBLOCKHASH.zkasm +28 -0
  42. package/counters/tests/opCALL.zkasm +41 -0
  43. package/counters/tests/opCALLCODE.zkasm +41 -0
  44. package/counters/tests/opCALLDATACOPY.zkasm +28 -0
  45. package/counters/tests/opCALLDATALOAD.zkasm +27 -0
  46. package/counters/tests/opCODECOPY.zkasm +28 -0
  47. package/counters/tests/opCREATE.zkasm +35 -0
  48. package/counters/tests/opCREATE2.zkasm +35 -0
  49. package/counters/tests/opDELEGATECALL.zkasm +35 -0
  50. package/counters/tests/opDIV.zkasm +27 -0
  51. package/counters/tests/opEXP.zkasm +29 -0
  52. package/counters/tests/opEXTCODECOPY.zkasm +29 -0
  53. package/counters/tests/opMOD.zkasm +27 -0
  54. package/counters/tests/opMUL.zkasm +27 -0
  55. package/counters/tests/opMULMOD.zkasm +28 -0
  56. package/counters/tests/opRETURN.zkasm +32 -0
  57. package/counters/tests/opRETURNDATACOPY.zkasm +29 -0
  58. package/counters/tests/opREVERT.zkasm +32 -0
  59. package/counters/tests/opSDIV.zkasm +28 -0
  60. package/counters/tests/opSHA3.zkasm +28 -0
  61. package/counters/tests/opSIGNEXTEND.zkasm +27 -0
  62. package/counters/tests/opSMOD.zkasm +28 -0
  63. package/counters/tests/opSTATICCALL.zkasm +35 -0
  64. package/counters/tests/opSUB.zkasm +27 -0
  65. package/counters/tests/saveMem.zkasm +31 -0
  66. package/docs/opcode-cost-zk-counters.md +315 -0
  67. package/docs/usage-ecrecover.md +51 -0
  68. package/index.js +43 -0
  69. package/main/block-info.zkasm +204 -0
  70. package/main/constants.zkasm +145 -0
  71. package/main/ecrecover/addFpEc.zkasm +31 -0
  72. package/main/ecrecover/checkSqrtFpEc.zkasm +1558 -0
  73. package/main/ecrecover/constEc.zkasm +13 -0
  74. package/main/ecrecover/ecrecover.zkasm +280 -0
  75. package/main/ecrecover/invFnEc.zkasm +44 -0
  76. package/main/ecrecover/invFpEc.zkasm +45 -0
  77. package/main/ecrecover/mulFnEc.zkasm +36 -0
  78. package/main/ecrecover/mulFpEc.zkasm +36 -0
  79. package/main/ecrecover/mulPointEc.zkasm +311 -0
  80. package/main/ecrecover/sqFpEc.zkasm +38 -0
  81. package/main/ecrecover/sqrtFpEc.zkasm +70 -0
  82. package/main/end.zkasm +4 -0
  83. package/main/l2-tx-hash.zkasm +159 -0
  84. package/main/load-change-l2-block-utils.zkasm +11 -0
  85. package/main/load-change-l2-block.zkasm +28 -0
  86. package/main/load-tx-rlp-utils.zkasm +72 -0
  87. package/main/load-tx-rlp.zkasm +431 -0
  88. package/main/main.zkasm +237 -0
  89. package/main/map-opcodes.zkasm +274 -0
  90. package/main/modexp/array_lib/array_add_AGTB.zkasm +123 -0
  91. package/main/modexp/array_lib/array_add_short.zkasm +85 -0
  92. package/main/modexp/array_lib/array_div.zkasm +215 -0
  93. package/main/modexp/array_lib/array_div_long.zkasm +284 -0
  94. package/main/modexp/array_lib/array_div_short.zkasm +222 -0
  95. package/main/modexp/array_lib/array_mul.zkasm +97 -0
  96. package/main/modexp/array_lib/array_mul_long.zkasm +156 -0
  97. package/main/modexp/array_lib/array_mul_short.zkasm +127 -0
  98. package/main/modexp/array_lib/array_square.zkasm +246 -0
  99. package/main/modexp/array_lib/unused/array_add.zkasm +100 -0
  100. package/main/modexp/array_lib/unused/array_is_odd.zkasm +23 -0
  101. package/main/modexp/array_lib/unused/array_is_one.zkasm +33 -0
  102. package/main/modexp/array_lib/unused/array_is_zero.zkasm +34 -0
  103. package/main/modexp/array_lib/unused/array_sub_AGTB.zkasm +111 -0
  104. package/main/modexp/array_lib/unused/array_unshift.zkasm +37 -0
  105. package/main/modexp/array_lib/utils/array_compare.zkasm +82 -0
  106. package/main/modexp/array_lib/utils/array_trim.zkasm +49 -0
  107. package/main/modexp/constants.zkasm +5 -0
  108. package/main/modexp/modexp.zkasm +296 -0
  109. package/main/modexp/modexp_utils.zkasm +230 -0
  110. package/main/opcodes/arithmetic.zkasm +357 -0
  111. package/main/opcodes/block.zkasm +163 -0
  112. package/main/opcodes/calldata-returndata-code.zkasm +619 -0
  113. package/main/opcodes/comparison.zkasm +446 -0
  114. package/main/opcodes/context-information.zkasm +169 -0
  115. package/main/opcodes/create-terminate-context.zkasm +1011 -0
  116. package/main/opcodes/crypto.zkasm +96 -0
  117. package/main/opcodes/flow-control.zkasm +126 -0
  118. package/main/opcodes/logs.zkasm +193 -0
  119. package/main/opcodes/stack-operations.zkasm +658 -0
  120. package/main/opcodes/storage-memory.zkasm +313 -0
  121. package/main/pairings/BN254/addPointBN254.zkasm +245 -0
  122. package/main/pairings/BN254/ecAdd.zkasm +312 -0
  123. package/main/pairings/BN254/ecMul.zkasm +159 -0
  124. package/main/pairings/BN254/escalarMulBN254.zkasm +155 -0
  125. package/main/pairings/BN254/lineDiffPointsBN254.zkasm +83 -0
  126. package/main/pairings/BN254/lineSamePointsBN254.zkasm +96 -0
  127. package/main/pairings/FP12BN254/CYCLOFP12BN254/compressFp12BN254.zkasm +49 -0
  128. package/main/pairings/FP12BN254/CYCLOFP12BN254/decompressFp12BN254.zkasm +236 -0
  129. package/main/pairings/FP12BN254/CYCLOFP12BN254/expByXCompCycloFp12BN254.zkasm +444 -0
  130. package/main/pairings/FP12BN254/CYCLOFP12BN254/squareCompCycloFp12BN254.zkasm +212 -0
  131. package/main/pairings/FP12BN254/CYCLOFP12BN254/squareCycloFp12BN254.zkasm +228 -0
  132. package/main/pairings/FP12BN254/CYCLOFP12BN254/xBinDecompBN254.zkasm +64 -0
  133. package/main/pairings/FP12BN254/frob2Fp12BN254.zkasm +80 -0
  134. package/main/pairings/FP12BN254/frob3Fp12BN254.zkasm +96 -0
  135. package/main/pairings/FP12BN254/frobFp12BN254.zkasm +96 -0
  136. package/main/pairings/FP12BN254/inverseFp12BN254.zkasm +289 -0
  137. package/main/pairings/FP12BN254/mulFp12BN254.zkasm +408 -0
  138. package/main/pairings/FP12BN254/sparseMulAFp12BN254.zkasm +296 -0
  139. package/main/pairings/FP12BN254/sparseMulBFp12BN254.zkasm +291 -0
  140. package/main/pairings/FP12BN254/squareFp12BN254.zkasm +376 -0
  141. package/main/pairings/FP2BN254/addFp2BN254.zkasm +19 -0
  142. package/main/pairings/FP2BN254/escalarMulFp2BN254.zkasm +20 -0
  143. package/main/pairings/FP2BN254/invFp2BN254.zkasm +66 -0
  144. package/main/pairings/FP2BN254/mulFp2BN254.zkasm +19 -0
  145. package/main/pairings/FP2BN254/squareFp2BN254.zkasm +21 -0
  146. package/main/pairings/FP2BN254/subFp2BN254.zkasm +19 -0
  147. package/main/pairings/FP4BN254/squareFp4BN254.zkasm +76 -0
  148. package/main/pairings/FP6BN254/addFp6BN254.zkasm +59 -0
  149. package/main/pairings/FP6BN254/escalarMulFp6BN254.zkasm +51 -0
  150. package/main/pairings/FP6BN254/inverseFp6BN254.zkasm +208 -0
  151. package/main/pairings/FP6BN254/mulFp6BN254.zkasm +201 -0
  152. package/main/pairings/FP6BN254/sparseMulAFp6BN254.zkasm +65 -0
  153. package/main/pairings/FP6BN254/sparseMulBFp6BN254.zkasm +134 -0
  154. package/main/pairings/FP6BN254/sparseMulCFp6BN254.zkasm +128 -0
  155. package/main/pairings/FP6BN254/squareFp6BN254.zkasm +147 -0
  156. package/main/pairings/FP6BN254/subFp6BN254.zkasm +59 -0
  157. package/main/pairings/FPBN254/addFpBN254.zkasm +29 -0
  158. package/main/pairings/FPBN254/invFpBN254.zkasm +55 -0
  159. package/main/pairings/FPBN254/mulFpBN254.zkasm +29 -0
  160. package/main/pairings/FPBN254/reduceFpBN254.zkasm +25 -0
  161. package/main/pairings/FPBN254/squareFpBN254.zkasm +31 -0
  162. package/main/pairings/FPBN254/subFpBN254.zkasm +36 -0
  163. package/main/pairings/FRBN254/reduceFrBN254.zkasm +25 -0
  164. package/main/pairings/constants.zkasm +62 -0
  165. package/main/pairings/ecPairing.zkasm +244 -0
  166. package/main/pairings/finalExpBN254.zkasm +2095 -0
  167. package/main/pairings/halfPairingBN254.zkasm +428 -0
  168. package/main/pairings/loopLengthBN254.zkasm +75 -0
  169. package/main/pairings/millerLoopBN254.zkasm +741 -0
  170. package/main/pairings/pairingBN254.zkasm +481 -0
  171. package/main/pairings/unused/addFp12BN254.zkasm +130 -0
  172. package/main/pairings/unused/expByXCycloFp12BN254.zkasm +411 -0
  173. package/main/pairings/unused/expFp12BN254.zkasm +333 -0
  174. package/main/pairings/unused/subFp12BN254.zkasm +130 -0
  175. package/main/pairings/unused/xPseudoBinDecompBN254.zkasm +68 -0
  176. package/main/pairings/utilsTests/expCycloFp12BN254.zkasm +334 -0
  177. package/main/precompiled/end.zkasm +42 -0
  178. package/main/precompiled/identity.zkasm +99 -0
  179. package/main/precompiled/pre-ecAdd.zkasm +84 -0
  180. package/main/precompiled/pre-ecMul.zkasm +82 -0
  181. package/main/precompiled/pre-ecPairing.zkasm +72 -0
  182. package/main/precompiled/pre-ecrecover.zkasm +71 -0
  183. package/main/precompiled/pre-modexp.zkasm +367 -0
  184. package/main/precompiled/pre-sha2-256.zkasm +125 -0
  185. package/main/precompiled/revert-precompiled.zkasm +25 -0
  186. package/main/precompiled/selector.zkasm +77 -0
  187. package/main/process-change-l2-block.zkasm +147 -0
  188. package/main/process-tx.zkasm +587 -0
  189. package/main/tables/2-exp.zkasm +260 -0
  190. package/main/touched.zkasm +118 -0
  191. package/main/utils.zkasm +2335 -0
  192. package/main/vars.zkasm +117 -0
  193. package/package.json +62 -3
  194. package/test/bytes-length.zkasm +39 -0
  195. package/test/ecrecover.zkasm +538 -0
  196. package/test/lt4-test.zkasm +38 -0
  197. package/test/mstorex.zkasm +191 -0
  198. package/test/opcalldatacopy.ignore.zkasm +331 -0
  199. package/test/performance/read-push.zkasm +71 -0
  200. package/test/read-push.zkasm +304 -0
  201. package/test/testArrayArith.zkasm +1099 -0
  202. package/test/testArrayUtils.zkasm +335 -0
  203. package/test/testCycloFp12ArithBN254.zkasm +548 -0
  204. package/test/testEcAdd.zkasm +252 -0
  205. package/test/testEcMul.zkasm +231 -0
  206. package/test/testEcPairing.zkasm +436 -0
  207. package/test/testFinalExpBn254.zkasm +139 -0
  208. package/test/testFp12ArithBN254.zkasm +692 -0
  209. package/test/testFp2ArithBN254.zkasm +185 -0
  210. package/test/testFp4ArithBN254.zkasm +128 -0
  211. package/test/testFp6ArithBN254.zkasm +260 -0
  212. package/test/testFpArithBN254.zkasm +159 -0
  213. package/test/testFrArithBN254.zkasm +113 -0
  214. package/test/testHalfPairingBN254.zkasm +285 -0
  215. package/test/testModExp.zkasm +586 -0
  216. package/test/testModExpReturn.zkasm +81 -0
  217. package/test/testPairingBN254.zkasm +463 -0
  218. package/test/testPointArithBN254.zkasm +270 -0
  219. package/test/testSHA256.zkasm +27 -0
  220. package/test/touched-assert.zkasm +59 -0
  221. package/test/utils-expAD.zkasm +48 -0
  222. package/test/utils-getLenBytes.zkasm +36 -0
  223. package/tools/audit-tools/registry-op-checker.js +71 -0
  224. package/tools/get-not-used-labels.js +31 -0
  225. package/tools/helpers/helpers.js +47 -0
  226. package/tools/modexp-utils/README.md +5 -0
  227. package/tools/modexp-utils/modexp-test-gen.js +168 -0
  228. package/tools/modexp-utils/modexp-test-int.sage +37 -0
  229. package/tools/parallel-testing/checker.sh +6 -0
  230. package/tools/parallel-testing/gen-parallel-tests.js +78 -0
  231. package/tools/parallel-testing/parallel-tests-sample/sample.test.js +136 -0
  232. package/tools/run-tests-zkasm.js +83 -0
@@ -0,0 +1,312 @@
1
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
+ ;; POST: The resulting coordinates are in the range [0,BN254_P) because if falls back to FP arithmetic
3
+ ;;
4
+ ;; ecAdd:
5
+ ;; in: P1 = (P1.x, P1.y), P2 = (P2.x, P2.y) ∈ E(Fp)
6
+ ;; out: P1 + P2 = (P3.x, P3.y) ∈ E(Fp)
7
+ ;;
8
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9
+
10
+ ; Since the curve is E/Fp: y² = x³ + 3, there is no issue in representing the point at infinity as (0, 0).
11
+
12
+ VAR GLOBAL ecAdd_P1_x
13
+ VAR GLOBAL ecAdd_P1_y
14
+ VAR GLOBAL ecAdd_P1_y_inv
15
+ VAR GLOBAL ecAdd_P2_x
16
+ VAR GLOBAL ecAdd_P2_y
17
+ VAR GLOBAL ecAdd_P3_x
18
+ VAR GLOBAL ecAdd_P3_y
19
+ VAR GLOBAL ecAdd_lambda
20
+
21
+ VAR GLOBAL ecAdd_RR
22
+
23
+ ; ERROR CODES (B)
24
+ ; 0 - no error
25
+ ; 1 - P1_x is too big
26
+ ; 2 - P1_y is too big
27
+ ; 3 - P2_x is too big
28
+ ; 4 - P2_y is too big
29
+ ; 5 - P1 is not in E(Fp)
30
+ ; 6 - P2 is not in E(Fp)
31
+
32
+ ecAdd:
33
+ RR :MSTORE(ecAdd_RR)
34
+
35
+ %BN254_P_MINUS_ONE => A
36
+ $ => B :MLOAD(ecAdd_P1_x)
37
+ $ :LT, JMPC(ecAdd_P1x_too_big)
38
+ $ => B :MLOAD(ecAdd_P1_y)
39
+ $ :LT, JMPC(ecAdd_P1y_too_big)
40
+ $ => B :MLOAD(ecAdd_P2_x)
41
+ $ :LT, JMPC(ecAdd_P2x_too_big)
42
+ $ => B :MLOAD(ecAdd_P2_y)
43
+ $ :LT, JMPC(ecAdd_P2y_too_big)
44
+
45
+ ; Is P1 = O?
46
+ 0n => B
47
+ $ => A :MLOAD(ecAdd_P1_x)
48
+ $ :EQ, JMPNC(__ecAdd_P1_continue)
49
+ $ => A :MLOAD(ecAdd_P1_y)
50
+ $ :EQ, JMPC(ecAdd_P1_is_zero)
51
+ __ecAdd_P1_continue:
52
+
53
+ ; Is P2 = O?
54
+ 0n => B
55
+ $ => A :MLOAD(ecAdd_P2_x)
56
+ $ :EQ, JMPNC(__ecAdd_P2_continue1)
57
+ $ => A :MLOAD(ecAdd_P2_y)
58
+ $ :EQ, JMPC(ecAdd_P2_is_zero)
59
+ __ecAdd_P2_continue1:
60
+
61
+ ; 1] Check if P1 is in E(Fp)
62
+ ; P1 in E iff (P1.y)² == (P1.x)³ + 3 (mod p)
63
+ ; 1.1] Compute LHS and RHS
64
+ $ => A :MLOAD(ecAdd_P1_x), CALL(squareFpBN254)
65
+ ; B = (P1.x)²
66
+
67
+ $ => A :MLOAD(ecAdd_P1_x), CALL(mulFpBN254)
68
+ ; C = (P1.x)³
69
+
70
+ %BN254_E_B => A :CALL(addFpBN254)
71
+ ; C = (P1.x)³ + 3
72
+ C :MSTORE(ecAdd_P3_x)
73
+
74
+ $ => A :MLOAD(ecAdd_P1_y), CALL(squareFpBN254)
75
+ ; B = (Py)²
76
+
77
+ ; 1.2] Check if LHS == RHS
78
+ B => A
79
+ $ => B :MLOAD(ecAdd_P3_x)
80
+ $ :EQ, JMPNC(ecAdd_P1_is_not_in_E)
81
+
82
+ ; 2] check if P2 is in E(Fp)
83
+ ; P2 in E iff (P2.y)² == (P2.x)³ + 3 (mod p)
84
+ ; 2.1] Compute LHS and RHS
85
+ $ => A :MLOAD(ecAdd_P2_x), CALL(squareFpBN254)
86
+ ; B = (P2.x)²
87
+
88
+ $ => A :MLOAD(ecAdd_P2_x), CALL(mulFpBN254)
89
+ ; C = (P2.x)³
90
+
91
+ %BN254_E_B => A :CALL(addFpBN254)
92
+ ; C = (P2.x)³ + 3
93
+ C :MSTORE(ecAdd_P3_x)
94
+
95
+ $ => A :MLOAD(ecAdd_P2_y), CALL(squareFpBN254)
96
+ ; B = (Py)²
97
+
98
+ ; 2.2] Check if LHS == RHS
99
+ B => A
100
+ $ => B :MLOAD(ecAdd_P3_x)
101
+ $ :EQ, JMPNC(ecAdd_P2_is_not_in_E)
102
+
103
+ ; P1 and P2 are not 0, let's check whether they are different points, the same point or inverses of each other
104
+ $ => A :MLOAD(ecAdd_P1_x)
105
+ $ => B :MLOAD(ecAdd_P2_x)
106
+
107
+ ; Is P1.x == P2.x?
108
+ $ :EQ, JMPNC(ecAdd_different)
109
+
110
+ $ => A :MLOAD(ecAdd_P1_y)
111
+ $ => B :MLOAD(ecAdd_P2_y)
112
+
113
+ ; Is P1.y == P2.y?
114
+ $ :EQ, JMPNC(ecAdd_P1_and_P2_are_inverted)
115
+
116
+ ; P1 == P2
117
+ :JMP(ecAdd_same)
118
+
119
+ ecAdd_P1_is_zero:
120
+ ; Is P2 = 0?
121
+ 0n => B
122
+ $ => A :MLOAD(ecAdd_P2_x)
123
+ $ :EQ, JMPNC(__ecAdd_P2_continue2)
124
+ $ => A :MLOAD(ecAdd_P2_y)
125
+ $ :EQ, JMPC(ecAdd_P1_and_P2_are_zero)
126
+ __ecAdd_P2_continue2:
127
+
128
+ ; P2 in E iff (P2.y)² == (P2.x)³ + 3 (mod p)
129
+ ; 1] Compute LHS and RHS
130
+ $ => A :MLOAD(ecAdd_P2_x), CALL(squareFpBN254)
131
+ ; B = (P2.x)²
132
+
133
+ $ => A :MLOAD(ecAdd_P2_x), CALL(mulFpBN254)
134
+ ; C = (P2.x)³
135
+
136
+ %BN254_E_B => A :CALL(addFpBN254)
137
+ ; C = (P2.x)³ + 3
138
+ C :MSTORE(ecAdd_P3_x)
139
+
140
+ $ => A :MLOAD(ecAdd_P2_y), CALL(squareFpBN254)
141
+ ; B = (Py)²
142
+
143
+ ; 2] Check if LHS == RHS
144
+ B => A
145
+ $ => B :MLOAD(ecAdd_P3_x)
146
+ $ :EQ, JMPNC(ecAdd_P2_is_not_in_E)
147
+
148
+ ; P3 = P2
149
+ $ => A :MLOAD(ecAdd_P2_x)
150
+ $ => B :MLOAD(ecAdd_P2_y)
151
+ A :MSTORE(ecAdd_P3_x)
152
+ B :MSTORE(ecAdd_P3_y)
153
+
154
+ :JMP(ecAdd_correct)
155
+
156
+ ecAdd_P2_is_zero:
157
+ ; P1 in E iff (P1.y)² == (P1.x)³ + 3 (mod p)
158
+ ; 1] Compute LHS and RHS
159
+ $ => A :MLOAD(ecAdd_P1_x), CALL(squareFpBN254)
160
+ ; B = (P1.x)²
161
+
162
+ $ => A :MLOAD(ecAdd_P1_x), CALL(mulFpBN254)
163
+ ; C = (P1.x)³
164
+
165
+ %BN254_E_B => A :CALL(addFpBN254)
166
+ ; C = (P1.x)³ + 3
167
+ C :MSTORE(ecAdd_P3_x)
168
+
169
+ $ => A :MLOAD(ecAdd_P1_y), CALL(squareFpBN254)
170
+ ; B = (Py)²
171
+
172
+ ; 2] Check if LHS == RHS
173
+ B => A
174
+ $ => B :MLOAD(ecAdd_P3_x)
175
+ $ :EQ, JMPNC(ecAdd_P1_is_not_in_E)
176
+
177
+ ; P3 = P1
178
+ $ => A :MLOAD(ecAdd_P1_x)
179
+ $ => B :MLOAD(ecAdd_P1_y)
180
+ A :MSTORE(ecAdd_P3_x)
181
+ B :MSTORE(ecAdd_P3_y)
182
+
183
+ :JMP(ecAdd_correct)
184
+
185
+ ecAdd_P1_and_P2_are_zero:
186
+ ; P3 = 0
187
+ 0n :MSTORE(ecAdd_P3_x)
188
+ 0n :MSTORE(ecAdd_P3_y)
189
+
190
+ :JMP(ecAdd_correct)
191
+
192
+ ecAdd_P1_and_P2_are_inverted:
193
+ ; P3 = 0
194
+ 0n :MSTORE(ecAdd_P3_x)
195
+ 0n :MSTORE(ecAdd_P3_y)
196
+
197
+ :JMP(ecAdd_correct)
198
+
199
+ ecAdd_same:
200
+ $ => A :MLOAD(ecAdd_P1_y)
201
+ $ => C :MLOAD(ecAdd_P1_y), CALL(addFpBN254)
202
+ ; C = 2y
203
+
204
+ C => A :CALL(invFpBN254)
205
+ ; B = 1 / 2y
206
+ B :MSTORE(ecAdd_P1_y_inv)
207
+
208
+ B => A,C :CALL(addFpBN254)
209
+ C => A
210
+ $ => C :MLOAD(ecAdd_P1_y_inv), CALL(addFpBN254)
211
+ ; C = 3/2y
212
+
213
+ C => A
214
+ $ => B :MLOAD(ecAdd_P1_x), CALL(mulFpBN254)
215
+ ; C = 3x/2y
216
+
217
+ C => A
218
+ $ => B :MLOAD(ecAdd_P1_x), CALL(mulFpBN254)
219
+ ; C = lambda = 3x²/2y
220
+
221
+ C :MSTORE(ecAdd_lambda)
222
+ ; C = lambda
223
+
224
+ C => A :CALL(squareFpBN254)
225
+ ; B = lambda²
226
+
227
+ B => A
228
+ $ => C :MLOAD(ecAdd_P1_x), CALL(subFpBN254)
229
+ ; C = lambda² - x
230
+
231
+ C => A
232
+ $ => C :MLOAD(ecAdd_P1_x), CALL(subFpBN254)
233
+ ; C = lambda² - x - x
234
+
235
+ :JMP(ecAdd_common_calculate)
236
+
237
+ ecAdd_different:
238
+ $ => A :MLOAD(ecAdd_P2_x)
239
+ $ => C :MLOAD(ecAdd_P1_x), CALL(subFpBN254)
240
+ ; C = P2.x - P1.x
241
+
242
+ C => A :CALL(invFpBN254)
243
+ ; B = 1 / (P2.x - P1.x)
244
+ B :MSTORE(ecAdd_lambda)
245
+
246
+ $ => A :MLOAD(ecAdd_P2_y)
247
+ $ => C :MLOAD(ecAdd_P1_y), CALL(subFpBN254)
248
+ ; C = P2.y - P1.y
249
+
250
+ C => A
251
+ $ => B :MLOAD(ecAdd_lambda), CALL(mulFpBN254)
252
+ ; C = lambda = (P2.y - P1.y) / (P2.x - P1.x)
253
+ C :MSTORE(ecAdd_lambda)
254
+
255
+ C => A :CALL(squareFpBN254)
256
+ ; B = lambda²
257
+
258
+ B => A
259
+ $ => C :MLOAD(ecAdd_P1_x), CALL(subFpBN254)
260
+ ; C = lambda² - P1.x
261
+
262
+ C => A
263
+ $ => C :MLOAD(ecAdd_P2_x), CALL(subFpBN254)
264
+ ; C = lambda² - P1.x - P2.x
265
+
266
+ ecAdd_common_calculate:
267
+ C :MSTORE(ecAdd_P3_x)
268
+ ; P3.x = lambda² - P1.x - P2.x
269
+
270
+ $ => A :MLOAD(ecAdd_P1_x), CALL(subFpBN254)
271
+ ; C = P1.x - P3.x
272
+
273
+ $ => A :MLOAD(ecAdd_lambda)
274
+ C => B :CALL(mulFpBN254)
275
+ ; C = lambda·(P1.x - P3.x)
276
+
277
+ C => A
278
+ $ => C :MLOAD(ecAdd_P1_y), CALL(subFpBN254)
279
+ ; C = lambda·(P1.x - P3.x) - P1.y
280
+
281
+ C :MSTORE(ecAdd_P3_y)
282
+
283
+ :JMP(ecAdd_correct)
284
+
285
+ ; ERRORS
286
+ ecAdd_P1x_too_big:
287
+ 1 => B :JMP(ecAdd_error)
288
+
289
+ ecAdd_P1y_too_big:
290
+ 2 => B :JMP(ecAdd_error)
291
+
292
+ ecAdd_P2x_too_big:
293
+ 3 => B :JMP(ecAdd_error)
294
+
295
+ ecAdd_P2y_too_big:
296
+ 4 => B :JMP(ecAdd_error)
297
+
298
+ ecAdd_P1_is_not_in_E:
299
+ 5 => B :JMP(ecAdd_error)
300
+
301
+ ecAdd_P2_is_not_in_E:
302
+ 6 => B :JMP(ecAdd_error)
303
+
304
+ ecAdd_correct:
305
+ 0 => B :JMP(ecAdd_end)
306
+
307
+ ecAdd_error:
308
+ 0 => A
309
+
310
+ ecAdd_end:
311
+ $ => RR :MLOAD(ecAdd_RR)
312
+ :RETURN
@@ -0,0 +1,159 @@
1
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
+ ;; POST: The resulting coordinates are in the range [0,BN254_P) because if falls back to FP arithmetic
3
+ ;;
4
+ ;; ecMul:
5
+ ;; in: k, P = (P.x, P.y) ∈ E(Fp), where k ∈ [0,r-1]
6
+ ;; out: k·P = (Q.x, Q.y) ∈ E(Fp)
7
+ ;;
8
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9
+
10
+ ; Since the curve is E/Fp: y² = x³ + 3, there is no issue in representing the point at infinity as (0, 0).
11
+
12
+ VAR GLOBAL ecMul_k
13
+ VAR GLOBAL ecMul_P_x
14
+ VAR GLOBAL ecMul_P_y
15
+ VAR GLOBAL ecMul_Q_x
16
+ VAR GLOBAL ecMul_Q_y
17
+
18
+ VAR GLOBAL ecMul_RR
19
+
20
+ ; ERROR CODES (B)
21
+ ; 0 - no error
22
+ ; 1 - P_x is too big
23
+ ; 2 - P_y is too big
24
+ ; 3 - P is not in E(Fp)
25
+
26
+ ecMul:
27
+ RR :MSTORE(ecMul_RR)
28
+
29
+ %BN254_P_MINUS_ONE => A
30
+ $ => B :MLOAD(ecMul_P_x)
31
+ $ :LT, JMPC(ecMul_Px_too_big)
32
+ $ => B :MLOAD(ecMul_P_y)
33
+ $ :LT, JMPC(ecMul_Py_too_big)
34
+
35
+ ; Is P = O?
36
+ 0n => B
37
+ $ => A :MLOAD(ecMul_P_x)
38
+ $ :EQ, JMPNC(__ecMul_P_continue)
39
+ $ => A :MLOAD(ecMul_P_y)
40
+ $ :EQ, JMPC(ecMul_P_is_zero)
41
+ __ecMul_P_continue:
42
+
43
+ ; 1] Check if P is in E(Fp)
44
+ ; P in E iff (P.y)² == (P.x)³ + 3 (mod p)
45
+ ; 1.1] Compute LHS and RHS
46
+ $ => A :MLOAD(ecMul_P_x), CALL(squareFpBN254)
47
+ ; B = (P.x)²
48
+
49
+ $ => A :MLOAD(ecMul_P_x), CALL(mulFpBN254)
50
+ ; C = (P.x)³
51
+
52
+ %BN254_E_B => A :CALL(addFpBN254)
53
+ ; C = (P.x)³ + 3
54
+ C :MSTORE(ecMul_Q_x)
55
+
56
+ $ => A :MLOAD(ecMul_P_y), CALL(squareFpBN254)
57
+ ; B = (Py)²
58
+
59
+ ; 1.2] Check if LHS == RHS
60
+ B => A
61
+ $ => B :MLOAD(ecMul_Q_x)
62
+ $ :EQ, JMPNC(ecMul_P_is_not_in_E)
63
+
64
+ ; Is k ∈ [1,r-1]?
65
+ $ => B :MLOAD(ecMul_k), CALL(reduceFrBN254)
66
+ A :MSTORE(ecMul_k)
67
+ 0n => B
68
+ $ :EQ, JMPC(ecMul_k_is_zero)
69
+
70
+ 257 => RCX
71
+
72
+ $ => A :MLOAD(ecMul_P_x)
73
+ $ => C :MLOAD(ecMul_P_y)
74
+ A :MSTORE(ecMul_Q_x)
75
+ C :MSTORE(ecMul_Q_y)
76
+
77
+ :JMP(ecMul_find_MSB_k)
78
+
79
+ ecMul_P_is_zero:
80
+ ; Q = O
81
+ 0n :MSTORE(ecMul_Q_x)
82
+ 0n :MSTORE(ecMul_Q_y)
83
+
84
+ :JMP(ecMul_correct)
85
+
86
+ ecMul_k_is_zero:
87
+ ; Q = O
88
+ 0n :MSTORE(ecMul_Q_x)
89
+ 0n :MSTORE(ecMul_Q_y)
90
+
91
+ :JMP(ecMul_correct)
92
+
93
+ ecMul_find_MSB_k:
94
+ RCX - 1 => RCX
95
+ $ => A,B :MLOAD(ecMul_k)
96
+ ; E = 2A
97
+ $ => E :ADD,MSTORE(ecMul_k), JMPNC(ecMul_find_MSB_k)
98
+
99
+
100
+ ecMul_loop:
101
+ RCX - 1 => RCX :JMPZ(ecMul_correct)
102
+
103
+ ; We always double
104
+ $ => A :MLOAD(ecMul_Q_x)
105
+ $ => B :MLOAD(ecMul_Q_y)
106
+ A :MSTORE(ecAdd_P1_x)
107
+ B :MSTORE(ecAdd_P1_y)
108
+ A :MSTORE(ecAdd_P2_x)
109
+ B :MSTORE(ecAdd_P2_y), CALL(ecAdd)
110
+ ; Q = Q + Q
111
+
112
+ $ => A :MLOAD(ecAdd_P3_x)
113
+ $ => B :MLOAD(ecAdd_P3_y)
114
+ A :MSTORE(ecMul_Q_x)
115
+ B :MSTORE(ecMul_Q_y)
116
+
117
+ ; We check if the MSB b of k is either 1 or 0. If b==1, we should add P to Q.
118
+ ; Then, update the value of k.
119
+ $ => A,B :MLOAD(ecMul_k)
120
+ ; E = 2A
121
+ $ => E :ADD, MSTORE(ecMul_k), JMPNC(ecMul_loop)
122
+
123
+ ecMul_add:
124
+ ; We add
125
+ $ => A :MLOAD(ecMul_Q_x)
126
+ $ => B :MLOAD(ecMul_Q_y)
127
+ $ => C :MLOAD(ecMul_P_x)
128
+ $ => D :MLOAD(ecMul_P_y)
129
+ A :MSTORE(ecAdd_P1_x)
130
+ B :MSTORE(ecAdd_P1_y)
131
+ C :MSTORE(ecAdd_P2_x)
132
+ D :MSTORE(ecAdd_P2_y), CALL(ecAdd)
133
+ ; Q = Q + P
134
+
135
+ $ => A :MLOAD(ecAdd_P3_x)
136
+ $ => B :MLOAD(ecAdd_P3_y)
137
+ A :MSTORE(ecMul_Q_x)
138
+ B :MSTORE(ecMul_Q_y), JMP(ecMul_loop)
139
+
140
+
141
+ ; ERRORS
142
+ ecMul_Px_too_big:
143
+ 1 => B :JMP(ecMul_error)
144
+
145
+ ecMul_Py_too_big:
146
+ 2 => B :JMP(ecMul_error)
147
+
148
+ ecMul_P_is_not_in_E:
149
+ 3 => B :JMP(ecMul_error)
150
+
151
+ ecMul_correct:
152
+ 0 => B :JMP(ecMul_end)
153
+
154
+ ecMul_error:
155
+ 0 => A
156
+
157
+ ecMul_end:
158
+ $ => RR :MLOAD(ecMul_RR)
159
+ :RETURN
@@ -0,0 +1,155 @@
1
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
+ ;; PRE: P ∈ E'(Fp2)
3
+ ;; POST: The resulting coordinates are in the range [0,BN254_P) because if falls back to addPointBN254
4
+ ;;
5
+ ;;
6
+ ;; escalarMulBN254:
7
+ ;; in: k, P = (P.x1 + P.x2·u, P.y1 + P.y2·u) ∈ E'(Fp2), where k ∈ [0,r-1]
8
+ ;; out: k·P = (Q.x1 + Q.x2·u, Q.y1 + Q.y2·u) ∈ E'(Fp2)
9
+ ;;
10
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11
+
12
+ ; escalarMulBN254 assumes P belong to E'(Fp2), since it is checked in the pairing.
13
+ ; However, it must be implemented if escalarMulBN254 wants to be used independently.
14
+
15
+ ; Since the curve is E'/Fp2: y² = x³ + 3/(9+u), there is no issue in representing the point at infinity as (0, 0).
16
+
17
+ VAR GLOBAL escalarMulBN254_k
18
+ VAR GLOBAL escalarMulBN254_P_x1
19
+ VAR GLOBAL escalarMulBN254_P_x2
20
+ VAR GLOBAL escalarMulBN254_P_y1
21
+ VAR GLOBAL escalarMulBN254_P_y2
22
+ VAR GLOBAL escalarMulBN254_Q_x1
23
+ VAR GLOBAL escalarMulBN254_Q_x2
24
+ VAR GLOBAL escalarMulBN254_Q_y1
25
+ VAR GLOBAL escalarMulBN254_Q_y2
26
+
27
+ VAR GLOBAL escalarMulBN254_RR
28
+
29
+
30
+ escalarMulBN254:
31
+ RR :MSTORE(escalarMulBN254_RR)
32
+
33
+ ; Is P = O?
34
+ 0n => B
35
+ $ => A :MLOAD(escalarMulBN254_P_x1)
36
+ $ :EQ, JMPNC(__escalarMulBN254_P_continue)
37
+ $ => A :MLOAD(escalarMulBN254_P_x2)
38
+ $ :EQ, JMPNC(__escalarMulBN254_P_continue)
39
+ $ => A :MLOAD(escalarMulBN254_P_y1)
40
+ $ :EQ, JMPNC(__escalarMulBN254_P_continue)
41
+ $ => A :MLOAD(escalarMulBN254_P_y2)
42
+ $ :EQ, JMPC(escalarMulBN254_P_is_zero)
43
+ __escalarMulBN254_P_continue:
44
+
45
+ ; Is k = 0?
46
+ $ => B :MLOAD(escalarMulBN254_k), CALL(reduceFrBN254)
47
+ A :MSTORE(escalarMulBN254_k)
48
+ 0n => B
49
+ $ :EQ, JMPC(escalarMulBN254_k_is_zero)
50
+
51
+ 257 => RCX
52
+
53
+ $ => A :MLOAD(escalarMulBN254_P_x1)
54
+ $ => B :MLOAD(escalarMulBN254_P_x2)
55
+ $ => C :MLOAD(escalarMulBN254_P_y1)
56
+ $ => D :MLOAD(escalarMulBN254_P_y2)
57
+ A :MSTORE(escalarMulBN254_Q_x1)
58
+ B :MSTORE(escalarMulBN254_Q_x2)
59
+ C :MSTORE(escalarMulBN254_Q_y1)
60
+ D :MSTORE(escalarMulBN254_Q_y2)
61
+
62
+ :JMP(escalarMulBN254_find_MSB_k)
63
+
64
+ escalarMulBN254_P_is_zero:
65
+ ; Q = O
66
+ 0n :MSTORE(escalarMulBN254_Q_x1)
67
+ 0n :MSTORE(escalarMulBN254_Q_x2)
68
+ 0n :MSTORE(escalarMulBN254_Q_y1)
69
+ 0n :MSTORE(escalarMulBN254_Q_y2)
70
+
71
+ :JMP(escalarMulBN254_end)
72
+
73
+ escalarMulBN254_k_is_zero:
74
+ ; Q = O
75
+ 0n :MSTORE(escalarMulBN254_Q_x1)
76
+ 0n :MSTORE(escalarMulBN254_Q_x2)
77
+ 0n :MSTORE(escalarMulBN254_Q_y1)
78
+ 0n :MSTORE(escalarMulBN254_Q_y2)
79
+
80
+ :JMP(escalarMulBN254_end)
81
+
82
+ escalarMulBN254_find_MSB_k:
83
+ RCX - 1 => RCX
84
+ $ => A,B :MLOAD(escalarMulBN254_k)
85
+ ; E = 2A
86
+ $ => E :ADD,MSTORE(escalarMulBN254_k), JMPNC(escalarMulBN254_find_MSB_k)
87
+
88
+
89
+ escalarMulBN254_loop:
90
+ RCX - 1 => RCX :JMPZ(escalarMulBN254_end)
91
+
92
+ ; We always double
93
+ $ => A :MLOAD(escalarMulBN254_Q_x1)
94
+ $ => B :MLOAD(escalarMulBN254_Q_x2)
95
+ $ => C :MLOAD(escalarMulBN254_Q_y1)
96
+ $ => D :MLOAD(escalarMulBN254_Q_y2)
97
+ A :MSTORE(addPointBN254_P1_x1)
98
+ B :MSTORE(addPointBN254_P1_x2)
99
+ C :MSTORE(addPointBN254_P1_y1)
100
+ D :MSTORE(addPointBN254_P1_y2)
101
+ A :MSTORE(addPointBN254_P2_x1)
102
+ B :MSTORE(addPointBN254_P2_x2)
103
+ C :MSTORE(addPointBN254_P2_y1)
104
+ D :MSTORE(addPointBN254_P2_y2), CALL(addPointBN254)
105
+ ; Q = Q + Q
106
+
107
+ $ => A :MLOAD(addPointBN254_P3_x1)
108
+ $ => B :MLOAD(addPointBN254_P3_x2)
109
+ $ => C :MLOAD(addPointBN254_P3_y1)
110
+ $ => D :MLOAD(addPointBN254_P3_y2)
111
+ A :MSTORE(escalarMulBN254_Q_x1)
112
+ B :MSTORE(escalarMulBN254_Q_x2)
113
+ C :MSTORE(escalarMulBN254_Q_y1)
114
+ D :MSTORE(escalarMulBN254_Q_y2)
115
+
116
+ ; We check if the MSB b of k is either 1 or 0. If b==1, we should add P to Q.
117
+ ; Then, update the value of k.
118
+ $ => A,B :MLOAD(escalarMulBN254_k)
119
+ ; E = 2A
120
+ $ => E :ADD,MSTORE(escalarMulBN254_k), JMPNC(escalarMulBN254_loop)
121
+
122
+ escalarMulBN254_add:
123
+ ; We add
124
+ $ => A :MLOAD(escalarMulBN254_Q_x1)
125
+ $ => B :MLOAD(escalarMulBN254_Q_x2)
126
+ $ => C :MLOAD(escalarMulBN254_Q_y1)
127
+ $ => D :MLOAD(escalarMulBN254_Q_y2)
128
+ A :MSTORE(addPointBN254_P1_x1)
129
+ B :MSTORE(addPointBN254_P1_x2)
130
+ C :MSTORE(addPointBN254_P1_y1)
131
+ D :MSTORE(addPointBN254_P1_y2)
132
+
133
+ $ => A :MLOAD(escalarMulBN254_P_x1)
134
+ $ => B :MLOAD(escalarMulBN254_P_x2)
135
+ $ => C :MLOAD(escalarMulBN254_P_y1)
136
+ $ => D :MLOAD(escalarMulBN254_P_y2)
137
+ A :MSTORE(addPointBN254_P2_x1)
138
+ B :MSTORE(addPointBN254_P2_x2)
139
+ C :MSTORE(addPointBN254_P2_y1)
140
+ D :MSTORE(addPointBN254_P2_y2), CALL(addPointBN254)
141
+ ; Q = Q + P
142
+
143
+ $ => A :MLOAD(addPointBN254_P3_x1)
144
+ $ => B :MLOAD(addPointBN254_P3_x2)
145
+ $ => C :MLOAD(addPointBN254_P3_y1)
146
+ $ => D :MLOAD(addPointBN254_P3_y2)
147
+ A :MSTORE(escalarMulBN254_Q_x1)
148
+ B :MSTORE(escalarMulBN254_Q_x2)
149
+ C :MSTORE(escalarMulBN254_Q_y1)
150
+ D :MSTORE(escalarMulBN254_Q_y2), JMP(escalarMulBN254_loop)
151
+
152
+
153
+ escalarMulBN254_end:
154
+ $ => RR :MLOAD(escalarMulBN254_RR)
155
+ :RETURN
@@ -0,0 +1,83 @@
1
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
+ ;; PRE: P1,P2 ∈ E'(Fp2) with P1 != P2,-P2 and Q ∈ E(Fp)
3
+ ;; POST: The result is in the range [0,BN254_P) because if falls back to FP2 arithmetic
4
+ ;;
5
+ ;; lineDiffPointsBN254:
6
+ ;; in: P1 = (P1.x1 + P1.x2·u, P1.y1 + P1.y2·u), P2 = (P2.x1 + P2.x2·u, P2.y1 + P2.y2·u) ∈ E'(Fp2)
7
+ ;; and Q = (Q.x,Q.y) ∈ E(Fp)
8
+ ;; out: line_{twist(P1), twist(P2)}(Q) = (P2.x - P1.x)·Q.y·w² + (P1.y - P2.y)·Q.x·w³ + (P1.x·P2.y - P2.x·P1.y)·w⁵ ∈ Fp12
9
+ ;;
10
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11
+
12
+ ; The precondition is ensured by the pairing.
13
+ ; However, it must be implemented if lineDiffPointsBN254 wants to be used independently.
14
+
15
+ VAR GLOBAL lineDiffPointsBN254_P1_x1
16
+ VAR GLOBAL lineDiffPointsBN254_P1_x2
17
+ VAR GLOBAL lineDiffPointsBN254_P1_y1
18
+ VAR GLOBAL lineDiffPointsBN254_P1_y2
19
+ VAR GLOBAL lineDiffPointsBN254_P2_x1
20
+ VAR GLOBAL lineDiffPointsBN254_P2_x2
21
+ VAR GLOBAL lineDiffPointsBN254_P2_y1
22
+ VAR GLOBAL lineDiffPointsBN254_P2_y2
23
+ VAR GLOBAL lineDiffPointsBN254_Q_x
24
+ VAR GLOBAL lineDiffPointsBN254_Q_y
25
+
26
+ VAR GLOBAL lineDiffPointsBN254_P2x_P1y_x
27
+ VAR GLOBAL lineDiffPointsBN254_P2x_P1y_y
28
+
29
+ VAR GLOBAL lineDiffPointsBN254_l12_x
30
+ VAR GLOBAL lineDiffPointsBN254_l12_y
31
+ VAR GLOBAL lineDiffPointsBN254_l22_x
32
+ VAR GLOBAL lineDiffPointsBN254_l22_y
33
+ VAR GLOBAL lineDiffPointsBN254_l23_x
34
+ VAR GLOBAL lineDiffPointsBN254_l23_y
35
+
36
+ VAR GLOBAL lineDiffPointsBN254_RR
37
+
38
+ lineDiffPointsBN254:
39
+ RR :MSTORE(lineDiffPointsBN254_RR)
40
+
41
+ ; 1] (P2.x - P1.x)·Q.y
42
+ $ => A :MLOAD(lineDiffPointsBN254_P2_x1)
43
+ $ => B :MLOAD(lineDiffPointsBN254_P2_x2)
44
+ $ => C :MLOAD(lineDiffPointsBN254_P1_x1)
45
+ $ => D :MLOAD(lineDiffPointsBN254_P1_x2), CALL(subFp2BN254)
46
+ $ => A :MLOAD(lineDiffPointsBN254_Q_y)
47
+ C => D
48
+ E => C :CALL(escalarMulFp2BN254)
49
+ E :MSTORE(lineDiffPointsBN254_l12_x)
50
+ C :MSTORE(lineDiffPointsBN254_l12_y)
51
+
52
+ ; 2] (P1.y - P2.y)·Q.x
53
+ $ => A :MLOAD(lineDiffPointsBN254_P1_y1)
54
+ $ => B :MLOAD(lineDiffPointsBN254_P1_y2)
55
+ $ => C :MLOAD(lineDiffPointsBN254_P2_y1)
56
+ $ => D :MLOAD(lineDiffPointsBN254_P2_y2), CALL(subFp2BN254)
57
+ $ => A :MLOAD(lineDiffPointsBN254_Q_x)
58
+ C => D
59
+ E => C :CALL(escalarMulFp2BN254)
60
+ E :MSTORE(lineDiffPointsBN254_l22_x)
61
+ C :MSTORE(lineDiffPointsBN254_l22_y)
62
+
63
+ ; 3] (P1.x·P2.y - P2.x·P1.y)
64
+ $ => A :MLOAD(lineDiffPointsBN254_P2_x1)
65
+ $ => B :MLOAD(lineDiffPointsBN254_P2_x2)
66
+ $ => C :MLOAD(lineDiffPointsBN254_P1_y1)
67
+ $ => D :MLOAD(lineDiffPointsBN254_P1_y2), CALL(mulFp2BN254)
68
+ E :MSTORE(lineDiffPointsBN254_P2x_P1y_x)
69
+ C :MSTORE(lineDiffPointsBN254_P2x_P1y_y)
70
+
71
+ $ => A :MLOAD(lineDiffPointsBN254_P1_x1)
72
+ $ => B :MLOAD(lineDiffPointsBN254_P1_x2)
73
+ $ => C :MLOAD(lineDiffPointsBN254_P2_y1)
74
+ $ => D :MLOAD(lineDiffPointsBN254_P2_y2), CALL(mulFp2BN254)
75
+ E => A
76
+ C => B
77
+ $ => C :MLOAD(lineDiffPointsBN254_P2x_P1y_x)
78
+ $ => D :MLOAD(lineDiffPointsBN254_P2x_P1y_y), CALL(subFp2BN254)
79
+ E :MSTORE(lineDiffPointsBN254_l23_x)
80
+ C :MSTORE(lineDiffPointsBN254_l23_y)
81
+
82
+ $ => RR :MLOAD(lineDiffPointsBN254_RR)
83
+ :RETURN