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,354 @@
|
|
|
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_LIGERO_LIGERO_PROVER_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_PROVER_H_
|
|
17
|
+
|
|
18
|
+
#include <stddef.h>
|
|
19
|
+
|
|
20
|
+
#include <algorithm>
|
|
21
|
+
#include <array>
|
|
22
|
+
#include <vector>
|
|
23
|
+
|
|
24
|
+
#include "algebra/blas.h"
|
|
25
|
+
#include "ligero/ligero_param.h"
|
|
26
|
+
#include "ligero/ligero_transcript.h"
|
|
27
|
+
#include "merkle/merkle_commitment.h"
|
|
28
|
+
#include "random/random.h"
|
|
29
|
+
#include "random/transcript.h"
|
|
30
|
+
#include "util/crypto.h"
|
|
31
|
+
#include "util/panic.h"
|
|
32
|
+
|
|
33
|
+
namespace proofs {
|
|
34
|
+
template <class Field, class InterpolatorFactory>
|
|
35
|
+
class LigeroProver {
|
|
36
|
+
using Elt = typename Field::Elt;
|
|
37
|
+
|
|
38
|
+
public:
|
|
39
|
+
explicit LigeroProver(const LigeroParam<Field> &p)
|
|
40
|
+
: p_(p), mc_(p.block_enc - p.dblock), tableau_(p.nrow * p.block_enc) {}
|
|
41
|
+
|
|
42
|
+
// The SUBFIELD_BOUNDARY parameter is kind of a hack.
|
|
43
|
+
//
|
|
44
|
+
// Most, but not all, witnesses in W[] are known statically to be in
|
|
45
|
+
// the subfield of Field, for example because they are bits or
|
|
46
|
+
// bit-plucked values in the subfield. For zero-knowledge, for
|
|
47
|
+
// these witnesses, it suffices to choose blinding randomness in the
|
|
48
|
+
// subfield, which yields a shorter proof since most column openings
|
|
49
|
+
// are fully in the subfield. The problem is now to distinguish
|
|
50
|
+
// subfield witnesses from field witnesses.
|
|
51
|
+
//
|
|
52
|
+
// In the fullness of time we should have a compiler with typing
|
|
53
|
+
// information (field vs subfield) of all input wires. For now
|
|
54
|
+
// we implement the following hack: W[i] is in the subfield for
|
|
55
|
+
// i < SUBFIELD_BOUNDARY, and in the full field otherwise.
|
|
56
|
+
// If you don't know better, set SUBFIELD_BOUNDARY = 0 which
|
|
57
|
+
// trivially works for any input.
|
|
58
|
+
void commit(LigeroCommitment<Field> &commitment, Transcript &ts,
|
|
59
|
+
const Elt W[/*p_.nw*/], const size_t subfield_boundary,
|
|
60
|
+
const LigeroQuadraticConstraint lqc[/*nq*/],
|
|
61
|
+
const InterpolatorFactory &interpolator, RandomEngine &rng,
|
|
62
|
+
const Field &F) {
|
|
63
|
+
// Paranoid check on the SUBFIELD_BOUNDARY correctness condition
|
|
64
|
+
for (size_t i = 0; i < subfield_boundary; ++i) {
|
|
65
|
+
check(F.in_subfield(W[i]), "element not in subfield");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
layout(W, subfield_boundary, lqc, interpolator, rng, F);
|
|
69
|
+
|
|
70
|
+
// Merkle commitment
|
|
71
|
+
auto updhash = [&](size_t j, SHA256 &sha) {
|
|
72
|
+
LigeroCommon<Field>::column_hash(p_.nrow, &tableau_at(0, j + p_.dblock),
|
|
73
|
+
p_.block_enc, sha, F);
|
|
74
|
+
};
|
|
75
|
+
commitment.root = mc_.commit(updhash, rng);
|
|
76
|
+
|
|
77
|
+
// P -> V
|
|
78
|
+
LigeroTranscript<Field>::write_commitment(commitment, ts);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// HASH_OF_LLTERM is a hash of LLTERM provided by the caller. We
|
|
82
|
+
// could compute the hash locally, but usually LLTERM has a special
|
|
83
|
+
// structure that makes the computation faster on the caller's side.
|
|
84
|
+
void prove(LigeroProof<Field> &proof, Transcript &ts, size_t nl,
|
|
85
|
+
size_t nllterm,
|
|
86
|
+
const LigeroLinearConstraint<Field> llterm[/*nllterm*/],
|
|
87
|
+
const LigeroHash &hash_of_llterm,
|
|
88
|
+
const LigeroQuadraticConstraint lqc[/*nq*/],
|
|
89
|
+
const InterpolatorFactory &interpolator, const Field &F) {
|
|
90
|
+
{
|
|
91
|
+
// P -> V
|
|
92
|
+
// theorem statement
|
|
93
|
+
ts.write(hash_of_llterm.bytes, hash_of_llterm.kLength);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
{
|
|
97
|
+
std::vector<Elt> u_ldt(p_.nwqrow);
|
|
98
|
+
|
|
99
|
+
// V -> P
|
|
100
|
+
LigeroTranscript<Field>::gen_uldt(&u_ldt[0], p_, ts, F);
|
|
101
|
+
low_degree_proof(&proof.y_ldt[0], &u_ldt[0], F);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
{
|
|
105
|
+
std::vector<Elt> alphal(nl);
|
|
106
|
+
std::vector<std::array<Elt, 3>> alphaq(p_.nq);
|
|
107
|
+
std::vector<Elt> A(p_.nwqrow * p_.w);
|
|
108
|
+
|
|
109
|
+
// V -> P
|
|
110
|
+
LigeroTranscript<Field>::gen_alphal(nl, &alphal[0], ts, F);
|
|
111
|
+
LigeroTranscript<Field>::gen_alphaq(&alphaq[0], p_, ts, F);
|
|
112
|
+
|
|
113
|
+
LigeroCommon<Field>::inner_product_vector(&A[0], p_, nl, nllterm, llterm,
|
|
114
|
+
&alphal[0], lqc, &alphaq[0], F);
|
|
115
|
+
|
|
116
|
+
dot_proof(&proof.y_dot[0], &A[0], interpolator, F);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
{
|
|
120
|
+
std::vector<Elt> u_quad(p_.nqtriples);
|
|
121
|
+
|
|
122
|
+
// V -> P
|
|
123
|
+
LigeroTranscript<Field>::gen_uquad(&u_quad[0], p_, ts, F);
|
|
124
|
+
quadratic_proof(&proof.y_quad_0[0], &proof.y_quad_2[0], &u_quad[0], F);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
{
|
|
128
|
+
// P -> V
|
|
129
|
+
ts.write(&proof.y_ldt[0], 1, p_.block, F);
|
|
130
|
+
ts.write(&proof.y_dot[0], 1, p_.dblock, F);
|
|
131
|
+
ts.write(&proof.y_quad_0[0], 1, p_.r, F);
|
|
132
|
+
ts.write(&proof.y_quad_2[0], 1, p_.dblock - p_.block, F);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
{
|
|
136
|
+
std::vector<size_t> idx(p_.nreq);
|
|
137
|
+
// V -> P
|
|
138
|
+
LigeroTranscript<Field>::gen_idx(&idx[0], p_, ts, F);
|
|
139
|
+
|
|
140
|
+
compute_req(proof, &idx[0]);
|
|
141
|
+
|
|
142
|
+
mc_.open(proof.merkle, &idx[0], p_.nreq);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private:
|
|
147
|
+
Elt &tableau_at(size_t i, size_t j) {
|
|
148
|
+
size_t ld = p_.block_enc;
|
|
149
|
+
return tableau_[i * ld + j];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// fill t_[i, [0,n)] with random elements
|
|
153
|
+
// If the base_only flag is true, then the random element is chosen from
|
|
154
|
+
// the base field if F is a field extension.
|
|
155
|
+
void random_row(size_t i, size_t n, RandomEngine &rng, const Field &F) {
|
|
156
|
+
for (size_t j = 0; j < n; ++j) {
|
|
157
|
+
tableau_at(i, j) = rng.elt(F);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
void random_subfield_row(size_t i, size_t n, RandomEngine &rng,
|
|
162
|
+
const Field &F) {
|
|
163
|
+
for (size_t j = 0; j < n; ++j) {
|
|
164
|
+
tableau_at(i, j) = rng.subfield_elt(F);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// generate the ILDT and IDOT blinding rows
|
|
169
|
+
void layout_blinding_rows(const InterpolatorFactory &interpolator,
|
|
170
|
+
RandomEngine &rng, const Field &F) {
|
|
171
|
+
{
|
|
172
|
+
// blinds of size [BLOCK]
|
|
173
|
+
const auto interp = interpolator.make(p_.block, p_.block_enc);
|
|
174
|
+
|
|
175
|
+
// low-degree blinding row
|
|
176
|
+
random_row(p_.ildt, p_.block, rng, F);
|
|
177
|
+
interp->interpolate(&tableau_at(p_.ildt, 0));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
{
|
|
181
|
+
// blinds of size [DBLOCK]
|
|
182
|
+
const auto interp = interpolator.make(p_.dblock, p_.block_enc);
|
|
183
|
+
|
|
184
|
+
// dot-product blinding row constrained to SUM(W) = 0. First
|
|
185
|
+
// randomize the dblock:
|
|
186
|
+
random_row(p_.idot, p_.dblock, rng, F);
|
|
187
|
+
|
|
188
|
+
// Then constrain to sum(W) = 0
|
|
189
|
+
Elt sum = Blas<Field>::dot1(p_.w, &tableau_at(p_.idot, p_.r), 1, F);
|
|
190
|
+
F.sub(tableau_at(p_.idot, p_.r), sum);
|
|
191
|
+
|
|
192
|
+
interp->interpolate(&tableau_at(p_.idot, 0));
|
|
193
|
+
|
|
194
|
+
// quadratic-test blinding row constrained to W = 0. First
|
|
195
|
+
// randomize the entire dblock:
|
|
196
|
+
random_row(p_.iquad, p_.dblock, rng, F);
|
|
197
|
+
|
|
198
|
+
// Then constrain to W = 0
|
|
199
|
+
Blas<Field>::clear(p_.w, &tableau_at(p_.iquad, p_.r), 1, F);
|
|
200
|
+
|
|
201
|
+
interp->interpolate(&tableau_at(p_.iquad, 0));
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
void layout_witness_rows(const Elt W[/*nw*/], size_t subfield_boundary,
|
|
206
|
+
const InterpolatorFactory &interpolator,
|
|
207
|
+
RandomEngine &rng, const Field &F) {
|
|
208
|
+
const auto interp = interpolator.make(p_.block, p_.block_enc);
|
|
209
|
+
|
|
210
|
+
// witness row EXTEND([RANDOM[R], WITNESS[W]], BLOCK)
|
|
211
|
+
for (size_t i = 0; i < p_.nwrow; ++i) {
|
|
212
|
+
// TRUE if the entire row is in the subfield
|
|
213
|
+
bool subfield_only = ((i + 1) * p_.w <= subfield_boundary);
|
|
214
|
+
|
|
215
|
+
if (subfield_only) {
|
|
216
|
+
random_subfield_row(i + p_.iw, p_.r, rng, F);
|
|
217
|
+
} else {
|
|
218
|
+
random_row(i + p_.iw, p_.r, rng, F);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Set the WITNESS columns to zero first, and then
|
|
222
|
+
// overwrite with the witnesses that actually exist
|
|
223
|
+
Blas<Field>::clear(p_.w, &tableau_at(i + p_.iw, p_.r), 1, F);
|
|
224
|
+
size_t max_col = std::min(p_.w, p_.nw - i * p_.w);
|
|
225
|
+
Blas<Field>::copy(max_col, &tableau_at(i + p_.iw, p_.r), 1, &W[i * p_.w],
|
|
226
|
+
1);
|
|
227
|
+
interp->interpolate(&tableau_at(i + p_.iw, 0));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
void layout_quadratic_rows(const Elt W[/*nw*/],
|
|
232
|
+
const LigeroQuadraticConstraint lqc[/*nq*/],
|
|
233
|
+
const InterpolatorFactory &interpolator,
|
|
234
|
+
RandomEngine &rng, const Field &F) {
|
|
235
|
+
const auto interp = interpolator.make(p_.block, p_.block_enc);
|
|
236
|
+
|
|
237
|
+
// copy the multiplicand witnesses into the quadratic rows
|
|
238
|
+
size_t iqx = p_.iq;
|
|
239
|
+
size_t iqy = iqx + p_.nqtriples;
|
|
240
|
+
size_t iqz = iqy + p_.nqtriples;
|
|
241
|
+
|
|
242
|
+
for (size_t i = 0; i < p_.nqtriples; ++i) {
|
|
243
|
+
random_row(iqx + i, p_.r, rng, F);
|
|
244
|
+
random_row(iqy + i, p_.r, rng, F);
|
|
245
|
+
random_row(iqz + i, p_.r, rng, F);
|
|
246
|
+
|
|
247
|
+
// clear everything first, then overwrite the witnesses that
|
|
248
|
+
// actually exist
|
|
249
|
+
Blas<Field>::clear(p_.w, &tableau_at(iqx + i, p_.r), 1, F);
|
|
250
|
+
Blas<Field>::clear(p_.w, &tableau_at(iqy + i, p_.r), 1, F);
|
|
251
|
+
Blas<Field>::clear(p_.w, &tableau_at(iqz + i, p_.r), 1, F);
|
|
252
|
+
|
|
253
|
+
for (size_t j = 0; j < p_.w && j + i * p_.w < p_.nq; ++j) {
|
|
254
|
+
const auto *l = &lqc[j + i * p_.w];
|
|
255
|
+
check(W[l->z] == F.mulf(W[l->x], W[l->y]),
|
|
256
|
+
"invalid quadratic constraints");
|
|
257
|
+
tableau_at(iqx + i, j + p_.r) = W[l->x];
|
|
258
|
+
tableau_at(iqy + i, j + p_.r) = W[l->y];
|
|
259
|
+
tableau_at(iqz + i, j + p_.r) = W[l->z];
|
|
260
|
+
}
|
|
261
|
+
interp->interpolate(&tableau_at(iqx + i, 0));
|
|
262
|
+
interp->interpolate(&tableau_at(iqy + i, 0));
|
|
263
|
+
interp->interpolate(&tableau_at(iqz + i, 0));
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
void layout(const Elt W[/*nw*/], size_t subfield_boundary,
|
|
268
|
+
const LigeroQuadraticConstraint lqc[/*nq*/],
|
|
269
|
+
const InterpolatorFactory &interpolator, RandomEngine &rng,
|
|
270
|
+
const Field &F) {
|
|
271
|
+
layout_blinding_rows(interpolator, rng, F);
|
|
272
|
+
layout_witness_rows(W, subfield_boundary, interpolator, rng, F);
|
|
273
|
+
layout_quadratic_rows(W, lqc, interpolator, rng, F);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
void low_degree_proof(Elt y[/*block*/], const Elt u_ldt[/*nwqrow*/],
|
|
277
|
+
const Field &F) {
|
|
278
|
+
// ILDT blinding row with coefficient 1
|
|
279
|
+
Blas<Field>::copy(p_.block, y, 1, &tableau_at(p_.ildt, 0), 1);
|
|
280
|
+
|
|
281
|
+
// all witness and quadratic rows with coefficient u_ldt[]
|
|
282
|
+
for (size_t i = 0; i < p_.nwqrow; ++i) {
|
|
283
|
+
Blas<Field>::axpy(p_.block, y, 1, u_ldt[i], &tableau_at(i + p_.iw, 0), 1,
|
|
284
|
+
F);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
void dot_proof(Elt y[/*dblock*/], const Elt A[/*nwqrow, w*/],
|
|
289
|
+
const InterpolatorFactory &interpolator, const Field &F) {
|
|
290
|
+
const auto interpA = interpolator.make(p_.block, p_.dblock);
|
|
291
|
+
|
|
292
|
+
// IDOT blinding row with coefficient 1
|
|
293
|
+
Blas<Field>::copy(p_.dblock, y, 1, &tableau_at(p_.idot, 0), 1);
|
|
294
|
+
|
|
295
|
+
std::vector<Elt> Aext(p_.dblock);
|
|
296
|
+
for (size_t i = 0; i < p_.nwqrow; ++i) {
|
|
297
|
+
LigeroCommon<Field>::layout_Aext(&Aext[0], p_, i, &A[0], F);
|
|
298
|
+
interpA->interpolate(&Aext[0]);
|
|
299
|
+
|
|
300
|
+
// Accumulate y += A \otimes W.
|
|
301
|
+
Blas<Field>::vaxpy(p_.dblock, &y[0], 1, &Aext[0], 1,
|
|
302
|
+
&tableau_at(i + p_.iw, 0), 1, F);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
void quadratic_proof(Elt y0[/*r*/], Elt y2[/*dblock - block*/],
|
|
307
|
+
const Elt u_quad[/*nqtriples*/], const Field &F) {
|
|
308
|
+
std::vector<Elt> y(p_.dblock);
|
|
309
|
+
std::vector<Elt> tmp(p_.dblock);
|
|
310
|
+
|
|
311
|
+
// IQUAD blinding row with coefficient 1
|
|
312
|
+
Blas<Field>::copy(p_.dblock, &y[0], 1, &tableau_at(p_.iquad, 0), 1);
|
|
313
|
+
|
|
314
|
+
size_t iqx = p_.iq;
|
|
315
|
+
size_t iqy = iqx + p_.nqtriples;
|
|
316
|
+
size_t iqz = iqy + p_.nqtriples;
|
|
317
|
+
|
|
318
|
+
for (size_t i = 0; i < p_.nqtriples; ++i) {
|
|
319
|
+
// y += u_quad[i] * (z[i] - x[i] * y[i])
|
|
320
|
+
|
|
321
|
+
// tmp = z[i]
|
|
322
|
+
Blas<Field>::copy(p_.dblock, &tmp[0], 1, &tableau_at(iqz + i, 0), 1);
|
|
323
|
+
|
|
324
|
+
// tmp -= x[i] \otimes y[i]
|
|
325
|
+
Blas<Field>::vymax(p_.dblock, &tmp[0], 1, &tableau_at(iqx + i, 0), 1,
|
|
326
|
+
&tableau_at(iqy + i, 0), 1, F);
|
|
327
|
+
|
|
328
|
+
// y += u_quad[i] * tmp
|
|
329
|
+
Blas<Field>::axpy(p_.dblock, &y[0], 1, u_quad[i], &tmp[0], 1, F);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// sanity check: the W part of Y is zero
|
|
333
|
+
bool ok = Blas<Field>::equal0(p_.w, &y[p_.r], 1, F);
|
|
334
|
+
check(ok, "W part is nonzero");
|
|
335
|
+
|
|
336
|
+
// extract the first and last parts
|
|
337
|
+
Blas<Field>::copy(p_.r, y0, 1, &y[0], 1);
|
|
338
|
+
Blas<Field>::copy(p_.dblock - p_.block, y2, 1, &y[p_.block], 1);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
void compute_req(LigeroProof<Field> &proof, const size_t idx[/*nreq*/]) {
|
|
342
|
+
for (size_t i = 0; i < p_.nrow; ++i) {
|
|
343
|
+
Blas<Field>::gather(p_.nreq, &proof.req_at(i, 0),
|
|
344
|
+
&tableau_at(i, p_.dblock), idx);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const LigeroParam<Field> p_; /* safer to make copy */
|
|
349
|
+
MerkleCommitment mc_;
|
|
350
|
+
std::vector<Elt> tableau_ /*[nrow, block_enc]*/;
|
|
351
|
+
};
|
|
352
|
+
} // namespace proofs
|
|
353
|
+
|
|
354
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_PROVER_H_
|
|
@@ -0,0 +1,136 @@
|
|
|
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 <stdlib.h>
|
|
16
|
+
|
|
17
|
+
#include <cstdint>
|
|
18
|
+
#include <cstdio>
|
|
19
|
+
#include <vector>
|
|
20
|
+
|
|
21
|
+
#include "algebra/blas.h"
|
|
22
|
+
#include "algebra/convolution.h"
|
|
23
|
+
#include "algebra/fp.h"
|
|
24
|
+
#include "algebra/reed_solomon.h"
|
|
25
|
+
#include "gf2k/gf2_128.h"
|
|
26
|
+
#include "gf2k/lch14_reed_solomon.h"
|
|
27
|
+
#include "ligero/ligero_param.h"
|
|
28
|
+
#include "ligero/ligero_prover.h"
|
|
29
|
+
#include "ligero/ligero_verifier.h"
|
|
30
|
+
#include "random/secure_random_engine.h"
|
|
31
|
+
#include "random/transcript.h"
|
|
32
|
+
#include "util/log.h"
|
|
33
|
+
#include "gtest/gtest.h"
|
|
34
|
+
|
|
35
|
+
namespace proofs {
|
|
36
|
+
namespace {
|
|
37
|
+
|
|
38
|
+
template <class Field, class ReedSolomonFactory>
|
|
39
|
+
void ligero_test(const ReedSolomonFactory &rs_factory, const Field &F) {
|
|
40
|
+
using Elt = typename Field::Elt;
|
|
41
|
+
set_log_level(INFO);
|
|
42
|
+
static const constexpr size_t nw = 300000;
|
|
43
|
+
static const constexpr size_t nq = 30000;
|
|
44
|
+
static const constexpr size_t nreq = 189;
|
|
45
|
+
static const constexpr size_t nl = 7;
|
|
46
|
+
LigeroParam<Field> param(nw, nq, /*rateinv=*/4, nreq);
|
|
47
|
+
log(INFO, "%zd %zd %zd %zd %zd %zd\n", param.r, param.w, param.block,
|
|
48
|
+
param.block_enc, param.nrow, param.nqtriples);
|
|
49
|
+
|
|
50
|
+
std::vector<Elt> W(nw);
|
|
51
|
+
std::vector<Elt> A(nw);
|
|
52
|
+
for (size_t i = 0; i < nw; ++i) {
|
|
53
|
+
W[i] = F.of_scalar_field(random());
|
|
54
|
+
A[i] = F.of_scalar_field(random());
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Set up semi-random quadratic constraints. For simplicity
|
|
58
|
+
// of testing, say that the first NQ odd-index witnesses are
|
|
59
|
+
// the product of two even-index witnesses
|
|
60
|
+
std::vector<LigeroQuadraticConstraint> lqc(nq);
|
|
61
|
+
for (size_t i = 0; i < nq; ++i) {
|
|
62
|
+
lqc[i].z = 2 * i + 1;
|
|
63
|
+
lqc[i].x = 2 * ((random() % nw) / 2);
|
|
64
|
+
lqc[i].y = 2 * ((random() % nw) / 2);
|
|
65
|
+
W[lqc[i].z] = F.mulf(W[lqc[i].x], W[lqc[i].y]);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Generate NL linear constraints.
|
|
69
|
+
std::vector<LigeroLinearConstraint<Field>> llterm;
|
|
70
|
+
std::vector<Elt> b(nl);
|
|
71
|
+
Blas<Field>::clear(nl, &b[0], 1, F);
|
|
72
|
+
for (size_t w = 0; w < nw; ++w) {
|
|
73
|
+
LigeroLinearConstraint<Field> term = {
|
|
74
|
+
w % nl, // c
|
|
75
|
+
w, // w
|
|
76
|
+
A[w], // k
|
|
77
|
+
};
|
|
78
|
+
llterm.push_back(term);
|
|
79
|
+
F.add(b[term.c], F.mulf(W[w], term.k));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
LigeroCommitment<Field> commitment;
|
|
83
|
+
LigeroProof<Field> proof(¶m);
|
|
84
|
+
|
|
85
|
+
const LigeroHash hash_of_llterm{0xde, 0xad, 0xbe, 0xef};
|
|
86
|
+
|
|
87
|
+
{
|
|
88
|
+
log(INFO, "start prover");
|
|
89
|
+
SecureRandomEngine rng;
|
|
90
|
+
LigeroProver<Field, ReedSolomonFactory> prover(param);
|
|
91
|
+
Transcript ts((uint8_t *)"test", 4);
|
|
92
|
+
prover.commit(commitment, ts, &W[0], /*subfield_boundary=*/0, &lqc[0],
|
|
93
|
+
rs_factory, rng, F);
|
|
94
|
+
prover.prove(proof, ts, nl, llterm.size(), &llterm[0], hash_of_llterm,
|
|
95
|
+
&lqc[0], rs_factory, F);
|
|
96
|
+
log(INFO, "end prover");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
{
|
|
100
|
+
log(INFO, "start verifier");
|
|
101
|
+
Transcript ts((uint8_t *)"test", 4);
|
|
102
|
+
LigeroVerifier<Field, ReedSolomonFactory>::receive_commitment(commitment,
|
|
103
|
+
ts);
|
|
104
|
+
const char *why = "";
|
|
105
|
+
bool ok = LigeroVerifier<Field, ReedSolomonFactory>::verify(
|
|
106
|
+
&why, param, commitment, proof, ts, nl, llterm.size(), &llterm[0],
|
|
107
|
+
hash_of_llterm, &b[0], &lqc[0], rs_factory, F);
|
|
108
|
+
EXPECT_TRUE(ok);
|
|
109
|
+
log(INFO, "end verifier");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
TEST(Ligero, Fp) {
|
|
114
|
+
using Field = Fp<1>;
|
|
115
|
+
using ConvolutionFactory = FFTConvolutionFactory<Field>;
|
|
116
|
+
using ReedSolomonFactory = ReedSolomonFactory<Field, ConvolutionFactory>;
|
|
117
|
+
|
|
118
|
+
const Field F("18446744069414584321");
|
|
119
|
+
const ConvolutionFactory conv_factory(F, F.of_scalar(1753635133440165772ull),
|
|
120
|
+
1ull << 32);
|
|
121
|
+
const ReedSolomonFactory rs_factory(conv_factory, F);
|
|
122
|
+
|
|
123
|
+
ligero_test(rs_factory, F);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
TEST(Ligero, GF2_128) {
|
|
127
|
+
using Field = GF2_128<>;
|
|
128
|
+
const Field F;
|
|
129
|
+
using ReedSolomonFactory = LCH14ReedSolomonFactory<Field>;
|
|
130
|
+
const ReedSolomonFactory rs_factory(F);
|
|
131
|
+
|
|
132
|
+
ligero_test(rs_factory, F);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
} // namespace
|
|
136
|
+
} // namespace proofs
|
|
@@ -0,0 +1,67 @@
|
|
|
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_LIGERO_LIGERO_TRANSCRIPT_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_TRANSCRIPT_H_
|
|
17
|
+
|
|
18
|
+
#include <stddef.h>
|
|
19
|
+
|
|
20
|
+
#include <array>
|
|
21
|
+
|
|
22
|
+
#include "ligero/ligero_param.h"
|
|
23
|
+
#include "random/transcript.h"
|
|
24
|
+
|
|
25
|
+
namespace proofs {
|
|
26
|
+
template <class Field>
|
|
27
|
+
class LigeroTranscript {
|
|
28
|
+
public:
|
|
29
|
+
using Elt = typename Field::Elt;
|
|
30
|
+
|
|
31
|
+
static void write_commitment(const LigeroCommitment<Field>& commitment,
|
|
32
|
+
Transcript& ts) {
|
|
33
|
+
ts.write(commitment.root.data, commitment.root.kLength);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static void gen_uldt(Elt u[/*nwqrow*/], const LigeroParam<Field>& p,
|
|
37
|
+
Transcript& ts, const Field& F) {
|
|
38
|
+
ts.elt(u, p.nwqrow, F);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static void gen_alphal(size_t nl, Elt alpha[/*nl*/], Transcript& ts,
|
|
42
|
+
const Field& F) {
|
|
43
|
+
ts.elt(alpha, nl, F);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static void gen_alphaq(std::array<Elt, 3> alpha[/*nq*/],
|
|
47
|
+
const LigeroParam<Field>& p, Transcript& ts,
|
|
48
|
+
const Field& F) {
|
|
49
|
+
ts.elt(&alpha[0][0], 3 * p.nq, F);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static void gen_uquad(Elt u[/*nqtriples*/], const LigeroParam<Field>& p,
|
|
53
|
+
Transcript& ts, const Field& F) {
|
|
54
|
+
ts.elt(u, p.nqtriples, F);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Choose p.nreq distinct naturals in [0, p.block_enc - p.dblock)
|
|
58
|
+
static void gen_idx(size_t idx[/*p.nreq*/], const LigeroParam<Field>& p,
|
|
59
|
+
Transcript& ts, const Field& F) {
|
|
60
|
+
check(p.block_enc >= p.dblock, "p.block_enc >= p.dblock");
|
|
61
|
+
check(p.block_enc - p.dblock >= p.nreq, "p.block_enc - p.dblock >= p.nreq");
|
|
62
|
+
ts.choose(idx, p.block_enc - p.dblock, p.nreq);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
} // namespace proofs
|
|
66
|
+
|
|
67
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_TRANSCRIPT_H_
|