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,193 @@
|
|
|
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_RANDOM_TRANSCRIPT_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_RANDOM_TRANSCRIPT_H_
|
|
17
|
+
|
|
18
|
+
#include <cstddef>
|
|
19
|
+
#include <cstdint>
|
|
20
|
+
#include <cstring>
|
|
21
|
+
#include <memory>
|
|
22
|
+
|
|
23
|
+
#include "random/random.h"
|
|
24
|
+
#include "util/crypto.h"
|
|
25
|
+
#include "util/panic.h"
|
|
26
|
+
#include "util/serialization.h"
|
|
27
|
+
|
|
28
|
+
namespace proofs {
|
|
29
|
+
|
|
30
|
+
/*
|
|
31
|
+
FSPRF and Transcript together used implement the Fiat-Shamir transform.
|
|
32
|
+
*/
|
|
33
|
+
class FSPRF {
|
|
34
|
+
public:
|
|
35
|
+
explicit FSPRF(const uint8_t key[kPRFKeySize])
|
|
36
|
+
: prf_(key), nblock_(0), rdptr_(kPRFOutputSize) {}
|
|
37
|
+
|
|
38
|
+
// Disable copy for good measure.
|
|
39
|
+
explicit FSPRF(const FSPRF&) = delete;
|
|
40
|
+
FSPRF& operator=(const FSPRF&) = delete;
|
|
41
|
+
|
|
42
|
+
// Maximum number of blocks that can be generated using a 128-bit PRF.
|
|
43
|
+
// The limit is 2^64, but 2^40 suffices for our application.
|
|
44
|
+
constexpr static uint64_t kMaxBlocks = 0x10000000000;
|
|
45
|
+
|
|
46
|
+
void bytes(uint8_t buf[/*n*/], size_t n) {
|
|
47
|
+
while (n-- > 0) {
|
|
48
|
+
if (rdptr_ == kPRFOutputSize) {
|
|
49
|
+
refill();
|
|
50
|
+
}
|
|
51
|
+
*buf++ = saved_[rdptr_++];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private:
|
|
56
|
+
void refill() {
|
|
57
|
+
check(nblock_ < kMaxBlocks, "too many blocks");
|
|
58
|
+
uint8_t in[kPRFInputSize] = {};
|
|
59
|
+
u64_to_le(in, nblock_++);
|
|
60
|
+
prf_.Eval(saved_, in);
|
|
61
|
+
rdptr_ = 0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
PRF prf_;
|
|
65
|
+
uint64_t nblock_;
|
|
66
|
+
size_t rdptr_; // read pointer into saved[]
|
|
67
|
+
uint8_t saved_[kPRFOutputSize]; // saved pseudo-random bytes
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
class Transcript : public RandomEngine {
|
|
71
|
+
enum { TAG_BSTR = 0, TAG_FIELD_ELEM = 1, TAG_ARRAY = 2 };
|
|
72
|
+
|
|
73
|
+
public:
|
|
74
|
+
// A transcript must be explicitly initialized so that each instance of
|
|
75
|
+
// the Random oracle is unique.
|
|
76
|
+
Transcript(const uint8_t init[], size_t init_len, size_t version = 6)
|
|
77
|
+
: sha_(), prf_(), version_(version) {
|
|
78
|
+
write(init, init_len);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Remove default copy and move implementations.
|
|
82
|
+
Transcript(const Transcript&) = delete;
|
|
83
|
+
Transcript& operator=(const Transcript&) = delete;
|
|
84
|
+
|
|
85
|
+
// Explicit copy to avoid accidental passing by value.
|
|
86
|
+
Transcript clone() { return Transcript(sha_, version_); }
|
|
87
|
+
|
|
88
|
+
// Generate bytes by via the current FSPRF object.
|
|
89
|
+
void bytes(uint8_t buf[/*n*/], size_t n) override {
|
|
90
|
+
if (!prf_) {
|
|
91
|
+
uint8_t key[kPRFKeySize];
|
|
92
|
+
get(key);
|
|
93
|
+
prf_ = std::make_unique<FSPRF>(key);
|
|
94
|
+
}
|
|
95
|
+
prf_->bytes(buf, n);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// snapshot the hash of the transcript so far
|
|
99
|
+
void get(uint8_t key[/*kPRFKeySize*/]) {
|
|
100
|
+
check(kPRFKeySize == kSHA256DigestSize, "prf key size != digest output");
|
|
101
|
+
// fork the state because we will finalize it
|
|
102
|
+
SHA256 tmp_hash;
|
|
103
|
+
tmp_hash.CopyState(sha_);
|
|
104
|
+
tmp_hash.DigestData(key);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Typed write operations. We tag byte-array(n), field-element, and
|
|
108
|
+
// array-of-field-element(n).
|
|
109
|
+
//
|
|
110
|
+
// We make a few arbitrary choices that make no real difference.
|
|
111
|
+
// All lengths are 64-bit. We distinguish a field element from
|
|
112
|
+
// an array of one field element, which is kind of arbitrary.
|
|
113
|
+
|
|
114
|
+
// byte string
|
|
115
|
+
void write(const uint8_t data[/*n*/], size_t n) {
|
|
116
|
+
tag(TAG_BSTR);
|
|
117
|
+
length(n);
|
|
118
|
+
|
|
119
|
+
write_untyped(data, n);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// N zero bytes
|
|
123
|
+
void write0(size_t n) {
|
|
124
|
+
tag(TAG_BSTR);
|
|
125
|
+
length(n);
|
|
126
|
+
|
|
127
|
+
uint8_t data[32] = {};
|
|
128
|
+
for (; n > 32; n -= 32) {
|
|
129
|
+
write_untyped(data, 32);
|
|
130
|
+
}
|
|
131
|
+
write_untyped(data, n);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// one field element
|
|
135
|
+
template <class Field>
|
|
136
|
+
void write(const typename Field::Elt& e, const Field& F) {
|
|
137
|
+
tag(TAG_FIELD_ELEM);
|
|
138
|
+
|
|
139
|
+
write_untyped(e, F);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// array of field elements
|
|
143
|
+
template <class Field>
|
|
144
|
+
void write(const typename Field::Elt e[/*n*/], size_t ince, size_t n,
|
|
145
|
+
const Field& F) {
|
|
146
|
+
tag(TAG_ARRAY);
|
|
147
|
+
length(n);
|
|
148
|
+
|
|
149
|
+
for (size_t i = 0; i < n; ++i) {
|
|
150
|
+
write_untyped(e[i * ince], F);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private:
|
|
155
|
+
explicit Transcript(const SHA256& sha, size_t version)
|
|
156
|
+
: sha_(), version_(version) {
|
|
157
|
+
sha_.CopyState(sha);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Output a 1-byte tag
|
|
161
|
+
void tag(size_t t) {
|
|
162
|
+
uint8_t d = static_cast<uint8_t>(t);
|
|
163
|
+
write_untyped(&d, 1);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Output a 8-byte length. We pass the length
|
|
167
|
+
// as size_t, but we always write it as uint64_t
|
|
168
|
+
void length(size_t x) {
|
|
169
|
+
uint8_t a[8];
|
|
170
|
+
u64_to_le(a, x);
|
|
171
|
+
write_untyped(a, 8);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
void write_untyped(const uint8_t data[/*n*/], size_t n) {
|
|
175
|
+
// invalidate the PRF on any writes
|
|
176
|
+
prf_.reset();
|
|
177
|
+
sha_.Update(data, n);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
template <class Field>
|
|
181
|
+
void write_untyped(const typename Field::Elt& e, const Field& F) {
|
|
182
|
+
uint8_t buf[Field::kBytes];
|
|
183
|
+
F.to_bytes_field(buf, e);
|
|
184
|
+
write_untyped(buf, sizeof(buf));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
SHA256 sha_;
|
|
188
|
+
std::unique_ptr<FSPRF> prf_;
|
|
189
|
+
const size_t version_; // version 4+ fixes the TAG_ARRAY typo.
|
|
190
|
+
};
|
|
191
|
+
} // namespace proofs
|
|
192
|
+
|
|
193
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_RANDOM_TRANSCRIPT_H_
|
|
@@ -0,0 +1,344 @@
|
|
|
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 "random/transcript.h"
|
|
16
|
+
|
|
17
|
+
#include <sys/types.h>
|
|
18
|
+
|
|
19
|
+
#include <cstddef>
|
|
20
|
+
#include <cstdint>
|
|
21
|
+
#include <cstdio>
|
|
22
|
+
|
|
23
|
+
#include "algebra/fp.h"
|
|
24
|
+
#include "algebra/static_string.h"
|
|
25
|
+
#include "gtest/gtest.h"
|
|
26
|
+
|
|
27
|
+
namespace proofs {
|
|
28
|
+
namespace {
|
|
29
|
+
typedef Fp<4> Field;
|
|
30
|
+
static const Field F(
|
|
31
|
+
"11579208921035624876269744694940757353008614341529031419553363130886709785"
|
|
32
|
+
"3951");
|
|
33
|
+
typedef Field::Elt Elt;
|
|
34
|
+
|
|
35
|
+
TEST(Transcript, Write) {
|
|
36
|
+
uint8_t buf1[4], buf2[4];
|
|
37
|
+
|
|
38
|
+
Transcript ts1((uint8_t*)"test", 4);
|
|
39
|
+
ts1.write(F.of_scalar(7), F);
|
|
40
|
+
ts1.bytes(buf1, 4);
|
|
41
|
+
|
|
42
|
+
Transcript ts2((uint8_t*)"test", 4);
|
|
43
|
+
ts2.write(F.of_scalar(8), F);
|
|
44
|
+
ts2.bytes(buf2, 4);
|
|
45
|
+
|
|
46
|
+
EXPECT_NE(buf1, buf2);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
TEST(Transcript, TwoBlocks) {
|
|
50
|
+
// Generate two blocks and check that they are not the same.
|
|
51
|
+
// Hardcoded 16 assumes AES PRF
|
|
52
|
+
uint8_t a[16], b[16];
|
|
53
|
+
Transcript ts((uint8_t*)"test", 4);
|
|
54
|
+
ts.write(F.of_scalar(8), F);
|
|
55
|
+
ts.bytes(a, 16);
|
|
56
|
+
ts.bytes(b, 16);
|
|
57
|
+
bool same = true;
|
|
58
|
+
for (size_t i = 0; i < 16; ++i) {
|
|
59
|
+
same &= (a[i] == b[i]);
|
|
60
|
+
}
|
|
61
|
+
EXPECT_FALSE(same);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
TEST(Transcript, Associative) {
|
|
65
|
+
constexpr size_t n = 100;
|
|
66
|
+
uint8_t a[n], b[n];
|
|
67
|
+
for (size_t i = 0; i < n; ++i) {
|
|
68
|
+
Transcript ts((uint8_t*)"test", 4);
|
|
69
|
+
ts.write(F.of_scalar(7), F);
|
|
70
|
+
{
|
|
71
|
+
Transcript ts1 = ts.clone();
|
|
72
|
+
ts.bytes(a, i);
|
|
73
|
+
ts.bytes(a + i, n - i);
|
|
74
|
+
}
|
|
75
|
+
{
|
|
76
|
+
Transcript ts1 = ts.clone();
|
|
77
|
+
ts1.bytes(b, n);
|
|
78
|
+
}
|
|
79
|
+
for (size_t j = 0; j < n; ++j) {
|
|
80
|
+
EXPECT_EQ(a[i], b[i]);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
void dump_elt(Elt elt) {
|
|
86
|
+
uint8_t buf[Field::kBytes];
|
|
87
|
+
F.to_bytes_field(buf, elt);
|
|
88
|
+
for (size_t i = Field::kBytes; i-- > 0;) {
|
|
89
|
+
printf("%02x", buf[i]);
|
|
90
|
+
}
|
|
91
|
+
printf(",\n");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
void check_elt_output(Transcript& ts, const StaticString want[/*16*/]) {
|
|
95
|
+
Elt e[16];
|
|
96
|
+
ts.clone().elt(e, 16, F);
|
|
97
|
+
|
|
98
|
+
for (size_t i = 0; i < 16; ++i) {
|
|
99
|
+
// Generating challenge one element at a time is equivalent to generating
|
|
100
|
+
// multiple elements together.
|
|
101
|
+
EXPECT_EQ(ts.elt(F), e[i]);
|
|
102
|
+
// EXPECT_EQ(F.of_string(want[i]), e[i]);
|
|
103
|
+
dump_elt(e[i]);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
void check_nat_output(Transcript& ts, const size_t want[/* 24 */]) {
|
|
108
|
+
size_t nat_sizes[24] = {
|
|
109
|
+
1, 1, 1, 2, 2, 2, 7, 7, 7, 7, 32, 32, 32, 32,
|
|
110
|
+
256, 256, 256, 256, 1000, 10000, 60000, 65535, 100000, 100000};
|
|
111
|
+
for (size_t i = 0; i < 24; ++i) {
|
|
112
|
+
size_t got = ts.nat(nat_sizes[i]);
|
|
113
|
+
printf("%zu ", got);
|
|
114
|
+
// EXPECT_EQ(got, want[i]);
|
|
115
|
+
}
|
|
116
|
+
printf("\n");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
void check_choose_output(Transcript& ts, const size_t want[]) {
|
|
120
|
+
size_t nat_sizes[6] = {31, 32, 63, 64, 1000, 65535};
|
|
121
|
+
size_t got[20];
|
|
122
|
+
|
|
123
|
+
for (size_t i = 0; i < 6; ++i) {
|
|
124
|
+
ts.choose(got, nat_sizes[i], 20);
|
|
125
|
+
for (size_t j = 0; j < 20; ++j) {
|
|
126
|
+
EXPECT_EQ(got[j], want[i * 20 + j]);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
TEST(Transcript, TestVectors) {
|
|
132
|
+
Transcript ts((uint8_t*)"test", 4, 4);
|
|
133
|
+
// write a byte array
|
|
134
|
+
uint8_t d[100];
|
|
135
|
+
for (size_t i = 0; i < 100; ++i) {
|
|
136
|
+
d[i] = static_cast<uint8_t>(i);
|
|
137
|
+
}
|
|
138
|
+
ts.write(d, 100);
|
|
139
|
+
|
|
140
|
+
StaticString want[16] = {
|
|
141
|
+
StaticString(
|
|
142
|
+
"0x8b297f0bffd583c6c6b6796385d5fd20a08665733b833970ebdd1054bbbc1b14"),
|
|
143
|
+
StaticString(
|
|
144
|
+
"0x0667c08ad7f38efec5f30dc8aa4f20d749cdcf96d63a770f9810ac5c0ca8dcb1"),
|
|
145
|
+
StaticString(
|
|
146
|
+
"0xc8037fc12d4da00b5dc7597e3042f33f72a06f970cb71fb6b103ebb5419d8a6b"),
|
|
147
|
+
StaticString(
|
|
148
|
+
"0xfbbcfa1eac48728fbfdacc1c21e2f78119457e0846337e46140e38e62856c4c5"),
|
|
149
|
+
StaticString(
|
|
150
|
+
"0x5358ae603691cc759faeb572fb6642654ea1c3dbc8f81d00276dd8c4df95aa58"),
|
|
151
|
+
StaticString(
|
|
152
|
+
"0x5266158c3c895dede5a23b6ce85a9f564b8059ebfcd1741f54497ec58189873e"),
|
|
153
|
+
StaticString(
|
|
154
|
+
"0x3ecea4b2343c007fc32f2aff40dc7320945f101ecae5d52494db21ad326e9739"),
|
|
155
|
+
StaticString(
|
|
156
|
+
"0x6462dd575e6b874118607212feec7ce5417ae3bf0f2e86604596f35d48bbaea2"),
|
|
157
|
+
StaticString(
|
|
158
|
+
"0x6d56c703c369edea3595db6b958241580ae9b4a76fead961413ed9e9e5852dcd"),
|
|
159
|
+
StaticString(
|
|
160
|
+
"0x6d31073cee650212a71b7b13e9f951e00ef3b14a008a79dd95047b26a4a83d06"),
|
|
161
|
+
StaticString(
|
|
162
|
+
"0x1b9e2a6666da63c43e52227d91a8a7f0bd5311f63c2e3a18839133375639e6cb"),
|
|
163
|
+
StaticString(
|
|
164
|
+
"0x332ea49dd23dd4745631ecbb15696192b1fa127256baf7a0483fd27db6f09a48"),
|
|
165
|
+
StaticString(
|
|
166
|
+
"0x43e735927ccbdc4d5ce912675d638d6d3dc8eef3def34504304e938846f157d6"),
|
|
167
|
+
StaticString(
|
|
168
|
+
"0xdc4a8868ae75e733a7257a8589230392a98d78594836dfccd01304742b5b3ad5"),
|
|
169
|
+
StaticString(
|
|
170
|
+
"0x976353931711c634f2691e507b119fd7f6e653d419a2620676122db08db18765"),
|
|
171
|
+
StaticString(
|
|
172
|
+
"0x332729ab436dca654866a9382deaee0add6fb7e90a80261f1488e56598e8bc99"),
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
check_elt_output(ts, want);
|
|
176
|
+
|
|
177
|
+
// write a field element
|
|
178
|
+
ts.write(F.of_scalar(7), F);
|
|
179
|
+
StaticString want2[16] = {
|
|
180
|
+
StaticString(
|
|
181
|
+
"0x609db3e9a8f548df038519fa46cef23eb8c6553d3c1f698604e60a51613a738e"),
|
|
182
|
+
StaticString(
|
|
183
|
+
"0x1cb69cb31999eb88e83c7586aac53f5e3286b084b0cf9e43619b48df01e0a310"),
|
|
184
|
+
StaticString(
|
|
185
|
+
"0x3bf36e3ddc690a1b12b417628c115959b373d056c90c42dc2417baf46f538868"),
|
|
186
|
+
StaticString(
|
|
187
|
+
"0xe336594f29dcda52e48896517b5cdb2d062ffd861ab02db5f8ca197aacc635f6"),
|
|
188
|
+
StaticString(
|
|
189
|
+
"0xc1f396a8bad16bb0f57da6d380402a25b571bd4691226d11449a741440e325c8"),
|
|
190
|
+
StaticString(
|
|
191
|
+
"0x5195336ec73751de066e3a8939b40c3c5555f1a513486dfc50dcf4c2d47e6ff2"),
|
|
192
|
+
StaticString(
|
|
193
|
+
"0x8dcf872f3ded2b7ed1d1ee9a2b125bedc6eacd3c09b3a4a5286d8fc2fc3a6634"),
|
|
194
|
+
StaticString(
|
|
195
|
+
"0x950dd2ef7be25eab686a6688497962ee4ad521da12b9ff3d8e56ad9435885b12"),
|
|
196
|
+
StaticString(
|
|
197
|
+
"0xe14389d1d8448678cac33fdbc9aab20dba019e75149d170dd2f353891cd4b84f"),
|
|
198
|
+
StaticString(
|
|
199
|
+
"0xe84906c09cd6423865baf64e48027cc598d52bdb90b17524c87ea892e53b5200"),
|
|
200
|
+
StaticString(
|
|
201
|
+
"0x493cea587f1ec5622c04221cd6e5a41c26c1c1c24c0375f7aaa367d9678d83bc"),
|
|
202
|
+
StaticString(
|
|
203
|
+
"0x5aca0010aced30bcb3b84a7f10ea39c4269ab7c92fcb6cff52958d8921ef2cc5"),
|
|
204
|
+
StaticString(
|
|
205
|
+
"0x4498fa8340f41467c0fa813bd0ca83ef6e1c4b85c7b1168a94339fd9e8296139"),
|
|
206
|
+
StaticString(
|
|
207
|
+
"0xf9a95b738a8e775421b1baa503abbeed2d283b236ebba25e1954b3c993d30a3d"),
|
|
208
|
+
StaticString(
|
|
209
|
+
"0x98178711d03a0b1204ebb56b37bd3a2724dfb08e4dc925609391768b126d21f2"),
|
|
210
|
+
StaticString(
|
|
211
|
+
"0x79251f49534f5c4b10b798b2dbf6e80a3b07593f616ce6a9617ccc61040aac78"),
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
check_elt_output(ts, want2);
|
|
215
|
+
|
|
216
|
+
// write a field element array
|
|
217
|
+
Elt array[2] = {F.of_scalar(8), F.of_scalar(9)};
|
|
218
|
+
ts.write(array, 1, 2, F);
|
|
219
|
+
|
|
220
|
+
StaticString want3[16] = {
|
|
221
|
+
StaticString(
|
|
222
|
+
"0xae1a921288590205fc24543303ff527476359b8db4a983b2886a133b02f3217e"),
|
|
223
|
+
StaticString(
|
|
224
|
+
"0x8c5d52a04b295f9fdb45ab66100fa00ca32c9634aa87cbbdb2bc3e1912459feb"),
|
|
225
|
+
StaticString(
|
|
226
|
+
"0x12f82963b5b242156f6e9eb756eddee7652b60c7d6394403f7bd995e0b9bcd9c"),
|
|
227
|
+
StaticString(
|
|
228
|
+
"0x880aa50b049b3939055deb7933749d338bb3fb5f64a9adf95019e6cfc232995c"),
|
|
229
|
+
StaticString(
|
|
230
|
+
"0xf8558f693f0fa6df20a37147a898fb4c678831f566d80113bbe2cdcd18285da2"),
|
|
231
|
+
StaticString(
|
|
232
|
+
"0xbbcc8d9b46f88bc8c6cec0ad2d5e49508b7db91d548548eddc61800de1329e1c"),
|
|
233
|
+
StaticString(
|
|
234
|
+
"0x479a17244398caae8155a73438a22583df7de10a8a2e12ad53ddd3bc7305fac9"),
|
|
235
|
+
StaticString(
|
|
236
|
+
"0x9ba1917f1227932250288a843f64b4e7b7f47a5fbc16c111f6e1f76235ccf38c"),
|
|
237
|
+
StaticString(
|
|
238
|
+
"0xd1582138045d1636fb7f677c9e8a4a4143ce2b2bb54fb4f49fb0ad1fee5df6b4"),
|
|
239
|
+
StaticString(
|
|
240
|
+
"0x05331e5b8508f79c017a8dfbbb805f3f8c5e3e4bc417e44849b9212439646331"),
|
|
241
|
+
StaticString(
|
|
242
|
+
"0xb6b95862194ca52dcaa9ee651b7fc5b708f43feae108bb9a7f95213f4d069048"),
|
|
243
|
+
StaticString(
|
|
244
|
+
"0xe86b1602f0a54c4e237867ebaf05e7581464fd238e50f6ed9c3cea63909c8e60"),
|
|
245
|
+
StaticString(
|
|
246
|
+
"0xb7280439f3b21b113ff29cefe39292d5e2d137709c3d3cec36473a0f97a24e62"),
|
|
247
|
+
StaticString(
|
|
248
|
+
"0xbeaa5e08257d232506fb3e46c6daa29e0859c34c7d0cd673bc6706ee261ae059"),
|
|
249
|
+
StaticString(
|
|
250
|
+
"0x0691ead55728cd087a1952b22b6628ba4e26fbefc8debeec5e6fbc3a16f637be"),
|
|
251
|
+
StaticString(
|
|
252
|
+
"0x47dc31f6d8bc9c44290781176df3e4b95ac8793a4a42fa5859c564d92d6d5af5"),
|
|
253
|
+
};
|
|
254
|
+
check_elt_output(ts, want3);
|
|
255
|
+
|
|
256
|
+
ts.write((uint8_t*)"nats", 4);
|
|
257
|
+
|
|
258
|
+
size_t want_nat[] = {0, 0, 0, 0, 0, 0, 3, 0,
|
|
259
|
+
4, 5, 10, 30, 27, 22, 100, 189,
|
|
260
|
+
3, 92, 999, 3105, 40886, 51590, 56367, 10678};
|
|
261
|
+
check_nat_output(ts, want_nat);
|
|
262
|
+
|
|
263
|
+
ts.write((uint8_t*)"choose", 6);
|
|
264
|
+
|
|
265
|
+
size_t want_ch[] = {
|
|
266
|
+
/* 31 */
|
|
267
|
+
10, 29, 30, 11, 4, 15, 16, 28, 19, 21, 25, 18, 17, 3, 5, 23, 24, 22, 6, 1,
|
|
268
|
+
/* 32 */
|
|
269
|
+
3, 17, 18, 8, 30, 7, 14, 19, 25, 23, 12, 4, 31, 16, 0, 6, 20, 27, 11, 10,
|
|
270
|
+
/* 63 */
|
|
271
|
+
9, 56, 61, 45, 35, 53, 51, 3, 39, 32, 31, 6, 59, 58, 54, 22, 27, 62, 55,
|
|
272
|
+
19,
|
|
273
|
+
/* 64 */
|
|
274
|
+
12, 52, 39, 17, 51, 38, 58, 2, 28, 27, 46, 63, 61, 50, 40, 55, 47, 13, 56,
|
|
275
|
+
32,
|
|
276
|
+
/* 1000 */
|
|
277
|
+
157, 668, 572, 138, 913, 994, 797, 249, 440, 723, 489, 241, 383, 108, 710,
|
|
278
|
+
341, 406, 585, 42, 692,
|
|
279
|
+
/* 65535 */
|
|
280
|
+
40745, 48408, 17108, 44500, 53993, 10008, 24910, 52200, 61265, 54989,
|
|
281
|
+
41237, 25958, 28697, 61187, 34729, 3525, 9005, 38627, 9724, 12169};
|
|
282
|
+
check_choose_output(ts, want_ch);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
TEST(Transcript, TestVec) {
|
|
286
|
+
uint8_t key[32];
|
|
287
|
+
|
|
288
|
+
Transcript ts((uint8_t*)"test", 4);
|
|
289
|
+
uint8_t d[100];
|
|
290
|
+
for (size_t i = 0; i < 100; ++i) {
|
|
291
|
+
d[i] = static_cast<uint8_t>(i);
|
|
292
|
+
}
|
|
293
|
+
ts.write(d, 100);
|
|
294
|
+
ts.get(key);
|
|
295
|
+
|
|
296
|
+
// manually computed SHA256 of
|
|
297
|
+
// 0
|
|
298
|
+
// 4 0 0 0 0 0 0 0
|
|
299
|
+
// t e s t
|
|
300
|
+
// 0 // TAG
|
|
301
|
+
// 100 0 0 0 0 0 0 0 // LENGTH
|
|
302
|
+
// 0 1 2 ... // PAYLOAD
|
|
303
|
+
{
|
|
304
|
+
const uint8_t key1[32] = {0x60, 0xcd, 0x16, 0x34, 0x92, 0x0f, 0x1c, 0xf2,
|
|
305
|
+
0xae, 0x83, 0x15, 0x02, 0xbf, 0x4b, 0xb9, 0x3a,
|
|
306
|
+
0x60, 0xcd, 0x03, 0xee, 0xb1, 0x9f, 0x93, 0xe2,
|
|
307
|
+
0xd6, 0xd5, 0x0d, 0xbd, 0x09, 0x84, 0xcb, 0xd8};
|
|
308
|
+
for (size_t i = 0; i < 32; ++i) {
|
|
309
|
+
EXPECT_EQ(key[i], key1[i]);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
{
|
|
314
|
+
// obtain two AES blocks
|
|
315
|
+
uint8_t bytes[32];
|
|
316
|
+
ts.bytes(bytes, 32);
|
|
317
|
+
|
|
318
|
+
// manually computed AES256 of [0 0 0 0 0 0 0 0] and
|
|
319
|
+
/// [1 0 0 0 0 0 0 0] under KEY
|
|
320
|
+
const uint8_t bytes1[32] = {0x14, 0x1B, 0xBC, 0xBB, 0x54, 0x10, 0xDD, 0xEB,
|
|
321
|
+
0x70, 0x39, 0x83, 0x3B, 0x73, 0x65, 0x86, 0xA0,
|
|
322
|
+
0x20, 0xFD, 0xD5, 0x85, 0x63, 0x79, 0xB6, 0xC6,
|
|
323
|
+
0xC6, 0x83, 0xD5, 0xFF, 0x0B, 0x7F, 0x29, 0x8B};
|
|
324
|
+
for (size_t i = 0; i < 32; ++i) {
|
|
325
|
+
EXPECT_EQ(bytes[i], bytes1[i]);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// append another zero
|
|
330
|
+
ts.write(d, 1);
|
|
331
|
+
ts.get(key);
|
|
332
|
+
|
|
333
|
+
{
|
|
334
|
+
const uint8_t key1[32] = {0x18, 0x19, 0x78, 0x38, 0x0b, 0x6f, 0xf3, 0x21,
|
|
335
|
+
0x85, 0xc8, 0x28, 0xd9, 0xa0, 0x07, 0xee, 0x93,
|
|
336
|
+
0x0b, 0xce, 0x2e, 0x94, 0x7f, 0x88, 0x7f, 0x85,
|
|
337
|
+
0xb6, 0x4f, 0x39, 0x9a, 0x94, 0xcb, 0xe4, 0xa8};
|
|
338
|
+
for (size_t i = 0; i < 32; ++i) {
|
|
339
|
+
EXPECT_EQ(key[i], key1[i]);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
} // namespace
|
|
344
|
+
} // namespace proofs
|
|
@@ -0,0 +1,148 @@
|
|
|
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_CIRCUIT_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_CIRCUIT_H_
|
|
17
|
+
|
|
18
|
+
#include <stddef.h>
|
|
19
|
+
|
|
20
|
+
#include <cstdint>
|
|
21
|
+
#include <memory>
|
|
22
|
+
#include <vector>
|
|
23
|
+
|
|
24
|
+
#include "algebra/poly.h"
|
|
25
|
+
#include "arrays/affine.h"
|
|
26
|
+
#include "sumcheck/quad.h"
|
|
27
|
+
|
|
28
|
+
namespace proofs {
|
|
29
|
+
template <class Field>
|
|
30
|
+
struct Layer {
|
|
31
|
+
corner_t nw; // number of inputs
|
|
32
|
+
size_t logw; // number of binding rounds for the hand variables
|
|
33
|
+
std::unique_ptr<const Quad<Field>> quad;
|
|
34
|
+
|
|
35
|
+
size_t nterms() const { return quad->size(); }
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
template <class Field>
|
|
39
|
+
struct Circuit {
|
|
40
|
+
corner_t nv; // number of outputs for one copy
|
|
41
|
+
size_t logv; // number of G variables in V[G,C] in the final output
|
|
42
|
+
corner_t nc; // number of copies
|
|
43
|
+
size_t logc; // number of sumcheck rounds for the C variables
|
|
44
|
+
size_t nl; // number of layers
|
|
45
|
+
|
|
46
|
+
size_t ninputs; // number of inputs
|
|
47
|
+
size_t npub_in; // number of public inputs, index of first private input
|
|
48
|
+
size_t subfield_boundary; // Least input wire not known to be in the
|
|
49
|
+
// subfield
|
|
50
|
+
|
|
51
|
+
std::vector<Layer<Field>> l; // layers
|
|
52
|
+
|
|
53
|
+
uint8_t id[32]; // unique id for the circuit, created by the compiler
|
|
54
|
+
|
|
55
|
+
size_t nterms() const {
|
|
56
|
+
size_t n = 0;
|
|
57
|
+
for (const auto& layer : l) {
|
|
58
|
+
n += layer.nterms();
|
|
59
|
+
}
|
|
60
|
+
return n;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
template <class Field>
|
|
65
|
+
struct LayerProof {
|
|
66
|
+
using Elt = typename Field::Elt;
|
|
67
|
+
// For efficiency, we distinguish polynomials needed to bind copy
|
|
68
|
+
// variables (CPoly, degree 3) from polynomials needed to bind
|
|
69
|
+
// wire variables (WPoly, degree 2).
|
|
70
|
+
using CPoly = SumcheckPoly<4, Field>;
|
|
71
|
+
using WPoly = SumcheckPoly<3, Field>;
|
|
72
|
+
using FWPoly = Poly<3, Field>;
|
|
73
|
+
using FCPoly = Poly<4, Field>;
|
|
74
|
+
|
|
75
|
+
// Maximum 2^40 gates/wires/copies per layer.
|
|
76
|
+
static constexpr size_t kMaxBindings = 40;
|
|
77
|
+
|
|
78
|
+
CPoly cp[kMaxBindings]; // polys for the C variables
|
|
79
|
+
|
|
80
|
+
// The binding order we use is "for (round) { for (hand) ... }", and
|
|
81
|
+
// thus one can organize this array as [kMaxBindings][2] for better
|
|
82
|
+
// memory locality.
|
|
83
|
+
// However, the corresponding challenges are organized as [2][kMaxBindings]
|
|
84
|
+
// to allow easier binding by hand, and so it makes sense to keep this
|
|
85
|
+
// array in the same order as the challenges.
|
|
86
|
+
WPoly hp[2][kMaxBindings]; // polys for each hand \in {right,left}
|
|
87
|
+
|
|
88
|
+
// prover provides W[R,C] and W[L,C], which serve as claims
|
|
89
|
+
// for the next layer
|
|
90
|
+
Elt wc[2];
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
template <class Field>
|
|
94
|
+
struct LayerChallenge {
|
|
95
|
+
using Elt = typename Field::Elt;
|
|
96
|
+
static constexpr size_t kMaxBindings = LayerProof<Field>::kMaxBindings;
|
|
97
|
+
|
|
98
|
+
// verifier: coefficient for the random linear combination
|
|
99
|
+
// claim[0] + alpha * claim[1] of the two input claims.
|
|
100
|
+
Elt alpha;
|
|
101
|
+
Elt beta; // random coefficient for assert-zero
|
|
102
|
+
Elt cb[kMaxBindings]; // bindings for the C variables
|
|
103
|
+
Elt hb[2][kMaxBindings]; // bindings for each hand
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
template <class Field>
|
|
107
|
+
struct Challenge {
|
|
108
|
+
using Elt = typename Field::Elt;
|
|
109
|
+
static constexpr size_t kMaxBindings = LayerProof<Field>::kMaxBindings;
|
|
110
|
+
|
|
111
|
+
// verifier picks Q for EQ[Q|c]
|
|
112
|
+
Elt q[kMaxBindings]; // [logC]
|
|
113
|
+
|
|
114
|
+
// verifier picks G for V[G,c]
|
|
115
|
+
Elt g[kMaxBindings]; // [logV]
|
|
116
|
+
std::vector<LayerChallenge<Field>> l;
|
|
117
|
+
explicit Challenge(size_t nl) : l(nl) {}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// Full proof:
|
|
121
|
+
template <class Field>
|
|
122
|
+
struct Proof {
|
|
123
|
+
typedef typename LayerProof<Field>::CPoly CPoly;
|
|
124
|
+
typedef typename LayerProof<Field>::WPoly WPoly;
|
|
125
|
+
|
|
126
|
+
using Elt = typename Field::Elt;
|
|
127
|
+
static constexpr size_t kMaxBindings = LayerProof<Field>::kMaxBindings;
|
|
128
|
+
|
|
129
|
+
// then engage in sumcheck one per layer
|
|
130
|
+
std::vector<LayerProof<Field>> l;
|
|
131
|
+
|
|
132
|
+
explicit Proof(size_t nl) : l(nl) {}
|
|
133
|
+
size_t size() const {
|
|
134
|
+
return l.size() * (kMaxBindings * 4 + kMaxBindings * 3 * 2 + 2);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// Auxiliary information generated by the prover to be
|
|
139
|
+
// used by the ZK prover
|
|
140
|
+
template <class Field>
|
|
141
|
+
struct ProofAux {
|
|
142
|
+
using Elt = typename Field::Elt;
|
|
143
|
+
std::vector<Elt> bound_quad;
|
|
144
|
+
explicit ProofAux(size_t nl) : bound_quad(nl) {}
|
|
145
|
+
};
|
|
146
|
+
} // namespace proofs
|
|
147
|
+
|
|
148
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_CIRCUIT_H_
|