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,150 @@
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_CBOR_PARSER_CBOR_BYTE_DECODER_H_
16
+ #define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_BYTE_DECODER_H_
17
+
18
+ #include <stddef.h>
19
+ #include <stdint.h>
20
+
21
+ #include "circuits/logic/counter.h"
22
+
23
+ namespace proofs {
24
+ template <class Logic>
25
+ class CborByteDecoder {
26
+ public:
27
+ using CounterL = Counter<Logic>;
28
+ using Field = typename Logic::Field;
29
+ using EltW = typename Logic::EltW;
30
+ using CEltW = typename CounterL::CEltW;
31
+ using BitW = typename Logic::BitW;
32
+ using v8 = typename Logic::v8;
33
+
34
+ explicit CborByteDecoder(const Logic& l) : l_(l), ctr_(l) {}
35
+
36
+ //------------------------------------------------------------
37
+ // Decoder (lexer)
38
+ //------------------------------------------------------------
39
+ struct decode {
40
+ BitW atomp;
41
+ BitW itemsp;
42
+ BitW stringp;
43
+ BitW arrayp;
44
+ BitW mapp;
45
+ BitW tagp;
46
+ BitW specialp;
47
+ BitW simple_specialp; // One of false, true, null, or undefined.
48
+ BitW count0_23;
49
+ BitW count24_27;
50
+ BitW count24;
51
+ BitW count25;
52
+ BitW count26;
53
+ BitW count27;
54
+ BitW length_plus_next_v8;
55
+ BitW count_is_next_v8;
56
+ BitW invalid;
57
+ CEltW length; // of this item
58
+ EltW as_scalar;
59
+ CEltW as_counter;
60
+ CEltW count_as_counter;
61
+ v8 as_bits;
62
+ };
63
+
64
+ // Extract whatever we can from one v8 alone, without looking
65
+ // at witnesses, assuming that
66
+ // this v8 is the start of a cbor token.
67
+ struct decode decode_one_v8(const v8& v) const {
68
+ const Logic& L = l_; // shorthand
69
+ struct decode s;
70
+ L.vassert_is_bit(v);
71
+
72
+ // v = type:3 count:5
73
+ auto count = L.template slice<0, 5>(v);
74
+ auto type = L.template slice<5, 8>(v);
75
+
76
+ s.atomp = L.veqmask(type, /*mask*/ 0b110, /*val*/ 0b000);
77
+ s.stringp = L.veqmask(type, /*mask*/ 0b110, /*val*/ 0b010);
78
+ s.itemsp = L.veqmask(type, /*mask*/ 0b110, /*val*/ 0b100);
79
+
80
+ s.specialp = L.veq(type, 7);
81
+ s.tagp = L.veq(type, 6);
82
+ s.arrayp = L.land(s.itemsp, L.lnot(type[0]));
83
+ s.mapp = L.land(s.itemsp, type[0]);
84
+
85
+ // count0_23 = (0 <= count < 24) = ~(count == 11xxx)
86
+ s.count0_23 = L.lnot(L.veqmask(count, /*mask*/ 0b11000, /*val*/ 0b11000));
87
+ s.count24_27 = L.veqmask(count, /*mask*/ 0b11100, /*val*/ 0b11000);
88
+
89
+ s.count24 = L.veq(count, 24);
90
+ s.count25 = L.veq(count, 25);
91
+ s.count26 = L.veq(count, 26);
92
+ s.count27 = L.veq(count, 27);
93
+
94
+ BitW count20_23 = L.veqmask(count, /*mask*/ 0b11100, /*val*/ 0b10100);
95
+ s.simple_specialp = L.land(s.specialp, count20_23);
96
+
97
+ // stringp && count24
98
+ s.length_plus_next_v8 =
99
+ L.veqmask(v, /*mask*/ 0b110'11111, /*val*/ 0b010'11000);
100
+
101
+ // itemsp && count24
102
+ s.count_is_next_v8 =
103
+ L.veqmask(v, /*mask*/ 0b110'11111, /*val*/ 0b100'11000);
104
+
105
+ BitW count0_24 = L.lor_exclusive(s.count24, s.count0_23);
106
+ BitW atom_or_tag = L.lor_exclusive(s.atomp, s.tagp);
107
+
108
+ // count0_24 works for all types (except invalid special)
109
+ // but atom_or_tag supports count <= 27
110
+ BitW good_count = L.lor(count0_24, L.land(atom_or_tag, s.count24_27));
111
+ BitW invalid_special = L.land(s.specialp, L.lnot(s.simple_specialp));
112
+ s.invalid = L.lor(invalid_special, L.lnot(good_count));
113
+
114
+ s.count_as_counter = ctr_.as_counter(count);
115
+
116
+ // Hack to compute the length. Unclear what the right
117
+ // abstraction should be.
118
+
119
+ // Compute l24_27, the length assuming count24_27
120
+ CEltW l1 = ctr_.as_counter(1 + 1);
121
+ CEltW l2 = ctr_.as_counter(1 + 2);
122
+ CEltW l4 = ctr_.as_counter(1 + 4);
123
+ CEltW l8 = ctr_.as_counter(1 + 8);
124
+ CEltW l24_25 = ctr_.mux(count[0], l2, l1);
125
+ CEltW l26_27 = ctr_.mux(count[0], l8, l4);
126
+ CEltW l24_27 = ctr_.mux(count[1], l26_27, l24_25);
127
+
128
+ // choose between count0_23 and count24_27
129
+ CEltW x1 = ctr_.as_counter(1);
130
+ s.length = ctr_.mux(s.count0_23, x1, l24_27);
131
+
132
+ // adjust for strings
133
+ BitW str_23 = L.land(s.stringp, s.count0_23);
134
+ CEltW adjust_if_string = ctr_.ite0(str_23, s.count_as_counter);
135
+ s.length = ctr_.add(s.length, adjust_if_string);
136
+
137
+ s.as_counter = ctr_.as_counter(v);
138
+ s.as_scalar = L.as_scalar(v);
139
+ s.as_bits = v;
140
+
141
+ return s;
142
+ }
143
+
144
+ private:
145
+ const Logic& l_;
146
+ const CounterL ctr_;
147
+ };
148
+ } // namespace proofs
149
+
150
+ #endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_BYTE_DECODER_H_
@@ -0,0 +1,147 @@
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/cbor_parser/cbor_byte_decoder.h"
16
+
17
+ #include <stddef.h>
18
+
19
+ #include "algebra/fp.h"
20
+ #include "circuits/logic/counter.h"
21
+ #include "circuits/logic/evaluation_backend.h"
22
+ #include "circuits/logic/logic.h"
23
+ #include "gf2k/gf2_128.h"
24
+ #include "gtest/gtest.h"
25
+
26
+ namespace proofs {
27
+ namespace {
28
+
29
+ template <class Field>
30
+ void test_decode_one_v8(const Field& F) {
31
+ using EvalBackend = EvaluationBackend<Field>;
32
+ using Logic = Logic<Field, EvalBackend>;
33
+ using CounterL = Counter<Logic>;
34
+
35
+ const EvalBackend ebk(F);
36
+ const Logic L(&ebk, F);
37
+ const CounterL CTR(L);
38
+
39
+ using CborBD = CborByteDecoder<Logic>;
40
+ const CborBD CBORBD(L);
41
+ for (size_t type = 0; type < 8; ++type) {
42
+ for (size_t count = 0; count < 32; ++count) {
43
+ size_t v_as_size_t = (type << 5) | count;
44
+ typename Logic::v8 v = L.template vbit<8>(v_as_size_t);
45
+ auto ds = CBORBD.decode_one_v8(v);
46
+
47
+ bool atomp = (type == 0) || (type == 1);
48
+ bool stringp = (type == 2) || (type == 3);
49
+ bool arrayp = (type == 4);
50
+ bool mapp = (type == 5);
51
+ bool itemsp = arrayp || mapp;
52
+ bool tagp = (type == 6);
53
+ bool specialp = (type == 7);
54
+ bool simple_specialp = specialp && (20 <= count && count < 24);
55
+ bool count0_23 = (count < 24);
56
+ bool count24_27 = (24 <= count) && (count < 28);
57
+ bool count24 = (count == 24);
58
+ bool count25 = (count == 25);
59
+ bool count26 = (count == 26);
60
+ bool count27 = (count == 27);
61
+
62
+ bool length_plus_next_v8 = false;
63
+ bool count_is_next_v8 = false;
64
+ bool invalid = false;
65
+ size_t length = ~0; // bogus
66
+ size_t count_as_counter = count;
67
+ if (atomp || tagp) {
68
+ if (count0_23) {
69
+ length = 1;
70
+ } else if (count24) {
71
+ length = 1 + 1;
72
+ } else if (count25) {
73
+ length = 1 + 2;
74
+ } else if (count26) {
75
+ length = 1 + 4;
76
+ } else if (count27) {
77
+ length = 1 + 8;
78
+ } else {
79
+ invalid = true;
80
+ }
81
+ } else if (itemsp) {
82
+ if (count0_23) {
83
+ length = 1;
84
+ } else if (count24) {
85
+ length = 2;
86
+ count_is_next_v8 = true;
87
+ } else {
88
+ invalid = true;
89
+ }
90
+ } else if (stringp) {
91
+ if (count0_23) {
92
+ length = 1 + count;
93
+ } else if (count24) {
94
+ length = 2;
95
+ length_plus_next_v8 = true;
96
+ } else {
97
+ invalid = true;
98
+ }
99
+ } else if (simple_specialp) {
100
+ length = 1;
101
+ } else {
102
+ invalid = true;
103
+ }
104
+
105
+ EXPECT_EQ(L.eval(ds.atomp), L.eval(L.bit(atomp)));
106
+ EXPECT_EQ(L.eval(ds.itemsp), L.eval(L.bit(itemsp)));
107
+ EXPECT_EQ(L.eval(ds.stringp), L.eval(L.bit(stringp)));
108
+ EXPECT_EQ(L.eval(ds.arrayp), L.eval(L.bit(arrayp)));
109
+ EXPECT_EQ(L.eval(ds.mapp), L.eval(L.bit(mapp)));
110
+ EXPECT_EQ(L.eval(ds.tagp), L.eval(L.bit(tagp)));
111
+ EXPECT_EQ(L.eval(ds.specialp), L.eval(L.bit(specialp)));
112
+ EXPECT_EQ(L.eval(ds.simple_specialp), L.eval(L.bit(simple_specialp)));
113
+
114
+ EXPECT_EQ(L.eval(ds.count0_23), L.eval(L.bit(count0_23)));
115
+ EXPECT_EQ(L.eval(ds.count24_27), L.eval(L.bit(count24_27)));
116
+ EXPECT_EQ(L.eval(ds.count24), L.eval(L.bit(count24)));
117
+ EXPECT_EQ(L.eval(ds.count25), L.eval(L.bit(count25)));
118
+ EXPECT_EQ(L.eval(ds.count26), L.eval(L.bit(count26)));
119
+ EXPECT_EQ(L.eval(ds.count27), L.eval(L.bit(count27)));
120
+ EXPECT_EQ(L.eval(ds.length_plus_next_v8),
121
+ L.eval(L.bit(length_plus_next_v8)));
122
+ EXPECT_EQ(L.eval(ds.count_is_next_v8), L.eval(L.bit(count_is_next_v8)));
123
+ EXPECT_EQ(L.eval(ds.invalid), L.eval(L.bit(invalid)));
124
+
125
+ if (!invalid) {
126
+ // the length is don't care unless valid
127
+ EXPECT_EQ(ds.length.e, CTR.as_counter(length).e);
128
+ }
129
+
130
+ EXPECT_EQ(ds.count_as_counter.e, CTR.as_counter(count_as_counter).e);
131
+ EXPECT_EQ(ds.as_counter.e, CTR.as_counter(v_as_size_t).e);
132
+ EXPECT_EQ(ds.as_scalar, L.konst(v_as_size_t));
133
+ for (size_t k = 0; k < 8; ++k) {
134
+ EXPECT_EQ(L.eval(ds.as_bits[k]), L.eval(L.bit((v_as_size_t >> k) & 1)));
135
+ }
136
+ }
137
+ }
138
+ }
139
+
140
+ TEST(CborByteDecoder, PrimeField) {
141
+ test_decode_one_v8(Fp<1>("18446744073709551557"));
142
+ }
143
+
144
+ TEST(CborByteDecoder, BinaryField) { test_decode_one_v8(GF2_128<>()); }
145
+
146
+ } // namespace
147
+ } // namespace proofs
@@ -0,0 +1,27 @@
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_CBOR_PARSER_CBOR_CONSTANTS_H_
16
+ #define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_CONSTANTS_H_
17
+
18
+ #include <stddef.h>
19
+
20
+ namespace proofs {
21
+ struct CborConstants {
22
+ static constexpr size_t kNCounters = 4;
23
+ static constexpr size_t kIndexBits = 12;
24
+ };
25
+ } // namespace proofs
26
+
27
+ #endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_CONSTANTS_H_
@@ -0,0 +1,110 @@
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_CBOR_PARSER_CBOR_PLUCK_H_
16
+ #define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_PLUCK_H_
17
+ #include <stddef.h>
18
+ #include <stdint.h>
19
+
20
+ #include <vector>
21
+
22
+ #include "algebra/interpolation.h"
23
+ #include "algebra/poly.h"
24
+ #include "circuits/logic/bit_plucker_constants.h"
25
+ #include "circuits/logic/polynomial.h"
26
+
27
+ namespace proofs {
28
+ // Special plucker that decodes into a pair (B, J) where B is one bit,
29
+ // and J is an array of NJ bits at most one of which can be set.
30
+ //
31
+ // B can assume one of two distinct values, and J can assume NJ+1
32
+ // distinct values. Thus there are N = 2*(NJ+1) evaluation points.
33
+ // We encode J as the index IJ of which bit is set, or IJ=NJ if no bit
34
+ // is set.
35
+ template <class Logic, size_t NJ>
36
+ class CborPlucker {
37
+ public:
38
+ using Field = typename Logic::Field;
39
+ using BitW = typename Logic::BitW;
40
+ using EltW = typename Logic::EltW;
41
+ using Elt = typename Field::Elt;
42
+ static constexpr size_t kN = 2 * (NJ + 1);
43
+ using PolyN = Poly<kN, Field>;
44
+ using InterpolationN = Interpolation<kN, Field>;
45
+ const Logic& l_;
46
+ PolyN pluckerb_;
47
+ std::vector<PolyN> pluckerj_;
48
+
49
+ explicit CborPlucker(const Logic& l) : l_(l), pluckerj_(NJ) {
50
+ const Field& F = l_.f_; // shorthand
51
+ // evaluation points
52
+ PolyN X;
53
+ for (size_t i = 0; i < kN; ++i) {
54
+ X[i] = bit_plucker_point<Field, kN>()(i, F);
55
+ }
56
+
57
+ // encode B in the low-order bit
58
+ PolyN Y;
59
+ for (size_t i = 0; i < kN; ++i) {
60
+ Y[i] = F.of_scalar(i & 1);
61
+ }
62
+ pluckerb_ = InterpolationN::monomial_of_lagrange(Y, X, F);
63
+
64
+ // encode J in the high-order bits
65
+ for (size_t j = 0; j < NJ; ++j) {
66
+ for (size_t i = 0; i < kN; ++i) {
67
+ Y[i] = F.of_scalar((i >> 1) == j);
68
+ }
69
+ pluckerj_[j] = InterpolationN::monomial_of_lagrange(Y, X, F);
70
+ }
71
+ }
72
+
73
+ BitW pluckb(const EltW& e) const {
74
+ const Logic& L = l_; // shorthand
75
+ const Polynomial<Logic> P(L);
76
+
77
+ EltW v = P.eval(pluckerb_, e);
78
+ L.assert_is_bit(v);
79
+ return BitW(v, L.f_);
80
+ }
81
+
82
+ typename Logic::template bitvec<NJ> pluckj(const EltW& e) const {
83
+ typename Logic::template bitvec<NJ> r;
84
+ const Logic& L = l_; // shorthand
85
+ const Polynomial<Logic> P(L);
86
+
87
+ for (size_t j = 0; j < NJ; ++j) {
88
+ EltW v = P.eval(pluckerj_[j], e);
89
+ L.assert_is_bit(v);
90
+ r[j] = BitW(v, L.f_);
91
+ }
92
+
93
+ return r;
94
+ }
95
+ };
96
+
97
+ template <class Field, size_t NJ>
98
+ struct cbor_plucker_point {
99
+ using Elt = typename Field::Elt;
100
+ static constexpr size_t kN = 2 * (NJ + 1);
101
+
102
+ // packing of bits compatible with even_lagrange_basis():
103
+ Elt operator()(bool b, size_t j, const Field& F) const {
104
+ uint64_t bits = b + 2 * j;
105
+ return bit_plucker_point<Field, kN>()(bits, F);
106
+ }
107
+ };
108
+ } // namespace proofs
109
+
110
+ #endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_PLUCK_H_
@@ -0,0 +1,55 @@
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/cbor_parser/cbor_pluck.h"
16
+
17
+ #include <stddef.h>
18
+
19
+ #include "algebra/fp.h"
20
+ #include "circuits/logic/bit_plucker_constants.h"
21
+ #include "circuits/logic/evaluation_backend.h"
22
+ #include "circuits/logic/logic.h"
23
+ #include "gf2k/gf2_128.h"
24
+ #include "gtest/gtest.h"
25
+
26
+ namespace proofs {
27
+ namespace {
28
+
29
+ template <class Field>
30
+ void pluck_test(const Field &F) {
31
+ using EvalBackend = EvaluationBackend<Field>;
32
+ using Logic = Logic<Field, EvalBackend>;
33
+
34
+ constexpr size_t NJ = 7;
35
+ constexpr size_t N = 2 * (NJ + 1);
36
+ const EvalBackend ebk(F);
37
+ const Logic L(&ebk, F);
38
+ const CborPlucker<Logic, NJ> P(L);
39
+
40
+ for (size_t i = 0; i < N; ++i) {
41
+ auto gotb = P.pluckb(L.konst(bit_plucker_point<Field, N>()(i, F)));
42
+ auto gotj = P.pluckj(L.konst(bit_plucker_point<Field, N>()(i, F)));
43
+ EXPECT_EQ(L.eval(gotb), L.konst(i & 1));
44
+ for (size_t j = 0; j < NJ; ++j) {
45
+ EXPECT_EQ(L.eval(gotj[j]), L.konst((i >> 1) == j));
46
+ }
47
+ }
48
+ }
49
+
50
+ TEST(CborPluck, PluckPrimeField) { pluck_test(Fp<1>("18446744073709551557")); }
51
+
52
+ TEST(CborPluck, PluckBinaryField) { pluck_test(GF2_128<>()); }
53
+
54
+ } // namespace
55
+ } // namespace proofs
@@ -0,0 +1,174 @@
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/cbor_parser/cbor.h"
16
+
17
+ #include <stddef.h>
18
+
19
+ #include <cstdint>
20
+ #include <vector>
21
+
22
+ #include "circuits/cbor_parser/cbor_constants.h"
23
+ #include "circuits/cbor_parser/cbor_pluck.h"
24
+ #include "circuits/compiler/circuit_dump.h"
25
+ #include "circuits/compiler/compiler.h"
26
+ #include "circuits/logic/compiler_backend.h"
27
+ #include "circuits/logic/counter.h"
28
+ #include "circuits/logic/evaluation_backend.h"
29
+ #include "circuits/logic/logic.h"
30
+ #include "gf2k/gf2_128.h"
31
+ #include "util/log.h"
32
+ #include "gtest/gtest.h"
33
+
34
+ namespace proofs {
35
+ namespace {
36
+ using Field = GF2_128<>;
37
+ const Field F;
38
+
39
+ using CompilerBackend = CompilerBackend<Field>;
40
+ using LogicCircuit = Logic<Field, CompilerBackend>;
41
+
42
+ using EvalBackend = EvaluationBackend<Field>;
43
+ using Logic = Logic<Field, EvalBackend>;
44
+ using CounterL = Counter<Logic>;
45
+
46
+
47
+ // encoder of input bytes
48
+ static inline uint8_t X(uint8_t type, uint8_t count) {
49
+ return (type << 5) | count;
50
+ }
51
+
52
+ const struct {
53
+ uint8_t v, len;
54
+ } testcase[] = {
55
+ // a small atom, constant 23
56
+ {X(0, 23), 1},
57
+
58
+ // a larger atom, constant 33
59
+ {X(0, 24), 2},
60
+ {33},
61
+
62
+ // another large atom
63
+ {X(0, 24), 2},
64
+ {34},
65
+
66
+ // a short string
67
+ {X(2, 3), 4},
68
+ {'f'},
69
+ {'o'},
70
+ {'o'},
71
+
72
+ // a long string
73
+ {X(2, 24), 5}, // header + next byte + string
74
+ {/*length of the string*/ 3},
75
+ {0xff},
76
+ {25},
77
+ {31},
78
+
79
+ // another small atom
80
+ {X(0, 22), 1},
81
+
82
+ // a long string
83
+ {X(2, 24), 6}, // header + next byte + string
84
+ {/*length of the string*/ 4},
85
+ {'q'},
86
+ {'u'},
87
+ {'u'},
88
+ {'x'},
89
+ };
90
+ constexpr size_t ntestcase = sizeof(testcase) / sizeof(testcase[0]);
91
+
92
+ TEST(CBOR, VerifyDecode) {
93
+ const EvalBackend ebk(F);
94
+ const Logic L(&ebk, F);
95
+ using Cbor = Cbor<Logic>;
96
+ const Cbor CBOR(L);
97
+
98
+ constexpr size_t n = ntestcase;
99
+ std::vector<Cbor::v8> in(n);
100
+ std::vector<Cbor::position_witness> pw(n);
101
+ Cbor::global_witness gw;
102
+
103
+ size_t slen = 1;
104
+ auto prod = F.one();
105
+ for (size_t i = 0; i < n; ++i) {
106
+ in[i] = L.vbit<8>(testcase[i].v);
107
+
108
+ size_t slenm1 = slen - 1;
109
+ size_t slen_next;
110
+ if (slenm1 == 0) {
111
+ slen_next = testcase[i].len;
112
+ } else {
113
+ if (i > 0) {
114
+ prod = F.mulf(prod, F.znz_indicator(F.as_counter(slenm1)));
115
+ }
116
+ slen_next = slenm1;
117
+ }
118
+ pw[i].encoded_sel_header =
119
+ L.konst(cbor_plucker_point<Field, CborConstants::kNCounters>()(
120
+ (slenm1 == 0), 0, F));
121
+ slen = slen_next;
122
+ }
123
+
124
+ std::vector<Cbor::decode> ds(n);
125
+ gw.invprod_decode = L.konst(F.invertf(prod));
126
+ CBOR.decode_and_assert_decode(n, ds.data(), in.data(), pw.data(), gw);
127
+ }
128
+
129
+ TEST(CBOR, VerifyParseSize) {
130
+ set_log_level(INFO);
131
+
132
+ size_t sizes[] = {247, 503, 1079, 1591, 2231, 2551};
133
+
134
+ for (size_t i = 0; i < sizeof(sizes) / sizeof(sizes[0]); ++i) {
135
+ size_t n = sizes[i];
136
+ QuadCircuit<Field> Q(F);
137
+ const CompilerBackend cbk(&Q);
138
+ const LogicCircuit LC(&cbk, F);
139
+ using CborC = Cbor<LogicCircuit>;
140
+ const CborC CBORC(LC);
141
+ const Counter<LogicCircuit> CTRC(LC);
142
+
143
+ std::vector<CborC::v8> inC(n);
144
+ std::vector<CborC::position_witness> pwC(n);
145
+ CborC::global_witness gwC;
146
+
147
+ for (size_t j = 0; j < n; ++j) {
148
+ inC[j] = LC.vinput<8>();
149
+ pwC[j].encoded_sel_header = LC.eltw_input();
150
+ }
151
+ gwC.invprod_decode = LC.eltw_input();
152
+ gwC.cc0_counter = CTRC.input();
153
+ gwC.invprod_parse = LC.eltw_input();
154
+
155
+ std::vector<CborC::decode> dsC(n);
156
+ std::vector<CborC::parse_output> psC(n);
157
+ CBORC.decode_and_assert_decode_and_parse(n, dsC.data(), psC.data(),
158
+ inC.data(), pwC.data(), gwC);
159
+
160
+ // Fake parser output, otherwise the compiler eliminates important wires.
161
+ constexpr size_t kNCounters = CborC::kNCounters;
162
+ size_t nout = 0;
163
+ for (size_t j = 0; j < n; ++j) {
164
+ for (size_t l = 0; l < kNCounters; ++l) {
165
+ LC.output(psC[j].c[l].e, nout++);
166
+ }
167
+ }
168
+
169
+ auto CIRCUIT = Q.mkcircuit(/*nc=*/1);
170
+ dump_info<Field>("decode_and_assert_decode_and_parse", n, Q);
171
+ }
172
+ }
173
+ } // namespace
174
+ } // namespace proofs