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,342 @@
|
|
|
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_FP24_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP24_H_
|
|
17
|
+
|
|
18
|
+
// 24-bit fields
|
|
19
|
+
#include <array>
|
|
20
|
+
#include <cstddef>
|
|
21
|
+
#include <cstdint>
|
|
22
|
+
#include <functional>
|
|
23
|
+
#include <optional>
|
|
24
|
+
#include <utility>
|
|
25
|
+
|
|
26
|
+
#include "algebra/fp_generic.h"
|
|
27
|
+
#include "algebra/nat.h"
|
|
28
|
+
#include "algebra/static_string.h"
|
|
29
|
+
#include "algebra/sysdep.h"
|
|
30
|
+
#include "util/panic.h"
|
|
31
|
+
#include "util/serialization.h"
|
|
32
|
+
|
|
33
|
+
namespace proofs {
|
|
34
|
+
class Fp24 {
|
|
35
|
+
public:
|
|
36
|
+
using N = Nat<1>;
|
|
37
|
+
using TypeTag = PrimeFieldTypeTag;
|
|
38
|
+
|
|
39
|
+
static constexpr size_t kU64 = 1;
|
|
40
|
+
static constexpr size_t kBytes = 4;
|
|
41
|
+
static constexpr size_t kSubFieldBytes = 4;
|
|
42
|
+
static constexpr size_t kBits = 32;
|
|
43
|
+
static constexpr size_t kSubFieldBits = kBits;
|
|
44
|
+
|
|
45
|
+
static constexpr bool kCharacteristicTwo = false;
|
|
46
|
+
static constexpr size_t kNPolyEvaluationPoints = 6;
|
|
47
|
+
static constexpr bool kSupportsDot = false;
|
|
48
|
+
|
|
49
|
+
uint32_t m_;
|
|
50
|
+
struct Elt {
|
|
51
|
+
uint32_t n;
|
|
52
|
+
bool operator==(const Elt& y) const { return n == y.n; }
|
|
53
|
+
bool operator!=(const Elt& y) const { return !operator==(y); }
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
explicit Fp24(uint32_t modulus) : m_(modulus), exact_bits_(kBits) {
|
|
57
|
+
check(modulus <= 0xffffff, "modulus exceeds 24 bits");
|
|
58
|
+
|
|
59
|
+
// Compute the exact number of bits in the modulus.
|
|
60
|
+
// This value helps with sampling.
|
|
61
|
+
while ((m_ & (1u << (exact_bits_ - 1))) == 0) {
|
|
62
|
+
--exact_bits_;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
for (uint32_t i = 0; i < sizeof(k_) / sizeof(k_[0]); ++i) {
|
|
66
|
+
k_[i] = Elt{i};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
mone_ = negf(k_[1]);
|
|
70
|
+
half_ = Elt{1u + (m_ / 2)};
|
|
71
|
+
|
|
72
|
+
for (size_t i = 0; i < kNPolyEvaluationPoints; ++i) {
|
|
73
|
+
poly_evaluation_points_[i] = of_scalar(i);
|
|
74
|
+
if (i == 0) {
|
|
75
|
+
inv_small_scalars_[i] = zero();
|
|
76
|
+
} else {
|
|
77
|
+
inv_small_scalars_[i] = invertf(poly_evaluation_points_[i]);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
Fp24(const Fp24&) = delete;
|
|
83
|
+
Fp24& operator=(const Fp24&) = delete;
|
|
84
|
+
|
|
85
|
+
template <size_t N>
|
|
86
|
+
Elt of_string(const char (&s)[N]) const {
|
|
87
|
+
return of_charp(&s[0]);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
Elt of_string(const StaticString& s) const { return of_charp(s.as_pointer); }
|
|
91
|
+
|
|
92
|
+
// The of_scalar methods should only be used on trusted inputs known
|
|
93
|
+
// at compile time to be valid field elements. As a result, they return
|
|
94
|
+
// Elt directly instead of std::optional, and panic if the condition is not
|
|
95
|
+
// satisfied. All untrusted input should be handled via the of_bytes method.
|
|
96
|
+
Elt of_scalar(uint64_t a) const { return of_scalar_field(a); }
|
|
97
|
+
|
|
98
|
+
Elt of_scalar_field(const std::array<uint64_t, 1>& a) const {
|
|
99
|
+
return of_scalar_field(a[0]);
|
|
100
|
+
}
|
|
101
|
+
Elt of_scalar_field(uint64_t a) const {
|
|
102
|
+
check(static_cast<uint32_t>(a) == a, "scalar too large for uint32_t");
|
|
103
|
+
return of_scalar_field(static_cast<uint32_t>(a));
|
|
104
|
+
}
|
|
105
|
+
Elt of_scalar_field(uint32_t a) const {
|
|
106
|
+
check(a < m_, "of_scalar must be less than m");
|
|
107
|
+
return to_montgomery(a);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
bool fits(uint64_t a) const { return a < m_; }
|
|
111
|
+
|
|
112
|
+
// basis for the binary representation of of_scalar(), so that
|
|
113
|
+
// of_scalar(sum_i b[i] 2^i) = sum_i b[i] beta(i)
|
|
114
|
+
Elt beta(size_t i) const {
|
|
115
|
+
check(i < 64, "i < 64");
|
|
116
|
+
return of_scalar(static_cast<uint64_t>(1) << i);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// a += y
|
|
120
|
+
void add(uint32_t& a, uint32_t y) const { a = addcmovc_32(a - m_, y, a + y); }
|
|
121
|
+
void add(Elt& a, Elt y) const { add(a.n, y.n); }
|
|
122
|
+
|
|
123
|
+
// a -= y
|
|
124
|
+
//
|
|
125
|
+
void sub(uint32_t& a, uint32_t y) const { a = sub_sysdep_32(a, y, m_); }
|
|
126
|
+
void sub(Elt& a, Elt y) const { sub(a.n, y.n); }
|
|
127
|
+
|
|
128
|
+
// x = -x
|
|
129
|
+
void neg(Elt& x) const {
|
|
130
|
+
Elt y{0};
|
|
131
|
+
sub(y, x);
|
|
132
|
+
x = y;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
void mul(uint32_t& x, const Elt& y) const {
|
|
136
|
+
x = (static_cast<uint64_t>(x) * static_cast<uint64_t>(y.n)) % m_;
|
|
137
|
+
}
|
|
138
|
+
void mul(Elt& a, Elt y) const { mul(a.n, y); }
|
|
139
|
+
|
|
140
|
+
// x = 1/x
|
|
141
|
+
void invert(Elt& x) const { x = invertf(x); }
|
|
142
|
+
|
|
143
|
+
// functional interface
|
|
144
|
+
Elt addf(Elt a, const Elt& y) const {
|
|
145
|
+
add(a, y);
|
|
146
|
+
return a;
|
|
147
|
+
}
|
|
148
|
+
Elt subf(Elt a, const Elt& y) const {
|
|
149
|
+
sub(a, y);
|
|
150
|
+
return a;
|
|
151
|
+
}
|
|
152
|
+
Elt mulf(Elt a, const Elt& y) const {
|
|
153
|
+
mul(a, y);
|
|
154
|
+
return a;
|
|
155
|
+
}
|
|
156
|
+
Elt mulf(Elt a, const uint32_t y) const {
|
|
157
|
+
mul(a, Elt{y});
|
|
158
|
+
return a;
|
|
159
|
+
}
|
|
160
|
+
Elt negf(Elt a) const {
|
|
161
|
+
neg(a);
|
|
162
|
+
return a;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// This is the binary extended gcd algorithm, modified
|
|
166
|
+
// to return the inverse of x.
|
|
167
|
+
Elt invertf(Elt x) const {
|
|
168
|
+
uint32_t a = x.n;
|
|
169
|
+
uint32_t b = m_;
|
|
170
|
+
Elt u = one();
|
|
171
|
+
Elt v = zero();
|
|
172
|
+
while (a != 0) {
|
|
173
|
+
if ((a & 0x1u) == 0) {
|
|
174
|
+
a >>= 1;
|
|
175
|
+
byhalf(u);
|
|
176
|
+
} else {
|
|
177
|
+
if (a < b) { // swap to maintain invariant
|
|
178
|
+
std::swap(a, b);
|
|
179
|
+
std::swap(u, v);
|
|
180
|
+
}
|
|
181
|
+
a = (a - b) >> 1;
|
|
182
|
+
sub(u, v);
|
|
183
|
+
byhalf(u);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return v;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
Elt zero() const { return Elt{0}; }
|
|
190
|
+
const Elt& one() const { return k_[1]; }
|
|
191
|
+
const Elt& two() const { return k_[2]; }
|
|
192
|
+
const Elt& half() const { return half_; }
|
|
193
|
+
const Elt& mone() const { return mone_; }
|
|
194
|
+
|
|
195
|
+
Elt poly_evaluation_point(size_t i) const {
|
|
196
|
+
check(i < kNPolyEvaluationPoints, "i < kNPolyEvaluationPoints");
|
|
197
|
+
return poly_evaluation_points_[i];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// return (X[k] - X[k - i])^{-1}, were X[i] is the
|
|
201
|
+
// i-th poly evalaluation point.
|
|
202
|
+
Elt newton_denominator(size_t k, size_t i) const {
|
|
203
|
+
check(k < kNPolyEvaluationPoints, "k < kNPolyEvaluationPoints");
|
|
204
|
+
check(i <= k, "i <= k");
|
|
205
|
+
check(k != (k - i), "k != (k - i)");
|
|
206
|
+
return inv_small_scalars_[/* k - (k - i) = */ i];
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Type for counters. For prime fields counters and field
|
|
210
|
+
// elements have the same representation, so all conversions
|
|
211
|
+
// are trivial.
|
|
212
|
+
struct CElt {
|
|
213
|
+
Elt e;
|
|
214
|
+
};
|
|
215
|
+
CElt as_counter(uint64_t a) const { return CElt{of_scalar_field(a)}; }
|
|
216
|
+
|
|
217
|
+
// Convert a counter into *some* field element such that the counter is
|
|
218
|
+
// zero (as a counter) iff the field element is zero.
|
|
219
|
+
Elt znz_indicator(const CElt& celt) const { return celt.e; }
|
|
220
|
+
|
|
221
|
+
// Reference implementation, unused.
|
|
222
|
+
N from_montgomery_reference(Elt x) const { return from_montgomery(x); }
|
|
223
|
+
|
|
224
|
+
N from_montgomery(Elt x) const { return N{x.n}; }
|
|
225
|
+
|
|
226
|
+
Elt to_montgomery(uint64_t xn) const {
|
|
227
|
+
return Elt{static_cast<uint32_t>(xn)};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Added to pass tests which verify the from_, to_ inverse relationship.
|
|
231
|
+
Elt to_montgomery(const N& xn) const {
|
|
232
|
+
std::array<uint64_t, 1> u = xn.u64();
|
|
233
|
+
return to_montgomery(u[0]);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
bool in_subfield(Elt e) const { return true; }
|
|
237
|
+
|
|
238
|
+
std::optional<Elt> of_bytes_field(const uint8_t ab[/* kBytes */]) const {
|
|
239
|
+
uint32_t an = u32_of_le(ab);
|
|
240
|
+
if (fits(an)) {
|
|
241
|
+
return to_montgomery(an);
|
|
242
|
+
} else {
|
|
243
|
+
return std::nullopt;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
void to_bytes_field(uint8_t ab[/* kBytes */], const Elt& x) const {
|
|
248
|
+
u32_to_le(ab, x.n);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
std::optional<Elt> of_bytes_subfield(const uint8_t ab[/* kBytes */]) const {
|
|
252
|
+
return of_bytes_field(ab);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
void to_bytes_subfield(uint8_t ab[/* kBytes */], const Elt& x) const {
|
|
256
|
+
to_bytes_field(ab, x);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
Elt sample(
|
|
260
|
+
const std::function<void(size_t n, uint8_t buf[])>& fill_bytes) const {
|
|
261
|
+
const size_t total_l = (exact_bits_ + 7) / 8;
|
|
262
|
+
const uint32_t mask = (~static_cast<uint32_t>(0)) >> (32 - exact_bits_);
|
|
263
|
+
uint8_t buf[kBytes] = {0};
|
|
264
|
+
for (;;) {
|
|
265
|
+
fill_bytes(total_l, buf);
|
|
266
|
+
uint32_t an = u32_of_le(buf);
|
|
267
|
+
an &= mask;
|
|
268
|
+
if (an < m_) {
|
|
269
|
+
return to_montgomery(an);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
Elt sample_subfield(
|
|
275
|
+
const std::function<void(size_t n, uint8_t buf[])>& fill_bytes) const {
|
|
276
|
+
return sample(fill_bytes);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// dot product is not supported
|
|
280
|
+
struct NatScaledForDot {};
|
|
281
|
+
|
|
282
|
+
NatScaledForDot prescale_for_dot(Elt e) const {
|
|
283
|
+
check(false, "prescale_for_dot() not implemented");
|
|
284
|
+
return NatScaledForDot{};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
template <size_t WX>
|
|
288
|
+
Elt reduce(const Nat<WX>& xn) const {
|
|
289
|
+
// Need one-limb reduction for crt.h, but other
|
|
290
|
+
// cases are not needed.
|
|
291
|
+
if (WX == 1) {
|
|
292
|
+
std::array<uint64_t, WX> u = xn.u64();
|
|
293
|
+
return reduce(u[0]);
|
|
294
|
+
} else {
|
|
295
|
+
check(false, "reduce() not implemented");
|
|
296
|
+
return zero();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
Elt dot(size_t n, const Nat<1> a[/*n*/],
|
|
300
|
+
const NatScaledForDot b[/*n*/]) const {
|
|
301
|
+
check(false, "dot() not implemented");
|
|
302
|
+
return zero();
|
|
303
|
+
}
|
|
304
|
+
Elt reduce(uint64_t x) const { return Elt{static_cast<uint32_t>(x % m_)}; }
|
|
305
|
+
|
|
306
|
+
private:
|
|
307
|
+
// This method should only be used on static strings known at
|
|
308
|
+
// compile time to be valid field elements. We make it
|
|
309
|
+
// private to prevent misuse.
|
|
310
|
+
Elt of_charp(const char* s) const {
|
|
311
|
+
Elt a(k_[0]);
|
|
312
|
+
Elt base = of_scalar(10);
|
|
313
|
+
if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) {
|
|
314
|
+
s += 2;
|
|
315
|
+
base = of_scalar(16);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
for (; *s; s++) {
|
|
319
|
+
Elt d = of_scalar(digit(*s));
|
|
320
|
+
mul(a, base);
|
|
321
|
+
add(a, d);
|
|
322
|
+
}
|
|
323
|
+
return a;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
void byhalf(Elt& a) const {
|
|
327
|
+
uint32_t b = a.n & 1;
|
|
328
|
+
a.n >>= 1;
|
|
329
|
+
if (b != 0) {
|
|
330
|
+
add(a, half_);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
size_t exact_bits_;
|
|
335
|
+
Elt k_[3]; // small constants
|
|
336
|
+
Elt half_; // 1/2
|
|
337
|
+
Elt mone_; // minus one
|
|
338
|
+
Elt poly_evaluation_points_[kNPolyEvaluationPoints];
|
|
339
|
+
Elt inv_small_scalars_[kNPolyEvaluationPoints];
|
|
340
|
+
};
|
|
341
|
+
} // namespace proofs
|
|
342
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP24_H_
|
|
@@ -0,0 +1,305 @@
|
|
|
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_FP24_6_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP24_6_H_
|
|
17
|
+
|
|
18
|
+
#include <stddef.h>
|
|
19
|
+
|
|
20
|
+
#include <array>
|
|
21
|
+
#include <cstdint>
|
|
22
|
+
#include <functional>
|
|
23
|
+
#include <iterator>
|
|
24
|
+
#include <optional>
|
|
25
|
+
#include <utility>
|
|
26
|
+
|
|
27
|
+
#include "algebra/fp24.h"
|
|
28
|
+
#include "util/panic.h"
|
|
29
|
+
|
|
30
|
+
namespace proofs {
|
|
31
|
+
// Sextic extensions of Fp24(m), represented as P(x) mod (x^6 - beta),
|
|
32
|
+
// where (x^6 - beta) is assumed to be irreducible.
|
|
33
|
+
class Fp24_6 {
|
|
34
|
+
public:
|
|
35
|
+
using BaseField = Fp24;
|
|
36
|
+
using Scalar = BaseField::Elt;
|
|
37
|
+
using TypeTag = BaseField::TypeTag;
|
|
38
|
+
using CElt = BaseField::CElt;
|
|
39
|
+
|
|
40
|
+
// size of the serialization into bytes
|
|
41
|
+
static constexpr size_t kBytes = 6 * BaseField::kBytes;
|
|
42
|
+
static constexpr size_t kBits = 6 * BaseField::kBits;
|
|
43
|
+
static constexpr size_t kSubFieldBytes = BaseField::kBytes;
|
|
44
|
+
static constexpr size_t kSubFieldBits = BaseField::kBits;
|
|
45
|
+
static constexpr bool kCharacteristicTwo = false;
|
|
46
|
+
static constexpr size_t kNPolyEvaluationPoints =
|
|
47
|
+
BaseField::kNPolyEvaluationPoints;
|
|
48
|
+
|
|
49
|
+
struct Elt {
|
|
50
|
+
std::array<Scalar, 6> e;
|
|
51
|
+
bool operator==(const Elt& y) const { return e == y.e; }
|
|
52
|
+
bool operator!=(const Elt& y) const { return !operator==(y); }
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
explicit Fp24_6(const BaseField& F, const uint32_t beta)
|
|
56
|
+
: f_(F), beta_(beta) {
|
|
57
|
+
// We need to compute length-6 sums of a[i] * b[j] * beta.
|
|
58
|
+
// A and B are 24 bit. Beta is 12 bits. Total is 63 bits.
|
|
59
|
+
check(beta <= 0xfff, "beta exceeds 12 bits");
|
|
60
|
+
|
|
61
|
+
for (uint64_t i = 0; i < std::size(k_); ++i) {
|
|
62
|
+
k_[i] = of_scalar(i);
|
|
63
|
+
}
|
|
64
|
+
khalf_ = of_scalar(f_.half());
|
|
65
|
+
kmone_ = of_scalar(f_.mone());
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Fp24_6 is not copyable or assignable because it holds a reference to a
|
|
69
|
+
// Field and precomputes constants based on that field.
|
|
70
|
+
Fp24_6(const Fp24_6&) = delete;
|
|
71
|
+
Fp24_6& operator=(const Fp24_6&) = delete;
|
|
72
|
+
|
|
73
|
+
const BaseField& base_field() const { return f_; }
|
|
74
|
+
|
|
75
|
+
void add(Elt& a, const Elt& y) const {
|
|
76
|
+
for (size_t i = 0; i < 6; ++i) {
|
|
77
|
+
f_.add(a.e[i], y.e[i]);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
void sub(Elt& a, const Elt& y) const {
|
|
81
|
+
for (size_t i = 0; i < 6; ++i) {
|
|
82
|
+
f_.sub(a.e[i], y.e[i]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
void mul(Elt& a, const Elt& y) const {
|
|
86
|
+
std::array<uint64_t, 11> m{};
|
|
87
|
+
// break the BaseField abstraction
|
|
88
|
+
for (size_t i = 0; i < 6; ++i) {
|
|
89
|
+
for (size_t j = 0; j < 6; ++j) {
|
|
90
|
+
m[i + j] +=
|
|
91
|
+
static_cast<uint64_t>(a.e[i].n) * static_cast<uint64_t>(y.e[j].n);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
for (size_t i = 0; i < 5; ++i) {
|
|
95
|
+
m[i] += m[i + 6] * beta_;
|
|
96
|
+
}
|
|
97
|
+
for (size_t i = 0; i < 6; ++i) {
|
|
98
|
+
a.e[i] = f_.reduce(m[i]);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
void mul(Elt& a, const Scalar& y) const {
|
|
102
|
+
for (size_t i = 0; i < 6; ++i) {
|
|
103
|
+
f_.mul(a.e[i], y);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
void neg(Elt& x) const {
|
|
107
|
+
for (size_t i = 0; i < 6; ++i) {
|
|
108
|
+
f_.neg(x.e[i]);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
void invert(Elt& x) const {
|
|
112
|
+
if (in_subfield(x)) {
|
|
113
|
+
f_.invert(x.e[0]);
|
|
114
|
+
} else {
|
|
115
|
+
gaussian_elimination_invert(x);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// functional interface
|
|
120
|
+
Elt addf(Elt a, const Elt& y) const {
|
|
121
|
+
add(a, y);
|
|
122
|
+
return a;
|
|
123
|
+
}
|
|
124
|
+
Elt subf(Elt a, const Elt& y) const {
|
|
125
|
+
sub(a, y);
|
|
126
|
+
return a;
|
|
127
|
+
}
|
|
128
|
+
Elt mulf(Elt a, const Elt& y) const {
|
|
129
|
+
mul(a, y);
|
|
130
|
+
return a;
|
|
131
|
+
}
|
|
132
|
+
Elt mulf(Elt a, const Scalar& y) const {
|
|
133
|
+
mul(a, y);
|
|
134
|
+
return a;
|
|
135
|
+
}
|
|
136
|
+
Elt negf(Elt a) const {
|
|
137
|
+
neg(a);
|
|
138
|
+
return a;
|
|
139
|
+
}
|
|
140
|
+
Elt invertf(Elt a) const {
|
|
141
|
+
invert(a);
|
|
142
|
+
return a;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
bool fits(uint64_t a) const { return f_.fits(a); }
|
|
146
|
+
|
|
147
|
+
Elt of_scalar(uint64_t a) const { return of_scalar_field(a); }
|
|
148
|
+
Elt of_scalar(const Scalar& e) const { return of_scalar_field(e); }
|
|
149
|
+
|
|
150
|
+
Elt of_scalar_field(const Scalar& e) const { return Elt{e}; }
|
|
151
|
+
Elt of_scalar_field(uint64_t a) const { return Elt{f_.of_scalar(a)}; }
|
|
152
|
+
Elt of_scalar_field(const std::array<uint64_t, 6>& a) const {
|
|
153
|
+
Elt e;
|
|
154
|
+
for (size_t i = 0; i < 6; ++i) {
|
|
155
|
+
e.e[i] = f_.of_scalar_field(a[i]);
|
|
156
|
+
}
|
|
157
|
+
return e;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
template <size_t N>
|
|
161
|
+
Elt of_string(const char (&s)[N]) const {
|
|
162
|
+
return of_scalar(f_.of_string(s));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
std::optional<Elt> of_bytes_field(const uint8_t ab[/* kBytes */]) const {
|
|
166
|
+
Elt e;
|
|
167
|
+
for (size_t i = 0; i < 6; ++i) {
|
|
168
|
+
auto scalar_opt = f_.of_bytes_field(ab + i * BaseField::kBytes);
|
|
169
|
+
if (!scalar_opt.has_value()) {
|
|
170
|
+
return std::nullopt;
|
|
171
|
+
}
|
|
172
|
+
e.e[i] = scalar_opt.value();
|
|
173
|
+
}
|
|
174
|
+
return e;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
Elt sample(
|
|
178
|
+
const std::function<void(size_t n, uint8_t buf[])>& fill_bytes) const {
|
|
179
|
+
Elt e;
|
|
180
|
+
for (size_t i = 0; i < 6; ++i) {
|
|
181
|
+
e.e[i] = f_.sample(fill_bytes);
|
|
182
|
+
}
|
|
183
|
+
return e;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
Elt sample_subfield(
|
|
187
|
+
const std::function<void(size_t n, uint8_t buf[])>& fill_bytes) const {
|
|
188
|
+
auto re = f_.sample(fill_bytes);
|
|
189
|
+
return of_scalar_field(re);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
void to_bytes_field(uint8_t ab[/* kBytes */], const Elt& x) const {
|
|
193
|
+
for (size_t i = 0; i < 6; ++i) {
|
|
194
|
+
f_.to_bytes_field(ab + i * BaseField::kBytes, x.e[i]);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
bool in_subfield(const Elt& e) const {
|
|
199
|
+
for (size_t i = 1; i < 6; ++i) {
|
|
200
|
+
if (e.e[i] != f_.zero()) return false;
|
|
201
|
+
}
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
std::optional<Elt> of_bytes_subfield(
|
|
206
|
+
const uint8_t ab[/* kSubFieldBytes */]) const {
|
|
207
|
+
if (auto re = f_.of_bytes_subfield(ab)) {
|
|
208
|
+
return of_scalar(re.value());
|
|
209
|
+
}
|
|
210
|
+
return std::nullopt;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
void to_bytes_subfield(uint8_t ab[/* kSubFieldBytes */], const Elt& x) const {
|
|
214
|
+
check(in_subfield(x), "x not in subfield");
|
|
215
|
+
f_.to_bytes_subfield(ab, x.e[0]);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const Elt& zero() const { return k_[0]; }
|
|
219
|
+
const Elt& one() const { return k_[1]; }
|
|
220
|
+
const Elt& two() const { return k_[2]; }
|
|
221
|
+
const Elt& half() const { return khalf_; }
|
|
222
|
+
const Elt& mone() const { return kmone_; }
|
|
223
|
+
|
|
224
|
+
Elt beta(size_t i) const { return of_scalar(f_.beta(i)); }
|
|
225
|
+
|
|
226
|
+
Elt poly_evaluation_point(size_t i) const {
|
|
227
|
+
return of_scalar(f_.poly_evaluation_point(i));
|
|
228
|
+
}
|
|
229
|
+
Elt newton_denominator(size_t k, size_t i) const {
|
|
230
|
+
return of_scalar(f_.newton_denominator(k, i));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Optimized implementation of from_montgomery_reference(), exploiting
|
|
234
|
+
// the fact that the multiplicand is Elt{N(1)}.
|
|
235
|
+
BaseField::N from_montgomery(const Elt& x) const {
|
|
236
|
+
for (size_t i = 1; i < 6; ++i) {
|
|
237
|
+
check(x.e[i] == f_.zero(), "x not in subfield");
|
|
238
|
+
}
|
|
239
|
+
return f_.from_montgomery(x.e[0]);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
private:
|
|
243
|
+
const BaseField& f_;
|
|
244
|
+
uint32_t beta_;
|
|
245
|
+
Elt k_[3]; // small constants
|
|
246
|
+
Elt khalf_;
|
|
247
|
+
Elt kmone_;
|
|
248
|
+
|
|
249
|
+
// Invert via gaussian elimination with partial pivoting
|
|
250
|
+
//
|
|
251
|
+
// Viewing the element X to be inverted as a polynomial
|
|
252
|
+
// A(x), we want to find B(x) such that A(x) * B(x) = 1
|
|
253
|
+
// mod (x^6 - beta). View this as a system of linear
|
|
254
|
+
// equations in the coefficients of B.
|
|
255
|
+
void gaussian_elimination_invert(Elt& x) const {
|
|
256
|
+
constexpr size_t n = 6;
|
|
257
|
+
std::array<std::array<Scalar, n>, n> A;
|
|
258
|
+
|
|
259
|
+
// Set up the beta-circulant matrix representing the Elt
|
|
260
|
+
// to be inverted
|
|
261
|
+
for (size_t i = 0; i < n; ++i) {
|
|
262
|
+
for (size_t j = 0; j < n; ++j) {
|
|
263
|
+
A[i][j] = (i >= j) ? x.e[i - j] : f_.mulf(x.e[i - j + n], beta_);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// initialize the right-hand side B, stored in-place as X
|
|
268
|
+
x = one();
|
|
269
|
+
|
|
270
|
+
// gaussian elimination
|
|
271
|
+
for (size_t i = 0; i < n; ++i) {
|
|
272
|
+
for (size_t r = i; r < n; ++r) {
|
|
273
|
+
if (A[r][i] != f_.zero()) {
|
|
274
|
+
if (i != r) {
|
|
275
|
+
std::swap(A[i], A[r]);
|
|
276
|
+
std::swap(x.e[i], x.e[r]);
|
|
277
|
+
}
|
|
278
|
+
goto have_pivot;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
check(false, "element is not invertible");
|
|
282
|
+
|
|
283
|
+
have_pivot:
|
|
284
|
+
Scalar scal = f_.invertf(A[i][i]);
|
|
285
|
+
for (size_t j = i; j < n; ++j) {
|
|
286
|
+
f_.mul(A[i][j], scal);
|
|
287
|
+
}
|
|
288
|
+
f_.mul(x.e[i], scal);
|
|
289
|
+
|
|
290
|
+
// eliminate all other rows k
|
|
291
|
+
for (size_t k = 0; k < n; ++k) {
|
|
292
|
+
if (k != i) {
|
|
293
|
+
Scalar a = A[k][i];
|
|
294
|
+
for (size_t j = i; j < n; ++j) {
|
|
295
|
+
f_.sub(A[k][j], f_.mulf(a, A[i][j]));
|
|
296
|
+
}
|
|
297
|
+
f_.sub(x.e[k], f_.mulf(a, x.e[i]));
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
} // namespace proofs
|
|
304
|
+
|
|
305
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP24_6_H_
|