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,257 @@
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/fft.h"
16
+
17
+ #include <stddef.h>
18
+
19
+ #include <cstdint>
20
+ #include <vector>
21
+
22
+ #include "algebra/bogorng.h"
23
+ #include "algebra/fp.h"
24
+ #include "algebra/fp2.h"
25
+ #include "algebra/fp_p128.h"
26
+ #include "algebra/fp_p256.h"
27
+ #include "benchmark/benchmark.h"
28
+ #include "gtest/gtest.h"
29
+
30
+ namespace proofs {
31
+ namespace {
32
+
33
+ typedef Fp<4> Field;
34
+ static const Field F(
35
+ "21888242871839275222246405745257275088548364400416034343698204186575808495"
36
+ "617");
37
+ typedef Field::Elt Elt;
38
+ Bogorng<Field> rng(&F);
39
+
40
+ // root of unity in F
41
+ Elt omega = F.of_string(
42
+ "19103219067921713944291392827692070036145651957329286315305642004821462161"
43
+ "904");
44
+ size_t omega_order = 1 << 28;
45
+ constexpr size_t N = 1 << 16;
46
+
47
+ static Elt reroot(const Elt& omega_n, size_t n, size_t r, const Field& FF) {
48
+ Elt omega_r = omega_n;
49
+ while (r < n) {
50
+ FF.mul(omega_r, omega_r);
51
+ r += r;
52
+ }
53
+ return omega_r;
54
+ }
55
+
56
+ TEST(FFT, Inverse) {
57
+ size_t n = N;
58
+ std::vector<Elt> A(n);
59
+ for (size_t i = 0; i < n; ++i) {
60
+ A[i] = rng.next();
61
+ }
62
+ std::vector<Elt> B(A);
63
+ FFT<Field>::fftf(&A[0], n, omega, omega_order, F);
64
+ FFT<Field>::fftb(&A[0], n, omega, omega_order, F);
65
+ for (size_t i = 0; i < n; ++i) {
66
+ F.mul(A[i], F.invertf(F.of_scalar(n)));
67
+ }
68
+ for (size_t i = 0; i < n; ++i) {
69
+ EXPECT_EQ(A[i], B[i]);
70
+ }
71
+ }
72
+
73
+ TEST(FFT, Linear) {
74
+ size_t n = N;
75
+ std::vector<Elt> A(n);
76
+ std::vector<Elt> B(n);
77
+ std::vector<Elt> C(n);
78
+ auto k0 = rng.next();
79
+ auto k1 = rng.next();
80
+ for (size_t i = 0; i < n; ++i) {
81
+ A[i] = rng.next();
82
+ B[i] = rng.next();
83
+ C[i] = F.addf(F.mulf(k0, A[i]), F.mulf(k1, B[i]));
84
+ }
85
+ FFT<Field>::fftf(&A[0], n, omega, omega_order, F);
86
+ FFT<Field>::fftf(&B[0], n, omega, omega_order, F);
87
+ FFT<Field>::fftf(&C[0], n, omega, omega_order, F);
88
+ for (size_t i = 0; i < n; ++i) {
89
+ EXPECT_EQ(C[i], F.addf(F.mulf(k0, A[i]), F.mulf(k1, B[i])));
90
+ }
91
+ }
92
+
93
+ TEST(FFT, Impulse) {
94
+ size_t n = N;
95
+ std::vector<Elt> A(n);
96
+ std::vector<Elt> B(n);
97
+ std::vector<Elt> C(n);
98
+ Elt k0 = rng.next();
99
+ Elt k1 = rng.next();
100
+
101
+ for (size_t i = 0; i < n; ++i) {
102
+ A[i] = i == 0 ? F.zero() : F.one();
103
+ B[i] = rng.next();
104
+ C[i] = F.addf(F.mulf(k0, A[i]), F.mulf(k1, B[i])); // k0 * A[i] + k1 * B[i]
105
+ }
106
+
107
+ FFT<Field>::fftf(&A[0], n, omega, omega_order, F);
108
+ FFT<Field>::fftf(&B[0], n, omega, omega_order, F);
109
+ FFT<Field>::fftf(&C[0], n, omega, omega_order, F);
110
+ for (size_t i = 0; i < n; ++i) {
111
+ EXPECT_EQ(C[i], F.addf(F.mulf(k0, A[i]), F.mulf(k1, B[i])));
112
+ }
113
+ }
114
+
115
+ TEST(FFT, RootOfUnity) {
116
+ Elt one = reroot(omega, omega_order, 1, F);
117
+ Elt one1 = F.one();
118
+ EXPECT_EQ(one, one1);
119
+ }
120
+
121
+ TEST(FFT, Shift) {
122
+ size_t n = N;
123
+ std::vector<Elt> A(n);
124
+ std::vector<Elt> B(n);
125
+ std::vector<Elt> C(n);
126
+ Elt omega_n = reroot(omega, omega_order, n, F);
127
+ Elt k0 = rng.next();
128
+ Elt k1 = rng.next();
129
+
130
+ for (size_t i = 0; i < n; ++i) {
131
+ A[i] = rng.next();
132
+ B[i] = rng.next();
133
+ }
134
+ for (size_t i = 0; i < n; ++i) {
135
+ // k0 * A[(i + 1) % n] + k1 * B[i]
136
+ C[i] = F.addf(F.mulf(k0, A[(i + 1) % n]), F.mulf(k1, B[i]));
137
+ }
138
+
139
+ FFT<Field>::fftb(&A[0], n, omega, omega_order, F);
140
+ FFT<Field>::fftb(&B[0], n, omega, omega_order, F);
141
+ FFT<Field>::fftb(&C[0], n, omega, omega_order, F);
142
+ Elt w = F.one();
143
+ EXPECT_EQ(w, reroot(omega_n, n, 1, F));
144
+ for (size_t i = 0; i < n; ++i) {
145
+ EXPECT_EQ(F.addf(F.mulf(k0, A[i]), F.mulf(F.mulf(k1, B[i]), w)),
146
+ F.mulf(w, C[i])); // k0 * A[i] + k1 * B[i] * w = C[i] * w
147
+ F.mul(w, omega_n);
148
+ }
149
+ }
150
+ } // namespace
151
+
152
+ // ================ Benchmarking ==============================================
153
+
154
+ // benchmark the FFT over a P256^2 with a real root of unity
155
+ namespace bench {
156
+ void BM_FFT_Fp256_2(benchmark::State& state) {
157
+ using BaseField = Fp256<true>;
158
+ using Field = Fp2<BaseField>;
159
+
160
+ using Elt = Field::Elt;
161
+ const BaseField F0;
162
+ const Field F(F0);
163
+ const Elt OMEGA31 = F.of_string(
164
+ "112649224146410281873500457609690258373018840430489408729223714171582664"
165
+ "680802",
166
+ "840879943585409076957404614278186605601821689971823787493130182544504602"
167
+ "12908");
168
+ Bogorng<BaseField> rng(&F0);
169
+ size_t N = state.range(0);
170
+ std::vector<Elt> A(N);
171
+ for (size_t i = 0; i < N; ++i) {
172
+ A[i] = F.of_scalar(rng.next());
173
+ }
174
+ for (auto _ : state) {
175
+ FFT<Field>::fftb(&A[0], N, OMEGA31, 1u << 31, F);
176
+ }
177
+ }
178
+ BENCHMARK(BM_FFT_Fp256_2)
179
+ ->RangeMultiplier(4)
180
+ ->Range(1024, (1 << 22));
181
+
182
+ void BM_FFT_Fp128(benchmark::State& state) {
183
+ using Field = Fp128<>;
184
+ using Elt = Field::Elt;
185
+ Field F;
186
+ Bogorng<Field> rng(&F);
187
+ // bogus root of unit, doesn't matter for benchmark purposes since
188
+ // we are transforming zeroes anyway
189
+ auto omega = F.two();
190
+ size_t N = state.range(0);
191
+ std::vector<Elt> A(N);
192
+ for (size_t i = 0; i < N; ++i) {
193
+ A[i] = rng.next();
194
+ }
195
+ for (auto _ : state) {
196
+ FFT<Field>::fftb(&A[0], N, omega, omega_order, F);
197
+ }
198
+ }
199
+
200
+ BENCHMARK(BM_FFT_Fp128)
201
+ ->RangeMultiplier(4)
202
+ ->Range(1024, (1 << 22));
203
+
204
+ void BM_FFT_F64_2(benchmark::State& state) {
205
+ using BaseField = Fp<1>;
206
+ using Field = Fp2<BaseField>;
207
+
208
+ const BaseField F("18446744069414584321");
209
+ const Field F2(F);
210
+ using Elt = Field::Elt;
211
+ static constexpr char kSmallRoot[] = "2752994695033296049";
212
+ static constexpr uint64_t kSmallOrder = 1ull << 32;
213
+
214
+ const Elt omega = F2.of_string(kSmallRoot);
215
+ Bogorng<BaseField> rng(&F);
216
+
217
+ size_t N = state.range(0);
218
+ std::vector<Elt> A(N);
219
+ for (size_t i = 0; i < N; ++i) {
220
+ A[i] = F2.of_scalar(rng.next());
221
+ }
222
+
223
+ for (auto _ : state) {
224
+ FFT<Field>::fftb(&A[0], N, omega, kSmallOrder, F2);
225
+ }
226
+ }
227
+
228
+ BENCHMARK(BM_FFT_F64_2)
229
+ ->RangeMultiplier(4)
230
+ ->Range(1024, (1 << 22));
231
+
232
+ void BM_FFT_F64(benchmark::State& state) {
233
+ using Field = Fp<1>;
234
+ const Field F("18446744069414584321");
235
+ using Elt = Field::Elt;
236
+ static constexpr char kSmallRoot[] = "2752994695033296049";
237
+ static constexpr uint64_t kSmallOrder = 1ull << 32;
238
+ const Elt omega = F.of_string(kSmallRoot);
239
+ Bogorng<Field> rng(&F);
240
+
241
+ size_t N = state.range(0);
242
+ std::vector<Elt> A(N);
243
+ for (size_t i = 0; i < N; ++i) {
244
+ A[i] = rng.next();
245
+ }
246
+
247
+ for (auto _ : state) {
248
+ FFT<Field>::fftb(&A[0], N, omega, kSmallOrder, F);
249
+ }
250
+ }
251
+
252
+ BENCHMARK(BM_FFT_F64)
253
+ ->RangeMultiplier(4)
254
+ ->Range(1024, (1 << 22));
255
+
256
+ } // namespace bench
257
+ } // 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_FP_H_
16
+ #define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_H_
17
+
18
+ #include <cstddef>
19
+
20
+ #include "algebra/fp_generic.h"
21
+ #include "algebra/sysdep.h"
22
+
23
+ namespace proofs {
24
+
25
+ /*
26
+ The FpReduce structure factors out the main routine for performing modular
27
+ reduction wrt to a Montgomery-represented field element in the FpGeneric
28
+ class. This struct contains a generic reduction step that always works,
29
+ but it can be specialized for certain primes to achieve better efficiency as
30
+ done with our 128- and 256- bit fields.
31
+ */
32
+ struct FpReduce {
33
+ template <class limb_t, class N>
34
+ static inline void reduction_step(limb_t a[], limb_t mprime, const N& m) {
35
+ constexpr size_t kLimbs = N::kLimbs;
36
+ if (kLimbs == 1) {
37
+ // The general case (below) represents the (kLimbs+1)-word product as
38
+ // L+(H<<64), where in general L and H overlap, requiring
39
+ // two additions. For kLimbs==1, L and H do not overlap, and we can
40
+ // interpret [L, H] as a single double-precision number.
41
+ limb_t lh[2];
42
+ limb_t r = mprime * a[0];
43
+ mulhl(1, lh, lh + 1, r, m.limb_);
44
+ accum(3, a, 2, lh);
45
+ } else {
46
+ limb_t l[kLimbs], h[kLimbs];
47
+ limb_t r = mprime * a[0];
48
+ mulhl(kLimbs, l, h, r, m.limb_);
49
+ accum(kLimbs + 2, a, kLimbs, l);
50
+ accum(kLimbs + 1, a + 1, kLimbs, h);
51
+ }
52
+ }
53
+ };
54
+
55
+ template <size_t W, bool optimized_mul = false>
56
+ using Fp = FpGeneric<W, optimized_mul, FpReduce>;
57
+ } // namespace proofs
58
+
59
+ #endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_H_
@@ -0,0 +1,240 @@
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_FP2_H_
16
+ #define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP2_H_
17
+
18
+ #include <stddef.h>
19
+
20
+ #include <cstdint>
21
+ #include <functional>
22
+ #include <optional>
23
+
24
+ #include "util/panic.h"
25
+
26
+ namespace proofs {
27
+ // Fields of the form a+sqrt(r)*b where a, b \in Fp and
28
+ // r is a quadratic nonresidue in Fp. The special "complex"
29
+ // case r = -1 allows for a faster implementation of multiplication.
30
+ //
31
+ // With slight abuse of terminology, we call "a" the "real" part and
32
+ // "b" the "imaginary" part, and we call the sqrt(r) "i" even when
33
+ // r != -1.
34
+ template <class Field, bool nonresidue_is_mone = true>
35
+ class Fp2 {
36
+ public:
37
+ using Scalar = typename Field::Elt;
38
+ using BaseField = Field;
39
+ using TypeTag = typename Field::TypeTag;
40
+
41
+ // size of the serialization into bytes
42
+ static constexpr size_t kBytes = 2 * Field::kBytes;
43
+ static constexpr size_t kBits = 2 * Field::kBits;
44
+ static constexpr size_t kSubFieldBytes = Field::kBytes;
45
+ static constexpr bool kCharacteristicTwo = false;
46
+ const Field& f_;
47
+
48
+ struct Elt {
49
+ Scalar re, im;
50
+ bool operator==(const Elt& y) const { return re == y.re && im == y.im; }
51
+ bool operator!=(const Elt& y) const { return !operator==(y); }
52
+ };
53
+
54
+ explicit Fp2(const Field& F, const Scalar& nonresidue)
55
+ : f_(F), nonresidue_(nonresidue) {
56
+ if (nonresidue_is_mone) {
57
+ check(nonresidue == F.mone(), "nonresidue == F.mone()");
58
+ } else {
59
+ check(nonresidue != F.mone(), "nonresidue != F.mone()");
60
+ }
61
+
62
+ i_ = Elt{f_.zero(), f_.one()};
63
+ for (uint64_t i = 0; i < sizeof(k_) / sizeof(k_[0]); ++i) {
64
+ k_[i] = of_scalar(i);
65
+ }
66
+ khalf_ = Elt{f_.half(), f_.zero()};
67
+ kmone_ = Elt{f_.mone(), f_.zero()};
68
+ }
69
+ explicit Fp2(const Field& F) : Fp2(F, F.mone()) {}
70
+
71
+ Fp2(const Fp2&) = delete;
72
+ Fp2& operator=(const Fp2&) = delete;
73
+
74
+ const Field& base_field() const { return f_; }
75
+
76
+ Scalar real(const Elt& e) const { return e.re; }
77
+ bool is_real(const Elt& e) const { return e.im == f_.zero(); }
78
+
79
+ void add(Elt& a, const Elt& y) const {
80
+ f_.add(a.re, y.re);
81
+ f_.add(a.im, y.im);
82
+ }
83
+ void sub(Elt& a, const Elt& y) const {
84
+ f_.sub(a.re, y.re);
85
+ f_.sub(a.im, y.im);
86
+ }
87
+ void mul(Elt& a, const Elt& y) const {
88
+ auto p0 = f_.mulf(a.re, y.re);
89
+ auto p1 = f_.mulf(a.im, y.im);
90
+ auto a01 = f_.addf(a.re, a.im);
91
+ auto y01 = f_.addf(y.re, y.im);
92
+ if (nonresidue_is_mone) {
93
+ a.re = f_.subf(p0, p1);
94
+ } else {
95
+ a.re = f_.addf(p0, f_.mulf(p1, nonresidue_));
96
+ }
97
+ f_.mul(a01, y01);
98
+ f_.sub(a01, p0);
99
+ f_.sub(a01, p1);
100
+ a.im = a01;
101
+ }
102
+ void mul(Elt& a, const Scalar& y) const {
103
+ f_.mul(a.re, y);
104
+ f_.mul(a.im, y);
105
+ }
106
+ void neg(Elt& x) const {
107
+ Elt y(k_[0]);
108
+ sub(y, x);
109
+ x = y;
110
+ }
111
+ void conj(Elt& x) const { f_.neg(x.im); }
112
+ void invert(Elt& x) const {
113
+ Scalar denom;
114
+ if (nonresidue_is_mone) {
115
+ denom = f_.addf(f_.mulf(x.re, x.re), f_.mulf(x.im, x.im));
116
+ } else {
117
+ denom = f_.subf(f_.mulf(x.re, x.re),
118
+ f_.mulf(nonresidue_, f_.mulf(x.im, x.im)));
119
+ }
120
+ f_.invert(denom);
121
+ conj(x);
122
+ mul(x, denom);
123
+ }
124
+
125
+ // functional interface
126
+ Elt addf(Elt a, const Elt& y) const {
127
+ add(a, y);
128
+ return a;
129
+ }
130
+ Elt subf(Elt a, const Elt& y) const {
131
+ sub(a, y);
132
+ return a;
133
+ }
134
+ Elt mulf(Elt a, const Elt& y) const {
135
+ mul(a, y);
136
+ return a;
137
+ }
138
+ Elt mulf(Elt a, const Scalar& y) const {
139
+ mul(a, y);
140
+ return a;
141
+ }
142
+ Elt negf(Elt a) const {
143
+ neg(a);
144
+ return a;
145
+ }
146
+ Elt invertf(Elt a) const {
147
+ invert(a);
148
+ return a;
149
+ }
150
+ Elt conjf(Elt a) const {
151
+ conj(a);
152
+ return a;
153
+ }
154
+
155
+ Elt of_scalar(uint64_t a) const { return of_scalar_field(a); }
156
+ Elt of_scalar(const Scalar& e) const { return of_scalar_field(e); }
157
+
158
+ Elt of_scalar_field(const Scalar& e) const { return Elt{e, f_.zero()}; }
159
+ Elt of_scalar_field(uint64_t a) const {
160
+ return Elt{f_.of_scalar(a), f_.zero()};
161
+ }
162
+ Elt of_scalar_field(uint64_t ar, uint64_t ai) const {
163
+ return Elt{f_.of_scalar(ar), f_.of_scalar(ai)};
164
+ }
165
+
166
+ template <size_t N>
167
+ Elt of_string(const char (&s)[N]) const {
168
+ return Elt{f_.of_string(s), f_.zero()};
169
+ }
170
+
171
+ template <size_t NR, size_t NI>
172
+ Elt of_string(const char (&sr)[NR], const char (&si)[NI]) const {
173
+ return Elt{f_.of_string(sr), f_.of_string(si)};
174
+ }
175
+
176
+ std::optional<Elt> of_bytes_field(const uint8_t ab[/* kBytes */]) const {
177
+ if (auto re = f_.of_bytes_field(ab)) {
178
+ if (auto im = f_.of_bytes_field(ab + Field::kBytes)) {
179
+ return Elt{re.value(), im.value()};
180
+ }
181
+ }
182
+ return std::nullopt;
183
+ }
184
+
185
+ Elt sample(
186
+ const std::function<void(size_t n, uint8_t buf[])>& fill_bytes) const {
187
+ auto re = f_.sample(fill_bytes);
188
+ auto im = f_.sample(fill_bytes);
189
+ return Elt{re, im};
190
+ }
191
+
192
+ Elt sample_subfield(
193
+ const std::function<void(size_t n, uint8_t buf[])>& fill_bytes) const {
194
+ auto re = f_.sample(fill_bytes);
195
+ return of_scalar_field(re);
196
+ }
197
+
198
+ void to_bytes_field(uint8_t ab[/* kBytes */], const Elt& x) const {
199
+ f_.to_bytes_field(ab, x.re);
200
+ f_.to_bytes_field(ab + Field::kBytes, x.im);
201
+ }
202
+
203
+ bool in_subfield(const Elt& e) const { return is_real(e); }
204
+
205
+ std::optional<Elt> of_bytes_subfield(
206
+ const uint8_t ab[/* kSubFieldBytes */]) const {
207
+ if (auto re = f_.of_bytes_subfield(ab)) {
208
+ return of_scalar(re.value());
209
+ }
210
+ return std::nullopt;
211
+ }
212
+
213
+ void to_bytes_subfield(uint8_t ab[/* kSubFieldBytes */], const Elt& x) const {
214
+ check(in_subfield(x), "x not in subfield");
215
+ f_.to_bytes_subfield(ab, x.re);
216
+ }
217
+
218
+ const Elt& zero() const { return k_[0]; }
219
+ const Elt& one() const { return k_[1]; }
220
+ const Elt& two() const { return k_[2]; }
221
+ const Elt& half() const { return khalf_; }
222
+ const Elt& mone() const { return kmone_; }
223
+ const Elt& i() const { return i_; }
224
+ Elt poly_evaluation_point(size_t i) const {
225
+ return of_scalar(f_.poly_evaluation_point(i));
226
+ }
227
+ Elt newton_denominator(size_t k, size_t i) const {
228
+ return of_scalar(f_.newton_denominator(k, i));
229
+ }
230
+
231
+ private:
232
+ Scalar nonresidue_;
233
+ Elt k_[3]; // small constants
234
+ Elt i_; // i^2 = -1
235
+ Elt khalf_;
236
+ Elt kmone_;
237
+ };
238
+ } // namespace proofs
239
+
240
+ #endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP2_H_