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,143 @@
|
|
|
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_MDOC_MDOC_SIGNATURE_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_SIGNATURE_H_
|
|
17
|
+
|
|
18
|
+
#include <cstddef>
|
|
19
|
+
|
|
20
|
+
#include "circuits/ecdsa/verify_circuit.h"
|
|
21
|
+
#include "circuits/logic/bit_plucker.h"
|
|
22
|
+
#include "circuits/mac/mac_circuit.h"
|
|
23
|
+
|
|
24
|
+
namespace proofs {
|
|
25
|
+
|
|
26
|
+
// This class creates a circuit to verify the signatures in an MDOC.
|
|
27
|
+
// There are 2 signatures:
|
|
28
|
+
// 1. A signature on the MSO by the issuer of the MDOC: The public
|
|
29
|
+
// key of the issuer is given as input for now. Later, it can be
|
|
30
|
+
// one among a list of issuers. While the signer is public, the
|
|
31
|
+
// message is private, and thus its hash is committed in the witness.
|
|
32
|
+
// 2. A signature on the transcript provided during a "Show" operation:
|
|
33
|
+
// the signature is under a device public key that is specified in the
|
|
34
|
+
// MSO. Thus, the signing key is private (and committed), but the
|
|
35
|
+
// message is public.
|
|
36
|
+
template <class LogicCircuit, class Field, class EC>
|
|
37
|
+
class MdocSignature {
|
|
38
|
+
using EltW = typename LogicCircuit::EltW;
|
|
39
|
+
using Elt = typename LogicCircuit::Elt;
|
|
40
|
+
using Nat = typename Field::N;
|
|
41
|
+
using v128 = typename LogicCircuit::v128;
|
|
42
|
+
using v256 = typename LogicCircuit::v256;
|
|
43
|
+
using Ecdsa = VerifyCircuit<LogicCircuit, Field, EC>;
|
|
44
|
+
using EcdsaWitness = typename Ecdsa::Witness;
|
|
45
|
+
using MacBitPlucker = BitPlucker<LogicCircuit, kMACPluckerBits>;
|
|
46
|
+
using packed_v256 = typename MacBitPlucker::packed_v256;
|
|
47
|
+
using mac = MAC<LogicCircuit, MacBitPlucker>;
|
|
48
|
+
using MACWitness = typename mac::Witness;
|
|
49
|
+
|
|
50
|
+
const LogicCircuit& lc_;
|
|
51
|
+
const EC& ec_;
|
|
52
|
+
const Nat& order_;
|
|
53
|
+
|
|
54
|
+
public:
|
|
55
|
+
class Witness {
|
|
56
|
+
public:
|
|
57
|
+
EltW e_;
|
|
58
|
+
EltW dpkx_, dpky_;
|
|
59
|
+
|
|
60
|
+
EcdsaWitness mdoc_sig_;
|
|
61
|
+
EcdsaWitness dpk_sig_;
|
|
62
|
+
MACWitness macs_[3];
|
|
63
|
+
|
|
64
|
+
void input(const LogicCircuit& lc) {
|
|
65
|
+
e_ = lc.eltw_input();
|
|
66
|
+
dpkx_ = lc.eltw_input();
|
|
67
|
+
dpky_ = lc.eltw_input();
|
|
68
|
+
|
|
69
|
+
mdoc_sig_.input(lc);
|
|
70
|
+
dpk_sig_.input(lc);
|
|
71
|
+
for (size_t i = 0; i < 3; ++i) {
|
|
72
|
+
macs_[i].input(lc);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
explicit MdocSignature(const LogicCircuit& lc, const EC& ec, const Nat& order)
|
|
78
|
+
: lc_(lc), ec_(ec), order_(order) {}
|
|
79
|
+
|
|
80
|
+
// This function is used to verify the signatures in an MDOC.
|
|
81
|
+
// The circuit verifies the following claims:
|
|
82
|
+
// 1. There exists a hash digest e and a signature (r,s) on e
|
|
83
|
+
// under the public key (pkX, pkY).
|
|
84
|
+
// 2. The MAC of e under the secret mac key (a_v+a_pe) is mac_e.
|
|
85
|
+
// 3. There exists a device public key (dpkX, dpky) and a signature (r,s)
|
|
86
|
+
// on the value hash_tr.
|
|
87
|
+
// 4. The MAC of the device public key (dpkX, dpky) under the secret MAC
|
|
88
|
+
// key (a_v + apdk) is mac_dkpX and mac_dpkY respectively.
|
|
89
|
+
void assert_signatures(EltW pkX, EltW pkY, EltW hash_tr, v128 mac_e[2],
|
|
90
|
+
v128 mac_dpkX[2], v128 mac_dpkY[2], const v128& a_v,
|
|
91
|
+
Witness& vw) const {
|
|
92
|
+
Ecdsa ecc(lc_, ec_, order_);
|
|
93
|
+
mac macc(lc_);
|
|
94
|
+
|
|
95
|
+
ecc.verify_signature3(pkX, pkY, vw.e_, vw.mdoc_sig_);
|
|
96
|
+
ecc.verify_signature3(vw.dpkx_, vw.dpky_, hash_tr, vw.dpk_sig_);
|
|
97
|
+
|
|
98
|
+
macc.verify_mac(vw.e_, mac_e, a_v, vw.macs_[0], order_);
|
|
99
|
+
macc.verify_mac(vw.dpkx_, mac_dpkX, a_v, vw.macs_[1], order_);
|
|
100
|
+
macc.verify_mac(vw.dpky_, mac_dpkY, a_v, vw.macs_[2], order_);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// This function is similar to assert_signatures, but it also hides the
|
|
104
|
+
// public key of the issuer. Instead, it verifies that the issuer's public
|
|
105
|
+
// key belongs in a list of 50 public keys that are supplied as input. The
|
|
106
|
+
// issuer pk lists are assumed to be trusted inputs, i.e., it is the
|
|
107
|
+
// caller's responsibility to ensure that (issuer_pkX[i], issuer_pkY[i]) is
|
|
108
|
+
// a valid curve point for i=0..49. The caller is also responsible for
|
|
109
|
+
// ensuring that issuer_pkY[i] != -issuer_pkY[j] for i != j.
|
|
110
|
+
// However, it is OK for the caller to repeat the same key in the list.
|
|
111
|
+
void assert_signatures_with_issuer_list(
|
|
112
|
+
EltW hash_tr, v128 mac_e[2], v128 mac_dpkX[2], v128 mac_dpkY[2],
|
|
113
|
+
const v128& a_v, EltW issuer_pkX[/*max_issuers*/],
|
|
114
|
+
EltW issuer_pkY[/*max_issuers*/], size_t max_issuers,
|
|
115
|
+
// private inputs begin here
|
|
116
|
+
EltW pkX, EltW pkY, Witness& vw) const {
|
|
117
|
+
assert_signatures(pkX, pkY, hash_tr, mac_e, mac_dpkX, mac_dpkY, a_v, vw);
|
|
118
|
+
|
|
119
|
+
// Verify that the issuer's public key is one of the 50 keys in the list.
|
|
120
|
+
// This is done by computing the difference between pkX and issuer_pkX[i]
|
|
121
|
+
// for i=0..49, and asserting that the product of the differences is zero.
|
|
122
|
+
//
|
|
123
|
+
// We argue that it suffices to verify that pkX is on the list and pkY is
|
|
124
|
+
// on the list independently. Suppose a malicious prover sets pkX to be
|
|
125
|
+
// equal to the j-th key in issuer_pkX and sets pkY to be the k-th key in
|
|
126
|
+
// issuer_pkY, where j != k. If (pkX, pkY) is not a curve point, then the
|
|
127
|
+
// assert_signatures() routine will fail. However, for each X on the curve,
|
|
128
|
+
// there are only 2 possible Y values, namely, +-Y. By the constraints
|
|
129
|
+
// imposed on issuer_pkY, we know that issuer_pkY[j] is on the curve, and
|
|
130
|
+
// that -issuer_pkY[j] does not occur in the issuer_pkY list. Thus, it is
|
|
131
|
+
// not possible for a witness to pass all checks and for k != j.
|
|
132
|
+
EltW goodXKey = lc_.mul(
|
|
133
|
+
0, max_issuers, [&](size_t i) { return lc_.sub(issuer_pkX[i], pkX); });
|
|
134
|
+
lc_.assert0(goodXKey);
|
|
135
|
+
|
|
136
|
+
EltW goodYKey = lc_.mul(
|
|
137
|
+
0, max_issuers, [&](size_t i) { return lc_.sub(issuer_pkY[i], pkY); });
|
|
138
|
+
lc_.assert0(goodYKey);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
} // namespace proofs
|
|
142
|
+
|
|
143
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_SIGNATURE_H_
|
|
@@ -0,0 +1,444 @@
|
|
|
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/mdoc/mdoc_signature.h"
|
|
16
|
+
|
|
17
|
+
#include <stdint.h>
|
|
18
|
+
|
|
19
|
+
#include <cstddef>
|
|
20
|
+
#include <memory>
|
|
21
|
+
#include <vector>
|
|
22
|
+
|
|
23
|
+
#include "algebra/fp_p128.h"
|
|
24
|
+
#include "arrays/dense.h"
|
|
25
|
+
#include "circuits/compiler/circuit_dump.h"
|
|
26
|
+
#include "circuits/compiler/compiler.h"
|
|
27
|
+
#include "circuits/logic/compiler_backend.h"
|
|
28
|
+
#include "circuits/logic/logic.h"
|
|
29
|
+
#include "circuits/mac/mac_reference.h"
|
|
30
|
+
#include "circuits/mdoc/mdoc_examples.h"
|
|
31
|
+
#include "circuits/mdoc/mdoc_hash.h"
|
|
32
|
+
#include "circuits/mdoc/mdoc_test_attributes.h"
|
|
33
|
+
#include "circuits/mdoc/mdoc_witness.h"
|
|
34
|
+
#include "circuits/mdoc/mdoc_zk.h"
|
|
35
|
+
#include "ec/p256.h"
|
|
36
|
+
#include "gf2k/gf2_128.h"
|
|
37
|
+
#include "random/secure_random_engine.h"
|
|
38
|
+
#include "sumcheck/circuit.h"
|
|
39
|
+
#include "util/log.h"
|
|
40
|
+
#include "util/panic.h"
|
|
41
|
+
#include "zk/zk_testing.h"
|
|
42
|
+
#include "gtest/gtest.h"
|
|
43
|
+
|
|
44
|
+
namespace proofs {
|
|
45
|
+
namespace {
|
|
46
|
+
/*
|
|
47
|
+
For Mdoc, we only need to be testing on P256, so we can
|
|
48
|
+
declare these types globally.
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
// For now, mac is chosen here.
|
|
52
|
+
using gf2k = GF2_128<>::Elt;
|
|
53
|
+
|
|
54
|
+
TEST(mdoc, mdoc_signature_test) {
|
|
55
|
+
using MdocSw = MdocSignatureWitness<P256, Fp256Scalar>;
|
|
56
|
+
using Elt = Fp256Base::Elt;
|
|
57
|
+
|
|
58
|
+
set_log_level(INFO);
|
|
59
|
+
|
|
60
|
+
std::unique_ptr<Circuit<Fp256Base>> CIRCUIT;
|
|
61
|
+
|
|
62
|
+
// ======== compile time =========================
|
|
63
|
+
{
|
|
64
|
+
using CompilerBackend = CompilerBackend<Fp256Base>;
|
|
65
|
+
using LogicCircuit = Logic<Fp256Base, CompilerBackend>;
|
|
66
|
+
using EltW = LogicCircuit::EltW;
|
|
67
|
+
using v128 = LogicCircuit::v128;
|
|
68
|
+
using MdocSig = MdocSignature<LogicCircuit, Fp256Base, P256>;
|
|
69
|
+
QuadCircuit<Fp256Base> Q(p256_base);
|
|
70
|
+
const CompilerBackend cbk(&Q);
|
|
71
|
+
const LogicCircuit LC(&cbk, p256_base);
|
|
72
|
+
|
|
73
|
+
MdocSig mdoc_sig(LC, p256, n256_order);
|
|
74
|
+
|
|
75
|
+
EltW pkX = LC.eltw_input(), pkY = LC.eltw_input(), htr = LC.eltw_input();
|
|
76
|
+
v128 emac[2] = {LC.vinput<128>(), LC.vinput<128>()};
|
|
77
|
+
v128 xmac[2] = {LC.vinput<128>(), LC.vinput<128>()};
|
|
78
|
+
v128 ymac[2] = {LC.vinput<128>(), LC.vinput<128>()};
|
|
79
|
+
|
|
80
|
+
v128 a_v = LC.vinput<128>();
|
|
81
|
+
Q.private_input();
|
|
82
|
+
|
|
83
|
+
MdocSig::Witness vwc;
|
|
84
|
+
vwc.input(LC);
|
|
85
|
+
|
|
86
|
+
mdoc_sig.assert_signatures(pkX, pkY, htr, emac, xmac, ymac, a_v, vwc);
|
|
87
|
+
|
|
88
|
+
CIRCUIT = Q.mkcircuit(/*nc=*/1);
|
|
89
|
+
dump_info("mdoc signature", Q);
|
|
90
|
+
log(INFO, "Compile done");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ======== Witness
|
|
94
|
+
// Generate a witness from the mdoc data structure to remain close
|
|
95
|
+
// to the application use case.
|
|
96
|
+
GF2_128<> gf;
|
|
97
|
+
gf2k ap[6], mac[6];
|
|
98
|
+
gf2k av = gf.of_scalar_field(2983471870111);
|
|
99
|
+
Elt pkX, pkY;
|
|
100
|
+
MdocSw sw(p256, p256_scalar, gf);
|
|
101
|
+
|
|
102
|
+
{
|
|
103
|
+
constexpr size_t t_ind = 2;
|
|
104
|
+
const uint8_t* mdoc = mdoc_tests[t_ind].mdoc;
|
|
105
|
+
pkX = p256_base.of_string(mdoc_tests[t_ind].pkx);
|
|
106
|
+
pkY = p256_base.of_string(mdoc_tests[t_ind].pky);
|
|
107
|
+
MdocProverErrorCode ok = sw.compute_witness(
|
|
108
|
+
pkX, pkY, mdoc, mdoc_tests[t_ind].mdoc_size,
|
|
109
|
+
mdoc_tests[t_ind].transcript, mdoc_tests[t_ind].transcript_size);
|
|
110
|
+
|
|
111
|
+
check(ok == MDOC_PROVER_SUCCESS, "Could not compute signature witness");
|
|
112
|
+
|
|
113
|
+
MACReference<GF2_128<>> mac_ref;
|
|
114
|
+
|
|
115
|
+
// Should be chosen by prover and added to commitment.
|
|
116
|
+
SecureRandomEngine rng;
|
|
117
|
+
mac_ref.sample(ap, 6, &rng);
|
|
118
|
+
|
|
119
|
+
// This value is chosen after the prover commits.
|
|
120
|
+
uint8_t buf[Fp256Base::kBytes];
|
|
121
|
+
|
|
122
|
+
Elt tt[3] = {sw.e_, sw.dpkx_, sw.dpky_};
|
|
123
|
+
for (size_t i = 0; i < 3; ++i) {
|
|
124
|
+
p256_base.to_bytes_field(buf, tt[i]);
|
|
125
|
+
sw.macs_[i].compute_witness(&ap[2 * i], buf);
|
|
126
|
+
mac_ref.compute(&mac[2 * i], av, &ap[2 * i], buf);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
log(INFO, "Witness done");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// ========= Fill witness
|
|
133
|
+
auto W = Dense<Fp256Base>(1, CIRCUIT->ninputs);
|
|
134
|
+
auto pub = Dense<Fp256Base>(1, CIRCUIT->npub_in);
|
|
135
|
+
DenseFiller<Fp256Base> filler(W);
|
|
136
|
+
DenseFiller<Fp256Base> pub_filler(pub);
|
|
137
|
+
|
|
138
|
+
filler.push_back(p256_base.one());
|
|
139
|
+
pub_filler.push_back(p256_base.one());
|
|
140
|
+
filler.push_back(pkX);
|
|
141
|
+
pub_filler.push_back(pkX);
|
|
142
|
+
filler.push_back(pkY);
|
|
143
|
+
pub_filler.push_back(pkY);
|
|
144
|
+
filler.push_back(sw.e2_);
|
|
145
|
+
pub_filler.push_back(sw.e2_);
|
|
146
|
+
|
|
147
|
+
for (size_t i = 0; i < 6; ++i) {
|
|
148
|
+
fill_gf2k<GF2_128<>, Fp256Base>(mac[i], filler, p256_base);
|
|
149
|
+
fill_gf2k<GF2_128<>, Fp256Base>(mac[i], pub_filler, p256_base);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
fill_gf2k<GF2_128<>, Fp256Base>(av, filler, p256_base);
|
|
153
|
+
fill_gf2k<GF2_128<>, Fp256Base>(av, pub_filler, p256_base);
|
|
154
|
+
|
|
155
|
+
sw.fill_witness(filler);
|
|
156
|
+
log(INFO, "Fill done");
|
|
157
|
+
|
|
158
|
+
// =========== ZK test
|
|
159
|
+
run2_test_zk(
|
|
160
|
+
*CIRCUIT, W, pub, p256_base,
|
|
161
|
+
p256_base.of_string("1126492241464102818735004576096902583730188404304894"
|
|
162
|
+
"08729223714171582664680802"), /* omega_x*/
|
|
163
|
+
p256_base.of_string("8408799435854090769574046142781866056018216899718237"
|
|
164
|
+
"8749313018254450460212908"), /* omega_y */
|
|
165
|
+
1ull << 31);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
TEST(mdoc, mdoc_issuer_list_valid) {
|
|
169
|
+
using Elt = Fp256Base::Elt;
|
|
170
|
+
// Verify the two constraints on issuer lists.
|
|
171
|
+
|
|
172
|
+
size_t sz = sizeof(kIssuerPKY) / sizeof(char*);
|
|
173
|
+
std::vector<Elt> pkY(sz);
|
|
174
|
+
for (size_t i = 0; i < sz; ++i) {
|
|
175
|
+
Elt pkX = p256_base.of_string(kIssuerPKX[i]);
|
|
176
|
+
pkY[i] = p256_base.of_string(kIssuerPKY[i]);
|
|
177
|
+
EXPECT_TRUE(p256.is_on_curve(pkX, pkY[i]));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// n^2 test ok for small n.
|
|
181
|
+
for (size_t i = 0; i < sz; ++i) {
|
|
182
|
+
for (size_t j = i + 1; j < sz; ++j) {
|
|
183
|
+
EXPECT_FALSE(pkY[i] == p256_base.negf(pkY[j]));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
TEST(mdoc, mdoc_signature_test_with_issuer_list) {
|
|
189
|
+
using MdocSw = MdocSignatureWitness<P256, Fp256Scalar>;
|
|
190
|
+
using Elt = Fp256Base::Elt;
|
|
191
|
+
|
|
192
|
+
constexpr size_t MAX_ISSUERS = 50;
|
|
193
|
+
set_log_level(INFO);
|
|
194
|
+
|
|
195
|
+
std::unique_ptr<Circuit<Fp256Base>> CIRCUIT;
|
|
196
|
+
|
|
197
|
+
// ======== compile time =========================
|
|
198
|
+
{
|
|
199
|
+
using CompilerBackend = CompilerBackend<Fp256Base>;
|
|
200
|
+
using LogicCircuit = Logic<Fp256Base, CompilerBackend>;
|
|
201
|
+
using EltW = LogicCircuit::EltW;
|
|
202
|
+
using v128 = LogicCircuit::v128;
|
|
203
|
+
using MdocSig = MdocSignature<LogicCircuit, Fp256Base, P256>;
|
|
204
|
+
QuadCircuit<Fp256Base> Q(p256_base);
|
|
205
|
+
const CompilerBackend cbk(&Q);
|
|
206
|
+
const LogicCircuit LC(&cbk, p256_base);
|
|
207
|
+
|
|
208
|
+
MdocSig mdoc_sig(LC, p256, n256_order);
|
|
209
|
+
|
|
210
|
+
// public inputs
|
|
211
|
+
EltW htr = LC.eltw_input();
|
|
212
|
+
v128 emac[2] = {LC.vinput<128>(), LC.vinput<128>()};
|
|
213
|
+
v128 xmac[2] = {LC.vinput<128>(), LC.vinput<128>()};
|
|
214
|
+
v128 ymac[2] = {LC.vinput<128>(), LC.vinput<128>()};
|
|
215
|
+
|
|
216
|
+
v128 a_v = LC.vinput<128>();
|
|
217
|
+
EltW xlist[MAX_ISSUERS], ylist[MAX_ISSUERS];
|
|
218
|
+
for (size_t i = 0; i < MAX_ISSUERS; ++i) {
|
|
219
|
+
xlist[i] = LC.eltw_input();
|
|
220
|
+
}
|
|
221
|
+
for (size_t i = 0; i < MAX_ISSUERS; ++i) {
|
|
222
|
+
ylist[i] = LC.eltw_input();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
Q.private_input();
|
|
226
|
+
EltW pkX = LC.eltw_input(), pkY = LC.eltw_input();
|
|
227
|
+
MdocSig::Witness vwc;
|
|
228
|
+
vwc.input(LC);
|
|
229
|
+
|
|
230
|
+
mdoc_sig.assert_signatures_with_issuer_list(
|
|
231
|
+
htr, emac, xmac, ymac, a_v, xlist, ylist, MAX_ISSUERS, pkX, pkY, vwc);
|
|
232
|
+
|
|
233
|
+
CIRCUIT = Q.mkcircuit(/*nc=*/1);
|
|
234
|
+
dump_info("mdoc signature_with_issuer", Q);
|
|
235
|
+
log(INFO, "Compile done");
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// ======== Witness
|
|
239
|
+
// Generate a witness from the mdoc data structure to remain close
|
|
240
|
+
// to the application use case.
|
|
241
|
+
GF2_128<> gf;
|
|
242
|
+
gf2k ap[6], mac[6];
|
|
243
|
+
gf2k av = gf.of_scalar_field(2983471870111);
|
|
244
|
+
Elt pkX, pkY;
|
|
245
|
+
Elt issuerX[MAX_ISSUERS], issuerY[MAX_ISSUERS];
|
|
246
|
+
MdocSw sw(p256, p256_scalar, gf);
|
|
247
|
+
|
|
248
|
+
{
|
|
249
|
+
constexpr size_t t_ind = 2;
|
|
250
|
+
const uint8_t* mdoc = mdoc_tests[t_ind].mdoc;
|
|
251
|
+
pkX = p256_base.of_string(mdoc_tests[t_ind].pkx);
|
|
252
|
+
pkY = p256_base.of_string(mdoc_tests[t_ind].pky);
|
|
253
|
+
MdocProverErrorCode ok = sw.compute_witness(
|
|
254
|
+
pkX, pkY, mdoc, mdoc_tests[t_ind].mdoc_size,
|
|
255
|
+
mdoc_tests[t_ind].transcript, mdoc_tests[t_ind].transcript_size);
|
|
256
|
+
|
|
257
|
+
check(ok == MDOC_PROVER_SUCCESS, "Could not compute signature witness");
|
|
258
|
+
|
|
259
|
+
MACReference<GF2_128<>> mac_ref;
|
|
260
|
+
|
|
261
|
+
// Should be chosen by prover and added to commitment.
|
|
262
|
+
SecureRandomEngine rng;
|
|
263
|
+
mac_ref.sample(ap, 6, &rng);
|
|
264
|
+
|
|
265
|
+
// This value is chosen after the prover commits.
|
|
266
|
+
uint8_t buf[Fp256Base::kBytes];
|
|
267
|
+
|
|
268
|
+
Elt tt[3] = {sw.e_, sw.dpkx_, sw.dpky_};
|
|
269
|
+
for (size_t i = 0; i < 3; ++i) {
|
|
270
|
+
p256_base.to_bytes_field(buf, tt[i]);
|
|
271
|
+
sw.macs_[i].compute_witness(&ap[2 * i], buf);
|
|
272
|
+
mac_ref.compute(&mac[2 * i], av, &ap[2 * i], buf);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// It is OK to repeat the issuers.
|
|
276
|
+
size_t numIssuer = sizeof(kIssuerPKX) / sizeof(char*);
|
|
277
|
+
for (size_t i = 0; i < MAX_ISSUERS; ++i) {
|
|
278
|
+
issuerX[i] = p256_base.of_string(kIssuerPKX[i % numIssuer]);
|
|
279
|
+
issuerY[i] = p256_base.of_string(kIssuerPKY[i % numIssuer]);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
log(INFO, "Witness created");
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// ========= Fill witness
|
|
286
|
+
auto W = Dense<Fp256Base>(1, CIRCUIT->ninputs);
|
|
287
|
+
auto pub = Dense<Fp256Base>(1, CIRCUIT->npub_in);
|
|
288
|
+
DenseFiller<Fp256Base> filler(W);
|
|
289
|
+
DenseFiller<Fp256Base> pub_filler(pub);
|
|
290
|
+
|
|
291
|
+
filler.push_back(p256_base.one());
|
|
292
|
+
pub_filler.push_back(p256_base.one());
|
|
293
|
+
filler.push_back(sw.e2_);
|
|
294
|
+
pub_filler.push_back(sw.e2_);
|
|
295
|
+
|
|
296
|
+
for (size_t i = 0; i < 6; ++i) {
|
|
297
|
+
fill_gf2k<GF2_128<>, Fp256Base>(mac[i], filler, p256_base);
|
|
298
|
+
fill_gf2k<GF2_128<>, Fp256Base>(mac[i], pub_filler, p256_base);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
fill_gf2k<GF2_128<>, Fp256Base>(av, filler, p256_base);
|
|
302
|
+
fill_gf2k<GF2_128<>, Fp256Base>(av, pub_filler, p256_base);
|
|
303
|
+
|
|
304
|
+
for (size_t i = 0; i < MAX_ISSUERS; ++i) {
|
|
305
|
+
filler.push_back(issuerX[i]);
|
|
306
|
+
pub_filler.push_back(issuerX[i]);
|
|
307
|
+
}
|
|
308
|
+
for (size_t i = 0; i < MAX_ISSUERS; ++i) {
|
|
309
|
+
filler.push_back(issuerY[i]);
|
|
310
|
+
pub_filler.push_back(issuerY[i]);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
filler.push_back(pkX);
|
|
314
|
+
filler.push_back(pkY);
|
|
315
|
+
sw.fill_witness(filler);
|
|
316
|
+
log(INFO, "Fill done");
|
|
317
|
+
|
|
318
|
+
// =========== ZK test
|
|
319
|
+
run2_test_zk(
|
|
320
|
+
*CIRCUIT, W, pub, p256_base,
|
|
321
|
+
p256_base.of_string("1126492241464102818735004576096902583730188404304894"
|
|
322
|
+
"08729223714171582664680802"), /* omega_x*/
|
|
323
|
+
p256_base.of_string("8408799435854090769574046142781866056018216899718237"
|
|
324
|
+
"8749313018254450460212908"), /* omega_y */
|
|
325
|
+
1ull << 31);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
template <class Field>
|
|
329
|
+
void mdoc_hash_run(const typename Field::Elt& omega, uint64_t omega_order,
|
|
330
|
+
const Field& F, std::vector<RequestedAttribute> attrs) {
|
|
331
|
+
using MdocHw = MdocHashWitness<P256, Field>;
|
|
332
|
+
|
|
333
|
+
set_log_level(INFO);
|
|
334
|
+
|
|
335
|
+
std::unique_ptr<Circuit<Field>> CIRCUIT;
|
|
336
|
+
|
|
337
|
+
// ======== compile time =========================
|
|
338
|
+
{
|
|
339
|
+
using CompilerBackend = CompilerBackend<Field>;
|
|
340
|
+
using LogicCircuit = Logic<Field, CompilerBackend>;
|
|
341
|
+
using v8 = typename LogicCircuit::v8;
|
|
342
|
+
using v256 = typename LogicCircuit::v256;
|
|
343
|
+
using MdocHash = MdocHash<LogicCircuit, Field>;
|
|
344
|
+
QuadCircuit<Field> Q(F);
|
|
345
|
+
const CompilerBackend cbk(&Q);
|
|
346
|
+
const LogicCircuit LC(&cbk, F);
|
|
347
|
+
|
|
348
|
+
std::vector<typename MdocHash::OpenedAttribute> oa(attrs.size());
|
|
349
|
+
MdocHash mdoc_hash(LC);
|
|
350
|
+
for (size_t ai = 0; ai < attrs.size(); ++ai) {
|
|
351
|
+
oa[ai].input(LC);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
v8 now[20];
|
|
355
|
+
for (size_t i = 0; i < 20; ++i) {
|
|
356
|
+
now[i] = LC.template vinput<8>();
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
Q.private_input();
|
|
360
|
+
v256 e = LC.template vinput<256>();
|
|
361
|
+
v256 dpkx = LC.template vinput<256>();
|
|
362
|
+
v256 dpky = LC.template vinput<256>();
|
|
363
|
+
|
|
364
|
+
typename MdocHash::Witness vwc(attrs.size());
|
|
365
|
+
vwc.input(LC);
|
|
366
|
+
|
|
367
|
+
mdoc_hash.assert_valid_hash_mdoc(oa.data(), now, e, dpkx, dpky, vwc);
|
|
368
|
+
|
|
369
|
+
CIRCUIT = Q.mkcircuit(/*nc=*/1);
|
|
370
|
+
dump_info("mdoc hash and parse", Q);
|
|
371
|
+
log(INFO, "Compile done");
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// ======== Witness: use the large Canonical Playground example
|
|
375
|
+
MdocHw hw(attrs.size(), p256, F);
|
|
376
|
+
constexpr size_t t_ind = 3;
|
|
377
|
+
const uint8_t* mdoc = mdoc_tests[t_ind].mdoc;
|
|
378
|
+
|
|
379
|
+
MdocProverErrorCode ok = hw.compute_witness(
|
|
380
|
+
mdoc, mdoc_tests[t_ind].mdoc_size, mdoc_tests[t_ind].transcript,
|
|
381
|
+
mdoc_tests[t_ind].transcript_size, attrs.data(), attrs.size(),
|
|
382
|
+
7 /* version */);
|
|
383
|
+
|
|
384
|
+
check(ok == MDOC_PROVER_SUCCESS, "Could not compute hash witness");
|
|
385
|
+
|
|
386
|
+
log(INFO, "Witness done");
|
|
387
|
+
|
|
388
|
+
// ========= Fill witness
|
|
389
|
+
auto W = Dense<Field>(1, CIRCUIT->ninputs);
|
|
390
|
+
auto pub = Dense<Field>(1, CIRCUIT->npub_in);
|
|
391
|
+
DenseFiller<Field> filler(W);
|
|
392
|
+
DenseFiller<Field> pub_filler(pub);
|
|
393
|
+
filler.push_back(F.one());
|
|
394
|
+
pub_filler.push_back(F.one());
|
|
395
|
+
|
|
396
|
+
for (size_t ai = 0; ai < attrs.size(); ++ai) {
|
|
397
|
+
fill_attribute(filler, attrs[ai], F, 7 /* version */);
|
|
398
|
+
fill_attribute(pub_filler, attrs[ai], F, 7 /* version */);
|
|
399
|
+
}
|
|
400
|
+
fill_bit_string(filler, mdoc_tests[t_ind].now, 20, 20, F);
|
|
401
|
+
fill_bit_string(pub_filler, mdoc_tests[t_ind].now, 20, 20, F);
|
|
402
|
+
|
|
403
|
+
// Private inputs
|
|
404
|
+
uint8_t buf[Fp256Base::kBytes];
|
|
405
|
+
Fp256Base::Elt tt[3] = {hw.e_, hw.dpkx_, hw.dpky_};
|
|
406
|
+
for (size_t i = 0; i < 3; ++i) {
|
|
407
|
+
p256_base.to_bytes_field(buf, tt[i]);
|
|
408
|
+
fill_bit_string(filler, buf, 32, 32, F);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
hw.fill_witness(filler, 7);
|
|
412
|
+
|
|
413
|
+
log(INFO, "Fill done");
|
|
414
|
+
|
|
415
|
+
// =========== ZK prover
|
|
416
|
+
|
|
417
|
+
run_test_zk<Field>(*CIRCUIT, W, pub, omega, omega_order, F);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
TEST(mdoc, mdoc_hash_test_fp128) {
|
|
421
|
+
std::vector<RequestedAttribute> oa;
|
|
422
|
+
oa.push_back(test::age_over_18);
|
|
423
|
+
|
|
424
|
+
static const Fp128<> Fg;
|
|
425
|
+
mdoc_hash_run<Fp128<>>(
|
|
426
|
+
Fg.of_string("164956748514267535023998284330560247862"), 1ull << 32, Fg,
|
|
427
|
+
oa);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
TEST(mdoc, mdoc_hash_test_fp128_2) {
|
|
431
|
+
std::vector<RequestedAttribute> oa;
|
|
432
|
+
oa.push_back(test::age_over_18);
|
|
433
|
+
|
|
434
|
+
oa.push_back(test::familyname_mustermann);
|
|
435
|
+
oa.shrink_to_fit();
|
|
436
|
+
|
|
437
|
+
static const Fp128<> Fg;
|
|
438
|
+
mdoc_hash_run<Fp128<>>(
|
|
439
|
+
Fg.of_string("164956748514267535023998284330560247862"), 1ull << 32, Fg,
|
|
440
|
+
oa);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
} // namespace
|
|
444
|
+
} // namespace proofs
|