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,72 @@
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_CIRCUITS_LOGIC_BIT_PLUCKER_ENCODER_H_
16
+ #define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_PLUCKER_ENCODER_H_
17
+
18
+ #include <stddef.h>
19
+ #include <stdint.h>
20
+
21
+ #include <array>
22
+
23
+ #include "circuits/logic/bit_plucker_constants.h"
24
+
25
+ namespace proofs {
26
+ template <class Field, size_t LOGN>
27
+ class BitPluckerEncoder {
28
+ const Field& f_;
29
+
30
+ using Elt = typename Field::Elt;
31
+ static constexpr size_t kN = size_t(1) << LOGN;
32
+ static constexpr size_t kNv32Elts = (32u + LOGN - 1u) / LOGN;
33
+ static constexpr size_t kNv128Elts = (128u + LOGN - 1u) / LOGN;
34
+ static constexpr size_t kNv256Elts = (256u + LOGN - 1u) / LOGN;
35
+
36
+ public:
37
+ using packed_v32 = std::array<Elt, kNv32Elts>;
38
+ using packed_v128 = std::array<Elt, kNv128Elts>;
39
+ using packed_v256 = std::array<Elt, kNv256Elts>;
40
+
41
+ explicit BitPluckerEncoder(const Field& F) : f_(F) {}
42
+
43
+ Elt encode(size_t i) const { return bit_plucker_point<Field, kN>()(i, f_); }
44
+
45
+ // Special case packer for uint32_t used in sha256.
46
+ packed_v32 mkpacked_v32(uint32_t j) {
47
+ packed_v32 r;
48
+ for (size_t i = 0; i < r.size(); ++i) {
49
+ r[i] = encode(j & (kN - 1));
50
+ j >>= LOGN;
51
+ }
52
+ return r;
53
+ }
54
+
55
+ template <typename T>
56
+ T pack(uint8_t bits[/* n bits */], size_t n) {
57
+ T r;
58
+ for (size_t i = 0; i < r.size(); ++i) {
59
+ size_t v = 0;
60
+ for (size_t j = 0; j < LOGN; ++j) {
61
+ if (i * LOGN + j < n) {
62
+ v += (bits[i * LOGN + j] & 0x1) << j;
63
+ }
64
+ }
65
+ r[i] = encode(v);
66
+ }
67
+ return r;
68
+ }
69
+ };
70
+ } // namespace proofs
71
+
72
+ #endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_PLUCKER_ENCODER_H_
@@ -0,0 +1,183 @@
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 "circuits/logic/bit_plucker.h"
16
+
17
+ #include <stddef.h>
18
+
19
+ #include "algebra/fp.h"
20
+ #include "circuits/compiler/circuit_dump.h"
21
+ #include "circuits/compiler/compiler.h"
22
+ #include "circuits/logic/bit_plucker_constants.h"
23
+ #include "circuits/logic/bit_plucker_encoder.h"
24
+ #include "circuits/logic/compiler_backend.h"
25
+ #include "circuits/logic/evaluation_backend.h"
26
+ #include "circuits/logic/logic.h"
27
+ #include "gf2k/gf2_128.h"
28
+ #include "gtest/gtest.h"
29
+
30
+ namespace proofs {
31
+ namespace {
32
+
33
+ template <size_t LOGN, class Field>
34
+ void test_plucker(const Field& F) {
35
+ using EvalBackend = EvaluationBackend<Field>;
36
+ using Logic = Logic<Field, EvalBackend>;
37
+
38
+ const EvalBackend ebk(F);
39
+ const Logic L(&ebk, F);
40
+ constexpr size_t N = 1 << LOGN;
41
+ const BitPluckerEncoder<Field, LOGN> PE(F);
42
+ const BitPlucker<Logic, LOGN> P(L);
43
+
44
+ for (size_t i = 0; i < N; ++i) {
45
+ auto enc = PE.encode(i);
46
+ auto got = P.pluck(L.konst(enc));
47
+ for (size_t k = 0; k < LOGN; ++k) {
48
+ EXPECT_EQ(L.eval(got[k]), L.konst((i >> k) & 1));
49
+ }
50
+ }
51
+ }
52
+
53
+ TEST(BitPlucker, PluckPrimeField) {
54
+ const Fp<1> F("18446744073709551557");
55
+ test_plucker<1>(F);
56
+ test_plucker<2>(F);
57
+ test_plucker<3>(F);
58
+ test_plucker<4>(F);
59
+ test_plucker<5>(F);
60
+ }
61
+
62
+ TEST(BitPlucker, PluckBinaryField) {
63
+ const GF2_128<> F;
64
+ test_plucker<1>(F);
65
+ test_plucker<2>(F);
66
+ test_plucker<3>(F);
67
+ test_plucker<4>(F);
68
+ test_plucker<5>(F);
69
+ }
70
+
71
+ template <size_t LOGN, class Field>
72
+ void pluck_size(const char *name, const Field &F) {
73
+ using CompilerBackend = CompilerBackend<Field>;
74
+ using LogicCircuit = Logic<Field, CompilerBackend>;
75
+ using EvalBackend = EvaluationBackend<Field>;
76
+ using Logic = Logic<Field, EvalBackend>;
77
+
78
+ const EvalBackend ebk(F);
79
+ const Logic L(&ebk, F);
80
+ QuadCircuit<Field> Q(F);
81
+ const CompilerBackend cbk(&Q);
82
+ const LogicCircuit LC(&cbk, F);
83
+ const BitPlucker<LogicCircuit, LOGN> PC(LC);
84
+
85
+ auto eC = LC.eltw_input();
86
+ auto r = PC.pluck(eC);
87
+ for (size_t k = 0; k < LOGN; ++k) {
88
+ LC.output(r[k], k);
89
+ }
90
+ auto CIRCUIT = Q.mkcircuit(/*nc=*/1);
91
+ dump_info(name, LOGN, Q);
92
+ }
93
+
94
+ TEST(BitPlucker, PluckSizePrimeField) {
95
+ using Field = Fp<1>;
96
+ const Field F("18446744073709551557");
97
+ const char *name = "pluck<FP<1>>";
98
+ pluck_size<1>(name, F);
99
+ pluck_size<2>(name, F);
100
+ pluck_size<3>(name, F);
101
+ pluck_size<4>(name, F);
102
+ pluck_size<5>(name, F);
103
+ pluck_size<6>(name, F);
104
+ pluck_size<7>(name, F);
105
+ pluck_size<8>(name, F);
106
+ }
107
+
108
+ TEST(BitPlucker, PluckSizeBinaryField) {
109
+ using Field = GF2_128<>;
110
+ const Field F;
111
+ const char *name = "pluck<GF2_128<>>";
112
+ pluck_size<1>(name, F);
113
+ pluck_size<2>(name, F);
114
+ pluck_size<3>(name, F);
115
+ pluck_size<4>(name, F);
116
+ pluck_size<5>(name, F);
117
+ pluck_size<6>(name, F);
118
+ pluck_size<7>(name, F);
119
+ pluck_size<8>(name, F);
120
+ }
121
+
122
+ TEST(BitPlucker, EltMuxer) {
123
+ using Field = Fp<1>;
124
+ using EvalBackend = EvaluationBackend<Field>;
125
+ using Logic = Logic<Field, EvalBackend>;
126
+ using EltW = Logic::EltW;
127
+
128
+ const Field F("257");
129
+ const EvalBackend ebk(F);
130
+ const Logic L(&ebk, F);
131
+ const EltW zero = L.konst(0);
132
+ const EltW one = L.konst(1);
133
+
134
+ EltW arr_z[] = {zero, one, one, one, one, one, one, one};
135
+ EltW arr_e[] = {zero, one, zero, one, zero, one, zero, one};
136
+ EltW arr_r[] = {zero, zero, one, one, zero, zero, one, one};
137
+ EltW arr_s[] = {zero, zero, zero, zero, one, one, one, one};
138
+
139
+ const EltMuxer<Logic, 8> em_z(L, arr_z);
140
+ const EltMuxer<Logic, 8> em_e(L, arr_e);
141
+ const EltMuxer<Logic, 8> em_r(L, arr_r);
142
+ const EltMuxer<Logic, 8> em_s(L, arr_s);
143
+
144
+ for (size_t i = 0; i < 8; ++i) {
145
+ auto enc = bit_plucker_point<Field, 8>()(i, F);
146
+
147
+ L.assert_eq(em_z.mux(L.konst(enc)), arr_z[i]);
148
+ L.assert_eq(em_e.mux(L.konst(enc)), arr_e[i]);
149
+ L.assert_eq(em_r.mux(L.konst(enc)), arr_r[i]);
150
+ L.assert_eq(em_s.mux(L.konst(enc)), arr_s[i]);
151
+ }
152
+ }
153
+
154
+ // Test use of the EltMuxer machinery to test whether a smaller muxer input
155
+ // is in range. In this case, we want to test whether the muxed input is in
156
+ // {0,1,2,3,4,5,6,7}. We want to ensure that there are no false positives and
157
+ // thus the test iterates over the entire field.
158
+ TEST(BitPlucker, EltMuxer9) {
159
+ using Field = Fp<1>;
160
+ using EvalBackend = EvaluationBackend<Field>;
161
+ using Logic = Logic<Field, EvalBackend>;
162
+ using EltW = Logic::EltW;
163
+
164
+ const Field F("257");
165
+ const EvalBackend ebk(F);
166
+ const Logic L(&ebk, F);
167
+ const EltW zero = L.konst(0);
168
+ const EltW one = L.konst(1);
169
+
170
+ EltW arr_v[] = {zero, zero, zero, zero, zero, zero, zero, zero, one};
171
+ const EltMuxer<Logic, 9, 8> em2(L, arr_v);
172
+ for (size_t i = 0; i < 128 + /*intentional extra element*/ 1; ++i) {
173
+ auto enc = bit_plucker_point<Field, 8>()(i, F);
174
+ if (i < 9) {
175
+ L.assert_eq(em2.mux(L.konst(enc)), arr_v[i]);
176
+ } else {
177
+ EXPECT_NE(em2.mux(L.konst(enc)).elt(), F.zero());
178
+ }
179
+ }
180
+ }
181
+
182
+ } // namespace
183
+ } // namespace proofs
@@ -0,0 +1,62 @@
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_CIRCUITS_LOGIC_COMPILER_BACKEND_H_
16
+ #define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_COMPILER_BACKEND_H_
17
+
18
+ #include <stdlib.h>
19
+
20
+ #include <cstddef>
21
+
22
+ #include "circuits/compiler/compiler.h"
23
+
24
+ namespace proofs {
25
+ // backend that compiles a circuit that, when evaluated, computes Elt's
26
+ template <class Field>
27
+ class CompilerBackend {
28
+ using QuadCircuitF = QuadCircuit<Field>;
29
+ using Elt = typename Field::Elt;
30
+
31
+ public:
32
+ using V = size_t;
33
+
34
+ explicit CompilerBackend(QuadCircuitF* q) : q_(q) {}
35
+
36
+ V assert0(const V& a) const { return q_->assert0(a); }
37
+ V add(const V& a, const V& b) const { return q_->add(a, b); }
38
+ V sub(const V& a, const V& b) const {
39
+ auto mb = mul(konst(q_->f_.mone()), b);
40
+ return add(a, mb);
41
+ }
42
+ V mul(const V& a, const V& b) const { return q_->mul(a, b); }
43
+ V mul(const Elt& a, const V& b) const { return q_->mul(a, b); }
44
+ V mul(const Elt& a, const V& b, const V& c) const { return q_->mul(a, b, c); }
45
+ V konst(const Elt& a) const { return q_->konst(a); }
46
+
47
+ V ax(const Elt& a, const V& x) const { return q_->mul(a, x); }
48
+ V axy(const Elt& a, const V& x, const V& y) const { return q_->mul(a, x, y); }
49
+ V axpy(const V& y, const Elt& a, const V& x) const {
50
+ return q_->axpy(y, a, x);
51
+ }
52
+ V apy(const V& y, const Elt& a) const { return q_->apy(y, a); }
53
+
54
+ V input_wire() const { return q_->input_wire(); }
55
+ void output_wire(size_t n, V wire_id) const { q_->output_wire(n, wire_id); }
56
+
57
+ private:
58
+ QuadCircuitF* q_;
59
+ };
60
+ } // namespace proofs
61
+
62
+ #endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_COMPILER_BACKEND_H_
@@ -0,0 +1,171 @@
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_CIRCUITS_LOGIC_COUNTER_H_
16
+ #define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_COUNTER_H_
17
+
18
+ #include <stddef.h>
19
+
20
+ #include <cstdint>
21
+
22
+ // Embedding of small unsigned integers into an additive group of
23
+ // unspecified size, but assumed to be able to encode 16 bits or so.
24
+ // For prime fields inject the integer mod p, and for
25
+ // binary fields use the multiplicative group.
26
+ namespace proofs {
27
+
28
+ template <class Logic, bool kCharacteristicTwo>
29
+ class CounterAux;
30
+
31
+ // Use the additive group in fields with large characteristic
32
+ template <class Logic_>
33
+ class CounterAux<Logic_, /*kCharacteristicTwo=*/false> {
34
+ public:
35
+ using Logic = Logic_;
36
+ using Field = typename Logic::Field;
37
+ using EltW = typename Logic::EltW;
38
+ using BitW = typename Logic::BitW;
39
+ using CElt = typename Field::CElt;
40
+
41
+ // Even though everything is ultimately represented
42
+ // as EltW, keeps the types distinct to avoid
43
+ // confusion.
44
+
45
+ struct CEltW {
46
+ EltW e;
47
+ };
48
+
49
+ explicit CounterAux(const Logic& l) : l_(l) {}
50
+
51
+ const Logic& logic() const { return l_; }
52
+
53
+ // Convert a counter into *some* field element such that the counter is
54
+ // nonzero (as a counter) iff the field element is nonzero.
55
+ EltW znz_indicator(const CEltW& celt) const { return celt.e; }
56
+
57
+ CEltW mone() const { return CEltW{l_.konst(l_.mone())}; }
58
+ CEltW as_counter(uint64_t n) const { return CEltW{l_.konst(n)}; }
59
+ CEltW as_counter(const CElt& x) const { return CEltW{l_.konst(x.e)}; }
60
+
61
+ CEltW as_counter(const BitW& b) const { return CEltW{l_.eval(b)}; }
62
+
63
+ template <size_t N>
64
+ CEltW as_counter(const typename Logic::template bitvec<N>& v) const {
65
+ // counters have the same representation as scalars
66
+ return CEltW{l_.as_scalar(v)};
67
+ }
68
+
69
+ CEltW add(const CEltW& a, const CEltW& b) const {
70
+ return CEltW{l_.add(a.e, b.e)};
71
+ }
72
+
73
+ // a ? b : 0
74
+ CEltW ite0(const BitW& a, const CEltW& b) const {
75
+ return CEltW{l_.mul(l_.eval(a), b.e)};
76
+ }
77
+
78
+ // a ? b : c
79
+ CEltW mux(const BitW& a, const CEltW& b, const CEltW& c) const {
80
+ return add(c, ite0(a, sub(b, c)));
81
+ }
82
+ void assert0(const CEltW& a) const { l_.assert0(a.e); }
83
+ void assert_eq(const CEltW& a, const CEltW& b) const {
84
+ l_.assert_eq(a.e, b.e);
85
+ }
86
+
87
+ CEltW input() const { return CEltW{l_.eltw_input()}; }
88
+
89
+ private:
90
+ const Logic& l_;
91
+
92
+ // used only internally, do not export since we don't
93
+ // want to invert in the multiplicative group
94
+ CEltW sub(const CEltW& a, const CEltW& b) const {
95
+ return CEltW{l_.sub(a.e, b.e)};
96
+ }
97
+ };
98
+
99
+ // use the multiplicative group in characteristic 2
100
+ template <class Logic_>
101
+ class CounterAux<Logic_, /*kCharacteristicTwo=*/true> {
102
+ public:
103
+ using Logic = Logic_;
104
+ using Field = typename Logic::Field;
105
+ using EltW = typename Logic::EltW;
106
+ using BitW = typename Logic::BitW;
107
+ using CElt = typename Field::CElt;
108
+
109
+ struct CEltW {
110
+ EltW e;
111
+ };
112
+
113
+ explicit CounterAux(const Logic& l) : l_(l) {}
114
+
115
+ const Logic& logic() const { return l_; }
116
+
117
+ // Convert a counter into *some* field element such that the counter is
118
+ // nonzero (as a counter) iff the field element is nonzero.
119
+ EltW znz_indicator(const CEltW& celt) const {
120
+ return l_.sub(celt.e, l_.konst(l_.one()));
121
+ }
122
+
123
+ CEltW mone() const { return CEltW{l_.konst(l_.f_.invg())}; }
124
+ CEltW as_counter(uint64_t n) const {
125
+ return CEltW{l_.konst(l_.f_.as_counter(n).e)};
126
+ }
127
+ CEltW as_counter(const CElt& x) const { return CEltW{l_.konst(x.e)}; }
128
+
129
+ CEltW as_counter(const BitW& b) const {
130
+ CEltW iftrue = CEltW{l_.konst(l_.f_.g())};
131
+ return ite0(b, iftrue);
132
+ }
133
+
134
+ template <size_t N>
135
+ CEltW as_counter(const typename Logic::template bitvec<N>& v) const {
136
+ // do the multiplication in Logic since we don't have
137
+ // a range addition in Counter
138
+ return CEltW{l_.mul(0, N, [&](size_t i) {
139
+ return l_.mux(v[i], l_.konst(l_.f_.counter_beta(i)), l_.konst(l_.one()));
140
+ })};
141
+ }
142
+
143
+ CEltW add(const CEltW& a, const CEltW& b) const {
144
+ return CEltW{l_.mul(a.e, b.e)};
145
+ }
146
+
147
+ // a ? b : 0
148
+ CEltW ite0(const BitW& a, const CEltW& b) const {
149
+ return CEltW{l_.mux(a, b.e, l_.konst(l_.one()))};
150
+ }
151
+
152
+ // a ? b : c
153
+ CEltW mux(const BitW& a, const CEltW& b, const CEltW& c) const {
154
+ return CEltW{l_.mux(a, b.e, c.e)};
155
+ }
156
+ void assert0(const CEltW& a) const { l_.assert_eq(a.e, l_.konst(l_.one())); }
157
+ void assert_eq(const CEltW& a, const CEltW& b) const {
158
+ l_.assert_eq(a.e, b.e);
159
+ }
160
+
161
+ CEltW input() const { return CEltW{l_.eltw_input()}; }
162
+
163
+ private:
164
+ const Logic& l_;
165
+ };
166
+
167
+ template <class Logic>
168
+ using Counter = CounterAux<Logic, Logic::Field::kCharacteristicTwo>;
169
+ } // namespace proofs
170
+
171
+ #endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_COUNTER_H_
@@ -0,0 +1,102 @@
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 "circuits/logic/counter.h"
16
+
17
+ #include <stddef.h>
18
+
19
+ #include "algebra/fp_p128.h"
20
+ #include "circuits/logic/evaluation_backend.h"
21
+ #include "circuits/logic/logic.h"
22
+ #include "gf2k/gf2_128.h"
23
+ #include "gtest/gtest.h"
24
+
25
+ namespace proofs {
26
+ namespace {
27
+
28
+ template <class Field>
29
+ void test_counter() {
30
+ const Field F;
31
+ constexpr size_t w = 7;
32
+
33
+ using EvalBackend = EvaluationBackend<Field>;
34
+ using Logic = Logic<Field, EvalBackend>;
35
+ using CounterL = Counter<Logic>;
36
+ const EvalBackend ebk(F, /* panic_on_assertion_failure=*/false);
37
+ const Logic L(&ebk, F);
38
+ const CounterL CTR(L);
39
+
40
+ for (size_t a = 0; a < (1 << w); ++a) {
41
+ auto ca = CTR.as_counter(a);
42
+
43
+ // Computing CA in the circuit from a bitvec
44
+ // produces the same result as computing CA in the field
45
+ {
46
+ CTR.assert_eq(ca, CTR.as_counter(F.as_counter(a)));
47
+ EXPECT_FALSE(ebk.assertion_failed());
48
+ CTR.assert_eq(ca, CTR.as_counter(L.template vbit<w>(a)));
49
+ EXPECT_FALSE(ebk.assertion_failed());
50
+ }
51
+
52
+ {
53
+ auto eca = CTR.znz_indicator(ca);
54
+ L.assert0(eca);
55
+ EXPECT_EQ(ebk.assertion_failed(), (a != 0));
56
+
57
+ // F.znz_indicator() and CTR.znz_indicator() must compute the
58
+ // same thing
59
+ L.assert_eq(eca, L.konst(F.znz_indicator(F.as_counter(a))));
60
+ EXPECT_FALSE(ebk.assertion_failed());
61
+ }
62
+
63
+ {
64
+ // assert0() works as expected
65
+ CTR.assert0(ca);
66
+ EXPECT_EQ(ebk.assertion_failed(), (a != 0));
67
+ }
68
+
69
+ {
70
+ // minus one works as expected
71
+ auto cam1 = CTR.add(ca, CTR.mone());
72
+ CTR.assert0(cam1);
73
+ EXPECT_EQ(ebk.assertion_failed(), (a != 1));
74
+
75
+ if (a > 0) {
76
+ auto want_cam1 = CTR.as_counter(a - 1);
77
+ CTR.assert_eq(cam1, want_cam1);
78
+ EXPECT_FALSE(ebk.assertion_failed());
79
+ }
80
+ }
81
+
82
+ // addition works as expected
83
+ for (size_t b = 0; b < (1 << w); ++b) {
84
+ auto cb = CTR.as_counter(b);
85
+ for (size_t s = 0; s < (2 << w); ++s) {
86
+ auto cs = CTR.as_counter(s);
87
+
88
+ auto ab = CTR.add(ca, cb);
89
+ CTR.assert_eq(ab, cs);
90
+ EXPECT_EQ(ebk.assertion_failed(), ((a + b) != s));
91
+ }
92
+ }
93
+ }
94
+ }
95
+
96
+ TEST(Counter, Fields) {
97
+ test_counter<GF2_128<>>();
98
+ test_counter<Fp128<>>();
99
+ }
100
+
101
+ } // namespace
102
+ } // namespace proofs
@@ -0,0 +1,94 @@
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_CIRCUITS_LOGIC_EVALUATION_BACKEND_H_
16
+ #define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_EVALUATION_BACKEND_H_
17
+
18
+ #include "util/panic.h"
19
+
20
+ namespace proofs {
21
+ // backend that evaluates values directly
22
+ template <class Field>
23
+ class EvaluationBackend {
24
+ using Elt = typename Field::Elt;
25
+
26
+ public:
27
+ explicit EvaluationBackend(const Field& F,
28
+ bool panic_on_assertion_failure = true)
29
+ : f_(F),
30
+ panic_on_assertion_failure_(panic_on_assertion_failure),
31
+ assertion_failed_(false) {}
32
+
33
+ ~EvaluationBackend() {
34
+ // Crash if assertion_failed_, which indicates that a test
35
+ // has forgotten to read the value
36
+ check(!assertion_failed_, "assertion_failed_ true in ~EvaluationBackend()");
37
+ }
38
+
39
+ // Reading ASSERTION_FAILED_ returns the current ASSERTION_FAILED_
40
+ // state and resets the state.
41
+ bool assertion_failed() const {
42
+ bool b = assertion_failed_;
43
+ assertion_failed_ = false;
44
+ return b;
45
+ }
46
+
47
+ struct V {
48
+ Elt e;
49
+ V() = default;
50
+ explicit V(const Elt& x) : e(x) {}
51
+ Elt elt() const { return e; }
52
+
53
+ bool operator==(const V& y) const { return e == y.e; }
54
+ bool operator!=(const V& y) const { return e != y.e; }
55
+ };
56
+
57
+ V assert0(const V& a) const {
58
+ if (a.e == f_.zero()) {
59
+ return a;
60
+ } else {
61
+ if (panic_on_assertion_failure_) {
62
+ check(false, "a != F.zero()");
63
+ }
64
+ assertion_failed_ = true;
65
+ }
66
+ return a;
67
+ }
68
+
69
+ V add(const V& a, const V& b) const { return V{f_.addf(a.e, b.e)}; }
70
+ V sub(const V& a, const V& b) const { return V{f_.subf(a.e, b.e)}; }
71
+ V mul(const V& a, const V& b) const { return V{f_.mulf(a.e, b.e)}; }
72
+ V mul(const Elt& a, const V& b) const { return V{f_.mulf(a, b.e)}; }
73
+ V mul(const Elt& a, const V& b, const V& c) const {
74
+ return mul(a, mul(b, c));
75
+ }
76
+ V konst(const Elt& a) const { return V{a}; }
77
+
78
+ V ax(const Elt& a, const V& x) const { return V{f_.mulf(a, x.e)}; }
79
+ V axy(const Elt& a, const V& x, const V& y) const {
80
+ return V{f_.mulf(a, f_.mulf(x.e, y.e))};
81
+ }
82
+ V axpy(const V& y, const Elt& a, const V& x) const {
83
+ return V{f_.addf(y.e, f_.mulf(a, x.e))};
84
+ }
85
+ V apy(const V& y, const Elt& a) const { return V{f_.addf(y.e, a)}; }
86
+
87
+ private:
88
+ const Field& f_;
89
+ bool panic_on_assertion_failure_;
90
+ mutable bool assertion_failed_;
91
+ };
92
+ } // namespace proofs
93
+
94
+ #endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_EVALUATION_BACKEND_H_