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,445 @@
|
|
|
1
|
+
// Copyright 2026 Google LLC.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_ROUTING_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_ROUTING_H_
|
|
17
|
+
|
|
18
|
+
#include <stddef.h>
|
|
19
|
+
|
|
20
|
+
#include <algorithm>
|
|
21
|
+
#include <vector>
|
|
22
|
+
|
|
23
|
+
#include "util/ceildiv.h"
|
|
24
|
+
#include "util/panic.h"
|
|
25
|
+
|
|
26
|
+
namespace proofs {
|
|
27
|
+
/*
|
|
28
|
+
The Routing class implements circuits that shift an array by a variable number
|
|
29
|
+
of positions. The following table can help pick parameters for a shift:
|
|
30
|
+
|
|
31
|
+
shift_bit[2][2][1] depth: 2 wires: 6 in: 4 out:2 use:6 ovh:0 t:5 cse:0
|
|
32
|
+
notn:7
|
|
33
|
+
|
|
34
|
+
unshift_bit[2][2][1] depth: 2 wires: 6 in: 4 out:2 use:6 ovh:0 t:5
|
|
35
|
+
cse:0 notn:7
|
|
36
|
+
|
|
37
|
+
shift_bit[4][4][1] depth: 3 wires: 17 in: 7 out:4 use:15 ovh:2 t:23
|
|
38
|
+
cse:0 notn:27
|
|
39
|
+
|
|
40
|
+
unshift_bit[4][4][1] depth: 3 wires: 17 in: 7 out:4 use:15 ovh:2 t:23
|
|
41
|
+
cse:0 notn:27
|
|
42
|
+
|
|
43
|
+
shift_bit[4][4][2] depth: 3 wires: 19 in: 7 out:4 use:15 ovh:4 t:23
|
|
44
|
+
cse:2 notn:20
|
|
45
|
+
|
|
46
|
+
unshift_bit[4][4][2] depth: 3 wires: 19 in: 7 out:4 use:15 ovh:4 t:23
|
|
47
|
+
cse:2 notn:20
|
|
48
|
+
|
|
49
|
+
shift_bit[8][8][1] depth: 4 wires: 41 in: 12 out:8 use:36 ovh:5 t:70
|
|
50
|
+
cse:0 notn:83
|
|
51
|
+
|
|
52
|
+
unshift_bit[8][8][1] depth: 4 wires: 41 in: 12 out:8 use:36 ovh:5 t:70
|
|
53
|
+
cse:0 notn:83
|
|
54
|
+
|
|
55
|
+
shift_bit[8][8][2] depth: 4 wires: 44 in: 12 out:8 use:32 ovh:12 t:64
|
|
56
|
+
cse:2 notn:62
|
|
57
|
+
|
|
58
|
+
unshift_bit[8][8][2] depth: 4 wires: 44 in: 12 out:8 use:32 ovh:12
|
|
59
|
+
t:67 cse:2 notn:68
|
|
60
|
+
|
|
61
|
+
shift_bit[16][16][1] depth: 5 wires: 94 in: 21 out:16 use:85 ovh:9
|
|
62
|
+
t:186 cse:0 notn:227
|
|
63
|
+
|
|
64
|
+
unshift_bit[16][16][1] depth: 5 wires: 94 in: 21 out:16 use:85 ovh:9
|
|
65
|
+
t:186 cse:0 notn:227
|
|
66
|
+
|
|
67
|
+
shift_bit[16][16][2] depth: 4 wires: 82 in: 21 out:16 use:61 ovh:21
|
|
68
|
+
t:137 cse:4 notn:147
|
|
69
|
+
|
|
70
|
+
unshift_bit[16][16][2] depth: 4 wires: 82 in: 21 out:16 use:61 ovh:21
|
|
71
|
+
t:137 cse:4 notn:147
|
|
72
|
+
|
|
73
|
+
shift_bit[16][16][4] depth: 4 wires: 94 in: 21 out:16 use:61 ovh:33
|
|
74
|
+
t:203 cse:58 notn:255
|
|
75
|
+
|
|
76
|
+
unshift_bit[16][16][4] depth: 4 wires: 94 in: 21 out:16 use:61 ovh:33
|
|
77
|
+
t:203 cse:58 notn:255
|
|
78
|
+
|
|
79
|
+
shift_bit[32][32][1] depth: 6 wires: 212 in: 38 out:32 use:198 ovh:14
|
|
80
|
+
t:463 cse:0 notn:579
|
|
81
|
+
|
|
82
|
+
unshift_bit[32][32][1] depth: 6 wires: 212 in: 38 out:32 use:198
|
|
83
|
+
ovh:14 t:463 cse:0 notn:579
|
|
84
|
+
|
|
85
|
+
shift_bit[32][32][2] depth: 5 wires: 184 in: 38 out:32 use:142 ovh:42
|
|
86
|
+
t:351 cse:4 notn:405
|
|
87
|
+
|
|
88
|
+
unshift_bit[32][32][2] depth: 5 wires: 184 in: 38 out:32 use:142
|
|
89
|
+
ovh:42 t:366 cse:4 notn:435
|
|
90
|
+
|
|
91
|
+
shift_bit[32][32][4] depth: 5 wires: 193 in: 38 out:32 use:118 ovh:75
|
|
92
|
+
t:371 cse:13 notn:427
|
|
93
|
+
|
|
94
|
+
unshift_bit[32][32][4] depth: 5 wires: 193 in: 38 out:32 use:118
|
|
95
|
+
ovh:75 t:413 cse:13 notn:511
|
|
96
|
+
|
|
97
|
+
shift_bit[64][64][1] depth: 7 wires: 475 in: 71 out:64 use:455 ovh:20
|
|
98
|
+
t:1109 cse:0 notn:1411
|
|
99
|
+
|
|
100
|
+
unshift_bit[64][64][1] depth: 7 wires: 475 in: 71 out:64 use:455
|
|
101
|
+
ovh:20 t:1109 cse:0 notn:1411
|
|
102
|
+
|
|
103
|
+
shift_bit[64][64][2] depth: 5 wires: 353 in: 71 out:64 use:275 ovh:78
|
|
104
|
+
t:747 cse:6 notn:922
|
|
105
|
+
|
|
106
|
+
unshift_bit[64][64][2] depth: 5 wires: 353 in: 71 out:64 use:275
|
|
107
|
+
ovh:78 t:747 cse:6 notn:922
|
|
108
|
+
|
|
109
|
+
shift_bit[64][64][4] depth: 5 wires: 363 in: 71 out:64 use:223 ovh:140
|
|
110
|
+
t:954 cse:22 notn:1319
|
|
111
|
+
|
|
112
|
+
unshift_bit[64][64][4] depth: 5 wires: 363 in: 71 out:64 use:223
|
|
113
|
+
ovh:140 t:954 cse:22 notn:1319
|
|
114
|
+
|
|
115
|
+
shift_bit[128][128][1] depth: 8 wires: 1059 in: 136 out:128 use:1032
|
|
116
|
+
ovh:27 t:2588 cse:0 notn:3331
|
|
117
|
+
|
|
118
|
+
unshift_bit[128][128][1] depth: 8 wires: 1059 in: 136 out:128 use:1032
|
|
119
|
+
ovh:27 t:2588 cse:0 notn:3331
|
|
120
|
+
|
|
121
|
+
shift_bit[128][128][2] depth: 6 wires: 808 in: 136 out:128 use:660
|
|
122
|
+
ovh:148 t:1842 cse:6 notn:2332
|
|
123
|
+
|
|
124
|
+
unshift_bit[128][128][2] depth: 6 wires: 808 in: 136 out:128 use:660
|
|
125
|
+
ovh:148 t:1905 cse:6 notn:2458
|
|
126
|
+
|
|
127
|
+
shift_bit[128][128][4] depth: 5 wires: 695 in: 136 out:128 use:428
|
|
128
|
+
ovh:267 t:2406 cse:69 notn:3686
|
|
129
|
+
|
|
130
|
+
unshift_bit[128][128][4] depth: 5 wires: 695 in: 136 out:128 use:428
|
|
131
|
+
ovh:267 t:2826 cse:69 notn:4526
|
|
132
|
+
|
|
133
|
+
shift_bit[256][256][1] depth: 9 wires: 2348 in: 265 out:256 use:2313
|
|
134
|
+
ovh:35 t:5924 cse:0 notn:7683
|
|
135
|
+
|
|
136
|
+
unshift_bit[256][256][1] depth: 9 wires: 2348 in: 265 out:256 use:2313
|
|
137
|
+
ovh:35 t:5924 cse:0 notn:7683
|
|
138
|
+
|
|
139
|
+
shift_bit[256][256][2] depth: 6 wires: 1588 in: 265 out:256 use:1305
|
|
140
|
+
ovh:283 t:3905 cse:8 notn:5153
|
|
141
|
+
|
|
142
|
+
unshift_bit[256][256][2] depth: 6 wires: 1588 in: 265 out:256 use:1305
|
|
143
|
+
ovh:283 t:3905 cse:8 notn:5153
|
|
144
|
+
|
|
145
|
+
shift_bit[256][256][4] depth: 5 wires: 1355 in: 265 out:256 use:825
|
|
146
|
+
ovh:530 t:6750 cse:116 notn:11309
|
|
147
|
+
|
|
148
|
+
unshift_bit[256][256][4] depth: 5 wires: 1355 in: 265 out:256 use:825
|
|
149
|
+
ovh:530 t:6750 cse:116 notn:11309
|
|
150
|
+
|
|
151
|
+
shift_bit[256][256][8] depth: 5 wires: 1595 in: 265 out:256 use:825
|
|
152
|
+
ovh:770 t:33990 cse:2756 notn:65309
|
|
153
|
+
|
|
154
|
+
unshift_bit[256][256][8] depth: 5 wires: 1595 in: 265 out:256 use:825
|
|
155
|
+
ovh:770 t:33990 cse:2756 notn:65309
|
|
156
|
+
|
|
157
|
+
shift_bit[512][512][1] depth: 10 wires: 5174 in: 522 out:512 use:5130
|
|
158
|
+
ovh:44 t:13357 cse:0 notn:17411
|
|
159
|
+
|
|
160
|
+
unshift_bit[512][512][1] depth: 10 wires: 5174 in: 522 out:512
|
|
161
|
+
use:5130 ovh:44 t:13357 cse:0 notn:17411
|
|
162
|
+
|
|
163
|
+
shift_bit[512][512][2] depth: 7 wires: 3644 in: 522 out:512 use:3098
|
|
164
|
+
ovh:546 t:9289 cse:8 notn:12323
|
|
165
|
+
|
|
166
|
+
unshift_bit[512][512][2] depth: 7 wires: 3644 in: 522 out:512 use:3098
|
|
167
|
+
ovh:546 t:9544 cse:8 notn:12833
|
|
168
|
+
|
|
169
|
+
shift_bit[512][512][4] depth: 6 wires: 3148 in: 522 out:512 use:2094
|
|
170
|
+
ovh:1054 t:11361 cse:33 notn:17462
|
|
171
|
+
|
|
172
|
+
unshift_bit[512][512][4] depth: 6 wires: 3148 in: 522 out:512 use:2094
|
|
173
|
+
ovh:1054 t:11361 cse:33 notn:17462
|
|
174
|
+
|
|
175
|
+
shift_bit[512][512][8] depth: 6 wires: 3194 in: 522 out:512 use:1618
|
|
176
|
+
ovh:1576 t:18192 cse:224 notn:31029
|
|
177
|
+
|
|
178
|
+
unshift_bit[512][512][8] depth: 6 wires: 3194 in: 522 out:512 use:1618
|
|
179
|
+
ovh:1576 t:21912 cse:224 notn:38469
|
|
180
|
+
|
|
181
|
+
shift_bit[1024][1024][1] depth: 11 wires: 11329 in: 1035 out:1024
|
|
182
|
+
use:11275 ovh:54 t:29751 cse:0 notn:38915
|
|
183
|
+
|
|
184
|
+
unshift_bit[1024][1024][1] depth: 11 wires: 11329 in: 1035 out:1024
|
|
185
|
+
use:11275 ovh:54 t:29751 cse:0 notn:38915
|
|
186
|
+
|
|
187
|
+
shift_bit[1024][1024][2] depth: 7 wires: 7243 in: 1035 out:1024
|
|
188
|
+
use:6175 ovh:1068 t:19547 cse:10 notn:26664
|
|
189
|
+
|
|
190
|
+
unshift_bit[1024][1024][2] depth: 7 wires: 7243 in: 1035 out:1024
|
|
191
|
+
use:6175 ovh:1068 t:19547 cse:10 notn:26664
|
|
192
|
+
|
|
193
|
+
shift_bit[1024][1024][4] depth: 6 wires: 6232 in: 1035 out:1024
|
|
194
|
+
use:4155 ovh:2077 t:26989 cse:80 notn:43573
|
|
195
|
+
|
|
196
|
+
unshift_bit[1024][1024][4] depth: 6 wires: 6232 in: 1035 out:1024
|
|
197
|
+
use:4155 ovh:2077 t:30769 cse:80 notn:51133
|
|
198
|
+
|
|
199
|
+
shift_bit[1024][1024][8] depth: 6 wires: 6296 in: 1035 out:1024
|
|
200
|
+
use:3179 ovh:3117 t:52409 cse:332 notn:94285
|
|
201
|
+
|
|
202
|
+
unshift_bit[1024][1024][8] depth: 6 wires: 6296 in: 1035 out:1024
|
|
203
|
+
use:3179 ovh:3117 t:52409 cse:332 notn:94285
|
|
204
|
+
*/
|
|
205
|
+
template <class Logic>
|
|
206
|
+
class Routing {
|
|
207
|
+
public:
|
|
208
|
+
typedef typename Logic::BitW bitW;
|
|
209
|
+
typedef typename Logic::EltW EltW;
|
|
210
|
+
const Logic& l_;
|
|
211
|
+
|
|
212
|
+
explicit Routing(const Logic& l) : l_(l) {}
|
|
213
|
+
|
|
214
|
+
// Set B[i] = A[i + amount], for 0 <= i < k. Note that A and B
|
|
215
|
+
// are in general of different size.
|
|
216
|
+
template <class T>
|
|
217
|
+
void shift(size_t logn, const bitW amount[/*logn*/], size_t k, T B[/*k*/],
|
|
218
|
+
size_t n, const T A[/*n*/], const T& defaultA,
|
|
219
|
+
size_t unroll) const {
|
|
220
|
+
std::vector<T> tmp(n);
|
|
221
|
+
for (size_t i = 0; i < n; ++i) {
|
|
222
|
+
tmp[i] = A[i];
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Now shift TMP in-place.
|
|
226
|
+
|
|
227
|
+
// Counting backwards from logn produces a smaller circuit if one
|
|
228
|
+
// only cares about a contiguous subset of outputs. E.g. if one
|
|
229
|
+
// wants the first k outputs the number of wires is O(n log k).
|
|
230
|
+
size_t l = logn;
|
|
231
|
+
|
|
232
|
+
// This funny logic in terms of (target_nrounds, consumed)
|
|
233
|
+
// attempts to equalize the number of bits consumed per round.
|
|
234
|
+
// E.g., if logn = 11 and unroll = 7, a naive consumed = unroll
|
|
235
|
+
// would yield 11 = 7 + 4. Instead, we set target_nrounds = 2,
|
|
236
|
+
// and consumed is 6 in the first round and 5 in the second round.
|
|
237
|
+
size_t target_nrounds = ceildiv(logn, unroll);
|
|
238
|
+
|
|
239
|
+
while (target_nrounds > 0) {
|
|
240
|
+
size_t consumed = ceildiv(l, target_nrounds);
|
|
241
|
+
--target_nrounds;
|
|
242
|
+
|
|
243
|
+
l -= consumed;
|
|
244
|
+
size_t shift = size_t(1) << l;
|
|
245
|
+
shift_step(consumed, &amount[l], n, k, tmp.data(), shift, defaultA);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
check(l == 0, "l==0");
|
|
249
|
+
|
|
250
|
+
for (size_t i = 0; i < k; ++i) {
|
|
251
|
+
if (i < n) {
|
|
252
|
+
B[i] = tmp[i];
|
|
253
|
+
} else {
|
|
254
|
+
B[i] = defaultA;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Set A[i + amount] = B[i], for 0 <= i < k. Note that A and B
|
|
260
|
+
// are in general of different size.
|
|
261
|
+
template <class T>
|
|
262
|
+
void unshift(size_t logn, const bitW amount[/*logn*/], size_t n, T A[/*n*/],
|
|
263
|
+
size_t k, const T B[/*k*/], const T& defaultB,
|
|
264
|
+
size_t unroll) const {
|
|
265
|
+
// we don't need TMP since we can operate on A directly
|
|
266
|
+
for (size_t i = 0; i < n; ++i) {
|
|
267
|
+
if (i < k) {
|
|
268
|
+
A[i] = B[i];
|
|
269
|
+
} else {
|
|
270
|
+
A[i] = defaultB;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
size_t l = 0;
|
|
275
|
+
size_t target_nrounds = ceildiv(logn, unroll);
|
|
276
|
+
while (target_nrounds > 0) {
|
|
277
|
+
size_t consumed = ceildiv((logn - l), target_nrounds);
|
|
278
|
+
--target_nrounds;
|
|
279
|
+
|
|
280
|
+
size_t shift = size_t(1) << l;
|
|
281
|
+
unshift_step(consumed, &amount[l], n, k, A, shift, defaultB);
|
|
282
|
+
|
|
283
|
+
l += consumed;
|
|
284
|
+
}
|
|
285
|
+
proofs::check(l == logn, "l==logn");
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
template <class T, size_t LOGN>
|
|
289
|
+
void shift(const typename Logic::template bitvec<LOGN>& amount, size_t k,
|
|
290
|
+
T B[/*k*/], size_t n, const T A[/*n*/], const T& defaultA,
|
|
291
|
+
size_t unroll) const {
|
|
292
|
+
shift(LOGN, &amount[0], k, B, n, A, defaultA, unroll);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
template <class T, size_t LOGN>
|
|
296
|
+
void unshift(const typename Logic::template bitvec<LOGN>& amount, size_t n,
|
|
297
|
+
T A[/*n*/], size_t k, const T B[/*k*/], const T& defaultB,
|
|
298
|
+
size_t unroll) const {
|
|
299
|
+
unshift(LOGN, &amount[0], n, A, k, B, defaultB, unroll);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
private:
|
|
303
|
+
template <class T>
|
|
304
|
+
void shift_step(size_t logc, const bitW amount[/*logc*/], size_t n, size_t k,
|
|
305
|
+
T tmp[/*n*/], size_t shift, const T& defaultA) const {
|
|
306
|
+
const Logic& L = l_; // shorthand
|
|
307
|
+
size_t c = size_t(1) << logc;
|
|
308
|
+
|
|
309
|
+
// cache the common subexpression amount_is[i]
|
|
310
|
+
std::vector<bitW> amount_is(c);
|
|
311
|
+
std::vector<bitW> ibits(logc);
|
|
312
|
+
for (size_t i = 0; i < c; ++i) {
|
|
313
|
+
L.bits(logc, ibits.data(), i);
|
|
314
|
+
amount_is[i] = L.eq(logc, ibits.data(), amount);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
really_shift(c, amount_is.data(), n, k, tmp, shift, defaultA);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
template <class T>
|
|
321
|
+
void unshift_step(size_t logc, const bitW amount[/*logc*/], size_t n,
|
|
322
|
+
size_t k, T A[/*n*/], size_t shift,
|
|
323
|
+
const T& defaultB) const {
|
|
324
|
+
const Logic& L = l_; // shorthand
|
|
325
|
+
size_t c = size_t(1) << logc;
|
|
326
|
+
|
|
327
|
+
// cache the common subexpression amount_is[i]
|
|
328
|
+
std::vector<bitW> amount_is(c);
|
|
329
|
+
std::vector<bitW> ibits(logc);
|
|
330
|
+
for (size_t i = 0; i < c; ++i) {
|
|
331
|
+
L.bits(logc, ibits.data(), i);
|
|
332
|
+
amount_is[i] = L.eq(logc, ibits.data(), amount);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
really_unshift(c, amount_is.data(), n, k, A, shift, defaultB);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
void really_shift(size_t c, const bitW amount_is[/*c*/], size_t n, size_t k,
|
|
339
|
+
EltW tmp[/*n*/], size_t shift, const EltW& defaultA) const {
|
|
340
|
+
const Logic& L = l_; // shorthand
|
|
341
|
+
for (size_t i = 0; i < n && i < k + shift; ++i) {
|
|
342
|
+
auto f = [&](size_t j) {
|
|
343
|
+
if (i + j * shift < n) {
|
|
344
|
+
return L.lmul(amount_is[j], tmp[i + j * shift]);
|
|
345
|
+
} else {
|
|
346
|
+
return L.lmul(amount_is[j], defaultA);
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
tmp[i] = L.add(0, c, f);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
void really_unshift(size_t c, const bitW amount_is[/*c*/], size_t n, size_t k,
|
|
355
|
+
EltW A[/*n*/], size_t shift, const EltW& defaultB) const {
|
|
356
|
+
const Logic& L = l_; // shorthand
|
|
357
|
+
for (size_t i = std::min(n, k + c * shift); i-- > 0;) {
|
|
358
|
+
auto f = [&](size_t j) {
|
|
359
|
+
if (i >= j * shift) {
|
|
360
|
+
return L.lmul(amount_is[j], A[i - j * shift]);
|
|
361
|
+
} else {
|
|
362
|
+
return L.lmul(amount_is[j], defaultB);
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
A[i] = L.add(0, c, f);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
void really_shift(size_t c, const bitW amount_is[/*c*/], size_t n, size_t k,
|
|
371
|
+
bitW tmp[/*n*/], size_t shift, const bitW& defaultA) const {
|
|
372
|
+
const Logic& L = l_; // shorthand
|
|
373
|
+
for (size_t i = 0; i < n && i < k + shift; ++i) {
|
|
374
|
+
bitW r = L.bit(0);
|
|
375
|
+
for (size_t j = 0; j < c; ++j) {
|
|
376
|
+
if (i + j * shift < n) {
|
|
377
|
+
r = L.lor_exclusive(r, L.land(amount_is[j], tmp[i + j * shift]));
|
|
378
|
+
} else {
|
|
379
|
+
r = L.lor_exclusive(r, L.land(amount_is[j], defaultA));
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
tmp[i] = r;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
void really_unshift(size_t c, const bitW amount_is[/*c*/], size_t n, size_t k,
|
|
387
|
+
bitW A[/*n*/], size_t shift, const bitW& defaultB) const {
|
|
388
|
+
const Logic& L = l_; // shorthand
|
|
389
|
+
for (size_t i = std::min(n, k + c * shift); i-- > 0;) {
|
|
390
|
+
bitW r = L.bit(0);
|
|
391
|
+
for (size_t j = 0; j < c; ++j) {
|
|
392
|
+
if (i >= j * shift) {
|
|
393
|
+
r = L.lor_exclusive(r, L.land(amount_is[j], A[i - j * shift]));
|
|
394
|
+
} else {
|
|
395
|
+
r = L.lor_exclusive(r, L.land(amount_is[j], defaultB));
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
A[i] = r;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
template <size_t W>
|
|
403
|
+
void really_shift(size_t c, const bitW amount_is[/*c*/], size_t n, size_t k,
|
|
404
|
+
typename Logic::template bitvec<W> tmp[/*n*/], size_t shift,
|
|
405
|
+
const typename Logic::template bitvec<W>& defaultA) const {
|
|
406
|
+
const Logic& L = l_; // shorthand
|
|
407
|
+
for (size_t i = 0; i < n && i < k + shift; ++i) {
|
|
408
|
+
for (size_t w = 0; w < W; ++w) {
|
|
409
|
+
bitW r = L.bit(0);
|
|
410
|
+
for (size_t j = 0; j < c; ++j) {
|
|
411
|
+
if (i + j * shift < n) {
|
|
412
|
+
r = L.lor_exclusive(r, L.land(amount_is[j], tmp[i + j * shift][w]));
|
|
413
|
+
} else {
|
|
414
|
+
r = L.lor_exclusive(r, L.land(amount_is[j], defaultA[w]));
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
tmp[i][w] = r;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
template <size_t W>
|
|
423
|
+
void really_unshift(
|
|
424
|
+
size_t c, const bitW amount_is[/*c*/], size_t n, size_t k,
|
|
425
|
+
typename Logic::template bitvec<W> A[/*n*/], size_t shift,
|
|
426
|
+
const typename Logic::template bitvec<W>& defaultB) const {
|
|
427
|
+
const Logic& L = l_; // shorthand
|
|
428
|
+
for (size_t i = std::min(n, k + c * shift); i-- > 0;) {
|
|
429
|
+
for (size_t w = 0; w < W; ++w) {
|
|
430
|
+
bitW r = L.bit(0);
|
|
431
|
+
for (size_t j = 0; j < c; ++j) {
|
|
432
|
+
if (i >= j * shift) {
|
|
433
|
+
r = L.lor_exclusive(r, L.land(amount_is[j], A[i - j * shift][w]));
|
|
434
|
+
} else {
|
|
435
|
+
r = L.lor_exclusive(r, L.land(amount_is[j], defaultB[w]));
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
A[i][w] = r;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
} // namespace proofs
|
|
444
|
+
|
|
445
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_ROUTING_H_
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
// Copyright 2026 Google LLC.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
#include "circuits/logic/routing.h"
|
|
16
|
+
|
|
17
|
+
#include <stddef.h>
|
|
18
|
+
|
|
19
|
+
#include <vector>
|
|
20
|
+
|
|
21
|
+
#include "algebra/fp.h"
|
|
22
|
+
#include "circuits/compiler/circuit_dump.h"
|
|
23
|
+
#include "circuits/compiler/compiler.h"
|
|
24
|
+
#include "circuits/logic/compiler_backend.h"
|
|
25
|
+
#include "circuits/logic/evaluation_backend.h"
|
|
26
|
+
#include "circuits/logic/logic.h"
|
|
27
|
+
#include "util/log.h"
|
|
28
|
+
#include "gtest/gtest.h"
|
|
29
|
+
|
|
30
|
+
namespace proofs {
|
|
31
|
+
namespace {
|
|
32
|
+
|
|
33
|
+
using Field = Fp<1>;
|
|
34
|
+
using CompilerBackend = CompilerBackend<Field>;
|
|
35
|
+
using LogicCircuit = Logic<Field, CompilerBackend>;
|
|
36
|
+
using BitWC = LogicCircuit::BitW;
|
|
37
|
+
using EltWC = LogicCircuit::EltW;
|
|
38
|
+
|
|
39
|
+
using EvaluationBackend = EvaluationBackend<Field>;
|
|
40
|
+
using Logic = Logic<Field, EvaluationBackend>;
|
|
41
|
+
using BitW = Logic::BitW;
|
|
42
|
+
using EltW = Logic::EltW;
|
|
43
|
+
|
|
44
|
+
template <size_t N>
|
|
45
|
+
void expect_vequal(const Logic& L, const Logic::bitvec<N>& a,
|
|
46
|
+
const Logic::bitvec<N>& b) {
|
|
47
|
+
for (size_t i = 0; i < N; ++i) {
|
|
48
|
+
EXPECT_EQ(L.eval(a[i]), L.eval(b[i]));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static void one_test(size_t logn, size_t n, size_t k, size_t shift,
|
|
53
|
+
size_t unroll, bool unshift, const Logic& L) {
|
|
54
|
+
const Routing<Logic> R(L);
|
|
55
|
+
constexpr size_t W = 3;
|
|
56
|
+
typedef Logic::bitvec<W> bv;
|
|
57
|
+
|
|
58
|
+
// "randomize" the default
|
|
59
|
+
BitW ldefault = L.bit((logn ^ n ^ k ^ shift ^ unroll) & 1);
|
|
60
|
+
EltW bdefault = L.konst(12345678);
|
|
61
|
+
bv bvdefault = L.vbit<W>(12345678);
|
|
62
|
+
|
|
63
|
+
std::vector<BitW> lA(n);
|
|
64
|
+
std::vector<EltW> bA(n);
|
|
65
|
+
std::vector<bv> bvA(n);
|
|
66
|
+
for (size_t i = 0; i < n; ++i) {
|
|
67
|
+
// random-ish bit
|
|
68
|
+
lA[i] = L.bit((i ^ (i >> 2) ^ (i >> 5)) & 1);
|
|
69
|
+
bA[i] = L.konst(i + 42);
|
|
70
|
+
bvA[i] = L.vbit<W>(i + 42);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
std::vector<BitW> lwant(k), lgot(k);
|
|
74
|
+
std::vector<EltW> bwant(k), bgot(k);
|
|
75
|
+
std::vector<bv> bvwant(k), bvgot(k);
|
|
76
|
+
|
|
77
|
+
// The circuit takes logn bits of shift amount, so it
|
|
78
|
+
// shifts by (SHIFT mod 2**LOGN)
|
|
79
|
+
size_t real_shift = shift % (1 << logn);
|
|
80
|
+
if (unshift) {
|
|
81
|
+
for (size_t i = 0; i < k; ++i) {
|
|
82
|
+
if (i >= real_shift && i < n + real_shift) {
|
|
83
|
+
lwant[i] = lA[i - real_shift];
|
|
84
|
+
bwant[i] = bA[i - real_shift];
|
|
85
|
+
bvwant[i] = bvA[i - real_shift];
|
|
86
|
+
} else {
|
|
87
|
+
lwant[i] = ldefault;
|
|
88
|
+
bwant[i] = bdefault;
|
|
89
|
+
bvwant[i] = bvdefault;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
for (size_t i = 0; i < k; ++i) {
|
|
94
|
+
if (i + real_shift < n) {
|
|
95
|
+
lwant[i] = lA[i + real_shift];
|
|
96
|
+
bwant[i] = bA[i + real_shift];
|
|
97
|
+
bvwant[i] = bvA[i + real_shift];
|
|
98
|
+
} else {
|
|
99
|
+
lwant[i] = ldefault;
|
|
100
|
+
bwant[i] = bdefault;
|
|
101
|
+
bvwant[i] = bvdefault;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
std::vector<BitW> shiftbits(logn);
|
|
107
|
+
L.bits(logn, shiftbits.data(), shift);
|
|
108
|
+
|
|
109
|
+
if (unshift) {
|
|
110
|
+
R.unshift(logn, shiftbits.data(), k, lgot.data(), n, lA.data(), ldefault,
|
|
111
|
+
unroll);
|
|
112
|
+
R.unshift(logn, shiftbits.data(), k, bgot.data(), n, bA.data(), bdefault,
|
|
113
|
+
unroll);
|
|
114
|
+
R.unshift(logn, shiftbits.data(), k, bvgot.data(), n, bvA.data(), bvdefault,
|
|
115
|
+
unroll);
|
|
116
|
+
} else {
|
|
117
|
+
R.shift(logn, shiftbits.data(), k, lgot.data(), n, lA.data(), ldefault,
|
|
118
|
+
unroll);
|
|
119
|
+
R.shift(logn, shiftbits.data(), k, bgot.data(), n, bA.data(), bdefault,
|
|
120
|
+
unroll);
|
|
121
|
+
R.shift(logn, shiftbits.data(), k, bvgot.data(), n, bvA.data(), bvdefault,
|
|
122
|
+
unroll);
|
|
123
|
+
}
|
|
124
|
+
for (size_t i = 0; i < k; ++i) {
|
|
125
|
+
EXPECT_EQ(L.eval(lgot[i]), L.eval(lwant[i]));
|
|
126
|
+
EXPECT_EQ(bgot[i], bwant[i]);
|
|
127
|
+
expect_vequal(L, bvgot[i], bvwant[i]);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
TEST(Routing, Simple) {
|
|
132
|
+
const Field F("18446744073709551557");
|
|
133
|
+
const EvaluationBackend ebk(F);
|
|
134
|
+
const Logic L(&ebk, F);
|
|
135
|
+
|
|
136
|
+
// test small cases exhaustively
|
|
137
|
+
for (size_t logn = 1; logn <= 5; ++logn) {
|
|
138
|
+
for (size_t n = 1; n <= 16; ++n) {
|
|
139
|
+
for (size_t k = 1; k <= 16; ++k) {
|
|
140
|
+
for (size_t shift = 0; shift <= 16; ++shift)
|
|
141
|
+
for (size_t unroll = 1; unroll <= 8; ++unroll) {
|
|
142
|
+
one_test(logn, n, k, shift, unroll, true, L);
|
|
143
|
+
one_test(logn, n, k, shift, unroll, false, L);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// test large cases more sparsely
|
|
150
|
+
size_t nn = 1;
|
|
151
|
+
for (size_t logn = 1; logn <= 8; ++logn) {
|
|
152
|
+
for (; nn <= (1 << logn); nn += 1 + (nn / 7)) {
|
|
153
|
+
for (size_t k = 1; k <= nn; k += 1 + (k / 5)) {
|
|
154
|
+
for (size_t shift = 0; shift < nn; shift += 1 + (shift / 3)) {
|
|
155
|
+
for (size_t unroll = 1; unroll <= logn; ++unroll) {
|
|
156
|
+
one_test(logn, nn, k, shift, unroll, true, L);
|
|
157
|
+
one_test(logn, nn, k, shift, unroll, false, L);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
TEST(Routing, EltCircuitSize) {
|
|
166
|
+
const Field F("18446744073709551557");
|
|
167
|
+
set_log_level(INFO);
|
|
168
|
+
for (size_t logn = 0; logn <= 10; ++logn) {
|
|
169
|
+
for (size_t unroll = 1; unroll <= logn; unroll *= 2) {
|
|
170
|
+
for (size_t unshift = 0; unshift < 2; ++unshift) {
|
|
171
|
+
size_t n = (1 << logn), k = (1 << logn);
|
|
172
|
+
QuadCircuit<Field> Q(F);
|
|
173
|
+
const CompilerBackend cbk(&Q);
|
|
174
|
+
const LogicCircuit LC(&cbk, F);
|
|
175
|
+
const Routing<LogicCircuit> RC(LC);
|
|
176
|
+
std::vector<BitWC> amount(logn);
|
|
177
|
+
std::vector<EltWC> a(n);
|
|
178
|
+
std::vector<EltWC> b(k);
|
|
179
|
+
for (size_t i = 0; i < logn; ++i) {
|
|
180
|
+
amount[i] = LC.input();
|
|
181
|
+
}
|
|
182
|
+
for (size_t i = 0; i < n; ++i) {
|
|
183
|
+
a[i] = LC.eltw_input();
|
|
184
|
+
}
|
|
185
|
+
if (unshift) {
|
|
186
|
+
RC.unshift(logn, amount.data(), k, b.data(), n, a.data(), LC.konst(0),
|
|
187
|
+
unroll);
|
|
188
|
+
} else {
|
|
189
|
+
RC.shift(logn, amount.data(), k, b.data(), n, a.data(), LC.konst(0),
|
|
190
|
+
unroll);
|
|
191
|
+
}
|
|
192
|
+
for (size_t i = 0; i < k; ++i) {
|
|
193
|
+
LC.output(b[i], i);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
auto CIRCUIT = Q.mkcircuit(/*nc=*/1);
|
|
197
|
+
dump_info(unshift ? "unshift_Elt" : "shift_Elt", n, k, unroll, Q);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
TEST(Routing, BitCircuitSize) {
|
|
204
|
+
const Field F("18446744073709551557");
|
|
205
|
+
set_log_level(INFO);
|
|
206
|
+
for (size_t logn = 0; logn <= 10; ++logn) {
|
|
207
|
+
for (size_t unroll = 1; unroll <= logn; unroll *= 2) {
|
|
208
|
+
for (size_t unshift = 0; unshift < 2; ++unshift) {
|
|
209
|
+
size_t n = (1 << logn), k = (1 << logn);
|
|
210
|
+
QuadCircuit<Field> Q(F);
|
|
211
|
+
const CompilerBackend cbk(&Q);
|
|
212
|
+
const LogicCircuit LC(&cbk, F);
|
|
213
|
+
const Routing<LogicCircuit> RC(LC);
|
|
214
|
+
std::vector<BitWC> amount(logn);
|
|
215
|
+
std::vector<BitWC> a(n);
|
|
216
|
+
std::vector<BitWC> b(k);
|
|
217
|
+
for (size_t i = 0; i < logn; ++i) {
|
|
218
|
+
amount[i] = LC.input();
|
|
219
|
+
}
|
|
220
|
+
for (size_t i = 0; i < n; ++i) {
|
|
221
|
+
a[i] = LC.input();
|
|
222
|
+
}
|
|
223
|
+
if (unshift) {
|
|
224
|
+
RC.unshift(logn, amount.data(), k, b.data(), n, a.data(), LC.bit(0),
|
|
225
|
+
unroll);
|
|
226
|
+
} else {
|
|
227
|
+
RC.shift(logn, amount.data(), k, b.data(), n, a.data(), LC.bit(0),
|
|
228
|
+
unroll);
|
|
229
|
+
}
|
|
230
|
+
for (size_t i = 0; i < k; ++i) {
|
|
231
|
+
LC.output(b[i], i);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
auto CIRCUIT = Q.mkcircuit(/*nc=*/1);
|
|
235
|
+
dump_info(unshift ? "unshift_bit" : "shift_bit", n, k, unroll, Q);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
} // namespace
|
|
241
|
+
} // namespace proofs
|