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,428 @@
|
|
|
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/tests/ec/pk_circuit.h"
|
|
16
|
+
|
|
17
|
+
#include <cstddef>
|
|
18
|
+
#include <cstdint>
|
|
19
|
+
#include <memory>
|
|
20
|
+
#include <vector>
|
|
21
|
+
|
|
22
|
+
#include "algebra/crt.h"
|
|
23
|
+
#include "algebra/crt_convolution.h"
|
|
24
|
+
#include "algebra/reed_solomon.h"
|
|
25
|
+
#include "arrays/dense.h"
|
|
26
|
+
#include "circuits/compiler/circuit_dump.h"
|
|
27
|
+
#include "circuits/compiler/compiler.h"
|
|
28
|
+
#include "circuits/logic/compiler_backend.h"
|
|
29
|
+
#include "circuits/logic/evaluation_backend.h"
|
|
30
|
+
#include "circuits/logic/logic.h"
|
|
31
|
+
#include "circuits/tests/ec/pk_witness.h"
|
|
32
|
+
#include "ec/p256.h"
|
|
33
|
+
#include "ec/p256k1.h"
|
|
34
|
+
#include "random/secure_random_engine.h"
|
|
35
|
+
#include "random/transcript.h"
|
|
36
|
+
#include "sumcheck/circuit.h"
|
|
37
|
+
#include "util/log.h"
|
|
38
|
+
#include "zk/zk_proof.h"
|
|
39
|
+
#include "zk/zk_prover.h"
|
|
40
|
+
#include "zk/zk_verifier.h"
|
|
41
|
+
#include "benchmark/benchmark.h"
|
|
42
|
+
#include "gtest/gtest.h"
|
|
43
|
+
|
|
44
|
+
namespace proofs {
|
|
45
|
+
// ZK parameters
|
|
46
|
+
constexpr size_t kRate = 4;
|
|
47
|
+
constexpr size_t kQueries = 128;
|
|
48
|
+
|
|
49
|
+
struct P256Traits {
|
|
50
|
+
using Field = Fp256Base;
|
|
51
|
+
using Scalar = Fp256Scalar;
|
|
52
|
+
using EC = P256;
|
|
53
|
+
|
|
54
|
+
static const EC& ec() { return p256; }
|
|
55
|
+
static const Field& field() { return p256_base; }
|
|
56
|
+
static const Scalar& scalar_field() { return p256_scalar; }
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
struct P256K1Traits {
|
|
60
|
+
using Field = Fp256k1Base;
|
|
61
|
+
using Scalar = Fp256k1Scalar;
|
|
62
|
+
using EC = P256k1;
|
|
63
|
+
|
|
64
|
+
static const EC& ec() { return p256k1; }
|
|
65
|
+
static const Field& field() { return p256k1_base; }
|
|
66
|
+
static const Scalar& scalar_field() { return p256k1_scalar; }
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
template <typename Traits>
|
|
70
|
+
class EcpkTest : public ::testing::Test {
|
|
71
|
+
public:
|
|
72
|
+
using Field = typename Traits::Field;
|
|
73
|
+
using Scalar = typename Traits::Scalar;
|
|
74
|
+
using EC = typename Traits::EC;
|
|
75
|
+
using Nat = typename Field::N;
|
|
76
|
+
using Elt = typename Field::Elt;
|
|
77
|
+
|
|
78
|
+
// Logic types
|
|
79
|
+
using EvalBackend = EvaluationBackend<Field>;
|
|
80
|
+
using LogicType = Logic<Field, EvalBackend>;
|
|
81
|
+
using EltW = typename LogicType::EltW;
|
|
82
|
+
using EcpkC = Ecpk<LogicType, Field, EC>;
|
|
83
|
+
using PkW = PkWitness<EC, Scalar>;
|
|
84
|
+
|
|
85
|
+
// Compiler types
|
|
86
|
+
using CompilerBackendType = CompilerBackend<Field>;
|
|
87
|
+
using LogicCircuit = Logic<Field, CompilerBackendType>;
|
|
88
|
+
using EltWC = typename LogicCircuit::EltW;
|
|
89
|
+
using EcpkCC = Ecpk<LogicCircuit, Field, EC>;
|
|
90
|
+
void CheckRelation(const Nat& sk_nat, const typename EC::ECPoint& PK,
|
|
91
|
+
bool expected) {
|
|
92
|
+
const Field& F = Traits::field();
|
|
93
|
+
const EC& ec = Traits::ec();
|
|
94
|
+
const Scalar& scalar = Traits::scalar_field();
|
|
95
|
+
|
|
96
|
+
const EvalBackend ebk(F, expected);
|
|
97
|
+
const LogicType l(&ebk, F);
|
|
98
|
+
|
|
99
|
+
EcpkC circuit(l, ec);
|
|
100
|
+
PkW wit_gen(scalar, ec);
|
|
101
|
+
|
|
102
|
+
EXPECT_TRUE(wit_gen.compute_witness(sk_nat));
|
|
103
|
+
|
|
104
|
+
EltW pk_x = l.konst(PK.x);
|
|
105
|
+
EltW pk_y = l.konst(PK.y);
|
|
106
|
+
|
|
107
|
+
typename EcpkC::Witness w;
|
|
108
|
+
for (size_t j = 0; j < EC::kBits; ++j) {
|
|
109
|
+
w.bits[j] = l.konst(wit_gen.bits_[j]);
|
|
110
|
+
if (j < EC::kBits - 1) {
|
|
111
|
+
w.int_x[j] = l.konst(wit_gen.int_x_[j]);
|
|
112
|
+
w.int_y[j] = l.konst(wit_gen.int_y_[j]);
|
|
113
|
+
w.int_z[j] = l.konst(wit_gen.int_z_[j]);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
circuit.assert_public_key(pk_x, pk_y, w);
|
|
118
|
+
if (expected) {
|
|
119
|
+
ASSERT_FALSE(ebk.assertion_failed());
|
|
120
|
+
} else {
|
|
121
|
+
ASSERT_TRUE(ebk.assertion_failed());
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Test for a particular attack in which (0,0,0) is provided as the
|
|
126
|
+
// intermediate witness values. This test should always fail.
|
|
127
|
+
void CheckRelationZeroWitness(const Nat& sk_nat,
|
|
128
|
+
const typename EC::ECPoint& PK) {
|
|
129
|
+
const Field& F = Traits::field();
|
|
130
|
+
const EC& ec = Traits::ec();
|
|
131
|
+
const Scalar& scalar = Traits::scalar_field();
|
|
132
|
+
|
|
133
|
+
const EvalBackend ebk(F, false);
|
|
134
|
+
const LogicType l(&ebk, F);
|
|
135
|
+
|
|
136
|
+
EcpkC circuit(l, ec);
|
|
137
|
+
PkW wit_gen(scalar, ec);
|
|
138
|
+
|
|
139
|
+
// Compute the real witness.
|
|
140
|
+
EXPECT_TRUE(wit_gen.compute_witness(sk_nat));
|
|
141
|
+
|
|
142
|
+
EltW pk_x = l.konst(PK.x);
|
|
143
|
+
EltW pk_y = l.konst(PK.y);
|
|
144
|
+
|
|
145
|
+
// Set the intermediate witness values to 0.
|
|
146
|
+
typename EcpkC::Witness w;
|
|
147
|
+
for (size_t j = 0; j < EC::kBits; ++j) {
|
|
148
|
+
w.bits[j] = l.konst(wit_gen.bits_[j]);
|
|
149
|
+
if (j < EC::kBits - 1) {
|
|
150
|
+
w.int_x[j] = l.konst(F.zero());
|
|
151
|
+
w.int_y[j] = l.konst(F.zero());
|
|
152
|
+
w.int_z[j] = l.konst(F.zero());
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
circuit.assert_public_key(pk_x, pk_y, w);
|
|
157
|
+
ASSERT_TRUE(ebk.assertion_failed());
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
TYPED_TEST_SUITE_P(EcpkTest);
|
|
162
|
+
|
|
163
|
+
TYPED_TEST_P(EcpkTest, VerifyRelation) {
|
|
164
|
+
using Field = typename TypeParam::Field;
|
|
165
|
+
using EC = typename TypeParam::EC;
|
|
166
|
+
using Nat = typename Field::N;
|
|
167
|
+
|
|
168
|
+
const EC& ec = TypeParam::ec();
|
|
169
|
+
|
|
170
|
+
for (int i = 0; i < 5; ++i) {
|
|
171
|
+
Nat sk_nat = Nat(9876543219999 + i);
|
|
172
|
+
auto PK = ec.scalar_multf(ec.generator(), sk_nat);
|
|
173
|
+
ec.normalize(PK);
|
|
174
|
+
|
|
175
|
+
this->CheckRelation(sk_nat, PK, true);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
TYPED_TEST_P(EcpkTest, VerifyFailure) {
|
|
180
|
+
using Field = typename TypeParam::Field;
|
|
181
|
+
using Scalar = typename TypeParam::Scalar;
|
|
182
|
+
using EC = typename TypeParam::EC;
|
|
183
|
+
using Nat = typename Field::N;
|
|
184
|
+
|
|
185
|
+
const EC& ec = TypeParam::ec();
|
|
186
|
+
const Scalar& scalar = TypeParam::scalar_field();
|
|
187
|
+
|
|
188
|
+
Nat sk_nat = Nat(123456);
|
|
189
|
+
|
|
190
|
+
Nat sk_plus_one = sk_nat;
|
|
191
|
+
scalar.add(sk_plus_one, Nat(1));
|
|
192
|
+
auto PK_wrong = ec.scalar_multf(ec.generator(), sk_plus_one);
|
|
193
|
+
ec.normalize(PK_wrong);
|
|
194
|
+
|
|
195
|
+
this->CheckRelation(sk_nat, PK_wrong, false);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
TYPED_TEST_P(EcpkTest, VerifyZeroWitnessFailure) {
|
|
199
|
+
using Field = typename TypeParam::Field;
|
|
200
|
+
using EC = typename TypeParam::EC;
|
|
201
|
+
using Nat = typename Field::N;
|
|
202
|
+
|
|
203
|
+
const EC& ec = TypeParam::ec();
|
|
204
|
+
|
|
205
|
+
Nat sk_nat = Nat(123456);
|
|
206
|
+
|
|
207
|
+
auto PK = ec.scalar_multf(ec.generator(), sk_nat);
|
|
208
|
+
ec.normalize(PK);
|
|
209
|
+
|
|
210
|
+
this->CheckRelationZeroWitness(sk_nat, PK);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
TYPED_TEST_P(EcpkTest, CircuitSize) {
|
|
214
|
+
using Field = typename TypeParam::Field;
|
|
215
|
+
using EC = typename TypeParam::EC;
|
|
216
|
+
using CompilerBackendType = CompilerBackend<Field>;
|
|
217
|
+
using LogicCircuit = Logic<Field, CompilerBackendType>;
|
|
218
|
+
using EltW = typename LogicCircuit::EltW;
|
|
219
|
+
using EcpkC = Ecpk<LogicCircuit, Field, EC>;
|
|
220
|
+
|
|
221
|
+
QuadCircuit<Field> Q(TypeParam::field());
|
|
222
|
+
const CompilerBackendType cbk(&Q);
|
|
223
|
+
const LogicCircuit lc(&cbk, TypeParam::field());
|
|
224
|
+
EcpkC circuit(lc, TypeParam::ec());
|
|
225
|
+
|
|
226
|
+
typename EcpkC::Witness w;
|
|
227
|
+
w.input(lc);
|
|
228
|
+
EltW pk_x = lc.eltw_input();
|
|
229
|
+
EltW pk_y = lc.eltw_input();
|
|
230
|
+
|
|
231
|
+
circuit.assert_public_key(pk_x, pk_y, w);
|
|
232
|
+
auto CIRCUIT = Q.mkcircuit(1);
|
|
233
|
+
dump_info("ecpk verify", Q);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Helpers for ZK Test
|
|
237
|
+
template <typename Traits>
|
|
238
|
+
std::unique_ptr<Circuit<typename Traits::Field>> make_circuit(size_t numKeys) {
|
|
239
|
+
using Field = typename Traits::Field;
|
|
240
|
+
using EC = typename Traits::EC;
|
|
241
|
+
using CompilerBackendType = CompilerBackend<Field>;
|
|
242
|
+
using LogicCircuit = Logic<Field, CompilerBackendType>;
|
|
243
|
+
using EltW = typename LogicCircuit::EltW;
|
|
244
|
+
using EcpkC = Ecpk<LogicCircuit, Field, EC>;
|
|
245
|
+
|
|
246
|
+
QuadCircuit<Field> Q(Traits::field());
|
|
247
|
+
const CompilerBackendType cbk(&Q);
|
|
248
|
+
const LogicCircuit lc(&cbk, Traits::field());
|
|
249
|
+
EcpkC circuit(lc, Traits::ec());
|
|
250
|
+
|
|
251
|
+
std::vector<typename EcpkC::Witness> ws(numKeys);
|
|
252
|
+
std::vector<EltW> pkxs(numKeys);
|
|
253
|
+
std::vector<EltW> pkys(numKeys);
|
|
254
|
+
|
|
255
|
+
for (size_t i = 0; i < numKeys; ++i) {
|
|
256
|
+
pkxs[i] = lc.eltw_input();
|
|
257
|
+
pkys[i] = lc.eltw_input();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
Q.private_input();
|
|
261
|
+
for (size_t i = 0; i < numKeys; ++i) {
|
|
262
|
+
ws[i].input(lc);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
for (size_t i = 0; i < numKeys; ++i) {
|
|
266
|
+
circuit.assert_public_key(pkxs[i], pkys[i], ws[i]);
|
|
267
|
+
}
|
|
268
|
+
return Q.mkcircuit(1);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
template <typename Traits>
|
|
272
|
+
void fill_input(Dense<typename Traits::Field>& W, size_t numSigs, bool prover) {
|
|
273
|
+
using Field = typename Traits::Field;
|
|
274
|
+
using EC = typename Traits::EC;
|
|
275
|
+
using Scalar = typename Traits::Scalar;
|
|
276
|
+
using Nat = typename Field::N;
|
|
277
|
+
using PkW = PkWitness<EC, Scalar>;
|
|
278
|
+
|
|
279
|
+
const auto& ec = Traits::ec();
|
|
280
|
+
const auto& scalar = Traits::scalar_field();
|
|
281
|
+
const auto& field = Traits::field();
|
|
282
|
+
|
|
283
|
+
PkW wit_gen(scalar, ec);
|
|
284
|
+
DenseFiller<Field> filler(W);
|
|
285
|
+
filler.push_back(field.one());
|
|
286
|
+
|
|
287
|
+
Nat sk = Nat(123456789);
|
|
288
|
+
auto PK = ec.scalar_multf(ec.generator(), sk);
|
|
289
|
+
ec.normalize(PK);
|
|
290
|
+
wit_gen.compute_witness(sk);
|
|
291
|
+
|
|
292
|
+
for (size_t i = 0; i < numSigs; ++i) {
|
|
293
|
+
filler.push_back(PK.x);
|
|
294
|
+
filler.push_back(PK.y);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (prover) {
|
|
298
|
+
for (size_t i = 0; i < numSigs; ++i) {
|
|
299
|
+
wit_gen.fill_witness(filler);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
TYPED_TEST_P(EcpkTest, ZkProverVerifier) {
|
|
305
|
+
using Field = typename TypeParam::Field;
|
|
306
|
+
|
|
307
|
+
set_log_level(INFO);
|
|
308
|
+
size_t numSigs = 1;
|
|
309
|
+
auto CIRCUIT = make_circuit<TypeParam>(numSigs);
|
|
310
|
+
auto W = std::make_unique<Dense<Field>>(1, CIRCUIT->ninputs);
|
|
311
|
+
fill_input<TypeParam>(*W, numSigs, true);
|
|
312
|
+
|
|
313
|
+
using Crt = CRT256<Field>;
|
|
314
|
+
using ConvolutionFactory = CrtConvolutionFactory<Crt, Field>;
|
|
315
|
+
using RSFactory = ReedSolomonFactory<Field, ConvolutionFactory>;
|
|
316
|
+
|
|
317
|
+
ConvolutionFactory factory(TypeParam::field());
|
|
318
|
+
RSFactory rsf(factory, TypeParam::field());
|
|
319
|
+
|
|
320
|
+
Transcript tp((uint8_t*)"zkproververifier", 16);
|
|
321
|
+
SecureRandomEngine rng;
|
|
322
|
+
|
|
323
|
+
ZkProof<Field> zkpr(*CIRCUIT, kRate, kQueries);
|
|
324
|
+
ZkProver<Field, RSFactory> prover(*CIRCUIT, TypeParam::field(), rsf);
|
|
325
|
+
prover.commit(zkpr, *W, tp, rng);
|
|
326
|
+
prover.prove(zkpr, *W, tp);
|
|
327
|
+
log(INFO, "Prover done");
|
|
328
|
+
|
|
329
|
+
Transcript tv((uint8_t*)"zkproververifier", 16);
|
|
330
|
+
auto pub = Dense<Field>(1, CIRCUIT->npub_in);
|
|
331
|
+
fill_input<TypeParam>(pub, numSigs, false);
|
|
332
|
+
|
|
333
|
+
ZkVerifier<Field, RSFactory> verifier(*CIRCUIT, rsf, kRate, kQueries,
|
|
334
|
+
TypeParam::field());
|
|
335
|
+
verifier.recv_commitment(zkpr, tv);
|
|
336
|
+
EXPECT_TRUE(verifier.verify(zkpr, pub, tv));
|
|
337
|
+
log(INFO, "Verifier done");
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
REGISTER_TYPED_TEST_SUITE_P(EcpkTest, VerifyRelation, VerifyFailure,
|
|
341
|
+
VerifyZeroWitnessFailure, CircuitSize,
|
|
342
|
+
ZkProverVerifier);
|
|
343
|
+
|
|
344
|
+
using TestTypes = ::testing::Types<P256Traits, P256K1Traits>;
|
|
345
|
+
INSTANTIATE_TYPED_TEST_SUITE_P(P256, EcpkTest, TestTypes);
|
|
346
|
+
|
|
347
|
+
// ===================== Benchmarks ==============================
|
|
348
|
+
|
|
349
|
+
template <typename Traits>
|
|
350
|
+
struct BenchmarkContext {
|
|
351
|
+
using Field = typename Traits::Field;
|
|
352
|
+
using Crt = CRT256<Field>;
|
|
353
|
+
using ConvolutionFactory = CrtConvolutionFactory<Crt, Field>;
|
|
354
|
+
using RSFactory = ReedSolomonFactory<Field, ConvolutionFactory>;
|
|
355
|
+
|
|
356
|
+
std::unique_ptr<Circuit<Field>> circuit;
|
|
357
|
+
Dense<Field> w;
|
|
358
|
+
ConvolutionFactory factory;
|
|
359
|
+
RSFactory rsf;
|
|
360
|
+
Transcript tp;
|
|
361
|
+
SecureRandomEngine rng;
|
|
362
|
+
ZkProof<Field> zkpr;
|
|
363
|
+
ZkProver<Field, RSFactory> prover;
|
|
364
|
+
|
|
365
|
+
explicit BenchmarkContext(size_t numKeys)
|
|
366
|
+
: circuit(make_circuit<Traits>(numKeys)),
|
|
367
|
+
w(1, circuit->ninputs),
|
|
368
|
+
factory(Traits::field()),
|
|
369
|
+
rsf(factory, Traits::field()),
|
|
370
|
+
tp((uint8_t*)"benchmark", 9),
|
|
371
|
+
zkpr(*circuit, kRate, kQueries),
|
|
372
|
+
prover(*circuit, Traits::field(), rsf) {
|
|
373
|
+
set_log_level(ERROR);
|
|
374
|
+
fill_input<Traits>(w, numKeys, true);
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
template <typename Traits>
|
|
379
|
+
void BM_EcpkProverTemplate(benchmark::State& state) {
|
|
380
|
+
BenchmarkContext<Traits> ctx(state.range(0));
|
|
381
|
+
for (auto s : state) {
|
|
382
|
+
ctx.prover.commit(ctx.zkpr, ctx.w, ctx.tp, ctx.rng);
|
|
383
|
+
ctx.prover.prove(ctx.zkpr, ctx.w, ctx.tp);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
template <typename Traits>
|
|
388
|
+
void BM_EcpkVerifierTemplate(benchmark::State& state) {
|
|
389
|
+
using Field = typename Traits::Field;
|
|
390
|
+
BenchmarkContext<Traits> ctx(state.range(0));
|
|
391
|
+
ctx.prover.commit(ctx.zkpr, ctx.w, ctx.tp, ctx.rng);
|
|
392
|
+
ctx.prover.prove(ctx.zkpr, ctx.w, ctx.tp);
|
|
393
|
+
|
|
394
|
+
ZkVerifier<Field, typename BenchmarkContext<Traits>::RSFactory> verifier(
|
|
395
|
+
*ctx.circuit, ctx.rsf, kRate, kQueries, Traits::field());
|
|
396
|
+
|
|
397
|
+
auto pub = Dense<Field>(1, ctx.circuit->npub_in);
|
|
398
|
+
fill_input<Traits>(pub, state.range(0), false);
|
|
399
|
+
|
|
400
|
+
for (auto s : state) {
|
|
401
|
+
Transcript tv((uint8_t*)"benchmark", 9);
|
|
402
|
+
verifier.recv_commitment(ctx.zkpr, tv);
|
|
403
|
+
verifier.verify(ctx.zkpr, pub, tv);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
void BM_EcpkProver_P256(benchmark::State& state) {
|
|
408
|
+
BM_EcpkProverTemplate<P256Traits>(state);
|
|
409
|
+
}
|
|
410
|
+
BENCHMARK(BM_EcpkProver_P256)->DenseRange(1, 4);
|
|
411
|
+
|
|
412
|
+
void BM_EcpkVerifier_P256(benchmark::State& state) {
|
|
413
|
+
BM_EcpkVerifierTemplate<P256Traits>(state);
|
|
414
|
+
}
|
|
415
|
+
BENCHMARK(BM_EcpkVerifier_P256)->DenseRange(1, 4);
|
|
416
|
+
|
|
417
|
+
void BM_EcpkProver_P256K1(benchmark::State& state) {
|
|
418
|
+
BM_EcpkProverTemplate<P256K1Traits>(state);
|
|
419
|
+
}
|
|
420
|
+
BENCHMARK(BM_EcpkProver_P256K1)
|
|
421
|
+
->DenseRange(1, 2); // Reduced range due to slowness
|
|
422
|
+
|
|
423
|
+
void BM_EcpkVerifier_P256K1(benchmark::State& state) {
|
|
424
|
+
BM_EcpkVerifierTemplate<P256K1Traits>(state);
|
|
425
|
+
}
|
|
426
|
+
BENCHMARK(BM_EcpkVerifier_P256K1)->DenseRange(1, 2);
|
|
427
|
+
|
|
428
|
+
} // namespace proofs
|
|
@@ -0,0 +1,102 @@
|
|
|
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_TESTS_EC_PK_WITNESS_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_TESTS_EC_PK_WITNESS_H_
|
|
17
|
+
|
|
18
|
+
#include <cstddef>
|
|
19
|
+
|
|
20
|
+
#include "arrays/dense.h"
|
|
21
|
+
|
|
22
|
+
namespace proofs {
|
|
23
|
+
|
|
24
|
+
template <class EC, class ScalarField>
|
|
25
|
+
class PkWitness {
|
|
26
|
+
using Field = typename EC::Field;
|
|
27
|
+
using Elt = typename Field::Elt;
|
|
28
|
+
using Nat = typename Field::N;
|
|
29
|
+
|
|
30
|
+
public:
|
|
31
|
+
constexpr static size_t kBits = EC::kBits;
|
|
32
|
+
const ScalarField& fn_;
|
|
33
|
+
const EC& ec_;
|
|
34
|
+
|
|
35
|
+
// Witness components
|
|
36
|
+
Elt bits_[kBits];
|
|
37
|
+
Elt int_x_[kBits];
|
|
38
|
+
Elt int_y_[kBits];
|
|
39
|
+
Elt int_z_[kBits];
|
|
40
|
+
|
|
41
|
+
PkWitness(const ScalarField& Fn, const EC& ec) : fn_(Fn), ec_(ec) {}
|
|
42
|
+
|
|
43
|
+
void fill_witness(DenseFiller<Field>& filler) const {
|
|
44
|
+
for (size_t i = 0; i < kBits; ++i) {
|
|
45
|
+
filler.push_back(bits_[i]);
|
|
46
|
+
if (i < kBits - 1) {
|
|
47
|
+
filler.push_back(int_x_[i]);
|
|
48
|
+
filler.push_back(int_y_[i]);
|
|
49
|
+
filler.push_back(int_z_[i]);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Computes witness for PK = sk * G
|
|
55
|
+
bool compute_witness(const Nat sk) {
|
|
56
|
+
const Field& F = ec_.f_;
|
|
57
|
+
const Elt one = F.one();
|
|
58
|
+
const Elt bgX = ec_.gx_;
|
|
59
|
+
const Elt bgY = ec_.gy_;
|
|
60
|
+
|
|
61
|
+
Elt aX = F.zero();
|
|
62
|
+
Elt aY = one;
|
|
63
|
+
Elt aZ = F.zero();
|
|
64
|
+
|
|
65
|
+
// VerifyCircuit loops i from 0 to kBits-1.
|
|
66
|
+
// So bits_[0] corresponds to sk.bit(kBits - 1).
|
|
67
|
+
|
|
68
|
+
for (size_t i = 0; i < kBits; ++i) {
|
|
69
|
+
// Get bit from high to low
|
|
70
|
+
size_t bit_idx = kBits - 1 - i;
|
|
71
|
+
int bit = sk.bit(bit_idx);
|
|
72
|
+
bits_[i] = F.of_scalar(bit);
|
|
73
|
+
|
|
74
|
+
ec_.doubleE(aX, aY, aZ, aX, aY, aZ);
|
|
75
|
+
|
|
76
|
+
if (bit == 1) {
|
|
77
|
+
ec_.addE(aX, aY, aZ, aX, aY, aZ, bgX, bgY, one);
|
|
78
|
+
} else {
|
|
79
|
+
// Adding point at infinity (0, 1, 0)
|
|
80
|
+
ec_.addE(aX, aY, aZ, aX, aY, aZ, F.zero(), one, F.zero());
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
int_x_[i] = aX;
|
|
84
|
+
int_y_[i] = aY;
|
|
85
|
+
int_z_[i] = aZ;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Sanity check: result shouldn't be infinity if sk != 0 (assuming order is
|
|
89
|
+
// prime and sk < order)
|
|
90
|
+
if (aZ == F.zero() && sk != Nat(0)) {
|
|
91
|
+
// Technically sk=0 gives point at infinity.
|
|
92
|
+
// If sk != 0, aZ should be non-zero (unless P is point of order 2 etc,
|
|
93
|
+
// but this is a cryptographic curve).
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
} // namespace proofs
|
|
101
|
+
|
|
102
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_TESTS_EC_PK_WITNESS_H_
|