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.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +152 -0
- data/ext/longfellow/CMakeLists.txt +76 -0
- data/ext/longfellow/extconf.rb +77 -0
- data/lib/longfellow/attribute.rb +65 -0
- data/lib/longfellow/c.rb +105 -0
- data/lib/longfellow/errors.rb +78 -0
- data/lib/longfellow/version.rb +5 -0
- data/lib/longfellow/zk_spec.rb +40 -0
- data/lib/longfellow.rb +162 -0
- data/sig/longfellow.rbs +74 -0
- data/vendor/longfellow-zk/LICENSE +203 -0
- data/vendor/longfellow-zk/lib/algebra/blas.h +121 -0
- data/vendor/longfellow-zk/lib/algebra/bogorng.h +68 -0
- data/vendor/longfellow-zk/lib/algebra/compare.h +40 -0
- data/vendor/longfellow-zk/lib/algebra/convolution.h +219 -0
- data/vendor/longfellow-zk/lib/algebra/crt.cc +42 -0
- data/vendor/longfellow-zk/lib/algebra/crt.h +299 -0
- data/vendor/longfellow-zk/lib/algebra/crt_convolution.h +114 -0
- data/vendor/longfellow-zk/lib/algebra/crt_test.cc +371 -0
- data/vendor/longfellow-zk/lib/algebra/fft.h +104 -0
- data/vendor/longfellow-zk/lib/algebra/fft_interpolation.h +304 -0
- data/vendor/longfellow-zk/lib/algebra/fft_interpolation_test.cc +168 -0
- data/vendor/longfellow-zk/lib/algebra/fft_test.cc +257 -0
- data/vendor/longfellow-zk/lib/algebra/fp.h +59 -0
- data/vendor/longfellow-zk/lib/algebra/fp2.h +240 -0
- data/vendor/longfellow-zk/lib/algebra/fp24.h +342 -0
- data/vendor/longfellow-zk/lib/algebra/fp24_6.h +305 -0
- data/vendor/longfellow-zk/lib/algebra/fp24_6_test.cc +197 -0
- data/vendor/longfellow-zk/lib/algebra/fp2_test.cc +280 -0
- data/vendor/longfellow-zk/lib/algebra/fp_generic.h +533 -0
- data/vendor/longfellow-zk/lib/algebra/fp_p128.h +91 -0
- data/vendor/longfellow-zk/lib/algebra/fp_p256.h +68 -0
- data/vendor/longfellow-zk/lib/algebra/fp_p256k1.h +123 -0
- data/vendor/longfellow-zk/lib/algebra/fp_p384.h +65 -0
- data/vendor/longfellow-zk/lib/algebra/fp_p521.h +62 -0
- data/vendor/longfellow-zk/lib/algebra/fp_test.cc +522 -0
- data/vendor/longfellow-zk/lib/algebra/hash.h +39 -0
- data/vendor/longfellow-zk/lib/algebra/interpolation.h +117 -0
- data/vendor/longfellow-zk/lib/algebra/interpolation_test.cc +74 -0
- data/vendor/longfellow-zk/lib/algebra/limb.h +153 -0
- data/vendor/longfellow-zk/lib/algebra/limb_test.cc +75 -0
- data/vendor/longfellow-zk/lib/algebra/nat.cc +32 -0
- data/vendor/longfellow-zk/lib/algebra/nat.h +212 -0
- data/vendor/longfellow-zk/lib/algebra/nat_test.cc +183 -0
- data/vendor/longfellow-zk/lib/algebra/nussbaumer.h +400 -0
- data/vendor/longfellow-zk/lib/algebra/nussbaumer_test.cc +138 -0
- data/vendor/longfellow-zk/lib/algebra/nussbaumerfp2_test.cc +139 -0
- data/vendor/longfellow-zk/lib/algebra/permutations.h +79 -0
- data/vendor/longfellow-zk/lib/algebra/poly.h +240 -0
- data/vendor/longfellow-zk/lib/algebra/poly_test.cc +123 -0
- data/vendor/longfellow-zk/lib/algebra/reed_solomon.h +150 -0
- data/vendor/longfellow-zk/lib/algebra/reed_solomon_extension.h +108 -0
- data/vendor/longfellow-zk/lib/algebra/reed_solomon_extension_test.cc +76 -0
- data/vendor/longfellow-zk/lib/algebra/reed_solomon_test.cc +473 -0
- data/vendor/longfellow-zk/lib/algebra/rfft.h +400 -0
- data/vendor/longfellow-zk/lib/algebra/rfft_test.cc +102 -0
- data/vendor/longfellow-zk/lib/algebra/static_string.h +29 -0
- data/vendor/longfellow-zk/lib/algebra/sysdep.h +495 -0
- data/vendor/longfellow-zk/lib/algebra/sysdep_test.cc +41 -0
- data/vendor/longfellow-zk/lib/algebra/twiddle.h +59 -0
- data/vendor/longfellow-zk/lib/algebra/utility.h +86 -0
- data/vendor/longfellow-zk/lib/algebra/utility_test.cc +86 -0
- data/vendor/longfellow-zk/lib/arrays/affine.h +56 -0
- data/vendor/longfellow-zk/lib/arrays/affine_test.cc +220 -0
- data/vendor/longfellow-zk/lib/arrays/dense.h +210 -0
- data/vendor/longfellow-zk/lib/arrays/eq.h +75 -0
- data/vendor/longfellow-zk/lib/arrays/eqs.h +137 -0
- data/vendor/longfellow-zk/lib/arrays/eqs_test.cc +151 -0
- data/vendor/longfellow-zk/lib/arrays/sparse.h +192 -0
- data/vendor/longfellow-zk/lib/cbor/host_decoder.h +323 -0
- data/vendor/longfellow-zk/lib/cbor/host_decoder_test.cc +541 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor.h +594 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_byte_decoder.h +150 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_byte_decoder_test.cc +147 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_constants.h +27 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_pluck.h +110 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_pluck_test.cc +55 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_test.cc +174 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_testing.h +98 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_witness.h +312 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/mso2_test.cc +662 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/mso_test.cc +485 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/scan.h +104 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/scan_test.cc +137 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/cbor.h +640 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/cbor_byte_decoder.h +150 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/cbor_byte_decoder_test.cc +147 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/cbor_constants.h +27 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/cbor_testing.h +99 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/cbor_witness.h +319 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/lexer_test.cc +120 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/mdoc_examples_test.cc +89 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/parser_circuit_test.cc +506 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/parser_size_test.cc +79 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/parser_test.cc +473 -0
- data/vendor/longfellow-zk/lib/circuits/compiler/canonicalization_test.cc +185 -0
- data/vendor/longfellow-zk/lib/circuits/compiler/circuit_dump.h +65 -0
- data/vendor/longfellow-zk/lib/circuits/compiler/compiler.h +471 -0
- data/vendor/longfellow-zk/lib/circuits/compiler/compiler_test.cc +110 -0
- data/vendor/longfellow-zk/lib/circuits/compiler/node.h +176 -0
- data/vendor/longfellow-zk/lib/circuits/compiler/pdqhash.h +127 -0
- data/vendor/longfellow-zk/lib/circuits/compiler/schedule.h +435 -0
- data/vendor/longfellow-zk/lib/circuits/ecdsa/verify_circuit.h +371 -0
- data/vendor/longfellow-zk/lib/circuits/ecdsa/verify_external_test.cc +246 -0
- data/vendor/longfellow-zk/lib/circuits/ecdsa/verify_test.cc +587 -0
- data/vendor/longfellow-zk/lib/circuits/ecdsa/verify_witness.h +201 -0
- data/vendor/longfellow-zk/lib/circuits/logic/bit_adder.h +140 -0
- data/vendor/longfellow-zk/lib/circuits/logic/bit_adder_test.cc +64 -0
- data/vendor/longfellow-zk/lib/circuits/logic/bit_plucker.h +247 -0
- data/vendor/longfellow-zk/lib/circuits/logic/bit_plucker_constants.h +35 -0
- data/vendor/longfellow-zk/lib/circuits/logic/bit_plucker_encoder.h +72 -0
- data/vendor/longfellow-zk/lib/circuits/logic/bit_plucker_test.cc +183 -0
- data/vendor/longfellow-zk/lib/circuits/logic/compiler_backend.h +62 -0
- data/vendor/longfellow-zk/lib/circuits/logic/counter.h +171 -0
- data/vendor/longfellow-zk/lib/circuits/logic/counter_test.cc +102 -0
- data/vendor/longfellow-zk/lib/circuits/logic/evaluation_backend.h +94 -0
- data/vendor/longfellow-zk/lib/circuits/logic/logic.h +1232 -0
- data/vendor/longfellow-zk/lib/circuits/logic/logic_circuit_test.cc +310 -0
- data/vendor/longfellow-zk/lib/circuits/logic/logic_test.cc +521 -0
- data/vendor/longfellow-zk/lib/circuits/logic/memcmp.h +68 -0
- data/vendor/longfellow-zk/lib/circuits/logic/memcmp_test.cc +148 -0
- data/vendor/longfellow-zk/lib/circuits/logic/polynomial.h +94 -0
- data/vendor/longfellow-zk/lib/circuits/logic/polynomial_test.cc +62 -0
- data/vendor/longfellow-zk/lib/circuits/logic/routing.h +445 -0
- data/vendor/longfellow-zk/lib/circuits/logic/routing_test.cc +241 -0
- data/vendor/longfellow-zk/lib/circuits/logic/unary.h +55 -0
- data/vendor/longfellow-zk/lib/circuits/logic/unary_plucker.h +77 -0
- data/vendor/longfellow-zk/lib/circuits/logic/unary_plucker_constants.h +37 -0
- data/vendor/longfellow-zk/lib/circuits/logic/unary_plucker_test.cc +53 -0
- data/vendor/longfellow-zk/lib/circuits/logic/unary_size_test.cc +69 -0
- data/vendor/longfellow-zk/lib/circuits/logic/unary_test.cc +62 -0
- data/vendor/longfellow-zk/lib/circuits/mac/mac_circuit.h +193 -0
- data/vendor/longfellow-zk/lib/circuits/mac/mac_circuit_test.cc +223 -0
- data/vendor/longfellow-zk/lib/circuits/mac/mac_reference.h +72 -0
- data/vendor/longfellow-zk/lib/circuits/mac/mac_witness.h +94 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/circuit_maker.cc +242 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_attribute_ids.h +311 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_attribute_test.cc +64 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_circuit_id.cc +85 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_constants.h +85 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_decompress.cc +41 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_decompress.h +27 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_examples.h +5232 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_generate_circuit.cc +199 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_hash.h +554 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_signature.h +143 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_signature_test.cc +444 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_test_attributes.h +157 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_witness.h +863 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_zk.cc +693 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_zk.h +216 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_zk_test.cc +724 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/zk_spec.cc +100 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/zk_spec_test.cc +155 -0
- data/vendor/longfellow-zk/lib/circuits/sha/flatsha256_circuit.h +330 -0
- data/vendor/longfellow-zk/lib/circuits/sha/flatsha256_circuit_test.cc +607 -0
- data/vendor/longfellow-zk/lib/circuits/sha/flatsha256_io.h +26 -0
- data/vendor/longfellow-zk/lib/circuits/sha/flatsha256_witness.cc +163 -0
- data/vendor/longfellow-zk/lib/circuits/sha/flatsha256_witness.h +47 -0
- data/vendor/longfellow-zk/lib/circuits/sha/sha256_constants.cc +34 -0
- data/vendor/longfellow-zk/lib/circuits/sha/sha256_constants.h +27 -0
- data/vendor/longfellow-zk/lib/circuits/sha/sha256_test_values.h +389 -0
- data/vendor/longfellow-zk/lib/circuits/tests/anoncred/ptrcred.h +171 -0
- data/vendor/longfellow-zk/lib/circuits/tests/anoncred/small.h +218 -0
- data/vendor/longfellow-zk/lib/circuits/tests/anoncred/small_examples.h +118 -0
- data/vendor/longfellow-zk/lib/circuits/tests/anoncred/small_io.h +25 -0
- data/vendor/longfellow-zk/lib/circuits/tests/anoncred/small_test.cc +208 -0
- data/vendor/longfellow-zk/lib/circuits/tests/anoncred/small_witness.h +130 -0
- data/vendor/longfellow-zk/lib/circuits/tests/base64/decode.h +508 -0
- data/vendor/longfellow-zk/lib/circuits/tests/base64/decode_circuit_test.cc +95 -0
- data/vendor/longfellow-zk/lib/circuits/tests/base64/decode_test.cc +119 -0
- data/vendor/longfellow-zk/lib/circuits/tests/base64/decode_util.cc +47 -0
- data/vendor/longfellow-zk/lib/circuits/tests/base64/decode_util.h +29 -0
- data/vendor/longfellow-zk/lib/circuits/tests/ec/pk_circuit.h +231 -0
- data/vendor/longfellow-zk/lib/circuits/tests/ec/pk_circuit_test.cc +428 -0
- data/vendor/longfellow-zk/lib/circuits/tests/ec/pk_witness.h +102 -0
- data/vendor/longfellow-zk/lib/circuits/tests/jwt/jwt.h +190 -0
- data/vendor/longfellow-zk/lib/circuits/tests/jwt/jwt_constants.h +26 -0
- data/vendor/longfellow-zk/lib/circuits/tests/jwt/jwt_test.cc +559 -0
- data/vendor/longfellow-zk/lib/circuits/tests/jwt/jwt_witness.h +315 -0
- data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_1f.h +411 -0
- data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_1f_io.h +32 -0
- data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_1f_test.cc +364 -0
- data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_1f_witness.h +278 -0
- data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_revocation.h +146 -0
- data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_revocation_constants.h +25 -0
- data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_revocation_test.cc +315 -0
- data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_revocation_witness.h +136 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/bitaddr/bitaddr.h +250 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/bitaddr/bitaddr_test.cc +333 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/bitaddr/bitaddr_witness.h +152 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44.h +903 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_circuit_test.cc +274 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_eval_test.cc +440 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_examples.cc +8851 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_examples.h +93 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_types.cc +24 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_types.h +118 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_witness.h +453 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_witness_test.cc +49 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_ref.cc +458 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_ref.h +150 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_ref_test.cc +398 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_ref_test_vectors.inc +3618 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_ref_test_vectors_pkdecode.inc +689 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_ref_test_vectors_sigdecode.inc +1501 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/sigdecode_test_vectors.inc +540 -0
- data/vendor/longfellow-zk/lib/circuits/tests/ripemd/ripemd_circuit.h +394 -0
- data/vendor/longfellow-zk/lib/circuits/tests/ripemd/ripemd_circuit_test.cc +577 -0
- data/vendor/longfellow-zk/lib/circuits/tests/ripemd/ripemd_constants.h +90 -0
- data/vendor/longfellow-zk/lib/circuits/tests/ripemd/ripemd_witness.cc +174 -0
- data/vendor/longfellow-zk/lib/circuits/tests/ripemd/ripemd_witness.h +140 -0
- data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_circuit.h +351 -0
- data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_circuit_test.cc +466 -0
- data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_reference.cc +207 -0
- data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_reference.h +59 -0
- data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_reference_test.cc +153 -0
- data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_round_constants.cc +39 -0
- data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_round_constants.h +29 -0
- data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_slicing.h +31 -0
- data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_witness.cc +83 -0
- data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_witness.h +72 -0
- data/vendor/longfellow-zk/lib/circuits/tests/sha3/shake_test_vectors.h +477 -0
- data/vendor/longfellow-zk/lib/ec/elliptic_curve.h +596 -0
- data/vendor/longfellow-zk/lib/ec/elliptic_curve_test.cc +548 -0
- data/vendor/longfellow-zk/lib/ec/p256.cc +36 -0
- data/vendor/longfellow-zk/lib/ec/p256.h +60 -0
- data/vendor/longfellow-zk/lib/ec/p256k1.cc +34 -0
- data/vendor/longfellow-zk/lib/ec/p256k1.h +60 -0
- data/vendor/longfellow-zk/lib/gf2k/gf2_128.h +503 -0
- data/vendor/longfellow-zk/lib/gf2k/gf2_128_bench.cc +48 -0
- data/vendor/longfellow-zk/lib/gf2k/gf2_128_test.cc +416 -0
- data/vendor/longfellow-zk/lib/gf2k/gf2poly.h +74 -0
- data/vendor/longfellow-zk/lib/gf2k/lch14.h +242 -0
- data/vendor/longfellow-zk/lib/gf2k/lch14_bench.cc +75 -0
- data/vendor/longfellow-zk/lib/gf2k/lch14_reed_solomon.h +127 -0
- data/vendor/longfellow-zk/lib/gf2k/lch14_reed_solomon_test.cc +110 -0
- data/vendor/longfellow-zk/lib/gf2k/lch14_test.cc +246 -0
- data/vendor/longfellow-zk/lib/gf2k/sysdep.h +329 -0
- data/vendor/longfellow-zk/lib/ligero/ligero_param.h +449 -0
- data/vendor/longfellow-zk/lib/ligero/ligero_prover.h +354 -0
- data/vendor/longfellow-zk/lib/ligero/ligero_test.cc +136 -0
- data/vendor/longfellow-zk/lib/ligero/ligero_transcript.h +67 -0
- data/vendor/longfellow-zk/lib/ligero/ligero_verifier.h +272 -0
- data/vendor/longfellow-zk/lib/merkle/merkle_commitment.h +104 -0
- data/vendor/longfellow-zk/lib/merkle/merkle_tree.h +216 -0
- data/vendor/longfellow-zk/lib/merkle/merkle_tree_test.cc +240 -0
- data/vendor/longfellow-zk/lib/proto/circuit.h +354 -0
- data/vendor/longfellow-zk/lib/proto/circuit_test.cc +202 -0
- data/vendor/longfellow-zk/lib/random/random.h +119 -0
- data/vendor/longfellow-zk/lib/random/random_test.cc +189 -0
- data/vendor/longfellow-zk/lib/random/secure_random_engine.h +37 -0
- data/vendor/longfellow-zk/lib/random/transcript.h +193 -0
- data/vendor/longfellow-zk/lib/random/transcript_test.cc +344 -0
- data/vendor/longfellow-zk/lib/sumcheck/circuit.h +148 -0
- data/vendor/longfellow-zk/lib/sumcheck/circuit_id.h +71 -0
- data/vendor/longfellow-zk/lib/sumcheck/equad.h +126 -0
- data/vendor/longfellow-zk/lib/sumcheck/hquad.h +115 -0
- data/vendor/longfellow-zk/lib/sumcheck/prover.h +59 -0
- data/vendor/longfellow-zk/lib/sumcheck/prover_layers.h +362 -0
- data/vendor/longfellow-zk/lib/sumcheck/quad.h +227 -0
- data/vendor/longfellow-zk/lib/sumcheck/quad_builder.h +211 -0
- data/vendor/longfellow-zk/lib/sumcheck/quad_test.cc +169 -0
- data/vendor/longfellow-zk/lib/sumcheck/sumcheck_test.cc +324 -0
- data/vendor/longfellow-zk/lib/sumcheck/testing.h +69 -0
- data/vendor/longfellow-zk/lib/sumcheck/transcript_sumcheck.h +85 -0
- data/vendor/longfellow-zk/lib/sumcheck/verifier.h +84 -0
- data/vendor/longfellow-zk/lib/sumcheck/verifier_layers.h +221 -0
- data/vendor/longfellow-zk/lib/testing/test_main.cc +50 -0
- data/vendor/longfellow-zk/lib/util/ceildiv.h +164 -0
- data/vendor/longfellow-zk/lib/util/ceildiv_test.cc +152 -0
- data/vendor/longfellow-zk/lib/util/crc64.h +45 -0
- data/vendor/longfellow-zk/lib/util/crypto.cc +39 -0
- data/vendor/longfellow-zk/lib/util/crypto.h +108 -0
- data/vendor/longfellow-zk/lib/util/log.cc +110 -0
- data/vendor/longfellow-zk/lib/util/log.h +33 -0
- data/vendor/longfellow-zk/lib/util/panic.h +40 -0
- data/vendor/longfellow-zk/lib/util/readbuffer.h +67 -0
- data/vendor/longfellow-zk/lib/util/serialization.h +54 -0
- data/vendor/longfellow-zk/lib/zk/zk_common.h +455 -0
- data/vendor/longfellow-zk/lib/zk/zk_proof.h +378 -0
- data/vendor/longfellow-zk/lib/zk/zk_prover.h +202 -0
- data/vendor/longfellow-zk/lib/zk/zk_test.cc +340 -0
- data/vendor/longfellow-zk/lib/zk/zk_testing.h +154 -0
- data/vendor/longfellow-zk/lib/zk/zk_verifier.h +109 -0
- metadata +347 -0
|
@@ -0,0 +1,223 @@
|
|
|
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/mac/mac_circuit.h"
|
|
16
|
+
|
|
17
|
+
#include <stddef.h>
|
|
18
|
+
#include <string.h>
|
|
19
|
+
|
|
20
|
+
#include <cstdint>
|
|
21
|
+
#include <memory>
|
|
22
|
+
#include <utility>
|
|
23
|
+
|
|
24
|
+
#include "arrays/dense.h"
|
|
25
|
+
#include "circuits/compiler/circuit_dump.h"
|
|
26
|
+
#include "circuits/compiler/compiler.h"
|
|
27
|
+
#include "circuits/logic/bit_plucker.h"
|
|
28
|
+
#include "circuits/logic/compiler_backend.h"
|
|
29
|
+
#include "circuits/logic/logic.h"
|
|
30
|
+
#include "circuits/mac/mac_reference.h"
|
|
31
|
+
#include "circuits/mac/mac_witness.h"
|
|
32
|
+
#include "ec/p256.h"
|
|
33
|
+
#include "gf2k/gf2_128.h"
|
|
34
|
+
#include "random/secure_random_engine.h"
|
|
35
|
+
#include "sumcheck/circuit.h"
|
|
36
|
+
#include "sumcheck/testing.h"
|
|
37
|
+
#include "util/log.h"
|
|
38
|
+
#include "gtest/gtest.h"
|
|
39
|
+
|
|
40
|
+
namespace proofs {
|
|
41
|
+
namespace {
|
|
42
|
+
|
|
43
|
+
// This test subsumes the evaluation test.
|
|
44
|
+
TEST(MAC, full_circuit_test_128) {
|
|
45
|
+
set_log_level(INFO);
|
|
46
|
+
constexpr size_t kNum = 3;
|
|
47
|
+
|
|
48
|
+
size_t ninput;
|
|
49
|
+
std::unique_ptr<Circuit<Fp256Base>> circuit;
|
|
50
|
+
|
|
51
|
+
/*scope to delimit compile-time*/ {
|
|
52
|
+
using CompilerBackend = CompilerBackend<Fp256Base>;
|
|
53
|
+
using LogicCircuit = Logic<Fp256Base, CompilerBackend>;
|
|
54
|
+
using v128 = LogicCircuit::v128;
|
|
55
|
+
QuadCircuit<Fp256Base> Q(p256_base);
|
|
56
|
+
const CompilerBackend cbk(&Q);
|
|
57
|
+
const LogicCircuit LC(&cbk, p256_base);
|
|
58
|
+
using MACCircuit =
|
|
59
|
+
MAC<LogicCircuit, BitPlucker<LogicCircuit, kMACPluckerBits>>;
|
|
60
|
+
MACCircuit mac(LC);
|
|
61
|
+
|
|
62
|
+
MACCircuit::Witness vwc[kNum];
|
|
63
|
+
LogicCircuit::EltW msg[kNum];
|
|
64
|
+
v128 mv[kNum][2];
|
|
65
|
+
v128 a_v[kNum];
|
|
66
|
+
for (size_t i = 0; i < kNum; ++i) {
|
|
67
|
+
msg[i] = LC.eltw_input();
|
|
68
|
+
mv[i][0] = LC.vinput<128>();
|
|
69
|
+
mv[i][1] = LC.vinput<128>();
|
|
70
|
+
a_v[i] = LC.vinput<128>();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
Q.private_input();
|
|
74
|
+
for (size_t i = 0; i < kNum; ++i) {
|
|
75
|
+
vwc[i].input(LC);
|
|
76
|
+
}
|
|
77
|
+
for (size_t i = 0; i < kNum; ++i) {
|
|
78
|
+
mac.verify_mac(msg[i], mv[i], a_v[i], vwc[i], n256_order);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
circuit = Q.mkcircuit(1);
|
|
82
|
+
dump_info("mac verify p256", Q);
|
|
83
|
+
ninput = Q.ninput();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
log(INFO, "Compile done");
|
|
87
|
+
/*------------------------------------------------------------*/
|
|
88
|
+
// Witness-creation time + fill inputs
|
|
89
|
+
using gf2k = GF2_128<>::Elt;
|
|
90
|
+
GF2_128<> gf;
|
|
91
|
+
MACReference<GF2_128<>> mac_ref;
|
|
92
|
+
SecureRandomEngine rng;
|
|
93
|
+
|
|
94
|
+
uint8_t test_msg[32];
|
|
95
|
+
|
|
96
|
+
for (size_t t = 0; t < 10; ++t) {
|
|
97
|
+
rng.bytes(test_msg, 32);
|
|
98
|
+
|
|
99
|
+
auto W = std::make_unique<Dense<Fp256Base>>(1, ninput);
|
|
100
|
+
DenseFiller<Fp256Base> filler(*W);
|
|
101
|
+
filler.push_back(p256_base.one());
|
|
102
|
+
|
|
103
|
+
Fp256Base::Elt msg_elt = p256_base.of_bytes_field(test_msg).value();
|
|
104
|
+
|
|
105
|
+
gf2k av, ap[2], mac[2];
|
|
106
|
+
mac_ref.sample(&av, 1, &rng);
|
|
107
|
+
mac_ref.sample(ap, 2, &rng);
|
|
108
|
+
mac_ref.compute(mac, av, ap, test_msg);
|
|
109
|
+
|
|
110
|
+
MacWitness<Fp256Base> vw(p256_base, gf);
|
|
111
|
+
vw.compute_witness(ap, test_msg);
|
|
112
|
+
|
|
113
|
+
for (size_t i = 0; i < kNum; ++i) {
|
|
114
|
+
filler.push_back(msg_elt);
|
|
115
|
+
|
|
116
|
+
// Fill inputs
|
|
117
|
+
for (size_t j = 0; j < 2; ++j) {
|
|
118
|
+
fill_gf2k<GF2_128<>, Fp256Base>(mac[j], filler, p256_base);
|
|
119
|
+
}
|
|
120
|
+
fill_gf2k<GF2_128<>, Fp256Base>(av, filler, p256_base);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
for (size_t i = 0; i < kNum; ++i) {
|
|
124
|
+
vw.fill_witness(filler);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
log(INFO, "Fill done");
|
|
128
|
+
/*------------------------------------------------------------*/
|
|
129
|
+
// Prove
|
|
130
|
+
Proof<Fp256Base> proof(circuit->nl);
|
|
131
|
+
run_prover<Fp256Base>(circuit.get(), W->clone(), &proof, p256_base);
|
|
132
|
+
|
|
133
|
+
log(INFO, "Prover done");
|
|
134
|
+
/*------------------------------------------------------------*/
|
|
135
|
+
// Verify
|
|
136
|
+
run_verifier<Fp256Base>(circuit.get(), std::move(W), proof, p256_base);
|
|
137
|
+
log(INFO, "Verify done");
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
TEST(MAC, full_circuit_GF2_128) {
|
|
142
|
+
set_log_level(INFO);
|
|
143
|
+
using f_128 = GF2_128<>;
|
|
144
|
+
size_t ninput;
|
|
145
|
+
std::unique_ptr<Circuit<f_128>> circuit;
|
|
146
|
+
f_128 F;
|
|
147
|
+
|
|
148
|
+
/*scope to delimit compile-time*/ {
|
|
149
|
+
using CompilerBackend = CompilerBackend<f_128>;
|
|
150
|
+
using LogicCircuit = Logic<f_128, CompilerBackend>;
|
|
151
|
+
using EltW = LogicCircuit::EltW;
|
|
152
|
+
using v256 = LogicCircuit::v256;
|
|
153
|
+
QuadCircuit<f_128> Q(F);
|
|
154
|
+
const CompilerBackend cbk(&Q);
|
|
155
|
+
const LogicCircuit LC(&cbk, F);
|
|
156
|
+
using MACCircuit =
|
|
157
|
+
MACGF2<CompilerBackend, BitPlucker<LogicCircuit, kMACPluckerBits>>;
|
|
158
|
+
MACCircuit mac(LC);
|
|
159
|
+
MACCircuit::Witness vwc;
|
|
160
|
+
|
|
161
|
+
v256 msg = LC.vinput<256>();
|
|
162
|
+
EltW mv[2] = {LC.eltw_input(), LC.eltw_input()};
|
|
163
|
+
EltW a_v = LC.eltw_input();
|
|
164
|
+
Q.private_input();
|
|
165
|
+
vwc.input(LC);
|
|
166
|
+
mac.verify_mac(mv, a_v, msg, vwc);
|
|
167
|
+
|
|
168
|
+
circuit = Q.mkcircuit(1);
|
|
169
|
+
dump_info("mac_gf2_128 verify", Q);
|
|
170
|
+
ninput = Q.ninput();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
log(INFO, "Compile done");
|
|
174
|
+
/*------------------------------------------------------------*/
|
|
175
|
+
// Witness-creation time + fill inputs
|
|
176
|
+
using gf2k = f_128::Elt;
|
|
177
|
+
MACReference<f_128> mac_ref;
|
|
178
|
+
SecureRandomEngine rng;
|
|
179
|
+
|
|
180
|
+
uint8_t test_msg[32];
|
|
181
|
+
|
|
182
|
+
for (size_t t = 0; t < 10; ++t) {
|
|
183
|
+
rng.bytes(test_msg, 32);
|
|
184
|
+
|
|
185
|
+
auto W = std::make_unique<Dense<f_128>>(1, ninput);
|
|
186
|
+
DenseFiller<f_128> filler(*W);
|
|
187
|
+
filler.push_back(F.one());
|
|
188
|
+
|
|
189
|
+
for (size_t i = 0; i < 256; ++i) {
|
|
190
|
+
filler.push_back((test_msg[i / 8] >> (i % 8) & 0x1) ? F.one() : F.zero());
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
gf2k av, ap[2], mac[2];
|
|
194
|
+
mac_ref.sample(&av, 1, &rng);
|
|
195
|
+
mac_ref.sample(ap, 2, &rng);
|
|
196
|
+
mac_ref.compute(mac, av, ap, test_msg);
|
|
197
|
+
|
|
198
|
+
MacGF2Witness vw;
|
|
199
|
+
vw.compute_witness(ap);
|
|
200
|
+
|
|
201
|
+
// Fill inputs
|
|
202
|
+
for (size_t i = 0; i < 2; ++i) {
|
|
203
|
+
filler.push_back(mac[i]);
|
|
204
|
+
}
|
|
205
|
+
filler.push_back(av);
|
|
206
|
+
vw.fill_witness(filler);
|
|
207
|
+
|
|
208
|
+
log(INFO, "Fill done");
|
|
209
|
+
/*------------------------------------------------------------*/
|
|
210
|
+
// Prove
|
|
211
|
+
Proof<f_128> proof(circuit->nl);
|
|
212
|
+
run_prover<f_128>(circuit.get(), W->clone(), &proof, F);
|
|
213
|
+
|
|
214
|
+
log(INFO, "Prover done");
|
|
215
|
+
/*------------------------------------------------------------*/
|
|
216
|
+
// Verify
|
|
217
|
+
run_verifier<f_128>(circuit.get(), std::move(W), proof, F);
|
|
218
|
+
log(INFO, "Verify done");
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
} // namespace
|
|
223
|
+
} // namespace proofs
|
|
@@ -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_MAC_MAC_REFERENCE_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MAC_MAC_REFERENCE_H_
|
|
17
|
+
|
|
18
|
+
#include <cstddef>
|
|
19
|
+
#include <cstdint>
|
|
20
|
+
#include <vector>
|
|
21
|
+
|
|
22
|
+
#include "arrays/dense.h"
|
|
23
|
+
#include "random/random.h"
|
|
24
|
+
#include "util/panic.h"
|
|
25
|
+
|
|
26
|
+
namespace proofs {
|
|
27
|
+
|
|
28
|
+
template <class GF>
|
|
29
|
+
class MACReference {
|
|
30
|
+
using gf2k = typename GF::Elt;
|
|
31
|
+
|
|
32
|
+
public:
|
|
33
|
+
void sample(gf2k ap[], size_t n, RandomEngine* rng) {
|
|
34
|
+
check(n > 0, "n must be positive");
|
|
35
|
+
std::vector<uint8_t> buf(n * GF::kBytes);
|
|
36
|
+
rng->bytes(buf.data(), n * GF::kBytes);
|
|
37
|
+
for (size_t i = 0; i < n; ++i) {
|
|
38
|
+
ap[i] = gf_.of_bytes_field(&buf[i * GF::kBytes]).value();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Computes the mac of a 32-byte message.
|
|
43
|
+
void compute(gf2k mac[/*2*/], const gf2k& av, const gf2k ap[/*2*/],
|
|
44
|
+
uint8_t msg[/*32*/]) const {
|
|
45
|
+
uint8_t tmp[GF::kBytes] = {0};
|
|
46
|
+
for (size_t i = 0; i < 2; ++i) {
|
|
47
|
+
memcpy(tmp, &msg[i * GF::kBytes], GF::kBytes);
|
|
48
|
+
gf2k m = gf_.of_bytes_field(tmp).value();
|
|
49
|
+
mac[i] = gf_.mulf(gf_.addf(av, ap[i]), m);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
void to_bytes(gf2k mac[/*2*/], uint8_t buf[/* 32 */]) {
|
|
54
|
+
gf_.to_bytes(mac[0], buf);
|
|
55
|
+
gf_.to_bytes(mac[1], buf + GF::kBytes);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private:
|
|
59
|
+
GF gf_;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
template <typename GF, typename Field>
|
|
63
|
+
void fill_gf2k(const typename GF::Elt& m, DenseFiller<Field>& df,
|
|
64
|
+
const Field& f) {
|
|
65
|
+
for (size_t i = 0; i < GF::kBits; ++i) {
|
|
66
|
+
df.push_back(m[i] ? f.one() : f.zero());
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
} // namespace proofs
|
|
71
|
+
|
|
72
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MAC_MAC_REFERENCE_H_
|
|
@@ -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_MAC_MAC_WITNESS_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MAC_MAC_WITNESS_H_
|
|
17
|
+
|
|
18
|
+
#include <cstddef>
|
|
19
|
+
#include <cstdint>
|
|
20
|
+
|
|
21
|
+
#include "arrays/dense.h"
|
|
22
|
+
#include "circuits/logic/bit_plucker_encoder.h"
|
|
23
|
+
#include "gf2k/gf2_128.h"
|
|
24
|
+
|
|
25
|
+
namespace proofs {
|
|
26
|
+
|
|
27
|
+
template <class Field>
|
|
28
|
+
class MacWitness {
|
|
29
|
+
using f_128 = GF2_128<>;
|
|
30
|
+
using gf2k = f_128::Elt;
|
|
31
|
+
using packer = BitPluckerEncoder<Field, 2>;
|
|
32
|
+
using packed_v128 = typename packer::packed_v128;
|
|
33
|
+
using packed_v256 = typename packer::packed_v256;
|
|
34
|
+
|
|
35
|
+
public:
|
|
36
|
+
explicit MacWitness(const Field& F, const f_128& GF) : f_(F), gf_(GF) {}
|
|
37
|
+
|
|
38
|
+
void fill_witness(DenseFiller<Field>& fill) const {
|
|
39
|
+
packer bp(f_);
|
|
40
|
+
uint8_t tmp[f_128::kBits];
|
|
41
|
+
for (size_t i = 0; i < 2; ++i) {
|
|
42
|
+
for (size_t j = 0; j < f_128::kBits; ++j) {
|
|
43
|
+
tmp[j] = ap_[i][j];
|
|
44
|
+
}
|
|
45
|
+
fill.push_back(bp.template pack<packed_v128>(tmp, f_128::kBits));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
for (size_t i = 0; i < 2; ++i) {
|
|
49
|
+
for (size_t j = 0; j < f_128::kBits; ++j) {
|
|
50
|
+
tmp[j] = x_[i][j];
|
|
51
|
+
}
|
|
52
|
+
fill.push_back(bp.template pack<packed_v128>(tmp, 128));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Computes a mac witness on a 32-byte message x.
|
|
57
|
+
// This code assumes that a gf element is at least 16 bytes.
|
|
58
|
+
void compute_witness(const gf2k a_p[/*2*/], const uint8_t x[/*32*/]) {
|
|
59
|
+
for (size_t i = 0; i < 2; ++i) {
|
|
60
|
+
x_[i] = gf_.of_bytes_field(&x[i * 16]).value();
|
|
61
|
+
ap_[i] = a_p[i];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private:
|
|
66
|
+
gf2k ap_[2], x_[2];
|
|
67
|
+
const Field& f_;
|
|
68
|
+
const f_128& gf_;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
class MacGF2Witness {
|
|
72
|
+
using f_128 = GF2_128<>;
|
|
73
|
+
using gf2k = f_128::Elt;
|
|
74
|
+
|
|
75
|
+
public:
|
|
76
|
+
void fill_witness(DenseFiller<f_128>& fill) const {
|
|
77
|
+
fill.push_back(ap_[0]);
|
|
78
|
+
fill.push_back(ap_[1]);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Computes a mac witness on a 32-byte message x.
|
|
82
|
+
void compute_witness(const gf2k a_p[/*2*/]) {
|
|
83
|
+
for (size_t i = 0; i < 2; ++i) {
|
|
84
|
+
ap_[i] = a_p[i];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private:
|
|
89
|
+
gf2k ap_[2];
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
} // namespace proofs
|
|
93
|
+
|
|
94
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MAC_MAC_WITNESS_H_
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
// Copyright 2025 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
|
+
// This program generates a circuit for mdoc_zk, computes its ID, and writes
|
|
16
|
+
// the circuit to a file named after the circuit ID in a specified output
|
|
17
|
+
// directory.
|
|
18
|
+
|
|
19
|
+
#include <cstddef>
|
|
20
|
+
#include <cstdint>
|
|
21
|
+
#include <cstdlib>
|
|
22
|
+
#include <filesystem>
|
|
23
|
+
#include <fstream>
|
|
24
|
+
#include <iomanip>
|
|
25
|
+
#include <iostream>
|
|
26
|
+
#include <sstream>
|
|
27
|
+
#include <string>
|
|
28
|
+
#include <vector>
|
|
29
|
+
#include <absl/cleanup/cleanup.h>
|
|
30
|
+
#include <absl/flags/flag.h>
|
|
31
|
+
#include <absl/flags/parse.h>
|
|
32
|
+
|
|
33
|
+
#include "circuits/mdoc/mdoc_zk.h"
|
|
34
|
+
#include "util/log.h"
|
|
35
|
+
#include "util/panic.h"
|
|
36
|
+
#include "util/readbuffer.h"
|
|
37
|
+
#include "zk/zk_common.h"
|
|
38
|
+
#include "circuits/mdoc/mdoc_decompress.h"
|
|
39
|
+
#include "ec/p256.h"
|
|
40
|
+
#include "gf2k/gf2_128.h"
|
|
41
|
+
#include "ligero/ligero_param.h"
|
|
42
|
+
#include "proto/circuit.h"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
ABSL_FLAG(std::string, output_dir, "circuits",
|
|
46
|
+
"Output directory for the circuit file");
|
|
47
|
+
ABSL_FLAG(int, num_attributes, 1,
|
|
48
|
+
"Number of attributes for the circuit (selects ZkSpec)");
|
|
49
|
+
|
|
50
|
+
std::string BytesToHexString(const uint8_t* bytes, size_t len) {
|
|
51
|
+
std::stringstream ss;
|
|
52
|
+
ss << std::hex << std::setfill('0');
|
|
53
|
+
for (size_t i = 0; i < len; ++i) {
|
|
54
|
+
ss << std::setw(2) << static_cast<int>(bytes[i]);
|
|
55
|
+
}
|
|
56
|
+
return ss.str();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Recompute the parameters to find the optimal fine grained block_enc.
|
|
60
|
+
template <class LigeroParam>
|
|
61
|
+
size_t optimize(LigeroParam &lp) {
|
|
62
|
+
size_t min_proof_size = lp.layout(lp.block_enc);
|
|
63
|
+
size_t best_block_enc = lp.block_enc;
|
|
64
|
+
for (size_t e = 100; e <= (1 << 17); e++) {
|
|
65
|
+
size_t proof_size = lp.layout(e);
|
|
66
|
+
if (proof_size < min_proof_size) {
|
|
67
|
+
min_proof_size = proof_size;
|
|
68
|
+
best_block_enc = e;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return best_block_enc;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Decompress and parse the circuit bytes, optimize the Ligero
|
|
75
|
+
// commitment parameters and print a ZkSpecStruct entry.
|
|
76
|
+
void optimize_params(const uint8_t* circuit_bytes, size_t circuit_len,
|
|
77
|
+
const std::string& circuit_id_hex,
|
|
78
|
+
const ZkSpecStruct* zk_spec) {
|
|
79
|
+
using f_128 = proofs::GF2_128<>;
|
|
80
|
+
// Parse circuits.
|
|
81
|
+
const f_128 Fs;
|
|
82
|
+
|
|
83
|
+
size_t len = 1 << 27;
|
|
84
|
+
std::vector<uint8_t> bytes(len);
|
|
85
|
+
size_t full_size = proofs::decompress(bytes, circuit_bytes, circuit_len);
|
|
86
|
+
|
|
87
|
+
// Ensure that the circuit was decompressed correctly.
|
|
88
|
+
proofs::check(full_size > 0, "Circuit decompression failed");
|
|
89
|
+
proofs::ReadBuffer rb_circuit(bytes.data(), full_size);
|
|
90
|
+
|
|
91
|
+
proofs::CircuitRep<proofs::Fp256Base> cr_s(proofs::p256_base,
|
|
92
|
+
proofs::P256_ID);
|
|
93
|
+
auto c_sig = cr_s.from_bytes(rb_circuit, false);
|
|
94
|
+
proofs::check(c_sig != nullptr, "Signature circuit could not be parsed");
|
|
95
|
+
|
|
96
|
+
proofs::CircuitRep<f_128> cr_h(Fs, proofs::GF2_128_ID);
|
|
97
|
+
auto c_hash = cr_h.from_bytes(rb_circuit, false);
|
|
98
|
+
proofs::check(c_hash != nullptr, "Hash circuit could not be parsed");
|
|
99
|
+
|
|
100
|
+
proofs::LigeroParam<f_128> hp(
|
|
101
|
+
(c_hash->ninputs - c_hash->npub_in) +
|
|
102
|
+
proofs::ZkCommon<f_128>::pad_size(*c_hash),
|
|
103
|
+
c_hash->nl, kLigeroRate, kLigeroNreq);
|
|
104
|
+
|
|
105
|
+
size_t min_proof_size = hp.layout(hp.block_enc);
|
|
106
|
+
std::cout << " hash legacy parameters: be:" << hp.block_enc
|
|
107
|
+
<< " sz:" << min_proof_size << " r:" << hp.r << " w:" << hp.w
|
|
108
|
+
<< " b:" << hp.block << " nr:" << hp.nrow << " nq:" << hp.nqtriples
|
|
109
|
+
<< std::endl;
|
|
110
|
+
size_t best_block_enc = optimize(hp);
|
|
111
|
+
min_proof_size = hp.layout(best_block_enc);
|
|
112
|
+
std::cout << " hash best parameters: be:" << best_block_enc
|
|
113
|
+
<< " sz:" << min_proof_size << std::endl;
|
|
114
|
+
|
|
115
|
+
proofs::LigeroParam<proofs::Fp256Base> sp(
|
|
116
|
+
(c_sig->ninputs - c_sig->npub_in) +
|
|
117
|
+
proofs::ZkCommon<proofs::Fp256Base>::pad_size(*c_sig),
|
|
118
|
+
c_sig->nl, kLigeroRate, kLigeroNreq);
|
|
119
|
+
|
|
120
|
+
min_proof_size = sp.layout(sp.block_enc);
|
|
121
|
+
|
|
122
|
+
std::cout << " sig legacy parameters: be:" << sp.block_enc
|
|
123
|
+
<< " sz:" << min_proof_size << " r:" << sp.r << " w:" << sp.w
|
|
124
|
+
<< " b:" << sp.block << " nr:" << sp.nrow << " nq:" << sp.nqtriples
|
|
125
|
+
<< std::endl;
|
|
126
|
+
|
|
127
|
+
size_t sig_best_block_enc = optimize(sp);
|
|
128
|
+
min_proof_size = sp.layout(sig_best_block_enc);
|
|
129
|
+
|
|
130
|
+
std::cout << " sig best parameters: be:" << sig_best_block_enc
|
|
131
|
+
<< " sz:" << min_proof_size << std::endl;
|
|
132
|
+
|
|
133
|
+
std::cout << "{\"" << zk_spec->system << "\", \"" << circuit_id_hex << "\", "
|
|
134
|
+
<< zk_spec->num_attributes << ", " << zk_spec->version << ", "
|
|
135
|
+
<< best_block_enc << ", " << sig_best_block_enc << "},"
|
|
136
|
+
<< std::endl;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Helper to find a ZkSpecStruct matching the desired number of attributes.
|
|
140
|
+
// If no exact match, returns nullptr. In a real scenario, you might pick the
|
|
141
|
+
// latest or closest one, or error out.
|
|
142
|
+
const ZkSpecStruct* FindZkSpecByNumAttributes(int n_attrs) {
|
|
143
|
+
for (size_t i = 0; i < kNumZkSpecs; ++i) {
|
|
144
|
+
if (static_cast<int>(kZkSpecs[i].num_attributes) == n_attrs) {
|
|
145
|
+
return &kZkSpecs[i];
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return nullptr; // Or handle as an error, or pick a default.
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
int main(int argc, char* argv[]) {
|
|
152
|
+
absl::ParseCommandLine(argc, argv);
|
|
153
|
+
proofs::set_log_level(proofs::ERROR);
|
|
154
|
+
|
|
155
|
+
std::string output_dir_path = absl::GetFlag(FLAGS_output_dir);
|
|
156
|
+
int n_attributes_requested = absl::GetFlag(FLAGS_num_attributes);
|
|
157
|
+
std::cout << "Output directory: " << output_dir_path << std::endl;
|
|
158
|
+
std::cout << "Requested number of attributes: " << n_attributes_requested
|
|
159
|
+
<< std::endl;
|
|
160
|
+
|
|
161
|
+
// Find a ZkSpecStruct based on the number of attributes requested
|
|
162
|
+
const ZkSpecStruct* selected_zk_spec =
|
|
163
|
+
FindZkSpecByNumAttributes(n_attributes_requested);
|
|
164
|
+
if (selected_zk_spec == nullptr) {
|
|
165
|
+
std::cerr << "Error: No ZkSpec available in kZkSpecs array." << std::endl;
|
|
166
|
+
return 1;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
std::cout << "Using ZkSpec: " << selected_zk_spec->system
|
|
170
|
+
<< ", version: " << selected_zk_spec->version
|
|
171
|
+
<< ", attributes: " << selected_zk_spec->num_attributes
|
|
172
|
+
<< std::endl;
|
|
173
|
+
|
|
174
|
+
std::ifstream dir(output_dir_path, std::ios::binary);
|
|
175
|
+
if (!dir.is_open()) {
|
|
176
|
+
std::cerr << "Error: Could not open dir " << output_dir_path << std::endl;
|
|
177
|
+
return 1;
|
|
178
|
+
}
|
|
179
|
+
dir.close();
|
|
180
|
+
|
|
181
|
+
uint8_t* circuit_bytes = nullptr;
|
|
182
|
+
size_t circuit_len = 0;
|
|
183
|
+
// Use absl mechanism to ensure that the memory is freed.
|
|
184
|
+
absl::Cleanup free_circuit_bytes = [&circuit_bytes] {
|
|
185
|
+
if (circuit_bytes) {
|
|
186
|
+
free(circuit_bytes); // mdoc_zk.h uses C-style allocation
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
std::cout << "Generating circuit..." << std::endl;
|
|
191
|
+
CircuitGenerationErrorCode circuit_gen_status =
|
|
192
|
+
generate_circuit(selected_zk_spec, &circuit_bytes, &circuit_len);
|
|
193
|
+
if (circuit_gen_status != CIRCUIT_GENERATION_SUCCESS) {
|
|
194
|
+
std::cerr << "Error generating circuit. Code: " << circuit_gen_status
|
|
195
|
+
<< std::endl;
|
|
196
|
+
return 1;
|
|
197
|
+
}
|
|
198
|
+
if (circuit_bytes == nullptr || circuit_len == 0) {
|
|
199
|
+
std::cerr << "Error: generate_circuit succeeded but output is empty."
|
|
200
|
+
<< std::endl;
|
|
201
|
+
return 1;
|
|
202
|
+
}
|
|
203
|
+
std::cout << "Circuit generated successfully. Size: " << circuit_len
|
|
204
|
+
<< " bytes." << std::endl;
|
|
205
|
+
|
|
206
|
+
// Compute circuit ID.
|
|
207
|
+
constexpr size_t kSHA256DigestSize = 32;
|
|
208
|
+
uint8_t c_id[kSHA256DigestSize];
|
|
209
|
+
std::cout << "Computing circuit ID." << std::endl;
|
|
210
|
+
if (!circuit_id(c_id, circuit_bytes, circuit_len, selected_zk_spec)) {
|
|
211
|
+
std::cerr << "Error computing circuit ID." << std::endl;
|
|
212
|
+
return 1;
|
|
213
|
+
}
|
|
214
|
+
std::string circuit_id_hex = BytesToHexString(c_id, kSHA256DigestSize);
|
|
215
|
+
std::cout << "Circuit ID (hex): " << circuit_id_hex << std::endl;
|
|
216
|
+
|
|
217
|
+
// Write circuit bytes to file.
|
|
218
|
+
namespace fs = std::filesystem;
|
|
219
|
+
std::string output_file_path = (fs::path(output_dir_path) / fs::path(circuit_id_hex)).string();
|
|
220
|
+
std::cout << "Writing circuit to: " << output_file_path << std::endl;
|
|
221
|
+
std::ofstream out_file(output_file_path, std::ios::binary | std::ios::trunc);
|
|
222
|
+
if (!out_file.is_open()) {
|
|
223
|
+
std::cerr << "Error: Could not open file for writing: " << output_file_path
|
|
224
|
+
<< std::endl;
|
|
225
|
+
return 1;
|
|
226
|
+
}
|
|
227
|
+
out_file.write(reinterpret_cast<const char*>(circuit_bytes), circuit_len);
|
|
228
|
+
if (!out_file) { // Check for write errors
|
|
229
|
+
std::cerr << "Error writing circuit to file: " << output_file_path
|
|
230
|
+
<< std::endl;
|
|
231
|
+
out_file.close();
|
|
232
|
+
return 1;
|
|
233
|
+
}
|
|
234
|
+
out_file.close();
|
|
235
|
+
std::cout << "Circuit successfully written to " << output_file_path
|
|
236
|
+
<< std::endl;
|
|
237
|
+
|
|
238
|
+
// Search for optimal Ligero parameters.
|
|
239
|
+
std::cout << "Optimizing Ligero parameters..." << std::endl;
|
|
240
|
+
optimize_params(circuit_bytes, circuit_len, circuit_id_hex, selected_zk_spec);
|
|
241
|
+
return 0;
|
|
242
|
+
}
|