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,364 @@
|
|
|
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/mdoc/mdoc_1f.h"
|
|
16
|
+
|
|
17
|
+
#include <cstddef>
|
|
18
|
+
#include <cstdint>
|
|
19
|
+
#include <memory>
|
|
20
|
+
#include <utility>
|
|
21
|
+
#include <vector>
|
|
22
|
+
|
|
23
|
+
#include "algebra/convolution.h"
|
|
24
|
+
#include "algebra/fp2.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/counter.h"
|
|
32
|
+
#include "circuits/logic/evaluation_backend.h"
|
|
33
|
+
#include "circuits/logic/logic.h"
|
|
34
|
+
#include "circuits/mdoc/mdoc_constants.h"
|
|
35
|
+
#include "circuits/mdoc/mdoc_examples.h"
|
|
36
|
+
#include "circuits/mdoc/mdoc_test_attributes.h"
|
|
37
|
+
#include "circuits/mdoc/mdoc_witness.h"
|
|
38
|
+
#include "circuits/mdoc/mdoc_zk.h"
|
|
39
|
+
#include "circuits/tests/mdoc/mdoc_1f_io.h"
|
|
40
|
+
#include "circuits/tests/mdoc/mdoc_1f_witness.h"
|
|
41
|
+
#include "ec/p256.h"
|
|
42
|
+
#include "random/secure_random_engine.h"
|
|
43
|
+
#include "random/transcript.h"
|
|
44
|
+
#include "sumcheck/circuit.h"
|
|
45
|
+
#include "util/log.h"
|
|
46
|
+
#include "zk/zk_proof.h"
|
|
47
|
+
#include "zk/zk_prover.h"
|
|
48
|
+
#include "zk/zk_testing.h" // For run2_test_zk
|
|
49
|
+
#include "benchmark/benchmark.h"
|
|
50
|
+
#include "gtest/gtest.h"
|
|
51
|
+
|
|
52
|
+
namespace proofs {
|
|
53
|
+
namespace {
|
|
54
|
+
|
|
55
|
+
template <class rsigw, class csigw, class Logic>
|
|
56
|
+
void copy_sig(csigw& cw, const rsigw& rw, const Logic& L) {
|
|
57
|
+
cw.rx = L.konst(rw.rx_);
|
|
58
|
+
cw.ry = L.konst(rw.ry_);
|
|
59
|
+
cw.rx_inv = L.konst(rw.rx_inv_);
|
|
60
|
+
cw.s_inv = L.konst(rw.s_inv_);
|
|
61
|
+
cw.pk_inv = L.konst(rw.pk_inv_);
|
|
62
|
+
for (size_t i = 0; i < 8; ++i) {
|
|
63
|
+
cw.pre[i] = L.konst(rw.pre_[i]);
|
|
64
|
+
}
|
|
65
|
+
for (size_t i = 0; i < p256.kBits; ++i) {
|
|
66
|
+
cw.bi[i] = L.konst(rw.bi_[i]);
|
|
67
|
+
if (i < p256.kBits - 1) {
|
|
68
|
+
cw.int_x[i] = L.konst(rw.int_x_[i]);
|
|
69
|
+
cw.int_y[i] = L.konst(rw.int_y_[i]);
|
|
70
|
+
cw.int_z[i] = L.konst(rw.int_z_[i]);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
template <class ShaBlockWitness, class BlockWitness, class Logic>
|
|
76
|
+
void copy_sha(ShaBlockWitness sbw[], const BlockWitness bw[], const Logic& L,
|
|
77
|
+
size_t num_sha_blocks) {
|
|
78
|
+
BitPluckerEncoder<Fp256Base, kMdoc1SHAPluckerBits> BPENC(p256_base);
|
|
79
|
+
|
|
80
|
+
for (size_t i = 0; i < num_sha_blocks; ++i) {
|
|
81
|
+
for (size_t k = 0; k < 48; ++k) {
|
|
82
|
+
sbw[i].outw[k] = L.konst(BPENC.mkpacked_v32(bw[i].outw[k]));
|
|
83
|
+
}
|
|
84
|
+
for (size_t k = 0; k < 64; ++k) {
|
|
85
|
+
sbw[i].oute[k] = L.konst(BPENC.mkpacked_v32(bw[i].oute[k]));
|
|
86
|
+
sbw[i].outa[k] = L.konst(BPENC.mkpacked_v32(bw[i].outa[k]));
|
|
87
|
+
}
|
|
88
|
+
for (size_t k = 0; k < 8; ++k) {
|
|
89
|
+
sbw[i].h1[k] = L.konst(BPENC.mkpacked_v32(bw[i].h1[k]));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
template <class T, class S, class Logic>
|
|
95
|
+
void copy_index(T& to, const S& from, const Logic& L) {
|
|
96
|
+
to = L.template vbit<kMdoc1CborIndexBits>(from);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
template <class T, class S, class Logic>
|
|
100
|
+
void copy_cbor_index(T& to, const S& from, const Logic& L, size_t offset = 0) {
|
|
101
|
+
to.k = L.template vbit<kMdoc1CborIndexBits>(from.k + offset);
|
|
102
|
+
to.v = L.template vbit<kMdoc1CborIndexBits>(from.v + offset);
|
|
103
|
+
to.ndx = L.template vbit<kMdoc1CborIndexBits>(from.ndx);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
template <class MW, class RMW, class Logic>
|
|
107
|
+
void fill_eval_witness(MW& vw, const RMW& rvw, const Logic& L) {
|
|
108
|
+
const Counter<Logic> CTR(L);
|
|
109
|
+
vw.e_ = L.konst(rvw.e_);
|
|
110
|
+
|
|
111
|
+
copy_sig(vw.sig_, rvw.ew_, L);
|
|
112
|
+
copy_sig(vw.dpk_sig_, rvw.dkw_, L);
|
|
113
|
+
vw.dpkx_ = L.konst(rvw.dpkx_);
|
|
114
|
+
vw.dpky_ = L.konst(rvw.dpky_);
|
|
115
|
+
|
|
116
|
+
// sha
|
|
117
|
+
for (size_t i = kCose1PrefixLen; i < 64 * kMdoc1MaxSHABlocks; ++i) {
|
|
118
|
+
vw.in_[i - kCose1PrefixLen] = L.template vbit<8>(rvw.signed_bytes_[i]);
|
|
119
|
+
}
|
|
120
|
+
vw.nb_ = L.template vbit<8>(rvw.numb_);
|
|
121
|
+
|
|
122
|
+
copy_sha(vw.sig_sha_, rvw.bw_, L, kMdoc1MaxSHABlocks);
|
|
123
|
+
|
|
124
|
+
// Cbor witnesses
|
|
125
|
+
size_t prepad_offset = kMdoc1MaxMsoLen - rvw.pm_.t_mso_.len + 5;
|
|
126
|
+
copy_index(vw.prepad_, prepad_offset, L);
|
|
127
|
+
copy_index(vw.mso_len_, rvw.pm_.t_mso_.len - 5, L);
|
|
128
|
+
for (size_t i = 0; i < kMdoc1MaxMsoLen; ++i) {
|
|
129
|
+
vw.pwcb_[i].encoded_sel_header = L.konst(rvw.pwcb_[i].encoded_sel_header);
|
|
130
|
+
}
|
|
131
|
+
vw.gwcb_.invprod_decode = L.konst(rvw.gwcb_.invprod_decode);
|
|
132
|
+
vw.gwcb_.cc0_counter = CTR.as_counter(rvw.gwcb_.cc0_counter);
|
|
133
|
+
vw.gwcb_.invprod_parse = L.konst(rvw.gwcb_.invprod_parse);
|
|
134
|
+
|
|
135
|
+
// The cbor indices need to be offset by the value of prepad because
|
|
136
|
+
// the cbor string is shifted to be padded with zeroes.
|
|
137
|
+
copy_cbor_index(vw.valid_, rvw.pm_.valid_, L, prepad_offset);
|
|
138
|
+
copy_cbor_index(vw.valid_from_, rvw.pm_.valid_from_, L, prepad_offset);
|
|
139
|
+
copy_cbor_index(vw.valid_until_, rvw.pm_.valid_until_, L, prepad_offset);
|
|
140
|
+
copy_cbor_index(vw.dev_key_info_, rvw.pm_.dev_key_info_, L, prepad_offset);
|
|
141
|
+
copy_cbor_index(vw.dev_key_, rvw.pm_.dev_key_, L, prepad_offset);
|
|
142
|
+
copy_cbor_index(vw.dev_key_pkx_, rvw.pm_.dev_key_pkx_, L, prepad_offset);
|
|
143
|
+
copy_cbor_index(vw.dev_key_pky_, rvw.pm_.dev_key_pky_, L, prepad_offset);
|
|
144
|
+
copy_cbor_index(vw.value_digests_, rvw.pm_.value_digests_, L, prepad_offset);
|
|
145
|
+
copy_cbor_index(vw.org_, rvw.pm_.org_, L, prepad_offset);
|
|
146
|
+
|
|
147
|
+
// Attribute witnesses.
|
|
148
|
+
for (size_t ai = 0; ai < vw.num_attr_; ++ai) {
|
|
149
|
+
vw.attrb_[ai].resize(2 * 64);
|
|
150
|
+
for (size_t i = 0; i < 2 * 64; ++i) {
|
|
151
|
+
vw.attrb_[ai][i] = L.template vbit<8>(rvw.attr_bytes_[ai][i]);
|
|
152
|
+
}
|
|
153
|
+
copy_sha(vw.attr_sha_[ai].data(), rvw.atw_[ai].data(), L, 2);
|
|
154
|
+
|
|
155
|
+
// In the case of attribute mso, push the value to avoid having to
|
|
156
|
+
// deal with 1- or 2- byte key length.
|
|
157
|
+
copy_cbor_index(vw.attr_mso_[ai], rvw.attr_mso_[ai], L, prepad_offset);
|
|
158
|
+
copy_index(vw.attr_ei_[ai].offset, rvw.attr_ei_[ai].offset, L);
|
|
159
|
+
copy_index(vw.attr_ei_[ai].len, rvw.attr_ei_[ai].len, L);
|
|
160
|
+
copy_index(vw.attr_ev_[ai].offset, rvw.attr_ev_[ai].offset, L);
|
|
161
|
+
copy_index(vw.attr_ev_[ai].len, rvw.attr_ev_[ai].len, L);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
TEST(jwt, EvalJWT) {
|
|
166
|
+
using EvaluationBackend = EvaluationBackend<Fp256Base>;
|
|
167
|
+
using MDL = mdoc_1f<Logic<Fp256Base, EvaluationBackend>, Fp256Base, P256, 1>;
|
|
168
|
+
using MW = MDL::Witness;
|
|
169
|
+
using RMW = mdoc_1f_witness<P256, Fp256Base, Fp256Scalar>;
|
|
170
|
+
using v8 = typename Logic<Fp256Base, EvaluationBackend>::v8;
|
|
171
|
+
|
|
172
|
+
const EvaluationBackend ebk(p256_base, true);
|
|
173
|
+
const Logic<Fp256Base, EvaluationBackend> L(&ebk, p256_base);
|
|
174
|
+
MDL mdoc_1f(L, p256, n256_order);
|
|
175
|
+
MW mw(1);
|
|
176
|
+
RMW rmw(1, p256, p256_scalar);
|
|
177
|
+
|
|
178
|
+
auto t0 = mdoc_tests[5];
|
|
179
|
+
auto pkX = p256_base.of_string(t0.pkx);
|
|
180
|
+
auto pkY = p256_base.of_string(t0.pky);
|
|
181
|
+
|
|
182
|
+
v8 now[kMdoc1DateLen];
|
|
183
|
+
for (size_t i = 0; i < kMdoc1DateLen; ++i) {
|
|
184
|
+
now[i] = L.vbit<8>(t0.now[i]);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
std::vector<RequestedAttribute> oa;
|
|
188
|
+
oa.push_back(test::age_over_18);
|
|
189
|
+
|
|
190
|
+
uint8_t want[] = {0x6B, 'a', 'g', 'e', '_', 'o', 'v', 'e', 'r',
|
|
191
|
+
'_', '1', '8', 0x6C, 'e', 'l', 'e', 'm', 'e',
|
|
192
|
+
'n', 't', 'V', 'a', 'l', 'u', 'e', 0xF5};
|
|
193
|
+
std::vector<MDL::OpenedAttribute> oa2;
|
|
194
|
+
for (size_t i = 0; i < oa.size(); ++i) {
|
|
195
|
+
MDL::OpenedAttribute oa2i;
|
|
196
|
+
for (size_t j = 0; j < 96; ++j) {
|
|
197
|
+
if (j < sizeof(want)) {
|
|
198
|
+
oa2i.attr[j] = L.vbit<8>(want[j]);
|
|
199
|
+
} else {
|
|
200
|
+
oa2i.attr[j] = L.vbit<8>(0);
|
|
201
|
+
}
|
|
202
|
+
size_t len = sizeof(want);
|
|
203
|
+
oa2i.len = L.vbit<8>(len);
|
|
204
|
+
}
|
|
205
|
+
oa2.push_back(std::move(oa2i));
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
EXPECT_TRUE(rmw.compute_witness(pkX, pkY, t0.mdoc, t0.mdoc_size,
|
|
209
|
+
t0.transcript, t0.transcript_size, t0.now,
|
|
210
|
+
oa.data(), oa.size()) == MDOC_PROVER_SUCCESS);
|
|
211
|
+
fill_eval_witness(mw, rmw, L);
|
|
212
|
+
mdoc_1f.assert_credential(L.konst(pkX), L.konst(pkY), L.konst(rmw.e2_),
|
|
213
|
+
oa2.data(), now, mw);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Helper function to compile the mdoc_1f circuit.
|
|
217
|
+
std::unique_ptr<Circuit<Fp256Base>> make_mdoc1f_circuit(const Fp256Base& f) {
|
|
218
|
+
using CompilerBackend = CompilerBackend<Fp256Base>;
|
|
219
|
+
using LogicCircuit = Logic<Fp256Base, CompilerBackend>;
|
|
220
|
+
using MDL = mdoc_1f<LogicCircuit, Fp256Base, P256, 1>;
|
|
221
|
+
using MW = MDL::Witness;
|
|
222
|
+
using v8 = LogicCircuit::v8;
|
|
223
|
+
|
|
224
|
+
using EltW = LogicCircuit::EltW;
|
|
225
|
+
|
|
226
|
+
QuadCircuit<Fp256Base> Q(f);
|
|
227
|
+
const CompilerBackend cbk(&Q);
|
|
228
|
+
const LogicCircuit lc(&cbk, f);
|
|
229
|
+
|
|
230
|
+
MDL mdoc(lc, p256, n256_order);
|
|
231
|
+
|
|
232
|
+
// Define Public Inputs (example structure)
|
|
233
|
+
EltW pkX = lc.eltw_input();
|
|
234
|
+
EltW pkY = lc.eltw_input();
|
|
235
|
+
EltW tr = lc.eltw_input();
|
|
236
|
+
|
|
237
|
+
// Add opened attributes and now.
|
|
238
|
+
MDL::OpenedAttribute oa2i[1];
|
|
239
|
+
for (size_t j = 0; j < 1; ++j) {
|
|
240
|
+
oa2i[j].input(lc);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
v8 now[kMdoc1DateLen];
|
|
244
|
+
for (size_t i = 0; i < kMdoc1DateLen; ++i) {
|
|
245
|
+
now[i] = lc.vinput<8>();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
Q.private_input();
|
|
249
|
+
MW witness(1);
|
|
250
|
+
witness.input(lc);
|
|
251
|
+
|
|
252
|
+
mdoc.assert_credential(pkX, pkY, tr, oa2i, now, witness);
|
|
253
|
+
|
|
254
|
+
auto circuit = Q.mkcircuit(/*nc=*/1); // Assuming 1 constraint system
|
|
255
|
+
dump_info("mdoc 1f circuit", Q);
|
|
256
|
+
return circuit;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
void fill_input(Dense<Fp256Base>& W, const MdocTests& t0, const Fp256Base& f,
|
|
260
|
+
bool prover = true) {
|
|
261
|
+
using RMW = mdoc_1f_witness<P256, Fp256Base, Fp256Scalar>;
|
|
262
|
+
RMW rmw(1, p256, p256_scalar);
|
|
263
|
+
auto pkX = p256_base.of_string(t0.pkx);
|
|
264
|
+
auto pkY = p256_base.of_string(t0.pky);
|
|
265
|
+
std::vector<RequestedAttribute> oa;
|
|
266
|
+
oa.push_back(test::age_over_18);
|
|
267
|
+
|
|
268
|
+
EXPECT_TRUE(rmw.compute_witness(pkX, pkY, t0.mdoc, t0.mdoc_size,
|
|
269
|
+
t0.transcript, t0.transcript_size, t0.now,
|
|
270
|
+
oa.data(), oa.size()) == MDOC_PROVER_SUCCESS);
|
|
271
|
+
|
|
272
|
+
// ========= Fill witness
|
|
273
|
+
DenseFiller<Fp256Base> filler(W);
|
|
274
|
+
|
|
275
|
+
filler.push_back(p256_base.one());
|
|
276
|
+
filler.push_back(pkX);
|
|
277
|
+
filler.push_back(pkY);
|
|
278
|
+
filler.push_back(rmw.e2_);
|
|
279
|
+
|
|
280
|
+
for (size_t i = 0; i < oa.size(); ++i) {
|
|
281
|
+
fill_attribute(filler, oa[i], f, 4);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
for (size_t j = 0; j < kMdoc1DateLen; ++j) {
|
|
285
|
+
filler.push_back(t0.now[j], 8, p256_base);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (prover) {
|
|
289
|
+
rmw.fill_witness(filler);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
TEST(Mdoc1fTest, RunsExamples) {
|
|
294
|
+
set_log_level(INFO);
|
|
295
|
+
|
|
296
|
+
// Compile the circuit
|
|
297
|
+
std::unique_ptr<Circuit<Fp256Base>> circuit = make_mdoc1f_circuit(p256_base);
|
|
298
|
+
|
|
299
|
+
// Now that small examples that use different namespaces have been added,
|
|
300
|
+
// change this test to only try the "website explainer" example.
|
|
301
|
+
const auto& test = mdoc_tests[5];
|
|
302
|
+
|
|
303
|
+
log(INFO, "Running example size %zu", test.mdoc_size);
|
|
304
|
+
|
|
305
|
+
// 2. Fill Witness (W) and Public Inputs (pub)
|
|
306
|
+
auto W = Dense<Fp256Base>(1, circuit->ninputs);
|
|
307
|
+
auto pub = Dense<Fp256Base>(1, circuit->npub_in);
|
|
308
|
+
fill_input(W, test, p256_base);
|
|
309
|
+
fill_input(pub, test, p256_base, /*prover=*/false);
|
|
310
|
+
|
|
311
|
+
log(INFO, "Fill done");
|
|
312
|
+
|
|
313
|
+
// 3. Run ZK Test
|
|
314
|
+
run2_test_zk(
|
|
315
|
+
*circuit, W, pub, p256_base,
|
|
316
|
+
p256_base.of_string("1126492241464102818735004576096902583730188404304894"
|
|
317
|
+
"08729223714171582664680802"), /* omega_x*/
|
|
318
|
+
p256_base.of_string("8408799435854090769574046142781866056018216899718237"
|
|
319
|
+
"8749313018254450460212908"), /* omega_y */
|
|
320
|
+
1ull << 31);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// ============ Benchmarks =====================================================
|
|
324
|
+
|
|
325
|
+
void BM_Mdoc1fProver(benchmark::State& state) {
|
|
326
|
+
std::unique_ptr<Circuit<Fp256Base>> CIRCUIT = make_mdoc1f_circuit(p256_base);
|
|
327
|
+
|
|
328
|
+
auto W = Dense<Fp256Base>(1, CIRCUIT->ninputs);
|
|
329
|
+
|
|
330
|
+
auto t0 = mdoc_tests[5];
|
|
331
|
+
fill_input(W, t0, p256_base);
|
|
332
|
+
|
|
333
|
+
using f2_p256 = Fp2<Fp256Base>;
|
|
334
|
+
using Elt2 = f2_p256::Elt;
|
|
335
|
+
using FftExtConvolutionFactory = FFTExtConvolutionFactory<Fp256Base, f2_p256>;
|
|
336
|
+
using RSFactory = ReedSolomonFactory<Fp256Base, FftExtConvolutionFactory>;
|
|
337
|
+
const f2_p256 p256_2(p256_base);
|
|
338
|
+
|
|
339
|
+
// Root of unity for the f_p256^2 extension field.
|
|
340
|
+
static constexpr char kRootX[] =
|
|
341
|
+
"112649224146410281873500457609690258373018840430489408729223714171582664"
|
|
342
|
+
"680802";
|
|
343
|
+
static constexpr char kRootY[] =
|
|
344
|
+
"840879943585409076957404614278186605601821689971823787493130182544504602"
|
|
345
|
+
"12908";
|
|
346
|
+
const Elt2 omega = p256_2.of_string(kRootX, kRootY);
|
|
347
|
+
const FftExtConvolutionFactory fft_b(p256_base, p256_2, omega, 1ull << 31);
|
|
348
|
+
const RSFactory rsf(fft_b, p256_base);
|
|
349
|
+
|
|
350
|
+
SecureRandomEngine rng;
|
|
351
|
+
|
|
352
|
+
ZkProof<Fp256Base> zkpr(*CIRCUIT, 4, 128);
|
|
353
|
+
ZkProver<Fp256Base, RSFactory> prover(*CIRCUIT, p256_base, rsf);
|
|
354
|
+
|
|
355
|
+
for (auto s : state) {
|
|
356
|
+
Transcript tp((uint8_t*)"test", 4);
|
|
357
|
+
prover.commit(zkpr, W, tp, rng);
|
|
358
|
+
prover.prove(zkpr, W, tp);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
BENCHMARK(BM_Mdoc1fProver);
|
|
362
|
+
|
|
363
|
+
} // namespace
|
|
364
|
+
} // namespace proofs
|
|
@@ -0,0 +1,278 @@
|
|
|
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_MDOC_MDOC_1F_WITNESS_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_TESTS_MDOC_MDOC_1F_WITNESS_H_
|
|
17
|
+
|
|
18
|
+
#include <cstddef>
|
|
19
|
+
#include <cstdint>
|
|
20
|
+
#include <cstring>
|
|
21
|
+
#include <vector>
|
|
22
|
+
|
|
23
|
+
#include "arrays/dense.h"
|
|
24
|
+
#include "circuits/cbor_parser/cbor_witness.h"
|
|
25
|
+
#include "circuits/ecdsa/verify_witness.h"
|
|
26
|
+
#include "circuits/logic/bit_plucker_encoder.h"
|
|
27
|
+
#include "circuits/mdoc/mdoc_constants.h"
|
|
28
|
+
#include "circuits/mdoc/mdoc_witness.h"
|
|
29
|
+
#include "circuits/mdoc/mdoc_zk.h"
|
|
30
|
+
#include "circuits/sha/flatsha256_witness.h"
|
|
31
|
+
#include "circuits/tests/mdoc/mdoc_1f_io.h"
|
|
32
|
+
namespace proofs {
|
|
33
|
+
|
|
34
|
+
template <typename EC, typename Field, class ScalarField>
|
|
35
|
+
class mdoc_1f_witness {
|
|
36
|
+
using ECField = typename EC::Field;
|
|
37
|
+
using ECElt = typename ECField::Elt;
|
|
38
|
+
using ECNat = typename ECField::N;
|
|
39
|
+
using Elt = typename Field::Elt;
|
|
40
|
+
using Nat = typename Field::N;
|
|
41
|
+
using EcdsaWitness = VerifyWitness3<EC, ScalarField>;
|
|
42
|
+
using CborWitnessF = CborWitness<Field>;
|
|
43
|
+
|
|
44
|
+
public:
|
|
45
|
+
const EC ec_;
|
|
46
|
+
Elt e_, e2_; /* Issuer signature values. */
|
|
47
|
+
Elt dpkx_, dpky_; /* device key */
|
|
48
|
+
EcdsaWitness ew_, dkw_;
|
|
49
|
+
uint8_t now_[kMdoc1DateLen]; /* CBOR-formatted time for expiry comparison. */
|
|
50
|
+
|
|
51
|
+
FlatSHA256Witness::BlockWitness bw_[kMdoc1MaxSHABlocks];
|
|
52
|
+
uint8_t signed_bytes_[kMdoc1MaxSHABlocks * 64];
|
|
53
|
+
uint8_t numb_; /* Number of the correct sha block. */
|
|
54
|
+
ParsedMdoc pm_;
|
|
55
|
+
|
|
56
|
+
size_t num_attr_;
|
|
57
|
+
std::vector<std::vector<uint8_t>> attr_bytes_;
|
|
58
|
+
std::vector<std::vector<FlatSHA256Witness::BlockWitness>> atw_;
|
|
59
|
+
|
|
60
|
+
std::vector<uint8_t> attr_n_; /* All attributes currently require 2 SHA. */
|
|
61
|
+
std::vector<CborIndex> attr_mso_; /* The cbor indices of the attributes. */
|
|
62
|
+
std::vector<AttrShift> attr_ei_;
|
|
63
|
+
std::vector<AttrShift> attr_ev_;
|
|
64
|
+
|
|
65
|
+
// Cbor parsing witnesses
|
|
66
|
+
std::vector<typename CborWitnessF::v8> incb_;
|
|
67
|
+
std::vector<typename CborWitnessF::position_witness> pwcb_;
|
|
68
|
+
typename CborWitnessF::global_witness gwcb_;
|
|
69
|
+
|
|
70
|
+
explicit mdoc_1f_witness(size_t num_attr, const EC& ec, const ScalarField& Fn)
|
|
71
|
+
: ec_(ec),
|
|
72
|
+
ew_(Fn, ec),
|
|
73
|
+
dkw_(Fn, ec),
|
|
74
|
+
num_attr_(num_attr),
|
|
75
|
+
attr_bytes_(num_attr_),
|
|
76
|
+
atw_(num_attr_),
|
|
77
|
+
attr_n_(num_attr_),
|
|
78
|
+
attr_mso_(num_attr_),
|
|
79
|
+
attr_ei_(num_attr_),
|
|
80
|
+
attr_ev_(num_attr_),
|
|
81
|
+
incb_(kMdoc1MaxMsoLen),
|
|
82
|
+
pwcb_(kMdoc1MaxMsoLen) {}
|
|
83
|
+
|
|
84
|
+
void fill_sha(DenseFiller<Field>& filler,
|
|
85
|
+
const FlatSHA256Witness::BlockWitness& bw) const {
|
|
86
|
+
BitPluckerEncoder<Field, kMdoc1SHAPluckerBits> BPENC(ec_.f_);
|
|
87
|
+
for (size_t k = 0; k < 48; ++k) {
|
|
88
|
+
filler.push_back(BPENC.mkpacked_v32(bw.outw[k]));
|
|
89
|
+
}
|
|
90
|
+
for (size_t k = 0; k < 64; ++k) {
|
|
91
|
+
filler.push_back(BPENC.mkpacked_v32(bw.oute[k]));
|
|
92
|
+
filler.push_back(BPENC.mkpacked_v32(bw.outa[k]));
|
|
93
|
+
}
|
|
94
|
+
for (size_t k = 0; k < 8; ++k) {
|
|
95
|
+
filler.push_back(BPENC.mkpacked_v32(bw.h1[k]));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
void fill_attr_shift(DenseFiller<Field>& df, const AttrShift& attr) const {
|
|
100
|
+
df.push_back(attr.offset, kMdoc1CborIndexBits, ec_.f_);
|
|
101
|
+
df.push_back(attr.len, kMdoc1CborIndexBits, ec_.f_);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// The cbor index that is computed by our witness maker is with reference
|
|
105
|
+
// to the beginning of the cbor string. However the convention for the cbor
|
|
106
|
+
// parser is to 0-pad from the left to fill the full cbor string buffer.
|
|
107
|
+
// As a result, all cbor indices need to be offset by the padding length.
|
|
108
|
+
void fill_cbor_index(DenseFiller<Field>& filler, const CborIndex& ind,
|
|
109
|
+
size_t padding_offset = 0) const {
|
|
110
|
+
filler.push_back(ind.k + padding_offset, kMdoc1CborIndexBits, ec_.f_);
|
|
111
|
+
filler.push_back(ind.v + padding_offset, kMdoc1CborIndexBits, ec_.f_);
|
|
112
|
+
filler.push_back(ind.ndx, kMdoc1CborIndexBits, ec_.f_);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
void fill_witness(DenseFiller<Field>& filler, bool small = false) const {
|
|
116
|
+
filler.push_back(e_);
|
|
117
|
+
filler.push_back(dpkx_);
|
|
118
|
+
filler.push_back(dpky_);
|
|
119
|
+
|
|
120
|
+
ew_.fill_witness(filler);
|
|
121
|
+
dkw_.fill_witness(filler);
|
|
122
|
+
|
|
123
|
+
filler.push_back(numb_, 8, ec_.f_);
|
|
124
|
+
for (size_t i = kCose1PrefixLen; i < kMdoc1MaxSHABlocks * 64; ++i) {
|
|
125
|
+
filler.push_back(signed_bytes_[i], 8, ec_.f_);
|
|
126
|
+
}
|
|
127
|
+
for (size_t j = 0; j < kMdoc1MaxSHABlocks; j++) {
|
|
128
|
+
fill_sha(filler, bw_[j]);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
size_t prepad = kMdoc1MaxMsoLen - pm_.t_mso_.len + 5;
|
|
132
|
+
filler.push_back(prepad, kMdoc1CborIndexBits, ec_.f_);
|
|
133
|
+
filler.push_back(pm_.t_mso_.len - 5, kMdoc1CborIndexBits, ec_.f_);
|
|
134
|
+
for (size_t i = 0; i < kMdoc1MaxMsoLen; ++i) {
|
|
135
|
+
filler.push_back(pwcb_[i].encoded_sel_header);
|
|
136
|
+
}
|
|
137
|
+
filler.push_back(gwcb_.invprod_decode);
|
|
138
|
+
filler.push_back(gwcb_.cc0_counter.e);
|
|
139
|
+
filler.push_back(gwcb_.invprod_parse);
|
|
140
|
+
|
|
141
|
+
fill_cbor_index(filler, pm_.valid_, prepad);
|
|
142
|
+
fill_cbor_index(filler, pm_.valid_from_, prepad);
|
|
143
|
+
fill_cbor_index(filler, pm_.valid_until_, prepad);
|
|
144
|
+
fill_cbor_index(filler, pm_.dev_key_info_, prepad);
|
|
145
|
+
fill_cbor_index(filler, pm_.dev_key_, prepad);
|
|
146
|
+
fill_cbor_index(filler, pm_.dev_key_pkx_, prepad);
|
|
147
|
+
fill_cbor_index(filler, pm_.dev_key_pky_, prepad);
|
|
148
|
+
fill_cbor_index(filler, pm_.value_digests_, prepad);
|
|
149
|
+
fill_cbor_index(filler, pm_.org_, prepad);
|
|
150
|
+
|
|
151
|
+
// Fill all attribute witnesses.
|
|
152
|
+
for (size_t ai = 0; ai < num_attr_; ++ai) {
|
|
153
|
+
for (size_t i = 0; i < 2 * 64; ++i) {
|
|
154
|
+
filler.push_back(attr_bytes_[ai][i], 8, ec_.f_);
|
|
155
|
+
}
|
|
156
|
+
for (size_t j = 0; j < 2; j++) {
|
|
157
|
+
fill_sha(filler, atw_[ai][j]);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// In the case of attribute mso, push the value to avoid having to
|
|
161
|
+
// deal with 1- or 2- byte key length.
|
|
162
|
+
// fill_cbor_index(filler, pm_.value_digests_);
|
|
163
|
+
fill_cbor_index(filler, attr_mso_[ai], prepad);
|
|
164
|
+
fill_attr_shift(filler, attr_ei_[ai]);
|
|
165
|
+
fill_attr_shift(filler, attr_ev_[ai]);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
MdocProverErrorCode compute_witness(Elt pkX, Elt pkY,
|
|
170
|
+
const uint8_t mdoc[/* len */], size_t len,
|
|
171
|
+
const uint8_t transcript[/* tlen */],
|
|
172
|
+
size_t tlen,
|
|
173
|
+
const uint8_t tnow[/*kMdoc1DateLen*/],
|
|
174
|
+
const RequestedAttribute attrs[],
|
|
175
|
+
size_t attrs_len) {
|
|
176
|
+
MdocProverErrorCode err = pm_.parse_device_response(len, mdoc);
|
|
177
|
+
if (err != MDOC_PROVER_SUCCESS) {
|
|
178
|
+
return err;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (pm_.t_mso_.len >= kMdoc1MaxSHABlocks * 64 - 9 - kCose1PrefixLen) {
|
|
182
|
+
return MDOC_PROVER_TAGGED_MSO_TOO_BIG;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
Nat ne = nat_from_hash<Nat>(pm_.tagged_mso_bytes_.data(),
|
|
186
|
+
pm_.tagged_mso_bytes_.size());
|
|
187
|
+
e_ = ec_.f_.to_montgomery(ne);
|
|
188
|
+
|
|
189
|
+
// Parse (r,s).
|
|
190
|
+
const size_t l = pm_.sig_.len;
|
|
191
|
+
Nat nr = nat_from_be<Nat>(&mdoc[pm_.sig_.pos]);
|
|
192
|
+
Nat ns = nat_from_be<Nat>(&mdoc[pm_.sig_.pos + l / 2]);
|
|
193
|
+
if (!ew_.compute_witness(pkX, pkY, ne, nr, ns)) {
|
|
194
|
+
return MDOC_PROVER_SIGNATURE_FAILURE;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
Nat ne2 = compute_transcript_hash<Nat>(transcript, tlen, &pm_.doc_type_);
|
|
198
|
+
const size_t l2 = pm_.dksig_.len;
|
|
199
|
+
Nat nr2 = nat_from_be<Nat>(&mdoc[pm_.dksig_.pos]);
|
|
200
|
+
Nat ns2 = nat_from_be<Nat>(&mdoc[pm_.dksig_.pos + l2 / 2]);
|
|
201
|
+
size_t pmso = pm_.t_mso_.pos + 5; /* skip the tag */
|
|
202
|
+
dpkx_ = ec_.f_.to_montgomery(
|
|
203
|
+
nat_from_be<Nat>(&mdoc[pmso + pm_.dev_key_pkx_.pos]));
|
|
204
|
+
dpky_ = ec_.f_.to_montgomery(
|
|
205
|
+
nat_from_be<Nat>(&mdoc[pmso + pm_.dev_key_pky_.pos]));
|
|
206
|
+
e2_ = ec_.f_.to_montgomery(ne2);
|
|
207
|
+
if (!dkw_.compute_witness(dpkx_, dpky_, ne2, nr2, ns2)) {
|
|
208
|
+
return MDOC_PROVER_DEVICE_SIGNATURE_FAILURE;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
memcpy(now_, tnow, kMdoc1DateLen);
|
|
212
|
+
std::vector<uint8_t> buf;
|
|
213
|
+
|
|
214
|
+
buf.assign(std::begin(kCose1Prefix), std::end(kCose1Prefix));
|
|
215
|
+
// Add 2-byte length
|
|
216
|
+
buf.push_back((pm_.t_mso_.len >> 8) & 0xff);
|
|
217
|
+
buf.push_back(pm_.t_mso_.len & 0xff);
|
|
218
|
+
for (size_t i = 0; i < pm_.t_mso_.len; ++i) {
|
|
219
|
+
buf.push_back(mdoc[pm_.t_mso_.pos + i]);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
FlatSHA256Witness::transform_and_witness_message(
|
|
223
|
+
buf.size(), buf.data(), kMdoc1MaxSHABlocks, numb_, signed_bytes_, bw_);
|
|
224
|
+
|
|
225
|
+
// Cbor parsing.
|
|
226
|
+
// The input is expected to be pre-padded with zeros.
|
|
227
|
+
// The +5 corresponds to the D8 18 59 <len2> prefix.
|
|
228
|
+
size_t prepad = kMdoc1MaxMsoLen - pm_.t_mso_.len + 5;
|
|
229
|
+
// Pad with enough 0s.
|
|
230
|
+
buf.erase(buf.begin(), buf.begin() + kCose1PrefixLen + 2 + 5);
|
|
231
|
+
buf.insert(buf.begin(), prepad, 0);
|
|
232
|
+
|
|
233
|
+
CborWitnessF cw(ec_.f_);
|
|
234
|
+
cw.fill_witnesses(kMdoc1MaxMsoLen, pm_.t_mso_.len, buf.data(), incb_.data(),
|
|
235
|
+
pwcb_.data(), gwcb_);
|
|
236
|
+
|
|
237
|
+
// initialize variables
|
|
238
|
+
for (size_t i = 0; i < num_attr_; ++i) {
|
|
239
|
+
attr_bytes_[i].resize(128);
|
|
240
|
+
atw_[i].resize(2);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Match the attributes with the witnesses from the deviceResponse.
|
|
244
|
+
for (size_t i = 0; i < num_attr_; ++i) {
|
|
245
|
+
bool found = false;
|
|
246
|
+
for (auto fa : pm_.attributes_) {
|
|
247
|
+
if (fa == attrs[i]) {
|
|
248
|
+
FlatSHA256Witness::transform_and_witness_message(
|
|
249
|
+
fa.tag_len, &fa.doc[fa.tag_ind], 2, attr_n_[i],
|
|
250
|
+
&attr_bytes_[i][0], &atw_[i][0]);
|
|
251
|
+
attr_mso_[i] = fa.mso;
|
|
252
|
+
attr_ei_[i].offset = fa.id_ind - fa.tag_ind;
|
|
253
|
+
|
|
254
|
+
// Apply the offset fix from cl/786482988. The length of the element
|
|
255
|
+
// identifier is pre-pended to the attribute comparison string. This
|
|
256
|
+
// requires adding either 1 or 2 bytes depending on the cbor encoding.
|
|
257
|
+
attr_ei_[i].offset -= 1;
|
|
258
|
+
if (fa.id_len > 23) {
|
|
259
|
+
attr_ei_[i].offset -= 1;
|
|
260
|
+
}
|
|
261
|
+
attr_ei_[i].len = fa.witness_length(attrs[i]);
|
|
262
|
+
attr_ev_[i].offset = fa.val_ind - fa.tag_ind;
|
|
263
|
+
attr_ev_[i].len = fa.val_len;
|
|
264
|
+
found = true;
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (!found) {
|
|
269
|
+
return MDOC_PROVER_ATTRIBUTE_NOT_FOUND;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return MDOC_PROVER_SUCCESS;
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
} // namespace proofs
|
|
277
|
+
|
|
278
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_TESTS_MDOC_MDOC_1F_WITNESS_H_
|