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,378 @@
|
|
|
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_ZK_ZK_PROOF_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_ZK_ZK_PROOF_H_
|
|
17
|
+
|
|
18
|
+
#include <cstddef>
|
|
19
|
+
#include <cstdint>
|
|
20
|
+
#include <optional>
|
|
21
|
+
#include <vector>
|
|
22
|
+
|
|
23
|
+
#include "ligero/ligero_param.h"
|
|
24
|
+
#include "merkle/merkle_commitment.h"
|
|
25
|
+
#include "merkle/merkle_tree.h"
|
|
26
|
+
#include "sumcheck/circuit.h"
|
|
27
|
+
#include "util/log.h"
|
|
28
|
+
#include "util/readbuffer.h"
|
|
29
|
+
#include "util/serialization.h"
|
|
30
|
+
#include "zk/zk_common.h"
|
|
31
|
+
|
|
32
|
+
namespace proofs {
|
|
33
|
+
|
|
34
|
+
// ZkProof class handles proof serialization.
|
|
35
|
+
//
|
|
36
|
+
// We expect circuits to be created and stored locally by the prover and
|
|
37
|
+
// verifier respectively, and thus the circuit representations are trusted and
|
|
38
|
+
// are assumed to contain parameters that do not induce arithmetic overflows.
|
|
39
|
+
// For example, we assume that values like c.logw and c.logc are smaller than
|
|
40
|
+
// 2^24 and therefore do not cause any overflows (even on 32b machines) in the
|
|
41
|
+
// range/length calculations that are performed during serialization.
|
|
42
|
+
//
|
|
43
|
+
// An earlier experiment implemented the IO methods using protobuf parsing.
|
|
44
|
+
// Despite applying techniques like arena allocation, those methods required
|
|
45
|
+
// an order of magnitude more time.
|
|
46
|
+
template <class Field>
|
|
47
|
+
struct ZkProof {
|
|
48
|
+
public:
|
|
49
|
+
const Circuit<Field> &c;
|
|
50
|
+
Proof<Field> proof;
|
|
51
|
+
LigeroParam<Field> param;
|
|
52
|
+
LigeroCommitment<Field> com;
|
|
53
|
+
LigeroProof<Field> com_proof;
|
|
54
|
+
|
|
55
|
+
// The max run length is 2^25, in order to prevent overflow issues on 32b
|
|
56
|
+
// machines when performing length calculations during serialization.
|
|
57
|
+
constexpr static size_t kMaxRunLen = (1 << 25);
|
|
58
|
+
|
|
59
|
+
constexpr static size_t kMaxNumDigests = (1 << 25);
|
|
60
|
+
|
|
61
|
+
typedef typename Field::Elt Elt;
|
|
62
|
+
|
|
63
|
+
explicit ZkProof(const Circuit<Field> &c, size_t rate, size_t req)
|
|
64
|
+
: c(c),
|
|
65
|
+
proof(c.nl),
|
|
66
|
+
param((c.ninputs - c.npub_in) + ZkCommon<Field>::pad_size(c), c.nl,
|
|
67
|
+
rate, req),
|
|
68
|
+
com_proof(¶m) {}
|
|
69
|
+
|
|
70
|
+
explicit ZkProof(const Circuit<Field> &c, size_t rate, size_t req,
|
|
71
|
+
size_t block_enc)
|
|
72
|
+
: c(c),
|
|
73
|
+
proof(c.nl),
|
|
74
|
+
param((c.ninputs - c.npub_in) + ZkCommon<Field>::pad_size(c), c.nl,
|
|
75
|
+
rate, req, block_enc),
|
|
76
|
+
com_proof(¶m) {}
|
|
77
|
+
|
|
78
|
+
// Maximum size of the proof in bytes. The actual size will be smaller
|
|
79
|
+
// because the Merkle proof is batched.
|
|
80
|
+
size_t size() const {
|
|
81
|
+
return Digest::kLength +
|
|
82
|
+
|
|
83
|
+
proof.size() * Field::kBytes +
|
|
84
|
+
|
|
85
|
+
com_proof.block * 2 * Field::kBytes +
|
|
86
|
+
com_proof.nreq * com_proof.nrow * Field::kBytes +
|
|
87
|
+
com_proof.nreq * com_proof.mc_pathlen * Digest::kLength;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
void write(std::vector<uint8_t> &buf, const Field &F) const {
|
|
91
|
+
size_t s0 = buf.size();
|
|
92
|
+
write_com(com, buf, F);
|
|
93
|
+
size_t s1 = buf.size();
|
|
94
|
+
write_sc_proof(proof, buf, F);
|
|
95
|
+
size_t s2 = buf.size();
|
|
96
|
+
write_com_proof(com_proof, buf, F);
|
|
97
|
+
size_t s3 = buf.size();
|
|
98
|
+
log(INFO,
|
|
99
|
+
"com:%zu, sc:%zu, com_proof:%zu [%zu el, %zu el, %zu d in %zu "
|
|
100
|
+
"rows]: %zub",
|
|
101
|
+
s1 - s0, s2 - s1, s3 - s2, 2 * com_proof.block,
|
|
102
|
+
com_proof.nreq * com_proof.nrow, com_proof.merkle.path.size(),
|
|
103
|
+
com_proof.nrow, s3 - s0);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// The read function returns false on error or underflow.
|
|
107
|
+
bool read(ReadBuffer &buf, const Field &F) {
|
|
108
|
+
if (!read_com(com, buf, F)) return false;
|
|
109
|
+
if (!read_sc_proof(proof, buf, F)) return false;
|
|
110
|
+
if (!read_com_proof(com_proof, buf, F)) return false;
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
void write_sc_proof(const Proof<Field> &pr, std::vector<uint8_t> &buf,
|
|
115
|
+
const Field &F) const {
|
|
116
|
+
check(c.logc == 0, "cannot write sc proof with logc != 0");
|
|
117
|
+
for (size_t i = 0; i < pr.l.size(); ++i) {
|
|
118
|
+
for (size_t wi = 0; wi < c.l[i].logw; ++wi) {
|
|
119
|
+
for (size_t k = 0; k < 3; ++k) {
|
|
120
|
+
// Optimization: do not send p(1) as it is implied by constraints.
|
|
121
|
+
if (k != 1) {
|
|
122
|
+
write_elt(pr.l[i].hp[0][wi].t_[k], buf, F);
|
|
123
|
+
write_elt(pr.l[i].hp[1][wi].t_[k], buf, F);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
write_elt(pr.l[i].wc[0], buf, F);
|
|
128
|
+
write_elt(pr.l[i].wc[1], buf, F);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
void write_com(const LigeroCommitment<Field> &com0, std::vector<uint8_t> &buf,
|
|
133
|
+
const Field &F) const {
|
|
134
|
+
buf.insert(buf.end(), com0.root.data, com0.root.data + Digest::kLength);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
void write_com_proof(const LigeroProof<Field> &pr, std::vector<uint8_t> &buf,
|
|
138
|
+
const Field &F) const {
|
|
139
|
+
for (size_t i = 0; i < pr.block; ++i) {
|
|
140
|
+
write_elt(pr.y_ldt[i], buf, F);
|
|
141
|
+
}
|
|
142
|
+
for (size_t i = 0; i < pr.dblock; ++i) {
|
|
143
|
+
write_elt(pr.y_dot[i], buf, F);
|
|
144
|
+
}
|
|
145
|
+
for (size_t i = 0; i < pr.r; ++i) {
|
|
146
|
+
write_elt(pr.y_quad_0[i], buf, F);
|
|
147
|
+
}
|
|
148
|
+
for (size_t i = 0; i < pr.dblock - pr.block; ++i) {
|
|
149
|
+
write_elt(pr.y_quad_2[i], buf, F);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// write all the Merkle nonces
|
|
153
|
+
for (size_t i = 0; i < pr.nreq; ++i) {
|
|
154
|
+
write_nonce(pr.merkle.nonce[i], buf);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// The format of the opened rows consists of a run of full-field elements,
|
|
158
|
+
// then a run of base-field elements, and finally a run of full-field
|
|
159
|
+
// elements. To compress, we employ a run-length encoding approach.
|
|
160
|
+
size_t ci = 0;
|
|
161
|
+
bool subfield_run = false;
|
|
162
|
+
while (ci < pr.nreq * pr.nrow) {
|
|
163
|
+
size_t runlen = 0;
|
|
164
|
+
while (ci + runlen < pr.nreq * pr.nrow && runlen < kMaxRunLen &&
|
|
165
|
+
F.in_subfield(pr.req[ci + runlen]) == subfield_run) {
|
|
166
|
+
++runlen;
|
|
167
|
+
}
|
|
168
|
+
write_size(runlen, buf);
|
|
169
|
+
for (size_t i = ci; i < ci + runlen; ++i) {
|
|
170
|
+
if (subfield_run) {
|
|
171
|
+
write_subfield_elt(pr.req[i], buf, F);
|
|
172
|
+
} else {
|
|
173
|
+
write_elt(pr.req[i], buf, F);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
ci += runlen;
|
|
177
|
+
subfield_run = !subfield_run;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
write_size(pr.merkle.path.size(), buf);
|
|
181
|
+
for (size_t i = 0; i < pr.merkle.path.size(); ++i) {
|
|
182
|
+
write_digest(pr.merkle.path[i], buf);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
private:
|
|
187
|
+
void write_elt(const Elt &x, std::vector<uint8_t> &buf,
|
|
188
|
+
const Field &F) const {
|
|
189
|
+
uint8_t tmp[Field::kBytes];
|
|
190
|
+
F.to_bytes_field(tmp, x);
|
|
191
|
+
buf.insert(buf.end(), tmp, tmp + Field::kBytes);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
void write_subfield_elt(const Elt &x, std::vector<uint8_t> &buf,
|
|
195
|
+
const Field &F) const {
|
|
196
|
+
uint8_t tmp[Field::kSubFieldBytes];
|
|
197
|
+
F.to_bytes_subfield(tmp, x);
|
|
198
|
+
buf.insert(buf.end(), tmp, tmp + Field::kSubFieldBytes);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
void write_digest(const Digest &x, std::vector<uint8_t> &buf) const {
|
|
202
|
+
buf.insert(buf.end(), x.data, x.data + Digest::kLength);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
void write_nonce(const MerkleNonce &x, std::vector<uint8_t> &buf) const {
|
|
206
|
+
buf.insert(buf.end(), x.bytes, x.bytes + MerkleNonce::kLength);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Assumption is that all of the sizes of arrays that are part of proofs
|
|
210
|
+
// fit into 4 bytes, and can thus work on 32-b machines.
|
|
211
|
+
void write_size(size_t g, std::vector<uint8_t> &buf) const {
|
|
212
|
+
for (size_t i = 0; i < 4; ++i) {
|
|
213
|
+
buf.push_back(static_cast<uint8_t>(g & 0xff));
|
|
214
|
+
g >>= 8;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
bool read_sc_proof(Proof<Field> &pr, ReadBuffer &buf, const Field &F) {
|
|
219
|
+
if (c.logc != 0) return false;
|
|
220
|
+
for (size_t i = 0; i < pr.l.size(); ++i) {
|
|
221
|
+
size_t needed = (c.l[i].logw * (3 - 1) * 2 + 2) * Field::kBytes;
|
|
222
|
+
if (!buf.have(needed)) return false;
|
|
223
|
+
for (size_t wi = 0; wi < c.l[i].logw; ++wi) {
|
|
224
|
+
for (size_t k = 0; k < 3; ++k) {
|
|
225
|
+
// Optimization: the p(1) value was not sent.
|
|
226
|
+
if (k != 1) {
|
|
227
|
+
for (size_t hi = 0; hi < 2; ++hi) {
|
|
228
|
+
auto v = read_elt(buf, F);
|
|
229
|
+
if (v) {
|
|
230
|
+
pr.l[i].hp[hi][wi].t_[k] = v.value();
|
|
231
|
+
} else {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
} else {
|
|
236
|
+
pr.l[i].hp[0][wi].t_[k] = F.zero();
|
|
237
|
+
pr.l[i].hp[1][wi].t_[k] = F.zero();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
for (size_t wi = 0; wi < 2; ++wi) {
|
|
242
|
+
auto v = read_elt(buf, F);
|
|
243
|
+
if (v) {
|
|
244
|
+
pr.l[i].wc[wi] = v.value();
|
|
245
|
+
} else {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
bool read_com(LigeroCommitment<Field> &com0, ReadBuffer &buf,
|
|
254
|
+
const Field &F) {
|
|
255
|
+
if (!buf.have(Digest::kLength)) return false;
|
|
256
|
+
read_digest(buf, com0.root);
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
bool read_com_proof(LigeroProof<Field> &pr, ReadBuffer &buf, const Field &F) {
|
|
261
|
+
if (!buf.have(pr.block * Field::kBytes)) return false;
|
|
262
|
+
for (size_t i = 0; i < pr.block; ++i) {
|
|
263
|
+
auto v = read_elt(buf, F);
|
|
264
|
+
if (v) {
|
|
265
|
+
pr.y_ldt[i] = v.value();
|
|
266
|
+
} else {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (!buf.have(pr.dblock * Field::kBytes)) return false;
|
|
272
|
+
for (size_t i = 0; i < pr.dblock; ++i) {
|
|
273
|
+
auto v = read_elt(buf, F);
|
|
274
|
+
if (v) {
|
|
275
|
+
pr.y_dot[i] = v.value();
|
|
276
|
+
} else {
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (!buf.have(pr.r * Field::kBytes)) return false;
|
|
282
|
+
for (size_t i = 0; i < pr.r; ++i) {
|
|
283
|
+
auto v = read_elt(buf, F);
|
|
284
|
+
if (v) {
|
|
285
|
+
pr.y_quad_0[i] = v.value();
|
|
286
|
+
} else {
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (!buf.have((pr.dblock - pr.block) * Field::kBytes)) return false;
|
|
292
|
+
for (size_t i = 0; i < pr.dblock - pr.block; ++i) {
|
|
293
|
+
auto v = read_elt(buf, F);
|
|
294
|
+
if (v) {
|
|
295
|
+
pr.y_quad_2[i] = v.value();
|
|
296
|
+
} else {
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (!buf.have(pr.nreq * MerkleNonce::kLength)) return false;
|
|
302
|
+
for (size_t i = 0; i < pr.nreq; ++i) {
|
|
303
|
+
read_nonce(buf, pr.merkle.nonce[i]);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Decode runs of real and full Field elements.
|
|
307
|
+
size_t ci = 0;
|
|
308
|
+
bool subfield_run = false;
|
|
309
|
+
while (ci < pr.nreq * pr.nrow) {
|
|
310
|
+
if (!buf.have(4)) return false;
|
|
311
|
+
size_t runlen = read_size(buf); /* untrusted size input */
|
|
312
|
+
if (runlen >= kMaxRunLen || ci + runlen > pr.nreq * pr.nrow) return false;
|
|
313
|
+
if (subfield_run) {
|
|
314
|
+
if (!buf.have(runlen * Field::kSubFieldBytes)) return false;
|
|
315
|
+
for (size_t i = ci; i < ci + runlen; ++i) {
|
|
316
|
+
auto v = read_subfield_elt(buf, F);
|
|
317
|
+
if (v) {
|
|
318
|
+
pr.req[i] = v.value();
|
|
319
|
+
} else {
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
} else {
|
|
324
|
+
if (!buf.have(runlen * Field::kBytes)) return false;
|
|
325
|
+
for (size_t i = ci; i < ci + runlen; ++i) {
|
|
326
|
+
auto v = read_elt(buf, F);
|
|
327
|
+
if (v) {
|
|
328
|
+
pr.req[i] = v.value();
|
|
329
|
+
} else {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
ci += runlen;
|
|
335
|
+
subfield_run = !subfield_run;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (!buf.have(4)) return false;
|
|
339
|
+
size_t sz = read_size(buf); /* untrusted size input */
|
|
340
|
+
|
|
341
|
+
// Merkle proofs of length < NREQ are not valid in the zk proof setting.
|
|
342
|
+
if (sz < pr.nreq || sz >= kMaxNumDigests) return false; // avoid overflow
|
|
343
|
+
if (!buf.have(sz * Digest::kLength)) return false;
|
|
344
|
+
|
|
345
|
+
// Sanity check, the proof should never be larger than this.
|
|
346
|
+
// That value should always fit into memory, so this check aims to avoid
|
|
347
|
+
// an exception by resize() if there is not enough memory to resize.
|
|
348
|
+
if (sz > pr.nreq * pr.mc_pathlen) return false;
|
|
349
|
+
|
|
350
|
+
pr.merkle.path.resize(sz);
|
|
351
|
+
for (size_t i = 0; i < sz; ++i) {
|
|
352
|
+
read_digest(buf, pr.merkle.path[i]);
|
|
353
|
+
}
|
|
354
|
+
return true;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
std::optional<Elt> read_elt(ReadBuffer &buf, const Field &F) const {
|
|
358
|
+
return F.of_bytes_field(buf.next(Field::kBytes));
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
std::optional<Elt> read_subfield_elt(ReadBuffer &buf, const Field &F) const {
|
|
362
|
+
return F.of_bytes_subfield(buf.next(Field::kSubFieldBytes));
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
void read_digest(ReadBuffer &buf, Digest &x) const {
|
|
366
|
+
buf.next(Digest::kLength, x.data);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
void read_nonce(ReadBuffer &buf, MerkleNonce &x) const {
|
|
370
|
+
buf.next(MerkleNonce::kLength, x.bytes);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
size_t read_size(ReadBuffer &buf) { return u32_of_le(buf.next(4)); }
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
} // namespace proofs
|
|
377
|
+
|
|
378
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_ZK_ZK_PROOF_H_
|
|
@@ -0,0 +1,202 @@
|
|
|
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_ZK_ZK_PROVER_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_ZK_ZK_PROVER_H_
|
|
17
|
+
|
|
18
|
+
#include <stddef.h>
|
|
19
|
+
|
|
20
|
+
#include <memory>
|
|
21
|
+
#include <vector>
|
|
22
|
+
|
|
23
|
+
#include "arrays/dense.h"
|
|
24
|
+
#include "ligero/ligero_param.h"
|
|
25
|
+
#include "ligero/ligero_prover.h"
|
|
26
|
+
#include "random/random.h"
|
|
27
|
+
#include "random/transcript.h"
|
|
28
|
+
#include "sumcheck/circuit.h"
|
|
29
|
+
#include "sumcheck/prover_layers.h"
|
|
30
|
+
#include "sumcheck/transcript_sumcheck.h"
|
|
31
|
+
#include "util/log.h"
|
|
32
|
+
#include "util/panic.h"
|
|
33
|
+
#include "zk/zk_common.h"
|
|
34
|
+
#include "zk/zk_proof.h"
|
|
35
|
+
|
|
36
|
+
namespace proofs {
|
|
37
|
+
// ZK Prover
|
|
38
|
+
//
|
|
39
|
+
// This class implements a zero-knowledge argument over a sumcheck transcript
|
|
40
|
+
// by first committing to a sumcheck witness and a random pad to encrypt
|
|
41
|
+
// a sumcheck transcript, then running the sumcheck protocol over the original
|
|
42
|
+
// claim and witness, but outputting the encrypted transcript, and finally
|
|
43
|
+
// using a Ligero prover to prove the statement: "the committed witness and
|
|
44
|
+
// pad, when used to decrypt the encrypted sumcheck transcript satisfies the
|
|
45
|
+
// sumcheck verifier."
|
|
46
|
+
//
|
|
47
|
+
// While this statement is complex, it can be implemented easily because
|
|
48
|
+
// the sumcheck verifier essentially checks the evaluations of degree-2 or -3
|
|
49
|
+
// polynomials, and performs one multiplication per layer of the circuit. The
|
|
50
|
+
// Hyrax paper makes a similar observation, but uses an elliptic-curve based
|
|
51
|
+
// proof, whereas here we use the Ligero system.
|
|
52
|
+
template <class Field, class ReedSolomonFactory>
|
|
53
|
+
class ZkProver : public ProverLayers<Field> {
|
|
54
|
+
using super = ProverLayers<Field>;
|
|
55
|
+
using typename super::bindings;
|
|
56
|
+
using Elt = typename Field::Elt;
|
|
57
|
+
using typename super::inputs;
|
|
58
|
+
|
|
59
|
+
public:
|
|
60
|
+
ZkProver(const Circuit<Field>& CIRCUIT, const Field& F,
|
|
61
|
+
const ReedSolomonFactory& rs_factory)
|
|
62
|
+
: ProverLayers<Field>(F),
|
|
63
|
+
c_(CIRCUIT),
|
|
64
|
+
n_witness_(c_.ninputs - c_.npub_in),
|
|
65
|
+
f_(F),
|
|
66
|
+
rsf_(rs_factory),
|
|
67
|
+
pad_(c_.nl),
|
|
68
|
+
witness_(n_witness_),
|
|
69
|
+
lqc_(c_.nl),
|
|
70
|
+
lp_(nullptr) {}
|
|
71
|
+
|
|
72
|
+
void commit(ZkProof<Field>& zkp, const Dense<Field>& W, Transcript& tp,
|
|
73
|
+
RandomEngine& rng) {
|
|
74
|
+
log(INFO, "ZK Commit start");
|
|
75
|
+
|
|
76
|
+
// Copy witnesses for commitment
|
|
77
|
+
// Layout of the com: 0 ...<witnesses>... start_pad <pad> len
|
|
78
|
+
// Only commit the private witnesses, which begin at index c_.npub_in.
|
|
79
|
+
for (size_t i = 0; i < n_witness_; ++i) {
|
|
80
|
+
witness_[i] = W.v_[i + c_.npub_in];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Rebase the circuit SUBFIELD_BOUNDARY (if any) to start at
|
|
84
|
+
// NPUB_IN,
|
|
85
|
+
size_t subfield_boundary = 0;
|
|
86
|
+
if (c_.subfield_boundary >= c_.npub_in) {
|
|
87
|
+
subfield_boundary = c_.subfield_boundary - c_.npub_in;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Fill pad with random values, add pad to witness, record lqc.
|
|
91
|
+
fill_pad(rng);
|
|
92
|
+
ZkCommon<Field>::setup_lqc(c_, lqc_, n_witness_ /* = start_pad */);
|
|
93
|
+
|
|
94
|
+
// Commit to witness and pad.
|
|
95
|
+
lp_ = std::make_unique<LigeroProver<Field, ReedSolomonFactory>>(zkp.param);
|
|
96
|
+
lp_->commit(zkp.com, tp, &witness_[0], subfield_boundary, &lqc_[0], rsf_,
|
|
97
|
+
rng, f_);
|
|
98
|
+
|
|
99
|
+
log(INFO, "ZK Commitment done");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
bool prove(ZkProof<Field>& zkp, const Dense<Field>& W, Transcript& tsp) {
|
|
103
|
+
check(lp_ != nullptr, "must run commit before prove");
|
|
104
|
+
|
|
105
|
+
// Interpret W as public parameters, we only append
|
|
106
|
+
// c_.npub_in elements of W to the transcript
|
|
107
|
+
ZkCommon<Field>::initialize_sumcheck_fiat_shamir(tsp, c_, W, f_);
|
|
108
|
+
Transcript tst = tsp.clone();
|
|
109
|
+
|
|
110
|
+
// Run sumcheck to generate a padded proof.
|
|
111
|
+
inputs in;
|
|
112
|
+
auto V = super::eval_circuit(&in, &c_, W.clone(), f_);
|
|
113
|
+
if (V == nullptr) {
|
|
114
|
+
log(ERROR, "eval_circuit failed");
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
for (size_t i = 0; i < V->n1_; ++i) {
|
|
118
|
+
if (V->v_[i] != f_.zero()) {
|
|
119
|
+
log(ERROR, "V->v_[i] != F.zero()");
|
|
120
|
+
return false;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
bindings bnd;
|
|
124
|
+
ProofAux<Field> aux(c_.nl);
|
|
125
|
+
|
|
126
|
+
TranscriptSumcheck<Field> tsts(tst, f_);
|
|
127
|
+
super::prove(&zkp.proof, &pad_, &c_, in, &aux, bnd, tsts, f_);
|
|
128
|
+
log(INFO, "ZK sumcheck done");
|
|
129
|
+
|
|
130
|
+
// 5. Simulate the verifier to assemble constraints on the committed vals.
|
|
131
|
+
// Form the sparse matrix A and vector b such that A*w = b.
|
|
132
|
+
std::vector<LigeroLinearConstraint<Field>> a;
|
|
133
|
+
std::vector<Elt> b;
|
|
134
|
+
size_t ci = ZkCommon<Field>::verifier_constraints(c_, W, zkp.proof, &aux, a,
|
|
135
|
+
b, tsp, n_witness_, f_);
|
|
136
|
+
log(INFO, "ZK constraints done");
|
|
137
|
+
|
|
138
|
+
// 6. Produce proof over commitment.
|
|
139
|
+
// For FS soundness, it is ok for hash_of_A to be any string.
|
|
140
|
+
// In the interactive version, the verifier provides a challenge for the
|
|
141
|
+
// com proof. The last prover message is the (wc_l,wc_r) pair, and this
|
|
142
|
+
// has already been added to the transcript.
|
|
143
|
+
const LigeroHash hash_of_A{0xde, 0xad, 0xbe, 0xef};
|
|
144
|
+
lp_->prove(zkp.com_proof, tsp, ci, a.size(), &a[0], hash_of_A, &lqc_[0],
|
|
145
|
+
rsf_, f_);
|
|
146
|
+
|
|
147
|
+
log(INFO, "Prover Done: flag");
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Fill proof with random pad values for a given circuit.
|
|
152
|
+
void fill_pad(RandomEngine& rng) {
|
|
153
|
+
for (size_t i = 0; i < c_.nl; ++i) {
|
|
154
|
+
for (size_t j = 0; j < c_.logc; ++j) {
|
|
155
|
+
for (size_t k = 0; k < 4; ++k) {
|
|
156
|
+
if (k != 1) { // P(1) optimization
|
|
157
|
+
Elt r = rng.elt(f_);
|
|
158
|
+
pad_.l[i].cp[j].t_[k] = r;
|
|
159
|
+
witness_.push_back(r);
|
|
160
|
+
} else {
|
|
161
|
+
pad_.l[i].cp[j].t_[k] = f_.zero();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
for (size_t j = 0; j < c_.l[i].logw; ++j) {
|
|
166
|
+
for (size_t h = 0; h < 2; ++h) {
|
|
167
|
+
for (size_t k = 0; k < 3; ++k) {
|
|
168
|
+
if (k != 1) { // P(1) optimization
|
|
169
|
+
Elt r = rng.elt(f_);
|
|
170
|
+
pad_.l[i].hp[h][j].t_[k] = r;
|
|
171
|
+
witness_.push_back(r);
|
|
172
|
+
} else {
|
|
173
|
+
pad_.l[i].hp[h][j].t_[k] = f_.zero();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
for (size_t k = 0; k < 2; ++k) {
|
|
179
|
+
Elt r = rng.elt(f_);
|
|
180
|
+
pad_.l[i].wc[k] = r;
|
|
181
|
+
witness_.push_back(r);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Commit to product of pads for product proof.
|
|
185
|
+
Elt rr = f_.mulf(pad_.l[i].wc[0], pad_.l[i].wc[1]);
|
|
186
|
+
witness_.push_back(rr);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const Circuit<Field>& c_;
|
|
191
|
+
const size_t n_witness_;
|
|
192
|
+
const Field& f_;
|
|
193
|
+
const ReedSolomonFactory& rsf_;
|
|
194
|
+
Proof<Field> pad_;
|
|
195
|
+
std::vector<Elt> witness_;
|
|
196
|
+
std::vector<LigeroQuadraticConstraint> lqc_;
|
|
197
|
+
std::unique_ptr<LigeroProver<Field, ReedSolomonFactory>> lp_;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
} // namespace proofs
|
|
201
|
+
|
|
202
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_ZK_ZK_PROVER_H_
|