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
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: a2421e8e860bf25c8098ed549c1e80af167266f5501e83339584b1e6ecbd5a3d
|
|
4
|
+
data.tar.gz: 668f55d3772117c37918aa76374251e64c3c848680a2bb87e59eebb2b97f7ef7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: bc45c228cd8f9aa0e3f09c88cf98459318bd9e55fb2d82c8fe04762a2857406b33ac3dd969f6e041f829a38b065473643f4d783d1277d458ca8a36adfeb1f270
|
|
7
|
+
data.tar.gz: a68ed9796d63d4792feea36c1deff8fb178e0065e7d0509a7526d92020c192bb445b5f94e89b43bce4b4c7d1d965ffc2597c2629f594dfae529ab5e74fb0c3f5
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Code of Conduct
|
|
2
|
+
|
|
3
|
+
"longfellow" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
|
|
4
|
+
|
|
5
|
+
* Participants will be tolerant of opposing views.
|
|
6
|
+
* Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
|
|
7
|
+
* When interpreting the words and actions of others, participants should always assume good intentions.
|
|
8
|
+
* Behaviour which can be reasonably considered harassment will not be tolerated.
|
|
9
|
+
|
|
10
|
+
If you have any concerns about behaviour within this project, please contact us at ["azuchi@chaintope.com"](mailto:"azuchi@chaintope.com").
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 azuchi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# Longfellow
|
|
2
|
+
|
|
3
|
+
Ruby bindings for Google's [longfellow-zk](https://github.com/google/longfellow-zk),
|
|
4
|
+
the zero-knowledge library for identity protocols. This gem lets you generate
|
|
5
|
+
and verify zero-knowledge proofs over ISO **mdoc / mDL** verifiable credentials
|
|
6
|
+
directly from Ruby.
|
|
7
|
+
|
|
8
|
+
The bindings load the upstream C ABI (`run_mdoc_prover`, `run_mdoc_verifier`,
|
|
9
|
+
`generate_circuit`, ...) through [Ruby-FFI](https://github.com/ffi/ffi). The
|
|
10
|
+
native library is compiled from the vendored upstream sources at install time.
|
|
11
|
+
|
|
12
|
+
## Supported version
|
|
13
|
+
|
|
14
|
+
This gem vendors **[google/longfellow-zk](https://github.com/google/longfellow-zk)
|
|
15
|
+
`v0.9`**, pinned as a git submodule (`vendor/longfellow-zk`). The native library
|
|
16
|
+
is built from exactly that revision, and the ZK system it exposes is
|
|
17
|
+
`longfellow-libzk-v1`.
|
|
18
|
+
|
|
19
|
+
Only the ISO **mdoc / mDL** C ABI (`circuits/mdoc/mdoc_zk.h`) is wrapped. JWT and
|
|
20
|
+
W3C Verifiable Credentials are not supported, because upstream provides no C ABI
|
|
21
|
+
for them (they exist only as experimental C++ circuit templates).
|
|
22
|
+
|
|
23
|
+
## Requirements
|
|
24
|
+
|
|
25
|
+
The native library is built from source during installation, so the build
|
|
26
|
+
toolchain must be available:
|
|
27
|
+
|
|
28
|
+
- A C++17 compiler (`clang++` preferred, `g++` works)
|
|
29
|
+
- [CMake](https://cmake.org/) >= 3.13
|
|
30
|
+
- OpenSSL (libcrypto) development headers
|
|
31
|
+
- zstd (libzstd) development headers
|
|
32
|
+
|
|
33
|
+
On Debian/Ubuntu:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
sudo apt-get install build-essential cmake clang libssl-dev libzstd-dev
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
This gem vendors longfellow-zk as a git submodule, so a source checkout must
|
|
42
|
+
initialize submodules before building:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
git clone https://github.com/azuchi/longfellow.git
|
|
46
|
+
cd longfellow
|
|
47
|
+
git submodule update --init --recursive
|
|
48
|
+
bundle install
|
|
49
|
+
bundle exec rake compile
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Add it to a project's Gemfile from git:
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
gem "longfellow", git: "https://github.com/azuchi/longfellow.git", submodules: true
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Usage
|
|
59
|
+
|
|
60
|
+
```ruby
|
|
61
|
+
require "longfellow"
|
|
62
|
+
|
|
63
|
+
# 1. Pick a ZK specification (these are hardcoded in the native library).
|
|
64
|
+
# Each spec fixes the circuit format and the number of attributes it opens.
|
|
65
|
+
spec = Longfellow.zk_specs.first # 1 attribute, longfellow-libzk v7
|
|
66
|
+
# or look one up by system name + circuit hash that a peer advertised:
|
|
67
|
+
# spec = Longfellow.find_zk_spec("longfellow-libzk-v1", "8d0792...")
|
|
68
|
+
|
|
69
|
+
# 2. Generate the circuit bytes for that spec. This is deterministic and can be
|
|
70
|
+
# cached and shared between provers and verifiers.
|
|
71
|
+
circuit = Longfellow.generate_circuit(spec)
|
|
72
|
+
Longfellow.circuit_id(circuit, spec).unpack1("H*") # == spec.circuit_hash
|
|
73
|
+
|
|
74
|
+
# 3. Describe the claims to open.
|
|
75
|
+
attribute = Longfellow::Attribute.new(
|
|
76
|
+
namespace_id: "org.iso.18013.5.1",
|
|
77
|
+
id: "age_over_18",
|
|
78
|
+
cbor_value: "\xF5".b # CBOR true
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
# 4. Prover side: produce a proof.
|
|
82
|
+
proof = Longfellow.prove(
|
|
83
|
+
circuit: circuit,
|
|
84
|
+
mdoc: mdoc_bytes, # the full mdoc/mDL
|
|
85
|
+
public_key_x: issuer_pkx, # string representation of the issuer key
|
|
86
|
+
public_key_y: issuer_pky,
|
|
87
|
+
transcript: session_transcript,
|
|
88
|
+
attributes: [attribute],
|
|
89
|
+
now: "2024-01-30T09:00:00Z",
|
|
90
|
+
zk_spec: spec
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
# 5. Verifier side: check it. Returns true, or raises Longfellow::VerifierError.
|
|
94
|
+
Longfellow.verify(
|
|
95
|
+
circuit: circuit,
|
|
96
|
+
public_key_x: issuer_pkx,
|
|
97
|
+
public_key_y: issuer_pky,
|
|
98
|
+
transcript: session_transcript,
|
|
99
|
+
attributes: [attribute],
|
|
100
|
+
now: "2024-01-30T09:00:00Z",
|
|
101
|
+
proof: proof,
|
|
102
|
+
doc_type: Longfellow::DEFAULT_DOC_TYPE,
|
|
103
|
+
zk_spec: spec
|
|
104
|
+
)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`Attribute`s may also be passed as plain hashes:
|
|
108
|
+
|
|
109
|
+
```ruby
|
|
110
|
+
attributes: [{ namespace_id: "org.iso.18013.5.1", id: "age_over_18", cbor_value: "\xF5".b }]
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## API
|
|
114
|
+
|
|
115
|
+
| Method | Description |
|
|
116
|
+
| --- | --- |
|
|
117
|
+
| `Longfellow.zk_specs` | All ZK specifications compiled into the library. |
|
|
118
|
+
| `Longfellow.find_zk_spec(system, hash)` | Look up a spec by system name and circuit hash (`nil` if unknown). |
|
|
119
|
+
| `Longfellow.generate_circuit(spec)` | Compressed circuit bytes for a spec. |
|
|
120
|
+
| `Longfellow.circuit_id(circuit, spec)` | 32-byte SHA-256 identifier of a circuit bundle. |
|
|
121
|
+
| `Longfellow.prove(...)` | Generate a proof; raises `Longfellow::ProverError` on failure. |
|
|
122
|
+
| `Longfellow.verify(...)` | Verify a proof; returns `true` or raises `Longfellow::VerifierError`. |
|
|
123
|
+
|
|
124
|
+
Errors carry a stable `#symbol` and the raw native `#code`:
|
|
125
|
+
|
|
126
|
+
```ruby
|
|
127
|
+
begin
|
|
128
|
+
Longfellow.verify(...)
|
|
129
|
+
rescue Longfellow::VerifierError => e
|
|
130
|
+
e.symbol # e.g. :general_failure
|
|
131
|
+
e.code # the raw MdocVerifierErrorCode integer
|
|
132
|
+
end
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Development
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
bundle exec rake compile # build the native library
|
|
139
|
+
bundle exec rspec --tag ~slow # fast unit specs
|
|
140
|
+
bundle exec rspec --tag slow # full prove/verify round trip (~13s)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
The slow integration spec exercises a real prover → verifier round trip against
|
|
144
|
+
an mdoc test vector extracted from the upstream examples.
|
|
145
|
+
|
|
146
|
+
## License
|
|
147
|
+
|
|
148
|
+
This gem is available under the [MIT License](LICENSE.txt).
|
|
149
|
+
|
|
150
|
+
The vendored upstream library, [google/longfellow-zk](https://github.com/google/longfellow-zk),
|
|
151
|
+
is distributed under the Apache License 2.0; see
|
|
152
|
+
`vendor/longfellow-zk/LICENSE`.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Self-contained build of the longfellow-zk mdoc ZK C ABI as a single shared
|
|
2
|
+
# library suitable for loading via Ruby-FFI.
|
|
3
|
+
#
|
|
4
|
+
# Upstream's top-level CMake pulls in GoogleTest/Benchmark via
|
|
5
|
+
# find_package(... REQUIRED), which we do not want as install-time
|
|
6
|
+
# dependencies. Instead we compile only the translation units that make up the
|
|
7
|
+
# upstream `mdoc_static` target (mdoc + flatsha + ec + algebra + util) and link
|
|
8
|
+
# against the system OpenSSL (crypto) and zstd. Everything else used by the
|
|
9
|
+
# prover/verifier (ligero, sumcheck, zk, gf2k, cbor, ...) is header-only
|
|
10
|
+
# template code and needs no separate compilation.
|
|
11
|
+
cmake_minimum_required(VERSION 3.13)
|
|
12
|
+
project(longfellow_native CXX)
|
|
13
|
+
|
|
14
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
15
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
16
|
+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
17
|
+
|
|
18
|
+
if(NOT CMAKE_BUILD_TYPE)
|
|
19
|
+
set(CMAKE_BUILD_TYPE Release)
|
|
20
|
+
endif()
|
|
21
|
+
|
|
22
|
+
# Root of the vendored upstream tree (include paths are relative to lib/).
|
|
23
|
+
get_filename_component(LFZK_ROOT
|
|
24
|
+
"${CMAKE_CURRENT_SOURCE_DIR}/../../vendor/longfellow-zk/lib" ABSOLUTE)
|
|
25
|
+
|
|
26
|
+
if(NOT EXISTS "${LFZK_ROOT}/circuits/mdoc/mdoc_zk.h")
|
|
27
|
+
message(FATAL_ERROR
|
|
28
|
+
"vendored longfellow-zk sources not found at ${LFZK_ROOT}. "
|
|
29
|
+
"Run: git submodule update --init --recursive")
|
|
30
|
+
endif()
|
|
31
|
+
|
|
32
|
+
# Mirror the architecture-specific flags upstream uses (carry-less multiply for
|
|
33
|
+
# the GF(2^128) arithmetic, etc.).
|
|
34
|
+
string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" LFZK_ARCH)
|
|
35
|
+
if(LFZK_ARCH MATCHES "x86_64|amd64")
|
|
36
|
+
set(ARCH_FLAGS -mpclmul)
|
|
37
|
+
elseif(LFZK_ARCH MATCHES "i386|i686")
|
|
38
|
+
set(ARCH_FLAGS -msse2 -mpclmul)
|
|
39
|
+
elseif(LFZK_ARCH MATCHES "aarch64|arm64")
|
|
40
|
+
set(ARCH_FLAGS -march=armv8-a+crypto)
|
|
41
|
+
elseif(LFZK_ARCH MATCHES "armv7")
|
|
42
|
+
set(ARCH_FLAGS -march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=hard)
|
|
43
|
+
else()
|
|
44
|
+
set(ARCH_FLAGS "")
|
|
45
|
+
message(STATUS "Unrecognized architecture '${LFZK_ARCH}', no ISA flags added.")
|
|
46
|
+
endif()
|
|
47
|
+
|
|
48
|
+
set(LFZK_SOURCES
|
|
49
|
+
${LFZK_ROOT}/util/log.cc
|
|
50
|
+
${LFZK_ROOT}/util/crypto.cc
|
|
51
|
+
${LFZK_ROOT}/algebra/nat.cc
|
|
52
|
+
${LFZK_ROOT}/algebra/crt.cc
|
|
53
|
+
${LFZK_ROOT}/ec/p256.cc
|
|
54
|
+
${LFZK_ROOT}/ec/p256k1.cc
|
|
55
|
+
${LFZK_ROOT}/circuits/sha/flatsha256_witness.cc
|
|
56
|
+
${LFZK_ROOT}/circuits/sha/sha256_constants.cc
|
|
57
|
+
${LFZK_ROOT}/circuits/mdoc/mdoc_zk.cc
|
|
58
|
+
${LFZK_ROOT}/circuits/mdoc/mdoc_decompress.cc
|
|
59
|
+
${LFZK_ROOT}/circuits/mdoc/mdoc_generate_circuit.cc
|
|
60
|
+
${LFZK_ROOT}/circuits/mdoc/mdoc_circuit_id.cc
|
|
61
|
+
${LFZK_ROOT}/circuits/mdoc/zk_spec.cc
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
add_library(longfellow_native SHARED ${LFZK_SOURCES})
|
|
65
|
+
target_include_directories(longfellow_native PRIVATE ${LFZK_ROOT})
|
|
66
|
+
target_compile_options(longfellow_native PRIVATE
|
|
67
|
+
$<$<COMPILE_LANGUAGE:CXX>:${ARCH_FLAGS}>)
|
|
68
|
+
|
|
69
|
+
# The upstream C ABI lives in extern "C" functions compiled with default
|
|
70
|
+
# visibility, so they are exported from the shared object as-is.
|
|
71
|
+
|
|
72
|
+
find_package(OpenSSL REQUIRED)
|
|
73
|
+
target_link_libraries(longfellow_native PRIVATE OpenSSL::Crypto)
|
|
74
|
+
|
|
75
|
+
find_library(ZSTD_LIBRARY NAMES zstd libzstd REQUIRED)
|
|
76
|
+
target_link_libraries(longfellow_native PRIVATE ${ZSTD_LIBRARY})
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# This is not a conventional mkmf C extension. The native artifact is the
|
|
4
|
+
# longfellow-zk C ABI compiled (via CMake) into a single shared object that the
|
|
5
|
+
# pure-Ruby FFI layer loads at runtime. RubyGems still drives extension builds
|
|
6
|
+
# through `extconf.rb` + `make`, so here we:
|
|
7
|
+
#
|
|
8
|
+
# 1. run CMake to build ext/longfellow/build/liblongfellow_native.{so,dylib}
|
|
9
|
+
# 2. copy the result next to the Ruby sources (lib/longfellow/)
|
|
10
|
+
# 3. emit a trivial Makefile whose `all`/`install`/`clean` targets succeed
|
|
11
|
+
#
|
|
12
|
+
# so the standard `gem install` flow works unchanged.
|
|
13
|
+
|
|
14
|
+
require "fileutils"
|
|
15
|
+
require "rbconfig"
|
|
16
|
+
|
|
17
|
+
ext_dir = __dir__
|
|
18
|
+
gem_root = File.expand_path("../..", ext_dir)
|
|
19
|
+
build_dir = File.join(ext_dir, "build")
|
|
20
|
+
lib_out = File.join(gem_root, "lib", "longfellow")
|
|
21
|
+
vendor = File.join(gem_root, "vendor", "longfellow-zk", "lib", "circuits",
|
|
22
|
+
"mdoc", "mdoc_zk.h")
|
|
23
|
+
|
|
24
|
+
abort_msg = lambda do |msg|
|
|
25
|
+
warn "[longfellow] #{msg}"
|
|
26
|
+
exit(1)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
unless File.exist?(vendor)
|
|
30
|
+
abort_msg.call(
|
|
31
|
+
"vendored longfellow-zk sources are missing. When installing from a git " \
|
|
32
|
+
"checkout run: git submodule update --init --recursive"
|
|
33
|
+
)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def find_tool(*names)
|
|
37
|
+
names.each do |name|
|
|
38
|
+
path = `command -v #{name} 2>/dev/null`.strip
|
|
39
|
+
return path unless path.empty?
|
|
40
|
+
end
|
|
41
|
+
nil
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
cmake = find_tool("cmake")
|
|
45
|
+
abort_msg.call("cmake was not found in PATH; it is required to build longfellow.") unless cmake
|
|
46
|
+
|
|
47
|
+
# Prefer clang++ to match upstream, but fall back to the platform default.
|
|
48
|
+
cxx = find_tool("clang++", "g++")
|
|
49
|
+
|
|
50
|
+
config_cmd = [cmake, "-S", ext_dir, "-B", build_dir, "-DCMAKE_BUILD_TYPE=Release"]
|
|
51
|
+
config_cmd << "-DCMAKE_CXX_COMPILER=#{cxx}" if cxx
|
|
52
|
+
|
|
53
|
+
puts "[longfellow] configuring native library..."
|
|
54
|
+
system(*config_cmd) || abort_msg.call("cmake configure failed")
|
|
55
|
+
|
|
56
|
+
puts "[longfellow] building native library..."
|
|
57
|
+
jobs = (ENV["MAKEFLAGS"].to_s[/-j\s*(\d+)/, 1] || 4)
|
|
58
|
+
system(cmake, "--build", build_dir, "--parallel", jobs.to_s) ||
|
|
59
|
+
abort_msg.call("cmake build failed")
|
|
60
|
+
|
|
61
|
+
so = Dir[File.join(build_dir, "liblongfellow_native.{so,dylib,bundle}")].first
|
|
62
|
+
abort_msg.call("native library was not produced") unless so
|
|
63
|
+
|
|
64
|
+
FileUtils.mkdir_p(lib_out)
|
|
65
|
+
FileUtils.cp(so, lib_out)
|
|
66
|
+
puts "[longfellow] installed #{File.basename(so)} -> lib/longfellow/"
|
|
67
|
+
|
|
68
|
+
# A no-op Makefile so that `make` and `make install` invoked by RubyGems pass.
|
|
69
|
+
File.write(File.join(ext_dir, "Makefile"), <<~MAKEFILE)
|
|
70
|
+
all:
|
|
71
|
+
\t@true
|
|
72
|
+
install:
|
|
73
|
+
\t@true
|
|
74
|
+
clean:
|
|
75
|
+
\t@true
|
|
76
|
+
.PHONY: all install clean
|
|
77
|
+
MAKEFILE
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Longfellow
|
|
4
|
+
# A claim that the prover must open and the verifier checks: a single mdoc
|
|
5
|
+
# attribute identified by its namespace and element identifier, together with
|
|
6
|
+
# the expected value encoded as the raw bytes of its CBOR representation.
|
|
7
|
+
#
|
|
8
|
+
# Mirrors the C `RequestedAttribute` struct. The fixed-size C buffers bound the
|
|
9
|
+
# lengths: namespace_id <= 64, id <= 32, cbor_value <= 64 bytes.
|
|
10
|
+
class Attribute
|
|
11
|
+
MAX_NAMESPACE = 64
|
|
12
|
+
MAX_ID = 32
|
|
13
|
+
MAX_CBOR_VALUE = 64
|
|
14
|
+
|
|
15
|
+
attr_reader :namespace_id, :id, :cbor_value
|
|
16
|
+
|
|
17
|
+
# @param namespace_id [String] e.g. "org.iso.18013.5.1"
|
|
18
|
+
# @param id [String] element identifier, e.g. "age_over_18"
|
|
19
|
+
# @param cbor_value [String] raw CBOR-encoded value bytes
|
|
20
|
+
def initialize(namespace_id:, id:, cbor_value:)
|
|
21
|
+
@namespace_id = String(namespace_id).b
|
|
22
|
+
@id = String(id).b
|
|
23
|
+
@cbor_value = String(cbor_value).b
|
|
24
|
+
validate!
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Coerce a Hash or Attribute into an Attribute.
|
|
28
|
+
def self.coerce(obj)
|
|
29
|
+
case obj
|
|
30
|
+
when Attribute then obj
|
|
31
|
+
when Hash then new(**obj.transform_keys(&:to_sym))
|
|
32
|
+
else
|
|
33
|
+
raise ArgumentError,
|
|
34
|
+
"expected Longfellow::Attribute or Hash, got #{obj.class}"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Populate a C::RequestedAttribute struct (backed by zeroed memory).
|
|
39
|
+
def write_to(struct)
|
|
40
|
+
ptr = struct.to_ptr
|
|
41
|
+
ptr.put_bytes(struct.offset_of(:namespace_id), @namespace_id) unless @namespace_id.empty?
|
|
42
|
+
ptr.put_bytes(struct.offset_of(:id), @id) unless @id.empty?
|
|
43
|
+
ptr.put_bytes(struct.offset_of(:cbor_value), @cbor_value) unless @cbor_value.empty?
|
|
44
|
+
struct[:namespace_len] = @namespace_id.bytesize
|
|
45
|
+
struct[:id_len] = @id.bytesize
|
|
46
|
+
struct[:cbor_value_len] = @cbor_value.bytesize
|
|
47
|
+
struct
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def validate!
|
|
53
|
+
check_length(:namespace_id, @namespace_id, MAX_NAMESPACE)
|
|
54
|
+
check_length(:id, @id, MAX_ID)
|
|
55
|
+
check_length(:cbor_value, @cbor_value, MAX_CBOR_VALUE)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def check_length(name, value, max)
|
|
59
|
+
return if value.bytesize <= max
|
|
60
|
+
|
|
61
|
+
raise ArgumentError,
|
|
62
|
+
"#{name} is #{value.bytesize} bytes, exceeds maximum of #{max}"
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
data/lib/longfellow/c.rb
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "ffi"
|
|
4
|
+
|
|
5
|
+
module Longfellow
|
|
6
|
+
# Low-level FFI binding to the longfellow-zk C ABI declared in
|
|
7
|
+
# `lib/circuits/mdoc/mdoc_zk.h`. Application code should prefer the
|
|
8
|
+
# high-level helpers on {Longfellow}; this module mirrors the C surface
|
|
9
|
+
# one-to-one and performs no validation or memory management of its own.
|
|
10
|
+
module C
|
|
11
|
+
extend FFI::Library
|
|
12
|
+
|
|
13
|
+
# The shared object produced by ext/longfellow during installation lives
|
|
14
|
+
# next to this file.
|
|
15
|
+
LIBRARY_PATH = File.expand_path(
|
|
16
|
+
"liblongfellow_native.#{FFI::Platform::LIBSUFFIX}", __dir__
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
unless File.exist?(LIBRARY_PATH)
|
|
20
|
+
raise LoadError,
|
|
21
|
+
"longfellow native library not found at #{LIBRARY_PATH}. " \
|
|
22
|
+
"Reinstall the gem or run `rake compile` after checking out the " \
|
|
23
|
+
"git submodule (git submodule update --init --recursive)."
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# The native library is searched first; libc provides `free` for the
|
|
27
|
+
# prover/circuit buffers the C ABI hands back to us.
|
|
28
|
+
ffi_lib [LIBRARY_PATH, FFI::Library::LIBC]
|
|
29
|
+
|
|
30
|
+
# enum { kNumZkSpecs = 12 };
|
|
31
|
+
NUM_ZK_SPECS = 12
|
|
32
|
+
|
|
33
|
+
# kSHA256DigestSize
|
|
34
|
+
CIRCUIT_ID_SIZE = 32
|
|
35
|
+
|
|
36
|
+
# typedef struct { ... } ZkSpecStruct;
|
|
37
|
+
class ZkSpecStruct < FFI::Struct
|
|
38
|
+
layout(
|
|
39
|
+
:system, :pointer,
|
|
40
|
+
:circuit_hash, [:char, 65],
|
|
41
|
+
:num_attributes, :size_t,
|
|
42
|
+
:version, :size_t,
|
|
43
|
+
:block_enc_hash, :size_t,
|
|
44
|
+
:block_enc_sig, :size_t
|
|
45
|
+
)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# typedef struct { ... } RequestedAttribute;
|
|
49
|
+
class RequestedAttribute < FFI::Struct
|
|
50
|
+
layout(
|
|
51
|
+
:namespace_id, [:uint8, 64],
|
|
52
|
+
:id, [:uint8, 32],
|
|
53
|
+
:cbor_value, [:uint8, 64],
|
|
54
|
+
:namespace_len, :size_t,
|
|
55
|
+
:id_len, :size_t,
|
|
56
|
+
:cbor_value_len, :size_t
|
|
57
|
+
)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# MdocProverErrorCode run_mdoc_prover(...)
|
|
61
|
+
attach_function :run_mdoc_prover, [
|
|
62
|
+
:pointer, :size_t, # bcp, bcsz
|
|
63
|
+
:pointer, :size_t, # mdoc, mdoc_len
|
|
64
|
+
:string, :string, # pkx, pky
|
|
65
|
+
:pointer, :size_t, # transcript, tr_len
|
|
66
|
+
:pointer, :size_t, # attrs, attrs_len
|
|
67
|
+
:string, # now
|
|
68
|
+
:pointer, :pointer, # prf (uint8_t**), proof_len (size_t*)
|
|
69
|
+
:pointer # zk_spec_version
|
|
70
|
+
], :int
|
|
71
|
+
|
|
72
|
+
# MdocVerifierErrorCode run_mdoc_verifier(...)
|
|
73
|
+
attach_function :run_mdoc_verifier, [
|
|
74
|
+
:pointer, :size_t, # bcp, bcsz
|
|
75
|
+
:string, :string, # pkx, pky
|
|
76
|
+
:pointer, :size_t, # transcript, tr_len
|
|
77
|
+
:pointer, :size_t, # attrs, attrs_len
|
|
78
|
+
:string, # now
|
|
79
|
+
:pointer, :size_t, # zkproof, proof_len
|
|
80
|
+
:string, # docType
|
|
81
|
+
:pointer # zk_spec_version
|
|
82
|
+
], :int
|
|
83
|
+
|
|
84
|
+
# CircuitGenerationErrorCode generate_circuit(zk_spec, cb, clen)
|
|
85
|
+
attach_function :generate_circuit, [:pointer, :pointer, :pointer], :int
|
|
86
|
+
|
|
87
|
+
# int circuit_id(id[32], bcp, bcsz, zk_spec)
|
|
88
|
+
attach_function :circuit_id, [:pointer, :pointer, :size_t, :pointer], :int
|
|
89
|
+
|
|
90
|
+
# const ZkSpecStruct* find_zk_spec(system_name, circuit_hash)
|
|
91
|
+
attach_function :find_zk_spec, [:string, :string], :pointer
|
|
92
|
+
|
|
93
|
+
# void free(void*) — releases buffers allocated by the prover / circuit gen.
|
|
94
|
+
attach_function :c_free, :free, [:pointer], :void
|
|
95
|
+
|
|
96
|
+
# The hardcoded `kZkSpecs[kNumZkSpecs]` global. Returns the FFI structs that
|
|
97
|
+
# point into the library's static storage (do not free or mutate them).
|
|
98
|
+
def self.zk_specs
|
|
99
|
+
base = ffi_libraries.first.find_variable("kZkSpecs")
|
|
100
|
+
Array.new(NUM_ZK_SPECS) do |i|
|
|
101
|
+
ZkSpecStruct.new(base + (i * ZkSpecStruct.size))
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Longfellow
|
|
4
|
+
# Base class for every error raised by this gem.
|
|
5
|
+
class Error < StandardError; end
|
|
6
|
+
|
|
7
|
+
# Raised when a native call fails. Carries the raw return {#code} from the C
|
|
8
|
+
# ABI and a stable {#symbol} for programmatic handling.
|
|
9
|
+
class NativeError < Error
|
|
10
|
+
attr_reader :code, :symbol
|
|
11
|
+
|
|
12
|
+
def initialize(symbol, code, context)
|
|
13
|
+
@symbol = symbol
|
|
14
|
+
@code = code
|
|
15
|
+
super("#{context} failed: #{symbol} (code #{code})")
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# run_mdoc_prover failure (MdocProverErrorCode).
|
|
20
|
+
class ProverError < NativeError; end
|
|
21
|
+
|
|
22
|
+
# run_mdoc_verifier failure (MdocVerifierErrorCode).
|
|
23
|
+
class VerifierError < NativeError; end
|
|
24
|
+
|
|
25
|
+
# generate_circuit failure (CircuitGenerationErrorCode).
|
|
26
|
+
class CircuitGenerationError < NativeError; end
|
|
27
|
+
|
|
28
|
+
# Maps the C ABI return enums to symbols and raises on non-success. The arrays
|
|
29
|
+
# below are ordered to match the enum declarations in mdoc_zk.h exactly.
|
|
30
|
+
module Errors
|
|
31
|
+
PROVER_CODES = %i[
|
|
32
|
+
success null_input invalid_input circuit_parsing_failure
|
|
33
|
+
hash_parsing_failure witness_creation_failure general_failure
|
|
34
|
+
memory_allocation_failure invalid_zk_spec_version root_decoding_failure
|
|
35
|
+
documents_missing document_0_missing doctype_missing
|
|
36
|
+
issuer_signed_missing issuer_auth_missing mso_missing nsig_missing
|
|
37
|
+
namespaces_missing device_signed_missing device_auth_missing
|
|
38
|
+
device_signature_missing device_key_missing mso_decoding_failure
|
|
39
|
+
validity_info_missing device_key_info_missing attribute_decode_failure
|
|
40
|
+
attribute_ei_missing attribute_ev_missing attribute_did_missing
|
|
41
|
+
signature_failure device_signature_failure attribute_not_found
|
|
42
|
+
attribute_too_long tagged_mso_too_big version_not_supported
|
|
43
|
+
attribute_random_missing
|
|
44
|
+
].freeze
|
|
45
|
+
|
|
46
|
+
VERIFIER_CODES = %i[
|
|
47
|
+
success circuit_parsing_failure proof_too_small hash_parsing_failure
|
|
48
|
+
signature_parsing_failure general_failure null_input invalid_input
|
|
49
|
+
arguments_too_small attribute_number_mismatch invalid_zk_spec_version
|
|
50
|
+
invalid_cbor
|
|
51
|
+
].freeze
|
|
52
|
+
|
|
53
|
+
CIRCUIT_CODES = %i[
|
|
54
|
+
success null_input zlib_failure general_failure invalid_zk_spec_version
|
|
55
|
+
].freeze
|
|
56
|
+
|
|
57
|
+
module_function
|
|
58
|
+
|
|
59
|
+
def check_prover!(code)
|
|
60
|
+
check!(code, PROVER_CODES, ProverError, "run_mdoc_prover")
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def check_verifier!(code)
|
|
64
|
+
check!(code, VERIFIER_CODES, VerifierError, "run_mdoc_verifier")
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def check_circuit!(code)
|
|
68
|
+
check!(code, CIRCUIT_CODES, CircuitGenerationError, "generate_circuit")
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def check!(code, table, klass, context)
|
|
72
|
+
return if code.zero?
|
|
73
|
+
|
|
74
|
+
symbol = table[code] || :unknown
|
|
75
|
+
raise klass.new(symbol, code, context)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Longfellow
|
|
4
|
+
# Immutable view over a `ZkSpecStruct` entry owned by the native library.
|
|
5
|
+
#
|
|
6
|
+
# A ZK specification identifies a circuit format/interpretation that a prover
|
|
7
|
+
# and verifier must agree on. Instances are obtained from {Longfellow.zk_specs}
|
|
8
|
+
# or {Longfellow.find_zk_spec}; they wrap a pointer into the library's static
|
|
9
|
+
# `kZkSpecs` storage and are passed back into the prover, verifier and circuit
|
|
10
|
+
# generator.
|
|
11
|
+
class ZkSpec
|
|
12
|
+
attr_reader :system, :circuit_hash, :num_attributes, :version,
|
|
13
|
+
:block_enc_hash, :block_enc_sig
|
|
14
|
+
|
|
15
|
+
# @param struct [Longfellow::C::ZkSpecStruct]
|
|
16
|
+
def initialize(struct)
|
|
17
|
+
@struct = struct
|
|
18
|
+
system_ptr = struct[:system]
|
|
19
|
+
@system = system_ptr.null? ? nil : system_ptr.read_string
|
|
20
|
+
# circuit_hash is a NUL-terminated 64-char hex string in a [65]char field.
|
|
21
|
+
@circuit_hash = struct[:circuit_hash].to_ptr.read_string
|
|
22
|
+
@num_attributes = struct[:num_attributes]
|
|
23
|
+
@version = struct[:version]
|
|
24
|
+
@block_enc_hash = struct[:block_enc_hash]
|
|
25
|
+
@block_enc_sig = struct[:block_enc_sig]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# @return [FFI::Pointer] pointer to the underlying ZkSpecStruct, for passing
|
|
29
|
+
# into native calls.
|
|
30
|
+
def to_ptr
|
|
31
|
+
@struct.to_ptr
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def to_s
|
|
35
|
+
"#<Longfellow::ZkSpec #{@system} v#{@version} " \
|
|
36
|
+
"attrs=#{@num_attributes} hash=#{@circuit_hash}>"
|
|
37
|
+
end
|
|
38
|
+
alias inspect to_s
|
|
39
|
+
end
|
|
40
|
+
end
|