longfellow 0.1.0

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.
Files changed (289) hide show
  1. checksums.yaml +7 -0
  2. data/CODE_OF_CONDUCT.md +10 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +152 -0
  5. data/ext/longfellow/CMakeLists.txt +76 -0
  6. data/ext/longfellow/extconf.rb +77 -0
  7. data/lib/longfellow/attribute.rb +65 -0
  8. data/lib/longfellow/c.rb +105 -0
  9. data/lib/longfellow/errors.rb +78 -0
  10. data/lib/longfellow/version.rb +5 -0
  11. data/lib/longfellow/zk_spec.rb +40 -0
  12. data/lib/longfellow.rb +162 -0
  13. data/sig/longfellow.rbs +74 -0
  14. data/vendor/longfellow-zk/LICENSE +203 -0
  15. data/vendor/longfellow-zk/lib/algebra/blas.h +121 -0
  16. data/vendor/longfellow-zk/lib/algebra/bogorng.h +68 -0
  17. data/vendor/longfellow-zk/lib/algebra/compare.h +40 -0
  18. data/vendor/longfellow-zk/lib/algebra/convolution.h +219 -0
  19. data/vendor/longfellow-zk/lib/algebra/crt.cc +42 -0
  20. data/vendor/longfellow-zk/lib/algebra/crt.h +299 -0
  21. data/vendor/longfellow-zk/lib/algebra/crt_convolution.h +114 -0
  22. data/vendor/longfellow-zk/lib/algebra/crt_test.cc +371 -0
  23. data/vendor/longfellow-zk/lib/algebra/fft.h +104 -0
  24. data/vendor/longfellow-zk/lib/algebra/fft_interpolation.h +304 -0
  25. data/vendor/longfellow-zk/lib/algebra/fft_interpolation_test.cc +168 -0
  26. data/vendor/longfellow-zk/lib/algebra/fft_test.cc +257 -0
  27. data/vendor/longfellow-zk/lib/algebra/fp.h +59 -0
  28. data/vendor/longfellow-zk/lib/algebra/fp2.h +240 -0
  29. data/vendor/longfellow-zk/lib/algebra/fp24.h +342 -0
  30. data/vendor/longfellow-zk/lib/algebra/fp24_6.h +305 -0
  31. data/vendor/longfellow-zk/lib/algebra/fp24_6_test.cc +197 -0
  32. data/vendor/longfellow-zk/lib/algebra/fp2_test.cc +280 -0
  33. data/vendor/longfellow-zk/lib/algebra/fp_generic.h +533 -0
  34. data/vendor/longfellow-zk/lib/algebra/fp_p128.h +91 -0
  35. data/vendor/longfellow-zk/lib/algebra/fp_p256.h +68 -0
  36. data/vendor/longfellow-zk/lib/algebra/fp_p256k1.h +123 -0
  37. data/vendor/longfellow-zk/lib/algebra/fp_p384.h +65 -0
  38. data/vendor/longfellow-zk/lib/algebra/fp_p521.h +62 -0
  39. data/vendor/longfellow-zk/lib/algebra/fp_test.cc +522 -0
  40. data/vendor/longfellow-zk/lib/algebra/hash.h +39 -0
  41. data/vendor/longfellow-zk/lib/algebra/interpolation.h +117 -0
  42. data/vendor/longfellow-zk/lib/algebra/interpolation_test.cc +74 -0
  43. data/vendor/longfellow-zk/lib/algebra/limb.h +153 -0
  44. data/vendor/longfellow-zk/lib/algebra/limb_test.cc +75 -0
  45. data/vendor/longfellow-zk/lib/algebra/nat.cc +32 -0
  46. data/vendor/longfellow-zk/lib/algebra/nat.h +212 -0
  47. data/vendor/longfellow-zk/lib/algebra/nat_test.cc +183 -0
  48. data/vendor/longfellow-zk/lib/algebra/nussbaumer.h +400 -0
  49. data/vendor/longfellow-zk/lib/algebra/nussbaumer_test.cc +138 -0
  50. data/vendor/longfellow-zk/lib/algebra/nussbaumerfp2_test.cc +139 -0
  51. data/vendor/longfellow-zk/lib/algebra/permutations.h +79 -0
  52. data/vendor/longfellow-zk/lib/algebra/poly.h +240 -0
  53. data/vendor/longfellow-zk/lib/algebra/poly_test.cc +123 -0
  54. data/vendor/longfellow-zk/lib/algebra/reed_solomon.h +150 -0
  55. data/vendor/longfellow-zk/lib/algebra/reed_solomon_extension.h +108 -0
  56. data/vendor/longfellow-zk/lib/algebra/reed_solomon_extension_test.cc +76 -0
  57. data/vendor/longfellow-zk/lib/algebra/reed_solomon_test.cc +473 -0
  58. data/vendor/longfellow-zk/lib/algebra/rfft.h +400 -0
  59. data/vendor/longfellow-zk/lib/algebra/rfft_test.cc +102 -0
  60. data/vendor/longfellow-zk/lib/algebra/static_string.h +29 -0
  61. data/vendor/longfellow-zk/lib/algebra/sysdep.h +495 -0
  62. data/vendor/longfellow-zk/lib/algebra/sysdep_test.cc +41 -0
  63. data/vendor/longfellow-zk/lib/algebra/twiddle.h +59 -0
  64. data/vendor/longfellow-zk/lib/algebra/utility.h +86 -0
  65. data/vendor/longfellow-zk/lib/algebra/utility_test.cc +86 -0
  66. data/vendor/longfellow-zk/lib/arrays/affine.h +56 -0
  67. data/vendor/longfellow-zk/lib/arrays/affine_test.cc +220 -0
  68. data/vendor/longfellow-zk/lib/arrays/dense.h +210 -0
  69. data/vendor/longfellow-zk/lib/arrays/eq.h +75 -0
  70. data/vendor/longfellow-zk/lib/arrays/eqs.h +137 -0
  71. data/vendor/longfellow-zk/lib/arrays/eqs_test.cc +151 -0
  72. data/vendor/longfellow-zk/lib/arrays/sparse.h +192 -0
  73. data/vendor/longfellow-zk/lib/cbor/host_decoder.h +323 -0
  74. data/vendor/longfellow-zk/lib/cbor/host_decoder_test.cc +541 -0
  75. data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor.h +594 -0
  76. data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_byte_decoder.h +150 -0
  77. data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_byte_decoder_test.cc +147 -0
  78. data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_constants.h +27 -0
  79. data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_pluck.h +110 -0
  80. data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_pluck_test.cc +55 -0
  81. data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_test.cc +174 -0
  82. data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_testing.h +98 -0
  83. data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_witness.h +312 -0
  84. data/vendor/longfellow-zk/lib/circuits/cbor_parser/mso2_test.cc +662 -0
  85. data/vendor/longfellow-zk/lib/circuits/cbor_parser/mso_test.cc +485 -0
  86. data/vendor/longfellow-zk/lib/circuits/cbor_parser/scan.h +104 -0
  87. data/vendor/longfellow-zk/lib/circuits/cbor_parser/scan_test.cc +137 -0
  88. data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/cbor.h +640 -0
  89. data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/cbor_byte_decoder.h +150 -0
  90. data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/cbor_byte_decoder_test.cc +147 -0
  91. data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/cbor_constants.h +27 -0
  92. data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/cbor_testing.h +99 -0
  93. data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/cbor_witness.h +319 -0
  94. data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/lexer_test.cc +120 -0
  95. data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/mdoc_examples_test.cc +89 -0
  96. data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/parser_circuit_test.cc +506 -0
  97. data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/parser_size_test.cc +79 -0
  98. data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/parser_test.cc +473 -0
  99. data/vendor/longfellow-zk/lib/circuits/compiler/canonicalization_test.cc +185 -0
  100. data/vendor/longfellow-zk/lib/circuits/compiler/circuit_dump.h +65 -0
  101. data/vendor/longfellow-zk/lib/circuits/compiler/compiler.h +471 -0
  102. data/vendor/longfellow-zk/lib/circuits/compiler/compiler_test.cc +110 -0
  103. data/vendor/longfellow-zk/lib/circuits/compiler/node.h +176 -0
  104. data/vendor/longfellow-zk/lib/circuits/compiler/pdqhash.h +127 -0
  105. data/vendor/longfellow-zk/lib/circuits/compiler/schedule.h +435 -0
  106. data/vendor/longfellow-zk/lib/circuits/ecdsa/verify_circuit.h +371 -0
  107. data/vendor/longfellow-zk/lib/circuits/ecdsa/verify_external_test.cc +246 -0
  108. data/vendor/longfellow-zk/lib/circuits/ecdsa/verify_test.cc +587 -0
  109. data/vendor/longfellow-zk/lib/circuits/ecdsa/verify_witness.h +201 -0
  110. data/vendor/longfellow-zk/lib/circuits/logic/bit_adder.h +140 -0
  111. data/vendor/longfellow-zk/lib/circuits/logic/bit_adder_test.cc +64 -0
  112. data/vendor/longfellow-zk/lib/circuits/logic/bit_plucker.h +247 -0
  113. data/vendor/longfellow-zk/lib/circuits/logic/bit_plucker_constants.h +35 -0
  114. data/vendor/longfellow-zk/lib/circuits/logic/bit_plucker_encoder.h +72 -0
  115. data/vendor/longfellow-zk/lib/circuits/logic/bit_plucker_test.cc +183 -0
  116. data/vendor/longfellow-zk/lib/circuits/logic/compiler_backend.h +62 -0
  117. data/vendor/longfellow-zk/lib/circuits/logic/counter.h +171 -0
  118. data/vendor/longfellow-zk/lib/circuits/logic/counter_test.cc +102 -0
  119. data/vendor/longfellow-zk/lib/circuits/logic/evaluation_backend.h +94 -0
  120. data/vendor/longfellow-zk/lib/circuits/logic/logic.h +1232 -0
  121. data/vendor/longfellow-zk/lib/circuits/logic/logic_circuit_test.cc +310 -0
  122. data/vendor/longfellow-zk/lib/circuits/logic/logic_test.cc +521 -0
  123. data/vendor/longfellow-zk/lib/circuits/logic/memcmp.h +68 -0
  124. data/vendor/longfellow-zk/lib/circuits/logic/memcmp_test.cc +148 -0
  125. data/vendor/longfellow-zk/lib/circuits/logic/polynomial.h +94 -0
  126. data/vendor/longfellow-zk/lib/circuits/logic/polynomial_test.cc +62 -0
  127. data/vendor/longfellow-zk/lib/circuits/logic/routing.h +445 -0
  128. data/vendor/longfellow-zk/lib/circuits/logic/routing_test.cc +241 -0
  129. data/vendor/longfellow-zk/lib/circuits/logic/unary.h +55 -0
  130. data/vendor/longfellow-zk/lib/circuits/logic/unary_plucker.h +77 -0
  131. data/vendor/longfellow-zk/lib/circuits/logic/unary_plucker_constants.h +37 -0
  132. data/vendor/longfellow-zk/lib/circuits/logic/unary_plucker_test.cc +53 -0
  133. data/vendor/longfellow-zk/lib/circuits/logic/unary_size_test.cc +69 -0
  134. data/vendor/longfellow-zk/lib/circuits/logic/unary_test.cc +62 -0
  135. data/vendor/longfellow-zk/lib/circuits/mac/mac_circuit.h +193 -0
  136. data/vendor/longfellow-zk/lib/circuits/mac/mac_circuit_test.cc +223 -0
  137. data/vendor/longfellow-zk/lib/circuits/mac/mac_reference.h +72 -0
  138. data/vendor/longfellow-zk/lib/circuits/mac/mac_witness.h +94 -0
  139. data/vendor/longfellow-zk/lib/circuits/mdoc/circuit_maker.cc +242 -0
  140. data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_attribute_ids.h +311 -0
  141. data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_attribute_test.cc +64 -0
  142. data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_circuit_id.cc +85 -0
  143. data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_constants.h +85 -0
  144. data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_decompress.cc +41 -0
  145. data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_decompress.h +27 -0
  146. data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_examples.h +5232 -0
  147. data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_generate_circuit.cc +199 -0
  148. data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_hash.h +554 -0
  149. data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_signature.h +143 -0
  150. data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_signature_test.cc +444 -0
  151. data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_test_attributes.h +157 -0
  152. data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_witness.h +863 -0
  153. data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_zk.cc +693 -0
  154. data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_zk.h +216 -0
  155. data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_zk_test.cc +724 -0
  156. data/vendor/longfellow-zk/lib/circuits/mdoc/zk_spec.cc +100 -0
  157. data/vendor/longfellow-zk/lib/circuits/mdoc/zk_spec_test.cc +155 -0
  158. data/vendor/longfellow-zk/lib/circuits/sha/flatsha256_circuit.h +330 -0
  159. data/vendor/longfellow-zk/lib/circuits/sha/flatsha256_circuit_test.cc +607 -0
  160. data/vendor/longfellow-zk/lib/circuits/sha/flatsha256_io.h +26 -0
  161. data/vendor/longfellow-zk/lib/circuits/sha/flatsha256_witness.cc +163 -0
  162. data/vendor/longfellow-zk/lib/circuits/sha/flatsha256_witness.h +47 -0
  163. data/vendor/longfellow-zk/lib/circuits/sha/sha256_constants.cc +34 -0
  164. data/vendor/longfellow-zk/lib/circuits/sha/sha256_constants.h +27 -0
  165. data/vendor/longfellow-zk/lib/circuits/sha/sha256_test_values.h +389 -0
  166. data/vendor/longfellow-zk/lib/circuits/tests/anoncred/ptrcred.h +171 -0
  167. data/vendor/longfellow-zk/lib/circuits/tests/anoncred/small.h +218 -0
  168. data/vendor/longfellow-zk/lib/circuits/tests/anoncred/small_examples.h +118 -0
  169. data/vendor/longfellow-zk/lib/circuits/tests/anoncred/small_io.h +25 -0
  170. data/vendor/longfellow-zk/lib/circuits/tests/anoncred/small_test.cc +208 -0
  171. data/vendor/longfellow-zk/lib/circuits/tests/anoncred/small_witness.h +130 -0
  172. data/vendor/longfellow-zk/lib/circuits/tests/base64/decode.h +508 -0
  173. data/vendor/longfellow-zk/lib/circuits/tests/base64/decode_circuit_test.cc +95 -0
  174. data/vendor/longfellow-zk/lib/circuits/tests/base64/decode_test.cc +119 -0
  175. data/vendor/longfellow-zk/lib/circuits/tests/base64/decode_util.cc +47 -0
  176. data/vendor/longfellow-zk/lib/circuits/tests/base64/decode_util.h +29 -0
  177. data/vendor/longfellow-zk/lib/circuits/tests/ec/pk_circuit.h +231 -0
  178. data/vendor/longfellow-zk/lib/circuits/tests/ec/pk_circuit_test.cc +428 -0
  179. data/vendor/longfellow-zk/lib/circuits/tests/ec/pk_witness.h +102 -0
  180. data/vendor/longfellow-zk/lib/circuits/tests/jwt/jwt.h +190 -0
  181. data/vendor/longfellow-zk/lib/circuits/tests/jwt/jwt_constants.h +26 -0
  182. data/vendor/longfellow-zk/lib/circuits/tests/jwt/jwt_test.cc +559 -0
  183. data/vendor/longfellow-zk/lib/circuits/tests/jwt/jwt_witness.h +315 -0
  184. data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_1f.h +411 -0
  185. data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_1f_io.h +32 -0
  186. data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_1f_test.cc +364 -0
  187. data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_1f_witness.h +278 -0
  188. data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_revocation.h +146 -0
  189. data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_revocation_constants.h +25 -0
  190. data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_revocation_test.cc +315 -0
  191. data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_revocation_witness.h +136 -0
  192. data/vendor/longfellow-zk/lib/circuits/tests/pq/bitaddr/bitaddr.h +250 -0
  193. data/vendor/longfellow-zk/lib/circuits/tests/pq/bitaddr/bitaddr_test.cc +333 -0
  194. data/vendor/longfellow-zk/lib/circuits/tests/pq/bitaddr/bitaddr_witness.h +152 -0
  195. data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44.h +903 -0
  196. data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_circuit_test.cc +274 -0
  197. data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_eval_test.cc +440 -0
  198. data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_examples.cc +8851 -0
  199. data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_examples.h +93 -0
  200. data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_types.cc +24 -0
  201. data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_types.h +118 -0
  202. data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_witness.h +453 -0
  203. data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_witness_test.cc +49 -0
  204. data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_ref.cc +458 -0
  205. data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_ref.h +150 -0
  206. data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_ref_test.cc +398 -0
  207. data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_ref_test_vectors.inc +3618 -0
  208. data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_ref_test_vectors_pkdecode.inc +689 -0
  209. data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_ref_test_vectors_sigdecode.inc +1501 -0
  210. data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/sigdecode_test_vectors.inc +540 -0
  211. data/vendor/longfellow-zk/lib/circuits/tests/ripemd/ripemd_circuit.h +394 -0
  212. data/vendor/longfellow-zk/lib/circuits/tests/ripemd/ripemd_circuit_test.cc +577 -0
  213. data/vendor/longfellow-zk/lib/circuits/tests/ripemd/ripemd_constants.h +90 -0
  214. data/vendor/longfellow-zk/lib/circuits/tests/ripemd/ripemd_witness.cc +174 -0
  215. data/vendor/longfellow-zk/lib/circuits/tests/ripemd/ripemd_witness.h +140 -0
  216. data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_circuit.h +351 -0
  217. data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_circuit_test.cc +466 -0
  218. data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_reference.cc +207 -0
  219. data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_reference.h +59 -0
  220. data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_reference_test.cc +153 -0
  221. data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_round_constants.cc +39 -0
  222. data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_round_constants.h +29 -0
  223. data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_slicing.h +31 -0
  224. data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_witness.cc +83 -0
  225. data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_witness.h +72 -0
  226. data/vendor/longfellow-zk/lib/circuits/tests/sha3/shake_test_vectors.h +477 -0
  227. data/vendor/longfellow-zk/lib/ec/elliptic_curve.h +596 -0
  228. data/vendor/longfellow-zk/lib/ec/elliptic_curve_test.cc +548 -0
  229. data/vendor/longfellow-zk/lib/ec/p256.cc +36 -0
  230. data/vendor/longfellow-zk/lib/ec/p256.h +60 -0
  231. data/vendor/longfellow-zk/lib/ec/p256k1.cc +34 -0
  232. data/vendor/longfellow-zk/lib/ec/p256k1.h +60 -0
  233. data/vendor/longfellow-zk/lib/gf2k/gf2_128.h +503 -0
  234. data/vendor/longfellow-zk/lib/gf2k/gf2_128_bench.cc +48 -0
  235. data/vendor/longfellow-zk/lib/gf2k/gf2_128_test.cc +416 -0
  236. data/vendor/longfellow-zk/lib/gf2k/gf2poly.h +74 -0
  237. data/vendor/longfellow-zk/lib/gf2k/lch14.h +242 -0
  238. data/vendor/longfellow-zk/lib/gf2k/lch14_bench.cc +75 -0
  239. data/vendor/longfellow-zk/lib/gf2k/lch14_reed_solomon.h +127 -0
  240. data/vendor/longfellow-zk/lib/gf2k/lch14_reed_solomon_test.cc +110 -0
  241. data/vendor/longfellow-zk/lib/gf2k/lch14_test.cc +246 -0
  242. data/vendor/longfellow-zk/lib/gf2k/sysdep.h +329 -0
  243. data/vendor/longfellow-zk/lib/ligero/ligero_param.h +449 -0
  244. data/vendor/longfellow-zk/lib/ligero/ligero_prover.h +354 -0
  245. data/vendor/longfellow-zk/lib/ligero/ligero_test.cc +136 -0
  246. data/vendor/longfellow-zk/lib/ligero/ligero_transcript.h +67 -0
  247. data/vendor/longfellow-zk/lib/ligero/ligero_verifier.h +272 -0
  248. data/vendor/longfellow-zk/lib/merkle/merkle_commitment.h +104 -0
  249. data/vendor/longfellow-zk/lib/merkle/merkle_tree.h +216 -0
  250. data/vendor/longfellow-zk/lib/merkle/merkle_tree_test.cc +240 -0
  251. data/vendor/longfellow-zk/lib/proto/circuit.h +354 -0
  252. data/vendor/longfellow-zk/lib/proto/circuit_test.cc +202 -0
  253. data/vendor/longfellow-zk/lib/random/random.h +119 -0
  254. data/vendor/longfellow-zk/lib/random/random_test.cc +189 -0
  255. data/vendor/longfellow-zk/lib/random/secure_random_engine.h +37 -0
  256. data/vendor/longfellow-zk/lib/random/transcript.h +193 -0
  257. data/vendor/longfellow-zk/lib/random/transcript_test.cc +344 -0
  258. data/vendor/longfellow-zk/lib/sumcheck/circuit.h +148 -0
  259. data/vendor/longfellow-zk/lib/sumcheck/circuit_id.h +71 -0
  260. data/vendor/longfellow-zk/lib/sumcheck/equad.h +126 -0
  261. data/vendor/longfellow-zk/lib/sumcheck/hquad.h +115 -0
  262. data/vendor/longfellow-zk/lib/sumcheck/prover.h +59 -0
  263. data/vendor/longfellow-zk/lib/sumcheck/prover_layers.h +362 -0
  264. data/vendor/longfellow-zk/lib/sumcheck/quad.h +227 -0
  265. data/vendor/longfellow-zk/lib/sumcheck/quad_builder.h +211 -0
  266. data/vendor/longfellow-zk/lib/sumcheck/quad_test.cc +169 -0
  267. data/vendor/longfellow-zk/lib/sumcheck/sumcheck_test.cc +324 -0
  268. data/vendor/longfellow-zk/lib/sumcheck/testing.h +69 -0
  269. data/vendor/longfellow-zk/lib/sumcheck/transcript_sumcheck.h +85 -0
  270. data/vendor/longfellow-zk/lib/sumcheck/verifier.h +84 -0
  271. data/vendor/longfellow-zk/lib/sumcheck/verifier_layers.h +221 -0
  272. data/vendor/longfellow-zk/lib/testing/test_main.cc +50 -0
  273. data/vendor/longfellow-zk/lib/util/ceildiv.h +164 -0
  274. data/vendor/longfellow-zk/lib/util/ceildiv_test.cc +152 -0
  275. data/vendor/longfellow-zk/lib/util/crc64.h +45 -0
  276. data/vendor/longfellow-zk/lib/util/crypto.cc +39 -0
  277. data/vendor/longfellow-zk/lib/util/crypto.h +108 -0
  278. data/vendor/longfellow-zk/lib/util/log.cc +110 -0
  279. data/vendor/longfellow-zk/lib/util/log.h +33 -0
  280. data/vendor/longfellow-zk/lib/util/panic.h +40 -0
  281. data/vendor/longfellow-zk/lib/util/readbuffer.h +67 -0
  282. data/vendor/longfellow-zk/lib/util/serialization.h +54 -0
  283. data/vendor/longfellow-zk/lib/zk/zk_common.h +455 -0
  284. data/vendor/longfellow-zk/lib/zk/zk_proof.h +378 -0
  285. data/vendor/longfellow-zk/lib/zk/zk_prover.h +202 -0
  286. data/vendor/longfellow-zk/lib/zk/zk_test.cc +340 -0
  287. data/vendor/longfellow-zk/lib/zk/zk_testing.h +154 -0
  288. data/vendor/longfellow-zk/lib/zk/zk_verifier.h +109 -0
  289. metadata +347 -0
@@ -0,0 +1,495 @@
1
+ // Copyright 2026 Google LLC.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_SYSDEP_H_
16
+ #define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_SYSDEP_H_
17
+
18
+ #include <stddef.h>
19
+
20
+ #include <cstdint>
21
+
22
+ #include "util/panic.h" // IWYU pragma: keep
23
+
24
+ #if defined(__x86_64__) || defined(__i386__)
25
+ // system-dependent basic arithmetic functions: add with carry
26
+ // and 64x64->128 bit multiplication
27
+ #include <x86intrin.h> // IWYU pragma: keep
28
+ #endif
29
+
30
+ namespace proofs {
31
+
32
+ #if defined(__x86_64__)
33
+ static inline uint64_t adc(uint64_t* a, uint64_t b, uint64_t c) {
34
+ // unsigned long long (not uint64_t) is *required* by the
35
+ // _addcarry_u64() prototype. uint64_t is unsigned long on
36
+ // linux, and pointers to the two types are incompatible even
37
+ // though the conversion is a no-op.
38
+ unsigned long long out;
39
+ c = _addcarry_u64(c, *a, b, &out);
40
+ *a = out;
41
+ return c;
42
+ }
43
+ static inline uint32_t adc(uint32_t* a, uint32_t b, uint32_t c) {
44
+ return _addcarry_u32(c, *a, b, a);
45
+ }
46
+ static inline uint64_t sbb(uint64_t* a, uint64_t b, uint64_t c) {
47
+ unsigned long long out;
48
+ c = _subborrow_u64(c, *a, b, &out);
49
+ *a = out;
50
+ return c;
51
+ }
52
+ static inline uint32_t sbb(uint32_t* a, uint32_t b, uint32_t c) {
53
+ return _subborrow_u32(c, *a, b, a);
54
+ }
55
+ static inline void mulq(uint64_t* l, uint64_t* h, uint64_t a, uint64_t b) {
56
+ asm("mulx %2, %0, %1" : "=r"(*l), "=r"(*h) : "r"(b), "d"(a));
57
+ }
58
+ #elif defined(__i386__)
59
+ static inline uint32_t adc(uint32_t* a, uint32_t b, uint32_t c) {
60
+ return _addcarry_u32(c, *a, b, a);
61
+ }
62
+ static inline uint32_t sbb(uint32_t* a, uint32_t b, uint32_t c) {
63
+ return _subborrow_u32(c, *a, b, a);
64
+ }
65
+
66
+ // these two functions are supposed to be defined but are
67
+ // never called
68
+ static inline unsigned long long adc(unsigned long long* a,
69
+ unsigned long long b,
70
+ unsigned long long c) {
71
+ check(false, "adcll() not defined");
72
+ return 0;
73
+ }
74
+ static inline unsigned long long sbb(unsigned long long* a,
75
+ unsigned long long b,
76
+ unsigned long long c) {
77
+ check(false, "sbbll() not defined");
78
+ return 0;
79
+ }
80
+
81
+ #define SYSDEP_MULQ64_NOT_DEFINED
82
+ #elif defined(__clang__)
83
+ // The clang intrinsics use the builtin-types int, long, etc.
84
+ // Thus we define adc() and sbb() in terms of those types.
85
+ static inline unsigned long long adc(unsigned long long* a,
86
+ unsigned long long b,
87
+ unsigned long long c) {
88
+ *a = __builtin_addcll(*a, b, c, &c);
89
+ return c;
90
+ }
91
+ static inline unsigned long adc(unsigned long* a, unsigned long b,
92
+ unsigned long c) {
93
+ *a = __builtin_addcl(*a, b, c, &c);
94
+ return c;
95
+ }
96
+ static inline unsigned int adc(unsigned int* a, unsigned int b,
97
+ unsigned int c) {
98
+ *a = __builtin_addc(*a, b, c, &c);
99
+ return c;
100
+ }
101
+
102
+ static inline unsigned long long sbb(unsigned long long* a,
103
+ unsigned long long b,
104
+ unsigned long long c) {
105
+ *a = __builtin_subcll(*a, b, c, &c);
106
+ return c;
107
+ }
108
+ static inline unsigned long sbb(unsigned long* a, unsigned long b,
109
+ unsigned long c) {
110
+ *a = __builtin_subcl(*a, b, c, &c);
111
+ return c;
112
+ }
113
+ static inline unsigned int sbb(unsigned int* a, unsigned int b,
114
+ unsigned int c) {
115
+ *a = __builtin_subc(*a, b, c, &c);
116
+ return c;
117
+ }
118
+
119
+ #if defined(__SIZEOF_INT128__)
120
+ // It seems that __SIZEOF_INT128__ is defined if __uint128_t is.
121
+ static inline void mulq(uint64_t* l, uint64_t* h, uint64_t a, uint64_t b) {
122
+ __uint128_t p = (__uint128_t)b * (__uint128_t)a;
123
+ *l = p;
124
+ *h = p >> 64;
125
+ }
126
+ #else // defined(__SIZEOF_INT128__)
127
+ #define SYSDEP_MULQ64_NOT_DEFINED
128
+ #endif // defined(__SIZEOF_INT128__)
129
+ #endif
130
+
131
+ static inline void mulq(uint32_t* l, uint32_t* h, uint32_t a, uint32_t b) {
132
+ uint64_t p = (uint64_t)b * (uint64_t)a;
133
+ *l = p;
134
+ *h = p >> 32;
135
+ }
136
+
137
+ // Identity function whose only purpose is to confuse the compiler.
138
+ // We have no coherent theory of when and why this is useful, but
139
+ // here are a couple of cases where this hack makes a difference:
140
+ //
141
+ // * Passing the cmov() values through identity_limb() seems
142
+ // to favor the generation of a conditional move instruction
143
+ // as opposed to a conditional branch.
144
+ // * Clang and gcc match a+b+carry to generate the adcq instruction,
145
+ // but a+0+carry becomes a+carry and the match fails. So
146
+ // we pretend that the zero is not a zero.
147
+ // * A similar issue arises in subtract with carry.
148
+ //
149
+ // This function is obviously a hack. Works for me today but YMMV.
150
+ //
151
+ template <class limb_t>
152
+ static inline limb_t identity_limb(limb_t v) {
153
+ asm("" : "+r"(v)::);
154
+ return v;
155
+ }
156
+
157
+ template <class limb_t>
158
+ static inline limb_t zero_limb() {
159
+ return identity_limb<limb_t>(0);
160
+ }
161
+
162
+ // a += b
163
+ template <class limb_t>
164
+ static inline void accum(size_t Wa, limb_t a[/*Wa*/], size_t Wb,
165
+ const limb_t b[/*Wb*/]) {
166
+ limb_t c = 0;
167
+ for (size_t i = 0; i < Wb; ++i) {
168
+ c = adc(&a[i], b[i], c);
169
+ }
170
+ for (size_t i = Wb; i < Wa; ++i) {
171
+ c = adc(&a[i], 0, c);
172
+ }
173
+ }
174
+
175
+ // a -= b
176
+ template <class limb_t>
177
+ static inline void negaccum(size_t Wa, limb_t a[/*Wa*/], size_t Wb,
178
+ const limb_t b[/*Wb*/]) {
179
+ limb_t c = 0;
180
+ for (size_t i = 0; i < Wb; ++i) {
181
+ c = sbb(&a[i], b[i], c);
182
+ }
183
+ for (size_t i = Wb; i < Wa; ++i) {
184
+ c = sbb(&a[i], 0, c);
185
+ }
186
+ }
187
+
188
+ // h::a += b
189
+ template <class limb_t>
190
+ static inline limb_t add_limb(size_t W, limb_t a[/*W*/],
191
+ const limb_t b[/*W*/]) {
192
+ limb_t c = 0;
193
+ for (size_t i = 0; i < W; ++i) {
194
+ c = adc(&a[i], b[i], c);
195
+ }
196
+ limb_t h = zero_limb<limb_t>();
197
+ c = adc(&h, 0, c);
198
+ return h;
199
+ }
200
+
201
+ // h::a += b * 2^(bits per limb)
202
+ template <class limb_t>
203
+ static inline limb_t addh(size_t W, limb_t a[/*W*/], const limb_t b[/*W*/]) {
204
+ limb_t c = 0;
205
+ for (size_t i = 1; i < W; ++i) {
206
+ c = adc(&a[i], b[i - 1], c);
207
+ }
208
+ limb_t h = zero_limb<limb_t>();
209
+ c = adc(&h, b[W - 1], c);
210
+ return h;
211
+ }
212
+
213
+ // h::a -= b
214
+ template <class limb_t>
215
+ static inline limb_t sub_limb(size_t W, limb_t a[/*W*/],
216
+ const limb_t b[/*W*/]) {
217
+ limb_t c = 0;
218
+ for (size_t i = 0; i < W; ++i) {
219
+ c = sbb(&a[i], b[i], c);
220
+ }
221
+ limb_t h = zero_limb<limb_t>();
222
+ c = sbb(&h, 0, c);
223
+ return h;
224
+ }
225
+
226
+ // h:l = a*b
227
+ template <class limb_t>
228
+ static inline void mulhl(size_t W, limb_t l[/*W*/], limb_t h[/*W*/], limb_t a,
229
+ const limb_t b[/*W*/]) {
230
+ for (size_t i = 0; i < W; ++i) {
231
+ mulq(&l[i], &h[i], a, b[i]);
232
+ }
233
+ }
234
+
235
+ // a = b
236
+ template <class limb_t>
237
+ static inline void mov(size_t W, limb_t a[/*W*/], const limb_t b[/*W*/]) {
238
+ for (size_t i = 0; i < W; ++i) {
239
+ a[i] = b[i];
240
+ }
241
+ }
242
+
243
+ // It seems that using assembly code is the only way to
244
+ // force gcc and clang to use conditional moves.
245
+ #if defined(__x86_64__)
246
+ static inline void cmovnz(size_t W, uint64_t a[/*W*/], uint64_t nz,
247
+ const uint64_t b[/*W*/]) {
248
+ if (W == 1) {
249
+ asm("testq %[nz], %[nz]\n\t"
250
+ "cmovneq %[b0], %[a0]\n\t"
251
+ : [a0] "+r"(a[0])
252
+ : [nz] "r"(nz), [b0] "r"(b[0]));
253
+ } else if (W == 2) {
254
+ asm("testq %[nz], %[nz]\n\t"
255
+ "cmovneq %[b0], %[a0]\n\t"
256
+ "cmovneq %[b1], %[a1]\n\t"
257
+ : [a0] "+r"(a[0]), [a1] "+r"(a[1])
258
+ : [nz] "r"(nz), [b0] "r"(b[0]), [b1] "r"(b[1]));
259
+ } else if (W == 3) {
260
+ asm("testq %[nz], %[nz]\n\t"
261
+ "cmovneq %[b0], %[a0]\n\t"
262
+ "cmovneq %[b1], %[a1]\n\t"
263
+ "cmovneq %[b2], %[a2]\n\t"
264
+ : [a0] "+r"(a[0]), [a1] "+r"(a[1]), [a2] "+r"(a[2])
265
+ : [nz] "r"(nz), [b0] "r"(b[0]), [b1] "r"(b[1]), [b2] "r"(b[2]));
266
+ } else if (W == 4) {
267
+ asm("testq %[nz], %[nz]\n\t"
268
+ "cmovneq %[b0], %[a0]\n\t"
269
+ "cmovneq %[b1], %[a1]\n\t"
270
+ "cmovneq %[b2], %[a2]\n\t"
271
+ "cmovneq %[b3], %[a3]\n\t"
272
+ : [a0] "+r"(a[0]), [a1] "+r"(a[1]), [a2] "+r"(a[2]), [a3] "+r"(a[3])
273
+ : [nz] "r"(nz), [b0] "r"(b[0]), [b1] "r"(b[1]), [b2] "r"(b[2]),
274
+ [b3] "r"(b[3]));
275
+ } else {
276
+ for (size_t i = 0; i < W; ++i) {
277
+ a[i] = (nz != 0) ? b[i] : a[i];
278
+ }
279
+ }
280
+ }
281
+
282
+ static inline void cmovne(size_t W, uint64_t a[/*W*/], uint64_t x, uint64_t y,
283
+ const uint64_t b[/*W*/]) {
284
+ if (W == 1) {
285
+ asm("cmpq %[x], %[y]\n\t"
286
+ "cmovneq %[b0], %[a0]\n\t"
287
+ : [a0] "+r"(a[0])
288
+ : [x] "r"(x), [y] "r"(y), [b0] "r"(b[0])
289
+ : "cc");
290
+ } else if (W == 2) {
291
+ asm("cmpq %[x], %[y]\n\t"
292
+ "cmovneq %[b0], %[a0]\n\t"
293
+ "cmovneq %[b1], %[a1]\n\t"
294
+ : [a0] "+r"(a[0]), [a1] "+r"(a[1])
295
+ : [x] "r"(x), [y] "r"(y), [b0] "r"(b[0]), [b1] "r"(b[1])
296
+ : "cc");
297
+ } else if (W == 3) {
298
+ asm("cmpq %[x], %[y]\n\t"
299
+ "cmovneq %[b0], %[a0]\n\t"
300
+ "cmovneq %[b1], %[a1]\n\t"
301
+ "cmovneq %[b2], %[a2]\n\t"
302
+ : [a0] "+r"(a[0]), [a1] "+r"(a[1]), [a2] "+r"(a[2])
303
+ : [x] "r"(x), [y] "r"(y), [b0] "r"(b[0]), [b1] "r"(b[1]), [b2] "r"(b[2])
304
+ : "cc");
305
+ } else if (W == 4) {
306
+ asm("cmpq %[x], %[y]\n\t"
307
+ "cmovneq %[b0], %[a0]\n\t"
308
+ "cmovneq %[b1], %[a1]\n\t"
309
+ "cmovneq %[b2], %[a2]\n\t"
310
+ "cmovneq %[b3], %[a3]\n\t"
311
+ : [a0] "+r"(a[0]), [a1] "+r"(a[1]), [a2] "+r"(a[2]), [a3] "+r"(a[3])
312
+ : [x] "r"(x), [y] "r"(y), [b0] "r"(b[0]), [b1] "r"(b[1]),
313
+ [b2] "r"(b[2]), [b3] "r"(b[3])
314
+ : "cc");
315
+ } else {
316
+ for (size_t i = 0; i < W; ++i) {
317
+ a[i] = (x != y) ? b[i] : a[i];
318
+ }
319
+ }
320
+ }
321
+
322
+ static inline uint64_t addcmovc(uint64_t a, uint64_t b, uint64_t c) {
323
+ asm("add %[b], %[a]\n\t"
324
+ "cmovaeq %[c], %[a]\n\t"
325
+ : [a] "+r"(a)
326
+ : [b] "r"(b), [c] "r"(c)
327
+ : "cc");
328
+ return a;
329
+ }
330
+
331
+ static inline uint64_t sub_sysdep(uint64_t a, uint64_t y, uint64_t m) {
332
+ uint64_t z = 0;
333
+ asm("subq %[y], %[a]\n\t"
334
+ "cmovbq %[m], %[z]\n\t"
335
+ : [a] "+r"(a), [z] "+r"(z)
336
+ : [y] "r"(y), [m] "r"(m)
337
+ : "cc");
338
+ return a + z;
339
+ }
340
+
341
+ // For x86_64 only, define 32-bit variants for testing 32-bit arithmetic
342
+ // without cross-compilation.
343
+
344
+ static inline void cmovne(size_t W, uint32_t a[/*W*/], uint32_t x, uint32_t y,
345
+ const uint32_t b[/*W*/]) {
346
+ for (size_t i = 0; i < W; ++i) {
347
+ a[i] = (x != y) ? b[i] : a[i];
348
+ }
349
+ }
350
+
351
+ static inline void cmovnz(size_t W, uint32_t a[/*W*/], uint32_t nz,
352
+ const uint32_t b[/*W*/]) {
353
+ constexpr uint32_t z = 0;
354
+ cmovne(W, a, nz, z, b);
355
+ }
356
+
357
+ static inline uint32_t addcmovc(uint32_t a, uint32_t b, uint32_t c) {
358
+ uint32_t t = a + b;
359
+ return (a > t) ? t : c;
360
+ }
361
+
362
+ static inline uint32_t sub_sysdep(uint32_t a, uint32_t y, uint32_t m) {
363
+ uint32_t t0 = a - y;
364
+ return (y > a) ? (t0 + m) : t0;
365
+ }
366
+
367
+ #elif defined(__aarch64__)
368
+
369
+ static inline void cmovne(size_t W, uint64_t a[/*W*/], uint64_t x, uint64_t y,
370
+ const uint64_t b[/*W*/]) {
371
+ if (W == 1) {
372
+ asm("cmp %[x], %[y]\n\t" //
373
+ "csel %[a0], %[a0], %[b0], eq\n\t" //
374
+ : [a0] "+r"(a[0]) //
375
+ : [x] "r"(x), [y] "ri"(y), //
376
+ [b0] "r"(b[0]) //
377
+ : "cc");
378
+ } else if (W == 2) {
379
+ asm("cmp %[x], %[y]\n\t" //
380
+ "csel %[a0], %[a0], %[b0], eq\n\t" //
381
+ "csel %[a1], %[a1], %[b1], eq\n\t" //
382
+ : [a0] "+r"(a[0]), //
383
+ [a1] "+r"(a[1]) //
384
+ : [x] "r"(x), [y] "ri"(y), //
385
+ [b0] "r"(b[0]), //
386
+ [b1] "r"(b[1]) //
387
+ : "cc");
388
+ } else if (W == 3) {
389
+ asm("cmp %[x], %[y]\n\t" //
390
+ "csel %[a0], %[a0], %[b0], eq\n\t" //
391
+ "csel %[a1], %[a1], %[b1], eq\n\t" //
392
+ "csel %[a2], %[a2], %[b2], eq\n\t" //
393
+ : [a0] "+r"(a[0]), //
394
+ [a1] "+r"(a[1]), //
395
+ [a2] "+r"(a[2]) //
396
+ : [x] "r"(x), [y] "ri"(y), //
397
+ [b0] "r"(b[0]), //
398
+ [b1] "r"(b[1]), //
399
+ [b2] "r"(b[2]) //
400
+ : "cc");
401
+ } else if (W == 4) {
402
+ asm("cmp %[x], %[y]\n\t" //
403
+ "csel %[a0], %[a0], %[b0], eq\n\t" //
404
+ "csel %[a1], %[a1], %[b1], eq\n\t" //
405
+ "csel %[a2], %[a2], %[b2], eq\n\t" //
406
+ "csel %[a3], %[a3], %[b3], eq\n\t" //
407
+ : [a0] "+r"(a[0]), //
408
+ [a1] "+r"(a[1]), //
409
+ [a2] "+r"(a[2]), //
410
+ [a3] "+r"(a[3]) //
411
+ : [x] "r"(x), [y] "ri"(y), //
412
+ [b0] "r"(b[0]), //
413
+ [b1] "r"(b[1]), //
414
+ [b2] "r"(b[2]), //
415
+ [b3] "r"(b[3]) //
416
+ : "cc");
417
+ } else {
418
+ for (size_t i = 0; i < W; ++i) {
419
+ a[i] = (x != y) ? b[i] : a[i];
420
+ }
421
+ }
422
+ }
423
+
424
+ // a = (nz != 0) ? b : a
425
+ static inline void cmovnz(size_t W, uint64_t a[/*W*/], uint64_t nz,
426
+ const uint64_t b[/*W*/]) {
427
+ constexpr uint64_t z = 0;
428
+ cmovne(W, a, nz, z, b);
429
+ }
430
+
431
+ static inline uint64_t addcmovc(uint64_t a, uint64_t b, uint64_t c) {
432
+ asm("adds %[a], %[a], %[b]\n\t"
433
+ "csel %[a], %[a], %[c], hs\n\t"
434
+ : [a] "+r"(a)
435
+ : [b] "r"(b), [c] "r"(c)
436
+ : "cc");
437
+ return a;
438
+ }
439
+
440
+ static inline uint64_t sub_sysdep(uint64_t a, uint64_t y, uint64_t m) {
441
+ asm("subs %[a], %[a], %[y]\n\t"
442
+ "csel %[m], %[m], xzr, lo"
443
+ : [a] "+r"(a), [m] "+r"(m)
444
+ : [y] "r"(y)
445
+ : "cc");
446
+ return a + m;
447
+ }
448
+
449
+ #else // generic portable code
450
+
451
+ // a = (x != y) ? b : a
452
+ template <class limb_t>
453
+ static inline void cmovne(size_t W, limb_t a[/*W*/], limb_t x, limb_t y,
454
+ const limb_t b[/*W*/]) {
455
+ for (size_t i = 0; i < W; ++i) {
456
+ a[i] = (x != y) ? b[i] : a[i];
457
+ }
458
+ }
459
+
460
+ // a = (nz != 0) ? b : a
461
+ template <class limb_t>
462
+ static inline void cmovnz(size_t W, limb_t a[/*W*/], limb_t nz,
463
+ const limb_t b[/*W*/]) {
464
+ constexpr limb_t z = 0;
465
+ cmovne(W, a, nz, z, b);
466
+ }
467
+
468
+ template <class limb_t>
469
+ static inline limb_t addcmovc(limb_t a, limb_t b, limb_t c) {
470
+ limb_t t = a + b;
471
+ return (a > t) ? t : c;
472
+ }
473
+
474
+ template <class limb_t>
475
+ static inline limb_t sub_sysdep(limb_t a, limb_t y, limb_t m) {
476
+ limb_t t0 = a - y;
477
+ return (y > a) ? (t0 + m) : t0;
478
+ }
479
+
480
+ #endif
481
+
482
+ // special cases for fp24
483
+ static inline uint32_t addcmovc_32(uint32_t a, uint32_t b, uint32_t c) {
484
+ uint32_t t = a + b;
485
+ return (a > t) ? t : c;
486
+ }
487
+
488
+ static inline uint32_t sub_sysdep_32(uint32_t a, uint32_t y, uint32_t m) {
489
+ uint32_t t0 = a - y;
490
+ return (y > a) ? (t0 + m) : t0;
491
+ }
492
+
493
+ } // namespace proofs
494
+
495
+ #endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_SYSDEP_H_
@@ -0,0 +1,41 @@
1
+ // Copyright 2026 Google LLC.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #include "algebra/sysdep.h"
16
+
17
+ #include <cstdint>
18
+
19
+ #include "gtest/gtest.h"
20
+
21
+ namespace proofs {
22
+ namespace {
23
+ #ifndef SYSDEP_MULQ64_NOT_DEFINED
24
+ TEST(Sysdep, mulhl64) {
25
+ uint64_t l, h;
26
+ uint64_t b = (1ull << 47) + 1u;
27
+ mulhl(1, &l, &h, (static_cast<uint64_t>(1) << 53) + 1u, &b);
28
+ EXPECT_EQ(l, 1 + (1ull << 53) + (1ull << 47));
29
+ EXPECT_EQ(h, 1ull << (53 + 47 - 64));
30
+ }
31
+ #endif
32
+
33
+ TEST(Sysdep, mulhl32) {
34
+ uint32_t l, h;
35
+ uint32_t b = (1ull << 29) + 1u;
36
+ mulhl(1, &l, &h, (static_cast<uint32_t>(1) << 27) + 1u, &b);
37
+ EXPECT_EQ(l, 1 + (1ull << 27) + (1ull << 29));
38
+ EXPECT_EQ(h, 1ull << (27 + 29 - 32));
39
+ }
40
+ } // namespace
41
+ } // namespace proofs
@@ -0,0 +1,59 @@
1
+ // Copyright 2026 Google LLC.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_TWIDDLE_H_
16
+ #define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_TWIDDLE_H_
17
+
18
+ #include <stddef.h>
19
+ #include <stdint.h>
20
+
21
+ #include <vector>
22
+
23
+ // Twiddle factors for FFT
24
+ namespace proofs {
25
+
26
+ template <class Field>
27
+ class Twiddle {
28
+ using Elt = typename Field::Elt;
29
+
30
+ public:
31
+ size_t order_;
32
+ // powers of omega_n
33
+ std::vector<Elt> w_;
34
+
35
+ explicit Twiddle(size_t n, const Elt& omega_n, const Field& F)
36
+ : order_(n), w_(n / 2) {
37
+ auto w = F.one();
38
+ for (size_t i = 0; 2 * i < n; ++i) {
39
+ w_[i] = w;
40
+ F.mul(w, omega_n);
41
+ }
42
+ }
43
+
44
+ // given a n-th root of unity omega_n, return a r-th root of unity
45
+ // for r <= n
46
+ static Elt reroot(const Elt& omega_n, uint64_t n, uint64_t r,
47
+ const Field& F) {
48
+ Elt omega_r = omega_n;
49
+ while (r < n) {
50
+ F.mul(omega_r, omega_r);
51
+ r += r;
52
+ }
53
+ return omega_r;
54
+ }
55
+ };
56
+
57
+ } // namespace proofs
58
+
59
+ #endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_TWIDDLE_H_
@@ -0,0 +1,86 @@
1
+ // Copyright 2026 Google LLC.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_UTILITY_H_
16
+ #define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_UTILITY_H_
17
+
18
+ #include <stddef.h>
19
+
20
+ #include <cstdint>
21
+
22
+ namespace proofs {
23
+ template <class Field>
24
+ class AlgebraUtil {
25
+ public:
26
+ using Elt = typename Field::Elt;
27
+
28
+ // a[i*da] = inverse(b[i*db]), via Montgomery batch inversion
29
+ static void batch_invert(size_t n, Elt a[/*n with stride da*/], size_t da,
30
+ const Elt b[/*n with stride db*/], size_t db,
31
+ const Field& F) {
32
+ Elt p = F.one();
33
+
34
+ // a[i] \gets \prod_{j<i] b[j]
35
+ for (size_t i = 0; i < n; ++i) {
36
+ Elt bi = b[i * db];
37
+ a[i * da] = p;
38
+ F.mul(p, bi);
39
+ }
40
+
41
+ // now p = \prod_{j<n] b[j]
42
+ F.invert(p);
43
+
44
+ for (size_t i = n; i-- > 0;) {
45
+ F.mul(a[i * da], p);
46
+ F.mul(p, b[i * db]);
47
+ }
48
+ }
49
+
50
+ // a[i] = 1/i, with a[0]=0
51
+ static void batch_inverse_arithmetic(size_t n, Elt a[/*n*/], const Field& F) {
52
+ a[0] = F.zero();
53
+ // this is essentially batch_inverse with b[i]=bi
54
+
55
+ Elt p = F.one();
56
+ Elt bi = F.zero();
57
+
58
+ for (size_t i = 1; i < n; ++i) {
59
+ F.add(bi, F.one());
60
+ a[i] = p;
61
+ F.mul(p, bi);
62
+ }
63
+
64
+ // now p = \prod_{j<n] b[j]
65
+ F.invert(p);
66
+
67
+ for (size_t i = n; i-- > 0;) {
68
+ F.mul(a[i], p);
69
+ F.mul(p, bi);
70
+ F.sub(bi, F.one());
71
+ }
72
+ }
73
+
74
+ static Elt factorial(uint64_t n, const Field& F) {
75
+ auto p = F.one();
76
+ auto fi = F.one();
77
+ for (uint64_t i = 1; i <= n; ++i) {
78
+ F.mul(p, fi);
79
+ F.add(fi, F.one());
80
+ }
81
+ return p;
82
+ }
83
+ };
84
+ } // namespace proofs
85
+
86
+ #endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_UTILITY_H_