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,152 @@
|
|
|
1
|
+
// Copyright 2026 Google LLC.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
#include "util/ceildiv.h"
|
|
16
|
+
|
|
17
|
+
#include <cstddef>
|
|
18
|
+
#include <cstdint>
|
|
19
|
+
|
|
20
|
+
#include "gtest/gtest.h"
|
|
21
|
+
|
|
22
|
+
namespace proofs {
|
|
23
|
+
namespace morton {
|
|
24
|
+
namespace {
|
|
25
|
+
|
|
26
|
+
static uint64_t bit(uint64_t x) { return x & 1u; }
|
|
27
|
+
static uint64_t naive_even(uint64_t x) {
|
|
28
|
+
uint64_t r = 0;
|
|
29
|
+
for (size_t i = 0; i < 32; ++i) {
|
|
30
|
+
r |= bit(x >> (2 * i)) << i;
|
|
31
|
+
}
|
|
32
|
+
return r;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static uint64_t naive_uneven(uint64_t x) {
|
|
36
|
+
uint64_t r = 0;
|
|
37
|
+
for (size_t i = 0; i < 32; ++i) {
|
|
38
|
+
r |= bit(x >> i) << (2 * i);
|
|
39
|
+
}
|
|
40
|
+
return r;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
TEST(Morton, Even) {
|
|
44
|
+
// small integers
|
|
45
|
+
for (uint64_t x = 0; x < 8192; ++x) {
|
|
46
|
+
EXPECT_EQ(naive_even(x), morton::even(x));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// powers of two and neighbors
|
|
50
|
+
for (uint64_t x = 1; x != 0; x *= 2) {
|
|
51
|
+
EXPECT_EQ(naive_even(x - 1), morton::even(x - 1));
|
|
52
|
+
EXPECT_EQ(naive_even(x), morton::even(x));
|
|
53
|
+
EXPECT_EQ(naive_even(x + 1), morton::even(x + 1));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// semi-random
|
|
57
|
+
for (uint64_t x = 0; x < 8192; ++x) {
|
|
58
|
+
uint64_t y = x * 0xdeadbeefabadcafeull;
|
|
59
|
+
EXPECT_EQ(naive_even(y - 1), morton::even(y - 1));
|
|
60
|
+
EXPECT_EQ(naive_even(y), morton::even(y));
|
|
61
|
+
EXPECT_EQ(naive_even(y + 1), morton::even(y + 1));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
TEST(Morton, Uneven) {
|
|
66
|
+
// small integers
|
|
67
|
+
for (uint64_t x = 0; x < 8192; ++x) {
|
|
68
|
+
EXPECT_EQ(naive_uneven(x), morton::uneven(x));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// powers of two and neighbors
|
|
72
|
+
for (uint64_t x = 1; x != 0; x *= 2) {
|
|
73
|
+
EXPECT_EQ(naive_uneven(x - 1), morton::uneven(x - 1));
|
|
74
|
+
EXPECT_EQ(naive_uneven(x), morton::uneven(x));
|
|
75
|
+
EXPECT_EQ(naive_uneven(x + 1), morton::uneven(x + 1));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// semi-random
|
|
79
|
+
for (uint64_t x = 0; x < 8192; ++x) {
|
|
80
|
+
uint64_t y = x * 0xdeadbeefabadcafeull;
|
|
81
|
+
EXPECT_EQ(naive_uneven(y - 1), morton::uneven(y - 1));
|
|
82
|
+
EXPECT_EQ(naive_uneven(y), morton::uneven(y));
|
|
83
|
+
EXPECT_EQ(naive_uneven(y + 1), morton::uneven(y + 1));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
static void one_add_test(uint64_t x, uint64_t y) {
|
|
88
|
+
uint32_t x0 = morton::even(x), x1 = morton::even(x >> 1);
|
|
89
|
+
uint32_t y0 = morton::even(y), y1 = morton::even(y >> 1);
|
|
90
|
+
morton::add<uint32_t>(&x0, &x1, y0, y1);
|
|
91
|
+
uint64_t r = morton::uneven(x0) | (morton::uneven(x1) << 1);
|
|
92
|
+
EXPECT_EQ(r, x + y);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
static void one_sub_test(uint64_t x, uint64_t y) {
|
|
96
|
+
uint32_t x0 = morton::even(x), x1 = morton::even(x >> 1);
|
|
97
|
+
uint32_t y0 = morton::even(y), y1 = morton::even(y >> 1);
|
|
98
|
+
morton::sub<uint32_t>(&x0, &x1, y0, y1);
|
|
99
|
+
uint64_t r = morton::uneven(x0) | (morton::uneven(x1) << 1);
|
|
100
|
+
EXPECT_EQ(r, x - y);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
static void one_lt_test(uint64_t x, uint64_t y) {
|
|
104
|
+
uint32_t x0 = morton::even(x), x1 = morton::even(x >> 1);
|
|
105
|
+
uint32_t y0 = morton::even(y), y1 = morton::even(y >> 1);
|
|
106
|
+
bool lt = morton::lt<uint32_t>(x0, x1, y0, y1);
|
|
107
|
+
// Define x < y as the sign bit of the subtraction.
|
|
108
|
+
// We could cast to int64_t but signed overflow is
|
|
109
|
+
// undefined behavior.
|
|
110
|
+
EXPECT_EQ(lt, (((x - y) >> 63) == 1));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static void one_eq_test(uint64_t x, uint64_t y) {
|
|
114
|
+
uint32_t x0 = morton::even(x), x1 = morton::even(x >> 1);
|
|
115
|
+
uint32_t y0 = morton::even(y), y1 = morton::even(y >> 1);
|
|
116
|
+
bool eq = morton::eq<uint32_t>(x0, x1, y0, y1);
|
|
117
|
+
// Define x < y as the sign bit of the subtraction.
|
|
118
|
+
// We could cast to int64_t but signed overflow is
|
|
119
|
+
// undefined behavior.
|
|
120
|
+
EXPECT_EQ(eq, x == y);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
static void one_test(uint64_t x, uint64_t y) {
|
|
124
|
+
one_add_test(x, y);
|
|
125
|
+
one_sub_test(x, y);
|
|
126
|
+
one_lt_test(x, y);
|
|
127
|
+
one_eq_test(x, y);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
TEST(Morton, AddSub) {
|
|
131
|
+
// small integers
|
|
132
|
+
for (size_t x = 0; x < 256; ++x) {
|
|
133
|
+
for (size_t y = 0; y < 256; ++y) {
|
|
134
|
+
one_test(x, y);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// powers of two plus delta
|
|
139
|
+
for (size_t x = 1; x; x *= 2) {
|
|
140
|
+
for (size_t y = 1; y; y *= 2) {
|
|
141
|
+
for (int dx = -16; dx < 16; ++dx) {
|
|
142
|
+
for (int dy = -16; dy < 16; ++dy) {
|
|
143
|
+
one_test(x + dx, y + dx);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
} // namespace
|
|
151
|
+
} // namespace morton
|
|
152
|
+
} // namespace proofs
|
|
@@ -0,0 +1,45 @@
|
|
|
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_UTIL_CRC64_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_UTIL_CRC64_H_
|
|
17
|
+
|
|
18
|
+
/*
|
|
19
|
+
This package defines 3 basic methods for computing a simple 64-bit CRC.
|
|
20
|
+
It is used for checksum and comparison of datastructures that are internal
|
|
21
|
+
to this library.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
#include <stdlib.h>
|
|
25
|
+
|
|
26
|
+
#include <cstdint>
|
|
27
|
+
|
|
28
|
+
namespace proofs {
|
|
29
|
+
namespace crc64 {
|
|
30
|
+
static inline uint64_t shlu64(uint64_t x, size_t n) {
|
|
31
|
+
return (n >= 64) ? 0u : (x << n);
|
|
32
|
+
}
|
|
33
|
+
static inline uint64_t shru64(uint64_t x, size_t n) {
|
|
34
|
+
return (n >= 64) ? 0u : (x >> n);
|
|
35
|
+
}
|
|
36
|
+
static inline uint64_t update(uint64_t crc, uint64_t u, size_t n = 64) {
|
|
37
|
+
crc ^= u;
|
|
38
|
+
uint64_t l = shlu64(crc, 127u - n) ^ shlu64(crc, 125u - n) ^
|
|
39
|
+
shlu64(crc, 124u - n) ^ shlu64(crc, 64u - n);
|
|
40
|
+
return shru64(crc, n) ^ l ^ (l >> 1) ^ (l >> 3) ^ (l >> 4);
|
|
41
|
+
}
|
|
42
|
+
} // namespace crc64
|
|
43
|
+
} // namespace proofs
|
|
44
|
+
|
|
45
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_UTIL_CRC64_H_
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Copyright 2026 Google LLC.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
#include "util/crypto.h"
|
|
16
|
+
|
|
17
|
+
#include <cstddef>
|
|
18
|
+
#include <cstdint>
|
|
19
|
+
|
|
20
|
+
#include "util/panic.h"
|
|
21
|
+
#include "openssl/rand.h"
|
|
22
|
+
|
|
23
|
+
namespace proofs {
|
|
24
|
+
|
|
25
|
+
void rand_bytes(uint8_t out[/*n*/], size_t n) {
|
|
26
|
+
int ret = RAND_bytes(out, n);
|
|
27
|
+
check(ret == 1, "openssl RAND_bytes failed");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
void hex_to_str(char out[/* 2*n + 1*/], const uint8_t in[/*n*/], size_t n) {
|
|
31
|
+
for (size_t i = 0; i < n; ++i) {
|
|
32
|
+
out[2 * i] = "0123456789abcdef"[in[i] >> 4];
|
|
33
|
+
out[2 * i + 1] = "0123456789abcdef"[in[i] & 0xf];
|
|
34
|
+
}
|
|
35
|
+
out[2 * n] = '\0';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
} // namespace proofs
|
|
@@ -0,0 +1,108 @@
|
|
|
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_UTIL_CRYPTO_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_UTIL_CRYPTO_H_
|
|
17
|
+
|
|
18
|
+
// Encapsulates all of the cryptographic primitives used by this library.
|
|
19
|
+
// Specifically, for the collision-resistant hash function, this library uses
|
|
20
|
+
// SHA256. For a pseudo-random function, this library uses AES in ECB mode.
|
|
21
|
+
// Finally, this library provides a method to generate random bytes using the
|
|
22
|
+
// openssl library.
|
|
23
|
+
|
|
24
|
+
#include <cstddef>
|
|
25
|
+
#include <cstdint>
|
|
26
|
+
#include <cstring>
|
|
27
|
+
|
|
28
|
+
#include "util/panic.h"
|
|
29
|
+
#include "openssl/sha.h"
|
|
30
|
+
#include "openssl/evp.h"
|
|
31
|
+
#include "openssl/aes.h"
|
|
32
|
+
|
|
33
|
+
namespace proofs {
|
|
34
|
+
|
|
35
|
+
constexpr size_t kSHA256DigestSize = 32;
|
|
36
|
+
constexpr size_t kPRFKeySize = 32;
|
|
37
|
+
constexpr size_t kPRFInputSize = 16;
|
|
38
|
+
constexpr size_t kPRFOutputSize = 16;
|
|
39
|
+
|
|
40
|
+
class SHA256 {
|
|
41
|
+
public:
|
|
42
|
+
SHA256() { SHA256_Init(&sha_); }
|
|
43
|
+
|
|
44
|
+
// Disable copy for good measure.
|
|
45
|
+
SHA256(const SHA256&) = delete;
|
|
46
|
+
SHA256& operator=(const SHA256&) = delete;
|
|
47
|
+
|
|
48
|
+
void Update(const uint8_t bytes[/*n*/], size_t n) { SHA256_Update(&sha_, bytes, n); }
|
|
49
|
+
void DigestData(uint8_t digest[/* kSHA256DigestSize */]) {
|
|
50
|
+
SHA256_Final(digest, &sha_);
|
|
51
|
+
}
|
|
52
|
+
void CopyState(const SHA256& src) { sha_ = src.sha_; }
|
|
53
|
+
|
|
54
|
+
void Update8(uint64_t x) {
|
|
55
|
+
uint8_t buf[8];
|
|
56
|
+
for (size_t i = 0; i < 8; ++i) {
|
|
57
|
+
buf[i] = x & 0xff;
|
|
58
|
+
x >>= 8;
|
|
59
|
+
}
|
|
60
|
+
Update(buf, 8);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private:
|
|
64
|
+
SHA256_CTX sha_;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// A pseudo-random function interface. This implementation uses AES in ECB mode.
|
|
68
|
+
// The caller must ensure that arguments are not reused.
|
|
69
|
+
class PRF {
|
|
70
|
+
public:
|
|
71
|
+
explicit PRF(const uint8_t key[/*kPRFKeySize*/]) {
|
|
72
|
+
ctx_ = EVP_CIPHER_CTX_new();
|
|
73
|
+
int ret =
|
|
74
|
+
EVP_EncryptInit_ex(ctx_, EVP_aes_256_ecb(), nullptr, key, nullptr);
|
|
75
|
+
check(ret == 1, "EVP_EncryptInit_ex failed");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
~PRF() { EVP_CIPHER_CTX_free(ctx_); }
|
|
79
|
+
|
|
80
|
+
// Disable copy for good measure.
|
|
81
|
+
PRF(const PRF&) = delete;
|
|
82
|
+
PRF& operator=(const PRF&) = delete;
|
|
83
|
+
|
|
84
|
+
// Evaluate the PRF on the input and write the output to the output buffer.
|
|
85
|
+
// This method should only be used internally by the Transcript class. The
|
|
86
|
+
// caller must ensure that the input and output buffers are different.
|
|
87
|
+
// This function implements a permutation, but we only need to exploit its
|
|
88
|
+
// pseudo-random function property in this application.
|
|
89
|
+
void Eval(uint8_t out[/*kPRFOutputSize*/], uint8_t in[/*kPRFInputSize*/]) {
|
|
90
|
+
int out_len = static_cast<int>(kPRFOutputSize);
|
|
91
|
+
int ret = EVP_EncryptUpdate(ctx_, out, &out_len, in,
|
|
92
|
+
static_cast<int>(kPRFInputSize));
|
|
93
|
+
check(ret == 1, "EVP_EncryptUpdate failed");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private:
|
|
97
|
+
EVP_CIPHER_CTX* ctx_;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// Generate n random bytes, following the openssl API convention.
|
|
101
|
+
// This method will panic if the openssl library fails.
|
|
102
|
+
void rand_bytes(uint8_t out[/*n*/], size_t n);
|
|
103
|
+
|
|
104
|
+
void hex_to_str(char out[/* 2*n + 1*/], const uint8_t in[/*n*/], size_t n);
|
|
105
|
+
|
|
106
|
+
} // namespace proofs
|
|
107
|
+
|
|
108
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_UTIL_CRYPTO_H_
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// Copyright 2026 Google LLC.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
#include "util/log.h"
|
|
16
|
+
|
|
17
|
+
#include <stdarg.h>
|
|
18
|
+
#include <stdio.h>
|
|
19
|
+
|
|
20
|
+
// The logic of these #ifdefs implements the following:
|
|
21
|
+
// 1. If we are building for Android, use the android logging library.
|
|
22
|
+
// 2. If we are building for google3, use the absl logging library.
|
|
23
|
+
// 3. Otherwise, use the std::chrono and fprintf(stderr) for logging.
|
|
24
|
+
|
|
25
|
+
#if defined(__ANDROID__)
|
|
26
|
+
#include <android/log.h>
|
|
27
|
+
#endif
|
|
28
|
+
|
|
29
|
+
#if defined(__ABSL__)
|
|
30
|
+
#include "third_party/absl/log/log.h"
|
|
31
|
+
#else
|
|
32
|
+
// The point of using std::chrono is to avoid the dependency on absl::time.
|
|
33
|
+
#include <chrono>
|
|
34
|
+
#endif
|
|
35
|
+
|
|
36
|
+
namespace proofs {
|
|
37
|
+
|
|
38
|
+
// This implementation maintains its own error thresholds in order to
|
|
39
|
+
// support future migration away from absl or android logging libraries.
|
|
40
|
+
static enum LogLevel _LOG_LEVEL = INFO;
|
|
41
|
+
|
|
42
|
+
#if !defined(__ABSL__)
|
|
43
|
+
static auto _last = std::chrono::steady_clock::now();
|
|
44
|
+
const char* level_str(enum LogLevel l) {
|
|
45
|
+
switch (l) {
|
|
46
|
+
case ERROR:
|
|
47
|
+
return "ERROR";
|
|
48
|
+
case WARNING:
|
|
49
|
+
return "WARNING";
|
|
50
|
+
case INFO:
|
|
51
|
+
return "INFO";
|
|
52
|
+
default:
|
|
53
|
+
return "[Unknown]";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
#endif
|
|
57
|
+
|
|
58
|
+
void set_log_level(enum LogLevel l) { _LOG_LEVEL = l; }
|
|
59
|
+
|
|
60
|
+
void log(enum LogLevel l, const char* format, ...) {
|
|
61
|
+
va_list args;
|
|
62
|
+
va_start(args, format);
|
|
63
|
+
char tmp[1024];
|
|
64
|
+
vsnprintf(tmp, sizeof(tmp), format, args);
|
|
65
|
+
va_end(args);
|
|
66
|
+
|
|
67
|
+
#if defined(__ANDROID__)
|
|
68
|
+
if (l <= _LOG_LEVEL) {
|
|
69
|
+
switch (l) {
|
|
70
|
+
case ERROR:
|
|
71
|
+
__android_log_print(ANDROID_LOG_ERROR, "proofs", "%s", tmp);
|
|
72
|
+
break;
|
|
73
|
+
case WARNING:
|
|
74
|
+
__android_log_print(ANDROID_LOG_WARN, "proofs", "%s", tmp);
|
|
75
|
+
break;
|
|
76
|
+
case INFO:
|
|
77
|
+
__android_log_print(ANDROID_LOG_INFO, "proofs", "%s", tmp);
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
#elif defined(__ABSL__)
|
|
82
|
+
if (l <= _LOG_LEVEL) {
|
|
83
|
+
switch (l) {
|
|
84
|
+
case LogLevel::ERROR:
|
|
85
|
+
LOG(ERROR) << tmp;
|
|
86
|
+
break;
|
|
87
|
+
case LogLevel::WARNING:
|
|
88
|
+
LOG(WARNING) << tmp;
|
|
89
|
+
break;
|
|
90
|
+
case LogLevel::INFO:
|
|
91
|
+
LOG(INFO) << tmp;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
#else
|
|
96
|
+
using microseconds = std::chrono::microseconds;
|
|
97
|
+
using milliseconds = std::chrono::milliseconds;
|
|
98
|
+
if (l <= _LOG_LEVEL) {
|
|
99
|
+
auto nt = std::chrono::steady_clock::now();
|
|
100
|
+
auto mus = std::chrono::duration_cast<microseconds>(nt - _last).count();
|
|
101
|
+
auto ms = std::chrono::duration_cast<milliseconds>(nt - _last).count();
|
|
102
|
+
mus -= ms * 1000;
|
|
103
|
+
_last = nt;
|
|
104
|
+
fprintf(stderr, "[%s][+%5llu.%.3llu ms] %s\n", level_str(_LOG_LEVEL),
|
|
105
|
+
static_cast<long long>(ms), static_cast<long long>(mus), tmp);
|
|
106
|
+
}
|
|
107
|
+
#endif
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
} // namespace proofs
|
|
@@ -0,0 +1,33 @@
|
|
|
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_UTIL_LOG_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_UTIL_LOG_H_
|
|
17
|
+
|
|
18
|
+
// Simple, self-contained logger for this library.
|
|
19
|
+
|
|
20
|
+
namespace proofs {
|
|
21
|
+
|
|
22
|
+
enum LogLevel {
|
|
23
|
+
ERROR = 1,
|
|
24
|
+
WARNING = 10,
|
|
25
|
+
INFO = 100,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
void set_log_level(enum LogLevel l);
|
|
29
|
+
|
|
30
|
+
void log(enum LogLevel l, const char* format, ...);
|
|
31
|
+
} // namespace proofs
|
|
32
|
+
|
|
33
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_UTIL_LOG_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_UTIL_PANIC_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_UTIL_PANIC_H_
|
|
17
|
+
|
|
18
|
+
#if defined(__ABSL__)
|
|
19
|
+
#include "third_party/absl/log/check.h"
|
|
20
|
+
#else
|
|
21
|
+
#include <cstdio>
|
|
22
|
+
#include <cstdlib>
|
|
23
|
+
#endif
|
|
24
|
+
|
|
25
|
+
namespace proofs {
|
|
26
|
+
|
|
27
|
+
inline void check(bool truth, const char* why) {
|
|
28
|
+
#if defined(__ABSL__)
|
|
29
|
+
CHECK(truth) << why;
|
|
30
|
+
#else
|
|
31
|
+
if (!truth) {
|
|
32
|
+
fprintf(stderr, "%s", why);
|
|
33
|
+
abort();
|
|
34
|
+
}
|
|
35
|
+
#endif
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
} // namespace proofs
|
|
39
|
+
|
|
40
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_UTIL_PANIC_H_
|
|
@@ -0,0 +1,67 @@
|
|
|
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_UTIL_READBUFFER_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_UTIL_READBUFFER_H_
|
|
17
|
+
|
|
18
|
+
#include <cstddef>
|
|
19
|
+
#include <cstdint>
|
|
20
|
+
#include <vector>
|
|
21
|
+
|
|
22
|
+
#include "util/panic.h"
|
|
23
|
+
|
|
24
|
+
namespace proofs {
|
|
25
|
+
|
|
26
|
+
class ReadBuffer {
|
|
27
|
+
public:
|
|
28
|
+
explicit ReadBuffer(const uint8_t *buf, size_t sz)
|
|
29
|
+
: buf_(buf), size_(sz), next_(0) {}
|
|
30
|
+
|
|
31
|
+
explicit ReadBuffer(const std::vector<uint8_t> &v)
|
|
32
|
+
: ReadBuffer(v.data(), v.size()) {}
|
|
33
|
+
|
|
34
|
+
// no copies
|
|
35
|
+
ReadBuffer(const ReadBuffer &) = delete;
|
|
36
|
+
|
|
37
|
+
// TRUE if at least N bytes remain
|
|
38
|
+
bool have(size_t n) const { return remaining() >= n; }
|
|
39
|
+
|
|
40
|
+
size_t remaining() const {
|
|
41
|
+
check(next_ <= size_, "next_ <= size_");
|
|
42
|
+
return size_ - next_;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const uint8_t *next(size_t n) {
|
|
46
|
+
check(have(n), "have(n)");
|
|
47
|
+
const uint8_t *p = &buf_[next_];
|
|
48
|
+
next_ += n;
|
|
49
|
+
return p;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
void next(size_t n, uint8_t dest[/*n*/]) {
|
|
53
|
+
const uint8_t *p = next(n);
|
|
54
|
+
for (size_t i = 0; i < n; ++i) {
|
|
55
|
+
dest[i] = p[i];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private:
|
|
60
|
+
const uint8_t *buf_;
|
|
61
|
+
size_t size_;
|
|
62
|
+
size_t next_;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
} // namespace proofs
|
|
66
|
+
|
|
67
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_UTIL_READBUFFER_H_
|
|
@@ -0,0 +1,54 @@
|
|
|
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_UTIL_SERIALIZATION_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_UTIL_SERIALIZATION_H_
|
|
17
|
+
|
|
18
|
+
#include <cstdint>
|
|
19
|
+
|
|
20
|
+
namespace proofs {
|
|
21
|
+
|
|
22
|
+
static inline void u64_to_le(uint8_t a[/*8*/], uint64_t x) {
|
|
23
|
+
a[0] = x & 0xffu;
|
|
24
|
+
a[1] = (x >> 8) & 0xffu;
|
|
25
|
+
a[2] = (x >> 16) & 0xffu;
|
|
26
|
+
a[3] = (x >> 24) & 0xffu;
|
|
27
|
+
a[4] = (x >> 32) & 0xffu;
|
|
28
|
+
a[5] = (x >> 40) & 0xffu;
|
|
29
|
+
a[6] = (x >> 48) & 0xffu;
|
|
30
|
+
a[7] = (x >> 56) & 0xffu;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static inline uint64_t u64_of_le(const uint8_t a[/*8*/]) {
|
|
34
|
+
return ((uint64_t)a[7] << 56) | ((uint64_t)a[6] << 48) |
|
|
35
|
+
((uint64_t)a[5] << 40) | ((uint64_t)a[4] << 32) |
|
|
36
|
+
((uint64_t)a[3] << 24) | ((uint64_t)a[2] << 16) |
|
|
37
|
+
((uint64_t)a[1] << 8) | (uint64_t)a[0];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static inline void u32_to_le(uint8_t a[/*4*/], uint32_t x) {
|
|
41
|
+
a[0] = x & 0xffu;
|
|
42
|
+
a[1] = (x >> 8) & 0xffu;
|
|
43
|
+
a[2] = (x >> 16) & 0xffu;
|
|
44
|
+
a[3] = (x >> 24) & 0xffu;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static inline uint32_t u32_of_le(const uint8_t a[/*4*/]) {
|
|
48
|
+
return ((uint32_t)a[3] << 24) | ((uint32_t)a[2] << 16) |
|
|
49
|
+
((uint32_t)a[1] << 8) | (uint32_t)a[0];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
} // namespace proofs
|
|
53
|
+
|
|
54
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_UTIL_SERIALIZATION_H_
|