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
data/lib/longfellow.rb
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "longfellow/version"
|
|
4
|
+
require_relative "longfellow/errors"
|
|
5
|
+
require_relative "longfellow/c"
|
|
6
|
+
require_relative "longfellow/zk_spec"
|
|
7
|
+
require_relative "longfellow/attribute"
|
|
8
|
+
|
|
9
|
+
# Ruby bindings for Google's longfellow-zk library
|
|
10
|
+
# (https://github.com/google/longfellow-zk): zero-knowledge proofs over ISO
|
|
11
|
+
# mdoc / mDL verifiable credentials.
|
|
12
|
+
#
|
|
13
|
+
# The typical flow is:
|
|
14
|
+
#
|
|
15
|
+
# spec = Longfellow.zk_specs.last # pick a ZK specification
|
|
16
|
+
# circuit = Longfellow.generate_circuit(spec) # once; cache the result
|
|
17
|
+
# proof = Longfellow.prove(circuit:, zk_spec:, ...) # prover side
|
|
18
|
+
# Longfellow.verify(circuit:, zk_spec:, proof:, ...) # verifier side
|
|
19
|
+
module Longfellow
|
|
20
|
+
# Default mdoc document type ("org.iso.18013.5.1.mDL").
|
|
21
|
+
DEFAULT_DOC_TYPE = "org.iso.18013.5.1.mDL"
|
|
22
|
+
|
|
23
|
+
class << self
|
|
24
|
+
# All ZK specifications hardcoded into the native library.
|
|
25
|
+
# @return [Array<Longfellow::ZkSpec>]
|
|
26
|
+
def zk_specs
|
|
27
|
+
@zk_specs ||= C.zk_specs.map { |s| ZkSpec.new(s) }.freeze
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Look up a ZK specification by system name and circuit hash.
|
|
31
|
+
# @return [Longfellow::ZkSpec, nil]
|
|
32
|
+
def find_zk_spec(system_name, circuit_hash)
|
|
33
|
+
ptr = C.find_zk_spec(system_name, circuit_hash)
|
|
34
|
+
return nil if ptr.null?
|
|
35
|
+
|
|
36
|
+
ZkSpec.new(C::ZkSpecStruct.new(ptr))
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Produce the compressed circuit bytes for the given specification. This is
|
|
40
|
+
# deterministic and can be cached and reused by provers and verifiers.
|
|
41
|
+
# @param zk_spec [Longfellow::ZkSpec]
|
|
42
|
+
# @return [String] binary circuit bytes
|
|
43
|
+
def generate_circuit(zk_spec)
|
|
44
|
+
cb = FFI::MemoryPointer.new(:pointer)
|
|
45
|
+
clen = FFI::MemoryPointer.new(:size_t)
|
|
46
|
+
code = C.generate_circuit(zk_spec.to_ptr, cb, clen)
|
|
47
|
+
Errors.check_circuit!(code)
|
|
48
|
+
read_and_free(cb, clen)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Compute the 32-byte identifier (SHA-256 over the two sub-circuit ids) of a
|
|
52
|
+
# compressed circuit bundle.
|
|
53
|
+
# @param circuit [String] compressed circuit bytes
|
|
54
|
+
# @param zk_spec [Longfellow::ZkSpec]
|
|
55
|
+
# @return [String] 32 binary bytes
|
|
56
|
+
def circuit_id(circuit, zk_spec)
|
|
57
|
+
out = FFI::MemoryPointer.new(:uint8, C::CIRCUIT_ID_SIZE)
|
|
58
|
+
data = byte_pointer(circuit)
|
|
59
|
+
rc = C.circuit_id(out, data, circuit.bytesize, zk_spec.to_ptr)
|
|
60
|
+
raise Error, "circuit_id failed (circuit could not be parsed)" if rc != 1
|
|
61
|
+
|
|
62
|
+
out.read_bytes(C::CIRCUIT_ID_SIZE)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Generate a zero-knowledge proof opening the requested attributes of an
|
|
66
|
+
# mdoc. Raises {ProverError} on failure (e.g. invalid mdoc, time outside the
|
|
67
|
+
# validity window, attribute not present).
|
|
68
|
+
#
|
|
69
|
+
# @param circuit [String] compressed circuit bytes (see {#generate_circuit})
|
|
70
|
+
# @param mdoc [String] the full mdoc/mDL bytes
|
|
71
|
+
# @param public_key_x [String] issuer public key X coordinate (string rep)
|
|
72
|
+
# @param public_key_y [String] issuer public key Y coordinate (string rep)
|
|
73
|
+
# @param transcript [String] session transcript bytes
|
|
74
|
+
# @param attributes [Array<Longfellow::Attribute, Hash>] claims to open
|
|
75
|
+
# @param now [String] current time, e.g. "2023-11-02T09:00:00Z"
|
|
76
|
+
# @param zk_spec [Longfellow::ZkSpec]
|
|
77
|
+
# @return [String] binary proof bytes
|
|
78
|
+
def prove(circuit:, mdoc:, public_key_x:, public_key_y:, transcript:,
|
|
79
|
+
attributes:, now:, zk_spec:)
|
|
80
|
+
attrs_ptr, count = build_attributes(attributes)
|
|
81
|
+
prf = FFI::MemoryPointer.new(:pointer)
|
|
82
|
+
plen = FFI::MemoryPointer.new(:size_t)
|
|
83
|
+
|
|
84
|
+
code = C.run_mdoc_prover(
|
|
85
|
+
byte_pointer(circuit), circuit.bytesize,
|
|
86
|
+
byte_pointer(mdoc), mdoc.bytesize,
|
|
87
|
+
public_key_x.to_s, public_key_y.to_s,
|
|
88
|
+
byte_pointer(transcript), transcript.bytesize,
|
|
89
|
+
attrs_ptr, count,
|
|
90
|
+
now.to_s,
|
|
91
|
+
prf, plen, zk_spec.to_ptr
|
|
92
|
+
)
|
|
93
|
+
Errors.check_prover!(code)
|
|
94
|
+
read_and_free(prf, plen)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Verify a zero-knowledge proof against the requested attributes. Returns
|
|
98
|
+
# true on success, raises {VerifierError} otherwise.
|
|
99
|
+
#
|
|
100
|
+
# @param doc_type [String] mdoc document type (defaults to {DEFAULT_DOC_TYPE})
|
|
101
|
+
# @return [true]
|
|
102
|
+
def verify(circuit:, public_key_x:, public_key_y:, transcript:, attributes:,
|
|
103
|
+
now:, proof:, zk_spec:, doc_type: DEFAULT_DOC_TYPE)
|
|
104
|
+
attrs_ptr, count = build_attributes(attributes)
|
|
105
|
+
|
|
106
|
+
code = C.run_mdoc_verifier(
|
|
107
|
+
byte_pointer(circuit), circuit.bytesize,
|
|
108
|
+
public_key_x.to_s, public_key_y.to_s,
|
|
109
|
+
byte_pointer(transcript), transcript.bytesize,
|
|
110
|
+
attrs_ptr, count,
|
|
111
|
+
now.to_s,
|
|
112
|
+
byte_pointer(proof), proof.bytesize,
|
|
113
|
+
doc_type.to_s, zk_spec.to_ptr
|
|
114
|
+
)
|
|
115
|
+
Errors.check_verifier!(code)
|
|
116
|
+
true
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
private
|
|
120
|
+
|
|
121
|
+
# Copy a Ruby string into a native buffer. Returns a NULL pointer for empty
|
|
122
|
+
# input so callers can pass through optional byte fields.
|
|
123
|
+
def byte_pointer(str)
|
|
124
|
+
bytes = String(str).b
|
|
125
|
+
return FFI::Pointer::NULL if bytes.empty?
|
|
126
|
+
|
|
127
|
+
ptr = FFI::MemoryPointer.new(:uint8, bytes.bytesize)
|
|
128
|
+
ptr.put_bytes(0, bytes)
|
|
129
|
+
ptr
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# Build a contiguous C array of RequestedAttribute. Returns
|
|
133
|
+
# [pointer, count]; an empty list yields [NULL, 0].
|
|
134
|
+
def build_attributes(attributes)
|
|
135
|
+
attrs = Array(attributes).map { |a| Attribute.coerce(a) }
|
|
136
|
+
return [FFI::Pointer::NULL, 0] if attrs.empty?
|
|
137
|
+
|
|
138
|
+
array = FFI::MemoryPointer.new(C::RequestedAttribute, attrs.size)
|
|
139
|
+
attrs.each_with_index do |attr, i|
|
|
140
|
+
struct = C::RequestedAttribute.new(
|
|
141
|
+
array + (i * C::RequestedAttribute.size)
|
|
142
|
+
)
|
|
143
|
+
attr.write_to(struct)
|
|
144
|
+
end
|
|
145
|
+
[array, attrs.size]
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# Read a (uint8_t* out, size_t* len) pair filled by the native side and free
|
|
149
|
+
# the C-allocated buffer.
|
|
150
|
+
def read_and_free(out_ptr, len_ptr)
|
|
151
|
+
buffer = out_ptr.read_pointer
|
|
152
|
+
length = len_ptr.read(:size_t)
|
|
153
|
+
return +"" if buffer.null? || length.zero?
|
|
154
|
+
|
|
155
|
+
begin
|
|
156
|
+
buffer.read_bytes(length)
|
|
157
|
+
ensure
|
|
158
|
+
C.c_free(buffer)
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
data/sig/longfellow.rbs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
module Longfellow
|
|
2
|
+
VERSION: String
|
|
3
|
+
DEFAULT_DOC_TYPE: String
|
|
4
|
+
|
|
5
|
+
def self.zk_specs: () -> Array[ZkSpec]
|
|
6
|
+
def self.find_zk_spec: (String system_name, String circuit_hash) -> ZkSpec?
|
|
7
|
+
def self.generate_circuit: (ZkSpec zk_spec) -> String
|
|
8
|
+
def self.circuit_id: (String circuit, ZkSpec zk_spec) -> String
|
|
9
|
+
|
|
10
|
+
def self.prove: (
|
|
11
|
+
circuit: String,
|
|
12
|
+
mdoc: String,
|
|
13
|
+
public_key_x: String,
|
|
14
|
+
public_key_y: String,
|
|
15
|
+
transcript: String,
|
|
16
|
+
attributes: Array[Attribute | Hash[Symbol | String, String]],
|
|
17
|
+
now: String,
|
|
18
|
+
zk_spec: ZkSpec
|
|
19
|
+
) -> String
|
|
20
|
+
|
|
21
|
+
def self.verify: (
|
|
22
|
+
circuit: String,
|
|
23
|
+
public_key_x: String,
|
|
24
|
+
public_key_y: String,
|
|
25
|
+
transcript: String,
|
|
26
|
+
attributes: Array[Attribute | Hash[Symbol | String, String]],
|
|
27
|
+
now: String,
|
|
28
|
+
proof: String,
|
|
29
|
+
zk_spec: ZkSpec,
|
|
30
|
+
?doc_type: String
|
|
31
|
+
) -> bool
|
|
32
|
+
|
|
33
|
+
class Error < StandardError
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
class NativeError < Error
|
|
37
|
+
attr_reader code: Integer
|
|
38
|
+
attr_reader symbol: Symbol
|
|
39
|
+
def initialize: (Symbol symbol, Integer code, String context) -> void
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class ProverError < NativeError
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
class VerifierError < NativeError
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
class CircuitGenerationError < NativeError
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
class ZkSpec
|
|
52
|
+
attr_reader system: String?
|
|
53
|
+
attr_reader circuit_hash: String
|
|
54
|
+
attr_reader num_attributes: Integer
|
|
55
|
+
attr_reader version: Integer
|
|
56
|
+
attr_reader block_enc_hash: Integer
|
|
57
|
+
attr_reader block_enc_sig: Integer
|
|
58
|
+
def to_ptr: () -> untyped
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
class Attribute
|
|
62
|
+
MAX_NAMESPACE: Integer
|
|
63
|
+
MAX_ID: Integer
|
|
64
|
+
MAX_CBOR_VALUE: Integer
|
|
65
|
+
|
|
66
|
+
attr_reader namespace_id: String
|
|
67
|
+
attr_reader id: String
|
|
68
|
+
attr_reader cbor_value: String
|
|
69
|
+
|
|
70
|
+
def initialize: (namespace_id: String, id: String, cbor_value: String) -> void
|
|
71
|
+
def self.coerce: (Attribute | Hash[Symbol | String, String] obj) -> Attribute
|
|
72
|
+
def write_to: (untyped struct) -> untyped
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
Copyright © 2025 Google LLC
|
|
2
|
+
|
|
3
|
+
Apache License
|
|
4
|
+
Version 2.0, January 2004
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
1. Definitions.
|
|
10
|
+
|
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
12
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
13
|
+
|
|
14
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
15
|
+
the copyright owner that is granting the License.
|
|
16
|
+
|
|
17
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
18
|
+
other entities that control, are controlled by, or are under common
|
|
19
|
+
control with that entity. For the purposes of this definition,
|
|
20
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
21
|
+
direction or management of such entity, whether by contract or
|
|
22
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
23
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
24
|
+
|
|
25
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
26
|
+
exercising permissions granted by this License.
|
|
27
|
+
|
|
28
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
29
|
+
including but not limited to software source code, documentation
|
|
30
|
+
source, and configuration files.
|
|
31
|
+
|
|
32
|
+
"Object" form shall mean any form resulting from mechanical
|
|
33
|
+
transformation or translation of a Source form, including but
|
|
34
|
+
not limited to compiled object code, generated documentation,
|
|
35
|
+
and conversions to other media types.
|
|
36
|
+
|
|
37
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
38
|
+
Object form, made available under the License, as indicated by a
|
|
39
|
+
copyright notice that is included in or attached to the work
|
|
40
|
+
(an example is provided in the Appendix below).
|
|
41
|
+
|
|
42
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
43
|
+
form, that is based on (or derived from) the Work and for which the
|
|
44
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
45
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
46
|
+
of this License, Derivative Works shall not include works that remain
|
|
47
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
48
|
+
the Work and Derivative Works thereof.
|
|
49
|
+
|
|
50
|
+
"Contribution" shall mean any work of authorship, including
|
|
51
|
+
the original version of the Work and any modifications or additions
|
|
52
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
53
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
54
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
55
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
56
|
+
means any form of electronic, verbal, or written communication sent
|
|
57
|
+
to the Licensor or its representatives, including but not limited to
|
|
58
|
+
communication on electronic mailing lists, source code control systems,
|
|
59
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
60
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
61
|
+
excluding communication that is conspicuously marked or otherwise
|
|
62
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
63
|
+
|
|
64
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
65
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
66
|
+
subsequently incorporated within the Work.
|
|
67
|
+
|
|
68
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
69
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
70
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
71
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
72
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
73
|
+
Work and such Derivative Works in Source or Object form.
|
|
74
|
+
|
|
75
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
76
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
77
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
78
|
+
(except as stated in this section) patent license to make, have made,
|
|
79
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
80
|
+
where such license applies only to those patent claims licensable
|
|
81
|
+
by such Contributor that are necessarily infringed by their
|
|
82
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
83
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
84
|
+
institute patent litigation against any entity (including a
|
|
85
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
86
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
87
|
+
or contributory patent infringement, then any patent licenses
|
|
88
|
+
granted to You under this License for that Work shall terminate
|
|
89
|
+
as of the date such litigation is filed.
|
|
90
|
+
|
|
91
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
92
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
93
|
+
modifications, and in Source or Object form, provided that You
|
|
94
|
+
meet the following conditions:
|
|
95
|
+
|
|
96
|
+
(a) You must give any other recipients of the Work or
|
|
97
|
+
Derivative Works a copy of this License; and
|
|
98
|
+
|
|
99
|
+
(b) You must cause any modified files to carry prominent notices
|
|
100
|
+
stating that You changed the files; and
|
|
101
|
+
|
|
102
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
103
|
+
that You distribute, all copyright, patent, trademark, and
|
|
104
|
+
attribution notices from the Source form of the Work,
|
|
105
|
+
excluding those notices that do not pertain to any part of
|
|
106
|
+
the Derivative Works; and
|
|
107
|
+
|
|
108
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
109
|
+
distribution, then any Derivative Works that You distribute must
|
|
110
|
+
include a readable copy of the attribution notices contained
|
|
111
|
+
within such NOTICE file, excluding those notices that do not
|
|
112
|
+
pertain to any part of the Derivative Works, in at least one
|
|
113
|
+
of the following places: within a NOTICE text file distributed
|
|
114
|
+
as part of the Derivative Works; within the Source form or
|
|
115
|
+
documentation, if provided along with the Derivative Works; or,
|
|
116
|
+
within a display generated by the Derivative Works, if and
|
|
117
|
+
wherever such third-party notices normally appear. The contents
|
|
118
|
+
of the NOTICE file are for informational purposes only and
|
|
119
|
+
do not modify the License. You may add Your own attribution
|
|
120
|
+
notices within Derivative Works that You distribute, alongside
|
|
121
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
122
|
+
that such additional attribution notices cannot be construed
|
|
123
|
+
as modifying the License.
|
|
124
|
+
|
|
125
|
+
You may add Your own copyright statement to Your modifications and
|
|
126
|
+
may provide additional or different license terms and conditions
|
|
127
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
128
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
129
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
130
|
+
the conditions stated in this License.
|
|
131
|
+
|
|
132
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
133
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
134
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
135
|
+
this License, without any additional terms or conditions.
|
|
136
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
137
|
+
the terms of any separate license agreement you may have executed
|
|
138
|
+
with Licensor regarding such Contributions.
|
|
139
|
+
|
|
140
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
141
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
142
|
+
except as required for reasonable and customary use in describing the
|
|
143
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
144
|
+
|
|
145
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
146
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
147
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
148
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
149
|
+
implied, including, without limitation, any warranties or conditions
|
|
150
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
151
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
152
|
+
appropriateness of using or redistributing the Work and assume any
|
|
153
|
+
risks associated with Your exercise of permissions under this License.
|
|
154
|
+
|
|
155
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
156
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
157
|
+
unless required by applicable law (such as deliberate and grossly
|
|
158
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
159
|
+
liable to You for damages, including any direct, indirect, special,
|
|
160
|
+
incidental, or consequential damages of any character arising as a
|
|
161
|
+
result of this License or out of the use or inability to use the
|
|
162
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
163
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
164
|
+
other commercial damages or losses), even if such Contributor
|
|
165
|
+
has been advised of the possibility of such damages.
|
|
166
|
+
|
|
167
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
168
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
169
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
170
|
+
or other liability obligations and/or rights consistent with this
|
|
171
|
+
License. However, in accepting such obligations, You may act only
|
|
172
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
173
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
174
|
+
defend, and hold each Contributor harmless for any liability
|
|
175
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
176
|
+
of your accepting any such warranty or additional liability.
|
|
177
|
+
|
|
178
|
+
END OF TERMS AND CONDITIONS
|
|
179
|
+
|
|
180
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
181
|
+
|
|
182
|
+
To apply the Apache License to your work, attach the following
|
|
183
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
184
|
+
replaced with your own identifying information. (Don't include
|
|
185
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
186
|
+
comment syntax for the file format. We also recommend that a
|
|
187
|
+
file or class name and description of purpose be included on the
|
|
188
|
+
same "printed page" as the copyright notice for easier
|
|
189
|
+
identification within third-party archives.
|
|
190
|
+
|
|
191
|
+
Copyright [yyyy] [name of copyright owner]
|
|
192
|
+
|
|
193
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
194
|
+
you may not use this file except in compliance with the License.
|
|
195
|
+
You may obtain a copy of the License at
|
|
196
|
+
|
|
197
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
198
|
+
|
|
199
|
+
Unless required by applicable law or agreed to in writing, software
|
|
200
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
201
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
202
|
+
See the License for the specific language governing permissions and
|
|
203
|
+
limitations under the License.
|
|
@@ -0,0 +1,121 @@
|
|
|
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_ALGEBRA_BLAS_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_BLAS_H_
|
|
17
|
+
|
|
18
|
+
// basic linear algebra subroutines
|
|
19
|
+
#include <stddef.h>
|
|
20
|
+
|
|
21
|
+
namespace proofs {
|
|
22
|
+
template <class Field>
|
|
23
|
+
class Blas {
|
|
24
|
+
public:
|
|
25
|
+
using Elt = typename Field::Elt;
|
|
26
|
+
|
|
27
|
+
// SUM_{i} x[i * incx].y[i * incy]
|
|
28
|
+
static Elt dot(size_t n, const Elt x[/*n:incx*/], size_t incx,
|
|
29
|
+
const Elt y[/*n:incy*/], size_t incy, const Field& F) {
|
|
30
|
+
Elt r = F.zero();
|
|
31
|
+
for (size_t i = 0; i < n; i++) {
|
|
32
|
+
F.add(r, F.mulf(x[i * incx], y[i * incy]));
|
|
33
|
+
}
|
|
34
|
+
return r;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// SUM_{i} x[i * incx], or the dot product x^T * 1
|
|
38
|
+
static Elt dot1(size_t n, const Elt x[/*n:incx*/], size_t incx,
|
|
39
|
+
const Field& F) {
|
|
40
|
+
Elt r = F.zero();
|
|
41
|
+
for (size_t i = 0; i < n; ++i) {
|
|
42
|
+
F.add(r, x[i * incx]);
|
|
43
|
+
}
|
|
44
|
+
return r;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// y = a*y
|
|
48
|
+
static void scale(size_t n, Elt y[/*k:incy*/], size_t incy, const Elt a,
|
|
49
|
+
const Field& F) {
|
|
50
|
+
for (size_t i = 0; i < n; i++) {
|
|
51
|
+
F.mul(y[i * incy], a);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// y = a*x + y.
|
|
56
|
+
static void axpy(size_t n, Elt y[/*k:incy*/], size_t incy, const Elt a,
|
|
57
|
+
const Elt x[/*k:incx*/], size_t incx, const Field& F) {
|
|
58
|
+
for (size_t i = 0; i < n; i++) {
|
|
59
|
+
F.add(y[i * incy], F.mulf(x[i * incx], a));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// nonstandard axpy() where A[] is itself an array
|
|
64
|
+
static void vaxpy(size_t n, Elt y[/*k:incy*/], size_t incy,
|
|
65
|
+
const Elt a[/*k:inca*/], size_t inca,
|
|
66
|
+
const Elt x[/*k:incx*/], size_t incx, const Field& F) {
|
|
67
|
+
for (size_t i = 0; i < n; i++) {
|
|
68
|
+
F.add(y[i * incy], F.mulf(x[i * incx], a[i * inca]));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// y[i] -= a[i] * x[i]
|
|
73
|
+
static void vymax(size_t n, Elt y[/*k:incy*/], size_t incy,
|
|
74
|
+
const Elt a[/*k:inca*/], size_t inca,
|
|
75
|
+
const Elt x[/*k:incx*/], size_t incx, const Field& F) {
|
|
76
|
+
for (size_t i = 0; i < n; i++) {
|
|
77
|
+
F.sub(y[i * incy], F.mulf(x[i * incx], a[i * inca]));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static bool equal(size_t n, const Elt x[/*n:incx*/], size_t incx,
|
|
82
|
+
const Elt y[/*n:incy*/], size_t incy, const Field& F) {
|
|
83
|
+
for (size_t i = 0; i < n; i++) {
|
|
84
|
+
if (x[i * incx] != y[i * incy]) return false;
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static bool equal0(size_t n, const Elt x[/*n:incx*/], size_t incx,
|
|
90
|
+
const Field& F) {
|
|
91
|
+
for (size_t i = 0; i < n; i++) {
|
|
92
|
+
if (x[i * incx] != F.zero()) return false;
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static void copy(size_t n, Elt dst[/*n:incx*/], size_t incd,
|
|
98
|
+
const Elt src[/*n:incy*/], size_t incs) {
|
|
99
|
+
for (size_t i = 0; i < n; i++) {
|
|
100
|
+
dst[i * incd] = src[i * incs];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// DST[i] = SRC[IDX[i]]. DST and SRC must not overlap.
|
|
105
|
+
static void gather(size_t n, Elt dst[/*n*/], const Elt src[],
|
|
106
|
+
const size_t idx[/*n*/]) {
|
|
107
|
+
for (size_t i = 0; i < n; i++) {
|
|
108
|
+
dst[i] = src[idx[i]];
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
static void clear(size_t n, Elt dst[/*n:incx*/], size_t incd,
|
|
113
|
+
const Field& F) {
|
|
114
|
+
for (size_t i = 0; i < n; i++) {
|
|
115
|
+
dst[i * incd] = F.zero();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
} // namespace proofs
|
|
120
|
+
|
|
121
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_BLAS_H_
|
|
@@ -0,0 +1,68 @@
|
|
|
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_ALGEBRA_BOGORNG_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_BOGORNG_H_
|
|
17
|
+
|
|
18
|
+
#include <cstdint>
|
|
19
|
+
namespace proofs {
|
|
20
|
+
// Totally bogus "random" number generator, used only for testing.
|
|
21
|
+
// The public and internal functions of this class all take a const Field&
|
|
22
|
+
// parameter to produce random elements in the Field. It is the caller's
|
|
23
|
+
// responsibility to ensure the object remains valid during execution.
|
|
24
|
+
//
|
|
25
|
+
// We are testing mostly with prime fields. Following Knuth, we pick a simple
|
|
26
|
+
// multiplier a, with reasonable Hamming weight, and good spectral scores.
|
|
27
|
+
// The smallest prime we care about is ~23 bits, so we tune "a" for that.
|
|
28
|
+
// For GF2_128, we use the same a*x generator, and have a unit test to ensure
|
|
29
|
+
// there are no short loops.
|
|
30
|
+
//
|
|
31
|
+
// Rank 3: a = 7300988
|
|
32
|
+
// Binary: 0b11011110110011101111100
|
|
33
|
+
// 2D Spectral Score: 2737.21 (Max theoretical is ~3109)
|
|
34
|
+
// 3D Spectral Score: 184.24 (Max theoretical is ~228)
|
|
35
|
+
//
|
|
36
|
+
// 3d: 184.24
|
|
37
|
+
// 3d: 7300988.00 // for > 128-bit field
|
|
38
|
+
template <class Field>
|
|
39
|
+
class Bogorng {
|
|
40
|
+
using Elt = typename Field::Elt;
|
|
41
|
+
|
|
42
|
+
public:
|
|
43
|
+
explicit Bogorng(const Field* F, uint64_t seed = 1234569u,
|
|
44
|
+
uint64_t mul = 7300988u)
|
|
45
|
+
: f_(F), next_(F->of_scalar_field(seed)), mul_(F->of_scalar_field(mul)) {}
|
|
46
|
+
|
|
47
|
+
Elt next() {
|
|
48
|
+
// really old-school
|
|
49
|
+
f_->mul(next_, mul_);
|
|
50
|
+
return next_;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
Elt nonzero() {
|
|
54
|
+
Elt x;
|
|
55
|
+
do {
|
|
56
|
+
x = next();
|
|
57
|
+
} while (x == f_->zero());
|
|
58
|
+
return x;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private:
|
|
62
|
+
const Field* f_;
|
|
63
|
+
Elt next_;
|
|
64
|
+
Elt mul_;
|
|
65
|
+
};
|
|
66
|
+
} // namespace proofs
|
|
67
|
+
|
|
68
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_BOGORNG_H_
|
|
@@ -0,0 +1,40 @@
|
|
|
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_ALGEBRA_COMPARE_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_COMPARE_H_
|
|
17
|
+
|
|
18
|
+
#include <cstddef>
|
|
19
|
+
#include <cstdint>
|
|
20
|
+
|
|
21
|
+
namespace proofs {
|
|
22
|
+
|
|
23
|
+
// canonical a < b operation, defined as lexicographic comparison of
|
|
24
|
+
// the Elt's serialization
|
|
25
|
+
template <class Field>
|
|
26
|
+
bool elt_less_than(const typename Field::Elt& a, const typename Field::Elt& b,
|
|
27
|
+
const Field& F) {
|
|
28
|
+
uint8_t ua[Field::kBytes], ub[Field::kBytes];
|
|
29
|
+
F.to_bytes_field(ua, a);
|
|
30
|
+
F.to_bytes_field(ub, b);
|
|
31
|
+
for (size_t j = 0; j < Field::kBytes; ++j) {
|
|
32
|
+
if (ua[j] < ub[j]) return true;
|
|
33
|
+
if (ua[j] > ub[j]) return false;
|
|
34
|
+
}
|
|
35
|
+
return false; // equal
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
} // namespace proofs
|
|
39
|
+
|
|
40
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_COMPARE_H_
|