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,640 @@
|
|
|
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_CBOR_PARSER_V2_CBOR_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_V2_CBOR_H_
|
|
17
|
+
|
|
18
|
+
#include <stddef.h>
|
|
19
|
+
#include <stdint.h>
|
|
20
|
+
|
|
21
|
+
#include <array>
|
|
22
|
+
#include <vector>
|
|
23
|
+
|
|
24
|
+
#include "circuits/cbor_parser_v2/cbor_byte_decoder.h"
|
|
25
|
+
#include "circuits/cbor_parser_v2/cbor_constants.h"
|
|
26
|
+
#include "circuits/logic/bit_plucker.h"
|
|
27
|
+
#include "circuits/logic/counter.h"
|
|
28
|
+
#include "circuits/logic/memcmp.h"
|
|
29
|
+
#include "circuits/logic/routing.h"
|
|
30
|
+
#include "circuits/logic/unary_plucker.h"
|
|
31
|
+
#include "util/panic.h"
|
|
32
|
+
|
|
33
|
+
namespace proofs {
|
|
34
|
+
template <class Logic, size_t IndexBits = CborConstants::kIndexBits>
|
|
35
|
+
class Cbor {
|
|
36
|
+
public:
|
|
37
|
+
using CounterL = Counter<Logic>;
|
|
38
|
+
using CborBD = CborByteDecoder2<Logic>;
|
|
39
|
+
using Field = typename Logic::Field;
|
|
40
|
+
using EltW = typename Logic::EltW;
|
|
41
|
+
using CEltW = typename CounterL::CEltW;
|
|
42
|
+
using BitW = typename Logic::BitW;
|
|
43
|
+
using v8 = typename Logic::v8;
|
|
44
|
+
static constexpr size_t kIndexBits = IndexBits;
|
|
45
|
+
static constexpr size_t kNCounters = CborConstants::kNCounters;
|
|
46
|
+
using counters = std::array<CEltW, kNCounters>;
|
|
47
|
+
using bv_counters = typename Logic::template bitvec<kNCounters>;
|
|
48
|
+
|
|
49
|
+
// a bitvector that contains an index into the input
|
|
50
|
+
// (byte) array.
|
|
51
|
+
using vindex = typename Logic::template bitvec<kIndexBits>;
|
|
52
|
+
|
|
53
|
+
explicit Cbor(const Logic& l)
|
|
54
|
+
: l_(l), ctr_(l), bd_(l), header_plucker_(l), sel_plucker_(l) {}
|
|
55
|
+
|
|
56
|
+
struct position_witness {
|
|
57
|
+
EltW encoded_header;
|
|
58
|
+
EltW encoded_sel;
|
|
59
|
+
CEltW slen_next;
|
|
60
|
+
counters cc_next;
|
|
61
|
+
|
|
62
|
+
// In principle we could save witnesses by storing the product of
|
|
63
|
+
// INVPROD_DECODE and INVPROD_PARSE, at the expense of commingling
|
|
64
|
+
// the decoder and parser assertions. Keep them distinct until we
|
|
65
|
+
// need this optimization.
|
|
66
|
+
EltW invprod_decode; // inverse of a certain product, see assert_decode()
|
|
67
|
+
EltW invprod_parse; // inverse of a certain product, see assert_parse()
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
//------------------------------------------------------------
|
|
71
|
+
// Canonical order of the witness wires.
|
|
72
|
+
//------------------------------------------------------------
|
|
73
|
+
void witness_wires(size_t n, position_witness pw[/*n*/]) const {
|
|
74
|
+
for (size_t i = 0; i < n; ++i) {
|
|
75
|
+
pw[i].encoded_header = l_.eltw_input();
|
|
76
|
+
pw[i].encoded_sel = l_.eltw_input();
|
|
77
|
+
pw[i].slen_next = ctr_.input();
|
|
78
|
+
for (size_t l = 0; l < kNCounters; ++l) {
|
|
79
|
+
pw[i].cc_next[l] = ctr_.input();
|
|
80
|
+
}
|
|
81
|
+
if (i > 0) {
|
|
82
|
+
pw[i].invprod_decode = l_.eltw_input();
|
|
83
|
+
pw[i].invprod_parse = l_.eltw_input();
|
|
84
|
+
} else {
|
|
85
|
+
// Witnesses at i==0 are unused and undefined.
|
|
86
|
+
// Do not create wires for them.
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
//------------------------------------------------------------
|
|
92
|
+
// Decoder (lexer)
|
|
93
|
+
//------------------------------------------------------------
|
|
94
|
+
struct decode {
|
|
95
|
+
// wires generated by the byte decoder given the input.
|
|
96
|
+
typename CborBD::decode bd;
|
|
97
|
+
|
|
98
|
+
// wires generated by the lexer from witnesses
|
|
99
|
+
BitW header;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
void assert_decode(size_t n, const decode ds[/*n*/],
|
|
103
|
+
const position_witness pw[/*n*/]) const {
|
|
104
|
+
const Logic& L = l_; // shorthand
|
|
105
|
+
|
|
106
|
+
// -------------------------------------------------------------
|
|
107
|
+
// Byte decoder didn't fail
|
|
108
|
+
for (size_t i = 0; i < n; ++i) {
|
|
109
|
+
L.assert_implies(ds[i].header, L.lnot(ds[i].bd.invalid));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// if COUNT_IS_NEXT_V8 is TRUE in the last position,
|
|
113
|
+
// then the input is invalid.
|
|
114
|
+
L.assert_implies(ds[n - 1].header, L.lnot(ds[n - 1].bd.count_is_next_v8));
|
|
115
|
+
|
|
116
|
+
// -------------------------------------------------------------
|
|
117
|
+
CEltW mone_counter = ctr_.mone();
|
|
118
|
+
|
|
119
|
+
// Check the SLEN update equation
|
|
120
|
+
// SLEN_NEXT[I] = HEADER[I] ? LENGTH[I] : (SLEN[I] - 1)
|
|
121
|
+
// where
|
|
122
|
+
// SLEN[I] = (I == 0) ? 0 : SLEN_NEXT[I - 1]
|
|
123
|
+
for (size_t i = 0; i < n; ++i) {
|
|
124
|
+
CEltW slen = (i == 0) ? ctr_.as_counter(0) : pw[i - 1].slen_next;
|
|
125
|
+
CEltW slenm1 = ctr_.add(slen, mone_counter);
|
|
126
|
+
CEltW length = ds[i].bd.length;
|
|
127
|
+
|
|
128
|
+
if (i + 1 < n) {
|
|
129
|
+
CEltW len_i =
|
|
130
|
+
ctr_.ite0(ds[i].bd.length_plus_next_v8, ds[i + 1].bd.as_counter);
|
|
131
|
+
length = ctr_.add(length, len_i);
|
|
132
|
+
} else {
|
|
133
|
+
// it is an error if, in a header, the length of the token is
|
|
134
|
+
// in a byte past the end of the document
|
|
135
|
+
L.assert_implies(ds[i].header, L.lnot(ds[i].bd.length_plus_next_v8));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
CEltW slen_next = ctr_.mux(ds[i].header, length, slenm1);
|
|
139
|
+
|
|
140
|
+
ctr_.assert_eq(slen_next, pw[i].slen_next);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Now check the headers.
|
|
144
|
+
{
|
|
145
|
+
// "The first position is a header"
|
|
146
|
+
L.assert1(ds[0].header);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
{
|
|
150
|
+
EltW one = L.konst(L.one());
|
|
151
|
+
|
|
152
|
+
// "\A I : (SLEN_NEXT[I] == 1) IFF HEADER[I+1]"
|
|
153
|
+
{
|
|
154
|
+
// "\A I : HEADER[I+1] => (SLEN_NEXT[I] == 1)"
|
|
155
|
+
for (size_t i = 0; i < n; ++i) {
|
|
156
|
+
// There is a header past the end of the document,
|
|
157
|
+
// i.e., SLEN_NEXT[N-1] == 1
|
|
158
|
+
BitW headerp1 = (i + 1 < n) ? ds[i + 1].header : L.bit(1);
|
|
159
|
+
|
|
160
|
+
CEltW implies =
|
|
161
|
+
ctr_.ite0(headerp1, ctr_.add(pw[i].slen_next, mone_counter));
|
|
162
|
+
ctr_.assert0(implies);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
{
|
|
166
|
+
// "\A I : (SLEN_NEXT[I] == 1) => HEADER[I+1] "
|
|
167
|
+
// Verify via the invertibility of
|
|
168
|
+
//
|
|
169
|
+
// HEADER[I+1] ? 1 : (SLEN_NEXT[I] - 1)
|
|
170
|
+
//
|
|
171
|
+
// HEADER[N] is implicitly TRUE, so the conditional chooses
|
|
172
|
+
// 1 and we don't need to check I==N-1.
|
|
173
|
+
for (size_t i = 0; i + 1 < n; ++i) {
|
|
174
|
+
CEltW snm1 = ctr_.add(pw[i].slen_next, mone_counter);
|
|
175
|
+
EltW x = L.mux(ds[i + 1].header, one, ctr_.znz_indicator(snm1));
|
|
176
|
+
auto want_one = L.mul(x, pw[i + 1].invprod_decode);
|
|
177
|
+
L.assert_eq(want_one, one);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
//------------------------------------------------------------
|
|
184
|
+
// Parser
|
|
185
|
+
//------------------------------------------------------------
|
|
186
|
+
struct parse_output {
|
|
187
|
+
bv_counters sel;
|
|
188
|
+
counters cc_next;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// "parse" here means produce the parser output, which is trivial
|
|
192
|
+
// because the parser output is given as witnesses.
|
|
193
|
+
void parse(size_t n, parse_output ps[/*n*/], const decode ds[/*n*/],
|
|
194
|
+
const position_witness pw[/*n*/]) const {
|
|
195
|
+
// unpluck the selector and pass the counters through
|
|
196
|
+
for (size_t i = 0; i < n; ++i) {
|
|
197
|
+
ps[i].sel = sel_plucker_.pluck(pw[i].encoded_sel);
|
|
198
|
+
ps[i].cc_next = pw[i].cc_next;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Given the current counters CC and the local count COUNT_I, return
|
|
203
|
+
// the new counters COUNTERS_NEXT. Set *OVERFLOW to TRUE if
|
|
204
|
+
// attempting to update a counter that does not exist.
|
|
205
|
+
//
|
|
206
|
+
// See cbor_witness.h::counters_next() for a perhaps more
|
|
207
|
+
// readable description of this logic.
|
|
208
|
+
counters counters_next(const counters& cc, const bv_counters& sel,
|
|
209
|
+
const CEltW& count_i, const decode& ds,
|
|
210
|
+
BitW* overflow) const {
|
|
211
|
+
counters cc_next = cc;
|
|
212
|
+
|
|
213
|
+
for (size_t l = 0; l < kNCounters; ++l) {
|
|
214
|
+
// if (header && sel[l]) cc_next[l] = cc[l] - 1;
|
|
215
|
+
BitW header_and_sel = l_.land(sel[l], ds.header);
|
|
216
|
+
CEltW mone_maybe = ctr_.ite0(header_and_sel, ctr_.mone());
|
|
217
|
+
cc_next[l] = ctr_.add(cc[l], mone_maybe);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
for (size_t l = 0; l < kNCounters; ++l) {
|
|
221
|
+
// NEWC = 1 if TAGP
|
|
222
|
+
// COUNT if ARRAYP
|
|
223
|
+
// 2*COUNT if MAPP
|
|
224
|
+
CEltW twice_count_i = ctr_.add(count_i, count_i);
|
|
225
|
+
CEltW one = ctr_.as_counter(1);
|
|
226
|
+
|
|
227
|
+
CEltW ifitems = ctr_.mux(ds.bd.arrayp, /*if array:*/ count_i,
|
|
228
|
+
/*if map:*/ twice_count_i);
|
|
229
|
+
CEltW ifnotitems = ctr_.ite0(ds.bd.tagp, one);
|
|
230
|
+
CEltW newc = ctr_.mux(ds.bd.itemsp, ifitems, ifnotitems);
|
|
231
|
+
|
|
232
|
+
BitW header_and_sel = l_.land(sel[l], ds.header);
|
|
233
|
+
BitW tagp_or_itemsp = l_.lor(ds.bd.tagp, ds.bd.itemsp);
|
|
234
|
+
BitW newc_enable = l_.land(header_and_sel, tagp_or_itemsp);
|
|
235
|
+
|
|
236
|
+
if (l + 1 < kNCounters) {
|
|
237
|
+
cc_next[l + 1] = ctr_.mux(newc_enable, newc, cc_next[l + 1]);
|
|
238
|
+
} else {
|
|
239
|
+
// *overflow is always set in the last iteration,
|
|
240
|
+
// so there is no need to initialize it to 0.
|
|
241
|
+
*overflow = newc_enable;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return cc_next;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// check that all counters are correctly updated
|
|
249
|
+
void assert_counter_updates(size_t n, const decode ds[/*n*/],
|
|
250
|
+
const parse_output ps[/*n*/]) const {
|
|
251
|
+
const Logic& L = l_; // shorthand
|
|
252
|
+
|
|
253
|
+
for (size_t i = 0; i < n; ++i) {
|
|
254
|
+
// Finish the decoding of COUNT, which may need
|
|
255
|
+
// lookahead
|
|
256
|
+
CEltW count_i = ds[i].bd.count_as_counter;
|
|
257
|
+
if (i + 1 < n) {
|
|
258
|
+
// if COUNT_IS_NEXT_V8, read COUNT from the next V8
|
|
259
|
+
count_i = ctr_.mux(ds[i].bd.count_is_next_v8, ds[i + 1].bd.as_counter,
|
|
260
|
+
count_i);
|
|
261
|
+
} else {
|
|
262
|
+
// if COUNT_I is actually needed, COUNT_IS_NEXT_V8 must be 0
|
|
263
|
+
L.assert_implies(ds[i].header, L.lnot(ds[i].bd.count_is_next_v8));
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (i > 0) {
|
|
267
|
+
BitW overflow;
|
|
268
|
+
|
|
269
|
+
// By convention, COUNTERS[I] = COUNTERS_NEXT[I - 1]
|
|
270
|
+
const counters cc = ps[i - 1].cc_next;
|
|
271
|
+
|
|
272
|
+
const counters cc_next =
|
|
273
|
+
counters_next(cc, ps[i].sel, count_i, ds[i], &overflow);
|
|
274
|
+
L.assert0(overflow);
|
|
275
|
+
|
|
276
|
+
for (size_t l = 0; l < kNCounters; ++l) {
|
|
277
|
+
ctr_.assert_eq(ps[i].cc_next[l], cc_next[l]);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
void assert_parse(size_t n, const decode ds[/*n*/],
|
|
284
|
+
const parse_output ps[/*n*/],
|
|
285
|
+
const position_witness pw[/*n*/]) const {
|
|
286
|
+
const Logic& L = l_; // shorthand
|
|
287
|
+
|
|
288
|
+
assert_counter_updates(n, ds, ps);
|
|
289
|
+
|
|
290
|
+
for (size_t i = 0; i < n; ++i) {
|
|
291
|
+
// "The SEL witnesses are mutually exclusive."
|
|
292
|
+
// The bit plucker guarantees that the SEL witnesses
|
|
293
|
+
// are bits, but in principle one could feed an
|
|
294
|
+
// out-of-domain input to the bit plucker that
|
|
295
|
+
// sets more than one bit.
|
|
296
|
+
// Another way to accomplish the same effect would
|
|
297
|
+
// be to range-check the input to the bit plucker.
|
|
298
|
+
for (size_t l = 0; l < kNCounters; ++l) {
|
|
299
|
+
for (size_t m = l + 1; m < kNCounters; ++m) {
|
|
300
|
+
L.assert0(L.land(ps[i].sel[l], ps[i].sel[m]));
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// "at a header, at least one SEL bit is set"
|
|
305
|
+
auto sum = L.bit(0);
|
|
306
|
+
for (size_t l = 0; l < kNCounters; ++l) {
|
|
307
|
+
// known to be exclusive by the test above
|
|
308
|
+
sum = L.lor_exclusive(sum, ps[i].sel[l]);
|
|
309
|
+
}
|
|
310
|
+
L.assert_implies(ds[i].header, sum);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// "All counters are zero at the end of the input"
|
|
314
|
+
// CC_NEXT[I][L] is the state of the parser at the end
|
|
315
|
+
// of position I, so CC_NEXT[N-1][L] is the final state.
|
|
316
|
+
for (size_t l = 0; l < kNCounters; ++l) {
|
|
317
|
+
ctr_.assert0(ps[n - 1].cc_next[l]);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// SEL[0][0] is set. We implicitly define CC_NEXT[-1][L] to make
|
|
321
|
+
// this the correct choice. Because SEL[I][.] are asserted above
|
|
322
|
+
// to be mutually exclusive, there is no need to test the other
|
|
323
|
+
// selectors.
|
|
324
|
+
L.assert1(ps[0].sel[0]);
|
|
325
|
+
|
|
326
|
+
for (size_t i = 0; i + 1 < n; ++i) {
|
|
327
|
+
// "If SEL[I+1][L] is set, then CC_NEXT[I][L] is the nonzero
|
|
328
|
+
// counter of maximal L. (CC_NEXT[I][L] contains the output
|
|
329
|
+
// counters of stage I, which affect SEL[I+1].) Here we check
|
|
330
|
+
// maximality: CC_NEXT[I][J]=0 for J>L. See below for
|
|
331
|
+
// SEL[I+1][L] => (CC_NEXT[I][L] != 0).
|
|
332
|
+
BitW b = ps[i + 1].sel[0];
|
|
333
|
+
for (size_t l = 1; l < kNCounters; ++l) {
|
|
334
|
+
// b => CC_NEXT[i][l] == 0
|
|
335
|
+
ctr_.assert0(ctr_.ite0(b, ps[i].cc_next[l]));
|
|
336
|
+
b = L.lor(b, ps[i + 1].sel[l]);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// "SEL[I+1][L] => (CC_NEXT[I][L] != 0)"
|
|
341
|
+
// Check via the invertibility of
|
|
342
|
+
//
|
|
343
|
+
// PROD_{L} SEL[I+1][L] ? CC_NEXT[I][L] : 1
|
|
344
|
+
// We don't need to check I == N-1 because SEL[N][.] is FALSE
|
|
345
|
+
// by definition, and thus the product is the constant 1
|
|
346
|
+
{
|
|
347
|
+
auto one = L.konst(1);
|
|
348
|
+
for (size_t i = 0; i + 1 < n; ++i) {
|
|
349
|
+
EltW p = L.mul(0, kNCounters, [&](size_t l) {
|
|
350
|
+
EltW cc_next = ctr_.znz_indicator(ps[i].cc_next[l]);
|
|
351
|
+
return L.mux(ps[i + 1].sel[l], cc_next, one);
|
|
352
|
+
});
|
|
353
|
+
auto want_one = L.mul(p, pw[i + 1].invprod_parse);
|
|
354
|
+
L.assert_eq(want_one, one);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
//------------------------------------------------------------
|
|
360
|
+
// "J is the header of a string of length LEN containing BYTES"
|
|
361
|
+
//------------------------------------------------------------
|
|
362
|
+
void assert_text_at(size_t n, const vindex& j, size_t len,
|
|
363
|
+
const uint8_t bytes[/*len*/],
|
|
364
|
+
const decode ds[/*n*/]) const {
|
|
365
|
+
const Logic& L = l_; // shorthand
|
|
366
|
+
const Routing<Logic> R(L);
|
|
367
|
+
|
|
368
|
+
// we don't handle long strings
|
|
369
|
+
proofs::check(len < 24, "len < 24");
|
|
370
|
+
|
|
371
|
+
assert_header(n, j, ds);
|
|
372
|
+
|
|
373
|
+
std::vector<EltW> A(n);
|
|
374
|
+
for (size_t i = 0; i < n; ++i) {
|
|
375
|
+
A[i] = ds[i].bd.as_scalar;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// shift len+1 bytes, including the header.
|
|
379
|
+
std::vector<EltW> B(len + 1);
|
|
380
|
+
const EltW defaultA = L.konst(256); // a constant that cannot appear in A[]
|
|
381
|
+
R.shift(j, len + 1, B.data(), n, A.data(), defaultA, /*unroll=*/3);
|
|
382
|
+
|
|
383
|
+
size_t expected_header = (3 << 5) + len;
|
|
384
|
+
L.assert_eq(B[0], L.konst(expected_header));
|
|
385
|
+
for (size_t i = 0; i < len; ++i) {
|
|
386
|
+
auto bi = L.konst(bytes[i]);
|
|
387
|
+
L.assert_eq(B[i + 1], bi);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
//------------------------------------------------------------
|
|
392
|
+
// "J is a header containing unsigned U."
|
|
393
|
+
//------------------------------------------------------------
|
|
394
|
+
void assert_unsigned_at(size_t n, const vindex& j, uint64_t u,
|
|
395
|
+
const decode ds[/*n*/]) const {
|
|
396
|
+
// only small u for now
|
|
397
|
+
proofs::check(u < 24, "u < 24");
|
|
398
|
+
|
|
399
|
+
size_t expected = (0 << 5) + u;
|
|
400
|
+
assert_atom_at(n, j, l_.konst(expected), ds);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
//------------------------------------------------------------
|
|
404
|
+
// "J is a header containing negative U." (U >= 0, and
|
|
405
|
+
// CBOR distinguishes 0 from -0 apparently)
|
|
406
|
+
//------------------------------------------------------------
|
|
407
|
+
void assert_negative_at(size_t n, const vindex& j, uint64_t u,
|
|
408
|
+
const decode ds[/*n*/]) const {
|
|
409
|
+
// only small u for now
|
|
410
|
+
proofs::check(u < 24, "u < 24");
|
|
411
|
+
|
|
412
|
+
size_t expected = (1 << 5) + u;
|
|
413
|
+
assert_atom_at(n, j, l_.konst(expected), ds);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
//------------------------------------------------------------
|
|
417
|
+
// "J is a header containing a boolean primitive (0xF4 or 0xF5)."
|
|
418
|
+
//
|
|
419
|
+
//------------------------------------------------------------
|
|
420
|
+
void assert_bool_at(size_t n, const vindex& j, bool val,
|
|
421
|
+
const decode ds[/*n*/]) const {
|
|
422
|
+
size_t expected = (7 << 5) + (val ? 21 : 20);
|
|
423
|
+
assert_atom_at(n, j, l_.konst(expected), ds);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// Helps assemble the checks for date assertions.
|
|
427
|
+
void date_helper(size_t n, const vindex& j, const decode ds[/*n*/],
|
|
428
|
+
std::vector<v8>& B /* size 22 */) const {
|
|
429
|
+
const Logic& L = l_; // shorthand
|
|
430
|
+
const Routing<Logic> R(L);
|
|
431
|
+
assert_header(n, j, ds);
|
|
432
|
+
|
|
433
|
+
std::vector<v8> A(n);
|
|
434
|
+
for (size_t i = 0; i < n; ++i) {
|
|
435
|
+
A[i] = ds[i].bd.as_bits;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
const v8 defaultA =
|
|
439
|
+
L.template vbit<8>(0); // a constant that cannot appear in A[]
|
|
440
|
+
R.shift(j, 20 + 2, B.data(), n, A.data(), defaultA, /*unroll=*/3);
|
|
441
|
+
|
|
442
|
+
// Check for tag: date/time string.
|
|
443
|
+
L.vassert_eq(B[0], L.template vbit<8>(0xc0));
|
|
444
|
+
|
|
445
|
+
// Check for string(20)
|
|
446
|
+
L.vassert_eq(B[1], L.template vbit<8>(0x74));
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
//------------------------------------------------------------
|
|
450
|
+
// "J is a header containing date d < now." now is 20 bytes
|
|
451
|
+
// in the format 2023-11-01T09:00:00Z
|
|
452
|
+
//------------------------------------------------------------
|
|
453
|
+
void assert_date_before_at(size_t n, const vindex& j, const v8 now[/* 20 */],
|
|
454
|
+
const decode ds[/*n*/]) const {
|
|
455
|
+
const Logic& L = l_; // shorthand
|
|
456
|
+
const Memcmp<Logic> CMP(L);
|
|
457
|
+
std::vector<v8> B(20 + 2);
|
|
458
|
+
date_helper(n, j, ds, B);
|
|
459
|
+
auto lt = CMP.lt(20, B[2], now);
|
|
460
|
+
L.assert1(lt);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
//------------------------------------------------------------
|
|
464
|
+
// "J is a header containing date d > now." now is 20 bytes in the
|
|
465
|
+
// format 2023-11-01T09:00:00Z
|
|
466
|
+
// ------------------------------------------------------------
|
|
467
|
+
void assert_date_after_at(size_t n, const vindex& j, const v8 now[/* 20 */],
|
|
468
|
+
const decode ds[/*n*/]) const {
|
|
469
|
+
const Logic& L = l_; // shorthand
|
|
470
|
+
const Memcmp<Logic> CMP(L);
|
|
471
|
+
std::vector<v8> B(20 + 2);
|
|
472
|
+
date_helper(n, j, ds, B);
|
|
473
|
+
auto lt = CMP.lt(20, now, B[2]);
|
|
474
|
+
L.assert1(lt);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
//------------------------------------------------------------
|
|
478
|
+
// "J is a header containing represented by the byte EXPECTED in the
|
|
479
|
+
// input."
|
|
480
|
+
//------------------------------------------------------------
|
|
481
|
+
void assert_atom_at(size_t n, const vindex& j, const EltW& expected,
|
|
482
|
+
const decode ds[/*n*/]) const {
|
|
483
|
+
const Logic& L = l_; // shorthand
|
|
484
|
+
const Routing<Logic> R(L);
|
|
485
|
+
|
|
486
|
+
assert_header(n, j, ds);
|
|
487
|
+
|
|
488
|
+
std::vector<EltW> A(n);
|
|
489
|
+
for (size_t i = 0; i < n; ++i) {
|
|
490
|
+
A[i] = ds[i].bd.as_scalar;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
EltW B[1];
|
|
494
|
+
size_t unroll = 3;
|
|
495
|
+
R.shift(j, 1, B, n, A.data(), L.konst(256), unroll);
|
|
496
|
+
L.assert_eq(B[0], expected);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
//------------------------------------------------------------
|
|
500
|
+
// "Position j contains a header"
|
|
501
|
+
//------------------------------------------------------------
|
|
502
|
+
void assert_header(size_t n, const vindex& j, const decode ds[/*n*/]) const {
|
|
503
|
+
const Logic& L = l_; // shorthand
|
|
504
|
+
|
|
505
|
+
L.vassert_is_bit(j);
|
|
506
|
+
|
|
507
|
+
// giant dot product since the veq(j, .) terms are mutually exclusive.
|
|
508
|
+
auto f = [&](size_t i) { return L.land(ds[i].header, L.veq(j, i)); };
|
|
509
|
+
L.assert1(L.lor_exclusive(0, n, f));
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
//------------------------------------------------------------
|
|
513
|
+
// "A map starts at position j"
|
|
514
|
+
//------------------------------------------------------------
|
|
515
|
+
void assert_map_header(size_t n, const vindex& j,
|
|
516
|
+
const decode ds[/*n*/]) const {
|
|
517
|
+
const Logic& L = l_; // shorthand
|
|
518
|
+
|
|
519
|
+
L.vassert_is_bit(j);
|
|
520
|
+
|
|
521
|
+
// giant dot product since the veq(j, .) terms are mutually exclusive.
|
|
522
|
+
auto f = [&](size_t i) {
|
|
523
|
+
auto eq_ji = L.veq(j, i);
|
|
524
|
+
auto dsi = L.land(ds[i].bd.mapp, ds[i].header);
|
|
525
|
+
return L.land(eq_ji, dsi);
|
|
526
|
+
};
|
|
527
|
+
L.assert1(L.lor_exclusive(0, n, f));
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
//------------------------------------------------------------
|
|
531
|
+
// "Position M starts a map of level LEVEL. (K, V) are headers
|
|
532
|
+
// representing the J-th pair in that map"
|
|
533
|
+
//------------------------------------------------------------
|
|
534
|
+
void assert_map_entry(size_t n, const vindex& m, size_t level,
|
|
535
|
+
const vindex& k, const vindex& v, const vindex& j,
|
|
536
|
+
const decode ds[/*n*/],
|
|
537
|
+
const parse_output ps[/*n*/]) const {
|
|
538
|
+
const Logic& L = l_; // shorthand
|
|
539
|
+
const Routing<Logic> R(L);
|
|
540
|
+
|
|
541
|
+
assert_map_header(n, m, ds);
|
|
542
|
+
assert_header(n, k, ds);
|
|
543
|
+
assert_header(n, v, ds);
|
|
544
|
+
|
|
545
|
+
for (size_t l = 0; l < kNCounters; ++l) {
|
|
546
|
+
// Hack: temporarily treat CEltW as EltW so as to reuse
|
|
547
|
+
// the shifter.
|
|
548
|
+
std::vector<EltW> A(n);
|
|
549
|
+
for (size_t i = 0; i < n; ++i) {
|
|
550
|
+
A[i] = ps[i].cc_next[l].e;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// Select counters[m], counters[k], and counters[v].
|
|
554
|
+
CEltW cm, ck, cv;
|
|
555
|
+
|
|
556
|
+
const size_t unroll = 3;
|
|
557
|
+
R.shift(m, 1, &cm.e, n, A.data(), L.konst(0), unroll);
|
|
558
|
+
R.shift(k, 1, &ck.e, n, A.data(), L.konst(0), unroll);
|
|
559
|
+
R.shift(v, 1, &cv.e, n, A.data(), L.konst(0), unroll);
|
|
560
|
+
|
|
561
|
+
if (l <= level) {
|
|
562
|
+
// Counters[L] must agree at the key, value, and root
|
|
563
|
+
// of the map.
|
|
564
|
+
ctr_.assert_eq(cm, ck);
|
|
565
|
+
ctr_.assert_eq(cm, cv);
|
|
566
|
+
} else if (l == level + 1) {
|
|
567
|
+
CEltW one = ctr_.as_counter(1);
|
|
568
|
+
CEltW two = ctr_.as_counter(2);
|
|
569
|
+
// LEVEL+1 counters must have the right number of decrements.
|
|
570
|
+
// Specifically, if the counter at the map is N, then the j-th
|
|
571
|
+
// key has N-(2*j+1) and the j-th value has N-(2*j+2)
|
|
572
|
+
CEltW jctr = ctr_.as_counter(j);
|
|
573
|
+
CEltW twoj = ctr_.add(jctr, jctr);
|
|
574
|
+
ctr_.assert_eq(cm, ctr_.add(ck, ctr_.add(twoj, one)));
|
|
575
|
+
ctr_.assert_eq(cm, ctr_.add(cv, ctr_.add(twoj, two)));
|
|
576
|
+
} else {
|
|
577
|
+
// not sure if this is necessary, but all other counters
|
|
578
|
+
// of CM are supposed to be zero.
|
|
579
|
+
ctr_.assert0(cm);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
//------------------------------------------------------------
|
|
585
|
+
// "JROOT is the first byte of the actual (unpadded) input and
|
|
586
|
+
// all previous bytes are 0"
|
|
587
|
+
//------------------------------------------------------------
|
|
588
|
+
void assert_input_starts_at(size_t n, const vindex& jroot,
|
|
589
|
+
const vindex& input_len,
|
|
590
|
+
const decode ds[/*n*/]) const {
|
|
591
|
+
const Logic& L = l_; // shorthand
|
|
592
|
+
|
|
593
|
+
L.assert1(L.vleq(input_len, n));
|
|
594
|
+
L.assert1(L.vlt(jroot, n));
|
|
595
|
+
auto tot = L.vadd(jroot, input_len);
|
|
596
|
+
L.vassert_eq(tot, n);
|
|
597
|
+
|
|
598
|
+
for (size_t i = 0; i < n; ++i) {
|
|
599
|
+
L.assert0(L.lmul(ds[i].bd.as_scalar, L.vlt(i, jroot)));
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
//------------------------------------------------------------
|
|
604
|
+
// Utilities
|
|
605
|
+
//------------------------------------------------------------
|
|
606
|
+
// The circuit accepts up to N input positions, of which
|
|
607
|
+
// INPUT_LEN are actual input and the rest are ignored.
|
|
608
|
+
void decode_all(size_t n, decode ds[/*n*/], const v8 in[/*n*/],
|
|
609
|
+
const position_witness pw[/*n*/]) const {
|
|
610
|
+
for (size_t i = 0; i < n; ++i) {
|
|
611
|
+
ds[i].bd = bd_.decode_one_v8(in[i]);
|
|
612
|
+
auto eh = header_plucker_.pluck(pw[i].encoded_header);
|
|
613
|
+
ds[i].header = eh[0];
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
void decode_and_assert_decode(size_t n, decode ds[/*n*/], const v8 in[/*n*/],
|
|
618
|
+
const position_witness pw[/*n*/]) const {
|
|
619
|
+
decode_all(n, ds, in, pw);
|
|
620
|
+
assert_decode(n, ds, pw);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
void decode_and_assert_decode_and_parse(
|
|
624
|
+
size_t n, decode ds[/*n*/], parse_output ps[/*n*/], const v8 in[/*n*/],
|
|
625
|
+
const position_witness pw[/*n*/]) const {
|
|
626
|
+
decode_and_assert_decode(n, ds, in, pw);
|
|
627
|
+
parse(n, ps, ds, pw);
|
|
628
|
+
assert_parse(n, ds, ps, pw);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
private:
|
|
632
|
+
const Logic& l_;
|
|
633
|
+
const CounterL ctr_;
|
|
634
|
+
const CborBD bd_;
|
|
635
|
+
const BitPlucker<Logic, 1> header_plucker_;
|
|
636
|
+
const UnaryPlucker<Logic, kNCounters> sel_plucker_;
|
|
637
|
+
};
|
|
638
|
+
} // namespace proofs
|
|
639
|
+
|
|
640
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_V2_CBOR_H_
|