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,69 @@
|
|
|
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_SUMCHECK_TESTING_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_TESTING_H_
|
|
17
|
+
|
|
18
|
+
#include <stddef.h>
|
|
19
|
+
|
|
20
|
+
#include <cstdint>
|
|
21
|
+
#include <memory>
|
|
22
|
+
|
|
23
|
+
#include "arrays/dense.h"
|
|
24
|
+
#include "random/transcript.h"
|
|
25
|
+
#include "sumcheck/circuit.h"
|
|
26
|
+
#include "sumcheck/prover.h"
|
|
27
|
+
#include "sumcheck/verifier.h"
|
|
28
|
+
#include "util/log.h"
|
|
29
|
+
#include "util/panic.h"
|
|
30
|
+
|
|
31
|
+
/*
|
|
32
|
+
These are methods that help test modules
|
|
33
|
+
by running the prover or the verifier.
|
|
34
|
+
*/
|
|
35
|
+
namespace proofs {
|
|
36
|
+
template <class Field>
|
|
37
|
+
void run_prover(const Circuit<Field> *C, std::unique_ptr<Dense<Field>> W,
|
|
38
|
+
Proof<Field> *proof, const Field& F) {
|
|
39
|
+
typename Prover<Field>::inputs pin;
|
|
40
|
+
|
|
41
|
+
Prover<Field> prover(F);
|
|
42
|
+
auto V = prover.eval_circuit(&pin, C, W->clone(), F);
|
|
43
|
+
|
|
44
|
+
check(V != nullptr, "eval_circuit failed.");
|
|
45
|
+
|
|
46
|
+
// Ensure the witness satisfies the circuit before making a proof.
|
|
47
|
+
for (size_t i = 0; i < V->n1_; ++i) {
|
|
48
|
+
if (V->v_[i] != F.zero()) {
|
|
49
|
+
log(INFO, "witness failed: non-zero output at %zu", i);
|
|
50
|
+
}
|
|
51
|
+
check(V->v_[i] == F.zero(), "witness failed, non-zero output");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
Transcript tsp((uint8_t *)"testing", 7);
|
|
55
|
+
prover.prove(proof, nullptr, C, pin, tsp);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
template <class Field>
|
|
59
|
+
void run_verifier(const Circuit<Field> *C, std::unique_ptr<Dense<Field>> W,
|
|
60
|
+
Proof<Field> &proof, const Field& F) {
|
|
61
|
+
const char *why = "ok";
|
|
62
|
+
auto V = std::make_unique<Dense<Field>>(F);
|
|
63
|
+
Transcript tsv((uint8_t *)"testing", 7);
|
|
64
|
+
check(Verifier<Field>::verify(&why, C, &proof, std::move(V),
|
|
65
|
+
W->clone(), tsv, F), why);
|
|
66
|
+
}
|
|
67
|
+
} // namespace proofs
|
|
68
|
+
|
|
69
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_TESTING_H_
|
|
@@ -0,0 +1,85 @@
|
|
|
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_SUMCHECK_TRANSCRIPT_SUMCHECK_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_TRANSCRIPT_SUMCHECK_H_
|
|
17
|
+
|
|
18
|
+
#include <stddef.h>
|
|
19
|
+
|
|
20
|
+
#include "arrays/affine.h"
|
|
21
|
+
#include "arrays/dense.h"
|
|
22
|
+
#include "random/transcript.h"
|
|
23
|
+
#include "sumcheck/circuit.h"
|
|
24
|
+
|
|
25
|
+
namespace proofs {
|
|
26
|
+
/*
|
|
27
|
+
Fiat-Shamir abstraction for sumcheck protocol.
|
|
28
|
+
This class takes wraps a transcript object and provides the interface for
|
|
29
|
+
sumcheck challenge and response.
|
|
30
|
+
*/
|
|
31
|
+
template <typename Field>
|
|
32
|
+
class TranscriptSumcheck {
|
|
33
|
+
using Elt = typename Field::Elt;
|
|
34
|
+
using CPoly = typename Proof<Field>::CPoly;
|
|
35
|
+
using WPoly = typename Proof<Field>::WPoly;
|
|
36
|
+
static constexpr size_t kMaxBindings = Proof<Field>::kMaxBindings;
|
|
37
|
+
|
|
38
|
+
public:
|
|
39
|
+
explicit TranscriptSumcheck(Transcript& ts, const Field& F)
|
|
40
|
+
: ts_(ts), f_(F) {}
|
|
41
|
+
|
|
42
|
+
void write_input(const Dense<Field>* X) {
|
|
43
|
+
// Write column by column to make it compatible with oracle.
|
|
44
|
+
for (corner_t c = 0; c < X->n0_; ++c) {
|
|
45
|
+
ts_.write(&X->v_[c], X->n0_, X->n1_, f_);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
void begin_circuit(Elt* Q, Elt* G) {
|
|
50
|
+
ts_.elt(Q, kMaxBindings, f_);
|
|
51
|
+
ts_.elt(G, kMaxBindings, f_);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
void begin_layer(Elt& alpha, Elt& beta, size_t layer) {
|
|
55
|
+
alpha = ts_.elt(f_);
|
|
56
|
+
beta = ts_.elt(f_);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
void write(const Elt e[/*n*/], size_t ince, size_t n) {
|
|
60
|
+
ts_.write(e, ince, n, f_);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
template <class Poly>
|
|
64
|
+
Elt /*R*/ round(const Poly& poly) {
|
|
65
|
+
write_poly(&poly);
|
|
66
|
+
return ts_.elt(f_);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private:
|
|
70
|
+
template <class Poly>
|
|
71
|
+
void write_poly(const Poly* poly) {
|
|
72
|
+
// Do not write the p(1) value to the transcript, as its value is
|
|
73
|
+
// implied by the constraints, and we can omit it from the proof.
|
|
74
|
+
for (size_t i = 0; i < Poly::kN; ++i) {
|
|
75
|
+
if (i != 1) {
|
|
76
|
+
ts_.write(poly->t_[i], f_);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
Transcript& ts_;
|
|
81
|
+
const Field& f_;
|
|
82
|
+
};
|
|
83
|
+
} // namespace proofs
|
|
84
|
+
|
|
85
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_TRANSCRIPT_SUMCHECK_H_
|
|
@@ -0,0 +1,84 @@
|
|
|
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_SUMCHECK_VERIFIER_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_VERIFIER_H_
|
|
17
|
+
|
|
18
|
+
#include <stddef.h>
|
|
19
|
+
|
|
20
|
+
#include <memory>
|
|
21
|
+
|
|
22
|
+
#include "arrays/dense.h"
|
|
23
|
+
#include "random/transcript.h"
|
|
24
|
+
#include "sumcheck/circuit.h"
|
|
25
|
+
#include "sumcheck/transcript_sumcheck.h"
|
|
26
|
+
#include "sumcheck/verifier_layers.h"
|
|
27
|
+
|
|
28
|
+
namespace proofs {
|
|
29
|
+
// Full sumcheck verifier that verifies the layers
|
|
30
|
+
// via verifier_layers<> and then checks the input
|
|
31
|
+
// binding directly.
|
|
32
|
+
template <class Field>
|
|
33
|
+
class Verifier : public VerifierLayers<Field> {
|
|
34
|
+
using super = VerifierLayers<Field>;
|
|
35
|
+
using typename super::claims;
|
|
36
|
+
using typename super::Elt;
|
|
37
|
+
|
|
38
|
+
public:
|
|
39
|
+
static bool verify(const char** why, const Circuit<Field>* circ,
|
|
40
|
+
const Proof<Field>* proof,
|
|
41
|
+
std::unique_ptr<Dense<Field>> V,
|
|
42
|
+
std::unique_ptr<Dense<Field>> X, Transcript& ts,
|
|
43
|
+
const Field& F) {
|
|
44
|
+
if (why == nullptr || circ == nullptr || proof == nullptr ||
|
|
45
|
+
V == nullptr || X == nullptr) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
claims cl{};
|
|
50
|
+
Challenge<Field> ch(circ->nl);
|
|
51
|
+
TranscriptSumcheck<Field> tss(ts, F);
|
|
52
|
+
tss.write_input(X.get());
|
|
53
|
+
|
|
54
|
+
if (!(super::circuit(why, &cl, circ, proof, &ch, std::move(V), tss,
|
|
55
|
+
F))) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Final check on W, the input wires.
|
|
60
|
+
// bind the copy variables:
|
|
61
|
+
X->bind_all(circ->logc, cl.q, F);
|
|
62
|
+
X->reshape(cl.nv);
|
|
63
|
+
|
|
64
|
+
// bind the gate variables, for two hands:
|
|
65
|
+
auto X1 = X->clone();
|
|
66
|
+
Dense<Field>* VH[2] = {X.get(), X1.get()};
|
|
67
|
+
|
|
68
|
+
for (size_t hand = 0; hand < 2; ++hand) {
|
|
69
|
+
VH[hand]->bind_all(cl.logv, cl.g[hand], F);
|
|
70
|
+
Elt got = VH[hand]->scalar();
|
|
71
|
+
if (got != cl.claim[hand]) {
|
|
72
|
+
*why = "got != cl.claim[hand]";
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
Verifier() = delete;
|
|
81
|
+
};
|
|
82
|
+
} // namespace proofs
|
|
83
|
+
|
|
84
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_VERIFIER_H_
|
|
@@ -0,0 +1,221 @@
|
|
|
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_SUMCHECK_VERIFIER_LAYERS_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_VERIFIER_LAYERS_H_
|
|
17
|
+
|
|
18
|
+
#include <stddef.h>
|
|
19
|
+
|
|
20
|
+
#include <cstddef>
|
|
21
|
+
#include <memory>
|
|
22
|
+
|
|
23
|
+
#include "arrays/affine.h"
|
|
24
|
+
#include "arrays/dense.h"
|
|
25
|
+
#include "arrays/eq.h"
|
|
26
|
+
#include "sumcheck/circuit.h"
|
|
27
|
+
#include "sumcheck/quad.h"
|
|
28
|
+
#include "sumcheck/transcript_sumcheck.h"
|
|
29
|
+
|
|
30
|
+
namespace proofs {
|
|
31
|
+
// Sumcheck verifier that only verifies the layers.
|
|
32
|
+
// Derived classes are responsible for verifying the
|
|
33
|
+
// input binding, either directly or through a commitment.
|
|
34
|
+
template <class Field>
|
|
35
|
+
class VerifierLayers {
|
|
36
|
+
public:
|
|
37
|
+
typedef typename Quad<Field>::index_t index_t;
|
|
38
|
+
using Elt = typename Field::Elt;
|
|
39
|
+
|
|
40
|
+
struct claims {
|
|
41
|
+
corner_t nv;
|
|
42
|
+
size_t logv;
|
|
43
|
+
Elt claim[2];
|
|
44
|
+
const Elt* q;
|
|
45
|
+
const Elt* g[2];
|
|
46
|
+
};
|
|
47
|
+
// Verify all the circuit layers, returning claims on the inputs in
|
|
48
|
+
// CL. The caller is responsible to verify the claims, either via
|
|
49
|
+
// direct check or polynomial commitment.
|
|
50
|
+
static bool circuit(const char** why, claims* cl,
|
|
51
|
+
const Circuit<Field>* CIRCUIT, const Proof<Field>* PROOF,
|
|
52
|
+
Challenge<Field>* CH, std::unique_ptr<Dense<Field>> V,
|
|
53
|
+
TranscriptSumcheck<Field>& ts, const Field& F) {
|
|
54
|
+
if (why == nullptr || cl == nullptr || CIRCUIT == nullptr ||
|
|
55
|
+
PROOF == nullptr || CH == nullptr) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
*why = "ok";
|
|
59
|
+
|
|
60
|
+
Elt claimV;
|
|
61
|
+
ts.begin_circuit(CH->q, CH->g);
|
|
62
|
+
|
|
63
|
+
if (V->n1_ == 1 && V->n0_ == 1 && V->v_[0] == F.zero()) {
|
|
64
|
+
// special case of all-zero binding
|
|
65
|
+
claimV = F.zero();
|
|
66
|
+
} else {
|
|
67
|
+
const desire desires[2] = {
|
|
68
|
+
{V->n1_ == CIRCUIT->nv, "V->n1_ != CIRCUIT->nv"},
|
|
69
|
+
{V->n0_ == CIRCUIT->nc, "V->n0_ != CIRCUIT->nc"},
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
if (!check(why, 2, desires)) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// initial claim on V[G, Q] for the output V
|
|
77
|
+
V->bind_all(CIRCUIT->logc, CH->q, F);
|
|
78
|
+
V->reshape(CIRCUIT->nv);
|
|
79
|
+
V->bind_all(CIRCUIT->logv, CH->g, F);
|
|
80
|
+
claimV = V->scalar();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Consider claimV on the binding to P.G as two (identical)
|
|
84
|
+
// claims, so we can get the induction going. Thus, alpha in
|
|
85
|
+
// the first layer is redundant.
|
|
86
|
+
*cl = claims{
|
|
87
|
+
.nv = CIRCUIT->nv,
|
|
88
|
+
.logv = CIRCUIT->logv,
|
|
89
|
+
.claim = {claimV, claimV},
|
|
90
|
+
.q = CH->q,
|
|
91
|
+
.g = {CH->g, CH->g},
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
return layers(why, cl, CIRCUIT, PROOF, ts, CH, F);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
VerifierLayers() = delete;
|
|
98
|
+
|
|
99
|
+
private:
|
|
100
|
+
struct desire {
|
|
101
|
+
bool cond;
|
|
102
|
+
const char* why;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
static bool check(const char** why, size_t n, const desire* d) {
|
|
106
|
+
for (size_t i = 0; i < n; ++i) {
|
|
107
|
+
if (!d[i].cond) {
|
|
108
|
+
*why = d[i].why;
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Verify CLAIM for one layer and update CLAIM in-place as next
|
|
116
|
+
// claim. Return TRUE on success, and (FALSE, why) on failure.
|
|
117
|
+
static bool layer_c(const char** why, Elt* claim, size_t logc,
|
|
118
|
+
const LayerProof<Field>* plr, LayerChallenge<Field>* ch,
|
|
119
|
+
TranscriptSumcheck<Field>& ts, const Field& F) {
|
|
120
|
+
for (size_t round = 0; round < logc; ++round) {
|
|
121
|
+
// Change verification equation from
|
|
122
|
+
// claim =? (p(0) + p(1))
|
|
123
|
+
// to p(1) = claim - p(0).
|
|
124
|
+
auto tp = plr->cp[round];
|
|
125
|
+
auto t1 = F.subf(*claim, tp.t_[0]);
|
|
126
|
+
ch->cb[round] = ts.round(plr->cp[round]);
|
|
127
|
+
auto p = tp.to_poly(t1);
|
|
128
|
+
*claim = p.eval_lagrange(ch->cb[round], F);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
static bool layer_h(const char** why, Elt* claim, size_t logw,
|
|
135
|
+
const LayerProof<Field>* plr, LayerChallenge<Field>* ch,
|
|
136
|
+
TranscriptSumcheck<Field>& ts, const Field& F) {
|
|
137
|
+
for (size_t round = 0; round < logw; ++round) {
|
|
138
|
+
for (size_t hand = 0; hand < 2; ++hand) {
|
|
139
|
+
// Change verification equation from
|
|
140
|
+
// claim =? (p(0) + p(1))
|
|
141
|
+
// to p(1) = claim - p(0).
|
|
142
|
+
auto tp = plr->hp[hand][round];
|
|
143
|
+
auto t1 = F.subf(*claim, tp.t_[0]);
|
|
144
|
+
ch->hb[hand][round] = ts.round(tp);
|
|
145
|
+
auto p = tp.to_poly(t1);
|
|
146
|
+
*claim = p.eval_lagrange(ch->hb[hand][round], F);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Verify CLAIMS for all layers and update CLAIMS in-place. Return
|
|
153
|
+
// TRUE on success, and (FALSE, why) on failure.
|
|
154
|
+
static bool layers(const char** why, claims* cl,
|
|
155
|
+
const Circuit<Field>* CIRCUIT, const Proof<Field>* PROOF,
|
|
156
|
+
TranscriptSumcheck<Field>& ts, Challenge<Field>* CH,
|
|
157
|
+
const Field& F) {
|
|
158
|
+
for (size_t ly = 0; ly < CIRCUIT->nl; ++ly) {
|
|
159
|
+
auto clr = &CIRCUIT->l.at(ly);
|
|
160
|
+
auto plr = &PROOF->l[ly];
|
|
161
|
+
auto challenge = &CH->l[ly];
|
|
162
|
+
|
|
163
|
+
// the claim is then an affine combination of the two
|
|
164
|
+
// inductive claims
|
|
165
|
+
ts.begin_layer(challenge->alpha, challenge->beta, ly);
|
|
166
|
+
Elt claim = F.addf(cl->claim[0], F.mulf(challenge->alpha, cl->claim[1]));
|
|
167
|
+
|
|
168
|
+
if (!layer_c(why, &claim, CIRCUIT->logc, plr, challenge, ts, F)) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (!layer_h(why, &claim, clr->logw, plr, challenge, ts, F)) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Now verify CLAIM = EQ[Q,C] QUAD[R,L] W[R,C] W[L,C]
|
|
177
|
+
// where W[R,C], W[L,C] are in the proof.
|
|
178
|
+
|
|
179
|
+
// bind QUAD[g|r,l] to the alpha-combination of the
|
|
180
|
+
// two G values GR, GL
|
|
181
|
+
auto EQUAD = clr->quad->bind_g(cl->logv, cl->g[0], cl->g[1],
|
|
182
|
+
challenge->alpha, challenge->beta, F);
|
|
183
|
+
|
|
184
|
+
// bind QUAD[G|r,l] to R, L
|
|
185
|
+
for (size_t round = 0; round < clr->logw; ++round) {
|
|
186
|
+
for (size_t hand = 0; hand < 2; ++hand) {
|
|
187
|
+
EQUAD->bind_h(challenge->hb[hand][round], hand, F);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// got = EQ[Q,C] QUAD[G|R,L] W[R,C] W[L,C], where
|
|
192
|
+
// W[.,C] is in the proof.
|
|
193
|
+
Elt got =
|
|
194
|
+
Eq<Field>::eval(CIRCUIT->logc, CIRCUIT->nc, cl->q, challenge->cb, F);
|
|
195
|
+
F.mul(got, EQUAD->scalar());
|
|
196
|
+
F.mul(got, plr->wc[0]);
|
|
197
|
+
F.mul(got, plr->wc[1]);
|
|
198
|
+
|
|
199
|
+
if (got != claim) {
|
|
200
|
+
*why = "got != claim (layer)";
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Add wc[0,1] to transcript
|
|
205
|
+
ts.write(&plr->wc[0], 1, 2);
|
|
206
|
+
|
|
207
|
+
// Reduce to two claims on W[R,C] and W[L,C]
|
|
208
|
+
*cl = claims{
|
|
209
|
+
.nv = clr->nw,
|
|
210
|
+
.logv = clr->logw,
|
|
211
|
+
.claim = {plr->wc[0], plr->wc[1]},
|
|
212
|
+
.q = challenge->cb,
|
|
213
|
+
.g = {challenge->hb[0], challenge->hb[1]},
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
} // namespace proofs
|
|
220
|
+
|
|
221
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_VERIFIER_LAYERS_H_
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Copyright 2024 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
|
+
// main() for running both tests and benchmarks in the same
|
|
16
|
+
// file.
|
|
17
|
+
//
|
|
18
|
+
// The behavior is as follows:
|
|
19
|
+
//
|
|
20
|
+
// foo_test
|
|
21
|
+
// Run tests but not benchmarks
|
|
22
|
+
//
|
|
23
|
+
// foo_test --benchmark_filter=all
|
|
24
|
+
// Run benchmarks but not tests
|
|
25
|
+
//
|
|
26
|
+
#include <benchmark/benchmark.h>
|
|
27
|
+
#include <gtest/gtest.h>
|
|
28
|
+
#include <string.h>
|
|
29
|
+
|
|
30
|
+
int main(int argc, char **argv) {
|
|
31
|
+
::testing::InitGoogleTest(&argc, argv);
|
|
32
|
+
|
|
33
|
+
// Hack: run benchmarks only if --benchmark_filter is
|
|
34
|
+
// specified explicitly.
|
|
35
|
+
|
|
36
|
+
// By default, the benchmark filter is set to *, which runs all
|
|
37
|
+
// benchmarks. We don't want to run benchmarks when testing. In
|
|
38
|
+
// recent versions of libbenchmark, one can call
|
|
39
|
+
// GetBenchmarkFilter(), but older versions don't support it.
|
|
40
|
+
// Check for anything that starts with --bench.
|
|
41
|
+
bool bench = (argc > 1) && !strncmp(argv[1], "--bench", 7);
|
|
42
|
+
|
|
43
|
+
if (bench) {
|
|
44
|
+
// By default run no benchmarks
|
|
45
|
+
benchmark::Initialize(&argc, argv);
|
|
46
|
+
return benchmark::RunSpecifiedBenchmarks();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return RUN_ALL_TESTS();
|
|
50
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
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_UTIL_CEILDIV_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_UTIL_CEILDIV_H_
|
|
17
|
+
|
|
18
|
+
// This package holds basic math utility functions.
|
|
19
|
+
|
|
20
|
+
#include <cstddef>
|
|
21
|
+
#include <cstdint>
|
|
22
|
+
|
|
23
|
+
namespace proofs {
|
|
24
|
+
|
|
25
|
+
// ceil(a/b)
|
|
26
|
+
template <class T>
|
|
27
|
+
T ceildiv(T a, T b) {
|
|
28
|
+
return (a + (b - 1)) / b;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
inline size_t lg(size_t n) {
|
|
32
|
+
size_t lgk = 0, k = 1;
|
|
33
|
+
while (k < n) {
|
|
34
|
+
k *= 2;
|
|
35
|
+
lgk += 1;
|
|
36
|
+
}
|
|
37
|
+
return lgk;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Morton-order operations
|
|
41
|
+
namespace morton {
|
|
42
|
+
// extract even bits (pack)
|
|
43
|
+
inline uint64_t even(uint64_t x) {
|
|
44
|
+
x &= 0x5555555555555555ull;
|
|
45
|
+
x |= (x >> 1);
|
|
46
|
+
x &= 0x3333333333333333ull;
|
|
47
|
+
x |= (x >> 2);
|
|
48
|
+
x &= 0x0F0F0F0F0F0F0F0Full;
|
|
49
|
+
x |= (x >> 4);
|
|
50
|
+
x &= 0x00FF00FF00FF00FFull;
|
|
51
|
+
x |= (x >> 8);
|
|
52
|
+
x &= 0x0000FFFF0000FFFFull;
|
|
53
|
+
x |= (x >> 16);
|
|
54
|
+
x &= 0x00000000FFFFFFFFull;
|
|
55
|
+
return x;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// inverse of even (unpack)
|
|
59
|
+
inline uint64_t uneven(uint64_t x) {
|
|
60
|
+
x &= 0x00000000FFFFFFFFull;
|
|
61
|
+
x |= (x << 16);
|
|
62
|
+
x &= 0x0000FFFF0000FFFFull;
|
|
63
|
+
x |= (x << 8);
|
|
64
|
+
x &= 0x00FF00FF00FF00FFull;
|
|
65
|
+
x |= (x << 4);
|
|
66
|
+
x &= 0x0F0F0F0F0F0F0F0Full;
|
|
67
|
+
x |= (x << 2);
|
|
68
|
+
x &= 0x3333333333333333ull;
|
|
69
|
+
x |= (x << 1);
|
|
70
|
+
x &= 0x5555555555555555ull;
|
|
71
|
+
return x;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Given two integers X and Y represented
|
|
75
|
+
// as (even, odd) bits (X0, X1) and
|
|
76
|
+
// (Y0, Y1), set (X0, X1) to the even/odd
|
|
77
|
+
// representation of X+Y
|
|
78
|
+
template <class T>
|
|
79
|
+
static void add(T *x0, T *x1, T y0, T y1) {
|
|
80
|
+
// Given two arrays X[i] and Y[i] of bits, the goal
|
|
81
|
+
// is to build an adder. One way to build an adder
|
|
82
|
+
// is to switch to the generate/propagate representation
|
|
83
|
+
// G[i] = X[i] & Y[i]
|
|
84
|
+
// P[i] = X[i] ^ Y[i]
|
|
85
|
+
// where G[i] means "position i generates a carry" and P[i] means
|
|
86
|
+
// "position i propagates the carry coming from position i-1".
|
|
87
|
+
//
|
|
88
|
+
// Generate/propagate can be extended to pairs of positions
|
|
89
|
+
// via the equations
|
|
90
|
+
//
|
|
91
|
+
// G = G[i+1] ^ (G[i] ^ P[i+1])
|
|
92
|
+
// P = P[i+1] & P[i]. (1)
|
|
93
|
+
//
|
|
94
|
+
// (This is all well-known adder stuff that has been known since
|
|
95
|
+
// at least the '50s).
|
|
96
|
+
//
|
|
97
|
+
// Our strategy is thus: convert the addends into G/P representation;
|
|
98
|
+
// combine the [2i] and [2i+1] positions via Equation (1), and
|
|
99
|
+
// use the C "+" operation to propagate the carry over one array.
|
|
100
|
+
//
|
|
101
|
+
// The fun part is, how do you use the C adder to propagate G.
|
|
102
|
+
// The standard form of the adder is:
|
|
103
|
+
//
|
|
104
|
+
// (G, P) = (X & Y, X ^ Y)
|
|
105
|
+
// G' = propagate G in any convenient way
|
|
106
|
+
// (X + Y) = RESULT = P ^ G'
|
|
107
|
+
//
|
|
108
|
+
// and thus we can extract the propagated G' as G' = (X + Y) ^ X ^ Y.
|
|
109
|
+
//
|
|
110
|
+
// The other fun part is, given G and P, how do you go back to X and
|
|
111
|
+
// Y that can be fed to the C adder? The transformation (X, Y) -> (G, P)
|
|
112
|
+
// is not injective, but any inverse will work. We choose
|
|
113
|
+
//
|
|
114
|
+
// X = G
|
|
115
|
+
// Y = P ^ G
|
|
116
|
+
|
|
117
|
+
// Convert inputs into (G, P) form.
|
|
118
|
+
T g0 = *x0 & y0, g1 = *x1 & y1;
|
|
119
|
+
T p0 = *x0 ^ y0, p1 = *x1 ^ y1;
|
|
120
|
+
|
|
121
|
+
// Combine the two (G, P) inputs.
|
|
122
|
+
T g = g1 ^ (g0 & p1);
|
|
123
|
+
T p = p0 & p1;
|
|
124
|
+
|
|
125
|
+
// Convert back into (X, Y) = (G, P ^ G) and compute
|
|
126
|
+
// GPRIME = (X + Y) ^ X ^ Y, which simplifies to (X + Y) ^ P
|
|
127
|
+
// because X = G and Y = P ^ G.
|
|
128
|
+
// Here we lose the carry of the addition, making it impossible
|
|
129
|
+
// to output a global carry.
|
|
130
|
+
T gprime = (g + (p ^ g)) ^ p;
|
|
131
|
+
|
|
132
|
+
// XOR the propagated carries back into P
|
|
133
|
+
*x0 = gprime ^ p0;
|
|
134
|
+
*x1 = g0 ^ (gprime & p0) ^ p1;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// a-b via ~(~a + b)
|
|
138
|
+
template <class T>
|
|
139
|
+
static void sub(T *x0, T *x1, T y0, T y1) {
|
|
140
|
+
*x0 = ~*x0;
|
|
141
|
+
*x1 = ~*x1;
|
|
142
|
+
add(x0, x1, y0, y1);
|
|
143
|
+
*x0 = ~*x0;
|
|
144
|
+
*x1 = ~*x1;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// a < b via (a - b) < 0. Since we don't have
|
|
148
|
+
// the output carry of the subtraction, we pretend that
|
|
149
|
+
// the result is signed.
|
|
150
|
+
template <class T>
|
|
151
|
+
static bool lt(T x0, T x1, T y0, T y1) {
|
|
152
|
+
sub(&x0, &x1, y0, y1);
|
|
153
|
+
return (x1 >> (8 * sizeof(T) - 1)) == 1;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
template <class T>
|
|
157
|
+
static bool eq(T x0, T x1, T y0, T y1) {
|
|
158
|
+
return x0 == y0 && x1 == y1;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
} // namespace morton
|
|
162
|
+
} // namespace proofs
|
|
163
|
+
|
|
164
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_UTIL_CEILDIV_H_
|