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,250 @@
|
|
|
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_PQ_BITADDR_BITADDR_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_TESTS_PQ_BITADDR_BITADDR_H_
|
|
17
|
+
|
|
18
|
+
#include <algorithm>
|
|
19
|
+
#include <cstddef>
|
|
20
|
+
|
|
21
|
+
#include "circuits/logic/bit_plucker.h"
|
|
22
|
+
#include "circuits/sha/flatsha256_circuit.h"
|
|
23
|
+
#include "circuits/tests/ec/pk_circuit.h"
|
|
24
|
+
#include "circuits/tests/ripemd/ripemd_circuit.h"
|
|
25
|
+
#include "ec/p256k1.h"
|
|
26
|
+
|
|
27
|
+
namespace proofs {
|
|
28
|
+
|
|
29
|
+
// BitaddrCircuit verifies that a Bitcoin address corresponds to a known
|
|
30
|
+
// private key.
|
|
31
|
+
// It checks:
|
|
32
|
+
// 1. Public key derivation: (pk_x, pk_y) = sk * G
|
|
33
|
+
// 2. Address generation: address = RIPEMD160(SHA256(compressed_pk))
|
|
34
|
+
//
|
|
35
|
+
// Note: This circuit only handles the legacy version of the Bitcoin address
|
|
36
|
+
// format (P2PKH). We can safely ignore the checksum digits of the address
|
|
37
|
+
// as those can be publicly verified outside the circuit.
|
|
38
|
+
//
|
|
39
|
+
// Also note that while Bitcoin addresses are typically presented in Base58Check
|
|
40
|
+
// encoding (e.g., starting with '1'), the input to this circuit should be the
|
|
41
|
+
// underlying 20-byte hash (Hash160) values.
|
|
42
|
+
//
|
|
43
|
+
// See
|
|
44
|
+
// https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses
|
|
45
|
+
//
|
|
46
|
+
// Example:
|
|
47
|
+
// Test case 0 in bitaddr_test.cc uses:
|
|
48
|
+
//
|
|
49
|
+
// Walkthrough:
|
|
50
|
+
// 1. Private Key (Input to Witness):
|
|
51
|
+
// 0x9FE33A7A06BD0FE6F5208A61991C49B5B4DD12DC42D9903E789F5118F9675030
|
|
52
|
+
//
|
|
53
|
+
// 2. Public Key (Compressed):
|
|
54
|
+
// Derived as (pk_x, pk_y) = sk * G
|
|
55
|
+
// Compressed format (used as input to SHA256):
|
|
56
|
+
// 0x0252C5262A39751CDDAB2DDF63BA58D04BE30939BE905CF54311385B3C9473E66A
|
|
57
|
+
//
|
|
58
|
+
// 3. SHA256 Hash:
|
|
59
|
+
// Input: Compressed Public Key (33 bytes)
|
|
60
|
+
// Output: SHA256(0252...66A)
|
|
61
|
+
// 0xF7216B404954F08AC191FB7EBA7EB15ADA706687E274707721CAA0DEE454F722
|
|
62
|
+
//
|
|
63
|
+
// 4. RIPEMD160 Hash (Hash160):
|
|
64
|
+
// Input: SHA256 Output (32 bytes)
|
|
65
|
+
// Output: RIPEMD160(F721...722)
|
|
66
|
+
// 0xE30798BD7D0193D12F3F6FEA6D9FF6FEAA2AC721
|
|
67
|
+
//
|
|
68
|
+
// *** This RIPEMD160 hash is the "Address" validated by this circuit ***
|
|
69
|
+
// circuit.assert_bitaddr(addr_elt, w) expects addr_elt to be this value.
|
|
70
|
+
//
|
|
71
|
+
// The following steps are used to generate the full address:
|
|
72
|
+
//
|
|
73
|
+
// 5. Version Byte (0x00) + Hash160:
|
|
74
|
+
// 00E30798BD7D0193D12F3F6FEA6D9FF6FEAA2AC721
|
|
75
|
+
//
|
|
76
|
+
// 6. Double SHA256 Checksum (first 4 bytes):
|
|
77
|
+
// SHA256(SHA256(00E3...21)) -> ... -> 83090D22
|
|
78
|
+
//
|
|
79
|
+
// 7. Base58Check Encoding (Final Address):
|
|
80
|
+
// Encode(Version + Hash160 + Checksum)
|
|
81
|
+
// 1MhRVNRfTw2NZbKBd1z9yaniy9NJtZVmE1
|
|
82
|
+
template <class Logic>
|
|
83
|
+
class BitaddrCircuit {
|
|
84
|
+
public:
|
|
85
|
+
using Field = Fp256k1Base;
|
|
86
|
+
using EC = P256k1; // This application only make sense with the 256k1 curve.
|
|
87
|
+
using EltW = typename Logic::EltW;
|
|
88
|
+
using Elt = typename Field::Elt;
|
|
89
|
+
using v8 = typename Logic::v8;
|
|
90
|
+
using v32 = typename Logic::v32;
|
|
91
|
+
using EcpkWitness = typename Ecpk<Logic, Field, EC>::Witness;
|
|
92
|
+
using ShaCircuit = FlatSHA256Circuit<Logic, BitPlucker<Logic, 2>>;
|
|
93
|
+
using RipemdCircuit = Ripemd160Circuit<Logic, BitPlucker<Logic, 2>>;
|
|
94
|
+
using ShaWitness = typename ShaCircuit::BlockWitness;
|
|
95
|
+
using RipemdWitness = typename RipemdCircuit::BlockWitness;
|
|
96
|
+
|
|
97
|
+
static constexpr size_t kBits = EC::kBits; // 256 for P256K1
|
|
98
|
+
|
|
99
|
+
struct Witness {
|
|
100
|
+
EcpkWitness ecpk;
|
|
101
|
+
// SHA256 of 33 bytes fits in 1 block (33 + 9 padding = 42 < 64)
|
|
102
|
+
ShaWitness sha;
|
|
103
|
+
// RIPEMD160 of 32 bytes fits in 1 block (32 + 9 padding = 41 < 64)
|
|
104
|
+
RipemdWitness ripemd;
|
|
105
|
+
|
|
106
|
+
EltW pk_x;
|
|
107
|
+
EltW pk_y;
|
|
108
|
+
// Decomposition of pk_x and pk_y
|
|
109
|
+
typename Logic::template bitvec<kBits> pk_x_bits;
|
|
110
|
+
typename Logic::template bitvec<kBits> pk_y_bits;
|
|
111
|
+
|
|
112
|
+
void input(const Logic& lc) {
|
|
113
|
+
ecpk.input(lc);
|
|
114
|
+
pk_x = lc.eltw_input();
|
|
115
|
+
pk_y = lc.eltw_input();
|
|
116
|
+
pk_x_bits = lc.template vinput<kBits>();
|
|
117
|
+
pk_y_bits = lc.template vinput<kBits>();
|
|
118
|
+
sha.input(lc);
|
|
119
|
+
ripemd.input(lc);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// The reason we do this is so that the circuit can have only 1 public
|
|
124
|
+
// argument instead of 160 bits.
|
|
125
|
+
template <size_t N>
|
|
126
|
+
EltW as_scalar_large(const typename Logic::template bitvec<N>& v) const {
|
|
127
|
+
EltW r = lc_.konst(lc_.f_.zero());
|
|
128
|
+
Elt p = lc_.f_.one();
|
|
129
|
+
Elt two = lc_.f_.two();
|
|
130
|
+
for (size_t i = 0; i < N; ++i) {
|
|
131
|
+
EltW vi = lc_.eval(v[i]);
|
|
132
|
+
r = lc_.axpy(r, p, vi);
|
|
133
|
+
p = lc_.f_.mulf(p, two);
|
|
134
|
+
}
|
|
135
|
+
return r;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
explicit BitaddrCircuit(const Logic& lc)
|
|
139
|
+
: lc_(lc), ecpk_(lc, p256k1), sha_(lc), ripemd_(lc) {}
|
|
140
|
+
|
|
141
|
+
void assert_bitaddr(EltW addr_elt, const Witness& w) const {
|
|
142
|
+
// 1. Verify (pk_x, pk_y) = sk * G
|
|
143
|
+
ecpk_.assert_public_key(w.pk_x, w.pk_y, w.ecpk);
|
|
144
|
+
|
|
145
|
+
// 2. Decompose pk_x and pk_y and verify decomposition
|
|
146
|
+
// Ensure witnesses are bits (implicitly checked by vinput/BitW)
|
|
147
|
+
lc_.assert_eq(w.pk_x, as_scalar_large(w.pk_x_bits));
|
|
148
|
+
lc_.assert_eq(w.pk_y, as_scalar_large(w.pk_y_bits));
|
|
149
|
+
|
|
150
|
+
// 3. Serialize pk for SHA256 input
|
|
151
|
+
// Format: [prefix, x_bytes...]
|
|
152
|
+
// prefix is 0x02 if y is even, 0x03 if y is odd.
|
|
153
|
+
|
|
154
|
+
// Construct SHA256 input (33 bytes) + Padding
|
|
155
|
+
// Input is 33 bytes.
|
|
156
|
+
// Padding: Append 1 bit (0x80 byte), then zeros, then 64-bit length.
|
|
157
|
+
// Length = 33 * 8 = 264 bits.
|
|
158
|
+
v8 sha_in[64];
|
|
159
|
+
std::fill(sha_in, sha_in + 64, lc_.vbit8(0));
|
|
160
|
+
|
|
161
|
+
// Byte 0: prefix
|
|
162
|
+
sha_in[0][0] = w.pk_y_bits[0];
|
|
163
|
+
sha_in[0][1] = lc_.bit(1);
|
|
164
|
+
for (size_t i = 2; i < 8; ++i) sha_in[0][i] = lc_.bit(0);
|
|
165
|
+
|
|
166
|
+
// Bytes 1..32: pk_x (Big Endian)
|
|
167
|
+
for (size_t i = 0; i < 32; ++i) {
|
|
168
|
+
size_t byte_idx = 31 - i;
|
|
169
|
+
for (size_t b = 0; b < 8; ++b) {
|
|
170
|
+
sha_in[1 + i][b] = w.pk_x_bits[byte_idx * 8 + b];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Byte 33: 0x80
|
|
175
|
+
sha_in[33] = lc_.vbit8(0x80);
|
|
176
|
+
// Bytes 34..55: Zeros (already set by std::fill)
|
|
177
|
+
|
|
178
|
+
// Bytes 56..63: Length (Big Endian) = 264
|
|
179
|
+
// Bytes 56..61: Zeros (already set by std::fill)
|
|
180
|
+
sha_in[62] = lc_.vbit8(1);
|
|
181
|
+
sha_in[63] = lc_.vbit8(8);
|
|
182
|
+
|
|
183
|
+
// Run SHA256
|
|
184
|
+
v8 nb = lc_.vbit8(1); // 1 block
|
|
185
|
+
sha_.assert_message(1, nb, sha_in, &w.sha);
|
|
186
|
+
|
|
187
|
+
// SHA output is in w.sha.h1 (packed_v32[8]).
|
|
188
|
+
// We need to unpack into v8[32] for RIPEMD.
|
|
189
|
+
// SHA output is Big Endian words.
|
|
190
|
+
// RIPEMD input: 32 bytes.
|
|
191
|
+
// Convert SHA output to bytes.
|
|
192
|
+
v8 ripemd_in[64];
|
|
193
|
+
std::fill(ripemd_in, ripemd_in + 64, lc_.vbit8(0));
|
|
194
|
+
|
|
195
|
+
for (size_t i = 0; i < 8; ++i) {
|
|
196
|
+
typename Logic::v32 word = sha_.bp_.unpack_v32(w.sha.h1[i]);
|
|
197
|
+
// v32 word is LSB.
|
|
198
|
+
// Byte 0 (MSB) = word >> 24
|
|
199
|
+
// Byte 3 (LSB) = word & 0xFF
|
|
200
|
+
for (size_t b = 0; b < 8; ++b) {
|
|
201
|
+
ripemd_in[4 * i + 0][b] = word[24 + b];
|
|
202
|
+
ripemd_in[4 * i + 1][b] = word[16 + b];
|
|
203
|
+
ripemd_in[4 * i + 2][b] = word[8 + b];
|
|
204
|
+
ripemd_in[4 * i + 3][b] = word[0 + b];
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Padding for RIPEMD160
|
|
209
|
+
// Message len = 32 bytes = 256 bits.
|
|
210
|
+
// Byte 32: 0x80
|
|
211
|
+
ripemd_in[32] = lc_.vbit8(0x80);
|
|
212
|
+
|
|
213
|
+
// Bytes 56..63: Length (Little Endian for RIPEMD) = 256
|
|
214
|
+
// 256 = 0x0100.
|
|
215
|
+
// 00 01 00 00 00 00 00 00
|
|
216
|
+
ripemd_in[57] = lc_.vbit8(1);
|
|
217
|
+
|
|
218
|
+
// Run RIPEMD160
|
|
219
|
+
ripemd_.assert_message(1, nb, ripemd_in, &w.ripemd);
|
|
220
|
+
|
|
221
|
+
typename Logic::template bitvec<160> hash_bits;
|
|
222
|
+
size_t bit_idx = 0;
|
|
223
|
+
|
|
224
|
+
// Iterate H4 down to H0 to construct the hash value as a little-endian bit
|
|
225
|
+
// sequence corresponding to the big-endian numeric value of the hash. H4's
|
|
226
|
+
// most significant byte (index 3) is the LSB of the numeric value.
|
|
227
|
+
for (int i = 4; i >= 0; --i) {
|
|
228
|
+
v32 word = sha_.bp_.unpack_v32(w.ripemd.h_out[i]);
|
|
229
|
+
for (int b = 3; b >= 0; --b) {
|
|
230
|
+
for (size_t j = 0; j < 8; ++j) {
|
|
231
|
+
hash_bits[bit_idx++] = word[b * 8 + j];
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
EltW hash_val = as_scalar_large(hash_bits);
|
|
237
|
+
|
|
238
|
+
lc_.assert_eq(addr_elt, hash_val);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
private:
|
|
242
|
+
const Logic& lc_;
|
|
243
|
+
Ecpk<Logic, Field, EC> ecpk_;
|
|
244
|
+
ShaCircuit sha_;
|
|
245
|
+
RipemdCircuit ripemd_;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
} // namespace proofs
|
|
249
|
+
|
|
250
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_TESTS_PQ_BITADDR_BITADDR_H_
|
|
@@ -0,0 +1,333 @@
|
|
|
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/pq/bitaddr/bitaddr.h"
|
|
16
|
+
|
|
17
|
+
#include <array>
|
|
18
|
+
#include <cstddef>
|
|
19
|
+
#include <cstdint>
|
|
20
|
+
#include <memory>
|
|
21
|
+
#include <vector>
|
|
22
|
+
|
|
23
|
+
#include "algebra/crt.h"
|
|
24
|
+
#include "algebra/crt_convolution.h"
|
|
25
|
+
#include "algebra/reed_solomon.h"
|
|
26
|
+
#include "arrays/dense.h"
|
|
27
|
+
#include "circuits/compiler/circuit_dump.h"
|
|
28
|
+
#include "circuits/compiler/compiler.h"
|
|
29
|
+
#include "circuits/logic/bit_plucker_encoder.h"
|
|
30
|
+
#include "circuits/logic/compiler_backend.h"
|
|
31
|
+
#include "circuits/logic/evaluation_backend.h"
|
|
32
|
+
#include "circuits/logic/logic.h"
|
|
33
|
+
#include "circuits/tests/pq/bitaddr/bitaddr_witness.h"
|
|
34
|
+
#include "ec/p256k1.h"
|
|
35
|
+
#include "random/secure_random_engine.h"
|
|
36
|
+
#include "random/transcript.h"
|
|
37
|
+
#include "sumcheck/circuit.h"
|
|
38
|
+
#include "util/log.h"
|
|
39
|
+
#include "util/panic.h"
|
|
40
|
+
#include "util/readbuffer.h"
|
|
41
|
+
#include "zk/zk_proof.h"
|
|
42
|
+
#include "zk/zk_prover.h"
|
|
43
|
+
#include "zk/zk_testing.h"
|
|
44
|
+
#include "zk/zk_verifier.h"
|
|
45
|
+
#include "benchmark/benchmark.h"
|
|
46
|
+
#include "gtest/gtest.h"
|
|
47
|
+
|
|
48
|
+
namespace proofs {
|
|
49
|
+
namespace {
|
|
50
|
+
|
|
51
|
+
using Field = Fp256k1Base;
|
|
52
|
+
using EC = P256k1;
|
|
53
|
+
using CompilerBackendType = CompilerBackend<Field>;
|
|
54
|
+
using LogicType = Logic<Field, CompilerBackendType>;
|
|
55
|
+
using EltW = typename LogicType::EltW;
|
|
56
|
+
using CircuitType = BitaddrCircuit<LogicType>;
|
|
57
|
+
using WitnessHelper = BitaddrWitness;
|
|
58
|
+
|
|
59
|
+
struct BitaddrTestCase {
|
|
60
|
+
const char* secret_key_hex;
|
|
61
|
+
const char* address_hex;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const BitaddrTestCase kBitaddrTestCases[] = {
|
|
65
|
+
{"0x9FE33A7A06BD0FE6F5208A61991C49B5B4DD12DC42D9903E789F5118F9675030",
|
|
66
|
+
"0xE30798BD7D0193D12F3F6FEA6D9FF6FEAA2AC721"},
|
|
67
|
+
{"0x8c6d70fb57790757d9047916962f90a16823ca87803a3915152865768565251d",
|
|
68
|
+
"0x229c2b46a1cc631f0733b4baf6037ff2cbdf39c1"},
|
|
69
|
+
{"0x73a6e34a2a5d783bed323a9d241945ed3e7038f1923aad669e651405ad44192f",
|
|
70
|
+
"0x94eff2102af4714cc85ed9059936994ace60c114"},
|
|
71
|
+
{"0x4a48b0d30c0e4df943f799c115164d1790a29cfb938b8089fcca353f97c75785",
|
|
72
|
+
"0x18c0a6ec42aaa4e2041d27bb1c832c8bf264127d"},
|
|
73
|
+
{"0x9554dca942a256e6baddeaf55e9877a60d5b0af1175a0b619f1a95b7f4a3e3e2",
|
|
74
|
+
"0xcb74d73967375d038117292d33e36e7812a37c89"},
|
|
75
|
+
{"0x919bae1e9ab4ad1df400cf21a2939acc3bc2214d30a437c4f0542f9f16bdb05e",
|
|
76
|
+
"0x58e0b8a4f94ac1ba44f1b7598c3ef024c7956670"},
|
|
77
|
+
{"0x40c43276d55b76153c82c8a37521ebed2c0a6b2ab0733362254b94b6299598c4",
|
|
78
|
+
"0x204e544155507a4ee3ca7a2c8e13669e52b2b999"},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
std::unique_ptr<Circuit<Field>> make_circuit() {
|
|
82
|
+
QuadCircuit<Field> Q(p256k1_base);
|
|
83
|
+
const CompilerBackendType cbk(&Q);
|
|
84
|
+
const LogicType lc(&cbk, p256k1_base);
|
|
85
|
+
CircuitType circuit(lc);
|
|
86
|
+
|
|
87
|
+
EltW addr = lc.eltw_input();
|
|
88
|
+
|
|
89
|
+
Q.private_input();
|
|
90
|
+
typename CircuitType::Witness w;
|
|
91
|
+
w.input(lc);
|
|
92
|
+
|
|
93
|
+
circuit.assert_bitaddr(addr, w);
|
|
94
|
+
return Q.mkcircuit(1);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Uses a fixed basis of primes to compute a convolution for 64--521 bit values.
|
|
98
|
+
// The CRT class must use the same Field in its definition.
|
|
99
|
+
template <class Field, class CRT>
|
|
100
|
+
void run_test_zk(const Circuit<Field>& circuit, Dense<Field>& W,
|
|
101
|
+
const Dense<Field>& pub, const Field& base) {
|
|
102
|
+
// Build the relevant algebra objects.
|
|
103
|
+
using CrtConvolutionFactory = CrtConvolutionFactory<CRT, Field>;
|
|
104
|
+
using RSFactory = ReedSolomonFactory<Field, CrtConvolutionFactory>;
|
|
105
|
+
|
|
106
|
+
const CrtConvolutionFactory fft(base);
|
|
107
|
+
const RSFactory rsf(fft, base);
|
|
108
|
+
|
|
109
|
+
ZkProof<Field> zkpr(circuit, kLigeroRate, kLigeroNreq);
|
|
110
|
+
|
|
111
|
+
Transcript tp((uint8_t*)"zk_test", 7, kVersion);
|
|
112
|
+
SecureRandomEngine rng;
|
|
113
|
+
ZkProver<Field, RSFactory> prover(circuit, base, rsf);
|
|
114
|
+
prover.commit(zkpr, W, tp, rng);
|
|
115
|
+
EXPECT_TRUE(prover.prove(zkpr, W, tp));
|
|
116
|
+
|
|
117
|
+
// ======= run verifier =============
|
|
118
|
+
// Re-parse the proof to simulate a different client.
|
|
119
|
+
std::vector<uint8_t> zbuf;
|
|
120
|
+
zkpr.write(zbuf, base);
|
|
121
|
+
ZkProof<Field> zkpv(circuit, kLigeroRate, kLigeroNreq);
|
|
122
|
+
ReadBuffer rb(zbuf);
|
|
123
|
+
EXPECT_TRUE(zkpv.read(rb, base));
|
|
124
|
+
|
|
125
|
+
ZkVerifier<Field, RSFactory> verifier(circuit, rsf, kLigeroRate, kLigeroNreq,
|
|
126
|
+
base);
|
|
127
|
+
Transcript tv((uint8_t*)"zk_test", 7, kVersion);
|
|
128
|
+
verifier.recv_commitment(zkpv, tv);
|
|
129
|
+
EXPECT_TRUE(verifier.verify(zkpv, pub, tv));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
void fill_input(Dense<Field>& W, bool prover,
|
|
133
|
+
const BitaddrTestCase& test_case) {
|
|
134
|
+
DenseFiller<Field> filler(W);
|
|
135
|
+
filler.push_back(p256k1_base.one());
|
|
136
|
+
|
|
137
|
+
auto sk_opt = Field::N::of_untrusted_string(test_case.secret_key_hex);
|
|
138
|
+
EXPECT_TRUE(sk_opt.has_value());
|
|
139
|
+
typename Field::N sk = *sk_opt;
|
|
140
|
+
|
|
141
|
+
auto addr_opt = Field::N::of_untrusted_string(test_case.address_hex);
|
|
142
|
+
EXPECT_TRUE(addr_opt.has_value());
|
|
143
|
+
typename Field::N addr_n = *addr_opt;
|
|
144
|
+
|
|
145
|
+
filler.push_back(p256k1_base.of_scalar_field(addr_n));
|
|
146
|
+
|
|
147
|
+
if (prover) {
|
|
148
|
+
WitnessHelper w(p256k1_base);
|
|
149
|
+
EXPECT_TRUE(w.compute_witness(sk));
|
|
150
|
+
w.fill_witness(filler);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
TEST(BitaddrTest, ZkProverVerifier) {
|
|
155
|
+
auto CIRCUIT = make_circuit();
|
|
156
|
+
auto W = std::make_unique<Dense<Field>>(1, CIRCUIT->ninputs);
|
|
157
|
+
fill_input(*W, true, kBitaddrTestCases[0]);
|
|
158
|
+
|
|
159
|
+
auto pub = std::make_unique<Dense<Field>>(1, CIRCUIT->npub_in);
|
|
160
|
+
fill_input(*pub, false, kBitaddrTestCases[0]);
|
|
161
|
+
|
|
162
|
+
run_test_zk<Field, CRT256<Field>>(*CIRCUIT, *W, *pub, p256k1_base);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
TEST(BitaddrTest, CircuitSize) {
|
|
166
|
+
QuadCircuit<Field> Q(p256k1_base);
|
|
167
|
+
const CompilerBackendType cbk(&Q);
|
|
168
|
+
const LogicType lc(&cbk, p256k1_base);
|
|
169
|
+
CircuitType circuit(lc);
|
|
170
|
+
|
|
171
|
+
EltW addr = lc.eltw_input();
|
|
172
|
+
|
|
173
|
+
Q.private_input();
|
|
174
|
+
typename CircuitType::Witness w;
|
|
175
|
+
w.input(lc);
|
|
176
|
+
|
|
177
|
+
circuit.assert_bitaddr(addr, w);
|
|
178
|
+
auto CIRCUIT = Q.mkcircuit(1);
|
|
179
|
+
dump_info("bitaddr", Q);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
TEST(BitaddrTest, LogicEvaluation) {
|
|
183
|
+
// 1. Setup Backend
|
|
184
|
+
using EvalBackend = EvaluationBackend<Field>;
|
|
185
|
+
using LogicEval = Logic<Field, EvalBackend>;
|
|
186
|
+
using CircuitEval = BitaddrCircuit<LogicEval>;
|
|
187
|
+
using WitnessEval = typename CircuitEval::Witness;
|
|
188
|
+
|
|
189
|
+
// Use true (default) to crash on assertion failure and get stack trace
|
|
190
|
+
EvalBackend ebk(p256k1_base);
|
|
191
|
+
LogicEval lc(&ebk, p256k1_base);
|
|
192
|
+
CircuitEval circuit(lc);
|
|
193
|
+
BitPluckerEncoder<Field, 2> enc(p256k1_base);
|
|
194
|
+
|
|
195
|
+
// 2. Generate Witness Values
|
|
196
|
+
for (const auto& test_case : kBitaddrTestCases) {
|
|
197
|
+
auto sk_opt = Field::N::of_untrusted_string(test_case.secret_key_hex);
|
|
198
|
+
check(sk_opt.has_value(), "failed to parse sk");
|
|
199
|
+
typename Field::N sk = *sk_opt;
|
|
200
|
+
|
|
201
|
+
auto addr_opt = Field::N::of_untrusted_string(test_case.address_hex);
|
|
202
|
+
check(addr_opt.has_value(), "failed to parse addr");
|
|
203
|
+
typename Field::N addr_n = *addr_opt;
|
|
204
|
+
|
|
205
|
+
// Fill witness
|
|
206
|
+
using WitnessHelper = BitaddrWitness;
|
|
207
|
+
WitnessHelper witness(p256k1_base);
|
|
208
|
+
ASSERT_TRUE(witness.compute_witness(sk));
|
|
209
|
+
|
|
210
|
+
// Because this is eval, convert the witness to logic witness manually.
|
|
211
|
+
WitnessEval cw;
|
|
212
|
+
for (size_t i = 0; i < EC::kBits; ++i) {
|
|
213
|
+
cw.ecpk.bits[i] = lc.konst(witness.ecpk_.bits_[i]);
|
|
214
|
+
if (i < EC::kBits - 1) {
|
|
215
|
+
cw.ecpk.int_x[i] = lc.konst(witness.ecpk_.int_x_[i]);
|
|
216
|
+
cw.ecpk.int_y[i] = lc.konst(witness.ecpk_.int_y_[i]);
|
|
217
|
+
cw.ecpk.int_z[i] = lc.konst(witness.ecpk_.int_z_[i]);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
cw.pk_x = lc.konst(witness.pkx_);
|
|
222
|
+
cw.pk_y = lc.konst(witness.pky_);
|
|
223
|
+
|
|
224
|
+
auto nx = p256k1_base.from_montgomery(witness.pkx_);
|
|
225
|
+
auto ny = p256k1_base.from_montgomery(witness.pky_);
|
|
226
|
+
|
|
227
|
+
for (size_t i = 0; i < EC::kBits; ++i) {
|
|
228
|
+
cw.pk_x_bits[i] = LogicEval::BitW(
|
|
229
|
+
lc.konst(p256k1_base.of_scalar(nx.bit(i))), p256k1_base);
|
|
230
|
+
cw.pk_y_bits[i] = LogicEval::BitW(
|
|
231
|
+
lc.konst(p256k1_base.of_scalar(ny.bit(i))), p256k1_base);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
auto to_packed = [&](uint32_t val) {
|
|
235
|
+
auto packed_arr = enc.mkpacked_v32(val);
|
|
236
|
+
typename LogicEval::EltW packed[16];
|
|
237
|
+
for (size_t k = 0; k < 16; ++k) {
|
|
238
|
+
packed[k] = lc.konst(packed_arr[k]);
|
|
239
|
+
}
|
|
240
|
+
return std::to_array(packed);
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
for (int k = 0; k < 48; ++k)
|
|
244
|
+
cw.sha.outw[k] = to_packed(witness.sha_.outw[k]);
|
|
245
|
+
for (int k = 0; k < 64; ++k)
|
|
246
|
+
cw.sha.oute[k] = to_packed(witness.sha_.oute[k]);
|
|
247
|
+
for (int k = 0; k < 64; ++k)
|
|
248
|
+
cw.sha.outa[k] = to_packed(witness.sha_.outa[k]);
|
|
249
|
+
for (int k = 0; k < 8; ++k) cw.sha.h1[k] = to_packed(witness.sha_.h1[k]);
|
|
250
|
+
|
|
251
|
+
for (int k = 0; k < 80; ++k)
|
|
252
|
+
cw.ripemd.left_temp[k] = to_packed(witness.ripemd_.left_temp[k]);
|
|
253
|
+
for (int k = 0; k < 80; ++k)
|
|
254
|
+
cw.ripemd.left_calc[k] = to_packed(witness.ripemd_.left_calc[k]);
|
|
255
|
+
for (int k = 0; k < 80; ++k)
|
|
256
|
+
cw.ripemd.right_temp[k] = to_packed(witness.ripemd_.right_temp[k]);
|
|
257
|
+
for (int k = 0; k < 80; ++k)
|
|
258
|
+
cw.ripemd.right_calc[k] = to_packed(witness.ripemd_.right_calc[k]);
|
|
259
|
+
for (int k = 0; k < 5; ++k)
|
|
260
|
+
cw.ripemd.h_out[k] = to_packed(witness.ripemd_.h_out[k]);
|
|
261
|
+
|
|
262
|
+
typename EvalBackend::V addr_v(p256k1_base.of_scalar_field(addr_n));
|
|
263
|
+
circuit.assert_bitaddr(addr_v, cw);
|
|
264
|
+
|
|
265
|
+
EXPECT_FALSE(ebk.assertion_failed());
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// ===================== Benchmarks ==============================
|
|
270
|
+
|
|
271
|
+
void BM_BitaddrProver(benchmark::State& state) {
|
|
272
|
+
set_log_level(LogLevel::ERROR);
|
|
273
|
+
auto CIRCUIT = make_circuit();
|
|
274
|
+
auto W = std::make_unique<Dense<Field>>(1, CIRCUIT->ninputs);
|
|
275
|
+
fill_input(*W, true, kBitaddrTestCases[0]);
|
|
276
|
+
|
|
277
|
+
using Crt = CRT256<Field>;
|
|
278
|
+
using ConvolutionFactory = CrtConvolutionFactory<Crt, Field>;
|
|
279
|
+
using RSFactory = ReedSolomonFactory<Field, ConvolutionFactory>;
|
|
280
|
+
|
|
281
|
+
const ConvolutionFactory fft(p256k1_base);
|
|
282
|
+
const RSFactory rsf(fft, p256k1_base);
|
|
283
|
+
|
|
284
|
+
Transcript tp((uint8_t*)"bench_prover", 12, kVersion);
|
|
285
|
+
SecureRandomEngine rng;
|
|
286
|
+
|
|
287
|
+
ZkProof<Field> zkpr(*CIRCUIT, kLigeroRate, kLigeroNreq);
|
|
288
|
+
ZkProver<Field, RSFactory> prover(*CIRCUIT, p256k1_base, rsf);
|
|
289
|
+
|
|
290
|
+
for (auto s : state) {
|
|
291
|
+
prover.commit(zkpr, *W, tp, rng);
|
|
292
|
+
EXPECT_TRUE(prover.prove(zkpr, *W, tp));
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
BENCHMARK(BM_BitaddrProver);
|
|
296
|
+
|
|
297
|
+
void BM_BitaddrVerifier(benchmark::State& state) {
|
|
298
|
+
set_log_level(LogLevel::ERROR);
|
|
299
|
+
auto CIRCUIT = make_circuit();
|
|
300
|
+
auto W = std::make_unique<Dense<Field>>(1, CIRCUIT->ninputs);
|
|
301
|
+
fill_input(*W, true, kBitaddrTestCases[0]);
|
|
302
|
+
|
|
303
|
+
using Crt = CRT256<Field>;
|
|
304
|
+
using ConvolutionFactory = CrtConvolutionFactory<Crt, Field>;
|
|
305
|
+
using RSFactory = ReedSolomonFactory<Field, ConvolutionFactory>;
|
|
306
|
+
|
|
307
|
+
const ConvolutionFactory fft(p256k1_base);
|
|
308
|
+
const RSFactory rsf(fft, p256k1_base);
|
|
309
|
+
|
|
310
|
+
Transcript tp((uint8_t*)"bench_verifier", 14, kVersion);
|
|
311
|
+
SecureRandomEngine rng;
|
|
312
|
+
|
|
313
|
+
ZkProof<Field> zkpr(*CIRCUIT, kLigeroRate, kLigeroNreq);
|
|
314
|
+
ZkProver<Field, RSFactory> prover(*CIRCUIT, p256k1_base, rsf);
|
|
315
|
+
prover.commit(zkpr, *W, tp, rng);
|
|
316
|
+
EXPECT_TRUE(prover.prove(zkpr, *W, tp));
|
|
317
|
+
|
|
318
|
+
ZkVerifier<Field, RSFactory> verifier(*CIRCUIT, rsf, kLigeroRate, kLigeroNreq,
|
|
319
|
+
p256k1_base);
|
|
320
|
+
auto pub = std::make_unique<Dense<Field>>(1, CIRCUIT->npub_in);
|
|
321
|
+
fill_input(*pub, false, kBitaddrTestCases[0]);
|
|
322
|
+
|
|
323
|
+
for (auto s : state) {
|
|
324
|
+
Transcript tv((uint8_t*)"bench_verifier", 14, kVersion);
|
|
325
|
+
verifier.recv_commitment(zkpr, tv);
|
|
326
|
+
EXPECT_TRUE(verifier.verify(zkpr, *pub, tv));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
BENCHMARK(BM_BitaddrVerifier);
|
|
330
|
+
|
|
331
|
+
} // namespace
|
|
332
|
+
|
|
333
|
+
} // namespace proofs
|