{"repo_name": "longfellow-zk", "file_name": "/longfellow-zk/lib/circuits/anoncred/small.h", "inference_info": {"prefix_code": "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_H_\n\n#include \n#include \n\n#include \"circuits/anoncred/small_io.h\"\n#include \"circuits/compiler/compiler.h\"\n#include \"circuits/ecdsa/verify_circuit.h\"\n#include \"circuits/logic/bit_plucker.h\"\n#include \"circuits/logic/memcmp.h\"\n#include \"circuits/logic/routing.h\"\n#include \"circuits/sha/flatsha256_circuit.h\"\n\nnamespace proofs {\n\n// This class creates a circuit to verify the signatures in a \"small\" MDOC.\n// A small credential is a 183-byte document formatted as:\n// first_name 32 0\n// family_name 32 32\n// date_of_birth YYYYMMDD 64\n// gender B 72\n// age_over_X. BBBBBBB 73 [16, 18, 21, 25, 62, 65, 67]\n// issuerid BBBB 80\n// validfrom YYYYMMDD 84\n// validuntil YYYYMMDD 92\n// DPKX 32x 100\n// DPKY 32x 132\n// \ntemplate \nclass Small {\n using EltW = typename LogicCircuit::EltW;\n using Elt = typename LogicCircuit::Elt;\n using Nat = typename Field::N;\n using Ecdsa = VerifyCircuit;\n using EcdsaWitness = typename Ecdsa::Witness;\n\n using v8 = typename LogicCircuit::v8;\n using v32 = typename LogicCircuit::v32;\n static constexpr size_t kIndexBits = 5;\n static constexpr size_t kMaxSHABlocks = 7;\n static constexpr size_t kMaxMsoLen = kMaxSHABlocks * 64 - 9;\n\n using vind = typename LogicCircuit::template bitvec;\n using Flatsha = FlatSHA256Circuit>;\n using RoutingL = Routing;\n using ShaBlockWitness = typename Flatsha::BlockWitness;\n\n const LogicCircuit& lc_;\n const EC& ec_;\n const Nat& order_;\n\n public:\n class Witness {\n public:\n EltW e_;\n EltW dpkx_, dpky_;\n\n EcdsaWitness sig_;\n EcdsaWitness dpk_sig_;\n\n v8 in_[64 * kMaxSHABlocks]; /* input bytes, 64 * MAX */\n v8 nb_; /* index of sha block that contains the real hash */\n ShaBlockWitness sig_sha_[kMaxSHABlocks];\n\n void input(QuadCircuit& Q, const LogicCircuit& lc) {\n e_ = Q.input();\n dpkx_ = Q.input();\n dpky_ = Q.input();\n\n sig_.input(Q);\n dpk_sig_.input(Q);\n\n nb_ = lc.template vinput<8>();\n\n // sha input init =========================\n for (size_t i = 0; i < 64 * kMaxSHABlocks; ++i) {\n in_[i] = lc.template vinput<8>();\n }\n for (size_t j = 0; j < kMaxSHABlocks; j++) {\n sig_sha_[j].input(Q);\n }\n }\n };\n\n struct OpenedAttribute {\n v8 ind; /* index of attribute */\n v8 len; /* length of attribute, 1--32 */\n v8 v1[32]; /* attribute value */\n void input(const LogicCircuit& lc) {\n ind = lc.template vinput<8>();\n len = lc.template vinput<8>();\n for (size_t j = 0; j < 32; ++j) {\n v1[j] = lc.template vinput<8>();\n }\n }\n };\n\n ", "suffix_code": "\n\n explicit Small(const LogicCircuit& lc, const EC& ec, const Nat& order)\n : lc_(lc), ec_(ec), order_(order), sha_(lc), r_(lc) {}\n\n void assert_credential(EltW pkX, EltW pkY, EltW hash_tr,\n OpenedAttribute oa[/* NUM_ATTR */],\n const v8 now[/*kDateLen*/], const Witness& vw) const {\n Ecdsa ecc(lc_, ec_, order_);\n\n ecc.verify_signature3(pkX, pkY, vw.e_, vw.sig_);\n ecc.verify_signature3(vw.dpkx_, vw.dpky_, hash_tr, vw.dpk_sig_);\n\n sha_.assert_message(kMaxSHABlocks, vw.nb_, vw.in_, vw.sig_sha_);\n\n const Memcmp CMP(lc_);\n // // validFrom <= now\n lc_.assert1(CMP.leq(kDateLen, &vw.in_[84], &now[0]));\n\n // // now <= validUntil\n lc_.assert1(CMP.leq(kDateLen, &now[0], &vw.in_[92]));\n\n // // DPK_{x,y}\n EltW dpkx = repack(vw.in_, 100);\n EltW dpky = repack(vw.in_, 132);\n lc_.assert_eq(&dpkx, vw.dpkx_);\n lc_.assert_eq(&dpky, vw.dpky_);\n\n // Attributes parsing\n const v8 zz = lc_.template vbit<8>(0xff); // cannot appear in strings\n std::vector cmp_buf(32);\n for (size_t ai = 0; ai < kNumAttr; ++ai) {\n r_.shift(oa[ai].ind, 32, &cmp_buf[0], kMaxMsoLen, vw.in_, zz, 3);\n assert_attribute(32, oa[ai].len, &cmp_buf[0], &oa[ai].v1[0]);\n }\n }\n\n private:\n // Checks that an attribute id or attribute value is as expected.\n // The len parameter holds the byte length of the expected id or value.\n void assert_attribute(size_t max, const v8& vlen, const v8 got[/*max*/],\n const v8 want[/*max*/]) const {\n for (size_t j = 0; j < max; ++j) {\n auto ll = lc_.vlt(j, vlen);\n auto cmp = lc_.veq(got[j], want[j]);\n lc_.assert_implies(&ll, cmp);\n }\n }\n\n Flatsha sha_;\n RoutingL r_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_H_\n", "middle_code": "EltW repack(const v8 in[], size_t ind) const {\n EltW h = lc_.konst(0);\n EltW base = lc_.konst(0x2);\n for (size_t i = 0; i < 32; ++i) {\n for (size_t j = 0; j < 8; ++j) {\n auto t = lc_.mul(&h, base);\n auto tin = lc_.eval(in[ind + i][7 - j]);\n h = lc_.add(&tin, t);\n }\n }\n return h;\n }", "code_description": null, "fill_type": "FUNCTION_TYPE", "language_type": "cpp", "sub_task_type": null}, "context_code": [["/longfellow-zk/lib/circuits/anoncred/ptrcred.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_PTRCRED_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_PTRCRED_H_\n#include \n#include \n\n#include \"circuits/anoncred/small_io.h\"\n#include \"circuits/compiler/compiler.h\"\n#include \"circuits/ecdsa/verify_circuit.h\"\n#include \"circuits/logic/bit_plucker.h\"\n#include \"circuits/logic/memcmp.h\"\n#include \"circuits/logic/routing.h\"\n#include \"circuits/sha/flatsha256_circuit.h\"\n\nnamespace proofs {\n\n// This class creates a circuit to verify the signatures in a \"ptrcred\".\n// A ptr credential is a document formatted as:\n// n // 8 bits specifying the number of attributes\n// ind \n// each pointer references from the beginning of the document\n// A byte string containing keys and values.\n// A key consists of 3 bytes.\n// A value can be arbitrarily long.\ntemplate \nclass PtrCred {\n using EltW = typename LogicCircuit::EltW;\n using Elt = typename LogicCircuit::Elt;\n using Nat = typename Field::N;\n using Ecdsa = VerifyCircuit;\n using EcdsaWitness = typename Ecdsa::Witness;\n\n using v8 = typename LogicCircuit::v8;\n using v32 = typename LogicCircuit::v32;\n static constexpr size_t kIndexBits = 5;\n static constexpr size_t kMaxSHABlocks = 3;\n static constexpr size_t kMaxMsoLen = kMaxSHABlocks * 64 - 9;\n\n using vind = typename LogicCircuit::template bitvec;\n using Flatsha = FlatSHA256Circuit>;\n using RoutingL = Routing;\n using ShaBlockWitness = typename Flatsha::BlockWitness;\n\n const LogicCircuit& lc_;\n const EC& ec_;\n const Nat& order_;\n\n public:\n class Witness {\n public:\n EltW e_;\n EltW dpkx_, dpky_;\n\n EcdsaWitness sig_;\n EcdsaWitness dpk_sig_;\n\n v8 in_[64 * kMaxSHABlocks]; /* input bytes, 64 * MAX */\n v8 nb_; /* index of sha block that contains the real hash */\n ShaBlockWitness sig_sha_[kMaxSHABlocks];\n\n void input(QuadCircuit& Q, const LogicCircuit& lc) {\n e_ = Q.input();\n dpkx_ = Q.input();\n dpky_ = Q.input();\n\n sig_.input(Q);\n dpk_sig_.input(Q);\n\n nb_ = lc.template vinput<8>();\n\n // sha input init =========================\n for (size_t i = 0; i < 64 * kMaxSHABlocks; ++i) {\n in_[i] = lc.template vinput<8>();\n }\n for (size_t j = 0; j < kMaxSHABlocks; j++) {\n sig_sha_[j].input(Q);\n }\n }\n };\n\n struct OpenedAttribute {\n v8 ind; /* index of attribute */\n v8 len; /* length of attribute, 1--32 */\n v8 v1[32]; /* attribute value */\n void input(const LogicCircuit& lc) {\n ind = lc.template vinput<8>();\n len = lc.template vinput<8>();\n for (size_t j = 0; j < 32; ++j) {\n v1[j] = lc.template vinput<8>();\n }\n }\n };\n\n EltW repack(const v8 in[], size_t ind) const {\n EltW h = lc_.konst(0);\n EltW base = lc_.konst(0x2);\n for (size_t i = 0; i < 32; ++i) {\n for (size_t j = 0; j < 8; ++j) {\n auto t = lc_.mul(&h, base);\n auto tin = lc_.eval(in[ind + i][7 - j]);\n h = lc_.add(&tin, t);\n }\n }\n return h;\n }\n\n explicit PtrCred(const LogicCircuit& lc, const EC& ec, const Nat& order)\n : lc_(lc), ec_(ec), order_(order), sha_(lc), r_(lc) {}\n\n void assert_credential(EltW pkX, EltW pkY, EltW hash_tr,\n OpenedAttribute oa[/* NUM_ATTR */],\n const v8 now[/*kDateLen*/], const Witness& vw) const {\n Ecdsa ecc(lc_, ec_, order_);\n\n ecc.verify_signature3(pkX, pkY, vw.e_, vw.sig_);\n ecc.verify_signature3(vw.dpkx_, vw.dpky_, hash_tr, vw.dpk_sig_);\n sha_.assert_message(kMaxSHABlocks, vw.nb_, vw.in_, vw.sig_sha_);\n\n const Memcmp CMP(lc_);\n // validFrom <= now\n lc_.assert1(CMP.leq(kDateLen, &vw.in_[84], &now[0]));\n\n // now <= validUntil\n lc_.assert1(CMP.leq(kDateLen, &now[0], &vw.in_[92]));\n\n // DPK_{x,y}\n EltW dpkx = repack(vw.in_, 100);\n EltW dpky = repack(vw.in_, 132);\n lc_.assert_eq(&dpkx, vw.dpkx_);\n lc_.assert_eq(&dpky, vw.dpky_);\n\n // Attributes parsing\n const v8 zz = lc_.template vbit<8>(0xff); // cannot appear in strings\n std::vector cmp_buf(32);\n for (size_t ai = 0; ai < kNumAttr; ++ai) {\n r_.shift(oa[ai].ind, 32, &cmp_buf[0], kMaxMsoLen, vw.in_, zz, 3);\n assert_attribute(32, oa[ai].len, &cmp_buf[0], &oa[ai].v1[0]);\n }\n }\n\n private:\n // Checks that an attribute id or attribute value is as expected.\n // The len parameter holds the byte length of the expected id or value.\n void assert_attribute(size_t max, const v8& vlen, const v8 got[/*max*/],\n const v8 want[/*max*/]) const {\n for (size_t j = 0; j < max; ++j) {\n auto ll = lc_.vlt(j, vlen);\n auto cmp = lc_.veq(got[j], want[j]);\n lc_.assert_implies(&ll, cmp);\n }\n }\n\n Flatsha sha_;\n RoutingL r_;\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_PTRCRED_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_1f.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_1F_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_1F_H_\n\n#include \n#include \n#include \n\n#include \"circuits/cbor_parser/cbor.h\"\n#include \"circuits/compiler/compiler.h\"\n#include \"circuits/ecdsa/verify_circuit.h\"\n#include \"circuits/logic/bit_plucker.h\"\n#include \"circuits/logic/routing.h\"\n#include \"circuits/mdoc/mdoc_1f_io.h\"\n#include \"circuits/mdoc/mdoc_constants.h\"\n#include \"circuits/sha/flatsha256_circuit.h\"\nnamespace proofs {\n\ntemplate \nclass mdoc_1f {\n using EltW = typename LogicCircuit::EltW;\n using Elt = typename LogicCircuit::Elt;\n using Nat = typename Field::N;\n using Ecdsa = VerifyCircuit;\n using EcdsaWitness = typename Ecdsa::Witness;\n\n using v8 = typename LogicCircuit::v8;\n using v32 = typename LogicCircuit::v32;\n using v256 = typename LogicCircuit::v256;\n using vind = typename LogicCircuit::template bitvec;\n using Flatsha =\n FlatSHA256Circuit>;\n using Routing = Routing;\n using ShaBlockWitness = typename Flatsha::BlockWitness;\n using sha_packed_v32 = typename Flatsha::packed_v32;\n using Cbor = Cbor;\n\n const LogicCircuit& lc_;\n const EC& ec_;\n const Nat& order_;\n\n public:\n struct CborIndex {\n vind k, v, ndx;\n void input(const LogicCircuit& lc) {\n k = lc.template vinput();\n v = lc.template vinput();\n ndx = lc.template vinput();\n }\n };\n\n struct AttrShift {\n vind offset;\n vind len;\n void input(const LogicCircuit& lc) {\n offset = lc.template vinput();\n len = lc.template vinput();\n }\n };\n\n class Witness {\n public:\n EltW e_;\n EltW dpkx_, dpky_;\n\n EcdsaWitness sig_;\n EcdsaWitness dpk_sig_;\n\n v8 in_[64 * kMdoc1MaxSHABlocks]; /* input bytes, 64 * MAX */\n v8 nb_; /* index of sha block that contains the real hash */\n ShaBlockWitness sig_sha_[kMdoc1MaxSHABlocks];\n\n size_t num_attr_;\n\n std::vector> attr_sha_;\n std::vector> attrb_;\n\n std::vector attr_mso_;\n std::vector attr_ei_;\n std::vector attr_ev_;\n\n std::vector incb_;\n std::vector pwcb_;\n typename Cbor::global_witness gwcb_;\n\n vind prepad_, mso_len_;\n\n CborIndex valid_, valid_from_, valid_until_;\n CborIndex dev_key_info_, dev_key_, dev_key_pkx_, dev_key_pky_;\n CborIndex value_digests_, org_;\n\n explicit Witness(size_t num_attr)\n : num_attr_(num_attr),\n attr_sha_(num_attr),\n attrb_(num_attr),\n attr_mso_(num_attr),\n attr_ei_(num_attr),\n attr_ev_(num_attr),\n incb_(kMdoc1MaxMsoLen),\n pwcb_(kMdoc1MaxMsoLen) {\n for (size_t i = 0; i < num_attr; ++i) {\n attr_sha_[i].resize(2);\n }\n }\n\n void input(QuadCircuit& Q, const LogicCircuit& lc) {\n e_ = Q.input();\n dpkx_ = Q.input();\n dpky_ = Q.input();\n\n sig_.input(Q);\n dpk_sig_.input(Q);\n\n nb_ = lc.template vinput<8>();\n\n // sha input init (skip the prefix) =========================\n for (size_t i = 0; i + kCose1PrefixLen < 64 * kMdoc1MaxSHABlocks; ++i) {\n in_[i] = lc.template vinput<8>();\n }\n\n for (size_t j = 0; j < kMdoc1MaxSHABlocks; j++) {\n sig_sha_[j].input(Q);\n }\n\n // Cbor input init: note, the inC array will be constructed in the\n // circuit.\n prepad_ = lc.template vinput();\n mso_len_ = lc.template vinput();\n for (size_t i = 0; i < kMdoc1MaxMsoLen; ++i) {\n pwcb_[i].encoded_sel_header = Q.input();\n }\n gwcb_.invprod_decode = Q.input();\n gwcb_.cc0 = Q.input();\n gwcb_.invprod_parse = Q.input();\n\n valid_.input(lc);\n valid_from_.input(lc);\n valid_until_.input(lc);\n dev_key_info_.input(lc);\n dev_key_.input(lc);\n dev_key_pkx_.input(lc);\n dev_key_pky_.input(lc);\n value_digests_.input(lc);\n org_.input(lc);\n\n // Attribute opening witnesses\n for (size_t ai = 0; ai < num_attr_; ++ai) {\n for (size_t i = 0; i < 64 * 2; ++i) {\n attrb_[ai].push_back(lc.template vinput<8>());\n }\n for (size_t j = 0; j < 2; j++) {\n attr_sha_[ai][j].input(Q);\n }\n attr_mso_[ai].input(lc);\n attr_ei_[ai].input(lc);\n attr_ev_[ai].input(lc);\n }\n }\n };\n\n struct OpenedAttribute {\n v8 attr[96]; // representing attribute name, elementValue delimiter, and\n // finally the attribute value.\n };\n\n struct PathEntry {\n CborIndex ind;\n size_t l;\n const uint8_t* name;\n };\n\n explicit mdoc_1f(const LogicCircuit& lc, const EC& ec, const Nat& order)\n : lc_(lc), ec_(ec), order_(order), sha_(lc), r_(lc), cbor_(lc) {}\n\n void assert_credential(EltW pkX, EltW pkY, EltW hash_tr,\n OpenedAttribute oa[/* NUM_ATTR */],\n const v8 now[/*kDateLen*/], const Witness& vw) const {\n Ecdsa ecc(lc_, ec_, order_);\n\n ecc.verify_signature3(pkX, pkY, vw.e_, vw.sig_);\n ecc.verify_signature3(vw.dpkx_, vw.dpky_, hash_tr, vw.dpk_sig_);\n\n sha_.assert_message_with_prefix(kMdoc1MaxSHABlocks, vw.nb_, vw.in_,\n kCose1Prefix, kCose1PrefixLen, vw.sig_sha_);\n // Verify that the hash of the mdoc is equal to e.\n assert_hash(vw.e_, vw);\n\n // Shift a portion of the MSO into buf and check it.\n const v8 zz = lc_.template vbit<8>(0); // cannot appear in strings\n std::vector cmp_buf(kMdoc1MaxMsoLen);\n\n // Re-arrange the input wires to produce the <0 padded> input\n // required for cbor parsing. The subtracted 5 corresponds to the fix\n // length D8 18 prefix of the mso that we want to skip parsing.\n // The subtracted 2 corresponds to the length.\n std::vector in_cb(kMdoc1MaxMsoLen);\n r_.unshift(vw.prepad_, kMdoc1MaxMsoLen, in_cb.data(),\n kMdoc1MaxMsoLen - 5 - 2, vw.in_ + 5 + 2, zz, 3);\n\n std::vector dsC(kMdoc1MaxMsoLen);\n std::vector psC(kMdoc1MaxMsoLen);\n cbor_.decode_and_assert_decode_and_parse(kMdoc1MaxMsoLen, dsC.data(),\n psC.data(), in_cb.data(),\n vw.pwcb_.data(), vw.gwcb_);\n\n cbor_.assert_input_starts_at(kMdoc1MaxMsoLen, vw.prepad_, vw.mso_len_,\n dsC.data());\n\n // Validity\n PathEntry vk[2] = {{vw.valid_, kValidityInfoLen, kValidityInfoID},\n {vw.valid_from_, kValidFromLen, kValidFromID}};\n assert_path(2, vk, vw, dsC, psC);\n cbor_.assert_date_before_at(kMdoc1MaxMsoLen, vw.valid_from_.v, now,\n dsC.data());\n\n // validUntil is a key in validityInfo.\n cbor_.assert_map_entry(kMdoc1MaxMsoLen, vw.valid_.v, 1, vw.valid_until_.k,\n vw.valid_until_.v, vw.valid_until_.ndx, dsC.data(),\n psC.data());\n cbor_.assert_text_at(kMdoc1MaxMsoLen, vw.valid_until_.k, kValidUntilLen,\n kValidUntilID, dsC.data());\n cbor_.assert_date_after_at(kMdoc1MaxMsoLen, vw.valid_until_.v, now,\n dsC.data());\n\n PathEntry dk[2] = {{vw.dev_key_info_, kDeviceKeyInfoLen, kDeviceKeyInfoID},\n {vw.dev_key_, kDeviceKeyLen, kDeviceKeyID}};\n assert_path(2, dk, vw, dsC, psC);\n cbor_.assert_map_entry(kMdoc1MaxMsoLen, vw.dev_key_.v, 2, vw.dev_key_pkx_.k,\n vw.dev_key_pkx_.v, vw.dev_key_pkx_.ndx, dsC.data(),\n psC.data());\n cbor_.assert_map_entry(kMdoc1MaxMsoLen, vw.dev_key_.v, 2, vw.dev_key_pky_.k,\n vw.dev_key_pky_.v, vw.dev_key_pky_.ndx, dsC.data(),\n psC.data());\n cbor_.assert_negative_at(kMdoc1MaxMsoLen, vw.dev_key_pkx_.k, 1, dsC.data());\n cbor_.assert_negative_at(kMdoc1MaxMsoLen, vw.dev_key_pky_.k, 2, dsC.data());\n cbor_.assert_elt_as_be_bytes_at(kMdoc1MaxMsoLen, vw.dev_key_pkx_.v, 32,\n vw.dpkx_, dsC.data());\n cbor_.assert_elt_as_be_bytes_at(kMdoc1MaxMsoLen, vw.dev_key_pky_.v, 32,\n vw.dpky_, dsC.data());\n // Attributes parsing\n PathEntry ak[2] = {{vw.value_digests_, kValueDigestsLen, kValueDigestsID},\n {vw.org_, kOrgLen, kOrgID}};\n assert_path(2, ak, vw, dsC, psC);\n\n // Attributes: Equality of hash with MSO value\n for (size_t ai = 0; ai < vw.num_attr_; ++ai) {\n auto two = lc_.template vbit<8>(2);\n v8 B[96];\n sha_.assert_message(2, two, vw.attrb_[ai].data(),\n vw.attr_sha_[ai].data());\n\n EltW h = repack32(vw.attr_sha_[ai][1].h1);\n // Check the hash matches the value in the signed MSO.\n cbor_.assert_map_entry(kMdoc1MaxMsoLen, vw.org_.v, 2, vw.attr_mso_[ai].k,\n vw.attr_mso_[ai].v, vw.attr_mso_[ai].ndx,\n dsC.data(), psC.data());\n cbor_.assert_elt_as_be_bytes_at(kMdoc1MaxMsoLen, vw.attr_mso_[ai].v, 32,\n h, dsC.data());\n\n // Check that the attribute_id and value occur in the hashed text.\n r_.shift(vw.attr_ei_[ai].offset, 96, B, 128, vw.attrb_[ai].data(), zz, 3);\n assert_attribute(96, vw.attr_ei_[ai].len, B, oa[ai].attr);\n }\n }\n\n private:\n EltW repack32(const sha_packed_v32 H[]) const {\n EltW h = lc_.konst(0);\n Elt twok = lc_.one();\n for (size_t j = 8; j-- > 0;) {\n auto hj = sha_.bp_.unpack_v32(H[j]);\n for (size_t k = 0; k < 32; ++k) {\n h = lc_.axpy(&h, twok, lc_.eval(hj[k]));\n lc_.f_.add(twok, twok);\n }\n }\n return h;\n }\n\n // Assert that the hash of the mdoc is equal to e.\n // The hash is encoded in the SHA witness, and thus the correct block\n // must be muxed for the comparison. Thus method first muxes the \"packed\"\n // encoding of the SHA witness, then unpacks it and compares it to e to\n // save a lot of work in the bit plucker.\n void assert_hash(const EltW& e, const Witness& vw) const {\n sha_packed_v32 x[8];\n for (size_t b = 0; b < kMdoc1MaxSHABlocks; ++b) {\n auto bt = lc_.veq(vw.nb_, b + 1); /* b is zero-indexed */\n auto ebt = lc_.eval(bt);\n for (size_t i = 0; i < 8; ++i) {\n for (size_t k = 0; k < sha_.bp_.kNv32Elts; ++k) {\n if (b == 0) {\n x[i][k] = lc_.mul(&ebt, vw.sig_sha_[b].h1[i][k]);\n } else {\n auto maybe_sha = lc_.mul(&ebt, vw.sig_sha_[b].h1[i][k]);\n x[i][k] = lc_.add(&x[i][k], maybe_sha);\n }\n }\n }\n }\n\n EltW h = repack32(x);\n lc_.assert_eq(&h, e);\n }\n\n // Checks that an attribute id or attribute value is as expected.\n // The len parameter holds the byte length of the expected id or value.\n void assert_attribute(size_t max, const vind& len, const v8 got[/*max*/],\n const v8 want[/*max*/]) const {\n // auto two = lc_.konst(2);\n for (size_t j = 0; j < max; ++j) {\n auto ll = lc_.vlt(j, len);\n auto same = lc_.eq(8, got[j].data(), want[j].data());\n lc_.assert_implies(&ll, same);\n }\n }\n\n void assert_path(size_t len, PathEntry p[], const Witness& vw,\n std::vector& dsC,\n std::vector& psC) const {\n vind start = vw.prepad_;\n for (size_t i = 0; i < len; ++i) {\n cbor_.assert_map_entry(kMdoc1MaxMsoLen, start, i, p[i].ind.k, p[i].ind.v,\n p[i].ind.ndx, dsC.data(), psC.data());\n cbor_.assert_text_at(kMdoc1MaxMsoLen, p[i].ind.k, p[i].l, p[i].name,\n dsC.data());\n start = p[i].ind.v;\n }\n }\n\n Flatsha sha_;\n Routing r_;\n Cbor cbor_;\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_1F_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_hash.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_HASH_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_HASH_H_\n\n#include \n#include \n#include \n\n#include \"circuits/compiler/compiler.h\"\n#include \"circuits/logic/bit_plucker.h\"\n#include \"circuits/logic/memcmp.h\"\n#include \"circuits/logic/routing.h\"\n#include \"circuits/mdoc/mdoc_constants.h\"\n#include \"circuits/sha/flatsha256_circuit.h\"\n\nnamespace proofs {\n\nstatic constexpr size_t kSHAPluckerBits = 4u;\n\n// This class (only) verifies the hashing and pseudo-parsing of an mdoc.\n// Specifically, it checks\n// (a) the hash of the mdoc matches its mac.\n// (b) the values dpk_{x,y} appear in approximate cbor form, and their macs\n// match the expected values\n// (c) validFrom, validUntil appear in approximate cbor form, and that\n// validFrom <= now <= validUntil\n// (d) For each expected attribute, there exists a preimage to a sha hash\n// that appears in the mso, the preimage is approximately cbor formatted,\n// and the preimage includes the expected attribute id and value.\ntemplate \nclass MdocHash {\n using v8 = typename LogicCircuit::v8;\n using v32 = typename LogicCircuit::v32;\n using v256 = typename LogicCircuit::v256;\n\n using vind = typename LogicCircuit::template bitvec;\n\n using Flatsha = FlatSHA256Circuit>;\n using ShaBlockWitness = typename Flatsha::BlockWitness;\n using sha_packed_v32 = typename Flatsha::packed_v32;\n\n public:\n // These structures mimic the similarly named structures in Witness, but\n // their members are circuit wire objects instead of size_t.\n struct OpenedAttribute {\n v8 attr[32]; /* 32b representing attribute name in be. */\n v8 v1[64]; /* 64b of attribute value */\n };\n struct CborIndex {\n vind k;\n void input(const LogicCircuit& lc) {\n k = lc.template vinput();\n }\n };\n\n struct AttrShift {\n vind offset;\n vind len;\n void input(const LogicCircuit& lc) {\n offset = lc.template vinput();\n len = lc.template vinput();\n }\n };\n\n class Witness {\n public:\n v8 in_[64 * kMaxSHABlocks]; /* input bytes, 64 * MAX */\n\n v8 nb_; /* index of sha block that contains the real hash */\n ShaBlockWitness sig_sha_[kMaxSHABlocks];\n\n std::vector> attr_sha_;\n std::vector> attrb_;\n\n CborIndex valid_from_, valid_until_;\n CborIndex dev_key_info_;\n CborIndex value_digests_;\n std::vector attr_mso_;\n std::vector attr_ei_;\n std::vector attr_ev_;\n size_t num_attr_;\n\n explicit Witness(size_t num_attr) {\n num_attr_ = num_attr;\n attr_mso_.resize(num_attr);\n attr_ei_.resize(num_attr);\n attr_ev_.resize(num_attr);\n attr_sha_.resize(num_attr);\n for (size_t i = 0; i < num_attr; ++i) {\n attr_sha_[i].resize(2);\n }\n\n attrb_.resize(num_attr);\n }\n\n void input(QuadCircuit& Q, const LogicCircuit& lc) {\n nb_ = lc.template vinput<8>();\n\n // sha input init =========================\n for (size_t i = 0; i + kCose1PrefixLen < 64 * kMaxSHABlocks; ++i) {\n in_[i] = lc.template vinput<8>();\n }\n for (size_t j = 0; j < kMaxSHABlocks; j++) {\n sig_sha_[j].input(Q);\n }\n\n valid_from_.input(lc);\n valid_until_.input(lc);\n dev_key_info_.input(lc);\n value_digests_.input(lc);\n\n // // Attribute opening witnesses\n for (size_t ai = 0; ai < num_attr_; ++ai) {\n for (size_t i = 0; i < 64 * 2; ++i) {\n attrb_[ai].push_back(lc.template vinput<8>());\n }\n for (size_t j = 0; j < 2; j++) {\n attr_sha_[ai][j].input(Q);\n }\n attr_mso_[ai].input(lc);\n attr_ei_[ai].input(lc);\n attr_ev_[ai].input(lc);\n }\n }\n };\n\n explicit MdocHash(const LogicCircuit& lc) : lc_(lc), sha_(lc), r_(lc) {}\n\n void assert_valid_hash_mdoc(OpenedAttribute oa[/* NUM_ATTR */],\n const v8 now[/*20*/], const v256& e,\n const v256& dpkx, const v256& dpky,\n const Witness& vw) const {\n sha_.assert_message_hash_with_prefix(kMaxSHABlocks, vw.nb_, vw.in_,\n kCose1Prefix, kCose1PrefixLen, e,\n vw.sig_sha_);\n\n // Shift a portion of the MSO into buf and check it.\n const v8 zz = lc_.template vbit<8>(0); // cannot appear in strings\n std::vector cmp_buf(kMaxMsoLen);\n const Memcmp CMP(lc_);\n\n // In the shifting below, the +5 corresponds to the prefix\n // D8 18 prefix of the mso that we want to skip parsing.\n // The +2 corresponds to the length.\n\n // validFrom <= now\n r_.shift(vw.valid_from_.k, kValidFromLen + kDateLen, &cmp_buf[0],\n kMaxMsoLen, vw.in_ + 5 + 2, zz, /*unroll=*/3);\n assert_bytes_at(kValidFromLen, &cmp_buf[0], kValidFromCheck);\n auto cmp = CMP.leq(kDateLen, &cmp_buf[kValidFromLen], &now[0]);\n lc_.assert1(cmp);\n\n // now <= validUntil\n r_.shift(vw.valid_until_.k, kValidUntilLen + kDateLen, &cmp_buf[0],\n kMaxMsoLen, vw.in_ + 5 + 2, zz, /*unroll=*/3);\n assert_bytes_at(kValidUntilLen, &cmp_buf[0], kValidUntilCheck);\n cmp = CMP.leq(kDateLen, &now[0], &cmp_buf[kValidUntilLen]);\n lc_.assert1(cmp);\n\n // DPK_{x,y}\n r_.shift(vw.dev_key_info_.k, kDeviceKeyInfoLen + 3 + 32 + 32, &cmp_buf[0],\n kMaxMsoLen, vw.in_ + 5 + 2, zz, /*unroll=*/3);\n assert_bytes_at(kDeviceKeyInfoLen, &cmp_buf[0], kDeviceKeyInfoCheck);\n uint8_t dpkyCheck[] = {0x22, 0x58, 0x20};\n assert_bytes_at(sizeof(dpkyCheck), &cmp_buf[65], dpkyCheck);\n\n assert_key(dpkx, &cmp_buf[kPkxInd]);\n assert_key(dpky, &cmp_buf[kPkyInd]);\n\n // Attributes parsing\n // valueDigests, ignore byte 13 \\in {A1,A2} representing map size.\n r_.shift(vw.value_digests_.k, kValueDigestsLen, cmp_buf.data(), kMaxMsoLen,\n vw.in_ + 5 + 2, zz, /*unroll=*/3);\n assert_bytes_at(13, &cmp_buf[0], kValueDigestsCheck);\n assert_bytes_at(18, &cmp_buf[14], &kValueDigestsCheck[14]);\n\n // Attributes: Equality of hash with MSO value\n for (size_t ai = 0; ai < vw.num_attr_; ++ai) {\n v8 B[96];\n // Check the hash matches the value in the signed MSO.\n r_.shift(vw.attr_mso_[ai].k, 2 + 32, &cmp_buf[0], kMaxMsoLen,\n vw.in_ + 5 + 2, zz, /*unroll=*/3);\n\n // Basic CBOR check of the Tag\n assert_bytes_at(2, &cmp_buf[0], kTag32);\n\n v256 mm;\n // The loop below accounts for endian and v256 vs v8 types.\n for (size_t j = 0; j < 256; ++j) {\n mm[j] = cmp_buf[2 + (255 - j) / 8][(j % 8)];\n }\n\n auto two = lc_.template vbit<8>(2);\n sha_.assert_message_hash(2, two, vw.attrb_[ai].data(), mm,\n vw.attr_sha_[ai].data());\n\n // Check that the attribute_id and value occur in the hashed text.\n r_.shift(vw.attr_ei_[ai].offset, 96, B, 128, vw.attrb_[ai].data(), zz, 3);\n assert_attribute(96, vw.attr_ei_[ai].len, B, oa[ai]);\n }\n }\n\n private:\n void assert_bytes_at(size_t len, const v8 buf[/*>=len*/],\n const uint8_t want[/*len*/]) const {\n for (size_t i = 0; i < len; ++i) {\n auto want_i = lc_.template vbit<8>(want[i]);\n lc_.vassert_eq(&buf[i], want_i);\n }\n }\n\n // Checks that an attribute id or attribute value is as expected.\n // The len parameter holds the byte length of the expected id or value.\n void assert_attribute(size_t max, const vind& len, const v8 got[/*max*/],\n const OpenedAttribute& oa) const {\n // Copy the attribute id and value into a single array.\n v8 want[96];\n for (size_t j = 0; j < 32; ++j) {\n want[j] = oa.attr[j];\n }\n for (size_t j = 0; j < 64; ++j) {\n want[32 + j] = oa.v1[j];\n }\n\n // Perform an equality check on the first len bytes.\n for (size_t j = 0; j < max; ++j) {\n auto ll = lc_.vlt(j, len);\n auto same = lc_.eq(8, got[j].data(), want[j].data());\n lc_.assert_implies(&ll, same);\n }\n }\n\n // Asserts that the key is equal to the value in big-endian order in buf_be.\n void assert_key(v256 key, const v8 buf_be[/*32*/]) const {\n v256 m;\n for (size_t i = 0; i < 256; ++i) {\n m[i] = buf_be[31 - (i / 8)][i % 8];\n }\n lc_.vassert_eq(&m, key);\n }\n\n // The constants below define the prefix of each field that is verified\n // in the MDOC. This string matching approach is substantially faster than\n // parsing the MDOC into cbor, and its soundness analysis provides at least 96\n // bits of static security. These constants differ from similarly named ones\n // in mdoc_constants because they include header bytes; the mdoc_constants\n // values are used for cbor parsing of the raw mdoc, whereas these are used by\n // the circuit.\n\n // 69 [text(9)] 76616C696446726F6D [validFrom] C0 [tag(0)] 74 [len 20]\n static constexpr uint8_t kValidFromCheck[] = {\n 0x69, 0x76, 0x61, 0x6C, 0x69, 0x64, 0x46, 0x72, 0x6F, 0x6D, 0xC0, 0x74};\n static constexpr size_t kValidFromLen = sizeof(kValidFromCheck);\n\n // 6A [text(10)] 76616C6964556E74696C [validUntil] C0 [tag(0)] 74\n static constexpr uint8_t kValidUntilCheck[] = {0x6A, 0x76, 0x61, 0x6C, 0x69,\n 0x64, 0x55, 0x6E, 0x74, 0x69,\n 0x6C, 0xC0, 0x74};\n static constexpr size_t kValidUntilLen = sizeof(kValidUntilCheck);\n\n // 6D text(13) 6465766963654B6579496E666F \"deviceKeyInfo\"\n // A1 map(1) 69 text(9) 6465766963654B6579 \"deviceKey\"\n // A4 map(4) 01 02 20 01\n // 21 negative(1) 58 20 bytes(32)\n // \n // 22 negative(2) 58 20 bytes(32)\n // \n static constexpr uint8_t kDeviceKeyInfoCheck[] = {\n 0x6D, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4B, 0x65, 0x79, 0x49,\n 0x6E, 0x66, 0x6F, 0xA1, 0x69, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65,\n 0x4B, 0x65, 0x79, 0xA4, 0x01, 0x02, 0x20, 0x01, 0x21, 0x58, 0x20};\n static constexpr size_t kDeviceKeyInfoLen = sizeof(kDeviceKeyInfoCheck);\n static constexpr size_t kPkxInd = kDeviceKeyInfoLen;\n static constexpr size_t kPkyInd = 68; /* 64 + 3 byte tag + 1*/\n\n // 6C text(12) 76616C756544696765737473 \"valueDigests\" A{1,2} # map(1,2)\n // 71 text(17) 6F72672E69736F2E31383031332E352E31 \"org.iso.18013.5.1\"\n static constexpr uint8_t kValueDigestsCheck[] = {\n 0x6C, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x44, 0x69, 0x67,\n 0x65, 0x73, 0x74, 0x73,\n 0xA0, // either {A1, A2}\n 0x71, 0x6F, 0x72, 0x67, 0x2E, 0x69, 0x73, 0x6F, 0x2E,\n 0x31, 0x38, 0x30, 0x31, 0x33, 0x2E, 0x35, 0x2E, 0x31};\n static constexpr size_t kValueDigestsLen = sizeof(kValueDigestsCheck);\n\n static constexpr size_t kDateLen = 20;\n\n const LogicCircuit& lc_;\n Flatsha sha_;\n Routing r_;\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_HASH_H_\n"], ["/longfellow-zk/lib/circuits/jwt/jwt.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_JWT_JWT_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_JWT_JWT_H_\n\n#include \n#include \n#include \n\n#include \"circuits/base64/decode.h\"\n#include \"circuits/compiler/compiler.h\"\n#include \"circuits/ecdsa/verify_circuit.h\"\n#include \"circuits/jwt/jwt_constants.h\"\n#include \"circuits/logic/bit_plucker.h\"\n#include \"circuits/logic/routing.h\"\n#include \"circuits/sha/flatsha256_circuit.h\"\n\nnamespace proofs {\n\ntemplate \nclass JWT {\n using EltW = typename LogicCircuit::EltW;\n using BitW = typename LogicCircuit::BitW;\n using Nat = typename Field::N;\n using Ecdsa = VerifyCircuit;\n using EcdsaWitness = typename Ecdsa::Witness;\n using v8 = typename LogicCircuit::v8;\n using v256 = typename LogicCircuit::v256;\n using Flatsha =\n FlatSHA256Circuit>;\n using ShaBlockWitness = typename Flatsha::BlockWitness;\n using sha_packed_v32 = typename Flatsha::packed_v32;\n using vind = typename LogicCircuit::template bitvec;\n\n public:\n struct OpenedAttribute {\n v8 attr[32]; /* 32b representing attribute name in be. */\n v8 v1[64]; /* 64b of attribute value */\n };\n\n class Witness {\n public:\n EltW r_, s_, e_;\n EcdsaWitness jwt_sig_;\n v8 preimage_[64 * kMaxJWTSHABlocks];\n v256 e_bits_;\n ShaBlockWitness sha_[kMaxJWTSHABlocks];\n v8 nb_; /* index of sha block that contains the real hash */\n std::vector attr_ind_;\n std::vector attr_id_len_;\n std::vector attr_value_len_;\n vind payload_ind_, payload_len_;\n\n void input(QuadCircuit& Q, const LogicCircuit& lc, size_t na) {\n r_ = Q.input();\n s_ = Q.input();\n e_ = Q.input();\n jwt_sig_.input(Q);\n for (size_t i = 0; i < 64 * kMaxJWTSHABlocks; ++i) {\n preimage_[i] = lc.template vinput<8>();\n }\n e_bits_ = lc.template vinput<256>();\n for (size_t j = 0; j < kMaxJWTSHABlocks; ++j) {\n sha_[j].input(Q);\n }\n nb_ = lc.template vinput<8>();\n\n for (size_t j = 0; j < na; ++j) {\n attr_ind_.push_back(lc.template vinput());\n attr_id_len_.push_back(lc.template vinput<8>());\n attr_value_len_.push_back(lc.template vinput<8>());\n }\n payload_ind_ = lc.template vinput();\n payload_len_ = lc.template vinput();\n }\n };\n\n explicit JWT(const LogicCircuit& lc, const EC& ec, const Nat& order)\n : lc_(lc), ec_(ec), order_(order), sha_(lc), r_(lc) {}\n\n // The assert_jwt_attributes circuit verifies the following claims:\n // 1. There exists a hash digest e and a signature (r,s) on e\n // under the public key (pkX, pkY).\n // 2. There exists a msg, and the hash of msg is equal to e.\n // 3. The JWT message is decoded correctly from base64.\n // 4. The decoded message is equal to the payload.header.\n // 5. The header contains alg:ESP256. [TODO]\n // 6. The attributes occur as \":\"\" in the payload.body.\n //\n // Note that the soundness of (6) relies on assumptions about the format of\n // the JWT. The issuer cannot add spaces, cannot escape quotes in the body,\n // and the character : should only appear as a separator.\n void assert_jwt_attributes(EltW pkX, EltW pkY,\n OpenedAttribute oa[/* NUM_ATTR */],\n Witness& vw) const {\n Ecdsa ecc(lc_, ec_, order_);\n\n ecc.verify_signature3(pkX, pkY, vw.e_, vw.jwt_sig_);\n\n sha_.assert_message_hash(kMaxJWTSHABlocks, vw.nb_, vw.preimage_, vw.e_bits_,\n vw.sha_);\n lc_.vassert_is_bit(vw.e_bits_);\n\n // Check that the e_bits_ match the EltW for e used in the signature.\n auto twok = lc_.one();\n auto est = lc_.konst(0);\n for (size_t i = 0; i < 256; ++i) {\n est = lc_.axpy(&est, twok, lc_.eval(vw.e_bits_[i]));\n lc_.f_.add(twok, twok);\n }\n lc_.assert_eq(&est, vw.e_);\n\n // Assert the attribute equality\n const v8 zz = lc_.template vbit<8>(0); // cannot appear in strings\n std::vector shift_buf(64 * kMaxJWTSHABlocks);\n\n // First shift the payload into the shift_buf.\n r_.shift(vw.payload_ind_, 64 * (kMaxJWTSHABlocks - 2), shift_buf.data(),\n 64 * kMaxJWTSHABlocks, vw.preimage_, zz, 3);\n\n // Decode the entire payload. A possible improvement is to decode just\n // the portion necessary.\n std::vector dec_buf(64 * kMaxJWTSHABlocks);\n Base64Decoder b64(lc_);\n b64.base64_rawurl_decode_len(shift_buf.data(), dec_buf.data(),\n 64 * (kMaxJWTSHABlocks - 2), vw.payload_len_);\n\n // For each attribute, shift the decoded payload so that the\n // attribute is at the beginning of B. Verify the attribute id, the\n // json separator, the attribute value, and the end quote.\n for (size_t i = 0; i < vw.attr_ind_.size(); ++i) {\n v8 B[32 + 3 + 64 + 1];\n\n // Check that values of the attribute_id.\n r_.shift(vw.attr_ind_[i], 100, B, dec_buf.size(), dec_buf.data(), zz, 3);\n assert_string_eq(32, vw.attr_id_len_[i], B, oa[i].attr);\n\n r_.shift(vw.attr_id_len_[i], 100, B, 100, B, zz, 3);\n uint8_t sep[3] = {'\"', ':', '\"'};\n for (size_t j = 0; j < 3; ++j) {\n auto want_j = lc_.template vbit<8>(sep[j]);\n lc_.vassert_eq(&B[j], want_j);\n }\n\n auto three = lc_.template vbit<2>(3);\n r_.shift(three, 100, B, 100, B, zz, 3);\n\n assert_string_eq(64, vw.attr_value_len_[i], B, oa[i].v1);\n\n r_.shift(vw.attr_value_len_[i], 100, B, 100, B, zz, 3);\n\n auto end_quote = lc_.template vbit<8>('\"');\n lc_.vassert_eq(&B[0], end_quote);\n }\n }\n\n void assert_string_eq(size_t max, const v8& len, const v8 got[/*max*/],\n const v8 want[/*max*/]) const {\n for (size_t j = 0; j < max; ++j) {\n auto ll = lc_.vlt(j, len);\n auto same = lc_.eq(8, got[j].data(), want[j].data());\n lc_.assert_implies(&ll, same);\n }\n }\n\n private:\n const LogicCircuit& lc_;\n const EC& ec_;\n const Nat& order_;\n Flatsha sha_;\n Routing r_;\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_JWT_JWT_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_revocation.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_REVOCATION_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_REVOCATION_H_\n\n#include \n\n#include \"circuits/compiler/compiler.h\"\n#include \"circuits/ecdsa/verify_circuit.h\"\n#include \"circuits/logic/bit_plucker.h\"\n#include \"circuits/mdoc/mdoc_revocation_constants.h\"\n#include \"circuits/sha/flatsha256_circuit.h\"\n\nnamespace proofs {\n\n// The first revocation approach works for small lists that are expected to\n// be small. In this case, the prover simply asserts that their identifier is\n// different from all the identifiers in the list.\ntemplate \nclass MdocRevocationList {\n using EltW = typename LogicCircuit::EltW;\n\n public:\n explicit MdocRevocationList(const LogicCircuit& lc) : lc_(lc) {}\n\n // This function asserts that a given identifier is not on a revocation list.\n // The method is to assert that Prod_i (list[i) - id) != 0.\n void assert_not_on_list(EltW list[], size_t list_size,\n /* the witness */ EltW id, EltW prodinv) const {\n EltW prod =\n lc_.mul(0, list_size, [&](size_t i) { return lc_.sub(&list[i], id); });\n EltW want_one = lc_.mul(&prod, prodinv);\n lc_.assert_eq(&want_one, lc_.konst(lc_.one()));\n }\n\n const LogicCircuit& lc_;\n};\n\n// The second revocation approachs works for larger lists. In this case, the\n// prover retrieves a witness that their credential is *not* on the revoked\n// list by presenting a signature of the span (l,r) and proving that their\n// revocation identifier rev_id satisfied l < rev_id < r.\n// Specifically, the format of the span is:\n// epoch || l || r\n// where epoch is a 64 bit integer, l and r are 256 bit integers. All of\n// the values are encoded in little endian order.\ntemplate \nclass MdocRevocationSpan {\n using EltW = typename LogicCircuit::EltW;\n using Nat = typename Field::N;\n using Ecdsa = VerifyCircuit;\n using EcdsaWitness = typename Ecdsa::Witness;\n using v8 = typename LogicCircuit::v8;\n using v256 = typename LogicCircuit::v256;\n using Flatsha =\n FlatSHA256Circuit>;\n using ShaBlockWitness = typename Flatsha::BlockWitness;\n using sha_packed_v32 = typename Flatsha::packed_v32;\n\n public:\n class Witness {\n public:\n EltW r_, s_, e_;\n EcdsaWitness rev_sig_;\n v8 preimage_[64 * 2]; // epoch || l || r in little endian order\n v256 id_bits_;\n v256 e_bits_;\n ShaBlockWitness sha_[2];\n\n void input(QuadCircuit& Q, const LogicCircuit& lc) {\n r_ = Q.input();\n s_ = Q.input();\n e_ = Q.input();\n rev_sig_.input(Q);\n for (size_t i = 0; i < 64 * 2; ++i) {\n preimage_[i] = lc.template vinput<8>();\n }\n id_bits_ = lc.template vinput<256>();\n e_bits_ = lc.template vinput<256>();\n for (size_t j = 0; j < 2; j++) {\n sha_[j].input(Q);\n }\n }\n };\n\n explicit MdocRevocationSpan(const LogicCircuit& lc, const EC& ec,\n const Nat& order)\n : lc_(lc), ec_(ec), order_(order), sha_(lc) {}\n\n // This function asserts that id is not on the revocation list by verifying\n // that the signature (r,s) on the span (l,r) is valid, and then verifying\n // that l < id < r. The argument (craPkX, craPkY) represent the public key\n // of the issuer of the revocation list.\n void assert_not_on_list(EltW craPkx, EltW craPkY,\n /* the witness */ EltW id, Witness& vw) const {\n Ecdsa ecc(lc_, ec_, order_);\n\n ecc.verify_signature3(craPkx, craPkY, vw.e_, vw.rev_sig_);\n\n lc_.vassert_is_bit(vw.e_bits_);\n lc_.vassert_is_bit(vw.id_bits_);\n\n // Check that e = hash(epoch || l || r)\n auto two = lc_.template vbit<8>(2);\n sha_.assert_message_hash(2, two, vw.preimage_, vw.e_bits_, vw.sha_);\n\n // Check that the bits of e match the EltW for e.\n auto twok = lc_.one();\n auto est = lc_.konst(0);\n for (size_t i = 0; i < 256; ++i) {\n est = lc_.axpy(&est, twok, lc_.eval(vw.e_bits_[i]));\n lc_.f_.add(twok, twok);\n }\n lc_.assert_eq(&est, vw.e_);\n\n // // Check that l < id < r\n v256 ll, rr;\n for (size_t i = 0; i < 256; ++i) {\n ll[i] = vw.preimage_[8 + i / 8][i % 8];\n rr[i] = vw.preimage_[40 + i / 8][i % 8];\n }\n lc_.assert1(lc_.vlt(&ll, vw.id_bits_));\n lc_.assert1(lc_.vlt(&vw.id_bits_, rr));\n }\n\n const LogicCircuit& lc_;\n const EC& ec_;\n const Nat& order_;\n Flatsha sha_;\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_REVOCATION_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_signature.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_SIGNATURE_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_SIGNATURE_H_\n\n#include \n\n#include \"circuits/compiler/compiler.h\"\n#include \"circuits/ecdsa/verify_circuit.h\"\n#include \"circuits/logic/bit_plucker.h\"\n#include \"circuits/mac/mac_circuit.h\"\n\nnamespace proofs {\n\n// This class creates a circuit to verify the signatures in an MDOC.\n// There are 2 signatures:\n// 1. A signature on the MSO by the issuer of the MDOC: The public\n// key of the issuer is given as input for now. Later, it can be\n// one among a list of issuers. While the signer is public, the\n// message is private, and thus its hash is committed in the witness.\n// 2. A signature on the transcript provided during a \"Show\" operation:\n// the signature is under a device public key that is specified in the\n// MSO. Thus, the signing key is private (and committed), but the\n// message is public.\ntemplate \nclass MdocSignature {\n using EltW = typename LogicCircuit::EltW;\n using Elt = typename LogicCircuit::Elt;\n using Nat = typename Field::N;\n using v128 = typename LogicCircuit::v128;\n using v256 = typename LogicCircuit::v256;\n using Ecdsa = VerifyCircuit;\n using EcdsaWitness = typename Ecdsa::Witness;\n using MacBitPlucker = BitPlucker;\n using packed_v256 = typename MacBitPlucker::packed_v256;\n using mac = MAC;\n using MACWitness = typename mac::Witness;\n\n const LogicCircuit& lc_;\n const EC& ec_;\n const Nat& order_;\n\n public:\n class Witness {\n public:\n EltW e_;\n EltW dpkx_, dpky_;\n\n EcdsaWitness mdoc_sig_;\n EcdsaWitness dpk_sig_;\n MACWitness macs_[3];\n\n void input(QuadCircuit& Q, const LogicCircuit& lc) {\n e_ = Q.input();\n dpkx_ = Q.input();\n dpky_ = Q.input();\n\n mdoc_sig_.input(Q);\n dpk_sig_.input(Q);\n for (size_t i = 0; i < 3; ++i) {\n macs_[i].input(lc, Q);\n }\n }\n };\n\n explicit MdocSignature(const LogicCircuit& lc, const EC& ec, const Nat& order)\n : lc_(lc), ec_(ec), order_(order) {}\n\n // This function is used to verify the signatures in an MDOC.\n // The circuit verifies the following claims:\n // 1. There exists a hash digest e and a signature (r,s) on e\n // under the public key (pkX, pkY).\n // 2. The MAC of e under the secret mac key (a_v+a_pe) is mac_e.\n // 3. There exists a device public key (dpkX, dpky) and a signature (r,s)\n // on the value hash_tr.\n // 4. The MAC of the device public key (dpkX, dpky) under the secret MAC\n // key (a_v + apdk) is mac_dkpX and mac_dpkY respectively.\n void assert_signatures(EltW pkX, EltW pkY, EltW hash_tr, v128 mac_e[2],\n v128 mac_dpkX[2], v128 mac_dpkY[2], v128 a_v,\n Witness& vw) const {\n Ecdsa ecc(lc_, ec_, order_);\n mac macc(lc_);\n\n ecc.verify_signature3(pkX, pkY, vw.e_, vw.mdoc_sig_);\n ecc.verify_signature3(vw.dpkx_, vw.dpky_, hash_tr, vw.dpk_sig_);\n\n macc.verify_mac(vw.e_, mac_e, a_v, vw.macs_[0], order_);\n macc.verify_mac(vw.dpkx_, mac_dpkX, a_v, vw.macs_[1], order_);\n macc.verify_mac(vw.dpky_, mac_dpkY, a_v, vw.macs_[2], order_);\n }\n\n // This function is similar to assert_signatures, but it also hides the\n // public key of the issuer. Instead, it verifies that the issuer's public\n // key belongs in a list of 50 public keys that are supplied as input. The\n // issuer pk lists are assumed to be trusted inputs, i.e., it is the\n // caller's responsibility to ensure that (issuer_pkX[i], issuer_pkY[i]) is\n // a valid curve point for i=0..49. The caller is also responsible for\n // ensuring that issuer_pkY[i] != -issuer_pkY[j] for i != j.\n // However, it is OK for the caller to repeat the same key in the list.\n void assert_signatures_with_issuer_list(\n EltW hash_tr, v128 mac_e[2], v128 mac_dpkX[2], v128 mac_dpkY[2], v128 a_v,\n EltW issuer_pkX[/*max_issuers*/], EltW issuer_pkY[/*max_issuers*/],\n size_t max_issuers,\n // private inputs begin here\n EltW pkX, EltW pkY, Witness& vw) const {\n assert_signatures(pkX, pkY, hash_tr, mac_e, mac_dpkX, mac_dpkY, a_v, vw);\n\n // Verify that the issuer's public key is one of the 50 keys in the list.\n // This is done by computing the difference between pkX and issuer_pkX[i]\n // for i=0..49, and asserting that the product of the differences is zero.\n //\n // We argue that it suffices to verify that pkX is on the list and pkY is\n // on the list independently. Suppose a malicious prover sets pkX to be\n // equal to the j-th key in issuer_pkX and sets pkY to be the k-th key in\n // issuer_pkY, where j != k. If (pkX, pkY) is not a curve point, then the\n // assert_signatures() routine will fail. However, for each X on the curve,\n // there are only 2 possible Y values, namely, +-Y. By the constraints\n // imposed on issuer_pkY, we know that issuer_pkY[j] is on the curve, and\n // that -issuer_pkY[j] does not occur in the issuer_pkY list. Thus, it is\n // not possible for a witness to pass all checks and for k != j.\n EltW goodXKey = lc_.mul(0, max_issuers, [&](size_t i) {\n return lc_.sub(&issuer_pkX[i], pkX);\n });\n lc_.assert0(goodXKey);\n\n EltW goodYKey = lc_.mul(0, max_issuers, [&](size_t i) {\n return lc_.sub(&issuer_pkY[i], pkY);\n });\n lc_.assert0(goodYKey);\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_SIGNATURE_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_witness.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_WITNESS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_WITNESS_H_\n\n#include \n#include \n\n#include \n#include \n#include \n#include \n\n#include \"arrays/dense.h\"\n#include \"cbor/host_decoder.h\"\n#include \"circuits/ecdsa/verify_witness.h\"\n#include \"circuits/logic/bit_plucker_encoder.h\"\n#include \"circuits/mac/mac_witness.h\"\n#include \"circuits/mdoc/mdoc_constants.h\"\n#include \"circuits/mdoc/mdoc_hash.h\"\n#include \"circuits/mdoc/mdoc_zk.h\"\n#include \"circuits/sha/flatsha256_witness.h\"\n#include \"gf2k/gf2_128.h\"\n#include \"util/crypto.h\"\n#include \"util/log.h\"\n#include \"util/panic.h\"\n\n\nnamespace proofs {\n\nstruct CborIndex {\n size_t k, v, ndx;\n size_t pos, len; /* optional fields for string/byte values */\n};\n\nstruct AttrShift {\n size_t offset, len;\n};\n\n// This class represents an attribute that is parsed out of the deviceResponse\n// data structure. It includes offsets into the original mdoc which can be used\n// to construct SHA witnesses for disclosing the value of an attribute.\nstruct FullAttribute {\n // Offset and length of the attribute identifier and attribute value.\n size_t id_ind;\n size_t id_len;\n size_t val_ind;\n size_t val_len;\n\n // Index for this attribute among all attributes in the mdoc hash list.\n size_t digest_id;\n CborIndex mso;\n\n // Offset and length of the attribute tag.\n size_t tag_ind;\n size_t tag_len;\n\n // The original mdoc into which all offsets point.\n const uint8_t* doc;\n\n bool operator==(const RequestedAttribute& y) const {\n return y.id_len == id_len && memcmp(y.id, &doc[id_ind], id_len) == 0;\n }\n\n size_t witness_length(const RequestedAttribute& attr) {\n size_t r = id_len + val_len + 1 + 12;\n if (attr.type == CborAttributeType::kDate) {\n r += 4;\n } else if (attr.type == CborAttributeType::kString ||\n attr.type == CborAttributeType::kBytes) {\n r += 1;\n if (val_len > 23) r++;\n if (val_len > 255) r++;\n }\n return r;\n }\n};\n\nclass ParsedMdoc {\n public:\n // Various cbor indices/witnesses for intermediate structures.\n CborIndex t_mso_, sig_, dksig_;\n CborIndex valid_, valid_from_, valid_until_;\n CborIndex dev_key_info_, dev_key_, dev_key_pkx_, dev_key_pky_;\n CborIndex value_digests_, org_;\n std::vector attributes_;\n std::vector doc_type_;\n\n // These are the exact bytes which produce the hash that is signed.\n std::vector tagged_mso_bytes_;\n\n /*\n Parses a byte representation of the \"DeviceResponse\" string from a phone.\n This contains all of the information needed to respond to an mdoc verifier.\n This method attempts to construct a witness from this.\n\n 8.3.2.1.2.2: first field is \"version\", 2nd optional field is \"documents\"\n [documents][0][issuerSigned][issuerAuth]{2} --> tagged mso\n [documents][0][issuerSigned][issuerAuth]{3} --> issuer sig\n [documents][0][issuerSigned][nameSpaces][ns][index-of-attr] --> enc attr\n [documents][0][deviceSigned][deviceAuth][deviceSignature][3] --> sig\n\n This method produces indices into doc as state.\n */\n bool parse_device_response(size_t len, const uint8_t resp[/* len */]) {\n size_t np = 0;\n // When this object falls out of scope, all parsing objects will be\n // garbage collected.\n CborDoc root;\n bool ok = root.decode(resp, len, np, 0);\n if (!ok) {\n log(ERROR, \"Failed to decode root\");\n return false;\n }\n\n size_t di;\n auto docs = root.lookup(resp, 9, (uint8_t*)\"documents\", di);\n if (docs == nullptr) return false;\n // Fields of Document are \"docType\", \"issuerSigned\", \"deviceSigned\", ?errors\n\n auto docs0 = docs[1].index(0);\n if (docs0 == nullptr) return false;\n\n auto dt = docs0[0].lookup(resp, 7, (uint8_t*)\"docType\", di);\n if (dt == nullptr) return false;\n doc_type_.insert(doc_type_.begin(), resp + dt[1].u_.string.pos,\n resp + dt[1].u_.string.pos + dt[1].u_.string.len);\n\n // The returned docs0 is the map, so index at [0].\n auto is = docs0[0].lookup(resp, 12, (uint8_t*)\"issuerSigned\", di);\n if (is == nullptr) return false;\n\n auto ia = is[1].lookup(resp, 10, (uint8_t*)\"issuerAuth\", di);\n if (ia == nullptr) return false;\n\n auto tmso = ia[1].index(2);\n if (tmso == nullptr) return false;\n copy_header(t_mso_, tmso);\n auto nsig = ia[1].index(3);\n if (nsig == nullptr) return false;\n copy_header(sig_, nsig);\n\n auto ns = is[1].lookup(resp, 10, (uint8_t*)\"nameSpaces\", di);\n if (ns == nullptr) return false;\n\n // Find the attribute witness we need from here.\n // For now, we only support 1 namespace.\n auto mldns = ns[1].lookup(resp, 17, (uint8_t*)\"org.iso.18013.5.1\", di);\n if (mldns == nullptr) return false;\n size_t ai = 0;\n auto tattr = mldns[1].index(ai++);\n while (tattr != nullptr) {\n CborDoc er;\n // Decode the map in this tagged attribute.\n size_t pos = tattr->children_[0].u_.string.pos;\n size_t end = pos + tattr->children_[0].u_.string.len;\n if (!er.decode(resp, end, pos, 0)) {\n return false;\n }\n\n auto ei = er.lookup(resp, 17, (uint8_t*)\"elementIdentifier\", di);\n if (ei == nullptr) return false;\n auto ev = er.lookup(resp, 12, (uint8_t*)\"elementValue\", di);\n if (ev == nullptr) return false;\n auto digid = er.lookup(resp, 8, (uint8_t*)\"digestID\", di);\n if (digid == nullptr) return false;\n\n attributes_.push_back(\n (FullAttribute){ei[1].position(),\n ei[1].length(),\n ev[1].position(),\n ev[1].length(),\n static_cast(digid[1].u_.u64), /* digest_id */\n {0, 0, 0}, /* default mso_ind */\n tattr->header_pos_, /* tag_ind */\n tattr->children_[0].u_.string.len +\n 4, /* +4 for the D8 18 58 <> prefix */\n resp});\n\n tattr = mldns[1].index(ai++);\n }\n\n auto ds = docs0[0].lookup(resp, 12, (uint8_t*)\"deviceSigned\", di);\n if (ds == nullptr) return false;\n auto da = ds[1].lookup(resp, 10, (uint8_t*)\"deviceAuth\", di);\n if (da == nullptr) return false;\n auto dsi = da[1].lookup(resp, 15, (uint8_t*)\"deviceSignature\", di);\n if (dsi == nullptr) return false;\n auto ndksig = dsi[1].index(3);\n if (ndksig == nullptr) return false;\n copy_header(dksig_, ndksig);\n\n // Then parse tagged mso. Skip 5 bytes to skip the D8 18 59 .\n const uint8_t* pmso = resp + tmso->u_.string.pos + 5;\n size_t pos = 0;\n CborDoc mso;\n if (!mso.decode(pmso, tmso->u_.string.len - 5, pos, 0)) return false;\n auto nv = mso.lookup(pmso, kValidityInfoLen, kValidityInfoID, valid_.ndx);\n if (nv == nullptr) return false;\n copy_kv_header(valid_, nv);\n\n auto nvf = nv[1].lookup(pmso, kValidFromLen, kValidFromID, valid_from_.ndx);\n if (nvf == nullptr) return false;\n copy_kv_header(valid_from_, nvf);\n\n auto nvu =\n nv[1].lookup(pmso, kValidUntilLen, kValidUntilID, valid_until_.ndx);\n if (nvu == nullptr) return false;\n copy_kv_header(valid_until_, nvu);\n\n auto ndki = mso.lookup(pmso, kDeviceKeyInfoLen, kDeviceKeyInfoID,\n dev_key_info_.ndx);\n if (ndki == nullptr) return false;\n copy_kv_header(dev_key_info_, ndki);\n\n auto ndk = ndki[1].lookup(pmso, kDeviceKeyLen, kDeviceKeyID, dev_key_.ndx);\n if (ndk == nullptr) return false;\n copy_kv_header(dev_key_, ndk);\n\n auto npkx = ndk[1].lookup_negative(-1, dev_key_pkx_.ndx);\n if (npkx == nullptr) return false;\n copy_kv_header(dev_key_pkx_, npkx);\n\n auto npky = ndk[1].lookup_negative(-2, dev_key_pky_.ndx);\n if (npky == nullptr) return false;\n copy_kv_header(dev_key_pky_, npky);\n\n auto nvd =\n mso.lookup(pmso, kValueDigestsLen, kValueDigestsID, value_digests_.ndx);\n if (nvd == nullptr) return false;\n copy_kv_header(value_digests_, nvd);\n\n auto norg = nvd[1].lookup(pmso, kOrgLen, kOrgID, org_.ndx);\n if (norg == nullptr) return false;\n copy_kv_header(org_, norg);\n\n for (auto& attr : attributes_) {\n uint64_t hi = (uint64_t)attr.digest_id;\n auto hattr = norg[1].lookup_unsigned(hi, attr.mso.ndx);\n if (hattr == nullptr) return false;\n copy_kv_header(attr.mso, hattr);\n }\n\n tagged_mso_bytes_.assign(std::begin(kCose1Prefix), std::end(kCose1Prefix));\n // Add 2-byte length\n tagged_mso_bytes_.push_back((t_mso_.len >> 8) & 0xff);\n tagged_mso_bytes_.push_back(t_mso_.len & 0xff);\n for (size_t i = 0; i < t_mso_.len; ++i) {\n tagged_mso_bytes_.push_back(resp[t_mso_.pos + i]);\n }\n\n return true;\n }\n\n private:\n // Used to copy the results of a map lookup.\n static void copy_kv_header(CborIndex& ind, const CborDoc* n) {\n ind.k = n[0].header_pos_;\n ind.v = n[1].header_pos_;\n\n if (n[1].t_ == TEXT || n[1].t_ == BYTES) {\n ind.pos = n[1].u_.string.pos;\n ind.len = n[1].u_.string.len;\n }\n }\n\n // Used to copy the results of an index lookup.\n static void copy_header(CborIndex& ind, const CborDoc* n) {\n ind.k = n->header_pos_;\n ind.pos = n->u_.string.pos;\n ind.len = n->u_.string.len;\n }\n};\n\n// Transform from u8 be (i.e., be[31] is the most significant byte) into\n// nat form, which requires first converting to le byte order.\ntemplate \nNat nat_from_be(const uint8_t be[/* Nat::kBytes */]) {\n uint8_t tmp[Nat::kBytes];\n // Transform into byte-wise le representation.\n for (size_t i = 0; i < Nat::kBytes; ++i) {\n tmp[i] = be[Nat::kBytes - i - 1];\n }\n return Nat::of_bytes(tmp);\n}\n\n// Transform from u32 be (i.e., be[0] is the most significant nibble)\n// into nat form, which requires first converting to le byte order.\ntemplate \nNat nat_from_u32(const uint32_t be[]) {\n uint8_t tmp[Nat::kBytes];\n const size_t top = Nat::kBytes / 4;\n for (size_t i = 0; i < Nat::kBytes; ++i) {\n tmp[i] = (be[top - i / 4 - 1] >> ((i % 4) * 8)) & 0xff;\n }\n return Nat::of_bytes(tmp);\n}\n\ntemplate \nNat nat_from_hash(const uint8_t data[], size_t len) {\n uint8_t hash[kSHA256DigestSize];\n SHA256 sha;\n sha.Update(data, len);\n sha.DigestData(hash);\n Nat ne = nat_from_be(hash);\n return ne;\n}\n\nstatic inline void append_bytes_len(std::vector& buf, size_t len) {\n if (len > 256) {\n uint8_t ll[] = {0x59, (uint8_t)((len >> 8) & 0xff), (uint8_t)(len & 0xff)};\n buf.insert(buf.end(), ll, ll + 3);\n } else {\n uint8_t ll[] = {0x58, static_cast(len & 0xff)};\n buf.insert(buf.end(), ll, ll + 2);\n }\n}\n\nstatic inline void append_text_len(std::vector& buf, size_t len) {\n check(len < 256, \"Text length too large\");\n if (len < 24) {\n buf.push_back(0x60 + len);\n } else if (len < 255) {\n buf.push_back(0x78);\n buf.push_back(len);\n }\n}\n\n// Form the COSE1 encoding of the DeviceAuthenticationBytes,\n// then compute its SHA-256 hash, and cast into a Nat.\n// The original form follows S9.1.3.4 of the mdoc spec and\n// assumed that the transcript was a simple string.\n// The Jan'2024 demo requires using the \"AndroidHandover\" version\n// of the DeviceAuthenticationBytes formatting, which is not\n// specified in the spec. As a result, this function is a hack\n// that mimics the bytes produced by the Android com.android.identity.wallet\n// library.\ntemplate \nstatic Nat compute_transcript_hash(\n const uint8_t transcript[], size_t len,\n const std::vector* docType = nullptr) {\n // The DeviceAuthenticationBytes is defined in 9.1.3.4 as:\n // DeviceAuthentication = [\n // \"DeviceAuthentication\",\n // SessionTranscript,\n // DocType, ; Same as in mdoc response\n // DeviceNameSpacesBytes ; Same as in mdoc response\n // ]\n std::vector deviceAuthentication = {\n 0x84, 0x74, 'D', 'e', 'v', 'i', 'c', 'e', 'A', 'u', 't',\n 'h', 'e', 'n', 't', 'i', 'c', 'a', 't', 'i', 'o', 'n',\n };\n std::vector docTypeBytes = {\n 0x75, 'o', 'r', 'g', '.', 'i', 's', 'o', '.', '1', '8',\n '0', '1', '3', '.', '5', '.', '1', '.', 'm', 'D', 'L',\n };\n std::vector deviceNameSpacesBytes = {0xD8, 0x18, 0x41, 0xA0};\n\n if (docType != nullptr) {\n docTypeBytes.clear();\n append_text_len(docTypeBytes, docType->size());\n docTypeBytes.insert(docTypeBytes.end(), docType->begin(), docType->end());\n }\n\n // Provide the DeviceAuthentication bytes\n std::vector da(deviceAuthentication);\n da.insert(da.end(), transcript, transcript + len);\n da.insert(da.end(), docTypeBytes.begin(), docTypeBytes.end());\n da.insert(da.end(), deviceNameSpacesBytes.begin(),\n deviceNameSpacesBytes.end());\n\n // Form the COSE1 encoding of the DeviceAuthenticationBytes.\n std::vector cose1{0x84, 0x6A, 0x53, 0x69, 0x67, 0x6E,\n 0x61, 0x74, 0x75, 0x72, 0x65, 0x31,\n 0x43, 0xA1, 0x01, 0x26, 0x40};\n uint8_t tag[] = {0xD8, 0x18};\n\n size_t l1 = da.size();\n size_t l2 = l1 + (l1 < 256 ? 4 : 5); /* Tagged array length. */\n append_bytes_len(cose1, l2);\n cose1.insert(cose1.end(), tag, tag + 2);\n append_bytes_len(cose1, l1);\n cose1.insert(cose1.end(), da.begin(), da.end());\n\n return nat_from_hash(cose1.data(), cose1.size());\n}\n\n// Interpret input s as an len*8-bit string, and use it to fill max*8 bits\n// in the dense filler.\n// Pad the input with the Field value 2 to indicate the positions\n// that are not part of the string.\ntemplate \nvoid fill_bit_string(DenseFiller& filler, const uint8_t s[/*len*/],\n size_t len, size_t max, const Field& Fs) {\n std::vector v(max * 8, Fs.of_scalar(2));\n for (size_t i = 0; i < max && i < len; ++i) {\n fill_byte(v, s[i], i, Fs);\n }\n filler.push_back(v);\n}\n\ntemplate \nvoid fill_byte(std::vector& v, uint8_t b, size_t i,\n const Field& F) {\n for (size_t j = 0; j < 8; ++j) {\n v[i*8 + j] = ( b >> j & 0x1 ) ? F.one() : F.zero();\n }\n}\n\ntemplate \nvoid fill_attribute(DenseFiller &filler, const RequestedAttribute &attr,\n const Field &F, size_t version = 2) {\n if (version <= 2) {\n fill_bit_string(filler, attr.id, attr.id_len, 32, F);\n fill_bit_string(filler, attr.value, attr.value_len, 64, F);\n } else if (version == 3) {\n // In version 3, the attribute is encoded as the raw cbor string that\n // included \n std::vector v(96 * 8, F.of_scalar(0));\n\n size_t i = 0;\n for (size_t j = 0; j < attr.id_len && i < 96; ++j, ++i) {\n fill_byte(v, attr.id[j], i, F);\n }\n fill_byte(v, 0x6C, i++, F); // Cbor type for length 12 string.\n const char* ev = \"elementValue\";\n for (size_t j = 0; j < 12 && i < 96; ++j, ++i) {\n fill_byte(v, ev[j], i, F);\n }\n std::vector vbuf;\n uint8_t tag[] = {0xD9, 0x03, 0xEC, 0x6A};\n switch (attr.type) {\n case CborAttributeType::kPrimitive:\n vbuf.push_back(attr.value[0]);\n break;\n case CborAttributeType::kString:\n append_text_len(vbuf, attr.value_len);\n vbuf.insert(vbuf.end(), attr.value, attr.value + attr.value_len);\n break;\n case CborAttributeType::kBytes:\n append_bytes_len(vbuf, attr.value_len);\n vbuf.insert(vbuf.end(), attr.value, attr.value + attr.value_len);\n break;\n case CborAttributeType::kDate:\n vbuf.insert(vbuf.end(), tag, tag + 4);\n vbuf.insert(vbuf.end(), attr.value, attr.value + attr.value_len);\n break;\n case CborAttributeType::kInt:\n vbuf.insert(vbuf.end(), attr.value, attr.value + attr.value_len);\n break;\n }\n for (size_t j = 0; j < vbuf.size() && i < 96; ++j, ++i) {\n fill_byte(v, vbuf[j], i, F);\n }\n filler.push_back(v);\n }\n}\n\n\ntemplate \nclass MdocSignatureWitness {\n using Field = typename EC::Field;\n using Elt = typename Field::Elt;\n using Nat = typename Field::N;\n using EcdsaWitness = VerifyWitness3;\n using MacWitnessF = MacWitness;\n using f_128 = GF2_128<>;\n const EC& ec_;\n const f_128& gf_;\n\n public:\n Elt e_, e2_; /* Issuer signature values. */\n Elt dpkx_, dpky_; /* device key */\n EcdsaWitness ew_, dkw_;\n MacWitnessF macs_[3]; /* macs for e_, dpkx_, dpky_ */\n\n explicit MdocSignatureWitness(const EC& ec, const ScalarField& Fn,\n const f_128& gf)\n : ec_(ec),\n gf_(gf),\n ew_(Fn, ec),\n dkw_(Fn, ec),\n macs_{MacWitnessF(ec.f_, gf_), MacWitnessF(ec.f_, gf_),\n MacWitnessF(ec.f_, gf_)} {}\n\n void fill_witness(DenseFiller& filler) const {\n filler.push_back(e_);\n filler.push_back(dpkx_);\n filler.push_back(dpky_);\n\n ew_.fill_witness(filler);\n dkw_.fill_witness(filler);\n for (auto& mac : macs_) {\n mac.fill_witness(filler);\n }\n }\n\n bool compute_witness(Elt pkX, Elt pkY, const uint8_t mdoc[/* len */],\n size_t len, const uint8_t transcript[/* tlen */],\n size_t tlen) {\n ParsedMdoc pm;\n\n if (!pm.parse_device_response(len, mdoc)) {\n return false;\n }\n\n Nat ne = nat_from_hash(pm.tagged_mso_bytes_.data(),\n pm.tagged_mso_bytes_.size());\n e_ = ec_.f_.to_montgomery(ne);\n\n // Parse (r,s).\n const size_t l = pm.sig_.len;\n Nat nr = nat_from_be(&mdoc[pm.sig_.pos]);\n Nat ns = nat_from_be(&mdoc[pm.sig_.pos + l / 2]);\n ew_.compute_witness(pkX, pkY, ne, nr, ns);\n\n Nat ne2 = compute_transcript_hash(transcript, tlen, &pm.doc_type_);\n const size_t l2 = pm.dksig_.len;\n Nat nr2 = nat_from_be(&mdoc[pm.dksig_.pos]);\n Nat ns2 = nat_from_be(&mdoc[pm.dksig_.pos + l2 / 2]);\n size_t pmso = pm.t_mso_.pos + 5; /* skip the tag */\n dpkx_ = ec_.f_.to_montgomery(\n nat_from_be(&mdoc[pmso + pm.dev_key_pkx_.pos]));\n dpky_ = ec_.f_.to_montgomery(\n nat_from_be(&mdoc[pmso + pm.dev_key_pky_.pos]));\n e2_ = ec_.f_.to_montgomery(ne2);\n dkw_.compute_witness(dpkx_, dpky_, ne2, nr2, ns2);\n return true;\n }\n};\n\n// EC: implements the elliptic curve for the mdoc\n// Field: implements the field used to define the sumcheck circuit, which can\n// be smaller than the EC field\ntemplate \nclass MdocHashWitness {\n using ECField = typename EC::Field;\n using ECElt = typename ECField::Elt;\n using ECNat = typename ECField::N;\n using Elt = typename Field::Elt;\n using vindex = std::array;\n\n const EC& ec_;\n const Field& fn_;\n\n public:\n ECElt e_; /* Issuer signature values. */\n ECElt dpkx_, dpky_; /* device key */\n uint8_t signed_bytes_[kMaxSHABlocks * 64];\n uint8_t numb_; /* Number of the correct sha block. */\n\n size_t num_attr_;\n std::vector> attr_bytes_;\n std::vector> atw_;\n\n std::vector attr_n_; /* All attributes currently require 2 SHA. */\n std::vector attr_mso_; /* The cbor indices of the attributes. */\n std::vector attr_ei_;\n std::vector attr_ev_;\n\n FlatSHA256Witness::BlockWitness bw_[kMaxSHABlocks];\n\n ParsedMdoc pm_;\n\n uint8_t now_[20]; /* CBOR-formatted time used for expiry comparison. */\n\n explicit MdocHashWitness(size_t num_attr, const EC& ec, const Field& Fn)\n : ec_(ec), fn_(Fn), num_attr_(num_attr) {}\n\n void fill_cbor_index(DenseFiller& df, const CborIndex& ind) const {\n df.push_back(ind.k, kCborIndexBits, fn_);\n }\n\n void fill_attr_shift(DenseFiller& df, const AttrShift& attr) const {\n df.push_back(attr.offset, kCborIndexBits, fn_);\n df.push_back(attr.len, kCborIndexBits, fn_);\n }\n\n void fill_sha(DenseFiller& filler,\n const FlatSHA256Witness::BlockWitness& bw) const {\n BitPluckerEncoder BPENC(fn_);\n for (size_t k = 0; k < 48; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.outw[k]));\n }\n for (size_t k = 0; k < 64; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.oute[k]));\n filler.push_back(BPENC.mkpacked_v32(bw.outa[k]));\n }\n for (size_t k = 0; k < 8; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.h1[k]));\n }\n }\n\n void fill_witness(DenseFiller& filler) const {\n // Fill sha of main mso.\n filler.push_back(numb_, 8, fn_);\n // Don't push the prefix.\n for (size_t i = kCose1PrefixLen; i < kMaxSHABlocks * 64; ++i) {\n filler.push_back(signed_bytes_[i], 8, fn_);\n }\n for (size_t j = 0; j < kMaxSHABlocks; j++) {\n fill_sha(filler, bw_[j]);\n }\n // === done with sha\n\n fill_cbor_index(filler, pm_.valid_from_);\n fill_cbor_index(filler, pm_.valid_until_);\n fill_cbor_index(filler, pm_.dev_key_info_);\n fill_cbor_index(filler, pm_.value_digests_);\n\n // Fill all attribute witnesses.\n for (size_t ai = 0; ai < num_attr_; ++ai) {\n for (size_t i = 0; i < 2 * 64; ++i) {\n filler.push_back(attr_bytes_[ai][i], 8, fn_);\n }\n for (size_t j = 0; j < 2; j++) {\n fill_sha(filler, atw_[ai][j]);\n }\n\n // In the case of attribute mso, push the value to avoid having to\n // deal with 1- or 2- byte key length.\n filler.push_back(attr_mso_[ai].v, kCborIndexBits, fn_);\n fill_attr_shift(filler, attr_ei_[ai]);\n fill_attr_shift(filler, attr_ev_[ai]);\n }\n }\n\n bool compute_witness(const uint8_t mdoc[/* len */], size_t len,\n const uint8_t transcript[/* tlen */], size_t tlen,\n const RequestedAttribute attrs[], size_t attrs_len,\n const uint8_t tnow[/*20*/], size_t version = 2) {\n if (!pm_.parse_device_response(len, mdoc)) {\n log(ERROR, \"Failed to parse device response\");\n return false;\n }\n\n std::vector buf;\n if (pm_.t_mso_.len >= kMaxSHABlocks * 64 - 9 - kCose1PrefixLen) {\n log(ERROR, \"tagged mso is too big: %zu\", pm_.t_mso_.len);\n return false;\n }\n\n buf.assign(std::begin(kCose1Prefix), std::end(kCose1Prefix));\n // Add 2-byte length\n buf.push_back((pm_.t_mso_.len >> 8) & 0xff);\n buf.push_back(pm_.t_mso_.len & 0xff);\n for (size_t i = 0; i < pm_.t_mso_.len; ++i) {\n buf.push_back(mdoc[pm_.t_mso_.pos + i]);\n }\n\n FlatSHA256Witness::transform_and_witness_message(\n buf.size(), buf.data(), kMaxSHABlocks, numb_, signed_bytes_, bw_);\n\n ECNat ne = nat_from_u32(bw_[numb_ - 1].h1);\n e_ = ec_.f_.to_montgomery(ne);\n\n memcpy(now_, tnow, 20);\n\n size_t pmso = pm_.t_mso_.pos + 5; /* +5 to skip the tag */\n dpkx_ = ec_.f_.to_montgomery(\n nat_from_be(&mdoc[pmso + pm_.dev_key_pkx_.pos]));\n dpky_ = ec_.f_.to_montgomery(\n nat_from_be(&mdoc[pmso + pm_.dev_key_pky_.pos]));\n\n // initialize variables\n attr_n_.resize(attrs_len);\n attr_mso_.resize(attrs_len);\n attr_ev_.resize(attrs_len);\n attr_ei_.resize(attrs_len);\n attr_bytes_.resize(attrs_len);\n atw_.resize(attrs_len);\n\n // Match the attributes with the witnesses from the deviceResponse.\n for (size_t i = 0; i < attrs_len; ++i) {\n attr_bytes_[i].resize(128);\n atw_[i].resize(2);\n bool found = false;\n for (auto fa : pm_.attributes_) {\n if (fa == attrs[i]) {\n FlatSHA256Witness::transform_and_witness_message(\n fa.tag_len, &fa.doc[fa.tag_ind], 2, attr_n_[i],\n &attr_bytes_[i][0], &atw_[i][0]);\n attr_mso_[i] = fa.mso;\n attr_ei_[i].offset = fa.id_ind - fa.tag_ind;\n attr_ei_[i].len = fa.id_len;\n if (version > 2) {\n attr_ei_[i].len = fa.witness_length(attrs[i]);\n }\n attr_ev_[i].offset = fa.val_ind - fa.tag_ind;\n attr_ev_[i].len = fa.val_len;\n found = true;\n break;\n }\n }\n if (!found) {\n log(ERROR, \"Could not find attribute %.*s\", attrs[i].id_len,\n attrs[i].id);\n return false;\n }\n }\n return true;\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_WITNESS_H_\n"], ["/longfellow-zk/lib/circuits/anoncred/small_witness.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_WITNESS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_WITNESS_H_\n\n#include \n#include \n\n#include \n#include \n\n#include \"algebra/static_string.h\"\n#include \"arrays/dense.h\"\n#include \"circuits/anoncred/small_io.h\"\n#include \"circuits/ecdsa/verify_witness.h\"\n#include \"circuits/logic/bit_plucker_encoder.h\"\n#include \"circuits/mdoc/mdoc_witness.h\"\n#include \"circuits/sha/flatsha256_witness.h\"\n\nnamespace proofs {\n\nclass SmallOpenedAttribute {\n public:\n size_t ind_, len_;\n std::vector value_;\n SmallOpenedAttribute(size_t ind, size_t len, const uint8_t* val, size_t vlen)\n : ind_(ind), len_(len), value_(val, val + vlen) {}\n};\n\ntemplate \nclass SmallWitness {\n using ECField = typename EC::Field;\n using ECElt = typename ECField::Elt;\n using ECNat = typename ECField::N;\n using Elt = typename Field::Elt;\n using Nat = typename Field::N;\n using EcdsaWitness = VerifyWitness3;\n static constexpr size_t kMaxSHABlocks = 7;\n\n public:\n const EC ec_;\n Elt e_, e2_; /* Issuer signature values. */\n Elt dpkx_, dpky_; /* device key */\n EcdsaWitness ew_, dkw_;\n uint8_t now_[kDateLen]; /* CBOR-formatted time used for expiry comparison. */\n\n FlatSHA256Witness::BlockWitness bw_[kMaxSHABlocks];\n uint8_t signed_bytes_[kMaxSHABlocks * 64];\n uint8_t numb_; /* Number of the correct sha block. */\n\n explicit SmallWitness(const EC& ec, const ScalarField& Fn)\n : ec_(ec), ew_(Fn, ec), dkw_(Fn, ec) {}\n\n void fill_sha(DenseFiller& filler,\n const FlatSHA256Witness::BlockWitness& bw) const {\n BitPluckerEncoder BPENC(ec_.f_);\n for (size_t k = 0; k < 48; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.outw[k]));\n }\n for (size_t k = 0; k < 64; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.oute[k]));\n filler.push_back(BPENC.mkpacked_v32(bw.outa[k]));\n }\n for (size_t k = 0; k < 8; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.h1[k]));\n }\n }\n\n void fill_witness(DenseFiller& filler, bool small = false) const {\n filler.push_back(e_);\n filler.push_back(dpkx_);\n filler.push_back(dpky_);\n\n ew_.fill_witness(filler);\n dkw_.fill_witness(filler);\n\n filler.push_back(numb_, 8, ec_.f_);\n for (size_t i = 0; i < kMaxSHABlocks * 64; ++i) {\n filler.push_back(signed_bytes_[i], 8, ec_.f_);\n }\n for (size_t j = 0; j < kMaxSHABlocks; j++) {\n fill_sha(filler, bw_[j]);\n }\n }\n\n bool compute_witness(Elt pkX, Elt pkY, const uint8_t mdoc[/* len */],\n size_t len, const uint8_t transcript[/* tlen */],\n size_t tlen, const uint8_t tnow[/*kDateLen*/],\n const StaticString& r, const StaticString& s,\n const StaticString& dr, const StaticString& ds) {\n Nat ne = nat_from_hash(mdoc, len);\n e_ = ec_.f_.to_montgomery(ne);\n\n // Parse (r,s).\n Nat nr = Nat(r);\n Nat ns = Nat(s);\n ew_.compute_witness(pkX, pkY, ne, nr, ns);\n\n Nat ne2 = nat_from_hash(transcript, tlen);\n Nat nr2 = Nat(dr);\n Nat ns2 = Nat(ds);\n\n dpkx_ = ec_.f_.to_montgomery(nat_from_be(&mdoc[100]));\n dpky_ = ec_.f_.to_montgomery(nat_from_be(&mdoc[132]));\n e2_ = ec_.f_.to_montgomery(ne2);\n dkw_.compute_witness(dpkx_, dpky_, ne2, nr2, ns2);\n\n FlatSHA256Witness::transform_and_witness_message(len, mdoc, kMaxSHABlocks,\n numb_, signed_bytes_, bw_);\n\n memcpy(now_, tnow, kDateLen);\n return true;\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_WITNESS_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_1f_witness.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_1F_WITNESS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_1F_WITNESS_H_\n\n#include \n#include \n#include \n#include \n\n#include \"arrays/dense.h\"\n#include \"circuits/cbor_parser/cbor_witness.h\"\n#include \"circuits/ecdsa/verify_witness.h\"\n#include \"circuits/logic/bit_plucker_encoder.h\"\n#include \"circuits/mdoc/mdoc_1f_io.h\"\n#include \"circuits/mdoc/mdoc_constants.h\"\n#include \"circuits/mdoc/mdoc_witness.h\"\n#include \"circuits/mdoc/mdoc_zk.h\"\n#include \"circuits/sha/flatsha256_witness.h\"\n#include \"util/log.h\"\nnamespace proofs {\n\ntemplate \nclass mdoc_1f_witness {\n using ECField = typename EC::Field;\n using ECElt = typename ECField::Elt;\n using ECNat = typename ECField::N;\n using Elt = typename Field::Elt;\n using Nat = typename Field::N;\n using EcdsaWitness = VerifyWitness3;\n using CborWitness = CborWitness;\n\n public:\n const EC ec_;\n Elt e_, e2_; /* Issuer signature values. */\n Elt dpkx_, dpky_; /* device key */\n EcdsaWitness ew_, dkw_;\n uint8_t now_[kMdoc1DateLen]; /* CBOR-formatted time for expiry comparison. */\n\n FlatSHA256Witness::BlockWitness bw_[kMdoc1MaxSHABlocks];\n uint8_t signed_bytes_[kMdoc1MaxSHABlocks * 64];\n uint8_t numb_; /* Number of the correct sha block. */\n ParsedMdoc pm_;\n\n size_t num_attr_;\n std::vector> attr_bytes_;\n std::vector> atw_;\n\n std::vector attr_n_; /* All attributes currently require 2 SHA. */\n std::vector attr_mso_; /* The cbor indices of the attributes. */\n std::vector attr_ei_;\n std::vector attr_ev_;\n\n // Cbor parsing witnesses\n std::vector incb_;\n std::vector pwcb_;\n typename CborWitness::global_witness gwcb_;\n\n explicit mdoc_1f_witness(size_t num_attr, const EC& ec, const ScalarField& Fn)\n : ec_(ec),\n ew_(Fn, ec),\n dkw_(Fn, ec),\n num_attr_(num_attr),\n attr_bytes_(num_attr_),\n atw_(num_attr_),\n attr_n_(num_attr_),\n attr_mso_(num_attr_),\n attr_ei_(num_attr_),\n attr_ev_(num_attr_),\n incb_(kMdoc1MaxMsoLen),\n pwcb_(kMdoc1MaxMsoLen) {}\n\n void fill_sha(DenseFiller& filler,\n const FlatSHA256Witness::BlockWitness& bw) const {\n BitPluckerEncoder BPENC(ec_.f_);\n for (size_t k = 0; k < 48; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.outw[k]));\n }\n for (size_t k = 0; k < 64; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.oute[k]));\n filler.push_back(BPENC.mkpacked_v32(bw.outa[k]));\n }\n for (size_t k = 0; k < 8; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.h1[k]));\n }\n }\n\n void fill_attr_shift(DenseFiller& df, const AttrShift& attr) const {\n df.push_back(attr.offset, kMdoc1CborIndexBits, ec_.f_);\n df.push_back(attr.len, kMdoc1CborIndexBits, ec_.f_);\n }\n\n // The cbor index that is computed by our witness maker is with reference\n // to the beginning of the cbor string. However the convention for the cbor\n // parser is to 0-pad from the left to fill the full cbor string buffer.\n // As a result, all cbor indices need to be offset by the padding length.\n void fill_cbor_index(DenseFiller& filler, const CborIndex& ind,\n size_t padding_offset = 0) const {\n filler.push_back(ind.k + padding_offset, kMdoc1CborIndexBits, ec_.f_);\n filler.push_back(ind.v + padding_offset, kMdoc1CborIndexBits, ec_.f_);\n filler.push_back(ind.ndx, kMdoc1CborIndexBits, ec_.f_);\n }\n\n void fill_witness(DenseFiller& filler, bool small = false) const {\n filler.push_back(e_);\n filler.push_back(dpkx_);\n filler.push_back(dpky_);\n\n ew_.fill_witness(filler);\n dkw_.fill_witness(filler);\n\n filler.push_back(numb_, 8, ec_.f_);\n for (size_t i = kCose1PrefixLen; i < kMdoc1MaxSHABlocks * 64; ++i) {\n filler.push_back(signed_bytes_[i], 8, ec_.f_);\n }\n for (size_t j = 0; j < kMdoc1MaxSHABlocks; j++) {\n fill_sha(filler, bw_[j]);\n }\n\n size_t prepad = kMdoc1MaxMsoLen - pm_.t_mso_.len + 5;\n filler.push_back(prepad, kMdoc1CborIndexBits, ec_.f_);\n filler.push_back(pm_.t_mso_.len - 5, kMdoc1CborIndexBits, ec_.f_);\n for (size_t i = 0; i < kMdoc1MaxMsoLen; ++i) {\n filler.push_back(pwcb_[i].encoded_sel_header);\n }\n filler.push_back(gwcb_.invprod_decode);\n filler.push_back(gwcb_.cc0);\n filler.push_back(gwcb_.invprod_parse);\n\n fill_cbor_index(filler, pm_.valid_, prepad);\n fill_cbor_index(filler, pm_.valid_from_, prepad);\n fill_cbor_index(filler, pm_.valid_until_, prepad);\n fill_cbor_index(filler, pm_.dev_key_info_, prepad);\n fill_cbor_index(filler, pm_.dev_key_, prepad);\n fill_cbor_index(filler, pm_.dev_key_pkx_, prepad);\n fill_cbor_index(filler, pm_.dev_key_pky_, prepad);\n fill_cbor_index(filler, pm_.value_digests_, prepad);\n fill_cbor_index(filler, pm_.org_, prepad);\n\n // Fill all attribute witnesses.\n for (size_t ai = 0; ai < num_attr_; ++ai) {\n for (size_t i = 0; i < 2 * 64; ++i) {\n filler.push_back(attr_bytes_[ai][i], 8, ec_.f_);\n }\n for (size_t j = 0; j < 2; j++) {\n fill_sha(filler, atw_[ai][j]);\n }\n\n // In the case of attribute mso, push the value to avoid having to\n // deal with 1- or 2- byte key length.\n // fill_cbor_index(filler, pm_.value_digests_);\n fill_cbor_index(filler, attr_mso_[ai], prepad);\n fill_attr_shift(filler, attr_ei_[ai]);\n fill_attr_shift(filler, attr_ev_[ai]);\n }\n }\n\n bool compute_witness(Elt pkX, Elt pkY, const uint8_t mdoc[/* len */],\n size_t len, const uint8_t transcript[/* tlen */],\n size_t tlen, const uint8_t tnow[/*kMdoc1DateLen*/],\n const RequestedAttribute attrs[], size_t attrs_len) {\n if (!pm_.parse_device_response(len, mdoc)) {\n return false;\n }\n if (pm_.t_mso_.len >= kMdoc1MaxSHABlocks * 64 - 9 - kCose1PrefixLen) {\n log(ERROR, \"tagged mso is too big: %zu\", pm_.t_mso_.len);\n return false;\n }\n\n Nat ne = nat_from_hash(pm_.tagged_mso_bytes_.data(),\n pm_.tagged_mso_bytes_.size());\n e_ = ec_.f_.to_montgomery(ne);\n\n // Parse (r,s).\n const size_t l = pm_.sig_.len;\n Nat nr = nat_from_be(&mdoc[pm_.sig_.pos]);\n Nat ns = nat_from_be(&mdoc[pm_.sig_.pos + l / 2]);\n ew_.compute_witness(pkX, pkY, ne, nr, ns);\n\n Nat ne2 = compute_transcript_hash(transcript, tlen, &pm_.doc_type_);\n const size_t l2 = pm_.dksig_.len;\n Nat nr2 = nat_from_be(&mdoc[pm_.dksig_.pos]);\n Nat ns2 = nat_from_be(&mdoc[pm_.dksig_.pos + l2 / 2]);\n size_t pmso = pm_.t_mso_.pos + 5; /* skip the tag */\n dpkx_ = ec_.f_.to_montgomery(\n nat_from_be(&mdoc[pmso + pm_.dev_key_pkx_.pos]));\n dpky_ = ec_.f_.to_montgomery(\n nat_from_be(&mdoc[pmso + pm_.dev_key_pky_.pos]));\n e2_ = ec_.f_.to_montgomery(ne2);\n dkw_.compute_witness(dpkx_, dpky_, ne2, nr2, ns2);\n\n memcpy(now_, tnow, kMdoc1DateLen);\n std::vector buf;\n\n buf.assign(std::begin(kCose1Prefix), std::end(kCose1Prefix));\n // Add 2-byte length\n buf.push_back((pm_.t_mso_.len >> 8) & 0xff);\n buf.push_back(pm_.t_mso_.len & 0xff);\n for (size_t i = 0; i < pm_.t_mso_.len; ++i) {\n buf.push_back(mdoc[pm_.t_mso_.pos + i]);\n }\n\n FlatSHA256Witness::transform_and_witness_message(\n buf.size(), buf.data(), kMdoc1MaxSHABlocks, numb_, signed_bytes_, bw_);\n\n // Cbor parsing.\n // The input is expected to be pre-padded with zeros.\n // The +5 corresponds to the D8 18 59 prefix.\n size_t prepad = kMdoc1MaxMsoLen - pm_.t_mso_.len + 5;\n // Pad with enough 0s.\n buf.erase(buf.begin(), buf.begin() + kCose1PrefixLen + 2 + 5);\n buf.insert(buf.begin(), prepad, 0);\n\n CborWitness cw(ec_.f_);\n cw.fill_witnesses(kMdoc1MaxMsoLen, pm_.t_mso_.len, buf.data(), incb_.data(),\n pwcb_.data(), gwcb_);\n\n // initialize variables\n for (size_t i = 0; i < num_attr_; ++i) {\n attr_bytes_[i].resize(128);\n atw_[i].resize(2);\n }\n\n // Match the attributes with the witnesses from the deviceResponse.\n for (size_t i = 0; i < num_attr_; ++i) {\n bool found = false;\n for (auto fa : pm_.attributes_) {\n if (fa == attrs[i]) {\n FlatSHA256Witness::transform_and_witness_message(\n fa.tag_len, &fa.doc[fa.tag_ind], 2, attr_n_[i],\n &attr_bytes_[i][0], &atw_[i][0]);\n attr_mso_[i] = fa.mso;\n attr_ei_[i].offset = fa.id_ind - fa.tag_ind;\n attr_ei_[i].len = fa.witness_length(attrs[i]);\n attr_ev_[i].offset = fa.val_ind - fa.tag_ind;\n attr_ev_[i].len = fa.val_len;\n found = true;\n break;\n }\n }\n if (!found) {\n log(ERROR, \"Could not find attribute %.*s\", attrs[i].id_len,\n attrs[i].id);\n return false;\n }\n }\n return true;\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_1F_WITNESS_H_\n"], ["/longfellow-zk/lib/circuits/ecdsa/verify_circuit.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ECDSA_VERIFY_CIRCUIT_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ECDSA_VERIFY_CIRCUIT_H_\n\n#include \n\n#include \"circuits/compiler/compiler.h\"\n#include \"circuits/logic/bit_plucker.h\"\n\nnamespace proofs {\n// Verify ECDSA signature using triple scalar mult form.\n//\n// The field used by sumcheck is the base field of the elliptic curve.\n// Compiled circuit: ecdsa verify\n// d: 7 wires: 21099 in: 1038 out:764 use:13911 ovh:7188 t:42963 cse:11351\n// notn:34724\n//\ntemplate \nclass VerifyCircuit {\n using EltW = typename LogicCircuit::EltW;\n using BitW = typename LogicCircuit::BitW;\n using Elt = typename LogicCircuit::Elt;\n using Nat = typename Field::N;\n static constexpr size_t kBits = EC::kBits;\n using Bitvec = typename LogicCircuit::v256;\n\n public:\n struct Witness {\n EltW rx, ry;\n EltW pre[8];\n EltW rx_inv, s_inv, pk_inv;\n EltW bi[kBits];\n EltW int_x[kBits - 1];\n EltW int_y[kBits - 1];\n EltW int_z[kBits - 1];\n\n void input(QuadCircuit& Q) {\n rx = Q.input();\n ry = Q.input();\n rx_inv = Q.input();\n s_inv = Q.input();\n pk_inv = Q.input();\n for (size_t i = 0; i < 8; ++i) {\n pre[i] = Q.input();\n }\n for (size_t i = 0; i < kBits; ++i) {\n bi[i] = Q.input();\n if (i < kBits - 1) {\n int_x[i] = Q.input();\n int_y[i] = Q.input();\n int_z[i] = Q.input();\n }\n }\n }\n };\n\n VerifyCircuit(const LogicCircuit& lc, const EC& ec, const Nat& order)\n : lc_(lc), ec_(ec), k2_(lc_.elt(2)), k3_(lc_.elt(3)) {\n // Compute the bit representation of the order of the curve.\n for (size_t i = 0; i < ec.kBits; ++i) {\n bits_n_[i] = lc_.bit(order.bit(i));\n }\n }\n\n // This verify takes the triple (pkx,pky,e) and checks that there exists\n // (r=rx, ry, s) such that:\n // identity = g*e + pk*r + (rx,ry)*-s\n // It performs this check using a witness table that includes\n // (g+pk, g+r, r+pk, g+r+pk), a correction element,\n // bits of exponents (e, r, -s) s.t. each triple of bits is packed into {0,7},\n // and intermediate ec points in (x,y,z) form. The bits are used to index the\n // witness table in order to compute the right-hand side in a loop. The loop\n // is sliced by providing the intermediate results in order reduce depth.\n //\n // An external constraint will need to ensure that e \\neq 0 (e.g.,\n // either the verifier checks this as part of the public input, or\n // the hash that defines e is produced in the circuit). In our mdoc case,\n // we use the later checks for both signatures.\n //\n // Other checks:\n // r is interpreted as both in the base field and the scalar field.\n // As a result, rx_inv is provided to ensure that r != 0.\n // Similarly, s_inv is provided to ensure that s != 0.\n //\n // (rx,ry) is verified to be on the curve.\n //\n // (pkx, pky) \\neq identity, because we set pk_z=1, we verify that\n // pkx != 0, and we ensure that (pkx,pky) is on the curve.\n //\n void verify_signature3(EltW pk_x, EltW pk_y, EltW e, const Witness& w) const {\n EltW zero = lc_.konst(lc_.zero());\n EltW one = lc_.konst(lc_.one());\n EltW gx = lc_.konst(ec_.gx_), gy = lc_.konst(ec_.gy_);\n\n // indices for the pre[] table, don't change order\n enum PreIndex {\n GPK_X = 0,\n GPK_Y,\n GR_X,\n GR_Y,\n RPK_X,\n RPK_Y,\n GRPK_X,\n GRPK_Y\n };\n\n // These variables hold the (e,r) exponents which are computed from the\n // bits of advice (e,r,-s). They are compared with their expected values.\n EltW est = zero, rst = zero, sst = zero;\n\n // initialize at the 0 point, but these indices are reset on each loop\n EltW ax = zero, ay = one, az = zero;\n\n // =========\n // Verify the values received in the table are correct.\n // By verifying these values in parallel with using them, we can reduce\n // the depth of the resulting circuit.\n EltW cg_pkx, cg_pky, cg_pkz;\n EltW cr_pkx, cr_pky, cr_pkz;\n EltW cr_gx, cr_gy, cr_gz;\n EltW cr_g_pkx, cr_g_pky, cr_g_pkz;\n addE(cg_pkx, cg_pky, cg_pkz, gx, gy, one, pk_x, pk_y, one);\n addE(cr_gx, cr_gy, cr_gz, w.rx, w.ry, one, gx, gy, one);\n addE(cr_pkx, cr_pky, cr_pkz, w.rx, w.ry, one, pk_x, pk_y, one);\n addE(cr_g_pkx, cr_g_pky, cr_g_pkz, gx, gy, one, w.pre[RPK_X], w.pre[RPK_Y],\n one);\n point_equality(cg_pkx, cg_pky, cg_pkz, w.pre[GPK_X], w.pre[GPK_Y]);\n point_equality(cr_gx, cr_gy, cr_gz, w.pre[GR_X], w.pre[GR_Y]);\n point_equality(cr_pkx, cr_pky, cr_pkz, w.pre[RPK_X], w.pre[RPK_Y]);\n point_equality(cr_g_pkx, cr_g_pky, cr_g_pkz, w.pre[GRPK_X], w.pre[GRPK_Y]);\n\n EltW arr_x[] = {zero, gx, pk_x, w.pre[GPK_X],\n w.rx, w.pre[GR_X], w.pre[RPK_X], w.pre[GRPK_X]};\n EltW arr_y[] = {one, gy, pk_y, w.pre[GPK_Y],\n w.ry, w.pre[GR_Y], w.pre[RPK_Y], w.pre[GRPK_Y]};\n EltW arr_z[] = {zero, one, one, one, one, one, one, one};\n EltW arr_e[] = {zero, one, zero, one, zero, one, zero, one};\n EltW arr_r[] = {zero, zero, one, one, zero, zero, one, one};\n EltW arr_s[] = {zero, zero, zero, zero, one, one, one, one};\n EltW arr_v[] = {one, one, one, one, one, one, one, one};\n\n EltMuxer xx(lc_, arr_x);\n EltMuxer yy(lc_, arr_y);\n EltMuxer zz(lc_, arr_z);\n EltMuxer ee(lc_, arr_e);\n EltMuxer rr(lc_, arr_r);\n EltMuxer ss(lc_, arr_s);\n EltMuxer vv(lc_, arr_v);\n\n Bitvec r_bits, s_bits;\n\n // Traverses the bits of the scalar from high-order to low-order.\n for (size_t i = 0; i < kBits; ++i) {\n // Use the arr{X..V} arrays and the muxer to pick the correct point\n // slice based on the bits of advice in the witness.\n EltW tx = xx.mux(w.bi[i]);\n EltW ty = yy.mux(w.bi[i]);\n EltW tz = zz.mux(w.bi[i]);\n\n // Update the exponent.\n EltW e_bi = ee.mux(w.bi[i]);\n EltW r_bi = rr.mux(w.bi[i]);\n EltW s_bi = ss.mux(w.bi[i]);\n auto k2 = lc_.konst(k2_);\n est = lc_.add(&e_bi, lc_.mul(&k2, est));\n rst = lc_.add(&r_bi, lc_.mul(&k2, rst));\n sst = lc_.add(&s_bi, lc_.mul(&k2, sst));\n r_bits[kBits - i - 1] = BitW(r_bi, ec_.f_);\n s_bits[kBits - i - 1] = BitW(s_bi, ec_.f_);\n\n // Verify that the advice bit is in [0,7].\n EltW range = vv.mux(w.bi[i]);\n lc_.assert_eq(&range, one);\n\n // Perform the basic add-dbl step in repeated squaring using the\n // muxed point {tx, ty, tz}.\n if (i > 0) {\n doubleE(ax, ay, az, ax, ay, az);\n }\n addE(ax, ay, az, ax, ay, az, tx, ty, tz);\n\n if (i < kBits - 1) {\n // Ensure that the resulting point is equal to the intermediate\n // point provided as input. Performing an explicit equality check\n // ensures that all intermediate witness points are on the curve.\n // This follows by induction. The first (ax,ay,az) is on the curve.\n // The addition formula ensures that the i-th (ax,ay,az) is on the\n // curve; equality ensures that the i-th witness is on the curve.\n lc_.assert_eq(&ax, w.int_x[i]);\n lc_.assert_eq(&ay, w.int_y[i]);\n lc_.assert_eq(&az, w.int_z[i]);\n\n // Use the intermediate (x,y,z) point as the next input.\n ax = w.int_x[i];\n ay = w.int_y[i];\n az = w.int_z[i];\n }\n }\n\n // Check that the aX,aZ points are 0.\n lc_.assert0(ax);\n lc_.assert0(az);\n\n // Check that the bits used for {e,rx} correspond to the input {e, rx}.\n lc_.assert_eq(&est, e);\n lc_.assert_eq(&rst, w.rx);\n\n // Check that (pk,py), (rx,ry) satisfy the curve equation.\n is_on_curve(pk_x, pk_y);\n is_on_curve(w.rx, w.ry);\n\n // Verify that exponents (r,s) are not zero.\n // A witness is provided to ensure that both values have inverses in F.\n // A bitwise comparison is done to ensure both are < |order| of EC.\n assert_nonzero(w.rx, w.rx_inv);\n assert_nonzero(sst, w.s_inv);\n assert_nonzero(pk_x, w.pk_inv);\n auto r_range = lc_.vlt(&r_bits, bits_n_);\n auto s_range = lc_.vlt(&s_bits, bits_n_);\n lc_.assert1(r_range);\n lc_.assert1(s_range);\n }\n\n private:\n void assert_nonzero(EltW x, EltW witness) const {\n auto maybe_one = lc_.mul(&x, witness);\n auto one = lc_.konst(lc_.one());\n lc_.assert_eq(&maybe_one, one);\n }\n\n void point_equality(EltW x, EltW y, EltW z, EltW p_x, EltW p_y) const {\n lc_.assert_eq(&x, lc_.mul(&z, p_x));\n lc_.assert_eq(&y, lc_.mul(&z, p_y));\n }\n\n void is_on_curve(EltW x, EltW y) const {\n // Check that y^2 = x^3 + ax + b\n auto yy = lc_.mul(&y, y);\n auto xx = lc_.mul(&x, x);\n auto xxx = lc_.mul(&x, xx);\n auto ax = lc_.mul(ec_.a_, x);\n auto b = lc_.konst(ec_.b_);\n auto axb = lc_.add(&ax, b);\n auto rhs = lc_.add(&axb, xxx);\n lc_.assert_eq(&yy, rhs);\n }\n\n void addE(EltW& X3, EltW& Y3, EltW& Z3, EltW X1, EltW Y1, EltW Z1, EltW X2,\n EltW Y2, EltW Z2) const {\n // The general case.\n // Algorithm 1: Complete, projective point addition for arbitrary prime\n // order short Weierstrass curves E/Fq : y^2 = x^3 + ax + b\n // The compiler seems to optimize the cases when Z1,Z2=1.\n EltW t0 = lc_.mul(&X1, X2);\n EltW t1 = lc_.mul(&Y1, Y2);\n EltW t2 = lc_.mul(&Z1, Z2);\n EltW t3 = lc_.add(&X1, Y1);\n EltW t4 = lc_.add(&X2, Y2);\n t3 = lc_.mul(&t3, t4);\n t4 = lc_.add(&t0, t1);\n t3 = lc_.sub(&t3, t4);\n t4 = lc_.add(&X1, Z1);\n EltW t5 = lc_.add(&X2, Z2);\n t4 = lc_.mul(&t4, t5);\n t5 = lc_.add(&t0, t2);\n t4 = lc_.sub(&t4, t5);\n t5 = lc_.add(&Y1, Z1);\n EltW X3t = lc_.add(&Y2, Z2);\n t5 = lc_.mul(&t5, X3t);\n X3t = lc_.add(&t1, t2);\n t5 = lc_.sub(&t5, X3t);\n auto a = lc_.konst(ec_.a_);\n EltW Z3t = lc_.mul(&a, t4);\n auto k3b = lc_.konst(ec_.k3b);\n X3t = lc_.mul(&k3b, t2);\n Z3t = lc_.add(&X3t, Z3t);\n X3t = lc_.sub(&t1, Z3t);\n Z3t = lc_.add(&t1, Z3t);\n EltW Y3t = lc_.mul(&X3t, Z3t);\n t1 = lc_.add(&t0, t0);\n t1 = lc_.add(&t1, t0);\n t2 = lc_.mul(&a, t2);\n t4 = lc_.mul(&k3b, t4);\n t1 = lc_.add(&t1, t2);\n t2 = lc_.sub(&t0, t2);\n t2 = lc_.mul(&a, t2);\n t4 = lc_.add(&t4, t2);\n t0 = lc_.mul(&t1, t4);\n Y3t = lc_.add(&Y3t, t0);\n t0 = lc_.mul(&t5, t4);\n X3t = lc_.mul(&t3, X3t);\n X3t = lc_.sub(&X3t, t0);\n t0 = lc_.mul(&t3, t1);\n Z3t = lc_.mul(&t5, Z3t);\n Z3t = lc_.add(&Z3t, t0);\n\n X3 = X3t;\n Y3 = Y3t;\n Z3 = Z3t;\n }\n\n void doubleE(EltW& X3, EltW& Y3, EltW& Z3, EltW X, EltW Y, EltW Z) const {\n // The general case.\n // Algorithm 3: Exception-free point doubling for arbitrary prime order\n // short Weierstrass curves E/Fq : y^2 = x^3 + ax + b.\n // The compiler will presumably optimize away 0 mults when a=0 and 1\n // mults when Z = 1.\n EltW t0 = lc_.mul(&X, X);\n EltW t1 = lc_.mul(&Y, Y);\n EltW t2 = lc_.mul(&Z, Z);\n EltW t3 = lc_.mul(&X, Y);\n t3 = lc_.add(&t3, t3);\n EltW Z3t = lc_.mul(&X, Z);\n Z3t = lc_.add(&Z3t, Z3t);\n auto a = lc_.konst(ec_.a_);\n auto k3b = lc_.konst(ec_.k3b);\n EltW X3t = lc_.mul(&a, Z3t);\n EltW Y3t = lc_.mul(&k3b, t2);\n Y3t = lc_.add(&X3t, Y3t);\n X3t = lc_.sub(&t1, Y3t);\n Y3t = lc_.add(&t1, Y3t);\n Y3t = lc_.mul(&X3t, Y3t);\n X3t = lc_.mul(&t3, X3t);\n Z3t = lc_.mul(&k3b, Z3t);\n t2 = lc_.mul(&a, t2);\n t3 = lc_.sub(&t0, t2);\n t3 = lc_.mul(&a, t3);\n t3 = lc_.add(&t3, Z3t);\n Z3t = lc_.add(&t0, t0);\n t0 = lc_.add(&Z3t, t0);\n t0 = lc_.add(&t0, t2);\n t0 = lc_.mul(&t0, t3);\n Y3t = lc_.add(&Y3t, t0);\n t2 = lc_.mul(&Y, Z);\n t2 = lc_.add(&t2, t2);\n t0 = lc_.mul(&t2, t3);\n X3t = lc_.sub(&X3t, t0);\n Z3t = lc_.mul(&t2, t1);\n Z3t = lc_.add(&Z3t, Z3t);\n Z3t = lc_.add(&Z3t, Z3t);\n\n X3 = X3t;\n Y3 = Y3t;\n Z3 = Z3t;\n }\n\n const LogicCircuit& lc_;\n const EC& ec_;\n\n Elt k2_, k3_;\n Bitvec bits_n_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ECDSA_VERIFY_CIRCUIT_H_\n"], ["/longfellow-zk/lib/circuits/jwt/jwt_witness.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_JWT_JWT_WITNESS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_JWT_JWT_WITNESS_H_\n\n#include \n#include \n#include \n#include \n#include \n\n#include \"arrays/dense.h\"\n#include \"circuits/base64/decode_util.h\"\n#include \"circuits/ecdsa/verify_witness.h\"\n#include \"circuits/jwt/jwt_constants.h\"\n#include \"circuits/logic/bit_plucker_encoder.h\"\n#include \"circuits/sha/flatsha256_witness.h\"\n#include \"util/log.h\"\n\nnamespace proofs {\n\n/* This struct allows a verifier to express which attribute and value the prover\n * must claim. */\nstruct OpenedAttribute {\n uint8_t id[32];\n uint8_t value[64];\n size_t id_len, value_len;\n};\n\ntemplate \nclass JWTWitness {\n using Field = typename EC::Field;\n using Elt = typename Field::Elt;\n using Nat = typename Field::N;\n using EcdsaWitness = VerifyWitness3;\n const EC& ec_;\n\n public:\n Elt e_, r_, s_;\n EcdsaWitness sig_;\n\n uint8_t preimage_[64 * kMaxJWTSHABlocks];\n uint8_t e_bits_[256];\n FlatSHA256Witness::BlockWitness sha_bw_[kMaxJWTSHABlocks];\n uint8_t numb_; /* Number of the correct sha block. */\n uint8_t na_; /* Number of attributes. */\n size_t payload_ind_, payload_len_;\n std::vector attr_ind_;\n std::vector attr_id_len_;\n std::vector attr_value_len_;\n\n explicit JWTWitness(const EC& ec, const ScalarField& Fn)\n : ec_(ec), sig_(Fn, ec) {}\n\n void fill_witness(DenseFiller& filler) const {\n filler.push_back(r_);\n filler.push_back(s_);\n filler.push_back(e_);\n sig_.fill_witness(filler);\n\n // Write the message.\n for (size_t i = 0; i < 64 * kMaxJWTSHABlocks; ++i) {\n filler.push_back(preimage_[i], 8, ec_.f_);\n }\n\n for (size_t i = 0; i < 256; ++i) {\n filler.push_back(e_bits_[i], 1, ec_.f_);\n }\n\n for (size_t j = 0; j < kMaxJWTSHABlocks; ++j) {\n fill_sha(filler, sha_bw_[j]);\n }\n\n filler.push_back(numb_, 8, ec_.f_);\n\n for (size_t i = 0; i < na_; ++i) {\n filler.push_back(attr_ind_[i], kJWTIndexBits, ec_.f_);\n filler.push_back(attr_id_len_[i], 8, ec_.f_);\n filler.push_back(attr_value_len_[i], 8, ec_.f_);\n }\n\n filler.push_back(payload_ind_, kJWTIndexBits, ec_.f_);\n filler.push_back(payload_len_, kJWTIndexBits, ec_.f_);\n }\n\n void fill_sha(DenseFiller& filler,\n const FlatSHA256Witness::BlockWitness& bw) const {\n BitPluckerEncoder BPENC(ec_.f_);\n for (size_t k = 0; k < 48; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.outw[k]));\n }\n for (size_t k = 0; k < 64; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.oute[k]));\n filler.push_back(BPENC.mkpacked_v32(bw.outa[k]));\n }\n for (size_t k = 0; k < 8; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.h1[k]));\n }\n }\n\n // Transform from u32 be (i.e., be[0] is the most significant nibble)\n // into nat form, which requires first converting to le byte order.\n Nat nat_from_u32(const uint32_t be[]) const {\n uint8_t tmp[Nat::kBytes];\n const size_t top = Nat::kBytes / 4;\n for (size_t i = 0; i < Nat::kBytes; ++i) {\n tmp[i] = (be[top - i / 4 - 1] >> ((i % 4) * 8)) & 0xff;\n }\n return Nat::of_bytes(tmp);\n }\n\n // Transform from u8 be (i.e., be[31] is the most significant byte) into\n // nat form, which requires first converting to le byte order.\n Nat nat_from_be(const uint8_t be[/* Nat::kBytes */]) {\n uint8_t tmp[Nat::kBytes];\n // Transform into byte-wise le representation.\n for (size_t i = 0; i < Nat::kBytes; ++i) {\n tmp[i] = be[Nat::kBytes - i - 1];\n }\n return Nat::of_bytes(tmp);\n }\n\n bool compute_witness(std::string jwt, Elt pkX, Elt pkY,\n std::vector attrs) {\n size_t dot = jwt.find_first_of('.');\n size_t dot2 = jwt.find_first_of('.', dot + 1);\n if (dot == std::string::npos || dot2 == std::string::npos) {\n log(ERROR, \"JWT is not in the format of header.payload.signature\");\n return false;\n }\n auto hdr = jwt.substr(0, dot);\n auto pld = jwt.substr(dot + 1, dot2 - dot - 1);\n auto rest = jwt.substr(dot2 + 1);\n auto msg = jwt.substr(0, dot2);\n payload_len_ = pld.size();\n payload_ind_ = dot + 1;\n\n if (payload_len_ > kMaxJWTSHABlocks * 64) {\n log(ERROR, \"JWT payload is too large\");\n return false;\n }\n\n size_t tilde = rest.find_first_of('~');\n if (tilde == std::string::npos) {\n log(ERROR, \"JWT is not in the format of header.payload.signature~epoch\");\n return false;\n }\n auto sig = rest.substr(0, tilde);\n auto claims = rest.substr(tilde + 1);\n\n FlatSHA256Witness::transform_and_witness_message(\n msg.size(), reinterpret_cast(msg.data()),\n kMaxJWTSHABlocks, numb_, preimage_, sha_bw_);\n\n Nat ne = nat_from_u32(sha_bw_[numb_ - 1].h1);\n e_ = ec_.f_.to_montgomery(ne);\n\n std::vector sigb;\n sigb.reserve(ec_.f_.kBytes * 2);\n if (!base64_decode_url(sig, sigb) || sigb.size() < ec_.f_.kBytes * 2) {\n log(ERROR, \"signature is not in the format of base64url\");\n return false;\n }\n Nat nr = nat_from_be(&sigb[0]);\n Nat ns = nat_from_be(&sigb[ec_.f_.kBytes]);\n\n r_ = ec_.f_.to_montgomery(nr);\n s_ = ec_.f_.to_montgomery(ns);\n if (!sig_.compute_witness(pkX, pkY, ne, nr, ns)) {\n log(ERROR, \"signature verification failed\");\n return false;\n }\n\n for (size_t i = 0; i < 256; ++i) {\n e_bits_[i] = ne.bit(i);\n }\n\n // Find the positions of each of the attributes.\n na_ = attrs.size();\n std::vector payload;\n payload.reserve(pld.size());\n if (!base64_decode_url(pld, payload)) {\n log(ERROR, \"JWT payload is not in the format of base64url\");\n return false;\n }\n std::string str((const char*)payload.data(), payload.size());\n for (size_t i = 0; i < na_; ++i) {\n size_t ind = str.find((const char*)attrs[i].id, 0, attrs[i].id_len);\n if (ind == std::string::npos) {\n log(ERROR, \"Could not find attribute %.*s\", attrs[i].id_len,\n attrs[i].id);\n return false;\n }\n size_t vstart = ind + attrs[i].id_len + 3;\n size_t vind =\n str.find((const char*)attrs[i].value, vstart, attrs[i].value_len);\n if (vind == std::string::npos || vind != vstart) {\n log(ERROR, \"Could not find attribute value %.*s\", attrs[i].value_len,\n attrs[i].value);\n return false;\n }\n attr_ind_.push_back(ind);\n attr_id_len_.push_back(attrs[i].id_len);\n attr_value_len_.push_back(attrs[i].value_len);\n }\n\n return true;\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_JWT_JWT_WITNESS_H_\n"], ["/longfellow-zk/lib/circuits/mac/mac_circuit.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MAC_MAC_CIRCUIT_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MAC_MAC_CIRCUIT_H_\n\n// Implements a message authentication code in GF 2^k for a 256-bit message.\n// The mac key is additively sampled by both the prover and verifier to ensure\n// soundness and zk.\n//\n// The mac is defined as (a_pi+a_v)*x_i = mac_i where (x_1,x_2) are 128-bit\n// portions of the hidden message. The verifier need only contribute one\n// a_v for all MACs verified in the circuit. The prover needs to commit to\n// separate a_p{i} for each portion of each message.\n//\n// The property that we need from this primitive is as follows:\n// Assume the prover has committed to a_pi and x, i.e., fix a_pi, x.\n// The probability over the verifier's random a_v that mac(x) = mac_(y)\n// if x != y is at most 2^{-128}.\n\n#include \n#include \n\n#include \"circuits/compiler/compiler.h\"\n#include \"circuits/logic/logic.h\"\n#include \"gf2k/gf2_128.h\"\n\nnamespace proofs {\n\nstatic constexpr size_t kMACPluckerBits = 2u;\n\n// MAC: implements a MAC in GF 2^k for a 256-bit message by simulating\n// the arithmetic of the GF 2^k field. This implementation commits both\n// the prover's a_p key as well as the bits of the message. This allows\n// the MAC computation and the equality of the purported message to be verified\n// in parallel to reduce depth.\ntemplate \nclass MAC {\n public:\n using Field = typename Logic::Field;\n using Elt = typename Field::Elt;\n using EltW = typename Logic::EltW;\n using Nat = typename Field::N;\n using v8 = typename Logic::v8;\n using v128 = typename Logic::v128;\n using v256 = typename Logic::v256;\n using packed_v128 = typename BitPlucker::packed_v128;\n using packed_v256 = typename BitPlucker::packed_v256;\n\n BitPlucker bp_;\n\n class Witness {\n public:\n packed_v128 aa_[2];\n packed_v256 xx_; // The value to be checked\n\n template \n static T packed_input(QuadCircuit& Q) {\n T r;\n for (size_t i = 0; i < r.size(); ++i) {\n r[i] = Q.input();\n }\n return r;\n }\n\n void input(const Logic& LC, QuadCircuit& Q) {\n aa_[0] = packed_input(Q);\n aa_[1] = packed_input(Q);\n xx_ = packed_input(Q);\n }\n };\n\n explicit MAC(const Logic& lc) : bp_(lc), lc_(lc) {}\n\n // Verifies a mac on the Field element value against the key (a_p + a_v).\n // This method can only be called when the field is at least 256 bits, e.g.,\n // with F_p256. In other cases, the caller should use a verify_mac method\n // that takes the message in bit-wise form. Additionally, the order parameter\n // is used to ensure that the message does not overflow the field.\n void verify_mac(EltW msg, const v128 mac[/*2*/], const v128& av,\n const Witness& vw, Nat order) const {\n check(Field::kBits >= 256, \"Field::kBits < 256\");\n v128 msg2[2];\n unpack_msg(msg2, msg, order, vw);\n assert_mac(mac, av, msg2, vw);\n }\n\n private:\n // Checks mac[i] = (a_p + a_v)*xi[i] for i=0..1.\n void assert_mac(const v128 mac[/*2*/], const v128& av, const v128 xi[/*2*/],\n const Witness& vw) const {\n v128 mv;\n for (size_t i = 0; i < 2; ++i) {\n v128 ap = bp_.template unpack(vw.aa_[i]);\n v128 key = lc_.vxor(&av, ap);\n lc_.gf2_128_mul(mv, key, xi[i]);\n lc_.vassert_eq(&mac[i], mv);\n }\n }\n\n void unpack_msg(v128 msg[/*2*/], EltW msgw, Nat order,\n const Witness& vw) const {\n v256 x = bp_.template unpack(vw.xx_);\n std::copy(x.begin(), x.begin() + 128, msg[0].begin());\n std::copy(x.begin() + 128, x.end(), msg[1].begin());\n\n // Ensure that the incoming message does not overflow the field.\n v256 bits_n;\n for (size_t i = 0; i < 256; ++i) {\n bits_n[i] = lc_.bit(order.bit(i));\n }\n lc_.assert1(lc_.vlt(&x, bits_n));\n\n // Verify that the message bits in the witness correspond to msg.\n EltW te = lc_.konst(lc_.zero());\n Elt twok = lc_.one();\n for (size_t i = 0; i < 256; ++i) {\n te = lc_.axpy(&te, twok, lc_.eval(x[i]));\n lc_.f_.add(twok, twok);\n }\n lc_.assert_eq(&te, msgw);\n }\n\n const Logic& lc_;\n};\n\n// Same MAC computation for native GF2_128 field.\ntemplate \nclass MACGF2 {\n public:\n using Elt = typename Logic, Backend>::Elt;\n using EltW = typename Logic, Backend>::EltW;\n using BitW = typename Logic, Backend>::BitW;\n\n // In this specialization, 128 bits are stored in a native EltW.\n using v128 = EltW;\n\n // Message input types v8, v256 are still encoded bit-wise.\n using v8 = typename Logic, Backend>::v8;\n using v256 = typename Logic, Backend>::v256;\n\n explicit MACGF2(const Logic, Backend>& lc)\n : lc_(lc) {}\n class Witness {\n public:\n EltW aa_[2];\n\n void input(const Logic, Backend>& lc,\n QuadCircuit>& Q) {\n aa_[0] = Q.input();\n aa_[1] = Q.input();\n }\n };\n\n // Verify a mac on the 256-bit message msg.\n void verify_mac(const EltW mac[/*2*/], const EltW& av, const v256& msg,\n const Witness& vw) const {\n // Check that mac[i] = (a_p + a_v)*mm[i] for i=0..1.\n for (size_t i = 0; i < 2; ++i) {\n EltW mm = pack(&msg[i * 128]);\n EltW key = lc_.add(&av, vw.aa_[i]);\n EltW got = lc_.mul(&key, mm);\n lc_.assert_eq(&mac[i], got);\n }\n }\n\n private:\n // Pack a 128-bit message into a GF(2^128) field element.\n EltW pack(const BitW msg[/*128*/]) const {\n Elt alpha = lc_.f_.x();\n Elt xi = lc_.f_.one();\n EltW m = lc_.konst(0);\n for (size_t i = 0; i < 128; ++i) {\n m = lc_.axpy(&m, xi, lc_.eval(msg[i]));\n xi = lc_.mulf(xi, alpha);\n }\n return m;\n }\n\n const Logic, Backend>& lc_;\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MAC_MAC_CIRCUIT_H_\n"], ["/longfellow-zk/lib/circuits/sha/flatsha256_circuit.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_FLATSHA256_CIRCUIT_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_FLATSHA256_CIRCUIT_H_\n\n#include \n\n#include \n#include \n\n#include \"circuits/compiler/compiler.h\"\n#include \"circuits/logic/bit_adder.h\"\n#include \"circuits/sha/sha256_constants.h\"\n\nnamespace proofs {\n// FlatSHA256Circuit\n//\n// Implements SHA256 hash function as an arithmetic circuit over the field F.\n// The circuit is flattened, meaning that the SHA round function has been\n// repeated in parallel instead of sequentially. As a result, the prover must\n// provide the intermediate round values as witnesses.\n//\n// This package does not have any external dependencies on a SHA256 library.\n//\n// There are two versions of this function, one with standard bit inputs, and\n// another with packed bit inputs. The later reduces the number of inputs at\n// the cost of increasing the depth and number of wires. For example, the\n// following shows the difference with pack parameter 2.\n//\n// FlatSHA256_Circuit.assert_transform_block\n// depth: 7 wires: 38029 in: 6657 out:128 use:30897 ovh:7132 t:166468 cse:9703\n// notn:113744\n//\n// FlatSHA256_Circuit.assert_transform_block_packed\n// depth: 9 wires: 65735 in: 3585 out:128 use:55486 ovh:10249 t:214653\n// cse:28135 notn:151504\n//\n//\ntemplate \nclass FlatSHA256Circuit {\n public:\n using v8 = typename Logic::v8;\n using v256 = typename Logic::v256;\n using v32 = typename Logic::v32;\n using EltW = typename Logic::EltW;\n using Field = typename Logic::Field;\n using packed_v32 = typename BitPlucker::packed_v32;\n\n const Logic& l_;\n BitPlucker bp_; /* public, so caller can encode input */\n\n struct BlockWitness {\n packed_v32 outw[48];\n packed_v32 oute[64];\n packed_v32 outa[64];\n packed_v32 h1[8];\n\n static packed_v32 packed_input(QuadCircuit& Q) {\n packed_v32 r;\n for (size_t i = 0; i < r.size(); ++i) {\n r[i] = Q.input();\n }\n return r;\n }\n\n void input(QuadCircuit& Q) {\n for (size_t k = 0; k < 48; ++k) {\n outw[k] = packed_input(Q);\n }\n for (size_t k = 0; k < 64; ++k) {\n oute[k] = packed_input(Q);\n outa[k] = packed_input(Q);\n }\n for (size_t k = 0; k < 8; ++k) {\n h1[k] = packed_input(Q);\n }\n }\n };\n\n explicit FlatSHA256Circuit(const Logic& l) : l_(l), bp_(l_) {}\n\n static packed_v32 packed_input(QuadCircuit& Q) {\n packed_v32 r;\n for (size_t i = 0; i < r.size(); ++i) {\n r[i] = Q.input();\n }\n return r;\n }\n\n void assert_transform_block(const v32 in[16], const v32 H0[8],\n const v32 outw[48], const v32 oute[64],\n const v32 outa[64], const v32 H1[8]) const {\n const Logic& L = l_; // shorthand\n BitAdder BA(L);\n\n std::vector w(64);\n for (size_t i = 0; i < 16; ++i) {\n w[i] = in[i];\n }\n\n for (size_t i = 16; i < 64; ++i) {\n auto sw2 = sigma1(w[i - 2]);\n auto sw15 = sigma0(w[i - 15]);\n std::vector terms = {sw2, w[i - 7], sw15, w[i - 16]};\n w[i] = outw[i - 16];\n BA.assert_eqmod(w[i], BA.add(terms), 4);\n }\n\n v32 a = H0[0];\n v32 b = H0[1];\n v32 c = H0[2];\n v32 d = H0[3];\n v32 e = H0[4];\n v32 f = H0[5];\n v32 g = H0[6];\n v32 h = H0[7];\n\n for (size_t t = 0; t < 64; ++t) {\n auto s1e = Sigma1(e);\n auto ch = L.vCh(&e, &f, g);\n auto rt = L.vbit32(kSha256Round[t]);\n std::vector t1_terms = {h, s1e, ch, rt, w[t]};\n EltW t1 = BA.add(t1_terms);\n EltW sigma0 = BA.as_field_element(Sigma0(a));\n EltW vmaj = BA.as_field_element(L.vMaj(&a, &b, c));\n EltW t2 = BA.add(&sigma0, vmaj);\n\n h = g;\n g = f;\n f = e;\n e = oute[t];\n EltW ed = BA.as_field_element(d);\n BA.assert_eqmod(e, BA.add(&t1, ed), 6);\n d = c;\n c = b;\n b = a;\n a = outa[t];\n BA.assert_eqmod(a, BA.add(&t1, t2), 7);\n }\n\n BA.assert_eqmod(H1[0], BA.add(H0[0], a), 2);\n BA.assert_eqmod(H1[1], BA.add(H0[1], b), 2);\n BA.assert_eqmod(H1[2], BA.add(H0[2], c), 2);\n BA.assert_eqmod(H1[3], BA.add(H0[3], d), 2);\n BA.assert_eqmod(H1[4], BA.add(H0[4], e), 2);\n BA.assert_eqmod(H1[5], BA.add(H0[5], f), 2);\n BA.assert_eqmod(H1[6], BA.add(H0[6], g), 2);\n BA.assert_eqmod(H1[7], BA.add(H0[7], h), 2);\n }\n\n // Packed API.\n // H0 not packed, all others packed\n void assert_transform_block(const v32 in[16], const v32 H0[8],\n const packed_v32 poutw[48],\n const packed_v32 poute[64],\n const packed_v32 pouta[64],\n const packed_v32 pH1[8]) const {\n std::vector H1(8);\n std::vector outw(48);\n std::vector oute(64), outa(64);\n for (size_t i = 0; i < 8; ++i) {\n H1[i] = bp_.unpack_v32(pH1[i]);\n }\n for (size_t i = 0; i < 48; ++i) {\n outw[i] = bp_.unpack_v32(poutw[i]);\n }\n for (size_t i = 0; i < 64; ++i) {\n oute[i] = bp_.unpack_v32(poute[i]);\n outa[i] = bp_.unpack_v32(pouta[i]);\n }\n assert_transform_block(in, H0, outw.data(), oute.data(), outa.data(),\n H1.data());\n }\n\n // all packed\n void assert_transform_block(const v32 in[16], const packed_v32 pH0[8],\n const packed_v32 poutw[48],\n const packed_v32 poute[64],\n const packed_v32 pouta[64],\n const packed_v32 pH1[8]) const {\n std::vector H0(8);\n for (size_t i = 0; i < 8; ++i) {\n H0[i] = bp_.unpack_v32(pH0[i]);\n }\n assert_transform_block(in, H0.data(), poutw, poute, pouta, pH1);\n }\n\n /* This method checks that the block witness corresponds to the iterated\n computation of the sha block transform on the input.\n */\n void assert_message(size_t max, const v8& nb, const v8 in[/* 64*max */],\n const BlockWitness bw[/*max*/]) const {\n const Logic& L = l_; // shorthand\n const packed_v32* H = nullptr;\n std::vector tmp(16);\n\n for (size_t b = 0; b < max; ++b) {\n const v8* inb = &in[64 * b];\n for (size_t i = 0; i < 16; ++i) {\n // big-endian mapping of v8[4] into v32. The first\n // argument of vappend() is the LSB, and thus +3 is\n // the LSB and +0 is the MSB, hence big-endian.\n tmp[i] = L.vappend(L.vappend(inb[4 * i + 3], inb[4 * i + 2]),\n L.vappend(inb[4 * i + 1], inb[4 * i + 0]));\n }\n if (b == 0) {\n v32 H0[8];\n initial_context(H0);\n assert_transform_block(tmp.data(), H0, bw[b].outw, bw[b].oute,\n bw[b].outa, bw[b].h1);\n } else {\n assert_transform_block(tmp.data(), H, bw[b].outw, bw[b].oute,\n bw[b].outa, bw[b].h1);\n }\n H = bw[b].h1;\n }\n }\n\n /* This method checks that the block witness corresponds to the iterated\n computation of the sha block transform on the prefix || input.\n */\n void assert_message_with_prefix(size_t max, const v8& nb,\n const v8 in[/* < 64*max */],\n const uint8_t prefix[/* len */], size_t len,\n const BlockWitness bw[/*max*/]) const {\n const Logic& L = l_; // shorthand\n std::vector tmp(16);\n\n std::vector bbuf(64 * max);\n for (size_t i = 0; i < len; ++i) {\n L.bits(8, bbuf[i].data(), prefix[i]);\n }\n for (size_t i = 0; i + len < 64 * max; ++i) {\n bbuf[i + len] = in[i];\n }\n\n assert_message(max, nb, bbuf.data(), bw);\n }\n\n /* This method checks if H(in) == target. The method requires that in[]\n contains exactly nb*64 bytes and has been padded according to the SHA256\n specification.\n */\n void assert_message_hash(size_t max, const v8& nb, const v8 in[/* 64*max */],\n const v256& target,\n const BlockWitness bw[/*max*/]) const {\n assert_message(max, nb, in, bw);\n assert_hash(max, target, nb, bw);\n }\n\n // This method checks if H(prefix || in) == target.\n // Since the prefix is hardcoded, the compiler can propagate constants\n // and produce smaller circuits. As above, the method requires that in[]\n // contains exactly nb*64 bytes and has been padded according to the SHA256\n // specification. To use this method, compute the block_witness for the\n // entire message as usual.\n void assert_message_hash_with_prefix(size_t max, const v8& nb,\n const v8 in[/* 64*max */],\n const uint8_t prefix[/* len */],\n size_t len, const v256& target,\n const BlockWitness bw[/*max*/]) const {\n assert_message_with_prefix(max, nb, in, prefix, len, bw);\n assert_hash(max, target, nb, bw);\n }\n\n // Verifies that the nb_th element of the block witness is equal to e.\n // The block witness keeps track of the intermediate output of each\n // block transform. Therefore, this method can be used to verify that the\n // prover knows a preimage that hashes to the desired e.\n void assert_hash(size_t max, const v256& e, const v8& nb,\n const BlockWitness bw[/*max*/]) const {\n packed_v32 x[8];\n for (size_t b = 0; b < max; ++b) {\n auto bt = l_.veq(nb, b + 1); /* b is zero-indexed */\n auto ebt = l_.eval(bt);\n for (size_t i = 0; i < 8; ++i) {\n for (size_t k = 0; k < bp_.kNv32Elts; ++k) {\n if (b == 0) {\n x[i][k] = l_.mul(&ebt, bw[b].h1[i][k]);\n } else {\n auto maybe_sha = l_.mul(&ebt, bw[b].h1[i][k]);\n x[i][k] = l_.add(&x[i][k], maybe_sha);\n }\n }\n }\n }\n\n // Unpack the hash into a v256 in reverse byte-order.\n v256 mm;\n for (size_t j = 0; j < 8; ++j) {\n auto hj = bp_.unpack_v32(x[j]);\n for (size_t k = 0; k < 32; ++k) {\n mm[((7 - j) * 32 + k)] = hj[k];\n }\n }\n l_.vassert_eq(&mm, e);\n }\n\n private:\n void initial_context(v32 H[8]) const {\n static const uint64_t initial[8] = {0x6a09e667u, 0xbb67ae85u, 0x3c6ef372u,\n 0xa54ff53au, 0x510e527fu, 0x9b05688cu,\n 0x1f83d9abu, 0x5be0cd19u};\n for (size_t i = 0; i < 8; i++) {\n H[i] = l_.template vbit<32>(initial[i]);\n }\n }\n\n v32 Sigma0(const v32& x) const {\n auto x2 = l_.vrotr(x, 2);\n auto x13 = l_.vrotr(x, 13);\n return l_.vxor3(&x2, &x13, l_.vrotr(x, 22));\n }\n\n v32 Sigma1(const v32& x) const {\n auto x6 = l_.vrotr(x, 6);\n auto x11 = l_.vrotr(x, 11);\n return l_.vxor3(&x6, &x11, l_.vrotr(x, 25));\n }\n\n v32 sigma0(const v32& x) const {\n auto x7 = l_.vrotr(x, 7);\n auto x18 = l_.vrotr(x, 18);\n return l_.vxor3(&x7, &x18, l_.vshr(x, 3));\n }\n\n v32 sigma1(const v32& x) const {\n auto x17 = l_.vrotr(x, 17);\n auto x19 = l_.vrotr(x, 19);\n return l_.vxor3(&x17, &x19, l_.vshr(x, 10));\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_FLATSHA256_CIRCUIT_H_\n"], ["/longfellow-zk/lib/circuits/cbor_parser/cbor.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_H_\n\n#include \n#include \n\n#include \n#include \n\n#include \"circuits/cbor_parser/cbor_constants.h\"\n#include \"circuits/cbor_parser/cbor_pluck.h\"\n#include \"circuits/cbor_parser/scan.h\"\n#include \"circuits/logic/bit_adder.h\"\n#include \"circuits/logic/memcmp.h\"\n#include \"circuits/logic/routing.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\ntemplate \nclass Cbor {\n public:\n using Field = typename Logic::Field;\n using EltW = typename Logic::EltW;\n using BitW = typename Logic::BitW;\n using v8 = typename Logic::v8;\n static constexpr size_t kIndexBits = IndexBits;\n static constexpr size_t kNCounters = CborConstants::kNCounters;\n using bv_counters = typename Logic::template bitvec;\n\n // a bitvector that contains an index into the input\n // (byte) array.\n using vindex = typename Logic::template bitvec;\n\n // does not yet work in binary fields\n static_assert(!Field::kCharacteristicTwo);\n\n explicit Cbor(const Logic& l)\n : l_(l), ba_count_(l), ba_byte_(l), ba_index_(l), bp_(l) {}\n\n struct global_witness {\n EltW invprod_decode; // inverse of a certain product, see assert_decode()\n EltW cc0; // initial value of counter[0]\n EltW invprod_parse; // inverse of a certain product, see assert_parse()\n };\n\n struct position_witness {\n EltW encoded_sel_header;\n };\n\n //------------------------------------------------------------\n // Decoder (lexer)\n //------------------------------------------------------------\n struct decode {\n BitW arrayp;\n BitW mapp;\n BitW itemsp;\n BitW stringp;\n BitW tagp;\n BitW specialp;\n BitW simple_specialp; // One of false, true, null, or undefined.\n BitW count0_23;\n BitW count24;\n BitW invalid;\n BitW length_plus_next_v8;\n BitW count_is_next_v8;\n BitW header;\n EltW length; // of this item\n EltW as_field_element;\n EltW count_as_field_element;\n v8 as_bits;\n };\n\n // extract whatever we can from one v8\n struct decode decode_one_v8(const v8& v) const {\n const Logic& L = l_; // shorthand\n struct decode s;\n L.vassert_is_bit(v);\n\n // v = type:3 count:5\n auto count = L.template slice<0, 5>(v);\n auto type = L.template slice<5, 8>(v);\n\n s.itemsp = L.veqmask(type, /*mask*/ 0b110, /*val*/ 0b100);\n s.stringp = L.veqmask(type, /*mask*/ 0b110, /*val*/ 0b010);\n\n s.specialp = L.veq(type, 7);\n s.tagp = L.veq(type, 6);\n s.arrayp = L.land(&s.itemsp, L.lnot(type[0]));\n s.mapp = L.land(&s.itemsp, type[0]);\n\n // count0_23 = (0 <= count < 24) = ~(count == 11xxx)\n s.count0_23 = L.lnot(L.veqmask(count, /*mask*/ 0b11000, /*val*/ 0b11000));\n\n s.count24 = L.veq(count, 24);\n\n BitW count20_23 = L.veqmask(count, /*mask*/ 0b11100, /*val*/ 0b10100);\n s.simple_specialp = L.land(&s.specialp, count20_23);\n\n // stringp && count24\n s.length_plus_next_v8 =\n L.veqmask(v, /*mask*/ 0b110'11111, /*val*/ 0b010'11000);\n\n // itemsp && count24\n s.count_is_next_v8 =\n L.veqmask(v, /*mask*/ 0b110'11111, /*val*/ 0b100'11000);\n\n // invalid = (specialp && !simple_specialp) || (!count24 && !count0_23)\n auto lhs = L.land(&s.specialp, L.lnot(s.simple_specialp));\n auto bad_count = L.lor_exclusive(&s.count24, s.count0_23);\n s.invalid = L.lor(&lhs, L.lnot(bad_count));\n\n s.count_as_field_element = ba_count_.as_field_element(count);\n\n // Length is the length of the item, including the header.\n //\n // 1 for header\n // +1 if (count24)\n // +count if (stringp && count0_23);\n s.length = L.konst(1);\n s.length = L.add(&s.length, L.eval(s.count24));\n auto str_23 = L.land(&s.stringp, s.count0_23);\n auto e_str_23 = L.eval(str_23);\n auto adjust_if_string = L.mul(&e_str_23, s.count_as_field_element);\n s.length = L.add(&s.length, adjust_if_string);\n\n s.as_field_element = ba_byte_.as_field_element(v);\n s.as_bits = v;\n\n s.header = L.bit(0); // for now\n return s;\n }\n\n void assert_decode(size_t n, const decode ds[/*n*/],\n const position_witness pw[/*n*/],\n const global_witness& gw) const {\n const Logic& L = l_; // shorthand\n Scan SC(l_);\n\n // -------------------------------------------------------------\n // Decoder didn't fail\n for (size_t i = 0; i < n; ++i) {\n L.assert_implies(&ds[i].header, L.lnot(ds[i].invalid));\n }\n // if LENGTH_PLUS_NEXT_V8 is TRUE in the last position,\n // then the input is invalid.\n L.assert_implies(&ds[n - 1].header, L.lnot(ds[n - 1].length_plus_next_v8));\n\n // if COUNT_IS_NEXT_V8 is TRUE in the last position,\n // then the input is invalid.\n L.assert_implies(&ds[n - 1].header, L.lnot(ds[n - 1].count_is_next_v8));\n\n // -------------------------------------------------------------\n // Headers are where they are supposed to be.\n // First, compute the segmented scan\n // slen[i] = header[i] ? length[i] : (slen[i-1] + mone[i])\n std::vector mone(n);\n std::vector header(n);\n std::vector length(n);\n std::vector slen_next(n);\n\n for (size_t i = 0; i + 1 < n; ++i) {\n mone[i] = L.konst(L.mone());\n header[i] = ds[i].header;\n length[i] = ds[i].length;\n if (i + 1 < n) {\n auto len_i =\n L.lmul(&ds[i].length_plus_next_v8, ds[i + 1].as_field_element);\n length[i] = L.add(&length[i], len_i);\n }\n }\n\n SC.add(n, slen_next.data(), header.data(), length.data(), mone.data());\n\n // Now check the headers.\n {\n // \"The first position is a header\"\n L.assert1(header[0]);\n }\n\n {\n auto one = L.konst(1);\n // \"\\A I : (SLEN_NEXT[I] == 1) IFF HEADER[I+1]\"\n {\n // \"\\A I : HEADER[I+1] => (SLEN_NEXT[I] == 1)\"\n for (size_t i = 0; i + 1 < n; ++i) {\n auto implies = L.lmul(&header[i + 1], L.sub(&slen_next[i], one));\n L.assert0(implies);\n }\n }\n {\n // \"\\A I : (SLEN_NEXT[I] == 1) => HEADER[i+1] \"\n // Verify via the invertibility of\n //\n // PROD_{I, L} HEADER[I+1] ? 1 : (SLEN_NEXT[I] - 1)\n //\n auto f = [&](size_t i) {\n return L.mux(&header[i + 1], &one, L.sub(&slen_next[i], one));\n };\n EltW prod = L.mul(0, n - 1, f);\n auto want_one = L.mul(&prod, gw.invprod_decode);\n L.assert_eq(&want_one, one);\n }\n }\n }\n\n //------------------------------------------------------------\n // Parser\n //------------------------------------------------------------\n using counters = std::array;\n struct parse_output {\n bv_counters sel;\n counters c;\n };\n\n void parse(size_t n, parse_output ps[/*n*/], const decode ds[/*n*/],\n const position_witness pw[/*n*/], const global_witness& gw) const {\n std::vector ddss(n);\n std::vector SS(n);\n std::vector AA(n);\n std::vector BB(n);\n\n const Logic& L = l_; // shorthand\n Scan SC(l_);\n\n for (size_t i = 0; i < n; ++i) {\n ps[i].sel = bp_.pluckj(pw[i].encoded_sel_header);\n }\n\n auto mone = L.konst(L.mone());\n for (size_t l = 0; l < kNCounters; ++l) {\n for (size_t i = 0; i < n; ++i) {\n // at the selected headers, decrement the level-L counter.\n auto dp = L.land(&ds[i].header, ps[i].sel[l]);\n ddss[i] = L.lmul(&dp, mone);\n }\n\n if (l == 0) {\n // do level-0 as an unsegmented parallel prefix\n // on DDSS starting at CC0.\n // One can achieve the same effect by using the segmented prefix\n // after initializing SS and AA as follows:\n //\n // SS[0] = L.bit(1);\n // AA[0] = gw.cc0;\n // for (size_t i = 1; i < n; ++i) {\n // SS[i] = L.bit(0);\n // AA[i] = L.konst(0);\n // }\n //\n // The compiler is smart enough to constant-fold the segment\n // SS[i] and produces the same circuit in both cases, but\n // there is no point in wasting compiler time and the\n // unsegmented prefix is more straightforward anyway.\n //\n // Note that AA, SS are uninitialized here. They will be initialized\n // below for the next level.\n ddss[0] = gw.cc0;\n SC.add(n, BB.data(), ddss.data());\n } else {\n SC.add(n, BB.data(), SS.data(), AA.data(), ddss.data());\n }\n\n // output the result of the parallel prefix\n for (size_t i = 0; i < n; ++i) {\n ps[i].c[l] = BB[i];\n }\n\n // prepare SS, AA for the next level\n for (size_t i = 0; i < n; ++i) {\n EltW newc = L.eval(ds[i].tagp);\n EltW count = ds[i].count_as_field_element;\n if (i + 1 < n) {\n count = L.mux(&ds[i].count_is_next_v8, &ds[i + 1].as_field_element,\n count);\n }\n newc = L.add(&newc, L.lmul(&ds[i].itemsp, count));\n newc = L.add(&newc, L.lmul(&ds[i].mapp, count));\n AA[i] = newc;\n\n auto sel = L.land(&ps[i].sel[l], ds[i].header);\n auto tag = L.lor(&ds[i].tagp, ds[i].itemsp);\n SS[i] = L.land(&sel, tag);\n }\n }\n\n // Assert that we don't want to start new segments at a level\n // that does not exist.\n for (size_t i = 0; i < n; ++i) {\n L.assert0(SS[i]);\n }\n }\n\n void assert_parse(size_t n, const decode ds[/*n*/],\n const parse_output ps[/*n*/],\n const global_witness& gw) const {\n const Logic& L = l_; // shorthand\n\n for (size_t i = 0; i < n; ++i) {\n // \"The SEL witnesses are mutually exclusive.\"\n // Verify by asserting that they are all bits\n // and that their sum (in the field) is a bit.\n auto sum = L.bit(0);\n for (size_t l = 0; l < kNCounters; ++l) {\n L.assert_is_bit(ps[i].sel[l]);\n sum = L.lor_exclusive(&sum, ps[i].sel[l]);\n }\n L.assert_is_bit(sum);\n\n // \"at a header, at least one SEL bit is set\"\n L.assert_implies(&ds[i].header, sum);\n }\n\n // \"All counters are zero at the end of the input\"\n // COUNTER[I][L] is the state of the parser at the end\n // of position I, so COUNTER[N-1][L] is the final state.\n for (size_t l = 0; l < kNCounters; ++l) {\n L.assert0(ps[n - 1].c[l]);\n }\n\n // SEL[0][0] is set. We implicitly define COUNTER[-1][L] to make\n // this the correct choice.\n L.assert1(ps[0].sel[0]);\n\n for (size_t i = 0; i + 1 < n; ++i) {\n // \"If SEL[I+1][L] is set, then COUNTER[I][L] is the nonzero\n // counter of maximal L. (COUNTER[I][L] contains the output\n // counter of stage I, which affects SEL[I+1].) Here we check\n // maximality: COUNTER[I][J]=0 for J>L. See below for\n // SEL[I+1][L] => (COUNTER[I][L] != 0).\n BitW b = ps[i + 1].sel[0];\n for (size_t l = 1; l < kNCounters; ++l) {\n // b => COUNTER[i][l] == 0\n L.assert0(L.lmul(&b, ps[i].c[l]));\n b = L.lor(&b, ps[i + 1].sel[l]);\n }\n }\n\n // \"SEL[I+1][L] => (COUNTER[I][L] != 0)\"\n // Check via the invertibility of\n //\n // PROD_{I, L} SEL[I+1][L] ? COUNTER[I][L] : 1\n std::vector prod(kNCounters);\n\n auto one = L.konst(1);\n for (size_t l = 0; l < kNCounters; ++l) {\n auto f = [&](size_t i) {\n return L.mux(&ps[i + 1].sel[l], &ps[i].c[l], one);\n };\n prod[l] = L.mul(0, n - 1, f);\n }\n\n EltW p = L.mul(0, kNCounters, [&](size_t l) { return prod[l]; });\n auto want_one = L.mul(&p, gw.invprod_parse);\n L.assert_eq(&want_one, one);\n }\n\n //------------------------------------------------------------\n // \"J is the header of a string of length LEN containing BYTES\"\n //------------------------------------------------------------\n void assert_text_at(size_t n, const vindex& j, size_t len,\n const uint8_t bytes[/*len*/],\n const decode ds[/*n*/]) const {\n const Logic& L = l_; // shorthand\n const Routing R(L);\n\n // we don't handle long strings\n proofs::check(len < 24, \"len < 24\");\n\n assert_header(n, j, ds);\n\n std::vector A(n);\n for (size_t i = 0; i < n; ++i) {\n A[i] = ds[i].as_field_element;\n }\n\n // shift len+1 bytes, including the header.\n std::vector B(len + 1);\n const EltW defaultA = L.konst(256); // a constant that cannot appear in A[]\n R.shift(j, len + 1, B.data(), n, A.data(), defaultA, /*unroll=*/3);\n\n size_t expected_header = (3 << 5) + len;\n L.assert_eq(&B[0], L.konst(expected_header));\n for (size_t i = 0; i < len; ++i) {\n auto bi = L.konst(bytes[i]);\n L.assert_eq(&B[i + 1], bi);\n }\n }\n\n //------------------------------------------------------------\n // \"J is a header containing unsigned U.\"\n //------------------------------------------------------------\n void assert_unsigned_at(size_t n, const vindex& j, uint64_t u,\n const decode ds[/*n*/]) const {\n // only small u for now\n proofs::check(u < 24, \"u < 24\");\n\n size_t expected = (0 << 5) + u;\n assert_atom_at(n, j, l_.konst(expected), ds);\n }\n\n //------------------------------------------------------------\n // \"J is a header containing negative U.\" (U >= 0, and\n // CBOR distinguishes 0 from -0 apparently)\n //------------------------------------------------------------\n void assert_negative_at(size_t n, const vindex& j, uint64_t u,\n const decode ds[/*n*/]) const {\n // only small u for now\n proofs::check(u < 24, \"u < 24\");\n\n size_t expected = (1 << 5) + u;\n assert_atom_at(n, j, l_.konst(expected), ds);\n }\n\n //------------------------------------------------------------\n // \"J is a header containing a boolean primitive (0xF4 or 0xF5).\"\n //\n //------------------------------------------------------------\n void assert_bool_at(size_t n, const vindex& j, bool val,\n const decode ds[/*n*/]) const {\n size_t expected = (7 << 5) + (val ? 21 : 20);\n assert_atom_at(n, j, l_.konst(expected), ds);\n }\n\n // Helps assemble the checks for date assertions.\n void date_helper(size_t n, const vindex& j, const decode ds[/*n*/],\n std::vector& B /* size 22 */) const {\n const Logic& L = l_; // shorthand\n const Routing R(L);\n assert_header(n, j, ds);\n\n std::vector A(n);\n for (size_t i = 0; i < n; ++i) {\n A[i] = ds[i].as_bits;\n }\n\n const v8 defaultA =\n L.template vbit<8>(0); // a constant that cannot appear in A[]\n R.shift(j, 20 + 2, B.data(), n, A.data(), defaultA, /*unroll=*/3);\n\n // Check for tag: date/time string.\n L.vassert_eq(&B[0], L.template vbit<8>(0xc0));\n\n // Check for string(20)\n L.vassert_eq(&B[1], L.template vbit<8>(0x74));\n }\n\n //------------------------------------------------------------\n // \"J is a header containing date d < now.\" now is 20 bytes\n // in the format 2023-11-01T09:00:00Z\n //------------------------------------------------------------\n void assert_date_before_at(size_t n, const vindex& j, const v8 now[/* 20 */],\n const decode ds[/*n*/]) const {\n const Logic& L = l_; // shorthand\n const Memcmp CMP(L);\n std::vector B(20 + 2);\n date_helper(n, j, ds, B);\n auto lt = CMP.lt(20, &B[2], now);\n L.assert1(lt);\n }\n\n //------------------------------------------------------------\n // \"J is a header containing date d > now.\" now is 20 bytes in the\n // format 2023-11-01T09:00:00Z\n // ------------------------------------------------------------\n void assert_date_after_at(size_t n, const vindex& j, const v8 now[/* 20 */],\n const decode ds[/*n*/]) const {\n const Logic& L = l_; // shorthand\n const Memcmp CMP(L);\n std::vector B(20 + 2);\n date_helper(n, j, ds, B);\n auto lt = CMP.lt(20, now, &B[2]);\n L.assert1(lt);\n }\n\n //------------------------------------------------------------\n // \"J is a header containing represented by the byte EXPECTED in the\n // input.\"\n //------------------------------------------------------------\n void assert_atom_at(size_t n, const vindex& j, const EltW& expected,\n const decode ds[/*n*/]) const {\n const Logic& L = l_; // shorthand\n const Routing R(L);\n\n assert_header(n, j, ds);\n\n std::vector A(n);\n for (size_t i = 0; i < n; ++i) {\n A[i] = ds[i].as_field_element;\n }\n\n EltW B[1];\n size_t unroll = 3;\n R.shift(j, 1, B, n, A.data(), L.konst(256), unroll);\n L.assert_eq(&B[0], expected);\n }\n\n //------------------------------------------------------------\n // \"J is a header beginning a byte array of length LEN that\n // is the big-endian representation of EltW X.\"\n // ------------------------------------------------------------\n void assert_elt_as_be_bytes_at(size_t n, const vindex& j, size_t len, EltW X,\n const decode ds[/*n*/]) const {\n const Logic& L = l_; // shorthand\n const Routing R(L);\n\n std::vector A(n);\n for (size_t i = 0; i < n; ++i) {\n A[i] = ds[i].as_field_element;\n }\n EltW tx = L.konst(0), k256 = L.konst(256);\n\n std::vector B(2 + len);\n size_t unroll = 3;\n size_t si = 1;\n R.shift(j, len + 2, B.data(), n, A.data(), L.konst(0), unroll);\n if (len < 24) {\n size_t expected_header = (2 << 5) + len;\n auto eh = L.konst(expected_header);\n L.assert_eq(&B[0], eh);\n } else if (len < 256) {\n size_t expected_header = (2 << 5) + 24;\n auto eh = L.konst(expected_header);\n L.assert_eq(&B[0], eh);\n L.assert_eq(&B[1], L.konst(len));\n si = 2;\n } else {\n check(false, \"len >= 256\");\n }\n\n for (size_t i = 0; i < len; ++i) {\n auto tmp = L.mul(&tx, k256);\n tx = L.add(&tmp, B[i + si]);\n }\n\n L.assert_eq(&tx, X);\n }\n\n //------------------------------------------------------------\n // \"Position j contains a header\"\n //------------------------------------------------------------\n void assert_header(size_t n, const vindex& j, const decode ds[/*n*/]) const {\n const Logic& L = l_; // shorthand\n\n L.vassert_is_bit(j);\n\n // giant dot product since the veq(j, .) terms are mutually exclusive.\n auto f = [&](size_t i) { return L.land(&ds[i].header, L.veq(j, i)); };\n L.assert1(L.lor_exclusive(0, n, f));\n }\n\n //------------------------------------------------------------\n // \"A map starts at position j\"\n //------------------------------------------------------------\n void assert_map_header(size_t n, const vindex& j,\n const decode ds[/*n*/]) const {\n const Logic& L = l_; // shorthand\n\n L.vassert_is_bit(j);\n\n // giant dot product since the veq(j, .) terms are mutually exclusive.\n auto f = [&](size_t i) {\n auto eq_ji = L.veq(j, i);\n auto dsi = L.land(&ds[i].mapp, ds[i].header);\n return L.land(&eq_ji, dsi);\n };\n L.assert1(L.lor_exclusive(0, n, f));\n }\n\n //------------------------------------------------------------\n // \"Position M starts a map of level LEVEL. (K, V) are headers\n // representing the J-th pair in that map\"\n //------------------------------------------------------------\n void assert_map_entry(size_t n, const vindex& m, size_t level,\n const vindex& k, const vindex& v, const vindex& j,\n const decode ds[/*n*/],\n const parse_output ps[/*n*/]) const {\n const Logic& L = l_; // shorthand\n const Routing R(L);\n\n assert_map_header(n, m, ds);\n assert_header(n, k, ds);\n assert_header(n, v, ds);\n\n for (size_t l = 0; l < kNCounters; ++l) {\n std::vector A(n);\n for (size_t i = 0; i < n; ++i) {\n A[i] = ps[i].c[l];\n }\n\n // Select counters[m], counters[k], and counters[v].\n EltW cm, ck, cv;\n\n const size_t unroll = 3;\n R.shift(m, 1, &cm, n, A.data(), L.konst(0), unroll);\n R.shift(k, 1, &ck, n, A.data(), L.konst(0), unroll);\n R.shift(v, 1, &cv, n, A.data(), L.konst(0), unroll);\n\n if (l <= level) {\n // Counters[L] must agree at the key, value, and root\n // of the map.\n L.assert_eq(&cm, ck);\n L.assert_eq(&cm, cv);\n } else if (l == level + 1) {\n auto one = L.konst(1);\n auto two = L.konst(2);\n // LEVEL+1 counters must have the right number of decrements.\n // Specifically, if the counter at the map is N, then the j-th\n // key has N-(2*j+1) and the j-th value has N-(2*j+2)\n auto twoj = L.mul(&two, ba_index_.as_field_element(j));\n L.assert_eq(&cm, L.add(&ck, L.add(&twoj, one)));\n L.assert_eq(&cm, L.add(&cv, L.add(&twoj, two)));\n } else {\n // not sure if this is necessary, but all other counters\n // of CM are supposed to be zero.\n L.assert0(cm);\n }\n }\n }\n\n //------------------------------------------------------------\n // \"JROOT is the first byte of the actual (unpadded) input and\n // all previous bytes are 0\"\n //------------------------------------------------------------\n void assert_input_starts_at(size_t n, const vindex& jroot,\n const vindex& input_len,\n const decode ds[/*n*/]) const {\n const Logic& L = l_; // shorthand\n\n L.assert1(L.vleq(input_len, n));\n L.assert1(L.vlt(jroot, n));\n auto tot = L.vadd(jroot, input_len);\n L.vassert_eq(tot, n);\n\n for (size_t i = 0; i < n; ++i) {\n L.assert0(L.lmul(&ds[i].as_field_element, L.vlt(i, jroot)));\n }\n }\n\n //------------------------------------------------------------\n // Utilities\n //------------------------------------------------------------\n // The circuit accepts up to N input positions, of which\n // INPUT_LEN are actual input and the rest are ignored.\n void decode_all(size_t n, decode ds[/*n*/], const v8 in[/*n*/],\n const position_witness pw[/*n*/]) const {\n for (size_t i = 0; i < n; ++i) {\n ds[i] = decode_one_v8(in[i]);\n ds[i].header = bp_.pluckb(pw[i].encoded_sel_header);\n }\n }\n\n void decode_and_assert_decode(size_t n, decode ds[/*n*/], const v8 in[/*n*/],\n const position_witness pw[/*n*/],\n const global_witness& gw) const {\n decode_all(n, ds, in, pw);\n assert_decode(n, ds, pw, gw);\n }\n\n void decode_and_assert_decode_and_parse(size_t n, decode ds[/*n*/],\n parse_output ps[/*n*/],\n const v8 in[/*n*/],\n const position_witness pw[/*n*/],\n const global_witness& gw) const {\n decode_and_assert_decode(n, ds, in, pw, gw);\n parse(n, ps, ds, pw, gw);\n assert_parse(n, ds, ps, gw);\n }\n\n private:\n const Logic& l_;\n const BitAdder ba_count_;\n const BitAdder ba_byte_;\n const BitAdder ba_index_;\n const CborPlucker bp_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_revocation_witness.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_REVOCATION_WITNESS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_REVOCATION_WITNESS_H_\n\n#include \n#include \n#include \n#include \n\n#include \"arrays/dense.h\"\n#include \"circuits/ecdsa/verify_witness.h\"\n#include \"circuits/logic/bit_plucker_encoder.h\"\n#include \"circuits/mdoc/mdoc_revocation_constants.h\"\n#include \"circuits/sha/flatsha256_witness.h\"\n\nnamespace proofs {\n\ntemplate \ntypename Field::Elt compute_mdoc_revocation_list_witness(\n typename Field::Elt id, const typename Field::Elt list[], size_t list_size,\n const Field& F) {\n typename Field::Elt prodinv = F.one();\n for (size_t i = 0; i < list_size; ++i) {\n prodinv = F.mulf(prodinv, F.subf(list[i], id));\n }\n F.invert(prodinv);\n return prodinv;\n}\n\ntemplate \nclass MdocRevocationSpanWitness {\n using Field = typename EC::Field;\n using Elt = typename Field::Elt;\n using Nat = typename Field::N;\n using EcdsaWitness = VerifyWitness3;\n const EC& ec_;\n\n public:\n Elt e_, r_, s_;\n EcdsaWitness sig_;\n uint8_t preimage_[64 * 2];\n uint8_t id_bits_[256];\n uint8_t e_bits_[256];\n FlatSHA256Witness::BlockWitness sha_bw_[2];\n\n explicit MdocRevocationSpanWitness(const EC& ec, const ScalarField& Fn)\n : ec_(ec), sig_(Fn, ec) {}\n\n void fill_witness(DenseFiller& filler) const {\n filler.push_back(r_);\n filler.push_back(s_);\n filler.push_back(e_);\n sig_.fill_witness(filler);\n\n // Write the span message.\n for (size_t i = 0; i < 64 * 2; ++i) {\n for (size_t j = 0; j < 8; ++j) {\n filler.push_back((preimage_[i] >> j) & 0x1 ? ec_.f_.one()\n : ec_.f_.zero());\n }\n }\n\n for (size_t i = 0; i < 256; ++i) {\n filler.push_back(id_bits_[i] ? ec_.f_.one() : ec_.f_.zero());\n }\n for (size_t i = 0; i < 256; ++i) {\n filler.push_back(e_bits_[i] ? ec_.f_.one() : ec_.f_.zero());\n }\n\n for (size_t j = 0; j < 2; j++) {\n fill_sha(filler, sha_bw_[j]);\n }\n }\n\n void fill_sha(DenseFiller& filler,\n const FlatSHA256Witness::BlockWitness& bw) const {\n BitPluckerEncoder BPENC(ec_.f_);\n for (size_t k = 0; k < 48; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.outw[k]));\n }\n for (size_t k = 0; k < 64; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.oute[k]));\n filler.push_back(BPENC.mkpacked_v32(bw.outa[k]));\n }\n for (size_t k = 0; k < 8; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.h1[k]));\n }\n }\n\n bool compute_witness(Elt pkX, Elt pkY, Nat ne, Nat nr, Nat ns, Nat id, Nat ll,\n Nat rr, uint64_t epoch) {\n e_ = ec_.f_.to_montgomery(ne);\n r_ = ec_.f_.to_montgomery(nr);\n s_ = ec_.f_.to_montgomery(ns);\n sig_.compute_witness(pkX, pkY, ne, nr, ns);\n\n std::vector buf;\n for (size_t i = 0; i < 8; ++i) {\n buf.push_back(epoch & 0xff);\n epoch >>= 8;\n }\n uint8_t tmp[Field::kBytes];\n ll.to_bytes(tmp);\n buf.insert(buf.end(), tmp, tmp + Field::kBytes);\n rr.to_bytes(tmp);\n buf.insert(buf.end(), tmp, tmp + Field::kBytes);\n\n for (size_t i = 0; i < 256; ++i) {\n id_bits_[i] = id.bit(i);\n e_bits_[i] = ne.bit(i);\n }\n\n uint8_t numb = 0;\n FlatSHA256Witness::transform_and_witness_message(buf.size(), buf.data(), 2,\n numb, preimage_, sha_bw_);\n\n return true;\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_REVOCATION_WITNESS_H_\n"], ["/longfellow-zk/lib/circuits/base64/decode.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_BASE64_DECODE_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_BASE64_DECODE_H_\n\n#include \n#include \n\n#include \"util/ceildiv.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n\n// This class implements a circuit to assert a base64 url decoding.\n// A string in base64 consists of the characters A-Z a-z 0-9 - _ and =.\n// 0--25 are mapped to A-Z, 26--51 are mapped to a-z, 52--61 are mapped to 0-9,\n// and 62--63 are mapped to - and _ respectively.\n// The base64 encoding is padded with = to a multiple of 4.\ntemplate \nclass Base64Decoder {\n using EltW = typename LogicCircuit::EltW;\n using BitW = typename LogicCircuit::BitW;\n using v8 = typename LogicCircuit::v8;\n using v6 = typename LogicCircuit::template bitvec<6>;\n\n public:\n explicit Base64Decoder(const LogicCircuit& lc) : lc_(lc) {}\n\n void base64_rawurl_decode(const v8 inputs[/*n*/],\n v8 output[/* ceil(n*6/8) */], size_t n) const {\n check(n < (1 << 28), \"input too large\"); // avoid overflows\n v6 zero = lc_.template vbit<6>(0);\n\n size_t max = ceildiv(n * 6, 8);\n size_t oc = 0;\n\n for (size_t i = 0; i < n; i += 4, oc += 3) {\n v6 quad[4] = {zero, zero, zero, zero};\n for (size_t j = 0; j < 4 && i + j < n; ++j) {\n decode(inputs[i + j], quad[j]);\n }\n // repack\n for (size_t j = 0; j < 24 && (oc + j / 8) < max; ++j) {\n output[oc + j / 8][7 - (j % 8)] = quad[j / 6][5 - (j % 6)];\n }\n }\n }\n\n template \n void base64_rawurl_decode_len(\n const v8 inputs[/*n*/], v8 output[/* ceil(n*6/8) */], size_t n,\n typename LogicCircuit::template bitvec& len) const {\n check(n < (1 << 28), \"input too large\"); // avoid overflows\n v6 zero = lc_.template vbit<6>(0);\n\n size_t max = ceildiv(n * 6, 8);\n size_t oc = 0;\n\n for (size_t i = 0; i < n; i += 4, oc += 3) {\n v6 quad[4] = {zero, zero, zero, zero};\n BitW invalid;\n for (size_t j = 0; j < 4 && i + j < n; ++j) {\n decode(inputs[i + j], quad[j], invalid);\n auto range = lc_.vlt(i + j, len);\n lc_.assert_implies(&range, lc_.lnot(invalid));\n }\n // repack\n for (size_t j = 0; j < 24 && (oc + j / 8) < max; ++j) {\n output[oc + j / 8][7 - (j % 8)] = quad[j / 6][5 - (j % 6)];\n }\n }\n }\n\n void decode(const v8 in, v6& out) const {\n BitW invalid;\n decode(in, out, invalid);\n lc_.assert0(invalid);\n }\n\n void decode(const v8 in, v6& out, BitW& invalid) const {\n v8 ni;\n for (size_t i = 0; i < 8; ++i) {\n ni[i] = lc_.lnot(in[i]);\n }\n std::vector > exp[] = {\n {\n // ['!v4', '!v3', '!v2', '!v1', '!v0']\n {\n ni[4],\n ni[3],\n ni[2],\n ni[1],\n ni[0],\n },\n // ['v4', 'v3', '!v2', 'v1', 'v0']\n {\n in[4],\n in[3],\n ni[2],\n in[1],\n in[0],\n },\n // ['v5', 'v4', 'v3', 'v1', 'v0']\n {\n in[5],\n in[4],\n in[3],\n in[1],\n in[0],\n },\n // ['!v6', 'v3', 'v2', '!v0']\n {\n ni[6],\n in[3],\n in[2],\n ni[0],\n },\n // ['v4', 'v3', 'v2', '!v1']\n {\n in[4],\n in[3],\n in[2],\n ni[1],\n },\n // ['v4', 'v3', 'v2', '!v0']\n {\n in[4],\n in[3],\n in[2],\n ni[0],\n },\n // ['!v6', '!v4', '!v3']\n {\n ni[6],\n ni[4],\n ni[3],\n },\n // ['!v6', '!v4', '!v2']\n {\n ni[6],\n ni[4],\n ni[2],\n },\n // ['!v6', 'v3', 'v1']\n {\n ni[6],\n in[3],\n in[1],\n },\n // ['!v6', '!v5']\n {\n ni[6],\n ni[5],\n },\n // ['v7']\n {\n in[7],\n },\n },\n {\n // ['v6', 'v5', 'v4', '!v3', '!v2']\n {\n in[6],\n in[5],\n in[4],\n ni[3],\n ni[2],\n },\n // ['v6', 'v5', 'v4', '!v3', '!v0']\n {\n in[6],\n in[5],\n in[4],\n ni[3],\n ni[0],\n },\n // ['v6', 'v5', 'v4', 'v2', '!v1']\n {\n in[6],\n in[5],\n in[4],\n in[2],\n ni[1],\n },\n // ['v5', 'v2', 'v1', 'v0']\n {\n in[5],\n in[2],\n in[1],\n in[0],\n },\n // ['v4', 'v3', 'v1', 'v0']\n {\n in[4],\n in[3],\n in[1],\n in[0],\n },\n // ['v5', 'v3']\n {\n in[5],\n in[3],\n },\n // ['!v6', '!v2']\n {\n ni[6],\n ni[2],\n },\n // ['!v6', 'v2']\n {\n ni[6],\n in[2],\n },\n },\n {\n // ['v5', '!v4', '!v3', '!v1']\n {\n in[5],\n ni[4],\n ni[3],\n ni[1],\n },\n // ['v5', '!v4', '!v3', '!v2']\n {\n in[5],\n ni[4],\n ni[3],\n ni[2],\n },\n // ['!v5', 'v4', 'v1']\n {\n ni[5],\n in[4],\n in[1],\n },\n // ['v5', '!v4', '!v3', '!v0']\n {\n in[5],\n ni[4],\n ni[3],\n ni[0],\n },\n // ['v4', 'v2', 'v1', 'v0']\n {\n in[4],\n in[2],\n in[1],\n in[0],\n },\n // ['!v5', 'v4', 'v0']\n {\n ni[5],\n in[4],\n in[0],\n },\n // ['!v5', 'v4', 'v2']\n {\n ni[5],\n in[4],\n in[2],\n },\n // ['v4', 'v3']\n {\n in[4],\n in[3],\n },\n // ['!v6', '!v2']\n {\n ni[6],\n ni[2],\n },\n // ['!v6', 'v2']\n {\n ni[6],\n in[2],\n },\n },\n {\n // ['v6', '!v3', '!v2', '!v1', '!v0']\n {\n in[6],\n ni[3],\n ni[2],\n ni[1],\n ni[0],\n },\n // ['v6', 'v5', 'v4', '!v3', '!v2']\n {\n in[6],\n in[5],\n in[4],\n ni[3],\n ni[2],\n },\n // ['v6', 'v5', 'v4', '!v3', '!v0']\n {\n in[6],\n in[5],\n in[4],\n ni[3],\n ni[0],\n },\n // ['v6', 'v5', 'v4', 'v2', '!v1']\n {\n in[6],\n in[5],\n in[4],\n in[2],\n ni[1],\n },\n // ['v5', '!v4', '!v3', '!v1']\n {\n in[5],\n ni[4],\n ni[3],\n ni[1],\n },\n // ['v5', '!v4', '!v3', '!v2']\n {\n in[5],\n ni[4],\n ni[3],\n ni[2],\n },\n // ['v5', '!v4', '!v3', '!v0']\n {\n in[5],\n ni[4],\n ni[3],\n ni[0],\n },\n // ['!v5', 'v3', 'v1']\n {\n ni[5],\n in[3],\n in[1],\n },\n // ['v3', 'v2', 'v1', 'v0']\n {\n in[3],\n in[2],\n in[1],\n in[0],\n },\n // ['!v5', 'v3', 'v0']\n {\n ni[5],\n in[3],\n in[0],\n },\n // ['!v5', 'v3', 'v2']\n {\n ni[5],\n in[3],\n in[2],\n },\n // ['!v6', 'v3']\n {\n ni[6],\n in[3],\n },\n // ['!v6', 'v2']\n {\n ni[6],\n in[2],\n },\n },\n {\n // ['v5', '!v4', 'v2', '!v1', 'v0']\n {\n in[5],\n ni[4],\n in[2],\n ni[1],\n in[0],\n },\n // ['v6', 'v5', 'v4', 'v2', '!v1']\n {\n in[6],\n in[5],\n in[4],\n in[2],\n ni[1],\n },\n // ['!v5', '!v2', '!v1', '!v0']\n {\n ni[5],\n ni[2],\n ni[1],\n ni[0],\n },\n // ['v6', 'v5', 'v2', '!v0']\n {\n in[6],\n in[5],\n in[2],\n ni[0],\n },\n // ['v5', '!v2', 'v1', 'v0']\n {\n in[5],\n ni[2],\n in[1],\n in[0],\n },\n // ['!v5', 'v2', 'v0']\n {\n ni[5],\n in[2],\n in[0],\n },\n // ['!v5', 'v2', 'v1']\n {\n ni[5],\n in[2],\n in[1],\n },\n // ['!v6', '!v2']\n {\n ni[6],\n ni[2],\n },\n },\n {\n // ['v5', '!v4', 'v2', '!v1', 'v0']\n {\n in[5],\n ni[4],\n in[2],\n ni[1],\n in[0],\n },\n // ['v6', 'v5', '!v1', 'v0']\n {\n in[6],\n in[5],\n ni[1],\n in[0],\n },\n // ['!v5', '!v1', '!v0']\n {\n ni[5],\n ni[1],\n ni[0],\n },\n // ['!v5', 'v1', 'v0']\n {\n ni[5],\n in[1],\n in[0],\n },\n // ['v5', 'v1', '!v0']\n {\n in[5],\n in[1],\n ni[0],\n },\n // ['!v6', 'v1']\n {\n ni[6],\n in[1],\n },\n },\n {\n // ['v4', 'v3', 'v1', 'v0']\n {\n in[4],\n in[3],\n in[1],\n in[0],\n },\n // ['!v6', 'v4', 'v0']\n {\n ni[6],\n in[4],\n in[0],\n },\n // ['v6', '!v0']\n {\n in[6],\n ni[0],\n },\n },\n };\n invalid = lc_.or_of_and(exp[0]);\n for (size_t i = 0; i < 6; ++i) {\n out[5 - i] = lc_.or_of_and(exp[i + 1]);\n }\n }\n\n private:\n const LogicCircuit& lc_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_BASE64_DECODE_H_\n"], ["/longfellow-zk/lib/circuits/logic/logic.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_LOGIC_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_LOGIC_H_\n\n#include \n\n#include \n#include \n#include \n#include \n\n#include \"algebra/fp_generic.h\"\n#include \"gf2k/gf2_128.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n/*\n Arithmetization of boolean logic in a field.\n This class builds logical and arithmetic operations such as add, sub, mul,\n and, or, xor, etc. over bits in the arithmetic circuit model.\n The class utilizes several optimizations, including changing from the {0,1}\n basis to the {-1,1} basis for representing bits.\n */\ntemplate \nclass Logic {\n public:\n using Field = Field_; /* this class export Field, Elt, and EltW */\n using Elt = typename Field::Elt;\n // an \"Elt Wire\", a wire carrying an Elt.\n using EltW = typename Backend::V;\n\n const Field& f_;\n\n explicit Logic(const Backend* bk, const Field& F) : f_(F), bk_(bk) {}\n\n //------------------------------------------------------------\n // Arithmetic.\n\n //\n // Re-export field operations\n Elt addf(const Elt& a, const Elt& b) const { return f_.addf(a, b); }\n Elt mulf(const Elt& a, const Elt& b) const { return f_.mulf(a, b); }\n Elt invertf(const Elt& a) const { return f_.invertf(a); }\n Elt negf(const Elt& a) const { return f_.negf(a); }\n Elt zero() const { return f_.zero(); }\n Elt one() const { return f_.one(); }\n Elt mone() const { return f_.mone(); }\n Elt elt(uint64_t a) const { return f_.of_scalar(a); }\n\n template \n Elt elt(const char (&s)[N]) const {\n return f_.of_string(s);\n }\n\n // To ensure deterministic behavior, the order of function calls that produce\n // circuit wires must be well-defined at compile time.\n // The C spec leaves certain order of operations unspecified in expressions.\n // One such ambiguity arises in the order of function calls in an argument\n // list. For example, the expression f(creates_wire(x), creates_wire(y))\n // results in an ambiguous order.\n // To help prevent this, all function calls that create wires can have at most\n // one argument that is itself a function. To enforce this property, we\n // require that all but the last argument to a function be a const pointer.\n\n // Re-export backend operations\n EltW assert0(const EltW& a) const { return bk_->assert0(a); }\n EltW add(const EltW* a, const EltW& b) const { return bk_->add(*a, b); }\n\n EltW sub(const EltW* a, const EltW& b) const { return bk_->sub(*a, b); }\n\n EltW mul(const EltW* a, const EltW& b) const { return bk_->mul(*a, b); }\n EltW mul(const Elt& k, const EltW& b) const { return bk_->mul(k, b); }\n EltW mul(const Elt& k, const EltW* a, const EltW& b) const {\n return bk_->mul(k, a, b);\n }\n\n EltW ax(const Elt& a, const EltW& x) const { return bk_->ax(a, x); }\n EltW axy(const Elt& a, const EltW* x, const EltW& y) const {\n return bk_->axy(a, *x, y);\n }\n EltW axpy(const EltW* y, const Elt& a, const EltW& x) const {\n return bk_->axpy(*y, a, x);\n }\n EltW apy(const EltW& y, const Elt& a) const { return bk_->apy(y, a); }\n\n EltW konst(const Elt& a) const { return bk_->konst(a); }\n EltW konst(uint64_t a) const { return konst(elt(a)); }\n\n template \n std::array konst(const std::array& a) const {\n std::array r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = konst(a[i]);\n }\n return r;\n }\n\n //------------------------------------------------------------\n // Boolean logic.\n //\n // We map TRUE to one() and FALSE to zero(). We call this convention\n // the \"standard basis\".\n //\n // However, actual values on wires may use different conventions,\n // e.g. -1 for TRUE and 1 for FALSE. To keep track of these changes,\n // we represent boolean values as (c0, c1, x) where c0+c1*x is\n // the value in the standard basis. c0 and c1\n // are compile-time constants that can be manipulated, and\n // x is a runtime value not known in advance.\n //\n // For example, let the \"xor basis\" denote the mapping FALSE -> 1,\n // TRUE -> -1. In the xor basis, xor(a,b)=a*b. The output of the\n // xor gate in the standard basis would be represented as 1/2 + (-1/2)*x\n // where x=a*b is the wire value in the xor basis.\n\n // a \"bit Wire\", a wire carrying a bit\n struct BitW {\n Elt c0, c1;\n EltW x;\n BitW() = default;\n\n // constructor in the standard basis\n explicit BitW(const EltW& bv, const Field& F)\n : BitW(F.zero(), F.one(), bv) {}\n\n BitW(Elt c0_, Elt c1_, const EltW& x_) : c0(c0_), c1(c1_), x(x_) {}\n };\n\n // vectors of N bits\n template \n class bitvec : public std::array {};\n\n // Common sizes, publicly exported for convenience. The type names are\n // intentionally lower-case to capture the spirit of basic \"intx_t\" types.\n using v1 = bitvec<1>;\n using v4 = bitvec<4>;\n using v8 = bitvec<8>;\n using v16 = bitvec<16>;\n using v32 = bitvec<32>;\n using v64 = bitvec<64>;\n using v128 = bitvec<128>;\n using v129 = bitvec<129>;\n using v256 = bitvec<256>;\n\n // Let v(x)=c0+c1*x. Return a representation of\n // d0+d1*v(x)=(d0+d1*c0)+(d1*c1)*x without changing x.\n // Does not involve the backend at all.\n BitW rebase(const Elt& d0, const Elt& d1, const BitW& v) const {\n return BitW(addf(d0, mulf(d1, v.c0)), mulf(d1, v.c1), v.x);\n }\n\n EltW eval(const BitW& v) const {\n EltW r = ax(v.c1, v.x);\n if (v.c0 != zero()) {\n auto c0 = konst(v.c0);\n r = add(&c0, r);\n }\n return r;\n }\n\n // return an EltW which is 0 iff v is 0\n EltW assert0(const BitW& v) const {\n auto e = eval(v);\n return assert0(e);\n }\n // return an EltW which is 0 iff v is 1\n EltW assert1(const BitW& v) const {\n auto e = lnot(v);\n return assert0(e);\n }\n\n // 0 iff a==b\n EltW assert_eq(const EltW* a, const EltW& b) const {\n return assert0(sub(a, b));\n }\n EltW assert_eq(const BitW* a, const BitW& b) const {\n return assert0(lxor(a, b));\n }\n EltW assert_implies(const BitW* a, const BitW& b) const {\n return assert1(limplies(a, b));\n }\n\n // special test for asserting that b \\in {0,1} (i.e.,\n // not some other field element).\n EltW assert_is_bit(const BitW& b) const {\n // b - b*b\n // Seems to work better than b*(1-b)\n // Equivalent to land(b,lnot(b)) but does not rely\n // on the specific arithmetization.\n auto eb = eval(b);\n return assert_is_bit(eb);\n }\n EltW assert_is_bit(const EltW& v) const {\n auto vvmv = sub(&v, mul(&v, v));\n return assert0(vvmv);\n }\n\n // bits in their own basis b + 0*1, to allow for some\n // compile-time constant folding\n BitW bit(size_t b) const {\n return BitW((b == 0) ? zero() : one(), zero(), konst(one()));\n }\n\n void bits(size_t n, BitW a[/*n*/], uint64_t x) const {\n for (size_t i = 0; i < n; ++i) {\n a[i] = bit((x >> i) & 1u);\n }\n }\n\n // gates\n BitW lnot(const BitW& x) const {\n // lnot() is a pure representation change that does not\n // involve actual circuit gates\n\n // 1 - x in the standard basis\n return rebase(one(), mone(), x);\n }\n\n BitW land(const BitW* a, const BitW& b) const {\n // a * b in the standard basis\n return mulv(a, b);\n }\n\n // special case of product of a logic value by a field\n // element\n EltW lmul(const BitW* a, const EltW& b) const {\n // a * b in the standard basis\n auto ab = mulv(a, BitW(b, f_));\n return eval(ab);\n }\n EltW lmul(const EltW* b, const BitW& a) const { return lmul(&a, *b); }\n\n BitW lxor(const BitW* a, const BitW& b) const {\n return lxor_aux(*a, b, typename Field::TypeTag());\n }\n BitW lxor(const BitW* a, const BitW* b) const {\n return lxor_aux(*a, *b, typename Field::TypeTag());\n }\n\n BitW lor(const BitW* a, const BitW& b) const {\n auto na = lnot(*a);\n auto nab = land(&na, lnot(b));\n return lnot(nab);\n }\n\n // a => b\n BitW limplies(const BitW* a, const BitW& b) const {\n auto na = lnot(*a);\n return lor(&na, b);\n }\n\n // OR of two quantities known to be mutually exclusive\n BitW lor_exclusive(const BitW* a, const BitW& b) const { return addv(*a, b); }\n\n BitW lxor3(const BitW* a, const BitW* b, const BitW& c) const {\n BitW p = lxor(a, b);\n return lxor(&p, c);\n }\n\n // sha256 Ch(): (x & y) ^ (~x & z);\n BitW lCh(const BitW* x, const BitW* y, const BitW& z) const {\n auto xy = land(x, *y);\n auto nx = lnot(*x);\n return lor_exclusive(&xy, land(&nx, z));\n }\n\n // sha256 Maj(): (x & y) ^ (x & z) ^ (y & z);\n BitW lMaj(const BitW* x, const BitW* y, const BitW& z) const {\n // Interpret as x + y + z >= 2 and compute the carry\n // for an adder in the (p, g) basis\n BitW p = lxor(x, *y);\n BitW g = land(x, *y);\n return lor_exclusive(&g, land(&p, z));\n }\n\n // mux over logic values\n BitW mux(const BitW* control, const BitW* iftrue, const BitW& iffalse) const {\n auto cif = land(control, *iftrue);\n auto nc = lnot(*control);\n auto ciff = land(&nc, *iffalse);\n return lor_exclusive(&cif, ciff);\n }\n\n // mux over backend values\n EltW mux(const BitW* control, const EltW* iftrue, const EltW& iffalse) const {\n auto cif = lmul(control, *iftrue);\n auto nc = lnot(*control);\n auto ciff = lmul(&nc, iffalse);\n return add(&cif, ciff);\n }\n\n // sum_{i0 <= i < i1} f(i)\n EltW add(size_t i0, size_t i1, const std::function& f) const {\n if (i1 <= i0) {\n return konst(0);\n } else if (i1 == i0 + 1) {\n return f(i0);\n } else {\n size_t im = i0 + (i1 - i0) / 2;\n auto lh = add(i0, im, f);\n auto rh = add(im, i1, f);\n return add(&lh, rh);\n }\n }\n\n // lor_exclusive_{i0 <= i < i1} f(i)\n BitW lor_exclusive(size_t i0, size_t i1,\n const std::function& f) const {\n if (i1 <= i0) {\n return bit(0);\n } else if (i1 == i0 + 1) {\n return f(i0);\n } else {\n size_t im = i0 + (i1 - i0) / 2;\n auto lh = lor_exclusive(i0, im, f);\n auto rh = lor_exclusive(im, i1, f);\n return lor_exclusive(&lh, rh);\n }\n }\n\n // and_{i0 <= i < i1} f(i)\n BitW land(size_t i0, size_t i1, const std::function& f) const {\n if (i1 <= i0) {\n return bit(1);\n } else if (i1 == i0 + 1) {\n return f(i0);\n } else {\n size_t im = i0 + (i1 - i0) / 2;\n auto lh = land(i0, im, f);\n auto rh = land(im, i1, f);\n return land(&lh, rh);\n }\n }\n\n // or_{i0 <= i < i1} f(i)\n BitW lor(size_t i0, size_t i1, const std::function& f) const {\n if (i1 <= i0) {\n return bit(0);\n } else if (i1 == i0 + 1) {\n return f(i0);\n } else {\n size_t im = i0 + (i1 - i0) / 2;\n auto lh = lor(i0, im, f);\n auto rh = lor(im, i1, f);\n return lor(&lh, rh);\n }\n }\n\n BitW or_of_and(std::vector> clauses_of_ands) const {\n std::vector ands(clauses_of_ands.size());\n for (size_t i = 0; i < clauses_of_ands.size(); ++i) {\n auto ai = clauses_of_ands[i];\n BitW res = land(0, ai.size(), [&](size_t i) { return ai[i]; });\n ands[i] = res;\n }\n return lor(0, ands.size(), [&](size_t i) { return ands[i]; });\n }\n\n // prod_{i0 <= i < i1} f(i)\n EltW mul(size_t i0, size_t i1, const std::function& f) const {\n if (i1 <= i0) {\n return konst(1);\n } else if (i1 == i0 + 1) {\n return f(i0);\n } else {\n size_t im = i0 + (i1 - i0) / 2;\n auto lh = mul(i0, im, f);\n auto rh = mul(im, i1, f);\n return mul(&lh, rh);\n }\n }\n\n // assert that a + b = c in constant depth\n void assert_sum(size_t w, const BitW c[/*w*/], const BitW a[/*w*/],\n const BitW b[/*w*/]) const {\n // first step of generic_gp_add(): change the basis from\n // (a, b) to (g, p):\n std::vector g(w), p(w), cy(w);\n for (size_t i = 0; i < w; ++i) {\n g[i] = land(&a[i], b[i]);\n p[i] = lxor(&a[i], &b[i]);\n }\n\n // invert the last step of generic_gp_add(): derive\n // cy[i - 1] (called g[i - 1] there) from\n // c[i] and p[i].\n assert_eq(&c[0], p[0]);\n for (size_t i = 1; i < w; ++i) {\n cy[i - 1] = lxor(&c[i], p[i]);\n }\n\n // Verify that applying ripple_scan to g[] produces cy[].\n // Note that ripple_scan() operates in-place on g[]. Here, however, g[] is\n // the input to ripple_scan(), and cy[] is the output.\n assert_eq(&cy[0], g[0]);\n for (size_t i = 1; i + 1 < w; ++i) {\n auto cyp = land(&cy[i - 1], p[i]);\n auto g_cyp = lor_exclusive(&g[i], cyp);\n assert_eq(&cy[i], g_cyp);\n }\n }\n\n // (carry, c) = a + b, returning the carry.\n BitW ripple_carry_add(size_t w, BitW c[/*w*/], const BitW a[/*w*/],\n const BitW b[/*w*/]) const {\n return generic_gp_add(w, c, a, b, &Logic::ripple_scan);\n }\n\n // (carry, c) = a - b, returning the carry.\n BitW ripple_carry_sub(size_t w, BitW c[/*w*/], const BitW a[/*w*/],\n const BitW b[/*w*/]) const {\n return generic_gp_sub(w, c, a, b, &Logic::ripple_scan);\n }\n\n BitW parallel_prefix_add(size_t w, BitW c[/*w*/], const BitW a[/*w*/],\n const BitW b[/*w*/]) const {\n return generic_gp_add(w, c, a, b, &Logic::sklansky_scan);\n }\n\n BitW parallel_prefix_sub(size_t w, BitW c[/*w*/], const BitW a[/*w*/],\n const BitW b[/*w*/]) const {\n return generic_gp_sub(w, c, a, b, &Logic::sklansky_scan);\n }\n\n // w x w -> 2w-bit multiplier c = a * b\n void multiplier(size_t w, BitW c[/*2*w*/], const BitW a[/*w*/],\n const BitW b[/*w*/]) const {\n std::vector t(w);\n for (size_t i = 0; i < w; ++i) {\n if (i == 0) {\n for (size_t j = 0; j < w; ++j) {\n c[j] = land(&a[0], b[j]);\n }\n c[w] = bit(0);\n } else {\n for (size_t j = 0; j < w; ++j) {\n t[j] = land(&a[i], b[j]);\n }\n BitW carry = ripple_carry_add(w, c + i, t.data(), c + i);\n c[i + w] = carry;\n }\n }\n }\n\n // w x w -> 2w-bit polynomial multiplier over gf2. c(x) = a(x) * b(x)\n void gf2_polynomial_multiplier(size_t w, BitW c[/*2*w*/], const BitW a[/*w*/],\n const BitW b[/*w*/]) const {\n std::vector t(w);\n for (size_t k = 0; k < 2 * w; ++k) {\n size_t n = 0;\n for (size_t i = 0; i < w; ++i) {\n if (k >= i && k - i < w) {\n t[n++] = land(&a[i], b[k - i]);\n }\n }\n c[k] = parity(0, n, t.data());\n }\n }\n\n // w x w -> 2w-bit polynomial multiplier over gf2. c(x) = a(x) * b(x)\n // via the Karatsuba recurrence. Only works for w = 2^k.\n void gf2_polynomial_multiplier_karat(size_t w, BitW c[/*2*w*/],\n const BitW a[/*w*/],\n const BitW b[/*w*/]) const {\n check(w == 128 || w == 64 || w < 64, \"input length is not a power of 2\");\n if (w < 64) {\n gf2_polynomial_multiplier(w, c, a, b);\n return;\n } else {\n // We only run this look on w=128 bits. To support odd w,\n std::vector a01(w / 2); /* a0 plus a1 */\n std::vector b01(w / 2); /* b0 plus b1 */\n std::vector ab01(w);\n std::vector a0b0(w);\n std::vector a1b1(w);\n\n for (size_t i = 0; i < w / 2; ++i) {\n a01[i] = lxor(&a[i], a[i + w / 2]);\n b01[i] = lxor(&b[i], b[i + w / 2]);\n }\n\n gf2_polynomial_multiplier_karat(w / 2, &ab01[0], &a01[0], &b01[0]);\n gf2_polynomial_multiplier_karat(w / 2, &a0b0[0], a, b);\n gf2_polynomial_multiplier_karat(w / 2, &a1b1[0], a + w / 2, b + w / 2);\n\n for (size_t i = 0; i < w; ++i) {\n ab01[i] = lxor3(&ab01[i], &a0b0[i], a1b1[i]);\n }\n\n for (size_t i = 0; i < w/2; ++i) {\n c[i] = a0b0[i];\n c[i + w/2] = lxor(&a0b0[i + w/2], ab01[i]);\n c[i + w] = lxor(&ab01[i + w/2], a1b1[i]);\n c[i + 3*w/2] = a1b1[i + w/2];\n }\n }\n }\n\n // Performs field multiplication in GF2^128 defined by the irreducible\n // x^128 + x^7 + x^2 + x + 1. This routine is generated in a sage script that\n // computes a sparse matrix-vector mult via the powers of x^k mod p(x).\n //\n // def make_mulmod(F, n):\n // r = F(1)\n // gen = F.gen()\n // nl = [[] for _ in range(n)]\n // terms = 0\n // for i in range(0, 2*n-1):\n // for j, var in enumerate(r.polynomial().list()):\n // if var == 1:\n // nl[j].append(i)\n // r = r * gen\n // print(nl)\n void gf2_128_mul(v128& c, const v128 a, const v128 b) const {\n const std::vector taps[128] = {\n {0, 128, 249, 254},\n {1, 128, 129, 249, 250, 254},\n {2, 128, 129, 130, 249, 250, 251, 254},\n {3, 129, 130, 131, 250, 251, 252},\n {4, 130, 131, 132, 251, 252, 253},\n {5, 131, 132, 133, 252, 253, 254},\n {6, 132, 133, 134, 253, 254},\n {7, 128, 133, 134, 135, 249},\n {8, 129, 134, 135, 136, 250},\n {9, 130, 135, 136, 137, 251},\n {10, 131, 136, 137, 138, 252},\n {11, 132, 137, 138, 139, 253},\n {12, 133, 138, 139, 140, 254},\n {13, 134, 139, 140, 141},\n {14, 135, 140, 141, 142},\n {15, 136, 141, 142, 143},\n {16, 137, 142, 143, 144},\n {17, 138, 143, 144, 145},\n {18, 139, 144, 145, 146},\n {19, 140, 145, 146, 147},\n {20, 141, 146, 147, 148},\n {21, 142, 147, 148, 149},\n {22, 143, 148, 149, 150},\n {23, 144, 149, 150, 151},\n {24, 145, 150, 151, 152},\n {25, 146, 151, 152, 153},\n {26, 147, 152, 153, 154},\n {27, 148, 153, 154, 155},\n {28, 149, 154, 155, 156},\n {29, 150, 155, 156, 157},\n {30, 151, 156, 157, 158},\n {31, 152, 157, 158, 159},\n {32, 153, 158, 159, 160},\n {33, 154, 159, 160, 161},\n {34, 155, 160, 161, 162},\n {35, 156, 161, 162, 163},\n {36, 157, 162, 163, 164},\n {37, 158, 163, 164, 165},\n {38, 159, 164, 165, 166},\n {39, 160, 165, 166, 167},\n {40, 161, 166, 167, 168},\n {41, 162, 167, 168, 169},\n {42, 163, 168, 169, 170},\n {43, 164, 169, 170, 171},\n {44, 165, 170, 171, 172},\n {45, 166, 171, 172, 173},\n {46, 167, 172, 173, 174},\n {47, 168, 173, 174, 175},\n {48, 169, 174, 175, 176},\n {49, 170, 175, 176, 177},\n {50, 171, 176, 177, 178},\n {51, 172, 177, 178, 179},\n {52, 173, 178, 179, 180},\n {53, 174, 179, 180, 181},\n {54, 175, 180, 181, 182},\n {55, 176, 181, 182, 183},\n {56, 177, 182, 183, 184},\n {57, 178, 183, 184, 185},\n {58, 179, 184, 185, 186},\n {59, 180, 185, 186, 187},\n {60, 181, 186, 187, 188},\n {61, 182, 187, 188, 189},\n {62, 183, 188, 189, 190},\n {63, 184, 189, 190, 191},\n {64, 185, 190, 191, 192},\n {65, 186, 191, 192, 193},\n {66, 187, 192, 193, 194},\n {67, 188, 193, 194, 195},\n {68, 189, 194, 195, 196},\n {69, 190, 195, 196, 197},\n {70, 191, 196, 197, 198},\n {71, 192, 197, 198, 199},\n {72, 193, 198, 199, 200},\n {73, 194, 199, 200, 201},\n {74, 195, 200, 201, 202},\n {75, 196, 201, 202, 203},\n {76, 197, 202, 203, 204},\n {77, 198, 203, 204, 205},\n {78, 199, 204, 205, 206},\n {79, 200, 205, 206, 207},\n {80, 201, 206, 207, 208},\n {81, 202, 207, 208, 209},\n {82, 203, 208, 209, 210},\n {83, 204, 209, 210, 211},\n {84, 205, 210, 211, 212},\n {85, 206, 211, 212, 213},\n {86, 207, 212, 213, 214},\n {87, 208, 213, 214, 215},\n {88, 209, 214, 215, 216},\n {89, 210, 215, 216, 217},\n {90, 211, 216, 217, 218},\n {91, 212, 217, 218, 219},\n {92, 213, 218, 219, 220},\n {93, 214, 219, 220, 221},\n {94, 215, 220, 221, 222},\n {95, 216, 221, 222, 223},\n {96, 217, 222, 223, 224},\n {97, 218, 223, 224, 225},\n {98, 219, 224, 225, 226},\n {99, 220, 225, 226, 227},\n {100, 221, 226, 227, 228},\n {101, 222, 227, 228, 229},\n {102, 223, 228, 229, 230},\n {103, 224, 229, 230, 231},\n {104, 225, 230, 231, 232},\n {105, 226, 231, 232, 233},\n {106, 227, 232, 233, 234},\n {107, 228, 233, 234, 235},\n {108, 229, 234, 235, 236},\n {109, 230, 235, 236, 237},\n {110, 231, 236, 237, 238},\n {111, 232, 237, 238, 239},\n {112, 233, 238, 239, 240},\n {113, 234, 239, 240, 241},\n {114, 235, 240, 241, 242},\n {115, 236, 241, 242, 243},\n {116, 237, 242, 243, 244},\n {117, 238, 243, 244, 245},\n {118, 239, 244, 245, 246},\n {119, 240, 245, 246, 247},\n {120, 241, 246, 247, 248},\n {121, 242, 247, 248, 249},\n {122, 243, 248, 249, 250},\n {123, 244, 249, 250, 251},\n {124, 245, 250, 251, 252},\n {125, 246, 251, 252, 253},\n {126, 247, 252, 253, 254},\n {127, 248, 253, 254},\n };\n gf2k_mul(c.data(), a.data(), b.data(), taps, 128);\n }\n\n // Performs field multiplication in GF2^k using a sparse matrix datastructure.\n void gf2k_mul(BitW c[/*w*/], const BitW a[/*w*/], const BitW b[/*w*/],\n const std::vector M[], size_t w) const {\n std::vector t(w * 2);\n gf2_polynomial_multiplier_karat(w, t.data(), a, b);\n\n std::vector tmp(w);\n for (size_t i = 0; i < w; ++i) {\n size_t n = 0;\n for (auto ti : M[i]) {\n tmp[n++] = t[ti];\n }\n c[i] = parity(0, n, tmp.data());\n }\n }\n\n // a == 0\n BitW eq0(size_t w, const BitW a[/*w*/]) const { return eq0(0, w, a); }\n\n // a == b\n BitW eq(size_t w, const BitW a[/*w*/], const BitW b[/*w*/]) const {\n return eq_reduce(0, w, a, b);\n }\n\n // a < b.\n // Specialization of the subtractor for the case (a - b) < 0\n BitW lt(size_t w, const BitW a[/*w*/], const BitW b[/*w*/]) const {\n if (w == 0) {\n return bit(0);\n } else {\n BitW xeq, xlt;\n lt_reduce(0, w, &xeq, &xlt, a, b);\n return xlt;\n }\n }\n\n // a <= b\n BitW leq(size_t w, const BitW a[/*w*/], const BitW b[/*w*/]) const {\n auto blt = lt(w, b, a);\n return lnot(blt);\n }\n\n // Parallel prefix of various kinds\n template \n void scan(const std::function& op, T x[],\n size_t i0, size_t i1, bool backward = false) const {\n // generic Sklansky scan\n if (i1 - i0 > 1) {\n size_t im = i0 + (i1 - i0) / 2;\n scan(op, x, i0, im, backward);\n scan(op, x, im, i1, backward);\n if (backward) {\n for (size_t i = i0; i < im; ++i) {\n op(&x[i], x[i], x[im]);\n }\n } else {\n for (size_t i = im; i < i1; ++i) {\n op(&x[i], x[im - 1], x[i]);\n }\n }\n }\n }\n\n void scan_and(BitW x[], size_t i0, size_t i1, bool backward = false) const {\n scan(\n [&](BitW* out, const BitW& l, const BitW& r) { *out = land(&l, r); }, x,\n i0, i1, backward);\n }\n\n void scan_or(BitW x[], size_t i0, size_t i1, bool backward = false) const {\n scan(\n [&](BitW* out, const BitW& l, const BitW& r) { *out = lor(&l, r); }, x,\n i0, i1, backward);\n }\n\n void scan_xor(BitW x[], size_t i0, size_t i1, bool backward = false) const {\n scan(\n [&](BitW* out, const BitW& l, const BitW& r) { *out = lxor(&l, r); }, x,\n i0, i1, backward);\n }\n\n template \n bitvec slice(const bitvec& a) const {\n bitvec r;\n for (size_t i = I0; i < I1; ++i) {\n r[i - I0] = a[i];\n }\n return r;\n }\n\n // Little-endian append of A and B. A[0] is the LSB, B starts at\n // position [NA].\n template \n bitvec vappend(const bitvec& a, const bitvec& b) const {\n bitvec r;\n for (size_t i = 0; i < NA; ++i) {\n r[i] = a[i];\n }\n for (size_t i = 0; i < NB; ++i) {\n r[i + NA] = b[i];\n }\n return r;\n }\n\n template \n bool vequal(const bitvec* a, const bitvec& b) const {\n for (size_t i = 0; i < N; ++i) {\n auto eai = eval((*a)[i]);\n auto ebi = eval(b[i]);\n if (eai != ebi) return false;\n }\n return true;\n }\n\n template \n bitvec vbit(uint64_t x) const {\n bitvec r;\n bits(N, r.data(), x);\n return r;\n }\n\n // shorthands for the silly \"template\" notation\n v8 vbit8(uint64_t x) const { return vbit<8>(x); }\n v32 vbit32(uint64_t x) const { return vbit<32>(x); }\n\n template \n bitvec vnot(const bitvec& x) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = lnot(x[i]);\n }\n return r;\n }\n\n template \n bitvec vand(const bitvec* a, const bitvec& b) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = land(&(*a)[i], b[i]);\n }\n return r;\n }\n\n template \n bitvec vand(const BitW* a, const bitvec& b) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = land(a, b[i]);\n }\n return r;\n }\n\n template \n bitvec vor(const bitvec* a, const bitvec& b) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = lor(&(*a)[i], b[i]);\n }\n return r;\n }\n template \n bitvec vor_exclusive(const bitvec* a, const bitvec& b) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = lor_exclusive(&(*a)[i], b[i]);\n }\n return r;\n }\n template \n bitvec vxor(const bitvec* a, const bitvec& b) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = lxor(&(*a)[i], b[i]);\n }\n return r;\n }\n\n template \n bitvec vCh(const bitvec* x, const bitvec* y,\n const bitvec& z) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = lCh(&(*x)[i], &(*y)[i], z[i]);\n }\n return r;\n }\n template \n bitvec vMaj(const bitvec* x, const bitvec* y,\n const bitvec& z) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = lMaj(&(*x)[i], &(*y)[i], z[i]);\n }\n return r;\n }\n\n template \n bitvec vxor3(const bitvec* x, const bitvec* y,\n const bitvec& z) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = lxor3(&(*x)[i], &(*y)[i], z[i]);\n }\n return r;\n }\n\n template \n bitvec vshr(const bitvec& a, size_t shift, size_t b = 0) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n if (i + shift < N) {\n r[i] = a[i + shift];\n } else {\n r[i] = bit(b);\n }\n }\n return r;\n }\n\n template \n bitvec vshl(const bitvec& a, size_t shift, size_t b = 0) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n if (i >= shift) {\n r[i] = a[i - shift];\n } else {\n r[i] = bit(b);\n }\n }\n return r;\n }\n\n template \n bitvec vrotr(const bitvec& a, size_t b) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = a[(i + b) % N];\n }\n return r;\n }\n\n template \n bitvec vrotl(const bitvec& a, size_t b) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[(i + b) % N] = a[i];\n }\n return r;\n }\n\n template \n bitvec vadd(const bitvec& a, const bitvec& b) const {\n bitvec r;\n (void)parallel_prefix_add(N, &r[0], &a[0], &b[0]);\n return r;\n }\n template \n bitvec vadd(const bitvec& a, uint64_t val) const {\n return vadd(a, vbit(val));\n }\n\n template \n BitW veq(const bitvec& a, const bitvec& b) const {\n return eq(N, a.data(), b.data());\n }\n template \n BitW veq(const bitvec& a, uint64_t val) const {\n auto v = vbit(val);\n return veq(a, v);\n }\n template \n BitW vlt(const bitvec* a, const bitvec& b) const {\n return lt(N, (*a).data(), b.data());\n }\n template \n BitW vlt(const bitvec& a, uint64_t val) const {\n auto v = vbit(val);\n return vlt(&a, v);\n }\n template \n BitW vlt(uint64_t a, const bitvec& b) const {\n auto va = vbit(a);\n return vlt(&va, b);\n }\n template \n BitW vleq(const bitvec* a, const bitvec& b) const {\n return leq(N, (*a).data(), b.data());\n }\n template \n BitW vleq(const bitvec& a, uint64_t val) const {\n auto v = vbit(val);\n return vleq(&a, v);\n }\n\n // (a ^ val) & mask == 0\n template \n BitW veqmask(const bitvec* a, uint64_t mask, const bitvec& val) const {\n auto r = vxor(a, val);\n size_t n = pack(mask, N, &r[0]);\n return eq0(0, n, &r[0]);\n }\n\n template \n BitW veqmask(const bitvec& a, uint64_t mask, uint64_t val) const {\n auto v = vbit(val);\n return veqmask(&a, mask, v);\n }\n\n // I/O. This is a hack which only works if the backend supports\n // bk_->{input,output}. Because C++ templates are lazily expanded,\n // this class compiles even with backends that do not support I/O,\n // as long as you don't expand vinput(), voutput().\n BitW input() const { return BitW(bk_->input(), f_); }\n void output(const BitW& x, size_t i) const { bk_->output(eval(x), i); }\n size_t wire_id(const BitW& v) const { return bk_->wire_id(v.x); }\n size_t wire_id(const EltW& x) const { return bk_->wire_id(x); }\n\n template \n bitvec vinput() const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = input();\n }\n return r;\n }\n\n template \n void voutput(const bitvec& x, size_t i0) const {\n for (size_t i = 0; i < N; ++i) {\n output(x[i], i + i0);\n }\n }\n\n template \n void vassert0(const bitvec& x) const {\n for (size_t i = 0; i < N; ++i) {\n (void)assert0(x[i]);\n }\n }\n\n template \n void vassert_eq(const bitvec* x, const bitvec& y) const {\n for (size_t i = 0; i < N; ++i) {\n (void)assert_eq(&(*x)[i], y[i]);\n }\n }\n\n template \n void vassert_eq(const bitvec& x, uint64_t y) const {\n auto v = vbit(y);\n vassert_eq(&x, v);\n }\n\n template \n void vassert_is_bit(const bitvec& a) const {\n for (size_t i = 0; i < N; ++i) {\n (void)assert_is_bit(a[i]);\n }\n }\n\n private:\n // return one quad gate for the product eval(a)*eval(b),\n // optimizing some \"obvious\" cases.\n BitW mulv(const BitW* a, const BitW& b) const {\n if (a->c1 == zero()) {\n return rebase(zero(), a->c0, b);\n } else if (b.c1 == zero()) {\n return mulv(&b, *a);\n } else {\n // Avoid creating the intermediate term 1 * a.x * b.x which is\n // likely a useless node. Moreover, two nodes (k1 * a.x * b.x)\n // and (k2 * a.x * b.x) will detect the common subexpression\n // (a.x * b.x), which will confusingly increment the\n // common-subexpression counter.\n EltW x = axy(mulf(a->c1, b.c1), &a->x, b.x);\n x = axpy(&x, mulf(a->c0, b.c1), b.x);\n x = axpy(&x, mulf(a->c1, b.c0), a->x);\n x = apy(x, mulf(a->c0, b.c0));\n return BitW(x, f_);\n }\n }\n\n BitW addv(const BitW& a, const BitW& b) const {\n if (a.c1 == zero()) {\n return BitW(addf(a.c0, b.c0), b.c1, b.x);\n } else if (b.c1 == zero()) {\n return addv(b, a);\n } else {\n EltW x = ax(a.c1, a.x);\n auto axb = ax(b.c1, b.x);\n x = add(&x, axb);\n x = apy(x, addf(a.c0, b.c0));\n return BitW(x, f_);\n }\n }\n\n BitW lxor_aux(const BitW& a, const BitW& b, PrimeFieldTypeTag tt) const {\n // a * b in the xor basis TRUE -> -1, FALSE -> 1\n // map a, b from standard basis to xor basis\n Elt mtwo = f_.negf(f_.two());\n Elt half = f_.half();\n Elt mhalf = f_.negf(half);\n\n BitW a1 = rebase(one(), mtwo, a);\n BitW b1 = rebase(one(), mtwo, b);\n BitW p = mulv(&a1, b1);\n return rebase(half, mhalf, p);\n }\n BitW lxor_aux(const BitW& a, const BitW& b, BinaryFieldTypeTag tt) const {\n return addv(a, b);\n }\n\n\n size_t pack(uint64_t mask, size_t n, BitW a[/*n*/]) const {\n size_t j = 0;\n for (size_t i = 0; i < n; ++i) {\n if (mask & 1) {\n a[j++] = a[i];\n }\n mask >>= 1;\n }\n return j;\n }\n\n // carry-propagation equations\n // (g0, p0) + (g1, p1) = (g1 | (g0 & p1), p0 & p1)\n // Accumulate in-place into (g1, p1).\n //\n // We use the property that g1 and p1 are mutually exclusive (g1&p1\n // is false), and therefore g1 and (g0 & p1) are also mutually\n // exclusive.\n void gp_reduce(const BitW& g0, const BitW& p0, BitW* g1, BitW* p1) const {\n auto g0p1 = land(&g0, *p1);\n *g1 = lor_exclusive(g1, g0p1);\n *p1 = land(&p0, *p1);\n }\n\n // ripple carry propagation\n void ripple_scan(std::vector& g, std::vector& p, size_t i0,\n size_t i1) const {\n for (size_t i = i0 + 1; i < i1; ++i) {\n gp_reduce(g[i - 1], p[i - 1], &g[i], &p[i]);\n }\n }\n\n // parallel-prefix carry propagation, Sklansky-style [1960]\n void sklansky_scan(std::vector& g, std::vector& p, size_t i0,\n size_t i1) const {\n if (i1 - i0 > 1) {\n size_t im = i0 + (i1 - i0) / 2;\n sklansky_scan(g, p, i0, im);\n sklansky_scan(g, p, im, i1);\n for (size_t i = im; i < i1; ++i) {\n gp_reduce(g[im - 1], p[im - 1], &g[i], &p[i]);\n }\n }\n }\n\n // generic add in generate/propagate form, parametrized\n // by the scan primitive.\n //\n // (carry, c) = a + b\n BitW generic_gp_add(size_t w, BitW c[/*w*/], const BitW a[/*w*/],\n const BitW b[/*w*/],\n void (Logic::*scan)(std::vector& /*g*/,\n std::vector& /*p*/,\n size_t /*i0*/, size_t /*i1*/)\n const) const {\n if (w == 0) {\n return bit(0);\n } else {\n std::vector g(w), p(w);\n for (size_t i = 0; i < w; ++i) {\n g[i] = land(&a[i], b[i]);\n p[i] = lxor(&a[i], b[i]);\n c[i] = p[i];\n }\n (this->*scan)(g, p, 0, w);\n for (size_t i = 1; i < w; ++i) {\n c[i] = lxor(&c[i], g[i - 1]);\n }\n return g[w - 1];\n }\n }\n\n BitW generic_gp_sub(size_t w, BitW c[/*w*/], const BitW a[/*w*/],\n const BitW b[/*w*/],\n void (Logic::*scan)(std::vector& /*g*/,\n std::vector& /*p*/,\n size_t /*i0*/, size_t /*i1*/)\n const) const {\n // implement as ~(~a + b)\n std::vector t(w);\n for (size_t j = 0; j < w; ++j) {\n t[j] = lnot(a[j]);\n }\n BitW carry = generic_gp_add(w, c, t.data(), b, scan);\n for (size_t j = 0; j < w; ++j) {\n c[j] = lnot(c[j]);\n }\n return carry;\n }\n\n // Recursion for the a < b comparison.\n // Let a = (a1, a0) and b = (b1, b0). Then:\n //\n // a == b iff a1 == b1 && a0 == b0\n // a < b iff a1 < b1 || (a1 == b1 && a0 < b0)\n void lt_reduce(size_t i0, size_t i1, BitW* xeq, BitW* xlt,\n const BitW a[/*w*/], const BitW b[/*w*/]) const {\n if (i1 - i0 > 1) {\n BitW eq0, eq1, lt0, lt1;\n size_t im = i0 + (i1 - i0) / 2;\n lt_reduce(i0, im, &eq0, <0, a, b);\n lt_reduce(im, i1, &eq1, <1, a, b);\n *xeq = land(&eq1, eq0);\n auto lt0_and_eq1 = land(&eq1, lt0);\n *xlt = lor_exclusive(<1, lt0_and_eq1);\n } else {\n auto axb = lxor(&a[i0], b[i0]);\n *xeq = lnot(axb);\n auto na = lnot(a[i0]);\n *xlt = land(&na, b[i0]);\n }\n }\n\n BitW parity(size_t i0, size_t i1, const BitW a[]) const {\n if (i1 <= i0) {\n return bit(0);\n } else if (i1 == i0 + 1) {\n return a[i0];\n } else {\n size_t im = i0 + (i1 - i0) / 2;\n auto lp = parity(i0, im, a);\n auto rp = parity(im, i1, a);\n return lxor(&lp, rp);\n }\n }\n\n BitW eq0(size_t i0, size_t i1, const BitW a[]) const {\n if (i1 <= i0) {\n return bit(1);\n } else if (i1 == i0 + 1) {\n return lnot(a[i0]);\n } else {\n size_t im = i0 + (i1 - i0) / 2;\n auto le = eq0(i0, im, a);\n auto re = eq0(im, i1, a);\n return land(&le, re);\n }\n }\n\n BitW eq_reduce(size_t i0, size_t i1, const BitW a[], const BitW b[]) const {\n if (i1 <= i0) {\n return bit(1);\n } else if (i1 == i0 + 1) {\n return lnot(lxor(&a[i0], b[i0]));\n } else {\n size_t im = i0 + (i1 - i0) / 2;\n auto le = eq_reduce(i0, im, a, b);\n auto re = eq_reduce(im, i1, a, b);\n return land(&le, re);\n }\n }\n\n const Backend* bk_;\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_LOGIC_H_\n"], ["/longfellow-zk/lib/circuits/logic/bit_plucker.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_PLUCKER_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_PLUCKER_H_\n\n#include \n\n#include \n#include \n\n#include \"algebra/interpolation.h\"\n#include \"algebra/poly.h\"\n#include \"circuits/logic/bit_plucker_constants.h\"\n#include \"circuits/logic/polynomial.h\"\n\nnamespace proofs {\n/*\n\nMany circuits we design require bit inputs in {0,1} when the field F takes 128+\nbits to represent. Each input to a circuit is an element in F, and must either\nbe sent to the verifier or committed, and thus sending several single-bit\ninputs represents an overhead.\n\nA bit-plucker is a circuit component that maps a set\nS \\subset F of size 2^k into k wires, b_0, ..., b_k-1, that are each in {0,1}.\nThus, it can reduce the number of inputs that a predicate circuit requires, and\nthus makes the proof smaller or more efficient to compute or verify.\n\nThe optimal bit-plucker for k bits depends on k. For small k, the simplest\nbit plucker is sufficient. In some cases, bit pluckers can exploit the field\nstructure.\n\n[ RUN ] BitPlucker.PluckSize\npluck[1]: depth: 3 wires: 6 in: 2 out:2 use:4 ovh:2 t:6 cse:0 notn:9\npluck[2]: depth: 4 wires: 14 in: 2 out:4 use:9 ovh:5 t:18 cse:5 notn:19\npluck[3]: depth: 5 wires: 25 in: 2 out:6 use:17 ovh:8 t:38 cse:23 notn:40\npluck[4]: depth: 6 wires: 40 in: 2 out:8 use:29 ovh:11 t:74 cse:73 notn:87\npluck[5]: depth: 7 wires: 61 in: 2 out:10 use:47 ovh:14 t:144 cse:199 notn:194\npluck[6]: depth: 8 wires: 92 in: 2 out:12 use:75 ovh:17 t:288 cse:501 notn:437\npluck[7]: depth: 9 wires: 141 in: 2 out:14 use:121 ovh:20 t:594 cse:1203 notn:984\npluck[8]: depth: 10 wires: 224 in: 2 out:16 use:201 ovh:23 t:1254 cse:2801 notn:2203\n\nOur experiments also considered an O(N)-wires, O(N)-terms bit plucker.\nTo pluck a LOGN-bit quantity E, write E = N0*E1 + E0 where E0 is a\nLOGN0-bit quantity and where E1 is a LOGN1-bit quantity, and where\nLOGN0 = ceil(LOGN/2), LOGN1 = floor(LOGN/2). This decomposition\ncan be computed by interpolating two Polynomials of length N. Now\nwe are left with plucking two quantities E0, E1, which can be done\nby any subquadratic-time plucker.\n\nA similar idea for the LOGN -> N binary decoder is in Knuth 7.1.2\nExercise 39. (A plucker is the moral transpose of the binary\ndecoder.)\n\nHowever, this plucker was dominated by the smaller one for our use case, and\nthus removed from the code here. It can be resurrected from experimental if\nneeded.\n\n[ RUN ] BitPlucker.LargePluckSize\nlarge_pluck[2] depth: 5 wires: 15 in: 2 out:4 use:9 ovh:6 t:19 cse:9 notn:27\nlarge_pluck[3] depth: 7 wires: 31 in: 2 out:5 use:20 ovh:11 t:43 cse:19 notn:50\nlarge_pluck[4] depth: 8 wires: 46 in: 2 out:8 use:33 ovh:13 t:70 cse:33 notn:89\nlarge_pluck[5] depth: 10 wires: 79 in: 2 out:8 use:60 ovh:19 t:128 cse:68 notn:164\nlarge_pluck[6] depth: 11 wires: 119 in: 2 out:12 use:99 ovh:20 t:209 cse:119 notn:299\nlarge_pluck[7] depth: 13 wires: 206 in: 2 out:11 use:179 ovh:27 t:381 cse:234 notn:567\nlarge_pluck[8] depth: 14 wires: 344 in: 2 out:16 use:317 ovh:27 t:668 cse:413 notn:1065\nlarge_pluck[9] depth: 16 wires: 631 in: 2 out:14 use:596 ovh:35 t:1260 cse:796 notn:2064\nlarge_pluck[10] depth: 17 wires: 1157 in: 2 out:20 use:1123 ovh:34 t:2347 cse:1435 notn:3967\nlarge_pluck[11] depth: 19 wires: 2224 in: 2 out:17 use:2181 ovh:43 t:4551 cse:2762 notn:7789\nlarge_pluck[12] depth: 20 wires: 4294 in: 2 out:24 use:4253 ovh:41 t:8782 cse:5113 notn:15205\n\n*/\ntemplate \nclass BitPlucker {\n public:\n static constexpr size_t kN = 1 << LOGN;\n static constexpr size_t kNv32Elts = (32u + LOGN - 1u) / LOGN;\n static constexpr size_t kNv256Elts = (256u + LOGN - 1u) / LOGN;\n static constexpr size_t kNv128Elts = (128u + LOGN - 1u) / LOGN;\n using Field = typename Logic::Field;\n using BitW = typename Logic::BitW;\n using EltW = typename Logic::EltW;\n using Elt = typename Field::Elt;\n using PolyN = Poly;\n using InterpolationN = Interpolation;\n using v32 = typename Logic::v32;\n using v256 = typename Logic::v256;\n using packed_v32 = std::array;\n using packed_v128 = std::array;\n using packed_v256 = std::array;\n\n const Logic& l_;\n std::vector plucker_;\n\n explicit BitPlucker(const Logic& l) : l_(l), plucker_(LOGN) {\n // evaluation points\n PolyN X;\n for (size_t i = 0; i < kN; ++i) {\n X[i] = bit_plucker_point()(i, l_.f_);\n }\n for (size_t k = 0; k < LOGN; ++k) {\n PolyN Y;\n for (size_t i = 0; i < kN; ++i) {\n Y[i] = l_.f_.of_scalar((i >> k) & 1);\n }\n plucker_[k] = InterpolationN::monomial_of_lagrange(Y, X, l_.f_);\n }\n }\n\n typename Logic::template bitvec pluck(const EltW& e) const {\n typename Logic::template bitvec r;\n const Logic& L = l_; // shorthand\n const Polynomial P(L);\n\n for (size_t k = 0; k < LOGN; ++k) {\n EltW v = P.eval(plucker_[k], e);\n L.assert_is_bit(v);\n r[k] = BitW(v, l_.f_);\n }\n\n return r;\n }\n\n v32 unpack_v32(const packed_v32& v) const {\n v32 r;\n for (size_t i = 0; i < v.size(); ++i) {\n auto b = pluck(v[i]);\n for (size_t j = 0; j < LOGN; ++j) {\n if (LOGN * i + j < 32) {\n r[LOGN * i + j] = b[j];\n }\n }\n }\n return r;\n }\n\n\n template \n T unpack(const PackedT& v) const {\n T r;\n for (size_t i = 0; i < v.size(); ++i) {\n auto b = pluck(v[i]);\n for (size_t j = 0; j < LOGN; ++j) {\n if (LOGN * i + j < r.size()) {\n r[LOGN * i + j] = b[j];\n }\n }\n }\n return r;\n }\n};\n\n/*\nOn input Elt ind, and Elt arr[], returns arr[ind].\nThis muxer is useful when the same array needs to be muxed multiple times\nwith different indices. It differs from the above classes in that it\nprecomputes the coefficient array, which can depend on EltW inputs.\n*/\ntemplate \nclass EltMuxer {\n static constexpr size_t kN = 1 << LOGN;\n\n public:\n using Field = typename Logic::Field;\n using EltW = typename Logic::EltW;\n using PolyN = Poly;\n using InterpolationN = Interpolation;\n\n EltMuxer(const Logic& l, const EltW arr[/* kN */]) : l_(l), coeff_(kN) {\n for (size_t i = 0; i < kN; ++i) {\n coeff_[i] = l_.konst(0);\n }\n for (size_t i = 0; i < kN; ++i) {\n PolyN basis_i = even_lagrange_basis(i);\n for (size_t j = 0; j < kN; ++j) {\n auto bi = l_.konst(basis_i[j]);\n auto barr_i = l_.mul(&bi, arr[i]);\n coeff_[j] = l_.add(&coeff_[j], barr_i);\n }\n }\n }\n\n EltW mux(const EltW& ind) const {\n const Polynomial P(l_);\n\n std::array xi;\n P.powers_of_x(kN, xi.data(), ind);\n\n // dot product with coefficients\n EltW r = l_.konst(0);\n for (size_t i = 0; i < kN; ++i) {\n auto cxi = l_.mul(&coeff_[i], xi[i]);\n r = l_.add(&r, cxi);\n }\n return r;\n }\n\n private:\n const Logic& l_;\n std::vector coeff_;\n\n PolyN even_lagrange_basis(size_t k) {\n PolyN X, Y;\n for (size_t i = 0; i < kN; ++i) {\n X[i] = bit_plucker_point()(i, l_.f_);\n Y[i] = l_.f_.of_scalar((i == k));\n }\n return InterpolationN::monomial_of_lagrange(Y, X, l_.f_);\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_PLUCKER_H_\n"], ["/longfellow-zk/lib/circuits/sha3/sha3_circuit.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA3_SHA3_CIRCUIT_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA3_SHA3_CIRCUIT_H_\n\n// arithmetized sha3 using logic bitvectors\n#include \n\n#include \n\n#include \"circuits/sha3/sha3_round_constants.h\"\n\nnamespace proofs {\ntemplate \nclass Sha3Circuit {\n typedef typename LogicCircuit::template bitvec<64> v64;\n\n const LogicCircuit& lc_;\n\n v64 of_scalar(uint64_t x) const { return lc_.template vbit<64>(x); }\n\n public:\n explicit Sha3Circuit(const LogicCircuit& lc) : lc_(lc) {}\n\n void keccak_f_1600(v64 A[5][5]) {\n for (size_t round = 0; round < 24; ++round) {\n // FIPS 202 3.2.1, theta\n v64 C[5];\n for (size_t x = 0; x < 5; ++x) {\n auto a01 = lc_.vxor(&A[x][0], A[x][1]);\n auto a23 = lc_.vxor(&A[x][2], A[x][3]);\n C[x] = lc_.vxor(&a01, lc_.vxor(&a23, A[x][4]));\n }\n\n for (size_t x = 0; x < 5; ++x) {\n v64 D_x = lc_.vxor(&C[(x + 4) % 5], lc_.vrotl(C[(x + 1) % 5], 1));\n for (size_t y = 0; y < 5; ++y) {\n A[x][y] = lc_.vxor(&A[x][y], D_x);\n }\n }\n\n // FIPS 202 3.2.2, rho\n {\n size_t x = 1, y = 0;\n for (size_t t = 0; t < 24; ++t) {\n A[x][y] = lc_.vrotl(A[x][y], sha3_rotc[t]);\n size_t nx = y, ny = (2 * x + 3 * y) % 5;\n x = nx;\n y = ny;\n }\n }\n\n // FIPS 202 3.2.3, pi\n v64 A1[5][5];\n for (size_t x = 0; x < 5; ++x) {\n for (size_t y = 0; y < 5; ++y) {\n A1[x][y] = A[(x + 3 * y) % 5][x];\n }\n }\n\n // FIPS 202 3.2.4, chi\n for (size_t x = 0; x < 5; ++x) {\n for (size_t y = 0; y < 5; ++y) {\n A[x][y] = lc_.vxor(&A1[x][y], lc_.vand(&A1[(x + 2) % 5][y],\n lc_.vnot(A1[(x + 1) % 5][y])));\n }\n }\n\n // FIPS 202 3.2.5, iota\n A[0][0] = lc_.vxor(&A[0][0], of_scalar(sha3_rc[round]));\n }\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA3_SHA3_CIRCUIT_H_\n"], ["/longfellow-zk/lib/proto/circuit.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_PROTO_CIRCUIT_H_\n#define PRIVACY_PROOFS_ZK_LIB_PROTO_CIRCUIT_H_\n\n#include \n\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#include \"algebra/hash.h\"\n#include \"sumcheck/circuit.h\"\n#include \"sumcheck/quad.h\"\n#include \"util/ceildiv.h\"\n#include \"util/panic.h\"\n#include \"util/readbuffer.h\"\n\nnamespace proofs {\n\n// CircuitRep class handles custom circuit serialization.\n//\n// We expect circuits to be created and stored locally by the prover and\n// verifier respectively. The byte representations are thus assumed to be\n// trusted. As a result, the methods below perform only basic sanity checking.\n//\n// An earlier experiment implemented the IO methods using protobuf parsing.\n// Despite applying techniques like arena allocation, those methods required\n// several seconds to deserialize the circuit. In contrast, these methods take\n// 100s of ms.\n//\n// This class implements an optimization by which internal indices for\n// wire and gate labels and circuit size statistics are stored in a configurable\n// number of bytes (kBytesWritten) which we set to 4 instead of 8 to save\n// space. If this value is set to >4, there is a possibility of failure on\n// 32b platforms, which currently stops execution. Thus, all circuits must be\n// tested on 32b platforms to ensure they are small enough to work.\nenum FieldID {\n NONE = 0,\n P256_ID = 1,\n P384_ID = 2,\n P521_ID = 3,\n GF2_128_ID = 4,\n GF2_16_ID = 5,\n FP128_ID = 6,\n FP64_ID = 7,\n GOLDI_ID = 8,\n FP64_2_ID = 9,\n SECP_ID = 10,\n};\n\ntemplate \nclass CircuitRep {\n using Elt = typename Field::Elt;\n using QuadCorner = typename Quad::quad_corner_t;\n constexpr static size_t kMaxLayers = 10000; /* deep circuits are errors */\n\n public:\n // Serialize kBytesWritten bytes of a size or index used in the circuit to\n // save space.\n static constexpr size_t kBytesWritten = 3;\n\n explicit CircuitRep(const Field& f, FieldID field_id)\n : f_(f), field_id_(field_id) {}\n\n void to_bytes(const Circuit& sc_c, std::vector& bytes) {\n EltHash eh(f_);\n bytes.push_back(0x1); // version\n serialize_field_id(bytes, field_id_);\n serialize_size(bytes, sc_c.nv);\n serialize_size(bytes, sc_c.nc);\n serialize_size(bytes, sc_c.npub_in);\n serialize_size(bytes, sc_c.subfield_boundary);\n serialize_size(bytes, sc_c.ninputs);\n serialize_size(bytes, sc_c.l.size());\n\n // Scan the circuit to generate the constant table. To keep one\n // scan, write the quad to a separate byte vector and later copy it.\n std::vector quadb;\n quadb.reserve(1 << 24);\n for (const auto& layer : sc_c.l) {\n serialize_size(quadb, layer.logw);\n serialize_size(quadb, layer.nw);\n serialize_size(quadb, layer.quad->n_);\n\n QuadCorner prevg(0), prevh0(0), prevh1(0);\n for (size_t i = 0; i < layer.quad->n_; ++i) {\n serialize_index(quadb, layer.quad->c_[i].g, prevg);\n prevg = layer.quad->c_[i].g;\n serialize_index(quadb, layer.quad->c_[i].h[0], prevh0);\n prevh0 = layer.quad->c_[i].h[0];\n serialize_index(quadb, layer.quad->c_[i].h[1], prevh1);\n prevh1 = layer.quad->c_[i].h[1];\n serialize_num(quadb, eh.kstore(layer.quad->c_[i].v));\n }\n }\n\n serialize_size(bytes, eh.constants_.size());\n for (const auto& v : eh.constants_) {\n uint8_t buf[Field::kBytes];\n f_.to_bytes_field(buf, v);\n bytes.insert(bytes.end(), buf, buf + Field::kBytes);\n }\n\n bytes.insert(bytes.end(), quadb.begin(), quadb.end());\n bytes.insert(bytes.end(), sc_c.id, sc_c.id + 32);\n }\n\n // Returns a unique_ptr or nullptr if there is an error in\n // deserializing the circuit.\n std::unique_ptr> from_bytes(ReadBuffer& buf) {\n if (!buf.have(8 * kBytesWritten + 1)) {\n return nullptr;\n }\n\n uint8_t version = *buf.next(1);\n if (version != 1) {\n return nullptr;\n }\n\n size_t fid_as_size_t = read_field_id(buf);\n size_t nv = read_size(buf);\n size_t nc = read_size(buf);\n size_t npub_in = read_size(buf);\n size_t subfield_boundary = read_size(buf);\n size_t ninputs = read_size(buf);\n size_t nl = read_size(buf);\n size_t numconst = read_size(buf);\n\n // Basic sanity checks.\n if (fid_as_size_t != static_cast(field_id_) || npub_in > ninputs ||\n subfield_boundary > ninputs || nl > kMaxLayers) {\n return nullptr;\n }\n\n // Ensure there are enough input bytes for the quad constants.\n auto need = checked_mul(numconst, Field::kBytes);\n if (!need || !buf.have(need.value())) {\n return nullptr;\n }\n\n std::vector constants(numconst);\n for (size_t i = 0; i < numconst; ++i) {\n // Fail if Elt cannot be parsed.\n auto vv = f_.of_bytes_field(buf.next(Field::kBytes));\n if (!vv.has_value()) {\n return nullptr;\n }\n constants[i] = vv.value();\n }\n\n auto c = std::make_unique>();\n *c = Circuit{\n .nv = nv,\n .logv = lg(nv),\n .nc = nc,\n .logc = lg(nc),\n .nl = nl,\n .ninputs = ninputs,\n .npub_in = npub_in,\n .subfield_boundary = subfield_boundary,\n };\n c->l.reserve(nl);\n\n size_t max_g = nv; // a starting bound on quad number\n\n for (size_t ly = 0; ly < nl; ++ly) {\n // Ensure there are enough input bytes for the layer, 3 values.\n if (!buf.have(3 * kBytesWritten)) {\n return nullptr;\n }\n\n size_t lw = read_size(buf);\n size_t nw = read_size(buf);\n size_t nq = read_size(buf);\n\n // Each quad takes 4 values, check for overflow.\n need = checked_mul(4 * kBytesWritten, nq);\n if (!need || !buf.have(need.value())) {\n return nullptr;\n }\n\n auto qq = std::make_unique>(nq);\n size_t prevg = 0, prevhl = 0, prevhr = 0;\n for (size_t i = 0; i < nq; ++i) {\n size_t g = read_index(buf, prevg);\n if (g > max_g) { // index of quad must be < wires in the layer\n return nullptr;\n }\n prevg = g;\n size_t hl = read_index(buf, prevhl);\n size_t hr = read_index(buf, prevhr);\n if (hl > nw || hr > nw) {\n return nullptr;\n }\n prevhl = hl;\n prevhr = hr;\n size_t vi = read_num(buf);\n if (vi >= numconst) {\n return nullptr;\n }\n\n qq->c_[i] = typename Quad::corner{\n QuadCorner(g), {QuadCorner(hl), QuadCorner(hr)}, constants[vi]};\n }\n c->l.push_back(Layer{\n .nw = nw,\n .logw = lw,\n .quad = std::unique_ptr>(std::move(qq))});\n max_g = nw;\n }\n // Read the circuit name from the serialization.\n if (!buf.have(32)) {\n return nullptr;\n }\n buf.next(32, c->id);\n return c;\n }\n\n private:\n static constexpr uint64_t kMaxValue = (1ULL << (kBytesWritten * 8)) - 1;\n\n // Multiplies arguments and checks for overflow.\n template \n std::optional checked_mul(T a, T b) {\n T ab = a * b;\n if (a == 0 || ab / a == b) return ab;\n return std::nullopt;\n }\n\n static void serialize_field_id(std::vector& bytes, FieldID id) {\n serialize_num(bytes, static_cast(id));\n }\n\n static void serialize_size(std::vector& bytes, size_t sz) {\n serialize_num(bytes, sz);\n }\n\n // We write indices as differences from the previous index. This\n // encoding appears to produce byte streams that compress better\n // under both gzip and xz compression. For example, xz compresses\n // a 35MB test circuit to 2MB without delta encoding, and to 100KB\n // with delta encoding. We have no real theory to explain this\n // phenomenon, but at least part of the reason is that the deltas\n // are usually smaller than the indices.\n //\n static void serialize_index(std::vector& bytes, QuadCorner ind0,\n QuadCorner prev_ind0) {\n size_t ind = static_cast(ind0);\n size_t prev_ind = static_cast(prev_ind0);\n\n // Encode the delta IND - PREV_IND. Since the delta can be\n // negative, and the rest of the code is unsigned only,\n // use the LSB as sign bit.\n if (ind >= prev_ind) {\n serialize_num(bytes, 2u * (ind - prev_ind));\n } else {\n serialize_num(bytes, 2u * (prev_ind - ind) + 1u);\n }\n }\n\n static void serialize_num(std::vector& bytes, size_t g) {\n check(g < kMaxValue, \"Violating small wire-label assumption\");\n uint8_t tmp[kBytesWritten];\n for (size_t i = 0; i < kBytesWritten; ++i) {\n tmp[i] = static_cast(g & 0xff);\n g >>= 8;\n }\n bytes.insert(bytes.end(), tmp, tmp + kBytesWritten);\n }\n\n // These routine reads bytes written by serialize_* methods, and thus\n // only needs to handle values expressed in kBytesWritten.\n // On 32b platforms, some large circuits may fail; this method\n // causes a failure in that case.\n\n // Do not cast to FieldID, since the input is untrusted and the\n // cast may fail.\n static size_t read_field_id(ReadBuffer& buf) { return read_num(buf); }\n\n static size_t read_size(ReadBuffer& buf) { return read_num(buf); }\n\n static size_t read_index(ReadBuffer& buf, size_t prev_ind) {\n size_t delta = read_num(buf);\n if (delta & 1) {\n return prev_ind - (delta >> 1);\n } else {\n return prev_ind + (delta >> 1);\n }\n }\n\n static size_t read_num(ReadBuffer& buf) {\n uint64_t r = 0;\n const uint8_t* p = buf.next(kBytesWritten);\n for (size_t i = 0; i < kBytesWritten; ++i) {\n r |= (p[i] << (i * 8));\n }\n\n // SIZE_MAX is system defined as max value for size_t.\n // This check fails if a large circuit is loaded on a 32b machine.\n check(r < SIZE_MAX, \"Violating small wire-label assumption\");\n return static_cast(r);\n }\n\n // Class that defines the hash function for Elt.\n class EHash {\n public:\n const Field& f_;\n explicit EHash(const Field& f) : f_(f) {}\n size_t operator()(const Elt& k) const { return elt_hash(k, f_); }\n };\n\n // This structure encapsulates the hash used by the compiler.\n class EltHash {\n public:\n std::vector constants_;\n\n explicit EltHash(const Field& f) : f_(f), table_(1000, EHash(f)) {}\n\n size_t kstore(const Elt& k) {\n if (auto search = table_.find(k); search != table_.end()) {\n return search->second;\n }\n\n size_t ki = constants_.size();\n constants_.push_back(k);\n table_[k] = ki;\n return ki;\n }\n\n private:\n const Field& f_;\n std::unordered_map table_;\n };\n\n const Field& f_;\n FieldID field_id_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_PROTO_CIRCUIT_H_\n"], ["/longfellow-zk/lib/circuits/compiler/compiler.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_COMPILER_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_COMPILER_H_\n\n#include \n#include \n\n#include \n#include \n#include \n\n#include \"algebra/hash.h\"\n#include \"circuits/compiler/circuit_id.h\"\n#include \"circuits/compiler/node.h\"\n#include \"circuits/compiler/pdqhash.h\"\n#include \"circuits/compiler/schedule.h\"\n#include \"sumcheck/circuit.h\"\n#include \"sumcheck/quad.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n/*\nQuadCircuit contains methods that facilitate defining circuits used to\nexpress predicates that are to be proven or verified. This class allows one\nto use basic arithmetic circuit operations (add, mul, input, assert0, ...)\nto define the circuit on a set of abstract wire labels.\n\nThe \"mkcircuit\" compiler method than optimizes the circuit by applying all of\nthe basic tricks of constant propagation, common sub-expression elimination,\nsquashing layers into as few as possible, and grouping terms into quads.\n\nQuads are a new form of gate (in contrast to the add and mul gates in most\nsumcheck proof systems). Quads represent a \"sum of quadratic terms\" where\neach term is w_l * w_r * v for two wire labels and a constant v.\n*/\ntemplate \nclass QuadCircuit {\n public:\n using Elt = typename Field::Elt;\n using nodeinfo = NodeInfoF;\n using node = NodeF;\n using size_t_for_storage = term::size_t_for_storage;\n using quad_corner_t = typename Quad::quad_corner_t;\n\n const Field& f_;\n\n public:\n // Variables for informational purposes:\n size_t ninput_;\n size_t npub_input_; // number of public inputs, index of 1st private\n size_t subfield_boundary_; // least wire not known to be in the subfield\n size_t noutput_;\n\n // set by the algebraic simplifiers in this file\n size_t depth_;\n size_t nwires_cse_eliminated_;\n size_t nwires_not_needed_;\n\n // set by the scheduler\n size_t nwires_;\n size_t nquad_terms_;\n size_t nwires_overhead_;\n\n explicit QuadCircuit(const Field& f)\n : f_(f),\n ninput_(0),\n npub_input_(0),\n subfield_boundary_(0),\n noutput_(0),\n depth_(0),\n nwires_cse_eliminated_(0),\n nwires_not_needed_(0),\n nwires_(-1), // undefined until set in mkcircuit()\n nquad_terms_(-1),\n nwires_overhead_(-1) {\n // make sure that Elt(0) is represented as index 0 in the constant\n // table.\n size_t ki0 = kstore(f.zero());\n proofs::check(ki0 == 0, \"ki0 == 0\");\n size_t ki1 = kstore(f.one());\n proofs::check(ki1 == 1, \"ki1 == 1\");\n\n // make sure node 0 exists, carrying input[0] = F.one()\n input();\n }\n\n // Produce a linear term 1 * op0 that the compiler will not\n // attempt to optimize to op0. The reason for this function\n // is to implement linear terms such as a*x in the quadratic form\n // a*x+b*x*y. Left to its own devices, the compiler peeks into x,\n // and if x=k*z*w, it produces a term (a*k)*z*w in the previous\n // layer, possibly destroying common subexpressions. linear(op)\n // introduces an explicit multiplication by wire 0, which the\n // compiler does not attempt to optimize away.\n size_t linear(size_t op0) { return mul(0, op0); }\n size_t linear(const Elt& k, size_t op0) { return mul(k, 0, op0); }\n\n size_t mul(const Elt& k, size_t op) {\n if (k == f_.zero()) {\n return konst(k);\n } else if (k == f_.one() || nodes_[op].zero()) {\n return op;\n } else {\n return push_node(scale(k, op));\n }\n }\n\n size_t mul(size_t op0, size_t op1) { return mul(f_.one(), op0, op1); }\n\n size_t mul(const Elt& k, size_t op0, size_t op1) {\n const auto& n0 = nodes_[op0];\n const auto& n1 = nodes_[op1];\n\n if (n0.zero()) {\n return op0;\n } else if (n0.constant()) {\n // k * (k1 * op1) -> (k * k1) * op1\n return mul(f_.mulf(k, kload(n0.terms[0].ki)), op1);\n } else if (n0.linearp()) {\n // k * ((k1 * op0) * op1) -> (k * k1) * op0 * op1\n return mul(f_.mulf(k, kload(n0.terms[0].ki)), n0.terms[0].op1, op1);\n } else if (n1.zero() || n1.constant() || n1.linearp()) {\n return mul(k, op1, op0);\n } else {\n // general term k * op0 * op1\n return push_node(node(kstore(k), op0, op1));\n }\n }\n\n size_t add(size_t op0, size_t op1) {\n const auto& n0 = nodes_[op0];\n const auto& n1 = nodes_[op1];\n\n if (n0.zero()) {\n return op1;\n } else if (n1.zero()) {\n return op0;\n } else {\n // If the two addends are of different depth, do not merge\n // them, which is accomplished by multiplying the shallower\n // node by 1 and treating it as a single term of the final\n // sum.\n //\n // Like many other \"optimizations\", this is a heuristic\n // that may or may not work, but it seems to be uniformly\n // beneficial or at least not harmful for all our circuits\n // as of 2023-11-15.\n if (n0.info.depth < n1.info.depth) {\n op0 = linear(op0);\n } else if (n1.info.depth < n0.info.depth) {\n op1 = linear(op1);\n }\n return push_node(merge(op0, op1));\n }\n }\n size_t sub(size_t op0, size_t op1) { return add(op0, mul(f_.mone(), op1)); }\n\n size_t konst(const Elt& k) { return push_node(node(kstore(k), 0, 0)); }\n\n // Generate a special node that asserts that op == 0.\n // The node has the form 0*(1*op), which does not normally\n // appear in circuits.\n size_t assert0(size_t op) {\n const node* n = &nodes_[op];\n if (n->zero()) {\n // Identically zero, so nothing to generate.\n // More importantly, we cannot multiply OP by 1,\n // since OP doesn't really exist.\n return op;\n } else if (n->linearp()) {\n // n = k * (1 * op1).\n //\n // Reduce to assert0(op1), but handle the screw case k==0,\n // which shouldn't happen but just in case...\n if (n->terms[0].ki == 0) {\n return op;\n } else {\n return assert0(n->terms[0].op1);\n }\n } else {\n typename term::assert0_type_hack hack;\n std::vector terms;\n terms.push_back(term(op, hack));\n size_t n1 = push_node(node(terms));\n nodes_[n1].info.is_assert0 = true;\n return n1;\n }\n }\n\n // Wrappers to avoid creating unnecessary wires. The\n // compiler will discard them anyway, but they still take\n // time and space.\n size_t axpy(size_t y, const Elt& a, size_t x) {\n if (a == f_.zero()) {\n return y;\n }\n return add(y, linear(a, x));\n }\n size_t apy(size_t y, const Elt& a) {\n if (a == f_.zero()) {\n return y;\n }\n return add(y, konst(a));\n }\n\n size_t input() { return push_node(node(quad_corner_t(ninput_++))); }\n\n // This function demarcates the end of the public inputs and beginning of\n // private inputs. It can only be called once.\n void private_input() {\n proofs::check(\n npub_input_ == 0,\n \"private_input can only be called once after setting public inputs\");\n npub_input_ = ninput_;\n }\n\n // This function demarcates the end of the private inputs in the\n // subfield and beginning of the full-field private inputs. It can\n // only be called once.\n void begin_full_field() {\n proofs::check(subfield_boundary_ == 0,\n \"begin_full_field() can only be called once\");\n subfield_boundary_ = ninput_;\n }\n\n size_t ninput() const { return ninput_; }\n\n void output(size_t n, size_t wire_id) {\n output_internal(n, quad_corner_t(wire_id));\n }\n\n std::unique_ptr> mkcircuit(size_t nc) {\n size_t depth_ub = compute_depth_ub();\n fixup_last_layer_assertions(depth_ub);\n compute_needed(depth_ub);\n\n Scheduler sched(nodes_, f_);\n std::unique_ptr> c =\n sched.mkcircuit(constants_, depth_ub, nc);\n\n // re-export the scheduler telemetry\n nwires_ = sched.nwires_;\n nquad_terms_ = sched.nquad_terms_;\n nwires_overhead_ = sched.nwires_overhead_;\n\n c->ninputs = ninput();\n c->npub_in = npub_input_;\n c->subfield_boundary = subfield_boundary_;\n\n circuit_id(c->id, *c, f_);\n return c;\n }\n\n private:\n void output_internal(size_t n, quad_corner_t wire_id) {\n nodes_[n].info.is_output = true;\n nodes_[n].info.desired_wire_id_for_output = wire_id;\n noutput_++;\n }\n\n size_t push_node(node n) {\n // common-subexpression elimination: if we have already seen a\n // node equal to n, return that node.\n uint64_t d = n.hash();\n\n auto pred = [&](PdqHash::value_t op) { return n == nodes_[op]; };\n if (size_t op = cse_.find(d, pred); op != PdqHash::kNil) {\n // do not linear terms as eliminated by the CSE, since they are\n // likely placeholder nodes absorbed by the next layer.\n if (!n.linearp()) {\n ++nwires_cse_eliminated_;\n }\n return op;\n }\n\n // compute the node depth, which has been so far uninitialized\n n.info.depth = 0;\n for (const auto& t : n.terms) {\n n.info.depth = std::max(\n n.info.depth, 1 + std::max(nodes_[t.op0].info.depth,\n nodes_[t.op1].info.depth));\n }\n\n size_t nid = nodes_.size();\n nodes_.push_back(n);\n\n // record NID into the common-subexpression elimination table\n cse_.insert(d, nid);\n\n return nid;\n }\n\n node materialize_input(size_t op) {\n if (nodes_[op].info.is_input) {\n return node(/*kstore(f.one())=*/1, 0, op);\n } else {\n return /*a copy of*/ nodes_[op];\n }\n }\n\n node scale(const Elt& k, size_t op) {\n node n = materialize_input(op);\n for (auto& t : n.terms) {\n t.ki = kstore(f_.mulf(kload(t.ki), k));\n }\n return n;\n }\n\n void push_back_unless_zero(std::vector& terms, const term& t) const {\n if (t.ki != 0) {\n terms.push_back(t);\n }\n }\n\n node merge(size_t op0, size_t op1) {\n const node n0 = materialize_input(op0);\n const node n1 = materialize_input(op1);\n const std::vector& t0 = n0.terms;\n const std::vector& t1 = n1.terms;\n std::vector terms;\n size_t i0 = 0, i1 = 0;\n while (i0 < t0.size() && i1 < t1.size()) {\n term t;\n if (t0[i0].eqndx(t1[i1])) {\n t = t0[i0];\n t.ki = kstore(f_.addf(kload(t.ki), kload(t1[i1].ki)));\n i0++;\n i1++;\n } else if (t0[i0].ltndx(t1[i1])) {\n t = t0[i0++];\n } else {\n t = t1[i1++];\n }\n push_back_unless_zero(terms, t);\n }\n\n while (i0 < t0.size()) {\n push_back_unless_zero(terms, t0[i0++]);\n }\n\n while (i1 < t1.size()) {\n push_back_unless_zero(terms, t1[i1++]);\n }\n\n return node(terms);\n }\n\n // constants_[n] stores the n-th constant, once.\n // Modulo collisions, constants_[constttab_[hash(k)]] == k\n // for k \\in Elt.\n std::vector constants_;\n PdqHash consttab_;\n\n std::vector nodes_;\n PdqHash cse_;\n\n size_t kstore(const Elt& k) {\n uint64_t d = elt_hash(k, f_);\n auto pred = [&](PdqHash::value_t ki) { return k == constants_[ki]; };\n size_t ki = consttab_.find(d, pred);\n\n if (ki == PdqHash::kNil) {\n ki = constants_.size();\n constants_.push_back(k);\n consttab_.insert(d, ki);\n }\n return ki;\n }\n Elt& kload(size_t ki) { return constants_[ki]; }\n\n void mark_needed(size_t op, size_t depth_at_which_needed) {\n nodeinfo* nfo = &nodes_[op].info;\n nfo->is_needed = true;\n nfo->max_needed_depth =\n std::max(depth_at_which_needed, nfo->max_needed_depth);\n\n // If DEPTH_AT_WHICH_NEEDED > DEPTH + 1, we need a constant 1 at\n // depth DEPTH_AT_WHICH_NEEDED-1 (and implicily any lower depths) in\n // order to copy the node across levels.\n if (depth_at_which_needed > nfo->depth + 1) {\n nodeinfo* nfo0 = &nodes_[0].info;\n nfo0->is_needed = true;\n nfo0->max_needed_depth =\n std::max(depth_at_which_needed - 1, nfo0->max_needed_depth);\n }\n }\n\n size_t compute_depth_ub() {\n size_t r = 0;\n for (auto& n : nodes_) {\n if (n.info.is_output) {\n r = std::max(r, 1 + n.info.depth);\n } else if (n.info.is_assert0) {\n // Assertions of the form 0*(1*OP) contibute n.info.depth and\n // not 1 + n.info.depth. If the assertion is in the last\n // layer, it will be transformed in an output of OP at\n // n.info.depth. If the assertion is not in the last layer,\n // then it doesn't matter whether we use DEPTH or 1 + DEPTH.\n if (n.linearp()) {\n r = std::max(r, n.info.depth);\n } else {\n r = std::max(r, 1 + n.info.depth);\n }\n }\n }\n depth_ = r;\n return r;\n }\n\n void fixup_last_layer_assertions(size_t depth_ub) {\n // convert assertions in the last layer into outputs\n for (auto& n : nodes_) {\n if (!n.info.is_output && n.info.is_assert0 && n.info.depth == depth_ub &&\n n.linearp()) {\n n.info.is_assert0 = false;\n output_internal(n.terms[0].op1, nodeinfo::kWireIdUndefined);\n }\n }\n }\n\n void compute_needed(size_t depth_ub) {\n nwires_not_needed_ = 0;\n for (size_t i = nodes_.size(); i-- > 0;) {\n nodeinfo* nfo = &nodes_[i].info;\n\n // mark all inputs as needed, to prevent ambiguity\n // in the layout of the W[] vector.\n if (nfo->is_input) {\n mark_needed(i, 1);\n }\n // outputs are needed at depth_ub_\n if (nfo->is_output) {\n mark_needed(i, depth_ub);\n }\n // assertions are needed in the next layer\n if (nfo->is_assert0) {\n mark_needed(i, nfo->depth + 1);\n }\n\n if (nfo->is_needed) {\n for (const auto& t : nodes_[i].terms) {\n mark_needed(t.op0, nfo->depth);\n mark_needed(t.op1, nfo->depth);\n }\n } else {\n ++nwires_not_needed_;\n }\n }\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_COMPILER_H_\n"], ["/longfellow-zk/lib/circuits/ecdsa/verify_witness.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ECDSA_VERIFY_WITNESS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ECDSA_VERIFY_WITNESS_H_\n\n#include \n\n#include \"algebra/utility.h\"\n#include \"arrays/dense.h\"\n#include \"util/panic.h\"\n\n/*\nMethods to help prepare witnesses for use in assertions about ecdsa.\n*/\nnamespace proofs {\n\ntemplate \nclass VerifyWitness3 {\n using Field = typename EC::Field;\n using Elt = typename Field::Elt;\n using Nat = typename Field::N;\n using Point = typename EC::ECPoint;\n using Scalar = typename ScalarField::Elt;\n\n public:\n constexpr static size_t kBits = EC::kBits;\n const ScalarField& fn_;\n const EC& ec_;\n Elt rx_, ry_;\n Elt rx_inv_;\n Elt s_inv_;\n Elt pk_inv_;\n Elt pre_[8];\n Elt bi_[kBits];\n Elt int_x_[kBits]; /* Intermediate x,y elliptic curve points */\n Elt int_y_[kBits]; /* encountered during the scalar mult loop. */\n Elt int_z_[kBits]; /* z-coordinate of the intermediate points */\n\n VerifyWitness3(const ScalarField& Fn, const EC& ec) : fn_(Fn), ec_(ec) {}\n\n void fill_witness(DenseFiller& filler) const {\n filler.push_back(rx_);\n filler.push_back(ry_);\n filler.push_back(rx_inv_);\n filler.push_back(s_inv_);\n filler.push_back(pk_inv_);\n for (size_t i = 0; i < 8; ++i) {\n filler.push_back(pre_[i]);\n }\n for (size_t i = 0; i < kBits; ++i) {\n filler.push_back(bi_[i]);\n if (i < kBits - 1) {\n filler.push_back(int_x_[i]);\n filler.push_back(int_y_[i]);\n filler.push_back(int_z_[i]);\n }\n }\n }\n\n // Produces witnesses to support the verification of the equation\n // id = g*e + pk*r + (rx,ry)*-s\n // Note that the same rx is interpreted in scalar field as r.\n bool compute_witness(const Elt pkX, const Elt pkY, const Nat e, const Nat r,\n const Nat s) {\n const Field& F = ec_.f_;\n const Scalar _s = fn_.invertf(fn_.to_montgomery(s));\n const Scalar tms = fn_.negf(fn_.to_montgomery(s));\n\n // Because Fp does not have a sqrt method, compute ry via the\n // elliptic curve point g*(e/s) + pk*(r/s).\n auto te_s = fn_.mulf(fn_.to_montgomery(e), _s);\n auto tr_s = fn_.mulf(fn_.to_montgomery(r), _s);\n const Nat nes = fn_.from_montgomery(te_s);\n const Nat nrs = fn_.from_montgomery(tr_s);\n Point bases[] = {ec_.generator(), Point(pkX, pkY, F.one())};\n Nat scalars[] = {nes, nrs};\n auto pr = ec_.scalar_multf(2, bases, scalars);\n ec_.normalize(pr);\n\n rx_ = F.to_montgomery(r);\n ry_ = pr.y;\n\n // In the case of a malicious input with rx=0 or s=0, the proof will fail.\n if (rx_ != F.zero()) {\n rx_inv_ = F.invertf(rx_);\n check(F.mulf(rx_, rx_inv_) == F.one(), \"bad inv\");\n }\n\n s_inv_ = F.to_montgomery(fn_.from_montgomery(tms));\n if (s_inv_ != F.zero()) {\n F.invert(s_inv_);\n }\n\n if (pkX != F.zero()) {\n pk_inv_ = F.invertf(pkX);\n }\n\n const Nat nms = fn_.from_montgomery(tms); /* -s */\n\n // Produce the table of pre-computed g,r,pk sums.\n const Elt one = F.one(), gX = ec_.gx_, gY = ec_.gy_;\n const Elt lh[] = {gX, gY, gX, gY, pkX, pkY};\n const Elt rh[] = {pkX, pkY, rx_, ry_, rx_, ry_};\n Elt zi;\n for (size_t i = 0; i < 3; ++i) {\n ec_.addE(pre_[2 * i], pre_[2 * i + 1], zi,\n lh[2 * i], lh[2 * i + 1], one,\n rh[2 * i], rh[2 * i + 1], one);\n\n // This invert cannot fail because both the generator and pk are\n // trusted inputs, so the above addition is not the identity.\n // In the case that it is, the proof will fail (and it should, since\n // the system is unsound with sk=-1).\n if (zi != F.zero()) {\n F.invert(zi);\n }\n F.mul(pre_[2 * i], zi);\n F.mul(pre_[2 * i + 1], zi);\n }\n // rgpk\n ec_.addE(pre_[6], pre_[7], zi, pre_[2], pre_[3], one, pkX, pkY, one);\n if (zi != F.zero()) {\n F.invert(zi);\n }\n F.mul(pre_[6], zi);\n F.mul(pre_[7], zi);\n\n Elt aX = F.zero(), aY = one, aZ = F.zero();\n\n // Compute b[], and intermediate points, encode b as:\n // 1:g 2:pk 3: gpk 4: r 5: r+g 6: r+pk 7:g+r+pk\n // Elt int_z[kBits];\n size_t b[kBits];\n // bool early_zero = false; /* indicates if any intermediate z is zero */\n for (size_t i = 0; i < kBits; ++i) {\n b[i] = e.bit(kBits - i - 1) + 2 * r.bit(kBits - i - 1) +\n 4 * nms.bit(kBits - i - 1);\n\n // Manually compute standard (-n...n representation).\n bi_[i] = F.subf(F.of_scalar(2 * b[i]), F.of_scalar(7));\n\n if (i > 0) {\n ec_.doubleE(aX, aY, aZ, aX, aY, aZ);\n }\n switch (b[i]) {\n case 0:\n ec_.addE(aX, aY, aZ, aX, aY, aZ, F.zero(), F.one(), F.zero());\n break;\n case 1:\n ec_.addE(aX, aY, aZ, aX, aY, aZ, gX, gY, one);\n break;\n case 2:\n ec_.addE(aX, aY, aZ, aX, aY, aZ, pkX, pkY, one);\n break;\n case 3:\n ec_.addE(aX, aY, aZ, aX, aY, aZ, pre_[0], pre_[1], one);\n break;\n case 4:\n ec_.addE(aX, aY, aZ, aX, aY, aZ, rx_, ry_, one);\n break;\n case 5:\n ec_.addE(aX, aY, aZ, aX, aY, aZ, pre_[2], pre_[3], one);\n break;\n case 6:\n ec_.addE(aX, aY, aZ, aX, aY, aZ, pre_[4], pre_[5], one);\n break;\n case 7:\n ec_.addE(aX, aY, aZ, aX, aY, aZ, pre_[6], pre_[7], one);\n break;\n }\n\n int_x_[i] = aX;\n int_y_[i] = aY;\n int_z_[i] = aZ;\n }\n\n if (aX != F.zero()) {\n return false;\n }\n if (aZ != F.zero()) {\n return false;\n }\n\n return true;\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ECDSA_VERIFY_WITNESS_H_\n"], ["/longfellow-zk/lib/zk/zk_common.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ZK_ZK_COMMON_H_\n#define PRIVACY_PROOFS_ZK_LIB_ZK_ZK_COMMON_H_\n\n#include \n#include \n\n#include \"arrays/dense.h\"\n#include \"arrays/eq.h\"\n#include \"arrays/eqs.h\"\n#include \"ligero/ligero_param.h\"\n#include \"random/transcript.h\"\n#include \"sumcheck/circuit.h\"\n#include \"sumcheck/quad.h\"\n#include \"sumcheck/transcript_sumcheck.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n\ntemplate \n// ZkCommon\n//\n// Used by prover and verifier to mimic the checks that the sumcheck verifier\n// applies to the sumcheck transcript. The difference is that the transcript\n// will now be encrypted with a random pad, and the checks will be verified\n// by the Ligero proof system with respect to a hiding commitment scheme.\nclass ZkCommon {\n using index_t = typename Quad::index_t;\n using Llc = LigeroLinearConstraint;\n using Elt = typename Field::Elt;\n using CPoly = typename LayerProof::CPoly;\n using WPoly = typename LayerProof::WPoly;\n\n public:\n // pi: witness index for first pad element in a larger commitment\n static size_t verifier_constraints(\n const Circuit& circuit, const Dense& pub,\n const Proof& proof, const ProofAux* aux,\n std::vector& a, std::vector& b, Transcript& tsv,\n size_t pi, const Field& F) {\n const size_t ninp = circuit.ninputs, npub = circuit.npub_in;\n\n Challenge ch(circuit.nl);\n TranscriptSumcheck tss(tsv, F);\n\n tss.begin_circuit(ch.q, ch.g);\n Claims cla = Claims{\n .logv = circuit.logv,\n .claim = {F.zero(), F.zero()},\n .q = ch.q,\n .g = {ch.g, ch.g},\n };\n\n size_t ci = 0; // Index of the next Ligero constraint.\n\n const typename WPoly::dot_interpolation dot_wpoly(F);\n\n // no copies in this version.\n check(circuit.logc == 0, \"assuming that copies=1\");\n\n // Constraints from the sumcheck verifier.\n for (size_t ly = 0; ly < circuit.nl; ++ly) {\n auto clr = &circuit.l.at(ly);\n auto plr = &proof.l[ly];\n auto challenge = &ch.l[ly];\n\n tss.begin_layer(challenge->alpha, challenge->beta, ly);\n\n // The loop below assumes at least one round.\n check(clr->logw > 0, \"clr->logw > 0\");\n\n PadLayout pl(clr->logw);\n ConstraintBuilder cb(pl, F); // representing 0\n\n cb.first(challenge->alpha, cla.claim);\n // now cb contains claim_{-1} from the previous layer\n\n for (size_t round = 0; round < clr->logw; ++round) {\n for (size_t hand = 0; hand < 2; ++hand) {\n size_t r = 2 * round + hand;\n const WPoly& hp = plr->hp[hand][round];\n challenge->hb[hand][round] = tss.round(hp);\n const WPoly lag = dot_wpoly.coef(challenge->hb[hand][round], F);\n\n cb.next(r, &lag[0], hp.t_);\n // now cb contains a symbolic representation of claim_{r}\n }\n }\n\n // Verify\n // claim = EQ[Q,C] QUAD[R,L] W[R,C] W[L,C]\n // by substituting in the symbolic constraint on p(1) from the relation:\n // claim = .\n Elt quad = aux == nullptr ? bind_quad(clr, cla, challenge, F)\n : aux->bound_quad[ly];\n Elt eqv =\n Eq::eval(circuit.logc, circuit.nc, ch.q, challenge->cb, F);\n Elt eqq = F.mulf(eqv, quad);\n\n // Add the final constraint from above.\n cb.finalize(plr->wc, eqq, ci++, ly, pi, a, b);\n\n tss.write(&plr->wc[0], 1, 2);\n\n cla = Claims{\n .logv = clr->logw,\n .claim = {plr->wc[0], plr->wc[1]},\n .q = challenge->cb,\n .g = {challenge->hb[0], challenge->hb[1]},\n };\n\n pi += pl.layer_size(); // Update index to poly_pad(0,0) of the\n // next layer\n }\n\n // Constraints induced by the input binding\n // = W_l + alpha.W_r\n Elt alpha = tsv.elt(F);\n auto plr = &proof.l[circuit.nl - 1];\n Elt got = F.addf(plr->wc[0], F.mulf(alpha, plr->wc[1]));\n\n return input_constraint(cla, pub, npub, ninp, pi, got, alpha, a, b, ci, F);\n }\n\n // Returns the size of the proof pad for circuit C.\n static size_t pad_size(const Circuit& C) {\n size_t sz = 0;\n for (size_t i = 0; i < C.nl; ++i) {\n PadLayout pl(C.l[i].logw);\n sz += pl.layer_size();\n }\n return sz;\n }\n\n // Setup lqc based on proof pad layout.\n static void setup_lqc(const Circuit& C,\n std::vector& lqc,\n size_t start_pad) {\n size_t pi = start_pad;\n for (size_t i = 0; i < C.nl; ++i) {\n PadLayout pl(C.l[i].logw);\n lqc[i].x = pi + pl.claim_pad(0);\n lqc[i].y = pi + pl.claim_pad(1);\n lqc[i].z = pi + pl.claim_pad(2);\n pi += pl.layer_size();\n }\n }\n\n // append public parameters to the FS transcript\n static void initialize_sumcheck_fiat_shamir(Transcript& ts,\n const Circuit& circuit,\n const Dense& pub,\n const Field& F) {\n ts.write(circuit.id, sizeof(circuit.id));\n\n // Public inputs:\n for (size_t i = 0; i < circuit.npub_in; ++i) {\n ts.write(pub.at(i), F);\n }\n\n // Outputs pro-forma:\n ts.write(F.zero(), F);\n\n // Enough zeroes for correlation intractability, one byte\n // per term.\n ts.write0(circuit.nterms());\n }\n\n private:\n // The claims struct mimics the same object in the sumcheck code. This\n // helps the verifier_constraints method above mimic the same steps as\n // the sumcheck verifier.\n struct Claims {\n size_t logv;\n Elt claim[2];\n const Elt* q;\n const Elt* g[2];\n };\n\n class PadLayout {\n size_t logw_;\n\n public:\n explicit PadLayout(size_t logw) : logw_(logw) {}\n\n // Layout of padding in the expr_.symbolic array.\n //\n // A *claim pad* is a triple [dWC[0], dWC[1], dWC[0]*dWC[1]].\n //\n // A *poly pad* is a pair [dP(0), dP(2)], where \"2\" is a generic\n // name for the third evaluation point of the sumcheck round\n // polynomial (could be X for binary fields GF(2)[X] / (Q(X))).\n //\n // The layout of expr_.symbolic is\n // [CLAIM_PAD[layer - 1], POLY_PAD[0], POLY_PAD[1], ..\n // POLY_PAD[LOGW - 1], CLAIM_PAD[layer]]\n //\n // The layout of adjacent layers thus overlaps. For layer 0\n // we still lay out CLAIM_PAD[layer - 1] to keep the representation\n // uniform, but we don't output the corresponding Ligero terms.\n\n // Because of different use cases, we have two indexing schemes:\n //\n // \"with overlap\": the first element is CLAIM_PAD[layer - 1][0]\n // \"without overlap\": the first element is POLY_PAD[0][0]\n\n //------------------------------------------------------------\n // Indexing without overlap.\n //------------------------------------------------------------\n size_t poly_pad(size_t r, size_t point) const {\n check(point == 0 || point == 2, \"unknown poly_pad() layout\");\n if (point == 0) {\n return 2 * r;\n } else if (point == 2) {\n return 2 * r + 1;\n }\n return 0; // silence noreturn warning\n }\n // index of CLAIM_PAD[layer][n]\n size_t claim_pad(size_t n) const { return poly_pad(2 * logw_, 0) + n; }\n\n // size of the layer\n size_t layer_size() const { return claim_pad(3); }\n\n //------------------------------------------------------------\n // Indexing with overlap.\n //------------------------------------------------------------\n // index of CLAIM_PAD[layer - 1][n]\n size_t ovp_claim_pad_m1(size_t n) const { return n; }\n size_t ovp_poly_pad(size_t r, size_t point) const {\n return 3 + poly_pad(r, point);\n }\n size_t ovp_claim_pad(size_t n) const { return 3 + claim_pad(n); }\n size_t ovp_layer_size() const { return ovp_claim_pad(3); }\n };\n\n // Represent symbolic expressions of the form\n //\n // KNOWN + SUM_{i} SYMBOLIC[i] * WITNESS[i]\n //\n // and support simple linear operations on such quantities\n class Expression {\n Elt known_;\n std::vector symbolic_;\n const Field& f_;\n\n public:\n Expression(size_t nvar, const Field& F)\n : known_(F.zero()), symbolic_(nvar, F.zero()), f_(F) {}\n\n Elt known() { return known_; }\n std::vector symbolic() { return symbolic_; }\n\n void scale(const Elt& k) {\n f_.mul(known_, k);\n for (auto& e : symbolic_) {\n f_.mul(e, k);\n }\n }\n\n // We don't need the general case of combining two\n // Expressions. Instead, we only need the two operations\n // below.\n\n // *this += k * (known_value + witness[var]).\n void axpy(size_t var, const Elt& known_value, const Elt& k) {\n f_.add(known_, f_.mulf(k, known_value));\n f_.add(symbolic_[var], k);\n }\n\n // *this -= k * (known_value + witness[var])\n void axmy(size_t var, const Elt& known_value, const Elt& k) {\n f_.sub(known_, f_.mulf(k, known_value));\n f_.sub(symbolic_[var], k);\n }\n };\n\n class ConstraintBuilder {\n Expression expr_;\n const PadLayout& pl_;\n const Field& f_;\n\n public:\n ConstraintBuilder(const PadLayout& pl, const Field& F)\n : expr_(pl.ovp_layer_size(), F), pl_(pl), f_(F) {}\n\n // For given unpadded variable X in the original non-ZK prover,\n // the transcript contains the padded variable Xhat = X - dX\n // where dX is the padding of X. Thus the unpadded variable is\n //\n // X = Xhat + dX\n //\n // The ZK verifier needs to compute linear combinations (and one\n // quadratic combination) of the X's, but it only has access to\n // the Xhat's and to a committment to the dX's. We also want to\n // discuss the verifier algorithm as if the verifier were\n // operating on X, in order to keep the discussion simple.\n //\n // To this end, the Expression class keeps a symbolic\n // representation of a variable X as\n //\n // X = KNOWN + SUM_{i} SYMBOLIC[i] dX[i]\n //\n // which is sufficient to capture any linear combination of\n // X variables. We do something special for the quadratic\n // combination in finalize().\n\n // We store only one quantity EXPR_ that represents either\n // p(1) at some certain round, or a claim at some round.\n // Comments make it clear which is which.\n\n // Initially, compute claim_{-1} = cl0 + alpha*cl1\n void first(Elt alpha, const Elt claims[]) {\n // expr_ contains zero\n expr_.axpy(pl_.ovp_claim_pad_m1(0), claims[0], f_.one());\n expr_.axpy(pl_.ovp_claim_pad_m1(1), claims[1], alpha);\n // expr_ contains claim_{-1} = cl0 + alpha*cl1\n }\n\n // Given claim_{r-1}, compute claim_{r}\n void next(size_t r, const Elt lag[], const Elt tr[]) {\n // expr contains claim_{r-1}\n expr_.axmy(pl_.ovp_poly_pad(r, 0), tr[0], f_.one());\n // expr contains p_{r}(1) = claim_{r-1} - p_{r}(0)\n\n // Compute the dot-product in place:\n // claim_{r} = p_{r}(1) * lag[1], overwriting expr_\n // claim_{r} += lag[0] * p_{r}(0)\n // claim_{r} += lag[2] * p_{r}(2)\n expr_.scale(lag[1]);\n expr_.axpy(pl_.ovp_poly_pad(r, 0), tr[0], lag[0]);\n expr_.axpy(pl_.ovp_poly_pad(r, 2), tr[2], lag[2]);\n // expr_ contains claim_{r} = \n }\n\n // The finalize method uses the last sumcheck claim to\n // add a constraint on the dX's (the pad) to the Ligero system.\n //\n // Our goal is to verify that\n //\n // CLAIM = EQQ * W[R,C] * W[L,C]\n //\n // where EQQ = EQ[Q,C] QUAD[R,L] and all variables are unpadded.\n //\n // We have a symbolic representation of CLAIM in expr_, the proof\n // contains W_hat[{R,L},C], the padding witnesses are at index pi,\n // pi+1, and their product is at index pi+2.\n //\n // Let CLAIM = KNOWN + SUM_{i} SYMBOLIC[i] dX[i] from the\n // Expression class. Then\n //\n // KNOWN + SUM_{i} SYMBOLIC[i] dX[i]\n // = EQQ * (W_hat[R,C] + dW[R,C]) * (W_hat[L,C] + dW[L,C])\n //\n // Rearranging in the Ax = b form needed for ligero, we have\n //\n // SUM_{i} SYMBOLIC[i] dX[i] - (EQQ * W[R, C]) dW[L, C]\n // - (EQQ * W[L, C]) dW[R, C] - EQQ * dW[R,C] * dW[L,C]\n // = EQQ * W[R,C] * W[L,C] - KNOWN\n void finalize(const Elt wc[], const Elt& eqq, size_t ci, size_t ly,\n size_t pi, std::vector& a, std::vector& b) {\n // break the Expression abstraction and split into constituents.\n\n // EQQ * W[R,C] * W[L,C] - known\n Elt rhs = f_.subf(f_.mulf(eqq, f_.mulf(wc[0], wc[1])), expr_.known());\n\n // symbolic part\n std::vector lhs = expr_.symbolic();\n f_.sub(lhs[pl_.ovp_claim_pad(0)], f_.mulf(eqq, wc[1]));\n f_.sub(lhs[pl_.ovp_claim_pad(1)], f_.mulf(eqq, wc[0]));\n f_.sub(lhs[pl_.ovp_claim_pad(2)], eqq);\n\n b.push_back(rhs);\n\n // Layer 0 does not refer to CLAIM_PAD[layer - 1]\n size_t i0 = (ly == 0) ? pl_.ovp_poly_pad(0, 0) : pl_.ovp_claim_pad_m1(0);\n\n for (size_t i = i0; i < lhs.size(); ++i) {\n // \"i\" is in the \"with overlap\" reference frame.\n // \"pi\" is in the \"without overlap\" reference frame.\n //\n // In theory at least, (pi - pl_.ovp_poly_pad(0, 0))\n // could overflow, but (pi + i) - pl_.ovp_poly_pad(0, 0) cannot.\n a.push_back(Llc{ci, (pi + i) - pl_.ovp_poly_pad(0, 0), lhs[i]});\n }\n }\n };\n\n // binding(inputs, R) = binding(pub_inputs, R_p) + binding(witness, R_w)\n // This method explicitly computes the public binding, and then adds the\n // constraints that\n // binding(witness, R_w) = got - binding(pub_inputs, R_p)\n static size_t input_constraint(const Claims& cla, const Dense& pub,\n size_t pub_inputs, size_t num_inputs,\n size_t pi, Elt got, Elt alpha,\n std::vector& a, std::vector& b,\n size_t ci, const Field& F) {\n Eqs eq0(cla.logv, num_inputs, cla.g[0], F);\n Eqs eq1(cla.logv, num_inputs, cla.g[1], F);\n Elt pub_binding = F.zero();\n for (index_t i = 0; i < num_inputs; ++i) {\n Elt b_i = F.addf(eq0.at(i), F.mulf(alpha, eq1.at(i)));\n if (i < pub_inputs) {\n F.add(pub_binding, F.mulf(b_i, pub.at(i)));\n } else {\n // Use (i - pub_inputs) for the index of private inputs.\n a.push_back(Llc{ci, i - pub_inputs, b_i});\n }\n }\n\n // We view the input constraints as being at fake layer\n // one past the last real layer. The alternative of\n // considering the input as part of the last real layer\n // yields code that looks even more convoluted.\n PadLayout pl(/*logw=*/0);\n\n // This paranoid assertion holds unless the circuit has zero\n // layers, which is not guaranteed by this function alone.\n check(pi >= pl.ovp_poly_pad(0, 0), \"pi >= pl.ovp_poly_pad(0, 0)\");\n\n size_t claim_pad_m1 = pi - pl.ovp_poly_pad(0, 0);\n a.push_back(Llc{ci, claim_pad_m1 + 0, F.mone()});\n a.push_back(Llc{ci, claim_pad_m1 + 1, F.negf(alpha)});\n b.push_back(F.subf(got, pub_binding));\n return ++ci;\n }\n\n static Elt bind_quad(const Layer* clr, const Claims& cla,\n const LayerChallenge* chal, const Field& F) {\n return clr->quad->bind_gh_all(\n // G\n cla.logv, cla.g[0], cla.g[1], chal->alpha, chal->beta,\n // H\n clr->logw, chal->hb[0], chal->hb[1],\n // Field\n F);\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ZK_ZK_COMMON_H_\n"], ["/longfellow-zk/lib/ec/elliptic_curve.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_EC_ELLIPTIC_CURVE_H_\n#define PRIVACY_PROOFS_ZK_LIB_EC_ELLIPTIC_CURVE_H_\n\n#include \n#include \n\n#include \"algebra/nat.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n// Elliptic curve class that supports basic operations such as addition,\n// doubling. The algorithms are described in\n// https://eprint.iacr.org/2015/1060.pdf.\n// The const Field parameter is meant as a type check to keep different\n// elliptic curves from interacting. The convention is to use the last 5\n// digits of the coordinate field prime in base-10 to name a curve.\n// The kN template parameter describes the number of bits in the curve\n// order, e.g., to handle curves like P-521, K-283, etc.\ntemplate \nclass EllipticCurve {\n public:\n using Field = Field_;\n using Elt = typename Field::Elt;\n using N = Nat;\n\n static constexpr const size_t kBits = kN; /* # bits in size of the group */\n\n const Field& f_;\n Elt a_;\n Elt b_;\n Elt gx_, gy_, gz_; // generator of the group\n const Elt k2, k3, k8, k3b, k9b, k24b;\n\n struct ECPoint {\n Elt x;\n Elt y;\n Elt z;\n\n ECPoint() = default;\n ECPoint(const Elt& x, const Elt& y, const Elt& z) : x(x), y(y), z(z) {}\n };\n\n EllipticCurve(const Elt& a, const Elt& b, const Elt& gX, const Elt& gY,\n const Field_& F)\n : f_(F),\n a_(a),\n b_(b),\n gx_(gX),\n gy_(gY),\n gz_(F.one()),\n k2(F.of_scalar(2)),\n k3(F.of_scalar(3)),\n k8(F.of_scalar(8)),\n k3b(F.mulf(k3, b_)),\n k9b(F.mulf(F.of_scalar(9), b_)),\n k24b(F.mulf(F.of_scalar(24), b_)) {\n is_minus_3_a_ = (a_ == F.negf(k3));\n is_zero_a_ = (a_ == F.zero());\n }\n\n // This equality method makes no assumptions about whether the inputs\n // are valid points on the curve. Just verifying cross-mult is not\n // enough if one of the points is invalid. This method is not constant\n // time and can return early if any point is infinity.\n bool equal(const ECPoint& p, const ECPoint& q) const {\n // handle inf point, then point equality, and finally projective eq\n if (q.x == f_.zero() && q.z == f_.zero() && q.y != f_.zero() &&\n p.x == f_.zero() && p.z == f_.zero() && p.y != f_.zero()) {\n return true;\n }\n if (q.x == p.x && q.z == p.z && q.y == p.y) {\n return true;\n }\n\n return (f_.mulf(p.x, q.z) == f_.mulf(q.x, p.z) &&\n f_.mulf(p.y, q.z) == f_.mulf(q.y, p.z));\n }\n\n // This method assumes a point is either zero or has z=1 coordinate,\n // so it does not implement the full mathematical notion of Jacobian-form\n // ec point.\n bool is_on_curve(const ECPoint& p) const {\n if (equal(p, zero())) {\n return true;\n }\n // Do not support Jacobian coordinate with z != 1\"\n if (p.z != f_.one()) {\n return false;\n }\n return is_on_curve(p.x, p.y);\n }\n\n // This caller of the constructor must first verify that (x,y) is on the\n // curve using the isOnCurve() method.\n ECPoint point(const Elt& x, const Elt& y) const {\n ECPoint p(x, y, f_.one());\n check(is_on_curve(p), \"Invalid curve point\");\n return p;\n }\n\n void normalize(ECPoint& p) const {\n if (p.z == f_.zero()) return;\n f_.invert(p.z);\n f_.mul(p.x, p.z);\n f_.mul(p.y, p.z);\n p.z = f_.one();\n }\n\n void addE(ECPoint& p3, const ECPoint& p2) const {\n addE(p3.x, p3.y, p3.z, p3.x, p3.y, p3.z, p2.x, p2.y, p2.z);\n }\n\n void doubleE(ECPoint& p3) const {\n doubleE(p3.x, p3.y, p3.z, p3.x, p3.y, p3.z);\n }\n\n // Functional interface.\n ECPoint addEf(ECPoint p1, const ECPoint& p2) const {\n addE(p1, p2);\n return p1;\n }\n\n ECPoint doubleEf(ECPoint p1) const {\n doubleE(p1);\n return p1;\n }\n\n // Computes the elliptic curve point p * scalar.\n // This method is not constant time, but that is not necessary in the current\n // zk implementation.\n ECPoint scalar_multf(const ECPoint& p, const N& scalar) const {\n ECPoint x = p;\n ECPoint p3 = zero();\n for (size_t d = 0; d < N::kLimbs; ++d) {\n auto nd = scalar.limb_[d];\n for (size_t i = 0; i < N::kBitsPerLimb; ++i) {\n if (nd & 1) {\n addE(p3, x);\n }\n doubleE(x);\n nd >>= 1;\n }\n }\n return p3;\n }\n\n // Computes the multi-scalar elliptic curve point multiplication.\n // Input: p1, p2, ..., pn, and scalars s1, s2, ..., sn\n // Output: p1 * s1 + p2 * s2 + ... + pn * sn\n // This method is not a constant time operation.\n ECPoint scalar_multf(size_t n, ECPoint p[/*n*/], N scalar[/*n*/]) const {\n if (n == 0) {\n return zero();\n } else if (n == 1) {\n return scalar_multf(p[0], scalar[0]);\n } else {\n return bos_coster(n, p, scalar);\n }\n }\n\n ECPoint zero() const { return ECPoint(f_.zero(), f_.one(), f_.zero()); }\n ECPoint generator() const { return ECPoint(gx_, gy_, gz_); }\n\n // Check whether Y^2 = X^3 + aX + b.\n bool is_on_curve(const Elt& X, const Elt& Y) const {\n Elt left = f_.mulf(Y, Y);\n Elt X3 = f_.mulf(X, f_.mulf(X, X));\n Elt right = f_.addf(f_.addf(X3, f_.mulf(a_, X)), b_);\n return left == right;\n }\n\n void addE(Elt& X3o, Elt& Y3o, Elt& Z3o, const Elt& X1, const Elt& Y1,\n const Elt& Z1, const Elt& X2, const Elt& Y2, const Elt& Z2) const {\n // Optimized special cases.\n if (is_zero_a_) return addEZeroA(X3o, Y3o, Z3o, X1, Y1, Z1, X2, Y2, Z2);\n if (is_minus_3_a_)\n return addEMinus3A(X3o, Y3o, Z3o, X1, Y1, Z1, X2, Y2, Z2);\n\n /*\n Source: 1998 Cohen–Miyaji–Ono \"Efficient elliptic curve exponentiation using\n mixed coordinates\", formula (3), plus common-subexpression elimination.\n These equations are taken from the Hyperelliptic curve formula database.\n This could have special short-cuts for addition with inf and self-addition,\n which speeds up all multi-exponentiation computations that involve a lot of\n small exponents.\n */\n if (X1 == f_.zero() && Z1 == f_.zero()) {\n X3o = X2;\n Y3o = Y2;\n Z3o = Z2;\n return;\n }\n\n if (X2 == f_.zero() && Z2 == f_.zero()) {\n X3o = X1;\n Y3o = Y1;\n Z3o = Z1;\n return;\n }\n\n Elt Y1Z2 = f_.mulf(Y1, Z2);\n Elt X1Z2 = f_.mulf(X1, Z2);\n Elt u = f_.subf(f_.mulf(Y2, Z1), Y1Z2);\n Elt v = f_.subf(f_.mulf(X2, Z1), X1Z2);\n if (u == f_.zero()) {\n doubleE(X3o, Y3o, Z3o, X1, Y1, Z1);\n return;\n // Self addition, invoke Double method.\n }\n /* This check occurs after the u check.\n If u!=0, but v=0, then the points are inverses.\n */\n if (v == f_.zero()) {\n X3o = f_.zero();\n Y3o = f_.one();\n Z3o = f_.zero();\n return;\n }\n\n Elt Z1Z2 = f_.mulf(Z1, Z2);\n Elt uu = f_.mulf(u, u);\n Elt vv = f_.mulf(v, v);\n Elt vvv = f_.mulf(v, vv);\n Elt R = f_.mulf(vv, X1Z2);\n Elt A = f_.subf(f_.subf(f_.mulf(uu, Z1Z2), vvv), f_.mulf(k2, R));\n Elt X3 = f_.mulf(v, A);\n Elt Y3 = f_.subf(f_.mulf(u, f_.subf(R, A)), f_.mulf(vvv, Y1Z2));\n Elt Z3 = f_.mulf(vvv, Z1Z2);\n\n X3o = X3;\n Y3o = Y3;\n Z3o = Z3;\n }\n\n void doubleE(Elt& X3o, Elt& Y3o, Elt& Z3o, const Elt& X, const Elt& Y,\n const Elt& Z) const {\n // Optimized special cases.\n if (is_zero_a_) return doubleEZeroA(X3o, Y3o, Z3o, X, Y, Z);\n if (is_minus_3_a_) return doubleEMinus3A(X3o, Y3o, Z3o, X, Y, Z);\n\n /*\n // 1998 Cohen–Miyaji–Ono \"Efficient elliptic curve exponentiation using\n mixed coordinates\", formula (4), This version of the double formula trades\n general mults for mults by 2,4,8 which can be implemented with additions.\n This results in savings of 200ns on double.\n */\n if (X == f_.zero() && Z == f_.zero()) {\n X3o = X;\n Y3o = f_.one();\n Z3o = Z;\n return;\n }\n\n Elt Z2 = f_.mulf(Z, Z);\n Elt X2 = f_.mulf(X, X);\n Elt X2_3 = f_.addf(f_.addf(X2, X2), X2);\n Elt s = f_.mulf(Y, Z);\n Elt ss = f_.mulf(s, s);\n Elt sss = f_.mulf(s, ss);\n Elt sss_2 = f_.addf(sss, sss);\n Elt w = f_.addf(f_.mulf(a_, Z2), X2_3);\n Elt R = f_.mulf(Y, s);\n Elt sss_4 = f_.addf(sss_2, sss_2);\n Elt B = f_.mulf(X, R);\n Elt sss_8 = f_.addf(sss_4, sss_4);\n Elt B_2 = f_.addf(B, B);\n Elt R2 = f_.mulf(R, R);\n Elt B_4 = f_.addf(B_2, B_2);\n Elt B_8 = f_.addf(B_4, B_4);\n Elt w2 = f_.mulf(w, w);\n Elt h = f_.subf(w2, B_8);\n Elt s_2 = f_.addf(s, s);\n Elt X3 = f_.mulf(h, s_2);\n Elt R2_2 = f_.addf(R2, R2);\n Elt R2_4 = f_.addf(R2_2, R2_2);\n Elt R2_8 = f_.addf(R2_4, R2_4);\n Elt Y3 = f_.subf(f_.mulf(w, f_.subf(B_4, h)), R2_8);\n Elt Z3 = sss_8;\n\n X3o = X3;\n Y3o = Y3;\n Z3o = Z3;\n }\n\n private:\n /* From Algorithm 7: Complete, projective point addition for prime order\n j-invariant 0 short Weierstrass curves E/Fq : y^2 = x^3 + b.\n\n X3 = (X1 Y2 + X2 Y1)(Y1 Y2 - 3b Z1 Z2) - 3b(Y1 Z2 + Y2 Z1)(X1 Z2 + X2 Z1)\n Y3 = (Y1 Y2 + 3b Z1 Z2)(Y1 Y2 - 3b Z1 Z2) + 9b X1 X2 (X1 Z2 + X2 Z1)\n Z3 = (Y1 Z2 + Y2 Z1)(Y1 Y2 + 3b Z1 Z2) + 3 X1 X2(X1 Y2 + X2 Y1)\n */\n void addEZeroA(Elt& X3o, Elt& Y3o, Elt& Z3o, const Elt& X1, const Elt& Y1,\n const Elt& Z1, const Elt& X2, const Elt& Y2,\n const Elt& Z2) const {\n Elt t0 = f_.mulf(X2, Y1);\n Elt t1 = f_.mulf(X1, Y2);\n Elt t2 = f_.addf(t1, t0);\n Elt t3 = f_.mulf(Y1, Y2);\n Elt t4 = f_.mulf(Z1, Z2);\n Elt t5 = f_.mulf(Y1, Z2);\n Elt t6 = f_.mulf(Y2, Z1);\n Elt t7 = f_.addf(t5, t6);\n Elt t8 = f_.mulf(X1, Z2);\n Elt t9 = f_.mulf(X2, Z1);\n Elt t10 = f_.addf(t8, t9);\n Elt t11 = f_.mulf(X1, X2);\n Elt t12 = f_.mulf(k3b, t4);\n Elt t13 = f_.addf(t3, t12);\n Elt t14 = f_.subf(t3, t12);\n\n X3o = f_.subf(f_.mulf(t2, t14), f_.mulf(k3b, f_.mulf(t7, t10)));\n Y3o = f_.addf(f_.mulf(t13, t14), f_.mulf(k9b, f_.mulf(t11, t10)));\n Z3o = f_.addf(f_.mulf(t7, t13), f_.mulf(k3, f_.mulf(t11, t2)));\n }\n\n /*Algorithm 4: Complete, projective point addition for prime order short\n * Weierstrass curves E/Fq : y^2 = x^33 + ax + b with a = −3.\n */\n void addEMinus3A(Elt& X3o, Elt& Y3o, Elt& Z3o, const Elt& X1, const Elt& Y1,\n const Elt& Z1, const Elt& X2, const Elt& Y2,\n const Elt& Z2) const {\n Elt t0 = f_.mulf(X1, X2);\n Elt t1 = f_.mulf(Y1, Y2);\n Elt t2 = f_.mulf(Z1, Z2);\n Elt t3 = f_.addf(X1, Y1);\n Elt t4 = f_.addf(X2, Y2);\n t3 = f_.mulf(t3, t4);\n t4 = f_.addf(t0, t1);\n t3 = f_.subf(t3, t4);\n t4 = f_.addf(Y1, Z1);\n Elt X3 = f_.addf(Y2, Z2);\n t4 = f_.mulf(t4, X3);\n X3 = f_.addf(t1, t2);\n t4 = f_.subf(t4, X3);\n X3 = f_.addf(X1, Z1);\n Elt Y3 = f_.addf(X2, Z2);\n X3 = f_.mulf(X3, Y3);\n Y3 = f_.addf(t0, t2);\n Y3 = f_.subf(X3, Y3);\n Elt Z3 = f_.mulf(b_, t2);\n X3 = f_.subf(Y3, Z3);\n Z3 = f_.addf(X3, X3);\n X3 = f_.addf(X3, Z3);\n Z3 = f_.subf(t1, X3);\n X3 = f_.addf(t1, X3);\n Y3 = f_.mulf(b_, Y3);\n t1 = f_.addf(t2, t2);\n t2 = f_.addf(t1, t2);\n Y3 = f_.subf(Y3, t2);\n Y3 = f_.subf(Y3, t0);\n t1 = f_.addf(Y3, Y3);\n Y3 = f_.addf(t1, Y3);\n t1 = f_.addf(t0, t0);\n t0 = f_.addf(t1, t0);\n t0 = f_.subf(t0, t2);\n t1 = f_.mulf(t4, Y3);\n t2 = f_.mulf(t0, Y3);\n Y3 = f_.mulf(X3, Z3);\n Y3 = f_.addf(Y3, t2);\n X3 = f_.mulf(t3, X3);\n X3 = f_.subf(X3, t1);\n Z3 = f_.mulf(t4, Z3);\n t1 = f_.mulf(t3, t0);\n Z3 = f_.addf(Z3, t1);\n\n X3o = X3;\n Y3o = Y3;\n Z3o = Z3;\n }\n\n /* From Algorithm 6: Exception-free point doubling for prime order short\n * Weierstrass curves E/Fq : y^2 = x^3 + ax + b with a = −3.\n */\n void doubleEMinus3A(Elt& X3o, Elt& Y3o, Elt& Z3o, const Elt& X, const Elt& Y,\n const Elt& Z) const {\n Elt t0 = f_.mulf(X, X);\n Elt t1 = f_.mulf(Y, Y);\n Elt t2 = f_.mulf(Z, Z);\n Elt t3 = f_.mulf(X, Y);\n t3 = f_.addf(t3, t3);\n Elt Z3 = f_.mulf(X, Z);\n Z3 = f_.addf(Z3, Z3);\n Elt Y3 = f_.mulf(b_, t2);\n Y3 = f_.subf(Y3, Z3);\n Elt X3 = f_.addf(Y3, Y3);\n Y3 = f_.addf(X3, Y3);\n X3 = f_.subf(t1, Y3);\n Y3 = f_.addf(t1, Y3);\n Y3 = f_.mulf(X3, Y3);\n X3 = f_.mulf(X3, t3);\n t3 = f_.addf(t2, t2);\n t2 = f_.addf(t2, t3);\n Z3 = f_.mulf(b_, Z3);\n Z3 = f_.subf(Z3, t2);\n Z3 = f_.subf(Z3, t0);\n t3 = f_.addf(Z3, Z3);\n Z3 = f_.addf(Z3, t3);\n t3 = f_.addf(t0, t0);\n t0 = f_.addf(t3, t0);\n t0 = f_.subf(t0, t2);\n t0 = f_.mulf(t0, Z3);\n Y3 = f_.addf(Y3, t0);\n t0 = f_.mulf(Y, Z);\n t0 = f_.addf(t0, t0);\n Z3 = f_.mulf(t0, Z3);\n X3 = f_.subf(X3, Z3);\n Z3 = f_.mulf(t0, t1);\n Z3 = f_.addf(Z3, Z3);\n Z3 = f_.addf(Z3, Z3);\n\n X3o = X3;\n Y3o = Y3;\n Z3o = Z3;\n }\n\n /* From Algorithm 9: Exception-free point doubling for prime order\n j-invariant 0 short Weierstrass curves E/Fq y^2 = x^3 + b\n\n X3 = 2XY (YY − 9bZZ)\n Y3 = (YY − 9bZZ)(YY + 3bZZ) + 24bYYZZ\n Z3 = 8YYYZ.\n */\n void doubleEZeroA(Elt& X3o, Elt& Y3o, Elt& Z3o, const Elt& X, const Elt& Y,\n const Elt& Z) const {\n Elt t0 = f_.mulf(X, Y);\n Elt t1 = f_.mulf(Y, Y);\n Elt t2 = f_.mulf(Z, Z);\n Elt t4 = f_.mulf(Y, Z);\n Elt t5 = f_.mulf(k9b, t2); // 9bZZ\n Elt t6 = f_.subf(t1, t5); // YY - 9bZZ\n Elt t7 = f_.mulf(k3b, t2); // 3bZZ\n Elt t8 = f_.addf(t1, t7); // YY + 3bZZ\n X3o = f_.mulf(k2, f_.mulf(t0, t6));\n Y3o = f_.addf(f_.mulf(t6, t8), f_.mulf(k24b, f_.mulf(t1, t2)));\n Z3o = f_.mulf(k8, f_.mulf(t1, t4));\n }\n\n //------------------------------------------------------------\n // Multi-exponentiation SUM_i scalarMult(p[i], s[i])\n\n // We follow the basic strategy outlined in Daniel J. Bernstein,\n // Niels Duif, Tanja Lange, Peter Schwabe, and Bo-Yin Yang,\n // \"High-speed high-security signatures\",\n // https://eprint.iacr.org/2011/368, where Bernstein et al. credit\n // the method to Bos and Coster via a reference to Peter de Rooij,\n // \"Efficient exponentiation using precomputation and vector\n // addition chains\", in Eurocrypt ’94. In my opinion [matteof@]\n // the method of Bernstein et al. is not quite the same as the papers\n // that they reference, but either way we follow Bernstein et al.\n // with a few modifications, and call the method bos_coster() in\n // this file.\n\n // The basic idea is to keep the list (p[i], s[i]) of pairs\n // (point, scalar) in descending order of scalar, so that s[0]\n // is the maximum.\n\n // Bernstein's method repeatedly replaces p[0]*s[0]+p[1]*s[1]\n // by p[0]*(s[0]-s[1])+(p[0]+p[1])*s[1], where now the first\n // scalar becomes smaller. Eventually all the scalars s[i] become\n // 0 for i>=1.\n\n // For random scalars, one can roughly expect s[0]-s[1] to be\n // about |F|/n, so the method can be expected to set approximately\n // log n scalar bits to zero in each iteration. However, its worst\n // case is horrific. E.g., if s[1]=1 and s[0] is O(2**256), the\n // method will require O(2**256) iterations to converge.\n\n // To avoid this worst-case behavior, we depart from Bernstein and\n // perform either a Bernstein step or a double-and-add step,\n // whichever one decreases s[0] the most. A double-and-add writes\n // s[0] = 2*a+b and replaces p[0]*s[0] with (2*p[0])*(s[0]/2) *\n // b*p[0], where the second multiplication is trivial because b \\in\n // {0,1}. With this choice, we are guaranteed to eliminate at least\n // one scalar bit per iteration, so the method is no worse than a\n // loop of single scalar multiplications. Bernstein et al., page\n // 17, are aware of the problem, but they say that doing anything\n // about it is \"not worthwhile\". On the other hand, the fix doesn't\n // cost anything either, so may as well do it. (Bernstein et\n // al. propose a different fix.)\n\n // For easy access to the largest s[0] and second-largest s[1], we\n // keep the (p[i], s[i]) terms in a heap. Here, \"heap\" denotes a\n // variant of the standard heap where the root node H[0] has one\n // child H[1] (as opposed to two children), and every other node i>0\n // has two children H[2*i] and H[2*i+1]. A heap comprises at least\n // two elements H[0] and H[1]. In this way, the two largest scalars\n // are always available directly.\n\n // The following function is equivalent to assigning (p[i], s[i]) =\n // (tp, ts) followed by restoring heap order. However, the logic is\n // a bit complicated by our desire to avoid unnecessary copies of\n // large objects (e.g., swap p[i] with a child, followed by another\n // swap of the child with its child.)\n //\n // Warning: tp and ts MUST NOT be references to p[i] and s[i], since\n // the algorithm overwrites the p and s arrays. This complication\n // ensues because we are trying to avoid unnecessary copies.\n void bury(size_t i, size_t n, ECPoint p[/*n*/], N s[/*n*/], const ECPoint& tp,\n const N& ts) const {\n while (2 * i < n) {\n // at least one child\n size_t cld = 2 * i;\n if (2 * i + 1 < n && s[cld] < s[2 * i + 1]) {\n // right child exists and is larger\n cld = 2 * i + 1;\n }\n\n if (ts < s[cld]) {\n // I is out of order with CLD. Bubble CLD up the tree and\n // continue as in BURY(CLD, N, P, S, TP, TS).\n s[i] = s[cld];\n p[i] = p[cld];\n i = cld;\n } else {\n // already in heap order, stop here.\n break;\n }\n }\n\n p[i] = tp;\n s[i] = ts;\n }\n\n // bury (p[0], s[0]) to its rightful place in the heap.\n void bury0(size_t n, ECPoint p[/*n*/], N s[/*n*/]) const {\n if (s[0] < s[1]) {\n // equivalent to swap(s[0], s[1]); bury(s[1]);\n // but without the possibly unnecessary assignment of (s,p)[1]\n ECPoint tp = p[0];\n N ts = s[0];\n p[0] = p[1];\n s[0] = s[1];\n bury(1, n, p, s, tp, ts);\n }\n }\n\n // The main Bernstein/Bos-Coster algorithm.\n ECPoint bos_coster(size_t n, ECPoint p[/*n*/], N s[/*n*/]) const {\n check(n >= 2, \"n >= 2\");\n ECPoint res = zero();\n\n // build a heap on [1..n)\n for (size_t i = /*floor*/ (n / 2); i >= 1; --i) {\n // create temporary copies of p[i], s[i], which are passed by\n // const &.\n bury(i, n, p, s, ECPoint(p[i]), N(s[i]));\n }\n // finish the heap on [0..n)\n bury0(n, p, s);\n\n while (s[0] != /*zero*/ N{}) {\n // ns0 = s[0] - s[1]\n N ns0(s[0]);\n ns0.sub(s[1]);\n\n // Double-and-add is (locally) better than Bernstein iff s[0]/2\n // < s[0] - s[1], equivalent to s[0] > 2*s[1], equivalent to\n // ns0 = s[0] - s[1] > s[1]:\n if (s[1] < ns0) {\n // res += (s[0] & 1) * p[0]; s[0] /= 2; p[0] *= 2;\n uint64_t lsb = s[0].shiftr(1);\n if (lsb != 0) {\n addE(res, p[0]);\n }\n doubleE(p[0]);\n } else {\n // s[0] -= s[1], p[1] += p[0]\n s[0] = ns0;\n addE(p[1], p[0]);\n }\n bury0(n, p, s);\n }\n return res;\n }\n\n bool is_zero_a_;\n bool is_minus_3_a_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_EC_ELLIPTIC_CURVE_H_\n"], ["/longfellow-zk/lib/circuits/cbor_parser/cbor_witness.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_WITNESS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_WITNESS_H_\n\n#include \n#include \n\n#include \n\n#include \"circuits/cbor_parser/cbor_constants.h\"\n#include \"circuits/cbor_parser/cbor_pluck.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\ntemplate \nclass CborWitness {\n public:\n using Elt = typename Field::Elt;\n static constexpr size_t kNCounters = CborConstants::kNCounters;\n static constexpr size_t kIndexBits = CborConstants::kIndexBits;\n using counters = std::array;\n using vindex = std::array;\n\n struct position_witness {\n Elt encoded_sel_header;\n\n // SLEN output value, used for debugging but not fed to the circuit\n size_t slen_next_debug;\n // counter values, used for debugging but not fed to the circuit\n counters cc_debug;\n size_t isel_debug;\n };\n\n struct global_witness {\n Elt invprod_decode;\n Elt cc0; // initial values of counter[0]\n Elt invprod_parse;\n };\n\n using v8 = std::array;\n\n explicit CborWitness(const Field& F) : f_(F) {}\n\n // Return an index as an array of Elt, which can be stored into W[]\n vindex index(size_t j) const {\n const Field& F = f_; // shorthand\n vindex r;\n for (size_t i = 0; i < kIndexBits; ++i) {\n r[i] = F.of_scalar((j >> i) & 1);\n }\n return r;\n }\n\n void fill_witnesses(size_t n, size_t input_len, const uint8_t bytes[/*n*/],\n v8 in[/*n*/], position_witness pw[/*n*/],\n global_witness& gw) const {\n const Field& F = f_; // shorthand\n\n // First pass to compute the number of top-level items. In the\n // second pass, we will use this value to that all counters are 0\n // at the end of the input.\n size_t top_level_items;\n {\n // start with a value of cc[0] guaranteed not to\n // underflow counter 0.\n counters cc{{n + 1}};\n\n size_t slen = 1;\n for (size_t i = 0; i < n; ++i) {\n bool overflow;\n bool header = (slen == 1);\n cc = counters_next(bytes[i], header,\n /*have_nextb=*/(i + 1) < n,\n /*nextb=*/(i + 1) < n ? bytes[i + 1] : 0, cc,\n &overflow);\n proofs::check(!overflow, \"!overflow\");\n slen = next_slen(slen, n, bytes, i);\n }\n\n top_level_items = (n + 1) - cc[0];\n }\n\n // second pass starting with the correct counter values\n {\n counters cc{{top_level_items}};\n Elt prod_parse = F.one();\n Elt prod_decode = F.one();\n\n size_t slen = 1;\n for (size_t i = 0; i < n; ++i) {\n bool overflow;\n bool header = (slen == 1);\n\n // Require all bytes to be 0 except the last N-INPUT_LEN.\n // That is, the input must be aligned towards the end\n // of arrays, and padded with zeroes at the beginning.\n proofs::check(input_len <= n, \"input_len <= n\");\n if (i + input_len < n) {\n proofs::check(bytes[i] == 0, \"bytes[i] == 0\");\n }\n\n // set up input\n for (size_t j = 0; j < 8; ++j) {\n in[i][j] = F.of_scalar((bytes[i] >> j) & 1);\n }\n\n if (!header) {\n F.mul(prod_decode, F.of_scalar(slen - 1));\n }\n\n // set up parse witness\n size_t isel = kNCounters;\n for (size_t l = kNCounters; l-- > 0;) {\n if (cc[l] != 0) {\n if (i > 0) {\n F.mul(prod_parse, F.of_scalar(cc[l]));\n }\n isel = l;\n break;\n }\n }\n\n cc = counters_next(bytes[i], header,\n /*have_nextb=*/(i + 1) < n,\n /*nextb=*/(i + 1) < n ? bytes[i + 1] : 0, cc,\n &overflow);\n proofs::check(!overflow, \"!overflow\");\n if (i == 0) {\n gw.cc0 = F.of_scalar(cc[0]);\n }\n pw[i].cc_debug = cc;\n\n // set up decode witness\n size_t slen_next = next_slen(slen, n, bytes, i);\n pw[i].slen_next_debug = slen_next;\n\n // encode witnesses\n pw[i].encoded_sel_header =\n cbor_plucker_point()(header, isel, F);\n pw[i].isel_debug = isel;\n\n // advance slen\n slen = slen_next;\n }\n\n gw.invprod_decode = F.invertf(prod_decode);\n gw.invprod_parse = F.invertf(prod_parse);\n }\n }\n\n private:\n static size_t next_slen(size_t slen, size_t n, const uint8_t bytes[/*n*/],\n size_t i) {\n size_t slenm1 = slen - 1;\n bool header = (slenm1 == 0);\n if (header) {\n if (i + 1 < n) {\n return item_length(bytes[i], true, bytes[i + 1]);\n } else {\n return item_length(bytes[i], false, 0);\n }\n } else {\n return slenm1;\n }\n }\n\n // TODO [matteof 2023-11-03] Should not panic() here.\n static size_t item_length(uint8_t b, bool valid_nextb, uint8_t nextb) {\n size_t type = (b >> 5) & 0x7u;\n size_t count = b & 0x1Fu;\n bool count0_23 = (count < 24);\n bool count24 = (count == 24);\n\n switch (type) {\n case 0: /* unsigned */\n case 1: /* negative integer */\n case 4: /* array */\n case 5: /* map */\n case 6: /* tag */\n if (count0_23) {\n return 1;\n } else if (count24) {\n return 2;\n } else {\n check(false, \"unwitnessed count (atom)\");\n return 0;\n }\n\n case 2: /* bytes */\n case 3: /* text */\n if (count0_23) {\n return 1 + count;\n } else if (count24) {\n if (valid_nextb) {\n return 2 + nextb;\n } else {\n check(false, \"invalid nextb\");\n return 0;\n }\n } else {\n check(false, \"unwitnessed count (bytes)\");\n return 0;\n }\n\n case 7: /* special */\n check(false, \"unwitnessed special\");\n return 0;\n\n default:\n check(false, \"can't happen\");\n return 0;\n }\n }\n\n static size_t decode_count(size_t count_in_header, bool have_nextb,\n uint8_t nextb) {\n if (count_in_header < 24) {\n return count_in_header;\n } else if (count_in_header == 24) {\n if (have_nextb) {\n return nextb;\n } else {\n check(false, \"!have_nextb\");\n }\n } else {\n check(false, \"count > 24\");\n }\n return 0xdeadbeef;\n }\n\n static counters counters_next(uint8_t b, bool header, bool have_nextb,\n uint8_t nextb, const counters& c,\n bool* overflow) {\n size_t type = (b >> 5) & 0x7u;\n size_t count_in_header = b & 0x1Fu;\n bool tagp = (type == 6);\n bool arrayp = (type == 4);\n bool mapp = (type == 5);\n\n counters c1 = c;\n *overflow = false;\n\n for (size_t l = kNCounters; l-- > 0;) {\n if (c[l] != 0) {\n if (header) {\n c1[l] = c[l] - 1;\n\n if (tagp) {\n if (l + 1 < kNCounters) {\n c1[l + 1] = 1;\n } else {\n *overflow = true;\n }\n } else if (arrayp) {\n if (l + 1 < kNCounters) {\n c1[l + 1] = decode_count(count_in_header, have_nextb, nextb);\n } else {\n *overflow = true;\n }\n } else if (mapp) {\n if (l + 1 < kNCounters) {\n c1[l + 1] = 2 * decode_count(count_in_header, have_nextb, nextb);\n } else {\n *overflow = true;\n }\n }\n }\n break;\n }\n }\n\n return c1;\n }\n\n private:\n const Field& f_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_WITNESS_H_\n"], ["/longfellow-zk/lib/sumcheck/prover_layers.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_SUMCHECK_PROVER_LAYERS_H_\n#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_PROVER_LAYERS_H_\n\n#include \n\n#include \n#include \n\n#include \"arrays/affine.h\"\n#include \"arrays/dense.h\"\n#include \"arrays/eqs.h\"\n#include \"sumcheck/circuit.h\"\n#include \"sumcheck/quad.h\"\n#include \"sumcheck/transcript_sumcheck.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n\n// A high level idea is partially described in chapter 4.6.7 \"Leveraging Data\n// Parallelism for Further Speedups\" in the book \"Proofs, Arguments, and\n// Zero-Knowledge\" by Justin Thaler.\ntemplate \nclass ProverLayers {\n using Elt = typename Field::Elt;\n\n public:\n using inputs = std::vector>>;\n\n explicit ProverLayers(const Field& f) : f_(f) {}\n\n // Evaluate CIRCUIT on input wires W0. This function stores the\n // input wires of each layer L into IN->at(L), and returns the\n // final output. This asymmetry reflects the fact that for L\n // layers there are L+1 meaningful sets of wires, and that the\n // prover needs IN while the verifier needs the final output.\n std::unique_ptr> eval_circuit(inputs* in,\n const Circuit* circ,\n std::unique_ptr> W0,\n const Field& F) {\n if (in == nullptr || circ == nullptr || W0 == nullptr) return nullptr;\n\n std::unique_ptr> finalV;\n size_t nl = circ->nl, nc = circ->nc;\n check(nl >= 1, \"nl >= 1\");\n check(nc >= 1, \"nc >= 1\");\n\n Dense* W = W0.get();\n\n in->resize(nl);\n in->at(nl - 1).swap(W0);\n\n // Allocate memory and evaluate layer on input W and output V\n for (size_t l = nl; l-- > 0;) {\n Dense* V;\n if (l > 0) {\n // input of layer l-1 = output of layer l\n in->at(l - 1) = std::make_unique>(nc, circ->l[l - 1].nw);\n V = in->at(l - 1).get();\n } else {\n // final output = output of layer 0\n finalV = std::make_unique>(nc, circ->nv);\n V = finalV.get();\n }\n\n bool ok = eval_quad(circ->l[l].quad.get(), V, W, F);\n if (!ok) {\n // Early exit in case of assertion failure.\n // In this case IN is only partially allocated.\n // To avoid ambiguities, free all memory that we may have allocated.\n for (size_t i = 0; i < nl; ++i) {\n in->at(i) = nullptr;\n }\n finalV = nullptr;\n\n return /*finalV=*/nullptr;\n }\n\n W = V;\n }\n\n return finalV;\n }\n\n protected:\n const Field& f_;\n\n // A struct that collects the bindings generated while proving one\n // layer, to serve as initial bindings for the next layer.\n // This protected class must be defined before the public section.\n struct bindings {\n size_t logv;\n Elt q[Proof::kMaxBindings];\n Elt g[2][Proof::kMaxBindings];\n };\n\n // Generate proof for circuit, as a protected member, the caller must\n // ensure that input parameters are valid.\n void prove(Proof* pr, const Proof* pad,\n const Circuit* circ, const inputs& in, ProofAux* aux,\n bindings& bnd, TranscriptSumcheck& ts, const Field& F) {\n size_t logc = circ->logc;\n corner_t nc = circ->nc;\n\n check(circ->logv <= Proof::kMaxBindings,\n \"CIRCUIT->logv <= kMaxBindings\");\n bnd.logv = circ->logv;\n\n // obtain the initial Q and G[0] bindings from the verifier\n ts.begin_circuit(bnd.q, bnd.g[0]);\n\n // Duplicate the g[0] binding.\n // In general, the prover step takes two claims G[0], G[1] on the output\n // wires and reduces them to one claim on G[0] + alpha * G[1] for random\n // alpha. However, in the first step, there is only one claim, so we\n // need to make up G[1]. The code sets G[1] = G[0] and it doesn't affect\n // soundness.\n for (size_t i = 0; i < bnd.logv; ++i) {\n bnd.g[1][i] = bnd.g[0][i];\n }\n\n for (size_t ly = 0; ly < circ->nl; ++ly) {\n auto clr = &circ->l.at(ly);\n Elt alpha, beta;\n ts.begin_layer(alpha, beta, ly);\n Eqs EQ(logc, nc, bnd.q, F);\n auto QUAD = clr->quad->clone();\n QUAD->bind_g(bnd.logv, bnd.g[0], bnd.g[1], alpha, beta, F);\n\n layer(pr, pad, ts, bnd, ly, logc, clr->logw, &EQ, QUAD.get(),\n in.at(ly).get(), F);\n\n if (aux != nullptr) {\n aux->bound_quad[ly] = QUAD->scalar();\n }\n }\n }\n\n private:\n using index_t = typename Quad::index_t;\n using CPoly = typename LayerProof::CPoly;\n using WPoly = typename LayerProof::WPoly;\n\n /*\n Engage in single-layer sumcheck on\n\n EQ[|c] QUAD[|r,l] W[r,c] W[l,c]\n\n Bind c to C, r to R, and l to L (in that order). Store claims\n W[R,C] and W[L,C] in the proof, and set BND to the new bindings for\n the next layer.\n\n logw: number of sumcheck rounds in r, l\n logc: number of sumcheck rounds in c\n */\n void layer(Proof* pr, const Proof* pad,\n TranscriptSumcheck& ts, bindings& bnd, size_t layer,\n size_t logc, size_t logw, Eqs* EQ, Quad* QUAD,\n Dense* W, const Field& F) {\n check(EQ->n() == W->n0_, \"EQ->n() == W->n0_\");\n\n check(logw <= Proof::kMaxBindings, \"logw <= kMaxBindings\");\n bnd.logv = logw;\n\n // Bind the C variables to Q.\n // Note that binding C variables takes O(number_of_copies * circuit_size)\n // while binding R, L takes O(circuit_size * log(circuit_size)). In most\n // cases number_of_copies > log(circuit_size), so we don't have to\n // optimize binding R, L.\n for (size_t round = 0; round < logc; ++round) {\n CPoly sum{};\n\n // sum over r,l: QUAD[|r,l] EQ[|c] W[r,c] W[l,c]\n for (index_t i = 0; i < QUAD->n_; i++) {\n corner_t r(QUAD->c_[i].h[0]);\n corner_t l(QUAD->c_[i].h[1]);\n\n // sum over c: EQ[|c] W[r,c] W[l,c]\n CPoly sumc{};\n\n // n0_ is the copy dimension, n1_ is the wire dimension.\n for (corner_t c = 0; c < W->n0_; c += 2) {\n CPoly poly = cpoly_at_dense(EQ, c, 0, F)\n .mul(cpoly_at_dense(W, c, r, F), F)\n .mul(cpoly_at_dense(W, c, l, F), F);\n sumc.add(poly, F);\n }\n\n sumc.mul_scalar(QUAD->c_[i].v, F);\n sum.add(sumc, F);\n }\n\n Elt rnd = round_c(pr, pad, ts, layer, round, sum, F);\n bnd.q[round] = rnd;\n\n // bind the c variable in both EQ and W\n EQ->bind(rnd, F);\n W->bind(rnd, F);\n }\n\n Elt eq0 = EQ->scalar();\n\n W->reshape(W->n1_);\n check(W->n1_ == 1, \"W->n1_ == 1\");\n\n auto Wclone = W->clone(); // keep alive until function end\n Dense* WH[2] = {W, Wclone.get()}; // reuse W\n\n for (size_t round = 0; round < logw; ++round) {\n for (size_t hand = 0; hand < 2; hand++) {\n // In SUM_{l,r} Q[l,r] W[l] W[r], first precompute QW[l] =\n // SUM_{r} Q[l,r] W[r] as a dense array, and then compute\n // SUM_{l} QW[l] W[l].\n Dense QW(WH[hand]->n0_, 1);\n QW.clear(F);\n size_t ohand = 1 - hand;\n\n // QW[l] = SUM_{r} Q[l,r] W[r]\n for (index_t i = 0; i < QUAD->n_; ++i) {\n corner_t p0(QUAD->c_[i].h[hand]);\n corner_t p1(QUAD->c_[i].h[ohand]);\n F.add(QW.v_[p0], F.mulf(QUAD->c_[i].v, WH[ohand]->v_[p1]));\n }\n\n // SUM_{l} QW[l] W[l].\n WPoly sum{};\n for (corner_t l = 0; l < QW.n0_; l += 2) {\n WPoly poly = wpoly_at_dense(WH[hand], l, 0, F)\n .mul(wpoly_at_dense(&QW, l, 0, F), F);\n sum.add(poly, F);\n }\n\n sum.mul_scalar(eq0, F);\n Elt rnd = round_h(pr, pad, ts, layer, hand, round, sum, F);\n bnd.g[hand][round] = rnd;\n\n // bind the r variable in W[hand] and QUAD\n WH[hand]->bind(rnd, F);\n QUAD->bind_h(rnd, hand, F);\n }\n }\n\n QUAD->scalar(); // for the side effect of assertions\n Elt WC[2] = {WH[0]->scalar(), WH[1]->scalar()};\n end_layer(pr, pad, ts, layer, WC, F);\n }\n\n // Evaluate the quadratic form\n //\n // V[g,c] = QUAD[g|r,l] W[r,c] W[l,c]\n //\n // Returns false in the case the quad is an assert0 check that fails.\n bool eval_quad(const Quad* quad, Dense* V,\n const Dense* W, const Field& F) {\n check(V->n0_ == W->n0_, \"V->n0_ == W->n0_\");\n corner_t n0 = V->n0_;\n\n V->clear(F);\n for (index_t i = 0; i < quad->n_; i++) {\n corner_t g(quad->c_[i].g);\n corner_t r(quad->c_[i].h[0]);\n corner_t l(quad->c_[i].h[1]);\n for (corner_t c = 0; c < n0; ++c) {\n auto x = quad->c_[i].v;\n if (x == F.zero()) {\n // assert that the computed W[l]W[r] is zero.\n auto y = W->v_[n0 * l + c];\n F.mul(y, W->v_[n0 * r + c]);\n if (y != F.zero()) {\n return false;\n }\n } else {\n F.mul(x, W->v_[n0 * l + c]);\n F.mul(x, W->v_[n0 * r + c]);\n F.add(V->v_[n0 * g + c], x);\n }\n }\n }\n return true;\n }\n\n Elt /*R*/ round_c(Proof* pr, const Proof* pad,\n TranscriptSumcheck& ts, size_t layer, size_t round,\n CPoly poly, const Field& F) {\n check(round <= Proof::kMaxBindings, \"round <= kMaxBindings\");\n\n if (pad) {\n poly.sub(pad->l[layer].cp[round], F);\n }\n\n pr->l[layer].cp[round] = poly;\n return ts.round(poly);\n }\n\n Elt /*R*/ round_h(Proof* pr, const Proof* pad,\n TranscriptSumcheck& ts, size_t layer, size_t hand,\n size_t round, WPoly poly, const Field& F) {\n check(round <= Proof::kMaxBindings, \"round <= kMaxBindings\");\n if (pad) {\n poly.sub(pad->l[layer].hp[hand][round], F);\n }\n pr->l[layer].hp[hand][round] = poly;\n return ts.round(poly);\n }\n\n void end_layer(Proof* pr, const Proof* pad,\n TranscriptSumcheck& ts, size_t layer, const Elt wc[2],\n const Field& F) {\n Elt tt[2] = {wc[0], wc[1]};\n if (pad) {\n F.sub(tt[0], pad->l[layer].wc[0]);\n F.sub(tt[1], pad->l[layer].wc[1]);\n }\n\n pr->l[layer].wc[0] = tt[0];\n pr->l[layer].wc[1] = tt[1];\n\n ts.write(tt, 1, 2);\n }\n\n CPoly cpoly_at_dense(const Dense* D, corner_t p0, corner_t p1,\n const Field& F) {\n return CPoly::extend(D->t2_at_corners(p0, p1, F), F);\n }\n\n WPoly wpoly_at_dense(const Dense* D, corner_t p0, corner_t p1,\n const Field& F) {\n return WPoly::extend(D->t2_at_corners(p0, p1, F), F);\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_PROVER_LAYERS_H_\n"], ["/longfellow-zk/lib/circuits/logic/bit_adder.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_ADDER_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_ADDER_H_\n\n#include \n\n#include \n#include \n\n// Circuit element that maps bitvec V to a field element E\n// in such a way that:\n//\n// 1) addition can be performed efficiently, e.g. as field\n// addition or field multiplication\n// 2) given and E that is the sum of K bitvecs, a simple circuit\n// asserts that E = A mod 2^N\nnamespace proofs {\n\ntemplate \nclass BitAdderAux;\n\n// Use the additive group in fields with large characteristic\ntemplate \nclass BitAdderAux {\n public:\n using Field = typename Logic::Field;\n using BitW = typename Logic::BitW;\n using EltW = typename Logic::EltW;\n using Elt = typename Field::Elt;\n using BV = typename Logic::template bitvec;\n const Logic& l_;\n\n explicit BitAdderAux(const Logic& l) : l_(l) {}\n\n EltW as_field_element(const BV& v) const {\n const Logic& L = l_; // shorthand\n constexpr uint64_t uno = 1;\n EltW r = L.konst(L.zero());\n for (size_t i = 0; i < N; ++i) {\n auto vi = L.eval(v[i]);\n r = L.axpy(&r, L.elt(uno << i), vi);\n }\n return r;\n }\n\n EltW add(const EltW* a, const EltW& b) const { return l_.add(a, b); }\n EltW add(const BV& a, const BV& b) const {\n auto a_fe = as_field_element(a);\n auto b_fe = as_field_element(b);\n return add(&a_fe, b_fe);\n }\n EltW add(const std::vector& a) const {\n return l_.add(0, a.size(),\n [&](size_t i) { return as_field_element(a[i]); });\n }\n\n // assert that B = A + i*2^N for 0 <= i < k\n void assert_eqmod(const BV& a, const EltW& b, size_t k) const {\n const Logic& L = l_; // shorthand\n constexpr uint64_t uno = 1;\n EltW z = L.sub(&b, as_field_element(a));\n EltW zz = L.mul(0, k, [&](size_t i) {\n return L.sub(&z, L.konst((uno << N) * i));\n });\n L.assert0(zz);\n }\n};\n\n// Use the multiplicative group in GF(2^k)\ntemplate \nclass BitAdderAux {\n public:\n using Field = typename Logic::Field;\n using BitW = typename Logic::BitW;\n using EltW = typename Logic::EltW;\n using Elt = typename Field::Elt;\n using BV = typename Logic::template bitvec;\n const Logic& l_;\n\n explicit BitAdderAux(const Logic& l) : l_(l) {\n const Logic& L = l_; // shorthand\n const Field& F = l_.f_; // shorthand\n\n // assume that X is a root of unity of order large enough.\n Elt alpha = F.x();\n\n for (size_t i = 0; i < N; ++i) {\n alpha_2_i_[i] = alpha;\n alpha = L.mulf(alpha, alpha);\n }\n alpha_2_N_ = alpha;\n }\n\n EltW as_field_element(const BV& v) const {\n const Logic& L = l_; // shorthand\n return L.mul(0, N, [&](size_t i) {\n auto a2i = L.konst(alpha_2_i_[i]);\n return L.mux(&v[i], &a2i, L.konst(L.one()));\n });\n }\n\n EltW add(const EltW* a, const EltW& b) const { return l_.mul(a, b); }\n EltW add(const BV& a, const BV& b) const {\n auto a_fe = as_field_element(a);\n auto b_fe = as_field_element(b);\n return add(&a_fe, b_fe);\n }\n EltW add(const std::vector& a) const {\n return l_.mul(0, a.size(),\n [&](size_t i) { return as_field_element(a[i]); });\n }\n\n // assert that B = A + alpha^(i*2^N) for 0 <= i < k\n void assert_eqmod(const BV& a, const EltW& b, size_t k) const {\n const Logic& L = l_; // shorthand\n const Field& F = l_.f_; // shorthand\n\n std::vector p(k);\n p[0] = F.one();\n for (size_t i = 1; i < k; ++i) {\n p[i] = F.mulf(alpha_2_N_, p[i - 1]);\n }\n EltW aa = as_field_element(a);\n EltW prod = L.mul(0, k, [&](size_t i) {\n auto pi = L.konst(p[i]);\n return L.sub(&b, L.mul(&pi, aa));\n });\n L.assert0(prod);\n }\n\n private:\n Elt alpha_2_i_[N + 1];\n Elt alpha_2_N_;\n};\n\ntemplate \nusing BitAdder = BitAdderAux;\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_ADDER_H_\n"], ["/longfellow-zk/lib/circuits/cbor_parser/cbor_testing.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_TESTING_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_TESTING_H_\n\n#include \n\n#include \"circuits/cbor_parser/cbor.h\"\n#include \"circuits/cbor_parser/cbor_constants.h\"\n#include \"circuits/cbor_parser/cbor_witness.h\"\n#include \"circuits/logic/evaluation_backend.h\"\n#include \"circuits/logic/logic.h\"\n\n// The purpose of this class is to convert the witnesses from Elt to\n// EltW.\n//\n// Why?\n//\n// We want EltW in the evaluation backend to be a distinct type from\n// Elt. They are really the same thing, but we want to be able to\n// instantiate circuits in the compiler backend as well, and thus\n// circuits ought not to rely on the fact that EvaluationBackend::EltW\n// is really an Elt in disguise.\n// Consequently, tests in the evaluation backend must accept EltW.\n//\n// The witness generator must produce Elt, otherwise this forces the\n// inclusion of Logic in the app. We don't like that because Logic\n// is just a set of helpers to generate circuits, and the final app\n// is not supposed to generate circuits (since circuits are part of the\n// prover<->verifier API and so they must be set in stone in advance.)\n//\n// So this class is the price to be paid to maintain this typing\n// hygiene. Time will tell whether it was worth it.\n\nnamespace proofs {\n\ntemplate \nclass CborTesting {\n using EvalBackend = EvaluationBackend;\n using LogicF = Logic;\n using EltW = typename LogicF::EltW;\n using BitW = typename LogicF::BitW;\n using CborL = Cbor;\n using CborWitnessF = CborWitness;\n\n public:\n explicit CborTesting(const Field &F) : f_(F) {}\n\n void convert_witnesses(\n size_t n, typename CborL::v8 in[/*n*/],\n typename CborL::position_witness pw[/*n*/],\n typename CborL::global_witness &gw,\n const typename CborWitnessF::v8 inS[/*n*/],\n const typename CborWitnessF::position_witness pwS[/*n*/],\n const typename CborWitnessF::global_witness &gwS) const {\n const EvalBackend ebk(f_);\n const LogicF L(&ebk, f_);\n\n for (size_t i = 0; i < n; ++i) {\n for (size_t j = 0; j < 8; ++j) {\n in[i][j] = BitW(L.konst(inS[i][j]), f_);\n }\n pw[i].encoded_sel_header = L.konst(pwS[i].encoded_sel_header);\n }\n\n gw.invprod_decode = L.konst(gwS.invprod_decode);\n gw.cc0 = L.konst(gwS.cc0);\n gw.invprod_parse = L.konst(gwS.invprod_parse);\n }\n\n // Return an index that can be fed to a circuit in the\n // evaluation backend (i.e., a bit vector).\n typename CborL::vindex index(size_t j) const {\n const EvalBackend ebk(f_);\n const LogicF L(&ebk, f_);\n return L.template vbit(j);\n }\n\n private:\n const Field &f_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_TESTING_H_\n"], ["/longfellow-zk/lib/circuits/cbor_parser/cbor_pluck.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_PLUCK_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_PLUCK_H_\n#include \n#include \n\n#include \n\n#include \"algebra/interpolation.h\"\n#include \"algebra/poly.h\"\n#include \"circuits/logic/bit_plucker_constants.h\"\n#include \"circuits/logic/polynomial.h\"\n\nnamespace proofs {\n// Special plucker that decodes into a pair (B, J) where B is one bit,\n// and J is an array of NJ bits at most one of which can be set.\n//\n// B can assume one of two distinct values, and J can assume NJ+1\n// distinct values. Thus there are N = 2*(NJ+1) evaluation points.\n// We encode J as the index IJ of which bit is set, or IJ=NJ if no bit\n// is set.\ntemplate \nclass CborPlucker {\n public:\n using Field = typename Logic::Field;\n using BitW = typename Logic::BitW;\n using EltW = typename Logic::EltW;\n using Elt = typename Field::Elt;\n static constexpr size_t kN = 2 * (NJ + 1);\n using PolyN = Poly;\n using InterpolationN = Interpolation;\n const Logic& l_;\n PolyN pluckerb_;\n std::vector pluckerj_;\n\n explicit CborPlucker(const Logic& l) : l_(l), pluckerj_(NJ) {\n const Field& F = l_.f_; // shorthand\n // evaluation points\n PolyN X;\n for (size_t i = 0; i < kN; ++i) {\n X[i] = bit_plucker_point()(i, F);\n }\n\n // encode B in the low-order bit\n PolyN Y;\n for (size_t i = 0; i < kN; ++i) {\n Y[i] = F.of_scalar(i & 1);\n }\n pluckerb_ = InterpolationN::monomial_of_lagrange(Y, X, F);\n\n // encode J in the high-order bits\n for (size_t j = 0; j < NJ; ++j) {\n for (size_t i = 0; i < kN; ++i) {\n Y[i] = F.of_scalar((i >> 1) == j);\n }\n pluckerj_[j] = InterpolationN::monomial_of_lagrange(Y, X, F);\n }\n }\n\n BitW pluckb(const EltW& e) const {\n const Logic& L = l_; // shorthand\n const Polynomial P(L);\n\n EltW v = P.eval(pluckerb_, e);\n L.assert_is_bit(v);\n return BitW(v, L.f_);\n }\n\n typename Logic::template bitvec pluckj(const EltW& e) const {\n typename Logic::template bitvec r;\n const Logic& L = l_; // shorthand\n const Polynomial P(L);\n\n for (size_t j = 0; j < NJ; ++j) {\n EltW v = P.eval(pluckerj_[j], e);\n L.assert_is_bit(v);\n r[j] = BitW(v, L.f_);\n }\n\n return r;\n }\n};\n\ntemplate \nstruct cbor_plucker_point {\n using Elt = typename Field::Elt;\n static constexpr size_t kN = 2 * (NJ + 1);\n\n // packing of bits compatible with even_lagrange_basis():\n Elt operator()(bool b, size_t j, const Field& F) const {\n uint64_t bits = b + 2 * j;\n return bit_plucker_point()(bits, F);\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_PLUCK_H_\n"], ["/longfellow-zk/lib/zk/zk_prover.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ZK_ZK_PROVER_H_\n#define PRIVACY_PROOFS_ZK_LIB_ZK_ZK_PROVER_H_\n\n#include \n\n#include \n#include \n\n#include \"arrays/dense.h\"\n#include \"ligero/ligero_param.h\"\n#include \"ligero/ligero_prover.h\"\n#include \"random/random.h\"\n#include \"random/transcript.h\"\n#include \"sumcheck/circuit.h\"\n#include \"sumcheck/prover_layers.h\"\n#include \"sumcheck/transcript_sumcheck.h\"\n#include \"util/log.h\"\n#include \"util/panic.h\"\n#include \"zk/zk_common.h\"\n#include \"zk/zk_proof.h\"\n\nnamespace proofs {\n// ZK Prover\n//\n// This class implements a zero-knowledge argument over a sumcheck transcript\n// by first committing to a sumcheck witness and a random pad to encrypt\n// a sumcheck transcript, then running the sumcheck protocol over the original\n// claim and witness, but outputting the encrypted transcript, and finally\n// using a Ligero prover to prove the statement: \"the committed witness and\n// pad, when used to decrypt the encrypted sumcheck transcript satisfies the\n// sumcheck verifier.\"\n//\n// While this statement is complex, it can be implemented easily because\n// the sumcheck verifier essentially checks the evaluations of degree-2 or -3\n// polynomials, and performs one multiplication per layer of the circuit. The\n// Hyrax paper makes a similar observation, but uses an elliptic-curve based\n// proof, whereas here we use the Ligero system.\ntemplate \nclass ZkProver : public ProverLayers {\n using super = ProverLayers;\n using typename super::bindings;\n using Elt = typename Field::Elt;\n using typename super::inputs;\n\n public:\n ZkProver(const Circuit& CIRCUIT, const Field& F,\n const ReedSolomonFactory& rs_factory)\n : ProverLayers(F),\n c_(CIRCUIT),\n n_witness_(c_.ninputs - c_.npub_in),\n f_(F),\n rsf_(rs_factory),\n pad_(c_.nl),\n witness_(n_witness_),\n lqc_(c_.nl),\n lp_(nullptr) {}\n\n void commit(ZkProof& zkp, const Dense& W, Transcript& tp,\n RandomEngine& rng) {\n log(INFO, \"ZK Commit start\");\n\n // Copy witnesses for commitment\n // Layout of the com: 0 ...... start_pad len\n // Only commit the private witnesses, which begin at index c_.npub_in.\n for (size_t i = 0; i < n_witness_; ++i) {\n witness_[i] = W.v_[i + c_.npub_in];\n }\n\n // Rebase the circuit SUBFIELD_BOUNDARY (if any) to start at\n // NPUB_IN,\n size_t subfield_boundary = 0;\n if (c_.subfield_boundary >= c_.npub_in) {\n subfield_boundary = c_.subfield_boundary - c_.npub_in;\n }\n\n // Fill pad with random values, add pad to witness, record lqc.\n fill_pad(rng);\n ZkCommon::setup_lqc(c_, lqc_, n_witness_ /* = start_pad */);\n\n // Commit to witness and pad.\n lp_ = std::make_unique>(zkp.param);\n lp_->commit(zkp.com, tp, &witness_[0], subfield_boundary, &lqc_[0], rsf_,\n rng, f_);\n\n log(INFO, \"ZK Commitment done\");\n }\n\n bool prove(ZkProof& zkp, const Dense& W, Transcript& tsp) {\n check(lp_ != nullptr, \"must run commit before prove\");\n\n // Interpret W as public parameters, we only append\n // c_.npub_in elements of W to the transcript\n ZkCommon::initialize_sumcheck_fiat_shamir(tsp, c_, W, f_);\n Transcript tst = tsp.clone();\n\n // Run sumcheck to generate a padded proof.\n inputs in;\n auto V = super::eval_circuit(&in, &c_, W.clone(), f_);\n if (V == nullptr) {\n log(ERROR, \"eval_circuit failed\");\n return false;\n }\n for (size_t i = 0; i < V->n1_; ++i) {\n if (V->v_[i] != f_.zero()) {\n log(ERROR, \"V->v_[i] != F.zero()\");\n return false;\n };\n }\n bindings bnd;\n ProofAux aux(c_.nl);\n\n TranscriptSumcheck tsts(tst, f_);\n super::prove(&zkp.proof, &pad_, &c_, in, &aux, bnd, tsts, f_);\n log(INFO, \"ZK sumcheck done\");\n\n // 5. Simulate the verifier to assemble constraints on the committed vals.\n // Form the sparse matrix A and vector b such that A*w = b.\n std::vector> a;\n std::vector b;\n size_t ci = ZkCommon::verifier_constraints(c_, W, zkp.proof, &aux, a,\n b, tsp, n_witness_, f_);\n log(INFO, \"ZK constraints done\");\n\n // 6. Produce proof over commitment.\n // For FS soundness, it is ok for hash_of_A to be any string.\n // In the interactive version, the verifier provides a challenge for the\n // com proof. The last prover message is the (wc_l,wc_r) pair, and this\n // has already been added to the transcript.\n const LigeroHash hash_of_A{0xde, 0xad, 0xbe, 0xef};\n lp_->prove(zkp.com_proof, tsp, ci, a.size(), &a[0], hash_of_A, &lqc_[0],\n rsf_, f_);\n\n log(INFO, \"Prover Done: flag\");\n return true;\n }\n\n // Fill proof with random pad values for a given circuit.\n void fill_pad(RandomEngine& rng) {\n for (size_t i = 0; i < c_.nl; ++i) {\n for (size_t j = 0; j < c_.logc; ++j) {\n for (size_t k = 0; k < 4; ++k) {\n if (k != 1) { // P(1) optimization\n Elt r = rng.elt(f_);\n pad_.l[i].cp[j].t_[k] = r;\n witness_.push_back(r);\n } else {\n pad_.l[i].cp[j].t_[k] = f_.zero();\n }\n }\n }\n for (size_t j = 0; j < c_.l[i].logw; ++j) {\n for (size_t h = 0; h < 2; ++h) {\n for (size_t k = 0; k < 3; ++k) {\n if (k != 1) { // P(1) optimization\n Elt r = rng.elt(f_);\n pad_.l[i].hp[h][j].t_[k] = r;\n witness_.push_back(r);\n } else {\n pad_.l[i].hp[h][j].t_[k] = f_.zero();\n }\n }\n }\n }\n for (size_t k = 0; k < 2; ++k) {\n Elt r = rng.elt(f_);\n pad_.l[i].wc[k] = r;\n witness_.push_back(r);\n }\n\n // Commit to product of pads for product proof.\n Elt rr = f_.mulf(pad_.l[i].wc[0], pad_.l[i].wc[1]);\n witness_.push_back(rr);\n }\n }\n\n const Circuit& c_;\n const size_t n_witness_;\n const Field& f_;\n const ReedSolomonFactory& rsf_;\n Proof pad_;\n std::vector witness_;\n std::vector lqc_;\n std::unique_ptr> lp_;\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ZK_ZK_PROVER_H_\n"], ["/longfellow-zk/lib/algebra/fp_generic.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_GENERIC_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_GENERIC_H_\n\n#include \n#include \n#include \n#include \n#include \n\n#include \"algebra/nat.h\"\n#include \"algebra/static_string.h\"\n#include \"algebra/sysdep.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\nstruct PrimeFieldTypeTag {};\n\n/*\nThe Fp_generic class contains the implementation of a finite field.\n*/\ntemplate \nclass FpGeneric {\n public:\n // Type alias for a natural number, and the limbs within the nat are public\n // to allow casting and operations.\n using N = Nat;\n using limb_t = typename N::limb_t;\n using TypeTag = PrimeFieldTypeTag;\n\n static constexpr size_t kU64 = N::kU64;\n static constexpr size_t kBytes = N::kBytes;\n static constexpr size_t kSubFieldBytes = kBytes;\n static constexpr size_t kBits = N::kBits;\n static constexpr size_t kLimbs = N::kLimbs;\n\n static constexpr bool kCharacteristicTwo = false;\n static constexpr size_t kNPolyEvaluationPoints = 6;\n\n /* The Elt struct represented an element in the finite field.\n */\n struct Elt {\n N n;\n bool operator==(const Elt& y) const { return n == y.n; }\n bool operator!=(const Elt& y) const { return !operator==(y); }\n };\n\n explicit FpGeneric(const N& modulus) : m_(modulus), negm_(N{}) {\n negm_.sub(m_);\n\n // compute rawhalf = (m + 1) / 2 = floor(m / 2) + 1 since m is odd\n N raw_half = m_;\n raw_half.shiftr(1);\n raw_half.add(N(1));\n raw_half_ = Elt{raw_half};\n\n mprime_ = -inv_mod_b(m_.limb_[0]);\n rsquare_ = Elt{N(1)};\n for (size_t bits = 2 * kBits; bits > 0; bits--) {\n add(rsquare_, rsquare_);\n }\n\n for (uint64_t i = 0; i < sizeof(k_) / sizeof(k_[0]); ++i) {\n // convert k_[i] into montgomery form by calling mul0()\n // directly, since mul() requires k_[0] and k_[1] to be\n // defined\n k_[i] = Elt{N(i)};\n mul0(k_[i], rsquare_);\n }\n\n mone_ = negf(k_[1]);\n half_ = invertf(k_[2]);\n\n for (size_t i = 0; i < kNPolyEvaluationPoints; ++i) {\n poly_evaluation_points_[i] = of_scalar(i);\n if (i == 0) {\n inv_small_scalars_[i] = zero();\n } else {\n inv_small_scalars_[i] = invertf(poly_evaluation_points_[i]);\n }\n }\n }\n\n explicit FpGeneric(const StaticString s) : FpGeneric(N(s)) {}\n\n template \n explicit FpGeneric(const char (&s)[LEN]) : FpGeneric(N(s)) {}\n\n // Hack: works only if OPS::modulus is defined, and will\n // fail to compile otherwise.\n explicit FpGeneric() : FpGeneric(N(OPS::kModulus)) {}\n\n FpGeneric(const FpGeneric&) = delete;\n FpGeneric& operator=(const FpGeneric&) = delete;\n\n template \n Elt of_string(const char (&s)[N]) const {\n return of_charp(&s[0]);\n }\n\n Elt of_string(const StaticString& s) const { return of_charp(s.as_pointer); }\n\n std::optional of_untrusted_string(const char* s) const {\n auto maybe = N::of_untrusted_string(s);\n if (maybe.has_value() && maybe.value() < m_) {\n return to_montgomery(maybe.value());\n } else {\n return std::nullopt;\n }\n }\n\n // a += y\n void add(Elt& a, const Elt& y) const {\n if (kLimbs == 1) {\n limb_t aa = a.n.limb_[0], yy = y.n.limb_[0], mm = m_.limb_[0];\n a.n.limb_[0] = addcmovc(aa - mm, yy, aa + yy);\n } else {\n limb_t ah = add_limb(kLimbs, a.n.limb_, y.n.limb_);\n maybe_minus_m(a.n.limb_, ah);\n }\n }\n\n // a -= y\n void sub(Elt& a, const Elt& y) const {\n if (kLimbs == 1) {\n a.n.limb_[0] = sub_sysdep(a.n.limb_[0], y.n.limb_[0], m_.limb_[0]);\n } else {\n limb_t ah = sub_limb(kLimbs, a.n.limb_, y.n.limb_);\n maybe_plus_m(a.n.limb_, ah);\n }\n }\n\n // x *= y, Montgomery\n void mul(Elt& x, const Elt& y) const {\n if (optimized_mul) {\n if (x == zero() || y == one()) {\n return;\n }\n if (y == zero() || x == one()) {\n x = y;\n return;\n }\n }\n mul0(x, y);\n }\n\n // x = -x\n void neg(Elt& x) const {\n Elt y(k_[0]);\n sub(y, x);\n x = y;\n }\n\n // x = 1/x\n void invert(Elt& x) const { x = invertf(x); }\n\n // functional interface\n Elt addf(Elt a, const Elt& y) const {\n add(a, y);\n return a;\n }\n Elt subf(Elt a, const Elt& y) const {\n sub(a, y);\n return a;\n }\n Elt mulf(Elt a, const Elt& y) const {\n mul(a, y);\n return a;\n }\n Elt negf(Elt a) const {\n neg(a);\n return a;\n }\n\n // This is the binary extended gcd algorithm, modified\n // to return the inverse of x.\n Elt invertf(Elt x) const {\n N a = from_montgomery(x);\n N b = m_;\n Elt u = one();\n Elt v = zero();\n while (a != /*zero*/ N{}) {\n if ((a.limb_[0] & 0x1u) == 0) {\n a.shiftr(1);\n byhalf(u);\n } else {\n if (a < b) { // swap to maintain invariant\n std::swap(a, b);\n std::swap(u, v);\n }\n a.sub(b).shiftr(1); // a = (a-b)/2\n sub(u, v);\n byhalf(u);\n }\n }\n return v;\n }\n\n // Reference implementation, unused.\n N from_montgomery_reference(const Elt& x) const {\n Elt r{N(1)};\n mul(r, x);\n return r.n;\n }\n\n // Optimized implementation of from_montgomery_reference(), exploiting\n // the fact that the multiplicand is Elt{N(1)}.\n N from_montgomery(const Elt& x) const {\n limb_t a[2 * kLimbs + 1]; // uninitialized\n mov(kLimbs, a, x.n.limb_);\n a[kLimbs] = zero_limb();\n for (size_t i = 0; i < kLimbs; ++i) {\n a[i + kLimbs + 1] = zero_limb();\n OPS::reduction_step(&a[i], mprime_, m_);\n }\n maybe_minus_m(a + kLimbs, a[2 * kLimbs]);\n N r;\n mov(kLimbs, r.limb_, a + kLimbs);\n return r;\n }\n\n Elt to_montgomery(const N& xn) const {\n Elt x{xn};\n mul(x, rsquare_);\n return x;\n }\n\n bool in_subfield(const Elt& e) const { return true; }\n\n // The of_scalar methods should only be used on trusted inputs known\n // at compile time to be valid field elements. As a result, they return\n // Elt directly instead of std::optional, and panic if the condition is not\n // satisfied. All untrusted input should be handled via the of_bytes method.\n Elt of_scalar(uint64_t a) const { return of_scalar_field(a); }\n\n Elt of_scalar_field(uint64_t a) const { return of_scalar_field(N(a)); }\n Elt of_scalar_field(const std::array& a) const {\n return of_scalar_field(N(a));\n }\n Elt of_scalar_field(const N& a) const {\n check(a < m_, \"of_scalar must be less than m\");\n return to_montgomery(a);\n }\n\n std::optional of_bytes_field(const uint8_t ab[/* kBytes */]) const {\n N an = N::of_bytes(ab);\n if (an < m_) {\n return to_montgomery(an);\n } else {\n return std::nullopt;\n }\n }\n\n void to_bytes_field(uint8_t ab[/* kBytes */], const Elt& x) const {\n from_montgomery(x).to_bytes(ab);\n }\n\n std::optional of_bytes_subfield(const uint8_t ab[/* kBytes */]) const {\n return of_bytes_field(ab);\n }\n\n void to_bytes_subfield(uint8_t ab[/* kBytes */], const Elt& x) const {\n to_bytes_field(ab, x);\n }\n\n const Elt& zero() const { return k_[0]; }\n const Elt& one() const { return k_[1]; }\n const Elt& two() const { return k_[2]; }\n const Elt& half() const { return half_; }\n const Elt& mone() const { return mone_; }\n\n Elt poly_evaluation_point(size_t i) const {\n check(i < kNPolyEvaluationPoints, \"i < kNPolyEvaluationPoints\");\n return poly_evaluation_points_[i];\n }\n\n // return (X[k] - X[k - i])^{-1}, were X[i] is the\n // i-th poly evalaluation point.\n Elt newton_denominator(size_t k, size_t i) const {\n check(k < kNPolyEvaluationPoints, \"k < kNPolyEvaluationPoints\");\n check(i <= k, \"i <= k\");\n check(k != (k - i), \"k != (k - i)\");\n return inv_small_scalars_[/* k - (k - i) = */ i];\n }\n\n private:\n void maybe_minus_m(limb_t a[kLimbs], limb_t ah) const {\n limb_t a1[kLimbs];\n mov(kLimbs, a1, negm_.limb_);\n limb_t ah1 = add_limb(kLimbs, a1, a);\n cmovne(kLimbs, a, ah, ah1, a1);\n }\n void maybe_plus_m(limb_t a[kLimbs], limb_t ah) const {\n limb_t a1[kLimbs];\n mov(kLimbs, a1, a);\n (void)add_limb(kLimbs, a1, m_.limb_);\n cmovnz(kLimbs, a, ah, a1);\n }\n\n void byhalf(Elt& a) const {\n if (a.n.shiftr(1) != 0) {\n // the lost bit is a raw 1, not one() in Montgomery form,\n // hence we must add a raw 1/2, not half().\n add(a, raw_half_);\n }\n }\n\n // unoptimized montgomery multiplication that does not\n // depend on the constants zero() and one() being defined.\n void mul0(Elt& x, const Elt& y) const {\n limb_t a[2 * kLimbs + 1]; // uninitialized\n mulstep(a, x.n.limb_[0], y.n.limb_);\n for (size_t i = 1; i < kLimbs; ++i) {\n mulstep(a + i, x.n.limb_[i], y.n.limb_);\n }\n maybe_minus_m(a + kLimbs, a[2 * kLimbs]);\n mov(kLimbs, x.n.limb_, a + kLimbs);\n }\n\n template \n inline void mulstep(limb_t* a, limb_t x, const limb_t y[kLimbs]) const {\n if (kLimbs == 1) {\n // The general case (below) represents the (kLimbs+1)-word\n // product as L+(H<();\n check(first, \"mulstep template must be have first=true for 1 limb\");\n mulhl(1, a, a + 1, x, y);\n OPS::reduction_step(a, mprime_, m_);\n } else {\n limb_t l[kLimbs], h[kLimbs];\n a[kLimbs + 1] = zero_limb();\n if (first) {\n a[kLimbs] = zero_limb();\n mulhl(kLimbs, a, h, x, y);\n } else {\n mulhl(kLimbs, l, h, x, y);\n accum(kLimbs + 1, a, kLimbs, l);\n }\n accum(kLimbs + 1, a + 1, kLimbs, h);\n OPS::reduction_step(a, mprime_, m_);\n }\n }\n\n // This method should only be used on static strings known at\n // compile time to be valid field elements. We make it\n // private to prevent misuse.\n Elt of_charp(const char* s) const {\n Elt a(k_[0]);\n Elt base = of_scalar(10);\n if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) {\n s += 2;\n base = of_scalar(16);\n }\n\n for (; *s; s++) {\n Elt d = of_scalar(digit(*s));\n mul(a, base);\n add(a, d);\n }\n return a;\n }\n\n N m_;\n N negm_;\n Elt rsquare_;\n limb_t mprime_;\n Elt k_[3]; // small constants\n Elt half_; // 1/2\n Elt raw_half_;\n Elt mone_; // minus one\n Elt poly_evaluation_points_[kNPolyEvaluationPoints];\n Elt inv_small_scalars_[kNPolyEvaluationPoints];\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_GENERIC_H_\n"], ["/longfellow-zk/lib/gf2k/gf2_128.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_GF2K_GF2_128_H_\n#define PRIVACY_PROOFS_ZK_LIB_GF2K_GF2_128_H_\n\n#include \n\n#include \n#include \n#include \n#include \n#include \n\n#include \"gf2k/gf2poly.h\"\n#include \"gf2k/sysdep.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n\nstruct BinaryFieldTypeTag {};\n\ntemplate \nclass GF2_128 {\n // avoid writing static_cast(1) all the time.\n static constexpr size_t k1 = 1;\n\n public:\n using TypeTag = BinaryFieldTypeTag;\n\n // Fast representation of the field element via the system-dependent\n // SIMD type.\n using N = gf2_128_elt_t;\n\n // \"Slow\" representation of the field element as array of\n // C++ integral types.\n using N1 = GF2Poly<2>;\n\n static constexpr size_t kNPolyEvaluationPoints = 6;\n static constexpr size_t kLogBits = 7;\n static constexpr size_t kBits = k1 << kLogBits;\n static constexpr size_t kBytes = kBits / 8u;\n\n static constexpr size_t kSubFieldLogBits = subfield_log_bits;\n static constexpr size_t kSubFieldBits = k1 << kSubFieldLogBits;\n static constexpr size_t kSubFieldBytes = kSubFieldBits / 8u;\n\n static_assert(kBits == 8u * kBytes);\n static_assert(kSubFieldBits == 8u * kSubFieldBytes);\n static constexpr bool kCharacteristicTwo = true;\n\n struct Elt {\n N n;\n\n Elt() : n{} {}\n explicit Elt(N n_) : n(n_) {}\n\n // Don't bother using SIMD instructions for comparisons,\n // otherwise we have to complicate the sysdep API surface.\n // Unpack into uint64[2] and compute manually.\n bool operator==(const Elt& y) const { return unpack() == y.unpack(); }\n bool operator!=(const Elt& y) const { return !operator==(y); }\n\n // Returns the coefficient of x^i in the polynomial.\n uint8_t operator[](size_t i) const {\n auto n1 = uint64x2_of_gf2_128(n);\n if (i < 64) {\n return static_cast((n1[0] >> i) & 0x1);\n } else if (i < 128) {\n return static_cast((n1[1] >> (i - 64)) & 0x1);\n } else {\n return 0;\n }\n }\n\n N1 unpack() const { return N1(uint64x2_of_gf2_128(n)); }\n };\n\n explicit GF2_128() {\n kone_ = of_scalar_field(0b1);\n kx_ = of_scalar_field(0b10);\n\n // x^{-1} = x^127 + x^6 + x + 1\n std::array invx = {\n (1ull << 6) | (1ull << 1) | (1ull << 0),\n (1ull << (127 - 64)),\n };\n kinvx_ = of_scalar_field(invx);\n\n Elt g = subfield_generator();\n\n // basis of the subfield = {1, g, g^2, ...}\n beta_[0] = one();\n for (size_t i = 1; i < kSubFieldBits; ++i) {\n beta_[i] = mulf(beta_[i - 1], g);\n }\n\n // Reduce the basis to row-echelon form\n beta_ref();\n\n // Evaluation points. We use g^i for these as well\n poly_evaluation_points_[0] = zero();\n Elt gi = one();\n for (size_t i = 1; i < kNPolyEvaluationPoints; ++i) {\n poly_evaluation_points_[i] = gi;\n mul(gi, g);\n }\n\n for (size_t i = 1; i < kNPolyEvaluationPoints; i++) {\n for (size_t k = kNPolyEvaluationPoints; k-- > i;) {\n auto dx =\n subf(poly_evaluation_points_[k], poly_evaluation_points_[k - i]);\n check(dx != zero(), \"dx != zero()\");\n newton_denominators_[k][i] = invertf(dx);\n }\n }\n }\n\n GF2_128(const GF2_128&) = delete;\n GF2_128& operator=(const GF2_128&) = delete;\n\n // The bits of u are the coordinates with respect to the basis\n // beta_[] of the subfield.\n Elt of_scalar(uint64_t u) const {\n Elt t = zero();\n for (size_t k = 0; k < kSubFieldBits; ++k, u >>= 1) {\n if (u & 1) {\n add(t, beta_[k]);\n }\n }\n check(u == 0, \"of_scalar(u), too many bits\");\n return t;\n }\n\n Elt of_scalar_field(uint64_t n) const {\n std::array u = {n, 0};\n return of_scalar_field(u);\n }\n Elt of_scalar_field(const std::array& u) const {\n return Elt(gf2_128_of_uint64x2(u));\n }\n\n // The base_only flag is a placeholder that takes meaning when F is an\n // extension field.\n std::optional of_bytes_field(const uint8_t ab[/* kBytes */],\n bool base_only = true) const {\n N1 an = N1::of_bytes(ab);\n return of_scalar_field(an.u64());\n }\n\n void to_bytes_field(uint8_t ab[/* kBytes */], const Elt& x) const {\n x.unpack().to_bytes(ab);\n }\n\n bool in_subfield(Elt e) const {\n auto eu = solve(e);\n return eu.first == N1{};\n }\n\n std::optional of_bytes_subfield(\n const uint8_t ab[/* kSubFieldBytes */]) const {\n uint64_t u = 0;\n for (size_t i = kSubFieldBytes; i-- > 0;) {\n u <<= 8;\n u |= ab[i];\n }\n return of_scalar(u);\n }\n\n void to_bytes_subfield(uint8_t ab[/* kSubFieldBytes */], const Elt& x) const {\n auto eu = solve(x);\n check(eu.first == N1{}, \"eu.first == N1{}\");\n uint64_t u = eu.second;\n for (size_t i = 0; i < kSubFieldBytes; ++i) {\n ab[i] = u & 0xFFu;\n u >>= 8;\n }\n }\n\n // functional interface\n Elt addf(const Elt& x, const Elt& y) const {\n return Elt{gf2_128_add(x.n, y.n)};\n }\n Elt subf(const Elt& x, const Elt& y) const {\n return Elt{gf2_128_add(x.n, y.n)};\n }\n Elt mulf(const Elt& x, const Elt& y) const {\n return Elt{gf2_128_mul(x.n, y.n)};\n }\n Elt negf(const Elt& x) const { return x; }\n\n // two-operands interface\n void add(Elt& a, const Elt& y) const { a = addf(a, y); }\n void sub(Elt& a, const Elt& y) const { a = subf(a, y); }\n void mul(Elt& a, const Elt& y) const { a = mulf(a, y); }\n void neg(Elt& a) const { /* noop */ }\n void invert(Elt& a) const { a = invertf(a); }\n\n Elt zero() const { return Elt{}; }\n Elt one() const { return kone_; }\n Elt mone() const { return kone_; }\n Elt x() const { return kx_; }\n Elt invx() const { return kinvx_; }\n Elt beta(size_t i) const {\n check(i < kSubFieldBits, \"i < kSubFieldBits\");\n return beta_[i];\n }\n\n Elt poly_evaluation_point(size_t i) const {\n check(i < kNPolyEvaluationPoints, \"i < kNPolyEvaluationPoints\");\n return poly_evaluation_points_[i];\n }\n\n // return (X[k] - X[k - i])^{-1}, were X[i] is the\n // i-th poly evalaluation point.\n Elt newton_denominator(size_t k, size_t i) const {\n check(k < kNPolyEvaluationPoints, \"k < kNPolyEvaluationPoints\");\n check(i <= k, \"i <= k\");\n check(k != (k - i), \"k != (k - i)\");\n return newton_denominators_[k][i];\n }\n\n Elt invertf(Elt x) const {\n N1 a = x.unpack();\n // Let POLY be the generator of GF(2^128) as GF(2)[x]/(POLY(x)).\n // The Euclid algorithm would initialize B = POLY, but we cannot\n // store POLY in one N1. Instead, we use the invariant that B is\n // always \"odd\" throughout the algorithm, and we represent B =\n // BM1OX * X + 1, or BM1OX = (B - 1) / X. For B = POLY, BM1OX =\n // 1/X initially.\n N1 bm1ox = kinvx_.unpack();\n Elt u = one();\n Elt v = zero();\n while (a != N1(0)) {\n if (a.bit(0) == 0) {\n a.shiftr(1);\n byinvx(u);\n } else {\n // Now A is \"odd\". Write A = AM1OX * X + 1. This operation\n // be done in-place in the A variable, but we use another\n // name for clarity.\n N1 am1ox = a;\n am1ox.shiftr(1);\n\n // Normalize to the partial order degree(A) >= degree(B).\n // We use the stronger total order \"<\" which is consistent\n // with the partial order that we care about.\n if (am1ox < bm1ox) {\n std::swap(am1ox, bm1ox);\n std::swap(u, v);\n }\n am1ox.sub(bm1ox);\n sub(u, v);\n byinvx(u);\n a = am1ox;\n }\n }\n return v;\n }\n\n private:\n Elt kone_;\n Elt kx_;\n Elt kinvx_; // x^{-1}\n Elt beta_[kSubFieldBits]; // basis of the subfield viewed as a\n // vector space over GF(2)\n\n // LU decomposition of beta_, in unpacked format. We store L^{-1}\n // instead of L, see comments in beta_ref()\n N1 u_[kSubFieldBits];\n uint64_t linv_[kSubFieldBits];\n\n // ldnz_[i] stores the column index of the leading nonzero in u_[i].\n // This array is in principle redundant, since one can always\n // reconstruct it from u_, but we cache it for efficiency.\n size_t ldnz_[kSubFieldBits];\n\n Elt poly_evaluation_points_[kNPolyEvaluationPoints];\n Elt newton_denominators_[kNPolyEvaluationPoints][kNPolyEvaluationPoints];\n\n void byinvx(Elt& u) const { mul(u, kinvx_); }\n\n Elt subfield_generator() {\n // Let k = kSubFieldLogBits and n = kLogBits.\n // Let x be the generator of Field.\n\n // The generator r of the subfield is then\n // x^{(2^{2^n}-1)/(2^{2^k}-1)}\n\n // Compute r via the identity\n // (2^{2^n}-1)/(2^{2^k}-1) =\n // (2^{2^k}+1)*(2^{2^(k+1)}+1)*...*(2^{2^(n-1)}+1)\n Elt r(kx_);\n for (size_t i = kSubFieldLogBits; i < kLogBits; ++i) {\n // s <- r^{2^(2^i))\n Elt s(r);\n for (size_t j = 0; j < (1u << i); ++j) {\n mul(s, s);\n }\n // r <- r^{2^(2^i)+1)\n mul(r, s);\n }\n\n return r;\n }\n\n // beta_ref() is a just a variant of Gaussian elimination, but\n // because many such variants exist, we now explain the exact\n // mechanics of the algorithm.\n //\n // The problem that we need to solve is the inversion of\n // of_scalar(): given e = of_scalar(u), solve for u. The constraint\n // we have is that e and u are arrays of bits, conveniently stored\n // in uint64_t, and ideally we want to perform parallel bitwise\n // operations, as opposed to extracting individual bits.\n //\n // Consider the following block matrix, or tableau:\n //\n // [ B | -I ]\n // [ ------ ]\n // [ e | u ]\n //\n // Here e and u are reinterpreted as row vectors of GF(2) elements;\n // I is the identity matrix; B is such that B[i] (the i-th row of b)\n // is beta(i) (the i-th element of the basis of the subfield), and\n // beta(i) is interpreted as a row vector of 128 GF(2) elements.\n // (The minus sign in -I is irrelevant over GF(2), but would be\n // necessary over other fields.)\n //\n // We now postulate that the only allowed operation on the tableau\n // is \"axpy\": add one row to another, which we can do efficiently\n // via bitwise xor.\n //\n // of_scalar(u) can be reinterpreted in terms axpy as follows.\n // Start with a tableau with e=0. Reduce u to 0 via axpy\n // operations, e.g., for all i such that u[i] = 1, add row i to the\n // last row. Because this is exactly what of_scalar() does, at the\n // end of the process we have e = of_scalar(u). Because I is\n // full-rank, any sequence of axpy's that reduces u to 0 produces\n // the same e.\n //\n // We now want to invert the of_scalar() process. We cannot apply\n // the axpy operations in of_scalar() in reverse order, because we\n // don't know u, and thus we don't know which operations\n // of_scalar(u) would apply. However, because B is a basis, any\n // sequence of axpy operations that starts with u=0 and reduces e to\n // 0 reconstructs the same u.\n //\n // For lack of a better idea, we choose the following sequence of\n // axpy operations. First reduce B to row-echelon form via axpy\n // operations on B, and then reduce e to zero via additional axpy\n // operations. A matrix U is in row-echelon form if the following\n // condition holds: i' > i implies that U[i'][ldnz[i]] = 0, where\n // ldnz[i] is the column index of the leading nonzero in row i.\n //\n // Since B is constant, we choose to pre-compute the row-echelon\n // form of B in beta_ref(), and finish the process in solve() when e\n // is known, for multiple values of e.\n //\n // As it happens, reducing B to row-echelon transforms the -I\n // in the upper-right block to -L^{-1}, where B=LU is the LU\n // factorization of B. We don't use this correspondence anywhere\n // in the code other than in the choice of the name Linv for the block.\n //\n void beta_ref() {\n for (size_t i = 0; i < kSubFieldBits; ++i) {\n // B in the tableau, becomes U at the end.\n u_[i] = beta_[i].unpack();\n\n // -I in the tableau, becomes -L^{-1} at the end.\n // Ignore the minus sign over GF(2).\n linv_[i] = (static_cast(1) << i);\n }\n\n // Reduce B to row-echelon form.\n //\n // Invariant: B([0,RNK), [0,J)) is already in row-echelon form.\n // The loop body extends this property to J+1 and possibly RNK+1.\n size_t rnk = 0;\n for (size_t j = 0; rnk < kSubFieldBits && j < kBits; ++j) {\n // find pivot at row >= RNK in column J\n for (size_t i = rnk; i < kSubFieldBits; ++i) {\n if (u_[i].bit(j)) {\n std::swap(u_[rnk], u_[i]);\n std::swap(linv_[rnk], linv_[i]);\n goto have_pivot;\n }\n }\n // If we get here there is no pivot. Keep the rank RNK the same\n // and proceed to the next column ++J\n continue;\n\n have_pivot:\n ldnz_[rnk] = j;\n\n // Pivot on [rnk][j].\n for (size_t i1 = rnk + 1; i1 < kSubFieldBits; ++i1) {\n if (u_[i1].bit(j)) {\n u_[i1].add(u_[rnk]); // axpy on U\n linv_[i1] ^= linv_[rnk]; // axpy on Linv\n }\n }\n ++rnk;\n }\n\n // the basis is indeed a basis:\n check(rnk == kSubFieldBits, \"rnk == kSubFieldBits\");\n }\n\n std::pair solve(const Elt& e) const {\n uint64_t u = 0;\n N1 ue = e.unpack();\n for (size_t rnk = 0; rnk < kSubFieldBits; ++rnk) {\n size_t j = ldnz_[rnk];\n if (ue.bit(j)) {\n ue.add(u_[rnk]);\n u ^= linv_[rnk];\n }\n }\n\n return std::pair(ue, u);\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_GF2K_GF2_128_H_\n"], ["/longfellow-zk/lib/zk/zk_proof.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ZK_ZK_PROOF_H_\n#define PRIVACY_PROOFS_ZK_LIB_ZK_ZK_PROOF_H_\n\n#include \n#include \n#include \n#include \n\n#include \"ligero/ligero_param.h\"\n#include \"merkle/merkle_commitment.h\"\n#include \"merkle/merkle_tree.h\"\n#include \"sumcheck/circuit.h\"\n#include \"util/log.h\"\n#include \"util/readbuffer.h\"\n#include \"util/serialization.h\"\n#include \"zk/zk_common.h\"\n\nnamespace proofs {\n\n// ZkProof class handles proof serialization.\n//\n// We expect circuits to be created and stored locally by the prover and\n// verifier respectively, and thus the circuit representations are trusted and\n// are assumed to contain parameters that do not induce arithmetic overflows.\n// For example, we assume that values like c.logw and c.logc are smaller than\n// 2^24 and therefore do not cause any overflows (even on 32b machines) in the\n// range/length calculations that are performed during serialization.\n//\n// An earlier experiment implemented the IO methods using protobuf parsing.\n// Despite applying techniques like arena allocation, those methods required\n// an order of magnitude more time.\ntemplate \nstruct ZkProof {\n public:\n const Circuit &c;\n Proof proof;\n LigeroParam param;\n LigeroCommitment com;\n LigeroProof com_proof;\n\n // The max run length is 2^25, in order to prevent overflow issues on 32b\n // machines when performing length calculations during serialization.\n constexpr static size_t kMaxRunLen = (1 << 25);\n\n constexpr static size_t kMaxNumDigests = (1 << 25);\n\n typedef typename Field::Elt Elt;\n\n explicit ZkProof(const Circuit &c, size_t rate, size_t req)\n : c(c),\n proof(c.nl),\n param((c.ninputs - c.npub_in) + ZkCommon::pad_size(c), c.nl,\n rate, req),\n com_proof(¶m) {}\n\n // Maximum size of the proof in bytes. The actual size will be smaller\n // because the Merkle proof is batched.\n size_t size() const {\n return Digest::kLength +\n\n proof.size() * Field::kBytes +\n\n com_proof.block * 2 * Field::kBytes +\n com_proof.nreq * com_proof.nrow * Field::kBytes +\n com_proof.nreq * com_proof.mc_pathlen * Digest::kLength;\n }\n\n void write(std::vector &buf, const Field &F) const {\n size_t s0 = buf.size();\n write_com(com, buf, F);\n size_t s1 = buf.size();\n write_sc_proof(proof, buf, F);\n size_t s2 = buf.size();\n write_com_proof(com_proof, buf, F);\n size_t s3 = buf.size();\n log(INFO,\n \"com:%zu, sc:%zu, com_proof:%zu [%zu el, %zu el, %zu d in %zu \"\n \"rows]: %zub\",\n s1 - s0, s2 - s1, s3 - s2, 2 * com_proof.block,\n com_proof.nreq * com_proof.nrow, com_proof.merkle.path.size(),\n com_proof.nrow, s3);\n }\n\n // The read function returns false on error or underflow.\n bool read(ReadBuffer &buf, const Field &F) {\n if (!read_com(com, buf, F)) return false;\n if (!read_sc_proof(proof, buf, F)) return false;\n if (!read_com_proof(com_proof, buf, F)) return false;\n return true;\n }\n\n void write_sc_proof(const Proof &pr, std::vector &buf,\n const Field &F) const {\n check(c.logc == 0, \"cannot write sc proof with logc != 0\");\n for (size_t i = 0; i < pr.l.size(); ++i) {\n for (size_t wi = 0; wi < c.l[i].logw; ++wi) {\n for (size_t k = 0; k < 3; ++k) {\n // Optimization: do not send p(1) as it is implied by constraints.\n if (k != 1) {\n write_elt(pr.l[i].hp[0][wi].t_[k], buf, F);\n write_elt(pr.l[i].hp[1][wi].t_[k], buf, F);\n }\n }\n }\n write_elt(pr.l[i].wc[0], buf, F);\n write_elt(pr.l[i].wc[1], buf, F);\n }\n }\n\n void write_com(const LigeroCommitment &com0, std::vector &buf,\n const Field &F) const {\n buf.insert(buf.end(), com0.root.data, com0.root.data + Digest::kLength);\n }\n\n void write_com_proof(const LigeroProof &pr, std::vector &buf,\n const Field &F) const {\n for (size_t i = 0; i < pr.block; ++i) {\n write_elt(pr.y_ldt[i], buf, F);\n }\n for (size_t i = 0; i < pr.dblock; ++i) {\n write_elt(pr.y_dot[i], buf, F);\n }\n for (size_t i = 0; i < pr.r; ++i) {\n write_elt(pr.y_quad_0[i], buf, F);\n }\n for (size_t i = 0; i < pr.dblock - pr.block; ++i) {\n write_elt(pr.y_quad_2[i], buf, F);\n }\n\n // write all the Merkle nonces\n for (size_t i = 0; i < pr.nreq; ++i) {\n write_nonce(pr.merkle.nonce[i], buf);\n }\n\n // The format of the opened rows consists of a run of full-field elements,\n // then a run of base-field elements, and finally a run of full-field\n // elements. To compress, we employ a run-length encoding approach.\n size_t ci = 0;\n bool subfield_run = false;\n while (ci < pr.nreq * pr.nrow) {\n size_t runlen = 0;\n while (ci + runlen < pr.nreq * pr.nrow && runlen < kMaxRunLen &&\n F.in_subfield(pr.req[ci + runlen]) == subfield_run) {\n ++runlen;\n }\n write_size(runlen, buf);\n for (size_t i = ci; i < ci + runlen; ++i) {\n if (subfield_run) {\n write_subfield_elt(pr.req[i], buf, F);\n } else {\n write_elt(pr.req[i], buf, F);\n }\n }\n ci += runlen;\n subfield_run = !subfield_run;\n }\n\n write_size(pr.merkle.path.size(), buf);\n for (size_t i = 0; i < pr.merkle.path.size(); ++i) {\n write_digest(pr.merkle.path[i], buf);\n }\n }\n\n private:\n void write_elt(const Elt &x, std::vector &buf,\n const Field &F) const {\n uint8_t tmp[Field::kBytes];\n F.to_bytes_field(tmp, x);\n buf.insert(buf.end(), tmp, tmp + Field::kBytes);\n }\n\n void write_subfield_elt(const Elt &x, std::vector &buf,\n const Field &F) const {\n uint8_t tmp[Field::kSubFieldBytes];\n F.to_bytes_subfield(tmp, x);\n buf.insert(buf.end(), tmp, tmp + Field::kSubFieldBytes);\n }\n\n void write_digest(const Digest &x, std::vector &buf) const {\n buf.insert(buf.end(), x.data, x.data + Digest::kLength);\n }\n\n void write_nonce(const MerkleNonce &x, std::vector &buf) const {\n buf.insert(buf.end(), x.bytes, x.bytes + MerkleNonce::kLength);\n }\n\n // Assumption is that all of the sizes of arrays that are part of proofs\n // fit into 4 bytes, and can thus work on 32-b machines.\n void write_size(size_t g, std::vector &buf) const {\n for (size_t i = 0; i < 4; ++i) {\n buf.push_back(static_cast(g & 0xff));\n g >>= 8;\n }\n }\n\n bool read_sc_proof(Proof &pr, ReadBuffer &buf, const Field &F) {\n if (c.logc != 0) return false;\n for (size_t i = 0; i < pr.l.size(); ++i) {\n size_t needed = (c.l[i].logw * (3 - 1) * 2 + 2) * Field::kBytes;\n if (!buf.have(needed)) return false;\n for (size_t wi = 0; wi < c.l[i].logw; ++wi) {\n for (size_t k = 0; k < 3; ++k) {\n // Optimization: the p(1) value was not sent.\n if (k != 1) {\n for (size_t hi = 0; hi < 2; ++hi) {\n auto v = read_elt(buf, F);\n if (v) {\n pr.l[i].hp[hi][wi].t_[k] = v.value();\n } else {\n return false;\n }\n }\n } else {\n pr.l[i].hp[0][wi].t_[k] = F.zero();\n pr.l[i].hp[1][wi].t_[k] = F.zero();\n }\n }\n }\n for (size_t wi = 0; wi < 2; ++wi) {\n auto v = read_elt(buf, F);\n if (v) {\n pr.l[i].wc[wi] = v.value();\n } else {\n return false;\n }\n }\n }\n return true;\n }\n\n bool read_com(LigeroCommitment &com0, ReadBuffer &buf,\n const Field &F) {\n if (!buf.have(Digest::kLength)) return false;\n read_digest(buf, com0.root);\n return true;\n }\n\n bool read_com_proof(LigeroProof &pr, ReadBuffer &buf, const Field &F) {\n if (!buf.have(pr.block * Field::kBytes)) return false;\n for (size_t i = 0; i < pr.block; ++i) {\n auto v = read_elt(buf, F);\n if (v) {\n pr.y_ldt[i] = v.value();\n } else {\n return false;\n }\n }\n\n if (!buf.have(pr.dblock * Field::kBytes)) return false;\n for (size_t i = 0; i < pr.dblock; ++i) {\n auto v = read_elt(buf, F);\n if (v) {\n pr.y_dot[i] = v.value();\n } else {\n return false;\n }\n }\n\n if (!buf.have(pr.r * Field::kBytes)) return false;\n for (size_t i = 0; i < pr.r; ++i) {\n auto v = read_elt(buf, F);\n if (v) {\n pr.y_quad_0[i] = v.value();\n } else {\n return false;\n }\n }\n\n if (!buf.have((pr.dblock - pr.block) * Field::kBytes)) return false;\n for (size_t i = 0; i < pr.dblock - pr.block; ++i) {\n auto v = read_elt(buf, F);\n if (v) {\n pr.y_quad_2[i] = v.value();\n } else {\n return false;\n }\n }\n\n if (!buf.have(pr.nreq * MerkleNonce::kLength)) return false;\n for (size_t i = 0; i < pr.nreq; ++i) {\n read_nonce(buf, pr.merkle.nonce[i]);\n }\n\n // Decode runs of real and full Field elements.\n size_t ci = 0;\n bool subfield_run = false;\n while (ci < pr.nreq * pr.nrow) {\n if (!buf.have(4)) return false;\n size_t runlen = read_size(buf); /* untrusted size input */\n if (runlen >= kMaxRunLen || ci + runlen > pr.nreq * pr.nrow) return false;\n if (subfield_run) {\n if (!buf.have(runlen * Field::kSubFieldBytes)) return false;\n for (size_t i = ci; i < ci + runlen; ++i) {\n auto v = read_subfield_elt(buf, F);\n if (v) {\n pr.req[i] = v.value();\n } else {\n return false;\n }\n }\n } else {\n if (!buf.have(runlen * Field::kBytes)) return false;\n for (size_t i = ci; i < ci + runlen; ++i) {\n auto v = read_elt(buf, F);\n if (v) {\n pr.req[i] = v.value();\n } else {\n return false;\n }\n }\n }\n ci += runlen;\n subfield_run = !subfield_run;\n }\n\n if (!buf.have(4)) return false;\n size_t sz = read_size(buf); /* untrusted size input */\n\n // Merkle proofs of length < NREQ are not valid in the zk proof setting.\n if (sz < pr.nreq || sz >= kMaxNumDigests) return false; // avoid overflow\n if (!buf.have(sz * Digest::kLength)) return false;\n\n // Sanity check, the proof should never be larger than this.\n // That value should always fit into memory, so this check aims to avoid\n // an exception by resize() if there is not enough memory to resize.\n if (sz > pr.nreq * pr.mc_pathlen) return false;\n\n pr.merkle.path.resize(sz);\n for (size_t i = 0; i < sz; ++i) {\n read_digest(buf, pr.merkle.path[i]);\n }\n return true;\n }\n\n std::optional read_elt(ReadBuffer &buf, const Field &F) const {\n return F.of_bytes_field(buf.next(Field::kBytes));\n }\n\n std::optional read_subfield_elt(ReadBuffer &buf, const Field &F) const {\n return F.of_bytes_subfield(buf.next(Field::kSubFieldBytes));\n }\n\n void read_digest(ReadBuffer &buf, Digest &x) const {\n buf.next(Digest::kLength, x.data);\n }\n\n void read_nonce(ReadBuffer &buf, MerkleNonce &x) const {\n buf.next(MerkleNonce::kLength, x.bytes);\n }\n\n size_t read_size(ReadBuffer &buf) { return u32_of_le(buf.next(4)); }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ZK_ZK_PROOF_H_\n"], ["/longfellow-zk/lib/circuits/compiler/schedule.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_SCHEDULE_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_SCHEDULE_H_\n\n#include \n#include \n\n#include \n#include \n#include \n\n#include \"algebra/compare.h\"\n#include \"arrays/affine.h\"\n#include \"circuits/compiler/node.h\"\n#include \"sumcheck/circuit.h\"\n#include \"sumcheck/quad.h\"\n#include \"util/ceildiv.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\ntemplate \nclass Scheduler {\n using Elt = typename Field::Elt;\n using nodeinfo = NodeInfoF;\n using node = NodeF;\n using size_t_for_storage = term::size_t_for_storage;\n using quad_corner_t = typename Quad::quad_corner_t;\n\n const Field& f_;\n const std::vector& nodes_;\n\n public:\n size_t nwires_;\n size_t nquad_terms_;\n size_t nwires_overhead_;\n\n Scheduler(const std::vector& nodes, const Field& f)\n : f_(f),\n nodes_(nodes),\n nwires_(0),\n nquad_terms_(0),\n nwires_overhead_(0) {}\n\n std::unique_ptr> mkcircuit(const std::vector& constants,\n size_t depth_ub, size_t nc) {\n std::unique_ptr> c = std::make_unique>();\n\n // number of layers and copies\n c->nl = depth_ub - 1; // depth 0 = input nodes, not a \"layer\"\n c->nc = nc;\n c->logc = lg(nc);\n\n auto lnodes = order_by_layer(constants, depth_ub);\n\n // TODO [matteof 2025-03-12] ASSIGN_WIRE_IDS() renames LNODES in\n // order to sort it and assign LNODES[].DESIRED_WIRE ID. Then it\n // throws away the renamed LNODES. Then FILL_LAYERS() renames\n // LNODES again in order to produce the final quad. It would be\n // better to produce the quad directly in ASSIGN_WIRE_IDS(). Punt\n // for now, this is just a performance optimization of the\n // compiler anyway.\n //\n assign_wire_ids(lnodes);\n fill_layers(c.get(), depth_ub, lnodes);\n\n return c;\n }\n\n private:\n // per-layer representation of nodes and terms\n struct lterm {\n Elt k;\n quad_corner_t lop0, lop1;\n };\n struct lnode {\n quad_corner_t desired_wire_id;\n\n // Copy wires are forced to be distinct from wires in the\n // original dag, in order to avoid ambiguity in renaming.\n //\n // Copy wires are always of the form 1*op, which doesn't\n // normally appear in the dag because the algebraic simplifier\n // reduces it to op. However, one can in theory create such\n // a node by judicious use of linear(). Rather than\n // trying to figure out which circuits one is not allowed\n // to write, it seems simpler to just handle this case\n // uniformly.\n bool is_copy_wire;\n\n std::vector lterms;\n\n lnode(quad_corner_t desired_wire_id, bool is_copy_wire,\n const std::vector& lterms)\n : desired_wire_id(desired_wire_id),\n is_copy_wire(is_copy_wire),\n lterms(lterms) {}\n };\n\n quad_corner_t lop_of_op_at_depth(\n const std::vector>& lop, size_t op,\n size_t d) const {\n const node& n = nodes_.at(op);\n return lop.at(op).at(d - n.info.depth);\n }\n\n // Convert the DAG of nodes into a layered dag of lnodes.\n std::vector> order_by_layer(\n const std::vector& constants, size_t depth_ub) {\n // The source DAG is indexed by NODES_[OP].\n // The destination dag uses a two-dimensional indexing\n // scheme LNODES[D][LOP], where D is the depth.\n\n // A single value NODES_[OP] may be replicated multiple times in\n // LNODES. The mapping is maintained in array LOPS such that\n // LOPS[OP][D - D0] contains the LOP index of node OP at depth D.\n // D0 is the depth at which NODES_[OP] is first computed, and\n // there is no point in storing LOPS[OP] for D < D0.\n\n std::vector> lnodes(depth_ub);\n std::vector> lops(nodes_.size());\n\n nwires_overhead_ = 0;\n\n for (size_t op = 0; op < nodes_.size(); ++op) {\n const auto& n = nodes_[op];\n const nodeinfo& nfo = n.info;\n if (nfo.is_needed && !n.zero()) {\n size_t d = nfo.depth;\n\n // Allocate the LOP at depth D\n quad_corner_t lop = quad_corner_t(lnodes.at(d).size());\n lops.at(op).push_back(lop);\n\n // create a LOPS entry for depth D\n /*scope*/ {\n std::vector lterms;\n for (const auto& t : n.terms) {\n lterm lt = {\n .k = constants.at(t.ki),\n .lop0 = lop_of_op_at_depth(lops, t.op0, d - 1),\n .lop1 = lop_of_op_at_depth(lops, t.op1, d - 1),\n };\n lterms.push_back(lt);\n }\n lnodes.at(d).push_back(lnode(nfo.desired_wire_id(d, depth_ub),\n /*is_copy_wire=*/false, lterms));\n }\n\n // create copy wires\n for (d = nfo.depth + 1; d < nfo.max_needed_depth; ++d) {\n quad_corner_t lop_dm1 = lop;\n\n // allocate the LOP at depth D\n lop = quad_corner_t(lnodes.at(d).size());\n lops.at(op).push_back(lop);\n\n std::vector lterms;\n\n // Insert a multiplication by one of the layer\n // at the previous layer.\n lterm lt = {\n .k = f_.one(),\n .lop0 = quad_corner_t(0),\n .lop1 = lop_dm1,\n };\n lterms.push_back(lt);\n lnodes.at(d).push_back(lnode(nfo.desired_wire_id(d, depth_ub),\n /*is_copy_wire=*/true, lterms));\n ++nwires_overhead_;\n } // for copy wires\n } // if needed\n } // for OP\n\n return lnodes;\n }\n\n //------------------------------------------------------------\n // canonical assignment of wire ids\n //------------------------------------------------------------\n //\n // The canonicalization order is a matter of convention.\n // We make some arbitrary choices that appear to interact\n // better with ZSTD compression. The label [ARBITRARY CHOICE]\n // denotes all places in the code where this occurs.\n //\n class renamed_lterm {\n public:\n Elt k_;\n quad_corner_t rlop0_, rlop1_;\n\n // [ARBITRARY CHOICE] Consistent with corner::canonicalize() in\n // sumcheck/quad.h\n renamed_lterm(const Elt& k, quad_corner_t rlop0, quad_corner_t rlop1)\n : k_(k),\n rlop0_(std::min(rlop0, rlop1)),\n rlop1_(std::max(rlop0, rlop1)) {}\n\n bool operator==(const renamed_lterm& y) const {\n return rlop0_ == y.rlop0_ && rlop1_ == y.rlop1_ && k_ == y.k_;\n }\n\n // canonical order\n static bool compare(const renamed_lterm& a, const renamed_lterm& b,\n const Field& F) {\n if (a.rlop0_ < b.rlop0_) return true;\n if (a.rlop0_ > b.rlop0_) return false;\n if (a.rlop1_ < b.rlop1_) return true;\n if (a.rlop1_ > b.rlop1_) return false;\n return elt_less_than(a.k_, b.k_, F);\n }\n };\n\n class renamed_lnode {\n public:\n quad_corner_t desired_wire_id_;\n quad_corner_t original_wire_index_;\n bool is_copy_wire_;\n std::vector rlterms_;\n\n renamed_lnode(quad_corner_t desired_wire_id,\n quad_corner_t original_wire_index, bool is_copy_wire,\n const std::vector& rlterms)\n : desired_wire_id_(desired_wire_id),\n original_wire_index_(original_wire_index),\n is_copy_wire_(is_copy_wire),\n rlterms_(rlterms) {}\n\n bool operator==(const renamed_lnode& y) const {\n if (is_copy_wire_ != y.is_copy_wire_) return false;\n if (rlterms_.size() != y.rlterms_.size()) return false;\n size_t l = rlterms_.size();\n for (size_t i = 0; i < l; ++i) {\n if (!(rlterms_[i] == y.rlterms_[i])) return false;\n }\n return true;\n }\n\n // canonical order\n static bool compare(const renamed_lnode& ra, const renamed_lnode& rb,\n const Field& F) {\n // Defined before undefined. This choice is mandated by the\n // fact that the range of defined wire id's starts at 0.\n if (ra.desired_wire_id_ != nodeinfo::kWireIdUndefined) {\n if (rb.desired_wire_id_ != nodeinfo::kWireIdUndefined) {\n return ra.desired_wire_id_ < rb.desired_wire_id_;\n } else {\n return true;\n }\n } else {\n if (rb.desired_wire_id_ != nodeinfo::kWireIdUndefined) {\n return false;\n }\n // else both undefined\n }\n\n // [ARBITRARY CHOICE] Lexicographic order on the reverse of the\n // terms array. This seems to compress much better than\n // the normal lexicographic order.\n for (size_t ia = ra.rlterms_.size(), ib = rb.rlterms_.size();\n ia-- > 0 && ib-- > 0;) {\n const renamed_lterm& rlta = ra.rlterms_[ia];\n const renamed_lterm& rltb = rb.rlterms_[ib];\n if (renamed_lterm::compare(rlta, rltb, F)) return true;\n if (renamed_lterm::compare(rltb, rlta, F)) return false;\n }\n\n // [ARBITRARY CHOICE] If the common suffixes are the same, the\n // shorter terms come first.\n if (ra.rlterms_.size() < rb.rlterms_.size()) return true;\n if (ra.rlterms_.size() > rb.rlterms_.size()) return false;\n\n // Nodes that were in the original dag come first.\n if (!ra.is_copy_wire_ && rb.is_copy_wire_) return true;\n if (!rb.is_copy_wire_ && ra.is_copy_wire_) return false;\n\n // equal, i.e., not less-than\n return false;\n }\n };\n\n template \n bool uniq(const std::vector& sorted) {\n for (size_t i = 0; i + 1 < sorted.size(); ++i) {\n if (sorted[i] == sorted[i + 1]) return false;\n }\n return true;\n }\n\n void assign_wire_ids(std::vector>& lnodes) {\n // all inputs are expected to be defined already\n assert_all_desired_wire_id_defined(lnodes.at(0));\n\n for (size_t d = 1; d < lnodes.size(); ++d) {\n const std::vector& lnodes_at_dm1 = lnodes.at(d - 1);\n const std::vector& lnodes_at_d = lnodes.at(d);\n\n // Create a renamed clone of LNODES_AT_D, in which all\n // the LOP's are mapped to their desired wire id's\n // at the previous layer. We use different types\n // to avoid any possibility of confusion.\n std::vector renamed_at_d;\n\n quad_corner_t original_wire_index(0);\n for (const lnode& ln : lnodes_at_d) {\n std::vector rlterms;\n\n // rename all terms\n rlterms.reserve(ln.lterms.size());\n for (const lterm& lt : ln.lterms) {\n rlterms.push_back(renamed_lterm(\n lt.k,\n lnodes_at_dm1.at(static_cast(lt.lop0)).desired_wire_id,\n lnodes_at_dm1.at(static_cast(lt.lop1)).desired_wire_id));\n }\n\n // canonicalize the terms order\n std::sort(rlterms.begin(), rlterms.end(),\n [&](const renamed_lterm& a, const renamed_lterm& b) {\n return renamed_lterm::compare(a, b, f_);\n });\n\n // Terms must be unique, otherwise the canonicalization is\n // ill-defined. Uniqueness is guaranteed by the algebraic\n // simplifier, but assert it for good measure.\n check(uniq(rlterms), \"rlterms not unique\");\n\n renamed_at_d.push_back(renamed_lnode(\n ln.desired_wire_id, original_wire_index, ln.is_copy_wire, rlterms));\n ++original_wire_index;\n }\n\n check(renamed_at_d.size() == lnodes_at_d.size(),\n \"renamed_at_d.size() == lnodes_at_d.size()\");\n\n std::sort(renamed_at_d.begin(), renamed_at_d.end(),\n [&](const renamed_lnode& a, const renamed_lnode& b) {\n return renamed_lnode::compare(a, b, f_);\n });\n\n // Nodes must be unique, otherwise the canonicalization is\n // ill-defined.\n check(uniq(renamed_at_d), \"renamed_at_d not unique\");\n\n quad_corner_t wid(0);\n std::vector& wlnodes_at_d = lnodes.at(d);\n\n for (const renamed_lnode& ln : renamed_at_d) {\n lnode& lnpi =\n wlnodes_at_d.at(static_cast(ln.original_wire_index_));\n if (lnpi.desired_wire_id != nodeinfo::kWireIdUndefined) {\n // We must have computed the same wire id\n check(wid == lnpi.desired_wire_id, \"wid == lnpi.desired_wire_id\");\n } else {\n lnpi.desired_wire_id = wid;\n }\n wid++;\n }\n }\n }\n\n void assert_all_desired_wire_id_defined(const std::vector& layer) {\n for (const auto& ln : layer) {\n check(ln.desired_wire_id != nodeinfo::kWireIdUndefined,\n \"ln.desired_wire_id != kWireIdUndefined\");\n }\n }\n\n void fill_layers(Circuit* c, size_t depth_ub,\n const std::vector>& lnodes) {\n check(depth_ub == lnodes.size(), \"depth_ub == lnodes.size()\");\n\n corner_t nv = corner_t(lnodes.at(depth_ub - 1).size());\n\n nwires_ = nv;\n c->nv = nv;\n c->logv = lg(nv);\n\n // d-- > 1 (not 0) because depth 0 denotes input nodes, not a layer.\n // Sumcheck counts layers starting from the output, hence the loop\n // counts downwards.\n for (size_t d = depth_ub; d-- > 1;) {\n corner_t nw =\n corner_t(lnodes.at(d - 1).size()); // inputs[d] == outputs[d-1]\n nwires_ += nw;\n c->l.push_back(\n Layer{.nw = nw,\n .logw = lg(nw),\n .quad = mkquad(lnodes.at(d), lnodes.at(d - 1))});\n }\n }\n\n std::unique_ptr> mkquad(\n const std::vector& lnodes0, // wires at this layer\n const std::vector& lnodes1 // wires at the previous layer\n ) {\n size_t nterms0 = 0;\n for (const auto& ln0 : lnodes0) {\n nterms0 += ln0.lterms.size();\n }\n nquad_terms_ += nterms0;\n\n auto S = std::make_unique>(nterms0);\n size_t i = 0;\n for (const auto& ln0 : lnodes0) {\n for (const auto& lt : ln0.lterms) {\n S->c_[i++] = typename Quad::corner{\n .g = ln0.desired_wire_id,\n .h = {lnodes1.at(static_cast(lt.lop0)).desired_wire_id,\n lnodes1.at(static_cast(lt.lop1)).desired_wire_id},\n .v = lt.k};\n }\n }\n S->canonicalize(f_);\n return S;\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_SCHEDULE_H_\n"], ["/longfellow-zk/lib/circuits/logic/routing.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_ROUTING_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_ROUTING_H_\n\n#include \n\n#include \n#include \n\n#include \"util/ceildiv.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n/*\nThe Routing class implements circuits that shift an array by a variable number\nof positions. The following table can help pick parameters for a shift:\n\nshift_bit[2][2][1] depth: 2 wires: 6 in: 4 out:2 use:6 ovh:0 t:5 cse:0 notn:7\nunshift_bit[2][2][1] depth: 2 wires: 6 in: 4 out:2 use:6 ovh:0 t:5 cse:0 notn:7\nshift_bit[4][4][1] depth: 3 wires: 17 in: 7 out:4 use:15 ovh:2 t:23 cse:0\nnotn:27 unshift_bit[4][4][1] depth: 3 wires: 17 in: 7 out:4 use:15 ovh:2 t:23\ncse:0 notn:27 shift_bit[4][4][2] depth: 3 wires: 19 in: 7 out:4 use:15 ovh:4\nt:23 cse:2 notn:20 unshift_bit[4][4][2] depth: 3 wires: 19 in: 7 out:4 use:15\novh:4 t:23 cse:2 notn:20 shift_bit[8][8][1] depth: 4 wires: 41 in: 12 out:8\nuse:36 ovh:5 t:70 cse:0 notn:83 unshift_bit[8][8][1] depth: 4 wires: 41 in: 12\nout:8 use:36 ovh:5 t:70 cse:0 notn:83 shift_bit[8][8][2] depth: 4 wires: 44\nin: 12 out:8 use:32 ovh:12 t:64 cse:2 notn:62 unshift_bit[8][8][2] depth: 4\nwires: 44 in: 12 out:8 use:32 ovh:12 t:67 cse:2 notn:68 shift_bit[16][16][1]\ndepth: 5 wires: 94 in: 21 out:16 use:85 ovh:9 t:186 cse:0 notn:227\nunshift_bit[16][16][1] depth: 5 wires: 94 in: 21 out:16 use:85 ovh:9 t:186\ncse:0 notn:227 shift_bit[16][16][2] depth: 4 wires: 82 in: 21 out:16 use:61\novh:21 t:137 cse:4 notn:147 unshift_bit[16][16][2] depth: 4 wires: 82 in: 21\nout:16 use:61 ovh:21 t:137 cse:4 notn:147 shift_bit[16][16][4] depth: 4\nwires: 94 in: 21 out:16 use:61 ovh:33 t:203 cse:58 notn:255\nunshift_bit[16][16][4] depth: 4 wires: 94 in: 21 out:16 use:61 ovh:33 t:203\ncse:58 notn:255 shift_bit[32][32][1] depth: 6 wires: 212 in: 38 out:32\nuse:198 ovh:14 t:463 cse:0 notn:579 unshift_bit[32][32][1] depth: 6 wires: 212\nin: 38 out:32 use:198 ovh:14 t:463 cse:0 notn:579 shift_bit[32][32][2] depth:\n5 wires: 184 in: 38 out:32 use:142 ovh:42 t:351 cse:4 notn:405\nunshift_bit[32][32][2] depth: 5 wires: 184 in: 38 out:32 use:142 ovh:42 t:366\ncse:4 notn:435 shift_bit[32][32][4] depth: 5 wires: 193 in: 38 out:32 use:118\novh:75 t:371 cse:13 notn:427 unshift_bit[32][32][4] depth: 5 wires: 193 in: 38\nout:32 use:118 ovh:75 t:413 cse:13 notn:511 shift_bit[64][64][1] depth: 7\nwires: 475 in: 71 out:64 use:455 ovh:20 t:1109 cse:0 notn:1411\nunshift_bit[64][64][1] depth: 7 wires: 475 in: 71 out:64 use:455 ovh:20 t:1109\ncse:0 notn:1411 shift_bit[64][64][2] depth: 5 wires: 353 in: 71 out:64\nuse:275 ovh:78 t:747 cse:6 notn:922 unshift_bit[64][64][2] depth: 5 wires: 353\nin: 71 out:64 use:275 ovh:78 t:747 cse:6 notn:922 shift_bit[64][64][4] depth:\n5 wires: 363 in: 71 out:64 use:223 ovh:140 t:954 cse:22 notn:1319\nunshift_bit[64][64][4] depth: 5 wires: 363 in: 71 out:64 use:223 ovh:140 t:954\ncse:22 notn:1319 shift_bit[128][128][1] depth: 8 wires: 1059 in: 136 out:128\nuse:1032 ovh:27 t:2588 cse:0 notn:3331 unshift_bit[128][128][1] depth: 8 wires:\n1059 in: 136 out:128 use:1032 ovh:27 t:2588 cse:0 notn:3331\nshift_bit[128][128][2] depth: 6 wires: 808 in: 136 out:128 use:660 ovh:148\nt:1842 cse:6 notn:2332 unshift_bit[128][128][2] depth: 6 wires: 808 in: 136\nout:128 use:660 ovh:148 t:1905 cse:6 notn:2458 shift_bit[128][128][4] depth:\n5 wires: 695 in: 136 out:128 use:428 ovh:267 t:2406 cse:69 notn:3686\nunshift_bit[128][128][4] depth: 5 wires: 695 in: 136 out:128 use:428 ovh:267\nt:2826 cse:69 notn:4526 shift_bit[256][256][1] depth: 9 wires: 2348 in: 265\nout:256 use:2313 ovh:35 t:5924 cse:0 notn:7683 unshift_bit[256][256][1] depth:\n9 wires: 2348 in: 265 out:256 use:2313 ovh:35 t:5924 cse:0 notn:7683\nshift_bit[256][256][2] depth: 6 wires: 1588 in: 265 out:256 use:1305 ovh:283\nt:3905 cse:8 notn:5153 unshift_bit[256][256][2] depth: 6 wires: 1588 in: 265\nout:256 use:1305 ovh:283 t:3905 cse:8 notn:5153 shift_bit[256][256][4] depth:\n5 wires: 1355 in: 265 out:256 use:825 ovh:530 t:6750 cse:116 notn:11309\nunshift_bit[256][256][4] depth: 5 wires: 1355 in: 265 out:256 use:825 ovh:530\nt:6750 cse:116 notn:11309 shift_bit[256][256][8] depth: 5 wires: 1595 in: 265\nout:256 use:825 ovh:770 t:33990 cse:2756 notn:65309 unshift_bit[256][256][8]\ndepth: 5 wires: 1595 in: 265 out:256 use:825 ovh:770 t:33990 cse:2756 notn:65309\nshift_bit[512][512][1] depth: 10 wires: 5174 in: 522 out:512 use:5130 ovh:44\nt:13357 cse:0 notn:17411 unshift_bit[512][512][1] depth: 10 wires: 5174 in: 522\nout:512 use:5130 ovh:44 t:13357 cse:0 notn:17411 shift_bit[512][512][2] depth: 7\nwires: 3644 in: 522 out:512 use:3098 ovh:546 t:9289 cse:8 notn:12323\nunshift_bit[512][512][2] depth: 7 wires: 3644 in: 522 out:512 use:3098 ovh:546\nt:9544 cse:8 notn:12833 shift_bit[512][512][4] depth: 6 wires: 3148 in: 522\nout:512 use:2094 ovh:1054 t:11361 cse:33 notn:17462 unshift_bit[512][512][4]\ndepth: 6 wires: 3148 in: 522 out:512 use:2094 ovh:1054 t:11361 cse:33 notn:17462\nshift_bit[512][512][8] depth: 6 wires: 3194 in: 522 out:512 use:1618 ovh:1576\nt:18192 cse:224 notn:31029 unshift_bit[512][512][8] depth: 6 wires: 3194 in:\n522 out:512 use:1618 ovh:1576 t:21912 cse:224 notn:38469\nshift_bit[1024][1024][1] depth: 11 wires: 11329 in: 1035 out:1024 use:11275\novh:54 t:29751 cse:0 notn:38915 unshift_bit[1024][1024][1] depth: 11 wires:\n11329 in: 1035 out:1024 use:11275 ovh:54 t:29751 cse:0 notn:38915\nshift_bit[1024][1024][2] depth: 7 wires: 7243 in: 1035 out:1024 use:6175\novh:1068 t:19547 cse:10 notn:26664 unshift_bit[1024][1024][2] depth: 7 wires:\n7243 in: 1035 out:1024 use:6175 ovh:1068 t:19547 cse:10 notn:26664\nshift_bit[1024][1024][4] depth: 6 wires: 6232 in: 1035 out:1024 use:4155\novh:2077 t:26989 cse:80 notn:43573 unshift_bit[1024][1024][4] depth: 6 wires:\n6232 in: 1035 out:1024 use:4155 ovh:2077 t:30769 cse:80 notn:51133\nshift_bit[1024][1024][8] depth: 6 wires: 6296 in: 1035 out:1024 use:3179\novh:3117 t:52409 cse:332 notn:94285 unshift_bit[1024][1024][8] depth: 6 wires:\n6296 in: 1035 out:1024 use:3179 ovh:3117 t:52409 cse:332 notn:94285\n*/\ntemplate \nclass Routing {\n public:\n typedef typename Logic::BitW bitW;\n typedef typename Logic::EltW EltW;\n const Logic& l_;\n\n explicit Routing(const Logic& l) : l_(l) {}\n\n // Set B[i] = A[i + amount], for 0 <= i < k. Note that A and B\n // are in general of different size.\n template \n void shift(size_t logn, const bitW amount[/*logn*/], size_t k, T B[/*k*/],\n size_t n, const T A[/*n*/], const T& defaultA,\n size_t unroll) const {\n std::vector tmp(n);\n for (size_t i = 0; i < n; ++i) {\n tmp[i] = A[i];\n }\n\n // Now shift TMP in-place.\n\n // Counting backwards from logn produces a smaller circuit if one\n // only cares about a contiguous subset of outputs. E.g. if one\n // wants the first k outputs the number of wires is O(n log k).\n size_t l = logn;\n\n // This funny logic in terms of (target_nrounds, consumed)\n // attempts to equalize the number of bits consumed per round.\n // E.g., if logn = 11 and unroll = 7, a naive consumed = unroll\n // would yield 11 = 7 + 4. Instead, we set target_nrounds = 2,\n // and consumed is 6 in the first round and 5 in the second round.\n size_t target_nrounds = ceildiv(logn, unroll);\n\n while (target_nrounds > 0) {\n size_t consumed = ceildiv(l, target_nrounds);\n --target_nrounds;\n\n l -= consumed;\n size_t shift = size_t(1) << l;\n shift_step(consumed, &amount[l], n, k, tmp.data(), shift, defaultA);\n }\n\n check(l == 0, \"l==0\");\n\n for (size_t i = 0; i < k; ++i) {\n if (i < n) {\n B[i] = tmp[i];\n } else {\n B[i] = defaultA;\n }\n }\n }\n\n // Set A[i + amount] = B[i], for 0 <= i < k. Note that A and B\n // are in general of different size.\n template \n void unshift(size_t logn, const bitW amount[/*logn*/], size_t n, T A[/*n*/],\n size_t k, const T B[/*k*/], const T& defaultB,\n size_t unroll) const {\n // we don't need TMP since we can operate on A directly\n for (size_t i = 0; i < n; ++i) {\n if (i < k) {\n A[i] = B[i];\n } else {\n A[i] = defaultB;\n }\n }\n\n size_t l = 0;\n size_t target_nrounds = ceildiv(logn, unroll);\n while (target_nrounds > 0) {\n size_t consumed = ceildiv((logn - l), target_nrounds);\n --target_nrounds;\n\n size_t shift = size_t(1) << l;\n unshift_step(consumed, &amount[l], n, k, A, shift, defaultB);\n\n l += consumed;\n }\n proofs::check(l == logn, \"l==logn\");\n }\n\n template \n void shift(const typename Logic::template bitvec& amount, size_t k,\n T B[/*k*/], size_t n, const T A[/*n*/], const T& defaultA,\n size_t unroll) const {\n shift(LOGN, &amount[0], k, B, n, A, defaultA, unroll);\n }\n\n template \n void unshift(const typename Logic::template bitvec& amount, size_t n,\n T A[/*n*/], size_t k, const T B[/*k*/], const T& defaultB,\n size_t unroll) const {\n unshift(LOGN, &amount[0], n, A, k, B, defaultB, unroll);\n }\n\n private:\n template \n void shift_step(size_t logc, const bitW amount[/*logc*/], size_t n, size_t k,\n T tmp[/*n*/], size_t shift, const T& defaultA) const {\n const Logic& L = l_; // shorthand\n size_t c = size_t(1) << logc;\n\n // cache the common subexpression amount_is[i]\n std::vector amount_is(c);\n std::vector ibits(logc);\n for (size_t i = 0; i < c; ++i) {\n L.bits(logc, ibits.data(), i);\n amount_is[i] = L.eq(logc, ibits.data(), amount);\n }\n\n really_shift(c, amount_is.data(), n, k, tmp, shift, defaultA);\n }\n\n template \n void unshift_step(size_t logc, const bitW amount[/*logc*/], size_t n,\n size_t k, T A[/*n*/], size_t shift,\n const T& defaultB) const {\n const Logic& L = l_; // shorthand\n size_t c = size_t(1) << logc;\n\n // cache the common subexpression amount_is[i]\n std::vector amount_is(c);\n std::vector ibits(logc);\n for (size_t i = 0; i < c; ++i) {\n L.bits(logc, ibits.data(), i);\n amount_is[i] = L.eq(logc, ibits.data(), amount);\n }\n\n really_unshift(c, amount_is.data(), n, k, A, shift, defaultB);\n }\n\n void really_shift(size_t c, const bitW amount_is[/*c*/], size_t n, size_t k,\n EltW tmp[/*n*/], size_t shift, const EltW& defaultA) const {\n const Logic& L = l_; // shorthand\n for (size_t i = 0; i < n && i < k + shift; ++i) {\n auto f = [&](size_t j) {\n if (i + j * shift < n) {\n return L.lmul(&amount_is[j], tmp[i + j * shift]);\n } else {\n return L.lmul(&amount_is[j], defaultA);\n }\n };\n\n tmp[i] = L.add(0, c, f);\n }\n }\n\n void really_unshift(size_t c, const bitW amount_is[/*c*/], size_t n, size_t k,\n EltW A[/*n*/], size_t shift, const EltW& defaultB) const {\n const Logic& L = l_; // shorthand\n for (size_t i = std::min(n, k + c * shift); i-- > 0;) {\n auto f = [&](size_t j) {\n if (i >= j * shift) {\n return L.lmul(&amount_is[j], A[i - j * shift]);\n } else {\n return L.lmul(&amount_is[j], defaultB);\n }\n };\n\n A[i] = L.add(0, c, f);\n }\n }\n\n void really_shift(size_t c, const bitW amount_is[/*c*/], size_t n, size_t k,\n bitW tmp[/*n*/], size_t shift, const bitW& defaultA) const {\n const Logic& L = l_; // shorthand\n for (size_t i = 0; i < n && i < k + shift; ++i) {\n bitW r = L.bit(0);\n for (size_t j = 0; j < c; ++j) {\n if (i + j * shift < n) {\n r = L.lor_exclusive(&r, L.land(&amount_is[j], tmp[i + j * shift]));\n } else {\n r = L.lor_exclusive(&r, L.land(&amount_is[j], defaultA));\n }\n }\n tmp[i] = r;\n }\n }\n\n void really_unshift(size_t c, const bitW amount_is[/*c*/], size_t n, size_t k,\n bitW A[/*n*/], size_t shift, const bitW& defaultB) const {\n const Logic& L = l_; // shorthand\n for (size_t i = std::min(n, k + c * shift); i-- > 0;) {\n bitW r = L.bit(0);\n for (size_t j = 0; j < c; ++j) {\n if (i >= j * shift) {\n r = L.lor_exclusive(&r, L.land(&amount_is[j], A[i - j * shift]));\n } else {\n r = L.lor_exclusive(&r, L.land(&amount_is[j], defaultB));\n }\n }\n A[i] = r;\n }\n }\n\n template \n void really_shift(size_t c, const bitW amount_is[/*c*/], size_t n, size_t k,\n typename Logic::template bitvec tmp[/*n*/], size_t shift,\n const typename Logic::template bitvec& defaultA) const {\n const Logic& L = l_; // shorthand\n for (size_t i = 0; i < n && i < k + shift; ++i) {\n for (size_t w = 0; w < W; ++w) {\n bitW r = L.bit(0);\n for (size_t j = 0; j < c; ++j) {\n if (i + j * shift < n) {\n r = L.lor_exclusive(&r,\n L.land(&amount_is[j], tmp[i + j * shift][w]));\n } else {\n r = L.lor_exclusive(&r, L.land(&amount_is[j], defaultA[w]));\n }\n }\n tmp[i][w] = r;\n }\n }\n }\n\n template \n void really_unshift(\n size_t c, const bitW amount_is[/*c*/], size_t n, size_t k,\n typename Logic::template bitvec A[/*n*/], size_t shift,\n const typename Logic::template bitvec& defaultB) const {\n const Logic& L = l_; // shorthand\n for (size_t i = std::min(n, k + c * shift); i-- > 0;) {\n for (size_t w = 0; w < W; ++w) {\n bitW r = L.bit(0);\n for (size_t j = 0; j < c; ++j) {\n if (i >= j * shift) {\n r = L.lor_exclusive(&r, L.land(&amount_is[j], A[i - j * shift][w]));\n } else {\n r = L.lor_exclusive(&r, L.land(&amount_is[j], defaultB[w]));\n }\n }\n A[i][w] = r;\n }\n }\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_ROUTING_H_\n"], ["/longfellow-zk/lib/arrays/dense.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ARRAYS_DENSE_H_\n#define PRIVACY_PROOFS_ZK_LIB_ARRAYS_DENSE_H_\n\n#include \n#include \n\n#include \n#include \n#include \n#include \n\n#include \"algebra/blas.h\"\n#include \"algebra/poly.h\"\n#include \"arrays/affine.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n// ------------------------------------------------------------\n// Dense representation of multi-affine function, heap-allocated.\n// The caller is responsible for instantiating const Field throughout call\n// duration.\ntemplate \nclass Dense {\n using T2 = Poly<2, Field>;\n using Elt = typename Field::Elt;\n\n public:\n corner_t n0_, n1_;\n\n // Row-major indexing: v_[i1*n0+i0] stores the value at (i0, i1)\n std::vector v_;\n\n explicit Dense(corner_t n0, corner_t n1) : n0_(n0), n1_(n1), v_(n0 * n1) {}\n\n // make0 replacement\n explicit Dense(const Field& F) : n0_(1), n1_(1), v_(1) { v_[0] = F.zero(); }\n\n // initialize dense array from P[i1*ldp+i0]\n explicit Dense(corner_t n0, corner_t n1, const Elt p[], size_t ldp)\n : n0_(n0), n1_(n1), v_(n0 * n1) {\n for (corner_t i1 = 0; i1 < n1; ++i1) {\n Blas::copy(n0, v_[i1 * n0], 1, &p[i1 * ldp], 1);\n }\n }\n\n Dense(const Dense& y) = delete;\n Dense(const Dense&& y) = delete;\n Dense operator=(const Dense& y) = delete;\n\n std::unique_ptr clone() const {\n auto d = std::make_unique(n0_, n1_);\n for (corner_t i = 0; i < n0_ * n1_; ++i) {\n d->v_[i] = v_[i];\n }\n return d;\n }\n\n void clear(const Field& F) { Blas::clear(n0_ * n1_, &v_[0], 1, F); }\n\n // For a given random number r, the binding operation computes\n // v[i] = (1 - r) * v[2 * i] + r * v[2 * i + 1]\n // = v[2 * i] + r * (v[2 * i + 1] - v[2 * i])\n // and shrinks the array v by half.\n void bind(const Elt& r, const Field& F) {\n corner_t rd = 0, wr = 0;\n for (corner_t i1 = 0; i1 < n1_; ++i1) {\n corner_t i0 = 0;\n while (2 * i0 + 1 < n0_) {\n v_[wr] = affine_interpolation(r, v_[rd], v_[rd + 1], F);\n i0++, rd += 2, wr += 1;\n }\n if (2 * i0 < n0_) {\n v_[wr] = affine_interpolation(r, v_[rd], F.zero(), F);\n i0++, rd++, wr++;\n }\n }\n n0_ = (n0_ + 1u) / 2u;\n }\n\n void bind_all(size_t logv, const Elt r[/*logv*/], const Field& F) {\n for (size_t v = 0; v < logv; ++v) {\n bind(r[v], F);\n }\n }\n\n Elt at(corner_t j) const { return v_[j]; }\n\n // Scale all elements by x, except for the last element in\n // the n0_ dimension, which is scaled by x_last. This \"last\" quirk\n // is used by EQ.\n void scale(const Elt& x, const Elt& x_last, const Field& F) {\n corner_t ndx = 0;\n for (corner_t i1 = 0; i1 < n1_; ++i1) {\n corner_t i0 = 0;\n for (; i0 + 1 < n0_; ++i0) {\n F.mul(v_[ndx++], x);\n }\n if (i0 < n0_) {\n F.mul(v_[ndx++], x_last);\n }\n }\n }\n\n Elt at_corners(corner_t p0, corner_t p1, const Field& F) const {\n if (p0 < n0_) {\n return v_[p1 * n0_ + p0];\n } else {\n return F.zero();\n }\n }\n\n T2 t2_at_corners(corner_t p0, corner_t p1, const Field& F) const {\n return T2{at_corners(p0, p1, F), at_corners(p0 + 1, p1, F)};\n }\n\n // The precondition for reshaping is that the first dimension must be\n // fully bound.\n void reshape(corner_t n0) {\n check(n0_ == 1, \"n0_ == 1\");\n check(n0 > 0, \"n0 > 0\");\n corner_t wasn1 = n1_;\n n0_ = n0;\n n1_ = n1_ / n0;\n check(n1_ * n0 == wasn1, \"n1_*n0 == wasn1\");\n }\n\n // This method can only be called after full binding; the caller\n // is responsible for ensuring that pre-condition.\n Elt scalar() {\n check(n0_ == 1, \"n0_ == 1\");\n check(n1_ == 1, \"n1_ == 1\");\n return v_[0];\n }\n};\n\n// Helper class to fill a dense array a la std::vector<>\n//\ntemplate \nclass DenseFiller {\n using Elt = typename Field::Elt;\n\n public:\n // Caller must ensure that W remains valid.\n explicit DenseFiller(Dense& W) : pos_(0), w_(W) {\n // only works in this special case\n check(w_.n0_ == 1, \"W_.n0_ == 1\");\n }\n\n DenseFiller& push_back(const Elt& x) {\n check(pos_ < w_.n1_, \"pos_ < w_.n1_\");\n w_.v_[pos_++] = x;\n return *this;\n }\n\n template \n DenseFiller& push_back(const std::array& a) {\n for (size_t i = 0; i < N; ++i) {\n push_back(a[i]);\n }\n return *this;\n }\n\n DenseFiller& push_back(const std::vector& a) {\n for (size_t i = 0; i < a.size(); ++i) {\n push_back(a[i]);\n }\n return *this;\n }\n\n // Push back a bit string derived from a number. The parameter \"bits\" is the\n // number of bits in the string, and \"x\" is the number to be converted. This\n // works for pushing v8, v32, etc.\n DenseFiller& push_back(uint64_t x, size_t bits, const Field& F) {\n for (size_t i = 0; i < bits; ++i) {\n push_back(F.of_scalar((x >> i) & 1));\n }\n return *this;\n }\n\n size_t size() const { return pos_; }\n\n private:\n size_t pos_;\n Dense& w_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ARRAYS_DENSE_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_zk.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_ZK_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_ZK_H_\n\n#include \n#include \n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n// This package implements C interfaces that allow external programs to call\n// the zk mdoc-based prover and verifier.\n//\n// It also contains a helper method that produces a byte representation\n// of a circuit which verifies the mdoc with regards to specific properties,\n// for example age_over_18. The circuit generation can be run once, and the\n// result cached for subsequent use in the prover and verifier.\n\nenum CborAttributeType { kPrimitive, kString, kBytes, kDate, kInt };\n\n/* This struct allows a verifier to express which attribute and value the prover\n * must claim. */\ntypedef struct {\n uint8_t id[32];\n uint8_t value[64];\n size_t id_len, value_len;\n CborAttributeType type;\n} RequestedAttribute;\n\n// Return codes for the run_mdoc2_prover method.\ntypedef enum {\n MDOC_PROVER_SUCCESS = 0,\n MDOC_PROVER_NULL_INPUT,\n MDOC_PROVER_INVALID_INPUT,\n MDOC_PROVER_CIRCUIT_PARSING_FAILURE,\n MDOC_PROVER_HASH_PARSING_FAILURE,\n MDOC_PROVER_WITNESS_CREATION_FAILURE,\n MDOC_PROVER_GENERAL_FAILURE,\n MDOC_PROVER_MEMORY_ALLOCATION_FAILURE,\n MDOC_PROVER_INVALID_ZK_SPEC_VERSION,\n} MdocProverErrorCode;\n\n// Return codes for the run_mdoc2_verifier method.\ntypedef enum {\n MDOC_VERIFIER_SUCCESS = 0,\n MDOC_VERIFIER_CIRCUIT_PARSING_FAILURE,\n MDOC_VERIFIER_PROOF_TOO_SMALL,\n MDOC_VERIFIER_HASH_PARSING_FAILURE,\n MDOC_VERIFIER_SIGNATURE_PARSING_FAILURE,\n MDOC_VERIFIER_GENERAL_FAILURE,\n MDOC_VERIFIER_NULL_INPUT,\n MDOC_VERIFIER_INVALID_INPUT,\n MDOC_VERIFIER_ARGUMENTS_TOO_SMALL,\n MDOC_VERIFIER_ATTRIBUTE_NUMBER_MISMATCH,\n MDOC_VERIFIER_INVALID_ZK_SPEC_VERSION,\n} MdocVerifierErrorCode;\n\n// Return codes for the generate_circuit method.\ntypedef enum {\n CIRCUIT_GENERATION_SUCCESS = 0,\n CIRCUIT_GENERATION_NULL_INPUT,\n CIRCUIT_GENERATION_ZLIB_FAILURE,\n CIRCUIT_GENERATION_GENERAL_FAILURE,\n CIRCUIT_GENERATION_INVALID_ZK_SPEC_VERSION,\n} CircuitGenerationErrorCode;\n\n// This structure represents a version of ZK specification supported by this\n// library. It is passed into all the methods for circuit generation, running\n// the prover and verifier.\n// It allows us to version the specification of the ZK system. The prover and\n// the verifier are supposed to negotiate the version of the specification they\n// both support before executing digital credential presentment.\ntypedef struct {\n // The ZK system name and version- \"longfellow-libzk-v*\" for Google library.\n const char* system;\n // The hash of the compressed circuit (the way it's generated and passed to\n // prover/verifier)\n const char circuit_hash[65];\n // The number of attributes that the circuit supports.\n size_t num_attributes;\n // The version of the ZK specification.\n size_t version;\n} ZkSpecStruct;\n\nstatic const char kDefaultDocType[] = \"org.iso.18013.5.1.mDL\";\n\n// The run_mdoc2_prover method takes byte-oriented inputs that describe a\n// circuit, mdoc, the public key of the issuer for the mdoc, a transcript\n// for the mdoc request operation, an array of RequestedAttribute that\n// represents claims that you want to prove, and a 20-char representation of the\n// current time. It writes the proof and its length into the input parameter prf\n// and proof_len. It is the responsibility of the caller to later free the proof\n// memory. If the prover fails to produce a proof, e.g., because the mdoc is\n// invalid, or the now time does not satisfy the validFrom and validUntil\n// constraints, then the prover returns an error code.\n// The following lines document how attributes can be opened in ZK.\n// {(uint8_t *)\"family_name\", 11, (uint8_t *)\"Mustermann\", 10},\n// {(uint8_t *)\"height\", 6, (uint8_t *)\"\\x18\\xaf\", 2},\n// {(uint8_t *)\"birth_date\", 10, (uint8_t *)\"\\xD9\\x03\\xEC\\x6A\" \"1971-09-01\",\n// 14},\n// {(uint8_t *)\"issue_date\", 10, (uint8_t *)\"\\xD9\\x03\\xEC\\x6A\" \"2024-03-15\",\n// 14},\nMdocProverErrorCode run_mdoc_prover(\n const uint8_t* bcp, size_t bcsz, /* circuit data */\n const uint8_t* mdoc, size_t mdoc_len, /* full mdoc */\n const char* pkx, const char* pky, /* string rep of public key */\n const uint8_t* transcript, size_t tr_len, /* session transcript */\n const RequestedAttribute* attrs, size_t attrs_len,\n const char* now, /* time formatted as \"2023-11-02T09:00:00Z\" */\n uint8_t** prf, size_t* proof_len, const ZkSpecStruct* zk_spec_version);\n\n// The run_mdoc2_verifier method accepts a byte representation of the circuit,\n// the public key of the issuer, the transcript, an array of RequestedAttribute\n// that represents claims that you want to verify, and a 20-char representation\n// of the time, as well as the proof and its length.\nMdocVerifierErrorCode run_mdoc_verifier(\n const uint8_t* bcp, size_t bcsz, /* circuit data */\n const char* pkx, const char* pky, /* string rep of public key */\n const uint8_t* transcript, size_t tr_len, /* session transcript */\n const RequestedAttribute* attrs, size_t attrs_len,\n const char* now, /* time formatted as \"2023-11-02T09:00:00Z\" */\n const uint8_t* zkproof, size_t proof_len, const char* docType,\n const ZkSpecStruct* zk_spec_version);\n\n// Produces a compressed version of the circuit bytes for the specified number\n// of attributes.\nCircuitGenerationErrorCode generate_circuit(const ZkSpecStruct* zk_spec_version,\n uint8_t** cb, size_t* clen);\n\n// Produces an identifier for a pair of circuits (c_1, c_2) over (Fp256, f_128)\n// respectively. This method parses the input bytes into two circuits, computes\n// the circuit's ids of each, and then computes the SHA256 hash of the two ids.\n// This method is used to identify \"circuit bundles\" consisting of multiple\n// circuits.\nint circuit_id(uint8_t id[/*kSHA256DigestSize*/], const uint8_t* bcp,\n size_t bcsz, const ZkSpecStruct* zk_spec);\n\nenum { kNumZkSpecs = 12 };\n// This is a hardcoded list of all the ZK specifications supported by this\n// library. Every time a new breaking change is introduced in either the circuit\n// format or its interpretation, a new version must be added here.\n// It is possible to remove old versions, if we're sure that they are not used\n// by either provers of verifiers in the wild.\nextern const ZkSpecStruct kZkSpecs[kNumZkSpecs];\n\n// Returns a static pointer to the ZkSpecStruct that matches the given system\n// name and circuit hash. Returns nullptr if no matching ZkSpecStruct is found.\nconst ZkSpecStruct* find_zk_spec(const char* system_name,\n const char* circuit_hash);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_ZK_H_\n"], ["/longfellow-zk/lib/algebra/nat.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_NAT_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_NAT_H_\n\n#include \n#include \n#include \n#include \n#include \n\n#include \"algebra/limb.h\"\n#include \"algebra/static_string.h\"\n#include \"algebra/sysdep.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n\n// return a^-1 mod 2^L where L is the number of bits in limb_t\ntemplate \nstatic limb_t inv_mod_b(limb_t a) {\n // Let v=1-a. We have 1/a=1/(1-v)=1+v+v^2+..., or\n // 1/a=(1+v)(1+v^2)(1+v^4)... At some point v^(2^k) becomes 0 mod\n // 2^L because v is even.\n\n // A more complicated variant of this idea appears in Dumas,\n // J.G. \"On Newton–Raphson Iteration for Multiplicative Inverses\n // Modulo Prime Powers\", Algorithm 3, where they use v'=a-1\n // instead of v=1-a, and so the first term needs to be handled\n // separately as 2-a instead of 1+v, breaking the uniformity of\n // the algorithm. The sign difference disappears after the first\n // squaring.\n check((a & 1) != 0, \"even A in inv_mod_b()\");\n\n limb_t v = 1u - a;\n limb_t u = 1u;\n while (v != 0) {\n u *= (1u + v);\n v *= v;\n }\n return u;\n}\n\n// This function should only be called on static input known at compile time.\nunsigned digit(char c);\n\ntemplate \nclass Nat : public Limb {\n public:\n using Super = Limb;\n using T = Nat;\n using limb_t = typename Super::limb_t;\n using Super::kLimbs;\n using Super::kU64;\n using Super::limb_;\n\n // Maximum length for an untrusted string, 2^64 ~ 20 decimal digits.\n static constexpr size_t kMaxStringLen = 20 * W64 + 1;\n\n Nat() = default; // uninitialized\n explicit Nat(uint64_t x) : Super(x) {}\n\n explicit Nat(const std::array& a) : Super(a) {}\n\n // Pre-condition: the caller of this function must check that the string\n // s is either a valid base-10 or base-16 representation of a natural number\n // that does not overflow the representation.\n // In our current implementation, this method is only used on static strings.\n explicit Nat(const StaticString& ss) : Super(0) {\n limb_t base = 10u;\n const char* s = ss.as_pointer;\n if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) {\n s += 2;\n base = 16u;\n }\n for (; *s; s++) {\n T d(digit(*s));\n bool ok = muls(limb_, base);\n check(ok, \"overflow in nat(const char *s)\");\n limb_t ah = add_limb(kLimbs, limb_, d.limb_);\n check(ah == 0, \"overflow in nat(const char *s)\");\n }\n }\n\n template \n explicit Nat(const char (&p)[LEN]) : Nat(StaticString(p)) {}\n\n // Interpret A[] as a little-endian nat\n static T of_bytes(const uint8_t a[/* kBytes */]) {\n T r;\n for (size_t i = 0; i < kLimbs; ++i) {\n a = Super::of_bytes(&r.limb_[i], a);\n }\n return r;\n }\n\n static std::optional safe_digit(char c, limb_t base) {\n c = tolower(c);\n if (c >= '0' && c <= '9') {\n return c - '0';\n } else if (base == 16u && c >= 'a' && c <= 'f') {\n return c - 'a' + 10;\n }\n return std::nullopt;\n }\n\n static std::optional of_untrusted_string(const char* s) {\n T r(0);\n limb_t base = 10u;\n if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) {\n s += 2;\n base = 16u;\n }\n const char* p = s;\n for (size_t len = 0; len < kMaxStringLen && *p; ++len, ++p) {\n auto d = safe_digit(*p, base);\n if (!d.has_value()) {\n return std::nullopt;\n }\n T td(d.value());\n if (!muls(r.limb_, base)) {\n return std::nullopt;\n }\n limb_t ah = add_limb(kLimbs, r.limb_, td.limb_);\n if (ah != 0) {\n return std::nullopt;\n }\n }\n // If the loop terminates due to the length limit, then the string is not\n // a valid base-10 or base-16 representation of a natural number.\n if (*p) {\n return std::nullopt;\n }\n return r;\n }\n\n bool operator<(const T& y) const {\n T b = *this;\n limb_t bh = sub_limb(kLimbs, b.limb_, y.limb_);\n return (bh != 0);\n }\n\n T& add(const T& y) {\n (void)add_limb(kLimbs, limb_, y.limb_);\n return *this;\n }\n T& sub(const T& y) {\n (void)sub_limb(kLimbs, limb_, y.limb_);\n return *this;\n }\n\n private:\n // b *= a, returns false if overflow occurred.\n static bool muls(limb_t b[kLimbs], limb_t a) {\n limb_t h[kLimbs];\n mulhl(kLimbs, b, h, a, b);\n limb_t bh = addh(kLimbs, b, h);\n return bh == 0;\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_NAT_H_\n"], ["/longfellow-zk/lib/gf2k/lch14.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_GF2K_LCH14_H_\n#define PRIVACY_PROOFS_ZK_LIB_GF2K_LCH14_H_\n\n#include \n\n#include \n\n#include \"util/panic.h\"\n\n// The algorithm from [LCH14] following [DP24, Algorithm 2]\n//\n// [LCH14] Sian-Jheng Lin, Wei-Ho Chung, and Yunghsiang S. Han: Novel\n// Polynomial Basis and Its Application to Reed-Solomon Erasure Codes,\n// https://arxiv.org/pdf/1404.3458\n\n// [DP24] Benjamin E. Diamond and Jim Posen, Polylogarithmic Proofs\n// for Multilinears over Binary Towers, https://eprint.iacr.org/2024/504\n\nnamespace proofs {\n\ntemplate \nclass LCH14 {\n using Elt = typename Field::Elt;\n\n // only works in binary fields\n static_assert(Field::kCharacteristicTwo);\n\n public:\n static constexpr size_t kSubFieldBits = Field::kSubFieldBits;\n\n explicit LCH14(const Field &F) : f_(F) {\n // Compute W_i(\\beta_j) for all i, j.\n\n // We store the unnormalized W_[i][j] = W_i(\\beta_j)\n // in the same memory as the normalized \\hat{W}_i(\\beta_j), since\n // the unnormalized values are not needed after normalization.\n\n // In an attempt to improve clarity, we syntactically distinguish\n // the unnormalized array W from the normalized array w_hat_,\n // but one must be mindful that the two names alias to the\n // same memory locations.\n auto W = w_hat_;\n\n // Base case: W_0(X) = X\n for (size_t j = 0; j < kSubFieldBits; ++j) {\n W[0][j] = f_.beta(j);\n }\n\n // Inductive case: W_{i+1}(X) = W_i(X)(W_i(X)+W_i(\\beta_i))\n for (size_t i = 0; i + 1 < kSubFieldBits; ++i) {\n for (size_t j = 0; j < kSubFieldBits; ++j) {\n W[i + 1][j] = f_.mulf(W[i][j], f_.addf(W[i][j], W[i][i]));\n }\n }\n\n // normalized \\hat{W}_i(\\beta j)\n for (size_t i = 0; i < kSubFieldBits; ++i) {\n Elt scale = f_.invertf(W[i][i]);\n for (size_t j = 0; j < kSubFieldBits; ++j) {\n w_hat_[i][j] = f_.mulf(scale, W[i][j]);\n }\n }\n }\n\n // Computation of a single twiddle factor.\n // Implicit in [LCH14, III.E], explicit in [DP24, Algorithm 2].\n Elt twiddle(size_t i, size_t u) const {\n Elt t = f_.zero();\n for (size_t k = 0; u != 0; ++k, u >>= 1) {\n if (u & 1) {\n f_.add(t, w_hat_[i][k]);\n }\n }\n return t;\n }\n\n // linear-time computation of all twiddles at the same time\n void twiddles(size_t i, size_t l, size_t coset, Elt tw[]) const {\n tw[0] = twiddle(i, coset);\n for (size_t k = 0; (i + 1) + k < l; ++k) {\n Elt shift = w_hat_[i][(i + 1) + k];\n for (size_t u = 0; u < (k1 << k); ++u) {\n tw[u + (k1 << k)] = f_.addf(tw[u], shift);\n }\n }\n }\n\n size_t ntwiddles(size_t l) const { return k1 << (l - 1); }\n\n // Notation from [DP24, Algorithm 2], except that we hardcode R=0\n // and add the coset parameter.\n void FFT(size_t l, size_t coset, Elt B[/* n = (1 << l) */]) const {\n check(l <= kSubFieldBits, \"l <= kSubFieldBits\");\n\n if (l > 0) {\n // space for twiddle factors\n std::vector tw(ntwiddles(l));\n\n for (size_t i = l; i-- > 0;) {\n size_t s = k1 << i;\n twiddles(i, l, coset, &tw[0]);\n for (size_t u = 0; (u << (i + 1)) < (k1 << l); ++u) {\n Elt twu = tw[u];\n for (size_t v = 0; v < s; ++v) {\n butterfly_fwd(B, (u << (i + 1)) + v, s, twu);\n }\n }\n }\n }\n }\n\n void IFFT(size_t l, size_t coset, Elt B[/* n = (1 << l) */]) const {\n check(l <= kSubFieldBits, \"l <= kSubFieldBits\");\n\n if (l > 0) {\n // space for twiddle factors\n std::vector tw(ntwiddles(l));\n\n for (size_t i = 0; i < l; ++i) {\n size_t s = k1 << i;\n twiddles(i, l, coset, &tw[0]);\n for (size_t u = 0; (u << (i + 1)) < (k1 << l); ++u) {\n Elt twu = tw[u];\n for (size_t v = 0; v < s; ++v) {\n butterfly_bwd(B, (u << (i + 1)) + v, s, twu);\n }\n }\n }\n }\n }\n\n void BidirectionalFFT(size_t l, size_t k, Elt B[/* n = (1 << l) */]) const {\n check(l <= kSubFieldBits, \"l <= kSubFieldBits\");\n bidir_recur(/*i=*/l, /*coset=*/0, k, B);\n }\n\n // debug access to w_hat_\n Elt WHat_DEBUG(size_t i, size_t j) const { return w_hat_[i][j]; }\n\n private:\n // avoid writing static_cast(1) all the time.\n static constexpr size_t k1 = 1;\n\n const Field &f_;\n\n // precomputed [i][j] -> \\hat{W}(\\beta_j)\n Elt w_hat_[kSubFieldBits][kSubFieldBits];\n\n // The algorithm described in Joris van der Hoeven, \"The Truncated\n // Fourier Transform and Applications\". This implementation is\n // based on the pseudo-code from the followup paper \"Notes on the\n // Truncated Fourier Transform\", also by Joris van der Hoeven.\n //\n // Van der Hoeven considers the classic multiplicative FFT;\n // here we port the algorithm to the [LCH14] adaptive FFT.\n\n // Here we call the algorithm the \"Bidirectional FFT\", because\n // the algorithm takes a set of points in the \"time\" domain\n // and the complementary set of points in the \"frequency\" domain,\n // and it flips time and frequency, so the algorithm can be\n // used to compute the forward and backward transforms, as well\n // as combinations of the two.\n //\n // The literature on the truncated Fourier transforms assumes that\n // the complementary set of points are implicitly set to zero, and\n // the main problem is how to avoid storing the zeroes. Our main\n // problem is not time or space efficiency, but polynomial\n // interpolation. Given k evaluations of a polynomial of degree 0) {\n size_t s = k1 << i;\n Elt twu = twiddle(i, coset);\n\n if (k < s) {\n for (size_t uv = k; uv < s; ++uv) {\n butterfly_fwd(B, uv, s, twu);\n }\n\n bidir_recur(i, coset, k, B);\n\n for (size_t uv = 0; uv < k; ++uv) {\n butterfly_diag(B, uv, s, twu);\n }\n\n FFT(i, coset + s, B + s);\n } else /* k >= s */ {\n IFFT(i, coset, B);\n\n for (size_t uv = k - s; uv < s; ++uv) {\n butterfly_diag(B, uv, s, twu);\n }\n\n bidir_recur(i, coset + s, k - s, B + s);\n\n for (size_t uv = 0; uv < k - s; ++uv) {\n butterfly_bwd(B, uv, s, twu);\n }\n }\n }\n }\n\n inline void butterfly_fwd(Elt B[], size_t uv, size_t s,\n const Elt &twu) const {\n f_.add(B[uv], f_.mulf(twu, B[uv + s]));\n f_.add(B[uv + s], B[uv]);\n }\n\n inline void butterfly_bwd(Elt B[], size_t uv, size_t s,\n const Elt &twu) const {\n f_.sub(B[uv + s], B[uv]);\n f_.sub(B[uv], f_.mulf(twu, B[uv + s]));\n }\n\n // forward at [uv + s], backward at [uv]\n inline void butterfly_diag(Elt B[], size_t uv, size_t s,\n const Elt &twu) const {\n Elt b1 = B[uv + s];\n f_.add(B[uv + s], B[uv]);\n f_.sub(B[uv], f_.mulf(twu, b1));\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_GF2K_LCH14_H_\n"], ["/longfellow-zk/lib/ligero/ligero_param.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_PARAM_H_\n#define PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_PARAM_H_\n\n#include \n\n#include \n#include \n#include \n#include \n#include \n\n#include \"algebra/blas.h\"\n#include \"merkle/merkle_commitment.h\"\n#include \"merkle/merkle_tree.h\"\n#include \"util/ceildiv.h\"\n#include \"util/crypto.h\"\n#include \"util/panic.h\"\n\n/*\n\n This is an implementation of the Ligero protocol described in\n\n Ligero: Lightweight Sublinear Arguments\n Without a Trusted Setup,\n\n Scott Ames and Carmit Hazay and Yuval Ishai and\n Muthuramakrishnan Venkitasubramaniam,\n https://eprint.iacr.org/2022/1608\n doi = {10.1145/3133956},\n\n The main data structure in the prover is a 2D array which we call a\n tableau organized as follows.\n\n Fix a block size BLOCK and let DBLOCK = 2 * BLOCK - 1. Fix another\n quantity BLOCK_EXT >= 0.\n\n Each row in the tableau has the form [X XD XEXT], where X is a row\n of BLOCK elements, XD is a row of BLOCK - 1 elements, and XEXT is a\n row of BLOCK_EXT elements. We call the X part the \"block\" and the\n XEXT part the \"extension\".\n\n Let BLOCK_ENC = 2 * BLOCK - 1 + BLOCK_EXT = DBLOCK + BLOCK_EXT be\n the total size of the row.\n\n A \"witness block\" has the form [RANDOM[R], WITNESS[W]], where R + W\n = BLOCK. The randomess (of size R) is used for zero-knowledge\n blinding. Although not strictly required by Ligero, we require W >=\n R to avoid wasting too much space, so that a witness block is at\n least half full.\n\n A block is interpreted as evaluations of some polynomial at point\n INJ(j) for 0 <= j < BLOCK, where INJ(.) is some field-specific\n injection that injects small natural numbers into distinct field\n elements. With the condition that the degree of the polynomial be\n less than BLOCK, the polynomial is uniquely determined, and the rest\n [XD XEXT] of the row is then computed as the evaluations of that\n polynomial for BLOCK <= j < BLOCK_ENC.\n\n To the extent that Ligero is based on Reed-Solomon codes, X is the\n \"message\" and XEXT is the \"codeword\". The \"rate\" is thus BLOCK /\n BLOCK_EXT.\n\n However, Ligero also needs products of two polynomials of degree\n less than BLOCK, so that the product has degree less than 2 * BLOCK\n - 1 = DBLOCK. XD exists in the tableau to facilitate the\n computation of these products. For zero knowledge, the indices of\n XD must be distinct from the indices of BLOCK_EXT.\n\n We now discuss the row structure of the tableau. The first three\n rows are special and used for zero-knowledge blinding purposes.\n\n The first row, row ILDT for ILDT = 0, used for the low-degree test,\n consists of BLOCK random field elements, extended to BLOCK_ENC.\n\n The second row, row IDOT for IDOT = 1, used in the linear test,\n consists of DBLOCK random field elements, with the additional\n constraint that the double block sum to 0. As usual, the row is\n extended to BLOCK_ENC by interpolation.\n\n The third row, row IQUAD for IQUAD = 2, used in the quadratic test,\n consists of DBLOCK random field elements, with the additional\n constraint that the WITNESS portion of the block be zero. Thus, the\n structure is really [RANDOM[R] ZERO[W] RANDOM[BLOCK-1]], extended to\n BLOCK_ENC by interpolation.\n\n The next group of \"witness rows\" IW <= I < IQ for IW = 3, stores\n witnesses. Each row is a witness block extended to BLOCK_ENC.\n\n The next group of \"quadratic\" rows IQ <= I < NROW, has the same\n syntactic structure as the \"witness\" rows, but they are used in the\n quadratic check in addition to the linear check. In Ligero, a\n quadratic constraint induces three entries in three quadratic rows.\n Thus, for NQ total quadratic constraints and W useful entries per\n row, we have a total of 3 * (NQ / W) quadratic rows. To enforce\n this structure, the code stores NQTRIPLES = (NQ / W) instead of the\n number 3 * NQTRIPLES of rows.\n\n */\n\nnamespace proofs {\n\ntemplate \nstruct LigeroParam {\n using Elt = typename Field::Elt;\n\n // parameters passed by the user\n size_t nw; // total number of witnesses\n size_t nq; // total number of quadratic constraints\n size_t rateinv; // inverse rate of the error-correcting code\n size_t nreq; // number of opened columns\n\n // computed parameters\n size_t block_enc; // total number of elts per row\n size_t block; // number of elts per block\n size_t dblock; // 2 * BLOCK - 1\n size_t block_ext; // BLOCK_ENC - DBLOCK (number of leaves in the\n // Merkle tree).\n size_t r; // number of random elts in a witness block\n size_t w; // number of witnesses in a witness block\n size_t nwrow; // number of witness rows\n size_t nqtriples; // number of triples of quadratic-check rows\n size_t nwqrow; // nwqrow + nqtriples\n size_t nrow; // total number of rows (nwqrow + three blinding rows)\n size_t mc_pathlen; // length of a Merkle-tree proof\n // with BLOCK_ENC-BLOCK leaves\n\n // layout of rows\n size_t ildt; // blinding for the low-degree test\n size_t idot; // blinding row for the dot-product check\n size_t iquad; // blinding row for the quadratic check\n size_t iw; // first witness row\n size_t iq; // first quadratic row\n\n LigeroParam(size_t nw, size_t nq, size_t rateinv, size_t nreq)\n : nw(nw), nq(nq), rateinv(rateinv), nreq(nreq) {\n r = nreq;\n\n size_t min_proof_size = SIZE_MAX;\n size_t best_block_enc = 1;\n for (size_t e = 1; e <= (1 << 28); e *= 2) {\n size_t proof_size = layout(e);\n if (proof_size < min_proof_size) {\n min_proof_size = proof_size;\n best_block_enc = e;\n }\n }\n\n // recompute parameters\n layout(best_block_enc);\n proofs::check(block_enc > block, \"block_enc > block\");\n\n ildt = 0;\n idot = 1;\n iquad = 2;\n iw = 3;\n iq = iw + nwrow;\n proofs::check(nrow == iq + 3 * nqtriples, \"nrow == iq + 3 * nqtriples\");\n }\n\n private:\n // Return an estimate of the proof size.\n //\n // This function is kind of a hack in that it breaks abstraction\n // boundaries, e.g. it knows about the size and layout of the Merkle\n // commitment. Punt on this wart until we have a better theory.\n size_t layout(size_t e) {\n // Maximum size we are prepared to handle. All dimensions will be\n // required to be < MAX_SIZE. In principle we could handle all\n // size_t, but we want 64-bit code to fail if it would fail on a\n // 32-bit machine, and for maximum paranoia we restrict to 28\n // bits, since one cannot malloc 2^{28} Elts on a 32-bit machine\n // anyway.\n constexpr size_t max_lg_size = 28;\n constexpr size_t max_size = static_cast(1) << max_lg_size;\n block_enc = e;\n\n // block_enc must fit in the subfield\n size_t subfield_bits = 8 * Field::kSubFieldBytes;\n if (subfield_bits <= max_lg_size) {\n if (block_enc >= (static_cast(1) << subfield_bits)) {\n return SIZE_MAX;\n }\n }\n\n // limit block_enc to avoid overflow in the computation\n // of the proof size\n if (block_enc > max_size || rateinv > max_size ||\n (block_enc + 1) < (2 + rateinv)) {\n return SIZE_MAX;\n }\n\n block = (block_enc + 1) / (2 + rateinv);\n // now 1 <= BLOCK < MAX_SIZE / 2\n\n // Ensure BLOCK = R + W (syntactic property)\n if (block < r) {\n return SIZE_MAX;\n }\n w = block - r;\n\n // now r <= BLOCK < MAX_SIZE / 2\n // 0 <= W < MAX_SIZE / 2\n // 0 <= W <= BLOCK\n // 0 <= R <= BLOCK\n // W + R == BLOCK\n\n // Ensure W >= R (needed for reasonable space utilization).\n if (w < r) {\n return SIZE_MAX;\n }\n // now R <= W < MAX_SIZE\n\n // Finish the layout of a row\n dblock = 2 * block - 1;\n // now DBLOCK < MAX_SIZE\n\n // Ensure BLOCK_ENC >= 0 (syntactic property). Should be true\n // for any reasonable rateinv, but check anyway.\n if (block_enc < dblock) {\n return SIZE_MAX;\n }\n // now DBLOCK <= BLOCK_ENC\n\n block_ext = block_enc - dblock;\n // now 0 <= BLOCK_EXT < MAX_SIZE\n\n nwrow = ceildiv(nw, w);\n nqtriples = ceildiv(nq, w);\n\n nwqrow = nwrow + 3 * nqtriples;\n nrow = nwqrow + /*blinding rows=*/3;\n\n // The total number of elements (NROW * BLOCK_ENC) in the tableau\n // must fit in MAX_SIZE.\n if (nrow >= max_size / block_enc) {\n return SIZE_MAX;\n }\n\n mc_pathlen = merkle_commitment_len(block_ext);\n\n /* proof+commitment size. */\n // Compute the size in uint64_t instead of size_t since\n // I am too lazy to worry about overflow.\n uint64_t sz = 0;\n\n // commitment\n sz += sizeof(Digest);\n\n // Merkle openings, approximated because the exact # of leaves depends\n // on the random coins.\n sz += static_cast(mc_pathlen) / 2 * static_cast(nreq) *\n static_cast(Digest::kLength);\n\n // y_ldt\n sz += static_cast(block) * static_cast(Field::kBytes);\n\n // y_dot\n sz += static_cast(dblock) * static_cast(Field::kBytes);\n\n // y_quad\n // The quadratic-test response has size DBLOCK, but W elements\n // are expected to be zero and not serialized.\n sz += static_cast(dblock - w) *\n static_cast(Field::kBytes);\n\n // nonces\n sz += static_cast(nreq) *\n static_cast(MerkleNonce::kLength);\n\n // req. Assume optimistically that all elements are in the subfield.\n sz += static_cast(nrow) * static_cast(nreq) *\n static_cast(Field::kSubFieldBytes);\n\n sz = std::min(sz, SIZE_MAX);\n return static_cast(sz);\n }\n};\n\ntemplate \nstruct LigeroCommitment {\n Digest root;\n};\n\ntemplate \nstruct LigeroProof {\n using Elt = typename Field::Elt;\n explicit LigeroProof(const LigeroParam *p)\n : block(p->block),\n dblock(p->dblock),\n r(p->r),\n block_enc(p->block_enc),\n nrow(p->nrow),\n nreq(p->nreq),\n mc_pathlen(p->mc_pathlen),\n y_ldt(p->block),\n y_dot(p->dblock),\n y_quad_0(p->r),\n y_quad_2(p->dblock - p->block),\n req(p->nrow * p->nreq),\n merkle(p->nreq) {}\n\n // The proof stores a copy of all parameters relevant to the proof.\n size_t block;\n size_t dblock;\n size_t r;\n size_t block_enc;\n size_t nrow;\n size_t nreq;\n size_t mc_pathlen;\n\n std::vector y_ldt; // [block]\n std::vector y_dot; // [dblock]\n std::vector y_quad_0; // [r] first part of y_quad.\n // The middle part [w] of y_quad is zero and not transmitted.\n std::vector y_quad_2; // [dblock - block] last part of y_quad\n std::vector req; // [nrow, nreq]\n MerkleProof merkle;\n\n Elt &req_at(size_t i, size_t j) { return req[i * nreq + j]; }\n const Elt &req_at(size_t i, size_t j) const { return req[i * nreq + j]; }\n};\n\n// a nonzero entry in the matrix A that defines\n// the linear constraints A w = b. The term\n// states that A[c, w] = k, where the \"row\"\n// c is interpreted as the constraint index, and\n// the \"column\" w is interpreted as the witness\n// index\ntemplate \nstruct LigeroLinearConstraint {\n using Elt = typename Field::Elt;\n size_t c;\n size_t w;\n Elt k;\n};\n\n// encode W[X] * W[Y] - W[Z] = 0\nstruct LigeroQuadraticConstraint {\n size_t x;\n size_t y;\n size_t z;\n};\n\ntemplate \nclass LigeroCommon {\n using Elt = typename Field::Elt;\n\n public:\n // create a grand dot product by A given the user-provided\n // linear-constraint terms LLTERM, the quadratic constraints LQC,\n // and their random challenges ALPHAL, ALPHAQ.\n static void inner_product_vector(\n Elt A[/*nwqrow, w*/], const LigeroParam &p, size_t nl,\n size_t nllterm, const LigeroLinearConstraint llterm[/*nllterm*/],\n const Elt alphal[/*nl*/], const LigeroQuadraticConstraint lqc[/*nq*/],\n const std::array alphaq[/*nq*/], const Field &F) {\n // clear A and overwrite it later.\n Blas::clear(p.nwqrow * p.w, A, 1, F);\n\n // random linear combinations of the linear constraints\n for (size_t l = 0; l < nllterm; ++l) {\n const auto &term = llterm[l];\n proofs::check(term.w < p.nw, \"term.w < p.nw\");\n proofs::check(term.c < nl, \"term.c < nl\");\n F.add(A[term.w], F.mulf(term.k, alphal[term.c]));\n }\n\n // routing terms for quadratic constraints\n Elt *Ax = &A[p.nwrow * p.w];\n Elt *Ay = Ax + (p.nqtriples * p.w);\n Elt *Az = Ay + (p.nqtriples * p.w);\n\n for (size_t i = 0; i < p.nqtriples; ++i) {\n for (size_t j = 0; j < p.w && j + i * p.w < p.nq; ++j) {\n // index into [_ , W] arrays\n size_t iw = j + i * p.w;\n const auto *l = &lqc[iw];\n F.add(Ax[iw], alphaq[iw][0]);\n F.sub(A[l->x], alphaq[iw][0]);\n\n F.add(Ay[iw], alphaq[iw][1]);\n F.sub(A[l->y], alphaq[iw][1]);\n\n F.add(Az[iw], alphaq[iw][2]);\n F.sub(A[l->z], alphaq[iw][2]);\n }\n }\n }\n\n // layout a witness block where the \"witness\" is public, and\n // thus the randomess is zero.\n static void layout_Aext(Elt Aext[/*>=block*/], const LigeroParam &p,\n size_t i, const Elt A[/*nwqrow, nw*/],\n const Field &F) {\n Blas::clear(p.r, &Aext[0], 1, F);\n Blas::copy(p.w, &Aext[p.r], 1, &A[i * p.w], 1);\n }\n\n static void column_hash(size_t n, const Elt x[/*n:incx*/], size_t incx,\n SHA256 &sha, const Field &F) {\n for (size_t i = 0; i < n; ++i) {\n uint8_t buf[Field::kBytes];\n F.to_bytes_field(buf, x[i * incx]);\n sha.Update(buf, sizeof(buf));\n }\n }\n};\n\n// A struct representing the hash of llterms. It is really the\n// same as Digest, but in theory Ligero should exist independently\n// of the Merkle tree.\nstruct LigeroHash {\n static constexpr size_t kLength = kSHA256DigestSize;\n uint8_t bytes[kLength];\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_PARAM_H_\n"], ["/longfellow-zk/lib/circuits/mac/mac_witness.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MAC_MAC_WITNESS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MAC_MAC_WITNESS_H_\n\n#include \n#include \n\n#include \"arrays/dense.h\"\n#include \"circuits/logic/bit_plucker_encoder.h\"\n#include \"gf2k/gf2_128.h\"\n\nnamespace proofs {\n\ntemplate \nclass MacWitness {\n using f_128 = GF2_128<>;\n using gf2k = f_128::Elt;\n using packer = BitPluckerEncoder;\n using packed_v128 = typename packer::packed_v128;\n using packed_v256 = typename packer::packed_v256;\n\n public:\n explicit MacWitness(const Field& F, const f_128& GF) : f_(F), gf_(GF) {}\n\n void fill_witness(DenseFiller& fill) const {\n packer bp(f_);\n uint8_t tmp[f_128::kBits];\n for (size_t i = 0; i < 2; ++i) {\n for (size_t j = 0; j < f_128::kBits; ++j) {\n tmp[j] = ap_[i][j];\n }\n fill.push_back(bp.template pack(tmp, f_128::kBits));\n }\n\n for (size_t i = 0; i < 2; ++i) {\n for (size_t j = 0; j < f_128::kBits; ++j) {\n tmp[j] = x_[i][j];\n }\n fill.push_back(bp.template pack(tmp, 128));\n }\n }\n\n // Computes a mac witness on a 32-byte message x.\n // This code assumes that a gf element is at least 16 bytes.\n void compute_witness(const gf2k a_p[/*2*/], const uint8_t x[/*32*/]) {\n for (size_t i = 0; i < 2; ++i) {\n x_[i] = gf_.of_bytes_field(&x[i * 16]).value();\n ap_[i] = a_p[i];\n }\n }\n\n private:\n gf2k ap_[2], x_[2];\n const Field& f_;\n const f_128& gf_;\n};\n\nclass MacGF2Witness {\n using f_128 = GF2_128<>;\n using gf2k = f_128::Elt;\n\n public:\n void fill_witness(DenseFiller& fill) const {\n fill.push_back(ap_[0]);\n fill.push_back(ap_[1]);\n }\n\n // Computes a mac witness on a 32-byte message x.\n void compute_witness(const gf2k a_p[/*2*/]) {\n for (size_t i = 0; i < 2; ++i) {\n ap_[i] = a_p[i];\n }\n }\n\n private:\n gf2k ap_[2];\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MAC_MAC_WITNESS_H_\n"], ["/longfellow-zk/lib/ligero/ligero_prover.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_PROVER_H_\n#define PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_PROVER_H_\n\n#include \n\n#include \n#include \n#include \n\n#include \"algebra/blas.h\"\n#include \"ligero/ligero_param.h\"\n#include \"ligero/ligero_transcript.h\"\n#include \"merkle/merkle_commitment.h\"\n#include \"random/random.h\"\n#include \"random/transcript.h\"\n#include \"util/crypto.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\ntemplate \nclass LigeroProver {\n using Elt = typename Field::Elt;\n\n public:\n explicit LigeroProver(const LigeroParam &p)\n : p_(p), mc_(p.block_enc - p.dblock), tableau_(p.nrow * p.block_enc) {}\n\n // The SUBFIELD_BOUNDARY parameter is kind of a hack.\n //\n // Most, but not all, witnesses in W[] are known statically to be in\n // the subfield of Field, for example because they are bits or\n // bit-plucked values in the subfield. For zero-knowledge, for\n // these witnesses, it suffices to choose blinding randomness in the\n // subfield, which yields a shorter proof since most column openings\n // are fully in the subfield. The problem is now to distinguish\n // subfield witnesses from field witnesses.\n //\n // In the fullness of time we should have a compiler with typing\n // information (field vs subfield) of all input wires. For now\n // we implement the following hack: W[i] is in the subfield for\n // i < SUBFIELD_BOUNDARY, and in the full field otherwise.\n // If you don't know better, set SUBFIELD_BOUNDARY = 0 which\n // trivially works for any input.\n void commit(LigeroCommitment &commitment, Transcript &ts,\n const Elt W[/*p_.nw*/], const size_t subfield_boundary,\n const LigeroQuadraticConstraint lqc[/*nq*/],\n const InterpolatorFactory &interpolator, RandomEngine &rng,\n const Field &F) {\n // Paranoid check on the SUBFIELD_BOUNDARY correctness condition\n for (size_t i = 0; i < subfield_boundary; ++i) {\n check(F.in_subfield(W[i]), \"element not in subfield\");\n }\n\n layout(W, subfield_boundary, lqc, interpolator, rng, F);\n\n // Merkle commitment\n auto updhash = [&](size_t j, SHA256 &sha) {\n LigeroCommon::column_hash(p_.nrow, &tableau_at(0, j + p_.dblock),\n p_.block_enc, sha, F);\n };\n commitment.root = mc_.commit(updhash, rng);\n\n // P -> V\n LigeroTranscript::write_commitment(commitment, ts);\n }\n\n // HASH_OF_LLTERM is a hash of LLTERM provided by the caller. We\n // could compute the hash locally, but usually LLTERM has a special\n // structure that makes the computation faster on the caller's side.\n void prove(LigeroProof &proof, Transcript &ts, size_t nl,\n size_t nllterm,\n const LigeroLinearConstraint llterm[/*nllterm*/],\n const LigeroHash &hash_of_llterm,\n const LigeroQuadraticConstraint lqc[/*nq*/],\n const InterpolatorFactory &interpolator, const Field &F) {\n {\n // P -> V\n // theorem statement\n ts.write(hash_of_llterm.bytes, hash_of_llterm.kLength);\n }\n\n {\n std::vector u_ldt(p_.nwqrow);\n\n // V -> P\n LigeroTranscript::gen_uldt(&u_ldt[0], p_, ts, F);\n low_degree_proof(&proof.y_ldt[0], &u_ldt[0], F);\n }\n\n {\n std::vector alphal(nl);\n std::vector> alphaq(p_.nq);\n std::vector A(p_.nwqrow * p_.w);\n\n // V -> P\n LigeroTranscript::gen_alphal(nl, &alphal[0], ts, F);\n LigeroTranscript::gen_alphaq(&alphaq[0], p_, ts, F);\n\n LigeroCommon::inner_product_vector(&A[0], p_, nl, nllterm, llterm,\n &alphal[0], lqc, &alphaq[0], F);\n\n dot_proof(&proof.y_dot[0], &A[0], interpolator, F);\n }\n\n {\n std::vector u_quad(p_.nqtriples);\n\n // V -> P\n LigeroTranscript::gen_uquad(&u_quad[0], p_, ts, F);\n quadratic_proof(&proof.y_quad_0[0], &proof.y_quad_2[0], &u_quad[0], F);\n }\n\n {\n // P -> V\n ts.write(&proof.y_ldt[0], 1, p_.block, F);\n ts.write(&proof.y_dot[0], 1, p_.dblock, F);\n ts.write(&proof.y_quad_0[0], 1, p_.r, F);\n ts.write(&proof.y_quad_2[0], 1, p_.dblock - p_.block, F);\n }\n\n {\n std::vector idx(p_.nreq);\n // V -> P\n LigeroTranscript::gen_idx(&idx[0], p_, ts, F);\n\n compute_req(proof, &idx[0]);\n\n mc_.open(proof.merkle, &idx[0], p_.nreq);\n }\n }\n\n private:\n Elt &tableau_at(size_t i, size_t j) {\n size_t ld = p_.block_enc;\n return tableau_[i * ld + j];\n }\n\n // fill t_[i, [0,n)] with random elements\n // If the base_only flag is true, then the random element is chosen from\n // the base field if F is a field extension.\n void random_row(size_t i, size_t n, RandomEngine &rng, const Field &F) {\n for (size_t j = 0; j < n; ++j) {\n tableau_at(i, j) = rng.elt(F);\n }\n }\n\n void random_subfield_row(size_t i, size_t n, RandomEngine &rng,\n const Field &F) {\n for (size_t j = 0; j < n; ++j) {\n tableau_at(i, j) = rng.subfield_elt(F);\n }\n }\n\n // generate the ILDT and IDOT blinding rows\n void layout_blinding_rows(const InterpolatorFactory &interpolator,\n RandomEngine &rng, const Field &F) {\n {\n // blinds of size [BLOCK]\n const auto interp = interpolator.make(p_.block, p_.block_enc);\n\n // low-degree blinding row\n random_row(p_.ildt, p_.block, rng, F);\n interp->interpolate(&tableau_at(p_.ildt, 0));\n }\n\n {\n // blinds of size [DBLOCK]\n const auto interp = interpolator.make(p_.dblock, p_.block_enc);\n\n // dot-product blinding row constrained to SUM(W) = 0. First\n // randomize the dblock:\n random_row(p_.idot, p_.dblock, rng, F);\n\n // Then constrain to sum(W) = 0\n Elt sum = Blas::dot1(p_.w, &tableau_at(p_.idot, p_.r), 1, F);\n F.sub(tableau_at(p_.idot, p_.r), sum);\n\n interp->interpolate(&tableau_at(p_.idot, 0));\n\n // quadratic-test blinding row constrained to W = 0. First\n // randomize the entire dblock:\n random_row(p_.iquad, p_.dblock, rng, F);\n\n // Then constrain to W = 0\n Blas::clear(p_.w, &tableau_at(p_.iquad, p_.r), 1, F);\n\n interp->interpolate(&tableau_at(p_.iquad, 0));\n }\n }\n\n void layout_witness_rows(const Elt W[/*nw*/], size_t subfield_boundary,\n const InterpolatorFactory &interpolator,\n RandomEngine &rng, const Field &F) {\n const auto interp = interpolator.make(p_.block, p_.block_enc);\n\n // witness row EXTEND([RANDOM[R], WITNESS[W]], BLOCK)\n for (size_t i = 0; i < p_.nwrow; ++i) {\n // TRUE if the entire row is in the subfield\n bool subfield_only = ((i + 1) * p_.w <= subfield_boundary);\n\n if (subfield_only) {\n random_subfield_row(i + p_.iw, p_.r, rng, F);\n } else {\n random_row(i + p_.iw, p_.r, rng, F);\n }\n\n // Set the WITNESS columns to zero first, and then\n // overwrite with the witnesses that actually exist\n Blas::clear(p_.w, &tableau_at(i + p_.iw, p_.r), 1, F);\n size_t max_col = std::min(p_.w, p_.nw - i * p_.w);\n Blas::copy(max_col, &tableau_at(i + p_.iw, p_.r), 1, &W[i * p_.w],\n 1);\n interp->interpolate(&tableau_at(i + p_.iw, 0));\n }\n }\n\n void layout_quadratic_rows(const Elt W[/*nw*/],\n const LigeroQuadraticConstraint lqc[/*nq*/],\n const InterpolatorFactory &interpolator,\n RandomEngine &rng, const Field &F) {\n const auto interp = interpolator.make(p_.block, p_.block_enc);\n\n // copy the multiplicand witnesses into the quadratic rows\n size_t iqx = p_.iq;\n size_t iqy = iqx + p_.nqtriples;\n size_t iqz = iqy + p_.nqtriples;\n\n for (size_t i = 0; i < p_.nqtriples; ++i) {\n random_row(iqx + i, p_.r, rng, F);\n random_row(iqy + i, p_.r, rng, F);\n random_row(iqz + i, p_.r, rng, F);\n\n // clear everything first, then overwrite the witnesses that\n // actually exist\n Blas::clear(p_.w, &tableau_at(iqx + i, p_.r), 1, F);\n Blas::clear(p_.w, &tableau_at(iqy + i, p_.r), 1, F);\n Blas::clear(p_.w, &tableau_at(iqz + i, p_.r), 1, F);\n\n for (size_t j = 0; j < p_.w && j + i * p_.w < p_.nq; ++j) {\n const auto *l = &lqc[j + i * p_.w];\n check(W[l->z] == F.mulf(W[l->x], W[l->y]),\n \"invalid quadratic constraints\");\n tableau_at(iqx + i, j + p_.r) = W[l->x];\n tableau_at(iqy + i, j + p_.r) = W[l->y];\n tableau_at(iqz + i, j + p_.r) = W[l->z];\n }\n interp->interpolate(&tableau_at(iqx + i, 0));\n interp->interpolate(&tableau_at(iqy + i, 0));\n interp->interpolate(&tableau_at(iqz + i, 0));\n }\n }\n\n void layout(const Elt W[/*nw*/], size_t subfield_boundary,\n const LigeroQuadraticConstraint lqc[/*nq*/],\n const InterpolatorFactory &interpolator, RandomEngine &rng,\n const Field &F) {\n layout_blinding_rows(interpolator, rng, F);\n layout_witness_rows(W, subfield_boundary, interpolator, rng, F);\n layout_quadratic_rows(W, lqc, interpolator, rng, F);\n }\n\n void low_degree_proof(Elt y[/*block*/], const Elt u_ldt[/*nwqrow*/],\n const Field &F) {\n // ILDT blinding row with coefficient 1\n Blas::copy(p_.block, y, 1, &tableau_at(p_.ildt, 0), 1);\n\n // all witness and quadratic rows with coefficient u_ldt[]\n for (size_t i = 0; i < p_.nwqrow; ++i) {\n Blas::axpy(p_.block, y, 1, u_ldt[i], &tableau_at(i + p_.iw, 0), 1,\n F);\n }\n }\n\n void dot_proof(Elt y[/*dblock*/], const Elt A[/*nwqrow, w*/],\n const InterpolatorFactory &interpolator, const Field &F) {\n const auto interpA = interpolator.make(p_.block, p_.dblock);\n\n // IDOT blinding row with coefficient 1\n Blas::copy(p_.dblock, y, 1, &tableau_at(p_.idot, 0), 1);\n\n std::vector Aext(p_.dblock);\n for (size_t i = 0; i < p_.nwqrow; ++i) {\n LigeroCommon::layout_Aext(&Aext[0], p_, i, &A[0], F);\n interpA->interpolate(&Aext[0]);\n\n // Accumulate y += A \\otimes W.\n Blas::vaxpy(p_.dblock, &y[0], 1, &Aext[0], 1,\n &tableau_at(i + p_.iw, 0), 1, F);\n }\n }\n\n void quadratic_proof(Elt y0[/*r*/], Elt y2[/*dblock - block*/],\n const Elt u_quad[/*nqtriples*/], const Field &F) {\n std::vector y(p_.dblock);\n std::vector tmp(p_.dblock);\n\n // IQUAD blinding row with coefficient 1\n Blas::copy(p_.dblock, &y[0], 1, &tableau_at(p_.iquad, 0), 1);\n\n size_t iqx = p_.iq;\n size_t iqy = iqx + p_.nqtriples;\n size_t iqz = iqy + p_.nqtriples;\n\n for (size_t i = 0; i < p_.nqtriples; ++i) {\n // y += u_quad[i] * (z[i] - x[i] * y[i])\n\n // tmp = z[i]\n Blas::copy(p_.dblock, &tmp[0], 1, &tableau_at(iqz + i, 0), 1);\n\n // tmp -= x[i] \\otimes y[i]\n Blas::vymax(p_.dblock, &tmp[0], 1, &tableau_at(iqx + i, 0), 1,\n &tableau_at(iqy + i, 0), 1, F);\n\n // y += u_quad[i] * tmp\n Blas::axpy(p_.dblock, &y[0], 1, u_quad[i], &tmp[0], 1, F);\n }\n\n // sanity check: the W part of Y is zero\n bool ok = Blas::equal0(p_.w, &y[p_.r], 1, F);\n check(ok, \"W part is nonzero\");\n\n // extract the first and last parts\n Blas::copy(p_.r, y0, 1, &y[0], 1);\n Blas::copy(p_.dblock - p_.block, y2, 1, &y[p_.block], 1);\n }\n\n void compute_req(LigeroProof &proof, const size_t idx[/*nreq*/]) {\n for (size_t i = 0; i < p_.nrow; ++i) {\n Blas::gather(p_.nreq, &proof.req_at(i, 0),\n &tableau_at(i, p_.dblock), idx);\n }\n }\n\n const LigeroParam p_; /* safer to make copy */\n MerkleCommitment mc_;\n std::vector tableau_ /*[nrow, block_enc]*/;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_PROVER_H_\n"], ["/longfellow-zk/lib/circuits/logic/memcmp.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_MEMCMP_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_MEMCMP_H_\n\n#include \n\n#include \n\nnamespace proofs {\n// This class implements the an equivalent of memcmp for arrays of\n// v8. The logic comparison operators do all the work, and the only\n// problem is to arrange bits in the correct order for comparison.\n// In more detail, these methods compare the bit strings represented by\n// the array of v8 inputs (recall a v8 is 8 wires each containing a {0,1} value\n// in the Field).\ntemplate \nclass Memcmp {\n public:\n using BitW = typename Logic::BitW;\n using v8 = typename Logic::v8;\n const Logic& l_;\n\n explicit Memcmp(const Logic& l) : l_(l) {}\n\n // A < B\n BitW lt(size_t n, const v8 A[/*n*/], const v8 B[/*n*/]) const {\n std::vector a(8 * n);\n std::vector b(8 * n);\n arrange(n, a.data(), A);\n arrange(n, b.data(), B);\n return l_.lt(8 * n, a.data(), b.data());\n }\n\n // A <= B\n BitW leq(size_t n, const v8 A[/*n*/], const v8 B[/*n*/]) const {\n std::vector a(8 * n);\n std::vector b(8 * n);\n arrange(n, a.data(), A);\n arrange(n, b.data(), B);\n return l_.leq(8 * n, a.data(), b.data());\n }\n\n private:\n void arrange(size_t n, BitW bits[/* 8 * n */], const v8 bytes[/*n*/]) const {\n // from LSB to MSB:\n for (size_t i = n; i-- > 0;) {\n for (size_t j = 0; j < 8; ++j) {\n *bits++ = bytes[i][j];\n }\n }\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_MEMCMP_H_\n"], ["/longfellow-zk/lib/sumcheck/quad.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_SUMCHECK_QUAD_H_\n#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_QUAD_H_\n\n#include \n\n#include \n#include \n#include \n#include \n\n#include \"algebra/compare.h\"\n#include \"algebra/poly.h\"\n#include \"arrays/affine.h\"\n#include \"arrays/eqs.h\"\n#include \"util/ceildiv.h\"\n#include \"util/panic.h\"\n#define DEFINE_STRONG_INT_TYPE(a, b) using a = b\n\n// ------------------------------------------------------------\n// Special-purpose sparse array for use with sumcheck\nnamespace proofs {\ntemplate \nclass Quad {\n using Elt = typename Field::Elt;\n using T2 = Poly<2, Field>;\n\n public:\n // To save space when representing large circuits, quad_corner_t\n // is defined as uint32_t. (Note that Elt probably imposes uint64_t\n // alignment, so struct corner has holes.)\n //\n // To make the narrowing explicit, define corner_t as a\n // Google-specific strong int. Outside of Google, replace\n // this definition with a typedef.\n DEFINE_STRONG_INT_TYPE(quad_corner_t, uint32_t);\n\n struct corner {\n quad_corner_t g; // \"gate\" variable\n quad_corner_t h[2]; // two \"hand\" variables\n Elt v;\n\n bool operator==(const corner& y) const {\n return g == y.g &&\n morton::eq(size_t(h[0]), size_t(h[1]), size_t(y.h[0]),\n size_t(y.h[1])) &&\n v == y.v;\n }\n\n bool eqndx(const corner& y) const {\n return (g == y.g && h[0] == y.h[0] && h[1] == y.h[1]);\n }\n\n void canonicalize() {\n quad_corner_t h0 = h[0], h1 = h[1];\n h[0] = std::min(h0, h1);\n h[1] = std::max(h0, h1);\n }\n\n static bool compare(const corner& x, const corner& y, const Field& F) {\n if (morton::lt(size_t(x.h[0]), size_t(x.h[1]), size_t(y.h[0]),\n size_t(y.h[1]))) {\n return true;\n } else if (morton::eq(size_t(x.h[0]), size_t(x.h[1]), size_t(y.h[0]),\n size_t(y.h[1]))) {\n if (x.g < y.g) return true;\n if (x.g > y.g) return false;\n return elt_less_than(x.v, y.v, F);\n } else {\n return false;\n }\n }\n };\n\n using index_t = size_t;\n index_t n_;\n std::vector c_;\n\n bool operator==(const Quad& y) const {\n return n_ == y.n_ &&\n std::equal(c_.begin(), c_.end(), y.c_.begin(), y.c_.end());\n }\n\n explicit Quad(index_t n) : n_(n), c_(n) {}\n\n // no copies, but see clone() below\n Quad(const Quad& y) = delete;\n Quad(const Quad&& y) = delete;\n Quad operator=(const Quad& y) = delete;\n\n std::unique_ptr clone() const {\n auto s = std::make_unique(n_);\n for (index_t i = 0; i < n_; ++i) {\n s->c_[i] = c_[i];\n }\n return s;\n }\n\n void bind_h(const Elt& r, size_t hand, const Field& F) {\n index_t rd = 0, wr = 0;\n while (rd < n_) {\n corner cc;\n cc.g = quad_corner_t(0);\n cc.h[hand] = c_[rd].h[hand] >> 1;\n cc.h[1 - hand] = c_[rd].h[1 - hand];\n\n size_t rd1 = rd + 1;\n if (rd1 < n_ && //\n c_[rd].h[1 - hand] == c_[rd1].h[1 - hand] && //\n (c_[rd].h[hand] >> 1) == (c_[rd1].h[hand] >> 1) && //\n c_[rd1].h[hand] == c_[rd].h[hand] + quad_corner_t(1)) {\n // we have two corners.\n cc.v = affine_interpolation(r, c_[rd].v, c_[rd1].v, F);\n rd += 2;\n } else {\n // we have one corner and the other one is zero.\n if ((c_[rd].h[hand] & quad_corner_t(1)) == quad_corner_t(0)) {\n cc.v = affine_interpolation_nz_z(r, c_[rd].v, F);\n } else {\n cc.v = affine_interpolation_z_nz(r, c_[rd].v, F);\n }\n rd = rd1;\n }\n\n c_[wr++] = cc;\n }\n\n // shrink the array\n n_ = wr;\n }\n\n // Set zero coefficients to BETA, then bind to both\n // G0 and G1 and take the linear combination bind(G0) + alpha*bind(G1)\n void bind_g(size_t logv, const Elt* G0, const Elt* G1, const Elt& alpha,\n const Elt& beta, const Field& F) {\n size_t nv = size_t(1) << logv;\n auto dot = Eqs::raw_eq2(logv, nv, G0, G1, alpha, F);\n for (index_t i = 0; i < n_; ++i) {\n if (c_[i].v == F.zero()) {\n c_[i].v = beta;\n }\n F.mul(c_[i].v, dot[corner_t(c_[i].g)]);\n c_[i].g = quad_corner_t(0);\n }\n\n // coalesce any duplicates that we may have created\n coalesce(F);\n }\n\n // Optimized combined bind_g + bind_h, nondestructive\n Elt bind_gh_all(\n // G bindings\n size_t logv, const Elt G0[/*logv*/], const Elt G1[/*logv*/],\n const Elt& alpha, const Elt& beta,\n // H bindings\n size_t logw, const Elt H0[/*logw*/], const Elt H1[/*logw*/],\n // field\n const Field& F) const {\n size_t nv = size_t(1) << logv;\n auto eqg = Eqs::raw_eq2(logv, nv, G0, G1, alpha, F);\n\n size_t nw = size_t(1) << logw;\n Eqs eqh0(logw, nw, H0, F);\n Eqs eqh1(logw, nw, H1, F);\n\n Elt s{};\n\n for (index_t i = 0; i < n_; ++i) {\n Elt q(c_[i].v);\n if (q == F.zero()) {\n q = beta;\n }\n F.mul(q, eqg[corner_t(c_[i].g)]);\n F.mul(q, eqh0.at(corner_t(c_[i].h[0])));\n F.mul(q, eqh1.at(corner_t(c_[i].h[1])));\n F.add(s, q);\n }\n return s;\n }\n\n Elt scalar() {\n check(n_ == 1, \"n_ == 1\");\n check(c_[0].g == quad_corner_t(0), \"c_[0].g == 0\");\n check(c_[0].h[0] == quad_corner_t(0), \"c_[0].h[0] == 0\");\n check(c_[0].h[1] == quad_corner_t(0), \"c_[0].h[1] == 0\");\n return c_[0].v;\n }\n\n void canonicalize(const Field& F) {\n for (index_t i = 0; i < n_; ++i) {\n c_[i].canonicalize();\n }\n std::sort(c_.begin(), c_.end(), [&F](const corner& x, const corner& y) {\n return corner::compare(x, y, F);\n });\n coalesce(F);\n }\n\n private:\n void coalesce(const Field& F) {\n // Coalesce duplicates.\n // The (rd,wr)=(0,0) iteration executes the else{} branch and\n // continues with (1,1), so we start at (1,1) and avoid the\n // special case for wr-1 at wr=0.\n index_t wr = 1;\n for (index_t rd = 1; rd < n_; ++rd) {\n if (c_[rd].eqndx(c_[wr - 1])) {\n F.add(c_[wr - 1].v, c_[rd].v);\n } else {\n c_[wr] = c_[rd];\n wr++;\n }\n }\n n_ = wr;\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_QUAD_H_\n"], ["/longfellow-zk/lib/circuits/logic/bit_plucker_encoder.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_PLUCKER_ENCODER_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_PLUCKER_ENCODER_H_\n\n#include \n#include \n\n#include \n\n#include \"circuits/logic/bit_plucker_constants.h\"\n\nnamespace proofs {\ntemplate \nclass BitPluckerEncoder {\n const Field& f_;\n\n using Elt = typename Field::Elt;\n static constexpr size_t kN = size_t(1) << LOGN;\n static constexpr size_t kNv32Elts = (32u + LOGN - 1u) / LOGN;\n static constexpr size_t kNv128Elts = (128u + LOGN - 1u) / LOGN;\n static constexpr size_t kNv256Elts = (256u + LOGN - 1u) / LOGN;\n\n public:\n using packed_v32 = std::array;\n using packed_v128 = std::array;\n using packed_v256 = std::array;\n\n explicit BitPluckerEncoder(const Field& F) : f_(F) {}\n\n Elt encode(size_t i) const { return bit_plucker_point()(i, f_); }\n\n // Special case packer for uint32_t used in sha256.\n packed_v32 mkpacked_v32(uint32_t j) {\n packed_v32 r;\n for (size_t i = 0; i < r.size(); ++i) {\n r[i] = encode(j & (kN - 1));\n j >>= LOGN;\n }\n return r;\n }\n\n template \n T pack(uint8_t bits[/* n bits */], size_t n) {\n T r;\n for (size_t i = 0; i < r.size(); ++i) {\n size_t v = 0;\n for (size_t j = 0; j < LOGN; ++j) {\n if (i * LOGN + j < n) {\n v += (bits[i * LOGN + j] & 0x1) << j;\n }\n }\n r[i] = encode(v);\n }\n return r;\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_PLUCKER_ENCODER_H_\n"], ["/longfellow-zk/lib/cbor/host_decoder.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CBOR_HOST_DECODER_H_\n#define PRIVACY_PROOFS_ZK_LIB_CBOR_HOST_DECODER_H_\n\n#include \n#include \n\n#include \n#include \n\n#include \"util/panic.h\"\n\nnamespace proofs {\n\nenum CborTag { UNSIGNED, NEGATIVE, BYTES, TEXT, ARRAY, MAP, TAG, PRIMITIVE };\nenum CborPrimitive { FALSE, TRUE, CNULL };\n\n// CBOR decoder for a subset of CBOR used in MDOC.\n//\n// The main advantage of this decoder is that it keeps\n// offsets into the input, which is useful because we need to\n// generate circuits that depend on input offsets.\n//\n// The other security advantage is the smaller codebase, versus\n// relying on an imported CBOR parser that handles a larger subset of CBOR\n// that may introduce issues.\n//\n// The decode function is used to process an untrusted array of bytes.\n// The method returns false if the input is not processed exactly per the\n// MDOC spec with only attributes in the org.iso.18013.5.1 namespace.\n// The resulting CborDoc object is static, and it is assumed that neither the\n// input doc, nor the tree structure changes. All of the lookup and index\n// methods return const pointers to attempt to maintain this property.\nclass CborDoc {\n public:\n size_t header_pos_;\n enum CborTag t_;\n\n // A union is used to store the attributes for either singleton objects (i.e.,\n // UNSIGNED, NEGATIVE, PRIMITIVE), the start position and len of TEXT and\n // BYTES array, and the children information for ARRAY or MAP objects.\n // len of strings and byte arrays\n union U {\n uint64_t u64; /* UNSIGNED */\n int64_t i64; /* NEGATIVE */\n enum CborPrimitive p; /* PRIMITIVE */\n\n // BYTES + TEXT, represented as offset in input + length\n struct {\n size_t pos;\n size_t len;\n } string;\n\n // arrays, maps, and tags: an array of children nodes.\n struct {\n // The original count in the source document. For tags,\n // the tag itself.\n size_t n;\n\n // The actual number of children (e.g. 2*n for maps).\n size_t nchildren;\n } items;\n } u_;\n\n // This field only applies to ARRAY, MAP nodes, but it has been moved\n // out of the union to avoid including components with non-default\n // constructors. It holds the children objects of an array or map. For a map,\n // even positions are the keys, and the odd positions are the values.\n std::vector children_;\n\n // Parse a byte sequence into a CborDoc structure.\n //\n // Caller passes in the input sequence, the length of the\n // input, and pos and offset values. The offset value handles the case when\n // the input sequence is a sub-sequence of another string, as it is in\n // the MDOC and MSO parsing.\n //\n // This function can handle adversarial inputs, and returns false when the\n // input cannot be parsed.\n bool decode(const uint8_t in[], size_t len, size_t &pos, size_t offset) {\n /* invariant: pos is always compared with len before it is referenced. */\n header_pos_ = pos + offset;\n\n if (pos >= len) {\n return false;\n }\n uint8_t b = in[pos++];\n\n size_t type = (b >> 5) & 0x7u;\n size_t count0 = b & 0x1Fu;\n\n // variable-length count\n size_t count = 0;\n if (count0 < 24) {\n count = count0;\n } else if (count0 == 24) {\n if (pos >= len) {\n return false;\n }\n count = in[pos++];\n } else if (count0 == 25) {\n if (pos + 1 >= len) {\n return false;\n }\n count = in[pos] * 256 + in[pos + 1];\n pos += 2;\n } else if (count0 == 26) {\n if (pos + 3 >= len) {\n return false;\n }\n for (size_t i = 0; i < 4; ++i) {\n count *= 256;\n count += in[pos++];\n }\n } else {\n return false;\n }\n\n switch (type) { /* type \\in [0,7] by construction */\n case 0:\n t_ = UNSIGNED;\n u_.u64 = count;\n break;\n case 1:\n t_ = NEGATIVE;\n u_.i64 = -(int64_t)count;\n break;\n\n case 2: /* BYTES */\n case 3: /* TEXT */\n if (pos + count > len) {\n return false;\n }\n t_ = (type == 2) ? BYTES : TEXT;\n u_.string.pos = pos;\n u_.string.len = count;\n pos += count;\n break;\n\n case 4: /* ARRAY */\n if (pos + count > len) {\n return false;\n }\n return decode_items(ARRAY, count, count, in, len, pos, offset);\n\n case 5: /* MAP, (key,val) pairs are stored as 2*children */\n if (pos + 2 * count > len) {\n return false;\n }\n return decode_items(MAP, 2 * count, count, in, len, pos, offset);\n\n case 6: /* TAG */\n // Special cases for TAG\n if (count == 1004) { // date in the form YYYY-MM-DD\n if (pos + 1 + 10 > len) { // 0xDA for str length + 10 characters\n return false;\n }\n }\n return decode_items(TAG, 1, count, in, len, pos, offset);\n\n case 7: /* PRIMITIVE */\n t_ = PRIMITIVE;\n switch (count) {\n case 20:\n u_.p = FALSE;\n break;\n case 21:\n u_.p = TRUE;\n break;\n case 22:\n u_.p = CNULL;\n break;\n default:\n return false;\n }\n break;\n }\n\n return true;\n }\n\n // Lookup a child node in an array. Returns null if the query is invalid.\n const CborDoc *index(size_t index) const {\n if (t_ == ARRAY && index < u_.items.nchildren) {\n return &children_[index];\n }\n return nullptr;\n }\n\n // Lookup a key in a map of type {bytes->elements}.\n // Returns null if the query is invalid.\n // The key is given as bytes with a length.\n // ndx is set to the child index of the located key.\n // The return pointer references the key, and the next object refers to\n // the value and is guaranteed to exist.\n const CborDoc *lookup(const uint8_t *const in, size_t len,\n const uint8_t bytes[/*len*/], size_t &ndx) const {\n if (t_ == MAP) {\n for (size_t i = 0; i < u_.items.n; ++i) {\n if (children_[2 * i].eq(in, len, bytes)) {\n ndx = i;\n return &children_[2 * i];\n }\n }\n }\n return nullptr;\n }\n\n // Lookup a key in a map of type {unsigned->object}.\n // Returns null if the query is invalid.\n const CborDoc *lookup_unsigned(uint64_t k, size_t &ndx) const {\n if (t_ == MAP) {\n for (size_t i = 0; i < u_.items.n; ++i) {\n const CborDoc *key = &children_[2 * i];\n if (key->t_ == UNSIGNED && key->u_.u64 == k) {\n ndx = i;\n return key;\n }\n }\n }\n return nullptr;\n }\n\n // Lookup a key in a map of type {negative->object}.\n // Returns null if the query is invalid.\n const CborDoc *lookup_negative(int64_t k, size_t &ndx) const {\n if (t_ == MAP) {\n for (size_t i = 0; i < u_.items.n; ++i) {\n const CborDoc *key = &children_[2 * i];\n if (key->t_ == NEGATIVE && key->u_.i64 == k) {\n ndx = i;\n return key;\n }\n }\n }\n return nullptr;\n }\n\n // Returns the index of the item with respect to the document bytes.\n size_t position() const {\n switch (t_) {\n case UNSIGNED:\n return header_pos_;\n case BYTES:\n case TEXT:\n return u_.string.pos;\n case TAG:\n return children_[0].u_.string.pos;\n case PRIMITIVE:\n return header_pos_;\n default:\n check(false, \"valueIndex called on non-value type\");\n }\n return 0;\n }\n\n // Returns the length of the item's value in bytes.\n // According to ISO 18013-5 7.2.1, the mDL data elements shall be encoded\n // as tstr, uint, bstr, bool, or tdate, so this function only handles those\n // cases.\n size_t length() const {\n switch (t_) {\n case UNSIGNED:\n if (u_.u64 < 24) {\n return 1;\n } else if (u_.u64 < 256) {\n return 2;\n } else if (u_.u64 < 65536) {\n return 3;\n }\n return 5;\n case BYTES:\n case TEXT:\n return u_.string.len;\n case TAG:\n return children_[0].u_.string.len; // full-date #6.1004(tstr) format\n case PRIMITIVE:\n return 1;\n default:\n check(false, \"valueLength called on non-value type\");\n }\n return 0;\n }\n\n private:\n // Decodes a sequence of children nodes.\n bool decode_items(CborTag t, size_t nchildren, size_t items_n,\n const uint8_t in[], size_t len, size_t &pos,\n size_t offset) {\n t_ = t;\n u_.items.n = items_n;\n u_.items.nchildren = nchildren;\n children_.resize(nchildren);\n for (size_t i = 0; i < nchildren; ++i) {\n if (!children_[i].decode(in, len, pos, offset)) return false;\n }\n return true;\n }\n\n // Compares a text node to a given string of bytes.\n bool eq(const uint8_t *const in, size_t len,\n const uint8_t bytes[/*len*/]) const {\n return t_ == TEXT && u_.string.len == len &&\n memcmp(bytes, &in[u_.string.pos], len) == 0;\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CBOR_HOST_DECODER_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_constants.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_CONSTANTS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_CONSTANTS_H_\n\n#include \n#include \n\nnamespace proofs {\n\n/* Max number of SHA blocks to process. */\nconstexpr static const size_t kMaxSHABlocks = 35;\n\n/* Number of bits in CBOR index. Must be large enough to index into MDOC.*/\nconstexpr static const size_t kCborIndexBits = 12;\n\n// This is the prefix added to the D8... mdoc encoding to produce\n// a COSE1 encoding that is ready to be hashed.\nstatic constexpr uint8_t kCose1Prefix[18] = {\n 0x84, 0x6A, 0x53, 0x69, 0x67, 0x6E, 0x61, 0x74, 0x75,\n 0x72, 0x65, 0x31, 0x43, 0xA1, 0x01, 0x26, 0x40, 0x59,\n};\nstatic constexpr size_t kCose1PrefixLen = 18;\n\n/* Max size of an MSO that hashes using < MAX SHA blocks. */\nconstexpr static const size_t kMaxMsoLen =\n kMaxSHABlocks * 64 - 9 - kCose1PrefixLen;\n\nstatic constexpr size_t kValidityInfoLen = 12;\nstatic constexpr size_t kValidFromLen = 9;\nstatic constexpr size_t kDeviceKeyLen = 9;\nstatic constexpr size_t kDeviceKeyInfoLen = 13;\nstatic constexpr size_t kValidUntilLen = 10;\nstatic constexpr size_t kValueDigestsLen = 12;\nstatic constexpr size_t kOrgLen = 17;\n\nstatic constexpr uint8_t kTag32[] = {0x58, 0x20};\nstatic constexpr size_t kIdLen = 32;\nstatic constexpr size_t kValueLen = 64;\n\nstatic constexpr uint8_t kValidityInfoID[kValidityInfoLen] = {\n 'v', 'a', 'l', 'i', 'd', 'i', 't', 'y', 'I', 'n', 'f', 'o'};\n\nstatic constexpr uint8_t kValidFromID[kValidFromLen] = {'v', 'a', 'l', 'i', 'd',\n 'F', 'r', 'o', 'm'};\n\nstatic constexpr uint8_t kValidUntilID[kValidUntilLen] = {\n 'v', 'a', 'l', 'i', 'd', 'U', 'n', 't', 'i', 'l'};\n\nstatic constexpr uint8_t kDeviceKeyID[kDeviceKeyLen] = {'d', 'e', 'v', 'i', 'c',\n 'e', 'K', 'e', 'y'};\n\nstatic constexpr uint8_t kDeviceKeyInfoID[kDeviceKeyInfoLen] = {\n 'd', 'e', 'v', 'i', 'c', 'e', 'K', 'e', 'y', 'I', 'n', 'f', 'o'};\n\nstatic constexpr uint8_t kValueDigestsID[kValueDigestsLen] = {\n 'v', 'a', 'l', 'u', 'e', 'D', 'i', 'g', 'e', 's', 't', 's'};\n\nstatic constexpr uint8_t kOrgID[kOrgLen] = {'o', 'r', 'g', '.', 'i', 's',\n 'o', '.', '1', '8', '0', '1',\n '3', '.', '5', '.', '1'};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_CONSTANTS_H_\n"], ["/longfellow-zk/lib/algebra/sysdep.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_SYSDEP_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_SYSDEP_H_\n\n#include \n\n#include \n\n#include \"util/panic.h\" // IWYU pragma: keep\n\n#if defined(__x86_64__) || defined(__i386__)\n// system-dependent basic arithmetic functions: add with carry\n// and 64x64->128 bit multiplication\n#include // IWYU pragma: keep\n#endif\n\nnamespace proofs {\n\n#if defined(__x86_64__)\nstatic inline uint64_t adc(uint64_t* a, uint64_t b, uint64_t c) {\n // unsigned long long (not uint64_t) is *required* by the\n // _addcarry_u64() prototype. uint64_t is unsigned long on\n // linux, and pointers to the two types are incompatible even\n // though the conversion is a no-op.\n unsigned long long out;\n c = _addcarry_u64(c, *a, b, &out);\n *a = out;\n return c;\n}\nstatic inline uint32_t adc(uint32_t* a, uint32_t b, uint32_t c) {\n return _addcarry_u32(c, *a, b, a);\n}\nstatic inline uint64_t sbb(uint64_t* a, uint64_t b, uint64_t c) {\n unsigned long long out;\n c = _subborrow_u64(c, *a, b, &out);\n *a = out;\n return c;\n}\nstatic inline uint32_t sbb(uint32_t* a, uint32_t b, uint32_t c) {\n return _subborrow_u32(c, *a, b, a);\n}\nstatic inline void mulq(uint64_t* l, uint64_t* h, uint64_t a, uint64_t b) {\n asm(\"mulx %2, %0, %1\" : \"=r\"(*l), \"=r\"(*h) : \"r\"(b), \"d\"(a));\n}\n#elif defined(__i386__)\nstatic inline uint32_t adc(uint32_t* a, uint32_t b, uint32_t c) {\n return _addcarry_u32(c, *a, b, a);\n}\nstatic inline uint32_t sbb(uint32_t* a, uint32_t b, uint32_t c) {\n return _subborrow_u32(c, *a, b, a);\n}\n\n// these two functions are supposed to be defined but are\n// never called\nstatic inline unsigned long long adc(unsigned long long* a,\n unsigned long long b,\n unsigned long long c) {\n check(false, \"adcll() not defined\");\n return 0;\n}\nstatic inline unsigned long long sbb(unsigned long long* a,\n unsigned long long b,\n unsigned long long c) {\n check(false, \"sbbll() not defined\");\n return 0;\n}\n\n#define SYSDEP_MULQ64_NOT_DEFINED\n#elif defined(__clang__)\n// The clang intrinsics use the builtin-types int, long, etc.\n// Thus we define adc() and sbb() in terms of those types.\nstatic inline unsigned long long adc(unsigned long long* a,\n unsigned long long b,\n unsigned long long c) {\n *a = __builtin_addcll(*a, b, c, &c);\n return c;\n}\nstatic inline unsigned long adc(unsigned long* a, unsigned long b,\n unsigned long c) {\n *a = __builtin_addcl(*a, b, c, &c);\n return c;\n}\nstatic inline unsigned int adc(unsigned int* a, unsigned int b,\n unsigned int c) {\n *a = __builtin_addc(*a, b, c, &c);\n return c;\n}\n\nstatic inline unsigned long long sbb(unsigned long long* a,\n unsigned long long b,\n unsigned long long c) {\n *a = __builtin_subcll(*a, b, c, &c);\n return c;\n}\nstatic inline unsigned long sbb(unsigned long* a, unsigned long b,\n unsigned long c) {\n *a = __builtin_subcl(*a, b, c, &c);\n return c;\n}\nstatic inline unsigned int sbb(unsigned int* a, unsigned int b,\n unsigned int c) {\n *a = __builtin_subc(*a, b, c, &c);\n return c;\n}\n\n#if defined(__SIZEOF_INT128__)\n// It seems that __SIZEOF_INT128__ is defined if __uint128_t is.\nstatic inline void mulq(uint64_t* l, uint64_t* h, uint64_t a, uint64_t b) {\n __uint128_t p = (__uint128_t)b * (__uint128_t)a;\n *l = p;\n *h = p >> 64;\n}\n#else // defined(__SIZEOF_INT128__)\n#define SYSDEP_MULQ64_NOT_DEFINED\n#endif // defined(__SIZEOF_INT128__)\n#endif\n\nstatic inline void mulq(uint32_t* l, uint32_t* h, uint32_t a, uint32_t b) {\n uint64_t p = (uint64_t)b * (uint64_t)a;\n *l = p;\n *h = p >> 32;\n}\n\n// Identity function whose only purpose is to confuse the compiler.\n// We have no coherent theory of when and why this is useful, but\n// here are a couple of cases where this hack makes a difference:\n//\n// * Passing the cmov() values through identity_limb() seems\n// to favor the generation of a conditional move instruction\n// as opposed to a conditional branch.\n// * Clang and gcc match a+b+carry to generate the adcq instruction,\n// but a+0+carry becomes a+carry and the match fails. So\n// we pretend that the zero is not a zero.\n// * A similar issue arises in subtract with carry.\n//\n// This function is obviously a hack. Works for me today but YMMV.\n//\ntemplate \nstatic inline limb_t identity_limb(limb_t v) {\n asm(\"\" : \"+r\"(v)::);\n return v;\n}\n\ntemplate \nstatic inline limb_t zero_limb() {\n return identity_limb(0);\n}\n\n// a += b\ntemplate \nstatic inline void accum(size_t Wa, limb_t a[/*Wa*/], size_t Wb,\n const limb_t b[/*Wb*/]) {\n limb_t c = 0;\n for (size_t i = 0; i < Wb; ++i) {\n c = adc(&a[i], b[i], c);\n }\n for (size_t i = Wb; i < Wa; ++i) {\n c = adc(&a[i], 0, c);\n }\n}\n\n// a -= b\ntemplate \nstatic inline void negaccum(size_t Wa, limb_t a[/*Wa*/], size_t Wb,\n const limb_t b[/*Wb*/]) {\n limb_t c = 0;\n for (size_t i = 0; i < Wb; ++i) {\n c = sbb(&a[i], b[i], c);\n }\n for (size_t i = Wb; i < Wa; ++i) {\n c = sbb(&a[i], 0, c);\n }\n}\n\n// h::a += b\ntemplate \nstatic inline limb_t add_limb(size_t W, limb_t a[/*W*/],\n const limb_t b[/*W*/]) {\n limb_t c = 0;\n for (size_t i = 0; i < W; ++i) {\n c = adc(&a[i], b[i], c);\n }\n limb_t h = zero_limb();\n c = adc(&h, 0, c);\n return h;\n}\n\n// h::a += b * 2^(bits per limb)\ntemplate \nstatic inline limb_t addh(size_t W, limb_t a[/*W*/], const limb_t b[/*W*/]) {\n limb_t c = 0;\n for (size_t i = 1; i < W; ++i) {\n c = adc(&a[i], b[i - 1], c);\n }\n limb_t h = zero_limb();\n c = adc(&h, b[W - 1], c);\n return h;\n}\n\n// h::a -= b\ntemplate \nstatic inline limb_t sub_limb(size_t W, limb_t a[/*W*/],\n const limb_t b[/*W*/]) {\n limb_t c = 0;\n for (size_t i = 0; i < W; ++i) {\n c = sbb(&a[i], b[i], c);\n }\n limb_t h = zero_limb();\n c = sbb(&h, 0, c);\n return h;\n}\n\n// h:l = a*b\ntemplate \nstatic inline void mulhl(size_t W, limb_t l[/*W*/], limb_t h[/*W*/], limb_t a,\n const limb_t b[/*W*/]) {\n for (size_t i = 0; i < W; ++i) {\n mulq(&l[i], &h[i], a, b[i]);\n }\n}\n\n// a = b\ntemplate \nstatic inline void mov(size_t W, limb_t a[/*W*/], const limb_t b[/*W*/]) {\n for (size_t i = 0; i < W; ++i) {\n a[i] = b[i];\n }\n}\n\n// It seems that using assembly code is the only way to\n// force gcc and clang to use conditional moves.\n#if defined(__x86_64__)\nstatic inline void cmovnz(size_t W, uint64_t a[/*W*/], uint64_t nz,\n const uint64_t b[/*W*/]) {\n if (W == 1) {\n asm(\"testq %[nz], %[nz]\\n\\t\"\n \"cmovneq %[b0], %[a0]\\n\\t\"\n : [a0] \"+r\"(a[0])\n : [nz] \"r\"(nz), [b0] \"r\"(b[0]));\n } else if (W == 2) {\n asm(\"testq %[nz], %[nz]\\n\\t\"\n \"cmovneq %[b0], %[a0]\\n\\t\"\n \"cmovneq %[b1], %[a1]\\n\\t\"\n : [a0] \"+r\"(a[0]), [a1] \"+r\"(a[1])\n : [nz] \"r\"(nz), [b0] \"r\"(b[0]), [b1] \"r\"(b[1]));\n } else if (W == 3) {\n asm(\"testq %[nz], %[nz]\\n\\t\"\n \"cmovneq %[b0], %[a0]\\n\\t\"\n \"cmovneq %[b1], %[a1]\\n\\t\"\n \"cmovneq %[b2], %[a2]\\n\\t\"\n : [a0] \"+r\"(a[0]), [a1] \"+r\"(a[1]), [a2] \"+r\"(a[2])\n : [nz] \"r\"(nz), [b0] \"r\"(b[0]), [b1] \"r\"(b[1]), [b2] \"r\"(b[2]));\n } else if (W == 4) {\n asm(\"testq %[nz], %[nz]\\n\\t\"\n \"cmovneq %[b0], %[a0]\\n\\t\"\n \"cmovneq %[b1], %[a1]\\n\\t\"\n \"cmovneq %[b2], %[a2]\\n\\t\"\n \"cmovneq %[b3], %[a3]\\n\\t\"\n : [a0] \"+r\"(a[0]), [a1] \"+r\"(a[1]), [a2] \"+r\"(a[2]), [a3] \"+r\"(a[3])\n : [nz] \"r\"(nz), [b0] \"r\"(b[0]), [b1] \"r\"(b[1]), [b2] \"r\"(b[2]),\n [b3] \"r\"(b[3]));\n } else {\n for (size_t i = 0; i < W; ++i) {\n a[i] = (nz != 0) ? b[i] : a[i];\n }\n }\n}\n\nstatic inline void cmovne(size_t W, uint64_t a[/*W*/], uint64_t x, uint64_t y,\n const uint64_t b[/*W*/]) {\n if (W == 1) {\n asm(\"cmpq %[x], %[y]\\n\\t\"\n \"cmovneq %[b0], %[a0]\\n\\t\"\n : [a0] \"+r\"(a[0])\n : [x] \"r\"(x), [y] \"r\"(y), [b0] \"r\"(b[0])\n : \"cc\");\n } else if (W == 2) {\n asm(\"cmpq %[x], %[y]\\n\\t\"\n \"cmovneq %[b0], %[a0]\\n\\t\"\n \"cmovneq %[b1], %[a1]\\n\\t\"\n : [a0] \"+r\"(a[0]), [a1] \"+r\"(a[1])\n : [x] \"r\"(x), [y] \"r\"(y), [b0] \"r\"(b[0]), [b1] \"r\"(b[1])\n : \"cc\");\n } else if (W == 3) {\n asm(\"cmpq %[x], %[y]\\n\\t\"\n \"cmovneq %[b0], %[a0]\\n\\t\"\n \"cmovneq %[b1], %[a1]\\n\\t\"\n \"cmovneq %[b2], %[a2]\\n\\t\"\n : [a0] \"+r\"(a[0]), [a1] \"+r\"(a[1]), [a2] \"+r\"(a[2])\n : [x] \"r\"(x), [y] \"r\"(y), [b0] \"r\"(b[0]), [b1] \"r\"(b[1]), [b2] \"r\"(b[2])\n : \"cc\");\n } else if (W == 4) {\n asm(\"cmpq %[x], %[y]\\n\\t\"\n \"cmovneq %[b0], %[a0]\\n\\t\"\n \"cmovneq %[b1], %[a1]\\n\\t\"\n \"cmovneq %[b2], %[a2]\\n\\t\"\n \"cmovneq %[b3], %[a3]\\n\\t\"\n : [a0] \"+r\"(a[0]), [a1] \"+r\"(a[1]), [a2] \"+r\"(a[2]), [a3] \"+r\"(a[3])\n : [x] \"r\"(x), [y] \"r\"(y), [b0] \"r\"(b[0]), [b1] \"r\"(b[1]),\n [b2] \"r\"(b[2]), [b3] \"r\"(b[3])\n : \"cc\");\n } else {\n for (size_t i = 0; i < W; ++i) {\n a[i] = (x != y) ? b[i] : a[i];\n }\n }\n}\n\nstatic inline uint64_t addcmovc(uint64_t a, uint64_t b, uint64_t c) {\n asm(\"add %[b], %[a]\\n\\t\"\n \"cmovaeq %[c], %[a]\\n\\t\"\n : [a] \"+r\"(a)\n : [b] \"r\"(b), [c] \"r\"(c)\n : \"cc\");\n return a;\n}\n\nstatic inline uint64_t sub_sysdep(uint64_t a, uint64_t y, uint64_t m) {\n uint64_t z = 0;\n asm(\"subq %[y], %[a]\\n\\t\"\n \"cmovbq %[m], %[z]\\n\\t\"\n : [a] \"+r\"(a), [z] \"+r\"(z)\n : [y] \"r\"(y), [m] \"r\"(m)\n : \"cc\");\n return a + z;\n}\n\n#elif defined(__aarch64__)\n\nstatic inline void cmovne(size_t W, uint64_t a[/*W*/], uint64_t x, uint64_t y,\n const uint64_t b[/*W*/]) {\n if (W == 1) {\n asm(\"cmp %[x], %[y]\\n\\t\" //\n \"csel %[a0], %[a0], %[b0], eq\\n\\t\" //\n : [a0] \"+r\"(a[0]) //\n : [x] \"r\"(x), [y] \"ri\"(y), //\n [b0] \"r\"(b[0]) //\n : \"cc\");\n } else if (W == 2) {\n asm(\"cmp %[x], %[y]\\n\\t\" //\n \"csel %[a0], %[a0], %[b0], eq\\n\\t\" //\n \"csel %[a1], %[a1], %[b1], eq\\n\\t\" //\n : [a0] \"+r\"(a[0]), //\n [a1] \"+r\"(a[1]) //\n : [x] \"r\"(x), [y] \"ri\"(y), //\n [b0] \"r\"(b[0]), //\n [b1] \"r\"(b[1]) //\n : \"cc\");\n } else if (W == 3) {\n asm(\"cmp %[x], %[y]\\n\\t\" //\n \"csel %[a0], %[a0], %[b0], eq\\n\\t\" //\n \"csel %[a1], %[a1], %[b1], eq\\n\\t\" //\n \"csel %[a2], %[a2], %[b2], eq\\n\\t\" //\n : [a0] \"+r\"(a[0]), //\n [a1] \"+r\"(a[1]), //\n [a2] \"+r\"(a[2]) //\n : [x] \"r\"(x), [y] \"ri\"(y), //\n [b0] \"r\"(b[0]), //\n [b1] \"r\"(b[1]), //\n [b2] \"r\"(b[2]) //\n : \"cc\");\n } else if (W == 4) {\n asm(\"cmp %[x], %[y]\\n\\t\" //\n \"csel %[a0], %[a0], %[b0], eq\\n\\t\" //\n \"csel %[a1], %[a1], %[b1], eq\\n\\t\" //\n \"csel %[a2], %[a2], %[b2], eq\\n\\t\" //\n \"csel %[a3], %[a3], %[b3], eq\\n\\t\" //\n : [a0] \"+r\"(a[0]), //\n [a1] \"+r\"(a[1]), //\n [a2] \"+r\"(a[2]), //\n [a3] \"+r\"(a[3]) //\n : [x] \"r\"(x), [y] \"ri\"(y), //\n [b0] \"r\"(b[0]), //\n [b1] \"r\"(b[1]), //\n [b2] \"r\"(b[2]), //\n [b3] \"r\"(b[3]) //\n : \"cc\");\n } else {\n for (size_t i = 0; i < W; ++i) {\n a[i] = (x != y) ? b[i] : a[i];\n }\n }\n}\n\n// a = (nz != 0) ? b : a\nstatic inline void cmovnz(size_t W, uint64_t a[/*W*/], uint64_t nz,\n const uint64_t b[/*W*/]) {\n constexpr uint64_t z = 0;\n cmovne(W, a, nz, z, b);\n}\n\nstatic inline uint64_t addcmovc(uint64_t a, uint64_t b, uint64_t c) {\n asm(\"adds %[a], %[a], %[b]\\n\\t\"\n \"csel %[a], %[a], %[c], hs\\n\\t\"\n : [a] \"+r\"(a)\n : [b] \"r\"(b), [c] \"r\"(c)\n : \"cc\");\n return a;\n}\n\nstatic inline uint64_t sub_sysdep(uint64_t a, uint64_t y, uint64_t m) {\n asm(\"subs %[a], %[a], %[y]\\n\\t\"\n \"csel %[m], %[m], xzr, lo\"\n : [a] \"+r\"(a), [m] \"+r\"(m)\n : [y] \"r\"(y)\n : \"cc\");\n return a + m;\n}\n\n#else // generic portable code\n\n// a = (x != y) ? b : a\ntemplate \nstatic inline void cmovne(size_t W, limb_t a[/*W*/], limb_t x, limb_t y,\n const limb_t b[/*W*/]) {\n for (size_t i = 0; i < W; ++i) {\n a[i] = (x != y) ? b[i] : a[i];\n }\n}\n\n// a = (nz != 0) ? b : a\ntemplate \nstatic inline void cmovnz(size_t W, limb_t a[/*W*/], limb_t nz,\n const limb_t b[/*W*/]) {\n constexpr limb_t z = 0;\n cmovne(W, a, nz, z, b);\n}\n\ntemplate \nstatic inline limb_t addcmovc(limb_t a, limb_t b, limb_t c) {\n limb_t t = a + b;\n return (a > t) ? t : c;\n}\n\ntemplate \nstatic inline limb_t sub_sysdep(limb_t a, limb_t y, limb_t m) {\n limb_t t0 = a - y;\n return (y > a) ? (t0 + m) : t0;\n}\n\n#endif\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_SYSDEP_H_\n"], ["/longfellow-zk/lib/sumcheck/transcript_sumcheck.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_SUMCHECK_TRANSCRIPT_SUMCHECK_H_\n#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_TRANSCRIPT_SUMCHECK_H_\n\n#include \n\n#include \"arrays/affine.h\"\n#include \"arrays/dense.h\"\n#include \"random/transcript.h\"\n#include \"sumcheck/circuit.h\"\n\nnamespace proofs {\n/*\nFiat-Shamir abstraction for sumcheck protocol.\nThis class takes wraps a transcript object and provides the interface for\nsumcheck challenge and response.\n*/\ntemplate \nclass TranscriptSumcheck {\n using Elt = typename Field::Elt;\n using CPoly = typename Proof::CPoly;\n using WPoly = typename Proof::WPoly;\n static constexpr size_t kMaxBindings = Proof::kMaxBindings;\n\n public:\n explicit TranscriptSumcheck(Transcript& ts, const Field& F)\n : ts_(ts), f_(F) {}\n\n void write_input(const Dense* X) {\n // Write column by column to make it compatible with oracle.\n for (corner_t c = 0; c < X->n0_; ++c) {\n ts_.write(&X->v_[c], X->n0_, X->n1_, f_);\n }\n }\n\n void begin_circuit(Elt* Q, Elt* G) {\n ts_.elt(Q, kMaxBindings, f_);\n ts_.elt(G, kMaxBindings, f_);\n }\n\n void begin_layer(Elt& alpha, Elt& beta, size_t layer) {\n alpha = ts_.elt(f_);\n beta = ts_.elt(f_);\n }\n\n void write(const Elt e[/*n*/], size_t ince, size_t n) {\n ts_.write(e, ince, n, f_);\n }\n\n template \n Elt /*R*/ round(const Poly& poly) {\n write_poly(&poly);\n return ts_.elt(f_);\n }\n\n private:\n template \n void write_poly(const Poly* poly) {\n // Do not write the p(1) value to the transcript, as its value is\n // implied by the constraints, and we can omit it from the proof.\n for (size_t i = 0; i < Poly::kN; ++i) {\n if (i != 1) {\n ts_.write(poly->t_[i], f_);\n }\n }\n }\n Transcript& ts_;\n const Field& f_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_TRANSCRIPT_SUMCHECK_H_\n"], ["/longfellow-zk/lib/random/transcript.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_RANDOM_TRANSCRIPT_H_\n#define PRIVACY_PROOFS_ZK_LIB_RANDOM_TRANSCRIPT_H_\n\n#include \n#include \n#include \n#include \n\n#include \"random/random.h\"\n#include \"util/crypto.h\"\n#include \"util/panic.h\"\n#include \"util/serialization.h\"\n\nnamespace proofs {\n\n/*\nFSPRF and Transcript together used implement the Fiat-Shamir transform.\n*/\nclass FSPRF {\n public:\n explicit FSPRF(const uint8_t key[kPRFKeySize])\n : prf_(key), nblock_(0), rdptr_(kPRFOutputSize) {}\n\n // Disable copy for good measure.\n explicit FSPRF(const FSPRF&) = delete;\n FSPRF& operator=(const FSPRF&) = delete;\n\n void bytes(uint8_t buf[/*n*/], size_t n) {\n while (n-- > 0) {\n if (rdptr_ == kPRFOutputSize) {\n refill();\n }\n *buf++ = saved_[rdptr_++];\n }\n }\n\n private:\n void refill() {\n uint8_t in[kPRFInputSize] = {};\n u64_to_le(in, nblock_++);\n prf_.Eval(saved_, in);\n rdptr_ = 0;\n }\n\n PRF prf_;\n uint64_t nblock_;\n size_t rdptr_; // read pointer into saved[]\n uint8_t saved_[kPRFOutputSize]; // saved pseudo-random bytes\n};\n\nclass Transcript : public RandomEngine {\n enum { TAG_BSTR = 0, TAG_FIELD_ELEM = 1, TAG_ARRAY = 1 };\n\n public:\n // A transcript must be explicitly initialized so that each instance of\n // the Random oracle is unique.\n Transcript(const uint8_t init[], size_t init_len) : sha_(), prf_() {\n write(init, init_len);\n }\n\n // Remove default copy and move implementations.\n Transcript(const Transcript&) = delete;\n Transcript& operator=(const Transcript&) = delete;\n\n // Explicit copy to avoid accidental passing by value.\n Transcript clone() { return Transcript(sha_); }\n\n // Generate bytes by via the current FSPRF object.\n void bytes(uint8_t buf[/*n*/], size_t n) override {\n if (!prf_) {\n uint8_t key[kPRFKeySize];\n get(key);\n prf_ = std::make_unique(key);\n }\n prf_->bytes(buf, n);\n }\n\n // snapshot the hash of the transcript so far\n void get(uint8_t key[/*kPRFKeySize*/]) {\n check(kPRFKeySize == kSHA256DigestSize, \"prf key size != digest output\");\n // fork the state because we will finalize it\n SHA256 tmp_hash;\n tmp_hash.CopyState(sha_);\n tmp_hash.DigestData(key);\n }\n\n // Typed write operations. We tag byte-array(n), field-element, and\n // array-of-field-element(n).\n //\n // We make a few arbitrary choices that make no real difference.\n // All lengths are 64-bit. We distinguish a field element from\n // an array of one field element, which is kind of arbitrary.\n\n // byte string\n void write(const uint8_t data[/*n*/], size_t n) {\n tag(TAG_BSTR);\n length(n);\n\n write_untyped(data, n);\n }\n\n // N zero bytes\n void write0(size_t n) {\n tag(TAG_BSTR);\n length(n);\n\n uint8_t data[32] = {};\n for (; n > 32; n -= 32) {\n write_untyped(data, 32);\n }\n write_untyped(data, n);\n }\n\n // one field element\n template \n void write(const typename Field::Elt& e, const Field& F) {\n tag(TAG_FIELD_ELEM);\n\n write_untyped(e, F);\n }\n\n // array of field elements\n template \n void write(const typename Field::Elt e[/*n*/], size_t ince, size_t n,\n const Field& F) {\n tag(TAG_ARRAY);\n length(n);\n\n for (size_t i = 0; i < n; ++i) {\n write_untyped(e[i * ince], F);\n }\n }\n\n private:\n explicit Transcript(const SHA256& sha) : sha_() {\n sha_.CopyState(sha);\n }\n\n // Output a 1-byte tag\n void tag(size_t t) {\n uint8_t d = static_cast(t);\n write_untyped(&d, 1);\n }\n\n // Output a 8-byte length. We pass the length\n // as size_t, but we always write it as uint64_t\n void length(size_t x) {\n uint8_t a[8];\n u64_to_le(a, x);\n write_untyped(a, 8);\n }\n\n void write_untyped(const uint8_t data[/*n*/], size_t n) {\n // invalidate the PRF on any writes\n prf_.reset();\n sha_.Update(data, n);\n }\n\n template \n void write_untyped(const typename Field::Elt& e, const Field& F) {\n uint8_t buf[Field::kBytes];\n F.to_bytes_field(buf, e);\n write_untyped(buf, sizeof(buf));\n }\n\n SHA256 sha_;\n std::unique_ptr prf_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_RANDOM_TRANSCRIPT_H_\n"], ["/longfellow-zk/lib/sumcheck/verifier_layers.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_SUMCHECK_VERIFIER_LAYERS_H_\n#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_VERIFIER_LAYERS_H_\n\n#include \n\n#include \n#include \n\n#include \"arrays/affine.h\"\n#include \"arrays/dense.h\"\n#include \"arrays/eq.h\"\n#include \"sumcheck/circuit.h\"\n#include \"sumcheck/quad.h\"\n#include \"sumcheck/transcript_sumcheck.h\"\n\nnamespace proofs {\n// Sumcheck verifier that only verifies the layers.\n// Derived classes are responsible for verifying the\n// input binding, either directly or through a commitment.\ntemplate \nclass VerifierLayers {\n public:\n typedef typename Quad::index_t index_t;\n using Elt = typename Field::Elt;\n\n struct claims {\n corner_t nv;\n size_t logv;\n Elt claim[2];\n const Elt* q;\n const Elt* g[2];\n };\n // Verify all the circuit layers, returning claims on the inputs in\n // CL. The caller is responsible to verify the claims, either via\n // direct check or polynomial commitment.\n static bool circuit(const char** why, claims* cl,\n const Circuit* CIRCUIT, const Proof* PROOF,\n Challenge* CH, std::unique_ptr> V,\n TranscriptSumcheck& ts, const Field& F) {\n if (why == nullptr || cl == nullptr || CIRCUIT == nullptr ||\n PROOF == nullptr || CH == nullptr) {\n return false;\n }\n *why = \"ok\";\n\n Elt claimV;\n ts.begin_circuit(CH->q, CH->g);\n\n if (V->n1_ == 1 && V->n0_ == 1 && V->v_[0] == F.zero()) {\n // special case of all-zero binding\n claimV = F.zero();\n } else {\n const desire desires[2] = {\n {V->n1_ == CIRCUIT->nv, \"V->n1_ != CIRCUIT->nv\"},\n {V->n0_ == CIRCUIT->nc, \"V->n0_ != CIRCUIT->nc\"},\n };\n\n if (!check(why, 2, desires)) {\n return false;\n }\n\n // initial claim on V[G, Q] for the output V\n V->bind_all(CIRCUIT->logc, CH->q, F);\n V->reshape(CIRCUIT->nv);\n V->bind_all(CIRCUIT->logv, CH->g, F);\n claimV = V->scalar();\n }\n\n // Consider claimV on the binding to P.G as two (identical)\n // claims, so we can get the induction going. Thus, alpha in\n // the first layer is redundant.\n *cl = claims{\n .nv = CIRCUIT->nv,\n .logv = CIRCUIT->logv,\n .claim = {claimV, claimV},\n .q = CH->q,\n .g = {CH->g, CH->g},\n };\n\n return layers(why, cl, CIRCUIT, PROOF, ts, CH, F);\n }\n\n VerifierLayers() = delete;\n\n private:\n struct desire {\n bool cond;\n const char* why;\n };\n\n static bool check(const char** why, size_t n, const desire* d) {\n for (size_t i = 0; i < n; ++i) {\n if (!d[i].cond) {\n *why = d[i].why;\n return false;\n }\n }\n return true;\n }\n\n // Verify CLAIM for one layer and update CLAIM in-place as next\n // claim. Return TRUE on success, and (FALSE, why) on failure.\n static bool layer_c(const char** why, Elt* claim, size_t logc,\n const LayerProof* plr, LayerChallenge* ch,\n TranscriptSumcheck& ts, const Field& F) {\n for (size_t round = 0; round < logc; ++round) {\n // (p(0) + p(1))\n Elt got = F.addf(plr->cp[round].t_[0], plr->cp[round].t_[1]);\n if (got != *claim) {\n *why = \"got != claim (round_c)\";\n return false;\n }\n ch->cb[round] = ts.round(plr->cp[round]);\n *claim = plr->cp[round].eval_lagrange(ch->cb[round], F);\n }\n\n return true;\n }\n\n static bool layer_h(const char** why, Elt* claim, size_t logw,\n const LayerProof* plr, LayerChallenge* ch,\n TranscriptSumcheck& ts, const Field& F) {\n for (size_t round = 0; round < logw; ++round) {\n for (size_t hand = 0; hand < 2; ++hand) {\n // (p(0) + p(1))\n Elt got =\n F.addf(plr->hp[hand][round].t_[0], plr->hp[hand][round].t_[1]);\n if (got != *claim) {\n *why = \"got != claim (round_h)\";\n return false;\n }\n ch->hb[hand][round] = ts.round(plr->hp[hand][round]);\n *claim = plr->hp[hand][round].eval_lagrange(ch->hb[hand][round], F);\n }\n }\n return true;\n }\n\n // Verify CLAIMS for all layers and update CLAIMS in-place. Return\n // TRUE on success, and (FALSE, why) on failure.\n static bool layers(const char** why, claims* cl,\n const Circuit* CIRCUIT, const Proof* PROOF,\n TranscriptSumcheck& ts, Challenge* CH,\n const Field& F) {\n for (size_t ly = 0; ly < CIRCUIT->nl; ++ly) {\n auto clr = &CIRCUIT->l.at(ly);\n auto plr = &PROOF->l[ly];\n auto challenge = &CH->l[ly];\n\n // the claim is then an affine combination of the two\n // inductive claims\n ts.begin_layer(challenge->alpha, challenge->beta, ly);\n Elt claim = F.addf(cl->claim[0], F.mulf(challenge->alpha, cl->claim[1]));\n\n if (!layer_c(why, &claim, CIRCUIT->logc, plr, challenge, ts, F)) {\n return false;\n }\n\n if (!layer_h(why, &claim, clr->logw, plr, challenge, ts, F)) {\n return false;\n }\n\n // Now verify CLAIM = EQ[Q,C] QUAD[R,L] W[R,C] W[L,C]\n // where W[R,C], W[L,C] are in the proof.\n\n // bind QUAD[g|r,l] to the alpha-combination of the\n // two G values GR, GL\n auto QUAD = clr->quad->clone();\n QUAD->bind_g(cl->logv, cl->g[0], cl->g[1], challenge->alpha,\n challenge->beta, F);\n\n // bind QUAD[G|r,l] to R, L\n for (size_t round = 0; round < clr->logw; ++round) {\n for (size_t hand = 0; hand < 2; ++hand) {\n QUAD->bind_h(challenge->hb[hand][round], hand, F);\n }\n }\n\n // got = EQ[Q,C] QUAD[G|R,L] W[R,C] W[L,C], where\n // W[.,C] is in the proof.\n Elt got =\n Eq::eval(CIRCUIT->logc, CIRCUIT->nc, cl->q, challenge->cb, F);\n F.mul(got, QUAD->scalar());\n F.mul(got, plr->wc[0]);\n F.mul(got, plr->wc[1]);\n\n if (got != claim) {\n *why = \"got != claim (layer)\";\n return false;\n }\n\n // Add wc[0,1] to transcript\n ts.write(&plr->wc[0], 1, 2);\n\n // Reduce to two claims on W[R,C] and W[L,C]\n *cl = claims{\n .nv = clr->nw,\n .logv = clr->logw,\n .claim = {plr->wc[0], plr->wc[1]},\n .q = challenge->cb,\n .g = {challenge->hb[0], challenge->hb[1]},\n };\n }\n return true;\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_VERIFIER_LAYERS_H_\n"], ["/longfellow-zk/lib/arrays/sparse.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ARRAYS_SPARSE_H_\n#define PRIVACY_PROOFS_ZK_LIB_ARRAYS_SPARSE_H_\n\n#include \n\n#include \n#include \n#include \n\n#include \"algebra/compare.h\"\n#include \"algebra/poly.h\"\n#include \"arrays/affine.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n// ------------------------------------------------------------\n// Sparse representation of multi-affine functions.\n//\n// This class is mainly used as a reference implementation\n// for testing, and it exposes a similar interface as dense.\n// Sumcheck has its own specialized \"quad\" implementation.\n//\ntemplate \nclass Sparse {\n using Elt = typename Field::Elt;\n using T2 = Poly<2, Field>;\n\n public:\n // A corner on the sparse hypercube, represented as triple of size_t\n // and a value. The 3D representation is kind of a guess of how\n // many bits we'll ever need. Under the theory that \"size_t\" has\n // enough bits to index a dense array that fills the address space,\n // and that the program should support |points| gates, and each gate\n // has three terminals, then a triple ought to be both necessary and\n // sufficient.\n struct corner {\n size_t p0, p1, p2;\n Elt v;\n\n bool eqndx(const corner& y) const {\n return (p2 == y.p2 && p1 == y.p1 && p0 == y.p0);\n }\n bool operator==(const corner& y) const { return eqndx(y) && v == y.v; }\n bool operator!=(const corner& y) const { return !operator==(y); }\n\n static bool compare(const corner& x, const corner& y, const Field& F) {\n if (x.p2 < y.p2) return true;\n if (x.p2 > y.p2) return false;\n if (x.p1 < y.p1) return true;\n if (x.p1 > y.p1) return false;\n if (x.p0 < y.p0) return true;\n if (x.p0 > y.p0) return false;\n return elt_less_than(x.v, y.v, F);\n }\n };\n\n // the index of a point in a sparse array\n using index_t = size_t;\n\n index_t n_;\n std::vector c_;\n\n explicit Sparse(index_t n) : n_(n), c_(n) {}\n\n // no copies, but see clone() below\n Sparse(const Sparse& y) = delete;\n Sparse(const Sparse&& y) = delete;\n Sparse operator=(const Sparse& y) = delete;\n\n // Nobody should need to clone a sparse array except tests.\n // Reflect this fact in the name.\n std::unique_ptr clone_testing_only() const {\n auto s = std::make_unique(n_);\n for (index_t i = 0; i < n_; ++i) {\n s->c_[i] = c_[i];\n }\n return s;\n }\n\n T2 t2_at_corners(index_t* newi, index_t i, const Field& F) const {\n // If c_[i] and c_[i+1] have the same (P2, P1), and they differ\n // by the least-significant bit in P0:\n if (i + 1 < n_ && //\n c_[i].p2 == c_[i + 1].p2 && //\n c_[i].p1 == c_[i + 1].p1 && //\n (c_[i].p0 >> 1) == (c_[i + 1].p0 >> 1) && //\n c_[i + 1].p0 == c_[i].p0 + 1) {\n // we have two corners.\n *newi = i + 2;\n return T2{c_[i].v, c_[i + 1].v};\n } else {\n // we have one corner and the other one is zero.\n *newi = i + 1;\n if ((c_[i].p0 & 1) == 0) {\n return T2{c_[i].v, F.zero()};\n } else {\n return T2{F.zero(), c_[i].v};\n }\n }\n }\n\n // For a given random number r, the binding operation computes\n // v[p2, p1, p0] = (1 - r) * v[p2, p1, 2 * p0] + r * v[p2, p1, 2 * p0 + 1]\n // Note that either the odd or the even element or both may not be actually\n // present in the sparse array.\n void bind(const Elt& r, const Field& F) {\n index_t rd = 0, wr = 0;\n while (rd < n_) {\n index_t newrd;\n T2 f = t2_at_corners(&newrd, rd, F);\n c_[wr] = corner{.p0 = c_[rd].p0 >> 1,\n .p1 = c_[rd].p1,\n .p2 = c_[rd].p2,\n .v = affine_interpolation(r, f.t_[0], f.t_[1], F)};\n wr++;\n rd = newrd;\n }\n\n // shrink the array\n n_ = wr;\n }\n\n void bind_all(size_t logv, const Elt r[/*logv*/], const Field& F) {\n for (size_t v = 0; v < logv; ++v) {\n bind(r[v], F);\n }\n }\n\n void reshape() {\n // this function works only if c_[i].p0 == 0 for all i, but\n // rather than checking them one at the time, keep a giant\n // bitwise OR and check at the end\n size_t lost_bits = 0;\n for (index_t i = 0; i < n_; ++i) {\n lost_bits |= c_[i].p0;\n c_[i] = corner{.p0 = c_[i].p1, .p1 = c_[i].p2, .p2 = 0, .v = c_[i].v};\n }\n check(lost_bits == 0, \"lost_bits == 0\");\n }\n\n // This method can only be called after full binding; the caller\n // is responsible for ensuring that pre-condition.\n Elt scalar() {\n check(n_ == 1, \"n_ == 1\");\n check(c_[0].p0 == 0, \"c_[0].p0_ == 0\");\n check(c_[0].p1 == 0, \"c_[0].p1_ == 0\");\n check(c_[0].p2 == 0, \"c_[0].p2_ == 0\");\n return c_[0].v;\n }\n\n void canonicalize(const Field& F) {\n std::sort(c_.begin(), c_.end(), [&F](const corner& x, const corner& y) {\n return corner::compare(x, y, F);\n });\n return coalesce(F);\n }\n\n private:\n void coalesce(const Field& F) {\n // Coalesce duplicates.\n // The (rd,wr)=(0,0) iteration executes the else{} branch and\n // continues with (1,1), so we start at (1,1) and avoid the\n // special case for wr-1 at wr=0.\n index_t wr = 1;\n for (index_t rd = 1; rd < n_; ++rd) {\n if (c_[rd].eqndx(c_[wr - 1])) {\n F.add(c_[wr - 1].v, c_[rd].v);\n } else {\n c_[wr] = c_[rd];\n wr++;\n }\n }\n n_ = wr;\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ARRAYS_SPARSE_H_\n"], ["/longfellow-zk/lib/algebra/fp2.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP2_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP2_H_\n\n#include \n\n#include \n#include \n\n#include \"util/panic.h\"\n\nnamespace proofs {\n// Fields of the form a+sqrt(r)*b where a, b \\in Fp and\n// r is a quadratic nonresidue in Fp. The special \"complex\"\n// case r = -1 allows for a faster implementation of multiplication.\n//\n// With slight abuse of terminology, we call \"a\" the \"real\" part and\n// \"b\" the \"imaginary\" part, and we call the sqrt(r) \"i\" even when\n// r != -1.\ntemplate \nclass Fp2 {\n public:\n using Scalar = typename Field::Elt;\n using BaseField = Field;\n using TypeTag = typename Field::TypeTag;\n\n // size of the serialization into bytes\n static constexpr size_t kBytes = 2 * Field::kBytes;\n static constexpr size_t kBits = 2 * Field::kBits;\n static constexpr size_t kSubFieldBytes = Field::kBytes;\n static constexpr bool kCharacteristicTwo = false;\n const Field& f_;\n\n struct Elt {\n Scalar re, im;\n bool operator==(const Elt& y) const { return re == y.re && im == y.im; }\n bool operator!=(const Elt& y) const { return !operator==(y); }\n };\n\n explicit Fp2(const Field& F, const Scalar& nonresidue)\n : f_(F), nonresidue_(nonresidue) {\n if (nonresidue_is_mone) {\n check(nonresidue == F.mone(), \"nonresidue == F.mone()\");\n } else {\n check(nonresidue != F.mone(), \"nonresidue != F.mone()\");\n }\n\n i_ = Elt{f_.zero(), f_.one()};\n for (uint64_t i = 0; i < sizeof(k_) / sizeof(k_[0]); ++i) {\n k_[i] = of_scalar(i);\n }\n khalf_ = Elt{f_.half(), f_.zero()};\n kmone_ = Elt{f_.mone(), f_.zero()};\n }\n explicit Fp2(const Field& F) : Fp2(F, F.mone()) {}\n\n Fp2(const Fp2&) = delete;\n Fp2& operator=(const Fp2&) = delete;\n\n const Field& base_field() const { return f_; }\n\n Scalar real(const Elt& e) const { return e.re; }\n bool is_real(const Elt& e) const { return e.im == f_.zero(); }\n\n void add(Elt& a, const Elt& y) const {\n f_.add(a.re, y.re);\n f_.add(a.im, y.im);\n }\n void sub(Elt& a, const Elt& y) const {\n f_.sub(a.re, y.re);\n f_.sub(a.im, y.im);\n }\n void mul(Elt& a, const Elt& y) const {\n auto p0 = f_.mulf(a.re, y.re);\n auto p1 = f_.mulf(a.im, y.im);\n auto a01 = f_.addf(a.re, a.im);\n auto y01 = f_.addf(y.re, y.im);\n if (nonresidue_is_mone) {\n a.re = f_.subf(p0, p1);\n } else {\n a.re = f_.addf(p0, f_.mulf(p1, nonresidue_));\n }\n f_.mul(a01, y01);\n f_.sub(a01, p0);\n f_.sub(a01, p1);\n a.im = a01;\n }\n void mul(Elt& a, const Scalar& y) const {\n f_.mul(a.re, y);\n f_.mul(a.im, y);\n }\n void neg(Elt& x) const {\n Elt y(k_[0]);\n sub(y, x);\n x = y;\n }\n void conj(Elt& x) const { f_.neg(x.im); }\n void invert(Elt& x) const {\n Scalar denom;\n if (nonresidue_is_mone) {\n denom = f_.addf(f_.mulf(x.re, x.re), f_.mulf(x.im, x.im));\n } else {\n denom = f_.subf(f_.mulf(x.re, x.re),\n f_.mulf(nonresidue_, f_.mulf(x.im, x.im)));\n }\n f_.invert(denom);\n conj(x);\n mul(x, denom);\n }\n\n // functional interface\n Elt addf(Elt a, const Elt& y) const {\n add(a, y);\n return a;\n }\n Elt subf(Elt a, const Elt& y) const {\n sub(a, y);\n return a;\n }\n Elt mulf(Elt a, const Elt& y) const {\n mul(a, y);\n return a;\n }\n Elt mulf(Elt a, const Scalar& y) const {\n mul(a, y);\n return a;\n }\n Elt negf(Elt a) const {\n neg(a);\n return a;\n }\n Elt invertf(Elt a) const {\n invert(a);\n return a;\n }\n Elt conjf(Elt a) const {\n conj(a);\n return a;\n }\n\n Elt of_scalar(uint64_t a) const { return of_scalar_field(a); }\n Elt of_scalar(const Scalar& e) const { return of_scalar_field(e); }\n\n Elt of_scalar_field(const Scalar& e) const { return Elt{e, f_.zero()}; }\n Elt of_scalar_field(uint64_t a) const {\n return Elt{f_.of_scalar(a), f_.zero()};\n }\n Elt of_scalar_field(uint64_t ar, uint64_t ai) const {\n return Elt{f_.of_scalar(ar), f_.of_scalar(ai)};\n }\n\n template \n Elt of_string(const char (&s)[N]) const {\n return Elt{f_.of_string(s), f_.zero()};\n }\n\n template \n Elt of_string(const char (&sr)[NR], const char (&si)[NI]) const {\n return Elt{f_.of_string(sr), f_.of_string(si)};\n }\n\n std::optional of_bytes_field(const uint8_t ab[/* kBytes */]) const {\n if (auto re = f_.of_bytes_field(ab)) {\n if (auto im = f_.of_bytes_field(ab + Field::kBytes)) {\n return Elt{re.value(), im.value()};\n }\n }\n return std::nullopt;\n }\n\n void to_bytes_field(uint8_t ab[/* kBytes */], const Elt& x) const {\n f_.to_bytes_field(ab, x.re);\n f_.to_bytes_field(ab + Field::kBytes, x.im);\n }\n\n bool in_subfield(const Elt& e) const { return is_real(e); }\n\n std::optional of_bytes_subfield(\n const uint8_t ab[/* kSubFieldBytes */]) const {\n if (auto re = f_.of_bytes_subfield(ab)) {\n return of_scalar(re.value());\n }\n return std::nullopt;\n }\n\n void to_bytes_subfield(uint8_t ab[/* kSubFieldBytes */], const Elt& x) const {\n check(in_subfield(x), \"x not in subfield\");\n f_.to_bytes_subfield(ab, x.re);\n }\n\n const Elt& zero() const { return k_[0]; }\n const Elt& one() const { return k_[1]; }\n const Elt& two() const { return k_[2]; }\n const Elt& half() const { return khalf_; }\n const Elt& mone() const { return kmone_; }\n const Elt& i() const { return i_; }\n Elt poly_evaluation_point(size_t i) const {\n return of_scalar(f_.poly_evaluation_point(i));\n }\n Elt newton_denominator(size_t k, size_t i) const {\n return of_scalar(f_.newton_denominator(k, i));\n }\n\n private:\n Scalar nonresidue_;\n Elt k_[3]; // small constants\n Elt i_; // i^2 = -1\n Elt khalf_;\n Elt kmone_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP2_H_\n"], ["/longfellow-zk/lib/sumcheck/circuit.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_SUMCHECK_CIRCUIT_H_\n#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_CIRCUIT_H_\n\n#include \n\n#include \n#include \n#include \n\n#include \"algebra/poly.h\"\n#include \"arrays/affine.h\"\n#include \"sumcheck/quad.h\"\n\nnamespace proofs {\ntemplate \nstruct Layer {\n corner_t nw; // number of inputs\n size_t logw; // number of binding rounds for the hand variables\n std::unique_ptr> quad;\n\n bool operator==(const Layer& y) const {\n // This operator relies on the layer being properly constructed, so that\n // the quad reference is never a nullptr.\n return nw == y.nw && logw == y.logw && *quad == *y.quad;\n }\n\n size_t nterms() const { return quad->n_; }\n};\n\ntemplate \nstruct Circuit {\n corner_t nv; // number of outputs for one copy\n size_t logv; // number of G variables in V[G,C] in the final output\n corner_t nc; // number of copies\n size_t logc; // number of sumcheck rounds for the C variables\n size_t nl; // number of layers\n\n size_t ninputs; // number of inputs\n size_t npub_in; // number of public inputs, index of first private input\n size_t subfield_boundary; // Least input wire not known to be in the\n // subfield\n\n std::vector> l; // layers\n\n uint8_t id[32]; // unique id for the circuit, created by the compiler\n\n bool operator==(const Circuit& y) const {\n return nv == y.nv && logv == y.logv && nc == y.nc && logc == y.logc &&\n nl == y.nl && l == y.l;\n }\n size_t nterms() const {\n size_t n = 0;\n for (const auto& layer : l) {\n n += layer.nterms();\n }\n return n;\n }\n};\n\ntemplate \nstruct LayerProof {\n using Elt = typename Field::Elt;\n // For efficiency, we distinguish polynomials needed to bind copy\n // variables (CPoly, degree 3) from polynomials needed to bind\n // wire variables (WPoly, degree 2).\n using CPoly = Poly<4, Field>;\n using WPoly = Poly<3, Field>;\n\n // Maximum 2^40 gates/wires/copies per layer.\n static constexpr size_t kMaxBindings = 40;\n\n CPoly cp[kMaxBindings]; // polys for the C variables\n\n // The binding order we use is \"for (round) { for (hand) ... }\", and\n // thus one can organize this array as [kMaxBindings][2] for better\n // memory locality.\n // However, the corresponding challenges are organized as [2][kMaxBindings]\n // to allow easier binding by hand, and so it makes sense to keep this\n // array in the same order as the challenges.\n WPoly hp[2][kMaxBindings]; // polys for each hand \\in {right,left}\n\n // prover provides W[R,C] and W[L,C], which serve as claims\n // for the next layer\n Elt wc[2];\n};\n\ntemplate \nstruct LayerChallenge {\n using Elt = typename Field::Elt;\n static constexpr size_t kMaxBindings = LayerProof::kMaxBindings;\n\n // verifier: coefficient for the random linear combination\n // claim[0] + alpha * claim[1] of the two input claims.\n Elt alpha;\n Elt beta; // random coefficient for assert-zero\n Elt cb[kMaxBindings]; // bindings for the C variables\n Elt hb[2][kMaxBindings]; // bindings for each hand\n};\n\ntemplate \nstruct Challenge {\n using Elt = typename Field::Elt;\n static constexpr size_t kMaxBindings = LayerProof::kMaxBindings;\n\n // verifier picks Q for EQ[Q|c]\n Elt q[kMaxBindings]; // [logC]\n\n // verifier picks G for V[G,c]\n Elt g[kMaxBindings]; // [logV]\n std::vector> l;\n explicit Challenge(size_t nl) : l(nl) {}\n};\n\n// Full proof:\ntemplate \nstruct Proof {\n typedef typename LayerProof::CPoly CPoly;\n typedef typename LayerProof::WPoly WPoly;\n\n using Elt = typename Field::Elt;\n static constexpr size_t kMaxBindings = LayerProof::kMaxBindings;\n\n // then engage in sumcheck one per layer\n std::vector> l;\n\n explicit Proof(size_t nl) : l(nl) {}\n size_t size() const {\n return l.size() * (kMaxBindings * 4 + kMaxBindings * 3 * 2 + 2);\n }\n};\n\n// Auxiliary information generated by the prover to be\n// used by the ZK prover\ntemplate \nstruct ProofAux {\n using Elt = typename Field::Elt;\n std::vector bound_quad;\n explicit ProofAux(size_t nl) : bound_quad(nl) {}\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_CIRCUIT_H_\n"], ["/longfellow-zk/lib/algebra/convolution.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_CONVOLUTION_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_CONVOLUTION_H_\n\n#include \n\n#include \n#include \n#include \n\n#include \"algebra/blas.h\"\n#include \"algebra/fft.h\"\n#include \"algebra/rfft.h\"\n\n/*\nAll of the classes in this package compute convolutions.\nThat is, given inputs arrays of field elements x, y, with |x|=n, |y|=m,\nthese methods compute the first m entries of\n\n z[k] = \\sum_{i=0}^{n-1} x[i] y[k-i]\n\nSlowConvolution uses an O(n*m) method for testing validation.\n\nFFTConvolution and FFTExtConvolution first pad y to length n and use advanced\nFFT algorithms to compute the same in O(nlogn) time.\n\nThe const Field& objects that are passed have lifetimes that exceed the call\ndurations and can be safely passed by const reference.\n*/\n\nnamespace proofs {\n\n// Returns the smallest power of 2 that is at least n.\nstatic size_t choose_padding(const size_t n) {\n size_t p = 1;\n while (p < n) {\n p *= 2;\n }\n return p;\n}\n\ntemplate \nclass FFTConvolution {\n using Elt = typename Field::Elt;\n\n public:\n FFTConvolution(size_t n, size_t m, const Field& f, const Elt omega,\n uint64_t omega_order, const Elt y[/*m*/])\n : f_(f),\n omega_(omega),\n omega_order_(omega_order),\n n_(n),\n m_(m),\n padding_(choose_padding(m)),\n y_fft_(padding_, f_.zero()) {\n Blas::copy(m, &y_fft_[0], 1, y, 1);\n FFT::fftf(&y_fft_[0], padding_, omega_, omega_order_, f_);\n\n // Pre-scale Y by 1/N to compensate for the scaling in FFTB(FFTF(.))\n Blas::scale(padding_, &y_fft_[0], 1,\n f_.invertf(f_.of_scalar(padding_)), f_);\n }\n\n // Computes (first m entries of) convolution of x with y, outputs in z:\n // z[k] = \\sum_{i=0}^{n-1} x[i] y[k-i].\n // Note that y has already been FFT'd and divided by padding_ in constructor\n void convolution(const Elt x[/*n_*/], Elt z[/*m_*/]) const {\n std::vector x_fft(padding_, f_.zero());\n Blas::copy(n_, &x_fft[0], 1, x, 1);\n FFT::fftf(&x_fft[0], padding_, omega_, omega_order_, f_);\n // Pointwise multiplication.\n for (size_t i = 0; i < padding_; ++i) {\n f_.mul(x_fft[i], y_fft_[i]);\n }\n // Backward fft.\n FFT::fftb(&x_fft[0], padding_, omega_, omega_order_, f_);\n Blas::copy(m_, z, 1, &x_fft[0], 1);\n }\n\n private:\n const Field& f_;\n const Elt omega_;\n const uint64_t omega_order_;\n\n // n is the number of points input\n size_t n_;\n size_t m_; // total number of points output (points in + new points out)\n size_t padding_;\n\n // fft(y[i]) / padding\n // padded with zeroes to the next power of 2 at least m.\n std::vector y_fft_;\n};\n\ntemplate \nclass FFTConvolutionFactory {\n using Elt = typename Field::Elt;\n\n public:\n using Convolver = FFTConvolution;\n FFTConvolutionFactory(const Field& f, const Elt omega, uint64_t omega_order)\n : f_(f), omega_(omega), omega_order_(omega_order) {}\n\n std::unique_ptr make(size_t n, size_t m,\n const Elt y[/*m*/]) const {\n return std::make_unique(n, m, f_, omega_, omega_order_, y);\n }\n\n private:\n const Field& f_;\n const Elt omega_;\n const uint64_t omega_order_;\n};\n\ntemplate \nclass FFTExtConvolution {\n using Elt = typename Field::Elt;\n using EltExt = typename FieldExt::Elt;\n\n public:\n FFTExtConvolution(size_t n, size_t m, const Field& f, const FieldExt& f_ext,\n const EltExt omega, uint64_t omega_order,\n const Elt y[/*m*/])\n : f_(f),\n f_ext_(f_ext),\n omega_(omega),\n omega_order_(omega_order),\n n_(n),\n m_(m),\n padding_(choose_padding(m)),\n y_fft_(padding_, f_.zero()) {\n Blas::copy(m, &y_fft_[0], 1, y, 1);\n RFFT::r2hc(&y_fft_[0], padding_, omega_, omega_order_, f_ext_);\n\n // Pre-scale Y by 1/N to compensate for the scaling in HC2R(R2HC(.))\n Blas::scale(padding_, &y_fft_[0], 1,\n f_.invertf(f_.of_scalar(padding_)), f_);\n }\n\n // Computes (first m entries of) convolution of x with y, stores in z:\n // z[k] = \\sum_{i=0}^{n-1} x[i] y[k-i].\n // Note that y has already been FFT'd and divided by padding_ in constructor\n void convolution(const Elt x[/*n_*/], Elt z[/*m_*/]) const {\n std::vector x_fft(padding_, f_.zero());\n Blas::copy(n_, &x_fft[0], 1, x, 1);\n RFFT::r2hc(&x_fft[0], padding_, omega_, omega_order_, f_ext_);\n\n // Pointwise multiplication\n {\n size_t i;\n f_.mul(x_fft[0], y_fft_[0]); // DC is real\n for (i = 1; i + i < padding_; ++i) {\n RFFT::cmul(&x_fft[i], &x_fft[padding_ - i], x_fft[i],\n x_fft[padding_ - i], y_fft_[i],\n y_fft_[padding_ - i], f_);\n }\n f_.mul(x_fft[i], y_fft_[i]); // Nyquist is real\n }\n\n // Backward FFT.\n RFFT::hc2r(&x_fft[0], padding_, omega_, omega_order_, f_ext_);\n Blas::copy(m_, z, 1, &x_fft[0], 1);\n }\n\n private:\n const Field& f_;\n const FieldExt& f_ext_;\n const EltExt omega_;\n const uint64_t omega_order_;\n\n // n is the number of points input in x\n size_t n_;\n size_t m_; // total number of points output in convolution\n size_t padding_;\n\n // fft(y[i]) / padding\n // padded with zeroes to the next power of 2 at least m.\n std::vector y_fft_;\n};\n\ntemplate \nclass FFTExtConvolutionFactory {\n using Elt = typename Field::Elt;\n using EltExt = typename FieldExt::Elt;\n\n public:\n using Convolver = FFTExtConvolution;\n\n FFTExtConvolutionFactory(const Field& f, const FieldExt& f_ext,\n const EltExt omega, uint64_t omega_order)\n : f_(f), f_ext_(f_ext), omega_(omega), omega_order_(omega_order) {}\n\n std::unique_ptr make(size_t n, size_t m,\n const Elt y[/*m*/]) const {\n return std::make_unique(n, m, f_, f_ext_, omega_,\n omega_order_, y);\n }\n\n private:\n const Field& f_;\n const FieldExt& f_ext_;\n const EltExt omega_;\n const uint64_t omega_order_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_CONVOLUTION_H_\n"], ["/longfellow-zk/lib/circuits/cbor_parser/scan.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_SCAN_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_SCAN_H_\n\n#include \n\n#include \n\nnamespace proofs {\ntemplate \nclass Scan {\n public:\n using EltW = typename Logic::EltW;\n using BitW = typename Logic::BitW;\n\n explicit Scan(const Logic& l) : l_(l) {}\n\n /* Segmented prefix add, equivalent to this code:\n\n s = 0;\n for (size_t i = 0; i < n; ++i) {\n if (S[i]) {\n s = A[i];\n } else {\n s += ds[i];\n }\n B[i] = s;\n }\n */\n void add(size_t n, EltW B[/*n*/], const BitW S[/*n*/], const EltW A[/*n*/],\n const EltW ds[/*n*/]) {\n const Logic& L = l_; // shorthand\n std::vector S1(n);\n for (size_t i = 0; i < n; ++i) {\n S1[i] = S[i];\n B[i] = L.mux(&S[i], &A[i], ds[i]);\n }\n scan_add(0, n, S1.data(), B);\n }\n\n // unsegmented variant of add(), assume S[i] = false\n void add(size_t n, EltW B[/*n*/], const EltW ds[/*n*/]) {\n for (size_t i = 0; i < n; ++i) {\n B[i] = ds[i];\n }\n scan_add(0, n, B);\n }\n\n private:\n const Logic& l_;\n\n void scan_add(size_t i0, size_t i1, BitW S[/*n*/], EltW B[/*n*/]) {\n if (i1 - i0 > 1) {\n const Logic& L = l_; // shorthand\n size_t im = i0 + (i1 - i0) / 2;\n scan_add(i0, im, S, B);\n scan_add(im, i1, S, B);\n\n size_t j = im - 1;\n for (size_t i = im; i < i1; ++i) {\n // special case of B[i] = S[i] ? B[i] : B[i] + B[j]\n // coded as B[i] = B[i] + (~S[i] * B[j])\n auto ns = L.lnot(S[i]);\n auto ns_bj = L.lmul(&ns, B[j]);\n B[i] = L.add(&B[i], ns_bj);\n S[i] = L.lor(&S[i], S[j]);\n }\n }\n }\n\n // unsegmented\n void scan_add(size_t i0, size_t i1, EltW B[/*n*/]) {\n if (i1 - i0 > 1) {\n const Logic& L = l_; // shorthand\n size_t im = i0 + (i1 - i0) / 2;\n scan_add(i0, im, B);\n scan_add(im, i1, B);\n\n size_t j = im - 1;\n for (size_t i = im; i < i1; ++i) {\n B[i] = L.add(&B[j], B[i]);\n }\n }\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_SCAN_H_\n"], ["/longfellow-zk/lib/circuits/compiler/pdqhash.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_PDQHASH_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_PDQHASH_H_\n\n#include \n#include \n\n#include \n#include \n\n#define DEFINE_STRONG_INT_TYPE(a, b) using a = b\n\nnamespace proofs {\n\n// Old-school, quick and dirty hash table specialized for\n// uint64_t key, value_t value. Support multiple keys\n// (\"multimap\").\n//\n// This is supposed to solve the same problem as the C++\n// unordered_multimap, except that the unordered_multimap\n// stores key/value as a linked list and leaves the malloc()\n// arena so fragmented that malloc_coalesce() takes several\n// hundred ms to reconstruct the heap.\nclass PdqHash {\n public:\n // value of NIL denotes empty slot\n using value_t = uint32_t;\n static const constexpr value_t kNil = ~static_cast(0);\n\n // Store the key as uint32_t to save space. This is ok because\n // \"key\" is not really a key. Instead, find() invokes pred() which\n // compares against the full key (stored outside this class).\n DEFINE_STRONG_INT_TYPE(stored_key_t, uint32_t);\n\n static stored_key_t narrow(uint64_t k) { return stored_key_t(k + (k >> 32)); }\n\n struct kv {\n stored_key_t k;\n value_t v;\n\n kv() : k(stored_key_t(0)), v(kNil) {}\n };\n\n PdqHash() : bits_(10), sz_(0), table_(capacity()) {}\n\n void insert(uint64_t k64, value_t v) {\n if (2 * sz_ > capacity()) {\n rehash();\n }\n insert0(narrow(k64), v);\n }\n\n size_t find(uint64_t k64, const std::function &pred) {\n stored_key_t k = narrow(k64);\n size_t mask = (size_t(1) << bits_) - 1;\n size_t dh = dhash(k);\n for (size_t h = hash(k);; h += dh) {\n const kv *p = &table_[h & mask];\n if (p->v == kNil) {\n // not found\n return kNil;\n }\n if (p->k == k && pred(p->v)) {\n // found\n return p->v;\n }\n }\n }\n\n private:\n void insert0(stored_key_t k, value_t v) {\n size_t mask = (size_t(1) << bits_) - 1;\n size_t dh = dhash(k);\n for (size_t h = hash(k);; h += dh) {\n kv *p = &table_[h & mask];\n if (p->v == kNil) {\n p->k = k;\n p->v = v;\n ++sz_;\n return;\n }\n }\n }\n\n // Adhoc hash function suffices for this application.\n uint64_t hash(uint64_t k) {\n return k + 3 * (k >> bits_) + 7 * (k >> (2 * bits_));\n }\n uint64_t hash(stored_key_t nk) { return hash(static_cast(nk)); }\n uint64_t dhash(stored_key_t nk) {\n // If gcd(dhash, capacity()) == 1, the insert loop does not have a short\n // cycle.\n return 2 * hash(hash(nk)) + 1;\n }\n void rehash() {\n ++bits_;\n std::vector table1(capacity());\n table_.swap(table1);\n for (const auto &p : table1) {\n if (p.v != kNil) {\n insert0(p.k, p.v);\n }\n }\n }\n\n size_t capacity() { return size_t(1) << bits_; }\n\n size_t bits_;\n size_t sz_;\n std::vector table_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_PDQHASH_H_\n"], ["/longfellow-zk/lib/algebra/rfft.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_RFFT_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_RFFT_H_\n\n#include \n#include \n\n#include \"algebra/permutations.h\"\n#include \"algebra/twiddle.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n\n// Real FFT and its inverse.\n//\n// The FFT F[j] of a real input R[k] is complex and\n// conjugate-symmetric: F[j] = conj(F[n - j]).\n//\n// Following the FFTW conventions, to avoid doubling the\n// storage, we store F[j] as a \"half-complex\" array HC[j] of elements\n// in the base field.\n//\n// HC[j] = (2j <= n) ? real(F[j]) : imag(F[n - j])\n//\n// Thus we have two kinds of transforms: R2HC (real to\n// half-complex) and HC2R (half-complex to real).\n//\n// Again following the FFTW conventions, we say that\n// the R2HC transform is \"forward\" (minus sign in the exponent)\n// and the HC2R sign is \"backward\" (plus sign in the exponent).\n// See fft.h for a definition of forward and backward.\n\ntemplate \nclass RFFT {\n using Field = typename FieldExt::BaseField;\n using RElt = typename Field::Elt;\n using CElt = typename FieldExt::Elt;\n\n // The machinery in this file only works if the root is\n // on the unit circle, because we multiply by the conjugate\n // instead of by the inverse.\n static void validate_root(const CElt& omega, const FieldExt& C) {\n check(C.mulf(omega, C.conjf(omega)) == C.one(),\n \"root of unity not on the unit circle\");\n }\n\n static void r2hcI(RElt* A, size_t s, const Field& R) {\n RElt t = A[s];\n A[s] = A[0];\n R.add(A[0], t);\n R.sub(A[s], t);\n }\n static void r2hcII(RElt* A, size_t s, const CElt& tw, const Field& R) {\n R.mul(A[s], R.negf(tw.im));\n }\n\n static void hc2hcf(RElt* Ar, RElt* Ai, size_t s, const CElt& tw,\n const Field& R) {\n RElt xr, xi;\n cmulj(&xr, &xi, Ar[s], Ai[s], tw.re, tw.im, R);\n RElt ar0 = Ar[0];\n RElt ai0 = Ai[0];\n Ar[0] = R.addf(ar0, xr);\n Ai[0] = R.subf(ar0, xr);\n Ar[s] = R.subf(xi, ai0);\n Ai[s] = R.addf(xi, ai0);\n }\n\n static void hc2rI(RElt* A, size_t s, const Field& R) {\n RElt t = A[s];\n A[s] = A[0];\n R.add(A[0], t);\n R.sub(A[s], t);\n }\n\n static void hc2rIII(RElt* A, size_t s, const CElt& tw, const Field& R) {\n R.add(A[0], A[0]);\n R.add(A[s], A[s]);\n R.mul(A[s], R.negf(tw.im));\n }\n\n static void hc2hcb(RElt* Ar, RElt* Ai, size_t s, const CElt& tw,\n const Field& R) {\n RElt ar0 = Ar[0];\n RElt ai0 = Ai[0];\n RElt ar1 = Ar[s];\n RElt ai1 = Ai[s];\n Ar[0] = R.addf(ar0, ai0);\n Ai[0] = R.subf(ai1, ar1);\n RElt xr = R.subf(ar0, ai0);\n RElt xi = R.addf(ai1, ar1);\n cmul(&Ar[s], &Ai[s], xr, xi, tw.re, tw.im, R);\n }\n\n public:\n // Forward real to half-complex in-place transform.\n // N (the length of A) must be a power of 2\n static void r2hc(RElt A[/*n*/], size_t n, const CElt& omega,\n uint64_t omega_order, const FieldExt& C) {\n validate_root(omega, C);\n\n if (n <= 1) {\n return;\n }\n\n const Field& R = C.base_field();\n CElt omega_n = Twiddle::reroot(omega, omega_order, n, C);\n Twiddle roots(n, omega_n, C);\n\n Permutations::bitrev(A, n);\n\n // m=1 iteration\n for (size_t k = 0; k < n; k += 2) {\n r2hcI(&A[k], 1, R);\n }\n\n // m>1 iterations\n for (size_t m = 2; m < n; m = 2 * m) {\n size_t ws = n / (2 * m);\n for (size_t k = 0; k < n; k += 2 * m) {\n size_t j;\n r2hcI(&A[k], m, R); // j==0\n\n for (j = 1; j + j < m; ++j) {\n hc2hcf(&A[k + j], &A[k + m - j], m, roots.w_[j * ws], R);\n }\n\n r2hcII(&A[k + j], m, roots.w_[j * ws], R); // j==m/2\n }\n }\n }\n\n // Backward half-complex to real in-place transform.\n static void hc2r(RElt A[/*n*/], size_t n, const CElt& omega,\n uint64_t omega_order, const FieldExt& C) {\n validate_root(omega, C);\n\n if (n <= 1) {\n return;\n }\n\n const Field& R = C.base_field();\n CElt omega_n = Twiddle::reroot(omega, omega_order, n, C);\n Twiddle roots(n, omega_n, C);\n\n // m>1 iterations\n for (size_t m = n; (m /= 2) >= 2;) {\n size_t ws = n / (2 * m);\n for (size_t k = 0; k < n; k += 2 * m) {\n size_t j;\n hc2rI(&A[k], m, R); // j==0\n\n for (j = 1; j + j < m; ++j) {\n hc2hcb(&A[k + j], &A[k + m - j], m, roots.w_[j * ws], R);\n }\n\n hc2rIII(&A[k + j], m, roots.w_[j * ws], R); // j==m/2\n }\n }\n\n // m=1 iteration\n for (size_t k = 0; k < n; k += 2) {\n hc2rI(&A[k], 1, R);\n }\n\n Permutations::bitrev(A, n);\n }\n\n // X = A * B\n static void cmul(RElt* xr, RElt* xi, const RElt& ar, const RElt& ai,\n const RElt& br, const RElt& bi, const Field& R) {\n // Karatsuba 3 mul + 5 add\n auto p0 = R.mulf(ar, br);\n auto p1 = R.mulf(ai, bi);\n auto a01 = R.addf(ar, ai);\n auto b01 = R.addf(br, bi);\n *xr = R.subf(p0, p1);\n R.mul(a01, b01);\n R.sub(a01, p0);\n R.sub(a01, p1);\n *xi = a01;\n }\n\n // X = A * conj(B)\n static void cmulj(RElt* xr, RElt* xi, const RElt& ar, const RElt& ai,\n const RElt& br, const RElt& bi, const Field& R) {\n // Karatsuba 3 mul + 5 add\n auto p0 = R.mulf(ar, br);\n auto p1 = R.mulf(ai, bi);\n auto a01 = R.addf(ar, ai);\n auto b01 = R.subf(br, bi);\n *xr = R.addf(p0, p1);\n R.mul(a01, b01);\n R.sub(a01, p0);\n R.add(a01, p1);\n *xi = a01;\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_RFFT_H_\n"], ["/longfellow-zk/lib/circuits/logic/compiler_backend.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_COMPILER_BACKEND_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_COMPILER_BACKEND_H_\n\n#include \n\n#include \n\n#include \"circuits/compiler/compiler.h\"\n\nnamespace proofs {\n// backend that compiles a circuit that, when evaluated, computes Elt's\ntemplate \nclass CompilerBackend {\n using QuadCircuitF = QuadCircuit;\n using Elt = typename Field::Elt;\n\n public:\n using V = size_t;\n\n explicit CompilerBackend(QuadCircuitF* q) : q_(q) {}\n\n V assert0(const V& a) const { return q_->assert0(a); }\n V add(const V& a, const V& b) const { return q_->add(a, b); }\n V sub(const V& a, const V& b) const {\n auto mb = mul(konst(q_->f_.mone()), b);\n return add(a, mb);\n }\n V mul(const V& a, const V& b) const { return q_->mul(a, b); }\n V mul(const Elt& a, const V& b) const { return q_->mul(a, b); }\n V mul(const Elt& a, const V& b, const V& c) const { return q_->mul(a, b, c); }\n V konst(const Elt& a) const { return q_->konst(a); }\n\n V ax(const Elt& a, const V& x) const { return q_->mul(a, x); }\n V axy(const Elt& a, const V& x, const V& y) const { return q_->mul(a, x, y); }\n V axpy(const V& y, const Elt& a, const V& x) const {\n return q_->axpy(y, a, x);\n }\n V apy(const V& y, const Elt& a) const { return q_->apy(y, a); }\n\n V input() const { return q_->input(); }\n void output(size_t n, V wire_id) const { q_->output(n, wire_id); }\n size_t wire_id(const V& a) const { return q_->wire_id(a); }\n\n private:\n QuadCircuitF* q_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_COMPILER_BACKEND_H_\n"], ["/longfellow-zk/lib/algebra/limb.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_LIMB_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_LIMB_H_\n\n#include \n#include \n#include \n\n#include \"util/serialization.h\"\n\nnamespace proofs {\n\n// Base class for representing bignum or bigpoly as arrays of\n// machine-dependent \"limbs\". The serialization is in this\n// class; arithmetic is in subclasses.\n\ntemplate \nclass Limb {\n public:\n using T = Limb;\n\n#if __WORDSIZE == 64\n using limb_t = uint64_t;\n#else\n using limb_t = uint32_t;\n#endif\n\n // sizes in bytes, bits, limbs, uint64_t\n static constexpr size_t kBytes = 8 * W64;\n static constexpr size_t kBits = 64 * W64;\n static constexpr size_t kLimbs = kBytes / sizeof(limb_t);\n static constexpr size_t kU64 = W64;\n static constexpr size_t kBitsPerLimb = 8 * sizeof(limb_t);\n\n // no rounding allowed\n static_assert(kLimbs * sizeof(limb_t) == kBytes);\n\n limb_t limb_[kLimbs];\n\n Limb() = default; // uninitialized\n explicit Limb(uint64_t x) : limb_{} { assign(limb_, 1, &x); }\n\n explicit Limb(const std::array& a) : limb_{} {\n assign(limb_, kU64, &a[0]);\n }\n\n std::array u64() const {\n std::array a;\n unassign(limb_, kU64, &a[0]);\n return a;\n }\n\n void to_bytes(uint8_t a[/* kBytes */]) const {\n for (size_t i = 0; i < kLimbs; ++i) {\n a = to_bytes(&limb_[i], a);\n }\n }\n\n bool operator==(const T& other) const {\n for (size_t i = 0; i < kLimbs; ++i) {\n if (limb_[i] != other.limb_[i]) {\n return false;\n }\n }\n return true;\n }\n bool operator!=(const T& other) const { return !(operator==(other)); }\n\n // Shift right by z. Return the bits that fall off\n // the edge.\n limb_t shiftr(size_t z) {\n limb_t c = 0;\n for (size_t i = kLimbs; i-- > 0;) {\n limb_t d = limb_[i];\n limb_[i] = c | (d >> z);\n c = d << (kBitsPerLimb - z);\n }\n return c;\n }\n\n // Returns the pos-th bit in the representation of this nat.\n limb_t bit(size_t pos) const {\n size_t ind = pos / kBitsPerLimb;\n if (ind < kLimbs) {\n size_t off = pos % kBitsPerLimb;\n return (limb_[ind] >> off) & 0x1u;\n }\n return 0;\n }\n\n protected:\n static void assign(uint64_t d[], size_t ns, const uint64_t s[/*ns*/]) {\n for (size_t i = 0; i < ns; ++i) {\n d[i] = s[i];\n }\n }\n\n static void assign(uint32_t d[], size_t ns, const uint64_t s[/*ns*/]) {\n for (size_t i = 0; i < ns; ++i) {\n d[2 * i] = static_cast(s[i]);\n d[2 * i + 1] = static_cast(s[i] >> 32);\n }\n }\n\n static void unassign(const uint64_t d[], size_t ns, uint64_t s[/*ns*/]) {\n for (size_t i = 0; i < ns; ++i) {\n s[i] = d[i];\n }\n }\n\n static void unassign(const uint32_t d[], size_t ns, uint64_t s[/*ns*/]) {\n for (size_t i = 0; i < ns; ++i) {\n s[i] = d[2 * i] | (static_cast(d[2 * i + 1]) << 32);\n }\n }\n\n static const uint8_t* of_bytes(uint64_t* r, const uint8_t* a) {\n *r = u64_of_le(a);\n return a + 8;\n }\n static const uint8_t* of_bytes(uint32_t* r, const uint8_t* a) {\n *r = u32_of_le(a);\n return a + 4;\n }\n\n static uint8_t* to_bytes(const uint64_t* r, uint8_t* a) {\n u64_to_le(a, *r);\n return a + 8;\n }\n static uint8_t* to_bytes(const uint32_t* r, uint8_t* a) {\n u32_to_le(a, *r);\n return a + 4;\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_LIMB_H_\n"], ["/longfellow-zk/lib/arrays/eqs.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ARRAYS_EQS_H_\n#define PRIVACY_PROOFS_ZK_LIB_ARRAYS_EQS_H_\n\n#include \n\n#include \n\n#include \"algebra/blas.h\"\n#include \"arrays/affine.h\"\n#include \"arrays/dense.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n\n// Stateful implementation of EQ[I, j] which, for fixed\n// I, holds an array indexed by j.\ntemplate \nclass Eqs : public Dense {\n using Elt = typename Field::Elt;\n using Dense::v_;\n using Dense::n0_;\n\n public:\n Eqs(size_t logn, corner_t n, const Elt I[/*logn*/], const Field& F)\n : Dense(n, 1) {\n filleq(&v_[0], logn, n, I, F);\n }\n\n corner_t n() const { return n0_; }\n\n // Optimization for a special case: return a raw vector EQ[G0|.] + alpha *\n // EQ[G1|.] Return std::vector<> because we don't need the full\n // dense<> machinery.\n static std::vector raw_eq2(size_t logn, corner_t n, const Elt* G0,\n const Elt* G1, const Elt& alpha,\n const Field& F) {\n std::vector eq0(n);\n std::vector eq1(n);\n filleq(&eq0[0], logn, n, G0, F);\n filleq(&eq1[0], logn, n, G1, F);\n Blas::axpy(n, &eq0[0], 1, alpha, &eq1[0], 1, F);\n return eq0;\n }\n\n private:\n // Return ceil(a / 2^{n}) for a != 0.\n //\n // Several ways exist to compute ceil(a/b) given a primitive that\n // computes floor(a/b), such as the C++ unsigned division operator.\n // The simplest one is floor((a+(b-1))/b), which potentally overflows.\n // Another way is 1+floor((a-1)/b), which underflows for a==0 but\n // otherwise does not overflow. More complicated ways exist that neither\n // overflow nor underflow. Since the rest of the code assumes\n // a!=0 anyway, we use the 1+floor((a-1)/b) version.\n static corner_t ceilshr(corner_t a, size_t n) { return 1u + ((a - 1u) >> n); }\n\n // Compute the array EQ[Q, i] for all 0<=i 0, \"n > 0\");\n eq[0] = F.one();\n for (size_t l = logn; l-- > 0;) {\n corner_t nl = ceilshr(n, l);\n corner_t i = ceilshr(nl, 1);\n\n // Special case for the first iteration of the i-loop\n // below: don't compute eq[2*i+1] (post decrement) if it\n // would overflow the array.\n if (/*2*(i-1)+1 = */ 2 * i - 1 >= nl) {\n i--;\n Elt v = eq[i], qv = Q[l];\n F.mul(qv, v);\n eq[2 * i] = v;\n F.sub(eq[2 * i], qv);\n }\n while (i-- > 0) {\n // Assign\n // eq[2*i] = (1-Q[l])*eq[i]\n // eq[2*i+1] = Q[l]*eq[i]\n // with one multiplication.\n Elt v = eq[i], qv = Q[l];\n F.mul(qv, v);\n eq[2 * i] = v;\n F.sub(eq[2 * i], qv);\n eq[2 * i + 1] = qv;\n }\n }\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ARRAYS_EQS_H_\n"], ["/longfellow-zk/lib/circuits/compiler/circuit_id.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_CIRCUIT_ID_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_CIRCUIT_ID_H_\n\n#include \n\n#include \n\n#include \"circuits/compiler/circuit_id.h\"\n#include \"sumcheck/circuit.h\"\n#include \"util/crypto.h\"\n\nnamespace proofs {\n\n// This method produces a unique name for a circuit. It does not match\n// the serialization method for the circuit.\ntemplate \nvoid circuit_id(uint8_t id[/*32*/], const Circuit& c, const Field& F) {\n const uint64_t CHAR2 = 0x2;\n const uint64_t ODD = 0x1;\n SHA256 sha;\n uint8_t tmp[Field::kBytes];\n if (F.kCharacteristicTwo) {\n // Characteristic two fields are uniquely determined by their length\n // in our codebase.\n sha.Update8(CHAR2); // Indicates binary field.\n sha.Update8(F.kBits);\n } else {\n // Prime fields are determined by -1.\n sha.Update8(ODD); // Indicates odd prime field.\n F.to_bytes_field(tmp, F.mone());\n sha.Update(tmp, sizeof(tmp));\n }\n sha.Update8(c.nv);\n sha.Update8(c.logv);\n sha.Update8(c.nc);\n sha.Update8(c.logc);\n sha.Update8(c.nl);\n sha.Update8(c.ninputs);\n sha.Update8(c.npub_in);\n sha.Update8(c.subfield_boundary);\n for (const auto& layer : c.l) {\n sha.Update8(layer.nw);\n sha.Update8(layer.logw);\n sha.Update8(layer.quad->n_);\n for (size_t i = 0; i < layer.quad->n_; ++i) {\n sha.Update8(static_cast(layer.quad->c_[i].g));\n sha.Update8(static_cast(layer.quad->c_[i].h[0]));\n sha.Update8(static_cast(layer.quad->c_[i].h[1]));\n F.to_bytes_field(tmp, layer.quad->c_[i].v);\n sha.Update(tmp, sizeof(tmp));\n }\n }\n sha.DigestData(id);\n}\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_CIRCUIT_ID_H_\n"], ["/longfellow-zk/lib/algebra/fft_interpolation.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FFT_INTERPOLATION_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FFT_INTERPOLATION_H_\n\n#include \n#include \n\n#include \n\n#include \"algebra/blas.h\"\n#include \"algebra/twiddle.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\ntemplate \nclass FFTInterpolation {\n using Elt = typename Field::Elt;\n\n // Know a0, a1 want b0, b1\n // Note winv = w^{-1}\n static void a0a1(const Elt* A, Elt* B, size_t s, const Elt& winv,\n const Field& F) {\n Elt x0 = A[0];\n Elt x1 = F.mulf(A[s], winv);\n B[0] = F.addf(x0, x1);\n B[s] = F.subf(x0, x1);\n }\n\n static void a0a1(const Elt* A, Elt* B, size_t s, const Field& F) {\n Elt x0 = A[0];\n Elt x1 = A[s];\n B[0] = F.addf(x0, x1);\n B[s] = F.subf(x0, x1);\n }\n\n // know b0, b1 want a0, a1\n static void b0b1(Elt* A, const Elt* B, size_t s, const Elt& w,\n const Field& F) {\n Elt x0 = F.mulf(F.half(), F.addf(B[0], B[s]));\n Elt x1 = F.mulf(F.half(), F.subf(B[0], B[s]));\n A[0] = x0;\n A[s] = F.mulf(x1, w);\n }\n\n static void b0b1_unscaled(Elt* A, const Elt* B, size_t s, const Elt& w,\n const Field& F) {\n Elt x0 = F.addf(B[0], B[s]);\n Elt x1 = F.subf(B[0], B[s]);\n A[0] = x0;\n A[s] = F.mulf(x1, w);\n }\n static void b0b1_unscaled(Elt* A, const Elt* B, size_t s, const Field& F) {\n Elt x0 = F.addf(B[0], B[s]);\n Elt x1 = F.subf(B[0], B[s]);\n A[0] = x0;\n A[s] = x1;\n }\n\n // know: a0 and b0, want a1 and b1\n // x0 = a0\n // x1 = a1 * w^{-1}\n // b0 = x0 + x1\n // b1 = x0 - x1\n static void a0b0(Elt* A, Elt* B, size_t s, const Elt& w, const Field& F) {\n Elt x0 = A[0];\n Elt x1 = F.subf(B[0], x0);\n A[s] = F.mulf(x1, w);\n B[s] = F.subf(x0, x1);\n }\n\n // know: a0 and b1, want a1 and b0\n // x0 = a0\n // x1 = a1 * w^{-1}\n // b0 = x0 + x1\n // b1 = x0 - x1\n static void a0b1(Elt* A, Elt* B, size_t s, const Elt& w, const Field& F) {\n Elt x0 = A[0];\n Elt x1 = F.subf(x0, B[s]);\n A[s] = F.mulf(x1, w);\n B[0] = F.addf(x0, x1);\n }\n\n // B -> A\n static void fftb(Elt A[/*n*/], const Elt B[/*n*/], size_t n,\n const Twiddle& roots, const Field& F) {\n for (size_t j = 0; j < n; ++j) {\n A[j] = B[j];\n }\n\n Elt scale = F.one();\n\n for (size_t m = n; m > 2;) {\n m /= 2;\n size_t ws = roots.order_ / (2 * m);\n for (size_t k = 0; k < n; k += 2 * m) {\n b0b1_unscaled(&A[k], &A[k], m, F); // j == 0\n for (size_t j = 1; j < m; ++j) {\n b0b1_unscaled(&A[k + j], &A[k + j], m, roots.w_[j * ws], F);\n }\n }\n F.mul(scale, F.half());\n }\n\n if (n >= 2) {\n for (size_t k = 0; k < n; k += 2) {\n b0b1_unscaled(&A[k], &A[k], 1, F);\n }\n F.mul(scale, F.half());\n }\n\n Blas::scale(n, A, 1, scale, F);\n }\n\n // A -> B\n static void fftf(const Elt A[/*n*/], Elt B[/*n*/], size_t n,\n const Twiddle& rootsinv, const Field& F) {\n for (size_t j = 0; j < n; ++j) {\n B[j] = A[j];\n }\n\n // m = 1\n if (n >= 2) {\n for (size_t k = 0; k < n; k += 2) {\n a0a1(&B[k], &B[k], 1, F);\n }\n }\n\n // m > 1\n for (size_t m = 2; m < n; m = 2 * m) {\n size_t ws = rootsinv.order_ / (2 * m);\n for (size_t k = 0; k < n; k += 2 * m) {\n a0a1(&B[k], &B[k], m, F); // j = 0\n for (size_t j = 1; j < m; ++j) {\n a0a1(&B[k + j], &B[k + j], m, rootsinv.w_[j * ws], F);\n }\n }\n }\n }\n\n static bool in_range(size_t j, size_t b0, size_t n, size_t k) {\n size_t b1 = b0 + (n - k);\n return (b0 <= j && j < b1) || (b0 <= j + n && j + n < b1);\n }\n\n // This is a generalization of the truncated FFT algorithm described\n // in Joris van der Hoeven, \"The Truncated Fourier Transform and\n // Applications\". See also the followup paper \"Notes on the\n // Truncated Fourier Transform\", also by Joris van der Hoeven.\n\n // Define arbitrarily an \"evaluation\" domain A and a \"coefficient\"\n // domain B. The \"forward\" FFT computes the cofficients B given\n // evaluations A, and the \"backward\" FFT computes the evaluations A\n // given the coefficients B. By convention, the evaluations A are in\n // bit-reversed order, and we put the 1/N normalization on\n // the backward side.\n\n // Given inputs\n //\n // A[j] for 0 <= j < k\n // B[j % n] for b0 <= j < b0 + (n - k)\n //\n // this function fills the rest of A[] and B[], so that at the\n // end B = fftf(A) and A = fftb(B).\n static void bidir(size_t n, Elt A[/*n*/], Elt B[/*n*/], size_t k, size_t b0,\n const Twiddle& roots, const Twiddle& rootsinv,\n Elt workspace[/*2*n*/], const Field& F) {\n check(k <= n, \"k <= n\");\n check(b0 < n, \"b0 < n\");\n\n if (k == 0) {\n fftb(A, B, n, roots, F);\n } else if (k == n) {\n fftf(A, B, n, rootsinv, F);\n } else if (n > 1) {\n size_t ws = roots.order_ / n;\n size_t n2 = n / 2;\n\n // allocate T from workspace\n Elt* T = workspace;\n workspace += n;\n\n if (k >= n2) {\n // first half A -> T\n fftf(A, &T[0], n2, rootsinv, F);\n\n // diagonal butterflies T <-> B\n for (size_t j = 0; j < n2; ++j) {\n if (in_range(j, b0, n, k)) {\n if (in_range(j + n2, b0, n, k)) {\n // can't happen because the range is < n2\n check(false, \"can't happen\");\n } else {\n a0b0(&T[j], &B[j], n2, roots.w_[j * ws], F);\n }\n } else {\n if (in_range(j + n2, b0, n, k)) {\n a0b1(&T[j], &B[j], n2, roots.w_[j * ws], F);\n } else {\n // done below\n }\n }\n }\n\n // second half A <-> T\n size_t bb0 = (b0 >= n2) ? (b0 - n2) : b0;\n bidir(n2, &A[n2], &T[n2], k - n2, bb0, roots, rootsinv, workspace, F);\n\n // forward butterflies T -> B\n for (size_t j = 0; j < n2; ++j) {\n if (in_range(j, b0, n, k)) {\n if (in_range(j + n2, b0, n, k)) {\n // can't happen because the range is < n2\n check(false, \"can't happen\");\n } else {\n // done above\n }\n } else {\n if (in_range(j + n2, b0, n, k)) {\n // done above\n } else {\n a0a1(&T[j], &B[j], n2, rootsinv.w_[j * ws], F);\n }\n }\n }\n } else {\n // backward butterflies B -> T\n for (size_t j = 0; j < n2; ++j) {\n if (in_range(j, b0, n, k)) {\n if (in_range(j + n2, b0, n, k)) {\n b0b1(&T[j], &B[j], n2, roots.w_[j * ws], F);\n } else {\n // done below\n }\n } else {\n // done below\n }\n }\n\n // first half A <-> T\n size_t bb0 = (b0 >= n2) ? (b0 - n2) : b0;\n bidir(n2, &A[0], &T[0], k, bb0, roots, rootsinv, workspace, F);\n\n // diagonal butterflies T <-> B\n for (size_t j = 0; j < n2; ++j) {\n if (in_range(j, b0, n, k)) {\n if (in_range(j + n2, b0, n, k)) {\n // done above\n } else {\n a0b0(&T[j], &B[j], n2, roots.w_[j * ws], F);\n }\n } else {\n if (in_range(j + n2, b0, n, k)) {\n a0b1(&T[j], &B[j], n2, roots.w_[j * ws], F);\n } else {\n // can't happen. Range is >= n2 so\n // either j or j+n2 is in range\n check(false, \"can't happen\");\n }\n }\n }\n\n // second half T -> A\n fftb(&A[n2], &T[n2], n2, roots, F);\n }\n }\n }\n\n public:\n static void interpolate(size_t n, Elt A[/*n*/], Elt B[/*n*/], size_t k,\n size_t b0, const Elt& omega_m, uint64_t m,\n const Field& F) {\n if (n > 1) {\n Elt omega_n = Twiddle::reroot(omega_m, m, n, F);\n Twiddle roots(n, omega_n, F);\n Twiddle rootsinv(n, F.invertf(omega_n), F);\n std::vector workspace(2 * n);\n bidir(n, A, B, k, b0, roots, rootsinv, &workspace[0], F);\n } else if (n == 1) {\n // Twiddle(n) fails because of vector of size 0.\n // Compute the answer directly.\n if (k == 0) {\n A[0] = B[0];\n } else {\n B[0] = A[0];\n }\n }\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FFT_INTERPOLATION_H_\n"], ["/longfellow-zk/lib/ligero/ligero_verifier.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_VERIFIER_H_\n#define PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_VERIFIER_H_\n\n#include \n\n#include \n#include \n\n#include \"algebra/blas.h\"\n#include \"ligero/ligero_param.h\"\n#include \"ligero/ligero_transcript.h\"\n#include \"merkle/merkle_commitment.h\"\n#include \"random/transcript.h\"\n#include \"util/crypto.h\"\n\nnamespace proofs {\ntemplate \nclass LigeroVerifier {\n using Elt = typename Field::Elt;\n\n public:\n static void receive_commitment(const LigeroCommitment& commitment,\n Transcript& ts) {\n // P -> V\n LigeroTranscript::write_commitment(commitment, ts);\n }\n\n static bool verify(const char** why, const LigeroParam& p,\n const LigeroCommitment& commitment,\n const LigeroProof& proof, Transcript& ts, size_t nl,\n size_t nllterm,\n const LigeroLinearConstraint llterm[/*nllterm*/],\n const LigeroHash& hash_of_llterm, const Elt b[/*nl*/],\n const LigeroQuadraticConstraint lqc[/*nq*/],\n const InterpolatorFactory& interpolator, const Field& F) {\n if (why == nullptr) {\n return false;\n }\n\n std::vector u_ldt(p.nwqrow);\n std::vector alphal(nl);\n std::vector> alphaq(p.nq);\n std::vector u_quad(p.nqtriples);\n std::vector idx(p.nreq);\n\n // Replay the protocol first in order to compute all the\n // challenges. In particular, we need IDX before we can do\n // anything useful.\n\n // P -> V\n ts.write(hash_of_llterm.bytes, hash_of_llterm.kLength);\n\n // V -> P\n LigeroTranscript::gen_uldt(&u_ldt[0], p, ts, F);\n\n // V -> P\n LigeroTranscript::gen_alphal(nl, &alphal[0], ts, F);\n LigeroTranscript::gen_alphaq(&alphaq[0], p, ts, F);\n\n // V -> P\n LigeroTranscript::gen_uquad(&u_quad[0], p, ts, F);\n\n // P -> V\n ts.write(&proof.y_ldt[0], 1, p.block, F);\n ts.write(&proof.y_dot[0], 1, p.dblock, F);\n ts.write(&proof.y_quad_0[0], 1, p.r, F);\n ts.write(&proof.y_quad_2[0], 1, p.dblock - p.block, F);\n\n // V -> P\n LigeroTranscript::gen_idx(&idx[0], p, ts, F);\n\n if (!merkle_check(p, commitment, proof, &idx[0], F)) {\n *why = \"merkle_check failed\";\n return false;\n }\n\n if (!low_degree_check(p, proof, &idx[0], &u_ldt[0], interpolator, F)) {\n *why = \"low_degree_check failed\";\n return false;\n }\n\n {\n // linear check\n std::vector A(p.nwqrow * p.w);\n\n LigeroCommon::inner_product_vector(&A[0], p, nl, nllterm, llterm,\n &alphal[0], lqc, &alphaq[0], F);\n\n if (!dot_check(p, proof, &idx[0], &A[0], interpolator, F)) {\n *why = \"dot_check failed\";\n return false;\n }\n\n // check the putative value of the inner product\n Elt want_dot = Blas::dot(nl, b, 1, &alphal[0], 1, F);\n Elt proof_dot = Blas::dot1(p.w, &proof.y_dot[p.r], 1, F);\n if (want_dot != proof_dot) {\n *why = \"wrong dot product\";\n return false;\n }\n }\n\n if (!quadratic_check(p, proof, &idx[0], &u_quad[0], interpolator, F)) {\n *why = \"quadratic_check failed\";\n return false;\n }\n\n *why = \"ok\";\n return true;\n }\n\n private:\n static void interpolate_req_columns(Elt yp[/*nreq*/],\n const LigeroParam& p, size_t ylen,\n const Elt y[/*ylen*/],\n const size_t idx[/*nreq*/],\n const InterpolatorFactory& interpolator,\n const Field& F) {\n const auto interpy = interpolator.make(ylen, p.block_enc);\n std::vector yext(p.block_enc);\n Blas::copy(ylen, &yext[0], 1, y, 1);\n interpy->interpolate(&yext[0]);\n Blas::gather(p.nreq, &yp[0], &yext[p.dblock], idx);\n }\n\n static bool merkle_check(const LigeroParam& p,\n const LigeroCommitment& commitment,\n const LigeroProof& proof,\n const size_t idx[/*nreq*/], const Field& F) {\n auto updhash = [&](size_t r, SHA256& sha) {\n LigeroCommon::column_hash(p.nrow, &proof.req_at(0, r), p.nreq, sha,\n F);\n };\n\n return MerkleCommitmentVerifier::verify(p.block_enc - p.dblock,\n commitment.root, proof.merkle, idx,\n p.nreq, updhash);\n }\n\n static bool low_degree_check(const LigeroParam& p,\n const LigeroProof& proof,\n const size_t idx[/*nreq*/],\n const Elt u_ldt[/*nrow*/],\n const InterpolatorFactory& interpolator,\n const Field& F) {\n std::vector yc(p.nreq);\n\n // the ILDT blinding row with coefficient 1\n Blas::copy(p.nreq, &yc[0], 1, &proof.req_at(p.ildt, 0), 1);\n\n // all remaining rows with coefficient u_ldt[]\n for (size_t i = 0; i < p.nwqrow; ++i) {\n Blas::axpy(p.nreq, &yc[0], 1, u_ldt[i], &proof.req_at(i + p.iw, 0),\n 1, F);\n }\n\n std::vector yp(p.nreq);\n interpolate_req_columns(&yp[0], p, p.block, &proof.y_ldt[0], idx,\n interpolator, F);\n\n if (!Blas::equal(p.nreq, &yp[0], 1, &yc[0], 1, F)) {\n return false;\n }\n\n return true;\n }\n\n static bool dot_check(const LigeroParam& p,\n const LigeroProof& proof,\n const size_t idx[/*nreq*/], const Elt A[/*nwqrow, w*/],\n const InterpolatorFactory& interpolator,\n const Field& F) {\n std::vector yc(p.nreq);\n\n // the IDOT blinding row with coefficient 1\n Blas::copy(p.nreq, &yc[0], 1, &proof.req_at(p.idot, 0), 1);\n\n {\n const auto interpA = interpolator.make(p.block, p.block_enc);\n\n std::vector Aext(p.block_enc);\n std::vector Areq(p.nreq);\n\n for (size_t i = 0; i < p.nwqrow; ++i) {\n LigeroCommon::layout_Aext(&Aext[0], p, i, &A[0], F);\n interpA->interpolate(&Aext[0]);\n Blas::gather(p.nreq, &Areq[0], &Aext[p.dblock], idx);\n\n // Accumulate z += A[j] \\otimes W[j].\n Blas::vaxpy(p.nreq, &yc[0], 1, &Areq[0], 1,\n &proof.req_at(i + p.iw, 0), 1, F);\n }\n }\n\n std::vector yp(p.nreq);\n interpolate_req_columns(&yp[0], p, p.dblock, &proof.y_dot[0], idx,\n interpolator, F);\n\n if (!Blas::equal(p.nreq, &yp[0], 1, &yc[0], 1, F)) {\n return false;\n }\n return true;\n }\n\n static bool quadratic_check(const LigeroParam& p,\n const LigeroProof& proof,\n const size_t idx[/*nreq*/],\n const Elt u_quad[/*nqtriples*/],\n const InterpolatorFactory& interpolator,\n const Field& F) {\n std::vector yc(p.nreq);\n\n // the IQUAD blinding row with coefficient 1\n Blas::copy(p.nreq, &yc[0], 1, &proof.req_at(p.iquad, 0), 1);\n\n {\n std::vector tmp(p.nreq);\n size_t iqx = p.iq;\n size_t iqy = iqx + p.nqtriples;\n size_t iqz = iqy + p.nqtriples;\n\n // all quadratic triples with coefficient u_ldt[]\n for (size_t i = 0; i < p.nqtriples; ++i) {\n // yc += u_quad[i] * (z[i] - x[i] * y[i])\n\n // tmp = z[i]\n Blas::copy(p.nreq, &tmp[0], 1, &proof.req_at(iqz + i, 0), 1);\n\n // tmp -= x[i] \\otimes y[i]\n Blas::vymax(p.nreq, &tmp[0], 1, &proof.req_at(iqx + i, 0), 1,\n &proof.req_at(iqy + i, 0), 1, F);\n\n // yc += u_quad[i] * tmp\n Blas::axpy(p.nreq, &yc[0], 1, u_quad[i], &tmp[0], 1, F);\n }\n }\n\n // reconstruct y_quad from the two parts in the proof\n std::vector yquad(p.dblock);\n Blas::copy(p.r, &yquad[0], 1, &proof.y_quad_0[0], 1);\n Blas::clear(p.w, &yquad[p.r], 1, F);\n Blas::copy(p.dblock - p.block, &yquad[p.block], 1,\n &proof.y_quad_2[0], 1);\n\n // interpolate y_quad at the opened columns\n std::vector yp(p.nreq);\n interpolate_req_columns(&yp[0], p, p.dblock, &yquad[0], idx, interpolator,\n F);\n\n if (!Blas::equal(p.nreq, &yp[0], 1, &yc[0], 1, F)) {\n return false;\n }\n return true;\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_VERIFIER_H_\n"], ["/longfellow-zk/lib/gf2k/lch14_reed_solomon.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_GF2K_LCH14_REED_SOLOMON_H_\n#define PRIVACY_PROOFS_ZK_LIB_GF2K_LCH14_REED_SOLOMON_H_\n\n#include \n\n#include \n#include \n#include \n\n#include \"gf2k/lch14.h\"\n\nnamespace proofs {\n\ntemplate \nclass LCH14ReedSolomon {\n using Elt = typename Field::Elt;\n\n // only works in binary fields\n static_assert(Field::kCharacteristicTwo);\n\n public:\n // We interpolate N points, assumed to be the evaluations at\n // F.of_scalar(i), 0 <= i < N, of a polynomial of degree C(fftn);\n\n // compute the \"coefficients\" under the assumption\n // that we know n_ evaluations and that the higher-order\n // (fftn - n_) \"coefficients\" are zero.\n for (size_t i = 0; i < n_; ++i) {\n C[i] = y[i];\n }\n for (size_t i = n_; i < fftn; ++i) {\n C[i] = f_.zero();\n }\n fft_.BidirectionalFFT(l, /*k=*/n_, &C[0]);\n\n // fill in the missing evaluations in the first coset, since we\n // already have the missing evaluations in C[[n_, (1< fft_;\n};\n\ntemplate \nclass LCH14ReedSolomonFactory {\n public:\n explicit LCH14ReedSolomonFactory(const Field& f) : f_(f) {}\n\n std::unique_ptr> make(size_t n, size_t m) const {\n return std::make_unique>(n, m, f_);\n }\n\n private:\n const Field& f_;\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_GF2K_LCH14_REED_SOLOMON_H_\n"], ["/longfellow-zk/lib/circuits/logic/polynomial.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_POLYNOMIAL_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_POLYNOMIAL_H_\n\n#include \n\n#include \n\n#include \"algebra/poly.h\"\n#include \"util/ceildiv.h\"\n\nnamespace proofs {\ntemplate \nclass Polynomial {\n public:\n using Field = typename Logic::Field;\n using BitW = typename Logic::BitW;\n using EltW = typename Logic::EltW;\n const Logic& l_;\n\n explicit Polynomial(const Logic& l) : l_(l) {}\n\n void powers_of_x(size_t n, EltW xi[/*n*/], const EltW& x) const {\n const Logic& L = l_; // shorthand\n\n if (n > 0) {\n xi[0] = L.konst(1);\n if (n > 1) {\n xi[1] = x;\n // invariant: xi[i] = x**i for i < k.\n // Extend inductively to k = n.\n for (size_t k = 2; k < n; ++k) {\n xi[k] = L.mul(&xi[k - k / 2], xi[k / 2]);\n }\n }\n }\n }\n\n // Evaluation via dot product with coefficients\n template \n EltW eval(const Poly& coef, const EltW& x) const {\n const Logic& L = l_; // shorthand\n\n std::array xi;\n powers_of_x(N, xi.data(), x);\n\n // dot product with coefficients\n EltW r = L.konst(0);\n for (size_t i = 0; i < N; ++i) {\n auto cxi = L.mul(coef[i], xi[i]);\n r = L.add(&r, cxi);\n }\n return r;\n }\n\n // Evaluation via parallel Horner's rule\n template \n EltW eval_horner(const Poly& coef, EltW x) const {\n const Logic& L = l_; // shorthand\n\n std::array c;\n for (size_t i = 0; i < N; ++i) {\n c[i] = L.konst(coef[i]);\n }\n\n for (size_t n = N; n > 1; n = ceildiv(n, 2)) {\n for (size_t i = 0; 2 * i < n; ++i) {\n c[i] = c[2 * i];\n if (2 * i + 1 < n) {\n auto cxi = L.mul(&x, c[2 * i + 1]);\n c[i] = L.add(&c[i], cxi);\n }\n }\n x = L.mul(&x, x);\n }\n return c[0];\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_POLYNOMIAL_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_1f_io.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_1F_IO_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_1F_IO_H_\n\n#include \n\n#include \"circuits/mdoc/mdoc_constants.h\"\n\nnamespace proofs {\n\nstatic constexpr size_t kMdoc1DateLen = 20; // Length of CBOR-formatted time.\nstatic constexpr size_t kMdoc1MaxSHABlocks = 7;\nstatic constexpr size_t kMdoc1CborIndexBits = 9;\nstatic constexpr size_t kMdoc1MaxMsoLen =\n kMdoc1MaxSHABlocks * 64 - 9 - kCose1PrefixLen;\nstatic constexpr size_t kMdoc1SHAPluckerBits = 3;\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_1F_IO_H_\n"], ["/longfellow-zk/lib/algebra/reed_solomon.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_REED_SOLOMON_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_REED_SOLOMON_H_\n\n#include \n\n#include \n#include \n\n#include \"algebra/utility.h\"\n\nnamespace proofs {\n\n/*\nThe ReedSolomon class interpolates a polynomial given as input in point-eval\nform at a set of different points, thereby computing a form of RS encoding.\nSpecifically, the input polynomial of degree d=n-1 is given as evaluations\nat 0, 1, 2, ..., n-1, and the output is the values at n, n+1, n+2, ..., n+m-1.\nThe algorithm uses the following relation:\n\n p(k) = (-1)^d (k-d)(k choose d) sum_{j=0}^{d} (1/k-j)(-1)^j (d choose j)p(j)\n\nwhich can be efficiently computed using a convolution, whose implementation\nis provided by a ConvolutionFactory for the field.\n\nThe const Field& objects that are passed have lifetimes that exceed the call\ndurations and can be safely passed by const reference.\n\n*/\ntemplate \nclass ReedSolomon {\n using Elt = typename Field::Elt;\n using Convolver = typename ConvolutionFactory::Convolver;\n\n public:\n // n is the number of points provided\n // m is the total number of points output (including the initial n points)\n ReedSolomon(size_t n, size_t m, const Field& F,\n const ConvolutionFactory& factory)\n : f_(F), // could grab this from the factory\n degree_bound_(n - 1),\n m_(m),\n leading_constant_(m - n + 1),\n binom_i_(n) {\n // inverses[i]: inverses[i] = 1/i from i = 1 to m-1 (inverses[0] = 0)\n std::vector inverses(m_);\n AlgebraUtil::batch_inverse_arithmetic(m, &inverses[0], F);\n c_ = factory.make(n, m, &inverses[0]);\n leading_constant_[0] = F.one();\n binom_i_[0] = F.one();\n // Set leading_constant_[i] = (i+degree_bound_) choose degree_bound_\n // (from i=0 to i=m)\n for (size_t i = 1; i + degree_bound_ < m; ++i) {\n leading_constant_[i] =\n F.mulf(leading_constant_[i - 1],\n F.mulf(F.of_scalar(degree_bound_ + i), inverses[i]));\n }\n // Finish computing the leading constants:\n // (-1)^degree_bound_ (k-degree_bound_) \\binom{k}{degree_bound_}\n for (size_t k = degree_bound_; k < m; ++k) {\n F.mul(leading_constant_[k - degree_bound_],\n F.of_scalar(k - degree_bound_));\n if (degree_bound_ % 2 == 1) {\n F.neg(leading_constant_[k - degree_bound_]);\n }\n }\n\n for (size_t i = 1; i < n; ++i) {\n binom_i_[i] =\n F.mulf(binom_i_[i - 1], F.mulf(F.of_scalar(n - i), inverses[i]));\n }\n for (size_t i = 1; i < n; i += 2) {\n F.neg(binom_i_[i]);\n }\n }\n\n // Given the values of a polynomial of degree at most n at 0, 1, 2, ..., n-1,\n // this computes the values at n, n+1, n+2, ..., m-1.\n // (n points go in, m points come out)\n void interpolate(Elt y[/*m*/]) const {\n // shorthands\n const Field& F = f_;\n size_t n = degree_bound_ + 1; // number of points input\n\n // Define x[i] = (-1)^i \\binom{n}{i} p(i) for i=0 through i=n\n std::vector x(n);\n for (size_t i = 0; i < n; i++) {\n x[i] = F.mulf(binom_i_[i], y[i]);\n }\n\n std::vector T(m_);\n c_->convolution(&x[0], &T[0]);\n // Multiply the leading constants by the convolution\n for (size_t i = n; i < m_; ++i) {\n y[i] = F.mulf(leading_constant_[i - degree_bound_], T[i]);\n }\n }\n\n private:\n const Field& f_;\n\n // n is the number of points input, and degree_bound = n + 1.\n // degree_bound_ is useful since the LaTeX math is written in terms of it\n const size_t degree_bound_; // degree bound, i.e., n - 1\n // total number of points output (points in + new points out)\n const size_t m_;\n\n std::unique_ptr c_;\n\n // leading_constant_[i] = \\binom{i+degree_bound_}{degree_bound_} *\n // (-1)^{degree_bound_} (i+degree_bound_ - degree_bound_) (from i=0 to i=m-n)\n // i.e., the leading constant \\binom{k}{degree_bound_} *\n // (-1)^degree_bound_ (k - degree_bound_), shifted left by degree_bound_\n std::vector leading_constant_;\n // (-1)^i (degree_bound_ choose i) from i=0 to i=degree_bound_\n std::vector binom_i_;\n};\n\ntemplate \nclass ReedSolomonFactory {\n public:\n ReedSolomonFactory(const ConvolutionFactory& factory, const Field& f)\n : factory_(factory), f_(f) {}\n\n std::unique_ptr> make(size_t n,\n size_t m) const {\n return std::make_unique>(n, m, f_,\n factory_);\n }\n\n private:\n const ConvolutionFactory& factory_;\n const Field& f_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_REED_SOLOMON_H_\n"], ["/longfellow-zk/lib/circuits/compiler/node.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_NODE_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_NODE_H_\n\n#include \n#include \n\n#include \n#include \n\n#include \"sumcheck/quad.h\"\n#include \"util/crc64.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n\nstruct term {\n // size_t surrogate for storing things like depth and\n // pointers to nodes, since we only really need 32 bits.\n using size_t_for_storage = uint32_t;\n\n size_t_for_storage ki; // index of the constant term into constants_[]\n size_t_for_storage op0, op1;\n\n term() = default;\n\n // canonicalized by op0 <= op1\n explicit term(size_t ki, size_t op0, size_t op1)\n : ki(ki),\n op0(std::min(op0, op1)),\n op1(std::max(op0, op1)) {\n // Terms with k=0 are not supposed to occur, since\n // we represent a zero node as an empty list of terms.\n // We represent Elt(0) as index ki=0 in the table of constants.\n proofs::check(ki != 0, \"ki != 0\");\n }\n\n // special hack for assert0\n struct assert0_type_hack {}; // so that we don't call this constructor\n // accidentally\n explicit term(size_t op, assert0_type_hack& hack)\n : ki(/*kstore(f.zero())=*/0), op0(0), op1(op) {}\n\n bool ltndx(const term& y) const {\n if (op1 < y.op1) return true;\n if (op1 > y.op1) return false;\n return op0 < y.op0;\n }\n bool eqndx(const term& y) const { return (op1 == y.op1 && op0 == y.op0); }\n\n // term is a constant\n bool constant() const { return op0 == 0 && op1 == 0; }\n\n // linear term k * (1 * op1)\n bool linearp() const { return op0 == 0; }\n\n bool operator==(const term& y) const {\n return ki == y.ki && op0 == y.op0 && op1 == y.op1;\n }\n};\n\ntemplate \nstruct NodeInfoF {\n using quad_corner_t = typename Quad::quad_corner_t;\n using size_t_for_storage = term::size_t_for_storage;\n\n static const constexpr quad_corner_t kWireIdUndefined = quad_corner_t(-1);\n\n size_t_for_storage depth;\n quad_corner_t desired_wire_id_for_input;\n quad_corner_t desired_wire_id_for_output;\n size_t_for_storage max_needed_depth;\n bool is_needed;\n bool is_output;\n bool is_input;\n bool is_assert0;\n\n NodeInfoF()\n : depth(0),\n desired_wire_id_for_input(kWireIdUndefined),\n desired_wire_id_for_output(kWireIdUndefined),\n max_needed_depth(0),\n is_needed(false),\n is_output(false),\n is_input(false),\n is_assert0(false) {}\n\n // we use the desired wire id only at the appropriate depth,\n // and not e.g. for copy wires.\n quad_corner_t desired_wire_id(size_t depth0, size_t depth_ub) const {\n if (is_input && depth0 == 0) {\n return desired_wire_id_for_input;\n }\n if (is_output && depth0 + 1 == depth_ub) {\n return desired_wire_id_for_output;\n }\n return kWireIdUndefined;\n }\n};\n\ntemplate \nstruct NodeF {\n using nodeinfo = NodeInfoF;\n using quad_corner_t = typename Quad::quad_corner_t;\n\n std::vector terms;\n nodeinfo info;\n\n NodeF() = delete;\n explicit NodeF(quad_corner_t id) : terms() {\n info.is_input = true;\n info.desired_wire_id_for_input = id;\n }\n\n explicit NodeF(size_t ki, size_t op0, size_t op1) : terms() {\n if (ki != 0) {\n terms.push_back(term(ki, op0, op1));\n }\n }\n\n explicit NodeF(const std::vector& terms) : terms(terms) {}\n\n bool zero() const { return !info.is_input && terms.empty(); }\n bool constant() const { return terms.size() == 1 && terms[0].constant(); }\n bool linearp() const { return terms.size() == 1 && terms[0].linearp(); }\n\n bool operator==(const NodeF& y) const {\n if (info.is_input != y.info.is_input) return false;\n if (info.desired_wire_id_for_input != y.info.desired_wire_id_for_input)\n return false;\n if (info.is_output != y.info.is_output) return false;\n if (info.desired_wire_id_for_output != y.info.desired_wire_id_for_output)\n return false;\n if (info.is_input != y.info.is_input) return false;\n if (terms.size() != y.terms.size()) return false;\n size_t l = terms.size();\n for (size_t i = 0; i < l; ++i) {\n if (!(terms[i] == y.terms[i])) return false;\n }\n return true;\n }\n uint64_t hash() const {\n uint64_t crc = 0x1;\n crc = crc64::update(crc,\n static_cast(info.desired_wire_id_for_input));\n crc = crc64::update(crc,\n static_cast(info.desired_wire_id_for_output));\n crc = crc64::update(crc, info.is_input);\n crc = crc64::update(crc, info.is_output);\n size_t l = terms.size();\n crc = crc64::update(crc, l);\n for (size_t i = 0; i < l; ++i) {\n crc = crc64::update(crc, terms[i].ki);\n crc = crc64::update(crc, terms[i].op0);\n crc = crc64::update(crc, terms[i].op1);\n }\n return crc;\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_NODE_H_\n"], ["/longfellow-zk/lib/util/crypto.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_UTIL_CRYPTO_H_\n#define PRIVACY_PROOFS_ZK_LIB_UTIL_CRYPTO_H_\n\n// Encapsulates all of the cryptographic primitives used by this library.\n// Specifically, for the collision-resistant hash function, this library uses\n// SHA256. For a pseudo-random function, this library uses AES in ECB mode.\n// Finally, this library provides a method to generate random bytes using the\n// openssl library.\n\n#include \n#include \n#include \n\n#include \"util/panic.h\"\n#include \"openssl/sha.h\"\n#include \"openssl/evp.h\"\n#include \"openssl/aes.h\"\n\nnamespace proofs {\n\nconstexpr size_t kSHA256DigestSize = 32;\nconstexpr size_t kPRFKeySize = 32;\nconstexpr size_t kPRFInputSize = 16;\nconstexpr size_t kPRFOutputSize = 16;\n\nclass SHA256 {\n public:\n SHA256() { SHA256_Init(&sha_); }\n\n // Disable copy for good measure.\n SHA256(const SHA256&) = delete;\n SHA256& operator=(const SHA256&) = delete;\n\n void Update(const uint8_t bytes[/*n*/], size_t n) { SHA256_Update(&sha_, bytes, n); }\n void DigestData(uint8_t digest[/* kSHA256DigestSize */]) {\n SHA256_Final(digest, &sha_);\n }\n void CopyState(const SHA256& src) { sha_ = src.sha_; }\n\n void Update8(uint64_t x) {\n uint8_t buf[8];\n for (size_t i = 0; i < 8; ++i) {\n buf[i] = x & 0xff;\n x >>= 8;\n }\n Update(buf, 8);\n }\n\n private:\n SHA256_CTX sha_;\n};\n\n// A pseudo-random function interface. This implementation uses AES in ECB mode.\n// The caller must ensure that arguments are not reused.\nclass PRF {\n public:\n explicit PRF(const uint8_t key[/*kPRFKeySize*/]) {\n ctx_ = EVP_CIPHER_CTX_new();\n int ret =\n EVP_EncryptInit_ex(ctx_, EVP_aes_256_ecb(), nullptr, key, nullptr);\n check(ret == 1, \"EVP_EncryptInit_ex failed\");\n }\n\n ~PRF() { EVP_CIPHER_CTX_free(ctx_); }\n\n // Disable copy for good measure.\n PRF(const PRF&) = delete;\n PRF& operator=(const PRF&) = delete;\n\n // Evaluate the PRF on the input and write the output to the output buffer.\n // This method should only be used internally by the Transcript class. The\n // caller must ensure that the input and output buffers are different.\n // This function implements a permutation, but we only need to exploit its\n // pseudo-random function property in this application.\n void Eval(uint8_t out[/*kPRFOutputSize*/], uint8_t in[/*kPRFInputSize*/]) {\n int out_len = static_cast(kPRFOutputSize);\n int ret = EVP_EncryptUpdate(ctx_, out, &out_len, in,\n static_cast(kPRFInputSize));\n check(ret == 1, \"EVP_EncryptUpdate failed\");\n }\n\n private:\n EVP_CIPHER_CTX* ctx_;\n};\n\n// Generate n random bytes, following the openssl API convention.\n// This method will panic if the openssl library fails.\nvoid rand_bytes(uint8_t out[/*n*/], size_t n);\n\nvoid hex_to_str(char out[/* 2*n + 1*/], const uint8_t in[/*n*/], size_t n);\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_UTIL_CRYPTO_H_\n"], ["/longfellow-zk/lib/algebra/fft.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FFT_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FFT_H_\n\n#include \n#include \n\n#include \"algebra/permutations.h\"\n#include \"algebra/twiddle.h\"\n\nnamespace proofs {\n/*\nFast Fourier Transform (FFT).\n\nWe use FFTPACK/FFTW/MATLAB conventions where the FFT\nhas a negative sign in the exponent. For root of unity\nW, input (\"time\") T and output (\"frequency\") F, the\n\"forward\" FFT computes\n\n F[k] = SUM_{j} T[j] W^{-jk}\n\nand the \"backward\" fft computes\n\n T[j] = SUM_{k} F[k] W^{jk}\n\nA forward transform followed by a backward transform\nmultiplies the array by N.\n\nMatlab and engineers call the forward transform the FFT.\nMathematicians tend to call the backward transform the FFT.\n*/\ntemplate \nclass FFT {\n using Elt = typename Field::Elt;\n\n static void butterfly(Elt* A, size_t s, const Field& F) {\n Elt t = A[s];\n A[s] = A[0];\n F.add(A[0], t);\n F.sub(A[s], t);\n }\n\n static void butterflytw(Elt* A, size_t s, const Elt& twiddle,\n const Field& F) {\n Elt t = A[s];\n F.mul(t, twiddle);\n A[s] = A[0];\n F.add(A[0], t);\n F.sub(A[s], t);\n }\n\n public:\n // Backward FFT.\n // N (the length of A) must be a power of 2\n static void fftb(Elt A[/*n*/], size_t n, const Elt& omega,\n uint64_t omega_order, const Field& F) {\n if (n <= 1) {\n return;\n }\n\n Elt omega_n = Twiddle::reroot(omega, omega_order, n, F);\n Twiddle roots(n, omega_n, F);\n\n Permutations::bitrev(A, n);\n\n // m=1 iteration\n for (size_t k = 0; k < n; k += 2) {\n butterfly(&A[k], 1, F);\n }\n\n // m>1 iterations\n for (size_t m = 2; m < n; m = 2 * m) {\n size_t ws = n / (2 * m);\n for (size_t k = 0; k < n; k += 2 * m) {\n butterfly(&A[k], m, F); // j==0\n for (size_t j = 1; j < m; ++j) {\n butterflytw(&A[k + j], m, roots.w_[j * ws], F);\n }\n }\n }\n }\n\n // forward transform\n static void fftf(Elt A[/*n*/], size_t n, const Elt& omega,\n uint64_t omega_order, const Field& F) {\n fftb(A, n, F.invertf(omega), omega_order, F);\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FFT_H_\n"], ["/longfellow-zk/lib/merkle/merkle_tree.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_MERKLE_MERKLE_TREE_H_\n#define PRIVACY_PROOFS_ZK_LIB_MERKLE_MERKLE_TREE_H_\n\n#include \n#include \n\n#include \n#include \n\n#include \"util/crypto.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n\n// This package computes and verifies Merkle Tree inclusion claims.\n// The standard Merkle tree algorithm has been implemented.\n\n// A digest of a Merkle tree.\nstruct Digest {\n static constexpr size_t kLength = kSHA256DigestSize;\n uint8_t data[kLength];\n\n bool operator==(const Digest& y) const {\n return memcmp(data, y.data, kLength) == 0;\n }\n\n static Digest hash2(const Digest& L, const Digest& R) {\n SHA256 sha;\n sha.Update(L.data, kLength);\n sha.Update(R.data, kLength);\n Digest output;\n sha.DigestData(output.data);\n return output;\n }\n};\n\n// Return the length of the proof for N leaves.\n// Mimic the code in generate_proof() without actually\n// computing the proof\ninline size_t merkle_tree_len(size_t n) {\n size_t r = 1;\n size_t pos = (n - 1); // maximum possible value\n for (pos += n; pos > 1; pos >>= 1) {\n ++r;\n }\n return r;\n}\n\n// compute the set of all nodes on the path from the\n// root to any leaf in POS.\ninline std::vector compressed_merkle_proof_tree(size_t n,\n const size_t pos[/*np*/],\n size_t np) {\n check(np > 0, \"A Merkle proof with 0 leaves is not defined.\");\n std::vector tree(2 * n, false);\n\n // leaves are in TREE\n for (size_t ip = 0; ip < np; ++ip) {\n check(pos[ip] < n, \"Invalid position for leaf in Merkle tree\");\n tree[pos[ip] + n] = true;\n }\n\n // If a child of an inner node is in TREE, then the parent is in TREE.\n for (size_t i = n; i-- > 1;) {\n tree[i] = (tree[2 * i] || tree[2 * i + 1]);\n }\n\n // Assert that the root is in TREE.\n check(tree[1], \"tree[1]\");\n\n return tree;\n}\n\nclass MerkleTree {\n public:\n explicit MerkleTree(size_t n) : n_(n), layers_(2 * n) {}\n\n void set_leaf(size_t pos, const Digest& leaf) {\n check(pos < n_, \"Invalid position for leaf in Merkle tree\");\n layers_[pos + n_] = leaf;\n }\n\n Digest build_tree() {\n for (size_t i = n_; i-- > 1;) {\n layers_[i] = Digest::hash2(layers_[2 * i], layers_[2 * i + 1]);\n }\n return layers_[1];\n }\n\n // The generate_proof method writes a Merkle tree proof for the leaf\n // at position pos into the proof array and returns the size of the proof\n // in number of Digests.\n size_t generate_proof(Digest proof[/*logn+1*/], size_t pos) const {\n Digest* begin = proof;\n *proof++ = layers_[pos + n_];\n for (pos += n_; pos > 1; pos >>= 1) {\n *proof++ = layers_[pos ^ 1];\n }\n return (proof - begin);\n }\n\n // Compressed Merkle proofs over a set POS[NP] of leaves.\n //\n // We first compute the set TREE of all nodes that are on the path\n // from the root to any leaf in POS. Then, for each inner node in\n // TREE, we include in the proof the child that is not in TREE, if\n // any.\n size_t generate_compressed_proof(std::vector& proof,\n const size_t pos[/*np*/], size_t np) {\n std::vector tree = compressed_merkle_proof_tree(n_, pos, np);\n\n // For each TREE node, include in the proof the\n // child that is not TREE, if any.\n size_t sz = 0;\n for (size_t i = n_; i-- > 1;) {\n if (tree[i]) {\n size_t child = 2 * i;\n if (tree[child]) {\n // try the other child\n child = 2 * i + 1;\n }\n if (!tree[child]) {\n proof.push_back(layers_[child]);\n ++sz;\n }\n }\n }\n return sz;\n }\n\n size_t n_;\n // layers_[n, 2 * n) stores the leaves (nodes at layer 0).\n // layers_[n/2, n) stores nodes at layer 1.\n // layers_[n/4, n/2) stores nodes at layer 2, etc.\n // The root is at layers_[1] where layers_[0] is not used.\n std::vector layers_;\n};\n\nclass MerkleTreeVerifier {\n public:\n explicit MerkleTreeVerifier(size_t n, const Digest& root)\n : n_(n), root_(root) {}\n\n bool verify_proof(const Digest* proof, size_t pos) const {\n Digest t = *proof++;\n for (pos += n_; pos > 1; pos >>= 1) {\n t = (pos & 1) ? Digest::hash2(*proof++, t) : Digest::hash2(t, *proof++);\n }\n return t == root_;\n }\n\n bool verify_compressed_proof(const Digest* proof, size_t proof_len,\n const Digest leaves[/*np*/],\n const size_t pos[/*np*/], size_t np) const {\n // Reconstructed layers_, where only the DEFINED subset is\n // defined.\n std::vector layers(2 * n_, Digest{});\n std::vector defined(2 * n_, false);\n\n /*scope for TREE */ {\n std::vector tree = compressed_merkle_proof_tree(n_, pos, np);\n\n // read the proof\n size_t sz = 0;\n for (size_t i = n_; i-- > 1;) {\n if (tree[i]) {\n size_t child = 2 * i;\n if (tree[child]) {\n // try the other child\n child = 2 * i + 1;\n }\n if (!tree[child]) {\n if (sz >= proof_len) {\n return false;\n }\n layers[child] = proof[sz++];\n defined[child] = true;\n }\n }\n }\n }\n\n // set LAYERS at all leaves in POS\n for (size_t ip = 0; ip < np; ++ip) {\n size_t l = pos[ip] + n_;\n layers[l] = leaves[ip];\n defined[l] = true;\n }\n\n // Recompute as many inner nodes as we can\n for (size_t i = n_; i-- > 1;) {\n if (defined[2 * i] && defined[2 * i + 1]) {\n layers[i] = Digest::hash2(layers[2 * i], layers[2 * i + 1]);\n defined[i] = true;\n }\n }\n\n return (defined[1] && (root_ == layers[1]));\n }\n\n private:\n size_t n_;\n Digest root_;\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_MERKLE_MERKLE_TREE_H_\n"], ["/longfellow-zk/lib/algebra/poly.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_POLY_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_POLY_H_\n\n#include \n\nnamespace proofs {\n// Fixed-size N-tuples of field elements, interpreted as polynomial coefficients\n// and/or values and/or newton expansion.\ntemplate \nclass Poly {\n public:\n static const size_t kN = N;\n using Elt = typename Field::Elt;\n using T = Poly;\n\n // the N-tuple itself\n Elt t_[N];\n\n Elt& operator[](size_t i) { return t_[i]; }\n const Elt& operator[](size_t i) const { return t_[i]; }\n\n T& add(const T& y, const Field& F) {\n for (size_t i = 0; i < N; ++i) {\n F.add(t_[i], y[i]);\n }\n return *this;\n }\n T& sub(const T& y, const Field& F) {\n for (size_t i = 0; i < N; ++i) {\n F.sub(t_[i], y[i]);\n }\n return *this;\n }\n T& mul(const T& y, const Field& F) {\n for (size_t i = 0; i < N; ++i) {\n F.mul(t_[i], y[i]);\n }\n return *this;\n }\n T& mul_scalar(const Elt& y, const Field& F) {\n for (size_t i = 0; i < N; ++i) {\n F.mul(t_[i], y);\n }\n return *this;\n }\n\n static T extend(const Poly<2, Field>& f, const Field& F) {\n T g;\n g[0] = f[0];\n g[1] = f[1];\n Elt df = F.subf(f[1], f[0]);\n\n if (Field::kCharacteristicTwo) {\n // Assume poly_evaluation_point[0] = 0, poly_evaluation_point[1] = 1,\n // and the rest are arbitrary.\n for (size_t i = 2; i < N; ++i) {\n g[i] = F.addf(g[0], F.mulf(F.poly_evaluation_point(i), df));\n }\n } else {\n // Assume that poly_evaluation_point[] form an arithmetic\n // progression.\n for (size_t i = 2; i < N; ++i) {\n g[i] = F.addf(g[i - 1], df);\n }\n }\n\n return g;\n }\n\n // convert Lagrange basis -> Newton forward differences for the\n // special case of evaluation points 0, 1, 2, ..., N-1.\n // See interpolation.h for the general case of interpolation.\n void newton_of_lagrange(const Field& F) {\n for (size_t i = 1; i < N; i++) {\n for (size_t k = N; k-- > i;) {\n F.sub(t_[k], t_[k - 1]);\n F.mul(t_[k], F.newton_denominator(k, i));\n }\n }\n }\n\n // Evaluate f(x) for a polynomial in the Newton forward-difference\n // basis.\n Elt eval_newton(const Elt& x, const Field& F) const {\n // Newton interpolation formula\n Elt e = t_[N - 1];\n for (size_t i = N - 1; i-- > 0;) {\n F.mul(e, F.subf(x, F.poly_evaluation_point(i)));\n F.add(e, t_[i]);\n }\n\n return e;\n }\n\n Elt eval_lagrange(const Elt& x, const Field& F) const {\n T tmp(*this); // do not clobber *this\n tmp.newton_of_lagrange(F);\n return tmp.eval_newton(x, F);\n }\n\n // Evaluate f(r) given a polynomial in the standard basis\n // f(x)=t_[i]*x^i.\n Elt eval_monomial(const Elt& x, const Field& F) const {\n // Horner's algorithm\n Elt e = t_[N - 1];\n for (size_t i = N - 1; i-- > 0;) {\n F.mul(e, x);\n F.add(e, t_[i]);\n }\n return e;\n }\n\n static T powers_of(const Elt& e, const Field& F) {\n T r;\n r[0] = F.one();\n for (size_t i = 1; i < N; ++i) {\n r[i] = F.mulf(r[i - 1], e);\n }\n return r;\n }\n\n // Interpolation via explicit dot product.\n //\n // The combination P.newton_of_lagrange().eval_newton(..., R, ...)\n // evaluates P at R given the Lagrange basis [P(0), P(1), ..., P(N-1)].\n //\n // On the contrary, this class computes a V(R) such that P(R) =\n // dot(V(R), [P(0), P(1), ..., P(N-1)]) and the caller computes the\n // inner product, either explicitly or via an inner-product\n // argument. The construction is pure linear algebra: express the\n // Lagrange basis P = [P(0), P(1), ..., P(N-1)]^T as I * P where I\n // is the identity matrix, and interpolate the rows of I\n // via newton_of_lagrange().eval_newton(). Since newton_of_lagrange()\n // is O(N^2) and eval_newton() is O(N), pre-compute the eval_newton()\n // of all rows.\n class dot_interpolation {\n // identity_[k] contains the Newton basis of the polynomial P(x) such\n // that P(k) = 1 and P(i) = 0 for i != k and 0 <= i < N.\n T identity_[N];\n\n public:\n explicit dot_interpolation(const Field& F) {\n for (size_t k = 0; k < N; ++k) {\n for (size_t i = 0; i < N; ++i) {\n identity_[k][i] = (i == k) ? F.one() : F.zero();\n }\n identity_[k].newton_of_lagrange(F);\n }\n }\n\n // return V such that P(r) = V^T [P(0), P(1), ..., P(N-1)]\n T coef(const Elt& x, const Field& F) const {\n T c;\n for (size_t k = 0; k < N; ++k) {\n c[k] = identity_[k].eval_newton(x, F);\n }\n return c;\n }\n };\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_POLY_H_\n"], ["/longfellow-zk/lib/gf2k/sysdep.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_GF2K_SYSDEP_H_\n#define PRIVACY_PROOFS_ZK_LIB_GF2K_SYSDEP_H_\n\n#include \n#include \n\n#include \n\n// Hardcoded GF(2^128) SIMD arithmetic where\n// GF(2^128) = GF(2)[x] / (x^128 + x^7 + x^2 + x + 1)\n\n#if defined(__x86_64__) || defined(__i386__)\n#include // IWYU pragma: keep\n\nnamespace proofs {\n\nusing gf2_128_elt_t = __m128i;\n\nstatic inline std::array uint64x2_of_gf2_128(gf2_128_elt_t x) {\n return std::array{static_cast(x[0]),\n static_cast(x[1])};\n}\n\nstatic inline gf2_128_elt_t gf2_128_of_uint64x2(\n const std::array &x) {\n // Cast to long long (as opposed to int64_t) is necessary because __m128i is\n // defined in terms of long long.\n return gf2_128_elt_t{static_cast(x[0]),\n static_cast(x[1])};\n}\n\nstatic inline gf2_128_elt_t gf2_128_add(gf2_128_elt_t x, gf2_128_elt_t y) {\n return _mm_xor_si128(x, y);\n}\n\n// return t0 + x^64 * t1\nstatic inline gf2_128_elt_t gf2_128_reduce(gf2_128_elt_t t0, gf2_128_elt_t t1) {\n const gf2_128_elt_t poly = {0x87};\n t0 = _mm_xor_si128(t0, _mm_slli_si128(t1, 64 /*bits*/ / 8 /*bits/byte*/));\n t0 = _mm_xor_si128(t0, _mm_clmulepi64_si128(t1, poly, 0x01));\n return t0;\n}\nstatic inline gf2_128_elt_t gf2_128_mul(gf2_128_elt_t x, gf2_128_elt_t y) {\n gf2_128_elt_t t1a = _mm_clmulepi64_si128(x, y, 0x01);\n gf2_128_elt_t t1b = _mm_clmulepi64_si128(x, y, 0x10);\n gf2_128_elt_t t1 = gf2_128_add(t1a, t1b);\n gf2_128_elt_t t2 = _mm_clmulepi64_si128(x, y, 0x11);\n t1 = gf2_128_reduce(t1, t2);\n gf2_128_elt_t t0 = _mm_clmulepi64_si128(x, y, 0x00);\n t0 = gf2_128_reduce(t0, t1);\n return t0;\n}\n} // namespace proofs\n#elif defined(__aarch64__)\n//\n// Implementation for arm/neon with AES instructions.\n// We assume that __aarch64__ implies AES, which isn't necessarily\n// the case. If this is a problem, change the defined(__aarch64__)\n// above and the code will fall back to the non-AES implementation\n// below.\n//\n#include // IWYU pragma: keep\n\nnamespace proofs {\nusing gf2_128_elt_t = poly64x2_t;\n\nstatic inline std::array uint64x2_of_gf2_128(gf2_128_elt_t x) {\n return std::array{static_cast(x[0]),\n static_cast(x[1])};\n}\n\nstatic inline gf2_128_elt_t gf2_128_of_uint64x2(\n const std::array &x) {\n return gf2_128_elt_t{static_cast(x[0]),\n static_cast(x[1])};\n}\n\nstatic inline gf2_128_elt_t vmull_low(gf2_128_elt_t t0, gf2_128_elt_t t1) {\n poly64_t tt0 = vgetq_lane_p64(t0, 0);\n poly64_t tt1 = vgetq_lane_p64(t1, 0);\n return vreinterpretq_p64_p128(vmull_p64(tt0, tt1));\n}\nstatic inline gf2_128_elt_t vmull_high(gf2_128_elt_t t0, gf2_128_elt_t t1) {\n return vreinterpretq_p64_p128(vmull_high_p64(t0, t1));\n}\n\n// return t0 + x^64 * t1\nstatic inline gf2_128_elt_t gf2_128_reduce(gf2_128_elt_t t0, gf2_128_elt_t t1) {\n const gf2_128_elt_t poly = {0x0, 0x87};\n const gf2_128_elt_t zero = {0x0, 0x0};\n t0 = vaddq_p64(t0, vextq_p64(zero, t1, 1));\n t0 = vaddq_p64(t0, vmull_high(t1, poly));\n return t0;\n}\nstatic inline gf2_128_elt_t gf2_128_add(gf2_128_elt_t x, gf2_128_elt_t y) {\n return vaddq_p64(x, y);\n}\nstatic inline gf2_128_elt_t gf2_128_mul(gf2_128_elt_t x, gf2_128_elt_t y) {\n gf2_128_elt_t swx = vextq_p64(x, x, 1);\n gf2_128_elt_t t1a = vmull_high(swx, y);\n gf2_128_elt_t t1b = vmull_low(swx, y);\n gf2_128_elt_t t1 = vaddq_p64(t1a, t1b);\n gf2_128_elt_t t2 = vmull_high(x, y);\n t1 = gf2_128_reduce(t1, t2);\n gf2_128_elt_t t0 = vmull_low(x, y);\n t0 = gf2_128_reduce(t0, t1);\n return t0;\n}\n} // namespace proofs\n\n#elif defined(__arm__) || defined(__aarch64__)\n//\n// Implementation for arm/neon without AES instructions\n//\n#include // IWYU pragma: keep\n\nnamespace proofs {\nusing gf2_128_elt_t = poly64x2_t;\n\nstatic inline std::array uint64x2_of_gf2_128(gf2_128_elt_t x) {\n return std::array{static_cast(x[0]),\n static_cast(x[1])};\n}\n\nstatic inline gf2_128_elt_t gf2_128_of_uint64x2(\n const std::array &x) {\n return gf2_128_elt_t{static_cast(x[0]),\n static_cast(x[1])};\n}\n\nstatic inline gf2_128_elt_t gf2_128_add(gf2_128_elt_t x, gf2_128_elt_t y) {\n return vaddq_p64(x, y);\n}\n\n// Emulate vmull_p64() with vmull_p8().\n//\n// This emulation is pretty naive and it performs a lot of permutations.\n//\n// A possibly better alternative appears in Danilo Câmara, Conrado\n// Gouvêa, Julio López, Ricardo Dahab, \"Fast Software Polynomial\n// Multiplication on ARM Processors Using the NEON Engine\", 1st\n// Cross-Domain Conference and Workshop on Availability, Reliability,\n// and Security in Information Systems (CD-ARES), Sep 2013,\n// Regensburg, Germany. pp.137-154. ⟨hal-01506572⟩\n//\n// However, the code from that paper makes heavy use of type\n// punning of 128-bit registers as two 64-bit registers, which\n// I don't know how to express in C.\nstatic inline poly8x16_t pmul64x8(poly8x8_t x, poly8_t y) {\n const poly8x16_t zero{};\n poly8x16_t prod = vmull_p8(x, vdup_n_p8(y));\n poly8x16x2_t uzp = vuzpq_p8(prod, zero);\n return vaddq_p8(uzp.val[0], vextq_p8(uzp.val[1], uzp.val[1], 15));\n}\n\n// multiply/add. Return (cout, s) = cin + x * y where the final sum\n// would be (cout << 8) + s.\nstatic inline poly8x16x2_t pmac64x8(poly8x16_t cin, poly8x8_t x, poly8_t y) {\n const poly8x16_t zero{};\n poly8x16_t prod = vmull_p8(x, vdup_n_p8(y));\n poly8x16x2_t uzp = vuzpq_p8(prod, zero);\n uzp.val[0] = vaddq_p8(uzp.val[0], cin);\n return uzp;\n}\n\nstatic inline poly8x16_t pmul64x64(poly8x8_t x, poly8x8_t y) {\n poly8x16_t r{};\n\n poly8x16x2_t prod = pmac64x8(r, x, y[0]);\n r = prod.val[0];\n\n prod = pmac64x8(prod.val[1], x, y[1]);\n r = vaddq_p8(r, vextq_p8(prod.val[0], prod.val[0], 15));\n\n prod = pmac64x8(prod.val[1], x, y[2]);\n r = vaddq_p8(r, vextq_p8(prod.val[0], prod.val[0], 14));\n\n prod = pmac64x8(prod.val[1], x, y[3]);\n r = vaddq_p8(r, vextq_p8(prod.val[0], prod.val[0], 13));\n\n prod = pmac64x8(prod.val[1], x, y[4]);\n r = vaddq_p8(r, vextq_p8(prod.val[0], prod.val[0], 12));\n\n prod = pmac64x8(prod.val[1], x, y[5]);\n r = vaddq_p8(r, vextq_p8(prod.val[0], prod.val[0], 11));\n\n prod = pmac64x8(prod.val[1], x, y[6]);\n r = vaddq_p8(r, vextq_p8(prod.val[0], prod.val[0], 10));\n\n prod = pmac64x8(prod.val[1], x, y[7]);\n r = vaddq_p8(r, vextq_p8(prod.val[0], prod.val[0], 9));\n r = vaddq_p8(r, vextq_p8(prod.val[1], prod.val[1], 8));\n\n return r;\n}\n\nstatic inline gf2_128_elt_t vmull_low(gf2_128_elt_t t0, gf2_128_elt_t t1) {\n // vreinterpretq_p64_p8() seems not to be defined, use\n // static_cast\n return static_cast(pmul64x64(vget_low_p8(t0), vget_low_p8(t1)));\n}\nstatic inline gf2_128_elt_t vmull_high(gf2_128_elt_t t0, gf2_128_elt_t t1) {\n return static_cast(pmul64x64(vget_high_p8(t0), vget_high_p8(t1)));\n}\n\n// vextq_p64() seems not to be defined.\nstatic inline gf2_128_elt_t vextq_p64_1_emul(gf2_128_elt_t t0,\n gf2_128_elt_t t1) {\n return static_cast(\n vextq_p8(static_cast(t0), static_cast(t1), 8));\n}\n\n// return t0 + x^64 * t1\nstatic inline gf2_128_elt_t gf2_128_reduce(gf2_128_elt_t t0, gf2_128_elt_t t1) {\n const poly8_t poly = static_cast(0x87);\n const gf2_128_elt_t zero = {0x0, 0x0};\n t0 = vaddq_p64(t0, vextq_p64_1_emul(zero, t1));\n t0 = vaddq_p64(t0, pmul64x8(vget_high_p8(t1), poly));\n return t0;\n}\n\nstatic inline gf2_128_elt_t gf2_128_mul(gf2_128_elt_t x, gf2_128_elt_t y) {\n gf2_128_elt_t swx = vextq_p64_1_emul(x, x);\n gf2_128_elt_t t1a = vmull_high(swx, y);\n gf2_128_elt_t t1b = vmull_low(swx, y);\n gf2_128_elt_t t1 = vaddq_p64(t1a, t1b);\n gf2_128_elt_t t2 = vmull_high(x, y);\n t1 = gf2_128_reduce(t1, t2);\n gf2_128_elt_t t0 = vmull_low(x, y);\n t0 = gf2_128_reduce(t0, t1);\n return t0;\n}\n\n} // namespace proofs\n#else\n#error \"unimplemented gf2k/sysdep.h\"\n#endif\n\n#endif // PRIVACY_PROOFS_ZK_LIB_GF2K_SYSDEP_H_\n"], ["/longfellow-zk/lib/circuits/anoncred/small_examples.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_EXAMPLES_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_EXAMPLES_H_\n\n#include \n#include \n\n#include \"algebra/static_string.h\"\n\nnamespace proofs {\n\nstruct SmallTest {\n StaticString pkx, pky; /* public key of the issuer */\n StaticString sigr, sigs, sigtr, sigts;\n uint8_t transcript[1024];\n size_t transcript_size;\n uint8_t *now;\n size_t mdoc_size;\n uint8_t mdoc[5000];\n};\n\nstatic const struct SmallTest mdoc_small_tests[] = {\n // Example that requires 3 SHA blocks for the credential.\n {StaticString(\n \"0x298aa30b14298b8bdb5b2b1cc0150e84a86a1469fa813f8df0f0bd09d8489661\"),\n StaticString(\n \"0x2f821d00395d0c63b222a8613c7af5f5cb2b655dda6c3926af7ea3acd6a05fba\"),\n StaticString(\n \"0xc96b7605f15536877592c24d4d65066a377c34e3e6a624ea52ce9d899207\"),\n StaticString(\n \"0xaca1128a3460368caefc5c24a27a7f9e8cc8d590b93485db2c408d1ac96d80ae\"),\n StaticString(\n \"0x08ca78156b6c60c711e501641d4b5000f1ff7715386f1186ce4aec1d6eb2ba92\"),\n StaticString(\n \"0xfdcb8d4da84f1dc03a7bd22909a6bcc103281310f9fe1fb97c13e5d2eb6934df\"),\n {0x60, 0x80, 0xf3, 0x09, 0x55, 0x56, 0xe5, 0x21, 0x4c, 0x5f, 0xff,\n 0x7c, 0x6d, 0x3d, 0xcb, 0x90, 0x3e, 0x2d, 0xcc, 0x45, 0x42, 0x9c,\n 0x4d, 0x81, 0xf9, 0x80, 0x8d, 0x5e, 0x7a, 0xd2, 0x14, 0x50},\n 32,\n (uint8_t *)\"20241005\",\n 183,\n {0x45, 0x72, 0x69, 0x6b, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4d, 0x75, 0x73, 0x74,\n 0x65, 0x72, 0x6d, 0x61, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x31, 0x39, 0x38, 0x30, 0x30, 0x31, 0x30, 0x31,\n 0x00, 0xf5, 0xf5, 0xf5, 0xf5, 0xf4, 0xf4, 0xf4, 0x00, 0x00, 0x00, 0x00,\n 0x32, 0x30, 0x32, 0x34, 0x31, 0x30, 0x30, 0x31, 0x32, 0x30, 0x32, 0x35,\n 0x31, 0x30, 0x30, 0x31, 0x3c, 0xeb, 0x4a, 0xec, 0x0d, 0x76, 0xbb, 0x50,\n 0x35, 0x09, 0xc6, 0x46, 0xad, 0xc6, 0x30, 0x3f, 0xb9, 0xea, 0xa5, 0x84,\n 0xb4, 0x8f, 0xa0, 0xbe, 0x07, 0x6f, 0x14, 0x28, 0xe4, 0xec, 0x3b, 0x37,\n 0x77, 0x91, 0x61, 0xbe, 0xb9, 0x86, 0x90, 0xfb, 0xc8, 0xe3, 0x57, 0x5a,\n 0x9d, 0xd9, 0x41, 0x91, 0xae, 0x8e, 0x4d, 0xbe, 0x2c, 0x44, 0x39, 0x07,\n 0x69, 0xea, 0x0c, 0x08, 0x80, 0x22, 0xf2, 0xc6, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00}},\n // The next examples requires 4 SHA blocks for the credential.\n {\n StaticString(\"0x08a25115e57d680260aafa44e674d45d43af885fffa6746b44ece71\"\n \"cd42febd2\"),\n StaticString(\"0x4a177f6c38543876c66573218db63de627d343f16a483a313069830\"\n \"37df79b2f\"),\n StaticString(\"0x95394343021474ed688e7e783063c768a3343def0f1245f1da09406\"\n \"34eb57410\"),\n StaticString(\"0x4953b2f11cd46c8e1673ac50ddc51665702a27e5788eca3a8bffa67\"\n \"fbdbf65ce\"),\n StaticString(\"0x1ca6eef3238ec5320429774f6b6b743cc868b3cfebff96c41112b36\"\n \"5638a9dc5\"),\n StaticString(\"0x7e303bd730d0e663621ddcaf52991ba9f744cabe161598a44b4508f\"\n \"de7bdaf2d\"),\n\n {0x60, 0x80, 0xf3, 0x09, 0x55, 0x56, 0xe5, 0x21, 0x4c, 0x5f, 0xff,\n 0x7c, 0x6d, 0x3d, 0xcb, 0x90, 0x3e, 0x2d, 0xcc, 0x45, 0x42, 0x9c,\n 0x4d, 0x81, 0xf9, 0x80, 0x8d, 0x5e, 0x7a, 0xd2, 0x14, 0x50},\n 32,\n (uint8_t *)\"20241005\",\n 247,\n {0x45, 0x72, 0x69, 0x6b, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4d, 0x75, 0x73, 0x74,\n 0x65, 0x72, 0x6d, 0x61, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x31, 0x39, 0x38, 0x30, 0x30, 0x31, 0x30, 0x31,\n 0x00, 0xf5, 0xf5, 0xf5, 0xf5, 0xf4, 0xf4, 0xf4, 0x00, 0x00, 0x00, 0x00,\n 0x32, 0x30, 0x32, 0x34, 0x31, 0x30, 0x30, 0x31, 0x32, 0x30, 0x32, 0x35,\n 0x31, 0x30, 0x30, 0x31, 0x3e, 0xf6, 0x39, 0x05, 0x33, 0xf8, 0xf3, 0x37,\n 0x7d, 0xe0, 0xb2, 0xb5, 0x65, 0x19, 0x93, 0x3f, 0x49, 0xe1, 0xa1, 0x41,\n 0x57, 0xa5, 0x22, 0x0e, 0xac, 0x79, 0x8a, 0xe2, 0xe2, 0xea, 0xd2, 0x0c,\n 0x9f, 0x23, 0x3d, 0x1b, 0xe2, 0x8e, 0x69, 0xc1, 0xda, 0x76, 0xec, 0xf9,\n 0xc3, 0x0c, 0xf9, 0x3b, 0xb5, 0xb6, 0x69, 0x6f, 0xc6, 0xc2, 0x8a, 0xa8,\n 0x98, 0x19, 0x7d, 0xbf, 0xea, 0x6d, 0xad, 0x40, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},\n },\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_EXAMPLES_H_\n"], ["/longfellow-zk/lib/merkle/merkle_commitment.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_MERKLE_MERKLE_COMMITMENT_H_\n#define PRIVACY_PROOFS_ZK_LIB_MERKLE_MERKLE_COMMITMENT_H_\n\n#include \n#include \n\n#include \n#include \n#include \n\n#include \"merkle/merkle_tree.h\"\n#include \"random/random.h\"\n#include \"util/crypto.h\"\n\nnamespace proofs {\n\nstruct MerkleNonce {\n static constexpr size_t kLength = kSHA256DigestSize;\n uint8_t bytes[kLength];\n};\n\nstruct MerkleProof {\n explicit MerkleProof(size_t nreq) : nonce(nreq), path() {}\n\n std::vector nonce; // [nreq]\n std::vector path; // variable size, but < nreq * mt_pathlen\n};\n\ninline size_t merkle_commitment_len(size_t n) { return merkle_tree_len(n); }\n\n// prover-side\nclass MerkleCommitment {\n public:\n explicit MerkleCommitment(size_t n) : n_(n), mt_(n), nonce_(n) {}\n\n Digest commit(const std::function &updhash,\n RandomEngine &rng) {\n for (size_t i = 0; i < n_; ++i) {\n SHA256 sha;\n rng.bytes(nonce_[i].bytes, MerkleNonce::kLength);\n sha.Update(nonce_[i].bytes, MerkleNonce::kLength);\n updhash(i, sha);\n\n Digest dig;\n sha.DigestData(dig.data);\n mt_.set_leaf(i, dig);\n }\n\n return mt_.build_tree();\n }\n\n void open(MerkleProof &proof, const size_t pos[/*np*/], size_t np) {\n // fill in the nonces of the opening\n for (size_t i = 0; i < np; ++i) {\n proof.nonce[i] = nonce_[pos[i]];\n }\n\n (void)mt_.generate_compressed_proof(proof.path, pos, np);\n }\n\n private:\n size_t n_;\n MerkleTree mt_;\n std::vector nonce_;\n};\n\n// Declare a class for symmetry, but this class is never instantiated\nclass MerkleCommitmentVerifier {\n public:\n static bool verify(size_t n, const Digest &root, const MerkleProof &proof,\n const size_t pos[/*nreq*/], size_t nreq,\n const std::function &updhash) {\n // Assemble the expected leaf values\n std::vector leaves(nreq);\n for (size_t r = 0; r < nreq; ++r) {\n SHA256 sha;\n sha.Update(proof.nonce[r].bytes, MerkleNonce::kLength);\n updhash(r, sha);\n sha.DigestData(leaves[r].data);\n }\n\n MerkleTreeVerifier mtv(n, root);\n return mtv.verify_compressed_proof(proof.path.data(), proof.path.size(),\n &leaves[0], pos, nreq);\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_MERKLE_MERKLE_COMMITMENT_H_\n"], ["/longfellow-zk/lib/circuits/compiler/circuit_dump.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_CIRCUIT_DUMP_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_CIRCUIT_DUMP_H_\n\n#include \n\n#include \"circuits/compiler/compiler.h\"\n#include \"util/log.h\"\n\n// Debug printing routines for circuit tests.\nnamespace proofs {\n\ntemplate \ninline void dump_info(const char* name, size_t size,\n const QuadCircuit& Q) {\n log(INFO, \"Compiled circuit: %s[%zu]\", name, size);\n dump_q(Q);\n}\n\ntemplate \ninline void dump_info(const char* name, size_t sz0, size_t sz1,\n const QuadCircuit& Q) {\n log(INFO, \"Compiled circuit: %s[%zu][%zu]\", name, sz0, sz1);\n dump_q(Q);\n}\n\ntemplate \ninline void dump_info(const char* name, size_t sz0, size_t sz1, size_t sz2,\n const QuadCircuit& Q) {\n log(INFO, \"Compiled circuit: %s[%zu][%zu][%zu]\", name, sz0, sz1, sz2);\n dump_q(Q);\n}\n\ntemplate \ninline void dump_info(const char* name, const QuadCircuit& Q) {\n log(INFO, \"Compiled circuit: %s\", name);\n dump_q(Q);\n}\n\ntemplate \ninline void dump_q(const QuadCircuit& Q) {\n log(INFO,\n \" depth: %zu wires: %zu in: %zu out:%zu use:%zu ovh:%zu t:%zu cse:%zu \"\n \"notn:%zu\",\n Q.depth_, Q.nwires_, Q.ninput_, Q.noutput_,\n Q.nwires_ - Q.nwires_overhead_, Q.nwires_overhead_, Q.nquad_terms_,\n Q.nwires_cse_eliminated_, Q.nwires_not_needed_);\n}\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_CIRCUIT_DUMP_H_\n"], ["/longfellow-zk/lib/zk/zk_verifier.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ZK_ZK_VERIFIER_H_\n#define PRIVACY_PROOFS_ZK_LIB_ZK_ZK_VERIFIER_H_\n\n#include \n\n#include \n\n#include \"arrays/dense.h\"\n#include \"ligero/ligero_param.h\"\n#include \"ligero/ligero_verifier.h\"\n#include \"random/transcript.h\"\n#include \"sumcheck/circuit.h\"\n#include \"util/log.h\"\n#include \"zk/zk_common.h\"\n#include \"zk/zk_proof.h\"\n\nnamespace proofs {\n// ZK Verifier\n//\n// Verifies a zk proof. See note in the prover for the design.\n// To verify a proof, instantiate the class, then call recv_commitment with\n// the commitment, and finally call verify. It is possible to receive several\n// commitments, or run other protocols between the recv_commitment and verify\n// calls. This allows composing two proofs in parallel.\n// To support this, the interface to both accepts a raw Transcript.\ntemplate \nclass ZkVerifier {\n using Elt = typename Field::Elt;\n\n public:\n explicit ZkVerifier(const Circuit& c, const RSFactory& rsf,\n size_t rate, size_t nreq, const Field& F)\n : circ_(c),\n n_witness_(c.ninputs - c.npub_in),\n param_(n_witness_ + ZkCommon::pad_size(c), c.nl, rate, nreq),\n lqc_(c.nl),\n rsf_(rsf),\n f_(F) {\n ZkCommon::setup_lqc(c, lqc_, n_witness_);\n }\n\n void recv_commitment(const ZkProof& zk, Transcript& t) const {\n log(INFO, \"verifier: recv commit\");\n LigeroVerifier::receive_commitment(zk.com, t);\n }\n\n // Verifies the proof.\n bool verify(const ZkProof& zk, const Dense& pub,\n Transcript& tv) const {\n log(INFO, \"verifier: verify\");\n\n ZkCommon::initialize_sumcheck_fiat_shamir(tv, circ_, pub, f_);\n\n // Derive constraints on the witness.\n using Llc = LigeroLinearConstraint;\n std::vector A;\n std::vector b;\n const LigeroHash hash_of_A{0xde, 0xad, 0xbe, 0xef};\n size_t cn = ZkCommon::verifier_constraints(circ_, pub, zk.proof,\n /*aux=*/nullptr, A, b, tv,\n n_witness_, f_);\n\n const char* why = \"\";\n bool ok = LigeroVerifier::verify(\n &why, param_, zk.com, zk.com_proof, tv, cn, A.size(), &A[0], hash_of_A,\n &b[0], &lqc_[0], rsf_, f_);\n\n log(INFO, \"verify done: %s\", why);\n return ok;\n }\n\n private:\n const Circuit& circ_;\n const size_t n_witness_;\n const LigeroParam param_;\n std::vector lqc_;\n const RSFactory& rsf_;\n const Field& f_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ZK_ZK_VERIFIER_H_\n"], ["/longfellow-zk/lib/sumcheck/testing.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_SUMCHECK_TESTING_H_\n#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_TESTING_H_\n\n#include \n\n#include \n#include \n\n#include \"arrays/dense.h\"\n#include \"random/transcript.h\"\n#include \"sumcheck/circuit.h\"\n#include \"sumcheck/prover.h\"\n#include \"sumcheck/verifier.h\"\n#include \"util/log.h\"\n#include \"util/panic.h\"\n\n/*\nThese are methods that help test modules\nby running the prover or the verifier.\n*/\nnamespace proofs {\ntemplate \nvoid run_prover(const Circuit *C, std::unique_ptr> W,\n Proof *proof, const Field& F) {\n typename Prover::inputs pin;\n\n Prover prover(F);\n auto V = prover.eval_circuit(&pin, C, W->clone(), F);\n\n check(V != nullptr, \"eval_circuit failed.\");\n\n // Ensure the witness satisfies the circuit before making a proof.\n for (size_t i = 0; i < V->n1_; ++i) {\n if (V->v_[i] != F.zero()) {\n log(INFO, \"witness failed: non-zero output at %zu\", i);\n }\n check(V->v_[i] == F.zero(), \"witness failed, non-zero output\");\n }\n\n Transcript tsp((uint8_t *)\"testing\", 7);\n prover.prove(proof, nullptr, C, pin, tsp);\n}\n\ntemplate \nvoid run_verifier(const Circuit *C, std::unique_ptr> W,\n Proof &proof, const Field& F) {\n const char *why = \"ok\";\n auto V = std::make_unique>(F);\n Transcript tsv((uint8_t *)\"testing\", 7);\n check(Verifier::verify(&why, C, &proof, std::move(V),\n W->clone(), tsv, F), why);\n}\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_TESTING_H_\n"], ["/longfellow-zk/lib/circuits/mac/mac_reference.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MAC_MAC_REFERENCE_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MAC_MAC_REFERENCE_H_\n\n#include \n#include \n#include \n\n#include \"arrays/dense.h\"\n#include \"random/random.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n\ntemplate \nclass MACReference {\n using gf2k = typename GF::Elt;\n\n public:\n void sample(gf2k ap[], size_t n, RandomEngine* rng) {\n check(n > 0, \"n must be positive\");\n std::vector buf(n * GF::kBytes);\n rng->bytes(buf.data(), n * GF::kBytes);\n for (size_t i = 0; i < n; ++i) {\n ap[i] = gf_.of_bytes_field(&buf[i * GF::kBytes]).value();\n }\n }\n\n // Computes the mac of a 32-byte message.\n void compute(gf2k mac[/*2*/], const gf2k& av, const gf2k ap[/*2*/],\n uint8_t msg[/*32*/]) const {\n uint8_t tmp[GF::kBytes] = {0};\n for (size_t i = 0; i < 2; ++i) {\n memcpy(tmp, &msg[i * GF::kBytes], GF::kBytes);\n gf2k m = gf_.of_bytes_field(tmp).value();\n mac[i] = gf_.mulf(gf_.addf(av, ap[i]), m);\n }\n }\n\n void to_bytes(gf2k mac[/*2*/], uint8_t buf[/* 32 */]) {\n gf_.to_bytes(mac[0], buf);\n gf_.to_bytes(mac[1], buf + GF::kBytes);\n }\n\n private:\n GF gf_;\n};\n\ntemplate \nvoid fill_gf2k(const typename GF::Elt& m, DenseFiller& df,\n const Field& f) {\n for (size_t i = 0; i < GF::kBits; ++i) {\n df.push_back(m[i] ? f.one() : f.zero());\n }\n}\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MAC_MAC_REFERENCE_H_\n"], ["/longfellow-zk/lib/zk/zk_testing.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ZK_ZK_TESTING_H_\n#define PRIVACY_PROOFS_ZK_LIB_ZK_ZK_TESTING_H_\n\n#include \n#include \n#include \n\n#include \"algebra/convolution.h\"\n#include \"algebra/fp2.h\"\n#include \"algebra/reed_solomon.h\"\n#include \"arrays/dense.h\"\n#include \"random/secure_random_engine.h\"\n#include \"random/transcript.h\"\n#include \"sumcheck/circuit.h\"\n#include \"util/log.h\"\n#include \"util/readbuffer.h\"\n#include \"zk/zk_proof.h\"\n#include \"zk/zk_prover.h\"\n#include \"zk/zk_verifier.h\"\n#include \"gtest/gtest.h\"\n\nnamespace proofs {\n\nconstexpr size_t kLigeroRate = 4;\nconstexpr size_t kLigeroNreq = 189;\n\n// Runs a zk prover and verifier for a field that requires a field extension\n// to perform the commitment.\ntemplate \nvoid run2_test_zk(const Circuit& circuit, Dense& W,\n const Dense& pub, const Field& base,\n const typename Field::Elt& root_x,\n const typename Field::Elt& root_y, size_t root_order) {\n // Build the relevant algebra objects.\n using Field2 = Fp2;\n using Elt2 = typename Field2::Elt;\n using FftExtConvolutionFactory = FFTExtConvolutionFactory;\n using RSFactory = ReedSolomonFactory;\n\n const Field2 base_2(base);\n const Elt2 omega{root_x, root_y};\n const FftExtConvolutionFactory fft(base, base_2, omega, root_order);\n const RSFactory rsf(fft, base);\n\n ZkProof zkpr(circuit, kLigeroRate, kLigeroNreq);\n\n Transcript tp((uint8_t*)\"zk_test\", 7);\n SecureRandomEngine rng;\n ZkProver prover(circuit, base, rsf);\n prover.commit(zkpr, W, tp, rng);\n EXPECT_TRUE(prover.prove(zkpr, W, tp));\n log(INFO, \"ZK Prover done\");\n\n std::vector zbuf;\n zkpr.write(zbuf, base);\n log(INFO, \"zkp len: %zu bytes\", zbuf.size());\n\n // ======= run verifier =============\n // Re-parse the proof to simulate a different client.\n ZkProof zkpv(circuit, kLigeroRate, kLigeroNreq);\n ReadBuffer rb(zbuf);\n EXPECT_TRUE(zkpv.read(rb, base));\n\n ZkVerifier verifier(circuit, rsf, kLigeroRate, kLigeroNreq,\n base);\n Transcript tv((uint8_t*)\"zk_test\", 7);\n verifier.recv_commitment(zkpv, tv);\n EXPECT_TRUE(verifier.verify(zkpv, pub, tv));\n log(INFO, \"ZK Verify done\");\n}\n\ntemplate \nvoid run_failing_test_zk2(const Circuit& circuit, Dense& W,\n const Dense& pub, const Field& base,\n const typename Field::Elt& root_x,\n const typename Field::Elt& root_y,\n size_t root_order) {\n // Build the relevant algebra objects.\n using Field2 = Fp2;\n using Elt2 = typename Field2::Elt;\n using FftExtConvolutionFactory = FFTExtConvolutionFactory;\n using RSFactory = ReedSolomonFactory;\n\n const Field2 base_2(base);\n const Elt2 omega{root_x, root_y};\n const FftExtConvolutionFactory fft(base, base_2, omega, root_order);\n const RSFactory rsf(fft, base);\n\n ZkProof zkpr(circuit, kLigeroRate, kLigeroNreq);\n\n Transcript tp((uint8_t*)\"zk_test\", 7);\n SecureRandomEngine rng;\n ZkProver prover(circuit, base, rsf);\n prover.commit(zkpr, W, tp, rng);\n bool p_ok = prover.prove(zkpr, W, tp);\n EXPECT_FALSE(p_ok);\n}\n\n// Runs a zk prover and verifier for a field that has a suitable root of unity.\ntemplate \nvoid run_test_zk(const Circuit& circuit, Dense& W,\n const Dense& pub, const typename Field::Elt& omega,\n uint64_t omega_order, const Field& F) {\n using FftConvolutionFactory = FFTConvolutionFactory;\n\n FftConvolutionFactory fft(F, omega, omega_order);\n using RSFactory = ReedSolomonFactory;\n const RSFactory rsf(fft, F);\n\n ZkProof zkpr(circuit, kLigeroRate, kLigeroNreq);\n\n Transcript tp((uint8_t*)\"zk_test\", 7);\n SecureRandomEngine rng;\n ZkProver prover(circuit, F, rsf);\n prover.commit(zkpr, W, tp, rng);\n EXPECT_TRUE(prover.prove(zkpr, W, tp));\n\n log(INFO, \"ZK Prover done\");\n\n std::vector zbuf;\n zkpr.write(zbuf, F);\n log(INFO, \"zkp len: %zu bytes\", zbuf.size());\n\n // ======= zk verifier =============\n // Re-parse the proof to simulate a different client.\n ZkProof zkpv(circuit, kLigeroRate, kLigeroNreq);\n ReadBuffer rb(zbuf);\n EXPECT_TRUE(zkpv.read(rb, F));\n\n ZkVerifier verifier(circuit, rsf, kLigeroRate, kLigeroNreq,\n F);\n Transcript tv((uint8_t*)\"zk_test\", 7);\n verifier.recv_commitment(zkpv, tv);\n EXPECT_TRUE(verifier.verify(zkpv, pub, tv));\n}\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ZK_ZK_TESTING_H_\n"], ["/longfellow-zk/lib/random/random.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_RANDOM_RANDOM_H_\n#define PRIVACY_PROOFS_ZK_LIB_RANDOM_RANDOM_H_\n\n#include \n#include \n#include \n#include \n#include \n\n#include \"util/panic.h\"\n\nnamespace proofs {\n\n// Our protocols require random coins; this interface provides both prover\n// and verifier components with those coins. Re-implementing this interface\n// allows easily supporting the Fiat-Shamir transform, or for sampling using\n// a system provided RNG such as openssl.\nclass RandomEngine {\n public:\n virtual ~RandomEngine() = default;\n virtual void bytes(uint8_t* buf, size_t n) = 0; // pure virtual\n\n // Sample a random field element.\n // TODO [matteof 2025-02-07] Per RFC, we must mask off the high\n // bits, but this requires changes to the field interface.\n // Punt for now since the mask is all ones anyway.\n template \n typename Field::Elt elt(const Field& F) {\n // Expected constant time.\n uint8_t buf[Field::kBytes];\n for (;;) {\n bytes(buf, sizeof(buf));\n if (std::optional maybe = F.of_bytes_field(buf)) {\n return maybe.value();\n }\n }\n }\n\n template \n typename Field::Elt subfield_elt(const Field& F) {\n // Expected constant time.\n uint8_t buf[Field::kSubFieldBytes];\n for (;;) {\n bytes(buf, sizeof(buf));\n if (std::optional maybe = F.of_bytes_subfield(buf)) {\n return maybe.value();\n }\n }\n }\n\n // Convenience method to sample an array of random field elements.\n template \n void elt(typename Field::Elt e[/*n*/], size_t n, const Field& F) {\n for (size_t i = 0; i < n; ++i) e[i] = elt(F);\n }\n\n // the minimal bitmask such that (n & mask) == n\n size_t mask(size_t n) {\n size_t mask = 0;\n while ((n & mask) != n) {\n mask <<= 1;\n mask |= 1u;\n }\n return mask;\n }\n\n // random size_t < n\n size_t nat(size_t n) {\n check(n > 0, \"nat(0)\");\n\n // compute the minimum number of random bytes needed\n size_t l = 0;\n size_t nn = n;\n while (nn != 0) {\n nn >>= 8;\n ++l;\n }\n check(l <= sizeof(size_t), \"l <= sizeof(size_t)\");\n\n size_t msk = mask(n);\n size_t r;\n uint8_t buf[sizeof(size_t)];\n\n // rejection sampling\n do {\n // consume L random bytes\n bytes(buf, l);\n\n // little-endian read\n r = 0;\n for (size_t i = l; i-- > 0;) {\n r = (r << 8) | buf[i];\n }\n\n // mask off high bits\n r &= msk;\n } while (r >= n);\n\n return r;\n }\n\n // Choose K distinct random naturals in [0..N).\n // Textbook algorithm requiring O(N) space\n void choose(size_t res[/*k*/], size_t n, size_t k) {\n check(n >= k, \"n >= k\");\n\n std::vector A(n);\n for (size_t i = 0; i < n; ++i) {\n A[i] = i;\n }\n for (size_t i = 0; i < k; ++i) {\n size_t j = i + nat(n - i);\n std::swap(A[i], A[j]);\n res[i] = A[i];\n }\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_RANDOM_RANDOM_H_\n"], ["/longfellow-zk/lib/algebra/interpolation.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_INTERPOLATION_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_INTERPOLATION_H_\n\n#include \n\n#include \"algebra/poly.h\"\n\nnamespace proofs {\n// General-purpose polynomial interpolation routines,\n// which operate on arbitrary points at the cost of\n// computing inverses in the field.\n// These static functions are grouped into a class due\n// to the common template arguments.\ntemplate \nclass Interpolation {\n public:\n static const size_t kN = N;\n using Elt = typename Field::Elt;\n using PolyN = Poly;\n\n // Throughout, X are the evaluation points.\n\n // Lagrange basis to Newton\n static void newton_of_lagrange_inplace(PolyN &A, const PolyN &X,\n const Field &F) {\n // Cache one element E and its inverse. In the common\n // case where the points X are in an arithmetic sequence,\n // this cache avoids the computation of most inverses.\n Elt e = F.one(), inve = F.one();\n\n for (size_t i = 1; i < N; i++) {\n for (size_t k = N; k-- > i;) {\n Elt dx = F.subf(X[k], X[k - i]);\n if (dx != e) {\n e = dx;\n inve = F.invertf(dx);\n }\n A[k] = F.mulf(F.subf(A[k], A[k - 1]), inve);\n }\n }\n }\n\n static PolyN newton_of_lagrange(const PolyN &L, const PolyN &X,\n const Field &F) {\n PolyN A = L;\n newton_of_lagrange_inplace(A, X, F);\n return A;\n }\n\n // evaluation in Newton basis\n static Elt eval_newton(PolyN &Newton, const PolyN &X, const Elt &x,\n const Field &F) {\n Elt e{};\n\n for (size_t i = N; i-- > 0;) {\n e = F.addf(Newton[i], F.mulf(e, F.subf(x, X[i])));\n }\n return e;\n }\n\n // Newton basis to monomial basis (i.e., coefficients)\n static void monomial_of_newton_inplace(PolyN &A, const PolyN &X,\n const Field &F) {\n for (size_t i = N; i-- > 0;) {\n for (size_t k = i + 1; k < N; ++k) {\n A[k - 1] = F.subf(A[k - 1], F.mulf(A[k], X[i]));\n }\n }\n }\n\n static PolyN monomial_of_newton(const PolyN &Newton, const PolyN &X,\n const Field &F) {\n PolyN A = Newton;\n monomial_of_newton_inplace(A, X, F);\n return A;\n }\n\n // evaluation in the monomial basis\n static Elt eval_monomial(PolyN &M, const Elt &x, const Field &F) {\n Elt e{};\n\n for (size_t i = N; i-- > 0;) {\n e = F.addf(M[i], F.mulf(e, x));\n }\n return e;\n }\n\n static void monomial_of_lagrange_inplace(PolyN &A, const PolyN &X,\n const Field &F) {\n newton_of_lagrange_inplace(A, X, F);\n monomial_of_newton_inplace(A, X, F);\n }\n\n static PolyN monomial_of_lagrange(const PolyN &L, const PolyN &X,\n const Field &F) {\n PolyN A = L;\n monomial_of_lagrange_inplace(A, X, F);\n return A;\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_INTERPOLATION_H_\n"], ["/longfellow-zk/lib/arrays/eq.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ARRAYS_EQ_H_\n#define PRIVACY_PROOFS_ZK_LIB_ARRAYS_EQ_H_\n\n#include \n\n#include \"arrays/affine.h\"\n\nnamespace proofs {\ntemplate \n// EQ[i,j] is 2D sparse array EQ[i, j] = (i == j).\n// This class contains a state-free version of EQ, which\n// evaluates EQ[i, j] on the fly. See Eqs for a stateful\n// version that stores all the values of EQ[I, j] for fixed I\n// and variable j.\nclass Eq {\n using Elt = typename Field::Elt;\n\n public:\n /*\n Bind EQ{logn,n} at I, J.\n\n We consider the diagonal matrix EQ[i,j] to be composed of\n N-1 diagonal elements A and one last diagonal element B, i.e.,\n EQ=diag([A A A A ... B]). We bind one I variable and one J\n variable in one step, yielding a matrix of the same form\n with ceil(n/2) diagonal entries.\n\n Let I1J1=I[0]*J[0] and I0J0=(1-I[0])*(1-J[0]).\n\n Binding A is equivalent to binding the 2x2 block [A 0; 0 A],\n yielding A <- A*(I0J0+I1J1).\n\n If n is even, then the last 2x2 block is [A 0; 0 B], whose binding\n yields B <- A*I0J0 + B*I1J1.\n\n If n is odd, then the last 2x2 block is [B 0; 0 0], whose binding\n yields B <- B*I0J0.\n */\n static Elt eval(size_t logn, corner_t n, const Elt I[/*logn*/],\n const Elt J[/*logn*/], const Field& F) {\n Elt a = F.one(), b = F.one();\n for (size_t round = 0; round < logn; round++) {\n Elt i1 = I[round], j1 = J[round];\n Elt i0 = F.subf(F.one(), i1), j0 = F.subf(F.one(), j1);\n Elt i0j0 = F.mulf(i0, j0);\n Elt i1j1 = F.mulf(i1, j1);\n if ((n & 1) == 0) {\n F.mul(b, i1j1);\n F.add(b, F.mulf(a, i0j0));\n } else {\n F.mul(b, i0j0);\n }\n F.mul(a, F.addf(i0j0, i1j1));\n n = (n + 1) / 2;\n }\n return b;\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ARRAYS_EQ_H_\n"], ["/longfellow-zk/lib/sumcheck/verifier.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_SUMCHECK_VERIFIER_H_\n#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_VERIFIER_H_\n\n#include \n\n#include \n\n#include \"arrays/dense.h\"\n#include \"random/transcript.h\"\n#include \"sumcheck/circuit.h\"\n#include \"sumcheck/transcript_sumcheck.h\"\n#include \"sumcheck/verifier_layers.h\"\n\nnamespace proofs {\n// Full sumcheck verifier that verifies the layers\n// via verifier_layers<> and then checks the input\n// binding directly.\ntemplate \nclass Verifier : public VerifierLayers {\n using super = VerifierLayers;\n using typename super::claims;\n using typename super::Elt;\n\n public:\n static bool verify(const char** why, const Circuit* circ,\n const Proof* proof,\n std::unique_ptr> V,\n std::unique_ptr> X, Transcript& ts,\n const Field& F) {\n if (why == nullptr || circ == nullptr || proof == nullptr ||\n V == nullptr || X == nullptr) {\n return false;\n }\n\n claims cl{};\n Challenge ch(circ->nl);\n TranscriptSumcheck tss(ts, F);\n tss.write_input(X.get());\n\n if (!(super::circuit(why, &cl, circ, proof, &ch, std::move(V), tss,\n F))) {\n return false;\n }\n\n // Final check on W, the input wires.\n // bind the copy variables:\n X->bind_all(circ->logc, cl.q, F);\n X->reshape(cl.nv);\n\n // bind the gate variables, for two hands:\n auto X1 = X->clone();\n Dense* VH[2] = {X.get(), X1.get()};\n\n for (size_t hand = 0; hand < 2; ++hand) {\n VH[hand]->bind_all(cl.logv, cl.g[hand], F);\n Elt got = VH[hand]->scalar();\n if (got != cl.claim[hand]) {\n *why = \"got != cl.claim[hand]\";\n return false;\n }\n }\n\n return true;\n }\n\n Verifier() = delete;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_VERIFIER_H_\n"], ["/longfellow-zk/lib/circuits/logic/evaluation_backend.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_EVALUATION_BACKEND_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_EVALUATION_BACKEND_H_\n\n#include \"util/panic.h\"\n\nnamespace proofs {\n// backend that evaluates values directly\ntemplate \nclass EvaluationBackend {\n using Elt = typename Field::Elt;\n\n public:\n explicit EvaluationBackend(const Field& F,\n bool panic_on_assertion_failure = true)\n : f_(F),\n panic_on_assertion_failure_(panic_on_assertion_failure),\n assertion_failed_(false) {}\n\n ~EvaluationBackend() {\n // Crash if assertion_failed_, which indicates that a test\n // has forgotten to read the value\n check(!assertion_failed_, \"assertion_failed_ true in ~EvaluationBackend()\");\n }\n\n // Reading ASSERTION_FAILED_ returns the current ASSERTION_FAILED_\n // state and resets the state.\n bool assertion_failed() const {\n bool b = assertion_failed_;\n assertion_failed_ = false;\n return b;\n }\n\n struct V {\n Elt e;\n V() = default;\n explicit V(const Elt& x) : e(x) {}\n Elt elt() const { return e; }\n\n bool operator==(const V& y) const { return e == y.e; }\n bool operator!=(const V& y) const { return e != y.e; }\n };\n\n V assert0(const V& a) const {\n if (a.e == f_.zero()) {\n return a;\n } else {\n if (panic_on_assertion_failure_) {\n check(false, \"a != F.zero()\");\n }\n assertion_failed_ = true;\n }\n return a;\n }\n\n V add(const V& a, const V& b) const { return V{f_.addf(a.e, b.e)}; }\n V sub(const V& a, const V& b) const { return V{f_.subf(a.e, b.e)}; }\n V mul(const V& a, const V& b) const { return V{f_.mulf(a.e, b.e)}; }\n V mul(const Elt& a, const V& b) const { return V{f_.mulf(a, b.e)}; }\n V mul(const Elt& a, const V& b, const V& c) const {\n return mul(a, mul(b, c));\n }\n V konst(const Elt& a) const { return V{a}; }\n\n V ax(const Elt& a, const V& x) const { return V{f_.mulf(a, x.e)}; }\n V axy(const Elt& a, const V& x, const V& y) const {\n return V{f_.mulf(a, f_.mulf(x.e, y.e))};\n }\n V axpy(const V& y, const Elt& a, const V& x) const {\n return V{f_.addf(y.e, f_.mulf(a, x.e))};\n }\n V apy(const V& y, const Elt& a) const { return V{f_.addf(y.e, a)}; }\n\n private:\n const Field& f_;\n bool panic_on_assertion_failure_;\n mutable bool assertion_failed_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_EVALUATION_BACKEND_H_\n"], ["/longfellow-zk/lib/algebra/utility.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_UTILITY_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_UTILITY_H_\n\n#include \n\n#include \n\nnamespace proofs {\ntemplate \nclass AlgebraUtil {\n public:\n using Elt = typename Field::Elt;\n\n // a[i*da] = inverse(b[i*db]), via Montgomery batch inversion\n static void batch_invert(size_t n, Elt a[/*n with stride da*/], size_t da,\n const Elt b[/*n with stride db*/], size_t db,\n const Field& F) {\n Elt p = F.one();\n\n // a[i] \\gets \\prod_{j 0;) {\n F.mul(a[i * da], p);\n F.mul(p, b[i * db]);\n }\n }\n\n // a[i] = 1/i, with a[0]=0\n static void batch_inverse_arithmetic(size_t n, Elt a[/*n*/], const Field& F) {\n a[0] = F.zero();\n // this is essentially batch_inverse with b[i]=bi\n\n Elt p = F.one();\n Elt bi = F.zero();\n\n for (size_t i = 1; i < n; ++i) {\n F.add(bi, F.one());\n a[i] = p;\n F.mul(p, bi);\n }\n\n // now p = \\prod_{j 0;) {\n F.mul(a[i], p);\n F.mul(p, bi);\n F.sub(bi, F.one());\n }\n }\n\n static Elt factorial(uint64_t n, const Field& F) {\n auto p = F.one();\n auto fi = F.one();\n for (uint64_t i = 1; i <= n; ++i) {\n F.mul(p, fi);\n F.add(fi, F.one());\n }\n return p;\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_UTILITY_H_\n"], ["/longfellow-zk/lib/algebra/blas.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_BLAS_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_BLAS_H_\n\n// basic linear algebra subroutines\n#include \n\nnamespace proofs {\ntemplate \nclass Blas {\n public:\n using Elt = typename Field::Elt;\n\n // SUM_{i} x[i * incx].y[i * incy]\n static Elt dot(size_t n, const Elt x[/*n:incx*/], size_t incx,\n const Elt y[/*n:incy*/], size_t incy, const Field& F) {\n Elt r = F.zero();\n for (size_t i = 0; i < n; i++) {\n F.add(r, F.mulf(x[i * incx], y[i * incy]));\n }\n return r;\n }\n\n // SUM_{i} x[i * incx], or the dot product x^T * 1\n static Elt dot1(size_t n, const Elt x[/*n:incx*/], size_t incx,\n const Field& F) {\n Elt r = F.zero();\n for (size_t i = 0; i < n; ++i) {\n F.add(r, x[i * incx]);\n }\n return r;\n }\n\n // y = a*y\n static void scale(size_t n, Elt y[/*k:incy*/], size_t incy, const Elt a,\n const Field& F) {\n for (size_t i = 0; i < n; i++) {\n F.mul(y[i * incy], a);\n }\n }\n\n // y = a*x + y.\n static void axpy(size_t n, Elt y[/*k:incy*/], size_t incy, const Elt a,\n const Elt x[/*k:incx*/], size_t incx, const Field& F) {\n for (size_t i = 0; i < n; i++) {\n F.add(y[i * incy], F.mulf(x[i * incx], a));\n }\n }\n\n // nonstandard axpy() where A[] is itself an array\n static void vaxpy(size_t n, Elt y[/*k:incy*/], size_t incy,\n const Elt a[/*k:inca*/], size_t inca,\n const Elt x[/*k:incx*/], size_t incx, const Field& F) {\n for (size_t i = 0; i < n; i++) {\n F.add(y[i * incy], F.mulf(x[i * incx], a[i * inca]));\n }\n }\n\n // y[i] -= a[i] * x[i]\n static void vymax(size_t n, Elt y[/*k:incy*/], size_t incy,\n const Elt a[/*k:inca*/], size_t inca,\n const Elt x[/*k:incx*/], size_t incx, const Field& F) {\n for (size_t i = 0; i < n; i++) {\n F.sub(y[i * incy], F.mulf(x[i * incx], a[i * inca]));\n }\n }\n\n static bool equal(size_t n, const Elt x[/*n:incx*/], size_t incx,\n const Elt y[/*n:incy*/], size_t incy, const Field& F) {\n for (size_t i = 0; i < n; i++) {\n if (x[i * incx] != y[i * incy]) return false;\n }\n return true;\n }\n\n static bool equal0(size_t n, const Elt x[/*n:incx*/], size_t incx,\n const Field& F) {\n for (size_t i = 0; i < n; i++) {\n if (x[i * incx] != F.zero()) return false;\n }\n return true;\n }\n\n static void copy(size_t n, Elt dst[/*n:incx*/], size_t incd,\n const Elt src[/*n:incy*/], size_t incs) {\n for (size_t i = 0; i < n; i++) {\n dst[i * incd] = src[i * incs];\n }\n }\n\n // DST[i] = SRC[IDX[i]]. DST and SRC must not overlap.\n static void gather(size_t n, Elt dst[/*n*/], const Elt src[],\n const size_t idx[/*n*/]) {\n for (size_t i = 0; i < n; i++) {\n dst[i] = src[idx[i]];\n }\n }\n\n static void clear(size_t n, Elt dst[/*n:incx*/], size_t incd,\n const Field& F) {\n for (size_t i = 0; i < n; i++) {\n dst[i * incd] = F.zero();\n }\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_BLAS_H_\n"], ["/longfellow-zk/lib/util/readbuffer.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_UTIL_READBUFFER_H_\n#define PRIVACY_PROOFS_ZK_LIB_UTIL_READBUFFER_H_\n\n#include \n#include \n#include \n\n#include \"util/panic.h\"\n\nnamespace proofs {\n\nclass ReadBuffer {\n public:\n explicit ReadBuffer(const uint8_t *buf, size_t sz)\n : buf_(buf), size_(sz), next_(0) {}\n\n explicit ReadBuffer(const std::vector &v)\n : ReadBuffer(v.data(), v.size()) {}\n\n // no copies\n ReadBuffer(const ReadBuffer &) = delete;\n\n // TRUE if at least N bytes remain\n bool have(size_t n) const { return remaining() >= n; }\n\n size_t remaining() const {\n check(next_ <= size_, \"next_ <= size_\");\n return size_ - next_;\n }\n\n const uint8_t *next(size_t n) {\n check(have(n), \"have(n)\");\n const uint8_t *p = &buf_[next_];\n next_ += n;\n return p;\n }\n\n void next(size_t n, uint8_t dest[/*n*/]) {\n const uint8_t *p = next(n);\n for (size_t i = 0; i < n; ++i) {\n dest[i] = p[i];\n }\n }\n\n private:\n const uint8_t *buf_;\n size_t size_;\n size_t next_;\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_UTIL_READBUFFER_H_\n"], ["/longfellow-zk/lib/circuits/sha/sha256_test_values.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_SHA256_TEST_VALUES_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_SHA256_TEST_VALUES_H_\n\n#include \n#include \n#include \n\nnamespace proofs {\n\nstruct sha256_testvec {\n const char* str;\n size_t len;\n uint8_t hash[32];\n};\n\n// A set of SHA256 test vectors used to verify the circuit implementation.\nstatic const struct sha256_testvec SHA256_TV[] = {\n {\"\", 0, {0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4,\n 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b,\n 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}},\n {\"abc\", 3, {0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,\n 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,\n 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,\n 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}},\n {\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\",\n 56,\n {0x24, 0x8d, 0x6a, 0x61, 0xd2, 0x06, 0x38, 0xb8, 0xe5, 0xc0, 0x26,\n 0x93, 0x0c, 0x3e, 0x60, 0x39, 0xa3, 0x3c, 0xe4, 0x59, 0x64, 0xff,\n 0x21, 0x67, 0xf6, 0xec, 0xed, 0xd4, 0x19, 0xdb, 0x06, 0xc1}},\n {\"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmno\"\n \"pjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu\",\n 112,\n {0xcf, 0x5b, 0x16, 0xa7, 0x78, 0xaf, 0x83, 0x80, 0x03, 0x6c, 0xe5,\n 0x9e, 0x7b, 0x04, 0x92, 0x37, 0x0b, 0x24, 0x9b, 0x11, 0xe8, 0xf0,\n 0x7a, 0x51, 0xaf, 0xac, 0x45, 0x03, 0x7a, 0xfe, 0xe9, 0xd1}},\n {\"D818590293A66776657273696F6E63312E306F646967657374416C676F726974686D67534\"\n \"8412D32353667646F6354797065756F72672E69736F2E31383031332E352E312E6D444C6C\"\n \"76616C756544696765737473A2716F72672E69736F2E31383031332E352E31A3005820CF9\"\n \"C1CB89584BF8C4176A37C2C954A8DC56077D3BA65EE44011E62AB7C63CE2D0158202F00C7\"\n \"0D5FA9867D7BD2207E0D0B87E35A9AC962A8DE36EE1BE3944B63B39141025820EA9C0339A\"\n \"AF9BAE8\",\n 372,\n {0xc7, 0xce, 0x90, 0x99, 0xbd, 0xb6, 0x41, 0x75, 0x02, 0xb7, 0x3e,\n 0x44, 0xc9, 0x82, 0x7c, 0xd2, 0x95, 0x6c, 0x54, 0x11, 0x0a, 0x39,\n 0xb2, 0x60, 0x67, 0xfb, 0xf7, 0x9f, 0xf8, 0x9b, 0x20, 0xee}},\n\n // test boundary conditions for padding\n // 55 a's\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\n 55,\n {0x9f, 0x43, 0x90, 0xf8, 0xd3, 0x0c, 0x2d, 0xd9, 0x2e, 0xc9, 0xf0,\n 0x95, 0xb6, 0x5e, 0x2b, 0x9a, 0xe9, 0xb0, 0xa9, 0x25, 0xa5, 0x25,\n 0x8e, 0x24, 0x1c, 0x9f, 0x1e, 0x91, 0x0f, 0x73, 0x43, 0x18}},\n // 56 a's\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\n 56,\n {0xb3, 0x54, 0x39, 0xa4, 0xac, 0x6f, 0x09, 0x48, 0xb6, 0xd6, 0xf9,\n 0xe3, 0xc6, 0xaf, 0x0f, 0x5f, 0x59, 0x0c, 0xe2, 0x0f, 0x1b, 0xde,\n 0x70, 0x90, 0xef, 0x79, 0x70, 0x68, 0x6e, 0xc6, 0x73, 0x8a}},\n // 57 a's\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\n 57,\n {0xf1, 0x3b, 0x2d, 0x72, 0x46, 0x59, 0xeb, 0x3b, 0xf4, 0x7f, 0x2d,\n 0xd6, 0xaf, 0x1a, 0xcc, 0xc8, 0x7b, 0x81, 0xf0, 0x9f, 0x59, 0xf2,\n 0xb7, 0x5e, 0x5c, 0x0b, 0xed, 0x65, 0x89, 0xdf, 0xe8, 0xc6}},\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\n 63,\n {0x7d, 0x3e, 0x74, 0xa0, 0x5d, 0x7d, 0xb1, 0x5b, 0xce, 0x4a, 0xd9,\n 0xec, 0x06, 0x58, 0xea, 0x98, 0xe3, 0xf0, 0x6e, 0xee, 0xcf, 0x16,\n 0xb4, 0xc6, 0xff, 0xf2, 0xda, 0x45, 0x7d, 0xdc, 0x2f, 0x34}},\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\n 64,\n {0xff, 0xe0, 0x54, 0xfe, 0x7a, 0xe0, 0xcb, 0x6d, 0xc6, 0x5c, 0x3a,\n 0xf9, 0xb6, 0x1d, 0x52, 0x09, 0xf4, 0x39, 0x85, 0x1d, 0xb4, 0x3d,\n 0x0b, 0xa5, 0x99, 0x73, 0x37, 0xdf, 0x15, 0x46, 0x68, 0xeb}},\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\n 65,\n {0x63, 0x53, 0x61, 0xc4, 0x8b, 0xb9, 0xea, 0xb1, 0x41, 0x98, 0xe7,\n 0x6e, 0xa8, 0xab, 0x7f, 0x1a, 0x41, 0x68, 0x5d, 0x6a, 0xd6, 0x2a,\n 0xa9, 0x14, 0x6d, 0x30, 0x1d, 0x4f, 0x17, 0xeb, 0x0a, 0xe0}},\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\n 66,\n {0xac, 0x13, 0x7f, 0xce, 0x49, 0x83, 0x7c, 0x7c, 0x29, 0x45, 0xf6,\n 0x16, 0x0d, 0x3c, 0x0e, 0x67, 0x9e, 0x6f, 0x40, 0x07, 0x08, 0x50,\n 0x42, 0x0a, 0x22, 0xbc, 0x10, 0xe0, 0x69, 0x2c, 0xbd, 0xc7}},\n // 2 block boundary conditions\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbb\"\n \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\n 118,\n {0x16, 0x1f, 0x88, 0x3d, 0xfb, 0x71, 0x6c, 0x8a, 0xcf, 0x49, 0x6c,\n 0x04, 0x78, 0x8d, 0x42, 0xf8, 0x0c, 0xe2, 0x21, 0x50, 0x4a, 0xfa,\n 0x81, 0x63, 0xc0, 0xe7, 0x3b, 0x11, 0xb5, 0xd2, 0x5f, 0xd0}},\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbb\"\n \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc\",\n 119,\n {0x6c, 0x17, 0x1b, 0xd6, 0x6a, 0x89, 0x03, 0x44, 0xee, 0x32, 0xde,\n 0x77, 0xe9, 0xdb, 0x13, 0xc0, 0x18, 0x23, 0xac, 0x16, 0xc6, 0xf4,\n 0x76, 0x67, 0x69, 0xd8, 0xa3, 0xf4, 0x91, 0x27, 0xda, 0x98}},\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbb\"\n \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccc\",\n 126,\n {0x8c, 0xfb, 0x31, 0xd1, 0x1d, 0xd7, 0x6e, 0xfb, 0x8c, 0x70, 0x38,\n 0xa5, 0x09, 0xb9, 0x80, 0x69, 0xbb, 0xb7, 0xa6, 0x04, 0x67, 0x55,\n 0xc5, 0x5b, 0x10, 0x83, 0x9e, 0xd8, 0x72, 0x39, 0x9b, 0x9c}},\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbb\"\n \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccd\",\n 127,\n {0xf4, 0xaf, 0x59, 0x2b, 0xd9, 0x85, 0xc2, 0x48, 0x66, 0x64, 0x61,\n 0x9a, 0xff, 0xd7, 0xf6, 0xe1, 0x97, 0x8d, 0x9b, 0x24, 0x01, 0x7c,\n 0xe8, 0x63, 0x82, 0x83, 0x62, 0xa1, 0xcd, 0xcd, 0x33, 0xfc}},\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbb\"\n \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccdd\",\n 128,\n {0xdb, 0x2c, 0x2b, 0xe4, 0xf8, 0x50, 0xcf, 0xd4, 0x2d, 0xce, 0x67,\n 0x8b, 0xe2, 0x63, 0xa9, 0xbb, 0x74, 0x26, 0xf6, 0xbf, 0x39, 0x12,\n 0x8e, 0x9e, 0x75, 0xd3, 0xa3, 0xbd, 0x02, 0x31, 0x64, 0x9a}},\n {\"\\x00\", 1, {0x6e, 0x34, 0x0b, 0x9c, 0xff, 0xb3, 0x7a, 0x98,\n 0x9c, 0xa5, 0x44, 0xe6, 0xbb, 0x78, 0x0a, 0x2c,\n 0x78, 0x90, 0x1d, 0x3f, 0xb3, 0x37, 0x38, 0x76,\n 0x85, 0x11, 0xa3, 0x06, 0x17, 0xaf, 0xa0, 0x1d}},\n {\"\\x00\\x01\", 2, {0xb4, 0x13, 0xf4, 0x7d, 0x13, 0xee, 0x2f, 0xe6,\n 0xc8, 0x45, 0xb2, 0xee, 0x14, 0x1a, 0xf8, 0x1d,\n 0xe8, 0x58, 0xdf, 0x4e, 0xc5, 0x49, 0xa5, 0x8b,\n 0x79, 0x70, 0xbb, 0x96, 0x64, 0x5b, 0xc8, 0xd2}},\n {\"\\x00\\x01\\x02\", 3, {0xae, 0x4b, 0x32, 0x80, 0xe5, 0x6e, 0x2f, 0xaf,\n 0x83, 0xf4, 0x14, 0xa6, 0xe3, 0xda, 0xbe, 0x9d,\n 0x5f, 0xbe, 0x18, 0x97, 0x65, 0x44, 0xc0, 0x5f,\n 0xed, 0x12, 0x1a, 0xcc, 0xb8, 0x5b, 0x53, 0xfc}},\n {\"\\x00\\x01\\x02\\x03\", 4, {0x05, 0x4e, 0xde, 0xc1, 0xd0, 0x21, 0x1f, 0x62,\n 0x4f, 0xed, 0x0c, 0xbc, 0xa9, 0xd4, 0xf9, 0x40,\n 0x0b, 0x0e, 0x49, 0x1c, 0x43, 0x74, 0x2a, 0xf2,\n 0xc5, 0xb0, 0xab, 0xeb, 0xf0, 0xc9, 0x90, 0xd8}},\n};\n\n// Sample input-output pairs for the block transform.\nstruct SHA256BlockTests {\n uint32_t input[16];\n uint32_t h[8];\n uint32_t want[8];\n};\n\nstatic const struct SHA256BlockTests kSha_bt_[] = {\n {\n {\n 0,\n 0xdeadbeef,\n 0xbd5b7dde,\n 0x9c093ccd,\n 0x7ab6fbbc,\n 0x5964baab,\n 0x3812799a,\n 0x16c03889,\n 0xf56df778,\n 0xd41bb667,\n 0xb2c97556,\n 0x91773445,\n 0x7024f334,\n 0x4ed2b223,\n 0x2d807112,\n 0xc2e3001,\n },\n {0, 0xabadcafe, 0x575b95fc, 0x30960fa, 0xaeb72bf8, 0x5a64f6f6,\n 0x612c1f4, 0xb1c08cf2},\n {\n 0x656f967b,\n 0x508cb605,\n 0x109902c5,\n 0xbe9909c,\n 0x30ed1bc6,\n 0x8d3bb28c,\n 0x836c99a8,\n 0x30731a12,\n },\n },\n {\n {\n 0x7,\n 0xe,\n 0x15,\n 0x1c,\n 0x23,\n 0x2a,\n 0x31,\n 0x38,\n 0x3f,\n 0x46,\n 0x4d,\n 0x54,\n 0x5b,\n 0x62,\n 0x69,\n 0x70,\n },\n {0x0, 0x13, 0x26, 0x39, 0x4c, 0x5f, 0x72, 0x85},\n {\n 0x95ddd507,\n 0x1a7a4b1f,\n 0xf5951676,\n 0x105a25a3,\n 0x511cee03,\n 0xd0972a96,\n 0xb1cb76d7,\n 0xf9f46d72,\n },\n },\n {\n {\n 0xf0cee5d1,\n 0x615dfa6a,\n 0xbda82adf,\n 0xcb66fb25,\n 0x30d60637,\n 0xb1018af9,\n 0x2c5c0e06,\n 0xb0556e74,\n 0xf8e2da1f,\n 0xf05b699b,\n 0xabbf6d16,\n 0x3377e5ad,\n 0x46d8cd9e,\n 0xcc01d8dd,\n 0x5532a535,\n 0x34e928ea,\n },\n {\n 0x515f007c,\n 0x5bd062c2,\n 0x12200854,\n 0x4db127f8,\n 0x216231b,\n 0x1f16e9e8,\n 0x1190cde7,\n 0x66ef438d,\n },\n {\n 0x3a3995a,\n 0xb55e568e,\n 0x5fb4b933,\n 0x97c9e9c0,\n 0xaea7d67c,\n 0xaee17ae4,\n 0xcfffacb8,\n 0x91d6ab5e,\n },\n }};\n\n// Output values for SHA256(a^k) for various values of k used in the\n// benchmarking results.\nstruct sha256_bench {\n size_t len;\n uint8_t hash[32];\n};\n\nstatic const struct sha256_bench kSha_benchmark_[] = {\n {50, {0x16, 0x0b, 0x4e, 0x43, 0x3e, 0x38, 0x4e, 0x05, 0xe5, 0x37, 0xdc,\n 0x59, 0xb4, 0x67, 0xf7, 0xcb, 0x24, 0x03, 0xf0, 0x21, 0x4d, 0xb1,\n 0x5c, 0x5d, 0xb5, 0x88, 0x62, 0xa3, 0xf1, 0x15, 0x6d, 0x2e}},\n {114, {0x6c, 0xb7, 0x50, 0xb2, 0x18, 0x16, 0x06, 0x51, 0x1f, 0x4a, 0x7e,\n 0x47, 0x86, 0xb5, 0x36, 0x92, 0xf5, 0x1a, 0x9c, 0xdc, 0x4d, 0x31,\n 0x72, 0xfd, 0xcf, 0xb9, 0x26, 0x7a, 0xec, 0xa7, 0xe4, 0xe4}},\n {178, {0xca, 0xad, 0x4b, 0x2f, 0xbb, 0x83, 0x0f, 0xa5, 0x40, 0x02, 0xa1,\n 0x67, 0x5f, 0x15, 0x99, 0xd9, 0xb0, 0x92, 0xcd, 0x39, 0x8a, 0xd6,\n 0xfb, 0xb8, 0x16, 0xbf, 0xe8, 0xf9, 0x48, 0xcd, 0xd6, 0x20}},\n {242, {0x8f, 0xde, 0xd5, 0x9c, 0x42, 0x7b, 0x2e, 0x68, 0x09, 0xc8, 0x10,\n 0x91, 0x5a, 0xac, 0xa9, 0x63, 0x57, 0x32, 0xa1, 0xde, 0xcc, 0x4b,\n 0xa2, 0xac, 0x8e, 0x0a, 0x1d, 0x90, 0xfc, 0x10, 0x92, 0xc9}},\n {306, {0x4c, 0xef, 0xdb, 0xa1, 0xba, 0x8d, 0x39, 0x75, 0xf3, 0x2c, 0xba,\n 0xc9, 0xf2, 0x27, 0xc7, 0xe6, 0xb6, 0xe6, 0x63, 0x43, 0x9e, 0x79,\n 0x85, 0x61, 0x6b, 0xbb, 0x5c, 0x61, 0x82, 0x4d, 0xbb, 0x0c}},\n {370, {0x27, 0xdd, 0xc5, 0x8e, 0xcc, 0x58, 0xfd, 0x86, 0x93, 0x37, 0x48,\n 0x1a, 0xf7, 0x73, 0x02, 0xd5, 0x4d, 0xd5, 0xba, 0x91, 0x84, 0x21,\n 0x44, 0xf8, 0x7d, 0xeb, 0x83, 0x24, 0x09, 0x06, 0x9d, 0x0b}},\n {434, {0xd9, 0x67, 0xcc, 0x55, 0x05, 0x9d, 0x00, 0x82, 0xb6, 0xb2, 0x47,\n 0xd2, 0xa7, 0xd7, 0xfb, 0x79, 0xb7, 0xdd, 0xed, 0xa9, 0x7b, 0xe5,\n 0x92, 0x7d, 0xf4, 0x0c, 0xf9, 0x64, 0x2c, 0xee, 0xc6, 0xd3}},\n {498, {0x40, 0x47, 0x02, 0x9c, 0x99, 0xeb, 0x4e, 0xf6, 0x39, 0x25, 0x9b,\n 0x2e, 0xe3, 0xc8, 0xde, 0xb4, 0x40, 0x90, 0x86, 0xc8, 0x1d, 0xe1,\n 0xcd, 0xab, 0x00, 0x53, 0xbb, 0xcc, 0x08, 0x84, 0xe4, 0x1e}},\n {562, {0x3e, 0x47, 0xed, 0x99, 0x0d, 0x31, 0xf0, 0xfe, 0xb0, 0xa7, 0x77,\n 0x1c, 0x72, 0xd1, 0x32, 0x0f, 0xad, 0x55, 0x58, 0x14, 0xf7, 0x81,\n 0x95, 0x6e, 0xfc, 0x89, 0xda, 0x88, 0x4f, 0xf6, 0x3d, 0x40}},\n {626, {0xc6, 0x20, 0x91, 0x3d, 0xad, 0x86, 0x0a, 0x2a, 0x77, 0x3d, 0x9d,\n 0x56, 0x0c, 0x2c, 0xed, 0x25, 0x03, 0xf6, 0xf9, 0xe2, 0xc5, 0x5c,\n 0xcd, 0x65, 0x08, 0x3b, 0xf0, 0x53, 0x2d, 0x60, 0x62, 0x61}},\n {690, {0x21, 0x8d, 0xb2, 0x31, 0x17, 0xd4, 0x98, 0x63, 0x1b, 0xfc, 0x22,\n 0x96, 0x49, 0x9a, 0xb2, 0x7e, 0x07, 0x2c, 0xce, 0xf4, 0xfa, 0xea,\n 0xca, 0x63, 0xe5, 0xa2, 0xec, 0xcc, 0x7e, 0x22, 0xf4, 0xac}},\n {754, {0x29, 0x2c, 0x65, 0x83, 0xeb, 0xe8, 0x2f, 0xee, 0xec, 0xed, 0x13,\n 0xa8, 0x6b, 0xdb, 0x83, 0x8a, 0x15, 0xaf, 0xcc, 0x5b, 0xf4, 0x7f,\n 0x2a, 0xcf, 0x51, 0x51, 0x50, 0x7e, 0xae, 0x03, 0xd7, 0x7c}},\n {818, {0x5f, 0x99, 0x78, 0x83, 0x81, 0x11, 0x36, 0x98, 0x23, 0x16, 0x54,\n 0xd9, 0x80, 0xfc, 0x73, 0x8d, 0x8e, 0x19, 0x11, 0xc6, 0xa3, 0x0d,\n 0xe8, 0xcb, 0x33, 0xa2, 0x9e, 0xf7, 0xc1, 0xed, 0xc3, 0x19}},\n {882, {0x5f, 0x2e, 0xb1, 0xec, 0x0f, 0xd7, 0x93, 0x76, 0xc4, 0x8a, 0xfc,\n 0x9c, 0x15, 0xd1, 0x98, 0x64, 0x94, 0x20, 0x5f, 0x69, 0x08, 0x36,\n 0x43, 0xb9, 0xd6, 0x9a, 0x05, 0x85, 0xf4, 0xfb, 0xdc, 0x5f}},\n {946, {0xe8, 0x06, 0x78, 0xdf, 0xad, 0xb0, 0x70, 0x4e, 0x5e, 0x68, 0x4a,\n 0xda, 0x0b, 0x0b, 0xe7, 0xac, 0x2f, 0x22, 0x54, 0x7f, 0x13, 0x04,\n 0xfe, 0x9a, 0xb4, 0xaa, 0xa7, 0x30, 0xd9, 0x90, 0x9a, 0x3a}},\n {1010, {0x69, 0x4d, 0x24, 0xc6, 0x82, 0x83, 0xb9, 0x9a, 0xd5, 0xee, 0x5c,\n 0xea, 0xa3, 0x5d, 0x9d, 0xe4, 0xdd, 0x55, 0x45, 0xdd, 0x7a, 0x38,\n 0x5f, 0x4b, 0x18, 0xfa, 0x85, 0xb2, 0xdc, 0x6d, 0xe2, 0xba}},\n {1074, {0x55, 0xd2, 0xfe, 0x88, 0x80, 0x0f, 0x6b, 0xcb, 0xe7, 0xce, 0xa2,\n 0x98, 0xf4, 0x88, 0xa7, 0xc8, 0x41, 0xd4, 0x03, 0x9f, 0x3f, 0xf3,\n 0xf0, 0xc6, 0xea, 0x2f, 0xa5, 0x40, 0x84, 0xf4, 0xa0, 0xdf}},\n {1138, {0xa3, 0x38, 0x31, 0x67, 0x79, 0x4a, 0x75, 0x6d, 0x88, 0x9a, 0x7a,\n 0x99, 0xf4, 0x15, 0x79, 0x4d, 0xe9, 0xdf, 0xeb, 0x21, 0x67, 0x2c,\n 0xd1, 0x04, 0x41, 0xcf, 0xfd, 0x93, 0xdb, 0xd8, 0x20, 0x5a}},\n {1202, {0xdb, 0xb3, 0x3f, 0x50, 0xf1, 0xc7, 0xb1, 0xd9, 0x28, 0x63, 0x2f,\n 0x81, 0x35, 0x08, 0x6a, 0x58, 0xc2, 0x6a, 0x66, 0x55, 0x3b, 0xd2,\n 0x27, 0x7e, 0x4f, 0x9a, 0x5f, 0x00, 0x61, 0xc6, 0xcc, 0x25}},\n {1266, {0xeb, 0xdd, 0x77, 0xc4, 0x04, 0x96, 0xa9, 0xeb, 0x3f, 0xf9, 0x24,\n 0xf4, 0xcf, 0xb5, 0x4e, 0xee, 0xb2, 0xc6, 0xf5, 0x04, 0x26, 0xb1,\n 0xca, 0x2f, 0xd4, 0xd9, 0x72, 0x83, 0xd8, 0x49, 0x72, 0xce}},\n {1330, {0x05, 0x3b, 0xbf, 0x41, 0xf3, 0x3d, 0xad, 0x63, 0x5a, 0x69, 0x03,\n 0xca, 0x32, 0x8f, 0x2e, 0xfd, 0x98, 0x87, 0x70, 0x2a, 0x3e, 0x02,\n 0x1e, 0x6a, 0xac, 0x55, 0x9c, 0x53, 0x53, 0xec, 0x43, 0x41}},\n {1394, {0xf2, 0xda, 0xba, 0x28, 0x4a, 0x48, 0xf7, 0xc6, 0x8f, 0x72, 0x9a,\n 0x17, 0x2b, 0x26, 0x3a, 0xaf, 0x97, 0xd8, 0x0c, 0x57, 0xab, 0xba,\n 0x9b, 0xec, 0xa6, 0x75, 0xb9, 0x4c, 0xcb, 0x6e, 0x9d, 0xa7}},\n {1458, {0x20, 0x2f, 0x4f, 0x63, 0xe9, 0x31, 0x90, 0x1a, 0xe1, 0xcb, 0x8d,\n 0x42, 0x1d, 0x16, 0x9b, 0x12, 0x78, 0x2a, 0x58, 0x51, 0xca, 0x49,\n 0x73, 0x72, 0xf4, 0xf4, 0x7c, 0x6f, 0xea, 0xc7, 0x61, 0x1d}},\n {1522, {0xee, 0x97, 0x06, 0xa8, 0xbd, 0x8b, 0x8f, 0xbe, 0x96, 0xa9, 0xff,\n 0x52, 0xb7, 0xc6, 0x36, 0x02, 0x80, 0x70, 0x5f, 0x74, 0xbe, 0x73,\n 0xb8, 0x65, 0x5b, 0xdb, 0x8d, 0x56, 0x07, 0x61, 0xa7, 0xad}},\n {1586, {0x60, 0xd6, 0x6a, 0xa2, 0x83, 0xbf, 0x1c, 0xed, 0x60, 0x6f, 0xa6,\n 0x40, 0x73, 0xf4, 0x36, 0x3d, 0xed, 0x46, 0x92, 0x4e, 0x93, 0xbe,\n 0x67, 0xb8, 0x19, 0x0b, 0x04, 0xa5, 0x70, 0xab, 0x4a, 0xb5}},\n {1650, {0x93, 0x32, 0xff, 0xe0, 0x58, 0x84, 0xbf, 0x8f, 0xdd, 0x09, 0x2f,\n 0x94, 0x43, 0x22, 0x57, 0x28, 0x4f, 0x9c, 0x23, 0x2a, 0x72, 0xe5,\n 0xaa, 0x3b, 0x9b, 0x11, 0xda, 0xc4, 0x57, 0xe3, 0x46, 0x34}},\n {1714, {0xd3, 0x47, 0xa1, 0xbe, 0xf9, 0xea, 0x05, 0x0d, 0xe5, 0x06, 0x2e,\n 0x27, 0x86, 0x72, 0x7d, 0x2b, 0x4c, 0xcb, 0x60, 0x77, 0x7c, 0x82,\n 0xf9, 0x7c, 0xd7, 0x58, 0xfa, 0x44, 0x27, 0x35, 0x51, 0x42}},\n {1778, {0xdd, 0xf6, 0x34, 0x5e, 0x0e, 0xd2, 0x19, 0x75, 0x06, 0xac, 0x22,\n 0x9f, 0x3b, 0x5f, 0x53, 0xe8, 0xc0, 0x44, 0x24, 0x1d, 0xf6, 0x52,\n 0x72, 0x79, 0xdd, 0x08, 0xa1, 0x2c, 0xbf, 0x75, 0x9f, 0x5e}},\n {1842, {0xd3, 0xc1, 0x90, 0xe9, 0x4b, 0x65, 0xd4, 0xd6, 0x87, 0xf4, 0xa0,\n 0x14, 0xc6, 0x9a, 0x21, 0x93, 0x87, 0x64, 0x19, 0xcc, 0xa9, 0xa4,\n 0x11, 0xf5, 0xdb, 0x10, 0x03, 0x29, 0xb2, 0x44, 0xe7, 0x98}},\n {1906, {0x5a, 0x13, 0x1d, 0xa8, 0x27, 0xb8, 0x8a, 0x0e, 0x43, 0x40, 0x7b,\n 0x2b, 0x61, 0x5a, 0x9b, 0x39, 0x1f, 0x80, 0xee, 0x45, 0xab, 0x70,\n 0x55, 0x6c, 0x13, 0xa4, 0x72, 0xe2, 0xa6, 0xf5, 0x79, 0xb3}},\n {1970, {0x36, 0xaf, 0x67, 0x22, 0xf2, 0xf8, 0x6f, 0x99, 0x3d, 0x5f, 0x36,\n 0x02, 0xc3, 0x1f, 0x3d, 0xea, 0xbd, 0x34, 0xdc, 0xf1, 0xe4, 0xe4,\n 0x78, 0x73, 0x05, 0x20, 0xea, 0xec, 0xf8, 0x71, 0x76, 0xac}},\n {2034, {0xad, 0x21, 0x5f, 0x13, 0xa8, 0xf7, 0x7d, 0xa1, 0xd0, 0x15, 0xc3,\n 0x5a, 0xdd, 0xee, 0xf8, 0x08, 0x54, 0x79, 0x51, 0xa0, 0x1b, 0x06,\n 0x58, 0x0d, 0x06, 0x31, 0x29, 0x3a, 0xab, 0x6b, 0x24, 0x31}},\n {2098, {0x5b, 0xff, 0x21, 0x09, 0x0b, 0x8c, 0x80, 0xcf, 0xaf, 0x9c, 0xae,\n 0x93, 0x11, 0x75, 0x05, 0x3e, 0xb2, 0x37, 0x9b, 0xa4, 0xe5, 0xd5,\n 0xa1, 0x2a, 0x60, 0x7c, 0x55, 0x57, 0x72, 0x10, 0xf0, 0xb3}},\n {2162, {0xad, 0x56, 0x0c, 0xd1, 0x7d, 0x76, 0x14, 0x5f, 0x19, 0x34, 0x14,\n 0x78, 0x31, 0x88, 0x89, 0xdc, 0x35, 0x58, 0xb1, 0x83, 0xed, 0xd4,\n 0x6a, 0x80, 0x07, 0x82, 0x93, 0xdf, 0x94, 0xd9, 0x35, 0x43}},\n {2226, {0x49, 0x2d, 0x5a, 0x85, 0xfc, 0x33, 0x49, 0xc1, 0x01, 0x83, 0xb0,\n 0x54, 0x80, 0x3c, 0x6d, 0x97, 0x52, 0x8d, 0xcf, 0x61, 0x5b, 0x7a,\n 0x6f, 0xfa, 0x12, 0x97, 0xee, 0x46, 0x3b, 0x48, 0x0b, 0x08}},\n {2290, {0x9b, 0xfc, 0x47, 0x6b, 0xc9, 0x7e, 0x17, 0x78, 0xd9, 0x20, 0x9f,\n 0x8e, 0x1f, 0x5b, 0xa5, 0x79, 0x1d, 0xad, 0x62, 0xb0, 0x9d, 0xf2,\n 0x45, 0x33, 0x17, 0x4e, 0xf6, 0x8f, 0x3a, 0x04, 0xfb, 0x11}},\n {2354, {0x7a, 0xbb, 0x72, 0xe9, 0x1a, 0xb0, 0x42, 0x7d, 0xf0, 0x33, 0xaa,\n 0xb7, 0x21, 0xaa, 0x8c, 0x0a, 0xd0, 0x73, 0xe7, 0xd0, 0xea, 0x03,\n 0x40, 0x15, 0xda, 0x17, 0x9c, 0xe7, 0x85, 0xf1, 0x0e, 0x1e}},\n {2418, {0x21, 0xc6, 0xcc, 0xdb, 0x95, 0x84, 0x53, 0x12, 0xe3, 0xc9, 0x35,\n 0xff, 0xb8, 0xff, 0x69, 0xc2, 0x6e, 0x00, 0x4e, 0x9c, 0x10, 0x80,\n 0xb0, 0x0d, 0x82, 0xfb, 0x17, 0x77, 0x98, 0x23, 0x52, 0x66}},\n {2482, {0xda, 0x0f, 0x57, 0x79, 0x4d, 0x99, 0x1e, 0x88, 0xd7, 0x4e, 0x03,\n 0x86, 0x63, 0x2a, 0xeb, 0x24, 0xc8, 0x60, 0xe8, 0xc7, 0xff, 0x62,\n 0x5d, 0x5a, 0xd1, 0x20, 0x03, 0x0c, 0x78, 0xb5, 0xba, 0x62}}};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_SHA256_TEST_VALUES_H_\n"], ["/longfellow-zk/lib/algebra/fp_p128.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_P128_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_P128_H_\n\n#include \n#include \n\n#include \"algebra/fp_generic.h\"\n#include \"algebra/nat.h\"\n#include \"algebra/sysdep.h\"\n\nnamespace proofs {\n// Optimized implementation of Fp(2^128 - 2^108 + 1). We call this\n// prime P128 because of lack of imagination, but unlike P256,\n// this is not a NIST standard name. The field contains\n// roots of unity of order 2^108.\n\n// Root of unity from pari-gp:\n// ? p=2^128-2^108+1\n// %1 = 340282042402384805036647824275747635201\n// ? g=ffgen(x+Mod(1,p))\n// %2 = 340282042402384805036647824275747635200\n// ? w=sqrtn(g,2^107)\n// %3 = 17166008163159356379329005055841088858\n//\n// ? w=Mod(17166008163159356379329005055841088858, p)\n// %4 = Mod(17166008163159356379329005055841088858,\n// 340282042402384805036647824275747635201)\n// ? w^(2^107)\n// %5 = Mod(340282042402384805036647824275747635200,\n// 340282042402384805036647824275747635201)\n// ? w^(2^108)\n// %6 = Mod(1, 340282042402384805036647824275747635201)\n//\n// Root of unity of order 32:\n// ? w32=w^(2^(108-32))\n// %15 = Mod(164956748514267535023998284330560247862,\n// 340282042402384805036647824275747635201)\n// ? w32^(2^31)\n// %16 = Mod(340282042402384805036647824275747635200,\n// 340282042402384805036647824275747635201)\n// ? w32^(2^32)\n// %17 = Mod(1, 340282042402384805036647824275747635201)\n\n/*\nThis struct contains an optimized reduction step for the chosen field.\n*/\nstruct Fp128Reduce {\n // Harcoded base_64 modulus.\n static const constexpr std::array kModulus = {\n 0x0000000000000001u,\n 0xFFFFF00000000000u,\n };\n\n static inline void reduction_step(uint64_t a[], uint64_t mprime,\n const Nat<2>& m) {\n uint64_t r = -a[0];\n uint64_t sub[2] = {r << 44, r >> 20};\n uint64_t add[3] = {r, 0, r};\n accum(4, a, 3, add);\n negaccum(3, a + 1, 2, sub);\n }\n\n static inline void reduction_step(uint32_t a[], uint32_t mprime,\n const Nat<2>& m) {\n uint32_t r = -a[0];\n uint32_t sub[2] = {r << 12, r >> 20};\n uint32_t add[5] = {r, 0, 0, 0, r};\n accum(6, a, 5, add);\n negaccum(3, a + 3, 2, sub);\n }\n};\n\ntemplate \nusing Fp128 = FpGeneric<2, optimized_mul, Fp128Reduce>;\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_P128_H_\n"], ["/longfellow-zk/lib/algebra/fp_p256.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_P256_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_P256_H_\n\n#include \n#include \n\n#include \"algebra/fp_generic.h\"\n#include \"algebra/nat.h\"\n#include \"algebra/sysdep.h\"\n\nnamespace proofs {\n// Optimized implementation of\n// Fp(115792089210356248762697446949407573530086143415290314195533631308867097853951)\n\n/*\nThis struct contains an optimized reduction step for the chosen field.\n*/\nstruct Fp256Reduce {\n // Harcoded base_64 modulus.\n static const constexpr std::array kModulus = {\n 0xFFFFFFFFFFFFFFFFu,\n 0xFFFFFFFFu,\n 0,\n 0xFFFFFFFF00000001u,\n };\n\n static inline void reduction_step(uint64_t a[], uint64_t mprime,\n const Nat<4>& m) {\n uint64_t r = a[0];\n uint64_t l[5] = {r, 0, 0, r << 32, r >> 32};\n negaccum(6, a, 5, l);\n uint64_t h[4] = {r << 32, r >> 32, r, r};\n accum(5, a + 1, 4, h);\n }\n\n static inline void reduction_step(uint32_t a[], uint32_t mprime,\n const Nat<4>& m) {\n uint32_t r = a[0];\n uint32_t l[8] = {r, 0, 0, 0, 0, 0, 0, r};\n negaccum(10, a, 8, l);\n uint32_t h[6] = {r, 0, 0, r, 0, r};\n accum(7, a + 3, 6, h);\n }\n};\n\ntemplate \nusing Fp256 = FpGeneric<4, optimized_mul, Fp256Reduce>;\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_P256_H_\n"], ["/longfellow-zk/lib/gf2k/gf2poly.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_GF2K_GF2POLY_H_\n#define PRIVACY_PROOFS_ZK_LIB_GF2K_GF2POLY_H_\n\n#include \n#include \n#include \n\n#include \"algebra/limb.h\"\n\nnamespace proofs {\n\n// Rough equivalent of Nat but representing polynomials\n// over GF2 instead of natural numbers.\ntemplate \nclass GF2Poly : public Limb {\n public:\n using Super = Limb;\n using T = GF2Poly;\n using Super::kLimbs;\n using Super::kU64;\n using Super::limb_;\n\n GF2Poly() = default; // uninitialized\n explicit GF2Poly(uint64_t x) : Super(x) {}\n\n explicit GF2Poly(const std::array& a) : Super(a) {}\n\n bool operator<(const T& other) const {\n for (size_t i = kLimbs; i-- > 0;) {\n if (limb_[i] < other.limb_[i]) {\n return true;\n }\n if (limb_[i] > other.limb_[i]) {\n return false;\n }\n }\n return false;\n }\n\n // Interpret A[] as a little-endian nat\n static T of_bytes(const uint8_t a[/* kBytes */]) {\n T r;\n for (size_t i = 0; i < kLimbs; ++i) {\n a = Super::of_bytes(&r.limb_[i], a);\n }\n return r;\n }\n\n T& add(const T& y) {\n for (size_t i = 0; i < kLimbs; ++i) {\n limb_[i] ^= y.limb_[i];\n }\n return *this;\n }\n T& sub(const T& y) { return add(y); }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_GF2K_GF2POLY_H_\n"], ["/longfellow-zk/lib/algebra/fp.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_H_\n\n#include \n\n#include \"algebra/fp_generic.h\"\n#include \"algebra/sysdep.h\"\n\nnamespace proofs {\n\n/*\nThe FpReduce structure factors out the main routine for performing modular\nreduction wrt to a Montgomery-represented field element in the FpGeneric\nclass. This struct contains a generic reduction step that always works,\nbut it can be specialized for certain primes to achieve better efficiency as\ndone with our 128- and 256- bit fields.\n*/\nstruct FpReduce {\n template \n static inline void reduction_step(limb_t a[], limb_t mprime, const N& m) {\n constexpr size_t kLimbs = N::kLimbs;\n if (kLimbs == 1) {\n // The general case (below) represents the (kLimbs+1)-word product as\n // L+(H<<64), where in general L and H overlap, requiring\n // two additions. For kLimbs==1, L and H do not overlap, and we can\n // interpret [L, H] as a single double-precision number.\n limb_t lh[2];\n limb_t r = mprime * a[0];\n mulhl(1, lh, lh + 1, r, m.limb_);\n accum(3, a, 2, lh);\n } else {\n limb_t l[kLimbs], h[kLimbs];\n limb_t r = mprime * a[0];\n mulhl(kLimbs, l, h, r, m.limb_);\n accum(kLimbs + 2, a, kLimbs, l);\n accum(kLimbs + 1, a + 1, kLimbs, h);\n }\n }\n};\n\ntemplate \nusing Fp = FpGeneric;\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_test_attributes.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_TEST_ATTRIBUTES_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_TEST_ATTRIBUTES_H_\n\n#include \"circuits/mdoc/mdoc_zk.h\"\n\nnamespace proofs {\nnamespace test {\nstatic const RequestedAttribute age_over_18 = {\n {'a', 'g', 'e', '_', 'o', 'v', 'e', 'r', '_', '1', '8'},\n {0xf5},\n 11,\n 1,\n kPrimitive};\n\nstatic const RequestedAttribute not_over_18 = {\n .id = {'a', 'g', 'e', '_', 'o', 'v', 'e', 'r', '_', '1', '8'},\n .value = {0xf4},\n .id_len = 11,\n .value_len = 1,\n .type = kPrimitive};\n\nstatic const RequestedAttribute familyname_mustermann = {\n .id = {'f', 'a', 'm', 'i', 'l', 'y', '_', 'n', 'a', 'm', 'e'},\n .value = {'M', 'u', 's', 't', 'e', 'r', 'm', 'a', 'n', 'n'},\n .id_len = 11,\n .value_len = 10,\n .type = kString};\n\nstatic const RequestedAttribute birthdate_1971_09_01 = {\n .id = {'b', 'i', 'r', 't', 'h', '_', 'd', 'a', 't', 'e'},\n .value = {'1', '9', '7', '1', '-', '0', '9', '-', '0', '1'},\n .id_len = 10,\n .value_len = 10,\n .type = kDate};\n\nstatic const RequestedAttribute birthdate_1998_09_04 = {\n .id = {'b', 'i', 'r', 't', 'h', '_', 'd', 'a', 't', 'e'},\n .value = {'1', '9', '9', '8', '-', '0', '9', '-', '0', '4'},\n .id_len = 10,\n .value_len = 10,\n .type = kDate};\n\nstatic const RequestedAttribute height_175 = {\n {'h', 'e', 'i', 'g', 'h', 't'}, {0x18, 0xaf}, 6, 2, kInt};\n\nstatic const RequestedAttribute issue_date_2024_03_15 = {\n {'i', 's', 's', 'u', 'e', '_', 'd', 'a', 't', 'e'},\n {'2', '0', '2', '4', '-', '0', '3', '-', '1', '5'},\n 10,\n 10,\n kDate};\n\n} // namespace test\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_TEST_ATTRIBUTES_H_\n"], ["/longfellow-zk/lib/algebra/bogorng.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_BOGORNG_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_BOGORNG_H_\n\nnamespace proofs {\n// Totally bogus \"random\" number generator, used only for testing.\n// There is no guarantee that it will cycle over all elements in the\n// field, but this keeps dependencies internal to this directory.\n// The public and internal functions of this class all take a const Field&\n// parameter to produce random elements in the Field. It is the caller's\n// responsibility to ensure the object remains valid during execution.\ntemplate \nclass Bogorng {\n using Elt = typename Field::Elt;\n\n public:\n explicit Bogorng(const Field* F)\n : f_(F), next_(F->of_scalar_field(123456789u)) {}\n\n Elt next() {\n // really old-school\n f_->mul(next_, f_->of_scalar_field(1103515245u));\n f_->add(next_, f_->of_scalar_field(12345u));\n return next_;\n }\n\n Elt nonzero() {\n Elt x;\n do {\n x = next();\n } while (x == f_->zero());\n return x;\n }\n\n private:\n const Field* f_;\n Elt next_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_BOGORNG_H_\n"], ["/longfellow-zk/lib/circuits/sha/flatsha256_witness.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_FLATSHA256_WITNESS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_FLATSHA256_WITNESS_H_\n\n#include \n#include \n\nnamespace proofs {\n\nuint32_t SHA256_ru32be(const uint8_t *d);\n\nclass FlatSHA256Witness {\n public:\n struct BlockWitness {\n uint32_t outw[48];\n uint32_t oute[64];\n uint32_t outa[64];\n uint32_t h1[8];\n };\n\n static void transform_and_witness_block(const uint32_t in[16],\n const uint32_t H0[8],\n uint32_t outw[48], uint32_t oute[64],\n uint32_t outa[64], uint32_t H1[8]);\n\n static void transform_and_witness_message(size_t n, const uint8_t msg[/*n*/],\n size_t max, uint8_t &numb,\n uint8_t in[/* 64*max */],\n BlockWitness bw[/*max*/]);\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_FLATSHA256_WITNESS_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_attribute_ids.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_ATTRIBUTE_IDS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_ATTRIBUTE_IDS_H_\n\n#include \n\nnamespace proofs {\n\nstruct MdocAttribute {\n std::string_view identifier;\n std::string_view documentspec;\n};\n\n// Extracted from\n// https://github.com/ISOWG10/ISO-18013/blob/main/Working%20Documents/Working%20Draft%20WG%2010_N2549_ISO-IEC%2018013-5-%20Personal%20identification%20%E2%80%94%20ISO-compliant%20driving%20licence%20%E2%80%94%20Part%205-%20Mobile%20driving%20lic.pdf\n// https://www.aamva.org/getmedia/bb4fee66-592d-4d39-813a-8fdfd910268a/MobileDLGuidelines1-5.pdf\nconstexpr MdocAttribute kMdocAttributes[] = {\n {\"family_name\", \"org.iso.18013.5.1\"},\n {\"given_name\", \"org.iso.18013.5.1\"},\n {\"birth_date\", \"org.iso.18013.5.1\"},\n {\"issue_date\", \"org.iso.18013.5.1\"},\n {\"expiry_date\", \"org.iso.18013.5.1\"},\n {\"issuing_country\", \"org.iso.18013.5.1\"},\n {\"issuing_authority\", \"org.iso.18013.5.1\"},\n {\"document_number\", \"org.iso.18013.5.1\"},\n {\"portrait\", \"org.iso.18013.5.1\"},\n {\"driving_privileges\", \"org.iso.18013.5.1\"},\n {\"un_distinguishing_sign\", \"org.iso.18013.5.1\"},\n {\"administrative_number\", \"org.iso.18013.5.1\"},\n {\"sex\", \"org.iso.18013.5.1\"},\n {\"height\", \"org.iso.18013.5.1\"},\n {\"weight\", \"org.iso.18013.5.1\"},\n {\"eye_colour\", \"org.iso.18013.5.1\"},\n {\"hair_colour\", \"org.iso.18013.5.1\"},\n {\"birth_place\", \"org.iso.18013.5.1\"},\n {\"resident_address\", \"org.iso.18013.5.1\"},\n {\"portrait_capture_date\", \"org.iso.18013.5.1\"},\n {\"age_in_years\", \"org.iso.18013.5.1\"},\n {\"age_birth_year\", \"org.iso.18013.5.1\"},\n {\"age_over_10\", \"org.iso.18013.5.1\"},\n {\"age_over_11\", \"org.iso.18013.5.1\"},\n {\"age_over_12\", \"org.iso.18013.5.1\"},\n {\"age_over_13\", \"org.iso.18013.5.1\"},\n {\"age_over_14\", \"org.iso.18013.5.1\"},\n {\"age_over_15\", \"org.iso.18013.5.1\"},\n {\"age_over_16\", \"org.iso.18013.5.1\"},\n {\"age_over_17\", \"org.iso.18013.5.1\"},\n {\"age_over_18\", \"org.iso.18013.5.1\"},\n {\"age_over_19\", \"org.iso.18013.5.1\"},\n {\"age_over_20\", \"org.iso.18013.5.1\"},\n {\"age_over_21\", \"org.iso.18013.5.1\"},\n {\"age_over_23\", \"org.iso.18013.5.1\"},\n {\"age_over_25\", \"org.iso.18013.5.1\"},\n {\"age_over_50\", \"org.iso.18013.5.1\"},\n {\"age_over_55\", \"org.iso.18013.5.1\"},\n {\"age_over_60\", \"org.iso.18013.5.1\"},\n {\"age_over_65\", \"org.iso.18013.5.1\"},\n {\"age_over_70\", \"org.iso.18013.5.1\"},\n {\"age_over_75\", \"org.iso.18013.5.1\"},\n {\"issuing_jurisdiction\", \"org.iso.18013.5.1\"},\n {\"nationality\", \"org.iso.18013.5.1\"},\n {\"resident_city\", \"org.iso.18013.5.1\"},\n {\"resident_state\", \"org.iso.18013.5.1\"},\n {\"resident_postal_code\", \"org.iso.18013.5.1\"},\n {\"resident_country\", \"org.iso.18013.5.1\"},\n {\"biometric_template_face\", \"org.iso.18013.5.1\"},\n {\"biometric_template_voice\", \"org.iso.18013.5.1\"},\n {\"biometric_template_finger\", \"org.iso.18013.5.1\"},\n {\"biometric_template_iris\", \"org.iso.18013.5.1\"},\n {\"biometric_template_retina\", \"org.iso.18013.5.1\"},\n {\"biometric_template_hand_geometry\", \"org.iso.18013.5.1\"},\n {\"biometric_template_keystroke\", \"org.iso.18013.5.1\"},\n {\"biometric_template_signature_sign\", \"org.iso.18013.5.1\"},\n {\"biometric_template_lip_movement\", \"org.iso.18013.5.1\"},\n {\"biometric_template_thermal_face\", \"org.iso.18013.5.1\"},\n {\"biometric_template_thermal_hand\", \"org.iso.18013.5.1\"},\n {\"biometric_template_gait\", \"org.iso.18013.5.1\"},\n {\"biometric_template_body_odor\", \"org.iso.18013.5.1\"},\n {\"biometric_template_dna\", \"org.iso.18013.5.1\"},\n {\"biometric_template_ear\", \"org.iso.18013.5.1\"},\n {\"biometric_template_finger_geometry\", \"org.iso.18013.5.1\"},\n {\"biometric_template_palm_geometry\", \"org.iso.18013.5.1\"},\n {\"biometric_template_vein_pattern\", \"org.iso.18013.5.1\"},\n {\"biometric_template_foot_print\", \"org.iso.18013.5.1\"},\n {\"family_name_national_character\", \"org.iso.18013.5.1\"},\n {\"given_name_national_character\", \"org.iso.18013.5.1\"},\n {\"signature_usual_mark\", \"org.iso.18013.5.1\"},\n\n {\"name_suffix\", \"org.iso.18013.5.1.aamva\"},\n {\"organ_donor\", \"org.iso.18013.5.1.aamva\"},\n {\"veteran\", \"org.iso.18013.5.1.aamva\"},\n {\"family_name_truncation\", \"org.iso.18013.5.1.aamva\"},\n {\"given_name_truncation\", \"org.iso.18013.5.1.aamva\"},\n {\"aka_family_name.v2\", \"org.iso.18013.5.1.aamva\"},\n {\"aka_given_name.v2\", \"org.iso.18013.5.1.aamva\"},\n {\"aka_suffix\", \"org.iso.18013.5.1.aamva\"},\n {\"weight_range\", \"org.iso.18013.5.1.aamva\"},\n {\"race_ethnicity\", \"org.iso.18013.5.1.aamva\"},\n {\"sex\", \"org.iso.18013.5.1.aamva\"},\n {\"first_name\", \"org.iso.18013.5.1.aamva\"},\n {\"middle_names\", \"org.iso.18013.5.1.aamva\"},\n {\"first_name_truncation\", \"org.iso.18013.5.1.aamva\"},\n {\"middle_names_truncation\", \"org.iso.18013.5.1.aamva\"},\n {\"EDL_credential\", \"org.iso.18013.5.1.aamva\"},\n {\"EDL_credential.v2\", \"org.iso.18013.5.1.aamva\"},\n {\"DHS_compliance\", \"org.iso.18013.5.1.aamva\"},\n {\"resident_county\", \"org.iso.18013.5.1.aamva\"},\n {\"resident_county.v2\", \"org.iso.18013.5.1.aamva\"},\n {\"hazmat_endorsement_expiration_date\", \"org.iso.18013.5.1.aamva\"},\n {\"CDL_indicator\", \"org.iso.18013.5.1.aamva\"},\n {\"CDL_non_domiciled\", \"org.iso.18013.5.1.aamva\"},\n {\"CDL_non_domiciled.v2\", \"org.iso.18013.5.1.aamva\"},\n {\"DHS_compliance_text\", \"org.iso.18013.5.1.aamva\"},\n {\"DHS_temporary_lawful_status\", \"org.iso.18013.5.1.aamva\"},\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_ATTRIBUTE_IDS_H_\n"], ["/longfellow-zk/lib/circuits/sha3/sha3_reference.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA3_SHA3_REFERENCE_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA3_SHA3_REFERENCE_H_\n\n// !!!!! DO NOT USE IN PRODUCTION !!!!!\n\n/* This is a simple reference implementation of sha3\n to be used to design zero-knowledge circuits. DO NOT USE\n THIS CODE IN PRODUCTION. */\n#include \n#include \n\nnamespace proofs {\nclass Sha3Reference {\n size_t mdlen_;\n size_t rate_;\n size_t wrptr_;\n uint8_t buf_[200];\n uint64_t a_[5][5];\n\n static void keccak_f_1600(uint64_t A[5][5]);\n\n public:\n explicit Sha3Reference(size_t mdlen)\n : mdlen_(mdlen), rate_(200 - 2 * mdlen), wrptr_(0), buf_{}, a_{} {}\n\n void update(const char* data, size_t n);\n void final(uint8_t digest[/*mdlen*/]);\n\n static void keccak_f_1600_DEBUG_ONLY(uint64_t A[5][5]);\n};\n} // namespace proofs\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA3_SHA3_REFERENCE_H_\n"], ["/longfellow-zk/lib/algebra/twiddle.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_TWIDDLE_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_TWIDDLE_H_\n\n#include \n#include \n\n#include \n\n// Twiddle factors for FFT\nnamespace proofs {\n\ntemplate \nclass Twiddle {\n using Elt = typename Field::Elt;\n\n public:\n size_t order_;\n // powers of omega_n\n std::vector w_;\n\n explicit Twiddle(size_t n, const Elt& omega_n, const Field& F)\n : order_(n), w_(n / 2) {\n auto w = F.one();\n for (size_t i = 0; 2 * i < n; ++i) {\n w_[i] = w;\n F.mul(w, omega_n);\n }\n }\n\n // given a n-th root of unity omega_n, return a r-th root of unity\n // for r <= n\n static Elt reroot(const Elt& omega_n, uint64_t n, uint64_t r,\n const Field& F) {\n Elt omega_r = omega_n;\n while (r < n) {\n F.mul(omega_r, omega_r);\n r += r;\n }\n return omega_r;\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_TWIDDLE_H_\n"], ["/longfellow-zk/lib/util/ceildiv.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_UTIL_CEILDIV_H_\n#define PRIVACY_PROOFS_ZK_LIB_UTIL_CEILDIV_H_\n\n// This package holds basic math utility functions.\n\n#include \n#include \n\nnamespace proofs {\n\n// ceil(a/b)\ntemplate \nT ceildiv(T a, T b) {\n return (a + (b - 1)) / b;\n}\n\ninline size_t lg(size_t n) {\n size_t lgk = 0, k = 1;\n while (k < n) {\n k *= 2;\n lgk += 1;\n }\n return lgk;\n}\n\n// Morton-order operations\nnamespace morton {\n// extract even bits (pack)\ninline uint64_t even(uint64_t x) {\n x &= 0x5555555555555555ull;\n x |= (x >> 1);\n x &= 0x3333333333333333ull;\n x |= (x >> 2);\n x &= 0x0F0F0F0F0F0F0F0Full;\n x |= (x >> 4);\n x &= 0x00FF00FF00FF00FFull;\n x |= (x >> 8);\n x &= 0x0000FFFF0000FFFFull;\n x |= (x >> 16);\n x &= 0x00000000FFFFFFFFull;\n return x;\n}\n\n// inverse of even (unpack)\ninline uint64_t uneven(uint64_t x) {\n x &= 0x00000000FFFFFFFFull;\n x |= (x << 16);\n x &= 0x0000FFFF0000FFFFull;\n x |= (x << 8);\n x &= 0x00FF00FF00FF00FFull;\n x |= (x << 4);\n x &= 0x0F0F0F0F0F0F0F0Full;\n x |= (x << 2);\n x &= 0x3333333333333333ull;\n x |= (x << 1);\n x &= 0x5555555555555555ull;\n return x;\n}\n\n// Given two integers X and Y represented\n// as (even, odd) bits (X0, X1) and\n// (Y0, Y1), set (X0, X1) to the even/odd\n// representation of X+Y\ntemplate \nstatic void add(T *x0, T *x1, T y0, T y1) {\n // Given two arrays X[i] and Y[i] of bits, the goal\n // is to build an adder. One way to build an adder\n // is to switch to the generate/propagate representation\n // G[i] = X[i] & Y[i]\n // P[i] = X[i] ^ Y[i]\n // where G[i] means \"position i generates a carry\" and P[i] means\n // \"position i propagates the carry coming from position i-1\".\n //\n // Generate/propagate can be extended to pairs of positions\n // via the equations\n //\n // G = G[i+1] ^ (G[i] ^ P[i+1])\n // P = P[i+1] & P[i]. (1)\n //\n // (This is all well-known adder stuff that has been known since\n // at least the '50s).\n //\n // Our strategy is thus: convert the addends into G/P representation;\n // combine the [2i] and [2i+1] positions via Equation (1), and\n // use the C \"+\" operation to propagate the carry over one array.\n //\n // The fun part is, how do you use the C adder to propagate G.\n // The standard form of the adder is:\n //\n // (G, P) = (X & Y, X ^ Y)\n // G' = propagate G in any convenient way\n // (X + Y) = RESULT = P ^ G'\n //\n // and thus we can extract the propagated G' as G' = (X + Y) ^ X ^ Y.\n //\n // The other fun part is, given G and P, how do you go back to X and\n // Y that can be fed to the C adder? The transformation (X, Y) -> (G, P)\n // is not injective, but any inverse will work. We choose\n //\n // X = G\n // Y = P ^ G\n\n // Convert inputs into (G, P) form.\n T g0 = *x0 & y0, g1 = *x1 & y1;\n T p0 = *x0 ^ y0, p1 = *x1 ^ y1;\n\n // Combine the two (G, P) inputs.\n T g = g1 ^ (g0 & p1);\n T p = p0 & p1;\n\n // Convert back into (X, Y) = (G, P ^ G) and compute\n // GPRIME = (X + Y) ^ X ^ Y, which simplifies to (X + Y) ^ P\n // because X = G and Y = P ^ G.\n // Here we lose the carry of the addition, making it impossible\n // to output a global carry.\n T gprime = (g + (p ^ g)) ^ p;\n\n // XOR the propagated carries back into P\n *x0 = gprime ^ p0;\n *x1 = g0 ^ (gprime & p0) ^ p1;\n}\n\n// a-b via ~(~a + b)\ntemplate \nstatic void sub(T *x0, T *x1, T y0, T y1) {\n *x0 = ~*x0;\n *x1 = ~*x1;\n add(x0, x1, y0, y1);\n *x0 = ~*x0;\n *x1 = ~*x1;\n}\n\n// a < b via (a - b) < 0. Since we don't have\n// the output carry of the subtraction, we pretend that\n// the result is signed.\ntemplate \nstatic bool lt(T x0, T x1, T y0, T y1) {\n sub(&x0, &x1, y0, y1);\n return (x1 >> (8 * sizeof(T) - 1)) == 1;\n}\n\ntemplate \nstatic bool eq(T x0, T x1, T y0, T y1) {\n return x0 == y0 && x1 == y1;\n}\n\n} // namespace morton\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_UTIL_CEILDIV_H_\n"], ["/longfellow-zk/lib/ligero/ligero_transcript.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_TRANSCRIPT_H_\n#define PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_TRANSCRIPT_H_\n\n#include \n\n#include \n\n#include \"ligero/ligero_param.h\"\n#include \"random/transcript.h\"\n\nnamespace proofs {\ntemplate \nclass LigeroTranscript {\n public:\n using Elt = typename Field::Elt;\n\n static void write_commitment(const LigeroCommitment& commitment,\n Transcript& ts) {\n ts.write(commitment.root.data, commitment.root.kLength);\n }\n\n static void gen_uldt(Elt u[/*nwqrow*/], const LigeroParam& p,\n Transcript& ts, const Field& F) {\n ts.elt(u, p.nwqrow, F);\n }\n\n static void gen_alphal(size_t nl, Elt alpha[/*nl*/], Transcript& ts,\n const Field& F) {\n ts.elt(alpha, nl, F);\n }\n\n static void gen_alphaq(std::array alpha[/*nq*/],\n const LigeroParam& p, Transcript& ts,\n const Field& F) {\n ts.elt(&alpha[0][0], 3 * p.nq, F);\n }\n\n static void gen_uquad(Elt u[/*nqtriples*/], const LigeroParam& p,\n Transcript& ts, const Field& F) {\n ts.elt(u, p.nqtriples, F);\n }\n\n // Choose p.nreq distinct naturals in [0, p.block_enc - p.dblock)\n static void gen_idx(size_t idx[/*p.nreq*/], const LigeroParam& p,\n Transcript& ts, const Field& F) {\n check(p.block_enc >= p.dblock, \"p.block_enc >= p.dblock\");\n check(p.block_enc - p.dblock >= p.nreq, \"p.block_enc - p.dblock >= p.nreq\");\n ts.choose(idx, p.block_enc - p.dblock, p.nreq);\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_TRANSCRIPT_H_\n"], ["/longfellow-zk/lib/sumcheck/prover.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_SUMCHECK_PROVER_H_\n#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_PROVER_H_\n\n#include \n\n#include \"random/transcript.h\"\n#include \"sumcheck/circuit.h\"\n#include \"sumcheck/prover_layers.h\"\n#include \"sumcheck/transcript_sumcheck.h\"\n\nnamespace proofs {\n\n// A high level idea is partially described in chapter 4.6.7 \"Leveraging Data\n// Parallelism for Further Speedups\" in the book \"Proofs, Arguments, and\n// Zero-Knowledge\" by Justin Thaler.\ntemplate \nclass Prover : public ProverLayers {\n using super = ProverLayers;\n using typename super::bindings;\n\n public:\n using typename super::inputs;\n\n explicit Prover(const Field& f) : ProverLayers(f) {}\n\n // Generate proof for circuit. pad can be nullptr if the caller does not\n // want to add any pad to the proof. Caller must ensure in, t, and F remain\n // valid during call duration.\n // This method always succeeds, but may not produce a verifying proof if\n // the inputs do not satisfy the circuit.\n void prove(Proof* proof, const Proof* pad,\n const Circuit* circ, const inputs& in, Transcript& t) {\n if (proof == nullptr || circ == nullptr) return;\n\n TranscriptSumcheck ts(t, super::f_);\n // The input X is stored at in's layer nl - 1.\n ts.write_input(in.at(circ->nl - 1).get());\n bindings bnd;\n super::prove(proof, pad, circ, in, /*aux=*/nullptr, bnd, ts, super::f_);\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_PROVER_H_\n"], ["/longfellow-zk/lib/circuits/anoncred/small_io.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_IO_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_IO_H_\n\n#include \nnamespace proofs {\n\nstatic constexpr size_t kDateLen = 8;\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_IO_H_\n"], ["/longfellow-zk/lib/algebra/permutations.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_PERMUTATIONS_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_PERMUTATIONS_H_\n\n#include \n\n#include \n\nnamespace proofs {\n\ntemplate \nclass Permutations {\n public:\n static void bitrev(Elt A[/*n*/], size_t n) {\n size_t revi = 0;\n for (size_t i = 0; i < n - 1; ++i) {\n if (i < revi) {\n std::swap(A[i], A[revi]);\n }\n\n bitrev_increment(&revi, n);\n }\n }\n\n private:\n static void bitrev_increment(size_t* j, size_t bit) {\n do {\n bit >>= 1;\n *j ^= bit;\n } while (!(*j & bit));\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_PERMUTATIONS_H_\n"], ["/longfellow-zk/lib/circuits/jwt/jwt_constants.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_JWT_JWT_CONSTANTS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_JWT_JWT_CONSTANTS_H_\n\n#include \nnamespace proofs {\n\nstatic constexpr size_t kSHAJWTPluckerBits = 4u;\nstatic constexpr size_t kMaxJWTSHABlocks = 7;\nstatic constexpr size_t kJWTIndexBits = 10; /* #bits to index into payload */\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_JWT_JWT_CONSTANTS_H_\n"], ["/longfellow-zk/lib/algebra/compare.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_COMPARE_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_COMPARE_H_\n\n#include \n#include \n\nnamespace proofs {\n\n// canonical a < b operation, defined as lexicographic comparison of\n// the Elt's serialization\ntemplate \nbool elt_less_than(const typename Field::Elt& a, const typename Field::Elt& b,\n const Field& F) {\n uint8_t ua[Field::kBytes], ub[Field::kBytes];\n F.to_bytes_field(ua, a);\n F.to_bytes_field(ub, b);\n for (size_t j = 0; j < Field::kBytes; ++j) {\n if (ua[j] < ub[j]) return true;\n if (ua[j] > ub[j]) return false;\n }\n return false; // equal\n}\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_COMPARE_H_\n"], ["/longfellow-zk/lib/algebra/hash.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_HASH_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_HASH_H_\n\n#include \n#include \n\n#include \"util/crc64.h\"\n\nnamespace proofs {\n\n// canonical hash of an Elt\ntemplate \nuint64_t elt_hash(const typename Field::Elt& k, const Field& F) {\n uint64_t crc = 0x1;\n uint8_t buf[Field::kBytes];\n F.to_bytes_field(buf, k);\n for (size_t l = 0; l < Field::kBytes; ++l) {\n crc = crc64::update(crc, buf[l], 8);\n }\n return crc;\n}\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_HASH_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_examples.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_EXAMPLES_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_EXAMPLES_H_\n\n#include \n#include \n\n#include \"algebra/static_string.h\"\n\nnamespace proofs {\n\nstatic const StaticString kIssuerPKX[] = {\n StaticString(\n \"0x2c80c10bf70f63bddcc41ea20d76a22ecba2a97fa8811bf19d572433b12c0c1f\"),\n StaticString(\n \"0xcc900843699408936c912474a27abb7b62d7c90e4f6d8557714825476eee2366\"),\n StaticString(\n \"0xdc1c1f55cff4cd5c76cf4169278f7217667f86ee81d8669b63f2e19bc12a0c9f\"),\n\n // AZ MVMProdCA\n StaticString(\n \"0xbace36c902b2bdfc41b4b36ae7e56b17d571424d8a04395cb2d9d42325436c5b\"),\n // AZ MVMProdCA\n StaticString(\n \"0x8b90d350003c890c55f8d5ec8c8d39a6eb3a7551a6fa5ca3c68cbeca32fe6666\"),\n // US-AZ MVMTestCA\n StaticString(\n \"0xf228c62ac2cbafff3fa728010b4a99c098e5d0ff27084155950c4e3fdabbff47\"),\n // California DMV IACA Root\n StaticString(\n \"0x60cca07942c457606c6621aa40de294ba17083c604cc236240ac0ef6550f602f\"),\n // Colorado Root Certificate\n StaticString(\n \"0xc3b5f6418a146d4f840ee9bf47d18eb1b27705abca2c423692721795fb8ff5cb\"),\n // CO DRIVES Root\n StaticString(\n \"0xe93b68b25e9a8c8a42b24e3595b83dbe2a2091d3e18cf0a735062abca578b4a4\"),\n // Georgia Root Certificate Authority\n StaticString(\n \"0xac469d749c214ab56eac24bd3130f30a0c291e28571c2dd4462a5da037db67cc\"),\n // Georgia Root Certificate Authority\n StaticString(\n \"0xbcc1c0025e04d985a34519e1ab3f721556aaa8ab658e591bb2bed40044782de0\"),\n // Maryland MVA, CN=Fast Enterprises Root\n StaticString(\n \"0x69670a22a94059ba15f774406b969dd0b2419fc5b4ff2630b4ec94971b93c68a\"),\n // Maryland MVA, CN=Fast Enterprises Root\n StaticString(\n \"0x530664d11e9e497f2d56ecb45ec876a543e5c153009f7b460514055883f9d0c6\"),\n // New Mexico Root Certificate Authority\n StaticString(\n \"0xe17985694bcec58d553e0f6d5179a53279264755c32d5d03148499b8eeeb7348\"),\n // Google UL TESTING Staging DS\n StaticString(\n \"0xcc900843699408936c912474a27abb7b62d7c90e4f6d8557714825476eee2366\"),\n // C=US\n StaticString(\n \"0xd2cfd2ab7d5b52d6ce2178bf94505d1435c87572a7874e6ad4acf18bd35c1be1\"),\n // State Of Utopia Issuing Authority Signing Key\n StaticString(\n \"0xac33541815b08cdd996aa325ba1a2b6f5c87a755c0c05956dca8b5dbdf73af69\"),\n};\n\nstatic const StaticString kIssuerPKY[] = {\n StaticString(\n \"0x3f994c043be7e17dd08387281bac0c37a529361b3cb36a0fac38d41ac066f903\"),\n StaticString(\n \"0xb19764d33b530e9bd6a87081f1d8e5cbc80db640ac962ee8a3e0393c14c6bfb4\"),\n StaticString(\n \"0x12355dd0385fed3bc33bedc9781b9aad47b33e4c24704b8d14288b1b3cb45c28\"),\n\n // AZ MVMProdCA\n StaticString(\n \"0xc2b612dd77e71e4a3a8642d4ef5a106b4e97618b194d2c1babdcae21f8304589\"),\n // AZ MVMProdCA\n StaticString(\n \"0x9a81b4198f1321f17f3caf33fac082f3dff6777185e8de2bb9cea8475b317fb7\"),\n // US-AZ MVMTestCA\n StaticString(\n \"0x1f79e1ecc5b9c6844bffa4c10b41cdbf4d514641a44eb6954913909db0964ed1\"),\n // California DMV IACA Root\n StaticString(\n \"0x60c82a4040725298b62c7bbd0c146e16c7efa9a799b3854b1625089b6295f975\"),\n // Colorado Root Certificate\n StaticString(\n \"0x22134720c33bbcddc1e237c24a27e535b9f33d4d60752b03be8231e8569bdc8c\"),\n // CO DRIVES Root\n StaticString(\n \"0x0f9ec3881c5ffbf7c360aaf4f591003f4b08aebe992cb7a8d5ccd8e77dbeacae\"),\n // Georgia Root Certificate Authority\n StaticString(\n \"0x68bd68479edf3f52faf387d84293c455668aa126092d6ee4b5c22a42c8abe0fe\"),\n // Georgia Root Certificate Authority\n StaticString(\n \"0x33630d016957de6e6a4b65b2827081886e520c84317af6af53846ceb2b1d7755\"),\n // Maryland MVA, CN=Fast Enterprises Root\n StaticString(\n \"0x3848f928aca98ecf71214e10be538591aedd776929c2b09b4afb0681160857bb\"),\n // Maryland MVA, CN=Fast Enterprises Root\n StaticString(\n \"0x79a63d1496b6ae12bf7946adeb5207b86a350927345248fcdcf3d781b24dc7c6\"),\n // New Mexico Root Certificate Authority\n StaticString(\n \"0x9b52d953a90b66dfcdf295663bc8304945915b751227516c0f5d1d563e914ab3\"),\n // Google UL TESTING Staging DS\n StaticString(\n \"0xb19764d33b530e9bd6a87081f1d8e5cbc80db640ac962ee8a3e0393c14c6bfb4\"),\n // C=US\n StaticString(\n \"0x8ab996be9c14dd5749bf9ad85d373f9bc4ee360428ef152823c6125b6c1fcb51\"),\n // State Of Utopia Issuing Authority Signing Key\n StaticString(\n \"0xb8555be0e8944c3f684b649cf2786a59fe7db6e73c27d4298fe903e3711a7017\"),\n};\n\nstatic const char *kIDPass = \"com.google.wallet.idcard.1\";\nstatic const char *kMDL = \"org.iso.18013.5.1.mDL\";\n\nstruct MdocTests {\n StaticString pkx, pky; /* public key of the issuer */\n uint8_t transcript[1024];\n size_t transcript_size;\n uint8_t *now;\n const char *doc_type;\n size_t mdoc_size;\n uint8_t mdoc[5000];\n};\n\n// These mdoc examples are used in several tests.\nstatic const struct MdocTests mdoc_tests[] = {\n // First example only has \"age_over_18\"\n {StaticString(\n \"0x2c80c10bf70f63bddcc41ea20d76a22ecba2a97fa8811bf19d572433b12c0c1f\"),\n StaticString(\n \"0x3f994c043be7e17dd08387281bac0c37a529361b3cb36a0fac38d41ac066f903\"),\n {0x83, 0xf6, 0xf6, 0x84, 0x71, 0x41, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64,\n 0x48, 0x61, 0x6e, 0x64, 0x6f, 0x76, 0x65, 0x72, 0x76, 0x31, 0x58, 0x20,\n 0x2e, 0x10, 0x05, 0xb3, 0xa9, 0xc8, 0xf0, 0xdf, 0x04, 0xdb, 0x42, 0x30,\n 0x01, 0xc8, 0xb5, 0x39, 0x03, 0xfe, 0xd0, 0x71, 0xba, 0x50, 0x24, 0xc3,\n 0xba, 0x69, 0x74, 0x0e, 0x62, 0xd4, 0x91, 0x7e, 0x58, 0x19, 0x63, 0x6f,\n 0x6d, 0x2e, 0x61, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x2e, 0x6d, 0x64,\n 0x6c, 0x2e, 0x61, 0x70, 0x70, 0x72, 0x65, 0x61, 0x64, 0x65, 0x72, 0x58,\n 0x20, 0xd8, 0xe7, 0x3c, 0x70, 0x60, 0xe3, 0xe8, 0x0d, 0x3d, 0xef, 0xc2,\n 0x63, 0x4e, 0xb0, 0x4d, 0x08, 0xc6, 0x56, 0xe2, 0x60, 0x68, 0xd8, 0xa5,\n 0x63, 0xf5, 0xb9, 0x45, 0x85, 0xda, 0xe1, 0x4f, 0xad},\n 117,\n (uint8_t *)\"2024-01-30T09:00:00Z\",\n kMDL,\n 1452,\n {0xa3, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e,\n 0x30, 0x69, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x81,\n 0xa3, 0x67, 0x64, 0x6f, 0x63, 0x54, 0x79, 0x70, 0x65, 0x75, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x2e, 0x6d, 0x44, 0x4c, 0x6c, 0x69, 0x73, 0x73, 0x75,\n 0x65, 0x72, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xa2, 0x6a, 0x6e, 0x61,\n 0x6d, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x73, 0xa1, 0x71, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x81, 0xd8, 0x18, 0x58, 0x4f, 0xa4, 0x68, 0x64, 0x69,\n 0x67, 0x65, 0x73, 0x74, 0x49, 0x44, 0x00, 0x66, 0x72, 0x61, 0x6e, 0x64,\n 0x6f, 0x6d, 0x50, 0xf1, 0x10, 0x59, 0xeb, 0x6f, 0xbc, 0xe6, 0x26, 0x55,\n 0xdf, 0xbd, 0x6f, 0x83, 0xb8, 0x96, 0x70, 0x71, 0x65, 0x6c, 0x65, 0x6d,\n 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65,\n 0x72, 0x6b, 0x61, 0x67, 0x65, 0x5f, 0x6f, 0x76, 0x65, 0x72, 0x5f, 0x31,\n 0x38, 0x6c, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x56, 0x61, 0x6c,\n 0x75, 0x65, 0xf5, 0x6a, 0x69, 0x73, 0x73, 0x75, 0x65, 0x72, 0x41, 0x75,\n 0x74, 0x68, 0x84, 0x43, 0xa1, 0x01, 0x26, 0xa1, 0x18, 0x21, 0x59, 0x02,\n 0x27, 0x30, 0x82, 0x02, 0x23, 0x30, 0x82, 0x01, 0xa9, 0xa0, 0x03, 0x02,\n 0x01, 0x02, 0x02, 0x10, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x5f, 0x54,\n 0x65, 0x73, 0x74, 0x5f, 0x44, 0x53, 0x5f, 0x31, 0x30, 0x0a, 0x06, 0x08,\n 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x03, 0x30, 0x3c, 0x31, 0x0b,\n 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31,\n 0x0e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x05, 0x55, 0x53,\n 0x2d, 0x4d, 0x41, 0x31, 0x1d, 0x30, 0x1b, 0x06, 0x03, 0x55, 0x04, 0x03,\n 0x0c, 0x14, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x20, 0x54, 0x45, 0x53,\n 0x54, 0x20, 0x49, 0x41, 0x43, 0x41, 0x20, 0x6d, 0x44, 0x4c, 0x30, 0x1e,\n 0x17, 0x0d, 0x32, 0x33, 0x30, 0x37, 0x32, 0x36, 0x30, 0x30, 0x30, 0x30,\n 0x30, 0x31, 0x5a, 0x17, 0x0d, 0x32, 0x34, 0x31, 0x30, 0x32, 0x35, 0x30,\n 0x30, 0x30, 0x30, 0x30, 0x31, 0x5a, 0x30, 0x3a, 0x31, 0x0b, 0x30, 0x09,\n 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x0e, 0x30,\n 0x0c, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x05, 0x55, 0x53, 0x2d, 0x4d,\n 0x41, 0x31, 0x1b, 0x30, 0x19, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x12,\n 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x20, 0x54, 0x45, 0x53, 0x54, 0x20,\n 0x44, 0x53, 0x20, 0x6d, 0x44, 0x4c, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07,\n 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48,\n 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x2c, 0x80, 0xc1,\n 0x0b, 0xf7, 0x0f, 0x63, 0xbd, 0xdc, 0xc4, 0x1e, 0xa2, 0x0d, 0x76, 0xa2,\n 0x2e, 0xcb, 0xa2, 0xa9, 0x7f, 0xa8, 0x81, 0x1b, 0xf1, 0x9d, 0x57, 0x24,\n 0x33, 0xb1, 0x2c, 0x0c, 0x1f, 0x3f, 0x99, 0x4c, 0x04, 0x3b, 0xe7, 0xe1,\n 0x7d, 0xd0, 0x83, 0x87, 0x28, 0x1b, 0xac, 0x0c, 0x37, 0xa5, 0x29, 0x36,\n 0x1b, 0x3c, 0xb3, 0x6a, 0x0f, 0xac, 0x38, 0xd4, 0x1a, 0xc0, 0x66, 0xf9,\n 0x03, 0xa3, 0x81, 0x8e, 0x30, 0x81, 0x8b, 0x30, 0x1f, 0x06, 0x03, 0x55,\n 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xde, 0xf3, 0xab, 0x6d,\n 0x37, 0xde, 0x9e, 0x3a, 0x81, 0x6e, 0x10, 0x32, 0xd0, 0x2b, 0x48, 0xaf,\n 0x35, 0x8a, 0x71, 0xab, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04,\n 0x16, 0x04, 0x14, 0x39, 0x7b, 0xe5, 0x3c, 0x50, 0xdf, 0xf0, 0xd7, 0xa2,\n 0xe4, 0xa9, 0xe4, 0x65, 0xea, 0x73, 0x7a, 0x9e, 0xd8, 0x92, 0xc8, 0x30,\n 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03,\n 0x02, 0x07, 0x80, 0x30, 0x22, 0x06, 0x03, 0x55, 0x1d, 0x12, 0x04, 0x1b,\n 0x30, 0x19, 0x86, 0x17, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f,\n 0x77, 0x77, 0x77, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63,\n 0x6f, 0x6d, 0x2f, 0x30, 0x15, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x01, 0x01,\n 0xff, 0x04, 0x0b, 0x30, 0x09, 0x06, 0x07, 0x28, 0x81, 0x8c, 0x5d, 0x05,\n 0x01, 0x02, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04,\n 0x03, 0x03, 0x03, 0x68, 0x00, 0x30, 0x65, 0x02, 0x31, 0x00, 0xa2, 0x5c,\n 0xdb, 0x8a, 0x6f, 0x0c, 0x23, 0x90, 0x5b, 0x9d, 0x3f, 0x58, 0x2a, 0x60,\n 0x8f, 0x0c, 0x16, 0xf4, 0x36, 0xb5, 0xee, 0xe3, 0x58, 0x7d, 0x2c, 0xa9,\n 0x77, 0x16, 0x7c, 0x6f, 0x16, 0xa2, 0xb9, 0xde, 0x10, 0xfe, 0x1d, 0xdd,\n 0x16, 0xde, 0x07, 0x2e, 0x4f, 0x86, 0x6f, 0x06, 0x05, 0xa7, 0x02, 0x30,\n 0x6a, 0x48, 0x89, 0x42, 0x1f, 0x9b, 0xb3, 0x74, 0xb8, 0xbd, 0xe1, 0x75,\n 0xb3, 0xd6, 0xab, 0x23, 0x21, 0x6b, 0xa9, 0x7e, 0x68, 0x95, 0x10, 0x97,\n 0x4a, 0xe0, 0xf6, 0x59, 0xa1, 0x0e, 0x95, 0x84, 0x69, 0xb5, 0xbd, 0x80,\n 0xdf, 0xc1, 0x05, 0x88, 0x83, 0x1d, 0x93, 0x19, 0x81, 0xa6, 0x39, 0x98,\n 0x59, 0x01, 0xe8, 0xd8, 0x18, 0x59, 0x01, 0xe3, 0xa6, 0x67, 0x76, 0x65,\n 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e, 0x30, 0x6f, 0x64, 0x69,\n 0x67, 0x65, 0x73, 0x74, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68,\n 0x6d, 0x67, 0x53, 0x48, 0x41, 0x2d, 0x32, 0x35, 0x36, 0x67, 0x64, 0x6f,\n 0x63, 0x54, 0x79, 0x70, 0x65, 0x75, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73,\n 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0x2e,\n 0x6d, 0x44, 0x4c, 0x6c, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x44, 0x69, 0x67,\n 0x65, 0x73, 0x74, 0x73, 0xa1, 0x71, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73,\n 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0xa5,\n 0x01, 0x58, 0x20, 0xad, 0xf6, 0xa3, 0x33, 0x03, 0x6a, 0xde, 0xfc, 0x48,\n 0x90, 0xdf, 0x38, 0xe0, 0xf7, 0x37, 0x22, 0x90, 0x85, 0xa9, 0xb0, 0xba,\n 0x7c, 0x07, 0x19, 0xd3, 0x92, 0x40, 0x5d, 0x74, 0x46, 0x23, 0x77, 0x02,\n 0x58, 0x20, 0xa0, 0xa1, 0x4a, 0x5a, 0xa1, 0xb3, 0x36, 0x84, 0x4d, 0x8f,\n 0x8d, 0x14, 0x8e, 0xd4, 0x4f, 0xd2, 0xcc, 0xc6, 0x6f, 0x54, 0xd8, 0x78,\n 0x2b, 0x70, 0xfb, 0x77, 0x13, 0xfb, 0x3c, 0x93, 0xf5, 0x56, 0x03, 0x58,\n 0x20, 0x97, 0xb0, 0x18, 0x4e, 0xdd, 0xe3, 0x99, 0xcb, 0x7d, 0xea, 0x2d,\n 0x7d, 0x27, 0x9a, 0x45, 0x69, 0x90, 0xd9, 0xf3, 0x12, 0x46, 0x71, 0x63,\n 0x78, 0x7e, 0x1b, 0xa7, 0x66, 0x0a, 0x5c, 0x08, 0x6f, 0x04, 0x58, 0x20,\n 0xaf, 0x0b, 0x9f, 0xe7, 0x24, 0x5c, 0xa9, 0xa5, 0x9f, 0x64, 0xb1, 0xaa,\n 0x82, 0xcc, 0x2c, 0x1a, 0xb1, 0x38, 0x6f, 0x77, 0x95, 0x64, 0x93, 0x83,\n 0x62, 0x97, 0xc8, 0xa8, 0x4d, 0x2a, 0xe0, 0xb4, 0x00, 0x58, 0x20, 0x0d,\n 0x98, 0x54, 0xdb, 0x51, 0x48, 0x6f, 0xf4, 0x49, 0x07, 0xbc, 0x61, 0x4f,\n 0xfa, 0xea, 0x93, 0xda, 0xe1, 0xa8, 0x9e, 0xad, 0x40, 0x26, 0x3f, 0x90,\n 0x1a, 0xe6, 0xce, 0x41, 0x26, 0x46, 0x21, 0x6d, 0x64, 0x65, 0x76, 0x69,\n 0x63, 0x65, 0x4b, 0x65, 0x79, 0x49, 0x6e, 0x66, 0x6f, 0xa1, 0x69, 0x64,\n 0x65, 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79, 0xa4, 0x01, 0x02, 0x20,\n 0x01, 0x21, 0x58, 0x20, 0xc3, 0x14, 0xa7, 0xab, 0xba, 0x07, 0xe4, 0x0e,\n 0x64, 0xae, 0x87, 0xdb, 0x4a, 0xd9, 0x71, 0x80, 0x13, 0xfd, 0x39, 0x8e,\n 0x6e, 0x23, 0x17, 0xb3, 0x04, 0xf5, 0x7f, 0xc9, 0xac, 0xca, 0xb9, 0xf5,\n 0x22, 0x58, 0x20, 0xed, 0xb8, 0xb0, 0x23, 0x0c, 0xcc, 0x98, 0xdd, 0x42,\n 0xcd, 0xff, 0x89, 0xa8, 0xd1, 0xe2, 0x5f, 0xf8, 0xd1, 0xa7, 0xfa, 0x38,\n 0x9e, 0x92, 0xdc, 0x8f, 0x01, 0xaf, 0x98, 0x5a, 0x79, 0xef, 0xcc, 0x6c,\n 0x76, 0x61, 0x6c, 0x69, 0x64, 0x69, 0x74, 0x79, 0x49, 0x6e, 0x66, 0x6f,\n 0xa3, 0x66, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xc0, 0x74, 0x32, 0x30,\n 0x32, 0x34, 0x2d, 0x30, 0x31, 0x2d, 0x32, 0x35, 0x54, 0x32, 0x31, 0x3a,\n 0x31, 0x32, 0x3a, 0x35, 0x39, 0x5a, 0x69, 0x76, 0x61, 0x6c, 0x69, 0x64,\n 0x46, 0x72, 0x6f, 0x6d, 0xc0, 0x74, 0x32, 0x30, 0x32, 0x34, 0x2d, 0x30,\n 0x31, 0x2d, 0x32, 0x35, 0x54, 0x32, 0x31, 0x3a, 0x31, 0x32, 0x3a, 0x35,\n 0x39, 0x5a, 0x6a, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x55, 0x6e, 0x74, 0x69,\n 0x6c, 0xc0, 0x74, 0x32, 0x30, 0x32, 0x34, 0x2d, 0x30, 0x32, 0x2d, 0x32,\n 0x34, 0x54, 0x32, 0x31, 0x3a, 0x31, 0x32, 0x3a, 0x35, 0x39, 0x5a, 0x58,\n 0x40, 0x67, 0x00, 0x7b, 0xe9, 0x95, 0xa3, 0xe7, 0x43, 0x94, 0x5c, 0x4f,\n 0xb1, 0xc5, 0x8a, 0xe8, 0x9d, 0x72, 0xd4, 0x97, 0x31, 0x82, 0x51, 0xd9,\n 0xf1, 0x97, 0x4f, 0x08, 0xe5, 0x13, 0x89, 0xc8, 0x6d, 0x40, 0x11, 0x01,\n 0x48, 0x8f, 0xc3, 0x7e, 0x66, 0x55, 0x46, 0x49, 0x53, 0xc5, 0x1c, 0x4f,\n 0x8c, 0x64, 0xb9, 0x60, 0x13, 0xa1, 0xab, 0x04, 0xa9, 0xa6, 0x5b, 0x80,\n 0xfd, 0x2f, 0x3b, 0x5c, 0xa3, 0x6c, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65,\n 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xa2, 0x6a, 0x6e, 0x61, 0x6d, 0x65,\n 0x53, 0x70, 0x61, 0x63, 0x65, 0x73, 0xd8, 0x18, 0x41, 0xa0, 0x6a, 0x64,\n 0x65, 0x76, 0x69, 0x63, 0x65, 0x41, 0x75, 0x74, 0x68, 0xa1, 0x6f, 0x64,\n 0x65, 0x76, 0x69, 0x63, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75,\n 0x72, 0x65, 0x84, 0x43, 0xa1, 0x01, 0x26, 0xa0, 0xf6, 0x58, 0x40, 0xcf,\n 0xb0, 0xac, 0x1a, 0x63, 0x1b, 0x06, 0xe1, 0xb5, 0xd5, 0x03, 0x16, 0xfa,\n 0x43, 0xda, 0xb2, 0x38, 0x86, 0xa2, 0x6b, 0x67, 0x6c, 0x33, 0xba, 0xb4,\n 0x52, 0x63, 0x4c, 0xba, 0xdf, 0xd1, 0xb3, 0xab, 0xd1, 0xbd, 0x7a, 0x5e,\n 0x3c, 0x36, 0x97, 0xde, 0x7c, 0xe1, 0xfc, 0x00, 0x4a, 0x90, 0xde, 0x84,\n 0xe0, 0x62, 0x64, 0xfe, 0x95, 0x78, 0x81, 0x98, 0xac, 0xdc, 0x3e, 0x4c,\n 0x57, 0x5d, 0x59, 0x66, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x00}},\n {\n StaticString(\"0x2c80c10bf70f63bddcc41ea20d76a22ecba2a97fa8811bf19d57243\"\n \"3b12c0c1f\"),\n StaticString(\"0x3f994c043be7e17dd08387281bac0c37a529361b3cb36a0fac38d41\"\n \"ac066f903\"),\n {0x83, 0xf6, 0xf6, 0x84, 0x71, 0x41, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64,\n 0x48, 0x61, 0x6e, 0x64, 0x6f, 0x76, 0x65, 0x72, 0x76, 0x31, 0x58, 0x20,\n 0x2e, 0x10, 0x05, 0xb3, 0xa9, 0xc8, 0xf0, 0xdf, 0x04, 0xdb, 0x42, 0x30,\n 0x01, 0xc8, 0xb5, 0x39, 0x03, 0xfe, 0xd0, 0x71, 0xba, 0x50, 0x24, 0xc3,\n 0xba, 0x69, 0x74, 0x0e, 0x62, 0xd4, 0x91, 0x7e, 0x58, 0x19, 0x63, 0x6f,\n 0x6d, 0x2e, 0x61, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x2e, 0x6d, 0x64,\n 0x6c, 0x2e, 0x61, 0x70, 0x70, 0x72, 0x65, 0x61, 0x64, 0x65, 0x72, 0x58,\n 0x20, 0xd8, 0xe7, 0x3c, 0x70, 0x60, 0xe3, 0xe8, 0x0d, 0x3d, 0xef, 0xc2,\n 0x63, 0x4e, 0xb0, 0x4d, 0x08, 0xc6, 0x56, 0xe2, 0x60, 0x68, 0xd8, 0xa5,\n 0x63, 0xf5, 0xb9, 0x45, 0x85, 0xda, 0xe1, 0x4f, 0xad},\n 117,\n (uint8_t *)\"2024-01-31T09:00:00Z\",\n kMDL,\n 1488,\n {0xa3, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e,\n 0x30, 0x69, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x81,\n 0xa3, 0x67, 0x64, 0x6f, 0x63, 0x54, 0x79, 0x70, 0x65, 0x75, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x2e, 0x6d, 0x44, 0x4c, 0x6c, 0x69, 0x73, 0x73, 0x75,\n 0x65, 0x72, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xa2, 0x6a, 0x6e, 0x61,\n 0x6d, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x73, 0xa1, 0x71, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x81, 0xd8, 0x18, 0x58, 0x4f, 0xa4, 0x68, 0x64, 0x69,\n 0x67, 0x65, 0x73, 0x74, 0x49, 0x44, 0x02, 0x66, 0x72, 0x61, 0x6e, 0x64,\n 0x6f, 0x6d, 0x50, 0x52, 0xd8, 0x3d, 0xee, 0xdc, 0x0b, 0xf6, 0x62, 0x05,\n 0x83, 0x5c, 0xcc, 0x16, 0xad, 0x68, 0x2d, 0x71, 0x65, 0x6c, 0x65, 0x6d,\n 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65,\n 0x72, 0x6b, 0x61, 0x67, 0x65, 0x5f, 0x6f, 0x76, 0x65, 0x72, 0x5f, 0x31,\n 0x38, 0x6c, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x56, 0x61, 0x6c,\n 0x75, 0x65, 0xf5, 0x6a, 0x69, 0x73, 0x73, 0x75, 0x65, 0x72, 0x41, 0x75,\n 0x74, 0x68, 0x84, 0x43, 0xa1, 0x01, 0x26, 0xa1, 0x18, 0x21, 0x59, 0x02,\n 0x27, 0x30, 0x82, 0x02, 0x23, 0x30, 0x82, 0x01, 0xa9, 0xa0, 0x03, 0x02,\n 0x01, 0x02, 0x02, 0x10, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x5f, 0x54,\n 0x65, 0x73, 0x74, 0x5f, 0x44, 0x53, 0x5f, 0x31, 0x30, 0x0a, 0x06, 0x08,\n 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x03, 0x30, 0x3c, 0x31, 0x0b,\n 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31,\n 0x0e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x05, 0x55, 0x53,\n 0x2d, 0x4d, 0x41, 0x31, 0x1d, 0x30, 0x1b, 0x06, 0x03, 0x55, 0x04, 0x03,\n 0x0c, 0x14, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x20, 0x54, 0x45, 0x53,\n 0x54, 0x20, 0x49, 0x41, 0x43, 0x41, 0x20, 0x6d, 0x44, 0x4c, 0x30, 0x1e,\n 0x17, 0x0d, 0x32, 0x33, 0x30, 0x37, 0x32, 0x36, 0x30, 0x30, 0x30, 0x30,\n 0x30, 0x31, 0x5a, 0x17, 0x0d, 0x32, 0x34, 0x31, 0x30, 0x32, 0x35, 0x30,\n 0x30, 0x30, 0x30, 0x30, 0x31, 0x5a, 0x30, 0x3a, 0x31, 0x0b, 0x30, 0x09,\n 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x0e, 0x30,\n 0x0c, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x05, 0x55, 0x53, 0x2d, 0x4d,\n 0x41, 0x31, 0x1b, 0x30, 0x19, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x12,\n 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x20, 0x54, 0x45, 0x53, 0x54, 0x20,\n 0x44, 0x53, 0x20, 0x6d, 0x44, 0x4c, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07,\n 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48,\n 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x2c, 0x80, 0xc1,\n 0x0b, 0xf7, 0x0f, 0x63, 0xbd, 0xdc, 0xc4, 0x1e, 0xa2, 0x0d, 0x76, 0xa2,\n 0x2e, 0xcb, 0xa2, 0xa9, 0x7f, 0xa8, 0x81, 0x1b, 0xf1, 0x9d, 0x57, 0x24,\n 0x33, 0xb1, 0x2c, 0x0c, 0x1f, 0x3f, 0x99, 0x4c, 0x04, 0x3b, 0xe7, 0xe1,\n 0x7d, 0xd0, 0x83, 0x87, 0x28, 0x1b, 0xac, 0x0c, 0x37, 0xa5, 0x29, 0x36,\n 0x1b, 0x3c, 0xb3, 0x6a, 0x0f, 0xac, 0x38, 0xd4, 0x1a, 0xc0, 0x66, 0xf9,\n 0x03, 0xa3, 0x81, 0x8e, 0x30, 0x81, 0x8b, 0x30, 0x1f, 0x06, 0x03, 0x55,\n 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xde, 0xf3, 0xab, 0x6d,\n 0x37, 0xde, 0x9e, 0x3a, 0x81, 0x6e, 0x10, 0x32, 0xd0, 0x2b, 0x48, 0xaf,\n 0x35, 0x8a, 0x71, 0xab, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04,\n 0x16, 0x04, 0x14, 0x39, 0x7b, 0xe5, 0x3c, 0x50, 0xdf, 0xf0, 0xd7, 0xa2,\n 0xe4, 0xa9, 0xe4, 0x65, 0xea, 0x73, 0x7a, 0x9e, 0xd8, 0x92, 0xc8, 0x30,\n 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03,\n 0x02, 0x07, 0x80, 0x30, 0x22, 0x06, 0x03, 0x55, 0x1d, 0x12, 0x04, 0x1b,\n 0x30, 0x19, 0x86, 0x17, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f,\n 0x77, 0x77, 0x77, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63,\n 0x6f, 0x6d, 0x2f, 0x30, 0x15, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x01, 0x01,\n 0xff, 0x04, 0x0b, 0x30, 0x09, 0x06, 0x07, 0x28, 0x81, 0x8c, 0x5d, 0x05,\n 0x01, 0x02, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04,\n 0x03, 0x03, 0x03, 0x68, 0x00, 0x30, 0x65, 0x02, 0x31, 0x00, 0xa2, 0x5c,\n 0xdb, 0x8a, 0x6f, 0x0c, 0x23, 0x90, 0x5b, 0x9d, 0x3f, 0x58, 0x2a, 0x60,\n 0x8f, 0x0c, 0x16, 0xf4, 0x36, 0xb5, 0xee, 0xe3, 0x58, 0x7d, 0x2c, 0xa9,\n 0x77, 0x16, 0x7c, 0x6f, 0x16, 0xa2, 0xb9, 0xde, 0x10, 0xfe, 0x1d, 0xdd,\n 0x16, 0xde, 0x07, 0x2e, 0x4f, 0x86, 0x6f, 0x06, 0x05, 0xa7, 0x02, 0x30,\n 0x6a, 0x48, 0x89, 0x42, 0x1f, 0x9b, 0xb3, 0x74, 0xb8, 0xbd, 0xe1, 0x75,\n 0xb3, 0xd6, 0xab, 0x23, 0x21, 0x6b, 0xa9, 0x7e, 0x68, 0x95, 0x10, 0x97,\n 0x4a, 0xe0, 0xf6, 0x59, 0xa1, 0x0e, 0x95, 0x84, 0x69, 0xb5, 0xbd, 0x80,\n 0xdf, 0xc1, 0x05, 0x88, 0x83, 0x1d, 0x93, 0x19, 0x81, 0xa6, 0x39, 0x98,\n 0x59, 0x02, 0x0b, 0xd8, 0x18, 0x59, 0x02, 0x06, 0xa6, 0x67, 0x76, 0x65,\n 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e, 0x30, 0x6f, 0x64, 0x69,\n 0x67, 0x65, 0x73, 0x74, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68,\n 0x6d, 0x67, 0x53, 0x48, 0x41, 0x2d, 0x32, 0x35, 0x36, 0x67, 0x64, 0x6f,\n 0x63, 0x54, 0x79, 0x70, 0x65, 0x75, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73,\n 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0x2e,\n 0x6d, 0x44, 0x4c, 0x6c, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x44, 0x69, 0x67,\n 0x65, 0x73, 0x74, 0x73, 0xa1, 0x71, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73,\n 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0xa6,\n 0x01, 0x58, 0x20, 0x6b, 0x6e, 0xe3, 0xd4, 0x97, 0x13, 0x66, 0xb2, 0xda,\n 0x89, 0x5f, 0x8b, 0x79, 0xb0, 0x08, 0x35, 0xd4, 0xeb, 0x9e, 0x36, 0x7b,\n 0xa2, 0x00, 0x21, 0x06, 0x39, 0xc9, 0xa2, 0x24, 0xd5, 0x61, 0x91, 0x00,\n 0x58, 0x20, 0x97, 0x1e, 0x94, 0xb3, 0x34, 0x56, 0xbb, 0x45, 0xd1, 0x7e,\n 0x9a, 0xe5, 0x58, 0xa3, 0x51, 0x5f, 0x68, 0xb4, 0x66, 0x27, 0x22, 0xb2,\n 0xee, 0x3c, 0x20, 0x98, 0x91, 0x52, 0xc2, 0xad, 0xc0, 0x71, 0x04, 0x58,\n 0x20, 0x64, 0x0a, 0x32, 0xae, 0x3e, 0xea, 0x27, 0x30, 0xe1, 0xdb, 0x11,\n 0x27, 0x56, 0xec, 0x65, 0x00, 0xa2, 0xab, 0xee, 0x2b, 0xe6, 0xe7, 0x50,\n 0xe2, 0x3c, 0x38, 0xb7, 0x55, 0x27, 0xf1, 0x8f, 0x37, 0x05, 0x58, 0x20,\n 0x28, 0x7e, 0x50, 0x4b, 0xd3, 0x5c, 0x0f, 0x8f, 0xa8, 0x23, 0x91, 0x66,\n 0x50, 0xd3, 0xc8, 0xa9, 0x8d, 0x38, 0x41, 0x50, 0xe7, 0x95, 0xf6, 0x2a,\n 0x11, 0x44, 0xda, 0x45, 0xc0, 0x91, 0x21, 0x3b, 0x03, 0x58, 0x20, 0xd1,\n 0x7f, 0x88, 0xf6, 0x17, 0x79, 0xaa, 0xc0, 0xa1, 0x00, 0xd0, 0xdd, 0xa0,\n 0xdd, 0x45, 0x85, 0xbd, 0x7b, 0x2c, 0xe5, 0x99, 0x22, 0x47, 0xf3, 0xed,\n 0x4f, 0xdc, 0xd7, 0x1d, 0x9c, 0xfa, 0xcc, 0x02, 0x58, 0x20, 0x96, 0x22,\n 0xa2, 0xd9, 0xfe, 0x02, 0xec, 0xbe, 0x3c, 0x63, 0x1d, 0x9a, 0xbb, 0x94,\n 0x05, 0xf5, 0x08, 0xed, 0xd0, 0xf4, 0x3e, 0x5f, 0x12, 0x51, 0xc9, 0xd7,\n 0xf8, 0x79, 0xe6, 0x96, 0xcb, 0x60, 0x6d, 0x64, 0x65, 0x76, 0x69, 0x63,\n 0x65, 0x4b, 0x65, 0x79, 0x49, 0x6e, 0x66, 0x6f, 0xa1, 0x69, 0x64, 0x65,\n 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79, 0xa4, 0x01, 0x02, 0x20, 0x01,\n 0x21, 0x58, 0x20, 0xc5, 0x4e, 0x80, 0xbd, 0xa8, 0xa1, 0xe1, 0xba, 0x92,\n 0x66, 0xcb, 0xe7, 0x4c, 0x7a, 0x73, 0xcf, 0x79, 0x08, 0xe2, 0x98, 0x58,\n 0x23, 0xc9, 0x1a, 0x9c, 0xb1, 0xfe, 0x57, 0x98, 0x52, 0x9d, 0xfb, 0x22,\n 0x58, 0x20, 0x1a, 0xc3, 0x2f, 0x5c, 0x02, 0x4d, 0xd7, 0xa7, 0x86, 0x1d,\n 0x2a, 0xb8, 0x97, 0x54, 0x3a, 0x1e, 0x17, 0x97, 0x04, 0x77, 0xab, 0xd3,\n 0x88, 0x63, 0xa5, 0xb8, 0xde, 0x22, 0x33, 0xd1, 0xdb, 0x95, 0x6c, 0x76,\n 0x61, 0x6c, 0x69, 0x64, 0x69, 0x74, 0x79, 0x49, 0x6e, 0x66, 0x6f, 0xa3,\n 0x66, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xc0, 0x74, 0x32, 0x30, 0x32,\n 0x34, 0x2d, 0x30, 0x31, 0x2d, 0x32, 0x36, 0x54, 0x31, 0x35, 0x3a, 0x33,\n 0x32, 0x3a, 0x35, 0x30, 0x5a, 0x69, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x46,\n 0x72, 0x6f, 0x6d, 0xc0, 0x74, 0x32, 0x30, 0x32, 0x34, 0x2d, 0x30, 0x31,\n 0x2d, 0x32, 0x36, 0x54, 0x31, 0x35, 0x3a, 0x33, 0x32, 0x3a, 0x35, 0x30,\n 0x5a, 0x6a, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x55, 0x6e, 0x74, 0x69, 0x6c,\n 0xc0, 0x74, 0x32, 0x30, 0x32, 0x34, 0x2d, 0x30, 0x32, 0x2d, 0x32, 0x35,\n 0x54, 0x31, 0x35, 0x3a, 0x33, 0x32, 0x3a, 0x35, 0x30, 0x5a, 0x58, 0x40,\n 0xac, 0x87, 0xaa, 0x02, 0x60, 0xb8, 0x36, 0x22, 0x9d, 0x1e, 0xa2, 0x85,\n 0x2f, 0x3c, 0xa3, 0x2a, 0xa3, 0x63, 0x9d, 0x26, 0x0c, 0x00, 0xda, 0x81,\n 0x24, 0x22, 0xbb, 0xd4, 0x5f, 0xc2, 0x05, 0x37, 0x08, 0xff, 0x70, 0x50,\n 0xde, 0xcc, 0x2d, 0xfc, 0xfd, 0x3a, 0xba, 0xfe, 0xea, 0x3d, 0x68, 0xe5,\n 0x14, 0xb5, 0x24, 0xe4, 0xc2, 0xee, 0xf8, 0xad, 0x28, 0xec, 0xd3, 0x14,\n 0x21, 0xfb, 0x9f, 0x8f, 0x6c, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x53,\n 0x69, 0x67, 0x6e, 0x65, 0x64, 0xa2, 0x6a, 0x6e, 0x61, 0x6d, 0x65, 0x53,\n 0x70, 0x61, 0x63, 0x65, 0x73, 0xd8, 0x18, 0x41, 0xa0, 0x6a, 0x64, 0x65,\n 0x76, 0x69, 0x63, 0x65, 0x41, 0x75, 0x74, 0x68, 0xa1, 0x6f, 0x64, 0x65,\n 0x76, 0x69, 0x63, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72,\n 0x65, 0x84, 0x43, 0xa1, 0x01, 0x26, 0xa0, 0xf6, 0x58, 0x40, 0xf2, 0xa2,\n 0x59, 0xcc, 0x16, 0xbf, 0x5c, 0x30, 0x52, 0x68, 0x4b, 0x1f, 0x16, 0x62,\n 0x07, 0xd5, 0x93, 0xff, 0x5b, 0x0e, 0x1d, 0xa8, 0xc1, 0x44, 0xc0, 0xb6,\n 0xe9, 0x0d, 0x53, 0x7b, 0xde, 0x49, 0x39, 0xe7, 0xe8, 0xa0, 0xfa, 0x24,\n 0x70, 0x8e, 0x5a, 0x59, 0x24, 0xb9, 0x53, 0x52, 0xd6, 0x4f, 0x02, 0x0b,\n 0x59, 0x89, 0x97, 0x1f, 0x09, 0x1c, 0xa1, 0xfe, 0x05, 0xe2, 0x5b, 0x45,\n 0x9d, 0x86, 0x66, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x00},\n },\n // Canonical payground example\n {StaticString(\n \"0xcc900843699408936c912474a27abb7b62d7c90e4f6d8557714825476eee2366\"),\n StaticString(\n \"0xb19764d33b530e9bd6a87081f1d8e5cbc80db640ac962ee8a3e0393c14c6bfb4\"),\n {0x83, 0xf6, 0xf6, 0x84, 0x76, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x57,\n 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x48, 0x61, 0x6e, 0x64, 0x6f, 0x76, 0x65,\n 0x72, 0x76, 0x31, 0x44, 0x01, 0x02, 0x03, 0x04, 0x78, 0x22, 0x63, 0x6f,\n 0x6d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x61, 0x6e, 0x64,\n 0x72, 0x6f, 0x69, 0x64, 0x2e, 0x67, 0x6d, 0x73, 0x2e, 0x74, 0x65, 0x73,\n 0x74, 0x2e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x58, 0x20, 0xb0, 0xd3,\n 0x81, 0x79, 0x7d, 0x0a, 0x06, 0x4b, 0x5e, 0xbe, 0xcf, 0xfd, 0x9c, 0x8b,\n 0x0f, 0x12, 0x88, 0xfc, 0x83, 0xb8, 0x59, 0xc7, 0x60, 0x8e, 0x91, 0x05,\n 0x14, 0x30, 0x25, 0x51, 0x2c, 0x54},\n 102,\n (uint8_t *)\"2024-05-05T09:00:00Z\",\n kMDL,\n 3272,\n {0xa3, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e,\n 0x30, 0x69, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x81,\n 0xa3, 0x67, 0x64, 0x6f, 0x63, 0x54, 0x79, 0x70, 0x65, 0x75, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x2e, 0x6d, 0x44, 0x4c, 0x6c, 0x69, 0x73, 0x73, 0x75,\n 0x65, 0x72, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xa2, 0x6a, 0x6e, 0x61,\n 0x6d, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x73, 0xa1, 0x71, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x81, 0xd8, 0x18, 0x58, 0x61, 0xa4, 0x68, 0x64, 0x69,\n 0x67, 0x65, 0x73, 0x74, 0x49, 0x44, 0x18, 0x1d, 0x66, 0x72, 0x61, 0x6e,\n 0x64, 0x6f, 0x6d, 0x58, 0x20, 0x3d, 0x02, 0x64, 0xc0, 0x07, 0x37, 0x5a,\n 0x43, 0x62, 0x0c, 0x37, 0xc0, 0xcc, 0x5c, 0x87, 0x3e, 0x15, 0x32, 0xa5,\n 0x2f, 0x5d, 0x32, 0x0e, 0x05, 0xc0, 0xfb, 0x17, 0x6c, 0x0c, 0xd9, 0xba,\n 0xb1, 0x71, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65,\n 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x6b, 0x61, 0x67, 0x65, 0x5f,\n 0x6f, 0x76, 0x65, 0x72, 0x5f, 0x31, 0x38, 0x6c, 0x65, 0x6c, 0x65, 0x6d,\n 0x65, 0x6e, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0xf5, 0x6a, 0x69, 0x73,\n 0x73, 0x75, 0x65, 0x72, 0x41, 0x75, 0x74, 0x68, 0x84, 0x43, 0xa1, 0x01,\n 0x26, 0xa1, 0x18, 0x21, 0x59, 0x02, 0xde, 0x30, 0x82, 0x02, 0xda, 0x30,\n 0x82, 0x02, 0x3b, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x14, 0x09, 0xbd,\n 0x7c, 0x4d, 0x2d, 0x53, 0x1a, 0x2c, 0x79, 0xbf, 0x50, 0x36, 0x29, 0x40,\n 0x8e, 0xe8, 0xfd, 0x40, 0xc8, 0x89, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86,\n 0x48, 0xce, 0x3d, 0x04, 0x03, 0x04, 0x30, 0x40, 0x31, 0x0f, 0x30, 0x0d,\n 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x06, 0x47, 0x6f, 0x6f, 0x67, 0x6c,\n 0x65, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,\n 0x5a, 0x5a, 0x31, 0x20, 0x30, 0x1e, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c,\n 0x17, 0x55, 0x4c, 0x20, 0x54, 0x45, 0x53, 0x54, 0x49, 0x4e, 0x47, 0x20,\n 0x53, 0x74, 0x61, 0x67, 0x69, 0x6e, 0x67, 0x20, 0x52, 0x6f, 0x6f, 0x74,\n 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34, 0x30, 0x34, 0x32, 0x36, 0x31, 0x35,\n 0x34, 0x39, 0x34, 0x35, 0x5a, 0x17, 0x0d, 0x32, 0x35, 0x30, 0x34, 0x32,\n 0x36, 0x31, 0x35, 0x34, 0x39, 0x34, 0x35, 0x5a, 0x30, 0x3e, 0x31, 0x0f,\n 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x06, 0x47, 0x6f, 0x6f,\n 0x67, 0x6c, 0x65, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06,\n 0x13, 0x02, 0x5a, 0x5a, 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x03, 0x55, 0x04,\n 0x03, 0x0c, 0x15, 0x55, 0x4c, 0x20, 0x54, 0x45, 0x53, 0x54, 0x49, 0x4e,\n 0x47, 0x20, 0x53, 0x74, 0x61, 0x67, 0x69, 0x6e, 0x67, 0x20, 0x44, 0x53,\n 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02,\n 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03,\n 0x42, 0x00, 0x04, 0xcc, 0x90, 0x08, 0x43, 0x69, 0x94, 0x08, 0x93, 0x6c,\n 0x91, 0x24, 0x74, 0xa2, 0x7a, 0xbb, 0x7b, 0x62, 0xd7, 0xc9, 0x0e, 0x4f,\n 0x6d, 0x85, 0x57, 0x71, 0x48, 0x25, 0x47, 0x6e, 0xee, 0x23, 0x66, 0xb1,\n 0x97, 0x64, 0xd3, 0x3b, 0x53, 0x0e, 0x9b, 0xd6, 0xa8, 0x70, 0x81, 0xf1,\n 0xd8, 0xe5, 0xcb, 0xc8, 0x0d, 0xb6, 0x40, 0xac, 0x96, 0x2e, 0xe8, 0xa3,\n 0xe0, 0x39, 0x3c, 0x14, 0xc6, 0xbf, 0xb4, 0xa3, 0x82, 0x01, 0x13, 0x30,\n 0x82, 0x01, 0x0f, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18,\n 0x30, 0x16, 0x80, 0x14, 0x73, 0xa7, 0x04, 0x1e, 0x50, 0x81, 0x93, 0x9e,\n 0xe0, 0xdb, 0xb7, 0x02, 0x8a, 0xe3, 0x71, 0x2f, 0xd0, 0xaa, 0x36, 0xc1,\n 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04,\n 0x03, 0x02, 0x07, 0x80, 0x30, 0x21, 0x06, 0x03, 0x55, 0x1d, 0x12, 0x04,\n 0x1a, 0x30, 0x18, 0x86, 0x16, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f,\n 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,\n 0x63, 0x6f, 0x6d, 0x30, 0x81, 0x82, 0x06, 0x03, 0x55, 0x1d, 0x1f, 0x04,\n 0x7b, 0x30, 0x79, 0x30, 0x77, 0xa0, 0x75, 0xa0, 0x73, 0x86, 0x71, 0x68,\n 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74,\n 0x65, 0x63, 0x61, 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d,\n 0x36, 0x36, 0x30, 0x33, 0x63, 0x36, 0x34, 0x37, 0x2d, 0x30, 0x30, 0x30,\n 0x30, 0x2d, 0x32, 0x39, 0x64, 0x34, 0x2d, 0x61, 0x65, 0x61, 0x36, 0x2d,\n 0x66, 0x34, 0x66, 0x35, 0x65, 0x38, 0x30, 0x64, 0x31, 0x62, 0x39, 0x30,\n 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x67, 0x6f, 0x6f,\n 0x67, 0x6c, 0x65, 0x61, 0x70, 0x69, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x2f,\n 0x34, 0x31, 0x64, 0x34, 0x33, 0x36, 0x38, 0x35, 0x39, 0x65, 0x34, 0x35,\n 0x64, 0x62, 0x66, 0x33, 0x65, 0x35, 0x61, 0x39, 0x2f, 0x63, 0x72, 0x6c,\n 0x2e, 0x63, 0x72, 0x6c, 0x30, 0x15, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x01,\n 0x01, 0xff, 0x04, 0x0b, 0x30, 0x09, 0x06, 0x07, 0x28, 0x81, 0x8c, 0x5d,\n 0x05, 0x01, 0x02, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16,\n 0x04, 0x14, 0x7c, 0xfd, 0x80, 0xe8, 0x38, 0x3f, 0x66, 0x5c, 0x9d, 0x6e,\n 0x2b, 0xa3, 0xbe, 0xf6, 0x78, 0x05, 0xf6, 0x16, 0x51, 0x13, 0x30, 0x0a,\n 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x04, 0x03, 0x81,\n 0x8c, 0x00, 0x30, 0x81, 0x88, 0x02, 0x42, 0x01, 0xfb, 0x90, 0x69, 0xf7,\n 0x3e, 0xc8, 0x67, 0x49, 0xfb, 0x2b, 0x12, 0x47, 0x2a, 0xbb, 0x43, 0x17,\n 0x44, 0xf0, 0x88, 0x85, 0x00, 0x1a, 0xcb, 0x1c, 0xea, 0xb4, 0xeb, 0x57,\n 0x5d, 0x34, 0xb1, 0x28, 0x44, 0x3d, 0xa5, 0x38, 0x11, 0x1b, 0x41, 0x0e,\n 0xfe, 0x65, 0xea, 0xfb, 0xc2, 0xb4, 0x2f, 0x5c, 0x60, 0x83, 0x7c, 0x38,\n 0xa0, 0x22, 0xe1, 0x98, 0x8c, 0x45, 0xe5, 0xf3, 0xb7, 0x87, 0x63, 0xa0,\n 0x55, 0x02, 0x42, 0x00, 0xd0, 0x15, 0x2a, 0x35, 0x94, 0x15, 0x5f, 0xc4,\n 0x59, 0x37, 0x90, 0x25, 0x07, 0x8d, 0x3a, 0xb1, 0x23, 0x2a, 0x13, 0x22,\n 0x7f, 0x13, 0xf7, 0x49, 0xe3, 0x93, 0xdd, 0x2b, 0xcd, 0xb6, 0xf7, 0xda,\n 0x00, 0xc4, 0xc2, 0xa5, 0x6e, 0x9c, 0x0c, 0x23, 0x9f, 0xa0, 0x74, 0x0b,\n 0x22, 0x2b, 0x71, 0xc2, 0x27, 0xf4, 0xa8, 0x94, 0x62, 0x43, 0x58, 0x07,\n 0x51, 0xa9, 0x3a, 0x8c, 0xbf, 0xed, 0xa1, 0x20, 0x88, 0x59, 0x08, 0x3c,\n 0xd8, 0x18, 0x59, 0x08, 0x37, 0xa6, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69,\n 0x6f, 0x6e, 0x63, 0x31, 0x2e, 0x30, 0x6f, 0x64, 0x69, 0x67, 0x65, 0x73,\n 0x74, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x67, 0x53,\n 0x48, 0x41, 0x2d, 0x32, 0x35, 0x36, 0x6c, 0x76, 0x61, 0x6c, 0x75, 0x65,\n 0x44, 0x69, 0x67, 0x65, 0x73, 0x74, 0x73, 0xa2, 0x71, 0x6f, 0x72, 0x67,\n 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35,\n 0x2e, 0x31, 0xb8, 0x2b, 0x00, 0x58, 0x20, 0x5b, 0xa2, 0x15, 0x53, 0xe6,\n 0x43, 0xe5, 0x20, 0xab, 0xde, 0x97, 0x81, 0x41, 0x9b, 0xa3, 0x30, 0x9e,\n 0x78, 0x69, 0x92, 0x25, 0xd5, 0x63, 0x5f, 0x4f, 0xe3, 0xa5, 0x01, 0xc7,\n 0x87, 0x0b, 0x9c, 0x01, 0x58, 0x20, 0x63, 0x42, 0x51, 0x8e, 0xb0, 0x68,\n 0x5a, 0x92, 0xe0, 0x4d, 0x2d, 0x8c, 0xf8, 0xfd, 0xa8, 0x8f, 0xad, 0x35,\n 0xe1, 0x8d, 0x77, 0x83, 0x48, 0xc2, 0x2d, 0xf9, 0x81, 0x09, 0x63, 0x29,\n 0x26, 0x40, 0x02, 0x58, 0x20, 0x49, 0xbe, 0x06, 0xcd, 0xf4, 0xb6, 0x1f,\n 0xe1, 0x6a, 0xb3, 0x4b, 0x3d, 0xf5, 0x30, 0x8d, 0xff, 0x42, 0x2a, 0xed,\n 0x4f, 0xd9, 0xdb, 0xdb, 0x0e, 0x82, 0x0d, 0xad, 0xf7, 0xae, 0x1d, 0xcf,\n 0x9e, 0x03, 0x58, 0x20, 0xc6, 0x4d, 0x57, 0x38, 0x99, 0x26, 0x59, 0xe5,\n 0xd2, 0x3c, 0x79, 0xaa, 0xfc, 0xde, 0x6a, 0xa8, 0x9f, 0xa7, 0x51, 0x7a,\n 0x6e, 0x63, 0xd4, 0x73, 0xe8, 0xa0, 0x1b, 0xd4, 0x5f, 0xa3, 0xba, 0xe3,\n 0x04, 0x58, 0x20, 0xa2, 0x5d, 0x81, 0xd8, 0x32, 0x72, 0xd3, 0x6d, 0x11,\n 0x76, 0x8c, 0x02, 0xab, 0x10, 0x3a, 0x8b, 0xdc, 0xd6, 0xae, 0x3b, 0x32,\n 0x5c, 0x51, 0x1a, 0xcd, 0x87, 0xdb, 0xe5, 0x64, 0xba, 0x61, 0x1a, 0x05,\n 0x58, 0x20, 0x46, 0x6c, 0x84, 0x0e, 0x42, 0x2b, 0x42, 0x43, 0x6a, 0x9e,\n 0xf6, 0x0a, 0xe8, 0xd5, 0x8b, 0x1c, 0x6e, 0x27, 0xab, 0xd3, 0xa8, 0x5e,\n 0xfa, 0x08, 0x2d, 0xbb, 0xb9, 0x91, 0xa7, 0x71, 0xec, 0x47, 0x06, 0x58,\n 0x20, 0x07, 0xb4, 0xcc, 0x54, 0xef, 0xd0, 0x1d, 0xb3, 0x22, 0x98, 0xe5,\n 0x77, 0x8b, 0x61, 0x43, 0xd1, 0x65, 0xeb, 0xe1, 0x11, 0x65, 0x19, 0x4c,\n 0x34, 0xed, 0x7b, 0x21, 0xe4, 0x51, 0x32, 0x53, 0x48, 0x07, 0x58, 0x20,\n 0x74, 0x2f, 0xc6, 0xb9, 0x4d, 0x42, 0xf4, 0xb5, 0x09, 0x3b, 0x2e, 0x09,\n 0xf0, 0xed, 0x05, 0x33, 0x70, 0x28, 0xc1, 0x02, 0xd8, 0x4b, 0x0b, 0x83,\n 0xd6, 0x17, 0xb3, 0x5e, 0xeb, 0xe4, 0x7d, 0x6b, 0x08, 0x58, 0x20, 0xc5,\n 0xc2, 0x6f, 0x0d, 0x3f, 0x59, 0x6f, 0x96, 0x16, 0x2e, 0xbe, 0xc7, 0xcc,\n 0xae, 0xfb, 0xf8, 0xa2, 0x9d, 0x77, 0x21, 0x9d, 0x21, 0xd6, 0xf9, 0xc2,\n 0xec, 0x62, 0xf4, 0x0f, 0x76, 0x32, 0x1e, 0x09, 0x58, 0x20, 0xec, 0xff,\n 0x29, 0x8b, 0xb3, 0x04, 0x89, 0x10, 0x7d, 0x67, 0x8a, 0x22, 0xd1, 0x0c,\n 0xc3, 0x00, 0x93, 0x96, 0xa0, 0xa4, 0xc8, 0x5b, 0x42, 0x03, 0x79, 0xc4,\n 0x99, 0x25, 0xcd, 0x84, 0xce, 0x99, 0x0a, 0x58, 0x20, 0x83, 0x98, 0x6e,\n 0x01, 0xd1, 0x26, 0xf0, 0x4d, 0x45, 0x1c, 0xf0, 0x83, 0xe7, 0x1e, 0x24,\n 0x0e, 0x3a, 0x9e, 0xe2, 0x24, 0x06, 0x86, 0xf1, 0xc9, 0xc7, 0x79, 0xe7,\n 0x09, 0x3e, 0x66, 0x30, 0x90, 0x0b, 0x58, 0x20, 0x5d, 0x9e, 0x05, 0x3d,\n 0x1a, 0xf1, 0x86, 0xad, 0x9d, 0xf4, 0xc1, 0xeb, 0x6b, 0xec, 0x06, 0xaa,\n 0xb5, 0xab, 0x1d, 0xf3, 0xfe, 0x43, 0x59, 0x7f, 0xe4, 0x92, 0x18, 0xcd,\n 0x05, 0x81, 0x98, 0x99, 0x0c, 0x58, 0x20, 0x3a, 0xda, 0x36, 0xa4, 0xa7,\n 0x34, 0xe3, 0xb8, 0x97, 0x3c, 0x17, 0x32, 0xdb, 0xcc, 0x71, 0x67, 0x88,\n 0x38, 0x3b, 0x11, 0x54, 0xea, 0xf4, 0x81, 0x8b, 0x58, 0xbf, 0xd9, 0xf8,\n 0x29, 0x83, 0x13, 0x0d, 0x58, 0x20, 0x29, 0x1b, 0x18, 0x71, 0xda, 0x79,\n 0x78, 0xb9, 0xc4, 0xe5, 0x2b, 0x1a, 0x6d, 0xfc, 0x14, 0x29, 0x74, 0x72,\n 0x9d, 0xe8, 0x2f, 0x14, 0x96, 0x44, 0x0a, 0x53, 0x72, 0xb7, 0x19, 0x4c,\n 0x8d, 0x4e, 0x0e, 0x58, 0x20, 0x47, 0x4b, 0x99, 0x28, 0x4b, 0xf4, 0xe7,\n 0x13, 0x1c, 0x74, 0x9d, 0x85, 0x2c, 0xcb, 0xdf, 0x29, 0xa7, 0x26, 0x45,\n 0x4b, 0x55, 0x96, 0x9e, 0x55, 0xfe, 0x0f, 0x47, 0xd4, 0x1a, 0xad, 0x5d,\n 0xfb, 0x0f, 0x58, 0x20, 0xe0, 0x98, 0xdb, 0x13, 0x84, 0x30, 0xb2, 0x6c,\n 0xc3, 0x3c, 0xb3, 0x15, 0xcc, 0x82, 0x0e, 0xc4, 0xea, 0x4b, 0x4b, 0x38,\n 0xf7, 0x5a, 0x54, 0xe6, 0xa6, 0x4c, 0x7c, 0xf0, 0x9b, 0x5f, 0xf2, 0xc5,\n 0x10, 0x58, 0x20, 0xfe, 0x68, 0xbd, 0x1d, 0xde, 0xf4, 0xc7, 0x60, 0xfd,\n 0xf9, 0x6b, 0x19, 0xaf, 0x5f, 0x5a, 0x7f, 0x82, 0xc5, 0x26, 0xb9, 0xcc,\n 0x66, 0xe4, 0xe3, 0x7a, 0x24, 0x3d, 0x33, 0x04, 0x91, 0x1f, 0x5c, 0x11,\n 0x58, 0x20, 0x91, 0x36, 0x4e, 0x16, 0x85, 0x3f, 0xfe, 0x4f, 0xa1, 0x50,\n 0x97, 0x87, 0xd8, 0x9d, 0xff, 0x12, 0x3b, 0x6b, 0x1f, 0xc4, 0x73, 0xe9,\n 0xe0, 0xaa, 0x07, 0x0a, 0xce, 0xfc, 0xbf, 0x25, 0xf6, 0x9a, 0x12, 0x58,\n 0x20, 0x89, 0xdb, 0x3e, 0x9b, 0xa2, 0x0e, 0xb0, 0x16, 0xd2, 0x80, 0xcd,\n 0x2b, 0xe2, 0xe5, 0x86, 0xdb, 0xac, 0xc5, 0xc8, 0x3b, 0xb5, 0x10, 0x9e,\n 0x8d, 0x01, 0xa3, 0xd2, 0x77, 0x1e, 0x6e, 0xa8, 0x1f, 0x13, 0x58, 0x20,\n 0x9b, 0xb5, 0x36, 0x08, 0x50, 0x6c, 0xe0, 0x03, 0x3b, 0x88, 0x49, 0xef,\n 0xd5, 0xeb, 0x15, 0x58, 0xe7, 0x14, 0xca, 0x05, 0x7a, 0x57, 0xa0, 0xcb,\n 0x00, 0x78, 0x67, 0xd4, 0x3c, 0x8f, 0x6f, 0x79, 0x14, 0x58, 0x20, 0x33,\n 0x3b, 0x9b, 0x28, 0x72, 0xbe, 0x3d, 0x76, 0xda, 0xeb, 0x79, 0x0e, 0x08,\n 0x86, 0x55, 0xcc, 0x63, 0x78, 0x52, 0x17, 0x11, 0x57, 0x71, 0x9f, 0xe3,\n 0x8d, 0x6c, 0xe9, 0xf7, 0xc3, 0x5e, 0x37, 0x15, 0x58, 0x20, 0xe9, 0xd4,\n 0x87, 0x4e, 0x06, 0x4c, 0x64, 0xf0, 0x95, 0xff, 0xaf, 0xd3, 0xce, 0x33,\n 0x2c, 0x6b, 0x5c, 0x31, 0xf1, 0x1e, 0xfe, 0x69, 0x6f, 0x3a, 0x9b, 0xbf,\n 0x6c, 0x2a, 0x37, 0x69, 0x9f, 0xf7, 0x16, 0x58, 0x20, 0x66, 0xf2, 0x53,\n 0xa4, 0xc5, 0xe0, 0xc9, 0x18, 0x5c, 0x29, 0x45, 0xee, 0x2d, 0x93, 0xc6,\n 0x40, 0xfd, 0x1c, 0x55, 0xcf, 0xac, 0xf6, 0x44, 0xd8, 0xa7, 0x9b, 0x26,\n 0xca, 0xc4, 0x32, 0xdf, 0x0c, 0x17, 0x58, 0x20, 0x79, 0xa3, 0x91, 0x0f,\n 0xba, 0x84, 0x41, 0x91, 0x27, 0xa3, 0xcb, 0x41, 0xfc, 0x75, 0x51, 0x67,\n 0xee, 0xf9, 0x9f, 0x6c, 0x32, 0x55, 0x9e, 0xbc, 0xe2, 0x5e, 0x81, 0x5d,\n 0x6e, 0x0e, 0x7d, 0x18, 0x18, 0x18, 0x58, 0x20, 0x00, 0x2b, 0x44, 0x81,\n 0x79, 0xd9, 0xde, 0xde, 0xb6, 0x72, 0xb1, 0x2a, 0xbd, 0xd1, 0xed, 0xfe,\n 0xcf, 0xf4, 0x3d, 0x30, 0x31, 0xa8, 0x93, 0x97, 0xd7, 0x6d, 0x26, 0x3e,\n 0x7f, 0x68, 0x8a, 0xad, 0x18, 0x19, 0x58, 0x20, 0x02, 0xf7, 0x7d, 0xac,\n 0x9f, 0x51, 0x08, 0x92, 0x01, 0xec, 0x78, 0x9a, 0x98, 0x3c, 0xa8, 0x0d,\n 0x60, 0x51, 0xcc, 0xa1, 0xda, 0x98, 0x3b, 0xb8, 0xcb, 0x8e, 0xb7, 0xe0,\n 0xc7, 0x02, 0xaf, 0x0a, 0x18, 0x1a, 0x58, 0x20, 0x0b, 0x0e, 0x24, 0xdb,\n 0xa7, 0x46, 0x48, 0xad, 0x2f, 0x1c, 0xbb, 0x66, 0x41, 0x46, 0xf7, 0x32,\n 0x9e, 0xa4, 0xfe, 0x57, 0xe2, 0xfa, 0x5b, 0x14, 0xb6, 0x9a, 0x7f, 0x3e,\n 0x3d, 0x98, 0xa0, 0x10, 0x18, 0x1b, 0x58, 0x20, 0x7f, 0x8c, 0x39, 0x1c,\n 0xe7, 0xcd, 0x6d, 0xaa, 0x75, 0xeb, 0xd7, 0xb5, 0xcd, 0x32, 0xf6, 0x1c,\n 0xd4, 0xf1, 0xdd, 0xe4, 0x5a, 0xba, 0xa1, 0xba, 0xdf, 0x35, 0x67, 0x1c,\n 0x94, 0xa8, 0x18, 0x40, 0x18, 0x1c, 0x58, 0x20, 0x45, 0x52, 0x2a, 0xab,\n 0xfe, 0x53, 0x5e, 0x05, 0x07, 0x16, 0x81, 0x0f, 0x0a, 0x72, 0x6b, 0x79,\n 0x00, 0xc5, 0xf7, 0xc2, 0x9d, 0xeb, 0x16, 0x0b, 0x7e, 0x1b, 0x38, 0xe4,\n 0x42, 0x7f, 0x10, 0x2c, 0x18, 0x1d, 0x58, 0x20, 0x96, 0x61, 0x0d, 0x45,\n 0x9e, 0x4b, 0xf5, 0x69, 0xb6, 0x73, 0x62, 0xcf, 0x08, 0x55, 0xff, 0xb3,\n 0xdd, 0x76, 0xc7, 0x0b, 0x62, 0x49, 0x48, 0xce, 0x63, 0xd5, 0x93, 0x90,\n 0xa2, 0x62, 0xba, 0x27, 0x18, 0x1e, 0x58, 0x20, 0xce, 0x79, 0xa1, 0xc5,\n 0x83, 0x75, 0x95, 0x5e, 0x00, 0x14, 0xdc, 0x4f, 0x2b, 0xdb, 0xc3, 0x3e,\n 0x26, 0x79, 0x6c, 0x0c, 0x5b, 0x32, 0xda, 0x23, 0x40, 0xa4, 0x3b, 0x2d,\n 0xc9, 0x81, 0x34, 0xf0, 0x18, 0x1f, 0x58, 0x20, 0x78, 0x71, 0x6e, 0x52,\n 0x0b, 0xcf, 0xc9, 0x77, 0x59, 0x74, 0x88, 0x7d, 0x41, 0x87, 0xe2, 0x0c,\n 0xef, 0xb9, 0x79, 0xe0, 0xa7, 0xf5, 0xd1, 0xc4, 0xdf, 0x11, 0xe7, 0xdd,\n 0x9c, 0x21, 0xed, 0x38, 0x18, 0x20, 0x58, 0x20, 0x5f, 0xc6, 0xed, 0x71,\n 0x46, 0xa0, 0xf4, 0xe3, 0x82, 0x97, 0x59, 0x1a, 0x58, 0x86, 0xba, 0x91,\n 0x62, 0xf8, 0x65, 0xcc, 0xf7, 0xa6, 0x0d, 0x7e, 0xb7, 0xdc, 0x0b, 0x97,\n 0xb3, 0xed, 0xa2, 0xdf, 0x18, 0x21, 0x58, 0x20, 0x22, 0x1d, 0xec, 0x99,\n 0xf8, 0xe5, 0x3a, 0xff, 0xc1, 0xac, 0x36, 0x98, 0x0e, 0xdd, 0x30, 0xd2,\n 0x45, 0xa0, 0x7d, 0x9e, 0x8a, 0x8f, 0xfe, 0xf8, 0x4e, 0xc4, 0x41, 0x53,\n 0x1d, 0x62, 0xed, 0x56, 0x18, 0x22, 0x58, 0x20, 0x2b, 0x1a, 0xcd, 0xda,\n 0xf5, 0xa5, 0x35, 0xc9, 0x43, 0xf9, 0x77, 0x0d, 0x18, 0x0e, 0x29, 0x6e,\n 0x1e, 0xa7, 0x48, 0xbd, 0xd3, 0x5c, 0xc8, 0xef, 0xfe, 0x6d, 0xa6, 0x69,\n 0x66, 0x9f, 0x01, 0x4d, 0x18, 0x23, 0x58, 0x20, 0x77, 0x6c, 0xc8, 0x79,\n 0x55, 0x8d, 0xf5, 0x5b, 0x38, 0xc7, 0x8e, 0xbe, 0xdf, 0xbf, 0x80, 0x8c,\n 0xfe, 0x42, 0x1f, 0x24, 0xeb, 0xd6, 0x16, 0x1a, 0x8b, 0xbf, 0xf4, 0xc9,\n 0x54, 0x70, 0x82, 0x9a, 0x18, 0x24, 0x58, 0x20, 0x4b, 0x7e, 0x0f, 0x51,\n 0x63, 0xbe, 0xa3, 0x76, 0xcf, 0x47, 0x76, 0xbd, 0x52, 0xa7, 0x76, 0x57,\n 0x28, 0xeb, 0xae, 0x1d, 0x17, 0x50, 0xc2, 0xc9, 0xc5, 0xb8, 0xa3, 0x08,\n 0xb3, 0x3a, 0x4f, 0xfd, 0x18, 0x25, 0x58, 0x20, 0x0d, 0x76, 0x9d, 0x48,\n 0x03, 0x55, 0x16, 0xca, 0x03, 0x59, 0x5c, 0x7f, 0xa6, 0x0d, 0xd4, 0x32,\n 0xfe, 0x75, 0xe0, 0x88, 0x11, 0x10, 0x15, 0x64, 0x89, 0x66, 0x8f, 0x92,\n 0xd1, 0xc0, 0x1b, 0xcb, 0x18, 0x26, 0x58, 0x20, 0x02, 0x70, 0x12, 0x7a,\n 0xb6, 0x66, 0x44, 0x57, 0x53, 0xd6, 0x12, 0x52, 0xca, 0xf0, 0x5d, 0x4a,\n 0x2f, 0x20, 0x77, 0x35, 0xca, 0xe9, 0x34, 0x9d, 0xdf, 0x35, 0x2c, 0x27,\n 0xea, 0xe7, 0x6e, 0xe8, 0x18, 0x27, 0x58, 0x20, 0x42, 0x9a, 0x96, 0xe3,\n 0x79, 0x51, 0xb1, 0xd8, 0x99, 0x98, 0x28, 0x81, 0x4a, 0xa2, 0x52, 0x68,\n 0xf8, 0xeb, 0x69, 0x53, 0xce, 0x41, 0x7f, 0xa9, 0x93, 0xf8, 0xd1, 0x47,\n 0xf2, 0xe0, 0xe7, 0x45, 0x18, 0x28, 0x58, 0x20, 0xf5, 0x03, 0xb9, 0x30,\n 0x8e, 0x63, 0x45, 0xb9, 0x9e, 0x0f, 0x01, 0xc6, 0x73, 0xc2, 0xcf, 0x0f,\n 0x84, 0x5e, 0x22, 0xfe, 0x1f, 0x77, 0x6a, 0xc8, 0xe4, 0x1e, 0xb1, 0x90,\n 0x58, 0x8d, 0xaf, 0x6a, 0x18, 0x29, 0x58, 0x20, 0xae, 0x02, 0x5f, 0x21,\n 0xb2, 0x08, 0x9d, 0xf9, 0x21, 0x6d, 0x6c, 0x7d, 0x65, 0x50, 0xf3, 0x36,\n 0x4b, 0x42, 0x19, 0x7b, 0x1f, 0x3f, 0xe2, 0x63, 0x72, 0xdc, 0x9c, 0x0c,\n 0xa7, 0xe3, 0x0c, 0x08, 0x18, 0x2a, 0x58, 0x20, 0x3e, 0xcd, 0x92, 0xc4,\n 0x9c, 0x3f, 0xee, 0x18, 0x41, 0xa9, 0xa5, 0xd7, 0x6e, 0x9e, 0xd5, 0xf0,\n 0xfd, 0x06, 0x22, 0x72, 0x98, 0xe7, 0x87, 0x6d, 0x25, 0xc1, 0xf6, 0x1f,\n 0x79, 0xb4, 0x37, 0xc0, 0x77, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73, 0x6f,\n 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0x2e, 0x61,\n 0x61, 0x6d, 0x76, 0x61, 0xa7, 0x00, 0x58, 0x20, 0xb9, 0x3d, 0x05, 0x94,\n 0xaf, 0x96, 0xfe, 0x77, 0x1a, 0xc8, 0x79, 0x7f, 0x9e, 0x75, 0x76, 0xf8,\n 0xd3, 0xa7, 0xd3, 0x14, 0x31, 0x7a, 0x7c, 0x6c, 0x29, 0x32, 0xbc, 0xe1,\n 0xf4, 0xde, 0x4f, 0x64, 0x01, 0x58, 0x20, 0xd8, 0x36, 0x54, 0x23, 0x07,\n 0x2f, 0x73, 0xbf, 0x62, 0x88, 0x46, 0x20, 0xd8, 0xb6, 0xdc, 0x27, 0xb2,\n 0x27, 0xe6, 0x56, 0xc7, 0xd6, 0xb2, 0x5e, 0xb0, 0xd6, 0xc8, 0xd5, 0xe2,\n 0x5c, 0x4a, 0x44, 0x02, 0x58, 0x20, 0xc1, 0xcb, 0x4f, 0x9a, 0xa4, 0x1b,\n 0x2f, 0x9b, 0xa1, 0x7a, 0x33, 0xaf, 0x86, 0xac, 0xbc, 0x47, 0x16, 0xf3,\n 0x8e, 0xf8, 0x91, 0x9f, 0x19, 0xd9, 0x8a, 0xfc, 0x33, 0x7c, 0x41, 0x5f,\n 0xe6, 0x1d, 0x03, 0x58, 0x20, 0x45, 0xdb, 0x9c, 0x8f, 0x0a, 0xe3, 0x43,\n 0x09, 0x0f, 0x2a, 0x39, 0x07, 0x9e, 0x89, 0xa4, 0x6a, 0xfb, 0xb4, 0x87,\n 0x1b, 0xc8, 0xc7, 0x70, 0x44, 0x62, 0xc0, 0xf4, 0x35, 0x48, 0x27, 0x74,\n 0x80, 0x04, 0x58, 0x20, 0x37, 0x0f, 0x26, 0x20, 0x67, 0x83, 0x1c, 0x85,\n 0x1d, 0x77, 0x84, 0xb1, 0x39, 0x5e, 0x73, 0x9e, 0x8f, 0xa0, 0x25, 0xe1,\n 0x8b, 0x92, 0x37, 0xdf, 0xa7, 0x10, 0x05, 0x87, 0x6e, 0xb4, 0x8b, 0x06,\n 0x05, 0x58, 0x20, 0x8c, 0xb6, 0xa4, 0x05, 0x06, 0xf7, 0xb1, 0x01, 0x20,\n 0x32, 0x46, 0x95, 0xef, 0x20, 0x15, 0xad, 0x45, 0xbe, 0x93, 0x33, 0x14,\n 0xb7, 0x5e, 0xa2, 0xb2, 0x50, 0xd6, 0x8b, 0xa9, 0x73, 0xd0, 0x09, 0x06,\n 0x58, 0x20, 0xe9, 0x00, 0x40, 0x02, 0xf9, 0x59, 0xc8, 0xe1, 0x80, 0x2d,\n 0x9b, 0xb2, 0x95, 0x6e, 0xc0, 0x07, 0x58, 0x18, 0x6e, 0xd1, 0x02, 0x61,\n 0x94, 0xa1, 0x3c, 0xc6, 0x79, 0x56, 0x34, 0x4a, 0x6c, 0xd5, 0x6d, 0x64,\n 0x65, 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79, 0x49, 0x6e, 0x66, 0x6f,\n 0xa1, 0x69, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79, 0xa4,\n 0x01, 0x02, 0x20, 0x01, 0x21, 0x58, 0x20, 0xd8, 0x03, 0x40, 0x9d, 0x10,\n 0x60, 0x75, 0xeb, 0x45, 0x83, 0xe1, 0xca, 0x94, 0xad, 0x54, 0x2b, 0x57,\n 0x79, 0xf1, 0xe8, 0x64, 0xa8, 0xd2, 0x46, 0x81, 0xa1, 0xa6, 0x2e, 0x3b,\n 0x50, 0xdb, 0xd3, 0x22, 0x58, 0x20, 0xd6, 0x66, 0x3f, 0x27, 0x76, 0x66,\n 0x68, 0x02, 0x6a, 0x25, 0x0c, 0x9e, 0xd2, 0xcb, 0xbb, 0xdd, 0xd7, 0x57,\n 0xe3, 0x03, 0x8a, 0xea, 0xf1, 0x07, 0x8f, 0xda, 0xb5, 0xd2, 0xb1, 0x82,\n 0x6b, 0xa0, 0x6c, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x69, 0x74, 0x79, 0x49,\n 0x6e, 0x66, 0x6f, 0xa3, 0x66, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xc0,\n 0x74, 0x32, 0x30, 0x32, 0x34, 0x2d, 0x30, 0x35, 0x2d, 0x30, 0x33, 0x54,\n 0x30, 0x37, 0x3a, 0x30, 0x30, 0x3a, 0x30, 0x30, 0x5a, 0x69, 0x76, 0x61,\n 0x6c, 0x69, 0x64, 0x46, 0x72, 0x6f, 0x6d, 0xc0, 0x74, 0x32, 0x30, 0x32,\n 0x34, 0x2d, 0x30, 0x35, 0x2d, 0x30, 0x33, 0x54, 0x30, 0x37, 0x3a, 0x30,\n 0x30, 0x3a, 0x30, 0x30, 0x5a, 0x6a, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x55,\n 0x6e, 0x74, 0x69, 0x6c, 0xc0, 0x74, 0x32, 0x30, 0x32, 0x35, 0x2d, 0x30,\n 0x35, 0x2d, 0x30, 0x33, 0x54, 0x30, 0x37, 0x3a, 0x30, 0x30, 0x3a, 0x30,\n 0x30, 0x5a, 0x67, 0x64, 0x6f, 0x63, 0x54, 0x79, 0x70, 0x65, 0x75, 0x6f,\n 0x72, 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33,\n 0x2e, 0x35, 0x2e, 0x31, 0x2e, 0x6d, 0x44, 0x4c, 0x58, 0x40, 0xfb, 0x37,\n 0x77, 0xd9, 0xbf, 0x2d, 0x25, 0x26, 0xe3, 0x0d, 0x8d, 0xf4, 0x59, 0xe0,\n 0x9e, 0x70, 0x48, 0x28, 0x40, 0x8d, 0x60, 0xa7, 0xc1, 0x3c, 0x14, 0xe9,\n 0x4f, 0xe4, 0x3d, 0xf3, 0x5e, 0xe2, 0xaf, 0x86, 0xe9, 0x60, 0x87, 0xf0,\n 0x40, 0x1b, 0xd0, 0xa7, 0x2f, 0x6e, 0x45, 0x16, 0xdf, 0xa9, 0x9d, 0xb1,\n 0xf1, 0xb7, 0x2d, 0xa5, 0xb7, 0x39, 0x4f, 0x86, 0x26, 0xe1, 0x98, 0x59,\n 0x27, 0xaf, 0x6c, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x53, 0x69, 0x67,\n 0x6e, 0x65, 0x64, 0xa2, 0x6a, 0x6e, 0x61, 0x6d, 0x65, 0x53, 0x70, 0x61,\n 0x63, 0x65, 0x73, 0xd8, 0x18, 0x41, 0xa0, 0x6a, 0x64, 0x65, 0x76, 0x69,\n 0x63, 0x65, 0x41, 0x75, 0x74, 0x68, 0xa1, 0x6f, 0x64, 0x65, 0x76, 0x69,\n 0x63, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x84,\n 0x43, 0xa1, 0x01, 0x26, 0xa0, 0xf6, 0x58, 0x40, 0xef, 0xde, 0xb6, 0xa0,\n 0x91, 0x85, 0x5f, 0x91, 0x1c, 0x5f, 0x94, 0x68, 0xd0, 0x4f, 0xe3, 0x9b,\n 0xee, 0xff, 0x3c, 0x9e, 0xb4, 0x32, 0x4a, 0xc4, 0x76, 0x9a, 0x5e, 0x81,\n 0x2d, 0x52, 0x45, 0x3b, 0xc6, 0x48, 0xf8, 0xc5, 0xe0, 0x3d, 0x12, 0x67,\n 0x7d, 0xf4, 0xf9, 0x6b, 0x9e, 0x56, 0xb0, 0xc5, 0x0f, 0x73, 0x7a, 0x02,\n 0xf7, 0x6b, 0x6f, 0x25, 0xe2, 0x50, 0x28, 0x34, 0xa5, 0x1d, 0x31, 0x47,\n 0x66, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x00}},\n\n // Sprind-Funke mdoc example that includes family_name,\n // birth_date, issue_date, height, and age_over_18.\n // To test these examples, change the kAgeShow[] data structure in\n // mdoc_zk.cc to include one of the following opened attributes:\n // {(uint8_t *)\"family_name\", 11, (uint8_t *)\"Mustermann\", 10},\n // {(uint8_t *)\"height\", 6, (uint8_t *)\"\\x18\\xaf\", 2},\n // {(uint8_t *)\"birth_date\", 10, (uint8_t *)\"\\xD9\\x03\\xEC\\x6A\"\n // \"1971-09-01\", 14},\n // {(uint8_t *)\"issue_date\", 10, (uint8_t *)\"\\xD9\\x03\\xEC\\x6A\"\n // \"2024-03-15\", 14},\n // Note that the D903EC6A prefix specifies the cbor full-date encoding for\n // the birth_date and issue_date. The spec suggests that the issue_date can\n // also be formatted as a tdate, which would have a different prefix.\n // The 0x18af formatting for the height attribute uses the uint formatting\n // and corresponds to the value 175.\n {\n StaticString(\"0xdc1c1f55cff4cd5c76cf4169278f7217667f86ee81d8669b63f2e19\"\n \"bc12a0c9f\"),\n StaticString(\"0x12355dd0385fed3bc33bedc9781b9aad47b33e4c24704b8d14288b1\"\n \"b3cb45c28\"),\n {0x83, 0xf6, 0xf6, 0x84, 0x71, 0x42, 0x72, 0x6f, 0x77, 0x73, 0x65, 0x72,\n 0x48, 0x61, 0x6e, 0x64, 0x6f, 0x76, 0x65, 0x72, 0x76, 0x31, 0x58, 0x20,\n 0xf9, 0x3e, 0xba, 0xc4, 0xce, 0x4d, 0x99, 0x01, 0xb9, 0xae, 0xa4, 0x72,\n 0x14, 0x5a, 0xe5, 0x42, 0x1f, 0x8f, 0xbe, 0xcb, 0xe5, 0xf0, 0x38, 0x96,\n 0x83, 0xf5, 0x9f, 0x08, 0xfc, 0xf9, 0x0e, 0x45, 0x58, 0x33, 0xa3, 0x63,\n 0x63, 0x61, 0x74, 0x01, 0x64, 0x74, 0x79, 0x70, 0x65, 0x01, 0x67, 0x64,\n 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0xa1, 0x67, 0x62, 0x61, 0x73, 0x65,\n 0x55, 0x72, 0x6c, 0x75, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x6c,\n 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x3a, 0x38, 0x30, 0x38,\n 0x30, 0x58, 0x20, 0x3c, 0x79, 0x91, 0x4b, 0x7f, 0x81, 0xa1, 0xc2, 0x55,\n 0x8f, 0xc8, 0x16, 0x19, 0xdd, 0x4a, 0x07, 0x4d, 0x32, 0x14, 0x3e, 0x6c,\n 0xf6, 0x89, 0x5f, 0xe4, 0x7d, 0xa1, 0x56, 0xd1, 0xc5, 0xb0, 0xae},\n 143,\n (uint8_t *)\"2024-10-01T09:00:00Z\",\n kMDL,\n 3173,\n {0xa3, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e,\n 0x30, 0x69, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x81,\n 0xa3, 0x67, 0x64, 0x6f, 0x63, 0x54, 0x79, 0x70, 0x65, 0x75, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x2e, 0x6d, 0x44, 0x4c, 0x6c, 0x69, 0x73, 0x73, 0x75,\n 0x65, 0x72, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xa2, 0x6a, 0x6e, 0x61,\n 0x6d, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x73, 0xa1, 0x71, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x85, 0xd8, 0x18, 0x58, 0x5a, 0xa4, 0x68, 0x64, 0x69,\n 0x67, 0x65, 0x73, 0x74, 0x49, 0x44, 0x18, 0x1a, 0x66, 0x72, 0x61, 0x6e,\n 0x64, 0x6f, 0x6d, 0x50, 0x72, 0xc7, 0xaf, 0x26, 0x49, 0xd0, 0x5a, 0x38,\n 0xb0, 0x2e, 0x7e, 0x1c, 0xc7, 0xf9, 0xd0, 0x46, 0x71, 0x65, 0x6c, 0x65,\n 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69,\n 0x65, 0x72, 0x6b, 0x66, 0x61, 0x6d, 0x69, 0x6c, 0x79, 0x5f, 0x6e, 0x61,\n 0x6d, 0x65, 0x6c, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x56, 0x61,\n 0x6c, 0x75, 0x65, 0x6a, 0x4d, 0x75, 0x73, 0x74, 0x65, 0x72, 0x6d, 0x61,\n 0x6e, 0x6e, 0xd8, 0x18, 0x58, 0x5b, 0xa4, 0x68, 0x64, 0x69, 0x67, 0x65,\n 0x73, 0x74, 0x49, 0x44, 0x0a, 0x66, 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d,\n 0x50, 0xfc, 0x8a, 0x8f, 0x5b, 0xaf, 0xb4, 0x0c, 0xb3, 0x21, 0x77, 0x6d,\n 0xbf, 0x5f, 0xbe, 0x18, 0x81, 0x71, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e,\n 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x6a,\n 0x62, 0x69, 0x72, 0x74, 0x68, 0x5f, 0x64, 0x61, 0x74, 0x65, 0x6c, 0x65,\n 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0xd9,\n 0x03, 0xec, 0x6a, 0x31, 0x39, 0x37, 0x31, 0x2d, 0x30, 0x39, 0x2d, 0x30,\n 0x31, 0xd8, 0x18, 0x58, 0x5b, 0xa4, 0x68, 0x64, 0x69, 0x67, 0x65, 0x73,\n 0x74, 0x49, 0x44, 0x14, 0x66, 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x50,\n 0x59, 0xcd, 0xdd, 0x91, 0xd7, 0x53, 0xed, 0x98, 0xff, 0x55, 0x5d, 0x2f,\n 0x97, 0x27, 0x45, 0x3b, 0x71, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74,\n 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x6a, 0x69,\n 0x73, 0x73, 0x75, 0x65, 0x5f, 0x64, 0x61, 0x74, 0x65, 0x6c, 0x65, 0x6c,\n 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0xd9, 0x03,\n 0xec, 0x6a, 0x32, 0x30, 0x32, 0x34, 0x2d, 0x30, 0x33, 0x2d, 0x31, 0x35,\n 0xd8, 0x18, 0x58, 0x4b, 0xa4, 0x68, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74,\n 0x49, 0x44, 0x0f, 0x66, 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x50, 0xcc,\n 0xdc, 0x59, 0x8c, 0xa9, 0xaf, 0xee, 0x95, 0xfd, 0x57, 0x68, 0x3e, 0xb1,\n 0x9a, 0xff, 0x33, 0x71, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x49,\n 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x66, 0x68, 0x65,\n 0x69, 0x67, 0x68, 0x74, 0x6c, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74,\n 0x56, 0x61, 0x6c, 0x75, 0x65, 0x18, 0xaf, 0xd8, 0x18, 0x58, 0x4f, 0xa4,\n 0x68, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74, 0x49, 0x44, 0x15, 0x66, 0x72,\n 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x50, 0xac, 0x50, 0xf6, 0x51, 0xbc, 0x04,\n 0xf0, 0x01, 0xd0, 0x21, 0x63, 0x84, 0x7c, 0x9f, 0x1c, 0xc9, 0x71, 0x65,\n 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69,\n 0x66, 0x69, 0x65, 0x72, 0x6b, 0x61, 0x67, 0x65, 0x5f, 0x6f, 0x76, 0x65,\n 0x72, 0x5f, 0x31, 0x38, 0x6c, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74,\n 0x56, 0x61, 0x6c, 0x75, 0x65, 0xf5, 0x6a, 0x69, 0x73, 0x73, 0x75, 0x65,\n 0x72, 0x41, 0x75, 0x74, 0x68, 0x84, 0x43, 0xa1, 0x01, 0x26, 0xa1, 0x18,\n 0x21, 0x59, 0x02, 0x83, 0x30, 0x82, 0x02, 0x7f, 0x30, 0x82, 0x02, 0x25,\n 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x10, 0x35, 0x00, 0xba, 0x9b, 0xef,\n 0xd9, 0x1c, 0xb9, 0xda, 0x79, 0x05, 0xff, 0xef, 0x18, 0xbe, 0x8a, 0x30,\n 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30,\n 0x39, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,\n 0x55, 0x54, 0x31, 0x2a, 0x30, 0x28, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c,\n 0x21, 0x4f, 0x57, 0x46, 0x20, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74,\n 0x79, 0x20, 0x43, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c,\n 0x20, 0x54, 0x45, 0x53, 0x54, 0x20, 0x49, 0x41, 0x43, 0x41, 0x30, 0x1e,\n 0x17, 0x0d, 0x32, 0x34, 0x30, 0x39, 0x30, 0x32, 0x31, 0x37, 0x32, 0x31,\n 0x31, 0x33, 0x5a, 0x17, 0x0d, 0x32, 0x35, 0x30, 0x39, 0x30, 0x32, 0x31,\n 0x37, 0x32, 0x31, 0x31, 0x33, 0x5a, 0x30, 0x37, 0x31, 0x28, 0x30, 0x26,\n 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x1f, 0x4f, 0x57, 0x46, 0x20, 0x49,\n 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x20, 0x43, 0x72, 0x65, 0x64,\n 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x20, 0x54, 0x45, 0x53, 0x54, 0x20,\n 0x44, 0x53, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,\n 0x02, 0x55, 0x54, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48,\n 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03,\n 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0xdc, 0x1c, 0x1f, 0x55, 0xcf, 0xf4,\n 0xcd, 0x5c, 0x76, 0xcf, 0x41, 0x69, 0x27, 0x8f, 0x72, 0x17, 0x66, 0x7f,\n 0x86, 0xee, 0x81, 0xd8, 0x66, 0x9b, 0x63, 0xf2, 0xe1, 0x9b, 0xc1, 0x2a,\n 0x0c, 0x9f, 0x12, 0x35, 0x5d, 0xd0, 0x38, 0x5f, 0xed, 0x3b, 0xc3, 0x3b,\n 0xed, 0xc9, 0x78, 0x1b, 0x9a, 0xad, 0x47, 0xb3, 0x3e, 0x4c, 0x24, 0x70,\n 0x4b, 0x8d, 0x14, 0x28, 0x8b, 0x1b, 0x3c, 0xb4, 0x5c, 0x28, 0xa3, 0x82,\n 0x01, 0x0f, 0x30, 0x82, 0x01, 0x0b, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d,\n 0x0e, 0x04, 0x16, 0x04, 0x14, 0x13, 0x09, 0xce, 0x86, 0x0b, 0x9d, 0xff,\n 0xbc, 0x85, 0x99, 0x28, 0x3a, 0x1d, 0xd9, 0xc1, 0xf3, 0x55, 0x6a, 0x63,\n 0xf1, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16,\n 0x80, 0x14, 0x3c, 0xc0, 0x46, 0x99, 0x0e, 0x93, 0x42, 0x85, 0x46, 0x6d,\n 0xf6, 0xc6, 0xe0, 0x9a, 0xe3, 0xe3, 0x68, 0xdf, 0x2b, 0x0e, 0x30, 0x0e,\n 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02,\n 0x07, 0x80, 0x30, 0x15, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x01, 0x01, 0xff,\n 0x04, 0x0b, 0x30, 0x09, 0x06, 0x07, 0x28, 0x81, 0x8c, 0x5d, 0x05, 0x01,\n 0x02, 0x30, 0x54, 0x06, 0x03, 0x55, 0x1d, 0x1f, 0x04, 0x4d, 0x04, 0x4b,\n 0x30, 0x49, 0x30, 0x47, 0xa0, 0x45, 0xa0, 0x43, 0x86, 0x41, 0x68, 0x74,\n 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62,\n 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6f, 0x70, 0x65, 0x6e, 0x77, 0x61, 0x6c,\n 0x6c, 0x65, 0x74, 0x2d, 0x66, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, 0x69,\n 0x6f, 0x6e, 0x2d, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x69, 0x64, 0x65, 0x6e,\n 0x74, 0x69, 0x74, 0x79, 0x2d, 0x63, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74,\n 0x69, 0x61, 0x6c, 0x30, 0x4c, 0x06, 0x03, 0x55, 0x1d, 0x12, 0x04, 0x45,\n 0x04, 0x43, 0x86, 0x41, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f,\n 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6f,\n 0x70, 0x65, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x2d, 0x66, 0x6f,\n 0x75, 0x6e, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2d, 0x6c, 0x61, 0x62,\n 0x73, 0x2f, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2d, 0x63,\n 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x30, 0x0a, 0x06,\n 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x48, 0x00,\n 0x30, 0x45, 0x02, 0x21, 0x00, 0xcc, 0x61, 0x2d, 0xb2, 0xda, 0x22, 0x60,\n 0x9b, 0xf0, 0xa9, 0xeb, 0xea, 0x39, 0xa9, 0x05, 0x74, 0xfa, 0xc6, 0xd1,\n 0xb0, 0xed, 0x8b, 0x8b, 0xe0, 0x45, 0x27, 0x3e, 0xc7, 0x27, 0x6f, 0x64,\n 0x0c, 0x02, 0x20, 0x7f, 0x21, 0x44, 0x30, 0x13, 0x45, 0x54, 0x40, 0x93,\n 0x53, 0xb4, 0xb7, 0x4c, 0x4b, 0x64, 0x52, 0x64, 0x15, 0x81, 0x6d, 0x2f,\n 0xcb, 0x43, 0x29, 0x57, 0x0c, 0x62, 0xd5, 0x56, 0x27, 0x2b, 0x54, 0x59,\n 0x06, 0xdb, 0xd8, 0x18, 0x59, 0x06, 0xd6, 0xa6, 0x67, 0x76, 0x65, 0x72,\n 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e, 0x30, 0x6f, 0x64, 0x69, 0x67,\n 0x65, 0x73, 0x74, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d,\n 0x67, 0x53, 0x48, 0x41, 0x2d, 0x32, 0x35, 0x36, 0x67, 0x64, 0x6f, 0x63,\n 0x54, 0x79, 0x70, 0x65, 0x75, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73, 0x6f,\n 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0x2e, 0x6d,\n 0x44, 0x4c, 0x6c, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x44, 0x69, 0x67, 0x65,\n 0x73, 0x74, 0x73, 0xa2, 0x71, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73, 0x6f,\n 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0xb8, 0x22,\n 0x18, 0x1a, 0x58, 0x20, 0x2c, 0xb7, 0x3e, 0x3e, 0xc2, 0x84, 0xc0, 0x76,\n 0x43, 0xcb, 0x0c, 0xf5, 0xdf, 0x2d, 0xc0, 0xac, 0x83, 0xf8, 0xb2, 0x36,\n 0xb3, 0xa9, 0xb7, 0x32, 0xb6, 0x8e, 0x4b, 0x3b, 0x64, 0x46, 0xf5, 0x79,\n 0x18, 0x1c, 0x58, 0x20, 0x9b, 0xbe, 0x80, 0x85, 0x23, 0x6e, 0xd0, 0x36,\n 0x89, 0x0f, 0x9b, 0x03, 0xf0, 0x18, 0x53, 0x1c, 0x33, 0xb2, 0x4b, 0x34,\n 0xb2, 0x95, 0x2d, 0xe6, 0xdb, 0x79, 0x1f, 0x39, 0x02, 0xc4, 0xa6, 0x6d,\n 0x0a, 0x58, 0x20, 0x5b, 0xde, 0xa4, 0x3a, 0x31, 0xd1, 0x78, 0xc3, 0xc7,\n 0x2f, 0xec, 0x44, 0xc7, 0x1b, 0xe5, 0x15, 0xa2, 0x68, 0x96, 0x27, 0xbe,\n 0x2d, 0x3e, 0x71, 0x5c, 0x3b, 0xba, 0x4e, 0x25, 0x78, 0x53, 0x34, 0x14,\n 0x58, 0x20, 0x55, 0xe0, 0xe0, 0x5e, 0xc0, 0xd6, 0xe2, 0x59, 0x20, 0xf4,\n 0x6e, 0x64, 0x28, 0x6c, 0xa9, 0x81, 0xf4, 0xfc, 0xba, 0xe9, 0xa0, 0xbc,\n 0xbd, 0x8b, 0x89, 0x3a, 0x22, 0x5d, 0x94, 0xa6, 0xc6, 0x94, 0x16, 0x58,\n 0x20, 0xc8, 0xf2, 0xef, 0x54, 0xbf, 0xa6, 0xb8, 0x19, 0x67, 0xf4, 0x78,\n 0xb5, 0xa7, 0xa9, 0xee, 0x36, 0x64, 0xf6, 0x00, 0xac, 0x8d, 0x28, 0x9f,\n 0xef, 0xd6, 0xa8, 0x03, 0xd1, 0x10, 0x7a, 0xa6, 0xb0, 0x18, 0x1f, 0x58,\n 0x20, 0x6a, 0x93, 0x6b, 0xd3, 0x48, 0x23, 0xee, 0x83, 0x20, 0x9d, 0x76,\n 0x4d, 0x1e, 0x5d, 0x38, 0xa7, 0x0c, 0x0d, 0xf2, 0x08, 0x93, 0x71, 0xcb,\n 0xb9, 0x84, 0x4c, 0xff, 0xf9, 0xb5, 0xc5, 0xc8, 0xef, 0x18, 0x27, 0x58,\n 0x20, 0x1a, 0x40, 0x41, 0x2d, 0xf1, 0x81, 0x55, 0x2d, 0xe9, 0xb5, 0x41,\n 0x74, 0x46, 0x66, 0x04, 0x9a, 0x86, 0x9f, 0xb2, 0x7e, 0x2d, 0x58, 0x86,\n 0xf7, 0xa9, 0x97, 0x28, 0xeb, 0xb8, 0xb9, 0x44, 0x30, 0x07, 0x58, 0x20,\n 0x38, 0xb1, 0x69, 0x90, 0xb9, 0xfc, 0x76, 0xf2, 0x3a, 0x85, 0x16, 0x69,\n 0x0a, 0x28, 0xa8, 0x22, 0x79, 0xd2, 0xcb, 0xd9, 0x6c, 0xdf, 0xd8, 0x89,\n 0xe4, 0x2b, 0xac, 0xbf, 0x06, 0xb9, 0xf0, 0x52, 0x18, 0x25, 0x58, 0x20,\n 0xe7, 0x8b, 0x03, 0x63, 0x13, 0x0b, 0x2c, 0x0c, 0xd8, 0x87, 0x03, 0x1d,\n 0x42, 0x0b, 0xc9, 0xd3, 0x86, 0x87, 0x05, 0x35, 0xfb, 0x16, 0x73, 0xcc,\n 0xd8, 0x6a, 0xcb, 0x83, 0xde, 0x2a, 0x10, 0x7c, 0x18, 0x21, 0x58, 0x20,\n 0x89, 0x90, 0xf0, 0xdc, 0x1a, 0xde, 0xd7, 0xa4, 0x61, 0x34, 0x81, 0x2c,\n 0x44, 0x0f, 0xc0, 0x8b, 0xeb, 0xaa, 0xfb, 0xf4, 0x72, 0xbd, 0x29, 0x8d,\n 0xf2, 0x8f, 0x1c, 0x65, 0xbd, 0xd0, 0x07, 0xdf, 0x08, 0x58, 0x20, 0x75,\n 0x1e, 0x3b, 0x24, 0xef, 0xb3, 0x2f, 0x74, 0x08, 0x11, 0x2b, 0x12, 0xe8,\n 0x86, 0xec, 0x4c, 0xf6, 0x17, 0x61, 0x56, 0x2f, 0x5a, 0xbd, 0x5a, 0xe5,\n 0x71, 0xc7, 0x30, 0x72, 0x30, 0x6c, 0xd9, 0x03, 0x58, 0x20, 0x52, 0x09,\n 0x57, 0x17, 0x6a, 0x82, 0x2a, 0x51, 0x94, 0x47, 0xd6, 0x15, 0x23, 0x4b,\n 0xcd, 0x6b, 0x97, 0x2a, 0x71, 0x54, 0xf2, 0xa4, 0x69, 0x99, 0x2b, 0x2e,\n 0xc1, 0x86, 0x29, 0x18, 0x19, 0x58, 0x0f, 0x58, 0x20, 0x7f, 0x49, 0x2e,\n 0xcd, 0xad, 0xe9, 0xb0, 0x15, 0xf1, 0x9e, 0x96, 0x56, 0xb7, 0xcb, 0x4f,\n 0x27, 0xd9, 0x68, 0x40, 0xee, 0xd5, 0x34, 0x26, 0x64, 0xdc, 0xd2, 0x23,\n 0xd1, 0x56, 0x41, 0xa8, 0x1b, 0x13, 0x58, 0x20, 0x9d, 0x2c, 0xf0, 0x53,\n 0x97, 0x9a, 0x21, 0x62, 0x2d, 0xb9, 0x13, 0x95, 0xf7, 0x8a, 0xaf, 0x5b,\n 0x9c, 0x92, 0x39, 0x16, 0x53, 0xd8, 0xc5, 0xbb, 0x42, 0x68, 0xa6, 0x40,\n 0x83, 0x96, 0xfe, 0x28, 0x04, 0x58, 0x20, 0xf7, 0x97, 0xdf, 0xe4, 0x0f,\n 0x5d, 0x9a, 0x61, 0x6c, 0x9d, 0x26, 0xf3, 0x74, 0x22, 0x51, 0x56, 0xa0,\n 0x9e, 0x61, 0xae, 0xa4, 0xa4, 0x38, 0x60, 0x68, 0x18, 0xd4, 0xbd, 0x2c,\n 0xe6, 0x18, 0xb0, 0x0c, 0x58, 0x20, 0xe5, 0x95, 0x37, 0xec, 0x38, 0xe7,\n 0xa7, 0x8f, 0xe9, 0xe8, 0xc0, 0xe8, 0xa8, 0x18, 0x81, 0xe7, 0xc1, 0xe9,\n 0x2f, 0x11, 0x17, 0xb6, 0x29, 0x7a, 0xcf, 0xf1, 0x7c, 0x8e, 0x74, 0xd0,\n 0xad, 0x12, 0x09, 0x58, 0x20, 0x6f, 0x7f, 0xb1, 0xdf, 0x35, 0x2f, 0x23,\n 0x2f, 0x25, 0x9a, 0xc0, 0xa4, 0xee, 0x39, 0x76, 0x09, 0x3a, 0x32, 0x4f,\n 0xd1, 0xb1, 0xa1, 0xf3, 0x15, 0xb2, 0x48, 0x1d, 0x40, 0xa0, 0x69, 0x7c,\n 0xc5, 0x18, 0x18, 0x58, 0x20, 0x70, 0x58, 0x58, 0x66, 0xab, 0xf1, 0xc5,\n 0xfb, 0x60, 0xd5, 0xf4, 0xb0, 0x9a, 0xa8, 0xab, 0xb9, 0xf9, 0x52, 0x2a,\n 0x14, 0x2d, 0xc3, 0x54, 0xa1, 0x1c, 0xbe, 0xb8, 0x58, 0xf6, 0x1c, 0xa1,\n 0x40, 0x06, 0x58, 0x20, 0xb7, 0x60, 0x27, 0x85, 0xef, 0x55, 0x31, 0x9c,\n 0x6e, 0xf1, 0xd3, 0xea, 0x6f, 0x36, 0x1d, 0xa9, 0xe1, 0xf0, 0x04, 0x50,\n 0x13, 0xcd, 0x2f, 0x74, 0xa1, 0xd8, 0x24, 0x7d, 0x1a, 0x75, 0x86, 0xbe,\n 0x12, 0x58, 0x20, 0xc1, 0x9a, 0xdf, 0x46, 0x4a, 0x9b, 0x22, 0xc5, 0x79,\n 0xc0, 0x56, 0xbb, 0x0e, 0x45, 0x98, 0xb8, 0x90, 0xa0, 0xbb, 0x16, 0x83,\n 0xb7, 0x29, 0x06, 0x7f, 0xa8, 0x2c, 0x5e, 0x6a, 0x10, 0x3d, 0x2d, 0x18,\n 0x1b, 0x58, 0x20, 0x94, 0x97, 0xfa, 0xb1, 0xcb, 0xa4, 0x6c, 0xe4, 0x10,\n 0x90, 0x9f, 0x5d, 0xb0, 0xea, 0xda, 0x49, 0xc5, 0xf0, 0x19, 0x5e, 0xcb,\n 0x03, 0x22, 0x0d, 0xe9, 0xba, 0x88, 0xc9, 0x61, 0xc4, 0xbb, 0xf8, 0x00,\n 0x58, 0x20, 0x5b, 0x22, 0x5a, 0xa1, 0xc6, 0x31, 0x6a, 0xcf, 0xed, 0x2b,\n 0xe6, 0x70, 0x15, 0xed, 0x71, 0xc2, 0xda, 0x4d, 0x87, 0x3f, 0x01, 0xa2,\n 0xfd, 0xd4, 0xd6, 0x2f, 0xb3, 0x01, 0x23, 0x38, 0x6d, 0xc8, 0x0e, 0x58,\n 0x20, 0xcf, 0x32, 0x74, 0x8e, 0x98, 0xfb, 0x6b, 0x9d, 0xee, 0x3d, 0x48,\n 0x42, 0x1f, 0xb5, 0xf6, 0xb4, 0x50, 0x24, 0xae, 0x46, 0x87, 0x89, 0x25,\n 0x79, 0xaa, 0x05, 0xe3, 0x10, 0x24, 0x60, 0x21, 0x80, 0x15, 0x58, 0x20,\n 0x71, 0xcd, 0x46, 0x7c, 0x9c, 0x1c, 0x7a, 0x0c, 0x88, 0x95, 0x06, 0xe9,\n 0x7e, 0x13, 0x35, 0xe0, 0xff, 0xb8, 0x1f, 0xd1, 0x9d, 0x8d, 0x5c, 0x84,\n 0x8d, 0x74, 0xd7, 0x02, 0x31, 0xab, 0xfa, 0x82, 0x18, 0x20, 0x58, 0x20,\n 0x88, 0x22, 0x51, 0x86, 0xc9, 0x41, 0xc8, 0x05, 0xea, 0xff, 0x63, 0x9d,\n 0xa5, 0xaf, 0x04, 0xaa, 0xf0, 0xe9, 0xad, 0x7c, 0xb4, 0x84, 0xb1, 0x66,\n 0x66, 0x94, 0x32, 0xed, 0x65, 0xf6, 0x3d, 0x52, 0x18, 0x26, 0x58, 0x20,\n 0xc6, 0xba, 0x1f, 0x99, 0x66, 0xd5, 0x25, 0x51, 0x5d, 0xc9, 0x0c, 0x48,\n 0x3f, 0x93, 0x25, 0xfe, 0x3d, 0x8d, 0x08, 0x3e, 0x2c, 0x58, 0xb6, 0x85,\n 0x97, 0x2b, 0x30, 0x8b, 0x4d, 0xa4, 0x3e, 0x31, 0x0d, 0x58, 0x20, 0x33,\n 0xb6, 0xfc, 0x44, 0xed, 0x68, 0x73, 0x54, 0x37, 0x11, 0xf5, 0xe7, 0x97,\n 0x9d, 0xef, 0xe9, 0xa7, 0x1a, 0x1b, 0x4a, 0x25, 0x4f, 0x91, 0x64, 0xf4,\n 0xfc, 0x37, 0xff, 0xb8, 0x00, 0x48, 0x50, 0x18, 0x1d, 0x58, 0x20, 0x3e,\n 0x1f, 0xfd, 0x36, 0x5a, 0x73, 0xb6, 0x9e, 0x8e, 0xe3, 0x7e, 0xd9, 0x1a,\n 0xc2, 0x7f, 0x79, 0xa1, 0x37, 0x00, 0xa7, 0xbc, 0x2e, 0xfe, 0xc0, 0xad,\n 0x0c, 0xce, 0xd1, 0xde, 0xb5, 0xbe, 0xbf, 0x18, 0x1e, 0x58, 0x20, 0x40,\n 0x89, 0xa1, 0x71, 0x6a, 0x4a, 0xd5, 0xb9, 0xd0, 0xf6, 0xd5, 0x18, 0xd3,\n 0x85, 0xd5, 0x2f, 0x77, 0xa2, 0x0d, 0x50, 0x46, 0x16, 0xf9, 0xc5, 0x88,\n 0xbd, 0x60, 0xc6, 0x14, 0xcd, 0x24, 0x8a, 0x11, 0x58, 0x20, 0x82, 0x1e,\n 0xa8, 0x0b, 0x1b, 0x53, 0x3b, 0xf3, 0x2c, 0x6c, 0x0f, 0xce, 0xdf, 0x78,\n 0x9d, 0x92, 0xac, 0xe2, 0x78, 0xc8, 0x68, 0x23, 0x06, 0x70, 0xe3, 0x41,\n 0xf9, 0x51, 0xfa, 0x15, 0x0b, 0xaa, 0x01, 0x58, 0x20, 0xa5, 0x8a, 0x7b,\n 0xe3, 0x89, 0x6c, 0x72, 0xb3, 0xce, 0x94, 0xe2, 0xc8, 0xf8, 0x23, 0x84,\n 0x0e, 0xc6, 0xe2, 0xd0, 0xe3, 0x2f, 0x9e, 0x27, 0xce, 0x4d, 0x51, 0xfb,\n 0x3e, 0xe1, 0x7c, 0x59, 0xd7, 0x02, 0x58, 0x20, 0xe4, 0xeb, 0x6b, 0x2d,\n 0x3c, 0x36, 0xd3, 0x54, 0xfe, 0x1e, 0xe2, 0x81, 0x89, 0x29, 0x49, 0x79,\n 0x82, 0x84, 0x82, 0xe3, 0x02, 0x64, 0x8b, 0x42, 0xd6, 0x4f, 0x89, 0xd8,\n 0x97, 0x02, 0x2e, 0x11, 0x17, 0x58, 0x20, 0xa3, 0x13, 0xf2, 0x6c, 0xb6,\n 0x25, 0xd2, 0x52, 0x20, 0x25, 0xf3, 0x33, 0x51, 0x17, 0x5c, 0xa0, 0x9a,\n 0xe5, 0x4d, 0xa5, 0xee, 0x6a, 0x75, 0x05, 0xa5, 0x40, 0xef, 0x55, 0x3c,\n 0xdd, 0x60, 0x29, 0x0b, 0x58, 0x20, 0x96, 0x47, 0xf0, 0xf8, 0xbc, 0x91,\n 0xd5, 0xc2, 0xb2, 0x48, 0x17, 0xb6, 0xe0, 0x0d, 0x7a, 0xfb, 0x2f, 0xa4,\n 0xe7, 0x8f, 0x4c, 0xce, 0xa3, 0x15, 0xeb, 0xfc, 0x01, 0xc4, 0x4a, 0xa0,\n 0x13, 0xd6, 0x77, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31,\n 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0x2e, 0x61, 0x61, 0x6d,\n 0x76, 0x61, 0xa6, 0x18, 0x19, 0x58, 0x20, 0xa6, 0xa9, 0x09, 0x5c, 0xa8,\n 0x57, 0xc0, 0x29, 0x4d, 0x81, 0x50, 0x8b, 0x26, 0xd6, 0x59, 0xa7, 0x73,\n 0xaf, 0x30, 0xfc, 0x24, 0x21, 0x5a, 0xb2, 0xdf, 0x92, 0xe2, 0x1e, 0x8f,\n 0xe7, 0xbf, 0xfb, 0x05, 0x58, 0x20, 0xfc, 0xba, 0xdd, 0x35, 0xf1, 0x3a,\n 0xf1, 0x53, 0xaa, 0xf1, 0x72, 0x7b, 0x3f, 0xd6, 0x86, 0x77, 0xfc, 0x5d,\n 0x52, 0xbb, 0xef, 0xc0, 0xd7, 0x9d, 0x1c, 0x35, 0xf3, 0x47, 0xd6, 0xd0,\n 0xce, 0x8c, 0x18, 0x23, 0x58, 0x20, 0x8b, 0x09, 0xae, 0xb3, 0xd6, 0x7d,\n 0x66, 0xb9, 0xe2, 0x65, 0x5a, 0x4f, 0x4f, 0xe9, 0x0e, 0x2b, 0x16, 0x42,\n 0x66, 0x81, 0x92, 0x7c, 0x05, 0xcb, 0x27, 0x8b, 0xe5, 0x4b, 0x6a, 0xca,\n 0x89, 0x3e, 0x10, 0x58, 0x20, 0x9b, 0xcd, 0x90, 0x2b, 0x6b, 0xcf, 0x9d,\n 0xa8, 0x70, 0xc1, 0x48, 0x4f, 0x14, 0x53, 0x23, 0xfc, 0x84, 0xa2, 0x64,\n 0xd4, 0x22, 0x41, 0x37, 0x52, 0x1c, 0x03, 0x53, 0xc4, 0x8c, 0x22, 0xc3,\n 0xab, 0x18, 0x24, 0x58, 0x20, 0x0f, 0xd3, 0xd9, 0x88, 0xef, 0x7c, 0x64,\n 0x0c, 0xc4, 0x83, 0xf1, 0x23, 0xcb, 0x0b, 0xeb, 0x0c, 0x49, 0xaa, 0x6e,\n 0xdd, 0xae, 0x96, 0xec, 0x17, 0xaf, 0x66, 0x58, 0x6b, 0x05, 0x16, 0x73,\n 0x55, 0x18, 0x22, 0x58, 0x20, 0x45, 0x87, 0xe3, 0x6a, 0x16, 0x9a, 0x71,\n 0xd6, 0xf2, 0x51, 0xfa, 0x39, 0x68, 0x69, 0x81, 0x22, 0x9e, 0x97, 0xe6,\n 0x46, 0xc9, 0x84, 0x3c, 0x1b, 0x5a, 0x13, 0x91, 0xdb, 0x03, 0x6b, 0xd2,\n 0xc0, 0x6d, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79, 0x49,\n 0x6e, 0x66, 0x6f, 0xa1, 0x69, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4b,\n 0x65, 0x79, 0xa4, 0x01, 0x02, 0x20, 0x01, 0x21, 0x58, 0x20, 0x53, 0x1a,\n 0x86, 0xbd, 0xc5, 0xae, 0xa7, 0xb4, 0xbf, 0xf1, 0x12, 0x08, 0xef, 0xb5,\n 0xc5, 0xa7, 0xdb, 0x1b, 0x00, 0x17, 0xc0, 0x20, 0xd7, 0xd9, 0xf6, 0xbf,\n 0x89, 0x2d, 0x47, 0xa6, 0x17, 0xd1, 0x22, 0x58, 0x20, 0x24, 0xac, 0x72,\n 0x74, 0xf7, 0xe6, 0xa1, 0x0a, 0x39, 0x56, 0xb9, 0x2e, 0x5a, 0xc2, 0xf8,\n 0xab, 0x53, 0xcd, 0x8a, 0xb3, 0xb4, 0x38, 0x22, 0xab, 0x1d, 0x05, 0x90,\n 0x4f, 0x3b, 0x50, 0xb2, 0xd6, 0x6c, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x69,\n 0x74, 0x79, 0x49, 0x6e, 0x66, 0x6f, 0xa3, 0x66, 0x73, 0x69, 0x67, 0x6e,\n 0x65, 0x64, 0xc0, 0x74, 0x32, 0x30, 0x32, 0x34, 0x2d, 0x30, 0x39, 0x2d,\n 0x33, 0x30, 0x54, 0x31, 0x33, 0x3a, 0x35, 0x30, 0x3a, 0x30, 0x30, 0x5a,\n 0x69, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x46, 0x72, 0x6f, 0x6d, 0xc0, 0x74,\n 0x32, 0x30, 0x32, 0x34, 0x2d, 0x30, 0x39, 0x2d, 0x33, 0x30, 0x54, 0x31,\n 0x33, 0x3a, 0x35, 0x30, 0x3a, 0x30, 0x30, 0x5a, 0x6a, 0x76, 0x61, 0x6c,\n 0x69, 0x64, 0x55, 0x6e, 0x74, 0x69, 0x6c, 0xc0, 0x74, 0x32, 0x30, 0x32,\n 0x34, 0x2d, 0x31, 0x30, 0x2d, 0x33, 0x30, 0x54, 0x31, 0x33, 0x3a, 0x35,\n 0x30, 0x3a, 0x30, 0x30, 0x5a, 0x58, 0x40, 0xc9, 0x9b, 0xd4, 0x13, 0xf8,\n 0x8d, 0xd3, 0xf1, 0x54, 0xe5, 0x82, 0x70, 0x10, 0xe3, 0x43, 0x14, 0xb4,\n 0x41, 0x2d, 0x4d, 0x25, 0x1a, 0xed, 0x28, 0xda, 0xae, 0xe2, 0x23, 0x36,\n 0x0a, 0x9d, 0xcc, 0x9f, 0xe9, 0x45, 0x08, 0x7e, 0x56, 0xc9, 0xa5, 0x4d,\n 0xb6, 0x7a, 0x0a, 0xe3, 0xd7, 0xe1, 0xa6, 0x2e, 0xfa, 0x63, 0xc3, 0x09,\n 0x74, 0x54, 0xa0, 0xe7, 0x82, 0xfa, 0x05, 0x77, 0xe5, 0xc4, 0xdc, 0x6c,\n 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64,\n 0xa2, 0x6a, 0x6e, 0x61, 0x6d, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x73,\n 0xd8, 0x18, 0x41, 0xa0, 0x6a, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x41,\n 0x75, 0x74, 0x68, 0xa1, 0x6f, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x53,\n 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x84, 0x43, 0xa1, 0x01,\n 0x26, 0xa0, 0xf6, 0x58, 0x40, 0x83, 0xef, 0x0e, 0x35, 0xd8, 0xc5, 0x36,\n 0x92, 0xb7, 0x1e, 0x9a, 0xea, 0x4c, 0x28, 0xab, 0xac, 0xd4, 0xf8, 0x50,\n 0x1d, 0x49, 0x21, 0x82, 0x2d, 0x24, 0xd1, 0xd4, 0x82, 0x6b, 0x2e, 0x4e,\n 0xe5, 0x0d, 0x2c, 0x3d, 0x35, 0xac, 0x4a, 0xf2, 0xdf, 0x95, 0x4e, 0x3a,\n 0x29, 0x72, 0x8a, 0xad, 0xb7, 0x9b, 0xdd, 0x86, 0xc6, 0x25, 0xe9, 0xd6,\n 0x7a, 0xb9, 0x0c, 0xbd, 0x7c, 0xd0, 0x7a, 0xe1, 0x3c, 0x66, 0x73, 0x74,\n 0x61, 0x74, 0x75, 0x73, 0x00},\n },\n // Google IACA identity-pass example\n {StaticString(\n \"0x5070e8199f3c5e1ecf6249662994997605b7205b039ff77fad4f9aceb3cadbcd\"),\n StaticString(\n \"0xc2f6fa056f2423ca57f828ded12656bdae863f23654561d494ae5efa9feb883f\"),\n {0x83, 0xf6, 0xf6, 0x84, 0x71, 0x42, 0x72, 0x6f, 0x77, 0x73, 0x65, 0x72,\n 0x48, 0x61, 0x6e, 0x64, 0x6f, 0x76, 0x65, 0x72, 0x76, 0x31, 0x58, 0x37,\n 0x01, 0x06, 0x78, 0x53, 0x3e, 0x47, 0xa7, 0xdb, 0x12, 0xde, 0x39, 0x1a,\n 0x58, 0xa0, 0x53, 0x1a, 0x13, 0x3e, 0x8f, 0x07, 0x14, 0xee, 0x07, 0x5f,\n 0xcb, 0x38, 0x4a, 0xf9, 0x0a, 0xb1, 0x71, 0x31, 0xce, 0x24, 0x1e, 0x7b,\n 0xf0, 0x71, 0x98, 0x32, 0xb5, 0xad, 0x02, 0xac, 0xee, 0x72, 0xfd, 0x69,\n 0x0e, 0xf3, 0x45, 0x28, 0x09, 0x71, 0xde, 0x58, 0x49, 0xa3, 0x63, 0x63,\n 0x61, 0x74, 0x01, 0x64, 0x74, 0x79, 0x70, 0x65, 0x01, 0x67, 0x64, 0x65,\n 0x74, 0x61, 0x69, 0x6c, 0x73, 0xa1, 0x67, 0x62, 0x61, 0x73, 0x65, 0x55,\n 0x72, 0x6c, 0x78, 0x2a, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f,\n 0x6f, 0x76, 0x32, 0x2d, 0x74, 0x64, 0x6d, 0x67, 0x70, 0x77, 0x61, 0x6d,\n 0x2e, 0x64, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x72, 0x70, 0x2e,\n 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x58, 0x20,\n 0xc5, 0x86, 0xef, 0x29, 0xc7, 0xf0, 0x76, 0xfc, 0x15, 0x2b, 0x93, 0x85,\n 0x94, 0x7e, 0x82, 0x58, 0x9d, 0x6d, 0xe2, 0x43, 0xae, 0x18, 0x90, 0xef,\n 0x08, 0x5f, 0xd1, 0x31, 0x2b, 0x1f, 0x25, 0xdd},\n 188,\n (uint8_t *)\"2025-01-29T18:00:00Z\",\n kIDPass,\n 2211,\n {0xa3, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e,\n 0x30, 0x69, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x81,\n 0xa3, 0x67, 0x64, 0x6f, 0x63, 0x54, 0x79, 0x70, 0x65, 0x78, 0x1a, 0x63,\n 0x6f, 0x6d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x77, 0x61,\n 0x6c, 0x6c, 0x65, 0x74, 0x2e, 0x69, 0x64, 0x63, 0x61, 0x72, 0x64, 0x2e,\n 0x31, 0x6c, 0x69, 0x73, 0x73, 0x75, 0x65, 0x72, 0x53, 0x69, 0x67, 0x6e,\n 0x65, 0x64, 0xa2, 0x6a, 0x6e, 0x61, 0x6d, 0x65, 0x53, 0x70, 0x61, 0x63,\n 0x65, 0x73, 0xa1, 0x71, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e,\n 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0x81, 0xd8, 0x18,\n 0x58, 0x5d, 0xa4, 0x68, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74, 0x49, 0x44,\n 0x19, 0xeb, 0xa5, 0x66, 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x50, 0xfa,\n 0xe2, 0x65, 0x0e, 0x5a, 0x8a, 0x33, 0x39, 0x2b, 0xc5, 0x74, 0x26, 0x6f,\n 0x4d, 0x19, 0xa7, 0x71, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x49,\n 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x6a, 0x62, 0x69,\n 0x72, 0x74, 0x68, 0x5f, 0x64, 0x61, 0x74, 0x65, 0x6c, 0x65, 0x6c, 0x65,\n 0x6d, 0x65, 0x6e, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0xd9, 0x03, 0xec,\n 0x6a, 0x31, 0x39, 0x39, 0x38, 0x2d, 0x30, 0x39, 0x2d, 0x30, 0x34, 0x6a,\n 0x69, 0x73, 0x73, 0x75, 0x65, 0x72, 0x41, 0x75, 0x74, 0x68, 0x84, 0x43,\n 0xa1, 0x01, 0x26, 0xa1, 0x18, 0x21, 0x59, 0x03, 0x91, 0x30, 0x82, 0x03,\n 0x8d, 0x30, 0x82, 0x03, 0x12, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x13,\n 0x35, 0xa5, 0x2a, 0x85, 0x87, 0x44, 0xb0, 0x01, 0x08, 0x5b, 0xe6, 0xaa,\n 0x4c, 0x72, 0xf8, 0xc8, 0x8f, 0x04, 0x97, 0x30, 0x0a, 0x06, 0x08, 0x2a,\n 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x03, 0x30, 0x5d, 0x31, 0x0b, 0x30,\n 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x54, 0x31, 0x13,\n 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0a, 0x47, 0x6f, 0x6f,\n 0x67, 0x6c, 0x65, 0x20, 0x4c, 0x4c, 0x43, 0x31, 0x0f, 0x30, 0x0d, 0x06,\n 0x03, 0x55, 0x04, 0x0b, 0x13, 0x06, 0x57, 0x61, 0x6c, 0x6c, 0x65, 0x74,\n 0x31, 0x28, 0x30, 0x26, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x1f, 0x54,\n 0x45, 0x53, 0x54, 0x20, 0x55, 0x53, 0x45, 0x20, 0x4f, 0x4e, 0x4c, 0x59,\n 0x20, 0x47, 0x49, 0x43, 0x49, 0x20, 0x53, 0x74, 0x61, 0x67, 0x69, 0x6e,\n 0x67, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34,\n 0x30, 0x33, 0x32, 0x38, 0x30, 0x31, 0x32, 0x32, 0x30, 0x30, 0x5a, 0x17,\n 0x0d, 0x32, 0x35, 0x30, 0x33, 0x32, 0x38, 0x30, 0x31, 0x32, 0x31, 0x35,\n 0x39, 0x5a, 0x30, 0x5b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,\n 0x06, 0x13, 0x02, 0x55, 0x54, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55,\n 0x04, 0x0a, 0x13, 0x0a, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x20, 0x4c,\n 0x4c, 0x43, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13,\n 0x06, 0x57, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x31, 0x26, 0x30, 0x24, 0x06,\n 0x03, 0x55, 0x04, 0x03, 0x13, 0x1d, 0x54, 0x45, 0x53, 0x54, 0x20, 0x55,\n 0x53, 0x45, 0x20, 0x4f, 0x4e, 0x4c, 0x59, 0x20, 0x47, 0x49, 0x43, 0x49,\n 0x20, 0x53, 0x74, 0x61, 0x67, 0x69, 0x6e, 0x67, 0x20, 0x44, 0x53, 0x30,\n 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01,\n 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42,\n 0x00, 0x04, 0x50, 0x70, 0xe8, 0x19, 0x9f, 0x3c, 0x5e, 0x1e, 0xcf, 0x62,\n 0x49, 0x66, 0x29, 0x94, 0x99, 0x76, 0x05, 0xb7, 0x20, 0x5b, 0x03, 0x9f,\n 0xf7, 0x7f, 0xad, 0x4f, 0x9a, 0xce, 0xb3, 0xca, 0xdb, 0xcd, 0xc2, 0xf6,\n 0xfa, 0x05, 0x6f, 0x24, 0x23, 0xca, 0x57, 0xf8, 0x28, 0xde, 0xd1, 0x26,\n 0x56, 0xbd, 0xae, 0x86, 0x3f, 0x23, 0x65, 0x45, 0x61, 0xd4, 0x94, 0xae,\n 0x5e, 0xfa, 0x9f, 0xeb, 0x88, 0x3f, 0xa3, 0x82, 0x01, 0xb1, 0x30, 0x82,\n 0x01, 0xad, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff,\n 0x04, 0x04, 0x03, 0x02, 0x07, 0x80, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d,\n 0x13, 0x01, 0x01, 0xff, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03,\n 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x62, 0x1b, 0xd1, 0x8c, 0xa5,\n 0x64, 0x49, 0x37, 0x2b, 0x6f, 0x0c, 0xf7, 0x82, 0x17, 0xac, 0x8a, 0x6d,\n 0xa3, 0xde, 0x67, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18,\n 0x30, 0x16, 0x80, 0x14, 0x9f, 0x5a, 0x68, 0xc3, 0xe9, 0x80, 0x19, 0xde,\n 0xe9, 0x98, 0x25, 0x64, 0xf6, 0xba, 0x23, 0x84, 0xff, 0x92, 0xed, 0xb4,\n 0x30, 0x81, 0x8d, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x01,\n 0x01, 0x04, 0x81, 0x80, 0x30, 0x7e, 0x30, 0x7c, 0x06, 0x08, 0x2b, 0x06,\n 0x01, 0x05, 0x05, 0x07, 0x30, 0x02, 0x86, 0x70, 0x68, 0x74, 0x74, 0x70,\n 0x3a, 0x2f, 0x2f, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x63, 0x61,\n 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x36, 0x36, 0x30,\n 0x33, 0x63, 0x36, 0x34, 0x37, 0x2d, 0x30, 0x30, 0x30, 0x30, 0x2d, 0x32,\n 0x39, 0x64, 0x34, 0x2d, 0x61, 0x65, 0x61, 0x36, 0x2d, 0x66, 0x34, 0x66,\n 0x35, 0x65, 0x38, 0x30, 0x64, 0x31, 0x62, 0x39, 0x30, 0x2e, 0x73, 0x74,\n 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65,\n 0x61, 0x70, 0x69, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x34, 0x31, 0x64,\n 0x34, 0x33, 0x36, 0x38, 0x35, 0x39, 0x65, 0x34, 0x35, 0x64, 0x62, 0x66,\n 0x33, 0x65, 0x35, 0x61, 0x39, 0x2f, 0x63, 0x61, 0x2e, 0x63, 0x72, 0x74,\n 0x30, 0x81, 0x82, 0x06, 0x03, 0x55, 0x1d, 0x1f, 0x04, 0x7b, 0x30, 0x79,\n 0x30, 0x77, 0xa0, 0x75, 0xa0, 0x73, 0x86, 0x71, 0x68, 0x74, 0x74, 0x70,\n 0x3a, 0x2f, 0x2f, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x63, 0x61,\n 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x36, 0x36, 0x30,\n 0x33, 0x63, 0x36, 0x34, 0x37, 0x2d, 0x30, 0x30, 0x30, 0x30, 0x2d, 0x32,\n 0x39, 0x64, 0x34, 0x2d, 0x61, 0x65, 0x61, 0x36, 0x2d, 0x66, 0x34, 0x66,\n 0x35, 0x65, 0x38, 0x30, 0x64, 0x31, 0x62, 0x39, 0x30, 0x2e, 0x73, 0x74,\n 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65,\n 0x61, 0x70, 0x69, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x34, 0x31, 0x64,\n 0x34, 0x33, 0x36, 0x38, 0x35, 0x39, 0x65, 0x34, 0x35, 0x64, 0x62, 0x66,\n 0x33, 0x65, 0x35, 0x61, 0x39, 0x2f, 0x63, 0x72, 0x6c, 0x2e, 0x63, 0x72,\n 0x6c, 0x30, 0x21, 0x06, 0x03, 0x55, 0x1d, 0x12, 0x04, 0x1a, 0x30, 0x18,\n 0x86, 0x16, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x77, 0x77,\n 0x77, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d,\n 0x30, 0x15, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x01, 0x01, 0xff, 0x04, 0x0b,\n 0x30, 0x09, 0x06, 0x07, 0x28, 0x81, 0x8c, 0x5d, 0x05, 0x01, 0x02, 0x30,\n 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x03, 0x03,\n 0x69, 0x00, 0x30, 0x66, 0x02, 0x31, 0x00, 0xfb, 0xa3, 0xb8, 0xf1, 0x2d,\n 0x58, 0xc6, 0xdf, 0x20, 0xbc, 0xa2, 0x6a, 0x6c, 0x2e, 0x9c, 0x30, 0x9e,\n 0x26, 0xf9, 0x75, 0x85, 0x16, 0x95, 0x71, 0xab, 0x11, 0xf1, 0x35, 0xb0,\n 0x4c, 0xd8, 0x19, 0x24, 0x6b, 0x24, 0x3f, 0xc0, 0xdc, 0x89, 0xab, 0x65,\n 0x4a, 0x4a, 0xe7, 0xc9, 0x25, 0xf5, 0x32, 0x02, 0x31, 0x00, 0xf9, 0xe0,\n 0xd4, 0x0a, 0xfc, 0x35, 0x6f, 0x74, 0x2d, 0xb0, 0x65, 0x7e, 0x64, 0xd7,\n 0xc8, 0x1f, 0x12, 0x64, 0x3c, 0x39, 0xc1, 0xeb, 0x3e, 0x6a, 0xf9, 0x0c,\n 0xd6, 0x24, 0x4e, 0xbf, 0x0d, 0x1a, 0xb7, 0x7a, 0x38, 0x01, 0x84, 0x5f,\n 0x0e, 0xcf, 0xc8, 0x69, 0x9c, 0x7c, 0xa0, 0xef, 0xf5, 0xde, 0x59, 0x03,\n 0x62, 0xd8, 0x18, 0x59, 0x03, 0x5d, 0xa6, 0x67, 0x76, 0x65, 0x72, 0x73,\n 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e, 0x30, 0x6f, 0x64, 0x69, 0x67, 0x65,\n 0x73, 0x74, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x67,\n 0x53, 0x48, 0x41, 0x2d, 0x32, 0x35, 0x36, 0x6c, 0x76, 0x61, 0x6c, 0x75,\n 0x65, 0x44, 0x69, 0x67, 0x65, 0x73, 0x74, 0x73, 0xa2, 0x71, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0xad, 0x19, 0x11, 0x9e, 0x58, 0x20, 0x0e, 0xc0, 0x48,\n 0x3e, 0x52, 0xb7, 0xe5, 0xb1, 0xa3, 0xba, 0xd7, 0x2d, 0xc3, 0x53, 0x13,\n 0x9b, 0x10, 0x83, 0xc0, 0x48, 0x37, 0xe0, 0xab, 0x2d, 0x62, 0x24, 0xb0,\n 0x31, 0xeb, 0xed, 0x79, 0x8f, 0x19, 0x29, 0xfa, 0x58, 0x20, 0x14, 0x6c,\n 0x91, 0x85, 0x3b, 0x61, 0xf0, 0xbd, 0x9d, 0x88, 0x93, 0x61, 0xfa, 0x40,\n 0x23, 0xe6, 0x22, 0xfe, 0x5b, 0x6a, 0x20, 0xaa, 0xd4, 0xa0, 0xad, 0x2a,\n 0x58, 0x48, 0x5e, 0xdf, 0xa3, 0x17, 0x19, 0x3f, 0x01, 0x58, 0x20, 0xfc,\n 0xb0, 0x96, 0xe0, 0x4d, 0xbe, 0x0e, 0xd5, 0x7a, 0xfe, 0x9a, 0x3c, 0x94,\n 0xd5, 0xca, 0x1f, 0x2e, 0x4f, 0x42, 0xf6, 0xa8, 0xae, 0xb6, 0x6a, 0x30,\n 0x5a, 0x73, 0xe8, 0x02, 0xf5, 0xd8, 0x0d, 0x19, 0x45, 0x0e, 0x58, 0x20,\n 0x4d, 0x55, 0x56, 0xdf, 0xe9, 0x6d, 0x0b, 0x4d, 0xd8, 0x3a, 0x03, 0xe5,\n 0x17, 0xe0, 0xa7, 0x85, 0xe5, 0xf6, 0x74, 0xb3, 0x87, 0xdc, 0xc8, 0xa6,\n 0x6c, 0x1b, 0x2f, 0x07, 0x87, 0x32, 0x44, 0x6c, 0x19, 0x4b, 0x15, 0x58,\n 0x20, 0x5a, 0x4e, 0xd4, 0xb6, 0x25, 0xa1, 0x67, 0x08, 0xa0, 0x02, 0xee,\n 0x8e, 0xfd, 0xfa, 0xa8, 0x34, 0x69, 0xe4, 0x28, 0xe2, 0x5e, 0x4b, 0xfe,\n 0xc2, 0xc3, 0xb6, 0xef, 0x7d, 0x5a, 0x98, 0xd3, 0xab, 0x19, 0x4b, 0xf9,\n 0x58, 0x20, 0x1f, 0xf4, 0x99, 0xcc, 0x18, 0x3a, 0xc8, 0xbb, 0x57, 0xce,\n 0x2d, 0xd6, 0x1d, 0xa2, 0x5e, 0x13, 0xe3, 0xc0, 0x71, 0xf1, 0xe9, 0x66,\n 0xbf, 0xf8, 0xc4, 0xa4, 0xab, 0x72, 0xa4, 0xc9, 0x31, 0x75, 0x19, 0x63,\n 0x99, 0x58, 0x20, 0xf9, 0x3d, 0xce, 0xdd, 0x21, 0x16, 0x53, 0xd9, 0x9c,\n 0x8a, 0x62, 0x70, 0x29, 0x10, 0xc5, 0x27, 0x57, 0x97, 0x24, 0x68, 0x57,\n 0xf8, 0x2a, 0xbe, 0x9c, 0xd5, 0xcd, 0xc0, 0x78, 0x36, 0x56, 0x74, 0x19,\n 0x65, 0x90, 0x58, 0x20, 0xa3, 0xf5, 0xc6, 0xc4, 0x74, 0x6a, 0xb5, 0x9d,\n 0xae, 0x8c, 0x43, 0x26, 0xf8, 0x00, 0xac, 0x25, 0xf3, 0xd8, 0x45, 0x3e,\n 0xf2, 0x14, 0x1e, 0x1c, 0x4f, 0x24, 0x46, 0x11, 0x8f, 0x7b, 0x59, 0xba,\n 0x19, 0x6e, 0xfb, 0x58, 0x20, 0xe1, 0x85, 0x25, 0xb6, 0x6f, 0xc9, 0x72,\n 0x86, 0x1d, 0x84, 0xc5, 0x7c, 0x60, 0x1e, 0x3b, 0xfb, 0x9f, 0x05, 0x4c,\n 0x8c, 0x1c, 0xb6, 0xb4, 0xb9, 0x50, 0xa1, 0x27, 0x7f, 0xb1, 0x13, 0xc7,\n 0x9a, 0x19, 0x94, 0xe0, 0x58, 0x20, 0xa5, 0x61, 0x36, 0x4f, 0x92, 0x27,\n 0xa5, 0x8c, 0xfb, 0xfd, 0xbf, 0x7c, 0xb2, 0x29, 0x17, 0x0c, 0xd0, 0x5c,\n 0x7b, 0x10, 0x9c, 0x7a, 0xa5, 0x1d, 0xa6, 0x76, 0x81, 0x72, 0xb9, 0x1f,\n 0x7f, 0x57, 0x19, 0x97, 0xbd, 0x58, 0x20, 0x04, 0xd5, 0xbe, 0xd8, 0x7e,\n 0x03, 0xb9, 0x08, 0xd2, 0x64, 0x76, 0x2d, 0x8f, 0x8d, 0xd6, 0x41, 0x2b,\n 0x61, 0xbb, 0xa4, 0x3d, 0xd7, 0x08, 0x70, 0x8b, 0xdd, 0x96, 0x94, 0x4d,\n 0xc4, 0xce, 0x5e, 0x19, 0xe1, 0x7b, 0x58, 0x20, 0x69, 0xcb, 0x57, 0x76,\n 0xe1, 0x2c, 0xe1, 0xe0, 0x06, 0x31, 0xbd, 0x8f, 0x76, 0x54, 0x99, 0x34,\n 0x4f, 0x27, 0x0f, 0x64, 0xd6, 0x45, 0xc6, 0x08, 0x88, 0x77, 0xa0, 0x3f,\n 0xa3, 0x90, 0x2e, 0x87, 0x19, 0xeb, 0xa5, 0x58, 0x20, 0x99, 0x03, 0xd0,\n 0x2a, 0xbd, 0xc6, 0x12, 0xc3, 0xde, 0xe7, 0x52, 0xbd, 0x88, 0x62, 0xed,\n 0xe0, 0xe3, 0x86, 0x8e, 0xe2, 0xa2, 0x0f, 0x5d, 0xc8, 0xdb, 0x03, 0x1a,\n 0x5f, 0x57, 0xd7, 0x5e, 0x4a, 0x78, 0x1a, 0x63, 0x6f, 0x6d, 0x2e, 0x67,\n 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74,\n 0x2e, 0x69, 0x64, 0x63, 0x61, 0x72, 0x64, 0x2e, 0x31, 0xa1, 0x19, 0x32,\n 0xab, 0x58, 0x20, 0xbb, 0x51, 0x2c, 0x61, 0x32, 0xd0, 0x3a, 0x2f, 0x13,\n 0xb7, 0x6a, 0x84, 0x37, 0x55, 0x82, 0xe7, 0x1d, 0xfa, 0x49, 0x76, 0x89,\n 0x81, 0xfa, 0xba, 0xf5, 0x3f, 0x84, 0x34, 0x01, 0x6b, 0x5e, 0x7b, 0x6d,\n 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79, 0x49, 0x6e, 0x66,\n 0x6f, 0xa1, 0x69, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79,\n 0xa4, 0x01, 0x02, 0x20, 0x01, 0x21, 0x58, 0x20, 0x84, 0x59, 0x27, 0x1c,\n 0xa2, 0x99, 0x4e, 0x77, 0x51, 0x7b, 0x74, 0x3f, 0x76, 0xfd, 0xbb, 0x81,\n 0x79, 0xad, 0xf1, 0x31, 0x31, 0xbb, 0x48, 0x7e, 0x93, 0x9b, 0xd1, 0x7b,\n 0xc7, 0xe8, 0xf5, 0x43, 0x22, 0x58, 0x20, 0x69, 0x0b, 0x7b, 0xf6, 0x3f,\n 0x8d, 0x14, 0x69, 0x5b, 0xc5, 0xd5, 0xcb, 0x4a, 0x82, 0x23, 0xfb, 0x7b,\n 0xee, 0x6d, 0xdd, 0x08, 0x7d, 0x9e, 0x3f, 0x06, 0xfc, 0x16, 0xff, 0xe8,\n 0x84, 0xce, 0x83, 0x67, 0x64, 0x6f, 0x63, 0x54, 0x79, 0x70, 0x65, 0x78,\n 0x1a, 0x63, 0x6f, 0x6d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,\n 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x2e, 0x69, 0x64, 0x63, 0x61, 0x72,\n 0x64, 0x2e, 0x31, 0x6c, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x69, 0x74, 0x79,\n 0x49, 0x6e, 0x66, 0x6f, 0xa3, 0x66, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64,\n 0xc0, 0x74, 0x32, 0x30, 0x32, 0x35, 0x2d, 0x30, 0x31, 0x2d, 0x32, 0x39,\n 0x54, 0x31, 0x34, 0x3a, 0x33, 0x39, 0x3a, 0x32, 0x38, 0x5a, 0x69, 0x76,\n 0x61, 0x6c, 0x69, 0x64, 0x46, 0x72, 0x6f, 0x6d, 0xc0, 0x74, 0x32, 0x30,\n 0x32, 0x35, 0x2d, 0x30, 0x31, 0x2d, 0x32, 0x39, 0x54, 0x31, 0x34, 0x3a,\n 0x33, 0x39, 0x3a, 0x32, 0x38, 0x5a, 0x6a, 0x76, 0x61, 0x6c, 0x69, 0x64,\n 0x55, 0x6e, 0x74, 0x69, 0x6c, 0xc0, 0x74, 0x32, 0x30, 0x32, 0x35, 0x2d,\n 0x30, 0x32, 0x2d, 0x31, 0x32, 0x54, 0x31, 0x34, 0x3a, 0x33, 0x39, 0x3a,\n 0x32, 0x38, 0x5a, 0x58, 0x40, 0x12, 0xb3, 0x7a, 0x55, 0xcb, 0xdc, 0xda,\n 0x03, 0xa0, 0x6e, 0xa0, 0x60, 0xd2, 0x44, 0xab, 0x5b, 0x1a, 0x10, 0xe4,\n 0x29, 0x50, 0xed, 0x84, 0xdf, 0x9e, 0xce, 0xf7, 0xbf, 0xb0, 0x0d, 0xb0,\n 0xfb, 0xa8, 0x4e, 0xa3, 0x86, 0x43, 0x22, 0x8c, 0xa2, 0x91, 0x4e, 0x25,\n 0x1f, 0x5d, 0x37, 0x65, 0xf2, 0x1e, 0x45, 0x33, 0x0e, 0xe7, 0x2b, 0xd8,\n 0x05, 0x28, 0x99, 0x76, 0xb7, 0xa6, 0x1b, 0x3f, 0x52, 0x6c, 0x64, 0x65,\n 0x76, 0x69, 0x63, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xa2, 0x6a,\n 0x6e, 0x61, 0x6d, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x73, 0xd8, 0x18,\n 0x41, 0xa0, 0x6a, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x41, 0x75, 0x74,\n 0x68, 0xa1, 0x6f, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x53, 0x69, 0x67,\n 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x84, 0x43, 0xa1, 0x01, 0x26, 0xa0,\n 0xf6, 0x58, 0x40, 0x3f, 0xae, 0x1b, 0xb1, 0x4c, 0x0f, 0x22, 0xb3, 0x73,\n 0x26, 0xf4, 0x4d, 0x61, 0x2f, 0x59, 0x94, 0x35, 0x39, 0xa6, 0x0b, 0xe8,\n 0xd4, 0xa6, 0x8f, 0x0b, 0x0a, 0x66, 0x19, 0xea, 0x3a, 0xbf, 0x56, 0xdb,\n 0xc3, 0xe2, 0xeb, 0x1e, 0xcd, 0xa8, 0x65, 0x2f, 0x62, 0xc5, 0xd4, 0x44,\n 0x3f, 0x2c, 0x1b, 0xde, 0x9a, 0xd5, 0xd9, 0x2c, 0xaf, 0x16, 0xbc, 0xdf,\n 0x0e, 0x7c, 0x40, 0xd8, 0x5b, 0xf5, 0xf3, 0x66, 0x73, 0x74, 0x61, 0x74,\n 0x75, 0x73, 0x00}},\n // Mdoc example from website explainer.\n {StaticString(\n \"0xb4682ec20e06e8df840b5dd32959798ab20c544d4da50109ff4684d06fd261fc\"),\n StaticString(\n \"0xf6f8e9a811911329a5f653fcec5990092c91a65bc1695d291cd51de9c94e7db7\"),\n {0x83, 0xF6, 0xF6, 0x84, 0x71, 0x42, 0x72, 0x6F, 0x77, 0x73, 0x65, 0x72,\n 0x48, 0x61, 0x6E, 0x64, 0x6F, 0x76, 0x65, 0x72, 0x76, 0x31, 0x58, 0x20,\n 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,\n 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,\n 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x58, 0x35, 0xA3, 0x63,\n 0x63, 0x61, 0x74, 0x01, 0x64, 0x74, 0x79, 0x70, 0x65, 0x01, 0x67, 0x64,\n 0x65, 0x74, 0x61, 0x69, 0x6C, 0x73, 0xA1, 0x67, 0x62, 0x61, 0x73, 0x65,\n 0x55, 0x72, 0x6C, 0x77, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x72,\n 0x65, 0x6C, 0x79, 0x69, 0x6E, 0x67, 0x70, 0x61, 0x72, 0x74, 0x79, 0x2E,\n 0x63, 0x6F, 0x6D, 0x58, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,\n 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33,\n 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,\n 0x40},\n 145,\n (uint8_t *)\"2025-04-30T00:00:00Z\",\n kMDL,\n 1298,\n {0xa3, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e,\n 0x30, 0x69, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x81,\n 0xa3, 0x67, 0x64, 0x6f, 0x63, 0x54, 0x79, 0x70, 0x65, 0x75, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x2e, 0x6d, 0x44, 0x4c, 0x6c, 0x69, 0x73, 0x73, 0x75,\n 0x65, 0x72, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xa2, 0x6a, 0x6e, 0x61,\n 0x6d, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x73, 0xa1, 0x71, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x82, 0xd8, 0x18, 0x58, 0x60, 0xa4, 0x68, 0x64, 0x69,\n 0x67, 0x65, 0x73, 0x74, 0x49, 0x44, 0x00, 0x66, 0x72, 0x61, 0x6e, 0x64,\n 0x6f, 0x6d, 0x58, 0x20, 0x22, 0x31, 0x18, 0x3c, 0x7d, 0x9f, 0x4d, 0x2e,\n 0x2e, 0x14, 0x6d, 0x24, 0x84, 0x58, 0xb4, 0xcc, 0xe9, 0x48, 0x79, 0x8f,\n 0xda, 0x82, 0x40, 0xd3, 0x60, 0xa8, 0xf4, 0x0f, 0x6d, 0x75, 0x48, 0xd3,\n 0x71, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e,\n 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x6b, 0x61, 0x67, 0x65, 0x5f, 0x6f,\n 0x76, 0x65, 0x72, 0x5f, 0x31, 0x38, 0x6c, 0x65, 0x6c, 0x65, 0x6d, 0x65,\n 0x6e, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0xf5, 0xd8, 0x18, 0x58, 0x5f,\n 0xa4, 0x68, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74, 0x49, 0x44, 0x01, 0x66,\n 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x58, 0x20, 0xcd, 0x6b, 0x77, 0x63,\n 0x8d, 0x8f, 0x26, 0x18, 0xb7, 0x2f, 0x90, 0x25, 0xb8, 0x8c, 0x3d, 0x63,\n 0x2a, 0xbb, 0xa8, 0xde, 0x96, 0xe3, 0x93, 0x2d, 0xa3, 0x56, 0x6e, 0x49,\n 0x1f, 0x19, 0xcb, 0x91, 0x71, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74,\n 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x63, 0x6e,\n 0x79, 0x6d, 0x6c, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x56, 0x61,\n 0x6c, 0x75, 0x65, 0x67, 0x31, 0x32, 0x33, 0x31, 0x32, 0x34, 0x34, 0x6a,\n 0x69, 0x73, 0x73, 0x75, 0x65, 0x72, 0x41, 0x75, 0x74, 0x68, 0x84, 0x43,\n 0xa1, 0x01, 0x26, 0xa1, 0x18, 0x21, 0x59, 0x01, 0x83, 0x30, 0x82, 0x01,\n 0x7f, 0x30, 0x82, 0x01, 0x26, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01,\n 0x01, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03,\n 0x02, 0x30, 0x29, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a,\n 0x13, 0x08, 0x61, 0x62, 0x68, 0x76, 0x69, 0x6f, 0x75, 0x73, 0x31, 0x14,\n 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x0b, 0x54, 0x65, 0x73,\n 0x74, 0x69, 0x6e, 0x67, 0x20, 0x6b, 0x65, 0x79, 0x30, 0x1e, 0x17, 0x0d,\n 0x32, 0x35, 0x30, 0x34, 0x32, 0x38, 0x32, 0x31, 0x31, 0x30, 0x31, 0x34,\n 0x5a, 0x17, 0x0d, 0x32, 0x35, 0x30, 0x35, 0x30, 0x35, 0x32, 0x31, 0x31,\n 0x30, 0x31, 0x34, 0x5a, 0x30, 0x29, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03,\n 0x55, 0x04, 0x0a, 0x13, 0x08, 0x61, 0x62, 0x68, 0x76, 0x69, 0x6f, 0x75,\n 0x73, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x0b,\n 0x54, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x6b, 0x65, 0x79, 0x30,\n 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01,\n 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42,\n 0x00, 0x04, 0xb4, 0x68, 0x2e, 0xc2, 0x0e, 0x06, 0xe8, 0xdf, 0x84, 0x0b,\n 0x5d, 0xd3, 0x29, 0x59, 0x79, 0x8a, 0xb2, 0x0c, 0x54, 0x4d, 0x4d, 0xa5,\n 0x01, 0x09, 0xff, 0x46, 0x84, 0xd0, 0x6f, 0xd2, 0x61, 0xfc, 0xf6, 0xf8,\n 0xe9, 0xa8, 0x11, 0x91, 0x13, 0x29, 0xa5, 0xf6, 0x53, 0xfc, 0xec, 0x59,\n 0x90, 0x09, 0x2c, 0x91, 0xa6, 0x5b, 0xc1, 0x69, 0x5d, 0x29, 0x1c, 0xd5,\n 0x1d, 0xe9, 0xc9, 0x4e, 0x7d, 0xb7, 0xa3, 0x3f, 0x30, 0x3d, 0x30, 0x0e,\n 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02,\n 0x05, 0xa0, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x16, 0x30,\n 0x14, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x06,\n 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02, 0x30, 0x0c, 0x06,\n 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x02, 0x30, 0x00, 0x30,\n 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03,\n 0x47, 0x00, 0x30, 0x44, 0x02, 0x20, 0x31, 0x0f, 0x9a, 0xc7, 0x56, 0xcf,\n 0xfa, 0x49, 0x3d, 0x2f, 0x75, 0x77, 0xab, 0x38, 0x0e, 0x9d, 0x4d, 0xa6,\n 0x91, 0xeb, 0x5a, 0x8f, 0x19, 0xeb, 0xb2, 0xd9, 0x39, 0xa1, 0x67, 0x49,\n 0x1f, 0xbe, 0x02, 0x20, 0x4c, 0x7d, 0xac, 0xde, 0x12, 0xf6, 0x98, 0xb1,\n 0xf9, 0x6e, 0xa1, 0xc9, 0xbc, 0xa1, 0x3e, 0xd7, 0x9c, 0xd5, 0x67, 0xf4,\n 0x04, 0x47, 0x3d, 0xa0, 0x66, 0x05, 0xa8, 0xf1, 0x49, 0xef, 0x67, 0x01,\n 0x59, 0x01, 0x7f, 0xd8, 0x18, 0x59, 0x01, 0x7a, 0xa6, 0x67, 0x76, 0x65,\n 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e, 0x30, 0x6f, 0x64, 0x69,\n 0x67, 0x65, 0x73, 0x74, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68,\n 0x6d, 0x67, 0x53, 0x48, 0x41, 0x2d, 0x32, 0x35, 0x36, 0x67, 0x64, 0x6f,\n 0x63, 0x54, 0x79, 0x70, 0x65, 0x75, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73,\n 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0x2e,\n 0x6d, 0x44, 0x4c, 0x6c, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x44, 0x69, 0x67,\n 0x65, 0x73, 0x74, 0x73, 0xa1, 0x71, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73,\n 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0xa2,\n 0x00, 0x58, 0x20, 0xff, 0x75, 0x3b, 0xf6, 0xc1, 0x19, 0x63, 0xfd, 0x64,\n 0x4c, 0xcc, 0xe4, 0x35, 0x56, 0xcd, 0xe1, 0x85, 0x7a, 0xcd, 0xfd, 0x8e,\n 0x7e, 0x60, 0x7c, 0x01, 0xdf, 0xf5, 0xdc, 0x3e, 0x1a, 0xfb, 0xfc, 0x01,\n 0x58, 0x20, 0xc5, 0x70, 0x2c, 0x25, 0x26, 0x38, 0xa4, 0xd0, 0xe9, 0x77,\n 0x44, 0xcd, 0x38, 0x4f, 0x0c, 0x04, 0x26, 0x07, 0x94, 0x84, 0xbe, 0xa1,\n 0xa2, 0xc9, 0x4b, 0xe5, 0x8f, 0xb5, 0xe8, 0xc2, 0x28, 0x61, 0x6d, 0x64,\n 0x65, 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79, 0x49, 0x6e, 0x66, 0x6f,\n 0xa1, 0x69, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79, 0xa4,\n 0x01, 0x02, 0x20, 0x01, 0x21, 0x58, 0x20, 0x02, 0x7a, 0x5a, 0x1f, 0xa9,\n 0x15, 0x1f, 0x67, 0xcd, 0xd2, 0xc5, 0x7f, 0xaf, 0x84, 0xcc, 0xfd, 0xb0,\n 0x5b, 0xcf, 0x59, 0x07, 0x87, 0x65, 0xfa, 0x0b, 0x7e, 0x1a, 0x82, 0x23,\n 0x79, 0x0d, 0xd2, 0x22, 0x58, 0x20, 0x3e, 0x17, 0x08, 0x11, 0xbe, 0xcf,\n 0x18, 0x4d, 0x36, 0xba, 0x38, 0xdb, 0xc2, 0x29, 0x21, 0x7d, 0x4f, 0xac,\n 0xa0, 0xf1, 0x62, 0xd5, 0x54, 0xe5, 0xf1, 0x40, 0x8d, 0x59, 0xc4, 0xba,\n 0xaa, 0x0b, 0x6c, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x69, 0x74, 0x79, 0x49,\n 0x6e, 0x66, 0x6f, 0xa3, 0x66, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xc0,\n 0x74, 0x32, 0x30, 0x32, 0x35, 0x2d, 0x30, 0x34, 0x2d, 0x32, 0x38, 0x54,\n 0x32, 0x31, 0x3a, 0x30, 0x30, 0x3a, 0x30, 0x30, 0x5a, 0x69, 0x76, 0x61,\n 0x6c, 0x69, 0x64, 0x46, 0x72, 0x6f, 0x6d, 0xc0, 0x74, 0x32, 0x30, 0x32,\n 0x35, 0x2d, 0x30, 0x34, 0x2d, 0x32, 0x38, 0x54, 0x32, 0x31, 0x3a, 0x30,\n 0x30, 0x3a, 0x30, 0x30, 0x5a, 0x6a, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x55,\n 0x6e, 0x74, 0x69, 0x6c, 0xc0, 0x74, 0x32, 0x30, 0x32, 0x36, 0x2d, 0x30,\n 0x34, 0x2d, 0x32, 0x38, 0x54, 0x32, 0x31, 0x3a, 0x30, 0x30, 0x3a, 0x30,\n 0x30, 0x5a, 0x58, 0x40, 0x29, 0x22, 0x9f, 0xa5, 0xda, 0x13, 0x7c, 0x73,\n 0xfa, 0xe1, 0xe5, 0xcb, 0x87, 0x5b, 0xa0, 0xd2, 0x21, 0x3d, 0x0d, 0xbe,\n 0xdc, 0x9d, 0x08, 0x96, 0xa7, 0x45, 0x99, 0x08, 0x83, 0x72, 0xd8, 0x98,\n 0x83, 0x45, 0x05, 0xb8, 0x6d, 0x3a, 0xde, 0x7e, 0xad, 0x4f, 0xc9, 0x3a,\n 0xa2, 0x8c, 0xd5, 0xc4, 0xf3, 0xff, 0x2d, 0xd4, 0x89, 0xfe, 0x89, 0x9a,\n 0x71, 0xe7, 0x21, 0x13, 0xae, 0x74, 0xfa, 0x8f, 0x6c, 0x64, 0x65, 0x76,\n 0x69, 0x63, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xa2, 0x6a, 0x6e,\n 0x61, 0x6d, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x73, 0xd8, 0x18, 0x41,\n 0xa0, 0x6a, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x41, 0x75, 0x74, 0x68,\n 0xa1, 0x6f, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x53, 0x69, 0x67, 0x6e,\n 0x61, 0x74, 0x75, 0x72, 0x65, 0x84, 0x43, 0xa1, 0x01, 0x26, 0xa0, 0xf6,\n 0x58, 0x40, 0x52, 0x0b, 0x17, 0xb8, 0xbd, 0x7e, 0xae, 0x5d, 0x4e, 0x7d,\n 0xcd, 0xb8, 0x8c, 0xdd, 0xb2, 0x4e, 0x7b, 0x2b, 0xf6, 0x5a, 0xfe, 0x42,\n 0x0a, 0x1c, 0x48, 0x81, 0x2d, 0x97, 0x65, 0x78, 0x42, 0xba, 0xb5, 0x05,\n 0x74, 0xf5, 0xc8, 0x29, 0xc3, 0x2f, 0xa6, 0xd7, 0xa2, 0x28, 0xdb, 0x96,\n 0x64, 0xdc, 0x75, 0x4e, 0x2f, 0x6c, 0x90, 0x1c, 0x7b, 0x9a, 0x97, 0x49,\n 0x59, 0xfc, 0x9b, 0x35, 0xcb, 0x4c, 0x66, 0x73, 0x74, 0x61, 0x74, 0x75,\n 0x73, 0x00}},\n // Large mDoc from Canonical Playground June 2025\n {StaticString(\n \"0xab4bb1a19d6bc9d61138cf43a004ba5156ae4f3080804c910cf638eacf3b4e00\"),\n StaticString(\n \"0x216a667060dae40ecca6fb4b39f1c93e1098ac64667b6e5bbf0140518672cb7b\"),\n {0x83, 0xf6, 0xf6, 0x82, 0x76, 0x4f, 0x70, 0x65, 0x6e,\n 0x49, 0x44, 0x34, 0x56, 0x50, 0x44, 0x43, 0x41, 0x50,\n 0x49, 0x48, 0x61, 0x6e, 0x64, 0x6f, 0x76, 0x65, 0x72,\n 0x58, 0x20, 0x6c, 0xd6, 0x05, 0x23, 0x72, 0x0c, 0x76,\n 0x4a, 0xda, 0x4b, 0xa1, 0x07, 0xe6, 0x4c, 0xcf, 0x2b,\n 0xb4, 0xc8, 0x1d, 0x21, 0xa9, 0xc3, 0x02, 0x0c, 0x52,\n 0xbf, 0x5c, 0x89, 0x40, 0x7d, 0x98, 0xee},\n 61,\n (uint8_t *)\"2025-06-10T23:59:59Z\",\n kMDL,\n 3321,\n { 0xa3, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e,\n 0x30, 0x69, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x81,\n 0xa3, 0x67, 0x64, 0x6f, 0x63, 0x54, 0x79, 0x70, 0x65, 0x75, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x2e, 0x6d, 0x44, 0x4c, 0x6c, 0x69, 0x73, 0x73, 0x75,\n 0x65, 0x72, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xa2, 0x6a, 0x6e, 0x61,\n 0x6d, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x73, 0xa1, 0x71, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x81, 0xd8, 0x18, 0x58, 0x51, 0xa4, 0x68, 0x64, 0x69,\n 0x67, 0x65, 0x73, 0x74, 0x49, 0x44, 0x19, 0x36, 0xf7, 0x66, 0x72, 0x61,\n 0x6e, 0x64, 0x6f, 0x6d, 0x50, 0x84, 0x83, 0x3b, 0x67, 0x34, 0x97, 0x7a,\n 0x63, 0x0b, 0xd7, 0xf7, 0xd4, 0xd8, 0xca, 0xd3, 0xe9, 0x71, 0x65, 0x6c,\n 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66,\n 0x69, 0x65, 0x72, 0x6b, 0x61, 0x67, 0x65, 0x5f, 0x6f, 0x76, 0x65, 0x72,\n 0x5f, 0x31, 0x38, 0x6c, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x56,\n 0x61, 0x6c, 0x75, 0x65, 0xf4, 0x6a, 0x69, 0x73, 0x73, 0x75, 0x65, 0x72,\n 0x41, 0x75, 0x74, 0x68, 0x84, 0x43, 0xa1, 0x01, 0x26, 0xa1, 0x18, 0x21,\n 0x59, 0x02, 0xce, 0x30, 0x82, 0x02, 0xca, 0x30, 0x82, 0x02, 0x2b, 0xa0,\n 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00, 0xd7, 0x05, 0x20, 0x76, 0xb8,\n 0x88, 0xe1, 0x1a, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,\n 0x04, 0x03, 0x04, 0x30, 0x37, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,\n 0x04, 0x06, 0x13, 0x02, 0x5a, 0x5a, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03,\n 0x55, 0x04, 0x0a, 0x0c, 0x06, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x31,\n 0x17, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0e, 0x50, 0x61,\n 0x79, 0x67, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x20, 0x52, 0x6f, 0x6f, 0x74,\n 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x35, 0x30, 0x35, 0x30, 0x37, 0x30, 0x35,\n 0x33, 0x34, 0x31, 0x30, 0x5a, 0x17, 0x0d, 0x32, 0x36, 0x30, 0x35, 0x30,\n 0x37, 0x30, 0x35, 0x33, 0x34, 0x31, 0x30, 0x5a, 0x30, 0x42, 0x31, 0x0b,\n 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x5a, 0x5a, 0x31,\n 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x06, 0x47, 0x6f,\n 0x6f, 0x67, 0x6c, 0x65, 0x31, 0x22, 0x30, 0x20, 0x06, 0x03, 0x55, 0x04,\n 0x03, 0x0c, 0x19, 0x50, 0x61, 0x79, 0x67, 0x72, 0x6f, 0x75, 0x6e, 0x64,\n 0x20, 0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x53, 0x69,\n 0x67, 0x6e, 0x65, 0x72, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86,\n 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,\n 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0xab, 0x4b, 0xb1, 0xa1, 0x9d,\n 0x6b, 0xc9, 0xd6, 0x11, 0x38, 0xcf, 0x43, 0xa0, 0x04, 0xba, 0x51, 0x56,\n 0xae, 0x4f, 0x30, 0x80, 0x80, 0x4c, 0x91, 0x0c, 0xf6, 0x38, 0xea, 0xcf,\n 0x3b, 0x4e, 0x00, 0x21, 0x6a, 0x66, 0x70, 0x60, 0xda, 0xe4, 0x0e, 0xcc,\n 0xa6, 0xfb, 0x4b, 0x39, 0xf1, 0xc9, 0x3e, 0x10, 0x98, 0xac, 0x64, 0x66,\n 0x7b, 0x6e, 0x5b, 0xbf, 0x01, 0x40, 0x51, 0x86, 0x72, 0xcb, 0x7b, 0xa3,\n 0x82, 0x01, 0x13, 0x30, 0x82, 0x01, 0x0f, 0x30, 0x1d, 0x06, 0x03, 0x55,\n 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x36, 0x86, 0x68, 0x1a, 0x2b, 0x1a,\n 0x9c, 0xc3, 0xc5, 0x50, 0x2d, 0xe4, 0x60, 0x1d, 0x44, 0xab, 0x83, 0x81,\n 0x89, 0x27, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30,\n 0x16, 0x80, 0x14, 0x73, 0xa7, 0x04, 0x1e, 0x50, 0x81, 0x93, 0x9e, 0xe0,\n 0xdb, 0xb7, 0x02, 0x8a, 0xe3, 0x71, 0x2f, 0xd0, 0xaa, 0x36, 0xc1, 0x30,\n 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03,\n 0x02, 0x07, 0x80, 0x30, 0x21, 0x06, 0x03, 0x55, 0x1d, 0x12, 0x04, 0x1a,\n 0x30, 0x18, 0x86, 0x16, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f,\n 0x77, 0x77, 0x77, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63,\n 0x6f, 0x6d, 0x30, 0x15, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x01, 0x01, 0xff,\n 0x04, 0x0b, 0x30, 0x09, 0x06, 0x07, 0x28, 0x81, 0x8c, 0x5d, 0x05, 0x01,\n 0x02, 0x30, 0x81, 0x82, 0x06, 0x03, 0x55, 0x1d, 0x1f, 0x04, 0x7b, 0x30,\n 0x79, 0x30, 0x77, 0xa0, 0x75, 0xa0, 0x73, 0x86, 0x71, 0x68, 0x74, 0x74,\n 0x70, 0x3a, 0x2f, 0x2f, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x63,\n 0x61, 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x36, 0x36,\n 0x30, 0x33, 0x63, 0x36, 0x34, 0x37, 0x2d, 0x30, 0x30, 0x30, 0x30, 0x2d,\n 0x32, 0x39, 0x64, 0x34, 0x2d, 0x61, 0x65, 0x61, 0x36, 0x2d, 0x66, 0x34,\n 0x66, 0x35, 0x65, 0x38, 0x30, 0x64, 0x31, 0x62, 0x39, 0x30, 0x2e, 0x73,\n 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c,\n 0x65, 0x61, 0x70, 0x69, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x34, 0x31,\n 0x64, 0x34, 0x33, 0x36, 0x38, 0x35, 0x39, 0x65, 0x34, 0x35, 0x64, 0x62,\n 0x66, 0x33, 0x65, 0x35, 0x61, 0x39, 0x2f, 0x63, 0x72, 0x6c, 0x2e, 0x63,\n 0x72, 0x6c, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04,\n 0x03, 0x04, 0x03, 0x81, 0x8c, 0x00, 0x30, 0x81, 0x88, 0x02, 0x42, 0x00,\n 0xab, 0x5b, 0x98, 0x44, 0x72, 0xb7, 0x1a, 0x25, 0x5d, 0xe8, 0x60, 0xff,\n 0x9b, 0x99, 0x52, 0x8c, 0x73, 0xa9, 0xb1, 0x29, 0x7e, 0x87, 0x36, 0x57,\n 0x9c, 0xb8, 0x18, 0xf6, 0x6a, 0x82, 0x5a, 0xd7, 0x0f, 0x39, 0xdd, 0x3c,\n 0x18, 0x11, 0x3c, 0xf8, 0x04, 0x90, 0x5d, 0x9b, 0xa9, 0x4a, 0x03, 0xe3,\n 0xfe, 0x5a, 0x9e, 0x22, 0x8f, 0x1b, 0x10, 0x1d, 0xd0, 0x86, 0x55, 0x96,\n 0xe5, 0x81, 0x9c, 0xe7, 0x74, 0x02, 0x42, 0x01, 0xd0, 0x1e, 0x5d, 0x2f,\n 0xc1, 0x4d, 0xb2, 0x0e, 0x4b, 0xc2, 0x0e, 0x8b, 0xaf, 0xe6, 0x1e, 0xc2,\n 0x29, 0x64, 0x71, 0x31, 0xaf, 0xc1, 0xe3, 0xbb, 0xdb, 0x16, 0xd1, 0x8c,\n 0x43, 0x97, 0x72, 0x11, 0xbb, 0x8f, 0xda, 0xc6, 0x6c, 0x05, 0xd1, 0x3b,\n 0x76, 0xd4, 0x5b, 0x80, 0x7a, 0x20, 0x99, 0x07, 0x2b, 0x7d, 0x97, 0x86,\n 0xec, 0x19, 0xcd, 0x8f, 0x4e, 0xd4, 0x85, 0x16, 0x76, 0xcf, 0x99, 0xb9,\n 0xa3, 0x59, 0x08, 0x8d, 0xd8, 0x18, 0x59, 0x08, 0x88, 0xa6, 0x67, 0x76,\n 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e, 0x30, 0x6f, 0x64,\n 0x69, 0x67, 0x65, 0x73, 0x74, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74,\n 0x68, 0x6d, 0x67, 0x53, 0x48, 0x41, 0x2d, 0x32, 0x35, 0x36, 0x6c, 0x76,\n 0x61, 0x6c, 0x75, 0x65, 0x44, 0x69, 0x67, 0x65, 0x73, 0x74, 0x73, 0xa2,\n 0x71, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30,\n 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0xb8, 0x2b, 0x19, 0x03, 0x65, 0x58,\n 0x20, 0x54, 0xe2, 0xe0, 0x57, 0xf8, 0xd7, 0x41, 0x2f, 0xb9, 0x67, 0xe7,\n 0x38, 0x31, 0xb1, 0xbd, 0x43, 0x9b, 0xf7, 0x61, 0x4f, 0xe3, 0x0b, 0x13,\n 0xa5, 0xf5, 0xd5, 0x9d, 0x21, 0xfd, 0x8a, 0xfc, 0x0f, 0x19, 0x06, 0x4a,\n 0x58, 0x20, 0x77, 0x11, 0x08, 0x33, 0x52, 0xf0, 0x6a, 0x9e, 0x71, 0x87,\n 0x90, 0xb7, 0xa4, 0x2f, 0x2f, 0x88, 0xe2, 0xae, 0xee, 0xf5, 0x1e, 0x51,\n 0x4f, 0xe0, 0x27, 0xde, 0x73, 0xdc, 0x60, 0x80, 0x28, 0x13, 0x19, 0x07,\n 0x08, 0x58, 0x20, 0x30, 0x97, 0x45, 0x71, 0x69, 0x0f, 0x39, 0x25, 0xb5,\n 0x1f, 0xa4, 0xab, 0x60, 0x2b, 0xf3, 0xcc, 0xc4, 0x44, 0x0f, 0x21, 0xd3,\n 0x24, 0xe2, 0x08, 0x14, 0xea, 0xd5, 0x7a, 0xe5, 0xfb, 0x3e, 0x56, 0x19,\n 0x08, 0x01, 0x58, 0x20, 0x73, 0x6a, 0x04, 0xe2, 0x35, 0x20, 0x20, 0x17,\n 0xa0, 0xa1, 0x65, 0xd9, 0xd1, 0x1c, 0x0c, 0x5a, 0x74, 0xcf, 0xad, 0x39,\n 0xdf, 0x94, 0x08, 0x5a, 0xb0, 0x95, 0x55, 0xc3, 0xd3, 0xfe, 0xfc, 0x4f,\n 0x19, 0x13, 0x95, 0x58, 0x20, 0xe2, 0x36, 0x1c, 0x51, 0x0a, 0xd1, 0x29,\n 0x42, 0xab, 0x1e, 0x5e, 0x84, 0xc4, 0x06, 0xd2, 0x4c, 0xc1, 0x7c, 0x44,\n 0xaa, 0x6f, 0x79, 0x91, 0x85, 0x61, 0xf9, 0xda, 0x3e, 0xe5, 0x86, 0x80,\n 0xcb, 0x19, 0x19, 0x42, 0x58, 0x20, 0x2b, 0x86, 0xfb, 0x8a, 0xd1, 0x65,\n 0xce, 0x24, 0xf6, 0xb4, 0x28, 0x81, 0x91, 0x58, 0x76, 0x82, 0x19, 0x18,\n 0x7a, 0x1f, 0x2a, 0x92, 0xd6, 0x5f, 0xe9, 0x42, 0x54, 0x6c, 0xae, 0xf7,\n 0xe2, 0x90, 0x19, 0x24, 0x07, 0x58, 0x20, 0x97, 0x1a, 0xf5, 0x99, 0x97,\n 0x59, 0x0e, 0x21, 0x54, 0xcb, 0x12, 0x32, 0xf2, 0x6d, 0x25, 0x4d, 0xcb,\n 0xba, 0x57, 0x47, 0x2d, 0x17, 0x1d, 0xbb, 0x53, 0xa8, 0x24, 0x73, 0x69,\n 0x46, 0x11, 0xb2, 0x19, 0x25, 0x90, 0x58, 0x20, 0x74, 0x31, 0xb9, 0xa8,\n 0xe4, 0x9e, 0xa1, 0xf7, 0x7b, 0x6a, 0xf3, 0x6a, 0x2c, 0x5b, 0xe5, 0x31,\n 0x97, 0x1e, 0x50, 0xc3, 0xd6, 0x80, 0xfd, 0x08, 0x0c, 0x33, 0xc0, 0x19,\n 0xba, 0xfa, 0x48, 0xa9, 0x19, 0x2c, 0x0d, 0x58, 0x20, 0x7c, 0x66, 0x45,\n 0x45, 0x17, 0x5e, 0xf0, 0x03, 0x70, 0xca, 0x47, 0x50, 0x8f, 0x6e, 0x19,\n 0x95, 0x8f, 0x63, 0x0f, 0x2b, 0xc2, 0x92, 0xdb, 0xb4, 0x33, 0xbf, 0x73,\n 0xe9, 0xec, 0xe9, 0xbb, 0xcc, 0x19, 0x2d, 0x97, 0x58, 0x20, 0x05, 0x53,\n 0x0d, 0x90, 0x53, 0x30, 0xf4, 0x0b, 0x71, 0x79, 0xb6, 0x51, 0x53, 0x03,\n 0x1a, 0x83, 0x01, 0xbe, 0xdd, 0x8a, 0x88, 0xc9, 0x21, 0x26, 0x77, 0xe3,\n 0xd9, 0x72, 0xba, 0x05, 0x16, 0x17, 0x19, 0x2e, 0xbd, 0x58, 0x20, 0xe6,\n 0x7f, 0x26, 0xac, 0x90, 0x32, 0x0a, 0xff, 0xd5, 0x1b, 0x87, 0x40, 0x58,\n 0xb3, 0x55, 0xcd, 0x7c, 0x06, 0x69, 0x9c, 0x96, 0x3a, 0xb4, 0xd7, 0x2d,\n 0xd7, 0xe9, 0x3d, 0x77, 0xea, 0xff, 0x3c, 0x19, 0x36, 0xe7, 0x58, 0x20,\n 0x22, 0x2a, 0x50, 0xb5, 0x67, 0x8e, 0x4e, 0x06, 0x6b, 0xd4, 0x70, 0xbf,\n 0xe9, 0x79, 0x91, 0x2e, 0x8a, 0xab, 0xd3, 0x1a, 0xa0, 0xc3, 0x95, 0x6c,\n 0x1e, 0x41, 0xae, 0x1a, 0xe5, 0xf2, 0xe1, 0x3c, 0x19, 0x36, 0xf7, 0x58,\n 0x20, 0x43, 0x9f, 0xfb, 0x14, 0x4b, 0x03, 0x08, 0xc4, 0x27, 0x23, 0xdb,\n 0x01, 0xf5, 0x42, 0xff, 0x8a, 0x32, 0xd9, 0xf5, 0x49, 0x5a, 0xb2, 0xb0,\n 0x7c, 0x10, 0x49, 0x20, 0xb1, 0x2a, 0xea, 0x57, 0xba, 0x19, 0x53, 0x7b,\n 0x58, 0x20, 0x9c, 0xf8, 0x0d, 0xe4, 0x88, 0x8b, 0x76, 0x96, 0xfc, 0x35,\n 0x9c, 0xb6, 0xa9, 0xa8, 0xf7, 0xa2, 0xe4, 0x18, 0xdd, 0xe5, 0xc9, 0xeb,\n 0x4f, 0x1d, 0x56, 0x42, 0x2a, 0xa4, 0x3f, 0xc6, 0x91, 0x74, 0x19, 0x53,\n 0xa0, 0x58, 0x20, 0x37, 0x43, 0x2d, 0xa3, 0xcc, 0x4f, 0x7d, 0x25, 0x20,\n 0xd7, 0x57, 0x96, 0xb3, 0x54, 0x9f, 0xc0, 0x45, 0x54, 0x81, 0xaa, 0x58,\n 0x01, 0xb0, 0xed, 0xc9, 0x51, 0xd5, 0x1a, 0xd6, 0x56, 0x58, 0x46, 0x19,\n 0x5d, 0xf2, 0x58, 0x20, 0xd7, 0xd2, 0x86, 0xd6, 0x55, 0xf1, 0x6c, 0xef,\n 0x3b, 0x2e, 0x8c, 0x22, 0xd1, 0x4c, 0xd9, 0xa3, 0x41, 0x26, 0x06, 0x58,\n 0x66, 0xd9, 0x78, 0x6f, 0x4c, 0x97, 0xe5, 0x1c, 0x8c, 0xf1, 0x7d, 0x5a,\n 0x19, 0x5f, 0x12, 0x58, 0x20, 0xec, 0xbf, 0x9b, 0xf5, 0x18, 0xd0, 0xa8,\n 0xc1, 0x73, 0xc6, 0x5b, 0x7f, 0x6a, 0x14, 0xe5, 0x6f, 0x9e, 0x9e, 0x48,\n 0x3e, 0x6c, 0x1a, 0xaa, 0x60, 0xd9, 0x30, 0xde, 0x57, 0xae, 0x5d, 0x80,\n 0x66, 0x19, 0x66, 0xb4, 0x58, 0x20, 0xe1, 0xd7, 0x8f, 0xc9, 0xae, 0xae,\n 0x63, 0x48, 0x0c, 0xc0, 0xd8, 0x94, 0x00, 0xa4, 0xc6, 0xe0, 0xd8, 0xb7,\n 0xc5, 0xdf, 0x79, 0xcb, 0x4d, 0x67, 0x11, 0xfb, 0xb3, 0xbe, 0x7a, 0xef,\n 0xd8, 0x45, 0x19, 0x67, 0x4e, 0x58, 0x20, 0x9c, 0x66, 0xa2, 0x1f, 0xdc,\n 0x13, 0xfa, 0x40, 0xf6, 0xf3, 0x82, 0xc3, 0x7f, 0x53, 0x7f, 0x1c, 0x52,\n 0x0b, 0xca, 0x4b, 0x09, 0x25, 0xfa, 0xdd, 0xda, 0x7b, 0x50, 0xc5, 0xb0,\n 0xd9, 0x60, 0xfd, 0x19, 0x6f, 0x91, 0x58, 0x20, 0xa0, 0x91, 0x53, 0xe0,\n 0x04, 0x9d, 0x18, 0x47, 0x14, 0xf8, 0x43, 0x79, 0x8c, 0x90, 0xde, 0x41,\n 0xd1, 0x46, 0x5b, 0x77, 0x2f, 0x63, 0x87, 0xf3, 0xeb, 0x0e, 0x70, 0x63,\n 0x81, 0xe4, 0x0a, 0x1d, 0x19, 0x71, 0x34, 0x58, 0x20, 0x31, 0xaf, 0xc9,\n 0x92, 0xfe, 0xc3, 0x09, 0x98, 0xb3, 0xe8, 0x18, 0xf1, 0x45, 0xe9, 0xdd,\n 0xdb, 0xf3, 0x27, 0x44, 0x4b, 0xc9, 0xaa, 0x25, 0x08, 0x2a, 0xe1, 0x85,\n 0xc4, 0xfb, 0x6f, 0x18, 0xd4, 0x19, 0x72, 0x3f, 0x58, 0x20, 0xf2, 0xa3,\n 0x12, 0xca, 0xdd, 0x1f, 0xf2, 0x21, 0xce, 0xdb, 0x5d, 0x86, 0x1d, 0x79,\n 0xa7, 0x0c, 0x88, 0x7b, 0xdc, 0x8c, 0xd7, 0x7e, 0x3f, 0xf6, 0x36, 0xa0,\n 0x12, 0xa9, 0xc1, 0x76, 0x82, 0x59, 0x19, 0x73, 0x28, 0x58, 0x20, 0xca,\n 0xc8, 0x13, 0x4b, 0x17, 0x19, 0xa7, 0x4e, 0xb4, 0x8c, 0x36, 0x9a, 0x65,\n 0x4d, 0xfc, 0x3a, 0x72, 0xca, 0x17, 0x3a, 0x55, 0xe0, 0x20, 0x30, 0x77,\n 0xd5, 0x81, 0x21, 0xb6, 0x00, 0x30, 0x41, 0x19, 0x77, 0x39, 0x58, 0x20,\n 0x44, 0x95, 0xaf, 0xb6, 0x80, 0x07, 0xab, 0xc3, 0x21, 0x66, 0xe9, 0xf2,\n 0xc8, 0xfa, 0xfb, 0xd8, 0x18, 0x04, 0xac, 0x9d, 0x48, 0xb2, 0xc6, 0xe6,\n 0x19, 0x0b, 0xb5, 0x2d, 0x94, 0x23, 0x8b, 0x07, 0x19, 0x7c, 0x2b, 0x58,\n 0x20, 0x17, 0x1c, 0xa0, 0x43, 0x36, 0x04, 0x23, 0x86, 0x65, 0x71, 0x14,\n 0x7e, 0xa2, 0x99, 0x8b, 0xa9, 0xff, 0x40, 0xde, 0xb9, 0x84, 0x84, 0x53,\n 0x1c, 0xf8, 0x6f, 0xc9, 0x79, 0x1d, 0x84, 0xcb, 0x28, 0x19, 0x93, 0x07,\n 0x58, 0x20, 0x3b, 0xd0, 0x95, 0x2e, 0xd7, 0x7a, 0x7d, 0x87, 0xe0, 0x3d,\n 0x52, 0x0c, 0x9c, 0x5e, 0xb3, 0x27, 0x84, 0x55, 0x62, 0x48, 0xb2, 0x2a,\n 0x47, 0x9c, 0xd9, 0x44, 0xcb, 0xb1, 0x64, 0x92, 0x00, 0x76, 0x19, 0x98,\n 0xfa, 0x58, 0x20, 0x6e, 0x26, 0x5f, 0x85, 0x05, 0x25, 0x18, 0xb9, 0xeb,\n 0xb7, 0x99, 0x32, 0x8a, 0x34, 0xcc, 0x66, 0x4a, 0xdb, 0x57, 0xef, 0x03,\n 0xa2, 0x16, 0x56, 0x78, 0x0d, 0x48, 0xde, 0xc0, 0x27, 0xa5, 0x9c, 0x19,\n 0x99, 0x44, 0x58, 0x20, 0x6c, 0xdd, 0xac, 0x1d, 0xd1, 0xad, 0x04, 0xbf,\n 0xef, 0x67, 0x17, 0x3e, 0x88, 0x0f, 0x59, 0xb8, 0xbd, 0x2c, 0x0f, 0xb7,\n 0x5a, 0xd8, 0xc5, 0xb1, 0x5c, 0xa7, 0x13, 0xd8, 0x04, 0x54, 0x2a, 0xce,\n 0x19, 0xa5, 0x87, 0x58, 0x20, 0xf0, 0xf8, 0x36, 0x0f, 0xef, 0xc5, 0x73,\n 0x98, 0xfc, 0xde, 0x1d, 0xa3, 0x49, 0x93, 0xc4, 0x95, 0x48, 0x28, 0xa9,\n 0xda, 0x86, 0x2f, 0x4f, 0xf8, 0xe1, 0xc7, 0xee, 0x8a, 0xbc, 0x4a, 0x62,\n 0xbc, 0x19, 0xab, 0xab, 0x58, 0x20, 0x09, 0xc2, 0x04, 0xc8, 0x6f, 0x93,\n 0xd0, 0x11, 0xa6, 0x61, 0x8c, 0x17, 0xbc, 0xb2, 0x29, 0xf5, 0x7d, 0x93,\n 0x0f, 0x41, 0x21, 0x7f, 0x2e, 0x8c, 0x27, 0xc6, 0xcb, 0xb8, 0xc1, 0x1d,\n 0xd6, 0xc0, 0x19, 0xb5, 0x76, 0x58, 0x20, 0xd8, 0x5f, 0x64, 0x48, 0x3d,\n 0x68, 0xe7, 0xbb, 0xca, 0x46, 0xf3, 0x69, 0x2b, 0x91, 0xb8, 0x96, 0xff,\n 0x9a, 0xb1, 0xe2, 0x32, 0xf3, 0x6b, 0x4e, 0xb8, 0x65, 0x76, 0x7e, 0x31,\n 0x9b, 0x3c, 0x31, 0x19, 0xba, 0xd5, 0x58, 0x20, 0x67, 0x16, 0x9a, 0x66,\n 0x8c, 0x34, 0xfa, 0xec, 0x6e, 0xbc, 0x4a, 0xbd, 0xdc, 0xce, 0xc6, 0x31,\n 0x30, 0x9d, 0x59, 0x1d, 0x86, 0xaa, 0xc3, 0x69, 0x74, 0x43, 0x26, 0xa0,\n 0x37, 0x71, 0xae, 0xd1, 0x19, 0xbb, 0x63, 0x58, 0x20, 0xe6, 0xf9, 0xc6,\n 0x68, 0x49, 0xda, 0xc8, 0xd5, 0x79, 0x9f, 0x3d, 0x7c, 0x98, 0xaa, 0xc0,\n 0x8f, 0x28, 0xe6, 0x83, 0x6a, 0x47, 0x5b, 0x2e, 0xc0, 0x2a, 0x91, 0x2b,\n 0x0f, 0x1a, 0x4c, 0x04, 0x27, 0x19, 0xbc, 0xc5, 0x58, 0x20, 0xe2, 0xff,\n 0x42, 0x08, 0x69, 0xff, 0x52, 0x39, 0x19, 0x00, 0x4f, 0x95, 0x45, 0x0f,\n 0x80, 0x32, 0x0f, 0x1b, 0x11, 0xbd, 0x9e, 0x39, 0x80, 0xa3, 0x86, 0xbf,\n 0xd5, 0xc8, 0x5b, 0xc7, 0x86, 0x65, 0x19, 0xc0, 0x19, 0x58, 0x20, 0x5d,\n 0x77, 0x76, 0x84, 0x99, 0x59, 0x1b, 0x05, 0x9f, 0xad, 0x15, 0xc8, 0xb7,\n 0x3e, 0x77, 0x96, 0x98, 0x85, 0x4e, 0x7e, 0xe9, 0x02, 0x0c, 0x37, 0xa4,\n 0xd7, 0xee, 0x84, 0x9b, 0xb8, 0xca, 0x3b, 0x19, 0xc0, 0x8c, 0x58, 0x20,\n 0xf0, 0x5f, 0xd5, 0xc0, 0x4e, 0xfa, 0x49, 0x4c, 0x7d, 0xd1, 0xa9, 0xb5,\n 0x5b, 0x7e, 0xdc, 0xd8, 0xee, 0xd7, 0x7a, 0x22, 0x8f, 0x32, 0x17, 0x05,\n 0x41, 0xcf, 0x95, 0x82, 0x11, 0xb2, 0x36, 0x81, 0x19, 0xc5, 0xf1, 0x58,\n 0x20, 0x0b, 0x4b, 0x67, 0xdf, 0xf8, 0x16, 0xad, 0x56, 0x46, 0xab, 0xc3,\n 0x80, 0x74, 0x02, 0x20, 0x85, 0xd2, 0x1d, 0xde, 0xb3, 0x87, 0x95, 0xc2,\n 0xd6, 0x4c, 0xe3, 0x79, 0x29, 0xf0, 0x29, 0x96, 0x2b, 0x19, 0xd9, 0x71,\n 0x58, 0x20, 0x3c, 0x01, 0xc3, 0x49, 0xa4, 0x52, 0xb2, 0xb0, 0x07, 0x0f,\n 0xb5, 0xac, 0xe9, 0x91, 0xb8, 0x30, 0xc1, 0x06, 0xa2, 0xce, 0x7d, 0x90,\n 0xa1, 0x87, 0x56, 0x50, 0x4f, 0x46, 0x0c, 0xde, 0x29, 0x05, 0x19, 0xdd,\n 0x74, 0x58, 0x20, 0xea, 0xcd, 0x7e, 0x83, 0x23, 0xe5, 0x77, 0x5e, 0x65,\n 0xcf, 0x04, 0xa3, 0x2f, 0x15, 0xbf, 0xf3, 0x00, 0x74, 0x2f, 0xf4, 0xf9,\n 0x43, 0xb1, 0xdc, 0xe7, 0x9f, 0xe8, 0xc2, 0x18, 0xda, 0x66, 0x1e, 0x19,\n 0xe1, 0x50, 0x58, 0x20, 0x89, 0x8a, 0xfc, 0xc9, 0x16, 0xdb, 0x1f, 0x4f,\n 0x53, 0x72, 0x82, 0x2c, 0x8b, 0x73, 0x9f, 0x80, 0xcd, 0xa8, 0x6f, 0x34,\n 0xad, 0x89, 0xf4, 0xe0, 0x54, 0x9e, 0x0e, 0x97, 0x73, 0x9c, 0xc4, 0x01,\n 0x19, 0xe7, 0x28, 0x58, 0x20, 0x22, 0x9f, 0xbb, 0x28, 0x46, 0xef, 0xd4,\n 0x2a, 0x6d, 0xe3, 0x21, 0xda, 0x89, 0x53, 0x29, 0xee, 0x3f, 0x5f, 0x02,\n 0xd3, 0x9a, 0x60, 0x4c, 0x4c, 0x8d, 0x6f, 0xce, 0xd5, 0xef, 0xcc, 0x11,\n 0x86, 0x19, 0xf4, 0xbd, 0x58, 0x20, 0x10, 0xe4, 0x43, 0x85, 0x10, 0x27,\n 0x62, 0xef, 0x6b, 0xbf, 0x0d, 0x2c, 0xee, 0xfd, 0x37, 0xdf, 0xc0, 0xb1,\n 0xbe, 0x6d, 0x73, 0x07, 0xb5, 0x93, 0x0d, 0x08, 0x05, 0x61, 0xca, 0xf6,\n 0x1a, 0xdf, 0x19, 0xf8, 0x18, 0x58, 0x20, 0xd3, 0xf1, 0x37, 0x31, 0x07,\n 0x09, 0xe6, 0x94, 0xc6, 0x26, 0x0e, 0xd3, 0x7b, 0x90, 0x7b, 0x26, 0x96,\n 0xdd, 0x44, 0x9d, 0x88, 0xff, 0x8f, 0x05, 0xba, 0x0b, 0xed, 0x56, 0xc4,\n 0x3e, 0x30, 0xab, 0x77, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e,\n 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0x2e, 0x61, 0x61,\n 0x6d, 0x76, 0x61, 0xa7, 0x19, 0x33, 0xd9, 0x58, 0x20, 0x86, 0x34, 0xab,\n 0x2a, 0xce, 0xa2, 0x32, 0x3a, 0x4c, 0x7c, 0xce, 0x45, 0x33, 0x93, 0x9a,\n 0x3f, 0xb3, 0x4d, 0x41, 0xca, 0x68, 0x0e, 0x6b, 0x8e, 0x27, 0x16, 0x58,\n 0xf0, 0x9e, 0x31, 0x65, 0x77, 0x19, 0x35, 0xb6, 0x58, 0x20, 0xd8, 0xb8,\n 0x74, 0x4b, 0x9d, 0x7c, 0xa9, 0xc6, 0x89, 0x4f, 0x0d, 0x5d, 0x2f, 0x7d,\n 0x1e, 0x54, 0x97, 0x5f, 0x3b, 0xdc, 0x9b, 0xfb, 0x4b, 0xe1, 0xb5, 0x34,\n 0x8e, 0xc5, 0x38, 0xe3, 0xb7, 0x03, 0x19, 0x50, 0x2f, 0x58, 0x20, 0xd0,\n 0x1c, 0xe7, 0x38, 0xf7, 0x1c, 0x26, 0x0b, 0x33, 0x6a, 0x3c, 0x5d, 0x79,\n 0x77, 0xdf, 0x5d, 0x1b, 0x42, 0xad, 0x22, 0x54, 0xcc, 0x32, 0x11, 0xde,\n 0x92, 0x95, 0x0c, 0x35, 0x46, 0xee, 0x3d, 0x19, 0x92, 0x51, 0x58, 0x20,\n 0x88, 0x8f, 0xc9, 0x85, 0xcb, 0xee, 0x8e, 0xda, 0x02, 0x8e, 0x70, 0xb2,\n 0x3d, 0x2b, 0xfc, 0x6d, 0x99, 0x72, 0x3e, 0x4e, 0xa2, 0x77, 0xca, 0x3b,\n 0x91, 0xbc, 0x02, 0xec, 0x18, 0x20, 0x0a, 0x6f, 0x19, 0xa4, 0x7c, 0x58,\n 0x20, 0xb3, 0x75, 0x9c, 0xee, 0x1e, 0x90, 0xc0, 0x59, 0x09, 0xe3, 0x1f,\n 0x69, 0x53, 0xf2, 0x08, 0x5f, 0x3e, 0xa6, 0xa0, 0xf8, 0x4d, 0x36, 0x89,\n 0x6a, 0xd1, 0x56, 0xb4, 0x66, 0x24, 0x84, 0x49, 0x18, 0x19, 0xb6, 0x49,\n 0x58, 0x20, 0x1b, 0xdd, 0xe3, 0x1d, 0x45, 0x82, 0x65, 0xe6, 0x59, 0xa6,\n 0xf9, 0x7c, 0x34, 0xd2, 0x76, 0xa6, 0xff, 0x6a, 0x4f, 0x95, 0xdc, 0xbf,\n 0x8b, 0x31, 0xa5, 0x50, 0x2d, 0x5e, 0x09, 0x65, 0xac, 0x05, 0x19, 0xe4,\n 0xe4, 0x58, 0x20, 0x27, 0x9e, 0x2e, 0x80, 0x83, 0xf8, 0x7f, 0x13, 0x43,\n 0xae, 0x43, 0x98, 0x92, 0x26, 0x0a, 0xf6, 0xc7, 0x39, 0x28, 0x69, 0x66,\n 0xb8, 0xdb, 0x15, 0xbe, 0x75, 0x1d, 0xe2, 0x45, 0xe5, 0x42, 0x0c, 0x6d,\n 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79, 0x49, 0x6e, 0x66,\n 0x6f, 0xa1, 0x69, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79,\n 0xa4, 0x01, 0x02, 0x20, 0x01, 0x21, 0x58, 0x20, 0x0b, 0xaa, 0x22, 0x38,\n 0x68, 0x47, 0x64, 0x27, 0x74, 0x33, 0xe4, 0x35, 0x17, 0xd0, 0x8f, 0x35,\n 0xa4, 0xbd, 0x72, 0xb2, 0x3b, 0xce, 0xf0, 0x28, 0x75, 0xae, 0x51, 0x0b,\n 0x88, 0x85, 0x99, 0xca, 0x22, 0x58, 0x20, 0xa5, 0xf5, 0x7b, 0xc8, 0x56,\n 0xe3, 0x9e, 0xa3, 0x8f, 0x18, 0xc7, 0x91, 0xb8, 0xca, 0x7c, 0xc3, 0x9b,\n 0xaf, 0xec, 0x37, 0x1b, 0xe0, 0x29, 0xa0, 0x28, 0x49, 0xa9, 0xb7, 0xfb,\n 0x0c, 0x31, 0x04, 0x67, 0x64, 0x6f, 0x63, 0x54, 0x79, 0x70, 0x65, 0x75,\n 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31,\n 0x33, 0x2e, 0x35, 0x2e, 0x31, 0x2e, 0x6d, 0x44, 0x4c, 0x6c, 0x76, 0x61,\n 0x6c, 0x69, 0x64, 0x69, 0x74, 0x79, 0x49, 0x6e, 0x66, 0x6f, 0xa3, 0x66,\n 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xc0, 0x74, 0x32, 0x30, 0x32, 0x35,\n 0x2d, 0x30, 0x36, 0x2d, 0x30, 0x35, 0x54, 0x31, 0x36, 0x3a, 0x35, 0x35,\n 0x3a, 0x31, 0x31, 0x5a, 0x69, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x46, 0x72,\n 0x6f, 0x6d, 0xc0, 0x74, 0x32, 0x30, 0x32, 0x35, 0x2d, 0x30, 0x36, 0x2d,\n 0x30, 0x35, 0x54, 0x31, 0x36, 0x3a, 0x35, 0x35, 0x3a, 0x31, 0x31, 0x5a,\n 0x6a, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x55, 0x6e, 0x74, 0x69, 0x6c, 0xc0,\n 0x74, 0x32, 0x30, 0x32, 0x35, 0x2d, 0x30, 0x36, 0x2d, 0x31, 0x39, 0x54,\n 0x31, 0x36, 0x3a, 0x35, 0x35, 0x3a, 0x31, 0x31, 0x5a, 0x58, 0x40, 0x35,\n 0x49, 0x2b, 0x30, 0x4e, 0xe2, 0x80, 0x8e, 0xd6, 0x93, 0x9d, 0xf8, 0xe2,\n 0xb2, 0x65, 0x01, 0xee, 0xe2, 0x89, 0xd3, 0x2b, 0x0b, 0x25, 0x96, 0x46,\n 0xe4, 0x89, 0x9d, 0xbe, 0x87, 0xb2, 0xf4, 0xfc, 0xe6, 0x90, 0x9c, 0xeb,\n 0x2c, 0x1c, 0x5c, 0x8e, 0x81, 0x3d, 0x8d, 0x28, 0xd5, 0x02, 0x47, 0x99,\n 0x72, 0x6e, 0x3c, 0x8e, 0x50, 0x26, 0xeb, 0x67, 0xe5, 0xc3, 0xfe, 0xfe,\n 0x31, 0x92, 0x30, 0x6c, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x53, 0x69,\n 0x67, 0x6e, 0x65, 0x64, 0xa2, 0x6a, 0x6e, 0x61, 0x6d, 0x65, 0x53, 0x70,\n 0x61, 0x63, 0x65, 0x73, 0xd8, 0x18, 0x41, 0xa0, 0x6a, 0x64, 0x65, 0x76,\n 0x69, 0x63, 0x65, 0x41, 0x75, 0x74, 0x68, 0xa1, 0x6f, 0x64, 0x65, 0x76,\n 0x69, 0x63, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65,\n 0x84, 0x43, 0xa1, 0x01, 0x26, 0xa0, 0xf6, 0x58, 0x40, 0x92, 0x37, 0x26,\n 0x8c, 0xe3, 0x53, 0xc8, 0x55, 0x11, 0xe7, 0x50, 0x58, 0x75, 0x3d, 0xa2,\n 0x03, 0x8b, 0xca, 0x9d, 0x20, 0xf7, 0x59, 0x51, 0x96, 0x1f, 0x14, 0xf7,\n 0x16, 0xc5, 0x9f, 0xef, 0x24, 0xd2, 0x45, 0xdb, 0xef, 0x45, 0x87, 0x02,\n 0x9f, 0x88, 0x5a, 0xed, 0x8d, 0xce, 0xba, 0x1a, 0xf8, 0x30, 0xa4, 0x49,\n 0x3b, 0xbc, 0xfa, 0xe6, 0x0b, 0xc2, 0xa5, 0xff, 0x99, 0xa1, 0xc1, 0x85,\n 0x07, 0x66, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x00}},\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_EXAMPLES_H_\n"], ["/longfellow-zk/lib/ec/p256.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_EC_P256_H_\n#define PRIVACY_PROOFS_ZK_LIB_EC_P256_H_\n\n/*\nThis file declares the one instance of the P256 curve and its related fields.\nThere should be only one instance of this curve in any program due to the\ntyping conventions.\n\nThis curve is also known as secp256r1 and prime256v1.\n\nIt is defined over the base field F_p for\np = 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff\n= 115792089210356248762697446949407573530086143415290314195533631308867097853951\n\nand has an order of\n0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551\n115792089210356248762697446949407573529996955224135760342422259061068512044369\n\n\n*/\n\n#include \"algebra/fp.h\"\n#include \"algebra/fp_p256.h\"\n#include \"ec/elliptic_curve.h\"\n\nnamespace proofs {\n\nusing Fp256Base = Fp256;\nusing Fp256Scalar = Fp<4, true>;\nusing Fp256Nat = Fp256Base::N;\n\n// This is the base field of the curve.\nextern const Fp256Base p256_base;\n\n// Order of the curve.\nextern const Fp256Nat n256_order;\n\n// This field allows operations mod the order of the curve.\nextern const Fp256Scalar p256_scalar;\n\ntypedef EllipticCurve P256;\n\nextern const P256 p256;\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_EC_P256_H_\n"], ["/longfellow-zk/lib/util/serialization.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_UTIL_SERIALIZATION_H_\n#define PRIVACY_PROOFS_ZK_LIB_UTIL_SERIALIZATION_H_\n\n#include \n\nnamespace proofs {\n\nstatic inline void u64_to_le(uint8_t a[/*8*/], uint64_t x) {\n a[0] = x & 0xffu;\n a[1] = (x >> 8) & 0xffu;\n a[2] = (x >> 16) & 0xffu;\n a[3] = (x >> 24) & 0xffu;\n a[4] = (x >> 32) & 0xffu;\n a[5] = (x >> 40) & 0xffu;\n a[6] = (x >> 48) & 0xffu;\n a[7] = (x >> 56) & 0xffu;\n}\n\nstatic inline uint64_t u64_of_le(const uint8_t a[/*8*/]) {\n return ((uint64_t)a[7] << 56) | ((uint64_t)a[6] << 48) |\n ((uint64_t)a[5] << 40) | ((uint64_t)a[4] << 32) |\n ((uint64_t)a[3] << 24) | ((uint64_t)a[2] << 16) |\n ((uint64_t)a[1] << 8) | (uint64_t)a[0];\n}\n\nstatic inline void u32_to_le(uint8_t a[/*4*/], uint32_t x) {\n a[0] = x & 0xffu;\n a[1] = (x >> 8) & 0xffu;\n a[2] = (x >> 16) & 0xffu;\n a[3] = (x >> 24) & 0xffu;\n}\n\nstatic inline uint32_t u32_of_le(const uint8_t a[/*4*/]) {\n return ((uint32_t)a[3] << 24) | ((uint32_t)a[2] << 16) |\n ((uint32_t)a[1] << 8) | (uint32_t)a[0];\n}\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_UTIL_SERIALIZATION_H_\n"], ["/longfellow-zk/lib/circuits/logic/bit_plucker_constants.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_PLUCKER_CONSTANTS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_PLUCKER_CONSTANTS_H_\n\n#include \n#include \n\nnamespace proofs {\n// bit-plucker code common to both compiler-time and\n// wire-fill time\ntemplate \nstruct bit_plucker_point {\n using Elt = typename Field::Elt;\n\n // packing of bits compatible with even_lagrange_basis():\n Elt operator()(uint64_t bits, const Field& F) const {\n return F.subf(F.of_scalar(2 * bits), F.of_scalar(N - 1));\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_PLUCKER_CONSTANTS_H_\n"], ["/longfellow-zk/lib/util/crc64.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_UTIL_CRC64_H_\n#define PRIVACY_PROOFS_ZK_LIB_UTIL_CRC64_H_\n\n/*\nThis package defines 3 basic methods for computing a simple 64-bit CRC.\nIt is used for checksum and comparison of datastructures that are internal\nto this library.\n*/\n\n#include \n\n#include \n\nnamespace proofs {\nnamespace crc64 {\nstatic inline uint64_t shlu64(uint64_t x, size_t n) {\n return (n >= 64) ? 0u : (x << n);\n}\nstatic inline uint64_t shru64(uint64_t x, size_t n) {\n return (n >= 64) ? 0u : (x >> n);\n}\nstatic inline uint64_t update(uint64_t crc, uint64_t u, size_t n = 64) {\n crc ^= u;\n uint64_t l = shlu64(crc, 127u - n) ^ shlu64(crc, 125u - n) ^\n shlu64(crc, 124u - n) ^ shlu64(crc, 64u - n);\n return shru64(crc, n) ^ l ^ (l >> 1) ^ (l >> 3) ^ (l >> 4);\n}\n} // namespace crc64\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_UTIL_CRC64_H_\n"], ["/longfellow-zk/lib/circuits/sha/sha256_constants.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_SHA256_CONSTANTS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_SHA256_CONSTANTS_H_\n\n#include \n\nnamespace proofs {\n\n// Array of round constants used to define SHA256.\n// See FIPS 180-4, section 4.2.2.\nextern const uint32_t kSha256Round[64];\n\n} // namespace proofs\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_SHA256_CONSTANTS_H_\n"], ["/longfellow-zk/lib/circuits/sha3/sha3_round_constants.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA3_SHA3_ROUND_CONSTANTS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA3_SHA3_ROUND_CONSTANTS_H_\n\n#include \n#include \n\nnamespace proofs {\nextern const uint64_t sha3_rc[24];\nextern const size_t sha3_rotc[24];\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA3_SHA3_ROUND_CONSTANTS_H_\n"], ["/longfellow-zk/lib/arrays/affine.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ARRAYS_AFFINE_H_\n#define PRIVACY_PROOFS_ZK_LIB_ARRAYS_AFFINE_H_\n\n#include \n\nnamespace proofs {\n\nusing corner_t = size_t;\n\n// return r * f0 + (1-r) * f1 = f0 + r * (f1 - f0)\ntemplate \ntypename Field::Elt affine_interpolation(const typename Field::Elt& r,\n typename Field::Elt f0,\n typename Field::Elt f1,\n const Field& F) {\n F.sub(f1, f0);\n F.mul(f1, r);\n F.add(f0, f1);\n return f0;\n}\n\n// special case f0 = 0\ntemplate \ntypename Field::Elt affine_interpolation_z_nz(const typename Field::Elt& r,\n typename Field::Elt f1,\n const Field& F) {\n F.mul(f1, r);\n return f1;\n}\n\n// special case f1 = 0\ntemplate \ntypename Field::Elt affine_interpolation_nz_z(const typename Field::Elt& r,\n typename Field::Elt f0,\n const Field& F) {\n F.sub(f0, F.mulf(f0, r));\n return f0;\n}\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ARRAYS_AFFINE_H_\n"], ["/longfellow-zk/lib/util/panic.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_UTIL_PANIC_H_\n#define PRIVACY_PROOFS_ZK_LIB_UTIL_PANIC_H_\n\n#if defined(__ABSL__)\n#include \"third_party/absl/log/check.h\"\n#else\n#include \n#include \n#endif\n\nnamespace proofs {\n\ninline void check(bool truth, const char* why) {\n#if defined(__ABSL__)\n CHECK(truth) << why;\n#else\n if (!truth) {\n fprintf(stderr, \"%s\", why);\n abort();\n }\n#endif\n}\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_UTIL_PANIC_H_\n"], ["/longfellow-zk/lib/circuits/base64/decode_util.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_BASE64_DECODE_UTIL_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_BASE64_DECODE_UTIL_H_\n\n#include \n\n#include \n#include \n\nnamespace proofs {\n\nbool base64_decode_url(std::string inp, std::vector& out);\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_BASE64_DECODE_UTIL_H_\n"], ["/longfellow-zk/lib/circuits/cbor_parser/cbor_constants.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_CONSTANTS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_CONSTANTS_H_\n\n#include \n\nnamespace proofs {\nstruct CborConstants {\n static constexpr size_t kNCounters = 4;\n static constexpr size_t kIndexBits = 12;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_CONSTANTS_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_revocation_constants.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_REVOCATION_CONSTANTS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_REVOCATION_CONSTANTS_H_\n\n#include \nnamespace proofs {\n\nstatic constexpr size_t kSHARevocationPluckerBits = 4u;\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_REVOCATION_CONSTANTS_H_\n"], ["/longfellow-zk/lib/random/secure_random_engine.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_RANDOM_SECURE_RANDOM_ENGINE_H_\n#define PRIVACY_PROOFS_ZK_LIB_RANDOM_SECURE_RANDOM_ENGINE_H_\n\n#include \n\n#include \n#include \n\n#include \"random/random.h\"\n#include \"util/crypto.h\"\n\nnamespace proofs {\n\n// SecureRandomEngine is a RandomEngine that uses openssl.\nclass SecureRandomEngine : public RandomEngine {\n public:\n SecureRandomEngine() = default;\n void bytes(uint8_t* buf, size_t n) override { rand_bytes(buf, n); }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_RANDOM_SECURE_RANDOM_ENGINE_H_\n"], ["/longfellow-zk/lib/circuits/sha/flatsha256_io.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_FLATSHA256_IO_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_FLATSHA256_IO_H_\n\n#include \n\nnamespace proofs {\n\nconstexpr const size_t kShaPluckerSize = 2;\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_FLATSHA256_IO_H_\n"], ["/longfellow-zk/lib/algebra/static_string.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_STATIC_STRING_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_STATIC_STRING_H_\n\n#include \n\n// utility class to wrap pointers to compile-time\n// constant strings\nstruct StaticString {\n template \n explicit StaticString(const char (&s)[N]) : as_pointer(s) {}\n\n const char* as_pointer;\n};\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_STATIC_STRING_H_\n"], ["/longfellow-zk/lib/util/log.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_UTIL_LOG_H_\n#define PRIVACY_PROOFS_ZK_LIB_UTIL_LOG_H_\n\n// Simple, self-contained logger for this library.\n\nnamespace proofs {\n\nenum LogLevel {\n ERROR = 1,\n WARNING = 10,\n INFO = 100,\n};\n\nvoid set_log_level(enum LogLevel l);\n\nvoid log(enum LogLevel l, const char* format, ...);\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_UTIL_LOG_H_\n"]], "task_instance_info": {"created_time": "2025-08-20 19:59:49", "created_task_model": "DeepSeek-R1", "function_skeleton": "EltW repack(const v8 in[], size_t ind) const {}", "code_description": "This code segment functions to: Convert a sequence of bytes into a numeric representation by iteratively processing individual bits and applying bitwise shifts and arithmetic operations to assemble a packed value."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```cpp\n[TASK_BEGIN]\nEltW repack(const v8 in[], size_t ind) const {\n return lc_.vn_to_eltw(lc_.vbytes_to_vnat(32, &in[ind]));\n}\n[TASK_END]\n```", "inference_time": "2025-08-20 20-00-09"}, "editdistance_info": {"edit_distance": 17.4242, "calculate_time": "2025-08-20 20:00:09", "true_code_clean": "EltW repack(const v8 in[], size_t ind) const {\n EltW h = lc_.konst(0);\n EltW base = lc_.konst(0x2);\n for (size_t i = 0; i < 32; ++i) {\n for (size_t j = 0; j < 8; ++j) {\n auto t = lc_.mul(&h, base);\n auto tin = lc_.eval(in[ind + i][7 - j]);\n h = lc_.add(&tin, t);\n }\n }\n return h;\n }", "predict_code_clean": "EltW repack(const v8 in[], size_t ind) const {\n return lc_.vn_to_eltw(lc_.vbytes_to_vnat(32, &in[ind]));\n}"}} {"repo_name": "longfellow-zk", "file_name": "/longfellow-zk/lib/circuits/mac/mac_circuit.h", "inference_info": {"prefix_code": "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MAC_MAC_CIRCUIT_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MAC_MAC_CIRCUIT_H_\n\n// Implements a message authentication code in GF 2^k for a 256-bit message.\n// The mac key is additively sampled by both the prover and verifier to ensure\n// soundness and zk.\n//\n// The mac is defined as (a_pi+a_v)*x_i = mac_i where (x_1,x_2) are 128-bit\n// portions of the hidden message. The verifier need only contribute one\n// a_v for all MACs verified in the circuit. The prover needs to commit to\n// separate a_p{i} for each portion of each message.\n//\n// The property that we need from this primitive is as follows:\n// Assume the prover has committed to a_pi and x, i.e., fix a_pi, x.\n// The probability over the verifier's random a_v that mac(x) = mac_(y)\n// if x != y is at most 2^{-128}.\n\n#include \n#include \n\n#include \"circuits/compiler/compiler.h\"\n#include \"circuits/logic/logic.h\"\n#include \"gf2k/gf2_128.h\"\n\nnamespace proofs {\n\nstatic constexpr size_t kMACPluckerBits = 2u;\n\n// MAC: implements a MAC in GF 2^k for a 256-bit message by simulating\n// the arithmetic of the GF 2^k field. This implementation commits both\n// the prover's a_p key as well as the bits of the message. This allows\n// the MAC computation and the equality of the purported message to be verified\n// in parallel to reduce depth.\ntemplate \nclass MAC {\n public:\n using Field = typename Logic::Field;\n using Elt = typename Field::Elt;\n using EltW = typename Logic::EltW;\n using Nat = typename Field::N;\n using v8 = typename Logic::v8;\n using v128 = typename Logic::v128;\n using v256 = typename Logic::v256;\n using packed_v128 = typename BitPlucker::packed_v128;\n using packed_v256 = typename BitPlucker::packed_v256;\n\n BitPlucker bp_;\n\n class Witness {\n public:\n packed_v128 aa_[2];\n packed_v256 xx_; // The value to be checked\n\n template \n static T packed_input(QuadCircuit& Q) {\n T r;\n for (size_t i = 0; i < r.size(); ++i) {\n r[i] = Q.input();\n }\n return r;\n }\n\n void input(const Logic& LC, QuadCircuit& Q) {\n aa_[0] = packed_input(Q);\n aa_[1] = packed_input(Q);\n xx_ = packed_input(Q);\n }\n };\n\n explicit MAC(const Logic& lc) : bp_(lc), lc_(lc) {}\n\n // Verifies a mac on the Field element value against the key (a_p + a_v).\n // This method can only be called when the field is at least 256 bits, e.g.,\n // with F_p256. In other cases, the caller should use a verify_mac method\n // that takes the message in bit-wise form. Additionally, the order parameter\n // is used to ensure that the message does not overflow the field.\n void verify_mac(EltW msg, const v128 mac[/*2*/], const v128& av,\n const Witness& vw, Nat order) const {\n check(Field::kBits >= 256, \"Field::kBits < 256\");\n v128 msg2[2];\n unpack_msg(msg2, msg, order, vw);\n assert_mac(mac, av, msg2, vw);\n }\n\n private:\n // Checks mac[i] = (a_p + a_v)*xi[i] for i=0..1.\n void assert_mac(const v128 mac[/*2*/], const v128& av, const v128 xi[/*2*/],\n const Witness& vw) const {\n v128 mv;\n for (size_t i = 0; i < 2; ++i) {\n v128 ap = bp_.template unpack(vw.aa_[i]);\n v128 key = lc_.vxor(&av, ap);\n lc_.gf2_128_mul(mv, key, xi[i]);\n lc_.vassert_eq(&mac[i], mv);\n }\n }\n\n ", "suffix_code": "\n\n const Logic& lc_;\n};\n\n// Same MAC computation for native GF2_128 field.\ntemplate \nclass MACGF2 {\n public:\n using Elt = typename Logic, Backend>::Elt;\n using EltW = typename Logic, Backend>::EltW;\n using BitW = typename Logic, Backend>::BitW;\n\n // In this specialization, 128 bits are stored in a native EltW.\n using v128 = EltW;\n\n // Message input types v8, v256 are still encoded bit-wise.\n using v8 = typename Logic, Backend>::v8;\n using v256 = typename Logic, Backend>::v256;\n\n explicit MACGF2(const Logic, Backend>& lc)\n : lc_(lc) {}\n class Witness {\n public:\n EltW aa_[2];\n\n void input(const Logic, Backend>& lc,\n QuadCircuit>& Q) {\n aa_[0] = Q.input();\n aa_[1] = Q.input();\n }\n };\n\n // Verify a mac on the 256-bit message msg.\n void verify_mac(const EltW mac[/*2*/], const EltW& av, const v256& msg,\n const Witness& vw) const {\n // Check that mac[i] = (a_p + a_v)*mm[i] for i=0..1.\n for (size_t i = 0; i < 2; ++i) {\n EltW mm = pack(&msg[i * 128]);\n EltW key = lc_.add(&av, vw.aa_[i]);\n EltW got = lc_.mul(&key, mm);\n lc_.assert_eq(&mac[i], got);\n }\n }\n\n private:\n // Pack a 128-bit message into a GF(2^128) field element.\n EltW pack(const BitW msg[/*128*/]) const {\n Elt alpha = lc_.f_.x();\n Elt xi = lc_.f_.one();\n EltW m = lc_.konst(0);\n for (size_t i = 0; i < 128; ++i) {\n m = lc_.axpy(&m, xi, lc_.eval(msg[i]));\n xi = lc_.mulf(xi, alpha);\n }\n return m;\n }\n\n const Logic, Backend>& lc_;\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MAC_MAC_CIRCUIT_H_\n", "middle_code": "void unpack_msg(v128 msg[], EltW msgw, Nat order,\n const Witness& vw) const {\n v256 x = bp_.template unpack(vw.xx_);\n std::copy(x.begin(), x.begin() + 128, msg[0].begin());\n std::copy(x.begin() + 128, x.end(), msg[1].begin());\n v256 bits_n;\n for (size_t i = 0; i < 256; ++i) {\n bits_n[i] = lc_.bit(order.bit(i));\n }\n lc_.assert1(lc_.vlt(&x, bits_n));\n EltW te = lc_.konst(lc_.zero());\n Elt twok = lc_.one();\n for (size_t i = 0; i < 256; ++i) {\n te = lc_.axpy(&te, twok, lc_.eval(x[i]));\n lc_.f_.add(twok, twok);\n }\n lc_.assert_eq(&te, msgw);\n }", "code_description": null, "fill_type": "FUNCTION_TYPE", "language_type": "cpp", "sub_task_type": null}, "context_code": [["/longfellow-zk/lib/circuits/mdoc/mdoc_signature.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_SIGNATURE_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_SIGNATURE_H_\n\n#include \n\n#include \"circuits/compiler/compiler.h\"\n#include \"circuits/ecdsa/verify_circuit.h\"\n#include \"circuits/logic/bit_plucker.h\"\n#include \"circuits/mac/mac_circuit.h\"\n\nnamespace proofs {\n\n// This class creates a circuit to verify the signatures in an MDOC.\n// There are 2 signatures:\n// 1. A signature on the MSO by the issuer of the MDOC: The public\n// key of the issuer is given as input for now. Later, it can be\n// one among a list of issuers. While the signer is public, the\n// message is private, and thus its hash is committed in the witness.\n// 2. A signature on the transcript provided during a \"Show\" operation:\n// the signature is under a device public key that is specified in the\n// MSO. Thus, the signing key is private (and committed), but the\n// message is public.\ntemplate \nclass MdocSignature {\n using EltW = typename LogicCircuit::EltW;\n using Elt = typename LogicCircuit::Elt;\n using Nat = typename Field::N;\n using v128 = typename LogicCircuit::v128;\n using v256 = typename LogicCircuit::v256;\n using Ecdsa = VerifyCircuit;\n using EcdsaWitness = typename Ecdsa::Witness;\n using MacBitPlucker = BitPlucker;\n using packed_v256 = typename MacBitPlucker::packed_v256;\n using mac = MAC;\n using MACWitness = typename mac::Witness;\n\n const LogicCircuit& lc_;\n const EC& ec_;\n const Nat& order_;\n\n public:\n class Witness {\n public:\n EltW e_;\n EltW dpkx_, dpky_;\n\n EcdsaWitness mdoc_sig_;\n EcdsaWitness dpk_sig_;\n MACWitness macs_[3];\n\n void input(QuadCircuit& Q, const LogicCircuit& lc) {\n e_ = Q.input();\n dpkx_ = Q.input();\n dpky_ = Q.input();\n\n mdoc_sig_.input(Q);\n dpk_sig_.input(Q);\n for (size_t i = 0; i < 3; ++i) {\n macs_[i].input(lc, Q);\n }\n }\n };\n\n explicit MdocSignature(const LogicCircuit& lc, const EC& ec, const Nat& order)\n : lc_(lc), ec_(ec), order_(order) {}\n\n // This function is used to verify the signatures in an MDOC.\n // The circuit verifies the following claims:\n // 1. There exists a hash digest e and a signature (r,s) on e\n // under the public key (pkX, pkY).\n // 2. The MAC of e under the secret mac key (a_v+a_pe) is mac_e.\n // 3. There exists a device public key (dpkX, dpky) and a signature (r,s)\n // on the value hash_tr.\n // 4. The MAC of the device public key (dpkX, dpky) under the secret MAC\n // key (a_v + apdk) is mac_dkpX and mac_dpkY respectively.\n void assert_signatures(EltW pkX, EltW pkY, EltW hash_tr, v128 mac_e[2],\n v128 mac_dpkX[2], v128 mac_dpkY[2], v128 a_v,\n Witness& vw) const {\n Ecdsa ecc(lc_, ec_, order_);\n mac macc(lc_);\n\n ecc.verify_signature3(pkX, pkY, vw.e_, vw.mdoc_sig_);\n ecc.verify_signature3(vw.dpkx_, vw.dpky_, hash_tr, vw.dpk_sig_);\n\n macc.verify_mac(vw.e_, mac_e, a_v, vw.macs_[0], order_);\n macc.verify_mac(vw.dpkx_, mac_dpkX, a_v, vw.macs_[1], order_);\n macc.verify_mac(vw.dpky_, mac_dpkY, a_v, vw.macs_[2], order_);\n }\n\n // This function is similar to assert_signatures, but it also hides the\n // public key of the issuer. Instead, it verifies that the issuer's public\n // key belongs in a list of 50 public keys that are supplied as input. The\n // issuer pk lists are assumed to be trusted inputs, i.e., it is the\n // caller's responsibility to ensure that (issuer_pkX[i], issuer_pkY[i]) is\n // a valid curve point for i=0..49. The caller is also responsible for\n // ensuring that issuer_pkY[i] != -issuer_pkY[j] for i != j.\n // However, it is OK for the caller to repeat the same key in the list.\n void assert_signatures_with_issuer_list(\n EltW hash_tr, v128 mac_e[2], v128 mac_dpkX[2], v128 mac_dpkY[2], v128 a_v,\n EltW issuer_pkX[/*max_issuers*/], EltW issuer_pkY[/*max_issuers*/],\n size_t max_issuers,\n // private inputs begin here\n EltW pkX, EltW pkY, Witness& vw) const {\n assert_signatures(pkX, pkY, hash_tr, mac_e, mac_dpkX, mac_dpkY, a_v, vw);\n\n // Verify that the issuer's public key is one of the 50 keys in the list.\n // This is done by computing the difference between pkX and issuer_pkX[i]\n // for i=0..49, and asserting that the product of the differences is zero.\n //\n // We argue that it suffices to verify that pkX is on the list and pkY is\n // on the list independently. Suppose a malicious prover sets pkX to be\n // equal to the j-th key in issuer_pkX and sets pkY to be the k-th key in\n // issuer_pkY, where j != k. If (pkX, pkY) is not a curve point, then the\n // assert_signatures() routine will fail. However, for each X on the curve,\n // there are only 2 possible Y values, namely, +-Y. By the constraints\n // imposed on issuer_pkY, we know that issuer_pkY[j] is on the curve, and\n // that -issuer_pkY[j] does not occur in the issuer_pkY list. Thus, it is\n // not possible for a witness to pass all checks and for k != j.\n EltW goodXKey = lc_.mul(0, max_issuers, [&](size_t i) {\n return lc_.sub(&issuer_pkX[i], pkX);\n });\n lc_.assert0(goodXKey);\n\n EltW goodYKey = lc_.mul(0, max_issuers, [&](size_t i) {\n return lc_.sub(&issuer_pkY[i], pkY);\n });\n lc_.assert0(goodYKey);\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_SIGNATURE_H_\n"], ["/longfellow-zk/lib/circuits/jwt/jwt.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_JWT_JWT_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_JWT_JWT_H_\n\n#include \n#include \n#include \n\n#include \"circuits/base64/decode.h\"\n#include \"circuits/compiler/compiler.h\"\n#include \"circuits/ecdsa/verify_circuit.h\"\n#include \"circuits/jwt/jwt_constants.h\"\n#include \"circuits/logic/bit_plucker.h\"\n#include \"circuits/logic/routing.h\"\n#include \"circuits/sha/flatsha256_circuit.h\"\n\nnamespace proofs {\n\ntemplate \nclass JWT {\n using EltW = typename LogicCircuit::EltW;\n using BitW = typename LogicCircuit::BitW;\n using Nat = typename Field::N;\n using Ecdsa = VerifyCircuit;\n using EcdsaWitness = typename Ecdsa::Witness;\n using v8 = typename LogicCircuit::v8;\n using v256 = typename LogicCircuit::v256;\n using Flatsha =\n FlatSHA256Circuit>;\n using ShaBlockWitness = typename Flatsha::BlockWitness;\n using sha_packed_v32 = typename Flatsha::packed_v32;\n using vind = typename LogicCircuit::template bitvec;\n\n public:\n struct OpenedAttribute {\n v8 attr[32]; /* 32b representing attribute name in be. */\n v8 v1[64]; /* 64b of attribute value */\n };\n\n class Witness {\n public:\n EltW r_, s_, e_;\n EcdsaWitness jwt_sig_;\n v8 preimage_[64 * kMaxJWTSHABlocks];\n v256 e_bits_;\n ShaBlockWitness sha_[kMaxJWTSHABlocks];\n v8 nb_; /* index of sha block that contains the real hash */\n std::vector attr_ind_;\n std::vector attr_id_len_;\n std::vector attr_value_len_;\n vind payload_ind_, payload_len_;\n\n void input(QuadCircuit& Q, const LogicCircuit& lc, size_t na) {\n r_ = Q.input();\n s_ = Q.input();\n e_ = Q.input();\n jwt_sig_.input(Q);\n for (size_t i = 0; i < 64 * kMaxJWTSHABlocks; ++i) {\n preimage_[i] = lc.template vinput<8>();\n }\n e_bits_ = lc.template vinput<256>();\n for (size_t j = 0; j < kMaxJWTSHABlocks; ++j) {\n sha_[j].input(Q);\n }\n nb_ = lc.template vinput<8>();\n\n for (size_t j = 0; j < na; ++j) {\n attr_ind_.push_back(lc.template vinput());\n attr_id_len_.push_back(lc.template vinput<8>());\n attr_value_len_.push_back(lc.template vinput<8>());\n }\n payload_ind_ = lc.template vinput();\n payload_len_ = lc.template vinput();\n }\n };\n\n explicit JWT(const LogicCircuit& lc, const EC& ec, const Nat& order)\n : lc_(lc), ec_(ec), order_(order), sha_(lc), r_(lc) {}\n\n // The assert_jwt_attributes circuit verifies the following claims:\n // 1. There exists a hash digest e and a signature (r,s) on e\n // under the public key (pkX, pkY).\n // 2. There exists a msg, and the hash of msg is equal to e.\n // 3. The JWT message is decoded correctly from base64.\n // 4. The decoded message is equal to the payload.header.\n // 5. The header contains alg:ESP256. [TODO]\n // 6. The attributes occur as \":\"\" in the payload.body.\n //\n // Note that the soundness of (6) relies on assumptions about the format of\n // the JWT. The issuer cannot add spaces, cannot escape quotes in the body,\n // and the character : should only appear as a separator.\n void assert_jwt_attributes(EltW pkX, EltW pkY,\n OpenedAttribute oa[/* NUM_ATTR */],\n Witness& vw) const {\n Ecdsa ecc(lc_, ec_, order_);\n\n ecc.verify_signature3(pkX, pkY, vw.e_, vw.jwt_sig_);\n\n sha_.assert_message_hash(kMaxJWTSHABlocks, vw.nb_, vw.preimage_, vw.e_bits_,\n vw.sha_);\n lc_.vassert_is_bit(vw.e_bits_);\n\n // Check that the e_bits_ match the EltW for e used in the signature.\n auto twok = lc_.one();\n auto est = lc_.konst(0);\n for (size_t i = 0; i < 256; ++i) {\n est = lc_.axpy(&est, twok, lc_.eval(vw.e_bits_[i]));\n lc_.f_.add(twok, twok);\n }\n lc_.assert_eq(&est, vw.e_);\n\n // Assert the attribute equality\n const v8 zz = lc_.template vbit<8>(0); // cannot appear in strings\n std::vector shift_buf(64 * kMaxJWTSHABlocks);\n\n // First shift the payload into the shift_buf.\n r_.shift(vw.payload_ind_, 64 * (kMaxJWTSHABlocks - 2), shift_buf.data(),\n 64 * kMaxJWTSHABlocks, vw.preimage_, zz, 3);\n\n // Decode the entire payload. A possible improvement is to decode just\n // the portion necessary.\n std::vector dec_buf(64 * kMaxJWTSHABlocks);\n Base64Decoder b64(lc_);\n b64.base64_rawurl_decode_len(shift_buf.data(), dec_buf.data(),\n 64 * (kMaxJWTSHABlocks - 2), vw.payload_len_);\n\n // For each attribute, shift the decoded payload so that the\n // attribute is at the beginning of B. Verify the attribute id, the\n // json separator, the attribute value, and the end quote.\n for (size_t i = 0; i < vw.attr_ind_.size(); ++i) {\n v8 B[32 + 3 + 64 + 1];\n\n // Check that values of the attribute_id.\n r_.shift(vw.attr_ind_[i], 100, B, dec_buf.size(), dec_buf.data(), zz, 3);\n assert_string_eq(32, vw.attr_id_len_[i], B, oa[i].attr);\n\n r_.shift(vw.attr_id_len_[i], 100, B, 100, B, zz, 3);\n uint8_t sep[3] = {'\"', ':', '\"'};\n for (size_t j = 0; j < 3; ++j) {\n auto want_j = lc_.template vbit<8>(sep[j]);\n lc_.vassert_eq(&B[j], want_j);\n }\n\n auto three = lc_.template vbit<2>(3);\n r_.shift(three, 100, B, 100, B, zz, 3);\n\n assert_string_eq(64, vw.attr_value_len_[i], B, oa[i].v1);\n\n r_.shift(vw.attr_value_len_[i], 100, B, 100, B, zz, 3);\n\n auto end_quote = lc_.template vbit<8>('\"');\n lc_.vassert_eq(&B[0], end_quote);\n }\n }\n\n void assert_string_eq(size_t max, const v8& len, const v8 got[/*max*/],\n const v8 want[/*max*/]) const {\n for (size_t j = 0; j < max; ++j) {\n auto ll = lc_.vlt(j, len);\n auto same = lc_.eq(8, got[j].data(), want[j].data());\n lc_.assert_implies(&ll, same);\n }\n }\n\n private:\n const LogicCircuit& lc_;\n const EC& ec_;\n const Nat& order_;\n Flatsha sha_;\n Routing r_;\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_JWT_JWT_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_1f.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_1F_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_1F_H_\n\n#include \n#include \n#include \n\n#include \"circuits/cbor_parser/cbor.h\"\n#include \"circuits/compiler/compiler.h\"\n#include \"circuits/ecdsa/verify_circuit.h\"\n#include \"circuits/logic/bit_plucker.h\"\n#include \"circuits/logic/routing.h\"\n#include \"circuits/mdoc/mdoc_1f_io.h\"\n#include \"circuits/mdoc/mdoc_constants.h\"\n#include \"circuits/sha/flatsha256_circuit.h\"\nnamespace proofs {\n\ntemplate \nclass mdoc_1f {\n using EltW = typename LogicCircuit::EltW;\n using Elt = typename LogicCircuit::Elt;\n using Nat = typename Field::N;\n using Ecdsa = VerifyCircuit;\n using EcdsaWitness = typename Ecdsa::Witness;\n\n using v8 = typename LogicCircuit::v8;\n using v32 = typename LogicCircuit::v32;\n using v256 = typename LogicCircuit::v256;\n using vind = typename LogicCircuit::template bitvec;\n using Flatsha =\n FlatSHA256Circuit>;\n using Routing = Routing;\n using ShaBlockWitness = typename Flatsha::BlockWitness;\n using sha_packed_v32 = typename Flatsha::packed_v32;\n using Cbor = Cbor;\n\n const LogicCircuit& lc_;\n const EC& ec_;\n const Nat& order_;\n\n public:\n struct CborIndex {\n vind k, v, ndx;\n void input(const LogicCircuit& lc) {\n k = lc.template vinput();\n v = lc.template vinput();\n ndx = lc.template vinput();\n }\n };\n\n struct AttrShift {\n vind offset;\n vind len;\n void input(const LogicCircuit& lc) {\n offset = lc.template vinput();\n len = lc.template vinput();\n }\n };\n\n class Witness {\n public:\n EltW e_;\n EltW dpkx_, dpky_;\n\n EcdsaWitness sig_;\n EcdsaWitness dpk_sig_;\n\n v8 in_[64 * kMdoc1MaxSHABlocks]; /* input bytes, 64 * MAX */\n v8 nb_; /* index of sha block that contains the real hash */\n ShaBlockWitness sig_sha_[kMdoc1MaxSHABlocks];\n\n size_t num_attr_;\n\n std::vector> attr_sha_;\n std::vector> attrb_;\n\n std::vector attr_mso_;\n std::vector attr_ei_;\n std::vector attr_ev_;\n\n std::vector incb_;\n std::vector pwcb_;\n typename Cbor::global_witness gwcb_;\n\n vind prepad_, mso_len_;\n\n CborIndex valid_, valid_from_, valid_until_;\n CborIndex dev_key_info_, dev_key_, dev_key_pkx_, dev_key_pky_;\n CborIndex value_digests_, org_;\n\n explicit Witness(size_t num_attr)\n : num_attr_(num_attr),\n attr_sha_(num_attr),\n attrb_(num_attr),\n attr_mso_(num_attr),\n attr_ei_(num_attr),\n attr_ev_(num_attr),\n incb_(kMdoc1MaxMsoLen),\n pwcb_(kMdoc1MaxMsoLen) {\n for (size_t i = 0; i < num_attr; ++i) {\n attr_sha_[i].resize(2);\n }\n }\n\n void input(QuadCircuit& Q, const LogicCircuit& lc) {\n e_ = Q.input();\n dpkx_ = Q.input();\n dpky_ = Q.input();\n\n sig_.input(Q);\n dpk_sig_.input(Q);\n\n nb_ = lc.template vinput<8>();\n\n // sha input init (skip the prefix) =========================\n for (size_t i = 0; i + kCose1PrefixLen < 64 * kMdoc1MaxSHABlocks; ++i) {\n in_[i] = lc.template vinput<8>();\n }\n\n for (size_t j = 0; j < kMdoc1MaxSHABlocks; j++) {\n sig_sha_[j].input(Q);\n }\n\n // Cbor input init: note, the inC array will be constructed in the\n // circuit.\n prepad_ = lc.template vinput();\n mso_len_ = lc.template vinput();\n for (size_t i = 0; i < kMdoc1MaxMsoLen; ++i) {\n pwcb_[i].encoded_sel_header = Q.input();\n }\n gwcb_.invprod_decode = Q.input();\n gwcb_.cc0 = Q.input();\n gwcb_.invprod_parse = Q.input();\n\n valid_.input(lc);\n valid_from_.input(lc);\n valid_until_.input(lc);\n dev_key_info_.input(lc);\n dev_key_.input(lc);\n dev_key_pkx_.input(lc);\n dev_key_pky_.input(lc);\n value_digests_.input(lc);\n org_.input(lc);\n\n // Attribute opening witnesses\n for (size_t ai = 0; ai < num_attr_; ++ai) {\n for (size_t i = 0; i < 64 * 2; ++i) {\n attrb_[ai].push_back(lc.template vinput<8>());\n }\n for (size_t j = 0; j < 2; j++) {\n attr_sha_[ai][j].input(Q);\n }\n attr_mso_[ai].input(lc);\n attr_ei_[ai].input(lc);\n attr_ev_[ai].input(lc);\n }\n }\n };\n\n struct OpenedAttribute {\n v8 attr[96]; // representing attribute name, elementValue delimiter, and\n // finally the attribute value.\n };\n\n struct PathEntry {\n CborIndex ind;\n size_t l;\n const uint8_t* name;\n };\n\n explicit mdoc_1f(const LogicCircuit& lc, const EC& ec, const Nat& order)\n : lc_(lc), ec_(ec), order_(order), sha_(lc), r_(lc), cbor_(lc) {}\n\n void assert_credential(EltW pkX, EltW pkY, EltW hash_tr,\n OpenedAttribute oa[/* NUM_ATTR */],\n const v8 now[/*kDateLen*/], const Witness& vw) const {\n Ecdsa ecc(lc_, ec_, order_);\n\n ecc.verify_signature3(pkX, pkY, vw.e_, vw.sig_);\n ecc.verify_signature3(vw.dpkx_, vw.dpky_, hash_tr, vw.dpk_sig_);\n\n sha_.assert_message_with_prefix(kMdoc1MaxSHABlocks, vw.nb_, vw.in_,\n kCose1Prefix, kCose1PrefixLen, vw.sig_sha_);\n // Verify that the hash of the mdoc is equal to e.\n assert_hash(vw.e_, vw);\n\n // Shift a portion of the MSO into buf and check it.\n const v8 zz = lc_.template vbit<8>(0); // cannot appear in strings\n std::vector cmp_buf(kMdoc1MaxMsoLen);\n\n // Re-arrange the input wires to produce the <0 padded> input\n // required for cbor parsing. The subtracted 5 corresponds to the fix\n // length D8 18 prefix of the mso that we want to skip parsing.\n // The subtracted 2 corresponds to the length.\n std::vector in_cb(kMdoc1MaxMsoLen);\n r_.unshift(vw.prepad_, kMdoc1MaxMsoLen, in_cb.data(),\n kMdoc1MaxMsoLen - 5 - 2, vw.in_ + 5 + 2, zz, 3);\n\n std::vector dsC(kMdoc1MaxMsoLen);\n std::vector psC(kMdoc1MaxMsoLen);\n cbor_.decode_and_assert_decode_and_parse(kMdoc1MaxMsoLen, dsC.data(),\n psC.data(), in_cb.data(),\n vw.pwcb_.data(), vw.gwcb_);\n\n cbor_.assert_input_starts_at(kMdoc1MaxMsoLen, vw.prepad_, vw.mso_len_,\n dsC.data());\n\n // Validity\n PathEntry vk[2] = {{vw.valid_, kValidityInfoLen, kValidityInfoID},\n {vw.valid_from_, kValidFromLen, kValidFromID}};\n assert_path(2, vk, vw, dsC, psC);\n cbor_.assert_date_before_at(kMdoc1MaxMsoLen, vw.valid_from_.v, now,\n dsC.data());\n\n // validUntil is a key in validityInfo.\n cbor_.assert_map_entry(kMdoc1MaxMsoLen, vw.valid_.v, 1, vw.valid_until_.k,\n vw.valid_until_.v, vw.valid_until_.ndx, dsC.data(),\n psC.data());\n cbor_.assert_text_at(kMdoc1MaxMsoLen, vw.valid_until_.k, kValidUntilLen,\n kValidUntilID, dsC.data());\n cbor_.assert_date_after_at(kMdoc1MaxMsoLen, vw.valid_until_.v, now,\n dsC.data());\n\n PathEntry dk[2] = {{vw.dev_key_info_, kDeviceKeyInfoLen, kDeviceKeyInfoID},\n {vw.dev_key_, kDeviceKeyLen, kDeviceKeyID}};\n assert_path(2, dk, vw, dsC, psC);\n cbor_.assert_map_entry(kMdoc1MaxMsoLen, vw.dev_key_.v, 2, vw.dev_key_pkx_.k,\n vw.dev_key_pkx_.v, vw.dev_key_pkx_.ndx, dsC.data(),\n psC.data());\n cbor_.assert_map_entry(kMdoc1MaxMsoLen, vw.dev_key_.v, 2, vw.dev_key_pky_.k,\n vw.dev_key_pky_.v, vw.dev_key_pky_.ndx, dsC.data(),\n psC.data());\n cbor_.assert_negative_at(kMdoc1MaxMsoLen, vw.dev_key_pkx_.k, 1, dsC.data());\n cbor_.assert_negative_at(kMdoc1MaxMsoLen, vw.dev_key_pky_.k, 2, dsC.data());\n cbor_.assert_elt_as_be_bytes_at(kMdoc1MaxMsoLen, vw.dev_key_pkx_.v, 32,\n vw.dpkx_, dsC.data());\n cbor_.assert_elt_as_be_bytes_at(kMdoc1MaxMsoLen, vw.dev_key_pky_.v, 32,\n vw.dpky_, dsC.data());\n // Attributes parsing\n PathEntry ak[2] = {{vw.value_digests_, kValueDigestsLen, kValueDigestsID},\n {vw.org_, kOrgLen, kOrgID}};\n assert_path(2, ak, vw, dsC, psC);\n\n // Attributes: Equality of hash with MSO value\n for (size_t ai = 0; ai < vw.num_attr_; ++ai) {\n auto two = lc_.template vbit<8>(2);\n v8 B[96];\n sha_.assert_message(2, two, vw.attrb_[ai].data(),\n vw.attr_sha_[ai].data());\n\n EltW h = repack32(vw.attr_sha_[ai][1].h1);\n // Check the hash matches the value in the signed MSO.\n cbor_.assert_map_entry(kMdoc1MaxMsoLen, vw.org_.v, 2, vw.attr_mso_[ai].k,\n vw.attr_mso_[ai].v, vw.attr_mso_[ai].ndx,\n dsC.data(), psC.data());\n cbor_.assert_elt_as_be_bytes_at(kMdoc1MaxMsoLen, vw.attr_mso_[ai].v, 32,\n h, dsC.data());\n\n // Check that the attribute_id and value occur in the hashed text.\n r_.shift(vw.attr_ei_[ai].offset, 96, B, 128, vw.attrb_[ai].data(), zz, 3);\n assert_attribute(96, vw.attr_ei_[ai].len, B, oa[ai].attr);\n }\n }\n\n private:\n EltW repack32(const sha_packed_v32 H[]) const {\n EltW h = lc_.konst(0);\n Elt twok = lc_.one();\n for (size_t j = 8; j-- > 0;) {\n auto hj = sha_.bp_.unpack_v32(H[j]);\n for (size_t k = 0; k < 32; ++k) {\n h = lc_.axpy(&h, twok, lc_.eval(hj[k]));\n lc_.f_.add(twok, twok);\n }\n }\n return h;\n }\n\n // Assert that the hash of the mdoc is equal to e.\n // The hash is encoded in the SHA witness, and thus the correct block\n // must be muxed for the comparison. Thus method first muxes the \"packed\"\n // encoding of the SHA witness, then unpacks it and compares it to e to\n // save a lot of work in the bit plucker.\n void assert_hash(const EltW& e, const Witness& vw) const {\n sha_packed_v32 x[8];\n for (size_t b = 0; b < kMdoc1MaxSHABlocks; ++b) {\n auto bt = lc_.veq(vw.nb_, b + 1); /* b is zero-indexed */\n auto ebt = lc_.eval(bt);\n for (size_t i = 0; i < 8; ++i) {\n for (size_t k = 0; k < sha_.bp_.kNv32Elts; ++k) {\n if (b == 0) {\n x[i][k] = lc_.mul(&ebt, vw.sig_sha_[b].h1[i][k]);\n } else {\n auto maybe_sha = lc_.mul(&ebt, vw.sig_sha_[b].h1[i][k]);\n x[i][k] = lc_.add(&x[i][k], maybe_sha);\n }\n }\n }\n }\n\n EltW h = repack32(x);\n lc_.assert_eq(&h, e);\n }\n\n // Checks that an attribute id or attribute value is as expected.\n // The len parameter holds the byte length of the expected id or value.\n void assert_attribute(size_t max, const vind& len, const v8 got[/*max*/],\n const v8 want[/*max*/]) const {\n // auto two = lc_.konst(2);\n for (size_t j = 0; j < max; ++j) {\n auto ll = lc_.vlt(j, len);\n auto same = lc_.eq(8, got[j].data(), want[j].data());\n lc_.assert_implies(&ll, same);\n }\n }\n\n void assert_path(size_t len, PathEntry p[], const Witness& vw,\n std::vector& dsC,\n std::vector& psC) const {\n vind start = vw.prepad_;\n for (size_t i = 0; i < len; ++i) {\n cbor_.assert_map_entry(kMdoc1MaxMsoLen, start, i, p[i].ind.k, p[i].ind.v,\n p[i].ind.ndx, dsC.data(), psC.data());\n cbor_.assert_text_at(kMdoc1MaxMsoLen, p[i].ind.k, p[i].l, p[i].name,\n dsC.data());\n start = p[i].ind.v;\n }\n }\n\n Flatsha sha_;\n Routing r_;\n Cbor cbor_;\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_1F_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_revocation.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_REVOCATION_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_REVOCATION_H_\n\n#include \n\n#include \"circuits/compiler/compiler.h\"\n#include \"circuits/ecdsa/verify_circuit.h\"\n#include \"circuits/logic/bit_plucker.h\"\n#include \"circuits/mdoc/mdoc_revocation_constants.h\"\n#include \"circuits/sha/flatsha256_circuit.h\"\n\nnamespace proofs {\n\n// The first revocation approach works for small lists that are expected to\n// be small. In this case, the prover simply asserts that their identifier is\n// different from all the identifiers in the list.\ntemplate \nclass MdocRevocationList {\n using EltW = typename LogicCircuit::EltW;\n\n public:\n explicit MdocRevocationList(const LogicCircuit& lc) : lc_(lc) {}\n\n // This function asserts that a given identifier is not on a revocation list.\n // The method is to assert that Prod_i (list[i) - id) != 0.\n void assert_not_on_list(EltW list[], size_t list_size,\n /* the witness */ EltW id, EltW prodinv) const {\n EltW prod =\n lc_.mul(0, list_size, [&](size_t i) { return lc_.sub(&list[i], id); });\n EltW want_one = lc_.mul(&prod, prodinv);\n lc_.assert_eq(&want_one, lc_.konst(lc_.one()));\n }\n\n const LogicCircuit& lc_;\n};\n\n// The second revocation approachs works for larger lists. In this case, the\n// prover retrieves a witness that their credential is *not* on the revoked\n// list by presenting a signature of the span (l,r) and proving that their\n// revocation identifier rev_id satisfied l < rev_id < r.\n// Specifically, the format of the span is:\n// epoch || l || r\n// where epoch is a 64 bit integer, l and r are 256 bit integers. All of\n// the values are encoded in little endian order.\ntemplate \nclass MdocRevocationSpan {\n using EltW = typename LogicCircuit::EltW;\n using Nat = typename Field::N;\n using Ecdsa = VerifyCircuit;\n using EcdsaWitness = typename Ecdsa::Witness;\n using v8 = typename LogicCircuit::v8;\n using v256 = typename LogicCircuit::v256;\n using Flatsha =\n FlatSHA256Circuit>;\n using ShaBlockWitness = typename Flatsha::BlockWitness;\n using sha_packed_v32 = typename Flatsha::packed_v32;\n\n public:\n class Witness {\n public:\n EltW r_, s_, e_;\n EcdsaWitness rev_sig_;\n v8 preimage_[64 * 2]; // epoch || l || r in little endian order\n v256 id_bits_;\n v256 e_bits_;\n ShaBlockWitness sha_[2];\n\n void input(QuadCircuit& Q, const LogicCircuit& lc) {\n r_ = Q.input();\n s_ = Q.input();\n e_ = Q.input();\n rev_sig_.input(Q);\n for (size_t i = 0; i < 64 * 2; ++i) {\n preimage_[i] = lc.template vinput<8>();\n }\n id_bits_ = lc.template vinput<256>();\n e_bits_ = lc.template vinput<256>();\n for (size_t j = 0; j < 2; j++) {\n sha_[j].input(Q);\n }\n }\n };\n\n explicit MdocRevocationSpan(const LogicCircuit& lc, const EC& ec,\n const Nat& order)\n : lc_(lc), ec_(ec), order_(order), sha_(lc) {}\n\n // This function asserts that id is not on the revocation list by verifying\n // that the signature (r,s) on the span (l,r) is valid, and then verifying\n // that l < id < r. The argument (craPkX, craPkY) represent the public key\n // of the issuer of the revocation list.\n void assert_not_on_list(EltW craPkx, EltW craPkY,\n /* the witness */ EltW id, Witness& vw) const {\n Ecdsa ecc(lc_, ec_, order_);\n\n ecc.verify_signature3(craPkx, craPkY, vw.e_, vw.rev_sig_);\n\n lc_.vassert_is_bit(vw.e_bits_);\n lc_.vassert_is_bit(vw.id_bits_);\n\n // Check that e = hash(epoch || l || r)\n auto two = lc_.template vbit<8>(2);\n sha_.assert_message_hash(2, two, vw.preimage_, vw.e_bits_, vw.sha_);\n\n // Check that the bits of e match the EltW for e.\n auto twok = lc_.one();\n auto est = lc_.konst(0);\n for (size_t i = 0; i < 256; ++i) {\n est = lc_.axpy(&est, twok, lc_.eval(vw.e_bits_[i]));\n lc_.f_.add(twok, twok);\n }\n lc_.assert_eq(&est, vw.e_);\n\n // // Check that l < id < r\n v256 ll, rr;\n for (size_t i = 0; i < 256; ++i) {\n ll[i] = vw.preimage_[8 + i / 8][i % 8];\n rr[i] = vw.preimage_[40 + i / 8][i % 8];\n }\n lc_.assert1(lc_.vlt(&ll, vw.id_bits_));\n lc_.assert1(lc_.vlt(&vw.id_bits_, rr));\n }\n\n const LogicCircuit& lc_;\n const EC& ec_;\n const Nat& order_;\n Flatsha sha_;\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_REVOCATION_H_\n"], ["/longfellow-zk/lib/circuits/ecdsa/verify_circuit.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ECDSA_VERIFY_CIRCUIT_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ECDSA_VERIFY_CIRCUIT_H_\n\n#include \n\n#include \"circuits/compiler/compiler.h\"\n#include \"circuits/logic/bit_plucker.h\"\n\nnamespace proofs {\n// Verify ECDSA signature using triple scalar mult form.\n//\n// The field used by sumcheck is the base field of the elliptic curve.\n// Compiled circuit: ecdsa verify\n// d: 7 wires: 21099 in: 1038 out:764 use:13911 ovh:7188 t:42963 cse:11351\n// notn:34724\n//\ntemplate \nclass VerifyCircuit {\n using EltW = typename LogicCircuit::EltW;\n using BitW = typename LogicCircuit::BitW;\n using Elt = typename LogicCircuit::Elt;\n using Nat = typename Field::N;\n static constexpr size_t kBits = EC::kBits;\n using Bitvec = typename LogicCircuit::v256;\n\n public:\n struct Witness {\n EltW rx, ry;\n EltW pre[8];\n EltW rx_inv, s_inv, pk_inv;\n EltW bi[kBits];\n EltW int_x[kBits - 1];\n EltW int_y[kBits - 1];\n EltW int_z[kBits - 1];\n\n void input(QuadCircuit& Q) {\n rx = Q.input();\n ry = Q.input();\n rx_inv = Q.input();\n s_inv = Q.input();\n pk_inv = Q.input();\n for (size_t i = 0; i < 8; ++i) {\n pre[i] = Q.input();\n }\n for (size_t i = 0; i < kBits; ++i) {\n bi[i] = Q.input();\n if (i < kBits - 1) {\n int_x[i] = Q.input();\n int_y[i] = Q.input();\n int_z[i] = Q.input();\n }\n }\n }\n };\n\n VerifyCircuit(const LogicCircuit& lc, const EC& ec, const Nat& order)\n : lc_(lc), ec_(ec), k2_(lc_.elt(2)), k3_(lc_.elt(3)) {\n // Compute the bit representation of the order of the curve.\n for (size_t i = 0; i < ec.kBits; ++i) {\n bits_n_[i] = lc_.bit(order.bit(i));\n }\n }\n\n // This verify takes the triple (pkx,pky,e) and checks that there exists\n // (r=rx, ry, s) such that:\n // identity = g*e + pk*r + (rx,ry)*-s\n // It performs this check using a witness table that includes\n // (g+pk, g+r, r+pk, g+r+pk), a correction element,\n // bits of exponents (e, r, -s) s.t. each triple of bits is packed into {0,7},\n // and intermediate ec points in (x,y,z) form. The bits are used to index the\n // witness table in order to compute the right-hand side in a loop. The loop\n // is sliced by providing the intermediate results in order reduce depth.\n //\n // An external constraint will need to ensure that e \\neq 0 (e.g.,\n // either the verifier checks this as part of the public input, or\n // the hash that defines e is produced in the circuit). In our mdoc case,\n // we use the later checks for both signatures.\n //\n // Other checks:\n // r is interpreted as both in the base field and the scalar field.\n // As a result, rx_inv is provided to ensure that r != 0.\n // Similarly, s_inv is provided to ensure that s != 0.\n //\n // (rx,ry) is verified to be on the curve.\n //\n // (pkx, pky) \\neq identity, because we set pk_z=1, we verify that\n // pkx != 0, and we ensure that (pkx,pky) is on the curve.\n //\n void verify_signature3(EltW pk_x, EltW pk_y, EltW e, const Witness& w) const {\n EltW zero = lc_.konst(lc_.zero());\n EltW one = lc_.konst(lc_.one());\n EltW gx = lc_.konst(ec_.gx_), gy = lc_.konst(ec_.gy_);\n\n // indices for the pre[] table, don't change order\n enum PreIndex {\n GPK_X = 0,\n GPK_Y,\n GR_X,\n GR_Y,\n RPK_X,\n RPK_Y,\n GRPK_X,\n GRPK_Y\n };\n\n // These variables hold the (e,r) exponents which are computed from the\n // bits of advice (e,r,-s). They are compared with their expected values.\n EltW est = zero, rst = zero, sst = zero;\n\n // initialize at the 0 point, but these indices are reset on each loop\n EltW ax = zero, ay = one, az = zero;\n\n // =========\n // Verify the values received in the table are correct.\n // By verifying these values in parallel with using them, we can reduce\n // the depth of the resulting circuit.\n EltW cg_pkx, cg_pky, cg_pkz;\n EltW cr_pkx, cr_pky, cr_pkz;\n EltW cr_gx, cr_gy, cr_gz;\n EltW cr_g_pkx, cr_g_pky, cr_g_pkz;\n addE(cg_pkx, cg_pky, cg_pkz, gx, gy, one, pk_x, pk_y, one);\n addE(cr_gx, cr_gy, cr_gz, w.rx, w.ry, one, gx, gy, one);\n addE(cr_pkx, cr_pky, cr_pkz, w.rx, w.ry, one, pk_x, pk_y, one);\n addE(cr_g_pkx, cr_g_pky, cr_g_pkz, gx, gy, one, w.pre[RPK_X], w.pre[RPK_Y],\n one);\n point_equality(cg_pkx, cg_pky, cg_pkz, w.pre[GPK_X], w.pre[GPK_Y]);\n point_equality(cr_gx, cr_gy, cr_gz, w.pre[GR_X], w.pre[GR_Y]);\n point_equality(cr_pkx, cr_pky, cr_pkz, w.pre[RPK_X], w.pre[RPK_Y]);\n point_equality(cr_g_pkx, cr_g_pky, cr_g_pkz, w.pre[GRPK_X], w.pre[GRPK_Y]);\n\n EltW arr_x[] = {zero, gx, pk_x, w.pre[GPK_X],\n w.rx, w.pre[GR_X], w.pre[RPK_X], w.pre[GRPK_X]};\n EltW arr_y[] = {one, gy, pk_y, w.pre[GPK_Y],\n w.ry, w.pre[GR_Y], w.pre[RPK_Y], w.pre[GRPK_Y]};\n EltW arr_z[] = {zero, one, one, one, one, one, one, one};\n EltW arr_e[] = {zero, one, zero, one, zero, one, zero, one};\n EltW arr_r[] = {zero, zero, one, one, zero, zero, one, one};\n EltW arr_s[] = {zero, zero, zero, zero, one, one, one, one};\n EltW arr_v[] = {one, one, one, one, one, one, one, one};\n\n EltMuxer xx(lc_, arr_x);\n EltMuxer yy(lc_, arr_y);\n EltMuxer zz(lc_, arr_z);\n EltMuxer ee(lc_, arr_e);\n EltMuxer rr(lc_, arr_r);\n EltMuxer ss(lc_, arr_s);\n EltMuxer vv(lc_, arr_v);\n\n Bitvec r_bits, s_bits;\n\n // Traverses the bits of the scalar from high-order to low-order.\n for (size_t i = 0; i < kBits; ++i) {\n // Use the arr{X..V} arrays and the muxer to pick the correct point\n // slice based on the bits of advice in the witness.\n EltW tx = xx.mux(w.bi[i]);\n EltW ty = yy.mux(w.bi[i]);\n EltW tz = zz.mux(w.bi[i]);\n\n // Update the exponent.\n EltW e_bi = ee.mux(w.bi[i]);\n EltW r_bi = rr.mux(w.bi[i]);\n EltW s_bi = ss.mux(w.bi[i]);\n auto k2 = lc_.konst(k2_);\n est = lc_.add(&e_bi, lc_.mul(&k2, est));\n rst = lc_.add(&r_bi, lc_.mul(&k2, rst));\n sst = lc_.add(&s_bi, lc_.mul(&k2, sst));\n r_bits[kBits - i - 1] = BitW(r_bi, ec_.f_);\n s_bits[kBits - i - 1] = BitW(s_bi, ec_.f_);\n\n // Verify that the advice bit is in [0,7].\n EltW range = vv.mux(w.bi[i]);\n lc_.assert_eq(&range, one);\n\n // Perform the basic add-dbl step in repeated squaring using the\n // muxed point {tx, ty, tz}.\n if (i > 0) {\n doubleE(ax, ay, az, ax, ay, az);\n }\n addE(ax, ay, az, ax, ay, az, tx, ty, tz);\n\n if (i < kBits - 1) {\n // Ensure that the resulting point is equal to the intermediate\n // point provided as input. Performing an explicit equality check\n // ensures that all intermediate witness points are on the curve.\n // This follows by induction. The first (ax,ay,az) is on the curve.\n // The addition formula ensures that the i-th (ax,ay,az) is on the\n // curve; equality ensures that the i-th witness is on the curve.\n lc_.assert_eq(&ax, w.int_x[i]);\n lc_.assert_eq(&ay, w.int_y[i]);\n lc_.assert_eq(&az, w.int_z[i]);\n\n // Use the intermediate (x,y,z) point as the next input.\n ax = w.int_x[i];\n ay = w.int_y[i];\n az = w.int_z[i];\n }\n }\n\n // Check that the aX,aZ points are 0.\n lc_.assert0(ax);\n lc_.assert0(az);\n\n // Check that the bits used for {e,rx} correspond to the input {e, rx}.\n lc_.assert_eq(&est, e);\n lc_.assert_eq(&rst, w.rx);\n\n // Check that (pk,py), (rx,ry) satisfy the curve equation.\n is_on_curve(pk_x, pk_y);\n is_on_curve(w.rx, w.ry);\n\n // Verify that exponents (r,s) are not zero.\n // A witness is provided to ensure that both values have inverses in F.\n // A bitwise comparison is done to ensure both are < |order| of EC.\n assert_nonzero(w.rx, w.rx_inv);\n assert_nonzero(sst, w.s_inv);\n assert_nonzero(pk_x, w.pk_inv);\n auto r_range = lc_.vlt(&r_bits, bits_n_);\n auto s_range = lc_.vlt(&s_bits, bits_n_);\n lc_.assert1(r_range);\n lc_.assert1(s_range);\n }\n\n private:\n void assert_nonzero(EltW x, EltW witness) const {\n auto maybe_one = lc_.mul(&x, witness);\n auto one = lc_.konst(lc_.one());\n lc_.assert_eq(&maybe_one, one);\n }\n\n void point_equality(EltW x, EltW y, EltW z, EltW p_x, EltW p_y) const {\n lc_.assert_eq(&x, lc_.mul(&z, p_x));\n lc_.assert_eq(&y, lc_.mul(&z, p_y));\n }\n\n void is_on_curve(EltW x, EltW y) const {\n // Check that y^2 = x^3 + ax + b\n auto yy = lc_.mul(&y, y);\n auto xx = lc_.mul(&x, x);\n auto xxx = lc_.mul(&x, xx);\n auto ax = lc_.mul(ec_.a_, x);\n auto b = lc_.konst(ec_.b_);\n auto axb = lc_.add(&ax, b);\n auto rhs = lc_.add(&axb, xxx);\n lc_.assert_eq(&yy, rhs);\n }\n\n void addE(EltW& X3, EltW& Y3, EltW& Z3, EltW X1, EltW Y1, EltW Z1, EltW X2,\n EltW Y2, EltW Z2) const {\n // The general case.\n // Algorithm 1: Complete, projective point addition for arbitrary prime\n // order short Weierstrass curves E/Fq : y^2 = x^3 + ax + b\n // The compiler seems to optimize the cases when Z1,Z2=1.\n EltW t0 = lc_.mul(&X1, X2);\n EltW t1 = lc_.mul(&Y1, Y2);\n EltW t2 = lc_.mul(&Z1, Z2);\n EltW t3 = lc_.add(&X1, Y1);\n EltW t4 = lc_.add(&X2, Y2);\n t3 = lc_.mul(&t3, t4);\n t4 = lc_.add(&t0, t1);\n t3 = lc_.sub(&t3, t4);\n t4 = lc_.add(&X1, Z1);\n EltW t5 = lc_.add(&X2, Z2);\n t4 = lc_.mul(&t4, t5);\n t5 = lc_.add(&t0, t2);\n t4 = lc_.sub(&t4, t5);\n t5 = lc_.add(&Y1, Z1);\n EltW X3t = lc_.add(&Y2, Z2);\n t5 = lc_.mul(&t5, X3t);\n X3t = lc_.add(&t1, t2);\n t5 = lc_.sub(&t5, X3t);\n auto a = lc_.konst(ec_.a_);\n EltW Z3t = lc_.mul(&a, t4);\n auto k3b = lc_.konst(ec_.k3b);\n X3t = lc_.mul(&k3b, t2);\n Z3t = lc_.add(&X3t, Z3t);\n X3t = lc_.sub(&t1, Z3t);\n Z3t = lc_.add(&t1, Z3t);\n EltW Y3t = lc_.mul(&X3t, Z3t);\n t1 = lc_.add(&t0, t0);\n t1 = lc_.add(&t1, t0);\n t2 = lc_.mul(&a, t2);\n t4 = lc_.mul(&k3b, t4);\n t1 = lc_.add(&t1, t2);\n t2 = lc_.sub(&t0, t2);\n t2 = lc_.mul(&a, t2);\n t4 = lc_.add(&t4, t2);\n t0 = lc_.mul(&t1, t4);\n Y3t = lc_.add(&Y3t, t0);\n t0 = lc_.mul(&t5, t4);\n X3t = lc_.mul(&t3, X3t);\n X3t = lc_.sub(&X3t, t0);\n t0 = lc_.mul(&t3, t1);\n Z3t = lc_.mul(&t5, Z3t);\n Z3t = lc_.add(&Z3t, t0);\n\n X3 = X3t;\n Y3 = Y3t;\n Z3 = Z3t;\n }\n\n void doubleE(EltW& X3, EltW& Y3, EltW& Z3, EltW X, EltW Y, EltW Z) const {\n // The general case.\n // Algorithm 3: Exception-free point doubling for arbitrary prime order\n // short Weierstrass curves E/Fq : y^2 = x^3 + ax + b.\n // The compiler will presumably optimize away 0 mults when a=0 and 1\n // mults when Z = 1.\n EltW t0 = lc_.mul(&X, X);\n EltW t1 = lc_.mul(&Y, Y);\n EltW t2 = lc_.mul(&Z, Z);\n EltW t3 = lc_.mul(&X, Y);\n t3 = lc_.add(&t3, t3);\n EltW Z3t = lc_.mul(&X, Z);\n Z3t = lc_.add(&Z3t, Z3t);\n auto a = lc_.konst(ec_.a_);\n auto k3b = lc_.konst(ec_.k3b);\n EltW X3t = lc_.mul(&a, Z3t);\n EltW Y3t = lc_.mul(&k3b, t2);\n Y3t = lc_.add(&X3t, Y3t);\n X3t = lc_.sub(&t1, Y3t);\n Y3t = lc_.add(&t1, Y3t);\n Y3t = lc_.mul(&X3t, Y3t);\n X3t = lc_.mul(&t3, X3t);\n Z3t = lc_.mul(&k3b, Z3t);\n t2 = lc_.mul(&a, t2);\n t3 = lc_.sub(&t0, t2);\n t3 = lc_.mul(&a, t3);\n t3 = lc_.add(&t3, Z3t);\n Z3t = lc_.add(&t0, t0);\n t0 = lc_.add(&Z3t, t0);\n t0 = lc_.add(&t0, t2);\n t0 = lc_.mul(&t0, t3);\n Y3t = lc_.add(&Y3t, t0);\n t2 = lc_.mul(&Y, Z);\n t2 = lc_.add(&t2, t2);\n t0 = lc_.mul(&t2, t3);\n X3t = lc_.sub(&X3t, t0);\n Z3t = lc_.mul(&t2, t1);\n Z3t = lc_.add(&Z3t, Z3t);\n Z3t = lc_.add(&Z3t, Z3t);\n\n X3 = X3t;\n Y3 = Y3t;\n Z3 = Z3t;\n }\n\n const LogicCircuit& lc_;\n const EC& ec_;\n\n Elt k2_, k3_;\n Bitvec bits_n_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ECDSA_VERIFY_CIRCUIT_H_\n"], ["/longfellow-zk/lib/circuits/anoncred/ptrcred.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_PTRCRED_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_PTRCRED_H_\n#include \n#include \n\n#include \"circuits/anoncred/small_io.h\"\n#include \"circuits/compiler/compiler.h\"\n#include \"circuits/ecdsa/verify_circuit.h\"\n#include \"circuits/logic/bit_plucker.h\"\n#include \"circuits/logic/memcmp.h\"\n#include \"circuits/logic/routing.h\"\n#include \"circuits/sha/flatsha256_circuit.h\"\n\nnamespace proofs {\n\n// This class creates a circuit to verify the signatures in a \"ptrcred\".\n// A ptr credential is a document formatted as:\n// n // 8 bits specifying the number of attributes\n// ind
\n// each pointer references from the beginning of the document\n// A byte string containing keys and values.\n// A key consists of 3 bytes.\n// A value can be arbitrarily long.\ntemplate \nclass PtrCred {\n using EltW = typename LogicCircuit::EltW;\n using Elt = typename LogicCircuit::Elt;\n using Nat = typename Field::N;\n using Ecdsa = VerifyCircuit;\n using EcdsaWitness = typename Ecdsa::Witness;\n\n using v8 = typename LogicCircuit::v8;\n using v32 = typename LogicCircuit::v32;\n static constexpr size_t kIndexBits = 5;\n static constexpr size_t kMaxSHABlocks = 3;\n static constexpr size_t kMaxMsoLen = kMaxSHABlocks * 64 - 9;\n\n using vind = typename LogicCircuit::template bitvec;\n using Flatsha = FlatSHA256Circuit>;\n using RoutingL = Routing;\n using ShaBlockWitness = typename Flatsha::BlockWitness;\n\n const LogicCircuit& lc_;\n const EC& ec_;\n const Nat& order_;\n\n public:\n class Witness {\n public:\n EltW e_;\n EltW dpkx_, dpky_;\n\n EcdsaWitness sig_;\n EcdsaWitness dpk_sig_;\n\n v8 in_[64 * kMaxSHABlocks]; /* input bytes, 64 * MAX */\n v8 nb_; /* index of sha block that contains the real hash */\n ShaBlockWitness sig_sha_[kMaxSHABlocks];\n\n void input(QuadCircuit& Q, const LogicCircuit& lc) {\n e_ = Q.input();\n dpkx_ = Q.input();\n dpky_ = Q.input();\n\n sig_.input(Q);\n dpk_sig_.input(Q);\n\n nb_ = lc.template vinput<8>();\n\n // sha input init =========================\n for (size_t i = 0; i < 64 * kMaxSHABlocks; ++i) {\n in_[i] = lc.template vinput<8>();\n }\n for (size_t j = 0; j < kMaxSHABlocks; j++) {\n sig_sha_[j].input(Q);\n }\n }\n };\n\n struct OpenedAttribute {\n v8 ind; /* index of attribute */\n v8 len; /* length of attribute, 1--32 */\n v8 v1[32]; /* attribute value */\n void input(const LogicCircuit& lc) {\n ind = lc.template vinput<8>();\n len = lc.template vinput<8>();\n for (size_t j = 0; j < 32; ++j) {\n v1[j] = lc.template vinput<8>();\n }\n }\n };\n\n EltW repack(const v8 in[], size_t ind) const {\n EltW h = lc_.konst(0);\n EltW base = lc_.konst(0x2);\n for (size_t i = 0; i < 32; ++i) {\n for (size_t j = 0; j < 8; ++j) {\n auto t = lc_.mul(&h, base);\n auto tin = lc_.eval(in[ind + i][7 - j]);\n h = lc_.add(&tin, t);\n }\n }\n return h;\n }\n\n explicit PtrCred(const LogicCircuit& lc, const EC& ec, const Nat& order)\n : lc_(lc), ec_(ec), order_(order), sha_(lc), r_(lc) {}\n\n void assert_credential(EltW pkX, EltW pkY, EltW hash_tr,\n OpenedAttribute oa[/* NUM_ATTR */],\n const v8 now[/*kDateLen*/], const Witness& vw) const {\n Ecdsa ecc(lc_, ec_, order_);\n\n ecc.verify_signature3(pkX, pkY, vw.e_, vw.sig_);\n ecc.verify_signature3(vw.dpkx_, vw.dpky_, hash_tr, vw.dpk_sig_);\n sha_.assert_message(kMaxSHABlocks, vw.nb_, vw.in_, vw.sig_sha_);\n\n const Memcmp CMP(lc_);\n // validFrom <= now\n lc_.assert1(CMP.leq(kDateLen, &vw.in_[84], &now[0]));\n\n // now <= validUntil\n lc_.assert1(CMP.leq(kDateLen, &now[0], &vw.in_[92]));\n\n // DPK_{x,y}\n EltW dpkx = repack(vw.in_, 100);\n EltW dpky = repack(vw.in_, 132);\n lc_.assert_eq(&dpkx, vw.dpkx_);\n lc_.assert_eq(&dpky, vw.dpky_);\n\n // Attributes parsing\n const v8 zz = lc_.template vbit<8>(0xff); // cannot appear in strings\n std::vector cmp_buf(32);\n for (size_t ai = 0; ai < kNumAttr; ++ai) {\n r_.shift(oa[ai].ind, 32, &cmp_buf[0], kMaxMsoLen, vw.in_, zz, 3);\n assert_attribute(32, oa[ai].len, &cmp_buf[0], &oa[ai].v1[0]);\n }\n }\n\n private:\n // Checks that an attribute id or attribute value is as expected.\n // The len parameter holds the byte length of the expected id or value.\n void assert_attribute(size_t max, const v8& vlen, const v8 got[/*max*/],\n const v8 want[/*max*/]) const {\n for (size_t j = 0; j < max; ++j) {\n auto ll = lc_.vlt(j, vlen);\n auto cmp = lc_.veq(got[j], want[j]);\n lc_.assert_implies(&ll, cmp);\n }\n }\n\n Flatsha sha_;\n RoutingL r_;\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_PTRCRED_H_\n"], ["/longfellow-zk/lib/circuits/sha/flatsha256_circuit.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_FLATSHA256_CIRCUIT_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_FLATSHA256_CIRCUIT_H_\n\n#include \n\n#include \n#include \n\n#include \"circuits/compiler/compiler.h\"\n#include \"circuits/logic/bit_adder.h\"\n#include \"circuits/sha/sha256_constants.h\"\n\nnamespace proofs {\n// FlatSHA256Circuit\n//\n// Implements SHA256 hash function as an arithmetic circuit over the field F.\n// The circuit is flattened, meaning that the SHA round function has been\n// repeated in parallel instead of sequentially. As a result, the prover must\n// provide the intermediate round values as witnesses.\n//\n// This package does not have any external dependencies on a SHA256 library.\n//\n// There are two versions of this function, one with standard bit inputs, and\n// another with packed bit inputs. The later reduces the number of inputs at\n// the cost of increasing the depth and number of wires. For example, the\n// following shows the difference with pack parameter 2.\n//\n// FlatSHA256_Circuit.assert_transform_block\n// depth: 7 wires: 38029 in: 6657 out:128 use:30897 ovh:7132 t:166468 cse:9703\n// notn:113744\n//\n// FlatSHA256_Circuit.assert_transform_block_packed\n// depth: 9 wires: 65735 in: 3585 out:128 use:55486 ovh:10249 t:214653\n// cse:28135 notn:151504\n//\n//\ntemplate \nclass FlatSHA256Circuit {\n public:\n using v8 = typename Logic::v8;\n using v256 = typename Logic::v256;\n using v32 = typename Logic::v32;\n using EltW = typename Logic::EltW;\n using Field = typename Logic::Field;\n using packed_v32 = typename BitPlucker::packed_v32;\n\n const Logic& l_;\n BitPlucker bp_; /* public, so caller can encode input */\n\n struct BlockWitness {\n packed_v32 outw[48];\n packed_v32 oute[64];\n packed_v32 outa[64];\n packed_v32 h1[8];\n\n static packed_v32 packed_input(QuadCircuit& Q) {\n packed_v32 r;\n for (size_t i = 0; i < r.size(); ++i) {\n r[i] = Q.input();\n }\n return r;\n }\n\n void input(QuadCircuit& Q) {\n for (size_t k = 0; k < 48; ++k) {\n outw[k] = packed_input(Q);\n }\n for (size_t k = 0; k < 64; ++k) {\n oute[k] = packed_input(Q);\n outa[k] = packed_input(Q);\n }\n for (size_t k = 0; k < 8; ++k) {\n h1[k] = packed_input(Q);\n }\n }\n };\n\n explicit FlatSHA256Circuit(const Logic& l) : l_(l), bp_(l_) {}\n\n static packed_v32 packed_input(QuadCircuit& Q) {\n packed_v32 r;\n for (size_t i = 0; i < r.size(); ++i) {\n r[i] = Q.input();\n }\n return r;\n }\n\n void assert_transform_block(const v32 in[16], const v32 H0[8],\n const v32 outw[48], const v32 oute[64],\n const v32 outa[64], const v32 H1[8]) const {\n const Logic& L = l_; // shorthand\n BitAdder BA(L);\n\n std::vector w(64);\n for (size_t i = 0; i < 16; ++i) {\n w[i] = in[i];\n }\n\n for (size_t i = 16; i < 64; ++i) {\n auto sw2 = sigma1(w[i - 2]);\n auto sw15 = sigma0(w[i - 15]);\n std::vector terms = {sw2, w[i - 7], sw15, w[i - 16]};\n w[i] = outw[i - 16];\n BA.assert_eqmod(w[i], BA.add(terms), 4);\n }\n\n v32 a = H0[0];\n v32 b = H0[1];\n v32 c = H0[2];\n v32 d = H0[3];\n v32 e = H0[4];\n v32 f = H0[5];\n v32 g = H0[6];\n v32 h = H0[7];\n\n for (size_t t = 0; t < 64; ++t) {\n auto s1e = Sigma1(e);\n auto ch = L.vCh(&e, &f, g);\n auto rt = L.vbit32(kSha256Round[t]);\n std::vector t1_terms = {h, s1e, ch, rt, w[t]};\n EltW t1 = BA.add(t1_terms);\n EltW sigma0 = BA.as_field_element(Sigma0(a));\n EltW vmaj = BA.as_field_element(L.vMaj(&a, &b, c));\n EltW t2 = BA.add(&sigma0, vmaj);\n\n h = g;\n g = f;\n f = e;\n e = oute[t];\n EltW ed = BA.as_field_element(d);\n BA.assert_eqmod(e, BA.add(&t1, ed), 6);\n d = c;\n c = b;\n b = a;\n a = outa[t];\n BA.assert_eqmod(a, BA.add(&t1, t2), 7);\n }\n\n BA.assert_eqmod(H1[0], BA.add(H0[0], a), 2);\n BA.assert_eqmod(H1[1], BA.add(H0[1], b), 2);\n BA.assert_eqmod(H1[2], BA.add(H0[2], c), 2);\n BA.assert_eqmod(H1[3], BA.add(H0[3], d), 2);\n BA.assert_eqmod(H1[4], BA.add(H0[4], e), 2);\n BA.assert_eqmod(H1[5], BA.add(H0[5], f), 2);\n BA.assert_eqmod(H1[6], BA.add(H0[6], g), 2);\n BA.assert_eqmod(H1[7], BA.add(H0[7], h), 2);\n }\n\n // Packed API.\n // H0 not packed, all others packed\n void assert_transform_block(const v32 in[16], const v32 H0[8],\n const packed_v32 poutw[48],\n const packed_v32 poute[64],\n const packed_v32 pouta[64],\n const packed_v32 pH1[8]) const {\n std::vector H1(8);\n std::vector outw(48);\n std::vector oute(64), outa(64);\n for (size_t i = 0; i < 8; ++i) {\n H1[i] = bp_.unpack_v32(pH1[i]);\n }\n for (size_t i = 0; i < 48; ++i) {\n outw[i] = bp_.unpack_v32(poutw[i]);\n }\n for (size_t i = 0; i < 64; ++i) {\n oute[i] = bp_.unpack_v32(poute[i]);\n outa[i] = bp_.unpack_v32(pouta[i]);\n }\n assert_transform_block(in, H0, outw.data(), oute.data(), outa.data(),\n H1.data());\n }\n\n // all packed\n void assert_transform_block(const v32 in[16], const packed_v32 pH0[8],\n const packed_v32 poutw[48],\n const packed_v32 poute[64],\n const packed_v32 pouta[64],\n const packed_v32 pH1[8]) const {\n std::vector H0(8);\n for (size_t i = 0; i < 8; ++i) {\n H0[i] = bp_.unpack_v32(pH0[i]);\n }\n assert_transform_block(in, H0.data(), poutw, poute, pouta, pH1);\n }\n\n /* This method checks that the block witness corresponds to the iterated\n computation of the sha block transform on the input.\n */\n void assert_message(size_t max, const v8& nb, const v8 in[/* 64*max */],\n const BlockWitness bw[/*max*/]) const {\n const Logic& L = l_; // shorthand\n const packed_v32* H = nullptr;\n std::vector tmp(16);\n\n for (size_t b = 0; b < max; ++b) {\n const v8* inb = &in[64 * b];\n for (size_t i = 0; i < 16; ++i) {\n // big-endian mapping of v8[4] into v32. The first\n // argument of vappend() is the LSB, and thus +3 is\n // the LSB and +0 is the MSB, hence big-endian.\n tmp[i] = L.vappend(L.vappend(inb[4 * i + 3], inb[4 * i + 2]),\n L.vappend(inb[4 * i + 1], inb[4 * i + 0]));\n }\n if (b == 0) {\n v32 H0[8];\n initial_context(H0);\n assert_transform_block(tmp.data(), H0, bw[b].outw, bw[b].oute,\n bw[b].outa, bw[b].h1);\n } else {\n assert_transform_block(tmp.data(), H, bw[b].outw, bw[b].oute,\n bw[b].outa, bw[b].h1);\n }\n H = bw[b].h1;\n }\n }\n\n /* This method checks that the block witness corresponds to the iterated\n computation of the sha block transform on the prefix || input.\n */\n void assert_message_with_prefix(size_t max, const v8& nb,\n const v8 in[/* < 64*max */],\n const uint8_t prefix[/* len */], size_t len,\n const BlockWitness bw[/*max*/]) const {\n const Logic& L = l_; // shorthand\n std::vector tmp(16);\n\n std::vector bbuf(64 * max);\n for (size_t i = 0; i < len; ++i) {\n L.bits(8, bbuf[i].data(), prefix[i]);\n }\n for (size_t i = 0; i + len < 64 * max; ++i) {\n bbuf[i + len] = in[i];\n }\n\n assert_message(max, nb, bbuf.data(), bw);\n }\n\n /* This method checks if H(in) == target. The method requires that in[]\n contains exactly nb*64 bytes and has been padded according to the SHA256\n specification.\n */\n void assert_message_hash(size_t max, const v8& nb, const v8 in[/* 64*max */],\n const v256& target,\n const BlockWitness bw[/*max*/]) const {\n assert_message(max, nb, in, bw);\n assert_hash(max, target, nb, bw);\n }\n\n // This method checks if H(prefix || in) == target.\n // Since the prefix is hardcoded, the compiler can propagate constants\n // and produce smaller circuits. As above, the method requires that in[]\n // contains exactly nb*64 bytes and has been padded according to the SHA256\n // specification. To use this method, compute the block_witness for the\n // entire message as usual.\n void assert_message_hash_with_prefix(size_t max, const v8& nb,\n const v8 in[/* 64*max */],\n const uint8_t prefix[/* len */],\n size_t len, const v256& target,\n const BlockWitness bw[/*max*/]) const {\n assert_message_with_prefix(max, nb, in, prefix, len, bw);\n assert_hash(max, target, nb, bw);\n }\n\n // Verifies that the nb_th element of the block witness is equal to e.\n // The block witness keeps track of the intermediate output of each\n // block transform. Therefore, this method can be used to verify that the\n // prover knows a preimage that hashes to the desired e.\n void assert_hash(size_t max, const v256& e, const v8& nb,\n const BlockWitness bw[/*max*/]) const {\n packed_v32 x[8];\n for (size_t b = 0; b < max; ++b) {\n auto bt = l_.veq(nb, b + 1); /* b is zero-indexed */\n auto ebt = l_.eval(bt);\n for (size_t i = 0; i < 8; ++i) {\n for (size_t k = 0; k < bp_.kNv32Elts; ++k) {\n if (b == 0) {\n x[i][k] = l_.mul(&ebt, bw[b].h1[i][k]);\n } else {\n auto maybe_sha = l_.mul(&ebt, bw[b].h1[i][k]);\n x[i][k] = l_.add(&x[i][k], maybe_sha);\n }\n }\n }\n }\n\n // Unpack the hash into a v256 in reverse byte-order.\n v256 mm;\n for (size_t j = 0; j < 8; ++j) {\n auto hj = bp_.unpack_v32(x[j]);\n for (size_t k = 0; k < 32; ++k) {\n mm[((7 - j) * 32 + k)] = hj[k];\n }\n }\n l_.vassert_eq(&mm, e);\n }\n\n private:\n void initial_context(v32 H[8]) const {\n static const uint64_t initial[8] = {0x6a09e667u, 0xbb67ae85u, 0x3c6ef372u,\n 0xa54ff53au, 0x510e527fu, 0x9b05688cu,\n 0x1f83d9abu, 0x5be0cd19u};\n for (size_t i = 0; i < 8; i++) {\n H[i] = l_.template vbit<32>(initial[i]);\n }\n }\n\n v32 Sigma0(const v32& x) const {\n auto x2 = l_.vrotr(x, 2);\n auto x13 = l_.vrotr(x, 13);\n return l_.vxor3(&x2, &x13, l_.vrotr(x, 22));\n }\n\n v32 Sigma1(const v32& x) const {\n auto x6 = l_.vrotr(x, 6);\n auto x11 = l_.vrotr(x, 11);\n return l_.vxor3(&x6, &x11, l_.vrotr(x, 25));\n }\n\n v32 sigma0(const v32& x) const {\n auto x7 = l_.vrotr(x, 7);\n auto x18 = l_.vrotr(x, 18);\n return l_.vxor3(&x7, &x18, l_.vshr(x, 3));\n }\n\n v32 sigma1(const v32& x) const {\n auto x17 = l_.vrotr(x, 17);\n auto x19 = l_.vrotr(x, 19);\n return l_.vxor3(&x17, &x19, l_.vshr(x, 10));\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_FLATSHA256_CIRCUIT_H_\n"], ["/longfellow-zk/lib/circuits/anoncred/small.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_H_\n\n#include \n#include \n\n#include \"circuits/anoncred/small_io.h\"\n#include \"circuits/compiler/compiler.h\"\n#include \"circuits/ecdsa/verify_circuit.h\"\n#include \"circuits/logic/bit_plucker.h\"\n#include \"circuits/logic/memcmp.h\"\n#include \"circuits/logic/routing.h\"\n#include \"circuits/sha/flatsha256_circuit.h\"\n\nnamespace proofs {\n\n// This class creates a circuit to verify the signatures in a \"small\" MDOC.\n// A small credential is a 183-byte document formatted as:\n// first_name 32 0\n// family_name 32 32\n// date_of_birth YYYYMMDD 64\n// gender B 72\n// age_over_X. BBBBBBB 73 [16, 18, 21, 25, 62, 65, 67]\n// issuerid BBBB 80\n// validfrom YYYYMMDD 84\n// validuntil YYYYMMDD 92\n// DPKX 32x 100\n// DPKY 32x 132\n// \ntemplate \nclass Small {\n using EltW = typename LogicCircuit::EltW;\n using Elt = typename LogicCircuit::Elt;\n using Nat = typename Field::N;\n using Ecdsa = VerifyCircuit;\n using EcdsaWitness = typename Ecdsa::Witness;\n\n using v8 = typename LogicCircuit::v8;\n using v32 = typename LogicCircuit::v32;\n static constexpr size_t kIndexBits = 5;\n static constexpr size_t kMaxSHABlocks = 7;\n static constexpr size_t kMaxMsoLen = kMaxSHABlocks * 64 - 9;\n\n using vind = typename LogicCircuit::template bitvec;\n using Flatsha = FlatSHA256Circuit>;\n using RoutingL = Routing;\n using ShaBlockWitness = typename Flatsha::BlockWitness;\n\n const LogicCircuit& lc_;\n const EC& ec_;\n const Nat& order_;\n\n public:\n class Witness {\n public:\n EltW e_;\n EltW dpkx_, dpky_;\n\n EcdsaWitness sig_;\n EcdsaWitness dpk_sig_;\n\n v8 in_[64 * kMaxSHABlocks]; /* input bytes, 64 * MAX */\n v8 nb_; /* index of sha block that contains the real hash */\n ShaBlockWitness sig_sha_[kMaxSHABlocks];\n\n void input(QuadCircuit& Q, const LogicCircuit& lc) {\n e_ = Q.input();\n dpkx_ = Q.input();\n dpky_ = Q.input();\n\n sig_.input(Q);\n dpk_sig_.input(Q);\n\n nb_ = lc.template vinput<8>();\n\n // sha input init =========================\n for (size_t i = 0; i < 64 * kMaxSHABlocks; ++i) {\n in_[i] = lc.template vinput<8>();\n }\n for (size_t j = 0; j < kMaxSHABlocks; j++) {\n sig_sha_[j].input(Q);\n }\n }\n };\n\n struct OpenedAttribute {\n v8 ind; /* index of attribute */\n v8 len; /* length of attribute, 1--32 */\n v8 v1[32]; /* attribute value */\n void input(const LogicCircuit& lc) {\n ind = lc.template vinput<8>();\n len = lc.template vinput<8>();\n for (size_t j = 0; j < 32; ++j) {\n v1[j] = lc.template vinput<8>();\n }\n }\n };\n\n EltW repack(const v8 in[], size_t ind) const {\n EltW h = lc_.konst(0);\n EltW base = lc_.konst(0x2);\n for (size_t i = 0; i < 32; ++i) {\n for (size_t j = 0; j < 8; ++j) {\n auto t = lc_.mul(&h, base);\n auto tin = lc_.eval(in[ind + i][7 - j]);\n h = lc_.add(&tin, t);\n }\n }\n return h;\n }\n\n explicit Small(const LogicCircuit& lc, const EC& ec, const Nat& order)\n : lc_(lc), ec_(ec), order_(order), sha_(lc), r_(lc) {}\n\n void assert_credential(EltW pkX, EltW pkY, EltW hash_tr,\n OpenedAttribute oa[/* NUM_ATTR */],\n const v8 now[/*kDateLen*/], const Witness& vw) const {\n Ecdsa ecc(lc_, ec_, order_);\n\n ecc.verify_signature3(pkX, pkY, vw.e_, vw.sig_);\n ecc.verify_signature3(vw.dpkx_, vw.dpky_, hash_tr, vw.dpk_sig_);\n\n sha_.assert_message(kMaxSHABlocks, vw.nb_, vw.in_, vw.sig_sha_);\n\n const Memcmp CMP(lc_);\n // // validFrom <= now\n lc_.assert1(CMP.leq(kDateLen, &vw.in_[84], &now[0]));\n\n // // now <= validUntil\n lc_.assert1(CMP.leq(kDateLen, &now[0], &vw.in_[92]));\n\n // // DPK_{x,y}\n EltW dpkx = repack(vw.in_, 100);\n EltW dpky = repack(vw.in_, 132);\n lc_.assert_eq(&dpkx, vw.dpkx_);\n lc_.assert_eq(&dpky, vw.dpky_);\n\n // Attributes parsing\n const v8 zz = lc_.template vbit<8>(0xff); // cannot appear in strings\n std::vector cmp_buf(32);\n for (size_t ai = 0; ai < kNumAttr; ++ai) {\n r_.shift(oa[ai].ind, 32, &cmp_buf[0], kMaxMsoLen, vw.in_, zz, 3);\n assert_attribute(32, oa[ai].len, &cmp_buf[0], &oa[ai].v1[0]);\n }\n }\n\n private:\n // Checks that an attribute id or attribute value is as expected.\n // The len parameter holds the byte length of the expected id or value.\n void assert_attribute(size_t max, const v8& vlen, const v8 got[/*max*/],\n const v8 want[/*max*/]) const {\n for (size_t j = 0; j < max; ++j) {\n auto ll = lc_.vlt(j, vlen);\n auto cmp = lc_.veq(got[j], want[j]);\n lc_.assert_implies(&ll, cmp);\n }\n }\n\n Flatsha sha_;\n RoutingL r_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_hash.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_HASH_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_HASH_H_\n\n#include \n#include \n#include \n\n#include \"circuits/compiler/compiler.h\"\n#include \"circuits/logic/bit_plucker.h\"\n#include \"circuits/logic/memcmp.h\"\n#include \"circuits/logic/routing.h\"\n#include \"circuits/mdoc/mdoc_constants.h\"\n#include \"circuits/sha/flatsha256_circuit.h\"\n\nnamespace proofs {\n\nstatic constexpr size_t kSHAPluckerBits = 4u;\n\n// This class (only) verifies the hashing and pseudo-parsing of an mdoc.\n// Specifically, it checks\n// (a) the hash of the mdoc matches its mac.\n// (b) the values dpk_{x,y} appear in approximate cbor form, and their macs\n// match the expected values\n// (c) validFrom, validUntil appear in approximate cbor form, and that\n// validFrom <= now <= validUntil\n// (d) For each expected attribute, there exists a preimage to a sha hash\n// that appears in the mso, the preimage is approximately cbor formatted,\n// and the preimage includes the expected attribute id and value.\ntemplate \nclass MdocHash {\n using v8 = typename LogicCircuit::v8;\n using v32 = typename LogicCircuit::v32;\n using v256 = typename LogicCircuit::v256;\n\n using vind = typename LogicCircuit::template bitvec;\n\n using Flatsha = FlatSHA256Circuit>;\n using ShaBlockWitness = typename Flatsha::BlockWitness;\n using sha_packed_v32 = typename Flatsha::packed_v32;\n\n public:\n // These structures mimic the similarly named structures in Witness, but\n // their members are circuit wire objects instead of size_t.\n struct OpenedAttribute {\n v8 attr[32]; /* 32b representing attribute name in be. */\n v8 v1[64]; /* 64b of attribute value */\n };\n struct CborIndex {\n vind k;\n void input(const LogicCircuit& lc) {\n k = lc.template vinput();\n }\n };\n\n struct AttrShift {\n vind offset;\n vind len;\n void input(const LogicCircuit& lc) {\n offset = lc.template vinput();\n len = lc.template vinput();\n }\n };\n\n class Witness {\n public:\n v8 in_[64 * kMaxSHABlocks]; /* input bytes, 64 * MAX */\n\n v8 nb_; /* index of sha block that contains the real hash */\n ShaBlockWitness sig_sha_[kMaxSHABlocks];\n\n std::vector> attr_sha_;\n std::vector> attrb_;\n\n CborIndex valid_from_, valid_until_;\n CborIndex dev_key_info_;\n CborIndex value_digests_;\n std::vector attr_mso_;\n std::vector attr_ei_;\n std::vector attr_ev_;\n size_t num_attr_;\n\n explicit Witness(size_t num_attr) {\n num_attr_ = num_attr;\n attr_mso_.resize(num_attr);\n attr_ei_.resize(num_attr);\n attr_ev_.resize(num_attr);\n attr_sha_.resize(num_attr);\n for (size_t i = 0; i < num_attr; ++i) {\n attr_sha_[i].resize(2);\n }\n\n attrb_.resize(num_attr);\n }\n\n void input(QuadCircuit& Q, const LogicCircuit& lc) {\n nb_ = lc.template vinput<8>();\n\n // sha input init =========================\n for (size_t i = 0; i + kCose1PrefixLen < 64 * kMaxSHABlocks; ++i) {\n in_[i] = lc.template vinput<8>();\n }\n for (size_t j = 0; j < kMaxSHABlocks; j++) {\n sig_sha_[j].input(Q);\n }\n\n valid_from_.input(lc);\n valid_until_.input(lc);\n dev_key_info_.input(lc);\n value_digests_.input(lc);\n\n // // Attribute opening witnesses\n for (size_t ai = 0; ai < num_attr_; ++ai) {\n for (size_t i = 0; i < 64 * 2; ++i) {\n attrb_[ai].push_back(lc.template vinput<8>());\n }\n for (size_t j = 0; j < 2; j++) {\n attr_sha_[ai][j].input(Q);\n }\n attr_mso_[ai].input(lc);\n attr_ei_[ai].input(lc);\n attr_ev_[ai].input(lc);\n }\n }\n };\n\n explicit MdocHash(const LogicCircuit& lc) : lc_(lc), sha_(lc), r_(lc) {}\n\n void assert_valid_hash_mdoc(OpenedAttribute oa[/* NUM_ATTR */],\n const v8 now[/*20*/], const v256& e,\n const v256& dpkx, const v256& dpky,\n const Witness& vw) const {\n sha_.assert_message_hash_with_prefix(kMaxSHABlocks, vw.nb_, vw.in_,\n kCose1Prefix, kCose1PrefixLen, e,\n vw.sig_sha_);\n\n // Shift a portion of the MSO into buf and check it.\n const v8 zz = lc_.template vbit<8>(0); // cannot appear in strings\n std::vector cmp_buf(kMaxMsoLen);\n const Memcmp CMP(lc_);\n\n // In the shifting below, the +5 corresponds to the prefix\n // D8 18 prefix of the mso that we want to skip parsing.\n // The +2 corresponds to the length.\n\n // validFrom <= now\n r_.shift(vw.valid_from_.k, kValidFromLen + kDateLen, &cmp_buf[0],\n kMaxMsoLen, vw.in_ + 5 + 2, zz, /*unroll=*/3);\n assert_bytes_at(kValidFromLen, &cmp_buf[0], kValidFromCheck);\n auto cmp = CMP.leq(kDateLen, &cmp_buf[kValidFromLen], &now[0]);\n lc_.assert1(cmp);\n\n // now <= validUntil\n r_.shift(vw.valid_until_.k, kValidUntilLen + kDateLen, &cmp_buf[0],\n kMaxMsoLen, vw.in_ + 5 + 2, zz, /*unroll=*/3);\n assert_bytes_at(kValidUntilLen, &cmp_buf[0], kValidUntilCheck);\n cmp = CMP.leq(kDateLen, &now[0], &cmp_buf[kValidUntilLen]);\n lc_.assert1(cmp);\n\n // DPK_{x,y}\n r_.shift(vw.dev_key_info_.k, kDeviceKeyInfoLen + 3 + 32 + 32, &cmp_buf[0],\n kMaxMsoLen, vw.in_ + 5 + 2, zz, /*unroll=*/3);\n assert_bytes_at(kDeviceKeyInfoLen, &cmp_buf[0], kDeviceKeyInfoCheck);\n uint8_t dpkyCheck[] = {0x22, 0x58, 0x20};\n assert_bytes_at(sizeof(dpkyCheck), &cmp_buf[65], dpkyCheck);\n\n assert_key(dpkx, &cmp_buf[kPkxInd]);\n assert_key(dpky, &cmp_buf[kPkyInd]);\n\n // Attributes parsing\n // valueDigests, ignore byte 13 \\in {A1,A2} representing map size.\n r_.shift(vw.value_digests_.k, kValueDigestsLen, cmp_buf.data(), kMaxMsoLen,\n vw.in_ + 5 + 2, zz, /*unroll=*/3);\n assert_bytes_at(13, &cmp_buf[0], kValueDigestsCheck);\n assert_bytes_at(18, &cmp_buf[14], &kValueDigestsCheck[14]);\n\n // Attributes: Equality of hash with MSO value\n for (size_t ai = 0; ai < vw.num_attr_; ++ai) {\n v8 B[96];\n // Check the hash matches the value in the signed MSO.\n r_.shift(vw.attr_mso_[ai].k, 2 + 32, &cmp_buf[0], kMaxMsoLen,\n vw.in_ + 5 + 2, zz, /*unroll=*/3);\n\n // Basic CBOR check of the Tag\n assert_bytes_at(2, &cmp_buf[0], kTag32);\n\n v256 mm;\n // The loop below accounts for endian and v256 vs v8 types.\n for (size_t j = 0; j < 256; ++j) {\n mm[j] = cmp_buf[2 + (255 - j) / 8][(j % 8)];\n }\n\n auto two = lc_.template vbit<8>(2);\n sha_.assert_message_hash(2, two, vw.attrb_[ai].data(), mm,\n vw.attr_sha_[ai].data());\n\n // Check that the attribute_id and value occur in the hashed text.\n r_.shift(vw.attr_ei_[ai].offset, 96, B, 128, vw.attrb_[ai].data(), zz, 3);\n assert_attribute(96, vw.attr_ei_[ai].len, B, oa[ai]);\n }\n }\n\n private:\n void assert_bytes_at(size_t len, const v8 buf[/*>=len*/],\n const uint8_t want[/*len*/]) const {\n for (size_t i = 0; i < len; ++i) {\n auto want_i = lc_.template vbit<8>(want[i]);\n lc_.vassert_eq(&buf[i], want_i);\n }\n }\n\n // Checks that an attribute id or attribute value is as expected.\n // The len parameter holds the byte length of the expected id or value.\n void assert_attribute(size_t max, const vind& len, const v8 got[/*max*/],\n const OpenedAttribute& oa) const {\n // Copy the attribute id and value into a single array.\n v8 want[96];\n for (size_t j = 0; j < 32; ++j) {\n want[j] = oa.attr[j];\n }\n for (size_t j = 0; j < 64; ++j) {\n want[32 + j] = oa.v1[j];\n }\n\n // Perform an equality check on the first len bytes.\n for (size_t j = 0; j < max; ++j) {\n auto ll = lc_.vlt(j, len);\n auto same = lc_.eq(8, got[j].data(), want[j].data());\n lc_.assert_implies(&ll, same);\n }\n }\n\n // Asserts that the key is equal to the value in big-endian order in buf_be.\n void assert_key(v256 key, const v8 buf_be[/*32*/]) const {\n v256 m;\n for (size_t i = 0; i < 256; ++i) {\n m[i] = buf_be[31 - (i / 8)][i % 8];\n }\n lc_.vassert_eq(&m, key);\n }\n\n // The constants below define the prefix of each field that is verified\n // in the MDOC. This string matching approach is substantially faster than\n // parsing the MDOC into cbor, and its soundness analysis provides at least 96\n // bits of static security. These constants differ from similarly named ones\n // in mdoc_constants because they include header bytes; the mdoc_constants\n // values are used for cbor parsing of the raw mdoc, whereas these are used by\n // the circuit.\n\n // 69 [text(9)] 76616C696446726F6D [validFrom] C0 [tag(0)] 74 [len 20]\n static constexpr uint8_t kValidFromCheck[] = {\n 0x69, 0x76, 0x61, 0x6C, 0x69, 0x64, 0x46, 0x72, 0x6F, 0x6D, 0xC0, 0x74};\n static constexpr size_t kValidFromLen = sizeof(kValidFromCheck);\n\n // 6A [text(10)] 76616C6964556E74696C [validUntil] C0 [tag(0)] 74\n static constexpr uint8_t kValidUntilCheck[] = {0x6A, 0x76, 0x61, 0x6C, 0x69,\n 0x64, 0x55, 0x6E, 0x74, 0x69,\n 0x6C, 0xC0, 0x74};\n static constexpr size_t kValidUntilLen = sizeof(kValidUntilCheck);\n\n // 6D text(13) 6465766963654B6579496E666F \"deviceKeyInfo\"\n // A1 map(1) 69 text(9) 6465766963654B6579 \"deviceKey\"\n // A4 map(4) 01 02 20 01\n // 21 negative(1) 58 20 bytes(32)\n // \n // 22 negative(2) 58 20 bytes(32)\n // \n static constexpr uint8_t kDeviceKeyInfoCheck[] = {\n 0x6D, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4B, 0x65, 0x79, 0x49,\n 0x6E, 0x66, 0x6F, 0xA1, 0x69, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65,\n 0x4B, 0x65, 0x79, 0xA4, 0x01, 0x02, 0x20, 0x01, 0x21, 0x58, 0x20};\n static constexpr size_t kDeviceKeyInfoLen = sizeof(kDeviceKeyInfoCheck);\n static constexpr size_t kPkxInd = kDeviceKeyInfoLen;\n static constexpr size_t kPkyInd = 68; /* 64 + 3 byte tag + 1*/\n\n // 6C text(12) 76616C756544696765737473 \"valueDigests\" A{1,2} # map(1,2)\n // 71 text(17) 6F72672E69736F2E31383031332E352E31 \"org.iso.18013.5.1\"\n static constexpr uint8_t kValueDigestsCheck[] = {\n 0x6C, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x44, 0x69, 0x67,\n 0x65, 0x73, 0x74, 0x73,\n 0xA0, // either {A1, A2}\n 0x71, 0x6F, 0x72, 0x67, 0x2E, 0x69, 0x73, 0x6F, 0x2E,\n 0x31, 0x38, 0x30, 0x31, 0x33, 0x2E, 0x35, 0x2E, 0x31};\n static constexpr size_t kValueDigestsLen = sizeof(kValueDigestsCheck);\n\n static constexpr size_t kDateLen = 20;\n\n const LogicCircuit& lc_;\n Flatsha sha_;\n Routing r_;\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_HASH_H_\n"], ["/longfellow-zk/lib/circuits/logic/bit_plucker.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_PLUCKER_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_PLUCKER_H_\n\n#include \n\n#include \n#include \n\n#include \"algebra/interpolation.h\"\n#include \"algebra/poly.h\"\n#include \"circuits/logic/bit_plucker_constants.h\"\n#include \"circuits/logic/polynomial.h\"\n\nnamespace proofs {\n/*\n\nMany circuits we design require bit inputs in {0,1} when the field F takes 128+\nbits to represent. Each input to a circuit is an element in F, and must either\nbe sent to the verifier or committed, and thus sending several single-bit\ninputs represents an overhead.\n\nA bit-plucker is a circuit component that maps a set\nS \\subset F of size 2^k into k wires, b_0, ..., b_k-1, that are each in {0,1}.\nThus, it can reduce the number of inputs that a predicate circuit requires, and\nthus makes the proof smaller or more efficient to compute or verify.\n\nThe optimal bit-plucker for k bits depends on k. For small k, the simplest\nbit plucker is sufficient. In some cases, bit pluckers can exploit the field\nstructure.\n\n[ RUN ] BitPlucker.PluckSize\npluck[1]: depth: 3 wires: 6 in: 2 out:2 use:4 ovh:2 t:6 cse:0 notn:9\npluck[2]: depth: 4 wires: 14 in: 2 out:4 use:9 ovh:5 t:18 cse:5 notn:19\npluck[3]: depth: 5 wires: 25 in: 2 out:6 use:17 ovh:8 t:38 cse:23 notn:40\npluck[4]: depth: 6 wires: 40 in: 2 out:8 use:29 ovh:11 t:74 cse:73 notn:87\npluck[5]: depth: 7 wires: 61 in: 2 out:10 use:47 ovh:14 t:144 cse:199 notn:194\npluck[6]: depth: 8 wires: 92 in: 2 out:12 use:75 ovh:17 t:288 cse:501 notn:437\npluck[7]: depth: 9 wires: 141 in: 2 out:14 use:121 ovh:20 t:594 cse:1203 notn:984\npluck[8]: depth: 10 wires: 224 in: 2 out:16 use:201 ovh:23 t:1254 cse:2801 notn:2203\n\nOur experiments also considered an O(N)-wires, O(N)-terms bit plucker.\nTo pluck a LOGN-bit quantity E, write E = N0*E1 + E0 where E0 is a\nLOGN0-bit quantity and where E1 is a LOGN1-bit quantity, and where\nLOGN0 = ceil(LOGN/2), LOGN1 = floor(LOGN/2). This decomposition\ncan be computed by interpolating two Polynomials of length N. Now\nwe are left with plucking two quantities E0, E1, which can be done\nby any subquadratic-time plucker.\n\nA similar idea for the LOGN -> N binary decoder is in Knuth 7.1.2\nExercise 39. (A plucker is the moral transpose of the binary\ndecoder.)\n\nHowever, this plucker was dominated by the smaller one for our use case, and\nthus removed from the code here. It can be resurrected from experimental if\nneeded.\n\n[ RUN ] BitPlucker.LargePluckSize\nlarge_pluck[2] depth: 5 wires: 15 in: 2 out:4 use:9 ovh:6 t:19 cse:9 notn:27\nlarge_pluck[3] depth: 7 wires: 31 in: 2 out:5 use:20 ovh:11 t:43 cse:19 notn:50\nlarge_pluck[4] depth: 8 wires: 46 in: 2 out:8 use:33 ovh:13 t:70 cse:33 notn:89\nlarge_pluck[5] depth: 10 wires: 79 in: 2 out:8 use:60 ovh:19 t:128 cse:68 notn:164\nlarge_pluck[6] depth: 11 wires: 119 in: 2 out:12 use:99 ovh:20 t:209 cse:119 notn:299\nlarge_pluck[7] depth: 13 wires: 206 in: 2 out:11 use:179 ovh:27 t:381 cse:234 notn:567\nlarge_pluck[8] depth: 14 wires: 344 in: 2 out:16 use:317 ovh:27 t:668 cse:413 notn:1065\nlarge_pluck[9] depth: 16 wires: 631 in: 2 out:14 use:596 ovh:35 t:1260 cse:796 notn:2064\nlarge_pluck[10] depth: 17 wires: 1157 in: 2 out:20 use:1123 ovh:34 t:2347 cse:1435 notn:3967\nlarge_pluck[11] depth: 19 wires: 2224 in: 2 out:17 use:2181 ovh:43 t:4551 cse:2762 notn:7789\nlarge_pluck[12] depth: 20 wires: 4294 in: 2 out:24 use:4253 ovh:41 t:8782 cse:5113 notn:15205\n\n*/\ntemplate \nclass BitPlucker {\n public:\n static constexpr size_t kN = 1 << LOGN;\n static constexpr size_t kNv32Elts = (32u + LOGN - 1u) / LOGN;\n static constexpr size_t kNv256Elts = (256u + LOGN - 1u) / LOGN;\n static constexpr size_t kNv128Elts = (128u + LOGN - 1u) / LOGN;\n using Field = typename Logic::Field;\n using BitW = typename Logic::BitW;\n using EltW = typename Logic::EltW;\n using Elt = typename Field::Elt;\n using PolyN = Poly;\n using InterpolationN = Interpolation;\n using v32 = typename Logic::v32;\n using v256 = typename Logic::v256;\n using packed_v32 = std::array;\n using packed_v128 = std::array;\n using packed_v256 = std::array;\n\n const Logic& l_;\n std::vector plucker_;\n\n explicit BitPlucker(const Logic& l) : l_(l), plucker_(LOGN) {\n // evaluation points\n PolyN X;\n for (size_t i = 0; i < kN; ++i) {\n X[i] = bit_plucker_point()(i, l_.f_);\n }\n for (size_t k = 0; k < LOGN; ++k) {\n PolyN Y;\n for (size_t i = 0; i < kN; ++i) {\n Y[i] = l_.f_.of_scalar((i >> k) & 1);\n }\n plucker_[k] = InterpolationN::monomial_of_lagrange(Y, X, l_.f_);\n }\n }\n\n typename Logic::template bitvec pluck(const EltW& e) const {\n typename Logic::template bitvec r;\n const Logic& L = l_; // shorthand\n const Polynomial P(L);\n\n for (size_t k = 0; k < LOGN; ++k) {\n EltW v = P.eval(plucker_[k], e);\n L.assert_is_bit(v);\n r[k] = BitW(v, l_.f_);\n }\n\n return r;\n }\n\n v32 unpack_v32(const packed_v32& v) const {\n v32 r;\n for (size_t i = 0; i < v.size(); ++i) {\n auto b = pluck(v[i]);\n for (size_t j = 0; j < LOGN; ++j) {\n if (LOGN * i + j < 32) {\n r[LOGN * i + j] = b[j];\n }\n }\n }\n return r;\n }\n\n\n template \n T unpack(const PackedT& v) const {\n T r;\n for (size_t i = 0; i < v.size(); ++i) {\n auto b = pluck(v[i]);\n for (size_t j = 0; j < LOGN; ++j) {\n if (LOGN * i + j < r.size()) {\n r[LOGN * i + j] = b[j];\n }\n }\n }\n return r;\n }\n};\n\n/*\nOn input Elt ind, and Elt arr[], returns arr[ind].\nThis muxer is useful when the same array needs to be muxed multiple times\nwith different indices. It differs from the above classes in that it\nprecomputes the coefficient array, which can depend on EltW inputs.\n*/\ntemplate \nclass EltMuxer {\n static constexpr size_t kN = 1 << LOGN;\n\n public:\n using Field = typename Logic::Field;\n using EltW = typename Logic::EltW;\n using PolyN = Poly;\n using InterpolationN = Interpolation;\n\n EltMuxer(const Logic& l, const EltW arr[/* kN */]) : l_(l), coeff_(kN) {\n for (size_t i = 0; i < kN; ++i) {\n coeff_[i] = l_.konst(0);\n }\n for (size_t i = 0; i < kN; ++i) {\n PolyN basis_i = even_lagrange_basis(i);\n for (size_t j = 0; j < kN; ++j) {\n auto bi = l_.konst(basis_i[j]);\n auto barr_i = l_.mul(&bi, arr[i]);\n coeff_[j] = l_.add(&coeff_[j], barr_i);\n }\n }\n }\n\n EltW mux(const EltW& ind) const {\n const Polynomial P(l_);\n\n std::array xi;\n P.powers_of_x(kN, xi.data(), ind);\n\n // dot product with coefficients\n EltW r = l_.konst(0);\n for (size_t i = 0; i < kN; ++i) {\n auto cxi = l_.mul(&coeff_[i], xi[i]);\n r = l_.add(&r, cxi);\n }\n return r;\n }\n\n private:\n const Logic& l_;\n std::vector coeff_;\n\n PolyN even_lagrange_basis(size_t k) {\n PolyN X, Y;\n for (size_t i = 0; i < kN; ++i) {\n X[i] = bit_plucker_point()(i, l_.f_);\n Y[i] = l_.f_.of_scalar((i == k));\n }\n return InterpolationN::monomial_of_lagrange(Y, X, l_.f_);\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_PLUCKER_H_\n"], ["/longfellow-zk/lib/circuits/cbor_parser/cbor.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_H_\n\n#include \n#include \n\n#include \n#include \n\n#include \"circuits/cbor_parser/cbor_constants.h\"\n#include \"circuits/cbor_parser/cbor_pluck.h\"\n#include \"circuits/cbor_parser/scan.h\"\n#include \"circuits/logic/bit_adder.h\"\n#include \"circuits/logic/memcmp.h\"\n#include \"circuits/logic/routing.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\ntemplate \nclass Cbor {\n public:\n using Field = typename Logic::Field;\n using EltW = typename Logic::EltW;\n using BitW = typename Logic::BitW;\n using v8 = typename Logic::v8;\n static constexpr size_t kIndexBits = IndexBits;\n static constexpr size_t kNCounters = CborConstants::kNCounters;\n using bv_counters = typename Logic::template bitvec;\n\n // a bitvector that contains an index into the input\n // (byte) array.\n using vindex = typename Logic::template bitvec;\n\n // does not yet work in binary fields\n static_assert(!Field::kCharacteristicTwo);\n\n explicit Cbor(const Logic& l)\n : l_(l), ba_count_(l), ba_byte_(l), ba_index_(l), bp_(l) {}\n\n struct global_witness {\n EltW invprod_decode; // inverse of a certain product, see assert_decode()\n EltW cc0; // initial value of counter[0]\n EltW invprod_parse; // inverse of a certain product, see assert_parse()\n };\n\n struct position_witness {\n EltW encoded_sel_header;\n };\n\n //------------------------------------------------------------\n // Decoder (lexer)\n //------------------------------------------------------------\n struct decode {\n BitW arrayp;\n BitW mapp;\n BitW itemsp;\n BitW stringp;\n BitW tagp;\n BitW specialp;\n BitW simple_specialp; // One of false, true, null, or undefined.\n BitW count0_23;\n BitW count24;\n BitW invalid;\n BitW length_plus_next_v8;\n BitW count_is_next_v8;\n BitW header;\n EltW length; // of this item\n EltW as_field_element;\n EltW count_as_field_element;\n v8 as_bits;\n };\n\n // extract whatever we can from one v8\n struct decode decode_one_v8(const v8& v) const {\n const Logic& L = l_; // shorthand\n struct decode s;\n L.vassert_is_bit(v);\n\n // v = type:3 count:5\n auto count = L.template slice<0, 5>(v);\n auto type = L.template slice<5, 8>(v);\n\n s.itemsp = L.veqmask(type, /*mask*/ 0b110, /*val*/ 0b100);\n s.stringp = L.veqmask(type, /*mask*/ 0b110, /*val*/ 0b010);\n\n s.specialp = L.veq(type, 7);\n s.tagp = L.veq(type, 6);\n s.arrayp = L.land(&s.itemsp, L.lnot(type[0]));\n s.mapp = L.land(&s.itemsp, type[0]);\n\n // count0_23 = (0 <= count < 24) = ~(count == 11xxx)\n s.count0_23 = L.lnot(L.veqmask(count, /*mask*/ 0b11000, /*val*/ 0b11000));\n\n s.count24 = L.veq(count, 24);\n\n BitW count20_23 = L.veqmask(count, /*mask*/ 0b11100, /*val*/ 0b10100);\n s.simple_specialp = L.land(&s.specialp, count20_23);\n\n // stringp && count24\n s.length_plus_next_v8 =\n L.veqmask(v, /*mask*/ 0b110'11111, /*val*/ 0b010'11000);\n\n // itemsp && count24\n s.count_is_next_v8 =\n L.veqmask(v, /*mask*/ 0b110'11111, /*val*/ 0b100'11000);\n\n // invalid = (specialp && !simple_specialp) || (!count24 && !count0_23)\n auto lhs = L.land(&s.specialp, L.lnot(s.simple_specialp));\n auto bad_count = L.lor_exclusive(&s.count24, s.count0_23);\n s.invalid = L.lor(&lhs, L.lnot(bad_count));\n\n s.count_as_field_element = ba_count_.as_field_element(count);\n\n // Length is the length of the item, including the header.\n //\n // 1 for header\n // +1 if (count24)\n // +count if (stringp && count0_23);\n s.length = L.konst(1);\n s.length = L.add(&s.length, L.eval(s.count24));\n auto str_23 = L.land(&s.stringp, s.count0_23);\n auto e_str_23 = L.eval(str_23);\n auto adjust_if_string = L.mul(&e_str_23, s.count_as_field_element);\n s.length = L.add(&s.length, adjust_if_string);\n\n s.as_field_element = ba_byte_.as_field_element(v);\n s.as_bits = v;\n\n s.header = L.bit(0); // for now\n return s;\n }\n\n void assert_decode(size_t n, const decode ds[/*n*/],\n const position_witness pw[/*n*/],\n const global_witness& gw) const {\n const Logic& L = l_; // shorthand\n Scan SC(l_);\n\n // -------------------------------------------------------------\n // Decoder didn't fail\n for (size_t i = 0; i < n; ++i) {\n L.assert_implies(&ds[i].header, L.lnot(ds[i].invalid));\n }\n // if LENGTH_PLUS_NEXT_V8 is TRUE in the last position,\n // then the input is invalid.\n L.assert_implies(&ds[n - 1].header, L.lnot(ds[n - 1].length_plus_next_v8));\n\n // if COUNT_IS_NEXT_V8 is TRUE in the last position,\n // then the input is invalid.\n L.assert_implies(&ds[n - 1].header, L.lnot(ds[n - 1].count_is_next_v8));\n\n // -------------------------------------------------------------\n // Headers are where they are supposed to be.\n // First, compute the segmented scan\n // slen[i] = header[i] ? length[i] : (slen[i-1] + mone[i])\n std::vector mone(n);\n std::vector header(n);\n std::vector length(n);\n std::vector slen_next(n);\n\n for (size_t i = 0; i + 1 < n; ++i) {\n mone[i] = L.konst(L.mone());\n header[i] = ds[i].header;\n length[i] = ds[i].length;\n if (i + 1 < n) {\n auto len_i =\n L.lmul(&ds[i].length_plus_next_v8, ds[i + 1].as_field_element);\n length[i] = L.add(&length[i], len_i);\n }\n }\n\n SC.add(n, slen_next.data(), header.data(), length.data(), mone.data());\n\n // Now check the headers.\n {\n // \"The first position is a header\"\n L.assert1(header[0]);\n }\n\n {\n auto one = L.konst(1);\n // \"\\A I : (SLEN_NEXT[I] == 1) IFF HEADER[I+1]\"\n {\n // \"\\A I : HEADER[I+1] => (SLEN_NEXT[I] == 1)\"\n for (size_t i = 0; i + 1 < n; ++i) {\n auto implies = L.lmul(&header[i + 1], L.sub(&slen_next[i], one));\n L.assert0(implies);\n }\n }\n {\n // \"\\A I : (SLEN_NEXT[I] == 1) => HEADER[i+1] \"\n // Verify via the invertibility of\n //\n // PROD_{I, L} HEADER[I+1] ? 1 : (SLEN_NEXT[I] - 1)\n //\n auto f = [&](size_t i) {\n return L.mux(&header[i + 1], &one, L.sub(&slen_next[i], one));\n };\n EltW prod = L.mul(0, n - 1, f);\n auto want_one = L.mul(&prod, gw.invprod_decode);\n L.assert_eq(&want_one, one);\n }\n }\n }\n\n //------------------------------------------------------------\n // Parser\n //------------------------------------------------------------\n using counters = std::array;\n struct parse_output {\n bv_counters sel;\n counters c;\n };\n\n void parse(size_t n, parse_output ps[/*n*/], const decode ds[/*n*/],\n const position_witness pw[/*n*/], const global_witness& gw) const {\n std::vector ddss(n);\n std::vector SS(n);\n std::vector AA(n);\n std::vector BB(n);\n\n const Logic& L = l_; // shorthand\n Scan SC(l_);\n\n for (size_t i = 0; i < n; ++i) {\n ps[i].sel = bp_.pluckj(pw[i].encoded_sel_header);\n }\n\n auto mone = L.konst(L.mone());\n for (size_t l = 0; l < kNCounters; ++l) {\n for (size_t i = 0; i < n; ++i) {\n // at the selected headers, decrement the level-L counter.\n auto dp = L.land(&ds[i].header, ps[i].sel[l]);\n ddss[i] = L.lmul(&dp, mone);\n }\n\n if (l == 0) {\n // do level-0 as an unsegmented parallel prefix\n // on DDSS starting at CC0.\n // One can achieve the same effect by using the segmented prefix\n // after initializing SS and AA as follows:\n //\n // SS[0] = L.bit(1);\n // AA[0] = gw.cc0;\n // for (size_t i = 1; i < n; ++i) {\n // SS[i] = L.bit(0);\n // AA[i] = L.konst(0);\n // }\n //\n // The compiler is smart enough to constant-fold the segment\n // SS[i] and produces the same circuit in both cases, but\n // there is no point in wasting compiler time and the\n // unsegmented prefix is more straightforward anyway.\n //\n // Note that AA, SS are uninitialized here. They will be initialized\n // below for the next level.\n ddss[0] = gw.cc0;\n SC.add(n, BB.data(), ddss.data());\n } else {\n SC.add(n, BB.data(), SS.data(), AA.data(), ddss.data());\n }\n\n // output the result of the parallel prefix\n for (size_t i = 0; i < n; ++i) {\n ps[i].c[l] = BB[i];\n }\n\n // prepare SS, AA for the next level\n for (size_t i = 0; i < n; ++i) {\n EltW newc = L.eval(ds[i].tagp);\n EltW count = ds[i].count_as_field_element;\n if (i + 1 < n) {\n count = L.mux(&ds[i].count_is_next_v8, &ds[i + 1].as_field_element,\n count);\n }\n newc = L.add(&newc, L.lmul(&ds[i].itemsp, count));\n newc = L.add(&newc, L.lmul(&ds[i].mapp, count));\n AA[i] = newc;\n\n auto sel = L.land(&ps[i].sel[l], ds[i].header);\n auto tag = L.lor(&ds[i].tagp, ds[i].itemsp);\n SS[i] = L.land(&sel, tag);\n }\n }\n\n // Assert that we don't want to start new segments at a level\n // that does not exist.\n for (size_t i = 0; i < n; ++i) {\n L.assert0(SS[i]);\n }\n }\n\n void assert_parse(size_t n, const decode ds[/*n*/],\n const parse_output ps[/*n*/],\n const global_witness& gw) const {\n const Logic& L = l_; // shorthand\n\n for (size_t i = 0; i < n; ++i) {\n // \"The SEL witnesses are mutually exclusive.\"\n // Verify by asserting that they are all bits\n // and that their sum (in the field) is a bit.\n auto sum = L.bit(0);\n for (size_t l = 0; l < kNCounters; ++l) {\n L.assert_is_bit(ps[i].sel[l]);\n sum = L.lor_exclusive(&sum, ps[i].sel[l]);\n }\n L.assert_is_bit(sum);\n\n // \"at a header, at least one SEL bit is set\"\n L.assert_implies(&ds[i].header, sum);\n }\n\n // \"All counters are zero at the end of the input\"\n // COUNTER[I][L] is the state of the parser at the end\n // of position I, so COUNTER[N-1][L] is the final state.\n for (size_t l = 0; l < kNCounters; ++l) {\n L.assert0(ps[n - 1].c[l]);\n }\n\n // SEL[0][0] is set. We implicitly define COUNTER[-1][L] to make\n // this the correct choice.\n L.assert1(ps[0].sel[0]);\n\n for (size_t i = 0; i + 1 < n; ++i) {\n // \"If SEL[I+1][L] is set, then COUNTER[I][L] is the nonzero\n // counter of maximal L. (COUNTER[I][L] contains the output\n // counter of stage I, which affects SEL[I+1].) Here we check\n // maximality: COUNTER[I][J]=0 for J>L. See below for\n // SEL[I+1][L] => (COUNTER[I][L] != 0).\n BitW b = ps[i + 1].sel[0];\n for (size_t l = 1; l < kNCounters; ++l) {\n // b => COUNTER[i][l] == 0\n L.assert0(L.lmul(&b, ps[i].c[l]));\n b = L.lor(&b, ps[i + 1].sel[l]);\n }\n }\n\n // \"SEL[I+1][L] => (COUNTER[I][L] != 0)\"\n // Check via the invertibility of\n //\n // PROD_{I, L} SEL[I+1][L] ? COUNTER[I][L] : 1\n std::vector prod(kNCounters);\n\n auto one = L.konst(1);\n for (size_t l = 0; l < kNCounters; ++l) {\n auto f = [&](size_t i) {\n return L.mux(&ps[i + 1].sel[l], &ps[i].c[l], one);\n };\n prod[l] = L.mul(0, n - 1, f);\n }\n\n EltW p = L.mul(0, kNCounters, [&](size_t l) { return prod[l]; });\n auto want_one = L.mul(&p, gw.invprod_parse);\n L.assert_eq(&want_one, one);\n }\n\n //------------------------------------------------------------\n // \"J is the header of a string of length LEN containing BYTES\"\n //------------------------------------------------------------\n void assert_text_at(size_t n, const vindex& j, size_t len,\n const uint8_t bytes[/*len*/],\n const decode ds[/*n*/]) const {\n const Logic& L = l_; // shorthand\n const Routing R(L);\n\n // we don't handle long strings\n proofs::check(len < 24, \"len < 24\");\n\n assert_header(n, j, ds);\n\n std::vector A(n);\n for (size_t i = 0; i < n; ++i) {\n A[i] = ds[i].as_field_element;\n }\n\n // shift len+1 bytes, including the header.\n std::vector B(len + 1);\n const EltW defaultA = L.konst(256); // a constant that cannot appear in A[]\n R.shift(j, len + 1, B.data(), n, A.data(), defaultA, /*unroll=*/3);\n\n size_t expected_header = (3 << 5) + len;\n L.assert_eq(&B[0], L.konst(expected_header));\n for (size_t i = 0; i < len; ++i) {\n auto bi = L.konst(bytes[i]);\n L.assert_eq(&B[i + 1], bi);\n }\n }\n\n //------------------------------------------------------------\n // \"J is a header containing unsigned U.\"\n //------------------------------------------------------------\n void assert_unsigned_at(size_t n, const vindex& j, uint64_t u,\n const decode ds[/*n*/]) const {\n // only small u for now\n proofs::check(u < 24, \"u < 24\");\n\n size_t expected = (0 << 5) + u;\n assert_atom_at(n, j, l_.konst(expected), ds);\n }\n\n //------------------------------------------------------------\n // \"J is a header containing negative U.\" (U >= 0, and\n // CBOR distinguishes 0 from -0 apparently)\n //------------------------------------------------------------\n void assert_negative_at(size_t n, const vindex& j, uint64_t u,\n const decode ds[/*n*/]) const {\n // only small u for now\n proofs::check(u < 24, \"u < 24\");\n\n size_t expected = (1 << 5) + u;\n assert_atom_at(n, j, l_.konst(expected), ds);\n }\n\n //------------------------------------------------------------\n // \"J is a header containing a boolean primitive (0xF4 or 0xF5).\"\n //\n //------------------------------------------------------------\n void assert_bool_at(size_t n, const vindex& j, bool val,\n const decode ds[/*n*/]) const {\n size_t expected = (7 << 5) + (val ? 21 : 20);\n assert_atom_at(n, j, l_.konst(expected), ds);\n }\n\n // Helps assemble the checks for date assertions.\n void date_helper(size_t n, const vindex& j, const decode ds[/*n*/],\n std::vector& B /* size 22 */) const {\n const Logic& L = l_; // shorthand\n const Routing R(L);\n assert_header(n, j, ds);\n\n std::vector A(n);\n for (size_t i = 0; i < n; ++i) {\n A[i] = ds[i].as_bits;\n }\n\n const v8 defaultA =\n L.template vbit<8>(0); // a constant that cannot appear in A[]\n R.shift(j, 20 + 2, B.data(), n, A.data(), defaultA, /*unroll=*/3);\n\n // Check for tag: date/time string.\n L.vassert_eq(&B[0], L.template vbit<8>(0xc0));\n\n // Check for string(20)\n L.vassert_eq(&B[1], L.template vbit<8>(0x74));\n }\n\n //------------------------------------------------------------\n // \"J is a header containing date d < now.\" now is 20 bytes\n // in the format 2023-11-01T09:00:00Z\n //------------------------------------------------------------\n void assert_date_before_at(size_t n, const vindex& j, const v8 now[/* 20 */],\n const decode ds[/*n*/]) const {\n const Logic& L = l_; // shorthand\n const Memcmp CMP(L);\n std::vector B(20 + 2);\n date_helper(n, j, ds, B);\n auto lt = CMP.lt(20, &B[2], now);\n L.assert1(lt);\n }\n\n //------------------------------------------------------------\n // \"J is a header containing date d > now.\" now is 20 bytes in the\n // format 2023-11-01T09:00:00Z\n // ------------------------------------------------------------\n void assert_date_after_at(size_t n, const vindex& j, const v8 now[/* 20 */],\n const decode ds[/*n*/]) const {\n const Logic& L = l_; // shorthand\n const Memcmp CMP(L);\n std::vector B(20 + 2);\n date_helper(n, j, ds, B);\n auto lt = CMP.lt(20, now, &B[2]);\n L.assert1(lt);\n }\n\n //------------------------------------------------------------\n // \"J is a header containing represented by the byte EXPECTED in the\n // input.\"\n //------------------------------------------------------------\n void assert_atom_at(size_t n, const vindex& j, const EltW& expected,\n const decode ds[/*n*/]) const {\n const Logic& L = l_; // shorthand\n const Routing R(L);\n\n assert_header(n, j, ds);\n\n std::vector A(n);\n for (size_t i = 0; i < n; ++i) {\n A[i] = ds[i].as_field_element;\n }\n\n EltW B[1];\n size_t unroll = 3;\n R.shift(j, 1, B, n, A.data(), L.konst(256), unroll);\n L.assert_eq(&B[0], expected);\n }\n\n //------------------------------------------------------------\n // \"J is a header beginning a byte array of length LEN that\n // is the big-endian representation of EltW X.\"\n // ------------------------------------------------------------\n void assert_elt_as_be_bytes_at(size_t n, const vindex& j, size_t len, EltW X,\n const decode ds[/*n*/]) const {\n const Logic& L = l_; // shorthand\n const Routing R(L);\n\n std::vector A(n);\n for (size_t i = 0; i < n; ++i) {\n A[i] = ds[i].as_field_element;\n }\n EltW tx = L.konst(0), k256 = L.konst(256);\n\n std::vector B(2 + len);\n size_t unroll = 3;\n size_t si = 1;\n R.shift(j, len + 2, B.data(), n, A.data(), L.konst(0), unroll);\n if (len < 24) {\n size_t expected_header = (2 << 5) + len;\n auto eh = L.konst(expected_header);\n L.assert_eq(&B[0], eh);\n } else if (len < 256) {\n size_t expected_header = (2 << 5) + 24;\n auto eh = L.konst(expected_header);\n L.assert_eq(&B[0], eh);\n L.assert_eq(&B[1], L.konst(len));\n si = 2;\n } else {\n check(false, \"len >= 256\");\n }\n\n for (size_t i = 0; i < len; ++i) {\n auto tmp = L.mul(&tx, k256);\n tx = L.add(&tmp, B[i + si]);\n }\n\n L.assert_eq(&tx, X);\n }\n\n //------------------------------------------------------------\n // \"Position j contains a header\"\n //------------------------------------------------------------\n void assert_header(size_t n, const vindex& j, const decode ds[/*n*/]) const {\n const Logic& L = l_; // shorthand\n\n L.vassert_is_bit(j);\n\n // giant dot product since the veq(j, .) terms are mutually exclusive.\n auto f = [&](size_t i) { return L.land(&ds[i].header, L.veq(j, i)); };\n L.assert1(L.lor_exclusive(0, n, f));\n }\n\n //------------------------------------------------------------\n // \"A map starts at position j\"\n //------------------------------------------------------------\n void assert_map_header(size_t n, const vindex& j,\n const decode ds[/*n*/]) const {\n const Logic& L = l_; // shorthand\n\n L.vassert_is_bit(j);\n\n // giant dot product since the veq(j, .) terms are mutually exclusive.\n auto f = [&](size_t i) {\n auto eq_ji = L.veq(j, i);\n auto dsi = L.land(&ds[i].mapp, ds[i].header);\n return L.land(&eq_ji, dsi);\n };\n L.assert1(L.lor_exclusive(0, n, f));\n }\n\n //------------------------------------------------------------\n // \"Position M starts a map of level LEVEL. (K, V) are headers\n // representing the J-th pair in that map\"\n //------------------------------------------------------------\n void assert_map_entry(size_t n, const vindex& m, size_t level,\n const vindex& k, const vindex& v, const vindex& j,\n const decode ds[/*n*/],\n const parse_output ps[/*n*/]) const {\n const Logic& L = l_; // shorthand\n const Routing R(L);\n\n assert_map_header(n, m, ds);\n assert_header(n, k, ds);\n assert_header(n, v, ds);\n\n for (size_t l = 0; l < kNCounters; ++l) {\n std::vector A(n);\n for (size_t i = 0; i < n; ++i) {\n A[i] = ps[i].c[l];\n }\n\n // Select counters[m], counters[k], and counters[v].\n EltW cm, ck, cv;\n\n const size_t unroll = 3;\n R.shift(m, 1, &cm, n, A.data(), L.konst(0), unroll);\n R.shift(k, 1, &ck, n, A.data(), L.konst(0), unroll);\n R.shift(v, 1, &cv, n, A.data(), L.konst(0), unroll);\n\n if (l <= level) {\n // Counters[L] must agree at the key, value, and root\n // of the map.\n L.assert_eq(&cm, ck);\n L.assert_eq(&cm, cv);\n } else if (l == level + 1) {\n auto one = L.konst(1);\n auto two = L.konst(2);\n // LEVEL+1 counters must have the right number of decrements.\n // Specifically, if the counter at the map is N, then the j-th\n // key has N-(2*j+1) and the j-th value has N-(2*j+2)\n auto twoj = L.mul(&two, ba_index_.as_field_element(j));\n L.assert_eq(&cm, L.add(&ck, L.add(&twoj, one)));\n L.assert_eq(&cm, L.add(&cv, L.add(&twoj, two)));\n } else {\n // not sure if this is necessary, but all other counters\n // of CM are supposed to be zero.\n L.assert0(cm);\n }\n }\n }\n\n //------------------------------------------------------------\n // \"JROOT is the first byte of the actual (unpadded) input and\n // all previous bytes are 0\"\n //------------------------------------------------------------\n void assert_input_starts_at(size_t n, const vindex& jroot,\n const vindex& input_len,\n const decode ds[/*n*/]) const {\n const Logic& L = l_; // shorthand\n\n L.assert1(L.vleq(input_len, n));\n L.assert1(L.vlt(jroot, n));\n auto tot = L.vadd(jroot, input_len);\n L.vassert_eq(tot, n);\n\n for (size_t i = 0; i < n; ++i) {\n L.assert0(L.lmul(&ds[i].as_field_element, L.vlt(i, jroot)));\n }\n }\n\n //------------------------------------------------------------\n // Utilities\n //------------------------------------------------------------\n // The circuit accepts up to N input positions, of which\n // INPUT_LEN are actual input and the rest are ignored.\n void decode_all(size_t n, decode ds[/*n*/], const v8 in[/*n*/],\n const position_witness pw[/*n*/]) const {\n for (size_t i = 0; i < n; ++i) {\n ds[i] = decode_one_v8(in[i]);\n ds[i].header = bp_.pluckb(pw[i].encoded_sel_header);\n }\n }\n\n void decode_and_assert_decode(size_t n, decode ds[/*n*/], const v8 in[/*n*/],\n const position_witness pw[/*n*/],\n const global_witness& gw) const {\n decode_all(n, ds, in, pw);\n assert_decode(n, ds, pw, gw);\n }\n\n void decode_and_assert_decode_and_parse(size_t n, decode ds[/*n*/],\n parse_output ps[/*n*/],\n const v8 in[/*n*/],\n const position_witness pw[/*n*/],\n const global_witness& gw) const {\n decode_and_assert_decode(n, ds, in, pw, gw);\n parse(n, ps, ds, pw, gw);\n assert_parse(n, ds, ps, gw);\n }\n\n private:\n const Logic& l_;\n const BitAdder ba_count_;\n const BitAdder ba_byte_;\n const BitAdder ba_index_;\n const CborPlucker bp_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_H_\n"], ["/longfellow-zk/lib/circuits/mac/mac_witness.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MAC_MAC_WITNESS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MAC_MAC_WITNESS_H_\n\n#include \n#include \n\n#include \"arrays/dense.h\"\n#include \"circuits/logic/bit_plucker_encoder.h\"\n#include \"gf2k/gf2_128.h\"\n\nnamespace proofs {\n\ntemplate \nclass MacWitness {\n using f_128 = GF2_128<>;\n using gf2k = f_128::Elt;\n using packer = BitPluckerEncoder;\n using packed_v128 = typename packer::packed_v128;\n using packed_v256 = typename packer::packed_v256;\n\n public:\n explicit MacWitness(const Field& F, const f_128& GF) : f_(F), gf_(GF) {}\n\n void fill_witness(DenseFiller& fill) const {\n packer bp(f_);\n uint8_t tmp[f_128::kBits];\n for (size_t i = 0; i < 2; ++i) {\n for (size_t j = 0; j < f_128::kBits; ++j) {\n tmp[j] = ap_[i][j];\n }\n fill.push_back(bp.template pack(tmp, f_128::kBits));\n }\n\n for (size_t i = 0; i < 2; ++i) {\n for (size_t j = 0; j < f_128::kBits; ++j) {\n tmp[j] = x_[i][j];\n }\n fill.push_back(bp.template pack(tmp, 128));\n }\n }\n\n // Computes a mac witness on a 32-byte message x.\n // This code assumes that a gf element is at least 16 bytes.\n void compute_witness(const gf2k a_p[/*2*/], const uint8_t x[/*32*/]) {\n for (size_t i = 0; i < 2; ++i) {\n x_[i] = gf_.of_bytes_field(&x[i * 16]).value();\n ap_[i] = a_p[i];\n }\n }\n\n private:\n gf2k ap_[2], x_[2];\n const Field& f_;\n const f_128& gf_;\n};\n\nclass MacGF2Witness {\n using f_128 = GF2_128<>;\n using gf2k = f_128::Elt;\n\n public:\n void fill_witness(DenseFiller& fill) const {\n fill.push_back(ap_[0]);\n fill.push_back(ap_[1]);\n }\n\n // Computes a mac witness on a 32-byte message x.\n void compute_witness(const gf2k a_p[/*2*/]) {\n for (size_t i = 0; i < 2; ++i) {\n ap_[i] = a_p[i];\n }\n }\n\n private:\n gf2k ap_[2];\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MAC_MAC_WITNESS_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_witness.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_WITNESS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_WITNESS_H_\n\n#include \n#include \n\n#include \n#include \n#include \n#include \n\n#include \"arrays/dense.h\"\n#include \"cbor/host_decoder.h\"\n#include \"circuits/ecdsa/verify_witness.h\"\n#include \"circuits/logic/bit_plucker_encoder.h\"\n#include \"circuits/mac/mac_witness.h\"\n#include \"circuits/mdoc/mdoc_constants.h\"\n#include \"circuits/mdoc/mdoc_hash.h\"\n#include \"circuits/mdoc/mdoc_zk.h\"\n#include \"circuits/sha/flatsha256_witness.h\"\n#include \"gf2k/gf2_128.h\"\n#include \"util/crypto.h\"\n#include \"util/log.h\"\n#include \"util/panic.h\"\n\n\nnamespace proofs {\n\nstruct CborIndex {\n size_t k, v, ndx;\n size_t pos, len; /* optional fields for string/byte values */\n};\n\nstruct AttrShift {\n size_t offset, len;\n};\n\n// This class represents an attribute that is parsed out of the deviceResponse\n// data structure. It includes offsets into the original mdoc which can be used\n// to construct SHA witnesses for disclosing the value of an attribute.\nstruct FullAttribute {\n // Offset and length of the attribute identifier and attribute value.\n size_t id_ind;\n size_t id_len;\n size_t val_ind;\n size_t val_len;\n\n // Index for this attribute among all attributes in the mdoc hash list.\n size_t digest_id;\n CborIndex mso;\n\n // Offset and length of the attribute tag.\n size_t tag_ind;\n size_t tag_len;\n\n // The original mdoc into which all offsets point.\n const uint8_t* doc;\n\n bool operator==(const RequestedAttribute& y) const {\n return y.id_len == id_len && memcmp(y.id, &doc[id_ind], id_len) == 0;\n }\n\n size_t witness_length(const RequestedAttribute& attr) {\n size_t r = id_len + val_len + 1 + 12;\n if (attr.type == CborAttributeType::kDate) {\n r += 4;\n } else if (attr.type == CborAttributeType::kString ||\n attr.type == CborAttributeType::kBytes) {\n r += 1;\n if (val_len > 23) r++;\n if (val_len > 255) r++;\n }\n return r;\n }\n};\n\nclass ParsedMdoc {\n public:\n // Various cbor indices/witnesses for intermediate structures.\n CborIndex t_mso_, sig_, dksig_;\n CborIndex valid_, valid_from_, valid_until_;\n CborIndex dev_key_info_, dev_key_, dev_key_pkx_, dev_key_pky_;\n CborIndex value_digests_, org_;\n std::vector attributes_;\n std::vector doc_type_;\n\n // These are the exact bytes which produce the hash that is signed.\n std::vector tagged_mso_bytes_;\n\n /*\n Parses a byte representation of the \"DeviceResponse\" string from a phone.\n This contains all of the information needed to respond to an mdoc verifier.\n This method attempts to construct a witness from this.\n\n 8.3.2.1.2.2: first field is \"version\", 2nd optional field is \"documents\"\n [documents][0][issuerSigned][issuerAuth]{2} --> tagged mso\n [documents][0][issuerSigned][issuerAuth]{3} --> issuer sig\n [documents][0][issuerSigned][nameSpaces][ns][index-of-attr] --> enc attr\n [documents][0][deviceSigned][deviceAuth][deviceSignature][3] --> sig\n\n This method produces indices into doc as state.\n */\n bool parse_device_response(size_t len, const uint8_t resp[/* len */]) {\n size_t np = 0;\n // When this object falls out of scope, all parsing objects will be\n // garbage collected.\n CborDoc root;\n bool ok = root.decode(resp, len, np, 0);\n if (!ok) {\n log(ERROR, \"Failed to decode root\");\n return false;\n }\n\n size_t di;\n auto docs = root.lookup(resp, 9, (uint8_t*)\"documents\", di);\n if (docs == nullptr) return false;\n // Fields of Document are \"docType\", \"issuerSigned\", \"deviceSigned\", ?errors\n\n auto docs0 = docs[1].index(0);\n if (docs0 == nullptr) return false;\n\n auto dt = docs0[0].lookup(resp, 7, (uint8_t*)\"docType\", di);\n if (dt == nullptr) return false;\n doc_type_.insert(doc_type_.begin(), resp + dt[1].u_.string.pos,\n resp + dt[1].u_.string.pos + dt[1].u_.string.len);\n\n // The returned docs0 is the map, so index at [0].\n auto is = docs0[0].lookup(resp, 12, (uint8_t*)\"issuerSigned\", di);\n if (is == nullptr) return false;\n\n auto ia = is[1].lookup(resp, 10, (uint8_t*)\"issuerAuth\", di);\n if (ia == nullptr) return false;\n\n auto tmso = ia[1].index(2);\n if (tmso == nullptr) return false;\n copy_header(t_mso_, tmso);\n auto nsig = ia[1].index(3);\n if (nsig == nullptr) return false;\n copy_header(sig_, nsig);\n\n auto ns = is[1].lookup(resp, 10, (uint8_t*)\"nameSpaces\", di);\n if (ns == nullptr) return false;\n\n // Find the attribute witness we need from here.\n // For now, we only support 1 namespace.\n auto mldns = ns[1].lookup(resp, 17, (uint8_t*)\"org.iso.18013.5.1\", di);\n if (mldns == nullptr) return false;\n size_t ai = 0;\n auto tattr = mldns[1].index(ai++);\n while (tattr != nullptr) {\n CborDoc er;\n // Decode the map in this tagged attribute.\n size_t pos = tattr->children_[0].u_.string.pos;\n size_t end = pos + tattr->children_[0].u_.string.len;\n if (!er.decode(resp, end, pos, 0)) {\n return false;\n }\n\n auto ei = er.lookup(resp, 17, (uint8_t*)\"elementIdentifier\", di);\n if (ei == nullptr) return false;\n auto ev = er.lookup(resp, 12, (uint8_t*)\"elementValue\", di);\n if (ev == nullptr) return false;\n auto digid = er.lookup(resp, 8, (uint8_t*)\"digestID\", di);\n if (digid == nullptr) return false;\n\n attributes_.push_back(\n (FullAttribute){ei[1].position(),\n ei[1].length(),\n ev[1].position(),\n ev[1].length(),\n static_cast(digid[1].u_.u64), /* digest_id */\n {0, 0, 0}, /* default mso_ind */\n tattr->header_pos_, /* tag_ind */\n tattr->children_[0].u_.string.len +\n 4, /* +4 for the D8 18 58 <> prefix */\n resp});\n\n tattr = mldns[1].index(ai++);\n }\n\n auto ds = docs0[0].lookup(resp, 12, (uint8_t*)\"deviceSigned\", di);\n if (ds == nullptr) return false;\n auto da = ds[1].lookup(resp, 10, (uint8_t*)\"deviceAuth\", di);\n if (da == nullptr) return false;\n auto dsi = da[1].lookup(resp, 15, (uint8_t*)\"deviceSignature\", di);\n if (dsi == nullptr) return false;\n auto ndksig = dsi[1].index(3);\n if (ndksig == nullptr) return false;\n copy_header(dksig_, ndksig);\n\n // Then parse tagged mso. Skip 5 bytes to skip the D8 18 59 .\n const uint8_t* pmso = resp + tmso->u_.string.pos + 5;\n size_t pos = 0;\n CborDoc mso;\n if (!mso.decode(pmso, tmso->u_.string.len - 5, pos, 0)) return false;\n auto nv = mso.lookup(pmso, kValidityInfoLen, kValidityInfoID, valid_.ndx);\n if (nv == nullptr) return false;\n copy_kv_header(valid_, nv);\n\n auto nvf = nv[1].lookup(pmso, kValidFromLen, kValidFromID, valid_from_.ndx);\n if (nvf == nullptr) return false;\n copy_kv_header(valid_from_, nvf);\n\n auto nvu =\n nv[1].lookup(pmso, kValidUntilLen, kValidUntilID, valid_until_.ndx);\n if (nvu == nullptr) return false;\n copy_kv_header(valid_until_, nvu);\n\n auto ndki = mso.lookup(pmso, kDeviceKeyInfoLen, kDeviceKeyInfoID,\n dev_key_info_.ndx);\n if (ndki == nullptr) return false;\n copy_kv_header(dev_key_info_, ndki);\n\n auto ndk = ndki[1].lookup(pmso, kDeviceKeyLen, kDeviceKeyID, dev_key_.ndx);\n if (ndk == nullptr) return false;\n copy_kv_header(dev_key_, ndk);\n\n auto npkx = ndk[1].lookup_negative(-1, dev_key_pkx_.ndx);\n if (npkx == nullptr) return false;\n copy_kv_header(dev_key_pkx_, npkx);\n\n auto npky = ndk[1].lookup_negative(-2, dev_key_pky_.ndx);\n if (npky == nullptr) return false;\n copy_kv_header(dev_key_pky_, npky);\n\n auto nvd =\n mso.lookup(pmso, kValueDigestsLen, kValueDigestsID, value_digests_.ndx);\n if (nvd == nullptr) return false;\n copy_kv_header(value_digests_, nvd);\n\n auto norg = nvd[1].lookup(pmso, kOrgLen, kOrgID, org_.ndx);\n if (norg == nullptr) return false;\n copy_kv_header(org_, norg);\n\n for (auto& attr : attributes_) {\n uint64_t hi = (uint64_t)attr.digest_id;\n auto hattr = norg[1].lookup_unsigned(hi, attr.mso.ndx);\n if (hattr == nullptr) return false;\n copy_kv_header(attr.mso, hattr);\n }\n\n tagged_mso_bytes_.assign(std::begin(kCose1Prefix), std::end(kCose1Prefix));\n // Add 2-byte length\n tagged_mso_bytes_.push_back((t_mso_.len >> 8) & 0xff);\n tagged_mso_bytes_.push_back(t_mso_.len & 0xff);\n for (size_t i = 0; i < t_mso_.len; ++i) {\n tagged_mso_bytes_.push_back(resp[t_mso_.pos + i]);\n }\n\n return true;\n }\n\n private:\n // Used to copy the results of a map lookup.\n static void copy_kv_header(CborIndex& ind, const CborDoc* n) {\n ind.k = n[0].header_pos_;\n ind.v = n[1].header_pos_;\n\n if (n[1].t_ == TEXT || n[1].t_ == BYTES) {\n ind.pos = n[1].u_.string.pos;\n ind.len = n[1].u_.string.len;\n }\n }\n\n // Used to copy the results of an index lookup.\n static void copy_header(CborIndex& ind, const CborDoc* n) {\n ind.k = n->header_pos_;\n ind.pos = n->u_.string.pos;\n ind.len = n->u_.string.len;\n }\n};\n\n// Transform from u8 be (i.e., be[31] is the most significant byte) into\n// nat form, which requires first converting to le byte order.\ntemplate \nNat nat_from_be(const uint8_t be[/* Nat::kBytes */]) {\n uint8_t tmp[Nat::kBytes];\n // Transform into byte-wise le representation.\n for (size_t i = 0; i < Nat::kBytes; ++i) {\n tmp[i] = be[Nat::kBytes - i - 1];\n }\n return Nat::of_bytes(tmp);\n}\n\n// Transform from u32 be (i.e., be[0] is the most significant nibble)\n// into nat form, which requires first converting to le byte order.\ntemplate \nNat nat_from_u32(const uint32_t be[]) {\n uint8_t tmp[Nat::kBytes];\n const size_t top = Nat::kBytes / 4;\n for (size_t i = 0; i < Nat::kBytes; ++i) {\n tmp[i] = (be[top - i / 4 - 1] >> ((i % 4) * 8)) & 0xff;\n }\n return Nat::of_bytes(tmp);\n}\n\ntemplate \nNat nat_from_hash(const uint8_t data[], size_t len) {\n uint8_t hash[kSHA256DigestSize];\n SHA256 sha;\n sha.Update(data, len);\n sha.DigestData(hash);\n Nat ne = nat_from_be(hash);\n return ne;\n}\n\nstatic inline void append_bytes_len(std::vector& buf, size_t len) {\n if (len > 256) {\n uint8_t ll[] = {0x59, (uint8_t)((len >> 8) & 0xff), (uint8_t)(len & 0xff)};\n buf.insert(buf.end(), ll, ll + 3);\n } else {\n uint8_t ll[] = {0x58, static_cast(len & 0xff)};\n buf.insert(buf.end(), ll, ll + 2);\n }\n}\n\nstatic inline void append_text_len(std::vector& buf, size_t len) {\n check(len < 256, \"Text length too large\");\n if (len < 24) {\n buf.push_back(0x60 + len);\n } else if (len < 255) {\n buf.push_back(0x78);\n buf.push_back(len);\n }\n}\n\n// Form the COSE1 encoding of the DeviceAuthenticationBytes,\n// then compute its SHA-256 hash, and cast into a Nat.\n// The original form follows S9.1.3.4 of the mdoc spec and\n// assumed that the transcript was a simple string.\n// The Jan'2024 demo requires using the \"AndroidHandover\" version\n// of the DeviceAuthenticationBytes formatting, which is not\n// specified in the spec. As a result, this function is a hack\n// that mimics the bytes produced by the Android com.android.identity.wallet\n// library.\ntemplate \nstatic Nat compute_transcript_hash(\n const uint8_t transcript[], size_t len,\n const std::vector* docType = nullptr) {\n // The DeviceAuthenticationBytes is defined in 9.1.3.4 as:\n // DeviceAuthentication = [\n // \"DeviceAuthentication\",\n // SessionTranscript,\n // DocType, ; Same as in mdoc response\n // DeviceNameSpacesBytes ; Same as in mdoc response\n // ]\n std::vector deviceAuthentication = {\n 0x84, 0x74, 'D', 'e', 'v', 'i', 'c', 'e', 'A', 'u', 't',\n 'h', 'e', 'n', 't', 'i', 'c', 'a', 't', 'i', 'o', 'n',\n };\n std::vector docTypeBytes = {\n 0x75, 'o', 'r', 'g', '.', 'i', 's', 'o', '.', '1', '8',\n '0', '1', '3', '.', '5', '.', '1', '.', 'm', 'D', 'L',\n };\n std::vector deviceNameSpacesBytes = {0xD8, 0x18, 0x41, 0xA0};\n\n if (docType != nullptr) {\n docTypeBytes.clear();\n append_text_len(docTypeBytes, docType->size());\n docTypeBytes.insert(docTypeBytes.end(), docType->begin(), docType->end());\n }\n\n // Provide the DeviceAuthentication bytes\n std::vector da(deviceAuthentication);\n da.insert(da.end(), transcript, transcript + len);\n da.insert(da.end(), docTypeBytes.begin(), docTypeBytes.end());\n da.insert(da.end(), deviceNameSpacesBytes.begin(),\n deviceNameSpacesBytes.end());\n\n // Form the COSE1 encoding of the DeviceAuthenticationBytes.\n std::vector cose1{0x84, 0x6A, 0x53, 0x69, 0x67, 0x6E,\n 0x61, 0x74, 0x75, 0x72, 0x65, 0x31,\n 0x43, 0xA1, 0x01, 0x26, 0x40};\n uint8_t tag[] = {0xD8, 0x18};\n\n size_t l1 = da.size();\n size_t l2 = l1 + (l1 < 256 ? 4 : 5); /* Tagged array length. */\n append_bytes_len(cose1, l2);\n cose1.insert(cose1.end(), tag, tag + 2);\n append_bytes_len(cose1, l1);\n cose1.insert(cose1.end(), da.begin(), da.end());\n\n return nat_from_hash(cose1.data(), cose1.size());\n}\n\n// Interpret input s as an len*8-bit string, and use it to fill max*8 bits\n// in the dense filler.\n// Pad the input with the Field value 2 to indicate the positions\n// that are not part of the string.\ntemplate \nvoid fill_bit_string(DenseFiller& filler, const uint8_t s[/*len*/],\n size_t len, size_t max, const Field& Fs) {\n std::vector v(max * 8, Fs.of_scalar(2));\n for (size_t i = 0; i < max && i < len; ++i) {\n fill_byte(v, s[i], i, Fs);\n }\n filler.push_back(v);\n}\n\ntemplate \nvoid fill_byte(std::vector& v, uint8_t b, size_t i,\n const Field& F) {\n for (size_t j = 0; j < 8; ++j) {\n v[i*8 + j] = ( b >> j & 0x1 ) ? F.one() : F.zero();\n }\n}\n\ntemplate \nvoid fill_attribute(DenseFiller &filler, const RequestedAttribute &attr,\n const Field &F, size_t version = 2) {\n if (version <= 2) {\n fill_bit_string(filler, attr.id, attr.id_len, 32, F);\n fill_bit_string(filler, attr.value, attr.value_len, 64, F);\n } else if (version == 3) {\n // In version 3, the attribute is encoded as the raw cbor string that\n // included \n std::vector v(96 * 8, F.of_scalar(0));\n\n size_t i = 0;\n for (size_t j = 0; j < attr.id_len && i < 96; ++j, ++i) {\n fill_byte(v, attr.id[j], i, F);\n }\n fill_byte(v, 0x6C, i++, F); // Cbor type for length 12 string.\n const char* ev = \"elementValue\";\n for (size_t j = 0; j < 12 && i < 96; ++j, ++i) {\n fill_byte(v, ev[j], i, F);\n }\n std::vector vbuf;\n uint8_t tag[] = {0xD9, 0x03, 0xEC, 0x6A};\n switch (attr.type) {\n case CborAttributeType::kPrimitive:\n vbuf.push_back(attr.value[0]);\n break;\n case CborAttributeType::kString:\n append_text_len(vbuf, attr.value_len);\n vbuf.insert(vbuf.end(), attr.value, attr.value + attr.value_len);\n break;\n case CborAttributeType::kBytes:\n append_bytes_len(vbuf, attr.value_len);\n vbuf.insert(vbuf.end(), attr.value, attr.value + attr.value_len);\n break;\n case CborAttributeType::kDate:\n vbuf.insert(vbuf.end(), tag, tag + 4);\n vbuf.insert(vbuf.end(), attr.value, attr.value + attr.value_len);\n break;\n case CborAttributeType::kInt:\n vbuf.insert(vbuf.end(), attr.value, attr.value + attr.value_len);\n break;\n }\n for (size_t j = 0; j < vbuf.size() && i < 96; ++j, ++i) {\n fill_byte(v, vbuf[j], i, F);\n }\n filler.push_back(v);\n }\n}\n\n\ntemplate \nclass MdocSignatureWitness {\n using Field = typename EC::Field;\n using Elt = typename Field::Elt;\n using Nat = typename Field::N;\n using EcdsaWitness = VerifyWitness3;\n using MacWitnessF = MacWitness;\n using f_128 = GF2_128<>;\n const EC& ec_;\n const f_128& gf_;\n\n public:\n Elt e_, e2_; /* Issuer signature values. */\n Elt dpkx_, dpky_; /* device key */\n EcdsaWitness ew_, dkw_;\n MacWitnessF macs_[3]; /* macs for e_, dpkx_, dpky_ */\n\n explicit MdocSignatureWitness(const EC& ec, const ScalarField& Fn,\n const f_128& gf)\n : ec_(ec),\n gf_(gf),\n ew_(Fn, ec),\n dkw_(Fn, ec),\n macs_{MacWitnessF(ec.f_, gf_), MacWitnessF(ec.f_, gf_),\n MacWitnessF(ec.f_, gf_)} {}\n\n void fill_witness(DenseFiller& filler) const {\n filler.push_back(e_);\n filler.push_back(dpkx_);\n filler.push_back(dpky_);\n\n ew_.fill_witness(filler);\n dkw_.fill_witness(filler);\n for (auto& mac : macs_) {\n mac.fill_witness(filler);\n }\n }\n\n bool compute_witness(Elt pkX, Elt pkY, const uint8_t mdoc[/* len */],\n size_t len, const uint8_t transcript[/* tlen */],\n size_t tlen) {\n ParsedMdoc pm;\n\n if (!pm.parse_device_response(len, mdoc)) {\n return false;\n }\n\n Nat ne = nat_from_hash(pm.tagged_mso_bytes_.data(),\n pm.tagged_mso_bytes_.size());\n e_ = ec_.f_.to_montgomery(ne);\n\n // Parse (r,s).\n const size_t l = pm.sig_.len;\n Nat nr = nat_from_be(&mdoc[pm.sig_.pos]);\n Nat ns = nat_from_be(&mdoc[pm.sig_.pos + l / 2]);\n ew_.compute_witness(pkX, pkY, ne, nr, ns);\n\n Nat ne2 = compute_transcript_hash(transcript, tlen, &pm.doc_type_);\n const size_t l2 = pm.dksig_.len;\n Nat nr2 = nat_from_be(&mdoc[pm.dksig_.pos]);\n Nat ns2 = nat_from_be(&mdoc[pm.dksig_.pos + l2 / 2]);\n size_t pmso = pm.t_mso_.pos + 5; /* skip the tag */\n dpkx_ = ec_.f_.to_montgomery(\n nat_from_be(&mdoc[pmso + pm.dev_key_pkx_.pos]));\n dpky_ = ec_.f_.to_montgomery(\n nat_from_be(&mdoc[pmso + pm.dev_key_pky_.pos]));\n e2_ = ec_.f_.to_montgomery(ne2);\n dkw_.compute_witness(dpkx_, dpky_, ne2, nr2, ns2);\n return true;\n }\n};\n\n// EC: implements the elliptic curve for the mdoc\n// Field: implements the field used to define the sumcheck circuit, which can\n// be smaller than the EC field\ntemplate \nclass MdocHashWitness {\n using ECField = typename EC::Field;\n using ECElt = typename ECField::Elt;\n using ECNat = typename ECField::N;\n using Elt = typename Field::Elt;\n using vindex = std::array;\n\n const EC& ec_;\n const Field& fn_;\n\n public:\n ECElt e_; /* Issuer signature values. */\n ECElt dpkx_, dpky_; /* device key */\n uint8_t signed_bytes_[kMaxSHABlocks * 64];\n uint8_t numb_; /* Number of the correct sha block. */\n\n size_t num_attr_;\n std::vector> attr_bytes_;\n std::vector> atw_;\n\n std::vector attr_n_; /* All attributes currently require 2 SHA. */\n std::vector attr_mso_; /* The cbor indices of the attributes. */\n std::vector attr_ei_;\n std::vector attr_ev_;\n\n FlatSHA256Witness::BlockWitness bw_[kMaxSHABlocks];\n\n ParsedMdoc pm_;\n\n uint8_t now_[20]; /* CBOR-formatted time used for expiry comparison. */\n\n explicit MdocHashWitness(size_t num_attr, const EC& ec, const Field& Fn)\n : ec_(ec), fn_(Fn), num_attr_(num_attr) {}\n\n void fill_cbor_index(DenseFiller& df, const CborIndex& ind) const {\n df.push_back(ind.k, kCborIndexBits, fn_);\n }\n\n void fill_attr_shift(DenseFiller& df, const AttrShift& attr) const {\n df.push_back(attr.offset, kCborIndexBits, fn_);\n df.push_back(attr.len, kCborIndexBits, fn_);\n }\n\n void fill_sha(DenseFiller& filler,\n const FlatSHA256Witness::BlockWitness& bw) const {\n BitPluckerEncoder BPENC(fn_);\n for (size_t k = 0; k < 48; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.outw[k]));\n }\n for (size_t k = 0; k < 64; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.oute[k]));\n filler.push_back(BPENC.mkpacked_v32(bw.outa[k]));\n }\n for (size_t k = 0; k < 8; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.h1[k]));\n }\n }\n\n void fill_witness(DenseFiller& filler) const {\n // Fill sha of main mso.\n filler.push_back(numb_, 8, fn_);\n // Don't push the prefix.\n for (size_t i = kCose1PrefixLen; i < kMaxSHABlocks * 64; ++i) {\n filler.push_back(signed_bytes_[i], 8, fn_);\n }\n for (size_t j = 0; j < kMaxSHABlocks; j++) {\n fill_sha(filler, bw_[j]);\n }\n // === done with sha\n\n fill_cbor_index(filler, pm_.valid_from_);\n fill_cbor_index(filler, pm_.valid_until_);\n fill_cbor_index(filler, pm_.dev_key_info_);\n fill_cbor_index(filler, pm_.value_digests_);\n\n // Fill all attribute witnesses.\n for (size_t ai = 0; ai < num_attr_; ++ai) {\n for (size_t i = 0; i < 2 * 64; ++i) {\n filler.push_back(attr_bytes_[ai][i], 8, fn_);\n }\n for (size_t j = 0; j < 2; j++) {\n fill_sha(filler, atw_[ai][j]);\n }\n\n // In the case of attribute mso, push the value to avoid having to\n // deal with 1- or 2- byte key length.\n filler.push_back(attr_mso_[ai].v, kCborIndexBits, fn_);\n fill_attr_shift(filler, attr_ei_[ai]);\n fill_attr_shift(filler, attr_ev_[ai]);\n }\n }\n\n bool compute_witness(const uint8_t mdoc[/* len */], size_t len,\n const uint8_t transcript[/* tlen */], size_t tlen,\n const RequestedAttribute attrs[], size_t attrs_len,\n const uint8_t tnow[/*20*/], size_t version = 2) {\n if (!pm_.parse_device_response(len, mdoc)) {\n log(ERROR, \"Failed to parse device response\");\n return false;\n }\n\n std::vector buf;\n if (pm_.t_mso_.len >= kMaxSHABlocks * 64 - 9 - kCose1PrefixLen) {\n log(ERROR, \"tagged mso is too big: %zu\", pm_.t_mso_.len);\n return false;\n }\n\n buf.assign(std::begin(kCose1Prefix), std::end(kCose1Prefix));\n // Add 2-byte length\n buf.push_back((pm_.t_mso_.len >> 8) & 0xff);\n buf.push_back(pm_.t_mso_.len & 0xff);\n for (size_t i = 0; i < pm_.t_mso_.len; ++i) {\n buf.push_back(mdoc[pm_.t_mso_.pos + i]);\n }\n\n FlatSHA256Witness::transform_and_witness_message(\n buf.size(), buf.data(), kMaxSHABlocks, numb_, signed_bytes_, bw_);\n\n ECNat ne = nat_from_u32(bw_[numb_ - 1].h1);\n e_ = ec_.f_.to_montgomery(ne);\n\n memcpy(now_, tnow, 20);\n\n size_t pmso = pm_.t_mso_.pos + 5; /* +5 to skip the tag */\n dpkx_ = ec_.f_.to_montgomery(\n nat_from_be(&mdoc[pmso + pm_.dev_key_pkx_.pos]));\n dpky_ = ec_.f_.to_montgomery(\n nat_from_be(&mdoc[pmso + pm_.dev_key_pky_.pos]));\n\n // initialize variables\n attr_n_.resize(attrs_len);\n attr_mso_.resize(attrs_len);\n attr_ev_.resize(attrs_len);\n attr_ei_.resize(attrs_len);\n attr_bytes_.resize(attrs_len);\n atw_.resize(attrs_len);\n\n // Match the attributes with the witnesses from the deviceResponse.\n for (size_t i = 0; i < attrs_len; ++i) {\n attr_bytes_[i].resize(128);\n atw_[i].resize(2);\n bool found = false;\n for (auto fa : pm_.attributes_) {\n if (fa == attrs[i]) {\n FlatSHA256Witness::transform_and_witness_message(\n fa.tag_len, &fa.doc[fa.tag_ind], 2, attr_n_[i],\n &attr_bytes_[i][0], &atw_[i][0]);\n attr_mso_[i] = fa.mso;\n attr_ei_[i].offset = fa.id_ind - fa.tag_ind;\n attr_ei_[i].len = fa.id_len;\n if (version > 2) {\n attr_ei_[i].len = fa.witness_length(attrs[i]);\n }\n attr_ev_[i].offset = fa.val_ind - fa.tag_ind;\n attr_ev_[i].len = fa.val_len;\n found = true;\n break;\n }\n }\n if (!found) {\n log(ERROR, \"Could not find attribute %.*s\", attrs[i].id_len,\n attrs[i].id);\n return false;\n }\n }\n return true;\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_WITNESS_H_\n"], ["/longfellow-zk/lib/circuits/logic/logic.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_LOGIC_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_LOGIC_H_\n\n#include \n\n#include \n#include \n#include \n#include \n\n#include \"algebra/fp_generic.h\"\n#include \"gf2k/gf2_128.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n/*\n Arithmetization of boolean logic in a field.\n This class builds logical and arithmetic operations such as add, sub, mul,\n and, or, xor, etc. over bits in the arithmetic circuit model.\n The class utilizes several optimizations, including changing from the {0,1}\n basis to the {-1,1} basis for representing bits.\n */\ntemplate \nclass Logic {\n public:\n using Field = Field_; /* this class export Field, Elt, and EltW */\n using Elt = typename Field::Elt;\n // an \"Elt Wire\", a wire carrying an Elt.\n using EltW = typename Backend::V;\n\n const Field& f_;\n\n explicit Logic(const Backend* bk, const Field& F) : f_(F), bk_(bk) {}\n\n //------------------------------------------------------------\n // Arithmetic.\n\n //\n // Re-export field operations\n Elt addf(const Elt& a, const Elt& b) const { return f_.addf(a, b); }\n Elt mulf(const Elt& a, const Elt& b) const { return f_.mulf(a, b); }\n Elt invertf(const Elt& a) const { return f_.invertf(a); }\n Elt negf(const Elt& a) const { return f_.negf(a); }\n Elt zero() const { return f_.zero(); }\n Elt one() const { return f_.one(); }\n Elt mone() const { return f_.mone(); }\n Elt elt(uint64_t a) const { return f_.of_scalar(a); }\n\n template \n Elt elt(const char (&s)[N]) const {\n return f_.of_string(s);\n }\n\n // To ensure deterministic behavior, the order of function calls that produce\n // circuit wires must be well-defined at compile time.\n // The C spec leaves certain order of operations unspecified in expressions.\n // One such ambiguity arises in the order of function calls in an argument\n // list. For example, the expression f(creates_wire(x), creates_wire(y))\n // results in an ambiguous order.\n // To help prevent this, all function calls that create wires can have at most\n // one argument that is itself a function. To enforce this property, we\n // require that all but the last argument to a function be a const pointer.\n\n // Re-export backend operations\n EltW assert0(const EltW& a) const { return bk_->assert0(a); }\n EltW add(const EltW* a, const EltW& b) const { return bk_->add(*a, b); }\n\n EltW sub(const EltW* a, const EltW& b) const { return bk_->sub(*a, b); }\n\n EltW mul(const EltW* a, const EltW& b) const { return bk_->mul(*a, b); }\n EltW mul(const Elt& k, const EltW& b) const { return bk_->mul(k, b); }\n EltW mul(const Elt& k, const EltW* a, const EltW& b) const {\n return bk_->mul(k, a, b);\n }\n\n EltW ax(const Elt& a, const EltW& x) const { return bk_->ax(a, x); }\n EltW axy(const Elt& a, const EltW* x, const EltW& y) const {\n return bk_->axy(a, *x, y);\n }\n EltW axpy(const EltW* y, const Elt& a, const EltW& x) const {\n return bk_->axpy(*y, a, x);\n }\n EltW apy(const EltW& y, const Elt& a) const { return bk_->apy(y, a); }\n\n EltW konst(const Elt& a) const { return bk_->konst(a); }\n EltW konst(uint64_t a) const { return konst(elt(a)); }\n\n template \n std::array konst(const std::array& a) const {\n std::array r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = konst(a[i]);\n }\n return r;\n }\n\n //------------------------------------------------------------\n // Boolean logic.\n //\n // We map TRUE to one() and FALSE to zero(). We call this convention\n // the \"standard basis\".\n //\n // However, actual values on wires may use different conventions,\n // e.g. -1 for TRUE and 1 for FALSE. To keep track of these changes,\n // we represent boolean values as (c0, c1, x) where c0+c1*x is\n // the value in the standard basis. c0 and c1\n // are compile-time constants that can be manipulated, and\n // x is a runtime value not known in advance.\n //\n // For example, let the \"xor basis\" denote the mapping FALSE -> 1,\n // TRUE -> -1. In the xor basis, xor(a,b)=a*b. The output of the\n // xor gate in the standard basis would be represented as 1/2 + (-1/2)*x\n // where x=a*b is the wire value in the xor basis.\n\n // a \"bit Wire\", a wire carrying a bit\n struct BitW {\n Elt c0, c1;\n EltW x;\n BitW() = default;\n\n // constructor in the standard basis\n explicit BitW(const EltW& bv, const Field& F)\n : BitW(F.zero(), F.one(), bv) {}\n\n BitW(Elt c0_, Elt c1_, const EltW& x_) : c0(c0_), c1(c1_), x(x_) {}\n };\n\n // vectors of N bits\n template \n class bitvec : public std::array {};\n\n // Common sizes, publicly exported for convenience. The type names are\n // intentionally lower-case to capture the spirit of basic \"intx_t\" types.\n using v1 = bitvec<1>;\n using v4 = bitvec<4>;\n using v8 = bitvec<8>;\n using v16 = bitvec<16>;\n using v32 = bitvec<32>;\n using v64 = bitvec<64>;\n using v128 = bitvec<128>;\n using v129 = bitvec<129>;\n using v256 = bitvec<256>;\n\n // Let v(x)=c0+c1*x. Return a representation of\n // d0+d1*v(x)=(d0+d1*c0)+(d1*c1)*x without changing x.\n // Does not involve the backend at all.\n BitW rebase(const Elt& d0, const Elt& d1, const BitW& v) const {\n return BitW(addf(d0, mulf(d1, v.c0)), mulf(d1, v.c1), v.x);\n }\n\n EltW eval(const BitW& v) const {\n EltW r = ax(v.c1, v.x);\n if (v.c0 != zero()) {\n auto c0 = konst(v.c0);\n r = add(&c0, r);\n }\n return r;\n }\n\n // return an EltW which is 0 iff v is 0\n EltW assert0(const BitW& v) const {\n auto e = eval(v);\n return assert0(e);\n }\n // return an EltW which is 0 iff v is 1\n EltW assert1(const BitW& v) const {\n auto e = lnot(v);\n return assert0(e);\n }\n\n // 0 iff a==b\n EltW assert_eq(const EltW* a, const EltW& b) const {\n return assert0(sub(a, b));\n }\n EltW assert_eq(const BitW* a, const BitW& b) const {\n return assert0(lxor(a, b));\n }\n EltW assert_implies(const BitW* a, const BitW& b) const {\n return assert1(limplies(a, b));\n }\n\n // special test for asserting that b \\in {0,1} (i.e.,\n // not some other field element).\n EltW assert_is_bit(const BitW& b) const {\n // b - b*b\n // Seems to work better than b*(1-b)\n // Equivalent to land(b,lnot(b)) but does not rely\n // on the specific arithmetization.\n auto eb = eval(b);\n return assert_is_bit(eb);\n }\n EltW assert_is_bit(const EltW& v) const {\n auto vvmv = sub(&v, mul(&v, v));\n return assert0(vvmv);\n }\n\n // bits in their own basis b + 0*1, to allow for some\n // compile-time constant folding\n BitW bit(size_t b) const {\n return BitW((b == 0) ? zero() : one(), zero(), konst(one()));\n }\n\n void bits(size_t n, BitW a[/*n*/], uint64_t x) const {\n for (size_t i = 0; i < n; ++i) {\n a[i] = bit((x >> i) & 1u);\n }\n }\n\n // gates\n BitW lnot(const BitW& x) const {\n // lnot() is a pure representation change that does not\n // involve actual circuit gates\n\n // 1 - x in the standard basis\n return rebase(one(), mone(), x);\n }\n\n BitW land(const BitW* a, const BitW& b) const {\n // a * b in the standard basis\n return mulv(a, b);\n }\n\n // special case of product of a logic value by a field\n // element\n EltW lmul(const BitW* a, const EltW& b) const {\n // a * b in the standard basis\n auto ab = mulv(a, BitW(b, f_));\n return eval(ab);\n }\n EltW lmul(const EltW* b, const BitW& a) const { return lmul(&a, *b); }\n\n BitW lxor(const BitW* a, const BitW& b) const {\n return lxor_aux(*a, b, typename Field::TypeTag());\n }\n BitW lxor(const BitW* a, const BitW* b) const {\n return lxor_aux(*a, *b, typename Field::TypeTag());\n }\n\n BitW lor(const BitW* a, const BitW& b) const {\n auto na = lnot(*a);\n auto nab = land(&na, lnot(b));\n return lnot(nab);\n }\n\n // a => b\n BitW limplies(const BitW* a, const BitW& b) const {\n auto na = lnot(*a);\n return lor(&na, b);\n }\n\n // OR of two quantities known to be mutually exclusive\n BitW lor_exclusive(const BitW* a, const BitW& b) const { return addv(*a, b); }\n\n BitW lxor3(const BitW* a, const BitW* b, const BitW& c) const {\n BitW p = lxor(a, b);\n return lxor(&p, c);\n }\n\n // sha256 Ch(): (x & y) ^ (~x & z);\n BitW lCh(const BitW* x, const BitW* y, const BitW& z) const {\n auto xy = land(x, *y);\n auto nx = lnot(*x);\n return lor_exclusive(&xy, land(&nx, z));\n }\n\n // sha256 Maj(): (x & y) ^ (x & z) ^ (y & z);\n BitW lMaj(const BitW* x, const BitW* y, const BitW& z) const {\n // Interpret as x + y + z >= 2 and compute the carry\n // for an adder in the (p, g) basis\n BitW p = lxor(x, *y);\n BitW g = land(x, *y);\n return lor_exclusive(&g, land(&p, z));\n }\n\n // mux over logic values\n BitW mux(const BitW* control, const BitW* iftrue, const BitW& iffalse) const {\n auto cif = land(control, *iftrue);\n auto nc = lnot(*control);\n auto ciff = land(&nc, *iffalse);\n return lor_exclusive(&cif, ciff);\n }\n\n // mux over backend values\n EltW mux(const BitW* control, const EltW* iftrue, const EltW& iffalse) const {\n auto cif = lmul(control, *iftrue);\n auto nc = lnot(*control);\n auto ciff = lmul(&nc, iffalse);\n return add(&cif, ciff);\n }\n\n // sum_{i0 <= i < i1} f(i)\n EltW add(size_t i0, size_t i1, const std::function& f) const {\n if (i1 <= i0) {\n return konst(0);\n } else if (i1 == i0 + 1) {\n return f(i0);\n } else {\n size_t im = i0 + (i1 - i0) / 2;\n auto lh = add(i0, im, f);\n auto rh = add(im, i1, f);\n return add(&lh, rh);\n }\n }\n\n // lor_exclusive_{i0 <= i < i1} f(i)\n BitW lor_exclusive(size_t i0, size_t i1,\n const std::function& f) const {\n if (i1 <= i0) {\n return bit(0);\n } else if (i1 == i0 + 1) {\n return f(i0);\n } else {\n size_t im = i0 + (i1 - i0) / 2;\n auto lh = lor_exclusive(i0, im, f);\n auto rh = lor_exclusive(im, i1, f);\n return lor_exclusive(&lh, rh);\n }\n }\n\n // and_{i0 <= i < i1} f(i)\n BitW land(size_t i0, size_t i1, const std::function& f) const {\n if (i1 <= i0) {\n return bit(1);\n } else if (i1 == i0 + 1) {\n return f(i0);\n } else {\n size_t im = i0 + (i1 - i0) / 2;\n auto lh = land(i0, im, f);\n auto rh = land(im, i1, f);\n return land(&lh, rh);\n }\n }\n\n // or_{i0 <= i < i1} f(i)\n BitW lor(size_t i0, size_t i1, const std::function& f) const {\n if (i1 <= i0) {\n return bit(0);\n } else if (i1 == i0 + 1) {\n return f(i0);\n } else {\n size_t im = i0 + (i1 - i0) / 2;\n auto lh = lor(i0, im, f);\n auto rh = lor(im, i1, f);\n return lor(&lh, rh);\n }\n }\n\n BitW or_of_and(std::vector> clauses_of_ands) const {\n std::vector ands(clauses_of_ands.size());\n for (size_t i = 0; i < clauses_of_ands.size(); ++i) {\n auto ai = clauses_of_ands[i];\n BitW res = land(0, ai.size(), [&](size_t i) { return ai[i]; });\n ands[i] = res;\n }\n return lor(0, ands.size(), [&](size_t i) { return ands[i]; });\n }\n\n // prod_{i0 <= i < i1} f(i)\n EltW mul(size_t i0, size_t i1, const std::function& f) const {\n if (i1 <= i0) {\n return konst(1);\n } else if (i1 == i0 + 1) {\n return f(i0);\n } else {\n size_t im = i0 + (i1 - i0) / 2;\n auto lh = mul(i0, im, f);\n auto rh = mul(im, i1, f);\n return mul(&lh, rh);\n }\n }\n\n // assert that a + b = c in constant depth\n void assert_sum(size_t w, const BitW c[/*w*/], const BitW a[/*w*/],\n const BitW b[/*w*/]) const {\n // first step of generic_gp_add(): change the basis from\n // (a, b) to (g, p):\n std::vector g(w), p(w), cy(w);\n for (size_t i = 0; i < w; ++i) {\n g[i] = land(&a[i], b[i]);\n p[i] = lxor(&a[i], &b[i]);\n }\n\n // invert the last step of generic_gp_add(): derive\n // cy[i - 1] (called g[i - 1] there) from\n // c[i] and p[i].\n assert_eq(&c[0], p[0]);\n for (size_t i = 1; i < w; ++i) {\n cy[i - 1] = lxor(&c[i], p[i]);\n }\n\n // Verify that applying ripple_scan to g[] produces cy[].\n // Note that ripple_scan() operates in-place on g[]. Here, however, g[] is\n // the input to ripple_scan(), and cy[] is the output.\n assert_eq(&cy[0], g[0]);\n for (size_t i = 1; i + 1 < w; ++i) {\n auto cyp = land(&cy[i - 1], p[i]);\n auto g_cyp = lor_exclusive(&g[i], cyp);\n assert_eq(&cy[i], g_cyp);\n }\n }\n\n // (carry, c) = a + b, returning the carry.\n BitW ripple_carry_add(size_t w, BitW c[/*w*/], const BitW a[/*w*/],\n const BitW b[/*w*/]) const {\n return generic_gp_add(w, c, a, b, &Logic::ripple_scan);\n }\n\n // (carry, c) = a - b, returning the carry.\n BitW ripple_carry_sub(size_t w, BitW c[/*w*/], const BitW a[/*w*/],\n const BitW b[/*w*/]) const {\n return generic_gp_sub(w, c, a, b, &Logic::ripple_scan);\n }\n\n BitW parallel_prefix_add(size_t w, BitW c[/*w*/], const BitW a[/*w*/],\n const BitW b[/*w*/]) const {\n return generic_gp_add(w, c, a, b, &Logic::sklansky_scan);\n }\n\n BitW parallel_prefix_sub(size_t w, BitW c[/*w*/], const BitW a[/*w*/],\n const BitW b[/*w*/]) const {\n return generic_gp_sub(w, c, a, b, &Logic::sklansky_scan);\n }\n\n // w x w -> 2w-bit multiplier c = a * b\n void multiplier(size_t w, BitW c[/*2*w*/], const BitW a[/*w*/],\n const BitW b[/*w*/]) const {\n std::vector t(w);\n for (size_t i = 0; i < w; ++i) {\n if (i == 0) {\n for (size_t j = 0; j < w; ++j) {\n c[j] = land(&a[0], b[j]);\n }\n c[w] = bit(0);\n } else {\n for (size_t j = 0; j < w; ++j) {\n t[j] = land(&a[i], b[j]);\n }\n BitW carry = ripple_carry_add(w, c + i, t.data(), c + i);\n c[i + w] = carry;\n }\n }\n }\n\n // w x w -> 2w-bit polynomial multiplier over gf2. c(x) = a(x) * b(x)\n void gf2_polynomial_multiplier(size_t w, BitW c[/*2*w*/], const BitW a[/*w*/],\n const BitW b[/*w*/]) const {\n std::vector t(w);\n for (size_t k = 0; k < 2 * w; ++k) {\n size_t n = 0;\n for (size_t i = 0; i < w; ++i) {\n if (k >= i && k - i < w) {\n t[n++] = land(&a[i], b[k - i]);\n }\n }\n c[k] = parity(0, n, t.data());\n }\n }\n\n // w x w -> 2w-bit polynomial multiplier over gf2. c(x) = a(x) * b(x)\n // via the Karatsuba recurrence. Only works for w = 2^k.\n void gf2_polynomial_multiplier_karat(size_t w, BitW c[/*2*w*/],\n const BitW a[/*w*/],\n const BitW b[/*w*/]) const {\n check(w == 128 || w == 64 || w < 64, \"input length is not a power of 2\");\n if (w < 64) {\n gf2_polynomial_multiplier(w, c, a, b);\n return;\n } else {\n // We only run this look on w=128 bits. To support odd w,\n std::vector a01(w / 2); /* a0 plus a1 */\n std::vector b01(w / 2); /* b0 plus b1 */\n std::vector ab01(w);\n std::vector a0b0(w);\n std::vector a1b1(w);\n\n for (size_t i = 0; i < w / 2; ++i) {\n a01[i] = lxor(&a[i], a[i + w / 2]);\n b01[i] = lxor(&b[i], b[i + w / 2]);\n }\n\n gf2_polynomial_multiplier_karat(w / 2, &ab01[0], &a01[0], &b01[0]);\n gf2_polynomial_multiplier_karat(w / 2, &a0b0[0], a, b);\n gf2_polynomial_multiplier_karat(w / 2, &a1b1[0], a + w / 2, b + w / 2);\n\n for (size_t i = 0; i < w; ++i) {\n ab01[i] = lxor3(&ab01[i], &a0b0[i], a1b1[i]);\n }\n\n for (size_t i = 0; i < w/2; ++i) {\n c[i] = a0b0[i];\n c[i + w/2] = lxor(&a0b0[i + w/2], ab01[i]);\n c[i + w] = lxor(&ab01[i + w/2], a1b1[i]);\n c[i + 3*w/2] = a1b1[i + w/2];\n }\n }\n }\n\n // Performs field multiplication in GF2^128 defined by the irreducible\n // x^128 + x^7 + x^2 + x + 1. This routine is generated in a sage script that\n // computes a sparse matrix-vector mult via the powers of x^k mod p(x).\n //\n // def make_mulmod(F, n):\n // r = F(1)\n // gen = F.gen()\n // nl = [[] for _ in range(n)]\n // terms = 0\n // for i in range(0, 2*n-1):\n // for j, var in enumerate(r.polynomial().list()):\n // if var == 1:\n // nl[j].append(i)\n // r = r * gen\n // print(nl)\n void gf2_128_mul(v128& c, const v128 a, const v128 b) const {\n const std::vector taps[128] = {\n {0, 128, 249, 254},\n {1, 128, 129, 249, 250, 254},\n {2, 128, 129, 130, 249, 250, 251, 254},\n {3, 129, 130, 131, 250, 251, 252},\n {4, 130, 131, 132, 251, 252, 253},\n {5, 131, 132, 133, 252, 253, 254},\n {6, 132, 133, 134, 253, 254},\n {7, 128, 133, 134, 135, 249},\n {8, 129, 134, 135, 136, 250},\n {9, 130, 135, 136, 137, 251},\n {10, 131, 136, 137, 138, 252},\n {11, 132, 137, 138, 139, 253},\n {12, 133, 138, 139, 140, 254},\n {13, 134, 139, 140, 141},\n {14, 135, 140, 141, 142},\n {15, 136, 141, 142, 143},\n {16, 137, 142, 143, 144},\n {17, 138, 143, 144, 145},\n {18, 139, 144, 145, 146},\n {19, 140, 145, 146, 147},\n {20, 141, 146, 147, 148},\n {21, 142, 147, 148, 149},\n {22, 143, 148, 149, 150},\n {23, 144, 149, 150, 151},\n {24, 145, 150, 151, 152},\n {25, 146, 151, 152, 153},\n {26, 147, 152, 153, 154},\n {27, 148, 153, 154, 155},\n {28, 149, 154, 155, 156},\n {29, 150, 155, 156, 157},\n {30, 151, 156, 157, 158},\n {31, 152, 157, 158, 159},\n {32, 153, 158, 159, 160},\n {33, 154, 159, 160, 161},\n {34, 155, 160, 161, 162},\n {35, 156, 161, 162, 163},\n {36, 157, 162, 163, 164},\n {37, 158, 163, 164, 165},\n {38, 159, 164, 165, 166},\n {39, 160, 165, 166, 167},\n {40, 161, 166, 167, 168},\n {41, 162, 167, 168, 169},\n {42, 163, 168, 169, 170},\n {43, 164, 169, 170, 171},\n {44, 165, 170, 171, 172},\n {45, 166, 171, 172, 173},\n {46, 167, 172, 173, 174},\n {47, 168, 173, 174, 175},\n {48, 169, 174, 175, 176},\n {49, 170, 175, 176, 177},\n {50, 171, 176, 177, 178},\n {51, 172, 177, 178, 179},\n {52, 173, 178, 179, 180},\n {53, 174, 179, 180, 181},\n {54, 175, 180, 181, 182},\n {55, 176, 181, 182, 183},\n {56, 177, 182, 183, 184},\n {57, 178, 183, 184, 185},\n {58, 179, 184, 185, 186},\n {59, 180, 185, 186, 187},\n {60, 181, 186, 187, 188},\n {61, 182, 187, 188, 189},\n {62, 183, 188, 189, 190},\n {63, 184, 189, 190, 191},\n {64, 185, 190, 191, 192},\n {65, 186, 191, 192, 193},\n {66, 187, 192, 193, 194},\n {67, 188, 193, 194, 195},\n {68, 189, 194, 195, 196},\n {69, 190, 195, 196, 197},\n {70, 191, 196, 197, 198},\n {71, 192, 197, 198, 199},\n {72, 193, 198, 199, 200},\n {73, 194, 199, 200, 201},\n {74, 195, 200, 201, 202},\n {75, 196, 201, 202, 203},\n {76, 197, 202, 203, 204},\n {77, 198, 203, 204, 205},\n {78, 199, 204, 205, 206},\n {79, 200, 205, 206, 207},\n {80, 201, 206, 207, 208},\n {81, 202, 207, 208, 209},\n {82, 203, 208, 209, 210},\n {83, 204, 209, 210, 211},\n {84, 205, 210, 211, 212},\n {85, 206, 211, 212, 213},\n {86, 207, 212, 213, 214},\n {87, 208, 213, 214, 215},\n {88, 209, 214, 215, 216},\n {89, 210, 215, 216, 217},\n {90, 211, 216, 217, 218},\n {91, 212, 217, 218, 219},\n {92, 213, 218, 219, 220},\n {93, 214, 219, 220, 221},\n {94, 215, 220, 221, 222},\n {95, 216, 221, 222, 223},\n {96, 217, 222, 223, 224},\n {97, 218, 223, 224, 225},\n {98, 219, 224, 225, 226},\n {99, 220, 225, 226, 227},\n {100, 221, 226, 227, 228},\n {101, 222, 227, 228, 229},\n {102, 223, 228, 229, 230},\n {103, 224, 229, 230, 231},\n {104, 225, 230, 231, 232},\n {105, 226, 231, 232, 233},\n {106, 227, 232, 233, 234},\n {107, 228, 233, 234, 235},\n {108, 229, 234, 235, 236},\n {109, 230, 235, 236, 237},\n {110, 231, 236, 237, 238},\n {111, 232, 237, 238, 239},\n {112, 233, 238, 239, 240},\n {113, 234, 239, 240, 241},\n {114, 235, 240, 241, 242},\n {115, 236, 241, 242, 243},\n {116, 237, 242, 243, 244},\n {117, 238, 243, 244, 245},\n {118, 239, 244, 245, 246},\n {119, 240, 245, 246, 247},\n {120, 241, 246, 247, 248},\n {121, 242, 247, 248, 249},\n {122, 243, 248, 249, 250},\n {123, 244, 249, 250, 251},\n {124, 245, 250, 251, 252},\n {125, 246, 251, 252, 253},\n {126, 247, 252, 253, 254},\n {127, 248, 253, 254},\n };\n gf2k_mul(c.data(), a.data(), b.data(), taps, 128);\n }\n\n // Performs field multiplication in GF2^k using a sparse matrix datastructure.\n void gf2k_mul(BitW c[/*w*/], const BitW a[/*w*/], const BitW b[/*w*/],\n const std::vector M[], size_t w) const {\n std::vector t(w * 2);\n gf2_polynomial_multiplier_karat(w, t.data(), a, b);\n\n std::vector tmp(w);\n for (size_t i = 0; i < w; ++i) {\n size_t n = 0;\n for (auto ti : M[i]) {\n tmp[n++] = t[ti];\n }\n c[i] = parity(0, n, tmp.data());\n }\n }\n\n // a == 0\n BitW eq0(size_t w, const BitW a[/*w*/]) const { return eq0(0, w, a); }\n\n // a == b\n BitW eq(size_t w, const BitW a[/*w*/], const BitW b[/*w*/]) const {\n return eq_reduce(0, w, a, b);\n }\n\n // a < b.\n // Specialization of the subtractor for the case (a - b) < 0\n BitW lt(size_t w, const BitW a[/*w*/], const BitW b[/*w*/]) const {\n if (w == 0) {\n return bit(0);\n } else {\n BitW xeq, xlt;\n lt_reduce(0, w, &xeq, &xlt, a, b);\n return xlt;\n }\n }\n\n // a <= b\n BitW leq(size_t w, const BitW a[/*w*/], const BitW b[/*w*/]) const {\n auto blt = lt(w, b, a);\n return lnot(blt);\n }\n\n // Parallel prefix of various kinds\n template \n void scan(const std::function& op, T x[],\n size_t i0, size_t i1, bool backward = false) const {\n // generic Sklansky scan\n if (i1 - i0 > 1) {\n size_t im = i0 + (i1 - i0) / 2;\n scan(op, x, i0, im, backward);\n scan(op, x, im, i1, backward);\n if (backward) {\n for (size_t i = i0; i < im; ++i) {\n op(&x[i], x[i], x[im]);\n }\n } else {\n for (size_t i = im; i < i1; ++i) {\n op(&x[i], x[im - 1], x[i]);\n }\n }\n }\n }\n\n void scan_and(BitW x[], size_t i0, size_t i1, bool backward = false) const {\n scan(\n [&](BitW* out, const BitW& l, const BitW& r) { *out = land(&l, r); }, x,\n i0, i1, backward);\n }\n\n void scan_or(BitW x[], size_t i0, size_t i1, bool backward = false) const {\n scan(\n [&](BitW* out, const BitW& l, const BitW& r) { *out = lor(&l, r); }, x,\n i0, i1, backward);\n }\n\n void scan_xor(BitW x[], size_t i0, size_t i1, bool backward = false) const {\n scan(\n [&](BitW* out, const BitW& l, const BitW& r) { *out = lxor(&l, r); }, x,\n i0, i1, backward);\n }\n\n template \n bitvec slice(const bitvec& a) const {\n bitvec r;\n for (size_t i = I0; i < I1; ++i) {\n r[i - I0] = a[i];\n }\n return r;\n }\n\n // Little-endian append of A and B. A[0] is the LSB, B starts at\n // position [NA].\n template \n bitvec vappend(const bitvec& a, const bitvec& b) const {\n bitvec r;\n for (size_t i = 0; i < NA; ++i) {\n r[i] = a[i];\n }\n for (size_t i = 0; i < NB; ++i) {\n r[i + NA] = b[i];\n }\n return r;\n }\n\n template \n bool vequal(const bitvec* a, const bitvec& b) const {\n for (size_t i = 0; i < N; ++i) {\n auto eai = eval((*a)[i]);\n auto ebi = eval(b[i]);\n if (eai != ebi) return false;\n }\n return true;\n }\n\n template \n bitvec vbit(uint64_t x) const {\n bitvec r;\n bits(N, r.data(), x);\n return r;\n }\n\n // shorthands for the silly \"template\" notation\n v8 vbit8(uint64_t x) const { return vbit<8>(x); }\n v32 vbit32(uint64_t x) const { return vbit<32>(x); }\n\n template \n bitvec vnot(const bitvec& x) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = lnot(x[i]);\n }\n return r;\n }\n\n template \n bitvec vand(const bitvec* a, const bitvec& b) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = land(&(*a)[i], b[i]);\n }\n return r;\n }\n\n template \n bitvec vand(const BitW* a, const bitvec& b) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = land(a, b[i]);\n }\n return r;\n }\n\n template \n bitvec vor(const bitvec* a, const bitvec& b) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = lor(&(*a)[i], b[i]);\n }\n return r;\n }\n template \n bitvec vor_exclusive(const bitvec* a, const bitvec& b) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = lor_exclusive(&(*a)[i], b[i]);\n }\n return r;\n }\n template \n bitvec vxor(const bitvec* a, const bitvec& b) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = lxor(&(*a)[i], b[i]);\n }\n return r;\n }\n\n template \n bitvec vCh(const bitvec* x, const bitvec* y,\n const bitvec& z) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = lCh(&(*x)[i], &(*y)[i], z[i]);\n }\n return r;\n }\n template \n bitvec vMaj(const bitvec* x, const bitvec* y,\n const bitvec& z) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = lMaj(&(*x)[i], &(*y)[i], z[i]);\n }\n return r;\n }\n\n template \n bitvec vxor3(const bitvec* x, const bitvec* y,\n const bitvec& z) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = lxor3(&(*x)[i], &(*y)[i], z[i]);\n }\n return r;\n }\n\n template \n bitvec vshr(const bitvec& a, size_t shift, size_t b = 0) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n if (i + shift < N) {\n r[i] = a[i + shift];\n } else {\n r[i] = bit(b);\n }\n }\n return r;\n }\n\n template \n bitvec vshl(const bitvec& a, size_t shift, size_t b = 0) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n if (i >= shift) {\n r[i] = a[i - shift];\n } else {\n r[i] = bit(b);\n }\n }\n return r;\n }\n\n template \n bitvec vrotr(const bitvec& a, size_t b) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = a[(i + b) % N];\n }\n return r;\n }\n\n template \n bitvec vrotl(const bitvec& a, size_t b) const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[(i + b) % N] = a[i];\n }\n return r;\n }\n\n template \n bitvec vadd(const bitvec& a, const bitvec& b) const {\n bitvec r;\n (void)parallel_prefix_add(N, &r[0], &a[0], &b[0]);\n return r;\n }\n template \n bitvec vadd(const bitvec& a, uint64_t val) const {\n return vadd(a, vbit(val));\n }\n\n template \n BitW veq(const bitvec& a, const bitvec& b) const {\n return eq(N, a.data(), b.data());\n }\n template \n BitW veq(const bitvec& a, uint64_t val) const {\n auto v = vbit(val);\n return veq(a, v);\n }\n template \n BitW vlt(const bitvec* a, const bitvec& b) const {\n return lt(N, (*a).data(), b.data());\n }\n template \n BitW vlt(const bitvec& a, uint64_t val) const {\n auto v = vbit(val);\n return vlt(&a, v);\n }\n template \n BitW vlt(uint64_t a, const bitvec& b) const {\n auto va = vbit(a);\n return vlt(&va, b);\n }\n template \n BitW vleq(const bitvec* a, const bitvec& b) const {\n return leq(N, (*a).data(), b.data());\n }\n template \n BitW vleq(const bitvec& a, uint64_t val) const {\n auto v = vbit(val);\n return vleq(&a, v);\n }\n\n // (a ^ val) & mask == 0\n template \n BitW veqmask(const bitvec* a, uint64_t mask, const bitvec& val) const {\n auto r = vxor(a, val);\n size_t n = pack(mask, N, &r[0]);\n return eq0(0, n, &r[0]);\n }\n\n template \n BitW veqmask(const bitvec& a, uint64_t mask, uint64_t val) const {\n auto v = vbit(val);\n return veqmask(&a, mask, v);\n }\n\n // I/O. This is a hack which only works if the backend supports\n // bk_->{input,output}. Because C++ templates are lazily expanded,\n // this class compiles even with backends that do not support I/O,\n // as long as you don't expand vinput(), voutput().\n BitW input() const { return BitW(bk_->input(), f_); }\n void output(const BitW& x, size_t i) const { bk_->output(eval(x), i); }\n size_t wire_id(const BitW& v) const { return bk_->wire_id(v.x); }\n size_t wire_id(const EltW& x) const { return bk_->wire_id(x); }\n\n template \n bitvec vinput() const {\n bitvec r;\n for (size_t i = 0; i < N; ++i) {\n r[i] = input();\n }\n return r;\n }\n\n template \n void voutput(const bitvec& x, size_t i0) const {\n for (size_t i = 0; i < N; ++i) {\n output(x[i], i + i0);\n }\n }\n\n template \n void vassert0(const bitvec& x) const {\n for (size_t i = 0; i < N; ++i) {\n (void)assert0(x[i]);\n }\n }\n\n template \n void vassert_eq(const bitvec* x, const bitvec& y) const {\n for (size_t i = 0; i < N; ++i) {\n (void)assert_eq(&(*x)[i], y[i]);\n }\n }\n\n template \n void vassert_eq(const bitvec& x, uint64_t y) const {\n auto v = vbit(y);\n vassert_eq(&x, v);\n }\n\n template \n void vassert_is_bit(const bitvec& a) const {\n for (size_t i = 0; i < N; ++i) {\n (void)assert_is_bit(a[i]);\n }\n }\n\n private:\n // return one quad gate for the product eval(a)*eval(b),\n // optimizing some \"obvious\" cases.\n BitW mulv(const BitW* a, const BitW& b) const {\n if (a->c1 == zero()) {\n return rebase(zero(), a->c0, b);\n } else if (b.c1 == zero()) {\n return mulv(&b, *a);\n } else {\n // Avoid creating the intermediate term 1 * a.x * b.x which is\n // likely a useless node. Moreover, two nodes (k1 * a.x * b.x)\n // and (k2 * a.x * b.x) will detect the common subexpression\n // (a.x * b.x), which will confusingly increment the\n // common-subexpression counter.\n EltW x = axy(mulf(a->c1, b.c1), &a->x, b.x);\n x = axpy(&x, mulf(a->c0, b.c1), b.x);\n x = axpy(&x, mulf(a->c1, b.c0), a->x);\n x = apy(x, mulf(a->c0, b.c0));\n return BitW(x, f_);\n }\n }\n\n BitW addv(const BitW& a, const BitW& b) const {\n if (a.c1 == zero()) {\n return BitW(addf(a.c0, b.c0), b.c1, b.x);\n } else if (b.c1 == zero()) {\n return addv(b, a);\n } else {\n EltW x = ax(a.c1, a.x);\n auto axb = ax(b.c1, b.x);\n x = add(&x, axb);\n x = apy(x, addf(a.c0, b.c0));\n return BitW(x, f_);\n }\n }\n\n BitW lxor_aux(const BitW& a, const BitW& b, PrimeFieldTypeTag tt) const {\n // a * b in the xor basis TRUE -> -1, FALSE -> 1\n // map a, b from standard basis to xor basis\n Elt mtwo = f_.negf(f_.two());\n Elt half = f_.half();\n Elt mhalf = f_.negf(half);\n\n BitW a1 = rebase(one(), mtwo, a);\n BitW b1 = rebase(one(), mtwo, b);\n BitW p = mulv(&a1, b1);\n return rebase(half, mhalf, p);\n }\n BitW lxor_aux(const BitW& a, const BitW& b, BinaryFieldTypeTag tt) const {\n return addv(a, b);\n }\n\n\n size_t pack(uint64_t mask, size_t n, BitW a[/*n*/]) const {\n size_t j = 0;\n for (size_t i = 0; i < n; ++i) {\n if (mask & 1) {\n a[j++] = a[i];\n }\n mask >>= 1;\n }\n return j;\n }\n\n // carry-propagation equations\n // (g0, p0) + (g1, p1) = (g1 | (g0 & p1), p0 & p1)\n // Accumulate in-place into (g1, p1).\n //\n // We use the property that g1 and p1 are mutually exclusive (g1&p1\n // is false), and therefore g1 and (g0 & p1) are also mutually\n // exclusive.\n void gp_reduce(const BitW& g0, const BitW& p0, BitW* g1, BitW* p1) const {\n auto g0p1 = land(&g0, *p1);\n *g1 = lor_exclusive(g1, g0p1);\n *p1 = land(&p0, *p1);\n }\n\n // ripple carry propagation\n void ripple_scan(std::vector& g, std::vector& p, size_t i0,\n size_t i1) const {\n for (size_t i = i0 + 1; i < i1; ++i) {\n gp_reduce(g[i - 1], p[i - 1], &g[i], &p[i]);\n }\n }\n\n // parallel-prefix carry propagation, Sklansky-style [1960]\n void sklansky_scan(std::vector& g, std::vector& p, size_t i0,\n size_t i1) const {\n if (i1 - i0 > 1) {\n size_t im = i0 + (i1 - i0) / 2;\n sklansky_scan(g, p, i0, im);\n sklansky_scan(g, p, im, i1);\n for (size_t i = im; i < i1; ++i) {\n gp_reduce(g[im - 1], p[im - 1], &g[i], &p[i]);\n }\n }\n }\n\n // generic add in generate/propagate form, parametrized\n // by the scan primitive.\n //\n // (carry, c) = a + b\n BitW generic_gp_add(size_t w, BitW c[/*w*/], const BitW a[/*w*/],\n const BitW b[/*w*/],\n void (Logic::*scan)(std::vector& /*g*/,\n std::vector& /*p*/,\n size_t /*i0*/, size_t /*i1*/)\n const) const {\n if (w == 0) {\n return bit(0);\n } else {\n std::vector g(w), p(w);\n for (size_t i = 0; i < w; ++i) {\n g[i] = land(&a[i], b[i]);\n p[i] = lxor(&a[i], b[i]);\n c[i] = p[i];\n }\n (this->*scan)(g, p, 0, w);\n for (size_t i = 1; i < w; ++i) {\n c[i] = lxor(&c[i], g[i - 1]);\n }\n return g[w - 1];\n }\n }\n\n BitW generic_gp_sub(size_t w, BitW c[/*w*/], const BitW a[/*w*/],\n const BitW b[/*w*/],\n void (Logic::*scan)(std::vector& /*g*/,\n std::vector& /*p*/,\n size_t /*i0*/, size_t /*i1*/)\n const) const {\n // implement as ~(~a + b)\n std::vector t(w);\n for (size_t j = 0; j < w; ++j) {\n t[j] = lnot(a[j]);\n }\n BitW carry = generic_gp_add(w, c, t.data(), b, scan);\n for (size_t j = 0; j < w; ++j) {\n c[j] = lnot(c[j]);\n }\n return carry;\n }\n\n // Recursion for the a < b comparison.\n // Let a = (a1, a0) and b = (b1, b0). Then:\n //\n // a == b iff a1 == b1 && a0 == b0\n // a < b iff a1 < b1 || (a1 == b1 && a0 < b0)\n void lt_reduce(size_t i0, size_t i1, BitW* xeq, BitW* xlt,\n const BitW a[/*w*/], const BitW b[/*w*/]) const {\n if (i1 - i0 > 1) {\n BitW eq0, eq1, lt0, lt1;\n size_t im = i0 + (i1 - i0) / 2;\n lt_reduce(i0, im, &eq0, <0, a, b);\n lt_reduce(im, i1, &eq1, <1, a, b);\n *xeq = land(&eq1, eq0);\n auto lt0_and_eq1 = land(&eq1, lt0);\n *xlt = lor_exclusive(<1, lt0_and_eq1);\n } else {\n auto axb = lxor(&a[i0], b[i0]);\n *xeq = lnot(axb);\n auto na = lnot(a[i0]);\n *xlt = land(&na, b[i0]);\n }\n }\n\n BitW parity(size_t i0, size_t i1, const BitW a[]) const {\n if (i1 <= i0) {\n return bit(0);\n } else if (i1 == i0 + 1) {\n return a[i0];\n } else {\n size_t im = i0 + (i1 - i0) / 2;\n auto lp = parity(i0, im, a);\n auto rp = parity(im, i1, a);\n return lxor(&lp, rp);\n }\n }\n\n BitW eq0(size_t i0, size_t i1, const BitW a[]) const {\n if (i1 <= i0) {\n return bit(1);\n } else if (i1 == i0 + 1) {\n return lnot(a[i0]);\n } else {\n size_t im = i0 + (i1 - i0) / 2;\n auto le = eq0(i0, im, a);\n auto re = eq0(im, i1, a);\n return land(&le, re);\n }\n }\n\n BitW eq_reduce(size_t i0, size_t i1, const BitW a[], const BitW b[]) const {\n if (i1 <= i0) {\n return bit(1);\n } else if (i1 == i0 + 1) {\n return lnot(lxor(&a[i0], b[i0]));\n } else {\n size_t im = i0 + (i1 - i0) / 2;\n auto le = eq_reduce(i0, im, a, b);\n auto re = eq_reduce(im, i1, a, b);\n return land(&le, re);\n }\n }\n\n const Backend* bk_;\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_LOGIC_H_\n"], ["/longfellow-zk/lib/circuits/jwt/jwt_witness.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_JWT_JWT_WITNESS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_JWT_JWT_WITNESS_H_\n\n#include \n#include \n#include \n#include \n#include \n\n#include \"arrays/dense.h\"\n#include \"circuits/base64/decode_util.h\"\n#include \"circuits/ecdsa/verify_witness.h\"\n#include \"circuits/jwt/jwt_constants.h\"\n#include \"circuits/logic/bit_plucker_encoder.h\"\n#include \"circuits/sha/flatsha256_witness.h\"\n#include \"util/log.h\"\n\nnamespace proofs {\n\n/* This struct allows a verifier to express which attribute and value the prover\n * must claim. */\nstruct OpenedAttribute {\n uint8_t id[32];\n uint8_t value[64];\n size_t id_len, value_len;\n};\n\ntemplate \nclass JWTWitness {\n using Field = typename EC::Field;\n using Elt = typename Field::Elt;\n using Nat = typename Field::N;\n using EcdsaWitness = VerifyWitness3;\n const EC& ec_;\n\n public:\n Elt e_, r_, s_;\n EcdsaWitness sig_;\n\n uint8_t preimage_[64 * kMaxJWTSHABlocks];\n uint8_t e_bits_[256];\n FlatSHA256Witness::BlockWitness sha_bw_[kMaxJWTSHABlocks];\n uint8_t numb_; /* Number of the correct sha block. */\n uint8_t na_; /* Number of attributes. */\n size_t payload_ind_, payload_len_;\n std::vector attr_ind_;\n std::vector attr_id_len_;\n std::vector attr_value_len_;\n\n explicit JWTWitness(const EC& ec, const ScalarField& Fn)\n : ec_(ec), sig_(Fn, ec) {}\n\n void fill_witness(DenseFiller& filler) const {\n filler.push_back(r_);\n filler.push_back(s_);\n filler.push_back(e_);\n sig_.fill_witness(filler);\n\n // Write the message.\n for (size_t i = 0; i < 64 * kMaxJWTSHABlocks; ++i) {\n filler.push_back(preimage_[i], 8, ec_.f_);\n }\n\n for (size_t i = 0; i < 256; ++i) {\n filler.push_back(e_bits_[i], 1, ec_.f_);\n }\n\n for (size_t j = 0; j < kMaxJWTSHABlocks; ++j) {\n fill_sha(filler, sha_bw_[j]);\n }\n\n filler.push_back(numb_, 8, ec_.f_);\n\n for (size_t i = 0; i < na_; ++i) {\n filler.push_back(attr_ind_[i], kJWTIndexBits, ec_.f_);\n filler.push_back(attr_id_len_[i], 8, ec_.f_);\n filler.push_back(attr_value_len_[i], 8, ec_.f_);\n }\n\n filler.push_back(payload_ind_, kJWTIndexBits, ec_.f_);\n filler.push_back(payload_len_, kJWTIndexBits, ec_.f_);\n }\n\n void fill_sha(DenseFiller& filler,\n const FlatSHA256Witness::BlockWitness& bw) const {\n BitPluckerEncoder BPENC(ec_.f_);\n for (size_t k = 0; k < 48; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.outw[k]));\n }\n for (size_t k = 0; k < 64; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.oute[k]));\n filler.push_back(BPENC.mkpacked_v32(bw.outa[k]));\n }\n for (size_t k = 0; k < 8; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.h1[k]));\n }\n }\n\n // Transform from u32 be (i.e., be[0] is the most significant nibble)\n // into nat form, which requires first converting to le byte order.\n Nat nat_from_u32(const uint32_t be[]) const {\n uint8_t tmp[Nat::kBytes];\n const size_t top = Nat::kBytes / 4;\n for (size_t i = 0; i < Nat::kBytes; ++i) {\n tmp[i] = (be[top - i / 4 - 1] >> ((i % 4) * 8)) & 0xff;\n }\n return Nat::of_bytes(tmp);\n }\n\n // Transform from u8 be (i.e., be[31] is the most significant byte) into\n // nat form, which requires first converting to le byte order.\n Nat nat_from_be(const uint8_t be[/* Nat::kBytes */]) {\n uint8_t tmp[Nat::kBytes];\n // Transform into byte-wise le representation.\n for (size_t i = 0; i < Nat::kBytes; ++i) {\n tmp[i] = be[Nat::kBytes - i - 1];\n }\n return Nat::of_bytes(tmp);\n }\n\n bool compute_witness(std::string jwt, Elt pkX, Elt pkY,\n std::vector attrs) {\n size_t dot = jwt.find_first_of('.');\n size_t dot2 = jwt.find_first_of('.', dot + 1);\n if (dot == std::string::npos || dot2 == std::string::npos) {\n log(ERROR, \"JWT is not in the format of header.payload.signature\");\n return false;\n }\n auto hdr = jwt.substr(0, dot);\n auto pld = jwt.substr(dot + 1, dot2 - dot - 1);\n auto rest = jwt.substr(dot2 + 1);\n auto msg = jwt.substr(0, dot2);\n payload_len_ = pld.size();\n payload_ind_ = dot + 1;\n\n if (payload_len_ > kMaxJWTSHABlocks * 64) {\n log(ERROR, \"JWT payload is too large\");\n return false;\n }\n\n size_t tilde = rest.find_first_of('~');\n if (tilde == std::string::npos) {\n log(ERROR, \"JWT is not in the format of header.payload.signature~epoch\");\n return false;\n }\n auto sig = rest.substr(0, tilde);\n auto claims = rest.substr(tilde + 1);\n\n FlatSHA256Witness::transform_and_witness_message(\n msg.size(), reinterpret_cast(msg.data()),\n kMaxJWTSHABlocks, numb_, preimage_, sha_bw_);\n\n Nat ne = nat_from_u32(sha_bw_[numb_ - 1].h1);\n e_ = ec_.f_.to_montgomery(ne);\n\n std::vector sigb;\n sigb.reserve(ec_.f_.kBytes * 2);\n if (!base64_decode_url(sig, sigb) || sigb.size() < ec_.f_.kBytes * 2) {\n log(ERROR, \"signature is not in the format of base64url\");\n return false;\n }\n Nat nr = nat_from_be(&sigb[0]);\n Nat ns = nat_from_be(&sigb[ec_.f_.kBytes]);\n\n r_ = ec_.f_.to_montgomery(nr);\n s_ = ec_.f_.to_montgomery(ns);\n if (!sig_.compute_witness(pkX, pkY, ne, nr, ns)) {\n log(ERROR, \"signature verification failed\");\n return false;\n }\n\n for (size_t i = 0; i < 256; ++i) {\n e_bits_[i] = ne.bit(i);\n }\n\n // Find the positions of each of the attributes.\n na_ = attrs.size();\n std::vector payload;\n payload.reserve(pld.size());\n if (!base64_decode_url(pld, payload)) {\n log(ERROR, \"JWT payload is not in the format of base64url\");\n return false;\n }\n std::string str((const char*)payload.data(), payload.size());\n for (size_t i = 0; i < na_; ++i) {\n size_t ind = str.find((const char*)attrs[i].id, 0, attrs[i].id_len);\n if (ind == std::string::npos) {\n log(ERROR, \"Could not find attribute %.*s\", attrs[i].id_len,\n attrs[i].id);\n return false;\n }\n size_t vstart = ind + attrs[i].id_len + 3;\n size_t vind =\n str.find((const char*)attrs[i].value, vstart, attrs[i].value_len);\n if (vind == std::string::npos || vind != vstart) {\n log(ERROR, \"Could not find attribute value %.*s\", attrs[i].value_len,\n attrs[i].value);\n return false;\n }\n attr_ind_.push_back(ind);\n attr_id_len_.push_back(attrs[i].id_len);\n attr_value_len_.push_back(attrs[i].value_len);\n }\n\n return true;\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_JWT_JWT_WITNESS_H_\n"], ["/longfellow-zk/lib/circuits/logic/bit_adder.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_ADDER_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_ADDER_H_\n\n#include \n\n#include \n#include \n\n// Circuit element that maps bitvec V to a field element E\n// in such a way that:\n//\n// 1) addition can be performed efficiently, e.g. as field\n// addition or field multiplication\n// 2) given and E that is the sum of K bitvecs, a simple circuit\n// asserts that E = A mod 2^N\nnamespace proofs {\n\ntemplate \nclass BitAdderAux;\n\n// Use the additive group in fields with large characteristic\ntemplate \nclass BitAdderAux {\n public:\n using Field = typename Logic::Field;\n using BitW = typename Logic::BitW;\n using EltW = typename Logic::EltW;\n using Elt = typename Field::Elt;\n using BV = typename Logic::template bitvec;\n const Logic& l_;\n\n explicit BitAdderAux(const Logic& l) : l_(l) {}\n\n EltW as_field_element(const BV& v) const {\n const Logic& L = l_; // shorthand\n constexpr uint64_t uno = 1;\n EltW r = L.konst(L.zero());\n for (size_t i = 0; i < N; ++i) {\n auto vi = L.eval(v[i]);\n r = L.axpy(&r, L.elt(uno << i), vi);\n }\n return r;\n }\n\n EltW add(const EltW* a, const EltW& b) const { return l_.add(a, b); }\n EltW add(const BV& a, const BV& b) const {\n auto a_fe = as_field_element(a);\n auto b_fe = as_field_element(b);\n return add(&a_fe, b_fe);\n }\n EltW add(const std::vector& a) const {\n return l_.add(0, a.size(),\n [&](size_t i) { return as_field_element(a[i]); });\n }\n\n // assert that B = A + i*2^N for 0 <= i < k\n void assert_eqmod(const BV& a, const EltW& b, size_t k) const {\n const Logic& L = l_; // shorthand\n constexpr uint64_t uno = 1;\n EltW z = L.sub(&b, as_field_element(a));\n EltW zz = L.mul(0, k, [&](size_t i) {\n return L.sub(&z, L.konst((uno << N) * i));\n });\n L.assert0(zz);\n }\n};\n\n// Use the multiplicative group in GF(2^k)\ntemplate \nclass BitAdderAux {\n public:\n using Field = typename Logic::Field;\n using BitW = typename Logic::BitW;\n using EltW = typename Logic::EltW;\n using Elt = typename Field::Elt;\n using BV = typename Logic::template bitvec;\n const Logic& l_;\n\n explicit BitAdderAux(const Logic& l) : l_(l) {\n const Logic& L = l_; // shorthand\n const Field& F = l_.f_; // shorthand\n\n // assume that X is a root of unity of order large enough.\n Elt alpha = F.x();\n\n for (size_t i = 0; i < N; ++i) {\n alpha_2_i_[i] = alpha;\n alpha = L.mulf(alpha, alpha);\n }\n alpha_2_N_ = alpha;\n }\n\n EltW as_field_element(const BV& v) const {\n const Logic& L = l_; // shorthand\n return L.mul(0, N, [&](size_t i) {\n auto a2i = L.konst(alpha_2_i_[i]);\n return L.mux(&v[i], &a2i, L.konst(L.one()));\n });\n }\n\n EltW add(const EltW* a, const EltW& b) const { return l_.mul(a, b); }\n EltW add(const BV& a, const BV& b) const {\n auto a_fe = as_field_element(a);\n auto b_fe = as_field_element(b);\n return add(&a_fe, b_fe);\n }\n EltW add(const std::vector& a) const {\n return l_.mul(0, a.size(),\n [&](size_t i) { return as_field_element(a[i]); });\n }\n\n // assert that B = A + alpha^(i*2^N) for 0 <= i < k\n void assert_eqmod(const BV& a, const EltW& b, size_t k) const {\n const Logic& L = l_; // shorthand\n const Field& F = l_.f_; // shorthand\n\n std::vector p(k);\n p[0] = F.one();\n for (size_t i = 1; i < k; ++i) {\n p[i] = F.mulf(alpha_2_N_, p[i - 1]);\n }\n EltW aa = as_field_element(a);\n EltW prod = L.mul(0, k, [&](size_t i) {\n auto pi = L.konst(p[i]);\n return L.sub(&b, L.mul(&pi, aa));\n });\n L.assert0(prod);\n }\n\n private:\n Elt alpha_2_i_[N + 1];\n Elt alpha_2_N_;\n};\n\ntemplate \nusing BitAdder = BitAdderAux;\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_ADDER_H_\n"], ["/longfellow-zk/lib/gf2k/gf2_128.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_GF2K_GF2_128_H_\n#define PRIVACY_PROOFS_ZK_LIB_GF2K_GF2_128_H_\n\n#include \n\n#include \n#include \n#include \n#include \n#include \n\n#include \"gf2k/gf2poly.h\"\n#include \"gf2k/sysdep.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n\nstruct BinaryFieldTypeTag {};\n\ntemplate \nclass GF2_128 {\n // avoid writing static_cast(1) all the time.\n static constexpr size_t k1 = 1;\n\n public:\n using TypeTag = BinaryFieldTypeTag;\n\n // Fast representation of the field element via the system-dependent\n // SIMD type.\n using N = gf2_128_elt_t;\n\n // \"Slow\" representation of the field element as array of\n // C++ integral types.\n using N1 = GF2Poly<2>;\n\n static constexpr size_t kNPolyEvaluationPoints = 6;\n static constexpr size_t kLogBits = 7;\n static constexpr size_t kBits = k1 << kLogBits;\n static constexpr size_t kBytes = kBits / 8u;\n\n static constexpr size_t kSubFieldLogBits = subfield_log_bits;\n static constexpr size_t kSubFieldBits = k1 << kSubFieldLogBits;\n static constexpr size_t kSubFieldBytes = kSubFieldBits / 8u;\n\n static_assert(kBits == 8u * kBytes);\n static_assert(kSubFieldBits == 8u * kSubFieldBytes);\n static constexpr bool kCharacteristicTwo = true;\n\n struct Elt {\n N n;\n\n Elt() : n{} {}\n explicit Elt(N n_) : n(n_) {}\n\n // Don't bother using SIMD instructions for comparisons,\n // otherwise we have to complicate the sysdep API surface.\n // Unpack into uint64[2] and compute manually.\n bool operator==(const Elt& y) const { return unpack() == y.unpack(); }\n bool operator!=(const Elt& y) const { return !operator==(y); }\n\n // Returns the coefficient of x^i in the polynomial.\n uint8_t operator[](size_t i) const {\n auto n1 = uint64x2_of_gf2_128(n);\n if (i < 64) {\n return static_cast((n1[0] >> i) & 0x1);\n } else if (i < 128) {\n return static_cast((n1[1] >> (i - 64)) & 0x1);\n } else {\n return 0;\n }\n }\n\n N1 unpack() const { return N1(uint64x2_of_gf2_128(n)); }\n };\n\n explicit GF2_128() {\n kone_ = of_scalar_field(0b1);\n kx_ = of_scalar_field(0b10);\n\n // x^{-1} = x^127 + x^6 + x + 1\n std::array invx = {\n (1ull << 6) | (1ull << 1) | (1ull << 0),\n (1ull << (127 - 64)),\n };\n kinvx_ = of_scalar_field(invx);\n\n Elt g = subfield_generator();\n\n // basis of the subfield = {1, g, g^2, ...}\n beta_[0] = one();\n for (size_t i = 1; i < kSubFieldBits; ++i) {\n beta_[i] = mulf(beta_[i - 1], g);\n }\n\n // Reduce the basis to row-echelon form\n beta_ref();\n\n // Evaluation points. We use g^i for these as well\n poly_evaluation_points_[0] = zero();\n Elt gi = one();\n for (size_t i = 1; i < kNPolyEvaluationPoints; ++i) {\n poly_evaluation_points_[i] = gi;\n mul(gi, g);\n }\n\n for (size_t i = 1; i < kNPolyEvaluationPoints; i++) {\n for (size_t k = kNPolyEvaluationPoints; k-- > i;) {\n auto dx =\n subf(poly_evaluation_points_[k], poly_evaluation_points_[k - i]);\n check(dx != zero(), \"dx != zero()\");\n newton_denominators_[k][i] = invertf(dx);\n }\n }\n }\n\n GF2_128(const GF2_128&) = delete;\n GF2_128& operator=(const GF2_128&) = delete;\n\n // The bits of u are the coordinates with respect to the basis\n // beta_[] of the subfield.\n Elt of_scalar(uint64_t u) const {\n Elt t = zero();\n for (size_t k = 0; k < kSubFieldBits; ++k, u >>= 1) {\n if (u & 1) {\n add(t, beta_[k]);\n }\n }\n check(u == 0, \"of_scalar(u), too many bits\");\n return t;\n }\n\n Elt of_scalar_field(uint64_t n) const {\n std::array u = {n, 0};\n return of_scalar_field(u);\n }\n Elt of_scalar_field(const std::array& u) const {\n return Elt(gf2_128_of_uint64x2(u));\n }\n\n // The base_only flag is a placeholder that takes meaning when F is an\n // extension field.\n std::optional of_bytes_field(const uint8_t ab[/* kBytes */],\n bool base_only = true) const {\n N1 an = N1::of_bytes(ab);\n return of_scalar_field(an.u64());\n }\n\n void to_bytes_field(uint8_t ab[/* kBytes */], const Elt& x) const {\n x.unpack().to_bytes(ab);\n }\n\n bool in_subfield(Elt e) const {\n auto eu = solve(e);\n return eu.first == N1{};\n }\n\n std::optional of_bytes_subfield(\n const uint8_t ab[/* kSubFieldBytes */]) const {\n uint64_t u = 0;\n for (size_t i = kSubFieldBytes; i-- > 0;) {\n u <<= 8;\n u |= ab[i];\n }\n return of_scalar(u);\n }\n\n void to_bytes_subfield(uint8_t ab[/* kSubFieldBytes */], const Elt& x) const {\n auto eu = solve(x);\n check(eu.first == N1{}, \"eu.first == N1{}\");\n uint64_t u = eu.second;\n for (size_t i = 0; i < kSubFieldBytes; ++i) {\n ab[i] = u & 0xFFu;\n u >>= 8;\n }\n }\n\n // functional interface\n Elt addf(const Elt& x, const Elt& y) const {\n return Elt{gf2_128_add(x.n, y.n)};\n }\n Elt subf(const Elt& x, const Elt& y) const {\n return Elt{gf2_128_add(x.n, y.n)};\n }\n Elt mulf(const Elt& x, const Elt& y) const {\n return Elt{gf2_128_mul(x.n, y.n)};\n }\n Elt negf(const Elt& x) const { return x; }\n\n // two-operands interface\n void add(Elt& a, const Elt& y) const { a = addf(a, y); }\n void sub(Elt& a, const Elt& y) const { a = subf(a, y); }\n void mul(Elt& a, const Elt& y) const { a = mulf(a, y); }\n void neg(Elt& a) const { /* noop */ }\n void invert(Elt& a) const { a = invertf(a); }\n\n Elt zero() const { return Elt{}; }\n Elt one() const { return kone_; }\n Elt mone() const { return kone_; }\n Elt x() const { return kx_; }\n Elt invx() const { return kinvx_; }\n Elt beta(size_t i) const {\n check(i < kSubFieldBits, \"i < kSubFieldBits\");\n return beta_[i];\n }\n\n Elt poly_evaluation_point(size_t i) const {\n check(i < kNPolyEvaluationPoints, \"i < kNPolyEvaluationPoints\");\n return poly_evaluation_points_[i];\n }\n\n // return (X[k] - X[k - i])^{-1}, were X[i] is the\n // i-th poly evalaluation point.\n Elt newton_denominator(size_t k, size_t i) const {\n check(k < kNPolyEvaluationPoints, \"k < kNPolyEvaluationPoints\");\n check(i <= k, \"i <= k\");\n check(k != (k - i), \"k != (k - i)\");\n return newton_denominators_[k][i];\n }\n\n Elt invertf(Elt x) const {\n N1 a = x.unpack();\n // Let POLY be the generator of GF(2^128) as GF(2)[x]/(POLY(x)).\n // The Euclid algorithm would initialize B = POLY, but we cannot\n // store POLY in one N1. Instead, we use the invariant that B is\n // always \"odd\" throughout the algorithm, and we represent B =\n // BM1OX * X + 1, or BM1OX = (B - 1) / X. For B = POLY, BM1OX =\n // 1/X initially.\n N1 bm1ox = kinvx_.unpack();\n Elt u = one();\n Elt v = zero();\n while (a != N1(0)) {\n if (a.bit(0) == 0) {\n a.shiftr(1);\n byinvx(u);\n } else {\n // Now A is \"odd\". Write A = AM1OX * X + 1. This operation\n // be done in-place in the A variable, but we use another\n // name for clarity.\n N1 am1ox = a;\n am1ox.shiftr(1);\n\n // Normalize to the partial order degree(A) >= degree(B).\n // We use the stronger total order \"<\" which is consistent\n // with the partial order that we care about.\n if (am1ox < bm1ox) {\n std::swap(am1ox, bm1ox);\n std::swap(u, v);\n }\n am1ox.sub(bm1ox);\n sub(u, v);\n byinvx(u);\n a = am1ox;\n }\n }\n return v;\n }\n\n private:\n Elt kone_;\n Elt kx_;\n Elt kinvx_; // x^{-1}\n Elt beta_[kSubFieldBits]; // basis of the subfield viewed as a\n // vector space over GF(2)\n\n // LU decomposition of beta_, in unpacked format. We store L^{-1}\n // instead of L, see comments in beta_ref()\n N1 u_[kSubFieldBits];\n uint64_t linv_[kSubFieldBits];\n\n // ldnz_[i] stores the column index of the leading nonzero in u_[i].\n // This array is in principle redundant, since one can always\n // reconstruct it from u_, but we cache it for efficiency.\n size_t ldnz_[kSubFieldBits];\n\n Elt poly_evaluation_points_[kNPolyEvaluationPoints];\n Elt newton_denominators_[kNPolyEvaluationPoints][kNPolyEvaluationPoints];\n\n void byinvx(Elt& u) const { mul(u, kinvx_); }\n\n Elt subfield_generator() {\n // Let k = kSubFieldLogBits and n = kLogBits.\n // Let x be the generator of Field.\n\n // The generator r of the subfield is then\n // x^{(2^{2^n}-1)/(2^{2^k}-1)}\n\n // Compute r via the identity\n // (2^{2^n}-1)/(2^{2^k}-1) =\n // (2^{2^k}+1)*(2^{2^(k+1)}+1)*...*(2^{2^(n-1)}+1)\n Elt r(kx_);\n for (size_t i = kSubFieldLogBits; i < kLogBits; ++i) {\n // s <- r^{2^(2^i))\n Elt s(r);\n for (size_t j = 0; j < (1u << i); ++j) {\n mul(s, s);\n }\n // r <- r^{2^(2^i)+1)\n mul(r, s);\n }\n\n return r;\n }\n\n // beta_ref() is a just a variant of Gaussian elimination, but\n // because many such variants exist, we now explain the exact\n // mechanics of the algorithm.\n //\n // The problem that we need to solve is the inversion of\n // of_scalar(): given e = of_scalar(u), solve for u. The constraint\n // we have is that e and u are arrays of bits, conveniently stored\n // in uint64_t, and ideally we want to perform parallel bitwise\n // operations, as opposed to extracting individual bits.\n //\n // Consider the following block matrix, or tableau:\n //\n // [ B | -I ]\n // [ ------ ]\n // [ e | u ]\n //\n // Here e and u are reinterpreted as row vectors of GF(2) elements;\n // I is the identity matrix; B is such that B[i] (the i-th row of b)\n // is beta(i) (the i-th element of the basis of the subfield), and\n // beta(i) is interpreted as a row vector of 128 GF(2) elements.\n // (The minus sign in -I is irrelevant over GF(2), but would be\n // necessary over other fields.)\n //\n // We now postulate that the only allowed operation on the tableau\n // is \"axpy\": add one row to another, which we can do efficiently\n // via bitwise xor.\n //\n // of_scalar(u) can be reinterpreted in terms axpy as follows.\n // Start with a tableau with e=0. Reduce u to 0 via axpy\n // operations, e.g., for all i such that u[i] = 1, add row i to the\n // last row. Because this is exactly what of_scalar() does, at the\n // end of the process we have e = of_scalar(u). Because I is\n // full-rank, any sequence of axpy's that reduces u to 0 produces\n // the same e.\n //\n // We now want to invert the of_scalar() process. We cannot apply\n // the axpy operations in of_scalar() in reverse order, because we\n // don't know u, and thus we don't know which operations\n // of_scalar(u) would apply. However, because B is a basis, any\n // sequence of axpy operations that starts with u=0 and reduces e to\n // 0 reconstructs the same u.\n //\n // For lack of a better idea, we choose the following sequence of\n // axpy operations. First reduce B to row-echelon form via axpy\n // operations on B, and then reduce e to zero via additional axpy\n // operations. A matrix U is in row-echelon form if the following\n // condition holds: i' > i implies that U[i'][ldnz[i]] = 0, where\n // ldnz[i] is the column index of the leading nonzero in row i.\n //\n // Since B is constant, we choose to pre-compute the row-echelon\n // form of B in beta_ref(), and finish the process in solve() when e\n // is known, for multiple values of e.\n //\n // As it happens, reducing B to row-echelon transforms the -I\n // in the upper-right block to -L^{-1}, where B=LU is the LU\n // factorization of B. We don't use this correspondence anywhere\n // in the code other than in the choice of the name Linv for the block.\n //\n void beta_ref() {\n for (size_t i = 0; i < kSubFieldBits; ++i) {\n // B in the tableau, becomes U at the end.\n u_[i] = beta_[i].unpack();\n\n // -I in the tableau, becomes -L^{-1} at the end.\n // Ignore the minus sign over GF(2).\n linv_[i] = (static_cast(1) << i);\n }\n\n // Reduce B to row-echelon form.\n //\n // Invariant: B([0,RNK), [0,J)) is already in row-echelon form.\n // The loop body extends this property to J+1 and possibly RNK+1.\n size_t rnk = 0;\n for (size_t j = 0; rnk < kSubFieldBits && j < kBits; ++j) {\n // find pivot at row >= RNK in column J\n for (size_t i = rnk; i < kSubFieldBits; ++i) {\n if (u_[i].bit(j)) {\n std::swap(u_[rnk], u_[i]);\n std::swap(linv_[rnk], linv_[i]);\n goto have_pivot;\n }\n }\n // If we get here there is no pivot. Keep the rank RNK the same\n // and proceed to the next column ++J\n continue;\n\n have_pivot:\n ldnz_[rnk] = j;\n\n // Pivot on [rnk][j].\n for (size_t i1 = rnk + 1; i1 < kSubFieldBits; ++i1) {\n if (u_[i1].bit(j)) {\n u_[i1].add(u_[rnk]); // axpy on U\n linv_[i1] ^= linv_[rnk]; // axpy on Linv\n }\n }\n ++rnk;\n }\n\n // the basis is indeed a basis:\n check(rnk == kSubFieldBits, \"rnk == kSubFieldBits\");\n }\n\n std::pair solve(const Elt& e) const {\n uint64_t u = 0;\n N1 ue = e.unpack();\n for (size_t rnk = 0; rnk < kSubFieldBits; ++rnk) {\n size_t j = ldnz_[rnk];\n if (ue.bit(j)) {\n ue.add(u_[rnk]);\n u ^= linv_[rnk];\n }\n }\n\n return std::pair(ue, u);\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_GF2K_GF2_128_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_1f_witness.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_1F_WITNESS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_1F_WITNESS_H_\n\n#include \n#include \n#include \n#include \n\n#include \"arrays/dense.h\"\n#include \"circuits/cbor_parser/cbor_witness.h\"\n#include \"circuits/ecdsa/verify_witness.h\"\n#include \"circuits/logic/bit_plucker_encoder.h\"\n#include \"circuits/mdoc/mdoc_1f_io.h\"\n#include \"circuits/mdoc/mdoc_constants.h\"\n#include \"circuits/mdoc/mdoc_witness.h\"\n#include \"circuits/mdoc/mdoc_zk.h\"\n#include \"circuits/sha/flatsha256_witness.h\"\n#include \"util/log.h\"\nnamespace proofs {\n\ntemplate \nclass mdoc_1f_witness {\n using ECField = typename EC::Field;\n using ECElt = typename ECField::Elt;\n using ECNat = typename ECField::N;\n using Elt = typename Field::Elt;\n using Nat = typename Field::N;\n using EcdsaWitness = VerifyWitness3;\n using CborWitness = CborWitness;\n\n public:\n const EC ec_;\n Elt e_, e2_; /* Issuer signature values. */\n Elt dpkx_, dpky_; /* device key */\n EcdsaWitness ew_, dkw_;\n uint8_t now_[kMdoc1DateLen]; /* CBOR-formatted time for expiry comparison. */\n\n FlatSHA256Witness::BlockWitness bw_[kMdoc1MaxSHABlocks];\n uint8_t signed_bytes_[kMdoc1MaxSHABlocks * 64];\n uint8_t numb_; /* Number of the correct sha block. */\n ParsedMdoc pm_;\n\n size_t num_attr_;\n std::vector> attr_bytes_;\n std::vector> atw_;\n\n std::vector attr_n_; /* All attributes currently require 2 SHA. */\n std::vector attr_mso_; /* The cbor indices of the attributes. */\n std::vector attr_ei_;\n std::vector attr_ev_;\n\n // Cbor parsing witnesses\n std::vector incb_;\n std::vector pwcb_;\n typename CborWitness::global_witness gwcb_;\n\n explicit mdoc_1f_witness(size_t num_attr, const EC& ec, const ScalarField& Fn)\n : ec_(ec),\n ew_(Fn, ec),\n dkw_(Fn, ec),\n num_attr_(num_attr),\n attr_bytes_(num_attr_),\n atw_(num_attr_),\n attr_n_(num_attr_),\n attr_mso_(num_attr_),\n attr_ei_(num_attr_),\n attr_ev_(num_attr_),\n incb_(kMdoc1MaxMsoLen),\n pwcb_(kMdoc1MaxMsoLen) {}\n\n void fill_sha(DenseFiller& filler,\n const FlatSHA256Witness::BlockWitness& bw) const {\n BitPluckerEncoder BPENC(ec_.f_);\n for (size_t k = 0; k < 48; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.outw[k]));\n }\n for (size_t k = 0; k < 64; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.oute[k]));\n filler.push_back(BPENC.mkpacked_v32(bw.outa[k]));\n }\n for (size_t k = 0; k < 8; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.h1[k]));\n }\n }\n\n void fill_attr_shift(DenseFiller& df, const AttrShift& attr) const {\n df.push_back(attr.offset, kMdoc1CborIndexBits, ec_.f_);\n df.push_back(attr.len, kMdoc1CborIndexBits, ec_.f_);\n }\n\n // The cbor index that is computed by our witness maker is with reference\n // to the beginning of the cbor string. However the convention for the cbor\n // parser is to 0-pad from the left to fill the full cbor string buffer.\n // As a result, all cbor indices need to be offset by the padding length.\n void fill_cbor_index(DenseFiller& filler, const CborIndex& ind,\n size_t padding_offset = 0) const {\n filler.push_back(ind.k + padding_offset, kMdoc1CborIndexBits, ec_.f_);\n filler.push_back(ind.v + padding_offset, kMdoc1CborIndexBits, ec_.f_);\n filler.push_back(ind.ndx, kMdoc1CborIndexBits, ec_.f_);\n }\n\n void fill_witness(DenseFiller& filler, bool small = false) const {\n filler.push_back(e_);\n filler.push_back(dpkx_);\n filler.push_back(dpky_);\n\n ew_.fill_witness(filler);\n dkw_.fill_witness(filler);\n\n filler.push_back(numb_, 8, ec_.f_);\n for (size_t i = kCose1PrefixLen; i < kMdoc1MaxSHABlocks * 64; ++i) {\n filler.push_back(signed_bytes_[i], 8, ec_.f_);\n }\n for (size_t j = 0; j < kMdoc1MaxSHABlocks; j++) {\n fill_sha(filler, bw_[j]);\n }\n\n size_t prepad = kMdoc1MaxMsoLen - pm_.t_mso_.len + 5;\n filler.push_back(prepad, kMdoc1CborIndexBits, ec_.f_);\n filler.push_back(pm_.t_mso_.len - 5, kMdoc1CborIndexBits, ec_.f_);\n for (size_t i = 0; i < kMdoc1MaxMsoLen; ++i) {\n filler.push_back(pwcb_[i].encoded_sel_header);\n }\n filler.push_back(gwcb_.invprod_decode);\n filler.push_back(gwcb_.cc0);\n filler.push_back(gwcb_.invprod_parse);\n\n fill_cbor_index(filler, pm_.valid_, prepad);\n fill_cbor_index(filler, pm_.valid_from_, prepad);\n fill_cbor_index(filler, pm_.valid_until_, prepad);\n fill_cbor_index(filler, pm_.dev_key_info_, prepad);\n fill_cbor_index(filler, pm_.dev_key_, prepad);\n fill_cbor_index(filler, pm_.dev_key_pkx_, prepad);\n fill_cbor_index(filler, pm_.dev_key_pky_, prepad);\n fill_cbor_index(filler, pm_.value_digests_, prepad);\n fill_cbor_index(filler, pm_.org_, prepad);\n\n // Fill all attribute witnesses.\n for (size_t ai = 0; ai < num_attr_; ++ai) {\n for (size_t i = 0; i < 2 * 64; ++i) {\n filler.push_back(attr_bytes_[ai][i], 8, ec_.f_);\n }\n for (size_t j = 0; j < 2; j++) {\n fill_sha(filler, atw_[ai][j]);\n }\n\n // In the case of attribute mso, push the value to avoid having to\n // deal with 1- or 2- byte key length.\n // fill_cbor_index(filler, pm_.value_digests_);\n fill_cbor_index(filler, attr_mso_[ai], prepad);\n fill_attr_shift(filler, attr_ei_[ai]);\n fill_attr_shift(filler, attr_ev_[ai]);\n }\n }\n\n bool compute_witness(Elt pkX, Elt pkY, const uint8_t mdoc[/* len */],\n size_t len, const uint8_t transcript[/* tlen */],\n size_t tlen, const uint8_t tnow[/*kMdoc1DateLen*/],\n const RequestedAttribute attrs[], size_t attrs_len) {\n if (!pm_.parse_device_response(len, mdoc)) {\n return false;\n }\n if (pm_.t_mso_.len >= kMdoc1MaxSHABlocks * 64 - 9 - kCose1PrefixLen) {\n log(ERROR, \"tagged mso is too big: %zu\", pm_.t_mso_.len);\n return false;\n }\n\n Nat ne = nat_from_hash(pm_.tagged_mso_bytes_.data(),\n pm_.tagged_mso_bytes_.size());\n e_ = ec_.f_.to_montgomery(ne);\n\n // Parse (r,s).\n const size_t l = pm_.sig_.len;\n Nat nr = nat_from_be(&mdoc[pm_.sig_.pos]);\n Nat ns = nat_from_be(&mdoc[pm_.sig_.pos + l / 2]);\n ew_.compute_witness(pkX, pkY, ne, nr, ns);\n\n Nat ne2 = compute_transcript_hash(transcript, tlen, &pm_.doc_type_);\n const size_t l2 = pm_.dksig_.len;\n Nat nr2 = nat_from_be(&mdoc[pm_.dksig_.pos]);\n Nat ns2 = nat_from_be(&mdoc[pm_.dksig_.pos + l2 / 2]);\n size_t pmso = pm_.t_mso_.pos + 5; /* skip the tag */\n dpkx_ = ec_.f_.to_montgomery(\n nat_from_be(&mdoc[pmso + pm_.dev_key_pkx_.pos]));\n dpky_ = ec_.f_.to_montgomery(\n nat_from_be(&mdoc[pmso + pm_.dev_key_pky_.pos]));\n e2_ = ec_.f_.to_montgomery(ne2);\n dkw_.compute_witness(dpkx_, dpky_, ne2, nr2, ns2);\n\n memcpy(now_, tnow, kMdoc1DateLen);\n std::vector buf;\n\n buf.assign(std::begin(kCose1Prefix), std::end(kCose1Prefix));\n // Add 2-byte length\n buf.push_back((pm_.t_mso_.len >> 8) & 0xff);\n buf.push_back(pm_.t_mso_.len & 0xff);\n for (size_t i = 0; i < pm_.t_mso_.len; ++i) {\n buf.push_back(mdoc[pm_.t_mso_.pos + i]);\n }\n\n FlatSHA256Witness::transform_and_witness_message(\n buf.size(), buf.data(), kMdoc1MaxSHABlocks, numb_, signed_bytes_, bw_);\n\n // Cbor parsing.\n // The input is expected to be pre-padded with zeros.\n // The +5 corresponds to the D8 18 59 prefix.\n size_t prepad = kMdoc1MaxMsoLen - pm_.t_mso_.len + 5;\n // Pad with enough 0s.\n buf.erase(buf.begin(), buf.begin() + kCose1PrefixLen + 2 + 5);\n buf.insert(buf.begin(), prepad, 0);\n\n CborWitness cw(ec_.f_);\n cw.fill_witnesses(kMdoc1MaxMsoLen, pm_.t_mso_.len, buf.data(), incb_.data(),\n pwcb_.data(), gwcb_);\n\n // initialize variables\n for (size_t i = 0; i < num_attr_; ++i) {\n attr_bytes_[i].resize(128);\n atw_[i].resize(2);\n }\n\n // Match the attributes with the witnesses from the deviceResponse.\n for (size_t i = 0; i < num_attr_; ++i) {\n bool found = false;\n for (auto fa : pm_.attributes_) {\n if (fa == attrs[i]) {\n FlatSHA256Witness::transform_and_witness_message(\n fa.tag_len, &fa.doc[fa.tag_ind], 2, attr_n_[i],\n &attr_bytes_[i][0], &atw_[i][0]);\n attr_mso_[i] = fa.mso;\n attr_ei_[i].offset = fa.id_ind - fa.tag_ind;\n attr_ei_[i].len = fa.witness_length(attrs[i]);\n attr_ev_[i].offset = fa.val_ind - fa.tag_ind;\n attr_ev_[i].len = fa.val_len;\n found = true;\n break;\n }\n }\n if (!found) {\n log(ERROR, \"Could not find attribute %.*s\", attrs[i].id_len,\n attrs[i].id);\n return false;\n }\n }\n return true;\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_1F_WITNESS_H_\n"], ["/longfellow-zk/lib/zk/zk_common.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ZK_ZK_COMMON_H_\n#define PRIVACY_PROOFS_ZK_LIB_ZK_ZK_COMMON_H_\n\n#include \n#include \n\n#include \"arrays/dense.h\"\n#include \"arrays/eq.h\"\n#include \"arrays/eqs.h\"\n#include \"ligero/ligero_param.h\"\n#include \"random/transcript.h\"\n#include \"sumcheck/circuit.h\"\n#include \"sumcheck/quad.h\"\n#include \"sumcheck/transcript_sumcheck.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n\ntemplate \n// ZkCommon\n//\n// Used by prover and verifier to mimic the checks that the sumcheck verifier\n// applies to the sumcheck transcript. The difference is that the transcript\n// will now be encrypted with a random pad, and the checks will be verified\n// by the Ligero proof system with respect to a hiding commitment scheme.\nclass ZkCommon {\n using index_t = typename Quad::index_t;\n using Llc = LigeroLinearConstraint;\n using Elt = typename Field::Elt;\n using CPoly = typename LayerProof::CPoly;\n using WPoly = typename LayerProof::WPoly;\n\n public:\n // pi: witness index for first pad element in a larger commitment\n static size_t verifier_constraints(\n const Circuit& circuit, const Dense& pub,\n const Proof& proof, const ProofAux* aux,\n std::vector& a, std::vector& b, Transcript& tsv,\n size_t pi, const Field& F) {\n const size_t ninp = circuit.ninputs, npub = circuit.npub_in;\n\n Challenge ch(circuit.nl);\n TranscriptSumcheck tss(tsv, F);\n\n tss.begin_circuit(ch.q, ch.g);\n Claims cla = Claims{\n .logv = circuit.logv,\n .claim = {F.zero(), F.zero()},\n .q = ch.q,\n .g = {ch.g, ch.g},\n };\n\n size_t ci = 0; // Index of the next Ligero constraint.\n\n const typename WPoly::dot_interpolation dot_wpoly(F);\n\n // no copies in this version.\n check(circuit.logc == 0, \"assuming that copies=1\");\n\n // Constraints from the sumcheck verifier.\n for (size_t ly = 0; ly < circuit.nl; ++ly) {\n auto clr = &circuit.l.at(ly);\n auto plr = &proof.l[ly];\n auto challenge = &ch.l[ly];\n\n tss.begin_layer(challenge->alpha, challenge->beta, ly);\n\n // The loop below assumes at least one round.\n check(clr->logw > 0, \"clr->logw > 0\");\n\n PadLayout pl(clr->logw);\n ConstraintBuilder cb(pl, F); // representing 0\n\n cb.first(challenge->alpha, cla.claim);\n // now cb contains claim_{-1} from the previous layer\n\n for (size_t round = 0; round < clr->logw; ++round) {\n for (size_t hand = 0; hand < 2; ++hand) {\n size_t r = 2 * round + hand;\n const WPoly& hp = plr->hp[hand][round];\n challenge->hb[hand][round] = tss.round(hp);\n const WPoly lag = dot_wpoly.coef(challenge->hb[hand][round], F);\n\n cb.next(r, &lag[0], hp.t_);\n // now cb contains a symbolic representation of claim_{r}\n }\n }\n\n // Verify\n // claim = EQ[Q,C] QUAD[R,L] W[R,C] W[L,C]\n // by substituting in the symbolic constraint on p(1) from the relation:\n // claim = .\n Elt quad = aux == nullptr ? bind_quad(clr, cla, challenge, F)\n : aux->bound_quad[ly];\n Elt eqv =\n Eq::eval(circuit.logc, circuit.nc, ch.q, challenge->cb, F);\n Elt eqq = F.mulf(eqv, quad);\n\n // Add the final constraint from above.\n cb.finalize(plr->wc, eqq, ci++, ly, pi, a, b);\n\n tss.write(&plr->wc[0], 1, 2);\n\n cla = Claims{\n .logv = clr->logw,\n .claim = {plr->wc[0], plr->wc[1]},\n .q = challenge->cb,\n .g = {challenge->hb[0], challenge->hb[1]},\n };\n\n pi += pl.layer_size(); // Update index to poly_pad(0,0) of the\n // next layer\n }\n\n // Constraints induced by the input binding\n // = W_l + alpha.W_r\n Elt alpha = tsv.elt(F);\n auto plr = &proof.l[circuit.nl - 1];\n Elt got = F.addf(plr->wc[0], F.mulf(alpha, plr->wc[1]));\n\n return input_constraint(cla, pub, npub, ninp, pi, got, alpha, a, b, ci, F);\n }\n\n // Returns the size of the proof pad for circuit C.\n static size_t pad_size(const Circuit& C) {\n size_t sz = 0;\n for (size_t i = 0; i < C.nl; ++i) {\n PadLayout pl(C.l[i].logw);\n sz += pl.layer_size();\n }\n return sz;\n }\n\n // Setup lqc based on proof pad layout.\n static void setup_lqc(const Circuit& C,\n std::vector& lqc,\n size_t start_pad) {\n size_t pi = start_pad;\n for (size_t i = 0; i < C.nl; ++i) {\n PadLayout pl(C.l[i].logw);\n lqc[i].x = pi + pl.claim_pad(0);\n lqc[i].y = pi + pl.claim_pad(1);\n lqc[i].z = pi + pl.claim_pad(2);\n pi += pl.layer_size();\n }\n }\n\n // append public parameters to the FS transcript\n static void initialize_sumcheck_fiat_shamir(Transcript& ts,\n const Circuit& circuit,\n const Dense& pub,\n const Field& F) {\n ts.write(circuit.id, sizeof(circuit.id));\n\n // Public inputs:\n for (size_t i = 0; i < circuit.npub_in; ++i) {\n ts.write(pub.at(i), F);\n }\n\n // Outputs pro-forma:\n ts.write(F.zero(), F);\n\n // Enough zeroes for correlation intractability, one byte\n // per term.\n ts.write0(circuit.nterms());\n }\n\n private:\n // The claims struct mimics the same object in the sumcheck code. This\n // helps the verifier_constraints method above mimic the same steps as\n // the sumcheck verifier.\n struct Claims {\n size_t logv;\n Elt claim[2];\n const Elt* q;\n const Elt* g[2];\n };\n\n class PadLayout {\n size_t logw_;\n\n public:\n explicit PadLayout(size_t logw) : logw_(logw) {}\n\n // Layout of padding in the expr_.symbolic array.\n //\n // A *claim pad* is a triple [dWC[0], dWC[1], dWC[0]*dWC[1]].\n //\n // A *poly pad* is a pair [dP(0), dP(2)], where \"2\" is a generic\n // name for the third evaluation point of the sumcheck round\n // polynomial (could be X for binary fields GF(2)[X] / (Q(X))).\n //\n // The layout of expr_.symbolic is\n // [CLAIM_PAD[layer - 1], POLY_PAD[0], POLY_PAD[1], ..\n // POLY_PAD[LOGW - 1], CLAIM_PAD[layer]]\n //\n // The layout of adjacent layers thus overlaps. For layer 0\n // we still lay out CLAIM_PAD[layer - 1] to keep the representation\n // uniform, but we don't output the corresponding Ligero terms.\n\n // Because of different use cases, we have two indexing schemes:\n //\n // \"with overlap\": the first element is CLAIM_PAD[layer - 1][0]\n // \"without overlap\": the first element is POLY_PAD[0][0]\n\n //------------------------------------------------------------\n // Indexing without overlap.\n //------------------------------------------------------------\n size_t poly_pad(size_t r, size_t point) const {\n check(point == 0 || point == 2, \"unknown poly_pad() layout\");\n if (point == 0) {\n return 2 * r;\n } else if (point == 2) {\n return 2 * r + 1;\n }\n return 0; // silence noreturn warning\n }\n // index of CLAIM_PAD[layer][n]\n size_t claim_pad(size_t n) const { return poly_pad(2 * logw_, 0) + n; }\n\n // size of the layer\n size_t layer_size() const { return claim_pad(3); }\n\n //------------------------------------------------------------\n // Indexing with overlap.\n //------------------------------------------------------------\n // index of CLAIM_PAD[layer - 1][n]\n size_t ovp_claim_pad_m1(size_t n) const { return n; }\n size_t ovp_poly_pad(size_t r, size_t point) const {\n return 3 + poly_pad(r, point);\n }\n size_t ovp_claim_pad(size_t n) const { return 3 + claim_pad(n); }\n size_t ovp_layer_size() const { return ovp_claim_pad(3); }\n };\n\n // Represent symbolic expressions of the form\n //\n // KNOWN + SUM_{i} SYMBOLIC[i] * WITNESS[i]\n //\n // and support simple linear operations on such quantities\n class Expression {\n Elt known_;\n std::vector symbolic_;\n const Field& f_;\n\n public:\n Expression(size_t nvar, const Field& F)\n : known_(F.zero()), symbolic_(nvar, F.zero()), f_(F) {}\n\n Elt known() { return known_; }\n std::vector symbolic() { return symbolic_; }\n\n void scale(const Elt& k) {\n f_.mul(known_, k);\n for (auto& e : symbolic_) {\n f_.mul(e, k);\n }\n }\n\n // We don't need the general case of combining two\n // Expressions. Instead, we only need the two operations\n // below.\n\n // *this += k * (known_value + witness[var]).\n void axpy(size_t var, const Elt& known_value, const Elt& k) {\n f_.add(known_, f_.mulf(k, known_value));\n f_.add(symbolic_[var], k);\n }\n\n // *this -= k * (known_value + witness[var])\n void axmy(size_t var, const Elt& known_value, const Elt& k) {\n f_.sub(known_, f_.mulf(k, known_value));\n f_.sub(symbolic_[var], k);\n }\n };\n\n class ConstraintBuilder {\n Expression expr_;\n const PadLayout& pl_;\n const Field& f_;\n\n public:\n ConstraintBuilder(const PadLayout& pl, const Field& F)\n : expr_(pl.ovp_layer_size(), F), pl_(pl), f_(F) {}\n\n // For given unpadded variable X in the original non-ZK prover,\n // the transcript contains the padded variable Xhat = X - dX\n // where dX is the padding of X. Thus the unpadded variable is\n //\n // X = Xhat + dX\n //\n // The ZK verifier needs to compute linear combinations (and one\n // quadratic combination) of the X's, but it only has access to\n // the Xhat's and to a committment to the dX's. We also want to\n // discuss the verifier algorithm as if the verifier were\n // operating on X, in order to keep the discussion simple.\n //\n // To this end, the Expression class keeps a symbolic\n // representation of a variable X as\n //\n // X = KNOWN + SUM_{i} SYMBOLIC[i] dX[i]\n //\n // which is sufficient to capture any linear combination of\n // X variables. We do something special for the quadratic\n // combination in finalize().\n\n // We store only one quantity EXPR_ that represents either\n // p(1) at some certain round, or a claim at some round.\n // Comments make it clear which is which.\n\n // Initially, compute claim_{-1} = cl0 + alpha*cl1\n void first(Elt alpha, const Elt claims[]) {\n // expr_ contains zero\n expr_.axpy(pl_.ovp_claim_pad_m1(0), claims[0], f_.one());\n expr_.axpy(pl_.ovp_claim_pad_m1(1), claims[1], alpha);\n // expr_ contains claim_{-1} = cl0 + alpha*cl1\n }\n\n // Given claim_{r-1}, compute claim_{r}\n void next(size_t r, const Elt lag[], const Elt tr[]) {\n // expr contains claim_{r-1}\n expr_.axmy(pl_.ovp_poly_pad(r, 0), tr[0], f_.one());\n // expr contains p_{r}(1) = claim_{r-1} - p_{r}(0)\n\n // Compute the dot-product in place:\n // claim_{r} = p_{r}(1) * lag[1], overwriting expr_\n // claim_{r} += lag[0] * p_{r}(0)\n // claim_{r} += lag[2] * p_{r}(2)\n expr_.scale(lag[1]);\n expr_.axpy(pl_.ovp_poly_pad(r, 0), tr[0], lag[0]);\n expr_.axpy(pl_.ovp_poly_pad(r, 2), tr[2], lag[2]);\n // expr_ contains claim_{r} = \n }\n\n // The finalize method uses the last sumcheck claim to\n // add a constraint on the dX's (the pad) to the Ligero system.\n //\n // Our goal is to verify that\n //\n // CLAIM = EQQ * W[R,C] * W[L,C]\n //\n // where EQQ = EQ[Q,C] QUAD[R,L] and all variables are unpadded.\n //\n // We have a symbolic representation of CLAIM in expr_, the proof\n // contains W_hat[{R,L},C], the padding witnesses are at index pi,\n // pi+1, and their product is at index pi+2.\n //\n // Let CLAIM = KNOWN + SUM_{i} SYMBOLIC[i] dX[i] from the\n // Expression class. Then\n //\n // KNOWN + SUM_{i} SYMBOLIC[i] dX[i]\n // = EQQ * (W_hat[R,C] + dW[R,C]) * (W_hat[L,C] + dW[L,C])\n //\n // Rearranging in the Ax = b form needed for ligero, we have\n //\n // SUM_{i} SYMBOLIC[i] dX[i] - (EQQ * W[R, C]) dW[L, C]\n // - (EQQ * W[L, C]) dW[R, C] - EQQ * dW[R,C] * dW[L,C]\n // = EQQ * W[R,C] * W[L,C] - KNOWN\n void finalize(const Elt wc[], const Elt& eqq, size_t ci, size_t ly,\n size_t pi, std::vector& a, std::vector& b) {\n // break the Expression abstraction and split into constituents.\n\n // EQQ * W[R,C] * W[L,C] - known\n Elt rhs = f_.subf(f_.mulf(eqq, f_.mulf(wc[0], wc[1])), expr_.known());\n\n // symbolic part\n std::vector lhs = expr_.symbolic();\n f_.sub(lhs[pl_.ovp_claim_pad(0)], f_.mulf(eqq, wc[1]));\n f_.sub(lhs[pl_.ovp_claim_pad(1)], f_.mulf(eqq, wc[0]));\n f_.sub(lhs[pl_.ovp_claim_pad(2)], eqq);\n\n b.push_back(rhs);\n\n // Layer 0 does not refer to CLAIM_PAD[layer - 1]\n size_t i0 = (ly == 0) ? pl_.ovp_poly_pad(0, 0) : pl_.ovp_claim_pad_m1(0);\n\n for (size_t i = i0; i < lhs.size(); ++i) {\n // \"i\" is in the \"with overlap\" reference frame.\n // \"pi\" is in the \"without overlap\" reference frame.\n //\n // In theory at least, (pi - pl_.ovp_poly_pad(0, 0))\n // could overflow, but (pi + i) - pl_.ovp_poly_pad(0, 0) cannot.\n a.push_back(Llc{ci, (pi + i) - pl_.ovp_poly_pad(0, 0), lhs[i]});\n }\n }\n };\n\n // binding(inputs, R) = binding(pub_inputs, R_p) + binding(witness, R_w)\n // This method explicitly computes the public binding, and then adds the\n // constraints that\n // binding(witness, R_w) = got - binding(pub_inputs, R_p)\n static size_t input_constraint(const Claims& cla, const Dense& pub,\n size_t pub_inputs, size_t num_inputs,\n size_t pi, Elt got, Elt alpha,\n std::vector& a, std::vector& b,\n size_t ci, const Field& F) {\n Eqs eq0(cla.logv, num_inputs, cla.g[0], F);\n Eqs eq1(cla.logv, num_inputs, cla.g[1], F);\n Elt pub_binding = F.zero();\n for (index_t i = 0; i < num_inputs; ++i) {\n Elt b_i = F.addf(eq0.at(i), F.mulf(alpha, eq1.at(i)));\n if (i < pub_inputs) {\n F.add(pub_binding, F.mulf(b_i, pub.at(i)));\n } else {\n // Use (i - pub_inputs) for the index of private inputs.\n a.push_back(Llc{ci, i - pub_inputs, b_i});\n }\n }\n\n // We view the input constraints as being at fake layer\n // one past the last real layer. The alternative of\n // considering the input as part of the last real layer\n // yields code that looks even more convoluted.\n PadLayout pl(/*logw=*/0);\n\n // This paranoid assertion holds unless the circuit has zero\n // layers, which is not guaranteed by this function alone.\n check(pi >= pl.ovp_poly_pad(0, 0), \"pi >= pl.ovp_poly_pad(0, 0)\");\n\n size_t claim_pad_m1 = pi - pl.ovp_poly_pad(0, 0);\n a.push_back(Llc{ci, claim_pad_m1 + 0, F.mone()});\n a.push_back(Llc{ci, claim_pad_m1 + 1, F.negf(alpha)});\n b.push_back(F.subf(got, pub_binding));\n return ++ci;\n }\n\n static Elt bind_quad(const Layer* clr, const Claims& cla,\n const LayerChallenge* chal, const Field& F) {\n return clr->quad->bind_gh_all(\n // G\n cla.logv, cla.g[0], cla.g[1], chal->alpha, chal->beta,\n // H\n clr->logw, chal->hb[0], chal->hb[1],\n // Field\n F);\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ZK_ZK_COMMON_H_\n"], ["/longfellow-zk/lib/circuits/mac/mac_reference.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MAC_MAC_REFERENCE_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MAC_MAC_REFERENCE_H_\n\n#include \n#include \n#include \n\n#include \"arrays/dense.h\"\n#include \"random/random.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n\ntemplate \nclass MACReference {\n using gf2k = typename GF::Elt;\n\n public:\n void sample(gf2k ap[], size_t n, RandomEngine* rng) {\n check(n > 0, \"n must be positive\");\n std::vector buf(n * GF::kBytes);\n rng->bytes(buf.data(), n * GF::kBytes);\n for (size_t i = 0; i < n; ++i) {\n ap[i] = gf_.of_bytes_field(&buf[i * GF::kBytes]).value();\n }\n }\n\n // Computes the mac of a 32-byte message.\n void compute(gf2k mac[/*2*/], const gf2k& av, const gf2k ap[/*2*/],\n uint8_t msg[/*32*/]) const {\n uint8_t tmp[GF::kBytes] = {0};\n for (size_t i = 0; i < 2; ++i) {\n memcpy(tmp, &msg[i * GF::kBytes], GF::kBytes);\n gf2k m = gf_.of_bytes_field(tmp).value();\n mac[i] = gf_.mulf(gf_.addf(av, ap[i]), m);\n }\n }\n\n void to_bytes(gf2k mac[/*2*/], uint8_t buf[/* 32 */]) {\n gf_.to_bytes(mac[0], buf);\n gf_.to_bytes(mac[1], buf + GF::kBytes);\n }\n\n private:\n GF gf_;\n};\n\ntemplate \nvoid fill_gf2k(const typename GF::Elt& m, DenseFiller& df,\n const Field& f) {\n for (size_t i = 0; i < GF::kBits; ++i) {\n df.push_back(m[i] ? f.one() : f.zero());\n }\n}\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MAC_MAC_REFERENCE_H_\n"], ["/longfellow-zk/lib/circuits/base64/decode.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_BASE64_DECODE_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_BASE64_DECODE_H_\n\n#include \n#include \n\n#include \"util/ceildiv.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n\n// This class implements a circuit to assert a base64 url decoding.\n// A string in base64 consists of the characters A-Z a-z 0-9 - _ and =.\n// 0--25 are mapped to A-Z, 26--51 are mapped to a-z, 52--61 are mapped to 0-9,\n// and 62--63 are mapped to - and _ respectively.\n// The base64 encoding is padded with = to a multiple of 4.\ntemplate \nclass Base64Decoder {\n using EltW = typename LogicCircuit::EltW;\n using BitW = typename LogicCircuit::BitW;\n using v8 = typename LogicCircuit::v8;\n using v6 = typename LogicCircuit::template bitvec<6>;\n\n public:\n explicit Base64Decoder(const LogicCircuit& lc) : lc_(lc) {}\n\n void base64_rawurl_decode(const v8 inputs[/*n*/],\n v8 output[/* ceil(n*6/8) */], size_t n) const {\n check(n < (1 << 28), \"input too large\"); // avoid overflows\n v6 zero = lc_.template vbit<6>(0);\n\n size_t max = ceildiv(n * 6, 8);\n size_t oc = 0;\n\n for (size_t i = 0; i < n; i += 4, oc += 3) {\n v6 quad[4] = {zero, zero, zero, zero};\n for (size_t j = 0; j < 4 && i + j < n; ++j) {\n decode(inputs[i + j], quad[j]);\n }\n // repack\n for (size_t j = 0; j < 24 && (oc + j / 8) < max; ++j) {\n output[oc + j / 8][7 - (j % 8)] = quad[j / 6][5 - (j % 6)];\n }\n }\n }\n\n template \n void base64_rawurl_decode_len(\n const v8 inputs[/*n*/], v8 output[/* ceil(n*6/8) */], size_t n,\n typename LogicCircuit::template bitvec& len) const {\n check(n < (1 << 28), \"input too large\"); // avoid overflows\n v6 zero = lc_.template vbit<6>(0);\n\n size_t max = ceildiv(n * 6, 8);\n size_t oc = 0;\n\n for (size_t i = 0; i < n; i += 4, oc += 3) {\n v6 quad[4] = {zero, zero, zero, zero};\n BitW invalid;\n for (size_t j = 0; j < 4 && i + j < n; ++j) {\n decode(inputs[i + j], quad[j], invalid);\n auto range = lc_.vlt(i + j, len);\n lc_.assert_implies(&range, lc_.lnot(invalid));\n }\n // repack\n for (size_t j = 0; j < 24 && (oc + j / 8) < max; ++j) {\n output[oc + j / 8][7 - (j % 8)] = quad[j / 6][5 - (j % 6)];\n }\n }\n }\n\n void decode(const v8 in, v6& out) const {\n BitW invalid;\n decode(in, out, invalid);\n lc_.assert0(invalid);\n }\n\n void decode(const v8 in, v6& out, BitW& invalid) const {\n v8 ni;\n for (size_t i = 0; i < 8; ++i) {\n ni[i] = lc_.lnot(in[i]);\n }\n std::vector > exp[] = {\n {\n // ['!v4', '!v3', '!v2', '!v1', '!v0']\n {\n ni[4],\n ni[3],\n ni[2],\n ni[1],\n ni[0],\n },\n // ['v4', 'v3', '!v2', 'v1', 'v0']\n {\n in[4],\n in[3],\n ni[2],\n in[1],\n in[0],\n },\n // ['v5', 'v4', 'v3', 'v1', 'v0']\n {\n in[5],\n in[4],\n in[3],\n in[1],\n in[0],\n },\n // ['!v6', 'v3', 'v2', '!v0']\n {\n ni[6],\n in[3],\n in[2],\n ni[0],\n },\n // ['v4', 'v3', 'v2', '!v1']\n {\n in[4],\n in[3],\n in[2],\n ni[1],\n },\n // ['v4', 'v3', 'v2', '!v0']\n {\n in[4],\n in[3],\n in[2],\n ni[0],\n },\n // ['!v6', '!v4', '!v3']\n {\n ni[6],\n ni[4],\n ni[3],\n },\n // ['!v6', '!v4', '!v2']\n {\n ni[6],\n ni[4],\n ni[2],\n },\n // ['!v6', 'v3', 'v1']\n {\n ni[6],\n in[3],\n in[1],\n },\n // ['!v6', '!v5']\n {\n ni[6],\n ni[5],\n },\n // ['v7']\n {\n in[7],\n },\n },\n {\n // ['v6', 'v5', 'v4', '!v3', '!v2']\n {\n in[6],\n in[5],\n in[4],\n ni[3],\n ni[2],\n },\n // ['v6', 'v5', 'v4', '!v3', '!v0']\n {\n in[6],\n in[5],\n in[4],\n ni[3],\n ni[0],\n },\n // ['v6', 'v5', 'v4', 'v2', '!v1']\n {\n in[6],\n in[5],\n in[4],\n in[2],\n ni[1],\n },\n // ['v5', 'v2', 'v1', 'v0']\n {\n in[5],\n in[2],\n in[1],\n in[0],\n },\n // ['v4', 'v3', 'v1', 'v0']\n {\n in[4],\n in[3],\n in[1],\n in[0],\n },\n // ['v5', 'v3']\n {\n in[5],\n in[3],\n },\n // ['!v6', '!v2']\n {\n ni[6],\n ni[2],\n },\n // ['!v6', 'v2']\n {\n ni[6],\n in[2],\n },\n },\n {\n // ['v5', '!v4', '!v3', '!v1']\n {\n in[5],\n ni[4],\n ni[3],\n ni[1],\n },\n // ['v5', '!v4', '!v3', '!v2']\n {\n in[5],\n ni[4],\n ni[3],\n ni[2],\n },\n // ['!v5', 'v4', 'v1']\n {\n ni[5],\n in[4],\n in[1],\n },\n // ['v5', '!v4', '!v3', '!v0']\n {\n in[5],\n ni[4],\n ni[3],\n ni[0],\n },\n // ['v4', 'v2', 'v1', 'v0']\n {\n in[4],\n in[2],\n in[1],\n in[0],\n },\n // ['!v5', 'v4', 'v0']\n {\n ni[5],\n in[4],\n in[0],\n },\n // ['!v5', 'v4', 'v2']\n {\n ni[5],\n in[4],\n in[2],\n },\n // ['v4', 'v3']\n {\n in[4],\n in[3],\n },\n // ['!v6', '!v2']\n {\n ni[6],\n ni[2],\n },\n // ['!v6', 'v2']\n {\n ni[6],\n in[2],\n },\n },\n {\n // ['v6', '!v3', '!v2', '!v1', '!v0']\n {\n in[6],\n ni[3],\n ni[2],\n ni[1],\n ni[0],\n },\n // ['v6', 'v5', 'v4', '!v3', '!v2']\n {\n in[6],\n in[5],\n in[4],\n ni[3],\n ni[2],\n },\n // ['v6', 'v5', 'v4', '!v3', '!v0']\n {\n in[6],\n in[5],\n in[4],\n ni[3],\n ni[0],\n },\n // ['v6', 'v5', 'v4', 'v2', '!v1']\n {\n in[6],\n in[5],\n in[4],\n in[2],\n ni[1],\n },\n // ['v5', '!v4', '!v3', '!v1']\n {\n in[5],\n ni[4],\n ni[3],\n ni[1],\n },\n // ['v5', '!v4', '!v3', '!v2']\n {\n in[5],\n ni[4],\n ni[3],\n ni[2],\n },\n // ['v5', '!v4', '!v3', '!v0']\n {\n in[5],\n ni[4],\n ni[3],\n ni[0],\n },\n // ['!v5', 'v3', 'v1']\n {\n ni[5],\n in[3],\n in[1],\n },\n // ['v3', 'v2', 'v1', 'v0']\n {\n in[3],\n in[2],\n in[1],\n in[0],\n },\n // ['!v5', 'v3', 'v0']\n {\n ni[5],\n in[3],\n in[0],\n },\n // ['!v5', 'v3', 'v2']\n {\n ni[5],\n in[3],\n in[2],\n },\n // ['!v6', 'v3']\n {\n ni[6],\n in[3],\n },\n // ['!v6', 'v2']\n {\n ni[6],\n in[2],\n },\n },\n {\n // ['v5', '!v4', 'v2', '!v1', 'v0']\n {\n in[5],\n ni[4],\n in[2],\n ni[1],\n in[0],\n },\n // ['v6', 'v5', 'v4', 'v2', '!v1']\n {\n in[6],\n in[5],\n in[4],\n in[2],\n ni[1],\n },\n // ['!v5', '!v2', '!v1', '!v0']\n {\n ni[5],\n ni[2],\n ni[1],\n ni[0],\n },\n // ['v6', 'v5', 'v2', '!v0']\n {\n in[6],\n in[5],\n in[2],\n ni[0],\n },\n // ['v5', '!v2', 'v1', 'v0']\n {\n in[5],\n ni[2],\n in[1],\n in[0],\n },\n // ['!v5', 'v2', 'v0']\n {\n ni[5],\n in[2],\n in[0],\n },\n // ['!v5', 'v2', 'v1']\n {\n ni[5],\n in[2],\n in[1],\n },\n // ['!v6', '!v2']\n {\n ni[6],\n ni[2],\n },\n },\n {\n // ['v5', '!v4', 'v2', '!v1', 'v0']\n {\n in[5],\n ni[4],\n in[2],\n ni[1],\n in[0],\n },\n // ['v6', 'v5', '!v1', 'v0']\n {\n in[6],\n in[5],\n ni[1],\n in[0],\n },\n // ['!v5', '!v1', '!v0']\n {\n ni[5],\n ni[1],\n ni[0],\n },\n // ['!v5', 'v1', 'v0']\n {\n ni[5],\n in[1],\n in[0],\n },\n // ['v5', 'v1', '!v0']\n {\n in[5],\n in[1],\n ni[0],\n },\n // ['!v6', 'v1']\n {\n ni[6],\n in[1],\n },\n },\n {\n // ['v4', 'v3', 'v1', 'v0']\n {\n in[4],\n in[3],\n in[1],\n in[0],\n },\n // ['!v6', 'v4', 'v0']\n {\n ni[6],\n in[4],\n in[0],\n },\n // ['v6', '!v0']\n {\n in[6],\n ni[0],\n },\n },\n };\n invalid = lc_.or_of_and(exp[0]);\n for (size_t i = 0; i < 6; ++i) {\n out[5 - i] = lc_.or_of_and(exp[i + 1]);\n }\n }\n\n private:\n const LogicCircuit& lc_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_BASE64_DECODE_H_\n"], ["/longfellow-zk/lib/proto/circuit.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_PROTO_CIRCUIT_H_\n#define PRIVACY_PROOFS_ZK_LIB_PROTO_CIRCUIT_H_\n\n#include \n\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#include \"algebra/hash.h\"\n#include \"sumcheck/circuit.h\"\n#include \"sumcheck/quad.h\"\n#include \"util/ceildiv.h\"\n#include \"util/panic.h\"\n#include \"util/readbuffer.h\"\n\nnamespace proofs {\n\n// CircuitRep class handles custom circuit serialization.\n//\n// We expect circuits to be created and stored locally by the prover and\n// verifier respectively. The byte representations are thus assumed to be\n// trusted. As a result, the methods below perform only basic sanity checking.\n//\n// An earlier experiment implemented the IO methods using protobuf parsing.\n// Despite applying techniques like arena allocation, those methods required\n// several seconds to deserialize the circuit. In contrast, these methods take\n// 100s of ms.\n//\n// This class implements an optimization by which internal indices for\n// wire and gate labels and circuit size statistics are stored in a configurable\n// number of bytes (kBytesWritten) which we set to 4 instead of 8 to save\n// space. If this value is set to >4, there is a possibility of failure on\n// 32b platforms, which currently stops execution. Thus, all circuits must be\n// tested on 32b platforms to ensure they are small enough to work.\nenum FieldID {\n NONE = 0,\n P256_ID = 1,\n P384_ID = 2,\n P521_ID = 3,\n GF2_128_ID = 4,\n GF2_16_ID = 5,\n FP128_ID = 6,\n FP64_ID = 7,\n GOLDI_ID = 8,\n FP64_2_ID = 9,\n SECP_ID = 10,\n};\n\ntemplate \nclass CircuitRep {\n using Elt = typename Field::Elt;\n using QuadCorner = typename Quad::quad_corner_t;\n constexpr static size_t kMaxLayers = 10000; /* deep circuits are errors */\n\n public:\n // Serialize kBytesWritten bytes of a size or index used in the circuit to\n // save space.\n static constexpr size_t kBytesWritten = 3;\n\n explicit CircuitRep(const Field& f, FieldID field_id)\n : f_(f), field_id_(field_id) {}\n\n void to_bytes(const Circuit& sc_c, std::vector& bytes) {\n EltHash eh(f_);\n bytes.push_back(0x1); // version\n serialize_field_id(bytes, field_id_);\n serialize_size(bytes, sc_c.nv);\n serialize_size(bytes, sc_c.nc);\n serialize_size(bytes, sc_c.npub_in);\n serialize_size(bytes, sc_c.subfield_boundary);\n serialize_size(bytes, sc_c.ninputs);\n serialize_size(bytes, sc_c.l.size());\n\n // Scan the circuit to generate the constant table. To keep one\n // scan, write the quad to a separate byte vector and later copy it.\n std::vector quadb;\n quadb.reserve(1 << 24);\n for (const auto& layer : sc_c.l) {\n serialize_size(quadb, layer.logw);\n serialize_size(quadb, layer.nw);\n serialize_size(quadb, layer.quad->n_);\n\n QuadCorner prevg(0), prevh0(0), prevh1(0);\n for (size_t i = 0; i < layer.quad->n_; ++i) {\n serialize_index(quadb, layer.quad->c_[i].g, prevg);\n prevg = layer.quad->c_[i].g;\n serialize_index(quadb, layer.quad->c_[i].h[0], prevh0);\n prevh0 = layer.quad->c_[i].h[0];\n serialize_index(quadb, layer.quad->c_[i].h[1], prevh1);\n prevh1 = layer.quad->c_[i].h[1];\n serialize_num(quadb, eh.kstore(layer.quad->c_[i].v));\n }\n }\n\n serialize_size(bytes, eh.constants_.size());\n for (const auto& v : eh.constants_) {\n uint8_t buf[Field::kBytes];\n f_.to_bytes_field(buf, v);\n bytes.insert(bytes.end(), buf, buf + Field::kBytes);\n }\n\n bytes.insert(bytes.end(), quadb.begin(), quadb.end());\n bytes.insert(bytes.end(), sc_c.id, sc_c.id + 32);\n }\n\n // Returns a unique_ptr or nullptr if there is an error in\n // deserializing the circuit.\n std::unique_ptr> from_bytes(ReadBuffer& buf) {\n if (!buf.have(8 * kBytesWritten + 1)) {\n return nullptr;\n }\n\n uint8_t version = *buf.next(1);\n if (version != 1) {\n return nullptr;\n }\n\n size_t fid_as_size_t = read_field_id(buf);\n size_t nv = read_size(buf);\n size_t nc = read_size(buf);\n size_t npub_in = read_size(buf);\n size_t subfield_boundary = read_size(buf);\n size_t ninputs = read_size(buf);\n size_t nl = read_size(buf);\n size_t numconst = read_size(buf);\n\n // Basic sanity checks.\n if (fid_as_size_t != static_cast(field_id_) || npub_in > ninputs ||\n subfield_boundary > ninputs || nl > kMaxLayers) {\n return nullptr;\n }\n\n // Ensure there are enough input bytes for the quad constants.\n auto need = checked_mul(numconst, Field::kBytes);\n if (!need || !buf.have(need.value())) {\n return nullptr;\n }\n\n std::vector constants(numconst);\n for (size_t i = 0; i < numconst; ++i) {\n // Fail if Elt cannot be parsed.\n auto vv = f_.of_bytes_field(buf.next(Field::kBytes));\n if (!vv.has_value()) {\n return nullptr;\n }\n constants[i] = vv.value();\n }\n\n auto c = std::make_unique>();\n *c = Circuit{\n .nv = nv,\n .logv = lg(nv),\n .nc = nc,\n .logc = lg(nc),\n .nl = nl,\n .ninputs = ninputs,\n .npub_in = npub_in,\n .subfield_boundary = subfield_boundary,\n };\n c->l.reserve(nl);\n\n size_t max_g = nv; // a starting bound on quad number\n\n for (size_t ly = 0; ly < nl; ++ly) {\n // Ensure there are enough input bytes for the layer, 3 values.\n if (!buf.have(3 * kBytesWritten)) {\n return nullptr;\n }\n\n size_t lw = read_size(buf);\n size_t nw = read_size(buf);\n size_t nq = read_size(buf);\n\n // Each quad takes 4 values, check for overflow.\n need = checked_mul(4 * kBytesWritten, nq);\n if (!need || !buf.have(need.value())) {\n return nullptr;\n }\n\n auto qq = std::make_unique>(nq);\n size_t prevg = 0, prevhl = 0, prevhr = 0;\n for (size_t i = 0; i < nq; ++i) {\n size_t g = read_index(buf, prevg);\n if (g > max_g) { // index of quad must be < wires in the layer\n return nullptr;\n }\n prevg = g;\n size_t hl = read_index(buf, prevhl);\n size_t hr = read_index(buf, prevhr);\n if (hl > nw || hr > nw) {\n return nullptr;\n }\n prevhl = hl;\n prevhr = hr;\n size_t vi = read_num(buf);\n if (vi >= numconst) {\n return nullptr;\n }\n\n qq->c_[i] = typename Quad::corner{\n QuadCorner(g), {QuadCorner(hl), QuadCorner(hr)}, constants[vi]};\n }\n c->l.push_back(Layer{\n .nw = nw,\n .logw = lw,\n .quad = std::unique_ptr>(std::move(qq))});\n max_g = nw;\n }\n // Read the circuit name from the serialization.\n if (!buf.have(32)) {\n return nullptr;\n }\n buf.next(32, c->id);\n return c;\n }\n\n private:\n static constexpr uint64_t kMaxValue = (1ULL << (kBytesWritten * 8)) - 1;\n\n // Multiplies arguments and checks for overflow.\n template \n std::optional checked_mul(T a, T b) {\n T ab = a * b;\n if (a == 0 || ab / a == b) return ab;\n return std::nullopt;\n }\n\n static void serialize_field_id(std::vector& bytes, FieldID id) {\n serialize_num(bytes, static_cast(id));\n }\n\n static void serialize_size(std::vector& bytes, size_t sz) {\n serialize_num(bytes, sz);\n }\n\n // We write indices as differences from the previous index. This\n // encoding appears to produce byte streams that compress better\n // under both gzip and xz compression. For example, xz compresses\n // a 35MB test circuit to 2MB without delta encoding, and to 100KB\n // with delta encoding. We have no real theory to explain this\n // phenomenon, but at least part of the reason is that the deltas\n // are usually smaller than the indices.\n //\n static void serialize_index(std::vector& bytes, QuadCorner ind0,\n QuadCorner prev_ind0) {\n size_t ind = static_cast(ind0);\n size_t prev_ind = static_cast(prev_ind0);\n\n // Encode the delta IND - PREV_IND. Since the delta can be\n // negative, and the rest of the code is unsigned only,\n // use the LSB as sign bit.\n if (ind >= prev_ind) {\n serialize_num(bytes, 2u * (ind - prev_ind));\n } else {\n serialize_num(bytes, 2u * (prev_ind - ind) + 1u);\n }\n }\n\n static void serialize_num(std::vector& bytes, size_t g) {\n check(g < kMaxValue, \"Violating small wire-label assumption\");\n uint8_t tmp[kBytesWritten];\n for (size_t i = 0; i < kBytesWritten; ++i) {\n tmp[i] = static_cast(g & 0xff);\n g >>= 8;\n }\n bytes.insert(bytes.end(), tmp, tmp + kBytesWritten);\n }\n\n // These routine reads bytes written by serialize_* methods, and thus\n // only needs to handle values expressed in kBytesWritten.\n // On 32b platforms, some large circuits may fail; this method\n // causes a failure in that case.\n\n // Do not cast to FieldID, since the input is untrusted and the\n // cast may fail.\n static size_t read_field_id(ReadBuffer& buf) { return read_num(buf); }\n\n static size_t read_size(ReadBuffer& buf) { return read_num(buf); }\n\n static size_t read_index(ReadBuffer& buf, size_t prev_ind) {\n size_t delta = read_num(buf);\n if (delta & 1) {\n return prev_ind - (delta >> 1);\n } else {\n return prev_ind + (delta >> 1);\n }\n }\n\n static size_t read_num(ReadBuffer& buf) {\n uint64_t r = 0;\n const uint8_t* p = buf.next(kBytesWritten);\n for (size_t i = 0; i < kBytesWritten; ++i) {\n r |= (p[i] << (i * 8));\n }\n\n // SIZE_MAX is system defined as max value for size_t.\n // This check fails if a large circuit is loaded on a 32b machine.\n check(r < SIZE_MAX, \"Violating small wire-label assumption\");\n return static_cast(r);\n }\n\n // Class that defines the hash function for Elt.\n class EHash {\n public:\n const Field& f_;\n explicit EHash(const Field& f) : f_(f) {}\n size_t operator()(const Elt& k) const { return elt_hash(k, f_); }\n };\n\n // This structure encapsulates the hash used by the compiler.\n class EltHash {\n public:\n std::vector constants_;\n\n explicit EltHash(const Field& f) : f_(f), table_(1000, EHash(f)) {}\n\n size_t kstore(const Elt& k) {\n if (auto search = table_.find(k); search != table_.end()) {\n return search->second;\n }\n\n size_t ki = constants_.size();\n constants_.push_back(k);\n table_[k] = ki;\n return ki;\n }\n\n private:\n const Field& f_;\n std::unordered_map table_;\n };\n\n const Field& f_;\n FieldID field_id_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_PROTO_CIRCUIT_H_\n"], ["/longfellow-zk/lib/algebra/fp_generic.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_GENERIC_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_GENERIC_H_\n\n#include \n#include \n#include \n#include \n#include \n\n#include \"algebra/nat.h\"\n#include \"algebra/static_string.h\"\n#include \"algebra/sysdep.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\nstruct PrimeFieldTypeTag {};\n\n/*\nThe Fp_generic class contains the implementation of a finite field.\n*/\ntemplate \nclass FpGeneric {\n public:\n // Type alias for a natural number, and the limbs within the nat are public\n // to allow casting and operations.\n using N = Nat;\n using limb_t = typename N::limb_t;\n using TypeTag = PrimeFieldTypeTag;\n\n static constexpr size_t kU64 = N::kU64;\n static constexpr size_t kBytes = N::kBytes;\n static constexpr size_t kSubFieldBytes = kBytes;\n static constexpr size_t kBits = N::kBits;\n static constexpr size_t kLimbs = N::kLimbs;\n\n static constexpr bool kCharacteristicTwo = false;\n static constexpr size_t kNPolyEvaluationPoints = 6;\n\n /* The Elt struct represented an element in the finite field.\n */\n struct Elt {\n N n;\n bool operator==(const Elt& y) const { return n == y.n; }\n bool operator!=(const Elt& y) const { return !operator==(y); }\n };\n\n explicit FpGeneric(const N& modulus) : m_(modulus), negm_(N{}) {\n negm_.sub(m_);\n\n // compute rawhalf = (m + 1) / 2 = floor(m / 2) + 1 since m is odd\n N raw_half = m_;\n raw_half.shiftr(1);\n raw_half.add(N(1));\n raw_half_ = Elt{raw_half};\n\n mprime_ = -inv_mod_b(m_.limb_[0]);\n rsquare_ = Elt{N(1)};\n for (size_t bits = 2 * kBits; bits > 0; bits--) {\n add(rsquare_, rsquare_);\n }\n\n for (uint64_t i = 0; i < sizeof(k_) / sizeof(k_[0]); ++i) {\n // convert k_[i] into montgomery form by calling mul0()\n // directly, since mul() requires k_[0] and k_[1] to be\n // defined\n k_[i] = Elt{N(i)};\n mul0(k_[i], rsquare_);\n }\n\n mone_ = negf(k_[1]);\n half_ = invertf(k_[2]);\n\n for (size_t i = 0; i < kNPolyEvaluationPoints; ++i) {\n poly_evaluation_points_[i] = of_scalar(i);\n if (i == 0) {\n inv_small_scalars_[i] = zero();\n } else {\n inv_small_scalars_[i] = invertf(poly_evaluation_points_[i]);\n }\n }\n }\n\n explicit FpGeneric(const StaticString s) : FpGeneric(N(s)) {}\n\n template \n explicit FpGeneric(const char (&s)[LEN]) : FpGeneric(N(s)) {}\n\n // Hack: works only if OPS::modulus is defined, and will\n // fail to compile otherwise.\n explicit FpGeneric() : FpGeneric(N(OPS::kModulus)) {}\n\n FpGeneric(const FpGeneric&) = delete;\n FpGeneric& operator=(const FpGeneric&) = delete;\n\n template \n Elt of_string(const char (&s)[N]) const {\n return of_charp(&s[0]);\n }\n\n Elt of_string(const StaticString& s) const { return of_charp(s.as_pointer); }\n\n std::optional of_untrusted_string(const char* s) const {\n auto maybe = N::of_untrusted_string(s);\n if (maybe.has_value() && maybe.value() < m_) {\n return to_montgomery(maybe.value());\n } else {\n return std::nullopt;\n }\n }\n\n // a += y\n void add(Elt& a, const Elt& y) const {\n if (kLimbs == 1) {\n limb_t aa = a.n.limb_[0], yy = y.n.limb_[0], mm = m_.limb_[0];\n a.n.limb_[0] = addcmovc(aa - mm, yy, aa + yy);\n } else {\n limb_t ah = add_limb(kLimbs, a.n.limb_, y.n.limb_);\n maybe_minus_m(a.n.limb_, ah);\n }\n }\n\n // a -= y\n void sub(Elt& a, const Elt& y) const {\n if (kLimbs == 1) {\n a.n.limb_[0] = sub_sysdep(a.n.limb_[0], y.n.limb_[0], m_.limb_[0]);\n } else {\n limb_t ah = sub_limb(kLimbs, a.n.limb_, y.n.limb_);\n maybe_plus_m(a.n.limb_, ah);\n }\n }\n\n // x *= y, Montgomery\n void mul(Elt& x, const Elt& y) const {\n if (optimized_mul) {\n if (x == zero() || y == one()) {\n return;\n }\n if (y == zero() || x == one()) {\n x = y;\n return;\n }\n }\n mul0(x, y);\n }\n\n // x = -x\n void neg(Elt& x) const {\n Elt y(k_[0]);\n sub(y, x);\n x = y;\n }\n\n // x = 1/x\n void invert(Elt& x) const { x = invertf(x); }\n\n // functional interface\n Elt addf(Elt a, const Elt& y) const {\n add(a, y);\n return a;\n }\n Elt subf(Elt a, const Elt& y) const {\n sub(a, y);\n return a;\n }\n Elt mulf(Elt a, const Elt& y) const {\n mul(a, y);\n return a;\n }\n Elt negf(Elt a) const {\n neg(a);\n return a;\n }\n\n // This is the binary extended gcd algorithm, modified\n // to return the inverse of x.\n Elt invertf(Elt x) const {\n N a = from_montgomery(x);\n N b = m_;\n Elt u = one();\n Elt v = zero();\n while (a != /*zero*/ N{}) {\n if ((a.limb_[0] & 0x1u) == 0) {\n a.shiftr(1);\n byhalf(u);\n } else {\n if (a < b) { // swap to maintain invariant\n std::swap(a, b);\n std::swap(u, v);\n }\n a.sub(b).shiftr(1); // a = (a-b)/2\n sub(u, v);\n byhalf(u);\n }\n }\n return v;\n }\n\n // Reference implementation, unused.\n N from_montgomery_reference(const Elt& x) const {\n Elt r{N(1)};\n mul(r, x);\n return r.n;\n }\n\n // Optimized implementation of from_montgomery_reference(), exploiting\n // the fact that the multiplicand is Elt{N(1)}.\n N from_montgomery(const Elt& x) const {\n limb_t a[2 * kLimbs + 1]; // uninitialized\n mov(kLimbs, a, x.n.limb_);\n a[kLimbs] = zero_limb();\n for (size_t i = 0; i < kLimbs; ++i) {\n a[i + kLimbs + 1] = zero_limb();\n OPS::reduction_step(&a[i], mprime_, m_);\n }\n maybe_minus_m(a + kLimbs, a[2 * kLimbs]);\n N r;\n mov(kLimbs, r.limb_, a + kLimbs);\n return r;\n }\n\n Elt to_montgomery(const N& xn) const {\n Elt x{xn};\n mul(x, rsquare_);\n return x;\n }\n\n bool in_subfield(const Elt& e) const { return true; }\n\n // The of_scalar methods should only be used on trusted inputs known\n // at compile time to be valid field elements. As a result, they return\n // Elt directly instead of std::optional, and panic if the condition is not\n // satisfied. All untrusted input should be handled via the of_bytes method.\n Elt of_scalar(uint64_t a) const { return of_scalar_field(a); }\n\n Elt of_scalar_field(uint64_t a) const { return of_scalar_field(N(a)); }\n Elt of_scalar_field(const std::array& a) const {\n return of_scalar_field(N(a));\n }\n Elt of_scalar_field(const N& a) const {\n check(a < m_, \"of_scalar must be less than m\");\n return to_montgomery(a);\n }\n\n std::optional of_bytes_field(const uint8_t ab[/* kBytes */]) const {\n N an = N::of_bytes(ab);\n if (an < m_) {\n return to_montgomery(an);\n } else {\n return std::nullopt;\n }\n }\n\n void to_bytes_field(uint8_t ab[/* kBytes */], const Elt& x) const {\n from_montgomery(x).to_bytes(ab);\n }\n\n std::optional of_bytes_subfield(const uint8_t ab[/* kBytes */]) const {\n return of_bytes_field(ab);\n }\n\n void to_bytes_subfield(uint8_t ab[/* kBytes */], const Elt& x) const {\n to_bytes_field(ab, x);\n }\n\n const Elt& zero() const { return k_[0]; }\n const Elt& one() const { return k_[1]; }\n const Elt& two() const { return k_[2]; }\n const Elt& half() const { return half_; }\n const Elt& mone() const { return mone_; }\n\n Elt poly_evaluation_point(size_t i) const {\n check(i < kNPolyEvaluationPoints, \"i < kNPolyEvaluationPoints\");\n return poly_evaluation_points_[i];\n }\n\n // return (X[k] - X[k - i])^{-1}, were X[i] is the\n // i-th poly evalaluation point.\n Elt newton_denominator(size_t k, size_t i) const {\n check(k < kNPolyEvaluationPoints, \"k < kNPolyEvaluationPoints\");\n check(i <= k, \"i <= k\");\n check(k != (k - i), \"k != (k - i)\");\n return inv_small_scalars_[/* k - (k - i) = */ i];\n }\n\n private:\n void maybe_minus_m(limb_t a[kLimbs], limb_t ah) const {\n limb_t a1[kLimbs];\n mov(kLimbs, a1, negm_.limb_);\n limb_t ah1 = add_limb(kLimbs, a1, a);\n cmovne(kLimbs, a, ah, ah1, a1);\n }\n void maybe_plus_m(limb_t a[kLimbs], limb_t ah) const {\n limb_t a1[kLimbs];\n mov(kLimbs, a1, a);\n (void)add_limb(kLimbs, a1, m_.limb_);\n cmovnz(kLimbs, a, ah, a1);\n }\n\n void byhalf(Elt& a) const {\n if (a.n.shiftr(1) != 0) {\n // the lost bit is a raw 1, not one() in Montgomery form,\n // hence we must add a raw 1/2, not half().\n add(a, raw_half_);\n }\n }\n\n // unoptimized montgomery multiplication that does not\n // depend on the constants zero() and one() being defined.\n void mul0(Elt& x, const Elt& y) const {\n limb_t a[2 * kLimbs + 1]; // uninitialized\n mulstep(a, x.n.limb_[0], y.n.limb_);\n for (size_t i = 1; i < kLimbs; ++i) {\n mulstep(a + i, x.n.limb_[i], y.n.limb_);\n }\n maybe_minus_m(a + kLimbs, a[2 * kLimbs]);\n mov(kLimbs, x.n.limb_, a + kLimbs);\n }\n\n template \n inline void mulstep(limb_t* a, limb_t x, const limb_t y[kLimbs]) const {\n if (kLimbs == 1) {\n // The general case (below) represents the (kLimbs+1)-word\n // product as L+(H<();\n check(first, \"mulstep template must be have first=true for 1 limb\");\n mulhl(1, a, a + 1, x, y);\n OPS::reduction_step(a, mprime_, m_);\n } else {\n limb_t l[kLimbs], h[kLimbs];\n a[kLimbs + 1] = zero_limb();\n if (first) {\n a[kLimbs] = zero_limb();\n mulhl(kLimbs, a, h, x, y);\n } else {\n mulhl(kLimbs, l, h, x, y);\n accum(kLimbs + 1, a, kLimbs, l);\n }\n accum(kLimbs + 1, a + 1, kLimbs, h);\n OPS::reduction_step(a, mprime_, m_);\n }\n }\n\n // This method should only be used on static strings known at\n // compile time to be valid field elements. We make it\n // private to prevent misuse.\n Elt of_charp(const char* s) const {\n Elt a(k_[0]);\n Elt base = of_scalar(10);\n if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) {\n s += 2;\n base = of_scalar(16);\n }\n\n for (; *s; s++) {\n Elt d = of_scalar(digit(*s));\n mul(a, base);\n add(a, d);\n }\n return a;\n }\n\n N m_;\n N negm_;\n Elt rsquare_;\n limb_t mprime_;\n Elt k_[3]; // small constants\n Elt half_; // 1/2\n Elt raw_half_;\n Elt mone_; // minus one\n Elt poly_evaluation_points_[kNPolyEvaluationPoints];\n Elt inv_small_scalars_[kNPolyEvaluationPoints];\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_GENERIC_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_revocation_witness.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_REVOCATION_WITNESS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_REVOCATION_WITNESS_H_\n\n#include \n#include \n#include \n#include \n\n#include \"arrays/dense.h\"\n#include \"circuits/ecdsa/verify_witness.h\"\n#include \"circuits/logic/bit_plucker_encoder.h\"\n#include \"circuits/mdoc/mdoc_revocation_constants.h\"\n#include \"circuits/sha/flatsha256_witness.h\"\n\nnamespace proofs {\n\ntemplate \ntypename Field::Elt compute_mdoc_revocation_list_witness(\n typename Field::Elt id, const typename Field::Elt list[], size_t list_size,\n const Field& F) {\n typename Field::Elt prodinv = F.one();\n for (size_t i = 0; i < list_size; ++i) {\n prodinv = F.mulf(prodinv, F.subf(list[i], id));\n }\n F.invert(prodinv);\n return prodinv;\n}\n\ntemplate \nclass MdocRevocationSpanWitness {\n using Field = typename EC::Field;\n using Elt = typename Field::Elt;\n using Nat = typename Field::N;\n using EcdsaWitness = VerifyWitness3;\n const EC& ec_;\n\n public:\n Elt e_, r_, s_;\n EcdsaWitness sig_;\n uint8_t preimage_[64 * 2];\n uint8_t id_bits_[256];\n uint8_t e_bits_[256];\n FlatSHA256Witness::BlockWitness sha_bw_[2];\n\n explicit MdocRevocationSpanWitness(const EC& ec, const ScalarField& Fn)\n : ec_(ec), sig_(Fn, ec) {}\n\n void fill_witness(DenseFiller& filler) const {\n filler.push_back(r_);\n filler.push_back(s_);\n filler.push_back(e_);\n sig_.fill_witness(filler);\n\n // Write the span message.\n for (size_t i = 0; i < 64 * 2; ++i) {\n for (size_t j = 0; j < 8; ++j) {\n filler.push_back((preimage_[i] >> j) & 0x1 ? ec_.f_.one()\n : ec_.f_.zero());\n }\n }\n\n for (size_t i = 0; i < 256; ++i) {\n filler.push_back(id_bits_[i] ? ec_.f_.one() : ec_.f_.zero());\n }\n for (size_t i = 0; i < 256; ++i) {\n filler.push_back(e_bits_[i] ? ec_.f_.one() : ec_.f_.zero());\n }\n\n for (size_t j = 0; j < 2; j++) {\n fill_sha(filler, sha_bw_[j]);\n }\n }\n\n void fill_sha(DenseFiller& filler,\n const FlatSHA256Witness::BlockWitness& bw) const {\n BitPluckerEncoder BPENC(ec_.f_);\n for (size_t k = 0; k < 48; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.outw[k]));\n }\n for (size_t k = 0; k < 64; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.oute[k]));\n filler.push_back(BPENC.mkpacked_v32(bw.outa[k]));\n }\n for (size_t k = 0; k < 8; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.h1[k]));\n }\n }\n\n bool compute_witness(Elt pkX, Elt pkY, Nat ne, Nat nr, Nat ns, Nat id, Nat ll,\n Nat rr, uint64_t epoch) {\n e_ = ec_.f_.to_montgomery(ne);\n r_ = ec_.f_.to_montgomery(nr);\n s_ = ec_.f_.to_montgomery(ns);\n sig_.compute_witness(pkX, pkY, ne, nr, ns);\n\n std::vector buf;\n for (size_t i = 0; i < 8; ++i) {\n buf.push_back(epoch & 0xff);\n epoch >>= 8;\n }\n uint8_t tmp[Field::kBytes];\n ll.to_bytes(tmp);\n buf.insert(buf.end(), tmp, tmp + Field::kBytes);\n rr.to_bytes(tmp);\n buf.insert(buf.end(), tmp, tmp + Field::kBytes);\n\n for (size_t i = 0; i < 256; ++i) {\n id_bits_[i] = id.bit(i);\n e_bits_[i] = ne.bit(i);\n }\n\n uint8_t numb = 0;\n FlatSHA256Witness::transform_and_witness_message(buf.size(), buf.data(), 2,\n numb, preimage_, sha_bw_);\n\n return true;\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_REVOCATION_WITNESS_H_\n"], ["/longfellow-zk/lib/circuits/anoncred/small_witness.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_WITNESS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_WITNESS_H_\n\n#include \n#include \n\n#include \n#include \n\n#include \"algebra/static_string.h\"\n#include \"arrays/dense.h\"\n#include \"circuits/anoncred/small_io.h\"\n#include \"circuits/ecdsa/verify_witness.h\"\n#include \"circuits/logic/bit_plucker_encoder.h\"\n#include \"circuits/mdoc/mdoc_witness.h\"\n#include \"circuits/sha/flatsha256_witness.h\"\n\nnamespace proofs {\n\nclass SmallOpenedAttribute {\n public:\n size_t ind_, len_;\n std::vector value_;\n SmallOpenedAttribute(size_t ind, size_t len, const uint8_t* val, size_t vlen)\n : ind_(ind), len_(len), value_(val, val + vlen) {}\n};\n\ntemplate \nclass SmallWitness {\n using ECField = typename EC::Field;\n using ECElt = typename ECField::Elt;\n using ECNat = typename ECField::N;\n using Elt = typename Field::Elt;\n using Nat = typename Field::N;\n using EcdsaWitness = VerifyWitness3;\n static constexpr size_t kMaxSHABlocks = 7;\n\n public:\n const EC ec_;\n Elt e_, e2_; /* Issuer signature values. */\n Elt dpkx_, dpky_; /* device key */\n EcdsaWitness ew_, dkw_;\n uint8_t now_[kDateLen]; /* CBOR-formatted time used for expiry comparison. */\n\n FlatSHA256Witness::BlockWitness bw_[kMaxSHABlocks];\n uint8_t signed_bytes_[kMaxSHABlocks * 64];\n uint8_t numb_; /* Number of the correct sha block. */\n\n explicit SmallWitness(const EC& ec, const ScalarField& Fn)\n : ec_(ec), ew_(Fn, ec), dkw_(Fn, ec) {}\n\n void fill_sha(DenseFiller& filler,\n const FlatSHA256Witness::BlockWitness& bw) const {\n BitPluckerEncoder BPENC(ec_.f_);\n for (size_t k = 0; k < 48; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.outw[k]));\n }\n for (size_t k = 0; k < 64; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.oute[k]));\n filler.push_back(BPENC.mkpacked_v32(bw.outa[k]));\n }\n for (size_t k = 0; k < 8; ++k) {\n filler.push_back(BPENC.mkpacked_v32(bw.h1[k]));\n }\n }\n\n void fill_witness(DenseFiller& filler, bool small = false) const {\n filler.push_back(e_);\n filler.push_back(dpkx_);\n filler.push_back(dpky_);\n\n ew_.fill_witness(filler);\n dkw_.fill_witness(filler);\n\n filler.push_back(numb_, 8, ec_.f_);\n for (size_t i = 0; i < kMaxSHABlocks * 64; ++i) {\n filler.push_back(signed_bytes_[i], 8, ec_.f_);\n }\n for (size_t j = 0; j < kMaxSHABlocks; j++) {\n fill_sha(filler, bw_[j]);\n }\n }\n\n bool compute_witness(Elt pkX, Elt pkY, const uint8_t mdoc[/* len */],\n size_t len, const uint8_t transcript[/* tlen */],\n size_t tlen, const uint8_t tnow[/*kDateLen*/],\n const StaticString& r, const StaticString& s,\n const StaticString& dr, const StaticString& ds) {\n Nat ne = nat_from_hash(mdoc, len);\n e_ = ec_.f_.to_montgomery(ne);\n\n // Parse (r,s).\n Nat nr = Nat(r);\n Nat ns = Nat(s);\n ew_.compute_witness(pkX, pkY, ne, nr, ns);\n\n Nat ne2 = nat_from_hash(transcript, tlen);\n Nat nr2 = Nat(dr);\n Nat ns2 = Nat(ds);\n\n dpkx_ = ec_.f_.to_montgomery(nat_from_be(&mdoc[100]));\n dpky_ = ec_.f_.to_montgomery(nat_from_be(&mdoc[132]));\n e2_ = ec_.f_.to_montgomery(ne2);\n dkw_.compute_witness(dpkx_, dpky_, ne2, nr2, ns2);\n\n FlatSHA256Witness::transform_and_witness_message(len, mdoc, kMaxSHABlocks,\n numb_, signed_bytes_, bw_);\n\n memcpy(now_, tnow, kDateLen);\n return true;\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_WITNESS_H_\n"], ["/longfellow-zk/lib/circuits/compiler/compiler.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_COMPILER_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_COMPILER_H_\n\n#include \n#include \n\n#include \n#include \n#include \n\n#include \"algebra/hash.h\"\n#include \"circuits/compiler/circuit_id.h\"\n#include \"circuits/compiler/node.h\"\n#include \"circuits/compiler/pdqhash.h\"\n#include \"circuits/compiler/schedule.h\"\n#include \"sumcheck/circuit.h\"\n#include \"sumcheck/quad.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n/*\nQuadCircuit contains methods that facilitate defining circuits used to\nexpress predicates that are to be proven or verified. This class allows one\nto use basic arithmetic circuit operations (add, mul, input, assert0, ...)\nto define the circuit on a set of abstract wire labels.\n\nThe \"mkcircuit\" compiler method than optimizes the circuit by applying all of\nthe basic tricks of constant propagation, common sub-expression elimination,\nsquashing layers into as few as possible, and grouping terms into quads.\n\nQuads are a new form of gate (in contrast to the add and mul gates in most\nsumcheck proof systems). Quads represent a \"sum of quadratic terms\" where\neach term is w_l * w_r * v for two wire labels and a constant v.\n*/\ntemplate \nclass QuadCircuit {\n public:\n using Elt = typename Field::Elt;\n using nodeinfo = NodeInfoF;\n using node = NodeF;\n using size_t_for_storage = term::size_t_for_storage;\n using quad_corner_t = typename Quad::quad_corner_t;\n\n const Field& f_;\n\n public:\n // Variables for informational purposes:\n size_t ninput_;\n size_t npub_input_; // number of public inputs, index of 1st private\n size_t subfield_boundary_; // least wire not known to be in the subfield\n size_t noutput_;\n\n // set by the algebraic simplifiers in this file\n size_t depth_;\n size_t nwires_cse_eliminated_;\n size_t nwires_not_needed_;\n\n // set by the scheduler\n size_t nwires_;\n size_t nquad_terms_;\n size_t nwires_overhead_;\n\n explicit QuadCircuit(const Field& f)\n : f_(f),\n ninput_(0),\n npub_input_(0),\n subfield_boundary_(0),\n noutput_(0),\n depth_(0),\n nwires_cse_eliminated_(0),\n nwires_not_needed_(0),\n nwires_(-1), // undefined until set in mkcircuit()\n nquad_terms_(-1),\n nwires_overhead_(-1) {\n // make sure that Elt(0) is represented as index 0 in the constant\n // table.\n size_t ki0 = kstore(f.zero());\n proofs::check(ki0 == 0, \"ki0 == 0\");\n size_t ki1 = kstore(f.one());\n proofs::check(ki1 == 1, \"ki1 == 1\");\n\n // make sure node 0 exists, carrying input[0] = F.one()\n input();\n }\n\n // Produce a linear term 1 * op0 that the compiler will not\n // attempt to optimize to op0. The reason for this function\n // is to implement linear terms such as a*x in the quadratic form\n // a*x+b*x*y. Left to its own devices, the compiler peeks into x,\n // and if x=k*z*w, it produces a term (a*k)*z*w in the previous\n // layer, possibly destroying common subexpressions. linear(op)\n // introduces an explicit multiplication by wire 0, which the\n // compiler does not attempt to optimize away.\n size_t linear(size_t op0) { return mul(0, op0); }\n size_t linear(const Elt& k, size_t op0) { return mul(k, 0, op0); }\n\n size_t mul(const Elt& k, size_t op) {\n if (k == f_.zero()) {\n return konst(k);\n } else if (k == f_.one() || nodes_[op].zero()) {\n return op;\n } else {\n return push_node(scale(k, op));\n }\n }\n\n size_t mul(size_t op0, size_t op1) { return mul(f_.one(), op0, op1); }\n\n size_t mul(const Elt& k, size_t op0, size_t op1) {\n const auto& n0 = nodes_[op0];\n const auto& n1 = nodes_[op1];\n\n if (n0.zero()) {\n return op0;\n } else if (n0.constant()) {\n // k * (k1 * op1) -> (k * k1) * op1\n return mul(f_.mulf(k, kload(n0.terms[0].ki)), op1);\n } else if (n0.linearp()) {\n // k * ((k1 * op0) * op1) -> (k * k1) * op0 * op1\n return mul(f_.mulf(k, kload(n0.terms[0].ki)), n0.terms[0].op1, op1);\n } else if (n1.zero() || n1.constant() || n1.linearp()) {\n return mul(k, op1, op0);\n } else {\n // general term k * op0 * op1\n return push_node(node(kstore(k), op0, op1));\n }\n }\n\n size_t add(size_t op0, size_t op1) {\n const auto& n0 = nodes_[op0];\n const auto& n1 = nodes_[op1];\n\n if (n0.zero()) {\n return op1;\n } else if (n1.zero()) {\n return op0;\n } else {\n // If the two addends are of different depth, do not merge\n // them, which is accomplished by multiplying the shallower\n // node by 1 and treating it as a single term of the final\n // sum.\n //\n // Like many other \"optimizations\", this is a heuristic\n // that may or may not work, but it seems to be uniformly\n // beneficial or at least not harmful for all our circuits\n // as of 2023-11-15.\n if (n0.info.depth < n1.info.depth) {\n op0 = linear(op0);\n } else if (n1.info.depth < n0.info.depth) {\n op1 = linear(op1);\n }\n return push_node(merge(op0, op1));\n }\n }\n size_t sub(size_t op0, size_t op1) { return add(op0, mul(f_.mone(), op1)); }\n\n size_t konst(const Elt& k) { return push_node(node(kstore(k), 0, 0)); }\n\n // Generate a special node that asserts that op == 0.\n // The node has the form 0*(1*op), which does not normally\n // appear in circuits.\n size_t assert0(size_t op) {\n const node* n = &nodes_[op];\n if (n->zero()) {\n // Identically zero, so nothing to generate.\n // More importantly, we cannot multiply OP by 1,\n // since OP doesn't really exist.\n return op;\n } else if (n->linearp()) {\n // n = k * (1 * op1).\n //\n // Reduce to assert0(op1), but handle the screw case k==0,\n // which shouldn't happen but just in case...\n if (n->terms[0].ki == 0) {\n return op;\n } else {\n return assert0(n->terms[0].op1);\n }\n } else {\n typename term::assert0_type_hack hack;\n std::vector terms;\n terms.push_back(term(op, hack));\n size_t n1 = push_node(node(terms));\n nodes_[n1].info.is_assert0 = true;\n return n1;\n }\n }\n\n // Wrappers to avoid creating unnecessary wires. The\n // compiler will discard them anyway, but they still take\n // time and space.\n size_t axpy(size_t y, const Elt& a, size_t x) {\n if (a == f_.zero()) {\n return y;\n }\n return add(y, linear(a, x));\n }\n size_t apy(size_t y, const Elt& a) {\n if (a == f_.zero()) {\n return y;\n }\n return add(y, konst(a));\n }\n\n size_t input() { return push_node(node(quad_corner_t(ninput_++))); }\n\n // This function demarcates the end of the public inputs and beginning of\n // private inputs. It can only be called once.\n void private_input() {\n proofs::check(\n npub_input_ == 0,\n \"private_input can only be called once after setting public inputs\");\n npub_input_ = ninput_;\n }\n\n // This function demarcates the end of the private inputs in the\n // subfield and beginning of the full-field private inputs. It can\n // only be called once.\n void begin_full_field() {\n proofs::check(subfield_boundary_ == 0,\n \"begin_full_field() can only be called once\");\n subfield_boundary_ = ninput_;\n }\n\n size_t ninput() const { return ninput_; }\n\n void output(size_t n, size_t wire_id) {\n output_internal(n, quad_corner_t(wire_id));\n }\n\n std::unique_ptr> mkcircuit(size_t nc) {\n size_t depth_ub = compute_depth_ub();\n fixup_last_layer_assertions(depth_ub);\n compute_needed(depth_ub);\n\n Scheduler sched(nodes_, f_);\n std::unique_ptr> c =\n sched.mkcircuit(constants_, depth_ub, nc);\n\n // re-export the scheduler telemetry\n nwires_ = sched.nwires_;\n nquad_terms_ = sched.nquad_terms_;\n nwires_overhead_ = sched.nwires_overhead_;\n\n c->ninputs = ninput();\n c->npub_in = npub_input_;\n c->subfield_boundary = subfield_boundary_;\n\n circuit_id(c->id, *c, f_);\n return c;\n }\n\n private:\n void output_internal(size_t n, quad_corner_t wire_id) {\n nodes_[n].info.is_output = true;\n nodes_[n].info.desired_wire_id_for_output = wire_id;\n noutput_++;\n }\n\n size_t push_node(node n) {\n // common-subexpression elimination: if we have already seen a\n // node equal to n, return that node.\n uint64_t d = n.hash();\n\n auto pred = [&](PdqHash::value_t op) { return n == nodes_[op]; };\n if (size_t op = cse_.find(d, pred); op != PdqHash::kNil) {\n // do not linear terms as eliminated by the CSE, since they are\n // likely placeholder nodes absorbed by the next layer.\n if (!n.linearp()) {\n ++nwires_cse_eliminated_;\n }\n return op;\n }\n\n // compute the node depth, which has been so far uninitialized\n n.info.depth = 0;\n for (const auto& t : n.terms) {\n n.info.depth = std::max(\n n.info.depth, 1 + std::max(nodes_[t.op0].info.depth,\n nodes_[t.op1].info.depth));\n }\n\n size_t nid = nodes_.size();\n nodes_.push_back(n);\n\n // record NID into the common-subexpression elimination table\n cse_.insert(d, nid);\n\n return nid;\n }\n\n node materialize_input(size_t op) {\n if (nodes_[op].info.is_input) {\n return node(/*kstore(f.one())=*/1, 0, op);\n } else {\n return /*a copy of*/ nodes_[op];\n }\n }\n\n node scale(const Elt& k, size_t op) {\n node n = materialize_input(op);\n for (auto& t : n.terms) {\n t.ki = kstore(f_.mulf(kload(t.ki), k));\n }\n return n;\n }\n\n void push_back_unless_zero(std::vector& terms, const term& t) const {\n if (t.ki != 0) {\n terms.push_back(t);\n }\n }\n\n node merge(size_t op0, size_t op1) {\n const node n0 = materialize_input(op0);\n const node n1 = materialize_input(op1);\n const std::vector& t0 = n0.terms;\n const std::vector& t1 = n1.terms;\n std::vector terms;\n size_t i0 = 0, i1 = 0;\n while (i0 < t0.size() && i1 < t1.size()) {\n term t;\n if (t0[i0].eqndx(t1[i1])) {\n t = t0[i0];\n t.ki = kstore(f_.addf(kload(t.ki), kload(t1[i1].ki)));\n i0++;\n i1++;\n } else if (t0[i0].ltndx(t1[i1])) {\n t = t0[i0++];\n } else {\n t = t1[i1++];\n }\n push_back_unless_zero(terms, t);\n }\n\n while (i0 < t0.size()) {\n push_back_unless_zero(terms, t0[i0++]);\n }\n\n while (i1 < t1.size()) {\n push_back_unless_zero(terms, t1[i1++]);\n }\n\n return node(terms);\n }\n\n // constants_[n] stores the n-th constant, once.\n // Modulo collisions, constants_[constttab_[hash(k)]] == k\n // for k \\in Elt.\n std::vector constants_;\n PdqHash consttab_;\n\n std::vector nodes_;\n PdqHash cse_;\n\n size_t kstore(const Elt& k) {\n uint64_t d = elt_hash(k, f_);\n auto pred = [&](PdqHash::value_t ki) { return k == constants_[ki]; };\n size_t ki = consttab_.find(d, pred);\n\n if (ki == PdqHash::kNil) {\n ki = constants_.size();\n constants_.push_back(k);\n consttab_.insert(d, ki);\n }\n return ki;\n }\n Elt& kload(size_t ki) { return constants_[ki]; }\n\n void mark_needed(size_t op, size_t depth_at_which_needed) {\n nodeinfo* nfo = &nodes_[op].info;\n nfo->is_needed = true;\n nfo->max_needed_depth =\n std::max(depth_at_which_needed, nfo->max_needed_depth);\n\n // If DEPTH_AT_WHICH_NEEDED > DEPTH + 1, we need a constant 1 at\n // depth DEPTH_AT_WHICH_NEEDED-1 (and implicily any lower depths) in\n // order to copy the node across levels.\n if (depth_at_which_needed > nfo->depth + 1) {\n nodeinfo* nfo0 = &nodes_[0].info;\n nfo0->is_needed = true;\n nfo0->max_needed_depth =\n std::max(depth_at_which_needed - 1, nfo0->max_needed_depth);\n }\n }\n\n size_t compute_depth_ub() {\n size_t r = 0;\n for (auto& n : nodes_) {\n if (n.info.is_output) {\n r = std::max(r, 1 + n.info.depth);\n } else if (n.info.is_assert0) {\n // Assertions of the form 0*(1*OP) contibute n.info.depth and\n // not 1 + n.info.depth. If the assertion is in the last\n // layer, it will be transformed in an output of OP at\n // n.info.depth. If the assertion is not in the last layer,\n // then it doesn't matter whether we use DEPTH or 1 + DEPTH.\n if (n.linearp()) {\n r = std::max(r, n.info.depth);\n } else {\n r = std::max(r, 1 + n.info.depth);\n }\n }\n }\n depth_ = r;\n return r;\n }\n\n void fixup_last_layer_assertions(size_t depth_ub) {\n // convert assertions in the last layer into outputs\n for (auto& n : nodes_) {\n if (!n.info.is_output && n.info.is_assert0 && n.info.depth == depth_ub &&\n n.linearp()) {\n n.info.is_assert0 = false;\n output_internal(n.terms[0].op1, nodeinfo::kWireIdUndefined);\n }\n }\n }\n\n void compute_needed(size_t depth_ub) {\n nwires_not_needed_ = 0;\n for (size_t i = nodes_.size(); i-- > 0;) {\n nodeinfo* nfo = &nodes_[i].info;\n\n // mark all inputs as needed, to prevent ambiguity\n // in the layout of the W[] vector.\n if (nfo->is_input) {\n mark_needed(i, 1);\n }\n // outputs are needed at depth_ub_\n if (nfo->is_output) {\n mark_needed(i, depth_ub);\n }\n // assertions are needed in the next layer\n if (nfo->is_assert0) {\n mark_needed(i, nfo->depth + 1);\n }\n\n if (nfo->is_needed) {\n for (const auto& t : nodes_[i].terms) {\n mark_needed(t.op0, nfo->depth);\n mark_needed(t.op1, nfo->depth);\n }\n } else {\n ++nwires_not_needed_;\n }\n }\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_COMPILER_H_\n"], ["/longfellow-zk/lib/sumcheck/prover_layers.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_SUMCHECK_PROVER_LAYERS_H_\n#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_PROVER_LAYERS_H_\n\n#include \n\n#include \n#include \n\n#include \"arrays/affine.h\"\n#include \"arrays/dense.h\"\n#include \"arrays/eqs.h\"\n#include \"sumcheck/circuit.h\"\n#include \"sumcheck/quad.h\"\n#include \"sumcheck/transcript_sumcheck.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n\n// A high level idea is partially described in chapter 4.6.7 \"Leveraging Data\n// Parallelism for Further Speedups\" in the book \"Proofs, Arguments, and\n// Zero-Knowledge\" by Justin Thaler.\ntemplate \nclass ProverLayers {\n using Elt = typename Field::Elt;\n\n public:\n using inputs = std::vector>>;\n\n explicit ProverLayers(const Field& f) : f_(f) {}\n\n // Evaluate CIRCUIT on input wires W0. This function stores the\n // input wires of each layer L into IN->at(L), and returns the\n // final output. This asymmetry reflects the fact that for L\n // layers there are L+1 meaningful sets of wires, and that the\n // prover needs IN while the verifier needs the final output.\n std::unique_ptr> eval_circuit(inputs* in,\n const Circuit* circ,\n std::unique_ptr> W0,\n const Field& F) {\n if (in == nullptr || circ == nullptr || W0 == nullptr) return nullptr;\n\n std::unique_ptr> finalV;\n size_t nl = circ->nl, nc = circ->nc;\n check(nl >= 1, \"nl >= 1\");\n check(nc >= 1, \"nc >= 1\");\n\n Dense* W = W0.get();\n\n in->resize(nl);\n in->at(nl - 1).swap(W0);\n\n // Allocate memory and evaluate layer on input W and output V\n for (size_t l = nl; l-- > 0;) {\n Dense* V;\n if (l > 0) {\n // input of layer l-1 = output of layer l\n in->at(l - 1) = std::make_unique>(nc, circ->l[l - 1].nw);\n V = in->at(l - 1).get();\n } else {\n // final output = output of layer 0\n finalV = std::make_unique>(nc, circ->nv);\n V = finalV.get();\n }\n\n bool ok = eval_quad(circ->l[l].quad.get(), V, W, F);\n if (!ok) {\n // Early exit in case of assertion failure.\n // In this case IN is only partially allocated.\n // To avoid ambiguities, free all memory that we may have allocated.\n for (size_t i = 0; i < nl; ++i) {\n in->at(i) = nullptr;\n }\n finalV = nullptr;\n\n return /*finalV=*/nullptr;\n }\n\n W = V;\n }\n\n return finalV;\n }\n\n protected:\n const Field& f_;\n\n // A struct that collects the bindings generated while proving one\n // layer, to serve as initial bindings for the next layer.\n // This protected class must be defined before the public section.\n struct bindings {\n size_t logv;\n Elt q[Proof::kMaxBindings];\n Elt g[2][Proof::kMaxBindings];\n };\n\n // Generate proof for circuit, as a protected member, the caller must\n // ensure that input parameters are valid.\n void prove(Proof* pr, const Proof* pad,\n const Circuit* circ, const inputs& in, ProofAux* aux,\n bindings& bnd, TranscriptSumcheck& ts, const Field& F) {\n size_t logc = circ->logc;\n corner_t nc = circ->nc;\n\n check(circ->logv <= Proof::kMaxBindings,\n \"CIRCUIT->logv <= kMaxBindings\");\n bnd.logv = circ->logv;\n\n // obtain the initial Q and G[0] bindings from the verifier\n ts.begin_circuit(bnd.q, bnd.g[0]);\n\n // Duplicate the g[0] binding.\n // In general, the prover step takes two claims G[0], G[1] on the output\n // wires and reduces them to one claim on G[0] + alpha * G[1] for random\n // alpha. However, in the first step, there is only one claim, so we\n // need to make up G[1]. The code sets G[1] = G[0] and it doesn't affect\n // soundness.\n for (size_t i = 0; i < bnd.logv; ++i) {\n bnd.g[1][i] = bnd.g[0][i];\n }\n\n for (size_t ly = 0; ly < circ->nl; ++ly) {\n auto clr = &circ->l.at(ly);\n Elt alpha, beta;\n ts.begin_layer(alpha, beta, ly);\n Eqs EQ(logc, nc, bnd.q, F);\n auto QUAD = clr->quad->clone();\n QUAD->bind_g(bnd.logv, bnd.g[0], bnd.g[1], alpha, beta, F);\n\n layer(pr, pad, ts, bnd, ly, logc, clr->logw, &EQ, QUAD.get(),\n in.at(ly).get(), F);\n\n if (aux != nullptr) {\n aux->bound_quad[ly] = QUAD->scalar();\n }\n }\n }\n\n private:\n using index_t = typename Quad::index_t;\n using CPoly = typename LayerProof::CPoly;\n using WPoly = typename LayerProof::WPoly;\n\n /*\n Engage in single-layer sumcheck on\n\n EQ[|c] QUAD[|r,l] W[r,c] W[l,c]\n\n Bind c to C, r to R, and l to L (in that order). Store claims\n W[R,C] and W[L,C] in the proof, and set BND to the new bindings for\n the next layer.\n\n logw: number of sumcheck rounds in r, l\n logc: number of sumcheck rounds in c\n */\n void layer(Proof* pr, const Proof* pad,\n TranscriptSumcheck& ts, bindings& bnd, size_t layer,\n size_t logc, size_t logw, Eqs* EQ, Quad* QUAD,\n Dense* W, const Field& F) {\n check(EQ->n() == W->n0_, \"EQ->n() == W->n0_\");\n\n check(logw <= Proof::kMaxBindings, \"logw <= kMaxBindings\");\n bnd.logv = logw;\n\n // Bind the C variables to Q.\n // Note that binding C variables takes O(number_of_copies * circuit_size)\n // while binding R, L takes O(circuit_size * log(circuit_size)). In most\n // cases number_of_copies > log(circuit_size), so we don't have to\n // optimize binding R, L.\n for (size_t round = 0; round < logc; ++round) {\n CPoly sum{};\n\n // sum over r,l: QUAD[|r,l] EQ[|c] W[r,c] W[l,c]\n for (index_t i = 0; i < QUAD->n_; i++) {\n corner_t r(QUAD->c_[i].h[0]);\n corner_t l(QUAD->c_[i].h[1]);\n\n // sum over c: EQ[|c] W[r,c] W[l,c]\n CPoly sumc{};\n\n // n0_ is the copy dimension, n1_ is the wire dimension.\n for (corner_t c = 0; c < W->n0_; c += 2) {\n CPoly poly = cpoly_at_dense(EQ, c, 0, F)\n .mul(cpoly_at_dense(W, c, r, F), F)\n .mul(cpoly_at_dense(W, c, l, F), F);\n sumc.add(poly, F);\n }\n\n sumc.mul_scalar(QUAD->c_[i].v, F);\n sum.add(sumc, F);\n }\n\n Elt rnd = round_c(pr, pad, ts, layer, round, sum, F);\n bnd.q[round] = rnd;\n\n // bind the c variable in both EQ and W\n EQ->bind(rnd, F);\n W->bind(rnd, F);\n }\n\n Elt eq0 = EQ->scalar();\n\n W->reshape(W->n1_);\n check(W->n1_ == 1, \"W->n1_ == 1\");\n\n auto Wclone = W->clone(); // keep alive until function end\n Dense* WH[2] = {W, Wclone.get()}; // reuse W\n\n for (size_t round = 0; round < logw; ++round) {\n for (size_t hand = 0; hand < 2; hand++) {\n // In SUM_{l,r} Q[l,r] W[l] W[r], first precompute QW[l] =\n // SUM_{r} Q[l,r] W[r] as a dense array, and then compute\n // SUM_{l} QW[l] W[l].\n Dense QW(WH[hand]->n0_, 1);\n QW.clear(F);\n size_t ohand = 1 - hand;\n\n // QW[l] = SUM_{r} Q[l,r] W[r]\n for (index_t i = 0; i < QUAD->n_; ++i) {\n corner_t p0(QUAD->c_[i].h[hand]);\n corner_t p1(QUAD->c_[i].h[ohand]);\n F.add(QW.v_[p0], F.mulf(QUAD->c_[i].v, WH[ohand]->v_[p1]));\n }\n\n // SUM_{l} QW[l] W[l].\n WPoly sum{};\n for (corner_t l = 0; l < QW.n0_; l += 2) {\n WPoly poly = wpoly_at_dense(WH[hand], l, 0, F)\n .mul(wpoly_at_dense(&QW, l, 0, F), F);\n sum.add(poly, F);\n }\n\n sum.mul_scalar(eq0, F);\n Elt rnd = round_h(pr, pad, ts, layer, hand, round, sum, F);\n bnd.g[hand][round] = rnd;\n\n // bind the r variable in W[hand] and QUAD\n WH[hand]->bind(rnd, F);\n QUAD->bind_h(rnd, hand, F);\n }\n }\n\n QUAD->scalar(); // for the side effect of assertions\n Elt WC[2] = {WH[0]->scalar(), WH[1]->scalar()};\n end_layer(pr, pad, ts, layer, WC, F);\n }\n\n // Evaluate the quadratic form\n //\n // V[g,c] = QUAD[g|r,l] W[r,c] W[l,c]\n //\n // Returns false in the case the quad is an assert0 check that fails.\n bool eval_quad(const Quad* quad, Dense* V,\n const Dense* W, const Field& F) {\n check(V->n0_ == W->n0_, \"V->n0_ == W->n0_\");\n corner_t n0 = V->n0_;\n\n V->clear(F);\n for (index_t i = 0; i < quad->n_; i++) {\n corner_t g(quad->c_[i].g);\n corner_t r(quad->c_[i].h[0]);\n corner_t l(quad->c_[i].h[1]);\n for (corner_t c = 0; c < n0; ++c) {\n auto x = quad->c_[i].v;\n if (x == F.zero()) {\n // assert that the computed W[l]W[r] is zero.\n auto y = W->v_[n0 * l + c];\n F.mul(y, W->v_[n0 * r + c]);\n if (y != F.zero()) {\n return false;\n }\n } else {\n F.mul(x, W->v_[n0 * l + c]);\n F.mul(x, W->v_[n0 * r + c]);\n F.add(V->v_[n0 * g + c], x);\n }\n }\n }\n return true;\n }\n\n Elt /*R*/ round_c(Proof* pr, const Proof* pad,\n TranscriptSumcheck& ts, size_t layer, size_t round,\n CPoly poly, const Field& F) {\n check(round <= Proof::kMaxBindings, \"round <= kMaxBindings\");\n\n if (pad) {\n poly.sub(pad->l[layer].cp[round], F);\n }\n\n pr->l[layer].cp[round] = poly;\n return ts.round(poly);\n }\n\n Elt /*R*/ round_h(Proof* pr, const Proof* pad,\n TranscriptSumcheck& ts, size_t layer, size_t hand,\n size_t round, WPoly poly, const Field& F) {\n check(round <= Proof::kMaxBindings, \"round <= kMaxBindings\");\n if (pad) {\n poly.sub(pad->l[layer].hp[hand][round], F);\n }\n pr->l[layer].hp[hand][round] = poly;\n return ts.round(poly);\n }\n\n void end_layer(Proof* pr, const Proof* pad,\n TranscriptSumcheck& ts, size_t layer, const Elt wc[2],\n const Field& F) {\n Elt tt[2] = {wc[0], wc[1]};\n if (pad) {\n F.sub(tt[0], pad->l[layer].wc[0]);\n F.sub(tt[1], pad->l[layer].wc[1]);\n }\n\n pr->l[layer].wc[0] = tt[0];\n pr->l[layer].wc[1] = tt[1];\n\n ts.write(tt, 1, 2);\n }\n\n CPoly cpoly_at_dense(const Dense* D, corner_t p0, corner_t p1,\n const Field& F) {\n return CPoly::extend(D->t2_at_corners(p0, p1, F), F);\n }\n\n WPoly wpoly_at_dense(const Dense* D, corner_t p0, corner_t p1,\n const Field& F) {\n return WPoly::extend(D->t2_at_corners(p0, p1, F), F);\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_PROVER_LAYERS_H_\n"], ["/longfellow-zk/lib/circuits/sha3/sha3_circuit.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA3_SHA3_CIRCUIT_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA3_SHA3_CIRCUIT_H_\n\n// arithmetized sha3 using logic bitvectors\n#include \n\n#include \n\n#include \"circuits/sha3/sha3_round_constants.h\"\n\nnamespace proofs {\ntemplate \nclass Sha3Circuit {\n typedef typename LogicCircuit::template bitvec<64> v64;\n\n const LogicCircuit& lc_;\n\n v64 of_scalar(uint64_t x) const { return lc_.template vbit<64>(x); }\n\n public:\n explicit Sha3Circuit(const LogicCircuit& lc) : lc_(lc) {}\n\n void keccak_f_1600(v64 A[5][5]) {\n for (size_t round = 0; round < 24; ++round) {\n // FIPS 202 3.2.1, theta\n v64 C[5];\n for (size_t x = 0; x < 5; ++x) {\n auto a01 = lc_.vxor(&A[x][0], A[x][1]);\n auto a23 = lc_.vxor(&A[x][2], A[x][3]);\n C[x] = lc_.vxor(&a01, lc_.vxor(&a23, A[x][4]));\n }\n\n for (size_t x = 0; x < 5; ++x) {\n v64 D_x = lc_.vxor(&C[(x + 4) % 5], lc_.vrotl(C[(x + 1) % 5], 1));\n for (size_t y = 0; y < 5; ++y) {\n A[x][y] = lc_.vxor(&A[x][y], D_x);\n }\n }\n\n // FIPS 202 3.2.2, rho\n {\n size_t x = 1, y = 0;\n for (size_t t = 0; t < 24; ++t) {\n A[x][y] = lc_.vrotl(A[x][y], sha3_rotc[t]);\n size_t nx = y, ny = (2 * x + 3 * y) % 5;\n x = nx;\n y = ny;\n }\n }\n\n // FIPS 202 3.2.3, pi\n v64 A1[5][5];\n for (size_t x = 0; x < 5; ++x) {\n for (size_t y = 0; y < 5; ++y) {\n A1[x][y] = A[(x + 3 * y) % 5][x];\n }\n }\n\n // FIPS 202 3.2.4, chi\n for (size_t x = 0; x < 5; ++x) {\n for (size_t y = 0; y < 5; ++y) {\n A[x][y] = lc_.vxor(&A1[x][y], lc_.vand(&A1[(x + 2) % 5][y],\n lc_.vnot(A1[(x + 1) % 5][y])));\n }\n }\n\n // FIPS 202 3.2.5, iota\n A[0][0] = lc_.vxor(&A[0][0], of_scalar(sha3_rc[round]));\n }\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA3_SHA3_CIRCUIT_H_\n"], ["/longfellow-zk/lib/arrays/dense.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ARRAYS_DENSE_H_\n#define PRIVACY_PROOFS_ZK_LIB_ARRAYS_DENSE_H_\n\n#include \n#include \n\n#include \n#include \n#include \n#include \n\n#include \"algebra/blas.h\"\n#include \"algebra/poly.h\"\n#include \"arrays/affine.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n// ------------------------------------------------------------\n// Dense representation of multi-affine function, heap-allocated.\n// The caller is responsible for instantiating const Field throughout call\n// duration.\ntemplate \nclass Dense {\n using T2 = Poly<2, Field>;\n using Elt = typename Field::Elt;\n\n public:\n corner_t n0_, n1_;\n\n // Row-major indexing: v_[i1*n0+i0] stores the value at (i0, i1)\n std::vector v_;\n\n explicit Dense(corner_t n0, corner_t n1) : n0_(n0), n1_(n1), v_(n0 * n1) {}\n\n // make0 replacement\n explicit Dense(const Field& F) : n0_(1), n1_(1), v_(1) { v_[0] = F.zero(); }\n\n // initialize dense array from P[i1*ldp+i0]\n explicit Dense(corner_t n0, corner_t n1, const Elt p[], size_t ldp)\n : n0_(n0), n1_(n1), v_(n0 * n1) {\n for (corner_t i1 = 0; i1 < n1; ++i1) {\n Blas::copy(n0, v_[i1 * n0], 1, &p[i1 * ldp], 1);\n }\n }\n\n Dense(const Dense& y) = delete;\n Dense(const Dense&& y) = delete;\n Dense operator=(const Dense& y) = delete;\n\n std::unique_ptr clone() const {\n auto d = std::make_unique(n0_, n1_);\n for (corner_t i = 0; i < n0_ * n1_; ++i) {\n d->v_[i] = v_[i];\n }\n return d;\n }\n\n void clear(const Field& F) { Blas::clear(n0_ * n1_, &v_[0], 1, F); }\n\n // For a given random number r, the binding operation computes\n // v[i] = (1 - r) * v[2 * i] + r * v[2 * i + 1]\n // = v[2 * i] + r * (v[2 * i + 1] - v[2 * i])\n // and shrinks the array v by half.\n void bind(const Elt& r, const Field& F) {\n corner_t rd = 0, wr = 0;\n for (corner_t i1 = 0; i1 < n1_; ++i1) {\n corner_t i0 = 0;\n while (2 * i0 + 1 < n0_) {\n v_[wr] = affine_interpolation(r, v_[rd], v_[rd + 1], F);\n i0++, rd += 2, wr += 1;\n }\n if (2 * i0 < n0_) {\n v_[wr] = affine_interpolation(r, v_[rd], F.zero(), F);\n i0++, rd++, wr++;\n }\n }\n n0_ = (n0_ + 1u) / 2u;\n }\n\n void bind_all(size_t logv, const Elt r[/*logv*/], const Field& F) {\n for (size_t v = 0; v < logv; ++v) {\n bind(r[v], F);\n }\n }\n\n Elt at(corner_t j) const { return v_[j]; }\n\n // Scale all elements by x, except for the last element in\n // the n0_ dimension, which is scaled by x_last. This \"last\" quirk\n // is used by EQ.\n void scale(const Elt& x, const Elt& x_last, const Field& F) {\n corner_t ndx = 0;\n for (corner_t i1 = 0; i1 < n1_; ++i1) {\n corner_t i0 = 0;\n for (; i0 + 1 < n0_; ++i0) {\n F.mul(v_[ndx++], x);\n }\n if (i0 < n0_) {\n F.mul(v_[ndx++], x_last);\n }\n }\n }\n\n Elt at_corners(corner_t p0, corner_t p1, const Field& F) const {\n if (p0 < n0_) {\n return v_[p1 * n0_ + p0];\n } else {\n return F.zero();\n }\n }\n\n T2 t2_at_corners(corner_t p0, corner_t p1, const Field& F) const {\n return T2{at_corners(p0, p1, F), at_corners(p0 + 1, p1, F)};\n }\n\n // The precondition for reshaping is that the first dimension must be\n // fully bound.\n void reshape(corner_t n0) {\n check(n0_ == 1, \"n0_ == 1\");\n check(n0 > 0, \"n0 > 0\");\n corner_t wasn1 = n1_;\n n0_ = n0;\n n1_ = n1_ / n0;\n check(n1_ * n0 == wasn1, \"n1_*n0 == wasn1\");\n }\n\n // This method can only be called after full binding; the caller\n // is responsible for ensuring that pre-condition.\n Elt scalar() {\n check(n0_ == 1, \"n0_ == 1\");\n check(n1_ == 1, \"n1_ == 1\");\n return v_[0];\n }\n};\n\n// Helper class to fill a dense array a la std::vector<>\n//\ntemplate \nclass DenseFiller {\n using Elt = typename Field::Elt;\n\n public:\n // Caller must ensure that W remains valid.\n explicit DenseFiller(Dense& W) : pos_(0), w_(W) {\n // only works in this special case\n check(w_.n0_ == 1, \"W_.n0_ == 1\");\n }\n\n DenseFiller& push_back(const Elt& x) {\n check(pos_ < w_.n1_, \"pos_ < w_.n1_\");\n w_.v_[pos_++] = x;\n return *this;\n }\n\n template \n DenseFiller& push_back(const std::array& a) {\n for (size_t i = 0; i < N; ++i) {\n push_back(a[i]);\n }\n return *this;\n }\n\n DenseFiller& push_back(const std::vector& a) {\n for (size_t i = 0; i < a.size(); ++i) {\n push_back(a[i]);\n }\n return *this;\n }\n\n // Push back a bit string derived from a number. The parameter \"bits\" is the\n // number of bits in the string, and \"x\" is the number to be converted. This\n // works for pushing v8, v32, etc.\n DenseFiller& push_back(uint64_t x, size_t bits, const Field& F) {\n for (size_t i = 0; i < bits; ++i) {\n push_back(F.of_scalar((x >> i) & 1));\n }\n return *this;\n }\n\n size_t size() const { return pos_; }\n\n private:\n size_t pos_;\n Dense& w_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ARRAYS_DENSE_H_\n"], ["/longfellow-zk/lib/ec/elliptic_curve.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_EC_ELLIPTIC_CURVE_H_\n#define PRIVACY_PROOFS_ZK_LIB_EC_ELLIPTIC_CURVE_H_\n\n#include \n#include \n\n#include \"algebra/nat.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n// Elliptic curve class that supports basic operations such as addition,\n// doubling. The algorithms are described in\n// https://eprint.iacr.org/2015/1060.pdf.\n// The const Field parameter is meant as a type check to keep different\n// elliptic curves from interacting. The convention is to use the last 5\n// digits of the coordinate field prime in base-10 to name a curve.\n// The kN template parameter describes the number of bits in the curve\n// order, e.g., to handle curves like P-521, K-283, etc.\ntemplate \nclass EllipticCurve {\n public:\n using Field = Field_;\n using Elt = typename Field::Elt;\n using N = Nat;\n\n static constexpr const size_t kBits = kN; /* # bits in size of the group */\n\n const Field& f_;\n Elt a_;\n Elt b_;\n Elt gx_, gy_, gz_; // generator of the group\n const Elt k2, k3, k8, k3b, k9b, k24b;\n\n struct ECPoint {\n Elt x;\n Elt y;\n Elt z;\n\n ECPoint() = default;\n ECPoint(const Elt& x, const Elt& y, const Elt& z) : x(x), y(y), z(z) {}\n };\n\n EllipticCurve(const Elt& a, const Elt& b, const Elt& gX, const Elt& gY,\n const Field_& F)\n : f_(F),\n a_(a),\n b_(b),\n gx_(gX),\n gy_(gY),\n gz_(F.one()),\n k2(F.of_scalar(2)),\n k3(F.of_scalar(3)),\n k8(F.of_scalar(8)),\n k3b(F.mulf(k3, b_)),\n k9b(F.mulf(F.of_scalar(9), b_)),\n k24b(F.mulf(F.of_scalar(24), b_)) {\n is_minus_3_a_ = (a_ == F.negf(k3));\n is_zero_a_ = (a_ == F.zero());\n }\n\n // This equality method makes no assumptions about whether the inputs\n // are valid points on the curve. Just verifying cross-mult is not\n // enough if one of the points is invalid. This method is not constant\n // time and can return early if any point is infinity.\n bool equal(const ECPoint& p, const ECPoint& q) const {\n // handle inf point, then point equality, and finally projective eq\n if (q.x == f_.zero() && q.z == f_.zero() && q.y != f_.zero() &&\n p.x == f_.zero() && p.z == f_.zero() && p.y != f_.zero()) {\n return true;\n }\n if (q.x == p.x && q.z == p.z && q.y == p.y) {\n return true;\n }\n\n return (f_.mulf(p.x, q.z) == f_.mulf(q.x, p.z) &&\n f_.mulf(p.y, q.z) == f_.mulf(q.y, p.z));\n }\n\n // This method assumes a point is either zero or has z=1 coordinate,\n // so it does not implement the full mathematical notion of Jacobian-form\n // ec point.\n bool is_on_curve(const ECPoint& p) const {\n if (equal(p, zero())) {\n return true;\n }\n // Do not support Jacobian coordinate with z != 1\"\n if (p.z != f_.one()) {\n return false;\n }\n return is_on_curve(p.x, p.y);\n }\n\n // This caller of the constructor must first verify that (x,y) is on the\n // curve using the isOnCurve() method.\n ECPoint point(const Elt& x, const Elt& y) const {\n ECPoint p(x, y, f_.one());\n check(is_on_curve(p), \"Invalid curve point\");\n return p;\n }\n\n void normalize(ECPoint& p) const {\n if (p.z == f_.zero()) return;\n f_.invert(p.z);\n f_.mul(p.x, p.z);\n f_.mul(p.y, p.z);\n p.z = f_.one();\n }\n\n void addE(ECPoint& p3, const ECPoint& p2) const {\n addE(p3.x, p3.y, p3.z, p3.x, p3.y, p3.z, p2.x, p2.y, p2.z);\n }\n\n void doubleE(ECPoint& p3) const {\n doubleE(p3.x, p3.y, p3.z, p3.x, p3.y, p3.z);\n }\n\n // Functional interface.\n ECPoint addEf(ECPoint p1, const ECPoint& p2) const {\n addE(p1, p2);\n return p1;\n }\n\n ECPoint doubleEf(ECPoint p1) const {\n doubleE(p1);\n return p1;\n }\n\n // Computes the elliptic curve point p * scalar.\n // This method is not constant time, but that is not necessary in the current\n // zk implementation.\n ECPoint scalar_multf(const ECPoint& p, const N& scalar) const {\n ECPoint x = p;\n ECPoint p3 = zero();\n for (size_t d = 0; d < N::kLimbs; ++d) {\n auto nd = scalar.limb_[d];\n for (size_t i = 0; i < N::kBitsPerLimb; ++i) {\n if (nd & 1) {\n addE(p3, x);\n }\n doubleE(x);\n nd >>= 1;\n }\n }\n return p3;\n }\n\n // Computes the multi-scalar elliptic curve point multiplication.\n // Input: p1, p2, ..., pn, and scalars s1, s2, ..., sn\n // Output: p1 * s1 + p2 * s2 + ... + pn * sn\n // This method is not a constant time operation.\n ECPoint scalar_multf(size_t n, ECPoint p[/*n*/], N scalar[/*n*/]) const {\n if (n == 0) {\n return zero();\n } else if (n == 1) {\n return scalar_multf(p[0], scalar[0]);\n } else {\n return bos_coster(n, p, scalar);\n }\n }\n\n ECPoint zero() const { return ECPoint(f_.zero(), f_.one(), f_.zero()); }\n ECPoint generator() const { return ECPoint(gx_, gy_, gz_); }\n\n // Check whether Y^2 = X^3 + aX + b.\n bool is_on_curve(const Elt& X, const Elt& Y) const {\n Elt left = f_.mulf(Y, Y);\n Elt X3 = f_.mulf(X, f_.mulf(X, X));\n Elt right = f_.addf(f_.addf(X3, f_.mulf(a_, X)), b_);\n return left == right;\n }\n\n void addE(Elt& X3o, Elt& Y3o, Elt& Z3o, const Elt& X1, const Elt& Y1,\n const Elt& Z1, const Elt& X2, const Elt& Y2, const Elt& Z2) const {\n // Optimized special cases.\n if (is_zero_a_) return addEZeroA(X3o, Y3o, Z3o, X1, Y1, Z1, X2, Y2, Z2);\n if (is_minus_3_a_)\n return addEMinus3A(X3o, Y3o, Z3o, X1, Y1, Z1, X2, Y2, Z2);\n\n /*\n Source: 1998 Cohen–Miyaji–Ono \"Efficient elliptic curve exponentiation using\n mixed coordinates\", formula (3), plus common-subexpression elimination.\n These equations are taken from the Hyperelliptic curve formula database.\n This could have special short-cuts for addition with inf and self-addition,\n which speeds up all multi-exponentiation computations that involve a lot of\n small exponents.\n */\n if (X1 == f_.zero() && Z1 == f_.zero()) {\n X3o = X2;\n Y3o = Y2;\n Z3o = Z2;\n return;\n }\n\n if (X2 == f_.zero() && Z2 == f_.zero()) {\n X3o = X1;\n Y3o = Y1;\n Z3o = Z1;\n return;\n }\n\n Elt Y1Z2 = f_.mulf(Y1, Z2);\n Elt X1Z2 = f_.mulf(X1, Z2);\n Elt u = f_.subf(f_.mulf(Y2, Z1), Y1Z2);\n Elt v = f_.subf(f_.mulf(X2, Z1), X1Z2);\n if (u == f_.zero()) {\n doubleE(X3o, Y3o, Z3o, X1, Y1, Z1);\n return;\n // Self addition, invoke Double method.\n }\n /* This check occurs after the u check.\n If u!=0, but v=0, then the points are inverses.\n */\n if (v == f_.zero()) {\n X3o = f_.zero();\n Y3o = f_.one();\n Z3o = f_.zero();\n return;\n }\n\n Elt Z1Z2 = f_.mulf(Z1, Z2);\n Elt uu = f_.mulf(u, u);\n Elt vv = f_.mulf(v, v);\n Elt vvv = f_.mulf(v, vv);\n Elt R = f_.mulf(vv, X1Z2);\n Elt A = f_.subf(f_.subf(f_.mulf(uu, Z1Z2), vvv), f_.mulf(k2, R));\n Elt X3 = f_.mulf(v, A);\n Elt Y3 = f_.subf(f_.mulf(u, f_.subf(R, A)), f_.mulf(vvv, Y1Z2));\n Elt Z3 = f_.mulf(vvv, Z1Z2);\n\n X3o = X3;\n Y3o = Y3;\n Z3o = Z3;\n }\n\n void doubleE(Elt& X3o, Elt& Y3o, Elt& Z3o, const Elt& X, const Elt& Y,\n const Elt& Z) const {\n // Optimized special cases.\n if (is_zero_a_) return doubleEZeroA(X3o, Y3o, Z3o, X, Y, Z);\n if (is_minus_3_a_) return doubleEMinus3A(X3o, Y3o, Z3o, X, Y, Z);\n\n /*\n // 1998 Cohen–Miyaji–Ono \"Efficient elliptic curve exponentiation using\n mixed coordinates\", formula (4), This version of the double formula trades\n general mults for mults by 2,4,8 which can be implemented with additions.\n This results in savings of 200ns on double.\n */\n if (X == f_.zero() && Z == f_.zero()) {\n X3o = X;\n Y3o = f_.one();\n Z3o = Z;\n return;\n }\n\n Elt Z2 = f_.mulf(Z, Z);\n Elt X2 = f_.mulf(X, X);\n Elt X2_3 = f_.addf(f_.addf(X2, X2), X2);\n Elt s = f_.mulf(Y, Z);\n Elt ss = f_.mulf(s, s);\n Elt sss = f_.mulf(s, ss);\n Elt sss_2 = f_.addf(sss, sss);\n Elt w = f_.addf(f_.mulf(a_, Z2), X2_3);\n Elt R = f_.mulf(Y, s);\n Elt sss_4 = f_.addf(sss_2, sss_2);\n Elt B = f_.mulf(X, R);\n Elt sss_8 = f_.addf(sss_4, sss_4);\n Elt B_2 = f_.addf(B, B);\n Elt R2 = f_.mulf(R, R);\n Elt B_4 = f_.addf(B_2, B_2);\n Elt B_8 = f_.addf(B_4, B_4);\n Elt w2 = f_.mulf(w, w);\n Elt h = f_.subf(w2, B_8);\n Elt s_2 = f_.addf(s, s);\n Elt X3 = f_.mulf(h, s_2);\n Elt R2_2 = f_.addf(R2, R2);\n Elt R2_4 = f_.addf(R2_2, R2_2);\n Elt R2_8 = f_.addf(R2_4, R2_4);\n Elt Y3 = f_.subf(f_.mulf(w, f_.subf(B_4, h)), R2_8);\n Elt Z3 = sss_8;\n\n X3o = X3;\n Y3o = Y3;\n Z3o = Z3;\n }\n\n private:\n /* From Algorithm 7: Complete, projective point addition for prime order\n j-invariant 0 short Weierstrass curves E/Fq : y^2 = x^3 + b.\n\n X3 = (X1 Y2 + X2 Y1)(Y1 Y2 - 3b Z1 Z2) - 3b(Y1 Z2 + Y2 Z1)(X1 Z2 + X2 Z1)\n Y3 = (Y1 Y2 + 3b Z1 Z2)(Y1 Y2 - 3b Z1 Z2) + 9b X1 X2 (X1 Z2 + X2 Z1)\n Z3 = (Y1 Z2 + Y2 Z1)(Y1 Y2 + 3b Z1 Z2) + 3 X1 X2(X1 Y2 + X2 Y1)\n */\n void addEZeroA(Elt& X3o, Elt& Y3o, Elt& Z3o, const Elt& X1, const Elt& Y1,\n const Elt& Z1, const Elt& X2, const Elt& Y2,\n const Elt& Z2) const {\n Elt t0 = f_.mulf(X2, Y1);\n Elt t1 = f_.mulf(X1, Y2);\n Elt t2 = f_.addf(t1, t0);\n Elt t3 = f_.mulf(Y1, Y2);\n Elt t4 = f_.mulf(Z1, Z2);\n Elt t5 = f_.mulf(Y1, Z2);\n Elt t6 = f_.mulf(Y2, Z1);\n Elt t7 = f_.addf(t5, t6);\n Elt t8 = f_.mulf(X1, Z2);\n Elt t9 = f_.mulf(X2, Z1);\n Elt t10 = f_.addf(t8, t9);\n Elt t11 = f_.mulf(X1, X2);\n Elt t12 = f_.mulf(k3b, t4);\n Elt t13 = f_.addf(t3, t12);\n Elt t14 = f_.subf(t3, t12);\n\n X3o = f_.subf(f_.mulf(t2, t14), f_.mulf(k3b, f_.mulf(t7, t10)));\n Y3o = f_.addf(f_.mulf(t13, t14), f_.mulf(k9b, f_.mulf(t11, t10)));\n Z3o = f_.addf(f_.mulf(t7, t13), f_.mulf(k3, f_.mulf(t11, t2)));\n }\n\n /*Algorithm 4: Complete, projective point addition for prime order short\n * Weierstrass curves E/Fq : y^2 = x^33 + ax + b with a = −3.\n */\n void addEMinus3A(Elt& X3o, Elt& Y3o, Elt& Z3o, const Elt& X1, const Elt& Y1,\n const Elt& Z1, const Elt& X2, const Elt& Y2,\n const Elt& Z2) const {\n Elt t0 = f_.mulf(X1, X2);\n Elt t1 = f_.mulf(Y1, Y2);\n Elt t2 = f_.mulf(Z1, Z2);\n Elt t3 = f_.addf(X1, Y1);\n Elt t4 = f_.addf(X2, Y2);\n t3 = f_.mulf(t3, t4);\n t4 = f_.addf(t0, t1);\n t3 = f_.subf(t3, t4);\n t4 = f_.addf(Y1, Z1);\n Elt X3 = f_.addf(Y2, Z2);\n t4 = f_.mulf(t4, X3);\n X3 = f_.addf(t1, t2);\n t4 = f_.subf(t4, X3);\n X3 = f_.addf(X1, Z1);\n Elt Y3 = f_.addf(X2, Z2);\n X3 = f_.mulf(X3, Y3);\n Y3 = f_.addf(t0, t2);\n Y3 = f_.subf(X3, Y3);\n Elt Z3 = f_.mulf(b_, t2);\n X3 = f_.subf(Y3, Z3);\n Z3 = f_.addf(X3, X3);\n X3 = f_.addf(X3, Z3);\n Z3 = f_.subf(t1, X3);\n X3 = f_.addf(t1, X3);\n Y3 = f_.mulf(b_, Y3);\n t1 = f_.addf(t2, t2);\n t2 = f_.addf(t1, t2);\n Y3 = f_.subf(Y3, t2);\n Y3 = f_.subf(Y3, t0);\n t1 = f_.addf(Y3, Y3);\n Y3 = f_.addf(t1, Y3);\n t1 = f_.addf(t0, t0);\n t0 = f_.addf(t1, t0);\n t0 = f_.subf(t0, t2);\n t1 = f_.mulf(t4, Y3);\n t2 = f_.mulf(t0, Y3);\n Y3 = f_.mulf(X3, Z3);\n Y3 = f_.addf(Y3, t2);\n X3 = f_.mulf(t3, X3);\n X3 = f_.subf(X3, t1);\n Z3 = f_.mulf(t4, Z3);\n t1 = f_.mulf(t3, t0);\n Z3 = f_.addf(Z3, t1);\n\n X3o = X3;\n Y3o = Y3;\n Z3o = Z3;\n }\n\n /* From Algorithm 6: Exception-free point doubling for prime order short\n * Weierstrass curves E/Fq : y^2 = x^3 + ax + b with a = −3.\n */\n void doubleEMinus3A(Elt& X3o, Elt& Y3o, Elt& Z3o, const Elt& X, const Elt& Y,\n const Elt& Z) const {\n Elt t0 = f_.mulf(X, X);\n Elt t1 = f_.mulf(Y, Y);\n Elt t2 = f_.mulf(Z, Z);\n Elt t3 = f_.mulf(X, Y);\n t3 = f_.addf(t3, t3);\n Elt Z3 = f_.mulf(X, Z);\n Z3 = f_.addf(Z3, Z3);\n Elt Y3 = f_.mulf(b_, t2);\n Y3 = f_.subf(Y3, Z3);\n Elt X3 = f_.addf(Y3, Y3);\n Y3 = f_.addf(X3, Y3);\n X3 = f_.subf(t1, Y3);\n Y3 = f_.addf(t1, Y3);\n Y3 = f_.mulf(X3, Y3);\n X3 = f_.mulf(X3, t3);\n t3 = f_.addf(t2, t2);\n t2 = f_.addf(t2, t3);\n Z3 = f_.mulf(b_, Z3);\n Z3 = f_.subf(Z3, t2);\n Z3 = f_.subf(Z3, t0);\n t3 = f_.addf(Z3, Z3);\n Z3 = f_.addf(Z3, t3);\n t3 = f_.addf(t0, t0);\n t0 = f_.addf(t3, t0);\n t0 = f_.subf(t0, t2);\n t0 = f_.mulf(t0, Z3);\n Y3 = f_.addf(Y3, t0);\n t0 = f_.mulf(Y, Z);\n t0 = f_.addf(t0, t0);\n Z3 = f_.mulf(t0, Z3);\n X3 = f_.subf(X3, Z3);\n Z3 = f_.mulf(t0, t1);\n Z3 = f_.addf(Z3, Z3);\n Z3 = f_.addf(Z3, Z3);\n\n X3o = X3;\n Y3o = Y3;\n Z3o = Z3;\n }\n\n /* From Algorithm 9: Exception-free point doubling for prime order\n j-invariant 0 short Weierstrass curves E/Fq y^2 = x^3 + b\n\n X3 = 2XY (YY − 9bZZ)\n Y3 = (YY − 9bZZ)(YY + 3bZZ) + 24bYYZZ\n Z3 = 8YYYZ.\n */\n void doubleEZeroA(Elt& X3o, Elt& Y3o, Elt& Z3o, const Elt& X, const Elt& Y,\n const Elt& Z) const {\n Elt t0 = f_.mulf(X, Y);\n Elt t1 = f_.mulf(Y, Y);\n Elt t2 = f_.mulf(Z, Z);\n Elt t4 = f_.mulf(Y, Z);\n Elt t5 = f_.mulf(k9b, t2); // 9bZZ\n Elt t6 = f_.subf(t1, t5); // YY - 9bZZ\n Elt t7 = f_.mulf(k3b, t2); // 3bZZ\n Elt t8 = f_.addf(t1, t7); // YY + 3bZZ\n X3o = f_.mulf(k2, f_.mulf(t0, t6));\n Y3o = f_.addf(f_.mulf(t6, t8), f_.mulf(k24b, f_.mulf(t1, t2)));\n Z3o = f_.mulf(k8, f_.mulf(t1, t4));\n }\n\n //------------------------------------------------------------\n // Multi-exponentiation SUM_i scalarMult(p[i], s[i])\n\n // We follow the basic strategy outlined in Daniel J. Bernstein,\n // Niels Duif, Tanja Lange, Peter Schwabe, and Bo-Yin Yang,\n // \"High-speed high-security signatures\",\n // https://eprint.iacr.org/2011/368, where Bernstein et al. credit\n // the method to Bos and Coster via a reference to Peter de Rooij,\n // \"Efficient exponentiation using precomputation and vector\n // addition chains\", in Eurocrypt ’94. In my opinion [matteof@]\n // the method of Bernstein et al. is not quite the same as the papers\n // that they reference, but either way we follow Bernstein et al.\n // with a few modifications, and call the method bos_coster() in\n // this file.\n\n // The basic idea is to keep the list (p[i], s[i]) of pairs\n // (point, scalar) in descending order of scalar, so that s[0]\n // is the maximum.\n\n // Bernstein's method repeatedly replaces p[0]*s[0]+p[1]*s[1]\n // by p[0]*(s[0]-s[1])+(p[0]+p[1])*s[1], where now the first\n // scalar becomes smaller. Eventually all the scalars s[i] become\n // 0 for i>=1.\n\n // For random scalars, one can roughly expect s[0]-s[1] to be\n // about |F|/n, so the method can be expected to set approximately\n // log n scalar bits to zero in each iteration. However, its worst\n // case is horrific. E.g., if s[1]=1 and s[0] is O(2**256), the\n // method will require O(2**256) iterations to converge.\n\n // To avoid this worst-case behavior, we depart from Bernstein and\n // perform either a Bernstein step or a double-and-add step,\n // whichever one decreases s[0] the most. A double-and-add writes\n // s[0] = 2*a+b and replaces p[0]*s[0] with (2*p[0])*(s[0]/2) *\n // b*p[0], where the second multiplication is trivial because b \\in\n // {0,1}. With this choice, we are guaranteed to eliminate at least\n // one scalar bit per iteration, so the method is no worse than a\n // loop of single scalar multiplications. Bernstein et al., page\n // 17, are aware of the problem, but they say that doing anything\n // about it is \"not worthwhile\". On the other hand, the fix doesn't\n // cost anything either, so may as well do it. (Bernstein et\n // al. propose a different fix.)\n\n // For easy access to the largest s[0] and second-largest s[1], we\n // keep the (p[i], s[i]) terms in a heap. Here, \"heap\" denotes a\n // variant of the standard heap where the root node H[0] has one\n // child H[1] (as opposed to two children), and every other node i>0\n // has two children H[2*i] and H[2*i+1]. A heap comprises at least\n // two elements H[0] and H[1]. In this way, the two largest scalars\n // are always available directly.\n\n // The following function is equivalent to assigning (p[i], s[i]) =\n // (tp, ts) followed by restoring heap order. However, the logic is\n // a bit complicated by our desire to avoid unnecessary copies of\n // large objects (e.g., swap p[i] with a child, followed by another\n // swap of the child with its child.)\n //\n // Warning: tp and ts MUST NOT be references to p[i] and s[i], since\n // the algorithm overwrites the p and s arrays. This complication\n // ensues because we are trying to avoid unnecessary copies.\n void bury(size_t i, size_t n, ECPoint p[/*n*/], N s[/*n*/], const ECPoint& tp,\n const N& ts) const {\n while (2 * i < n) {\n // at least one child\n size_t cld = 2 * i;\n if (2 * i + 1 < n && s[cld] < s[2 * i + 1]) {\n // right child exists and is larger\n cld = 2 * i + 1;\n }\n\n if (ts < s[cld]) {\n // I is out of order with CLD. Bubble CLD up the tree and\n // continue as in BURY(CLD, N, P, S, TP, TS).\n s[i] = s[cld];\n p[i] = p[cld];\n i = cld;\n } else {\n // already in heap order, stop here.\n break;\n }\n }\n\n p[i] = tp;\n s[i] = ts;\n }\n\n // bury (p[0], s[0]) to its rightful place in the heap.\n void bury0(size_t n, ECPoint p[/*n*/], N s[/*n*/]) const {\n if (s[0] < s[1]) {\n // equivalent to swap(s[0], s[1]); bury(s[1]);\n // but without the possibly unnecessary assignment of (s,p)[1]\n ECPoint tp = p[0];\n N ts = s[0];\n p[0] = p[1];\n s[0] = s[1];\n bury(1, n, p, s, tp, ts);\n }\n }\n\n // The main Bernstein/Bos-Coster algorithm.\n ECPoint bos_coster(size_t n, ECPoint p[/*n*/], N s[/*n*/]) const {\n check(n >= 2, \"n >= 2\");\n ECPoint res = zero();\n\n // build a heap on [1..n)\n for (size_t i = /*floor*/ (n / 2); i >= 1; --i) {\n // create temporary copies of p[i], s[i], which are passed by\n // const &.\n bury(i, n, p, s, ECPoint(p[i]), N(s[i]));\n }\n // finish the heap on [0..n)\n bury0(n, p, s);\n\n while (s[0] != /*zero*/ N{}) {\n // ns0 = s[0] - s[1]\n N ns0(s[0]);\n ns0.sub(s[1]);\n\n // Double-and-add is (locally) better than Bernstein iff s[0]/2\n // < s[0] - s[1], equivalent to s[0] > 2*s[1], equivalent to\n // ns0 = s[0] - s[1] > s[1]:\n if (s[1] < ns0) {\n // res += (s[0] & 1) * p[0]; s[0] /= 2; p[0] *= 2;\n uint64_t lsb = s[0].shiftr(1);\n if (lsb != 0) {\n addE(res, p[0]);\n }\n doubleE(p[0]);\n } else {\n // s[0] -= s[1], p[1] += p[0]\n s[0] = ns0;\n addE(p[1], p[0]);\n }\n bury0(n, p, s);\n }\n return res;\n }\n\n bool is_zero_a_;\n bool is_minus_3_a_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_EC_ELLIPTIC_CURVE_H_\n"], ["/longfellow-zk/lib/circuits/cbor_parser/cbor_pluck.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_PLUCK_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_PLUCK_H_\n#include \n#include \n\n#include \n\n#include \"algebra/interpolation.h\"\n#include \"algebra/poly.h\"\n#include \"circuits/logic/bit_plucker_constants.h\"\n#include \"circuits/logic/polynomial.h\"\n\nnamespace proofs {\n// Special plucker that decodes into a pair (B, J) where B is one bit,\n// and J is an array of NJ bits at most one of which can be set.\n//\n// B can assume one of two distinct values, and J can assume NJ+1\n// distinct values. Thus there are N = 2*(NJ+1) evaluation points.\n// We encode J as the index IJ of which bit is set, or IJ=NJ if no bit\n// is set.\ntemplate \nclass CborPlucker {\n public:\n using Field = typename Logic::Field;\n using BitW = typename Logic::BitW;\n using EltW = typename Logic::EltW;\n using Elt = typename Field::Elt;\n static constexpr size_t kN = 2 * (NJ + 1);\n using PolyN = Poly;\n using InterpolationN = Interpolation;\n const Logic& l_;\n PolyN pluckerb_;\n std::vector pluckerj_;\n\n explicit CborPlucker(const Logic& l) : l_(l), pluckerj_(NJ) {\n const Field& F = l_.f_; // shorthand\n // evaluation points\n PolyN X;\n for (size_t i = 0; i < kN; ++i) {\n X[i] = bit_plucker_point()(i, F);\n }\n\n // encode B in the low-order bit\n PolyN Y;\n for (size_t i = 0; i < kN; ++i) {\n Y[i] = F.of_scalar(i & 1);\n }\n pluckerb_ = InterpolationN::monomial_of_lagrange(Y, X, F);\n\n // encode J in the high-order bits\n for (size_t j = 0; j < NJ; ++j) {\n for (size_t i = 0; i < kN; ++i) {\n Y[i] = F.of_scalar((i >> 1) == j);\n }\n pluckerj_[j] = InterpolationN::monomial_of_lagrange(Y, X, F);\n }\n }\n\n BitW pluckb(const EltW& e) const {\n const Logic& L = l_; // shorthand\n const Polynomial P(L);\n\n EltW v = P.eval(pluckerb_, e);\n L.assert_is_bit(v);\n return BitW(v, L.f_);\n }\n\n typename Logic::template bitvec pluckj(const EltW& e) const {\n typename Logic::template bitvec r;\n const Logic& L = l_; // shorthand\n const Polynomial P(L);\n\n for (size_t j = 0; j < NJ; ++j) {\n EltW v = P.eval(pluckerj_[j], e);\n L.assert_is_bit(v);\n r[j] = BitW(v, L.f_);\n }\n\n return r;\n }\n};\n\ntemplate \nstruct cbor_plucker_point {\n using Elt = typename Field::Elt;\n static constexpr size_t kN = 2 * (NJ + 1);\n\n // packing of bits compatible with even_lagrange_basis():\n Elt operator()(bool b, size_t j, const Field& F) const {\n uint64_t bits = b + 2 * j;\n return bit_plucker_point()(bits, F);\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_PLUCK_H_\n"], ["/longfellow-zk/lib/circuits/logic/bit_plucker_encoder.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_PLUCKER_ENCODER_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_PLUCKER_ENCODER_H_\n\n#include \n#include \n\n#include \n\n#include \"circuits/logic/bit_plucker_constants.h\"\n\nnamespace proofs {\ntemplate \nclass BitPluckerEncoder {\n const Field& f_;\n\n using Elt = typename Field::Elt;\n static constexpr size_t kN = size_t(1) << LOGN;\n static constexpr size_t kNv32Elts = (32u + LOGN - 1u) / LOGN;\n static constexpr size_t kNv128Elts = (128u + LOGN - 1u) / LOGN;\n static constexpr size_t kNv256Elts = (256u + LOGN - 1u) / LOGN;\n\n public:\n using packed_v32 = std::array;\n using packed_v128 = std::array;\n using packed_v256 = std::array;\n\n explicit BitPluckerEncoder(const Field& F) : f_(F) {}\n\n Elt encode(size_t i) const { return bit_plucker_point()(i, f_); }\n\n // Special case packer for uint32_t used in sha256.\n packed_v32 mkpacked_v32(uint32_t j) {\n packed_v32 r;\n for (size_t i = 0; i < r.size(); ++i) {\n r[i] = encode(j & (kN - 1));\n j >>= LOGN;\n }\n return r;\n }\n\n template \n T pack(uint8_t bits[/* n bits */], size_t n) {\n T r;\n for (size_t i = 0; i < r.size(); ++i) {\n size_t v = 0;\n for (size_t j = 0; j < LOGN; ++j) {\n if (i * LOGN + j < n) {\n v += (bits[i * LOGN + j] & 0x1) << j;\n }\n }\n r[i] = encode(v);\n }\n return r;\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_PLUCKER_ENCODER_H_\n"], ["/longfellow-zk/lib/circuits/cbor_parser/cbor_testing.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_TESTING_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_TESTING_H_\n\n#include \n\n#include \"circuits/cbor_parser/cbor.h\"\n#include \"circuits/cbor_parser/cbor_constants.h\"\n#include \"circuits/cbor_parser/cbor_witness.h\"\n#include \"circuits/logic/evaluation_backend.h\"\n#include \"circuits/logic/logic.h\"\n\n// The purpose of this class is to convert the witnesses from Elt to\n// EltW.\n//\n// Why?\n//\n// We want EltW in the evaluation backend to be a distinct type from\n// Elt. They are really the same thing, but we want to be able to\n// instantiate circuits in the compiler backend as well, and thus\n// circuits ought not to rely on the fact that EvaluationBackend::EltW\n// is really an Elt in disguise.\n// Consequently, tests in the evaluation backend must accept EltW.\n//\n// The witness generator must produce Elt, otherwise this forces the\n// inclusion of Logic in the app. We don't like that because Logic\n// is just a set of helpers to generate circuits, and the final app\n// is not supposed to generate circuits (since circuits are part of the\n// prover<->verifier API and so they must be set in stone in advance.)\n//\n// So this class is the price to be paid to maintain this typing\n// hygiene. Time will tell whether it was worth it.\n\nnamespace proofs {\n\ntemplate \nclass CborTesting {\n using EvalBackend = EvaluationBackend;\n using LogicF = Logic;\n using EltW = typename LogicF::EltW;\n using BitW = typename LogicF::BitW;\n using CborL = Cbor;\n using CborWitnessF = CborWitness;\n\n public:\n explicit CborTesting(const Field &F) : f_(F) {}\n\n void convert_witnesses(\n size_t n, typename CborL::v8 in[/*n*/],\n typename CborL::position_witness pw[/*n*/],\n typename CborL::global_witness &gw,\n const typename CborWitnessF::v8 inS[/*n*/],\n const typename CborWitnessF::position_witness pwS[/*n*/],\n const typename CborWitnessF::global_witness &gwS) const {\n const EvalBackend ebk(f_);\n const LogicF L(&ebk, f_);\n\n for (size_t i = 0; i < n; ++i) {\n for (size_t j = 0; j < 8; ++j) {\n in[i][j] = BitW(L.konst(inS[i][j]), f_);\n }\n pw[i].encoded_sel_header = L.konst(pwS[i].encoded_sel_header);\n }\n\n gw.invprod_decode = L.konst(gwS.invprod_decode);\n gw.cc0 = L.konst(gwS.cc0);\n gw.invprod_parse = L.konst(gwS.invprod_parse);\n }\n\n // Return an index that can be fed to a circuit in the\n // evaluation backend (i.e., a bit vector).\n typename CborL::vindex index(size_t j) const {\n const EvalBackend ebk(f_);\n const LogicF L(&ebk, f_);\n return L.template vbit(j);\n }\n\n private:\n const Field &f_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_TESTING_H_\n"], ["/longfellow-zk/lib/zk/zk_prover.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ZK_ZK_PROVER_H_\n#define PRIVACY_PROOFS_ZK_LIB_ZK_ZK_PROVER_H_\n\n#include \n\n#include \n#include \n\n#include \"arrays/dense.h\"\n#include \"ligero/ligero_param.h\"\n#include \"ligero/ligero_prover.h\"\n#include \"random/random.h\"\n#include \"random/transcript.h\"\n#include \"sumcheck/circuit.h\"\n#include \"sumcheck/prover_layers.h\"\n#include \"sumcheck/transcript_sumcheck.h\"\n#include \"util/log.h\"\n#include \"util/panic.h\"\n#include \"zk/zk_common.h\"\n#include \"zk/zk_proof.h\"\n\nnamespace proofs {\n// ZK Prover\n//\n// This class implements a zero-knowledge argument over a sumcheck transcript\n// by first committing to a sumcheck witness and a random pad to encrypt\n// a sumcheck transcript, then running the sumcheck protocol over the original\n// claim and witness, but outputting the encrypted transcript, and finally\n// using a Ligero prover to prove the statement: \"the committed witness and\n// pad, when used to decrypt the encrypted sumcheck transcript satisfies the\n// sumcheck verifier.\"\n//\n// While this statement is complex, it can be implemented easily because\n// the sumcheck verifier essentially checks the evaluations of degree-2 or -3\n// polynomials, and performs one multiplication per layer of the circuit. The\n// Hyrax paper makes a similar observation, but uses an elliptic-curve based\n// proof, whereas here we use the Ligero system.\ntemplate \nclass ZkProver : public ProverLayers {\n using super = ProverLayers;\n using typename super::bindings;\n using Elt = typename Field::Elt;\n using typename super::inputs;\n\n public:\n ZkProver(const Circuit& CIRCUIT, const Field& F,\n const ReedSolomonFactory& rs_factory)\n : ProverLayers(F),\n c_(CIRCUIT),\n n_witness_(c_.ninputs - c_.npub_in),\n f_(F),\n rsf_(rs_factory),\n pad_(c_.nl),\n witness_(n_witness_),\n lqc_(c_.nl),\n lp_(nullptr) {}\n\n void commit(ZkProof& zkp, const Dense& W, Transcript& tp,\n RandomEngine& rng) {\n log(INFO, \"ZK Commit start\");\n\n // Copy witnesses for commitment\n // Layout of the com: 0 ...... start_pad len\n // Only commit the private witnesses, which begin at index c_.npub_in.\n for (size_t i = 0; i < n_witness_; ++i) {\n witness_[i] = W.v_[i + c_.npub_in];\n }\n\n // Rebase the circuit SUBFIELD_BOUNDARY (if any) to start at\n // NPUB_IN,\n size_t subfield_boundary = 0;\n if (c_.subfield_boundary >= c_.npub_in) {\n subfield_boundary = c_.subfield_boundary - c_.npub_in;\n }\n\n // Fill pad with random values, add pad to witness, record lqc.\n fill_pad(rng);\n ZkCommon::setup_lqc(c_, lqc_, n_witness_ /* = start_pad */);\n\n // Commit to witness and pad.\n lp_ = std::make_unique>(zkp.param);\n lp_->commit(zkp.com, tp, &witness_[0], subfield_boundary, &lqc_[0], rsf_,\n rng, f_);\n\n log(INFO, \"ZK Commitment done\");\n }\n\n bool prove(ZkProof& zkp, const Dense& W, Transcript& tsp) {\n check(lp_ != nullptr, \"must run commit before prove\");\n\n // Interpret W as public parameters, we only append\n // c_.npub_in elements of W to the transcript\n ZkCommon::initialize_sumcheck_fiat_shamir(tsp, c_, W, f_);\n Transcript tst = tsp.clone();\n\n // Run sumcheck to generate a padded proof.\n inputs in;\n auto V = super::eval_circuit(&in, &c_, W.clone(), f_);\n if (V == nullptr) {\n log(ERROR, \"eval_circuit failed\");\n return false;\n }\n for (size_t i = 0; i < V->n1_; ++i) {\n if (V->v_[i] != f_.zero()) {\n log(ERROR, \"V->v_[i] != F.zero()\");\n return false;\n };\n }\n bindings bnd;\n ProofAux aux(c_.nl);\n\n TranscriptSumcheck tsts(tst, f_);\n super::prove(&zkp.proof, &pad_, &c_, in, &aux, bnd, tsts, f_);\n log(INFO, \"ZK sumcheck done\");\n\n // 5. Simulate the verifier to assemble constraints on the committed vals.\n // Form the sparse matrix A and vector b such that A*w = b.\n std::vector> a;\n std::vector b;\n size_t ci = ZkCommon::verifier_constraints(c_, W, zkp.proof, &aux, a,\n b, tsp, n_witness_, f_);\n log(INFO, \"ZK constraints done\");\n\n // 6. Produce proof over commitment.\n // For FS soundness, it is ok for hash_of_A to be any string.\n // In the interactive version, the verifier provides a challenge for the\n // com proof. The last prover message is the (wc_l,wc_r) pair, and this\n // has already been added to the transcript.\n const LigeroHash hash_of_A{0xde, 0xad, 0xbe, 0xef};\n lp_->prove(zkp.com_proof, tsp, ci, a.size(), &a[0], hash_of_A, &lqc_[0],\n rsf_, f_);\n\n log(INFO, \"Prover Done: flag\");\n return true;\n }\n\n // Fill proof with random pad values for a given circuit.\n void fill_pad(RandomEngine& rng) {\n for (size_t i = 0; i < c_.nl; ++i) {\n for (size_t j = 0; j < c_.logc; ++j) {\n for (size_t k = 0; k < 4; ++k) {\n if (k != 1) { // P(1) optimization\n Elt r = rng.elt(f_);\n pad_.l[i].cp[j].t_[k] = r;\n witness_.push_back(r);\n } else {\n pad_.l[i].cp[j].t_[k] = f_.zero();\n }\n }\n }\n for (size_t j = 0; j < c_.l[i].logw; ++j) {\n for (size_t h = 0; h < 2; ++h) {\n for (size_t k = 0; k < 3; ++k) {\n if (k != 1) { // P(1) optimization\n Elt r = rng.elt(f_);\n pad_.l[i].hp[h][j].t_[k] = r;\n witness_.push_back(r);\n } else {\n pad_.l[i].hp[h][j].t_[k] = f_.zero();\n }\n }\n }\n }\n for (size_t k = 0; k < 2; ++k) {\n Elt r = rng.elt(f_);\n pad_.l[i].wc[k] = r;\n witness_.push_back(r);\n }\n\n // Commit to product of pads for product proof.\n Elt rr = f_.mulf(pad_.l[i].wc[0], pad_.l[i].wc[1]);\n witness_.push_back(rr);\n }\n }\n\n const Circuit& c_;\n const size_t n_witness_;\n const Field& f_;\n const ReedSolomonFactory& rsf_;\n Proof pad_;\n std::vector witness_;\n std::vector lqc_;\n std::unique_ptr> lp_;\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ZK_ZK_PROVER_H_\n"], ["/longfellow-zk/lib/gf2k/lch14.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_GF2K_LCH14_H_\n#define PRIVACY_PROOFS_ZK_LIB_GF2K_LCH14_H_\n\n#include \n\n#include \n\n#include \"util/panic.h\"\n\n// The algorithm from [LCH14] following [DP24, Algorithm 2]\n//\n// [LCH14] Sian-Jheng Lin, Wei-Ho Chung, and Yunghsiang S. Han: Novel\n// Polynomial Basis and Its Application to Reed-Solomon Erasure Codes,\n// https://arxiv.org/pdf/1404.3458\n\n// [DP24] Benjamin E. Diamond and Jim Posen, Polylogarithmic Proofs\n// for Multilinears over Binary Towers, https://eprint.iacr.org/2024/504\n\nnamespace proofs {\n\ntemplate \nclass LCH14 {\n using Elt = typename Field::Elt;\n\n // only works in binary fields\n static_assert(Field::kCharacteristicTwo);\n\n public:\n static constexpr size_t kSubFieldBits = Field::kSubFieldBits;\n\n explicit LCH14(const Field &F) : f_(F) {\n // Compute W_i(\\beta_j) for all i, j.\n\n // We store the unnormalized W_[i][j] = W_i(\\beta_j)\n // in the same memory as the normalized \\hat{W}_i(\\beta_j), since\n // the unnormalized values are not needed after normalization.\n\n // In an attempt to improve clarity, we syntactically distinguish\n // the unnormalized array W from the normalized array w_hat_,\n // but one must be mindful that the two names alias to the\n // same memory locations.\n auto W = w_hat_;\n\n // Base case: W_0(X) = X\n for (size_t j = 0; j < kSubFieldBits; ++j) {\n W[0][j] = f_.beta(j);\n }\n\n // Inductive case: W_{i+1}(X) = W_i(X)(W_i(X)+W_i(\\beta_i))\n for (size_t i = 0; i + 1 < kSubFieldBits; ++i) {\n for (size_t j = 0; j < kSubFieldBits; ++j) {\n W[i + 1][j] = f_.mulf(W[i][j], f_.addf(W[i][j], W[i][i]));\n }\n }\n\n // normalized \\hat{W}_i(\\beta j)\n for (size_t i = 0; i < kSubFieldBits; ++i) {\n Elt scale = f_.invertf(W[i][i]);\n for (size_t j = 0; j < kSubFieldBits; ++j) {\n w_hat_[i][j] = f_.mulf(scale, W[i][j]);\n }\n }\n }\n\n // Computation of a single twiddle factor.\n // Implicit in [LCH14, III.E], explicit in [DP24, Algorithm 2].\n Elt twiddle(size_t i, size_t u) const {\n Elt t = f_.zero();\n for (size_t k = 0; u != 0; ++k, u >>= 1) {\n if (u & 1) {\n f_.add(t, w_hat_[i][k]);\n }\n }\n return t;\n }\n\n // linear-time computation of all twiddles at the same time\n void twiddles(size_t i, size_t l, size_t coset, Elt tw[]) const {\n tw[0] = twiddle(i, coset);\n for (size_t k = 0; (i + 1) + k < l; ++k) {\n Elt shift = w_hat_[i][(i + 1) + k];\n for (size_t u = 0; u < (k1 << k); ++u) {\n tw[u + (k1 << k)] = f_.addf(tw[u], shift);\n }\n }\n }\n\n size_t ntwiddles(size_t l) const { return k1 << (l - 1); }\n\n // Notation from [DP24, Algorithm 2], except that we hardcode R=0\n // and add the coset parameter.\n void FFT(size_t l, size_t coset, Elt B[/* n = (1 << l) */]) const {\n check(l <= kSubFieldBits, \"l <= kSubFieldBits\");\n\n if (l > 0) {\n // space for twiddle factors\n std::vector tw(ntwiddles(l));\n\n for (size_t i = l; i-- > 0;) {\n size_t s = k1 << i;\n twiddles(i, l, coset, &tw[0]);\n for (size_t u = 0; (u << (i + 1)) < (k1 << l); ++u) {\n Elt twu = tw[u];\n for (size_t v = 0; v < s; ++v) {\n butterfly_fwd(B, (u << (i + 1)) + v, s, twu);\n }\n }\n }\n }\n }\n\n void IFFT(size_t l, size_t coset, Elt B[/* n = (1 << l) */]) const {\n check(l <= kSubFieldBits, \"l <= kSubFieldBits\");\n\n if (l > 0) {\n // space for twiddle factors\n std::vector tw(ntwiddles(l));\n\n for (size_t i = 0; i < l; ++i) {\n size_t s = k1 << i;\n twiddles(i, l, coset, &tw[0]);\n for (size_t u = 0; (u << (i + 1)) < (k1 << l); ++u) {\n Elt twu = tw[u];\n for (size_t v = 0; v < s; ++v) {\n butterfly_bwd(B, (u << (i + 1)) + v, s, twu);\n }\n }\n }\n }\n }\n\n void BidirectionalFFT(size_t l, size_t k, Elt B[/* n = (1 << l) */]) const {\n check(l <= kSubFieldBits, \"l <= kSubFieldBits\");\n bidir_recur(/*i=*/l, /*coset=*/0, k, B);\n }\n\n // debug access to w_hat_\n Elt WHat_DEBUG(size_t i, size_t j) const { return w_hat_[i][j]; }\n\n private:\n // avoid writing static_cast(1) all the time.\n static constexpr size_t k1 = 1;\n\n const Field &f_;\n\n // precomputed [i][j] -> \\hat{W}(\\beta_j)\n Elt w_hat_[kSubFieldBits][kSubFieldBits];\n\n // The algorithm described in Joris van der Hoeven, \"The Truncated\n // Fourier Transform and Applications\". This implementation is\n // based on the pseudo-code from the followup paper \"Notes on the\n // Truncated Fourier Transform\", also by Joris van der Hoeven.\n //\n // Van der Hoeven considers the classic multiplicative FFT;\n // here we port the algorithm to the [LCH14] adaptive FFT.\n\n // Here we call the algorithm the \"Bidirectional FFT\", because\n // the algorithm takes a set of points in the \"time\" domain\n // and the complementary set of points in the \"frequency\" domain,\n // and it flips time and frequency, so the algorithm can be\n // used to compute the forward and backward transforms, as well\n // as combinations of the two.\n //\n // The literature on the truncated Fourier transforms assumes that\n // the complementary set of points are implicitly set to zero, and\n // the main problem is how to avoid storing the zeroes. Our main\n // problem is not time or space efficiency, but polynomial\n // interpolation. Given k evaluations of a polynomial of degree 0) {\n size_t s = k1 << i;\n Elt twu = twiddle(i, coset);\n\n if (k < s) {\n for (size_t uv = k; uv < s; ++uv) {\n butterfly_fwd(B, uv, s, twu);\n }\n\n bidir_recur(i, coset, k, B);\n\n for (size_t uv = 0; uv < k; ++uv) {\n butterfly_diag(B, uv, s, twu);\n }\n\n FFT(i, coset + s, B + s);\n } else /* k >= s */ {\n IFFT(i, coset, B);\n\n for (size_t uv = k - s; uv < s; ++uv) {\n butterfly_diag(B, uv, s, twu);\n }\n\n bidir_recur(i, coset + s, k - s, B + s);\n\n for (size_t uv = 0; uv < k - s; ++uv) {\n butterfly_bwd(B, uv, s, twu);\n }\n }\n }\n }\n\n inline void butterfly_fwd(Elt B[], size_t uv, size_t s,\n const Elt &twu) const {\n f_.add(B[uv], f_.mulf(twu, B[uv + s]));\n f_.add(B[uv + s], B[uv]);\n }\n\n inline void butterfly_bwd(Elt B[], size_t uv, size_t s,\n const Elt &twu) const {\n f_.sub(B[uv + s], B[uv]);\n f_.sub(B[uv], f_.mulf(twu, B[uv + s]));\n }\n\n // forward at [uv + s], backward at [uv]\n inline void butterfly_diag(Elt B[], size_t uv, size_t s,\n const Elt &twu) const {\n Elt b1 = B[uv + s];\n f_.add(B[uv + s], B[uv]);\n f_.sub(B[uv], f_.mulf(twu, b1));\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_GF2K_LCH14_H_\n"], ["/longfellow-zk/lib/circuits/compiler/schedule.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_SCHEDULE_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_SCHEDULE_H_\n\n#include \n#include \n\n#include \n#include \n#include \n\n#include \"algebra/compare.h\"\n#include \"arrays/affine.h\"\n#include \"circuits/compiler/node.h\"\n#include \"sumcheck/circuit.h\"\n#include \"sumcheck/quad.h\"\n#include \"util/ceildiv.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\ntemplate \nclass Scheduler {\n using Elt = typename Field::Elt;\n using nodeinfo = NodeInfoF;\n using node = NodeF;\n using size_t_for_storage = term::size_t_for_storage;\n using quad_corner_t = typename Quad::quad_corner_t;\n\n const Field& f_;\n const std::vector& nodes_;\n\n public:\n size_t nwires_;\n size_t nquad_terms_;\n size_t nwires_overhead_;\n\n Scheduler(const std::vector& nodes, const Field& f)\n : f_(f),\n nodes_(nodes),\n nwires_(0),\n nquad_terms_(0),\n nwires_overhead_(0) {}\n\n std::unique_ptr> mkcircuit(const std::vector& constants,\n size_t depth_ub, size_t nc) {\n std::unique_ptr> c = std::make_unique>();\n\n // number of layers and copies\n c->nl = depth_ub - 1; // depth 0 = input nodes, not a \"layer\"\n c->nc = nc;\n c->logc = lg(nc);\n\n auto lnodes = order_by_layer(constants, depth_ub);\n\n // TODO [matteof 2025-03-12] ASSIGN_WIRE_IDS() renames LNODES in\n // order to sort it and assign LNODES[].DESIRED_WIRE ID. Then it\n // throws away the renamed LNODES. Then FILL_LAYERS() renames\n // LNODES again in order to produce the final quad. It would be\n // better to produce the quad directly in ASSIGN_WIRE_IDS(). Punt\n // for now, this is just a performance optimization of the\n // compiler anyway.\n //\n assign_wire_ids(lnodes);\n fill_layers(c.get(), depth_ub, lnodes);\n\n return c;\n }\n\n private:\n // per-layer representation of nodes and terms\n struct lterm {\n Elt k;\n quad_corner_t lop0, lop1;\n };\n struct lnode {\n quad_corner_t desired_wire_id;\n\n // Copy wires are forced to be distinct from wires in the\n // original dag, in order to avoid ambiguity in renaming.\n //\n // Copy wires are always of the form 1*op, which doesn't\n // normally appear in the dag because the algebraic simplifier\n // reduces it to op. However, one can in theory create such\n // a node by judicious use of linear(). Rather than\n // trying to figure out which circuits one is not allowed\n // to write, it seems simpler to just handle this case\n // uniformly.\n bool is_copy_wire;\n\n std::vector lterms;\n\n lnode(quad_corner_t desired_wire_id, bool is_copy_wire,\n const std::vector& lterms)\n : desired_wire_id(desired_wire_id),\n is_copy_wire(is_copy_wire),\n lterms(lterms) {}\n };\n\n quad_corner_t lop_of_op_at_depth(\n const std::vector>& lop, size_t op,\n size_t d) const {\n const node& n = nodes_.at(op);\n return lop.at(op).at(d - n.info.depth);\n }\n\n // Convert the DAG of nodes into a layered dag of lnodes.\n std::vector> order_by_layer(\n const std::vector& constants, size_t depth_ub) {\n // The source DAG is indexed by NODES_[OP].\n // The destination dag uses a two-dimensional indexing\n // scheme LNODES[D][LOP], where D is the depth.\n\n // A single value NODES_[OP] may be replicated multiple times in\n // LNODES. The mapping is maintained in array LOPS such that\n // LOPS[OP][D - D0] contains the LOP index of node OP at depth D.\n // D0 is the depth at which NODES_[OP] is first computed, and\n // there is no point in storing LOPS[OP] for D < D0.\n\n std::vector> lnodes(depth_ub);\n std::vector> lops(nodes_.size());\n\n nwires_overhead_ = 0;\n\n for (size_t op = 0; op < nodes_.size(); ++op) {\n const auto& n = nodes_[op];\n const nodeinfo& nfo = n.info;\n if (nfo.is_needed && !n.zero()) {\n size_t d = nfo.depth;\n\n // Allocate the LOP at depth D\n quad_corner_t lop = quad_corner_t(lnodes.at(d).size());\n lops.at(op).push_back(lop);\n\n // create a LOPS entry for depth D\n /*scope*/ {\n std::vector lterms;\n for (const auto& t : n.terms) {\n lterm lt = {\n .k = constants.at(t.ki),\n .lop0 = lop_of_op_at_depth(lops, t.op0, d - 1),\n .lop1 = lop_of_op_at_depth(lops, t.op1, d - 1),\n };\n lterms.push_back(lt);\n }\n lnodes.at(d).push_back(lnode(nfo.desired_wire_id(d, depth_ub),\n /*is_copy_wire=*/false, lterms));\n }\n\n // create copy wires\n for (d = nfo.depth + 1; d < nfo.max_needed_depth; ++d) {\n quad_corner_t lop_dm1 = lop;\n\n // allocate the LOP at depth D\n lop = quad_corner_t(lnodes.at(d).size());\n lops.at(op).push_back(lop);\n\n std::vector lterms;\n\n // Insert a multiplication by one of the layer\n // at the previous layer.\n lterm lt = {\n .k = f_.one(),\n .lop0 = quad_corner_t(0),\n .lop1 = lop_dm1,\n };\n lterms.push_back(lt);\n lnodes.at(d).push_back(lnode(nfo.desired_wire_id(d, depth_ub),\n /*is_copy_wire=*/true, lterms));\n ++nwires_overhead_;\n } // for copy wires\n } // if needed\n } // for OP\n\n return lnodes;\n }\n\n //------------------------------------------------------------\n // canonical assignment of wire ids\n //------------------------------------------------------------\n //\n // The canonicalization order is a matter of convention.\n // We make some arbitrary choices that appear to interact\n // better with ZSTD compression. The label [ARBITRARY CHOICE]\n // denotes all places in the code where this occurs.\n //\n class renamed_lterm {\n public:\n Elt k_;\n quad_corner_t rlop0_, rlop1_;\n\n // [ARBITRARY CHOICE] Consistent with corner::canonicalize() in\n // sumcheck/quad.h\n renamed_lterm(const Elt& k, quad_corner_t rlop0, quad_corner_t rlop1)\n : k_(k),\n rlop0_(std::min(rlop0, rlop1)),\n rlop1_(std::max(rlop0, rlop1)) {}\n\n bool operator==(const renamed_lterm& y) const {\n return rlop0_ == y.rlop0_ && rlop1_ == y.rlop1_ && k_ == y.k_;\n }\n\n // canonical order\n static bool compare(const renamed_lterm& a, const renamed_lterm& b,\n const Field& F) {\n if (a.rlop0_ < b.rlop0_) return true;\n if (a.rlop0_ > b.rlop0_) return false;\n if (a.rlop1_ < b.rlop1_) return true;\n if (a.rlop1_ > b.rlop1_) return false;\n return elt_less_than(a.k_, b.k_, F);\n }\n };\n\n class renamed_lnode {\n public:\n quad_corner_t desired_wire_id_;\n quad_corner_t original_wire_index_;\n bool is_copy_wire_;\n std::vector rlterms_;\n\n renamed_lnode(quad_corner_t desired_wire_id,\n quad_corner_t original_wire_index, bool is_copy_wire,\n const std::vector& rlterms)\n : desired_wire_id_(desired_wire_id),\n original_wire_index_(original_wire_index),\n is_copy_wire_(is_copy_wire),\n rlterms_(rlterms) {}\n\n bool operator==(const renamed_lnode& y) const {\n if (is_copy_wire_ != y.is_copy_wire_) return false;\n if (rlterms_.size() != y.rlterms_.size()) return false;\n size_t l = rlterms_.size();\n for (size_t i = 0; i < l; ++i) {\n if (!(rlterms_[i] == y.rlterms_[i])) return false;\n }\n return true;\n }\n\n // canonical order\n static bool compare(const renamed_lnode& ra, const renamed_lnode& rb,\n const Field& F) {\n // Defined before undefined. This choice is mandated by the\n // fact that the range of defined wire id's starts at 0.\n if (ra.desired_wire_id_ != nodeinfo::kWireIdUndefined) {\n if (rb.desired_wire_id_ != nodeinfo::kWireIdUndefined) {\n return ra.desired_wire_id_ < rb.desired_wire_id_;\n } else {\n return true;\n }\n } else {\n if (rb.desired_wire_id_ != nodeinfo::kWireIdUndefined) {\n return false;\n }\n // else both undefined\n }\n\n // [ARBITRARY CHOICE] Lexicographic order on the reverse of the\n // terms array. This seems to compress much better than\n // the normal lexicographic order.\n for (size_t ia = ra.rlterms_.size(), ib = rb.rlterms_.size();\n ia-- > 0 && ib-- > 0;) {\n const renamed_lterm& rlta = ra.rlterms_[ia];\n const renamed_lterm& rltb = rb.rlterms_[ib];\n if (renamed_lterm::compare(rlta, rltb, F)) return true;\n if (renamed_lterm::compare(rltb, rlta, F)) return false;\n }\n\n // [ARBITRARY CHOICE] If the common suffixes are the same, the\n // shorter terms come first.\n if (ra.rlterms_.size() < rb.rlterms_.size()) return true;\n if (ra.rlterms_.size() > rb.rlterms_.size()) return false;\n\n // Nodes that were in the original dag come first.\n if (!ra.is_copy_wire_ && rb.is_copy_wire_) return true;\n if (!rb.is_copy_wire_ && ra.is_copy_wire_) return false;\n\n // equal, i.e., not less-than\n return false;\n }\n };\n\n template \n bool uniq(const std::vector& sorted) {\n for (size_t i = 0; i + 1 < sorted.size(); ++i) {\n if (sorted[i] == sorted[i + 1]) return false;\n }\n return true;\n }\n\n void assign_wire_ids(std::vector>& lnodes) {\n // all inputs are expected to be defined already\n assert_all_desired_wire_id_defined(lnodes.at(0));\n\n for (size_t d = 1; d < lnodes.size(); ++d) {\n const std::vector& lnodes_at_dm1 = lnodes.at(d - 1);\n const std::vector& lnodes_at_d = lnodes.at(d);\n\n // Create a renamed clone of LNODES_AT_D, in which all\n // the LOP's are mapped to their desired wire id's\n // at the previous layer. We use different types\n // to avoid any possibility of confusion.\n std::vector renamed_at_d;\n\n quad_corner_t original_wire_index(0);\n for (const lnode& ln : lnodes_at_d) {\n std::vector rlterms;\n\n // rename all terms\n rlterms.reserve(ln.lterms.size());\n for (const lterm& lt : ln.lterms) {\n rlterms.push_back(renamed_lterm(\n lt.k,\n lnodes_at_dm1.at(static_cast(lt.lop0)).desired_wire_id,\n lnodes_at_dm1.at(static_cast(lt.lop1)).desired_wire_id));\n }\n\n // canonicalize the terms order\n std::sort(rlterms.begin(), rlterms.end(),\n [&](const renamed_lterm& a, const renamed_lterm& b) {\n return renamed_lterm::compare(a, b, f_);\n });\n\n // Terms must be unique, otherwise the canonicalization is\n // ill-defined. Uniqueness is guaranteed by the algebraic\n // simplifier, but assert it for good measure.\n check(uniq(rlterms), \"rlterms not unique\");\n\n renamed_at_d.push_back(renamed_lnode(\n ln.desired_wire_id, original_wire_index, ln.is_copy_wire, rlterms));\n ++original_wire_index;\n }\n\n check(renamed_at_d.size() == lnodes_at_d.size(),\n \"renamed_at_d.size() == lnodes_at_d.size()\");\n\n std::sort(renamed_at_d.begin(), renamed_at_d.end(),\n [&](const renamed_lnode& a, const renamed_lnode& b) {\n return renamed_lnode::compare(a, b, f_);\n });\n\n // Nodes must be unique, otherwise the canonicalization is\n // ill-defined.\n check(uniq(renamed_at_d), \"renamed_at_d not unique\");\n\n quad_corner_t wid(0);\n std::vector& wlnodes_at_d = lnodes.at(d);\n\n for (const renamed_lnode& ln : renamed_at_d) {\n lnode& lnpi =\n wlnodes_at_d.at(static_cast(ln.original_wire_index_));\n if (lnpi.desired_wire_id != nodeinfo::kWireIdUndefined) {\n // We must have computed the same wire id\n check(wid == lnpi.desired_wire_id, \"wid == lnpi.desired_wire_id\");\n } else {\n lnpi.desired_wire_id = wid;\n }\n wid++;\n }\n }\n }\n\n void assert_all_desired_wire_id_defined(const std::vector& layer) {\n for (const auto& ln : layer) {\n check(ln.desired_wire_id != nodeinfo::kWireIdUndefined,\n \"ln.desired_wire_id != kWireIdUndefined\");\n }\n }\n\n void fill_layers(Circuit* c, size_t depth_ub,\n const std::vector>& lnodes) {\n check(depth_ub == lnodes.size(), \"depth_ub == lnodes.size()\");\n\n corner_t nv = corner_t(lnodes.at(depth_ub - 1).size());\n\n nwires_ = nv;\n c->nv = nv;\n c->logv = lg(nv);\n\n // d-- > 1 (not 0) because depth 0 denotes input nodes, not a layer.\n // Sumcheck counts layers starting from the output, hence the loop\n // counts downwards.\n for (size_t d = depth_ub; d-- > 1;) {\n corner_t nw =\n corner_t(lnodes.at(d - 1).size()); // inputs[d] == outputs[d-1]\n nwires_ += nw;\n c->l.push_back(\n Layer{.nw = nw,\n .logw = lg(nw),\n .quad = mkquad(lnodes.at(d), lnodes.at(d - 1))});\n }\n }\n\n std::unique_ptr> mkquad(\n const std::vector& lnodes0, // wires at this layer\n const std::vector& lnodes1 // wires at the previous layer\n ) {\n size_t nterms0 = 0;\n for (const auto& ln0 : lnodes0) {\n nterms0 += ln0.lterms.size();\n }\n nquad_terms_ += nterms0;\n\n auto S = std::make_unique>(nterms0);\n size_t i = 0;\n for (const auto& ln0 : lnodes0) {\n for (const auto& lt : ln0.lterms) {\n S->c_[i++] = typename Quad::corner{\n .g = ln0.desired_wire_id,\n .h = {lnodes1.at(static_cast(lt.lop0)).desired_wire_id,\n lnodes1.at(static_cast(lt.lop1)).desired_wire_id},\n .v = lt.k};\n }\n }\n S->canonicalize(f_);\n return S;\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_SCHEDULE_H_\n"], ["/longfellow-zk/lib/circuits/logic/routing.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_ROUTING_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_ROUTING_H_\n\n#include \n\n#include \n#include \n\n#include \"util/ceildiv.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n/*\nThe Routing class implements circuits that shift an array by a variable number\nof positions. The following table can help pick parameters for a shift:\n\nshift_bit[2][2][1] depth: 2 wires: 6 in: 4 out:2 use:6 ovh:0 t:5 cse:0 notn:7\nunshift_bit[2][2][1] depth: 2 wires: 6 in: 4 out:2 use:6 ovh:0 t:5 cse:0 notn:7\nshift_bit[4][4][1] depth: 3 wires: 17 in: 7 out:4 use:15 ovh:2 t:23 cse:0\nnotn:27 unshift_bit[4][4][1] depth: 3 wires: 17 in: 7 out:4 use:15 ovh:2 t:23\ncse:0 notn:27 shift_bit[4][4][2] depth: 3 wires: 19 in: 7 out:4 use:15 ovh:4\nt:23 cse:2 notn:20 unshift_bit[4][4][2] depth: 3 wires: 19 in: 7 out:4 use:15\novh:4 t:23 cse:2 notn:20 shift_bit[8][8][1] depth: 4 wires: 41 in: 12 out:8\nuse:36 ovh:5 t:70 cse:0 notn:83 unshift_bit[8][8][1] depth: 4 wires: 41 in: 12\nout:8 use:36 ovh:5 t:70 cse:0 notn:83 shift_bit[8][8][2] depth: 4 wires: 44\nin: 12 out:8 use:32 ovh:12 t:64 cse:2 notn:62 unshift_bit[8][8][2] depth: 4\nwires: 44 in: 12 out:8 use:32 ovh:12 t:67 cse:2 notn:68 shift_bit[16][16][1]\ndepth: 5 wires: 94 in: 21 out:16 use:85 ovh:9 t:186 cse:0 notn:227\nunshift_bit[16][16][1] depth: 5 wires: 94 in: 21 out:16 use:85 ovh:9 t:186\ncse:0 notn:227 shift_bit[16][16][2] depth: 4 wires: 82 in: 21 out:16 use:61\novh:21 t:137 cse:4 notn:147 unshift_bit[16][16][2] depth: 4 wires: 82 in: 21\nout:16 use:61 ovh:21 t:137 cse:4 notn:147 shift_bit[16][16][4] depth: 4\nwires: 94 in: 21 out:16 use:61 ovh:33 t:203 cse:58 notn:255\nunshift_bit[16][16][4] depth: 4 wires: 94 in: 21 out:16 use:61 ovh:33 t:203\ncse:58 notn:255 shift_bit[32][32][1] depth: 6 wires: 212 in: 38 out:32\nuse:198 ovh:14 t:463 cse:0 notn:579 unshift_bit[32][32][1] depth: 6 wires: 212\nin: 38 out:32 use:198 ovh:14 t:463 cse:0 notn:579 shift_bit[32][32][2] depth:\n5 wires: 184 in: 38 out:32 use:142 ovh:42 t:351 cse:4 notn:405\nunshift_bit[32][32][2] depth: 5 wires: 184 in: 38 out:32 use:142 ovh:42 t:366\ncse:4 notn:435 shift_bit[32][32][4] depth: 5 wires: 193 in: 38 out:32 use:118\novh:75 t:371 cse:13 notn:427 unshift_bit[32][32][4] depth: 5 wires: 193 in: 38\nout:32 use:118 ovh:75 t:413 cse:13 notn:511 shift_bit[64][64][1] depth: 7\nwires: 475 in: 71 out:64 use:455 ovh:20 t:1109 cse:0 notn:1411\nunshift_bit[64][64][1] depth: 7 wires: 475 in: 71 out:64 use:455 ovh:20 t:1109\ncse:0 notn:1411 shift_bit[64][64][2] depth: 5 wires: 353 in: 71 out:64\nuse:275 ovh:78 t:747 cse:6 notn:922 unshift_bit[64][64][2] depth: 5 wires: 353\nin: 71 out:64 use:275 ovh:78 t:747 cse:6 notn:922 shift_bit[64][64][4] depth:\n5 wires: 363 in: 71 out:64 use:223 ovh:140 t:954 cse:22 notn:1319\nunshift_bit[64][64][4] depth: 5 wires: 363 in: 71 out:64 use:223 ovh:140 t:954\ncse:22 notn:1319 shift_bit[128][128][1] depth: 8 wires: 1059 in: 136 out:128\nuse:1032 ovh:27 t:2588 cse:0 notn:3331 unshift_bit[128][128][1] depth: 8 wires:\n1059 in: 136 out:128 use:1032 ovh:27 t:2588 cse:0 notn:3331\nshift_bit[128][128][2] depth: 6 wires: 808 in: 136 out:128 use:660 ovh:148\nt:1842 cse:6 notn:2332 unshift_bit[128][128][2] depth: 6 wires: 808 in: 136\nout:128 use:660 ovh:148 t:1905 cse:6 notn:2458 shift_bit[128][128][4] depth:\n5 wires: 695 in: 136 out:128 use:428 ovh:267 t:2406 cse:69 notn:3686\nunshift_bit[128][128][4] depth: 5 wires: 695 in: 136 out:128 use:428 ovh:267\nt:2826 cse:69 notn:4526 shift_bit[256][256][1] depth: 9 wires: 2348 in: 265\nout:256 use:2313 ovh:35 t:5924 cse:0 notn:7683 unshift_bit[256][256][1] depth:\n9 wires: 2348 in: 265 out:256 use:2313 ovh:35 t:5924 cse:0 notn:7683\nshift_bit[256][256][2] depth: 6 wires: 1588 in: 265 out:256 use:1305 ovh:283\nt:3905 cse:8 notn:5153 unshift_bit[256][256][2] depth: 6 wires: 1588 in: 265\nout:256 use:1305 ovh:283 t:3905 cse:8 notn:5153 shift_bit[256][256][4] depth:\n5 wires: 1355 in: 265 out:256 use:825 ovh:530 t:6750 cse:116 notn:11309\nunshift_bit[256][256][4] depth: 5 wires: 1355 in: 265 out:256 use:825 ovh:530\nt:6750 cse:116 notn:11309 shift_bit[256][256][8] depth: 5 wires: 1595 in: 265\nout:256 use:825 ovh:770 t:33990 cse:2756 notn:65309 unshift_bit[256][256][8]\ndepth: 5 wires: 1595 in: 265 out:256 use:825 ovh:770 t:33990 cse:2756 notn:65309\nshift_bit[512][512][1] depth: 10 wires: 5174 in: 522 out:512 use:5130 ovh:44\nt:13357 cse:0 notn:17411 unshift_bit[512][512][1] depth: 10 wires: 5174 in: 522\nout:512 use:5130 ovh:44 t:13357 cse:0 notn:17411 shift_bit[512][512][2] depth: 7\nwires: 3644 in: 522 out:512 use:3098 ovh:546 t:9289 cse:8 notn:12323\nunshift_bit[512][512][2] depth: 7 wires: 3644 in: 522 out:512 use:3098 ovh:546\nt:9544 cse:8 notn:12833 shift_bit[512][512][4] depth: 6 wires: 3148 in: 522\nout:512 use:2094 ovh:1054 t:11361 cse:33 notn:17462 unshift_bit[512][512][4]\ndepth: 6 wires: 3148 in: 522 out:512 use:2094 ovh:1054 t:11361 cse:33 notn:17462\nshift_bit[512][512][8] depth: 6 wires: 3194 in: 522 out:512 use:1618 ovh:1576\nt:18192 cse:224 notn:31029 unshift_bit[512][512][8] depth: 6 wires: 3194 in:\n522 out:512 use:1618 ovh:1576 t:21912 cse:224 notn:38469\nshift_bit[1024][1024][1] depth: 11 wires: 11329 in: 1035 out:1024 use:11275\novh:54 t:29751 cse:0 notn:38915 unshift_bit[1024][1024][1] depth: 11 wires:\n11329 in: 1035 out:1024 use:11275 ovh:54 t:29751 cse:0 notn:38915\nshift_bit[1024][1024][2] depth: 7 wires: 7243 in: 1035 out:1024 use:6175\novh:1068 t:19547 cse:10 notn:26664 unshift_bit[1024][1024][2] depth: 7 wires:\n7243 in: 1035 out:1024 use:6175 ovh:1068 t:19547 cse:10 notn:26664\nshift_bit[1024][1024][4] depth: 6 wires: 6232 in: 1035 out:1024 use:4155\novh:2077 t:26989 cse:80 notn:43573 unshift_bit[1024][1024][4] depth: 6 wires:\n6232 in: 1035 out:1024 use:4155 ovh:2077 t:30769 cse:80 notn:51133\nshift_bit[1024][1024][8] depth: 6 wires: 6296 in: 1035 out:1024 use:3179\novh:3117 t:52409 cse:332 notn:94285 unshift_bit[1024][1024][8] depth: 6 wires:\n6296 in: 1035 out:1024 use:3179 ovh:3117 t:52409 cse:332 notn:94285\n*/\ntemplate \nclass Routing {\n public:\n typedef typename Logic::BitW bitW;\n typedef typename Logic::EltW EltW;\n const Logic& l_;\n\n explicit Routing(const Logic& l) : l_(l) {}\n\n // Set B[i] = A[i + amount], for 0 <= i < k. Note that A and B\n // are in general of different size.\n template \n void shift(size_t logn, const bitW amount[/*logn*/], size_t k, T B[/*k*/],\n size_t n, const T A[/*n*/], const T& defaultA,\n size_t unroll) const {\n std::vector tmp(n);\n for (size_t i = 0; i < n; ++i) {\n tmp[i] = A[i];\n }\n\n // Now shift TMP in-place.\n\n // Counting backwards from logn produces a smaller circuit if one\n // only cares about a contiguous subset of outputs. E.g. if one\n // wants the first k outputs the number of wires is O(n log k).\n size_t l = logn;\n\n // This funny logic in terms of (target_nrounds, consumed)\n // attempts to equalize the number of bits consumed per round.\n // E.g., if logn = 11 and unroll = 7, a naive consumed = unroll\n // would yield 11 = 7 + 4. Instead, we set target_nrounds = 2,\n // and consumed is 6 in the first round and 5 in the second round.\n size_t target_nrounds = ceildiv(logn, unroll);\n\n while (target_nrounds > 0) {\n size_t consumed = ceildiv(l, target_nrounds);\n --target_nrounds;\n\n l -= consumed;\n size_t shift = size_t(1) << l;\n shift_step(consumed, &amount[l], n, k, tmp.data(), shift, defaultA);\n }\n\n check(l == 0, \"l==0\");\n\n for (size_t i = 0; i < k; ++i) {\n if (i < n) {\n B[i] = tmp[i];\n } else {\n B[i] = defaultA;\n }\n }\n }\n\n // Set A[i + amount] = B[i], for 0 <= i < k. Note that A and B\n // are in general of different size.\n template \n void unshift(size_t logn, const bitW amount[/*logn*/], size_t n, T A[/*n*/],\n size_t k, const T B[/*k*/], const T& defaultB,\n size_t unroll) const {\n // we don't need TMP since we can operate on A directly\n for (size_t i = 0; i < n; ++i) {\n if (i < k) {\n A[i] = B[i];\n } else {\n A[i] = defaultB;\n }\n }\n\n size_t l = 0;\n size_t target_nrounds = ceildiv(logn, unroll);\n while (target_nrounds > 0) {\n size_t consumed = ceildiv((logn - l), target_nrounds);\n --target_nrounds;\n\n size_t shift = size_t(1) << l;\n unshift_step(consumed, &amount[l], n, k, A, shift, defaultB);\n\n l += consumed;\n }\n proofs::check(l == logn, \"l==logn\");\n }\n\n template \n void shift(const typename Logic::template bitvec& amount, size_t k,\n T B[/*k*/], size_t n, const T A[/*n*/], const T& defaultA,\n size_t unroll) const {\n shift(LOGN, &amount[0], k, B, n, A, defaultA, unroll);\n }\n\n template \n void unshift(const typename Logic::template bitvec& amount, size_t n,\n T A[/*n*/], size_t k, const T B[/*k*/], const T& defaultB,\n size_t unroll) const {\n unshift(LOGN, &amount[0], n, A, k, B, defaultB, unroll);\n }\n\n private:\n template \n void shift_step(size_t logc, const bitW amount[/*logc*/], size_t n, size_t k,\n T tmp[/*n*/], size_t shift, const T& defaultA) const {\n const Logic& L = l_; // shorthand\n size_t c = size_t(1) << logc;\n\n // cache the common subexpression amount_is[i]\n std::vector amount_is(c);\n std::vector ibits(logc);\n for (size_t i = 0; i < c; ++i) {\n L.bits(logc, ibits.data(), i);\n amount_is[i] = L.eq(logc, ibits.data(), amount);\n }\n\n really_shift(c, amount_is.data(), n, k, tmp, shift, defaultA);\n }\n\n template \n void unshift_step(size_t logc, const bitW amount[/*logc*/], size_t n,\n size_t k, T A[/*n*/], size_t shift,\n const T& defaultB) const {\n const Logic& L = l_; // shorthand\n size_t c = size_t(1) << logc;\n\n // cache the common subexpression amount_is[i]\n std::vector amount_is(c);\n std::vector ibits(logc);\n for (size_t i = 0; i < c; ++i) {\n L.bits(logc, ibits.data(), i);\n amount_is[i] = L.eq(logc, ibits.data(), amount);\n }\n\n really_unshift(c, amount_is.data(), n, k, A, shift, defaultB);\n }\n\n void really_shift(size_t c, const bitW amount_is[/*c*/], size_t n, size_t k,\n EltW tmp[/*n*/], size_t shift, const EltW& defaultA) const {\n const Logic& L = l_; // shorthand\n for (size_t i = 0; i < n && i < k + shift; ++i) {\n auto f = [&](size_t j) {\n if (i + j * shift < n) {\n return L.lmul(&amount_is[j], tmp[i + j * shift]);\n } else {\n return L.lmul(&amount_is[j], defaultA);\n }\n };\n\n tmp[i] = L.add(0, c, f);\n }\n }\n\n void really_unshift(size_t c, const bitW amount_is[/*c*/], size_t n, size_t k,\n EltW A[/*n*/], size_t shift, const EltW& defaultB) const {\n const Logic& L = l_; // shorthand\n for (size_t i = std::min(n, k + c * shift); i-- > 0;) {\n auto f = [&](size_t j) {\n if (i >= j * shift) {\n return L.lmul(&amount_is[j], A[i - j * shift]);\n } else {\n return L.lmul(&amount_is[j], defaultB);\n }\n };\n\n A[i] = L.add(0, c, f);\n }\n }\n\n void really_shift(size_t c, const bitW amount_is[/*c*/], size_t n, size_t k,\n bitW tmp[/*n*/], size_t shift, const bitW& defaultA) const {\n const Logic& L = l_; // shorthand\n for (size_t i = 0; i < n && i < k + shift; ++i) {\n bitW r = L.bit(0);\n for (size_t j = 0; j < c; ++j) {\n if (i + j * shift < n) {\n r = L.lor_exclusive(&r, L.land(&amount_is[j], tmp[i + j * shift]));\n } else {\n r = L.lor_exclusive(&r, L.land(&amount_is[j], defaultA));\n }\n }\n tmp[i] = r;\n }\n }\n\n void really_unshift(size_t c, const bitW amount_is[/*c*/], size_t n, size_t k,\n bitW A[/*n*/], size_t shift, const bitW& defaultB) const {\n const Logic& L = l_; // shorthand\n for (size_t i = std::min(n, k + c * shift); i-- > 0;) {\n bitW r = L.bit(0);\n for (size_t j = 0; j < c; ++j) {\n if (i >= j * shift) {\n r = L.lor_exclusive(&r, L.land(&amount_is[j], A[i - j * shift]));\n } else {\n r = L.lor_exclusive(&r, L.land(&amount_is[j], defaultB));\n }\n }\n A[i] = r;\n }\n }\n\n template \n void really_shift(size_t c, const bitW amount_is[/*c*/], size_t n, size_t k,\n typename Logic::template bitvec tmp[/*n*/], size_t shift,\n const typename Logic::template bitvec& defaultA) const {\n const Logic& L = l_; // shorthand\n for (size_t i = 0; i < n && i < k + shift; ++i) {\n for (size_t w = 0; w < W; ++w) {\n bitW r = L.bit(0);\n for (size_t j = 0; j < c; ++j) {\n if (i + j * shift < n) {\n r = L.lor_exclusive(&r,\n L.land(&amount_is[j], tmp[i + j * shift][w]));\n } else {\n r = L.lor_exclusive(&r, L.land(&amount_is[j], defaultA[w]));\n }\n }\n tmp[i][w] = r;\n }\n }\n }\n\n template \n void really_unshift(\n size_t c, const bitW amount_is[/*c*/], size_t n, size_t k,\n typename Logic::template bitvec A[/*n*/], size_t shift,\n const typename Logic::template bitvec& defaultB) const {\n const Logic& L = l_; // shorthand\n for (size_t i = std::min(n, k + c * shift); i-- > 0;) {\n for (size_t w = 0; w < W; ++w) {\n bitW r = L.bit(0);\n for (size_t j = 0; j < c; ++j) {\n if (i >= j * shift) {\n r = L.lor_exclusive(&r, L.land(&amount_is[j], A[i - j * shift][w]));\n } else {\n r = L.lor_exclusive(&r, L.land(&amount_is[j], defaultB[w]));\n }\n }\n A[i][w] = r;\n }\n }\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_ROUTING_H_\n"], ["/longfellow-zk/lib/circuits/logic/memcmp.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_MEMCMP_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_MEMCMP_H_\n\n#include \n\n#include \n\nnamespace proofs {\n// This class implements the an equivalent of memcmp for arrays of\n// v8. The logic comparison operators do all the work, and the only\n// problem is to arrange bits in the correct order for comparison.\n// In more detail, these methods compare the bit strings represented by\n// the array of v8 inputs (recall a v8 is 8 wires each containing a {0,1} value\n// in the Field).\ntemplate \nclass Memcmp {\n public:\n using BitW = typename Logic::BitW;\n using v8 = typename Logic::v8;\n const Logic& l_;\n\n explicit Memcmp(const Logic& l) : l_(l) {}\n\n // A < B\n BitW lt(size_t n, const v8 A[/*n*/], const v8 B[/*n*/]) const {\n std::vector a(8 * n);\n std::vector b(8 * n);\n arrange(n, a.data(), A);\n arrange(n, b.data(), B);\n return l_.lt(8 * n, a.data(), b.data());\n }\n\n // A <= B\n BitW leq(size_t n, const v8 A[/*n*/], const v8 B[/*n*/]) const {\n std::vector a(8 * n);\n std::vector b(8 * n);\n arrange(n, a.data(), A);\n arrange(n, b.data(), B);\n return l_.leq(8 * n, a.data(), b.data());\n }\n\n private:\n void arrange(size_t n, BitW bits[/* 8 * n */], const v8 bytes[/*n*/]) const {\n // from LSB to MSB:\n for (size_t i = n; i-- > 0;) {\n for (size_t j = 0; j < 8; ++j) {\n *bits++ = bytes[i][j];\n }\n }\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_MEMCMP_H_\n"], ["/longfellow-zk/lib/circuits/ecdsa/verify_witness.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ECDSA_VERIFY_WITNESS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ECDSA_VERIFY_WITNESS_H_\n\n#include \n\n#include \"algebra/utility.h\"\n#include \"arrays/dense.h\"\n#include \"util/panic.h\"\n\n/*\nMethods to help prepare witnesses for use in assertions about ecdsa.\n*/\nnamespace proofs {\n\ntemplate \nclass VerifyWitness3 {\n using Field = typename EC::Field;\n using Elt = typename Field::Elt;\n using Nat = typename Field::N;\n using Point = typename EC::ECPoint;\n using Scalar = typename ScalarField::Elt;\n\n public:\n constexpr static size_t kBits = EC::kBits;\n const ScalarField& fn_;\n const EC& ec_;\n Elt rx_, ry_;\n Elt rx_inv_;\n Elt s_inv_;\n Elt pk_inv_;\n Elt pre_[8];\n Elt bi_[kBits];\n Elt int_x_[kBits]; /* Intermediate x,y elliptic curve points */\n Elt int_y_[kBits]; /* encountered during the scalar mult loop. */\n Elt int_z_[kBits]; /* z-coordinate of the intermediate points */\n\n VerifyWitness3(const ScalarField& Fn, const EC& ec) : fn_(Fn), ec_(ec) {}\n\n void fill_witness(DenseFiller& filler) const {\n filler.push_back(rx_);\n filler.push_back(ry_);\n filler.push_back(rx_inv_);\n filler.push_back(s_inv_);\n filler.push_back(pk_inv_);\n for (size_t i = 0; i < 8; ++i) {\n filler.push_back(pre_[i]);\n }\n for (size_t i = 0; i < kBits; ++i) {\n filler.push_back(bi_[i]);\n if (i < kBits - 1) {\n filler.push_back(int_x_[i]);\n filler.push_back(int_y_[i]);\n filler.push_back(int_z_[i]);\n }\n }\n }\n\n // Produces witnesses to support the verification of the equation\n // id = g*e + pk*r + (rx,ry)*-s\n // Note that the same rx is interpreted in scalar field as r.\n bool compute_witness(const Elt pkX, const Elt pkY, const Nat e, const Nat r,\n const Nat s) {\n const Field& F = ec_.f_;\n const Scalar _s = fn_.invertf(fn_.to_montgomery(s));\n const Scalar tms = fn_.negf(fn_.to_montgomery(s));\n\n // Because Fp does not have a sqrt method, compute ry via the\n // elliptic curve point g*(e/s) + pk*(r/s).\n auto te_s = fn_.mulf(fn_.to_montgomery(e), _s);\n auto tr_s = fn_.mulf(fn_.to_montgomery(r), _s);\n const Nat nes = fn_.from_montgomery(te_s);\n const Nat nrs = fn_.from_montgomery(tr_s);\n Point bases[] = {ec_.generator(), Point(pkX, pkY, F.one())};\n Nat scalars[] = {nes, nrs};\n auto pr = ec_.scalar_multf(2, bases, scalars);\n ec_.normalize(pr);\n\n rx_ = F.to_montgomery(r);\n ry_ = pr.y;\n\n // In the case of a malicious input with rx=0 or s=0, the proof will fail.\n if (rx_ != F.zero()) {\n rx_inv_ = F.invertf(rx_);\n check(F.mulf(rx_, rx_inv_) == F.one(), \"bad inv\");\n }\n\n s_inv_ = F.to_montgomery(fn_.from_montgomery(tms));\n if (s_inv_ != F.zero()) {\n F.invert(s_inv_);\n }\n\n if (pkX != F.zero()) {\n pk_inv_ = F.invertf(pkX);\n }\n\n const Nat nms = fn_.from_montgomery(tms); /* -s */\n\n // Produce the table of pre-computed g,r,pk sums.\n const Elt one = F.one(), gX = ec_.gx_, gY = ec_.gy_;\n const Elt lh[] = {gX, gY, gX, gY, pkX, pkY};\n const Elt rh[] = {pkX, pkY, rx_, ry_, rx_, ry_};\n Elt zi;\n for (size_t i = 0; i < 3; ++i) {\n ec_.addE(pre_[2 * i], pre_[2 * i + 1], zi,\n lh[2 * i], lh[2 * i + 1], one,\n rh[2 * i], rh[2 * i + 1], one);\n\n // This invert cannot fail because both the generator and pk are\n // trusted inputs, so the above addition is not the identity.\n // In the case that it is, the proof will fail (and it should, since\n // the system is unsound with sk=-1).\n if (zi != F.zero()) {\n F.invert(zi);\n }\n F.mul(pre_[2 * i], zi);\n F.mul(pre_[2 * i + 1], zi);\n }\n // rgpk\n ec_.addE(pre_[6], pre_[7], zi, pre_[2], pre_[3], one, pkX, pkY, one);\n if (zi != F.zero()) {\n F.invert(zi);\n }\n F.mul(pre_[6], zi);\n F.mul(pre_[7], zi);\n\n Elt aX = F.zero(), aY = one, aZ = F.zero();\n\n // Compute b[], and intermediate points, encode b as:\n // 1:g 2:pk 3: gpk 4: r 5: r+g 6: r+pk 7:g+r+pk\n // Elt int_z[kBits];\n size_t b[kBits];\n // bool early_zero = false; /* indicates if any intermediate z is zero */\n for (size_t i = 0; i < kBits; ++i) {\n b[i] = e.bit(kBits - i - 1) + 2 * r.bit(kBits - i - 1) +\n 4 * nms.bit(kBits - i - 1);\n\n // Manually compute standard (-n...n representation).\n bi_[i] = F.subf(F.of_scalar(2 * b[i]), F.of_scalar(7));\n\n if (i > 0) {\n ec_.doubleE(aX, aY, aZ, aX, aY, aZ);\n }\n switch (b[i]) {\n case 0:\n ec_.addE(aX, aY, aZ, aX, aY, aZ, F.zero(), F.one(), F.zero());\n break;\n case 1:\n ec_.addE(aX, aY, aZ, aX, aY, aZ, gX, gY, one);\n break;\n case 2:\n ec_.addE(aX, aY, aZ, aX, aY, aZ, pkX, pkY, one);\n break;\n case 3:\n ec_.addE(aX, aY, aZ, aX, aY, aZ, pre_[0], pre_[1], one);\n break;\n case 4:\n ec_.addE(aX, aY, aZ, aX, aY, aZ, rx_, ry_, one);\n break;\n case 5:\n ec_.addE(aX, aY, aZ, aX, aY, aZ, pre_[2], pre_[3], one);\n break;\n case 6:\n ec_.addE(aX, aY, aZ, aX, aY, aZ, pre_[4], pre_[5], one);\n break;\n case 7:\n ec_.addE(aX, aY, aZ, aX, aY, aZ, pre_[6], pre_[7], one);\n break;\n }\n\n int_x_[i] = aX;\n int_y_[i] = aY;\n int_z_[i] = aZ;\n }\n\n if (aX != F.zero()) {\n return false;\n }\n if (aZ != F.zero()) {\n return false;\n }\n\n return true;\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ECDSA_VERIFY_WITNESS_H_\n"], ["/longfellow-zk/lib/sumcheck/quad.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_SUMCHECK_QUAD_H_\n#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_QUAD_H_\n\n#include \n\n#include \n#include \n#include \n#include \n\n#include \"algebra/compare.h\"\n#include \"algebra/poly.h\"\n#include \"arrays/affine.h\"\n#include \"arrays/eqs.h\"\n#include \"util/ceildiv.h\"\n#include \"util/panic.h\"\n#define DEFINE_STRONG_INT_TYPE(a, b) using a = b\n\n// ------------------------------------------------------------\n// Special-purpose sparse array for use with sumcheck\nnamespace proofs {\ntemplate \nclass Quad {\n using Elt = typename Field::Elt;\n using T2 = Poly<2, Field>;\n\n public:\n // To save space when representing large circuits, quad_corner_t\n // is defined as uint32_t. (Note that Elt probably imposes uint64_t\n // alignment, so struct corner has holes.)\n //\n // To make the narrowing explicit, define corner_t as a\n // Google-specific strong int. Outside of Google, replace\n // this definition with a typedef.\n DEFINE_STRONG_INT_TYPE(quad_corner_t, uint32_t);\n\n struct corner {\n quad_corner_t g; // \"gate\" variable\n quad_corner_t h[2]; // two \"hand\" variables\n Elt v;\n\n bool operator==(const corner& y) const {\n return g == y.g &&\n morton::eq(size_t(h[0]), size_t(h[1]), size_t(y.h[0]),\n size_t(y.h[1])) &&\n v == y.v;\n }\n\n bool eqndx(const corner& y) const {\n return (g == y.g && h[0] == y.h[0] && h[1] == y.h[1]);\n }\n\n void canonicalize() {\n quad_corner_t h0 = h[0], h1 = h[1];\n h[0] = std::min(h0, h1);\n h[1] = std::max(h0, h1);\n }\n\n static bool compare(const corner& x, const corner& y, const Field& F) {\n if (morton::lt(size_t(x.h[0]), size_t(x.h[1]), size_t(y.h[0]),\n size_t(y.h[1]))) {\n return true;\n } else if (morton::eq(size_t(x.h[0]), size_t(x.h[1]), size_t(y.h[0]),\n size_t(y.h[1]))) {\n if (x.g < y.g) return true;\n if (x.g > y.g) return false;\n return elt_less_than(x.v, y.v, F);\n } else {\n return false;\n }\n }\n };\n\n using index_t = size_t;\n index_t n_;\n std::vector c_;\n\n bool operator==(const Quad& y) const {\n return n_ == y.n_ &&\n std::equal(c_.begin(), c_.end(), y.c_.begin(), y.c_.end());\n }\n\n explicit Quad(index_t n) : n_(n), c_(n) {}\n\n // no copies, but see clone() below\n Quad(const Quad& y) = delete;\n Quad(const Quad&& y) = delete;\n Quad operator=(const Quad& y) = delete;\n\n std::unique_ptr clone() const {\n auto s = std::make_unique(n_);\n for (index_t i = 0; i < n_; ++i) {\n s->c_[i] = c_[i];\n }\n return s;\n }\n\n void bind_h(const Elt& r, size_t hand, const Field& F) {\n index_t rd = 0, wr = 0;\n while (rd < n_) {\n corner cc;\n cc.g = quad_corner_t(0);\n cc.h[hand] = c_[rd].h[hand] >> 1;\n cc.h[1 - hand] = c_[rd].h[1 - hand];\n\n size_t rd1 = rd + 1;\n if (rd1 < n_ && //\n c_[rd].h[1 - hand] == c_[rd1].h[1 - hand] && //\n (c_[rd].h[hand] >> 1) == (c_[rd1].h[hand] >> 1) && //\n c_[rd1].h[hand] == c_[rd].h[hand] + quad_corner_t(1)) {\n // we have two corners.\n cc.v = affine_interpolation(r, c_[rd].v, c_[rd1].v, F);\n rd += 2;\n } else {\n // we have one corner and the other one is zero.\n if ((c_[rd].h[hand] & quad_corner_t(1)) == quad_corner_t(0)) {\n cc.v = affine_interpolation_nz_z(r, c_[rd].v, F);\n } else {\n cc.v = affine_interpolation_z_nz(r, c_[rd].v, F);\n }\n rd = rd1;\n }\n\n c_[wr++] = cc;\n }\n\n // shrink the array\n n_ = wr;\n }\n\n // Set zero coefficients to BETA, then bind to both\n // G0 and G1 and take the linear combination bind(G0) + alpha*bind(G1)\n void bind_g(size_t logv, const Elt* G0, const Elt* G1, const Elt& alpha,\n const Elt& beta, const Field& F) {\n size_t nv = size_t(1) << logv;\n auto dot = Eqs::raw_eq2(logv, nv, G0, G1, alpha, F);\n for (index_t i = 0; i < n_; ++i) {\n if (c_[i].v == F.zero()) {\n c_[i].v = beta;\n }\n F.mul(c_[i].v, dot[corner_t(c_[i].g)]);\n c_[i].g = quad_corner_t(0);\n }\n\n // coalesce any duplicates that we may have created\n coalesce(F);\n }\n\n // Optimized combined bind_g + bind_h, nondestructive\n Elt bind_gh_all(\n // G bindings\n size_t logv, const Elt G0[/*logv*/], const Elt G1[/*logv*/],\n const Elt& alpha, const Elt& beta,\n // H bindings\n size_t logw, const Elt H0[/*logw*/], const Elt H1[/*logw*/],\n // field\n const Field& F) const {\n size_t nv = size_t(1) << logv;\n auto eqg = Eqs::raw_eq2(logv, nv, G0, G1, alpha, F);\n\n size_t nw = size_t(1) << logw;\n Eqs eqh0(logw, nw, H0, F);\n Eqs eqh1(logw, nw, H1, F);\n\n Elt s{};\n\n for (index_t i = 0; i < n_; ++i) {\n Elt q(c_[i].v);\n if (q == F.zero()) {\n q = beta;\n }\n F.mul(q, eqg[corner_t(c_[i].g)]);\n F.mul(q, eqh0.at(corner_t(c_[i].h[0])));\n F.mul(q, eqh1.at(corner_t(c_[i].h[1])));\n F.add(s, q);\n }\n return s;\n }\n\n Elt scalar() {\n check(n_ == 1, \"n_ == 1\");\n check(c_[0].g == quad_corner_t(0), \"c_[0].g == 0\");\n check(c_[0].h[0] == quad_corner_t(0), \"c_[0].h[0] == 0\");\n check(c_[0].h[1] == quad_corner_t(0), \"c_[0].h[1] == 0\");\n return c_[0].v;\n }\n\n void canonicalize(const Field& F) {\n for (index_t i = 0; i < n_; ++i) {\n c_[i].canonicalize();\n }\n std::sort(c_.begin(), c_.end(), [&F](const corner& x, const corner& y) {\n return corner::compare(x, y, F);\n });\n coalesce(F);\n }\n\n private:\n void coalesce(const Field& F) {\n // Coalesce duplicates.\n // The (rd,wr)=(0,0) iteration executes the else{} branch and\n // continues with (1,1), so we start at (1,1) and avoid the\n // special case for wr-1 at wr=0.\n index_t wr = 1;\n for (index_t rd = 1; rd < n_; ++rd) {\n if (c_[rd].eqndx(c_[wr - 1])) {\n F.add(c_[wr - 1].v, c_[rd].v);\n } else {\n c_[wr] = c_[rd];\n wr++;\n }\n }\n n_ = wr;\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_QUAD_H_\n"], ["/longfellow-zk/lib/arrays/sparse.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ARRAYS_SPARSE_H_\n#define PRIVACY_PROOFS_ZK_LIB_ARRAYS_SPARSE_H_\n\n#include \n\n#include \n#include \n#include \n\n#include \"algebra/compare.h\"\n#include \"algebra/poly.h\"\n#include \"arrays/affine.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n// ------------------------------------------------------------\n// Sparse representation of multi-affine functions.\n//\n// This class is mainly used as a reference implementation\n// for testing, and it exposes a similar interface as dense.\n// Sumcheck has its own specialized \"quad\" implementation.\n//\ntemplate \nclass Sparse {\n using Elt = typename Field::Elt;\n using T2 = Poly<2, Field>;\n\n public:\n // A corner on the sparse hypercube, represented as triple of size_t\n // and a value. The 3D representation is kind of a guess of how\n // many bits we'll ever need. Under the theory that \"size_t\" has\n // enough bits to index a dense array that fills the address space,\n // and that the program should support |points| gates, and each gate\n // has three terminals, then a triple ought to be both necessary and\n // sufficient.\n struct corner {\n size_t p0, p1, p2;\n Elt v;\n\n bool eqndx(const corner& y) const {\n return (p2 == y.p2 && p1 == y.p1 && p0 == y.p0);\n }\n bool operator==(const corner& y) const { return eqndx(y) && v == y.v; }\n bool operator!=(const corner& y) const { return !operator==(y); }\n\n static bool compare(const corner& x, const corner& y, const Field& F) {\n if (x.p2 < y.p2) return true;\n if (x.p2 > y.p2) return false;\n if (x.p1 < y.p1) return true;\n if (x.p1 > y.p1) return false;\n if (x.p0 < y.p0) return true;\n if (x.p0 > y.p0) return false;\n return elt_less_than(x.v, y.v, F);\n }\n };\n\n // the index of a point in a sparse array\n using index_t = size_t;\n\n index_t n_;\n std::vector c_;\n\n explicit Sparse(index_t n) : n_(n), c_(n) {}\n\n // no copies, but see clone() below\n Sparse(const Sparse& y) = delete;\n Sparse(const Sparse&& y) = delete;\n Sparse operator=(const Sparse& y) = delete;\n\n // Nobody should need to clone a sparse array except tests.\n // Reflect this fact in the name.\n std::unique_ptr clone_testing_only() const {\n auto s = std::make_unique(n_);\n for (index_t i = 0; i < n_; ++i) {\n s->c_[i] = c_[i];\n }\n return s;\n }\n\n T2 t2_at_corners(index_t* newi, index_t i, const Field& F) const {\n // If c_[i] and c_[i+1] have the same (P2, P1), and they differ\n // by the least-significant bit in P0:\n if (i + 1 < n_ && //\n c_[i].p2 == c_[i + 1].p2 && //\n c_[i].p1 == c_[i + 1].p1 && //\n (c_[i].p0 >> 1) == (c_[i + 1].p0 >> 1) && //\n c_[i + 1].p0 == c_[i].p0 + 1) {\n // we have two corners.\n *newi = i + 2;\n return T2{c_[i].v, c_[i + 1].v};\n } else {\n // we have one corner and the other one is zero.\n *newi = i + 1;\n if ((c_[i].p0 & 1) == 0) {\n return T2{c_[i].v, F.zero()};\n } else {\n return T2{F.zero(), c_[i].v};\n }\n }\n }\n\n // For a given random number r, the binding operation computes\n // v[p2, p1, p0] = (1 - r) * v[p2, p1, 2 * p0] + r * v[p2, p1, 2 * p0 + 1]\n // Note that either the odd or the even element or both may not be actually\n // present in the sparse array.\n void bind(const Elt& r, const Field& F) {\n index_t rd = 0, wr = 0;\n while (rd < n_) {\n index_t newrd;\n T2 f = t2_at_corners(&newrd, rd, F);\n c_[wr] = corner{.p0 = c_[rd].p0 >> 1,\n .p1 = c_[rd].p1,\n .p2 = c_[rd].p2,\n .v = affine_interpolation(r, f.t_[0], f.t_[1], F)};\n wr++;\n rd = newrd;\n }\n\n // shrink the array\n n_ = wr;\n }\n\n void bind_all(size_t logv, const Elt r[/*logv*/], const Field& F) {\n for (size_t v = 0; v < logv; ++v) {\n bind(r[v], F);\n }\n }\n\n void reshape() {\n // this function works only if c_[i].p0 == 0 for all i, but\n // rather than checking them one at the time, keep a giant\n // bitwise OR and check at the end\n size_t lost_bits = 0;\n for (index_t i = 0; i < n_; ++i) {\n lost_bits |= c_[i].p0;\n c_[i] = corner{.p0 = c_[i].p1, .p1 = c_[i].p2, .p2 = 0, .v = c_[i].v};\n }\n check(lost_bits == 0, \"lost_bits == 0\");\n }\n\n // This method can only be called after full binding; the caller\n // is responsible for ensuring that pre-condition.\n Elt scalar() {\n check(n_ == 1, \"n_ == 1\");\n check(c_[0].p0 == 0, \"c_[0].p0_ == 0\");\n check(c_[0].p1 == 0, \"c_[0].p1_ == 0\");\n check(c_[0].p2 == 0, \"c_[0].p2_ == 0\");\n return c_[0].v;\n }\n\n void canonicalize(const Field& F) {\n std::sort(c_.begin(), c_.end(), [&F](const corner& x, const corner& y) {\n return corner::compare(x, y, F);\n });\n return coalesce(F);\n }\n\n private:\n void coalesce(const Field& F) {\n // Coalesce duplicates.\n // The (rd,wr)=(0,0) iteration executes the else{} branch and\n // continues with (1,1), so we start at (1,1) and avoid the\n // special case for wr-1 at wr=0.\n index_t wr = 1;\n for (index_t rd = 1; rd < n_; ++rd) {\n if (c_[rd].eqndx(c_[wr - 1])) {\n F.add(c_[wr - 1].v, c_[rd].v);\n } else {\n c_[wr] = c_[rd];\n wr++;\n }\n }\n n_ = wr;\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ARRAYS_SPARSE_H_\n"], ["/longfellow-zk/lib/circuits/logic/polynomial.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_POLYNOMIAL_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_POLYNOMIAL_H_\n\n#include \n\n#include \n\n#include \"algebra/poly.h\"\n#include \"util/ceildiv.h\"\n\nnamespace proofs {\ntemplate \nclass Polynomial {\n public:\n using Field = typename Logic::Field;\n using BitW = typename Logic::BitW;\n using EltW = typename Logic::EltW;\n const Logic& l_;\n\n explicit Polynomial(const Logic& l) : l_(l) {}\n\n void powers_of_x(size_t n, EltW xi[/*n*/], const EltW& x) const {\n const Logic& L = l_; // shorthand\n\n if (n > 0) {\n xi[0] = L.konst(1);\n if (n > 1) {\n xi[1] = x;\n // invariant: xi[i] = x**i for i < k.\n // Extend inductively to k = n.\n for (size_t k = 2; k < n; ++k) {\n xi[k] = L.mul(&xi[k - k / 2], xi[k / 2]);\n }\n }\n }\n }\n\n // Evaluation via dot product with coefficients\n template \n EltW eval(const Poly& coef, const EltW& x) const {\n const Logic& L = l_; // shorthand\n\n std::array xi;\n powers_of_x(N, xi.data(), x);\n\n // dot product with coefficients\n EltW r = L.konst(0);\n for (size_t i = 0; i < N; ++i) {\n auto cxi = L.mul(coef[i], xi[i]);\n r = L.add(&r, cxi);\n }\n return r;\n }\n\n // Evaluation via parallel Horner's rule\n template \n EltW eval_horner(const Poly& coef, EltW x) const {\n const Logic& L = l_; // shorthand\n\n std::array c;\n for (size_t i = 0; i < N; ++i) {\n c[i] = L.konst(coef[i]);\n }\n\n for (size_t n = N; n > 1; n = ceildiv(n, 2)) {\n for (size_t i = 0; 2 * i < n; ++i) {\n c[i] = c[2 * i];\n if (2 * i + 1 < n) {\n auto cxi = L.mul(&x, c[2 * i + 1]);\n c[i] = L.add(&c[i], cxi);\n }\n }\n x = L.mul(&x, x);\n }\n return c[0];\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_POLYNOMIAL_H_\n"], ["/longfellow-zk/lib/ligero/ligero_param.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_PARAM_H_\n#define PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_PARAM_H_\n\n#include \n\n#include \n#include \n#include \n#include \n#include \n\n#include \"algebra/blas.h\"\n#include \"merkle/merkle_commitment.h\"\n#include \"merkle/merkle_tree.h\"\n#include \"util/ceildiv.h\"\n#include \"util/crypto.h\"\n#include \"util/panic.h\"\n\n/*\n\n This is an implementation of the Ligero protocol described in\n\n Ligero: Lightweight Sublinear Arguments\n Without a Trusted Setup,\n\n Scott Ames and Carmit Hazay and Yuval Ishai and\n Muthuramakrishnan Venkitasubramaniam,\n https://eprint.iacr.org/2022/1608\n doi = {10.1145/3133956},\n\n The main data structure in the prover is a 2D array which we call a\n tableau organized as follows.\n\n Fix a block size BLOCK and let DBLOCK = 2 * BLOCK - 1. Fix another\n quantity BLOCK_EXT >= 0.\n\n Each row in the tableau has the form [X XD XEXT], where X is a row\n of BLOCK elements, XD is a row of BLOCK - 1 elements, and XEXT is a\n row of BLOCK_EXT elements. We call the X part the \"block\" and the\n XEXT part the \"extension\".\n\n Let BLOCK_ENC = 2 * BLOCK - 1 + BLOCK_EXT = DBLOCK + BLOCK_EXT be\n the total size of the row.\n\n A \"witness block\" has the form [RANDOM[R], WITNESS[W]], where R + W\n = BLOCK. The randomess (of size R) is used for zero-knowledge\n blinding. Although not strictly required by Ligero, we require W >=\n R to avoid wasting too much space, so that a witness block is at\n least half full.\n\n A block is interpreted as evaluations of some polynomial at point\n INJ(j) for 0 <= j < BLOCK, where INJ(.) is some field-specific\n injection that injects small natural numbers into distinct field\n elements. With the condition that the degree of the polynomial be\n less than BLOCK, the polynomial is uniquely determined, and the rest\n [XD XEXT] of the row is then computed as the evaluations of that\n polynomial for BLOCK <= j < BLOCK_ENC.\n\n To the extent that Ligero is based on Reed-Solomon codes, X is the\n \"message\" and XEXT is the \"codeword\". The \"rate\" is thus BLOCK /\n BLOCK_EXT.\n\n However, Ligero also needs products of two polynomials of degree\n less than BLOCK, so that the product has degree less than 2 * BLOCK\n - 1 = DBLOCK. XD exists in the tableau to facilitate the\n computation of these products. For zero knowledge, the indices of\n XD must be distinct from the indices of BLOCK_EXT.\n\n We now discuss the row structure of the tableau. The first three\n rows are special and used for zero-knowledge blinding purposes.\n\n The first row, row ILDT for ILDT = 0, used for the low-degree test,\n consists of BLOCK random field elements, extended to BLOCK_ENC.\n\n The second row, row IDOT for IDOT = 1, used in the linear test,\n consists of DBLOCK random field elements, with the additional\n constraint that the double block sum to 0. As usual, the row is\n extended to BLOCK_ENC by interpolation.\n\n The third row, row IQUAD for IQUAD = 2, used in the quadratic test,\n consists of DBLOCK random field elements, with the additional\n constraint that the WITNESS portion of the block be zero. Thus, the\n structure is really [RANDOM[R] ZERO[W] RANDOM[BLOCK-1]], extended to\n BLOCK_ENC by interpolation.\n\n The next group of \"witness rows\" IW <= I < IQ for IW = 3, stores\n witnesses. Each row is a witness block extended to BLOCK_ENC.\n\n The next group of \"quadratic\" rows IQ <= I < NROW, has the same\n syntactic structure as the \"witness\" rows, but they are used in the\n quadratic check in addition to the linear check. In Ligero, a\n quadratic constraint induces three entries in three quadratic rows.\n Thus, for NQ total quadratic constraints and W useful entries per\n row, we have a total of 3 * (NQ / W) quadratic rows. To enforce\n this structure, the code stores NQTRIPLES = (NQ / W) instead of the\n number 3 * NQTRIPLES of rows.\n\n */\n\nnamespace proofs {\n\ntemplate \nstruct LigeroParam {\n using Elt = typename Field::Elt;\n\n // parameters passed by the user\n size_t nw; // total number of witnesses\n size_t nq; // total number of quadratic constraints\n size_t rateinv; // inverse rate of the error-correcting code\n size_t nreq; // number of opened columns\n\n // computed parameters\n size_t block_enc; // total number of elts per row\n size_t block; // number of elts per block\n size_t dblock; // 2 * BLOCK - 1\n size_t block_ext; // BLOCK_ENC - DBLOCK (number of leaves in the\n // Merkle tree).\n size_t r; // number of random elts in a witness block\n size_t w; // number of witnesses in a witness block\n size_t nwrow; // number of witness rows\n size_t nqtriples; // number of triples of quadratic-check rows\n size_t nwqrow; // nwqrow + nqtriples\n size_t nrow; // total number of rows (nwqrow + three blinding rows)\n size_t mc_pathlen; // length of a Merkle-tree proof\n // with BLOCK_ENC-BLOCK leaves\n\n // layout of rows\n size_t ildt; // blinding for the low-degree test\n size_t idot; // blinding row for the dot-product check\n size_t iquad; // blinding row for the quadratic check\n size_t iw; // first witness row\n size_t iq; // first quadratic row\n\n LigeroParam(size_t nw, size_t nq, size_t rateinv, size_t nreq)\n : nw(nw), nq(nq), rateinv(rateinv), nreq(nreq) {\n r = nreq;\n\n size_t min_proof_size = SIZE_MAX;\n size_t best_block_enc = 1;\n for (size_t e = 1; e <= (1 << 28); e *= 2) {\n size_t proof_size = layout(e);\n if (proof_size < min_proof_size) {\n min_proof_size = proof_size;\n best_block_enc = e;\n }\n }\n\n // recompute parameters\n layout(best_block_enc);\n proofs::check(block_enc > block, \"block_enc > block\");\n\n ildt = 0;\n idot = 1;\n iquad = 2;\n iw = 3;\n iq = iw + nwrow;\n proofs::check(nrow == iq + 3 * nqtriples, \"nrow == iq + 3 * nqtriples\");\n }\n\n private:\n // Return an estimate of the proof size.\n //\n // This function is kind of a hack in that it breaks abstraction\n // boundaries, e.g. it knows about the size and layout of the Merkle\n // commitment. Punt on this wart until we have a better theory.\n size_t layout(size_t e) {\n // Maximum size we are prepared to handle. All dimensions will be\n // required to be < MAX_SIZE. In principle we could handle all\n // size_t, but we want 64-bit code to fail if it would fail on a\n // 32-bit machine, and for maximum paranoia we restrict to 28\n // bits, since one cannot malloc 2^{28} Elts on a 32-bit machine\n // anyway.\n constexpr size_t max_lg_size = 28;\n constexpr size_t max_size = static_cast(1) << max_lg_size;\n block_enc = e;\n\n // block_enc must fit in the subfield\n size_t subfield_bits = 8 * Field::kSubFieldBytes;\n if (subfield_bits <= max_lg_size) {\n if (block_enc >= (static_cast(1) << subfield_bits)) {\n return SIZE_MAX;\n }\n }\n\n // limit block_enc to avoid overflow in the computation\n // of the proof size\n if (block_enc > max_size || rateinv > max_size ||\n (block_enc + 1) < (2 + rateinv)) {\n return SIZE_MAX;\n }\n\n block = (block_enc + 1) / (2 + rateinv);\n // now 1 <= BLOCK < MAX_SIZE / 2\n\n // Ensure BLOCK = R + W (syntactic property)\n if (block < r) {\n return SIZE_MAX;\n }\n w = block - r;\n\n // now r <= BLOCK < MAX_SIZE / 2\n // 0 <= W < MAX_SIZE / 2\n // 0 <= W <= BLOCK\n // 0 <= R <= BLOCK\n // W + R == BLOCK\n\n // Ensure W >= R (needed for reasonable space utilization).\n if (w < r) {\n return SIZE_MAX;\n }\n // now R <= W < MAX_SIZE\n\n // Finish the layout of a row\n dblock = 2 * block - 1;\n // now DBLOCK < MAX_SIZE\n\n // Ensure BLOCK_ENC >= 0 (syntactic property). Should be true\n // for any reasonable rateinv, but check anyway.\n if (block_enc < dblock) {\n return SIZE_MAX;\n }\n // now DBLOCK <= BLOCK_ENC\n\n block_ext = block_enc - dblock;\n // now 0 <= BLOCK_EXT < MAX_SIZE\n\n nwrow = ceildiv(nw, w);\n nqtriples = ceildiv(nq, w);\n\n nwqrow = nwrow + 3 * nqtriples;\n nrow = nwqrow + /*blinding rows=*/3;\n\n // The total number of elements (NROW * BLOCK_ENC) in the tableau\n // must fit in MAX_SIZE.\n if (nrow >= max_size / block_enc) {\n return SIZE_MAX;\n }\n\n mc_pathlen = merkle_commitment_len(block_ext);\n\n /* proof+commitment size. */\n // Compute the size in uint64_t instead of size_t since\n // I am too lazy to worry about overflow.\n uint64_t sz = 0;\n\n // commitment\n sz += sizeof(Digest);\n\n // Merkle openings, approximated because the exact # of leaves depends\n // on the random coins.\n sz += static_cast(mc_pathlen) / 2 * static_cast(nreq) *\n static_cast(Digest::kLength);\n\n // y_ldt\n sz += static_cast(block) * static_cast(Field::kBytes);\n\n // y_dot\n sz += static_cast(dblock) * static_cast(Field::kBytes);\n\n // y_quad\n // The quadratic-test response has size DBLOCK, but W elements\n // are expected to be zero and not serialized.\n sz += static_cast(dblock - w) *\n static_cast(Field::kBytes);\n\n // nonces\n sz += static_cast(nreq) *\n static_cast(MerkleNonce::kLength);\n\n // req. Assume optimistically that all elements are in the subfield.\n sz += static_cast(nrow) * static_cast(nreq) *\n static_cast(Field::kSubFieldBytes);\n\n sz = std::min(sz, SIZE_MAX);\n return static_cast(sz);\n }\n};\n\ntemplate \nstruct LigeroCommitment {\n Digest root;\n};\n\ntemplate \nstruct LigeroProof {\n using Elt = typename Field::Elt;\n explicit LigeroProof(const LigeroParam *p)\n : block(p->block),\n dblock(p->dblock),\n r(p->r),\n block_enc(p->block_enc),\n nrow(p->nrow),\n nreq(p->nreq),\n mc_pathlen(p->mc_pathlen),\n y_ldt(p->block),\n y_dot(p->dblock),\n y_quad_0(p->r),\n y_quad_2(p->dblock - p->block),\n req(p->nrow * p->nreq),\n merkle(p->nreq) {}\n\n // The proof stores a copy of all parameters relevant to the proof.\n size_t block;\n size_t dblock;\n size_t r;\n size_t block_enc;\n size_t nrow;\n size_t nreq;\n size_t mc_pathlen;\n\n std::vector y_ldt; // [block]\n std::vector y_dot; // [dblock]\n std::vector y_quad_0; // [r] first part of y_quad.\n // The middle part [w] of y_quad is zero and not transmitted.\n std::vector y_quad_2; // [dblock - block] last part of y_quad\n std::vector req; // [nrow, nreq]\n MerkleProof merkle;\n\n Elt &req_at(size_t i, size_t j) { return req[i * nreq + j]; }\n const Elt &req_at(size_t i, size_t j) const { return req[i * nreq + j]; }\n};\n\n// a nonzero entry in the matrix A that defines\n// the linear constraints A w = b. The term\n// states that A[c, w] = k, where the \"row\"\n// c is interpreted as the constraint index, and\n// the \"column\" w is interpreted as the witness\n// index\ntemplate \nstruct LigeroLinearConstraint {\n using Elt = typename Field::Elt;\n size_t c;\n size_t w;\n Elt k;\n};\n\n// encode W[X] * W[Y] - W[Z] = 0\nstruct LigeroQuadraticConstraint {\n size_t x;\n size_t y;\n size_t z;\n};\n\ntemplate \nclass LigeroCommon {\n using Elt = typename Field::Elt;\n\n public:\n // create a grand dot product by A given the user-provided\n // linear-constraint terms LLTERM, the quadratic constraints LQC,\n // and their random challenges ALPHAL, ALPHAQ.\n static void inner_product_vector(\n Elt A[/*nwqrow, w*/], const LigeroParam &p, size_t nl,\n size_t nllterm, const LigeroLinearConstraint llterm[/*nllterm*/],\n const Elt alphal[/*nl*/], const LigeroQuadraticConstraint lqc[/*nq*/],\n const std::array alphaq[/*nq*/], const Field &F) {\n // clear A and overwrite it later.\n Blas::clear(p.nwqrow * p.w, A, 1, F);\n\n // random linear combinations of the linear constraints\n for (size_t l = 0; l < nllterm; ++l) {\n const auto &term = llterm[l];\n proofs::check(term.w < p.nw, \"term.w < p.nw\");\n proofs::check(term.c < nl, \"term.c < nl\");\n F.add(A[term.w], F.mulf(term.k, alphal[term.c]));\n }\n\n // routing terms for quadratic constraints\n Elt *Ax = &A[p.nwrow * p.w];\n Elt *Ay = Ax + (p.nqtriples * p.w);\n Elt *Az = Ay + (p.nqtriples * p.w);\n\n for (size_t i = 0; i < p.nqtriples; ++i) {\n for (size_t j = 0; j < p.w && j + i * p.w < p.nq; ++j) {\n // index into [_ , W] arrays\n size_t iw = j + i * p.w;\n const auto *l = &lqc[iw];\n F.add(Ax[iw], alphaq[iw][0]);\n F.sub(A[l->x], alphaq[iw][0]);\n\n F.add(Ay[iw], alphaq[iw][1]);\n F.sub(A[l->y], alphaq[iw][1]);\n\n F.add(Az[iw], alphaq[iw][2]);\n F.sub(A[l->z], alphaq[iw][2]);\n }\n }\n }\n\n // layout a witness block where the \"witness\" is public, and\n // thus the randomess is zero.\n static void layout_Aext(Elt Aext[/*>=block*/], const LigeroParam &p,\n size_t i, const Elt A[/*nwqrow, nw*/],\n const Field &F) {\n Blas::clear(p.r, &Aext[0], 1, F);\n Blas::copy(p.w, &Aext[p.r], 1, &A[i * p.w], 1);\n }\n\n static void column_hash(size_t n, const Elt x[/*n:incx*/], size_t incx,\n SHA256 &sha, const Field &F) {\n for (size_t i = 0; i < n; ++i) {\n uint8_t buf[Field::kBytes];\n F.to_bytes_field(buf, x[i * incx]);\n sha.Update(buf, sizeof(buf));\n }\n }\n};\n\n// A struct representing the hash of llterms. It is really the\n// same as Digest, but in theory Ligero should exist independently\n// of the Merkle tree.\nstruct LigeroHash {\n static constexpr size_t kLength = kSHA256DigestSize;\n uint8_t bytes[kLength];\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_PARAM_H_\n"], ["/longfellow-zk/lib/zk/zk_proof.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ZK_ZK_PROOF_H_\n#define PRIVACY_PROOFS_ZK_LIB_ZK_ZK_PROOF_H_\n\n#include \n#include \n#include \n#include \n\n#include \"ligero/ligero_param.h\"\n#include \"merkle/merkle_commitment.h\"\n#include \"merkle/merkle_tree.h\"\n#include \"sumcheck/circuit.h\"\n#include \"util/log.h\"\n#include \"util/readbuffer.h\"\n#include \"util/serialization.h\"\n#include \"zk/zk_common.h\"\n\nnamespace proofs {\n\n// ZkProof class handles proof serialization.\n//\n// We expect circuits to be created and stored locally by the prover and\n// verifier respectively, and thus the circuit representations are trusted and\n// are assumed to contain parameters that do not induce arithmetic overflows.\n// For example, we assume that values like c.logw and c.logc are smaller than\n// 2^24 and therefore do not cause any overflows (even on 32b machines) in the\n// range/length calculations that are performed during serialization.\n//\n// An earlier experiment implemented the IO methods using protobuf parsing.\n// Despite applying techniques like arena allocation, those methods required\n// an order of magnitude more time.\ntemplate \nstruct ZkProof {\n public:\n const Circuit &c;\n Proof proof;\n LigeroParam param;\n LigeroCommitment com;\n LigeroProof com_proof;\n\n // The max run length is 2^25, in order to prevent overflow issues on 32b\n // machines when performing length calculations during serialization.\n constexpr static size_t kMaxRunLen = (1 << 25);\n\n constexpr static size_t kMaxNumDigests = (1 << 25);\n\n typedef typename Field::Elt Elt;\n\n explicit ZkProof(const Circuit &c, size_t rate, size_t req)\n : c(c),\n proof(c.nl),\n param((c.ninputs - c.npub_in) + ZkCommon::pad_size(c), c.nl,\n rate, req),\n com_proof(¶m) {}\n\n // Maximum size of the proof in bytes. The actual size will be smaller\n // because the Merkle proof is batched.\n size_t size() const {\n return Digest::kLength +\n\n proof.size() * Field::kBytes +\n\n com_proof.block * 2 * Field::kBytes +\n com_proof.nreq * com_proof.nrow * Field::kBytes +\n com_proof.nreq * com_proof.mc_pathlen * Digest::kLength;\n }\n\n void write(std::vector &buf, const Field &F) const {\n size_t s0 = buf.size();\n write_com(com, buf, F);\n size_t s1 = buf.size();\n write_sc_proof(proof, buf, F);\n size_t s2 = buf.size();\n write_com_proof(com_proof, buf, F);\n size_t s3 = buf.size();\n log(INFO,\n \"com:%zu, sc:%zu, com_proof:%zu [%zu el, %zu el, %zu d in %zu \"\n \"rows]: %zub\",\n s1 - s0, s2 - s1, s3 - s2, 2 * com_proof.block,\n com_proof.nreq * com_proof.nrow, com_proof.merkle.path.size(),\n com_proof.nrow, s3);\n }\n\n // The read function returns false on error or underflow.\n bool read(ReadBuffer &buf, const Field &F) {\n if (!read_com(com, buf, F)) return false;\n if (!read_sc_proof(proof, buf, F)) return false;\n if (!read_com_proof(com_proof, buf, F)) return false;\n return true;\n }\n\n void write_sc_proof(const Proof &pr, std::vector &buf,\n const Field &F) const {\n check(c.logc == 0, \"cannot write sc proof with logc != 0\");\n for (size_t i = 0; i < pr.l.size(); ++i) {\n for (size_t wi = 0; wi < c.l[i].logw; ++wi) {\n for (size_t k = 0; k < 3; ++k) {\n // Optimization: do not send p(1) as it is implied by constraints.\n if (k != 1) {\n write_elt(pr.l[i].hp[0][wi].t_[k], buf, F);\n write_elt(pr.l[i].hp[1][wi].t_[k], buf, F);\n }\n }\n }\n write_elt(pr.l[i].wc[0], buf, F);\n write_elt(pr.l[i].wc[1], buf, F);\n }\n }\n\n void write_com(const LigeroCommitment &com0, std::vector &buf,\n const Field &F) const {\n buf.insert(buf.end(), com0.root.data, com0.root.data + Digest::kLength);\n }\n\n void write_com_proof(const LigeroProof &pr, std::vector &buf,\n const Field &F) const {\n for (size_t i = 0; i < pr.block; ++i) {\n write_elt(pr.y_ldt[i], buf, F);\n }\n for (size_t i = 0; i < pr.dblock; ++i) {\n write_elt(pr.y_dot[i], buf, F);\n }\n for (size_t i = 0; i < pr.r; ++i) {\n write_elt(pr.y_quad_0[i], buf, F);\n }\n for (size_t i = 0; i < pr.dblock - pr.block; ++i) {\n write_elt(pr.y_quad_2[i], buf, F);\n }\n\n // write all the Merkle nonces\n for (size_t i = 0; i < pr.nreq; ++i) {\n write_nonce(pr.merkle.nonce[i], buf);\n }\n\n // The format of the opened rows consists of a run of full-field elements,\n // then a run of base-field elements, and finally a run of full-field\n // elements. To compress, we employ a run-length encoding approach.\n size_t ci = 0;\n bool subfield_run = false;\n while (ci < pr.nreq * pr.nrow) {\n size_t runlen = 0;\n while (ci + runlen < pr.nreq * pr.nrow && runlen < kMaxRunLen &&\n F.in_subfield(pr.req[ci + runlen]) == subfield_run) {\n ++runlen;\n }\n write_size(runlen, buf);\n for (size_t i = ci; i < ci + runlen; ++i) {\n if (subfield_run) {\n write_subfield_elt(pr.req[i], buf, F);\n } else {\n write_elt(pr.req[i], buf, F);\n }\n }\n ci += runlen;\n subfield_run = !subfield_run;\n }\n\n write_size(pr.merkle.path.size(), buf);\n for (size_t i = 0; i < pr.merkle.path.size(); ++i) {\n write_digest(pr.merkle.path[i], buf);\n }\n }\n\n private:\n void write_elt(const Elt &x, std::vector &buf,\n const Field &F) const {\n uint8_t tmp[Field::kBytes];\n F.to_bytes_field(tmp, x);\n buf.insert(buf.end(), tmp, tmp + Field::kBytes);\n }\n\n void write_subfield_elt(const Elt &x, std::vector &buf,\n const Field &F) const {\n uint8_t tmp[Field::kSubFieldBytes];\n F.to_bytes_subfield(tmp, x);\n buf.insert(buf.end(), tmp, tmp + Field::kSubFieldBytes);\n }\n\n void write_digest(const Digest &x, std::vector &buf) const {\n buf.insert(buf.end(), x.data, x.data + Digest::kLength);\n }\n\n void write_nonce(const MerkleNonce &x, std::vector &buf) const {\n buf.insert(buf.end(), x.bytes, x.bytes + MerkleNonce::kLength);\n }\n\n // Assumption is that all of the sizes of arrays that are part of proofs\n // fit into 4 bytes, and can thus work on 32-b machines.\n void write_size(size_t g, std::vector &buf) const {\n for (size_t i = 0; i < 4; ++i) {\n buf.push_back(static_cast(g & 0xff));\n g >>= 8;\n }\n }\n\n bool read_sc_proof(Proof &pr, ReadBuffer &buf, const Field &F) {\n if (c.logc != 0) return false;\n for (size_t i = 0; i < pr.l.size(); ++i) {\n size_t needed = (c.l[i].logw * (3 - 1) * 2 + 2) * Field::kBytes;\n if (!buf.have(needed)) return false;\n for (size_t wi = 0; wi < c.l[i].logw; ++wi) {\n for (size_t k = 0; k < 3; ++k) {\n // Optimization: the p(1) value was not sent.\n if (k != 1) {\n for (size_t hi = 0; hi < 2; ++hi) {\n auto v = read_elt(buf, F);\n if (v) {\n pr.l[i].hp[hi][wi].t_[k] = v.value();\n } else {\n return false;\n }\n }\n } else {\n pr.l[i].hp[0][wi].t_[k] = F.zero();\n pr.l[i].hp[1][wi].t_[k] = F.zero();\n }\n }\n }\n for (size_t wi = 0; wi < 2; ++wi) {\n auto v = read_elt(buf, F);\n if (v) {\n pr.l[i].wc[wi] = v.value();\n } else {\n return false;\n }\n }\n }\n return true;\n }\n\n bool read_com(LigeroCommitment &com0, ReadBuffer &buf,\n const Field &F) {\n if (!buf.have(Digest::kLength)) return false;\n read_digest(buf, com0.root);\n return true;\n }\n\n bool read_com_proof(LigeroProof &pr, ReadBuffer &buf, const Field &F) {\n if (!buf.have(pr.block * Field::kBytes)) return false;\n for (size_t i = 0; i < pr.block; ++i) {\n auto v = read_elt(buf, F);\n if (v) {\n pr.y_ldt[i] = v.value();\n } else {\n return false;\n }\n }\n\n if (!buf.have(pr.dblock * Field::kBytes)) return false;\n for (size_t i = 0; i < pr.dblock; ++i) {\n auto v = read_elt(buf, F);\n if (v) {\n pr.y_dot[i] = v.value();\n } else {\n return false;\n }\n }\n\n if (!buf.have(pr.r * Field::kBytes)) return false;\n for (size_t i = 0; i < pr.r; ++i) {\n auto v = read_elt(buf, F);\n if (v) {\n pr.y_quad_0[i] = v.value();\n } else {\n return false;\n }\n }\n\n if (!buf.have((pr.dblock - pr.block) * Field::kBytes)) return false;\n for (size_t i = 0; i < pr.dblock - pr.block; ++i) {\n auto v = read_elt(buf, F);\n if (v) {\n pr.y_quad_2[i] = v.value();\n } else {\n return false;\n }\n }\n\n if (!buf.have(pr.nreq * MerkleNonce::kLength)) return false;\n for (size_t i = 0; i < pr.nreq; ++i) {\n read_nonce(buf, pr.merkle.nonce[i]);\n }\n\n // Decode runs of real and full Field elements.\n size_t ci = 0;\n bool subfield_run = false;\n while (ci < pr.nreq * pr.nrow) {\n if (!buf.have(4)) return false;\n size_t runlen = read_size(buf); /* untrusted size input */\n if (runlen >= kMaxRunLen || ci + runlen > pr.nreq * pr.nrow) return false;\n if (subfield_run) {\n if (!buf.have(runlen * Field::kSubFieldBytes)) return false;\n for (size_t i = ci; i < ci + runlen; ++i) {\n auto v = read_subfield_elt(buf, F);\n if (v) {\n pr.req[i] = v.value();\n } else {\n return false;\n }\n }\n } else {\n if (!buf.have(runlen * Field::kBytes)) return false;\n for (size_t i = ci; i < ci + runlen; ++i) {\n auto v = read_elt(buf, F);\n if (v) {\n pr.req[i] = v.value();\n } else {\n return false;\n }\n }\n }\n ci += runlen;\n subfield_run = !subfield_run;\n }\n\n if (!buf.have(4)) return false;\n size_t sz = read_size(buf); /* untrusted size input */\n\n // Merkle proofs of length < NREQ are not valid in the zk proof setting.\n if (sz < pr.nreq || sz >= kMaxNumDigests) return false; // avoid overflow\n if (!buf.have(sz * Digest::kLength)) return false;\n\n // Sanity check, the proof should never be larger than this.\n // That value should always fit into memory, so this check aims to avoid\n // an exception by resize() if there is not enough memory to resize.\n if (sz > pr.nreq * pr.mc_pathlen) return false;\n\n pr.merkle.path.resize(sz);\n for (size_t i = 0; i < sz; ++i) {\n read_digest(buf, pr.merkle.path[i]);\n }\n return true;\n }\n\n std::optional read_elt(ReadBuffer &buf, const Field &F) const {\n return F.of_bytes_field(buf.next(Field::kBytes));\n }\n\n std::optional read_subfield_elt(ReadBuffer &buf, const Field &F) const {\n return F.of_bytes_subfield(buf.next(Field::kSubFieldBytes));\n }\n\n void read_digest(ReadBuffer &buf, Digest &x) const {\n buf.next(Digest::kLength, x.data);\n }\n\n void read_nonce(ReadBuffer &buf, MerkleNonce &x) const {\n buf.next(MerkleNonce::kLength, x.bytes);\n }\n\n size_t read_size(ReadBuffer &buf) { return u32_of_le(buf.next(4)); }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ZK_ZK_PROOF_H_\n"], ["/longfellow-zk/lib/algebra/fp2.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP2_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP2_H_\n\n#include \n\n#include \n#include \n\n#include \"util/panic.h\"\n\nnamespace proofs {\n// Fields of the form a+sqrt(r)*b where a, b \\in Fp and\n// r is a quadratic nonresidue in Fp. The special \"complex\"\n// case r = -1 allows for a faster implementation of multiplication.\n//\n// With slight abuse of terminology, we call \"a\" the \"real\" part and\n// \"b\" the \"imaginary\" part, and we call the sqrt(r) \"i\" even when\n// r != -1.\ntemplate \nclass Fp2 {\n public:\n using Scalar = typename Field::Elt;\n using BaseField = Field;\n using TypeTag = typename Field::TypeTag;\n\n // size of the serialization into bytes\n static constexpr size_t kBytes = 2 * Field::kBytes;\n static constexpr size_t kBits = 2 * Field::kBits;\n static constexpr size_t kSubFieldBytes = Field::kBytes;\n static constexpr bool kCharacteristicTwo = false;\n const Field& f_;\n\n struct Elt {\n Scalar re, im;\n bool operator==(const Elt& y) const { return re == y.re && im == y.im; }\n bool operator!=(const Elt& y) const { return !operator==(y); }\n };\n\n explicit Fp2(const Field& F, const Scalar& nonresidue)\n : f_(F), nonresidue_(nonresidue) {\n if (nonresidue_is_mone) {\n check(nonresidue == F.mone(), \"nonresidue == F.mone()\");\n } else {\n check(nonresidue != F.mone(), \"nonresidue != F.mone()\");\n }\n\n i_ = Elt{f_.zero(), f_.one()};\n for (uint64_t i = 0; i < sizeof(k_) / sizeof(k_[0]); ++i) {\n k_[i] = of_scalar(i);\n }\n khalf_ = Elt{f_.half(), f_.zero()};\n kmone_ = Elt{f_.mone(), f_.zero()};\n }\n explicit Fp2(const Field& F) : Fp2(F, F.mone()) {}\n\n Fp2(const Fp2&) = delete;\n Fp2& operator=(const Fp2&) = delete;\n\n const Field& base_field() const { return f_; }\n\n Scalar real(const Elt& e) const { return e.re; }\n bool is_real(const Elt& e) const { return e.im == f_.zero(); }\n\n void add(Elt& a, const Elt& y) const {\n f_.add(a.re, y.re);\n f_.add(a.im, y.im);\n }\n void sub(Elt& a, const Elt& y) const {\n f_.sub(a.re, y.re);\n f_.sub(a.im, y.im);\n }\n void mul(Elt& a, const Elt& y) const {\n auto p0 = f_.mulf(a.re, y.re);\n auto p1 = f_.mulf(a.im, y.im);\n auto a01 = f_.addf(a.re, a.im);\n auto y01 = f_.addf(y.re, y.im);\n if (nonresidue_is_mone) {\n a.re = f_.subf(p0, p1);\n } else {\n a.re = f_.addf(p0, f_.mulf(p1, nonresidue_));\n }\n f_.mul(a01, y01);\n f_.sub(a01, p0);\n f_.sub(a01, p1);\n a.im = a01;\n }\n void mul(Elt& a, const Scalar& y) const {\n f_.mul(a.re, y);\n f_.mul(a.im, y);\n }\n void neg(Elt& x) const {\n Elt y(k_[0]);\n sub(y, x);\n x = y;\n }\n void conj(Elt& x) const { f_.neg(x.im); }\n void invert(Elt& x) const {\n Scalar denom;\n if (nonresidue_is_mone) {\n denom = f_.addf(f_.mulf(x.re, x.re), f_.mulf(x.im, x.im));\n } else {\n denom = f_.subf(f_.mulf(x.re, x.re),\n f_.mulf(nonresidue_, f_.mulf(x.im, x.im)));\n }\n f_.invert(denom);\n conj(x);\n mul(x, denom);\n }\n\n // functional interface\n Elt addf(Elt a, const Elt& y) const {\n add(a, y);\n return a;\n }\n Elt subf(Elt a, const Elt& y) const {\n sub(a, y);\n return a;\n }\n Elt mulf(Elt a, const Elt& y) const {\n mul(a, y);\n return a;\n }\n Elt mulf(Elt a, const Scalar& y) const {\n mul(a, y);\n return a;\n }\n Elt negf(Elt a) const {\n neg(a);\n return a;\n }\n Elt invertf(Elt a) const {\n invert(a);\n return a;\n }\n Elt conjf(Elt a) const {\n conj(a);\n return a;\n }\n\n Elt of_scalar(uint64_t a) const { return of_scalar_field(a); }\n Elt of_scalar(const Scalar& e) const { return of_scalar_field(e); }\n\n Elt of_scalar_field(const Scalar& e) const { return Elt{e, f_.zero()}; }\n Elt of_scalar_field(uint64_t a) const {\n return Elt{f_.of_scalar(a), f_.zero()};\n }\n Elt of_scalar_field(uint64_t ar, uint64_t ai) const {\n return Elt{f_.of_scalar(ar), f_.of_scalar(ai)};\n }\n\n template \n Elt of_string(const char (&s)[N]) const {\n return Elt{f_.of_string(s), f_.zero()};\n }\n\n template \n Elt of_string(const char (&sr)[NR], const char (&si)[NI]) const {\n return Elt{f_.of_string(sr), f_.of_string(si)};\n }\n\n std::optional of_bytes_field(const uint8_t ab[/* kBytes */]) const {\n if (auto re = f_.of_bytes_field(ab)) {\n if (auto im = f_.of_bytes_field(ab + Field::kBytes)) {\n return Elt{re.value(), im.value()};\n }\n }\n return std::nullopt;\n }\n\n void to_bytes_field(uint8_t ab[/* kBytes */], const Elt& x) const {\n f_.to_bytes_field(ab, x.re);\n f_.to_bytes_field(ab + Field::kBytes, x.im);\n }\n\n bool in_subfield(const Elt& e) const { return is_real(e); }\n\n std::optional of_bytes_subfield(\n const uint8_t ab[/* kSubFieldBytes */]) const {\n if (auto re = f_.of_bytes_subfield(ab)) {\n return of_scalar(re.value());\n }\n return std::nullopt;\n }\n\n void to_bytes_subfield(uint8_t ab[/* kSubFieldBytes */], const Elt& x) const {\n check(in_subfield(x), \"x not in subfield\");\n f_.to_bytes_subfield(ab, x.re);\n }\n\n const Elt& zero() const { return k_[0]; }\n const Elt& one() const { return k_[1]; }\n const Elt& two() const { return k_[2]; }\n const Elt& half() const { return khalf_; }\n const Elt& mone() const { return kmone_; }\n const Elt& i() const { return i_; }\n Elt poly_evaluation_point(size_t i) const {\n return of_scalar(f_.poly_evaluation_point(i));\n }\n Elt newton_denominator(size_t k, size_t i) const {\n return of_scalar(f_.newton_denominator(k, i));\n }\n\n private:\n Scalar nonresidue_;\n Elt k_[3]; // small constants\n Elt i_; // i^2 = -1\n Elt khalf_;\n Elt kmone_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP2_H_\n"], ["/longfellow-zk/lib/ligero/ligero_prover.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_PROVER_H_\n#define PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_PROVER_H_\n\n#include \n\n#include \n#include \n#include \n\n#include \"algebra/blas.h\"\n#include \"ligero/ligero_param.h\"\n#include \"ligero/ligero_transcript.h\"\n#include \"merkle/merkle_commitment.h\"\n#include \"random/random.h\"\n#include \"random/transcript.h\"\n#include \"util/crypto.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\ntemplate \nclass LigeroProver {\n using Elt = typename Field::Elt;\n\n public:\n explicit LigeroProver(const LigeroParam &p)\n : p_(p), mc_(p.block_enc - p.dblock), tableau_(p.nrow * p.block_enc) {}\n\n // The SUBFIELD_BOUNDARY parameter is kind of a hack.\n //\n // Most, but not all, witnesses in W[] are known statically to be in\n // the subfield of Field, for example because they are bits or\n // bit-plucked values in the subfield. For zero-knowledge, for\n // these witnesses, it suffices to choose blinding randomness in the\n // subfield, which yields a shorter proof since most column openings\n // are fully in the subfield. The problem is now to distinguish\n // subfield witnesses from field witnesses.\n //\n // In the fullness of time we should have a compiler with typing\n // information (field vs subfield) of all input wires. For now\n // we implement the following hack: W[i] is in the subfield for\n // i < SUBFIELD_BOUNDARY, and in the full field otherwise.\n // If you don't know better, set SUBFIELD_BOUNDARY = 0 which\n // trivially works for any input.\n void commit(LigeroCommitment &commitment, Transcript &ts,\n const Elt W[/*p_.nw*/], const size_t subfield_boundary,\n const LigeroQuadraticConstraint lqc[/*nq*/],\n const InterpolatorFactory &interpolator, RandomEngine &rng,\n const Field &F) {\n // Paranoid check on the SUBFIELD_BOUNDARY correctness condition\n for (size_t i = 0; i < subfield_boundary; ++i) {\n check(F.in_subfield(W[i]), \"element not in subfield\");\n }\n\n layout(W, subfield_boundary, lqc, interpolator, rng, F);\n\n // Merkle commitment\n auto updhash = [&](size_t j, SHA256 &sha) {\n LigeroCommon::column_hash(p_.nrow, &tableau_at(0, j + p_.dblock),\n p_.block_enc, sha, F);\n };\n commitment.root = mc_.commit(updhash, rng);\n\n // P -> V\n LigeroTranscript::write_commitment(commitment, ts);\n }\n\n // HASH_OF_LLTERM is a hash of LLTERM provided by the caller. We\n // could compute the hash locally, but usually LLTERM has a special\n // structure that makes the computation faster on the caller's side.\n void prove(LigeroProof &proof, Transcript &ts, size_t nl,\n size_t nllterm,\n const LigeroLinearConstraint llterm[/*nllterm*/],\n const LigeroHash &hash_of_llterm,\n const LigeroQuadraticConstraint lqc[/*nq*/],\n const InterpolatorFactory &interpolator, const Field &F) {\n {\n // P -> V\n // theorem statement\n ts.write(hash_of_llterm.bytes, hash_of_llterm.kLength);\n }\n\n {\n std::vector u_ldt(p_.nwqrow);\n\n // V -> P\n LigeroTranscript::gen_uldt(&u_ldt[0], p_, ts, F);\n low_degree_proof(&proof.y_ldt[0], &u_ldt[0], F);\n }\n\n {\n std::vector alphal(nl);\n std::vector> alphaq(p_.nq);\n std::vector A(p_.nwqrow * p_.w);\n\n // V -> P\n LigeroTranscript::gen_alphal(nl, &alphal[0], ts, F);\n LigeroTranscript::gen_alphaq(&alphaq[0], p_, ts, F);\n\n LigeroCommon::inner_product_vector(&A[0], p_, nl, nllterm, llterm,\n &alphal[0], lqc, &alphaq[0], F);\n\n dot_proof(&proof.y_dot[0], &A[0], interpolator, F);\n }\n\n {\n std::vector u_quad(p_.nqtriples);\n\n // V -> P\n LigeroTranscript::gen_uquad(&u_quad[0], p_, ts, F);\n quadratic_proof(&proof.y_quad_0[0], &proof.y_quad_2[0], &u_quad[0], F);\n }\n\n {\n // P -> V\n ts.write(&proof.y_ldt[0], 1, p_.block, F);\n ts.write(&proof.y_dot[0], 1, p_.dblock, F);\n ts.write(&proof.y_quad_0[0], 1, p_.r, F);\n ts.write(&proof.y_quad_2[0], 1, p_.dblock - p_.block, F);\n }\n\n {\n std::vector idx(p_.nreq);\n // V -> P\n LigeroTranscript::gen_idx(&idx[0], p_, ts, F);\n\n compute_req(proof, &idx[0]);\n\n mc_.open(proof.merkle, &idx[0], p_.nreq);\n }\n }\n\n private:\n Elt &tableau_at(size_t i, size_t j) {\n size_t ld = p_.block_enc;\n return tableau_[i * ld + j];\n }\n\n // fill t_[i, [0,n)] with random elements\n // If the base_only flag is true, then the random element is chosen from\n // the base field if F is a field extension.\n void random_row(size_t i, size_t n, RandomEngine &rng, const Field &F) {\n for (size_t j = 0; j < n; ++j) {\n tableau_at(i, j) = rng.elt(F);\n }\n }\n\n void random_subfield_row(size_t i, size_t n, RandomEngine &rng,\n const Field &F) {\n for (size_t j = 0; j < n; ++j) {\n tableau_at(i, j) = rng.subfield_elt(F);\n }\n }\n\n // generate the ILDT and IDOT blinding rows\n void layout_blinding_rows(const InterpolatorFactory &interpolator,\n RandomEngine &rng, const Field &F) {\n {\n // blinds of size [BLOCK]\n const auto interp = interpolator.make(p_.block, p_.block_enc);\n\n // low-degree blinding row\n random_row(p_.ildt, p_.block, rng, F);\n interp->interpolate(&tableau_at(p_.ildt, 0));\n }\n\n {\n // blinds of size [DBLOCK]\n const auto interp = interpolator.make(p_.dblock, p_.block_enc);\n\n // dot-product blinding row constrained to SUM(W) = 0. First\n // randomize the dblock:\n random_row(p_.idot, p_.dblock, rng, F);\n\n // Then constrain to sum(W) = 0\n Elt sum = Blas::dot1(p_.w, &tableau_at(p_.idot, p_.r), 1, F);\n F.sub(tableau_at(p_.idot, p_.r), sum);\n\n interp->interpolate(&tableau_at(p_.idot, 0));\n\n // quadratic-test blinding row constrained to W = 0. First\n // randomize the entire dblock:\n random_row(p_.iquad, p_.dblock, rng, F);\n\n // Then constrain to W = 0\n Blas::clear(p_.w, &tableau_at(p_.iquad, p_.r), 1, F);\n\n interp->interpolate(&tableau_at(p_.iquad, 0));\n }\n }\n\n void layout_witness_rows(const Elt W[/*nw*/], size_t subfield_boundary,\n const InterpolatorFactory &interpolator,\n RandomEngine &rng, const Field &F) {\n const auto interp = interpolator.make(p_.block, p_.block_enc);\n\n // witness row EXTEND([RANDOM[R], WITNESS[W]], BLOCK)\n for (size_t i = 0; i < p_.nwrow; ++i) {\n // TRUE if the entire row is in the subfield\n bool subfield_only = ((i + 1) * p_.w <= subfield_boundary);\n\n if (subfield_only) {\n random_subfield_row(i + p_.iw, p_.r, rng, F);\n } else {\n random_row(i + p_.iw, p_.r, rng, F);\n }\n\n // Set the WITNESS columns to zero first, and then\n // overwrite with the witnesses that actually exist\n Blas::clear(p_.w, &tableau_at(i + p_.iw, p_.r), 1, F);\n size_t max_col = std::min(p_.w, p_.nw - i * p_.w);\n Blas::copy(max_col, &tableau_at(i + p_.iw, p_.r), 1, &W[i * p_.w],\n 1);\n interp->interpolate(&tableau_at(i + p_.iw, 0));\n }\n }\n\n void layout_quadratic_rows(const Elt W[/*nw*/],\n const LigeroQuadraticConstraint lqc[/*nq*/],\n const InterpolatorFactory &interpolator,\n RandomEngine &rng, const Field &F) {\n const auto interp = interpolator.make(p_.block, p_.block_enc);\n\n // copy the multiplicand witnesses into the quadratic rows\n size_t iqx = p_.iq;\n size_t iqy = iqx + p_.nqtriples;\n size_t iqz = iqy + p_.nqtriples;\n\n for (size_t i = 0; i < p_.nqtriples; ++i) {\n random_row(iqx + i, p_.r, rng, F);\n random_row(iqy + i, p_.r, rng, F);\n random_row(iqz + i, p_.r, rng, F);\n\n // clear everything first, then overwrite the witnesses that\n // actually exist\n Blas::clear(p_.w, &tableau_at(iqx + i, p_.r), 1, F);\n Blas::clear(p_.w, &tableau_at(iqy + i, p_.r), 1, F);\n Blas::clear(p_.w, &tableau_at(iqz + i, p_.r), 1, F);\n\n for (size_t j = 0; j < p_.w && j + i * p_.w < p_.nq; ++j) {\n const auto *l = &lqc[j + i * p_.w];\n check(W[l->z] == F.mulf(W[l->x], W[l->y]),\n \"invalid quadratic constraints\");\n tableau_at(iqx + i, j + p_.r) = W[l->x];\n tableau_at(iqy + i, j + p_.r) = W[l->y];\n tableau_at(iqz + i, j + p_.r) = W[l->z];\n }\n interp->interpolate(&tableau_at(iqx + i, 0));\n interp->interpolate(&tableau_at(iqy + i, 0));\n interp->interpolate(&tableau_at(iqz + i, 0));\n }\n }\n\n void layout(const Elt W[/*nw*/], size_t subfield_boundary,\n const LigeroQuadraticConstraint lqc[/*nq*/],\n const InterpolatorFactory &interpolator, RandomEngine &rng,\n const Field &F) {\n layout_blinding_rows(interpolator, rng, F);\n layout_witness_rows(W, subfield_boundary, interpolator, rng, F);\n layout_quadratic_rows(W, lqc, interpolator, rng, F);\n }\n\n void low_degree_proof(Elt y[/*block*/], const Elt u_ldt[/*nwqrow*/],\n const Field &F) {\n // ILDT blinding row with coefficient 1\n Blas::copy(p_.block, y, 1, &tableau_at(p_.ildt, 0), 1);\n\n // all witness and quadratic rows with coefficient u_ldt[]\n for (size_t i = 0; i < p_.nwqrow; ++i) {\n Blas::axpy(p_.block, y, 1, u_ldt[i], &tableau_at(i + p_.iw, 0), 1,\n F);\n }\n }\n\n void dot_proof(Elt y[/*dblock*/], const Elt A[/*nwqrow, w*/],\n const InterpolatorFactory &interpolator, const Field &F) {\n const auto interpA = interpolator.make(p_.block, p_.dblock);\n\n // IDOT blinding row with coefficient 1\n Blas::copy(p_.dblock, y, 1, &tableau_at(p_.idot, 0), 1);\n\n std::vector Aext(p_.dblock);\n for (size_t i = 0; i < p_.nwqrow; ++i) {\n LigeroCommon::layout_Aext(&Aext[0], p_, i, &A[0], F);\n interpA->interpolate(&Aext[0]);\n\n // Accumulate y += A \\otimes W.\n Blas::vaxpy(p_.dblock, &y[0], 1, &Aext[0], 1,\n &tableau_at(i + p_.iw, 0), 1, F);\n }\n }\n\n void quadratic_proof(Elt y0[/*r*/], Elt y2[/*dblock - block*/],\n const Elt u_quad[/*nqtriples*/], const Field &F) {\n std::vector y(p_.dblock);\n std::vector tmp(p_.dblock);\n\n // IQUAD blinding row with coefficient 1\n Blas::copy(p_.dblock, &y[0], 1, &tableau_at(p_.iquad, 0), 1);\n\n size_t iqx = p_.iq;\n size_t iqy = iqx + p_.nqtriples;\n size_t iqz = iqy + p_.nqtriples;\n\n for (size_t i = 0; i < p_.nqtriples; ++i) {\n // y += u_quad[i] * (z[i] - x[i] * y[i])\n\n // tmp = z[i]\n Blas::copy(p_.dblock, &tmp[0], 1, &tableau_at(iqz + i, 0), 1);\n\n // tmp -= x[i] \\otimes y[i]\n Blas::vymax(p_.dblock, &tmp[0], 1, &tableau_at(iqx + i, 0), 1,\n &tableau_at(iqy + i, 0), 1, F);\n\n // y += u_quad[i] * tmp\n Blas::axpy(p_.dblock, &y[0], 1, u_quad[i], &tmp[0], 1, F);\n }\n\n // sanity check: the W part of Y is zero\n bool ok = Blas::equal0(p_.w, &y[p_.r], 1, F);\n check(ok, \"W part is nonzero\");\n\n // extract the first and last parts\n Blas::copy(p_.r, y0, 1, &y[0], 1);\n Blas::copy(p_.dblock - p_.block, y2, 1, &y[p_.block], 1);\n }\n\n void compute_req(LigeroProof &proof, const size_t idx[/*nreq*/]) {\n for (size_t i = 0; i < p_.nrow; ++i) {\n Blas::gather(p_.nreq, &proof.req_at(i, 0),\n &tableau_at(i, p_.dblock), idx);\n }\n }\n\n const LigeroParam p_; /* safer to make copy */\n MerkleCommitment mc_;\n std::vector tableau_ /*[nrow, block_enc]*/;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_PROVER_H_\n"], ["/longfellow-zk/lib/algebra/convolution.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_CONVOLUTION_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_CONVOLUTION_H_\n\n#include \n\n#include \n#include \n#include \n\n#include \"algebra/blas.h\"\n#include \"algebra/fft.h\"\n#include \"algebra/rfft.h\"\n\n/*\nAll of the classes in this package compute convolutions.\nThat is, given inputs arrays of field elements x, y, with |x|=n, |y|=m,\nthese methods compute the first m entries of\n\n z[k] = \\sum_{i=0}^{n-1} x[i] y[k-i]\n\nSlowConvolution uses an O(n*m) method for testing validation.\n\nFFTConvolution and FFTExtConvolution first pad y to length n and use advanced\nFFT algorithms to compute the same in O(nlogn) time.\n\nThe const Field& objects that are passed have lifetimes that exceed the call\ndurations and can be safely passed by const reference.\n*/\n\nnamespace proofs {\n\n// Returns the smallest power of 2 that is at least n.\nstatic size_t choose_padding(const size_t n) {\n size_t p = 1;\n while (p < n) {\n p *= 2;\n }\n return p;\n}\n\ntemplate \nclass FFTConvolution {\n using Elt = typename Field::Elt;\n\n public:\n FFTConvolution(size_t n, size_t m, const Field& f, const Elt omega,\n uint64_t omega_order, const Elt y[/*m*/])\n : f_(f),\n omega_(omega),\n omega_order_(omega_order),\n n_(n),\n m_(m),\n padding_(choose_padding(m)),\n y_fft_(padding_, f_.zero()) {\n Blas::copy(m, &y_fft_[0], 1, y, 1);\n FFT::fftf(&y_fft_[0], padding_, omega_, omega_order_, f_);\n\n // Pre-scale Y by 1/N to compensate for the scaling in FFTB(FFTF(.))\n Blas::scale(padding_, &y_fft_[0], 1,\n f_.invertf(f_.of_scalar(padding_)), f_);\n }\n\n // Computes (first m entries of) convolution of x with y, outputs in z:\n // z[k] = \\sum_{i=0}^{n-1} x[i] y[k-i].\n // Note that y has already been FFT'd and divided by padding_ in constructor\n void convolution(const Elt x[/*n_*/], Elt z[/*m_*/]) const {\n std::vector x_fft(padding_, f_.zero());\n Blas::copy(n_, &x_fft[0], 1, x, 1);\n FFT::fftf(&x_fft[0], padding_, omega_, omega_order_, f_);\n // Pointwise multiplication.\n for (size_t i = 0; i < padding_; ++i) {\n f_.mul(x_fft[i], y_fft_[i]);\n }\n // Backward fft.\n FFT::fftb(&x_fft[0], padding_, omega_, omega_order_, f_);\n Blas::copy(m_, z, 1, &x_fft[0], 1);\n }\n\n private:\n const Field& f_;\n const Elt omega_;\n const uint64_t omega_order_;\n\n // n is the number of points input\n size_t n_;\n size_t m_; // total number of points output (points in + new points out)\n size_t padding_;\n\n // fft(y[i]) / padding\n // padded with zeroes to the next power of 2 at least m.\n std::vector y_fft_;\n};\n\ntemplate \nclass FFTConvolutionFactory {\n using Elt = typename Field::Elt;\n\n public:\n using Convolver = FFTConvolution;\n FFTConvolutionFactory(const Field& f, const Elt omega, uint64_t omega_order)\n : f_(f), omega_(omega), omega_order_(omega_order) {}\n\n std::unique_ptr make(size_t n, size_t m,\n const Elt y[/*m*/]) const {\n return std::make_unique(n, m, f_, omega_, omega_order_, y);\n }\n\n private:\n const Field& f_;\n const Elt omega_;\n const uint64_t omega_order_;\n};\n\ntemplate \nclass FFTExtConvolution {\n using Elt = typename Field::Elt;\n using EltExt = typename FieldExt::Elt;\n\n public:\n FFTExtConvolution(size_t n, size_t m, const Field& f, const FieldExt& f_ext,\n const EltExt omega, uint64_t omega_order,\n const Elt y[/*m*/])\n : f_(f),\n f_ext_(f_ext),\n omega_(omega),\n omega_order_(omega_order),\n n_(n),\n m_(m),\n padding_(choose_padding(m)),\n y_fft_(padding_, f_.zero()) {\n Blas::copy(m, &y_fft_[0], 1, y, 1);\n RFFT::r2hc(&y_fft_[0], padding_, omega_, omega_order_, f_ext_);\n\n // Pre-scale Y by 1/N to compensate for the scaling in HC2R(R2HC(.))\n Blas::scale(padding_, &y_fft_[0], 1,\n f_.invertf(f_.of_scalar(padding_)), f_);\n }\n\n // Computes (first m entries of) convolution of x with y, stores in z:\n // z[k] = \\sum_{i=0}^{n-1} x[i] y[k-i].\n // Note that y has already been FFT'd and divided by padding_ in constructor\n void convolution(const Elt x[/*n_*/], Elt z[/*m_*/]) const {\n std::vector x_fft(padding_, f_.zero());\n Blas::copy(n_, &x_fft[0], 1, x, 1);\n RFFT::r2hc(&x_fft[0], padding_, omega_, omega_order_, f_ext_);\n\n // Pointwise multiplication\n {\n size_t i;\n f_.mul(x_fft[0], y_fft_[0]); // DC is real\n for (i = 1; i + i < padding_; ++i) {\n RFFT::cmul(&x_fft[i], &x_fft[padding_ - i], x_fft[i],\n x_fft[padding_ - i], y_fft_[i],\n y_fft_[padding_ - i], f_);\n }\n f_.mul(x_fft[i], y_fft_[i]); // Nyquist is real\n }\n\n // Backward FFT.\n RFFT::hc2r(&x_fft[0], padding_, omega_, omega_order_, f_ext_);\n Blas::copy(m_, z, 1, &x_fft[0], 1);\n }\n\n private:\n const Field& f_;\n const FieldExt& f_ext_;\n const EltExt omega_;\n const uint64_t omega_order_;\n\n // n is the number of points input in x\n size_t n_;\n size_t m_; // total number of points output in convolution\n size_t padding_;\n\n // fft(y[i]) / padding\n // padded with zeroes to the next power of 2 at least m.\n std::vector y_fft_;\n};\n\ntemplate \nclass FFTExtConvolutionFactory {\n using Elt = typename Field::Elt;\n using EltExt = typename FieldExt::Elt;\n\n public:\n using Convolver = FFTExtConvolution;\n\n FFTExtConvolutionFactory(const Field& f, const FieldExt& f_ext,\n const EltExt omega, uint64_t omega_order)\n : f_(f), f_ext_(f_ext), omega_(omega), omega_order_(omega_order) {}\n\n std::unique_ptr make(size_t n, size_t m,\n const Elt y[/*m*/]) const {\n return std::make_unique(n, m, f_, f_ext_, omega_,\n omega_order_, y);\n }\n\n private:\n const Field& f_;\n const FieldExt& f_ext_;\n const EltExt omega_;\n const uint64_t omega_order_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_CONVOLUTION_H_\n"], ["/longfellow-zk/lib/circuits/cbor_parser/cbor_witness.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_WITNESS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_WITNESS_H_\n\n#include \n#include \n\n#include \n\n#include \"circuits/cbor_parser/cbor_constants.h\"\n#include \"circuits/cbor_parser/cbor_pluck.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\ntemplate \nclass CborWitness {\n public:\n using Elt = typename Field::Elt;\n static constexpr size_t kNCounters = CborConstants::kNCounters;\n static constexpr size_t kIndexBits = CborConstants::kIndexBits;\n using counters = std::array;\n using vindex = std::array;\n\n struct position_witness {\n Elt encoded_sel_header;\n\n // SLEN output value, used for debugging but not fed to the circuit\n size_t slen_next_debug;\n // counter values, used for debugging but not fed to the circuit\n counters cc_debug;\n size_t isel_debug;\n };\n\n struct global_witness {\n Elt invprod_decode;\n Elt cc0; // initial values of counter[0]\n Elt invprod_parse;\n };\n\n using v8 = std::array;\n\n explicit CborWitness(const Field& F) : f_(F) {}\n\n // Return an index as an array of Elt, which can be stored into W[]\n vindex index(size_t j) const {\n const Field& F = f_; // shorthand\n vindex r;\n for (size_t i = 0; i < kIndexBits; ++i) {\n r[i] = F.of_scalar((j >> i) & 1);\n }\n return r;\n }\n\n void fill_witnesses(size_t n, size_t input_len, const uint8_t bytes[/*n*/],\n v8 in[/*n*/], position_witness pw[/*n*/],\n global_witness& gw) const {\n const Field& F = f_; // shorthand\n\n // First pass to compute the number of top-level items. In the\n // second pass, we will use this value to that all counters are 0\n // at the end of the input.\n size_t top_level_items;\n {\n // start with a value of cc[0] guaranteed not to\n // underflow counter 0.\n counters cc{{n + 1}};\n\n size_t slen = 1;\n for (size_t i = 0; i < n; ++i) {\n bool overflow;\n bool header = (slen == 1);\n cc = counters_next(bytes[i], header,\n /*have_nextb=*/(i + 1) < n,\n /*nextb=*/(i + 1) < n ? bytes[i + 1] : 0, cc,\n &overflow);\n proofs::check(!overflow, \"!overflow\");\n slen = next_slen(slen, n, bytes, i);\n }\n\n top_level_items = (n + 1) - cc[0];\n }\n\n // second pass starting with the correct counter values\n {\n counters cc{{top_level_items}};\n Elt prod_parse = F.one();\n Elt prod_decode = F.one();\n\n size_t slen = 1;\n for (size_t i = 0; i < n; ++i) {\n bool overflow;\n bool header = (slen == 1);\n\n // Require all bytes to be 0 except the last N-INPUT_LEN.\n // That is, the input must be aligned towards the end\n // of arrays, and padded with zeroes at the beginning.\n proofs::check(input_len <= n, \"input_len <= n\");\n if (i + input_len < n) {\n proofs::check(bytes[i] == 0, \"bytes[i] == 0\");\n }\n\n // set up input\n for (size_t j = 0; j < 8; ++j) {\n in[i][j] = F.of_scalar((bytes[i] >> j) & 1);\n }\n\n if (!header) {\n F.mul(prod_decode, F.of_scalar(slen - 1));\n }\n\n // set up parse witness\n size_t isel = kNCounters;\n for (size_t l = kNCounters; l-- > 0;) {\n if (cc[l] != 0) {\n if (i > 0) {\n F.mul(prod_parse, F.of_scalar(cc[l]));\n }\n isel = l;\n break;\n }\n }\n\n cc = counters_next(bytes[i], header,\n /*have_nextb=*/(i + 1) < n,\n /*nextb=*/(i + 1) < n ? bytes[i + 1] : 0, cc,\n &overflow);\n proofs::check(!overflow, \"!overflow\");\n if (i == 0) {\n gw.cc0 = F.of_scalar(cc[0]);\n }\n pw[i].cc_debug = cc;\n\n // set up decode witness\n size_t slen_next = next_slen(slen, n, bytes, i);\n pw[i].slen_next_debug = slen_next;\n\n // encode witnesses\n pw[i].encoded_sel_header =\n cbor_plucker_point()(header, isel, F);\n pw[i].isel_debug = isel;\n\n // advance slen\n slen = slen_next;\n }\n\n gw.invprod_decode = F.invertf(prod_decode);\n gw.invprod_parse = F.invertf(prod_parse);\n }\n }\n\n private:\n static size_t next_slen(size_t slen, size_t n, const uint8_t bytes[/*n*/],\n size_t i) {\n size_t slenm1 = slen - 1;\n bool header = (slenm1 == 0);\n if (header) {\n if (i + 1 < n) {\n return item_length(bytes[i], true, bytes[i + 1]);\n } else {\n return item_length(bytes[i], false, 0);\n }\n } else {\n return slenm1;\n }\n }\n\n // TODO [matteof 2023-11-03] Should not panic() here.\n static size_t item_length(uint8_t b, bool valid_nextb, uint8_t nextb) {\n size_t type = (b >> 5) & 0x7u;\n size_t count = b & 0x1Fu;\n bool count0_23 = (count < 24);\n bool count24 = (count == 24);\n\n switch (type) {\n case 0: /* unsigned */\n case 1: /* negative integer */\n case 4: /* array */\n case 5: /* map */\n case 6: /* tag */\n if (count0_23) {\n return 1;\n } else if (count24) {\n return 2;\n } else {\n check(false, \"unwitnessed count (atom)\");\n return 0;\n }\n\n case 2: /* bytes */\n case 3: /* text */\n if (count0_23) {\n return 1 + count;\n } else if (count24) {\n if (valid_nextb) {\n return 2 + nextb;\n } else {\n check(false, \"invalid nextb\");\n return 0;\n }\n } else {\n check(false, \"unwitnessed count (bytes)\");\n return 0;\n }\n\n case 7: /* special */\n check(false, \"unwitnessed special\");\n return 0;\n\n default:\n check(false, \"can't happen\");\n return 0;\n }\n }\n\n static size_t decode_count(size_t count_in_header, bool have_nextb,\n uint8_t nextb) {\n if (count_in_header < 24) {\n return count_in_header;\n } else if (count_in_header == 24) {\n if (have_nextb) {\n return nextb;\n } else {\n check(false, \"!have_nextb\");\n }\n } else {\n check(false, \"count > 24\");\n }\n return 0xdeadbeef;\n }\n\n static counters counters_next(uint8_t b, bool header, bool have_nextb,\n uint8_t nextb, const counters& c,\n bool* overflow) {\n size_t type = (b >> 5) & 0x7u;\n size_t count_in_header = b & 0x1Fu;\n bool tagp = (type == 6);\n bool arrayp = (type == 4);\n bool mapp = (type == 5);\n\n counters c1 = c;\n *overflow = false;\n\n for (size_t l = kNCounters; l-- > 0;) {\n if (c[l] != 0) {\n if (header) {\n c1[l] = c[l] - 1;\n\n if (tagp) {\n if (l + 1 < kNCounters) {\n c1[l + 1] = 1;\n } else {\n *overflow = true;\n }\n } else if (arrayp) {\n if (l + 1 < kNCounters) {\n c1[l + 1] = decode_count(count_in_header, have_nextb, nextb);\n } else {\n *overflow = true;\n }\n } else if (mapp) {\n if (l + 1 < kNCounters) {\n c1[l + 1] = 2 * decode_count(count_in_header, have_nextb, nextb);\n } else {\n *overflow = true;\n }\n }\n }\n break;\n }\n }\n\n return c1;\n }\n\n private:\n const Field& f_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_WITNESS_H_\n"], ["/longfellow-zk/lib/random/transcript.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_RANDOM_TRANSCRIPT_H_\n#define PRIVACY_PROOFS_ZK_LIB_RANDOM_TRANSCRIPT_H_\n\n#include \n#include \n#include \n#include \n\n#include \"random/random.h\"\n#include \"util/crypto.h\"\n#include \"util/panic.h\"\n#include \"util/serialization.h\"\n\nnamespace proofs {\n\n/*\nFSPRF and Transcript together used implement the Fiat-Shamir transform.\n*/\nclass FSPRF {\n public:\n explicit FSPRF(const uint8_t key[kPRFKeySize])\n : prf_(key), nblock_(0), rdptr_(kPRFOutputSize) {}\n\n // Disable copy for good measure.\n explicit FSPRF(const FSPRF&) = delete;\n FSPRF& operator=(const FSPRF&) = delete;\n\n void bytes(uint8_t buf[/*n*/], size_t n) {\n while (n-- > 0) {\n if (rdptr_ == kPRFOutputSize) {\n refill();\n }\n *buf++ = saved_[rdptr_++];\n }\n }\n\n private:\n void refill() {\n uint8_t in[kPRFInputSize] = {};\n u64_to_le(in, nblock_++);\n prf_.Eval(saved_, in);\n rdptr_ = 0;\n }\n\n PRF prf_;\n uint64_t nblock_;\n size_t rdptr_; // read pointer into saved[]\n uint8_t saved_[kPRFOutputSize]; // saved pseudo-random bytes\n};\n\nclass Transcript : public RandomEngine {\n enum { TAG_BSTR = 0, TAG_FIELD_ELEM = 1, TAG_ARRAY = 1 };\n\n public:\n // A transcript must be explicitly initialized so that each instance of\n // the Random oracle is unique.\n Transcript(const uint8_t init[], size_t init_len) : sha_(), prf_() {\n write(init, init_len);\n }\n\n // Remove default copy and move implementations.\n Transcript(const Transcript&) = delete;\n Transcript& operator=(const Transcript&) = delete;\n\n // Explicit copy to avoid accidental passing by value.\n Transcript clone() { return Transcript(sha_); }\n\n // Generate bytes by via the current FSPRF object.\n void bytes(uint8_t buf[/*n*/], size_t n) override {\n if (!prf_) {\n uint8_t key[kPRFKeySize];\n get(key);\n prf_ = std::make_unique(key);\n }\n prf_->bytes(buf, n);\n }\n\n // snapshot the hash of the transcript so far\n void get(uint8_t key[/*kPRFKeySize*/]) {\n check(kPRFKeySize == kSHA256DigestSize, \"prf key size != digest output\");\n // fork the state because we will finalize it\n SHA256 tmp_hash;\n tmp_hash.CopyState(sha_);\n tmp_hash.DigestData(key);\n }\n\n // Typed write operations. We tag byte-array(n), field-element, and\n // array-of-field-element(n).\n //\n // We make a few arbitrary choices that make no real difference.\n // All lengths are 64-bit. We distinguish a field element from\n // an array of one field element, which is kind of arbitrary.\n\n // byte string\n void write(const uint8_t data[/*n*/], size_t n) {\n tag(TAG_BSTR);\n length(n);\n\n write_untyped(data, n);\n }\n\n // N zero bytes\n void write0(size_t n) {\n tag(TAG_BSTR);\n length(n);\n\n uint8_t data[32] = {};\n for (; n > 32; n -= 32) {\n write_untyped(data, 32);\n }\n write_untyped(data, n);\n }\n\n // one field element\n template \n void write(const typename Field::Elt& e, const Field& F) {\n tag(TAG_FIELD_ELEM);\n\n write_untyped(e, F);\n }\n\n // array of field elements\n template \n void write(const typename Field::Elt e[/*n*/], size_t ince, size_t n,\n const Field& F) {\n tag(TAG_ARRAY);\n length(n);\n\n for (size_t i = 0; i < n; ++i) {\n write_untyped(e[i * ince], F);\n }\n }\n\n private:\n explicit Transcript(const SHA256& sha) : sha_() {\n sha_.CopyState(sha);\n }\n\n // Output a 1-byte tag\n void tag(size_t t) {\n uint8_t d = static_cast(t);\n write_untyped(&d, 1);\n }\n\n // Output a 8-byte length. We pass the length\n // as size_t, but we always write it as uint64_t\n void length(size_t x) {\n uint8_t a[8];\n u64_to_le(a, x);\n write_untyped(a, 8);\n }\n\n void write_untyped(const uint8_t data[/*n*/], size_t n) {\n // invalidate the PRF on any writes\n prf_.reset();\n sha_.Update(data, n);\n }\n\n template \n void write_untyped(const typename Field::Elt& e, const Field& F) {\n uint8_t buf[Field::kBytes];\n F.to_bytes_field(buf, e);\n write_untyped(buf, sizeof(buf));\n }\n\n SHA256 sha_;\n std::unique_ptr prf_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_RANDOM_TRANSCRIPT_H_\n"], ["/longfellow-zk/lib/algebra/sysdep.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_SYSDEP_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_SYSDEP_H_\n\n#include \n\n#include \n\n#include \"util/panic.h\" // IWYU pragma: keep\n\n#if defined(__x86_64__) || defined(__i386__)\n// system-dependent basic arithmetic functions: add with carry\n// and 64x64->128 bit multiplication\n#include // IWYU pragma: keep\n#endif\n\nnamespace proofs {\n\n#if defined(__x86_64__)\nstatic inline uint64_t adc(uint64_t* a, uint64_t b, uint64_t c) {\n // unsigned long long (not uint64_t) is *required* by the\n // _addcarry_u64() prototype. uint64_t is unsigned long on\n // linux, and pointers to the two types are incompatible even\n // though the conversion is a no-op.\n unsigned long long out;\n c = _addcarry_u64(c, *a, b, &out);\n *a = out;\n return c;\n}\nstatic inline uint32_t adc(uint32_t* a, uint32_t b, uint32_t c) {\n return _addcarry_u32(c, *a, b, a);\n}\nstatic inline uint64_t sbb(uint64_t* a, uint64_t b, uint64_t c) {\n unsigned long long out;\n c = _subborrow_u64(c, *a, b, &out);\n *a = out;\n return c;\n}\nstatic inline uint32_t sbb(uint32_t* a, uint32_t b, uint32_t c) {\n return _subborrow_u32(c, *a, b, a);\n}\nstatic inline void mulq(uint64_t* l, uint64_t* h, uint64_t a, uint64_t b) {\n asm(\"mulx %2, %0, %1\" : \"=r\"(*l), \"=r\"(*h) : \"r\"(b), \"d\"(a));\n}\n#elif defined(__i386__)\nstatic inline uint32_t adc(uint32_t* a, uint32_t b, uint32_t c) {\n return _addcarry_u32(c, *a, b, a);\n}\nstatic inline uint32_t sbb(uint32_t* a, uint32_t b, uint32_t c) {\n return _subborrow_u32(c, *a, b, a);\n}\n\n// these two functions are supposed to be defined but are\n// never called\nstatic inline unsigned long long adc(unsigned long long* a,\n unsigned long long b,\n unsigned long long c) {\n check(false, \"adcll() not defined\");\n return 0;\n}\nstatic inline unsigned long long sbb(unsigned long long* a,\n unsigned long long b,\n unsigned long long c) {\n check(false, \"sbbll() not defined\");\n return 0;\n}\n\n#define SYSDEP_MULQ64_NOT_DEFINED\n#elif defined(__clang__)\n// The clang intrinsics use the builtin-types int, long, etc.\n// Thus we define adc() and sbb() in terms of those types.\nstatic inline unsigned long long adc(unsigned long long* a,\n unsigned long long b,\n unsigned long long c) {\n *a = __builtin_addcll(*a, b, c, &c);\n return c;\n}\nstatic inline unsigned long adc(unsigned long* a, unsigned long b,\n unsigned long c) {\n *a = __builtin_addcl(*a, b, c, &c);\n return c;\n}\nstatic inline unsigned int adc(unsigned int* a, unsigned int b,\n unsigned int c) {\n *a = __builtin_addc(*a, b, c, &c);\n return c;\n}\n\nstatic inline unsigned long long sbb(unsigned long long* a,\n unsigned long long b,\n unsigned long long c) {\n *a = __builtin_subcll(*a, b, c, &c);\n return c;\n}\nstatic inline unsigned long sbb(unsigned long* a, unsigned long b,\n unsigned long c) {\n *a = __builtin_subcl(*a, b, c, &c);\n return c;\n}\nstatic inline unsigned int sbb(unsigned int* a, unsigned int b,\n unsigned int c) {\n *a = __builtin_subc(*a, b, c, &c);\n return c;\n}\n\n#if defined(__SIZEOF_INT128__)\n// It seems that __SIZEOF_INT128__ is defined if __uint128_t is.\nstatic inline void mulq(uint64_t* l, uint64_t* h, uint64_t a, uint64_t b) {\n __uint128_t p = (__uint128_t)b * (__uint128_t)a;\n *l = p;\n *h = p >> 64;\n}\n#else // defined(__SIZEOF_INT128__)\n#define SYSDEP_MULQ64_NOT_DEFINED\n#endif // defined(__SIZEOF_INT128__)\n#endif\n\nstatic inline void mulq(uint32_t* l, uint32_t* h, uint32_t a, uint32_t b) {\n uint64_t p = (uint64_t)b * (uint64_t)a;\n *l = p;\n *h = p >> 32;\n}\n\n// Identity function whose only purpose is to confuse the compiler.\n// We have no coherent theory of when and why this is useful, but\n// here are a couple of cases where this hack makes a difference:\n//\n// * Passing the cmov() values through identity_limb() seems\n// to favor the generation of a conditional move instruction\n// as opposed to a conditional branch.\n// * Clang and gcc match a+b+carry to generate the adcq instruction,\n// but a+0+carry becomes a+carry and the match fails. So\n// we pretend that the zero is not a zero.\n// * A similar issue arises in subtract with carry.\n//\n// This function is obviously a hack. Works for me today but YMMV.\n//\ntemplate \nstatic inline limb_t identity_limb(limb_t v) {\n asm(\"\" : \"+r\"(v)::);\n return v;\n}\n\ntemplate \nstatic inline limb_t zero_limb() {\n return identity_limb(0);\n}\n\n// a += b\ntemplate \nstatic inline void accum(size_t Wa, limb_t a[/*Wa*/], size_t Wb,\n const limb_t b[/*Wb*/]) {\n limb_t c = 0;\n for (size_t i = 0; i < Wb; ++i) {\n c = adc(&a[i], b[i], c);\n }\n for (size_t i = Wb; i < Wa; ++i) {\n c = adc(&a[i], 0, c);\n }\n}\n\n// a -= b\ntemplate \nstatic inline void negaccum(size_t Wa, limb_t a[/*Wa*/], size_t Wb,\n const limb_t b[/*Wb*/]) {\n limb_t c = 0;\n for (size_t i = 0; i < Wb; ++i) {\n c = sbb(&a[i], b[i], c);\n }\n for (size_t i = Wb; i < Wa; ++i) {\n c = sbb(&a[i], 0, c);\n }\n}\n\n// h::a += b\ntemplate \nstatic inline limb_t add_limb(size_t W, limb_t a[/*W*/],\n const limb_t b[/*W*/]) {\n limb_t c = 0;\n for (size_t i = 0; i < W; ++i) {\n c = adc(&a[i], b[i], c);\n }\n limb_t h = zero_limb();\n c = adc(&h, 0, c);\n return h;\n}\n\n// h::a += b * 2^(bits per limb)\ntemplate \nstatic inline limb_t addh(size_t W, limb_t a[/*W*/], const limb_t b[/*W*/]) {\n limb_t c = 0;\n for (size_t i = 1; i < W; ++i) {\n c = adc(&a[i], b[i - 1], c);\n }\n limb_t h = zero_limb();\n c = adc(&h, b[W - 1], c);\n return h;\n}\n\n// h::a -= b\ntemplate \nstatic inline limb_t sub_limb(size_t W, limb_t a[/*W*/],\n const limb_t b[/*W*/]) {\n limb_t c = 0;\n for (size_t i = 0; i < W; ++i) {\n c = sbb(&a[i], b[i], c);\n }\n limb_t h = zero_limb();\n c = sbb(&h, 0, c);\n return h;\n}\n\n// h:l = a*b\ntemplate \nstatic inline void mulhl(size_t W, limb_t l[/*W*/], limb_t h[/*W*/], limb_t a,\n const limb_t b[/*W*/]) {\n for (size_t i = 0; i < W; ++i) {\n mulq(&l[i], &h[i], a, b[i]);\n }\n}\n\n// a = b\ntemplate \nstatic inline void mov(size_t W, limb_t a[/*W*/], const limb_t b[/*W*/]) {\n for (size_t i = 0; i < W; ++i) {\n a[i] = b[i];\n }\n}\n\n// It seems that using assembly code is the only way to\n// force gcc and clang to use conditional moves.\n#if defined(__x86_64__)\nstatic inline void cmovnz(size_t W, uint64_t a[/*W*/], uint64_t nz,\n const uint64_t b[/*W*/]) {\n if (W == 1) {\n asm(\"testq %[nz], %[nz]\\n\\t\"\n \"cmovneq %[b0], %[a0]\\n\\t\"\n : [a0] \"+r\"(a[0])\n : [nz] \"r\"(nz), [b0] \"r\"(b[0]));\n } else if (W == 2) {\n asm(\"testq %[nz], %[nz]\\n\\t\"\n \"cmovneq %[b0], %[a0]\\n\\t\"\n \"cmovneq %[b1], %[a1]\\n\\t\"\n : [a0] \"+r\"(a[0]), [a1] \"+r\"(a[1])\n : [nz] \"r\"(nz), [b0] \"r\"(b[0]), [b1] \"r\"(b[1]));\n } else if (W == 3) {\n asm(\"testq %[nz], %[nz]\\n\\t\"\n \"cmovneq %[b0], %[a0]\\n\\t\"\n \"cmovneq %[b1], %[a1]\\n\\t\"\n \"cmovneq %[b2], %[a2]\\n\\t\"\n : [a0] \"+r\"(a[0]), [a1] \"+r\"(a[1]), [a2] \"+r\"(a[2])\n : [nz] \"r\"(nz), [b0] \"r\"(b[0]), [b1] \"r\"(b[1]), [b2] \"r\"(b[2]));\n } else if (W == 4) {\n asm(\"testq %[nz], %[nz]\\n\\t\"\n \"cmovneq %[b0], %[a0]\\n\\t\"\n \"cmovneq %[b1], %[a1]\\n\\t\"\n \"cmovneq %[b2], %[a2]\\n\\t\"\n \"cmovneq %[b3], %[a3]\\n\\t\"\n : [a0] \"+r\"(a[0]), [a1] \"+r\"(a[1]), [a2] \"+r\"(a[2]), [a3] \"+r\"(a[3])\n : [nz] \"r\"(nz), [b0] \"r\"(b[0]), [b1] \"r\"(b[1]), [b2] \"r\"(b[2]),\n [b3] \"r\"(b[3]));\n } else {\n for (size_t i = 0; i < W; ++i) {\n a[i] = (nz != 0) ? b[i] : a[i];\n }\n }\n}\n\nstatic inline void cmovne(size_t W, uint64_t a[/*W*/], uint64_t x, uint64_t y,\n const uint64_t b[/*W*/]) {\n if (W == 1) {\n asm(\"cmpq %[x], %[y]\\n\\t\"\n \"cmovneq %[b0], %[a0]\\n\\t\"\n : [a0] \"+r\"(a[0])\n : [x] \"r\"(x), [y] \"r\"(y), [b0] \"r\"(b[0])\n : \"cc\");\n } else if (W == 2) {\n asm(\"cmpq %[x], %[y]\\n\\t\"\n \"cmovneq %[b0], %[a0]\\n\\t\"\n \"cmovneq %[b1], %[a1]\\n\\t\"\n : [a0] \"+r\"(a[0]), [a1] \"+r\"(a[1])\n : [x] \"r\"(x), [y] \"r\"(y), [b0] \"r\"(b[0]), [b1] \"r\"(b[1])\n : \"cc\");\n } else if (W == 3) {\n asm(\"cmpq %[x], %[y]\\n\\t\"\n \"cmovneq %[b0], %[a0]\\n\\t\"\n \"cmovneq %[b1], %[a1]\\n\\t\"\n \"cmovneq %[b2], %[a2]\\n\\t\"\n : [a0] \"+r\"(a[0]), [a1] \"+r\"(a[1]), [a2] \"+r\"(a[2])\n : [x] \"r\"(x), [y] \"r\"(y), [b0] \"r\"(b[0]), [b1] \"r\"(b[1]), [b2] \"r\"(b[2])\n : \"cc\");\n } else if (W == 4) {\n asm(\"cmpq %[x], %[y]\\n\\t\"\n \"cmovneq %[b0], %[a0]\\n\\t\"\n \"cmovneq %[b1], %[a1]\\n\\t\"\n \"cmovneq %[b2], %[a2]\\n\\t\"\n \"cmovneq %[b3], %[a3]\\n\\t\"\n : [a0] \"+r\"(a[0]), [a1] \"+r\"(a[1]), [a2] \"+r\"(a[2]), [a3] \"+r\"(a[3])\n : [x] \"r\"(x), [y] \"r\"(y), [b0] \"r\"(b[0]), [b1] \"r\"(b[1]),\n [b2] \"r\"(b[2]), [b3] \"r\"(b[3])\n : \"cc\");\n } else {\n for (size_t i = 0; i < W; ++i) {\n a[i] = (x != y) ? b[i] : a[i];\n }\n }\n}\n\nstatic inline uint64_t addcmovc(uint64_t a, uint64_t b, uint64_t c) {\n asm(\"add %[b], %[a]\\n\\t\"\n \"cmovaeq %[c], %[a]\\n\\t\"\n : [a] \"+r\"(a)\n : [b] \"r\"(b), [c] \"r\"(c)\n : \"cc\");\n return a;\n}\n\nstatic inline uint64_t sub_sysdep(uint64_t a, uint64_t y, uint64_t m) {\n uint64_t z = 0;\n asm(\"subq %[y], %[a]\\n\\t\"\n \"cmovbq %[m], %[z]\\n\\t\"\n : [a] \"+r\"(a), [z] \"+r\"(z)\n : [y] \"r\"(y), [m] \"r\"(m)\n : \"cc\");\n return a + z;\n}\n\n#elif defined(__aarch64__)\n\nstatic inline void cmovne(size_t W, uint64_t a[/*W*/], uint64_t x, uint64_t y,\n const uint64_t b[/*W*/]) {\n if (W == 1) {\n asm(\"cmp %[x], %[y]\\n\\t\" //\n \"csel %[a0], %[a0], %[b0], eq\\n\\t\" //\n : [a0] \"+r\"(a[0]) //\n : [x] \"r\"(x), [y] \"ri\"(y), //\n [b0] \"r\"(b[0]) //\n : \"cc\");\n } else if (W == 2) {\n asm(\"cmp %[x], %[y]\\n\\t\" //\n \"csel %[a0], %[a0], %[b0], eq\\n\\t\" //\n \"csel %[a1], %[a1], %[b1], eq\\n\\t\" //\n : [a0] \"+r\"(a[0]), //\n [a1] \"+r\"(a[1]) //\n : [x] \"r\"(x), [y] \"ri\"(y), //\n [b0] \"r\"(b[0]), //\n [b1] \"r\"(b[1]) //\n : \"cc\");\n } else if (W == 3) {\n asm(\"cmp %[x], %[y]\\n\\t\" //\n \"csel %[a0], %[a0], %[b0], eq\\n\\t\" //\n \"csel %[a1], %[a1], %[b1], eq\\n\\t\" //\n \"csel %[a2], %[a2], %[b2], eq\\n\\t\" //\n : [a0] \"+r\"(a[0]), //\n [a1] \"+r\"(a[1]), //\n [a2] \"+r\"(a[2]) //\n : [x] \"r\"(x), [y] \"ri\"(y), //\n [b0] \"r\"(b[0]), //\n [b1] \"r\"(b[1]), //\n [b2] \"r\"(b[2]) //\n : \"cc\");\n } else if (W == 4) {\n asm(\"cmp %[x], %[y]\\n\\t\" //\n \"csel %[a0], %[a0], %[b0], eq\\n\\t\" //\n \"csel %[a1], %[a1], %[b1], eq\\n\\t\" //\n \"csel %[a2], %[a2], %[b2], eq\\n\\t\" //\n \"csel %[a3], %[a3], %[b3], eq\\n\\t\" //\n : [a0] \"+r\"(a[0]), //\n [a1] \"+r\"(a[1]), //\n [a2] \"+r\"(a[2]), //\n [a3] \"+r\"(a[3]) //\n : [x] \"r\"(x), [y] \"ri\"(y), //\n [b0] \"r\"(b[0]), //\n [b1] \"r\"(b[1]), //\n [b2] \"r\"(b[2]), //\n [b3] \"r\"(b[3]) //\n : \"cc\");\n } else {\n for (size_t i = 0; i < W; ++i) {\n a[i] = (x != y) ? b[i] : a[i];\n }\n }\n}\n\n// a = (nz != 0) ? b : a\nstatic inline void cmovnz(size_t W, uint64_t a[/*W*/], uint64_t nz,\n const uint64_t b[/*W*/]) {\n constexpr uint64_t z = 0;\n cmovne(W, a, nz, z, b);\n}\n\nstatic inline uint64_t addcmovc(uint64_t a, uint64_t b, uint64_t c) {\n asm(\"adds %[a], %[a], %[b]\\n\\t\"\n \"csel %[a], %[a], %[c], hs\\n\\t\"\n : [a] \"+r\"(a)\n : [b] \"r\"(b), [c] \"r\"(c)\n : \"cc\");\n return a;\n}\n\nstatic inline uint64_t sub_sysdep(uint64_t a, uint64_t y, uint64_t m) {\n asm(\"subs %[a], %[a], %[y]\\n\\t\"\n \"csel %[m], %[m], xzr, lo\"\n : [a] \"+r\"(a), [m] \"+r\"(m)\n : [y] \"r\"(y)\n : \"cc\");\n return a + m;\n}\n\n#else // generic portable code\n\n// a = (x != y) ? b : a\ntemplate \nstatic inline void cmovne(size_t W, limb_t a[/*W*/], limb_t x, limb_t y,\n const limb_t b[/*W*/]) {\n for (size_t i = 0; i < W; ++i) {\n a[i] = (x != y) ? b[i] : a[i];\n }\n}\n\n// a = (nz != 0) ? b : a\ntemplate \nstatic inline void cmovnz(size_t W, limb_t a[/*W*/], limb_t nz,\n const limb_t b[/*W*/]) {\n constexpr limb_t z = 0;\n cmovne(W, a, nz, z, b);\n}\n\ntemplate \nstatic inline limb_t addcmovc(limb_t a, limb_t b, limb_t c) {\n limb_t t = a + b;\n return (a > t) ? t : c;\n}\n\ntemplate \nstatic inline limb_t sub_sysdep(limb_t a, limb_t y, limb_t m) {\n limb_t t0 = a - y;\n return (y > a) ? (t0 + m) : t0;\n}\n\n#endif\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_SYSDEP_H_\n"], ["/longfellow-zk/lib/circuits/cbor_parser/scan.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_SCAN_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_SCAN_H_\n\n#include \n\n#include \n\nnamespace proofs {\ntemplate \nclass Scan {\n public:\n using EltW = typename Logic::EltW;\n using BitW = typename Logic::BitW;\n\n explicit Scan(const Logic& l) : l_(l) {}\n\n /* Segmented prefix add, equivalent to this code:\n\n s = 0;\n for (size_t i = 0; i < n; ++i) {\n if (S[i]) {\n s = A[i];\n } else {\n s += ds[i];\n }\n B[i] = s;\n }\n */\n void add(size_t n, EltW B[/*n*/], const BitW S[/*n*/], const EltW A[/*n*/],\n const EltW ds[/*n*/]) {\n const Logic& L = l_; // shorthand\n std::vector S1(n);\n for (size_t i = 0; i < n; ++i) {\n S1[i] = S[i];\n B[i] = L.mux(&S[i], &A[i], ds[i]);\n }\n scan_add(0, n, S1.data(), B);\n }\n\n // unsegmented variant of add(), assume S[i] = false\n void add(size_t n, EltW B[/*n*/], const EltW ds[/*n*/]) {\n for (size_t i = 0; i < n; ++i) {\n B[i] = ds[i];\n }\n scan_add(0, n, B);\n }\n\n private:\n const Logic& l_;\n\n void scan_add(size_t i0, size_t i1, BitW S[/*n*/], EltW B[/*n*/]) {\n if (i1 - i0 > 1) {\n const Logic& L = l_; // shorthand\n size_t im = i0 + (i1 - i0) / 2;\n scan_add(i0, im, S, B);\n scan_add(im, i1, S, B);\n\n size_t j = im - 1;\n for (size_t i = im; i < i1; ++i) {\n // special case of B[i] = S[i] ? B[i] : B[i] + B[j]\n // coded as B[i] = B[i] + (~S[i] * B[j])\n auto ns = L.lnot(S[i]);\n auto ns_bj = L.lmul(&ns, B[j]);\n B[i] = L.add(&B[i], ns_bj);\n S[i] = L.lor(&S[i], S[j]);\n }\n }\n }\n\n // unsegmented\n void scan_add(size_t i0, size_t i1, EltW B[/*n*/]) {\n if (i1 - i0 > 1) {\n const Logic& L = l_; // shorthand\n size_t im = i0 + (i1 - i0) / 2;\n scan_add(i0, im, B);\n scan_add(im, i1, B);\n\n size_t j = im - 1;\n for (size_t i = im; i < i1; ++i) {\n B[i] = L.add(&B[j], B[i]);\n }\n }\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_SCAN_H_\n"], ["/longfellow-zk/lib/algebra/nat.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_NAT_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_NAT_H_\n\n#include \n#include \n#include \n#include \n#include \n\n#include \"algebra/limb.h\"\n#include \"algebra/static_string.h\"\n#include \"algebra/sysdep.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n\n// return a^-1 mod 2^L where L is the number of bits in limb_t\ntemplate \nstatic limb_t inv_mod_b(limb_t a) {\n // Let v=1-a. We have 1/a=1/(1-v)=1+v+v^2+..., or\n // 1/a=(1+v)(1+v^2)(1+v^4)... At some point v^(2^k) becomes 0 mod\n // 2^L because v is even.\n\n // A more complicated variant of this idea appears in Dumas,\n // J.G. \"On Newton–Raphson Iteration for Multiplicative Inverses\n // Modulo Prime Powers\", Algorithm 3, where they use v'=a-1\n // instead of v=1-a, and so the first term needs to be handled\n // separately as 2-a instead of 1+v, breaking the uniformity of\n // the algorithm. The sign difference disappears after the first\n // squaring.\n check((a & 1) != 0, \"even A in inv_mod_b()\");\n\n limb_t v = 1u - a;\n limb_t u = 1u;\n while (v != 0) {\n u *= (1u + v);\n v *= v;\n }\n return u;\n}\n\n// This function should only be called on static input known at compile time.\nunsigned digit(char c);\n\ntemplate \nclass Nat : public Limb {\n public:\n using Super = Limb;\n using T = Nat;\n using limb_t = typename Super::limb_t;\n using Super::kLimbs;\n using Super::kU64;\n using Super::limb_;\n\n // Maximum length for an untrusted string, 2^64 ~ 20 decimal digits.\n static constexpr size_t kMaxStringLen = 20 * W64 + 1;\n\n Nat() = default; // uninitialized\n explicit Nat(uint64_t x) : Super(x) {}\n\n explicit Nat(const std::array& a) : Super(a) {}\n\n // Pre-condition: the caller of this function must check that the string\n // s is either a valid base-10 or base-16 representation of a natural number\n // that does not overflow the representation.\n // In our current implementation, this method is only used on static strings.\n explicit Nat(const StaticString& ss) : Super(0) {\n limb_t base = 10u;\n const char* s = ss.as_pointer;\n if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) {\n s += 2;\n base = 16u;\n }\n for (; *s; s++) {\n T d(digit(*s));\n bool ok = muls(limb_, base);\n check(ok, \"overflow in nat(const char *s)\");\n limb_t ah = add_limb(kLimbs, limb_, d.limb_);\n check(ah == 0, \"overflow in nat(const char *s)\");\n }\n }\n\n template \n explicit Nat(const char (&p)[LEN]) : Nat(StaticString(p)) {}\n\n // Interpret A[] as a little-endian nat\n static T of_bytes(const uint8_t a[/* kBytes */]) {\n T r;\n for (size_t i = 0; i < kLimbs; ++i) {\n a = Super::of_bytes(&r.limb_[i], a);\n }\n return r;\n }\n\n static std::optional safe_digit(char c, limb_t base) {\n c = tolower(c);\n if (c >= '0' && c <= '9') {\n return c - '0';\n } else if (base == 16u && c >= 'a' && c <= 'f') {\n return c - 'a' + 10;\n }\n return std::nullopt;\n }\n\n static std::optional of_untrusted_string(const char* s) {\n T r(0);\n limb_t base = 10u;\n if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) {\n s += 2;\n base = 16u;\n }\n const char* p = s;\n for (size_t len = 0; len < kMaxStringLen && *p; ++len, ++p) {\n auto d = safe_digit(*p, base);\n if (!d.has_value()) {\n return std::nullopt;\n }\n T td(d.value());\n if (!muls(r.limb_, base)) {\n return std::nullopt;\n }\n limb_t ah = add_limb(kLimbs, r.limb_, td.limb_);\n if (ah != 0) {\n return std::nullopt;\n }\n }\n // If the loop terminates due to the length limit, then the string is not\n // a valid base-10 or base-16 representation of a natural number.\n if (*p) {\n return std::nullopt;\n }\n return r;\n }\n\n bool operator<(const T& y) const {\n T b = *this;\n limb_t bh = sub_limb(kLimbs, b.limb_, y.limb_);\n return (bh != 0);\n }\n\n T& add(const T& y) {\n (void)add_limb(kLimbs, limb_, y.limb_);\n return *this;\n }\n T& sub(const T& y) {\n (void)sub_limb(kLimbs, limb_, y.limb_);\n return *this;\n }\n\n private:\n // b *= a, returns false if overflow occurred.\n static bool muls(limb_t b[kLimbs], limb_t a) {\n limb_t h[kLimbs];\n mulhl(kLimbs, b, h, a, b);\n limb_t bh = addh(kLimbs, b, h);\n return bh == 0;\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_NAT_H_\n"], ["/longfellow-zk/lib/sumcheck/verifier_layers.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_SUMCHECK_VERIFIER_LAYERS_H_\n#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_VERIFIER_LAYERS_H_\n\n#include \n\n#include \n#include \n\n#include \"arrays/affine.h\"\n#include \"arrays/dense.h\"\n#include \"arrays/eq.h\"\n#include \"sumcheck/circuit.h\"\n#include \"sumcheck/quad.h\"\n#include \"sumcheck/transcript_sumcheck.h\"\n\nnamespace proofs {\n// Sumcheck verifier that only verifies the layers.\n// Derived classes are responsible for verifying the\n// input binding, either directly or through a commitment.\ntemplate \nclass VerifierLayers {\n public:\n typedef typename Quad::index_t index_t;\n using Elt = typename Field::Elt;\n\n struct claims {\n corner_t nv;\n size_t logv;\n Elt claim[2];\n const Elt* q;\n const Elt* g[2];\n };\n // Verify all the circuit layers, returning claims on the inputs in\n // CL. The caller is responsible to verify the claims, either via\n // direct check or polynomial commitment.\n static bool circuit(const char** why, claims* cl,\n const Circuit* CIRCUIT, const Proof* PROOF,\n Challenge* CH, std::unique_ptr> V,\n TranscriptSumcheck& ts, const Field& F) {\n if (why == nullptr || cl == nullptr || CIRCUIT == nullptr ||\n PROOF == nullptr || CH == nullptr) {\n return false;\n }\n *why = \"ok\";\n\n Elt claimV;\n ts.begin_circuit(CH->q, CH->g);\n\n if (V->n1_ == 1 && V->n0_ == 1 && V->v_[0] == F.zero()) {\n // special case of all-zero binding\n claimV = F.zero();\n } else {\n const desire desires[2] = {\n {V->n1_ == CIRCUIT->nv, \"V->n1_ != CIRCUIT->nv\"},\n {V->n0_ == CIRCUIT->nc, \"V->n0_ != CIRCUIT->nc\"},\n };\n\n if (!check(why, 2, desires)) {\n return false;\n }\n\n // initial claim on V[G, Q] for the output V\n V->bind_all(CIRCUIT->logc, CH->q, F);\n V->reshape(CIRCUIT->nv);\n V->bind_all(CIRCUIT->logv, CH->g, F);\n claimV = V->scalar();\n }\n\n // Consider claimV on the binding to P.G as two (identical)\n // claims, so we can get the induction going. Thus, alpha in\n // the first layer is redundant.\n *cl = claims{\n .nv = CIRCUIT->nv,\n .logv = CIRCUIT->logv,\n .claim = {claimV, claimV},\n .q = CH->q,\n .g = {CH->g, CH->g},\n };\n\n return layers(why, cl, CIRCUIT, PROOF, ts, CH, F);\n }\n\n VerifierLayers() = delete;\n\n private:\n struct desire {\n bool cond;\n const char* why;\n };\n\n static bool check(const char** why, size_t n, const desire* d) {\n for (size_t i = 0; i < n; ++i) {\n if (!d[i].cond) {\n *why = d[i].why;\n return false;\n }\n }\n return true;\n }\n\n // Verify CLAIM for one layer and update CLAIM in-place as next\n // claim. Return TRUE on success, and (FALSE, why) on failure.\n static bool layer_c(const char** why, Elt* claim, size_t logc,\n const LayerProof* plr, LayerChallenge* ch,\n TranscriptSumcheck& ts, const Field& F) {\n for (size_t round = 0; round < logc; ++round) {\n // (p(0) + p(1))\n Elt got = F.addf(plr->cp[round].t_[0], plr->cp[round].t_[1]);\n if (got != *claim) {\n *why = \"got != claim (round_c)\";\n return false;\n }\n ch->cb[round] = ts.round(plr->cp[round]);\n *claim = plr->cp[round].eval_lagrange(ch->cb[round], F);\n }\n\n return true;\n }\n\n static bool layer_h(const char** why, Elt* claim, size_t logw,\n const LayerProof* plr, LayerChallenge* ch,\n TranscriptSumcheck& ts, const Field& F) {\n for (size_t round = 0; round < logw; ++round) {\n for (size_t hand = 0; hand < 2; ++hand) {\n // (p(0) + p(1))\n Elt got =\n F.addf(plr->hp[hand][round].t_[0], plr->hp[hand][round].t_[1]);\n if (got != *claim) {\n *why = \"got != claim (round_h)\";\n return false;\n }\n ch->hb[hand][round] = ts.round(plr->hp[hand][round]);\n *claim = plr->hp[hand][round].eval_lagrange(ch->hb[hand][round], F);\n }\n }\n return true;\n }\n\n // Verify CLAIMS for all layers and update CLAIMS in-place. Return\n // TRUE on success, and (FALSE, why) on failure.\n static bool layers(const char** why, claims* cl,\n const Circuit* CIRCUIT, const Proof* PROOF,\n TranscriptSumcheck& ts, Challenge* CH,\n const Field& F) {\n for (size_t ly = 0; ly < CIRCUIT->nl; ++ly) {\n auto clr = &CIRCUIT->l.at(ly);\n auto plr = &PROOF->l[ly];\n auto challenge = &CH->l[ly];\n\n // the claim is then an affine combination of the two\n // inductive claims\n ts.begin_layer(challenge->alpha, challenge->beta, ly);\n Elt claim = F.addf(cl->claim[0], F.mulf(challenge->alpha, cl->claim[1]));\n\n if (!layer_c(why, &claim, CIRCUIT->logc, plr, challenge, ts, F)) {\n return false;\n }\n\n if (!layer_h(why, &claim, clr->logw, plr, challenge, ts, F)) {\n return false;\n }\n\n // Now verify CLAIM = EQ[Q,C] QUAD[R,L] W[R,C] W[L,C]\n // where W[R,C], W[L,C] are in the proof.\n\n // bind QUAD[g|r,l] to the alpha-combination of the\n // two G values GR, GL\n auto QUAD = clr->quad->clone();\n QUAD->bind_g(cl->logv, cl->g[0], cl->g[1], challenge->alpha,\n challenge->beta, F);\n\n // bind QUAD[G|r,l] to R, L\n for (size_t round = 0; round < clr->logw; ++round) {\n for (size_t hand = 0; hand < 2; ++hand) {\n QUAD->bind_h(challenge->hb[hand][round], hand, F);\n }\n }\n\n // got = EQ[Q,C] QUAD[G|R,L] W[R,C] W[L,C], where\n // W[.,C] is in the proof.\n Elt got =\n Eq::eval(CIRCUIT->logc, CIRCUIT->nc, cl->q, challenge->cb, F);\n F.mul(got, QUAD->scalar());\n F.mul(got, plr->wc[0]);\n F.mul(got, plr->wc[1]);\n\n if (got != claim) {\n *why = \"got != claim (layer)\";\n return false;\n }\n\n // Add wc[0,1] to transcript\n ts.write(&plr->wc[0], 1, 2);\n\n // Reduce to two claims on W[R,C] and W[L,C]\n *cl = claims{\n .nv = clr->nw,\n .logv = clr->logw,\n .claim = {plr->wc[0], plr->wc[1]},\n .q = challenge->cb,\n .g = {challenge->hb[0], challenge->hb[1]},\n };\n }\n return true;\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_VERIFIER_LAYERS_H_\n"], ["/longfellow-zk/lib/arrays/eqs.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ARRAYS_EQS_H_\n#define PRIVACY_PROOFS_ZK_LIB_ARRAYS_EQS_H_\n\n#include \n\n#include \n\n#include \"algebra/blas.h\"\n#include \"arrays/affine.h\"\n#include \"arrays/dense.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n\n// Stateful implementation of EQ[I, j] which, for fixed\n// I, holds an array indexed by j.\ntemplate \nclass Eqs : public Dense {\n using Elt = typename Field::Elt;\n using Dense::v_;\n using Dense::n0_;\n\n public:\n Eqs(size_t logn, corner_t n, const Elt I[/*logn*/], const Field& F)\n : Dense(n, 1) {\n filleq(&v_[0], logn, n, I, F);\n }\n\n corner_t n() const { return n0_; }\n\n // Optimization for a special case: return a raw vector EQ[G0|.] + alpha *\n // EQ[G1|.] Return std::vector<> because we don't need the full\n // dense<> machinery.\n static std::vector raw_eq2(size_t logn, corner_t n, const Elt* G0,\n const Elt* G1, const Elt& alpha,\n const Field& F) {\n std::vector eq0(n);\n std::vector eq1(n);\n filleq(&eq0[0], logn, n, G0, F);\n filleq(&eq1[0], logn, n, G1, F);\n Blas::axpy(n, &eq0[0], 1, alpha, &eq1[0], 1, F);\n return eq0;\n }\n\n private:\n // Return ceil(a / 2^{n}) for a != 0.\n //\n // Several ways exist to compute ceil(a/b) given a primitive that\n // computes floor(a/b), such as the C++ unsigned division operator.\n // The simplest one is floor((a+(b-1))/b), which potentally overflows.\n // Another way is 1+floor((a-1)/b), which underflows for a==0 but\n // otherwise does not overflow. More complicated ways exist that neither\n // overflow nor underflow. Since the rest of the code assumes\n // a!=0 anyway, we use the 1+floor((a-1)/b) version.\n static corner_t ceilshr(corner_t a, size_t n) { return 1u + ((a - 1u) >> n); }\n\n // Compute the array EQ[Q, i] for all 0<=i 0, \"n > 0\");\n eq[0] = F.one();\n for (size_t l = logn; l-- > 0;) {\n corner_t nl = ceilshr(n, l);\n corner_t i = ceilshr(nl, 1);\n\n // Special case for the first iteration of the i-loop\n // below: don't compute eq[2*i+1] (post decrement) if it\n // would overflow the array.\n if (/*2*(i-1)+1 = */ 2 * i - 1 >= nl) {\n i--;\n Elt v = eq[i], qv = Q[l];\n F.mul(qv, v);\n eq[2 * i] = v;\n F.sub(eq[2 * i], qv);\n }\n while (i-- > 0) {\n // Assign\n // eq[2*i] = (1-Q[l])*eq[i]\n // eq[2*i+1] = Q[l]*eq[i]\n // with one multiplication.\n Elt v = eq[i], qv = Q[l];\n F.mul(qv, v);\n eq[2 * i] = v;\n F.sub(eq[2 * i], qv);\n eq[2 * i + 1] = qv;\n }\n }\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ARRAYS_EQS_H_\n"], ["/longfellow-zk/lib/sumcheck/circuit.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_SUMCHECK_CIRCUIT_H_\n#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_CIRCUIT_H_\n\n#include \n\n#include \n#include \n#include \n\n#include \"algebra/poly.h\"\n#include \"arrays/affine.h\"\n#include \"sumcheck/quad.h\"\n\nnamespace proofs {\ntemplate \nstruct Layer {\n corner_t nw; // number of inputs\n size_t logw; // number of binding rounds for the hand variables\n std::unique_ptr> quad;\n\n bool operator==(const Layer& y) const {\n // This operator relies on the layer being properly constructed, so that\n // the quad reference is never a nullptr.\n return nw == y.nw && logw == y.logw && *quad == *y.quad;\n }\n\n size_t nterms() const { return quad->n_; }\n};\n\ntemplate \nstruct Circuit {\n corner_t nv; // number of outputs for one copy\n size_t logv; // number of G variables in V[G,C] in the final output\n corner_t nc; // number of copies\n size_t logc; // number of sumcheck rounds for the C variables\n size_t nl; // number of layers\n\n size_t ninputs; // number of inputs\n size_t npub_in; // number of public inputs, index of first private input\n size_t subfield_boundary; // Least input wire not known to be in the\n // subfield\n\n std::vector> l; // layers\n\n uint8_t id[32]; // unique id for the circuit, created by the compiler\n\n bool operator==(const Circuit& y) const {\n return nv == y.nv && logv == y.logv && nc == y.nc && logc == y.logc &&\n nl == y.nl && l == y.l;\n }\n size_t nterms() const {\n size_t n = 0;\n for (const auto& layer : l) {\n n += layer.nterms();\n }\n return n;\n }\n};\n\ntemplate \nstruct LayerProof {\n using Elt = typename Field::Elt;\n // For efficiency, we distinguish polynomials needed to bind copy\n // variables (CPoly, degree 3) from polynomials needed to bind\n // wire variables (WPoly, degree 2).\n using CPoly = Poly<4, Field>;\n using WPoly = Poly<3, Field>;\n\n // Maximum 2^40 gates/wires/copies per layer.\n static constexpr size_t kMaxBindings = 40;\n\n CPoly cp[kMaxBindings]; // polys for the C variables\n\n // The binding order we use is \"for (round) { for (hand) ... }\", and\n // thus one can organize this array as [kMaxBindings][2] for better\n // memory locality.\n // However, the corresponding challenges are organized as [2][kMaxBindings]\n // to allow easier binding by hand, and so it makes sense to keep this\n // array in the same order as the challenges.\n WPoly hp[2][kMaxBindings]; // polys for each hand \\in {right,left}\n\n // prover provides W[R,C] and W[L,C], which serve as claims\n // for the next layer\n Elt wc[2];\n};\n\ntemplate \nstruct LayerChallenge {\n using Elt = typename Field::Elt;\n static constexpr size_t kMaxBindings = LayerProof::kMaxBindings;\n\n // verifier: coefficient for the random linear combination\n // claim[0] + alpha * claim[1] of the two input claims.\n Elt alpha;\n Elt beta; // random coefficient for assert-zero\n Elt cb[kMaxBindings]; // bindings for the C variables\n Elt hb[2][kMaxBindings]; // bindings for each hand\n};\n\ntemplate \nstruct Challenge {\n using Elt = typename Field::Elt;\n static constexpr size_t kMaxBindings = LayerProof::kMaxBindings;\n\n // verifier picks Q for EQ[Q|c]\n Elt q[kMaxBindings]; // [logC]\n\n // verifier picks G for V[G,c]\n Elt g[kMaxBindings]; // [logV]\n std::vector> l;\n explicit Challenge(size_t nl) : l(nl) {}\n};\n\n// Full proof:\ntemplate \nstruct Proof {\n typedef typename LayerProof::CPoly CPoly;\n typedef typename LayerProof::WPoly WPoly;\n\n using Elt = typename Field::Elt;\n static constexpr size_t kMaxBindings = LayerProof::kMaxBindings;\n\n // then engage in sumcheck one per layer\n std::vector> l;\n\n explicit Proof(size_t nl) : l(nl) {}\n size_t size() const {\n return l.size() * (kMaxBindings * 4 + kMaxBindings * 3 * 2 + 2);\n }\n};\n\n// Auxiliary information generated by the prover to be\n// used by the ZK prover\ntemplate \nstruct ProofAux {\n using Elt = typename Field::Elt;\n std::vector bound_quad;\n explicit ProofAux(size_t nl) : bound_quad(nl) {}\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_CIRCUIT_H_\n"], ["/longfellow-zk/lib/algebra/reed_solomon.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_REED_SOLOMON_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_REED_SOLOMON_H_\n\n#include \n\n#include \n#include \n\n#include \"algebra/utility.h\"\n\nnamespace proofs {\n\n/*\nThe ReedSolomon class interpolates a polynomial given as input in point-eval\nform at a set of different points, thereby computing a form of RS encoding.\nSpecifically, the input polynomial of degree d=n-1 is given as evaluations\nat 0, 1, 2, ..., n-1, and the output is the values at n, n+1, n+2, ..., n+m-1.\nThe algorithm uses the following relation:\n\n p(k) = (-1)^d (k-d)(k choose d) sum_{j=0}^{d} (1/k-j)(-1)^j (d choose j)p(j)\n\nwhich can be efficiently computed using a convolution, whose implementation\nis provided by a ConvolutionFactory for the field.\n\nThe const Field& objects that are passed have lifetimes that exceed the call\ndurations and can be safely passed by const reference.\n\n*/\ntemplate \nclass ReedSolomon {\n using Elt = typename Field::Elt;\n using Convolver = typename ConvolutionFactory::Convolver;\n\n public:\n // n is the number of points provided\n // m is the total number of points output (including the initial n points)\n ReedSolomon(size_t n, size_t m, const Field& F,\n const ConvolutionFactory& factory)\n : f_(F), // could grab this from the factory\n degree_bound_(n - 1),\n m_(m),\n leading_constant_(m - n + 1),\n binom_i_(n) {\n // inverses[i]: inverses[i] = 1/i from i = 1 to m-1 (inverses[0] = 0)\n std::vector inverses(m_);\n AlgebraUtil::batch_inverse_arithmetic(m, &inverses[0], F);\n c_ = factory.make(n, m, &inverses[0]);\n leading_constant_[0] = F.one();\n binom_i_[0] = F.one();\n // Set leading_constant_[i] = (i+degree_bound_) choose degree_bound_\n // (from i=0 to i=m)\n for (size_t i = 1; i + degree_bound_ < m; ++i) {\n leading_constant_[i] =\n F.mulf(leading_constant_[i - 1],\n F.mulf(F.of_scalar(degree_bound_ + i), inverses[i]));\n }\n // Finish computing the leading constants:\n // (-1)^degree_bound_ (k-degree_bound_) \\binom{k}{degree_bound_}\n for (size_t k = degree_bound_; k < m; ++k) {\n F.mul(leading_constant_[k - degree_bound_],\n F.of_scalar(k - degree_bound_));\n if (degree_bound_ % 2 == 1) {\n F.neg(leading_constant_[k - degree_bound_]);\n }\n }\n\n for (size_t i = 1; i < n; ++i) {\n binom_i_[i] =\n F.mulf(binom_i_[i - 1], F.mulf(F.of_scalar(n - i), inverses[i]));\n }\n for (size_t i = 1; i < n; i += 2) {\n F.neg(binom_i_[i]);\n }\n }\n\n // Given the values of a polynomial of degree at most n at 0, 1, 2, ..., n-1,\n // this computes the values at n, n+1, n+2, ..., m-1.\n // (n points go in, m points come out)\n void interpolate(Elt y[/*m*/]) const {\n // shorthands\n const Field& F = f_;\n size_t n = degree_bound_ + 1; // number of points input\n\n // Define x[i] = (-1)^i \\binom{n}{i} p(i) for i=0 through i=n\n std::vector x(n);\n for (size_t i = 0; i < n; i++) {\n x[i] = F.mulf(binom_i_[i], y[i]);\n }\n\n std::vector T(m_);\n c_->convolution(&x[0], &T[0]);\n // Multiply the leading constants by the convolution\n for (size_t i = n; i < m_; ++i) {\n y[i] = F.mulf(leading_constant_[i - degree_bound_], T[i]);\n }\n }\n\n private:\n const Field& f_;\n\n // n is the number of points input, and degree_bound = n + 1.\n // degree_bound_ is useful since the LaTeX math is written in terms of it\n const size_t degree_bound_; // degree bound, i.e., n - 1\n // total number of points output (points in + new points out)\n const size_t m_;\n\n std::unique_ptr c_;\n\n // leading_constant_[i] = \\binom{i+degree_bound_}{degree_bound_} *\n // (-1)^{degree_bound_} (i+degree_bound_ - degree_bound_) (from i=0 to i=m-n)\n // i.e., the leading constant \\binom{k}{degree_bound_} *\n // (-1)^degree_bound_ (k - degree_bound_), shifted left by degree_bound_\n std::vector leading_constant_;\n // (-1)^i (degree_bound_ choose i) from i=0 to i=degree_bound_\n std::vector binom_i_;\n};\n\ntemplate \nclass ReedSolomonFactory {\n public:\n ReedSolomonFactory(const ConvolutionFactory& factory, const Field& f)\n : factory_(factory), f_(f) {}\n\n std::unique_ptr> make(size_t n,\n size_t m) const {\n return std::make_unique>(n, m, f_,\n factory_);\n }\n\n private:\n const ConvolutionFactory& factory_;\n const Field& f_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_REED_SOLOMON_H_\n"], ["/longfellow-zk/lib/cbor/host_decoder.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CBOR_HOST_DECODER_H_\n#define PRIVACY_PROOFS_ZK_LIB_CBOR_HOST_DECODER_H_\n\n#include \n#include \n\n#include \n#include \n\n#include \"util/panic.h\"\n\nnamespace proofs {\n\nenum CborTag { UNSIGNED, NEGATIVE, BYTES, TEXT, ARRAY, MAP, TAG, PRIMITIVE };\nenum CborPrimitive { FALSE, TRUE, CNULL };\n\n// CBOR decoder for a subset of CBOR used in MDOC.\n//\n// The main advantage of this decoder is that it keeps\n// offsets into the input, which is useful because we need to\n// generate circuits that depend on input offsets.\n//\n// The other security advantage is the smaller codebase, versus\n// relying on an imported CBOR parser that handles a larger subset of CBOR\n// that may introduce issues.\n//\n// The decode function is used to process an untrusted array of bytes.\n// The method returns false if the input is not processed exactly per the\n// MDOC spec with only attributes in the org.iso.18013.5.1 namespace.\n// The resulting CborDoc object is static, and it is assumed that neither the\n// input doc, nor the tree structure changes. All of the lookup and index\n// methods return const pointers to attempt to maintain this property.\nclass CborDoc {\n public:\n size_t header_pos_;\n enum CborTag t_;\n\n // A union is used to store the attributes for either singleton objects (i.e.,\n // UNSIGNED, NEGATIVE, PRIMITIVE), the start position and len of TEXT and\n // BYTES array, and the children information for ARRAY or MAP objects.\n // len of strings and byte arrays\n union U {\n uint64_t u64; /* UNSIGNED */\n int64_t i64; /* NEGATIVE */\n enum CborPrimitive p; /* PRIMITIVE */\n\n // BYTES + TEXT, represented as offset in input + length\n struct {\n size_t pos;\n size_t len;\n } string;\n\n // arrays, maps, and tags: an array of children nodes.\n struct {\n // The original count in the source document. For tags,\n // the tag itself.\n size_t n;\n\n // The actual number of children (e.g. 2*n for maps).\n size_t nchildren;\n } items;\n } u_;\n\n // This field only applies to ARRAY, MAP nodes, but it has been moved\n // out of the union to avoid including components with non-default\n // constructors. It holds the children objects of an array or map. For a map,\n // even positions are the keys, and the odd positions are the values.\n std::vector children_;\n\n // Parse a byte sequence into a CborDoc structure.\n //\n // Caller passes in the input sequence, the length of the\n // input, and pos and offset values. The offset value handles the case when\n // the input sequence is a sub-sequence of another string, as it is in\n // the MDOC and MSO parsing.\n //\n // This function can handle adversarial inputs, and returns false when the\n // input cannot be parsed.\n bool decode(const uint8_t in[], size_t len, size_t &pos, size_t offset) {\n /* invariant: pos is always compared with len before it is referenced. */\n header_pos_ = pos + offset;\n\n if (pos >= len) {\n return false;\n }\n uint8_t b = in[pos++];\n\n size_t type = (b >> 5) & 0x7u;\n size_t count0 = b & 0x1Fu;\n\n // variable-length count\n size_t count = 0;\n if (count0 < 24) {\n count = count0;\n } else if (count0 == 24) {\n if (pos >= len) {\n return false;\n }\n count = in[pos++];\n } else if (count0 == 25) {\n if (pos + 1 >= len) {\n return false;\n }\n count = in[pos] * 256 + in[pos + 1];\n pos += 2;\n } else if (count0 == 26) {\n if (pos + 3 >= len) {\n return false;\n }\n for (size_t i = 0; i < 4; ++i) {\n count *= 256;\n count += in[pos++];\n }\n } else {\n return false;\n }\n\n switch (type) { /* type \\in [0,7] by construction */\n case 0:\n t_ = UNSIGNED;\n u_.u64 = count;\n break;\n case 1:\n t_ = NEGATIVE;\n u_.i64 = -(int64_t)count;\n break;\n\n case 2: /* BYTES */\n case 3: /* TEXT */\n if (pos + count > len) {\n return false;\n }\n t_ = (type == 2) ? BYTES : TEXT;\n u_.string.pos = pos;\n u_.string.len = count;\n pos += count;\n break;\n\n case 4: /* ARRAY */\n if (pos + count > len) {\n return false;\n }\n return decode_items(ARRAY, count, count, in, len, pos, offset);\n\n case 5: /* MAP, (key,val) pairs are stored as 2*children */\n if (pos + 2 * count > len) {\n return false;\n }\n return decode_items(MAP, 2 * count, count, in, len, pos, offset);\n\n case 6: /* TAG */\n // Special cases for TAG\n if (count == 1004) { // date in the form YYYY-MM-DD\n if (pos + 1 + 10 > len) { // 0xDA for str length + 10 characters\n return false;\n }\n }\n return decode_items(TAG, 1, count, in, len, pos, offset);\n\n case 7: /* PRIMITIVE */\n t_ = PRIMITIVE;\n switch (count) {\n case 20:\n u_.p = FALSE;\n break;\n case 21:\n u_.p = TRUE;\n break;\n case 22:\n u_.p = CNULL;\n break;\n default:\n return false;\n }\n break;\n }\n\n return true;\n }\n\n // Lookup a child node in an array. Returns null if the query is invalid.\n const CborDoc *index(size_t index) const {\n if (t_ == ARRAY && index < u_.items.nchildren) {\n return &children_[index];\n }\n return nullptr;\n }\n\n // Lookup a key in a map of type {bytes->elements}.\n // Returns null if the query is invalid.\n // The key is given as bytes with a length.\n // ndx is set to the child index of the located key.\n // The return pointer references the key, and the next object refers to\n // the value and is guaranteed to exist.\n const CborDoc *lookup(const uint8_t *const in, size_t len,\n const uint8_t bytes[/*len*/], size_t &ndx) const {\n if (t_ == MAP) {\n for (size_t i = 0; i < u_.items.n; ++i) {\n if (children_[2 * i].eq(in, len, bytes)) {\n ndx = i;\n return &children_[2 * i];\n }\n }\n }\n return nullptr;\n }\n\n // Lookup a key in a map of type {unsigned->object}.\n // Returns null if the query is invalid.\n const CborDoc *lookup_unsigned(uint64_t k, size_t &ndx) const {\n if (t_ == MAP) {\n for (size_t i = 0; i < u_.items.n; ++i) {\n const CborDoc *key = &children_[2 * i];\n if (key->t_ == UNSIGNED && key->u_.u64 == k) {\n ndx = i;\n return key;\n }\n }\n }\n return nullptr;\n }\n\n // Lookup a key in a map of type {negative->object}.\n // Returns null if the query is invalid.\n const CborDoc *lookup_negative(int64_t k, size_t &ndx) const {\n if (t_ == MAP) {\n for (size_t i = 0; i < u_.items.n; ++i) {\n const CborDoc *key = &children_[2 * i];\n if (key->t_ == NEGATIVE && key->u_.i64 == k) {\n ndx = i;\n return key;\n }\n }\n }\n return nullptr;\n }\n\n // Returns the index of the item with respect to the document bytes.\n size_t position() const {\n switch (t_) {\n case UNSIGNED:\n return header_pos_;\n case BYTES:\n case TEXT:\n return u_.string.pos;\n case TAG:\n return children_[0].u_.string.pos;\n case PRIMITIVE:\n return header_pos_;\n default:\n check(false, \"valueIndex called on non-value type\");\n }\n return 0;\n }\n\n // Returns the length of the item's value in bytes.\n // According to ISO 18013-5 7.2.1, the mDL data elements shall be encoded\n // as tstr, uint, bstr, bool, or tdate, so this function only handles those\n // cases.\n size_t length() const {\n switch (t_) {\n case UNSIGNED:\n if (u_.u64 < 24) {\n return 1;\n } else if (u_.u64 < 256) {\n return 2;\n } else if (u_.u64 < 65536) {\n return 3;\n }\n return 5;\n case BYTES:\n case TEXT:\n return u_.string.len;\n case TAG:\n return children_[0].u_.string.len; // full-date #6.1004(tstr) format\n case PRIMITIVE:\n return 1;\n default:\n check(false, \"valueLength called on non-value type\");\n }\n return 0;\n }\n\n private:\n // Decodes a sequence of children nodes.\n bool decode_items(CborTag t, size_t nchildren, size_t items_n,\n const uint8_t in[], size_t len, size_t &pos,\n size_t offset) {\n t_ = t;\n u_.items.n = items_n;\n u_.items.nchildren = nchildren;\n children_.resize(nchildren);\n for (size_t i = 0; i < nchildren; ++i) {\n if (!children_[i].decode(in, len, pos, offset)) return false;\n }\n return true;\n }\n\n // Compares a text node to a given string of bytes.\n bool eq(const uint8_t *const in, size_t len,\n const uint8_t bytes[/*len*/]) const {\n return t_ == TEXT && u_.string.len == len &&\n memcmp(bytes, &in[u_.string.pos], len) == 0;\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CBOR_HOST_DECODER_H_\n"], ["/longfellow-zk/lib/algebra/rfft.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_RFFT_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_RFFT_H_\n\n#include \n#include \n\n#include \"algebra/permutations.h\"\n#include \"algebra/twiddle.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n\n// Real FFT and its inverse.\n//\n// The FFT F[j] of a real input R[k] is complex and\n// conjugate-symmetric: F[j] = conj(F[n - j]).\n//\n// Following the FFTW conventions, to avoid doubling the\n// storage, we store F[j] as a \"half-complex\" array HC[j] of elements\n// in the base field.\n//\n// HC[j] = (2j <= n) ? real(F[j]) : imag(F[n - j])\n//\n// Thus we have two kinds of transforms: R2HC (real to\n// half-complex) and HC2R (half-complex to real).\n//\n// Again following the FFTW conventions, we say that\n// the R2HC transform is \"forward\" (minus sign in the exponent)\n// and the HC2R sign is \"backward\" (plus sign in the exponent).\n// See fft.h for a definition of forward and backward.\n\ntemplate \nclass RFFT {\n using Field = typename FieldExt::BaseField;\n using RElt = typename Field::Elt;\n using CElt = typename FieldExt::Elt;\n\n // The machinery in this file only works if the root is\n // on the unit circle, because we multiply by the conjugate\n // instead of by the inverse.\n static void validate_root(const CElt& omega, const FieldExt& C) {\n check(C.mulf(omega, C.conjf(omega)) == C.one(),\n \"root of unity not on the unit circle\");\n }\n\n static void r2hcI(RElt* A, size_t s, const Field& R) {\n RElt t = A[s];\n A[s] = A[0];\n R.add(A[0], t);\n R.sub(A[s], t);\n }\n static void r2hcII(RElt* A, size_t s, const CElt& tw, const Field& R) {\n R.mul(A[s], R.negf(tw.im));\n }\n\n static void hc2hcf(RElt* Ar, RElt* Ai, size_t s, const CElt& tw,\n const Field& R) {\n RElt xr, xi;\n cmulj(&xr, &xi, Ar[s], Ai[s], tw.re, tw.im, R);\n RElt ar0 = Ar[0];\n RElt ai0 = Ai[0];\n Ar[0] = R.addf(ar0, xr);\n Ai[0] = R.subf(ar0, xr);\n Ar[s] = R.subf(xi, ai0);\n Ai[s] = R.addf(xi, ai0);\n }\n\n static void hc2rI(RElt* A, size_t s, const Field& R) {\n RElt t = A[s];\n A[s] = A[0];\n R.add(A[0], t);\n R.sub(A[s], t);\n }\n\n static void hc2rIII(RElt* A, size_t s, const CElt& tw, const Field& R) {\n R.add(A[0], A[0]);\n R.add(A[s], A[s]);\n R.mul(A[s], R.negf(tw.im));\n }\n\n static void hc2hcb(RElt* Ar, RElt* Ai, size_t s, const CElt& tw,\n const Field& R) {\n RElt ar0 = Ar[0];\n RElt ai0 = Ai[0];\n RElt ar1 = Ar[s];\n RElt ai1 = Ai[s];\n Ar[0] = R.addf(ar0, ai0);\n Ai[0] = R.subf(ai1, ar1);\n RElt xr = R.subf(ar0, ai0);\n RElt xi = R.addf(ai1, ar1);\n cmul(&Ar[s], &Ai[s], xr, xi, tw.re, tw.im, R);\n }\n\n public:\n // Forward real to half-complex in-place transform.\n // N (the length of A) must be a power of 2\n static void r2hc(RElt A[/*n*/], size_t n, const CElt& omega,\n uint64_t omega_order, const FieldExt& C) {\n validate_root(omega, C);\n\n if (n <= 1) {\n return;\n }\n\n const Field& R = C.base_field();\n CElt omega_n = Twiddle::reroot(omega, omega_order, n, C);\n Twiddle roots(n, omega_n, C);\n\n Permutations::bitrev(A, n);\n\n // m=1 iteration\n for (size_t k = 0; k < n; k += 2) {\n r2hcI(&A[k], 1, R);\n }\n\n // m>1 iterations\n for (size_t m = 2; m < n; m = 2 * m) {\n size_t ws = n / (2 * m);\n for (size_t k = 0; k < n; k += 2 * m) {\n size_t j;\n r2hcI(&A[k], m, R); // j==0\n\n for (j = 1; j + j < m; ++j) {\n hc2hcf(&A[k + j], &A[k + m - j], m, roots.w_[j * ws], R);\n }\n\n r2hcII(&A[k + j], m, roots.w_[j * ws], R); // j==m/2\n }\n }\n }\n\n // Backward half-complex to real in-place transform.\n static void hc2r(RElt A[/*n*/], size_t n, const CElt& omega,\n uint64_t omega_order, const FieldExt& C) {\n validate_root(omega, C);\n\n if (n <= 1) {\n return;\n }\n\n const Field& R = C.base_field();\n CElt omega_n = Twiddle::reroot(omega, omega_order, n, C);\n Twiddle roots(n, omega_n, C);\n\n // m>1 iterations\n for (size_t m = n; (m /= 2) >= 2;) {\n size_t ws = n / (2 * m);\n for (size_t k = 0; k < n; k += 2 * m) {\n size_t j;\n hc2rI(&A[k], m, R); // j==0\n\n for (j = 1; j + j < m; ++j) {\n hc2hcb(&A[k + j], &A[k + m - j], m, roots.w_[j * ws], R);\n }\n\n hc2rIII(&A[k + j], m, roots.w_[j * ws], R); // j==m/2\n }\n }\n\n // m=1 iteration\n for (size_t k = 0; k < n; k += 2) {\n hc2rI(&A[k], 1, R);\n }\n\n Permutations::bitrev(A, n);\n }\n\n // X = A * B\n static void cmul(RElt* xr, RElt* xi, const RElt& ar, const RElt& ai,\n const RElt& br, const RElt& bi, const Field& R) {\n // Karatsuba 3 mul + 5 add\n auto p0 = R.mulf(ar, br);\n auto p1 = R.mulf(ai, bi);\n auto a01 = R.addf(ar, ai);\n auto b01 = R.addf(br, bi);\n *xr = R.subf(p0, p1);\n R.mul(a01, b01);\n R.sub(a01, p0);\n R.sub(a01, p1);\n *xi = a01;\n }\n\n // X = A * conj(B)\n static void cmulj(RElt* xr, RElt* xi, const RElt& ar, const RElt& ai,\n const RElt& br, const RElt& bi, const Field& R) {\n // Karatsuba 3 mul + 5 add\n auto p0 = R.mulf(ar, br);\n auto p1 = R.mulf(ai, bi);\n auto a01 = R.addf(ar, ai);\n auto b01 = R.subf(br, bi);\n *xr = R.addf(p0, p1);\n R.mul(a01, b01);\n R.sub(a01, p0);\n R.add(a01, p1);\n *xi = a01;\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_RFFT_H_\n"], ["/longfellow-zk/lib/algebra/poly.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_POLY_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_POLY_H_\n\n#include \n\nnamespace proofs {\n// Fixed-size N-tuples of field elements, interpreted as polynomial coefficients\n// and/or values and/or newton expansion.\ntemplate \nclass Poly {\n public:\n static const size_t kN = N;\n using Elt = typename Field::Elt;\n using T = Poly;\n\n // the N-tuple itself\n Elt t_[N];\n\n Elt& operator[](size_t i) { return t_[i]; }\n const Elt& operator[](size_t i) const { return t_[i]; }\n\n T& add(const T& y, const Field& F) {\n for (size_t i = 0; i < N; ++i) {\n F.add(t_[i], y[i]);\n }\n return *this;\n }\n T& sub(const T& y, const Field& F) {\n for (size_t i = 0; i < N; ++i) {\n F.sub(t_[i], y[i]);\n }\n return *this;\n }\n T& mul(const T& y, const Field& F) {\n for (size_t i = 0; i < N; ++i) {\n F.mul(t_[i], y[i]);\n }\n return *this;\n }\n T& mul_scalar(const Elt& y, const Field& F) {\n for (size_t i = 0; i < N; ++i) {\n F.mul(t_[i], y);\n }\n return *this;\n }\n\n static T extend(const Poly<2, Field>& f, const Field& F) {\n T g;\n g[0] = f[0];\n g[1] = f[1];\n Elt df = F.subf(f[1], f[0]);\n\n if (Field::kCharacteristicTwo) {\n // Assume poly_evaluation_point[0] = 0, poly_evaluation_point[1] = 1,\n // and the rest are arbitrary.\n for (size_t i = 2; i < N; ++i) {\n g[i] = F.addf(g[0], F.mulf(F.poly_evaluation_point(i), df));\n }\n } else {\n // Assume that poly_evaluation_point[] form an arithmetic\n // progression.\n for (size_t i = 2; i < N; ++i) {\n g[i] = F.addf(g[i - 1], df);\n }\n }\n\n return g;\n }\n\n // convert Lagrange basis -> Newton forward differences for the\n // special case of evaluation points 0, 1, 2, ..., N-1.\n // See interpolation.h for the general case of interpolation.\n void newton_of_lagrange(const Field& F) {\n for (size_t i = 1; i < N; i++) {\n for (size_t k = N; k-- > i;) {\n F.sub(t_[k], t_[k - 1]);\n F.mul(t_[k], F.newton_denominator(k, i));\n }\n }\n }\n\n // Evaluate f(x) for a polynomial in the Newton forward-difference\n // basis.\n Elt eval_newton(const Elt& x, const Field& F) const {\n // Newton interpolation formula\n Elt e = t_[N - 1];\n for (size_t i = N - 1; i-- > 0;) {\n F.mul(e, F.subf(x, F.poly_evaluation_point(i)));\n F.add(e, t_[i]);\n }\n\n return e;\n }\n\n Elt eval_lagrange(const Elt& x, const Field& F) const {\n T tmp(*this); // do not clobber *this\n tmp.newton_of_lagrange(F);\n return tmp.eval_newton(x, F);\n }\n\n // Evaluate f(r) given a polynomial in the standard basis\n // f(x)=t_[i]*x^i.\n Elt eval_monomial(const Elt& x, const Field& F) const {\n // Horner's algorithm\n Elt e = t_[N - 1];\n for (size_t i = N - 1; i-- > 0;) {\n F.mul(e, x);\n F.add(e, t_[i]);\n }\n return e;\n }\n\n static T powers_of(const Elt& e, const Field& F) {\n T r;\n r[0] = F.one();\n for (size_t i = 1; i < N; ++i) {\n r[i] = F.mulf(r[i - 1], e);\n }\n return r;\n }\n\n // Interpolation via explicit dot product.\n //\n // The combination P.newton_of_lagrange().eval_newton(..., R, ...)\n // evaluates P at R given the Lagrange basis [P(0), P(1), ..., P(N-1)].\n //\n // On the contrary, this class computes a V(R) such that P(R) =\n // dot(V(R), [P(0), P(1), ..., P(N-1)]) and the caller computes the\n // inner product, either explicitly or via an inner-product\n // argument. The construction is pure linear algebra: express the\n // Lagrange basis P = [P(0), P(1), ..., P(N-1)]^T as I * P where I\n // is the identity matrix, and interpolate the rows of I\n // via newton_of_lagrange().eval_newton(). Since newton_of_lagrange()\n // is O(N^2) and eval_newton() is O(N), pre-compute the eval_newton()\n // of all rows.\n class dot_interpolation {\n // identity_[k] contains the Newton basis of the polynomial P(x) such\n // that P(k) = 1 and P(i) = 0 for i != k and 0 <= i < N.\n T identity_[N];\n\n public:\n explicit dot_interpolation(const Field& F) {\n for (size_t k = 0; k < N; ++k) {\n for (size_t i = 0; i < N; ++i) {\n identity_[k][i] = (i == k) ? F.one() : F.zero();\n }\n identity_[k].newton_of_lagrange(F);\n }\n }\n\n // return V such that P(r) = V^T [P(0), P(1), ..., P(N-1)]\n T coef(const Elt& x, const Field& F) const {\n T c;\n for (size_t k = 0; k < N; ++k) {\n c[k] = identity_[k].eval_newton(x, F);\n }\n return c;\n }\n };\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_POLY_H_\n"], ["/longfellow-zk/lib/circuits/compiler/pdqhash.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_PDQHASH_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_PDQHASH_H_\n\n#include \n#include \n\n#include \n#include \n\n#define DEFINE_STRONG_INT_TYPE(a, b) using a = b\n\nnamespace proofs {\n\n// Old-school, quick and dirty hash table specialized for\n// uint64_t key, value_t value. Support multiple keys\n// (\"multimap\").\n//\n// This is supposed to solve the same problem as the C++\n// unordered_multimap, except that the unordered_multimap\n// stores key/value as a linked list and leaves the malloc()\n// arena so fragmented that malloc_coalesce() takes several\n// hundred ms to reconstruct the heap.\nclass PdqHash {\n public:\n // value of NIL denotes empty slot\n using value_t = uint32_t;\n static const constexpr value_t kNil = ~static_cast(0);\n\n // Store the key as uint32_t to save space. This is ok because\n // \"key\" is not really a key. Instead, find() invokes pred() which\n // compares against the full key (stored outside this class).\n DEFINE_STRONG_INT_TYPE(stored_key_t, uint32_t);\n\n static stored_key_t narrow(uint64_t k) { return stored_key_t(k + (k >> 32)); }\n\n struct kv {\n stored_key_t k;\n value_t v;\n\n kv() : k(stored_key_t(0)), v(kNil) {}\n };\n\n PdqHash() : bits_(10), sz_(0), table_(capacity()) {}\n\n void insert(uint64_t k64, value_t v) {\n if (2 * sz_ > capacity()) {\n rehash();\n }\n insert0(narrow(k64), v);\n }\n\n size_t find(uint64_t k64, const std::function &pred) {\n stored_key_t k = narrow(k64);\n size_t mask = (size_t(1) << bits_) - 1;\n size_t dh = dhash(k);\n for (size_t h = hash(k);; h += dh) {\n const kv *p = &table_[h & mask];\n if (p->v == kNil) {\n // not found\n return kNil;\n }\n if (p->k == k && pred(p->v)) {\n // found\n return p->v;\n }\n }\n }\n\n private:\n void insert0(stored_key_t k, value_t v) {\n size_t mask = (size_t(1) << bits_) - 1;\n size_t dh = dhash(k);\n for (size_t h = hash(k);; h += dh) {\n kv *p = &table_[h & mask];\n if (p->v == kNil) {\n p->k = k;\n p->v = v;\n ++sz_;\n return;\n }\n }\n }\n\n // Adhoc hash function suffices for this application.\n uint64_t hash(uint64_t k) {\n return k + 3 * (k >> bits_) + 7 * (k >> (2 * bits_));\n }\n uint64_t hash(stored_key_t nk) { return hash(static_cast(nk)); }\n uint64_t dhash(stored_key_t nk) {\n // If gcd(dhash, capacity()) == 1, the insert loop does not have a short\n // cycle.\n return 2 * hash(hash(nk)) + 1;\n }\n void rehash() {\n ++bits_;\n std::vector table1(capacity());\n table_.swap(table1);\n for (const auto &p : table1) {\n if (p.v != kNil) {\n insert0(p.k, p.v);\n }\n }\n }\n\n size_t capacity() { return size_t(1) << bits_; }\n\n size_t bits_;\n size_t sz_;\n std::vector table_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_PDQHASH_H_\n"], ["/longfellow-zk/lib/gf2k/sysdep.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_GF2K_SYSDEP_H_\n#define PRIVACY_PROOFS_ZK_LIB_GF2K_SYSDEP_H_\n\n#include \n#include \n\n#include \n\n// Hardcoded GF(2^128) SIMD arithmetic where\n// GF(2^128) = GF(2)[x] / (x^128 + x^7 + x^2 + x + 1)\n\n#if defined(__x86_64__) || defined(__i386__)\n#include // IWYU pragma: keep\n\nnamespace proofs {\n\nusing gf2_128_elt_t = __m128i;\n\nstatic inline std::array uint64x2_of_gf2_128(gf2_128_elt_t x) {\n return std::array{static_cast(x[0]),\n static_cast(x[1])};\n}\n\nstatic inline gf2_128_elt_t gf2_128_of_uint64x2(\n const std::array &x) {\n // Cast to long long (as opposed to int64_t) is necessary because __m128i is\n // defined in terms of long long.\n return gf2_128_elt_t{static_cast(x[0]),\n static_cast(x[1])};\n}\n\nstatic inline gf2_128_elt_t gf2_128_add(gf2_128_elt_t x, gf2_128_elt_t y) {\n return _mm_xor_si128(x, y);\n}\n\n// return t0 + x^64 * t1\nstatic inline gf2_128_elt_t gf2_128_reduce(gf2_128_elt_t t0, gf2_128_elt_t t1) {\n const gf2_128_elt_t poly = {0x87};\n t0 = _mm_xor_si128(t0, _mm_slli_si128(t1, 64 /*bits*/ / 8 /*bits/byte*/));\n t0 = _mm_xor_si128(t0, _mm_clmulepi64_si128(t1, poly, 0x01));\n return t0;\n}\nstatic inline gf2_128_elt_t gf2_128_mul(gf2_128_elt_t x, gf2_128_elt_t y) {\n gf2_128_elt_t t1a = _mm_clmulepi64_si128(x, y, 0x01);\n gf2_128_elt_t t1b = _mm_clmulepi64_si128(x, y, 0x10);\n gf2_128_elt_t t1 = gf2_128_add(t1a, t1b);\n gf2_128_elt_t t2 = _mm_clmulepi64_si128(x, y, 0x11);\n t1 = gf2_128_reduce(t1, t2);\n gf2_128_elt_t t0 = _mm_clmulepi64_si128(x, y, 0x00);\n t0 = gf2_128_reduce(t0, t1);\n return t0;\n}\n} // namespace proofs\n#elif defined(__aarch64__)\n//\n// Implementation for arm/neon with AES instructions.\n// We assume that __aarch64__ implies AES, which isn't necessarily\n// the case. If this is a problem, change the defined(__aarch64__)\n// above and the code will fall back to the non-AES implementation\n// below.\n//\n#include // IWYU pragma: keep\n\nnamespace proofs {\nusing gf2_128_elt_t = poly64x2_t;\n\nstatic inline std::array uint64x2_of_gf2_128(gf2_128_elt_t x) {\n return std::array{static_cast(x[0]),\n static_cast(x[1])};\n}\n\nstatic inline gf2_128_elt_t gf2_128_of_uint64x2(\n const std::array &x) {\n return gf2_128_elt_t{static_cast(x[0]),\n static_cast(x[1])};\n}\n\nstatic inline gf2_128_elt_t vmull_low(gf2_128_elt_t t0, gf2_128_elt_t t1) {\n poly64_t tt0 = vgetq_lane_p64(t0, 0);\n poly64_t tt1 = vgetq_lane_p64(t1, 0);\n return vreinterpretq_p64_p128(vmull_p64(tt0, tt1));\n}\nstatic inline gf2_128_elt_t vmull_high(gf2_128_elt_t t0, gf2_128_elt_t t1) {\n return vreinterpretq_p64_p128(vmull_high_p64(t0, t1));\n}\n\n// return t0 + x^64 * t1\nstatic inline gf2_128_elt_t gf2_128_reduce(gf2_128_elt_t t0, gf2_128_elt_t t1) {\n const gf2_128_elt_t poly = {0x0, 0x87};\n const gf2_128_elt_t zero = {0x0, 0x0};\n t0 = vaddq_p64(t0, vextq_p64(zero, t1, 1));\n t0 = vaddq_p64(t0, vmull_high(t1, poly));\n return t0;\n}\nstatic inline gf2_128_elt_t gf2_128_add(gf2_128_elt_t x, gf2_128_elt_t y) {\n return vaddq_p64(x, y);\n}\nstatic inline gf2_128_elt_t gf2_128_mul(gf2_128_elt_t x, gf2_128_elt_t y) {\n gf2_128_elt_t swx = vextq_p64(x, x, 1);\n gf2_128_elt_t t1a = vmull_high(swx, y);\n gf2_128_elt_t t1b = vmull_low(swx, y);\n gf2_128_elt_t t1 = vaddq_p64(t1a, t1b);\n gf2_128_elt_t t2 = vmull_high(x, y);\n t1 = gf2_128_reduce(t1, t2);\n gf2_128_elt_t t0 = vmull_low(x, y);\n t0 = gf2_128_reduce(t0, t1);\n return t0;\n}\n} // namespace proofs\n\n#elif defined(__arm__) || defined(__aarch64__)\n//\n// Implementation for arm/neon without AES instructions\n//\n#include // IWYU pragma: keep\n\nnamespace proofs {\nusing gf2_128_elt_t = poly64x2_t;\n\nstatic inline std::array uint64x2_of_gf2_128(gf2_128_elt_t x) {\n return std::array{static_cast(x[0]),\n static_cast(x[1])};\n}\n\nstatic inline gf2_128_elt_t gf2_128_of_uint64x2(\n const std::array &x) {\n return gf2_128_elt_t{static_cast(x[0]),\n static_cast(x[1])};\n}\n\nstatic inline gf2_128_elt_t gf2_128_add(gf2_128_elt_t x, gf2_128_elt_t y) {\n return vaddq_p64(x, y);\n}\n\n// Emulate vmull_p64() with vmull_p8().\n//\n// This emulation is pretty naive and it performs a lot of permutations.\n//\n// A possibly better alternative appears in Danilo Câmara, Conrado\n// Gouvêa, Julio López, Ricardo Dahab, \"Fast Software Polynomial\n// Multiplication on ARM Processors Using the NEON Engine\", 1st\n// Cross-Domain Conference and Workshop on Availability, Reliability,\n// and Security in Information Systems (CD-ARES), Sep 2013,\n// Regensburg, Germany. pp.137-154. ⟨hal-01506572⟩\n//\n// However, the code from that paper makes heavy use of type\n// punning of 128-bit registers as two 64-bit registers, which\n// I don't know how to express in C.\nstatic inline poly8x16_t pmul64x8(poly8x8_t x, poly8_t y) {\n const poly8x16_t zero{};\n poly8x16_t prod = vmull_p8(x, vdup_n_p8(y));\n poly8x16x2_t uzp = vuzpq_p8(prod, zero);\n return vaddq_p8(uzp.val[0], vextq_p8(uzp.val[1], uzp.val[1], 15));\n}\n\n// multiply/add. Return (cout, s) = cin + x * y where the final sum\n// would be (cout << 8) + s.\nstatic inline poly8x16x2_t pmac64x8(poly8x16_t cin, poly8x8_t x, poly8_t y) {\n const poly8x16_t zero{};\n poly8x16_t prod = vmull_p8(x, vdup_n_p8(y));\n poly8x16x2_t uzp = vuzpq_p8(prod, zero);\n uzp.val[0] = vaddq_p8(uzp.val[0], cin);\n return uzp;\n}\n\nstatic inline poly8x16_t pmul64x64(poly8x8_t x, poly8x8_t y) {\n poly8x16_t r{};\n\n poly8x16x2_t prod = pmac64x8(r, x, y[0]);\n r = prod.val[0];\n\n prod = pmac64x8(prod.val[1], x, y[1]);\n r = vaddq_p8(r, vextq_p8(prod.val[0], prod.val[0], 15));\n\n prod = pmac64x8(prod.val[1], x, y[2]);\n r = vaddq_p8(r, vextq_p8(prod.val[0], prod.val[0], 14));\n\n prod = pmac64x8(prod.val[1], x, y[3]);\n r = vaddq_p8(r, vextq_p8(prod.val[0], prod.val[0], 13));\n\n prod = pmac64x8(prod.val[1], x, y[4]);\n r = vaddq_p8(r, vextq_p8(prod.val[0], prod.val[0], 12));\n\n prod = pmac64x8(prod.val[1], x, y[5]);\n r = vaddq_p8(r, vextq_p8(prod.val[0], prod.val[0], 11));\n\n prod = pmac64x8(prod.val[1], x, y[6]);\n r = vaddq_p8(r, vextq_p8(prod.val[0], prod.val[0], 10));\n\n prod = pmac64x8(prod.val[1], x, y[7]);\n r = vaddq_p8(r, vextq_p8(prod.val[0], prod.val[0], 9));\n r = vaddq_p8(r, vextq_p8(prod.val[1], prod.val[1], 8));\n\n return r;\n}\n\nstatic inline gf2_128_elt_t vmull_low(gf2_128_elt_t t0, gf2_128_elt_t t1) {\n // vreinterpretq_p64_p8() seems not to be defined, use\n // static_cast\n return static_cast(pmul64x64(vget_low_p8(t0), vget_low_p8(t1)));\n}\nstatic inline gf2_128_elt_t vmull_high(gf2_128_elt_t t0, gf2_128_elt_t t1) {\n return static_cast(pmul64x64(vget_high_p8(t0), vget_high_p8(t1)));\n}\n\n// vextq_p64() seems not to be defined.\nstatic inline gf2_128_elt_t vextq_p64_1_emul(gf2_128_elt_t t0,\n gf2_128_elt_t t1) {\n return static_cast(\n vextq_p8(static_cast(t0), static_cast(t1), 8));\n}\n\n// return t0 + x^64 * t1\nstatic inline gf2_128_elt_t gf2_128_reduce(gf2_128_elt_t t0, gf2_128_elt_t t1) {\n const poly8_t poly = static_cast(0x87);\n const gf2_128_elt_t zero = {0x0, 0x0};\n t0 = vaddq_p64(t0, vextq_p64_1_emul(zero, t1));\n t0 = vaddq_p64(t0, pmul64x8(vget_high_p8(t1), poly));\n return t0;\n}\n\nstatic inline gf2_128_elt_t gf2_128_mul(gf2_128_elt_t x, gf2_128_elt_t y) {\n gf2_128_elt_t swx = vextq_p64_1_emul(x, x);\n gf2_128_elt_t t1a = vmull_high(swx, y);\n gf2_128_elt_t t1b = vmull_low(swx, y);\n gf2_128_elt_t t1 = vaddq_p64(t1a, t1b);\n gf2_128_elt_t t2 = vmull_high(x, y);\n t1 = gf2_128_reduce(t1, t2);\n gf2_128_elt_t t0 = vmull_low(x, y);\n t0 = gf2_128_reduce(t0, t1);\n return t0;\n}\n\n} // namespace proofs\n#else\n#error \"unimplemented gf2k/sysdep.h\"\n#endif\n\n#endif // PRIVACY_PROOFS_ZK_LIB_GF2K_SYSDEP_H_\n"], ["/longfellow-zk/lib/circuits/compiler/node.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_NODE_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_NODE_H_\n\n#include \n#include \n\n#include \n#include \n\n#include \"sumcheck/quad.h\"\n#include \"util/crc64.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n\nstruct term {\n // size_t surrogate for storing things like depth and\n // pointers to nodes, since we only really need 32 bits.\n using size_t_for_storage = uint32_t;\n\n size_t_for_storage ki; // index of the constant term into constants_[]\n size_t_for_storage op0, op1;\n\n term() = default;\n\n // canonicalized by op0 <= op1\n explicit term(size_t ki, size_t op0, size_t op1)\n : ki(ki),\n op0(std::min(op0, op1)),\n op1(std::max(op0, op1)) {\n // Terms with k=0 are not supposed to occur, since\n // we represent a zero node as an empty list of terms.\n // We represent Elt(0) as index ki=0 in the table of constants.\n proofs::check(ki != 0, \"ki != 0\");\n }\n\n // special hack for assert0\n struct assert0_type_hack {}; // so that we don't call this constructor\n // accidentally\n explicit term(size_t op, assert0_type_hack& hack)\n : ki(/*kstore(f.zero())=*/0), op0(0), op1(op) {}\n\n bool ltndx(const term& y) const {\n if (op1 < y.op1) return true;\n if (op1 > y.op1) return false;\n return op0 < y.op0;\n }\n bool eqndx(const term& y) const { return (op1 == y.op1 && op0 == y.op0); }\n\n // term is a constant\n bool constant() const { return op0 == 0 && op1 == 0; }\n\n // linear term k * (1 * op1)\n bool linearp() const { return op0 == 0; }\n\n bool operator==(const term& y) const {\n return ki == y.ki && op0 == y.op0 && op1 == y.op1;\n }\n};\n\ntemplate \nstruct NodeInfoF {\n using quad_corner_t = typename Quad::quad_corner_t;\n using size_t_for_storage = term::size_t_for_storage;\n\n static const constexpr quad_corner_t kWireIdUndefined = quad_corner_t(-1);\n\n size_t_for_storage depth;\n quad_corner_t desired_wire_id_for_input;\n quad_corner_t desired_wire_id_for_output;\n size_t_for_storage max_needed_depth;\n bool is_needed;\n bool is_output;\n bool is_input;\n bool is_assert0;\n\n NodeInfoF()\n : depth(0),\n desired_wire_id_for_input(kWireIdUndefined),\n desired_wire_id_for_output(kWireIdUndefined),\n max_needed_depth(0),\n is_needed(false),\n is_output(false),\n is_input(false),\n is_assert0(false) {}\n\n // we use the desired wire id only at the appropriate depth,\n // and not e.g. for copy wires.\n quad_corner_t desired_wire_id(size_t depth0, size_t depth_ub) const {\n if (is_input && depth0 == 0) {\n return desired_wire_id_for_input;\n }\n if (is_output && depth0 + 1 == depth_ub) {\n return desired_wire_id_for_output;\n }\n return kWireIdUndefined;\n }\n};\n\ntemplate \nstruct NodeF {\n using nodeinfo = NodeInfoF;\n using quad_corner_t = typename Quad::quad_corner_t;\n\n std::vector terms;\n nodeinfo info;\n\n NodeF() = delete;\n explicit NodeF(quad_corner_t id) : terms() {\n info.is_input = true;\n info.desired_wire_id_for_input = id;\n }\n\n explicit NodeF(size_t ki, size_t op0, size_t op1) : terms() {\n if (ki != 0) {\n terms.push_back(term(ki, op0, op1));\n }\n }\n\n explicit NodeF(const std::vector& terms) : terms(terms) {}\n\n bool zero() const { return !info.is_input && terms.empty(); }\n bool constant() const { return terms.size() == 1 && terms[0].constant(); }\n bool linearp() const { return terms.size() == 1 && terms[0].linearp(); }\n\n bool operator==(const NodeF& y) const {\n if (info.is_input != y.info.is_input) return false;\n if (info.desired_wire_id_for_input != y.info.desired_wire_id_for_input)\n return false;\n if (info.is_output != y.info.is_output) return false;\n if (info.desired_wire_id_for_output != y.info.desired_wire_id_for_output)\n return false;\n if (info.is_input != y.info.is_input) return false;\n if (terms.size() != y.terms.size()) return false;\n size_t l = terms.size();\n for (size_t i = 0; i < l; ++i) {\n if (!(terms[i] == y.terms[i])) return false;\n }\n return true;\n }\n uint64_t hash() const {\n uint64_t crc = 0x1;\n crc = crc64::update(crc,\n static_cast(info.desired_wire_id_for_input));\n crc = crc64::update(crc,\n static_cast(info.desired_wire_id_for_output));\n crc = crc64::update(crc, info.is_input);\n crc = crc64::update(crc, info.is_output);\n size_t l = terms.size();\n crc = crc64::update(crc, l);\n for (size_t i = 0; i < l; ++i) {\n crc = crc64::update(crc, terms[i].ki);\n crc = crc64::update(crc, terms[i].op0);\n crc = crc64::update(crc, terms[i].op1);\n }\n return crc;\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_NODE_H_\n"], ["/longfellow-zk/lib/algebra/limb.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_LIMB_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_LIMB_H_\n\n#include \n#include \n#include \n\n#include \"util/serialization.h\"\n\nnamespace proofs {\n\n// Base class for representing bignum or bigpoly as arrays of\n// machine-dependent \"limbs\". The serialization is in this\n// class; arithmetic is in subclasses.\n\ntemplate \nclass Limb {\n public:\n using T = Limb;\n\n#if __WORDSIZE == 64\n using limb_t = uint64_t;\n#else\n using limb_t = uint32_t;\n#endif\n\n // sizes in bytes, bits, limbs, uint64_t\n static constexpr size_t kBytes = 8 * W64;\n static constexpr size_t kBits = 64 * W64;\n static constexpr size_t kLimbs = kBytes / sizeof(limb_t);\n static constexpr size_t kU64 = W64;\n static constexpr size_t kBitsPerLimb = 8 * sizeof(limb_t);\n\n // no rounding allowed\n static_assert(kLimbs * sizeof(limb_t) == kBytes);\n\n limb_t limb_[kLimbs];\n\n Limb() = default; // uninitialized\n explicit Limb(uint64_t x) : limb_{} { assign(limb_, 1, &x); }\n\n explicit Limb(const std::array& a) : limb_{} {\n assign(limb_, kU64, &a[0]);\n }\n\n std::array u64() const {\n std::array a;\n unassign(limb_, kU64, &a[0]);\n return a;\n }\n\n void to_bytes(uint8_t a[/* kBytes */]) const {\n for (size_t i = 0; i < kLimbs; ++i) {\n a = to_bytes(&limb_[i], a);\n }\n }\n\n bool operator==(const T& other) const {\n for (size_t i = 0; i < kLimbs; ++i) {\n if (limb_[i] != other.limb_[i]) {\n return false;\n }\n }\n return true;\n }\n bool operator!=(const T& other) const { return !(operator==(other)); }\n\n // Shift right by z. Return the bits that fall off\n // the edge.\n limb_t shiftr(size_t z) {\n limb_t c = 0;\n for (size_t i = kLimbs; i-- > 0;) {\n limb_t d = limb_[i];\n limb_[i] = c | (d >> z);\n c = d << (kBitsPerLimb - z);\n }\n return c;\n }\n\n // Returns the pos-th bit in the representation of this nat.\n limb_t bit(size_t pos) const {\n size_t ind = pos / kBitsPerLimb;\n if (ind < kLimbs) {\n size_t off = pos % kBitsPerLimb;\n return (limb_[ind] >> off) & 0x1u;\n }\n return 0;\n }\n\n protected:\n static void assign(uint64_t d[], size_t ns, const uint64_t s[/*ns*/]) {\n for (size_t i = 0; i < ns; ++i) {\n d[i] = s[i];\n }\n }\n\n static void assign(uint32_t d[], size_t ns, const uint64_t s[/*ns*/]) {\n for (size_t i = 0; i < ns; ++i) {\n d[2 * i] = static_cast(s[i]);\n d[2 * i + 1] = static_cast(s[i] >> 32);\n }\n }\n\n static void unassign(const uint64_t d[], size_t ns, uint64_t s[/*ns*/]) {\n for (size_t i = 0; i < ns; ++i) {\n s[i] = d[i];\n }\n }\n\n static void unassign(const uint32_t d[], size_t ns, uint64_t s[/*ns*/]) {\n for (size_t i = 0; i < ns; ++i) {\n s[i] = d[2 * i] | (static_cast(d[2 * i + 1]) << 32);\n }\n }\n\n static const uint8_t* of_bytes(uint64_t* r, const uint8_t* a) {\n *r = u64_of_le(a);\n return a + 8;\n }\n static const uint8_t* of_bytes(uint32_t* r, const uint8_t* a) {\n *r = u32_of_le(a);\n return a + 4;\n }\n\n static uint8_t* to_bytes(const uint64_t* r, uint8_t* a) {\n u64_to_le(a, *r);\n return a + 8;\n }\n static uint8_t* to_bytes(const uint32_t* r, uint8_t* a) {\n u32_to_le(a, *r);\n return a + 4;\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_LIMB_H_\n"], ["/longfellow-zk/lib/ligero/ligero_verifier.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_VERIFIER_H_\n#define PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_VERIFIER_H_\n\n#include \n\n#include \n#include \n\n#include \"algebra/blas.h\"\n#include \"ligero/ligero_param.h\"\n#include \"ligero/ligero_transcript.h\"\n#include \"merkle/merkle_commitment.h\"\n#include \"random/transcript.h\"\n#include \"util/crypto.h\"\n\nnamespace proofs {\ntemplate \nclass LigeroVerifier {\n using Elt = typename Field::Elt;\n\n public:\n static void receive_commitment(const LigeroCommitment& commitment,\n Transcript& ts) {\n // P -> V\n LigeroTranscript::write_commitment(commitment, ts);\n }\n\n static bool verify(const char** why, const LigeroParam& p,\n const LigeroCommitment& commitment,\n const LigeroProof& proof, Transcript& ts, size_t nl,\n size_t nllterm,\n const LigeroLinearConstraint llterm[/*nllterm*/],\n const LigeroHash& hash_of_llterm, const Elt b[/*nl*/],\n const LigeroQuadraticConstraint lqc[/*nq*/],\n const InterpolatorFactory& interpolator, const Field& F) {\n if (why == nullptr) {\n return false;\n }\n\n std::vector u_ldt(p.nwqrow);\n std::vector alphal(nl);\n std::vector> alphaq(p.nq);\n std::vector u_quad(p.nqtriples);\n std::vector idx(p.nreq);\n\n // Replay the protocol first in order to compute all the\n // challenges. In particular, we need IDX before we can do\n // anything useful.\n\n // P -> V\n ts.write(hash_of_llterm.bytes, hash_of_llterm.kLength);\n\n // V -> P\n LigeroTranscript::gen_uldt(&u_ldt[0], p, ts, F);\n\n // V -> P\n LigeroTranscript::gen_alphal(nl, &alphal[0], ts, F);\n LigeroTranscript::gen_alphaq(&alphaq[0], p, ts, F);\n\n // V -> P\n LigeroTranscript::gen_uquad(&u_quad[0], p, ts, F);\n\n // P -> V\n ts.write(&proof.y_ldt[0], 1, p.block, F);\n ts.write(&proof.y_dot[0], 1, p.dblock, F);\n ts.write(&proof.y_quad_0[0], 1, p.r, F);\n ts.write(&proof.y_quad_2[0], 1, p.dblock - p.block, F);\n\n // V -> P\n LigeroTranscript::gen_idx(&idx[0], p, ts, F);\n\n if (!merkle_check(p, commitment, proof, &idx[0], F)) {\n *why = \"merkle_check failed\";\n return false;\n }\n\n if (!low_degree_check(p, proof, &idx[0], &u_ldt[0], interpolator, F)) {\n *why = \"low_degree_check failed\";\n return false;\n }\n\n {\n // linear check\n std::vector A(p.nwqrow * p.w);\n\n LigeroCommon::inner_product_vector(&A[0], p, nl, nllterm, llterm,\n &alphal[0], lqc, &alphaq[0], F);\n\n if (!dot_check(p, proof, &idx[0], &A[0], interpolator, F)) {\n *why = \"dot_check failed\";\n return false;\n }\n\n // check the putative value of the inner product\n Elt want_dot = Blas::dot(nl, b, 1, &alphal[0], 1, F);\n Elt proof_dot = Blas::dot1(p.w, &proof.y_dot[p.r], 1, F);\n if (want_dot != proof_dot) {\n *why = \"wrong dot product\";\n return false;\n }\n }\n\n if (!quadratic_check(p, proof, &idx[0], &u_quad[0], interpolator, F)) {\n *why = \"quadratic_check failed\";\n return false;\n }\n\n *why = \"ok\";\n return true;\n }\n\n private:\n static void interpolate_req_columns(Elt yp[/*nreq*/],\n const LigeroParam& p, size_t ylen,\n const Elt y[/*ylen*/],\n const size_t idx[/*nreq*/],\n const InterpolatorFactory& interpolator,\n const Field& F) {\n const auto interpy = interpolator.make(ylen, p.block_enc);\n std::vector yext(p.block_enc);\n Blas::copy(ylen, &yext[0], 1, y, 1);\n interpy->interpolate(&yext[0]);\n Blas::gather(p.nreq, &yp[0], &yext[p.dblock], idx);\n }\n\n static bool merkle_check(const LigeroParam& p,\n const LigeroCommitment& commitment,\n const LigeroProof& proof,\n const size_t idx[/*nreq*/], const Field& F) {\n auto updhash = [&](size_t r, SHA256& sha) {\n LigeroCommon::column_hash(p.nrow, &proof.req_at(0, r), p.nreq, sha,\n F);\n };\n\n return MerkleCommitmentVerifier::verify(p.block_enc - p.dblock,\n commitment.root, proof.merkle, idx,\n p.nreq, updhash);\n }\n\n static bool low_degree_check(const LigeroParam& p,\n const LigeroProof& proof,\n const size_t idx[/*nreq*/],\n const Elt u_ldt[/*nrow*/],\n const InterpolatorFactory& interpolator,\n const Field& F) {\n std::vector yc(p.nreq);\n\n // the ILDT blinding row with coefficient 1\n Blas::copy(p.nreq, &yc[0], 1, &proof.req_at(p.ildt, 0), 1);\n\n // all remaining rows with coefficient u_ldt[]\n for (size_t i = 0; i < p.nwqrow; ++i) {\n Blas::axpy(p.nreq, &yc[0], 1, u_ldt[i], &proof.req_at(i + p.iw, 0),\n 1, F);\n }\n\n std::vector yp(p.nreq);\n interpolate_req_columns(&yp[0], p, p.block, &proof.y_ldt[0], idx,\n interpolator, F);\n\n if (!Blas::equal(p.nreq, &yp[0], 1, &yc[0], 1, F)) {\n return false;\n }\n\n return true;\n }\n\n static bool dot_check(const LigeroParam& p,\n const LigeroProof& proof,\n const size_t idx[/*nreq*/], const Elt A[/*nwqrow, w*/],\n const InterpolatorFactory& interpolator,\n const Field& F) {\n std::vector yc(p.nreq);\n\n // the IDOT blinding row with coefficient 1\n Blas::copy(p.nreq, &yc[0], 1, &proof.req_at(p.idot, 0), 1);\n\n {\n const auto interpA = interpolator.make(p.block, p.block_enc);\n\n std::vector Aext(p.block_enc);\n std::vector Areq(p.nreq);\n\n for (size_t i = 0; i < p.nwqrow; ++i) {\n LigeroCommon::layout_Aext(&Aext[0], p, i, &A[0], F);\n interpA->interpolate(&Aext[0]);\n Blas::gather(p.nreq, &Areq[0], &Aext[p.dblock], idx);\n\n // Accumulate z += A[j] \\otimes W[j].\n Blas::vaxpy(p.nreq, &yc[0], 1, &Areq[0], 1,\n &proof.req_at(i + p.iw, 0), 1, F);\n }\n }\n\n std::vector yp(p.nreq);\n interpolate_req_columns(&yp[0], p, p.dblock, &proof.y_dot[0], idx,\n interpolator, F);\n\n if (!Blas::equal(p.nreq, &yp[0], 1, &yc[0], 1, F)) {\n return false;\n }\n return true;\n }\n\n static bool quadratic_check(const LigeroParam& p,\n const LigeroProof& proof,\n const size_t idx[/*nreq*/],\n const Elt u_quad[/*nqtriples*/],\n const InterpolatorFactory& interpolator,\n const Field& F) {\n std::vector yc(p.nreq);\n\n // the IQUAD blinding row with coefficient 1\n Blas::copy(p.nreq, &yc[0], 1, &proof.req_at(p.iquad, 0), 1);\n\n {\n std::vector tmp(p.nreq);\n size_t iqx = p.iq;\n size_t iqy = iqx + p.nqtriples;\n size_t iqz = iqy + p.nqtriples;\n\n // all quadratic triples with coefficient u_ldt[]\n for (size_t i = 0; i < p.nqtriples; ++i) {\n // yc += u_quad[i] * (z[i] - x[i] * y[i])\n\n // tmp = z[i]\n Blas::copy(p.nreq, &tmp[0], 1, &proof.req_at(iqz + i, 0), 1);\n\n // tmp -= x[i] \\otimes y[i]\n Blas::vymax(p.nreq, &tmp[0], 1, &proof.req_at(iqx + i, 0), 1,\n &proof.req_at(iqy + i, 0), 1, F);\n\n // yc += u_quad[i] * tmp\n Blas::axpy(p.nreq, &yc[0], 1, u_quad[i], &tmp[0], 1, F);\n }\n }\n\n // reconstruct y_quad from the two parts in the proof\n std::vector yquad(p.dblock);\n Blas::copy(p.r, &yquad[0], 1, &proof.y_quad_0[0], 1);\n Blas::clear(p.w, &yquad[p.r], 1, F);\n Blas::copy(p.dblock - p.block, &yquad[p.block], 1,\n &proof.y_quad_2[0], 1);\n\n // interpolate y_quad at the opened columns\n std::vector yp(p.nreq);\n interpolate_req_columns(&yp[0], p, p.dblock, &yquad[0], idx, interpolator,\n F);\n\n if (!Blas::equal(p.nreq, &yp[0], 1, &yc[0], 1, F)) {\n return false;\n }\n return true;\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_VERIFIER_H_\n"], ["/longfellow-zk/lib/util/crypto.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_UTIL_CRYPTO_H_\n#define PRIVACY_PROOFS_ZK_LIB_UTIL_CRYPTO_H_\n\n// Encapsulates all of the cryptographic primitives used by this library.\n// Specifically, for the collision-resistant hash function, this library uses\n// SHA256. For a pseudo-random function, this library uses AES in ECB mode.\n// Finally, this library provides a method to generate random bytes using the\n// openssl library.\n\n#include \n#include \n#include \n\n#include \"util/panic.h\"\n#include \"openssl/sha.h\"\n#include \"openssl/evp.h\"\n#include \"openssl/aes.h\"\n\nnamespace proofs {\n\nconstexpr size_t kSHA256DigestSize = 32;\nconstexpr size_t kPRFKeySize = 32;\nconstexpr size_t kPRFInputSize = 16;\nconstexpr size_t kPRFOutputSize = 16;\n\nclass SHA256 {\n public:\n SHA256() { SHA256_Init(&sha_); }\n\n // Disable copy for good measure.\n SHA256(const SHA256&) = delete;\n SHA256& operator=(const SHA256&) = delete;\n\n void Update(const uint8_t bytes[/*n*/], size_t n) { SHA256_Update(&sha_, bytes, n); }\n void DigestData(uint8_t digest[/* kSHA256DigestSize */]) {\n SHA256_Final(digest, &sha_);\n }\n void CopyState(const SHA256& src) { sha_ = src.sha_; }\n\n void Update8(uint64_t x) {\n uint8_t buf[8];\n for (size_t i = 0; i < 8; ++i) {\n buf[i] = x & 0xff;\n x >>= 8;\n }\n Update(buf, 8);\n }\n\n private:\n SHA256_CTX sha_;\n};\n\n// A pseudo-random function interface. This implementation uses AES in ECB mode.\n// The caller must ensure that arguments are not reused.\nclass PRF {\n public:\n explicit PRF(const uint8_t key[/*kPRFKeySize*/]) {\n ctx_ = EVP_CIPHER_CTX_new();\n int ret =\n EVP_EncryptInit_ex(ctx_, EVP_aes_256_ecb(), nullptr, key, nullptr);\n check(ret == 1, \"EVP_EncryptInit_ex failed\");\n }\n\n ~PRF() { EVP_CIPHER_CTX_free(ctx_); }\n\n // Disable copy for good measure.\n PRF(const PRF&) = delete;\n PRF& operator=(const PRF&) = delete;\n\n // Evaluate the PRF on the input and write the output to the output buffer.\n // This method should only be used internally by the Transcript class. The\n // caller must ensure that the input and output buffers are different.\n // This function implements a permutation, but we only need to exploit its\n // pseudo-random function property in this application.\n void Eval(uint8_t out[/*kPRFOutputSize*/], uint8_t in[/*kPRFInputSize*/]) {\n int out_len = static_cast(kPRFOutputSize);\n int ret = EVP_EncryptUpdate(ctx_, out, &out_len, in,\n static_cast(kPRFInputSize));\n check(ret == 1, \"EVP_EncryptUpdate failed\");\n }\n\n private:\n EVP_CIPHER_CTX* ctx_;\n};\n\n// Generate n random bytes, following the openssl API convention.\n// This method will panic if the openssl library fails.\nvoid rand_bytes(uint8_t out[/*n*/], size_t n);\n\nvoid hex_to_str(char out[/* 2*n + 1*/], const uint8_t in[/*n*/], size_t n);\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_UTIL_CRYPTO_H_\n"], ["/longfellow-zk/lib/random/random.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_RANDOM_RANDOM_H_\n#define PRIVACY_PROOFS_ZK_LIB_RANDOM_RANDOM_H_\n\n#include \n#include \n#include \n#include \n#include \n\n#include \"util/panic.h\"\n\nnamespace proofs {\n\n// Our protocols require random coins; this interface provides both prover\n// and verifier components with those coins. Re-implementing this interface\n// allows easily supporting the Fiat-Shamir transform, or for sampling using\n// a system provided RNG such as openssl.\nclass RandomEngine {\n public:\n virtual ~RandomEngine() = default;\n virtual void bytes(uint8_t* buf, size_t n) = 0; // pure virtual\n\n // Sample a random field element.\n // TODO [matteof 2025-02-07] Per RFC, we must mask off the high\n // bits, but this requires changes to the field interface.\n // Punt for now since the mask is all ones anyway.\n template \n typename Field::Elt elt(const Field& F) {\n // Expected constant time.\n uint8_t buf[Field::kBytes];\n for (;;) {\n bytes(buf, sizeof(buf));\n if (std::optional maybe = F.of_bytes_field(buf)) {\n return maybe.value();\n }\n }\n }\n\n template \n typename Field::Elt subfield_elt(const Field& F) {\n // Expected constant time.\n uint8_t buf[Field::kSubFieldBytes];\n for (;;) {\n bytes(buf, sizeof(buf));\n if (std::optional maybe = F.of_bytes_subfield(buf)) {\n return maybe.value();\n }\n }\n }\n\n // Convenience method to sample an array of random field elements.\n template \n void elt(typename Field::Elt e[/*n*/], size_t n, const Field& F) {\n for (size_t i = 0; i < n; ++i) e[i] = elt(F);\n }\n\n // the minimal bitmask such that (n & mask) == n\n size_t mask(size_t n) {\n size_t mask = 0;\n while ((n & mask) != n) {\n mask <<= 1;\n mask |= 1u;\n }\n return mask;\n }\n\n // random size_t < n\n size_t nat(size_t n) {\n check(n > 0, \"nat(0)\");\n\n // compute the minimum number of random bytes needed\n size_t l = 0;\n size_t nn = n;\n while (nn != 0) {\n nn >>= 8;\n ++l;\n }\n check(l <= sizeof(size_t), \"l <= sizeof(size_t)\");\n\n size_t msk = mask(n);\n size_t r;\n uint8_t buf[sizeof(size_t)];\n\n // rejection sampling\n do {\n // consume L random bytes\n bytes(buf, l);\n\n // little-endian read\n r = 0;\n for (size_t i = l; i-- > 0;) {\n r = (r << 8) | buf[i];\n }\n\n // mask off high bits\n r &= msk;\n } while (r >= n);\n\n return r;\n }\n\n // Choose K distinct random naturals in [0..N).\n // Textbook algorithm requiring O(N) space\n void choose(size_t res[/*k*/], size_t n, size_t k) {\n check(n >= k, \"n >= k\");\n\n std::vector A(n);\n for (size_t i = 0; i < n; ++i) {\n A[i] = i;\n }\n for (size_t i = 0; i < k; ++i) {\n size_t j = i + nat(n - i);\n std::swap(A[i], A[j]);\n res[i] = A[i];\n }\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_RANDOM_RANDOM_H_\n"], ["/longfellow-zk/lib/sumcheck/transcript_sumcheck.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_SUMCHECK_TRANSCRIPT_SUMCHECK_H_\n#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_TRANSCRIPT_SUMCHECK_H_\n\n#include \n\n#include \"arrays/affine.h\"\n#include \"arrays/dense.h\"\n#include \"random/transcript.h\"\n#include \"sumcheck/circuit.h\"\n\nnamespace proofs {\n/*\nFiat-Shamir abstraction for sumcheck protocol.\nThis class takes wraps a transcript object and provides the interface for\nsumcheck challenge and response.\n*/\ntemplate \nclass TranscriptSumcheck {\n using Elt = typename Field::Elt;\n using CPoly = typename Proof::CPoly;\n using WPoly = typename Proof::WPoly;\n static constexpr size_t kMaxBindings = Proof::kMaxBindings;\n\n public:\n explicit TranscriptSumcheck(Transcript& ts, const Field& F)\n : ts_(ts), f_(F) {}\n\n void write_input(const Dense* X) {\n // Write column by column to make it compatible with oracle.\n for (corner_t c = 0; c < X->n0_; ++c) {\n ts_.write(&X->v_[c], X->n0_, X->n1_, f_);\n }\n }\n\n void begin_circuit(Elt* Q, Elt* G) {\n ts_.elt(Q, kMaxBindings, f_);\n ts_.elt(G, kMaxBindings, f_);\n }\n\n void begin_layer(Elt& alpha, Elt& beta, size_t layer) {\n alpha = ts_.elt(f_);\n beta = ts_.elt(f_);\n }\n\n void write(const Elt e[/*n*/], size_t ince, size_t n) {\n ts_.write(e, ince, n, f_);\n }\n\n template \n Elt /*R*/ round(const Poly& poly) {\n write_poly(&poly);\n return ts_.elt(f_);\n }\n\n private:\n template \n void write_poly(const Poly* poly) {\n // Do not write the p(1) value to the transcript, as its value is\n // implied by the constraints, and we can omit it from the proof.\n for (size_t i = 0; i < Poly::kN; ++i) {\n if (i != 1) {\n ts_.write(poly->t_[i], f_);\n }\n }\n }\n Transcript& ts_;\n const Field& f_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_TRANSCRIPT_SUMCHECK_H_\n"], ["/longfellow-zk/lib/algebra/fft_interpolation.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FFT_INTERPOLATION_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FFT_INTERPOLATION_H_\n\n#include \n#include \n\n#include \n\n#include \"algebra/blas.h\"\n#include \"algebra/twiddle.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\ntemplate \nclass FFTInterpolation {\n using Elt = typename Field::Elt;\n\n // Know a0, a1 want b0, b1\n // Note winv = w^{-1}\n static void a0a1(const Elt* A, Elt* B, size_t s, const Elt& winv,\n const Field& F) {\n Elt x0 = A[0];\n Elt x1 = F.mulf(A[s], winv);\n B[0] = F.addf(x0, x1);\n B[s] = F.subf(x0, x1);\n }\n\n static void a0a1(const Elt* A, Elt* B, size_t s, const Field& F) {\n Elt x0 = A[0];\n Elt x1 = A[s];\n B[0] = F.addf(x0, x1);\n B[s] = F.subf(x0, x1);\n }\n\n // know b0, b1 want a0, a1\n static void b0b1(Elt* A, const Elt* B, size_t s, const Elt& w,\n const Field& F) {\n Elt x0 = F.mulf(F.half(), F.addf(B[0], B[s]));\n Elt x1 = F.mulf(F.half(), F.subf(B[0], B[s]));\n A[0] = x0;\n A[s] = F.mulf(x1, w);\n }\n\n static void b0b1_unscaled(Elt* A, const Elt* B, size_t s, const Elt& w,\n const Field& F) {\n Elt x0 = F.addf(B[0], B[s]);\n Elt x1 = F.subf(B[0], B[s]);\n A[0] = x0;\n A[s] = F.mulf(x1, w);\n }\n static void b0b1_unscaled(Elt* A, const Elt* B, size_t s, const Field& F) {\n Elt x0 = F.addf(B[0], B[s]);\n Elt x1 = F.subf(B[0], B[s]);\n A[0] = x0;\n A[s] = x1;\n }\n\n // know: a0 and b0, want a1 and b1\n // x0 = a0\n // x1 = a1 * w^{-1}\n // b0 = x0 + x1\n // b1 = x0 - x1\n static void a0b0(Elt* A, Elt* B, size_t s, const Elt& w, const Field& F) {\n Elt x0 = A[0];\n Elt x1 = F.subf(B[0], x0);\n A[s] = F.mulf(x1, w);\n B[s] = F.subf(x0, x1);\n }\n\n // know: a0 and b1, want a1 and b0\n // x0 = a0\n // x1 = a1 * w^{-1}\n // b0 = x0 + x1\n // b1 = x0 - x1\n static void a0b1(Elt* A, Elt* B, size_t s, const Elt& w, const Field& F) {\n Elt x0 = A[0];\n Elt x1 = F.subf(x0, B[s]);\n A[s] = F.mulf(x1, w);\n B[0] = F.addf(x0, x1);\n }\n\n // B -> A\n static void fftb(Elt A[/*n*/], const Elt B[/*n*/], size_t n,\n const Twiddle& roots, const Field& F) {\n for (size_t j = 0; j < n; ++j) {\n A[j] = B[j];\n }\n\n Elt scale = F.one();\n\n for (size_t m = n; m > 2;) {\n m /= 2;\n size_t ws = roots.order_ / (2 * m);\n for (size_t k = 0; k < n; k += 2 * m) {\n b0b1_unscaled(&A[k], &A[k], m, F); // j == 0\n for (size_t j = 1; j < m; ++j) {\n b0b1_unscaled(&A[k + j], &A[k + j], m, roots.w_[j * ws], F);\n }\n }\n F.mul(scale, F.half());\n }\n\n if (n >= 2) {\n for (size_t k = 0; k < n; k += 2) {\n b0b1_unscaled(&A[k], &A[k], 1, F);\n }\n F.mul(scale, F.half());\n }\n\n Blas::scale(n, A, 1, scale, F);\n }\n\n // A -> B\n static void fftf(const Elt A[/*n*/], Elt B[/*n*/], size_t n,\n const Twiddle& rootsinv, const Field& F) {\n for (size_t j = 0; j < n; ++j) {\n B[j] = A[j];\n }\n\n // m = 1\n if (n >= 2) {\n for (size_t k = 0; k < n; k += 2) {\n a0a1(&B[k], &B[k], 1, F);\n }\n }\n\n // m > 1\n for (size_t m = 2; m < n; m = 2 * m) {\n size_t ws = rootsinv.order_ / (2 * m);\n for (size_t k = 0; k < n; k += 2 * m) {\n a0a1(&B[k], &B[k], m, F); // j = 0\n for (size_t j = 1; j < m; ++j) {\n a0a1(&B[k + j], &B[k + j], m, rootsinv.w_[j * ws], F);\n }\n }\n }\n }\n\n static bool in_range(size_t j, size_t b0, size_t n, size_t k) {\n size_t b1 = b0 + (n - k);\n return (b0 <= j && j < b1) || (b0 <= j + n && j + n < b1);\n }\n\n // This is a generalization of the truncated FFT algorithm described\n // in Joris van der Hoeven, \"The Truncated Fourier Transform and\n // Applications\". See also the followup paper \"Notes on the\n // Truncated Fourier Transform\", also by Joris van der Hoeven.\n\n // Define arbitrarily an \"evaluation\" domain A and a \"coefficient\"\n // domain B. The \"forward\" FFT computes the cofficients B given\n // evaluations A, and the \"backward\" FFT computes the evaluations A\n // given the coefficients B. By convention, the evaluations A are in\n // bit-reversed order, and we put the 1/N normalization on\n // the backward side.\n\n // Given inputs\n //\n // A[j] for 0 <= j < k\n // B[j % n] for b0 <= j < b0 + (n - k)\n //\n // this function fills the rest of A[] and B[], so that at the\n // end B = fftf(A) and A = fftb(B).\n static void bidir(size_t n, Elt A[/*n*/], Elt B[/*n*/], size_t k, size_t b0,\n const Twiddle& roots, const Twiddle& rootsinv,\n Elt workspace[/*2*n*/], const Field& F) {\n check(k <= n, \"k <= n\");\n check(b0 < n, \"b0 < n\");\n\n if (k == 0) {\n fftb(A, B, n, roots, F);\n } else if (k == n) {\n fftf(A, B, n, rootsinv, F);\n } else if (n > 1) {\n size_t ws = roots.order_ / n;\n size_t n2 = n / 2;\n\n // allocate T from workspace\n Elt* T = workspace;\n workspace += n;\n\n if (k >= n2) {\n // first half A -> T\n fftf(A, &T[0], n2, rootsinv, F);\n\n // diagonal butterflies T <-> B\n for (size_t j = 0; j < n2; ++j) {\n if (in_range(j, b0, n, k)) {\n if (in_range(j + n2, b0, n, k)) {\n // can't happen because the range is < n2\n check(false, \"can't happen\");\n } else {\n a0b0(&T[j], &B[j], n2, roots.w_[j * ws], F);\n }\n } else {\n if (in_range(j + n2, b0, n, k)) {\n a0b1(&T[j], &B[j], n2, roots.w_[j * ws], F);\n } else {\n // done below\n }\n }\n }\n\n // second half A <-> T\n size_t bb0 = (b0 >= n2) ? (b0 - n2) : b0;\n bidir(n2, &A[n2], &T[n2], k - n2, bb0, roots, rootsinv, workspace, F);\n\n // forward butterflies T -> B\n for (size_t j = 0; j < n2; ++j) {\n if (in_range(j, b0, n, k)) {\n if (in_range(j + n2, b0, n, k)) {\n // can't happen because the range is < n2\n check(false, \"can't happen\");\n } else {\n // done above\n }\n } else {\n if (in_range(j + n2, b0, n, k)) {\n // done above\n } else {\n a0a1(&T[j], &B[j], n2, rootsinv.w_[j * ws], F);\n }\n }\n }\n } else {\n // backward butterflies B -> T\n for (size_t j = 0; j < n2; ++j) {\n if (in_range(j, b0, n, k)) {\n if (in_range(j + n2, b0, n, k)) {\n b0b1(&T[j], &B[j], n2, roots.w_[j * ws], F);\n } else {\n // done below\n }\n } else {\n // done below\n }\n }\n\n // first half A <-> T\n size_t bb0 = (b0 >= n2) ? (b0 - n2) : b0;\n bidir(n2, &A[0], &T[0], k, bb0, roots, rootsinv, workspace, F);\n\n // diagonal butterflies T <-> B\n for (size_t j = 0; j < n2; ++j) {\n if (in_range(j, b0, n, k)) {\n if (in_range(j + n2, b0, n, k)) {\n // done above\n } else {\n a0b0(&T[j], &B[j], n2, roots.w_[j * ws], F);\n }\n } else {\n if (in_range(j + n2, b0, n, k)) {\n a0b1(&T[j], &B[j], n2, roots.w_[j * ws], F);\n } else {\n // can't happen. Range is >= n2 so\n // either j or j+n2 is in range\n check(false, \"can't happen\");\n }\n }\n }\n\n // second half T -> A\n fftb(&A[n2], &T[n2], n2, roots, F);\n }\n }\n }\n\n public:\n static void interpolate(size_t n, Elt A[/*n*/], Elt B[/*n*/], size_t k,\n size_t b0, const Elt& omega_m, uint64_t m,\n const Field& F) {\n if (n > 1) {\n Elt omega_n = Twiddle::reroot(omega_m, m, n, F);\n Twiddle roots(n, omega_n, F);\n Twiddle rootsinv(n, F.invertf(omega_n), F);\n std::vector workspace(2 * n);\n bidir(n, A, B, k, b0, roots, rootsinv, &workspace[0], F);\n } else if (n == 1) {\n // Twiddle(n) fails because of vector of size 0.\n // Compute the answer directly.\n if (k == 0) {\n A[0] = B[0];\n } else {\n B[0] = A[0];\n }\n }\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FFT_INTERPOLATION_H_\n"], ["/longfellow-zk/lib/gf2k/lch14_reed_solomon.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_GF2K_LCH14_REED_SOLOMON_H_\n#define PRIVACY_PROOFS_ZK_LIB_GF2K_LCH14_REED_SOLOMON_H_\n\n#include \n\n#include \n#include \n#include \n\n#include \"gf2k/lch14.h\"\n\nnamespace proofs {\n\ntemplate \nclass LCH14ReedSolomon {\n using Elt = typename Field::Elt;\n\n // only works in binary fields\n static_assert(Field::kCharacteristicTwo);\n\n public:\n // We interpolate N points, assumed to be the evaluations at\n // F.of_scalar(i), 0 <= i < N, of a polynomial of degree C(fftn);\n\n // compute the \"coefficients\" under the assumption\n // that we know n_ evaluations and that the higher-order\n // (fftn - n_) \"coefficients\" are zero.\n for (size_t i = 0; i < n_; ++i) {\n C[i] = y[i];\n }\n for (size_t i = n_; i < fftn; ++i) {\n C[i] = f_.zero();\n }\n fft_.BidirectionalFFT(l, /*k=*/n_, &C[0]);\n\n // fill in the missing evaluations in the first coset, since we\n // already have the missing evaluations in C[[n_, (1< fft_;\n};\n\ntemplate \nclass LCH14ReedSolomonFactory {\n public:\n explicit LCH14ReedSolomonFactory(const Field& f) : f_(f) {}\n\n std::unique_ptr> make(size_t n, size_t m) const {\n return std::make_unique>(n, m, f_);\n }\n\n private:\n const Field& f_;\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_GF2K_LCH14_REED_SOLOMON_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_zk.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_ZK_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_ZK_H_\n\n#include \n#include \n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n// This package implements C interfaces that allow external programs to call\n// the zk mdoc-based prover and verifier.\n//\n// It also contains a helper method that produces a byte representation\n// of a circuit which verifies the mdoc with regards to specific properties,\n// for example age_over_18. The circuit generation can be run once, and the\n// result cached for subsequent use in the prover and verifier.\n\nenum CborAttributeType { kPrimitive, kString, kBytes, kDate, kInt };\n\n/* This struct allows a verifier to express which attribute and value the prover\n * must claim. */\ntypedef struct {\n uint8_t id[32];\n uint8_t value[64];\n size_t id_len, value_len;\n CborAttributeType type;\n} RequestedAttribute;\n\n// Return codes for the run_mdoc2_prover method.\ntypedef enum {\n MDOC_PROVER_SUCCESS = 0,\n MDOC_PROVER_NULL_INPUT,\n MDOC_PROVER_INVALID_INPUT,\n MDOC_PROVER_CIRCUIT_PARSING_FAILURE,\n MDOC_PROVER_HASH_PARSING_FAILURE,\n MDOC_PROVER_WITNESS_CREATION_FAILURE,\n MDOC_PROVER_GENERAL_FAILURE,\n MDOC_PROVER_MEMORY_ALLOCATION_FAILURE,\n MDOC_PROVER_INVALID_ZK_SPEC_VERSION,\n} MdocProverErrorCode;\n\n// Return codes for the run_mdoc2_verifier method.\ntypedef enum {\n MDOC_VERIFIER_SUCCESS = 0,\n MDOC_VERIFIER_CIRCUIT_PARSING_FAILURE,\n MDOC_VERIFIER_PROOF_TOO_SMALL,\n MDOC_VERIFIER_HASH_PARSING_FAILURE,\n MDOC_VERIFIER_SIGNATURE_PARSING_FAILURE,\n MDOC_VERIFIER_GENERAL_FAILURE,\n MDOC_VERIFIER_NULL_INPUT,\n MDOC_VERIFIER_INVALID_INPUT,\n MDOC_VERIFIER_ARGUMENTS_TOO_SMALL,\n MDOC_VERIFIER_ATTRIBUTE_NUMBER_MISMATCH,\n MDOC_VERIFIER_INVALID_ZK_SPEC_VERSION,\n} MdocVerifierErrorCode;\n\n// Return codes for the generate_circuit method.\ntypedef enum {\n CIRCUIT_GENERATION_SUCCESS = 0,\n CIRCUIT_GENERATION_NULL_INPUT,\n CIRCUIT_GENERATION_ZLIB_FAILURE,\n CIRCUIT_GENERATION_GENERAL_FAILURE,\n CIRCUIT_GENERATION_INVALID_ZK_SPEC_VERSION,\n} CircuitGenerationErrorCode;\n\n// This structure represents a version of ZK specification supported by this\n// library. It is passed into all the methods for circuit generation, running\n// the prover and verifier.\n// It allows us to version the specification of the ZK system. The prover and\n// the verifier are supposed to negotiate the version of the specification they\n// both support before executing digital credential presentment.\ntypedef struct {\n // The ZK system name and version- \"longfellow-libzk-v*\" for Google library.\n const char* system;\n // The hash of the compressed circuit (the way it's generated and passed to\n // prover/verifier)\n const char circuit_hash[65];\n // The number of attributes that the circuit supports.\n size_t num_attributes;\n // The version of the ZK specification.\n size_t version;\n} ZkSpecStruct;\n\nstatic const char kDefaultDocType[] = \"org.iso.18013.5.1.mDL\";\n\n// The run_mdoc2_prover method takes byte-oriented inputs that describe a\n// circuit, mdoc, the public key of the issuer for the mdoc, a transcript\n// for the mdoc request operation, an array of RequestedAttribute that\n// represents claims that you want to prove, and a 20-char representation of the\n// current time. It writes the proof and its length into the input parameter prf\n// and proof_len. It is the responsibility of the caller to later free the proof\n// memory. If the prover fails to produce a proof, e.g., because the mdoc is\n// invalid, or the now time does not satisfy the validFrom and validUntil\n// constraints, then the prover returns an error code.\n// The following lines document how attributes can be opened in ZK.\n// {(uint8_t *)\"family_name\", 11, (uint8_t *)\"Mustermann\", 10},\n// {(uint8_t *)\"height\", 6, (uint8_t *)\"\\x18\\xaf\", 2},\n// {(uint8_t *)\"birth_date\", 10, (uint8_t *)\"\\xD9\\x03\\xEC\\x6A\" \"1971-09-01\",\n// 14},\n// {(uint8_t *)\"issue_date\", 10, (uint8_t *)\"\\xD9\\x03\\xEC\\x6A\" \"2024-03-15\",\n// 14},\nMdocProverErrorCode run_mdoc_prover(\n const uint8_t* bcp, size_t bcsz, /* circuit data */\n const uint8_t* mdoc, size_t mdoc_len, /* full mdoc */\n const char* pkx, const char* pky, /* string rep of public key */\n const uint8_t* transcript, size_t tr_len, /* session transcript */\n const RequestedAttribute* attrs, size_t attrs_len,\n const char* now, /* time formatted as \"2023-11-02T09:00:00Z\" */\n uint8_t** prf, size_t* proof_len, const ZkSpecStruct* zk_spec_version);\n\n// The run_mdoc2_verifier method accepts a byte representation of the circuit,\n// the public key of the issuer, the transcript, an array of RequestedAttribute\n// that represents claims that you want to verify, and a 20-char representation\n// of the time, as well as the proof and its length.\nMdocVerifierErrorCode run_mdoc_verifier(\n const uint8_t* bcp, size_t bcsz, /* circuit data */\n const char* pkx, const char* pky, /* string rep of public key */\n const uint8_t* transcript, size_t tr_len, /* session transcript */\n const RequestedAttribute* attrs, size_t attrs_len,\n const char* now, /* time formatted as \"2023-11-02T09:00:00Z\" */\n const uint8_t* zkproof, size_t proof_len, const char* docType,\n const ZkSpecStruct* zk_spec_version);\n\n// Produces a compressed version of the circuit bytes for the specified number\n// of attributes.\nCircuitGenerationErrorCode generate_circuit(const ZkSpecStruct* zk_spec_version,\n uint8_t** cb, size_t* clen);\n\n// Produces an identifier for a pair of circuits (c_1, c_2) over (Fp256, f_128)\n// respectively. This method parses the input bytes into two circuits, computes\n// the circuit's ids of each, and then computes the SHA256 hash of the two ids.\n// This method is used to identify \"circuit bundles\" consisting of multiple\n// circuits.\nint circuit_id(uint8_t id[/*kSHA256DigestSize*/], const uint8_t* bcp,\n size_t bcsz, const ZkSpecStruct* zk_spec);\n\nenum { kNumZkSpecs = 12 };\n// This is a hardcoded list of all the ZK specifications supported by this\n// library. Every time a new breaking change is introduced in either the circuit\n// format or its interpretation, a new version must be added here.\n// It is possible to remove old versions, if we're sure that they are not used\n// by either provers of verifiers in the wild.\nextern const ZkSpecStruct kZkSpecs[kNumZkSpecs];\n\n// Returns a static pointer to the ZkSpecStruct that matches the given system\n// name and circuit hash. Returns nullptr if no matching ZkSpecStruct is found.\nconst ZkSpecStruct* find_zk_spec(const char* system_name,\n const char* circuit_hash);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_ZK_H_\n"], ["/longfellow-zk/lib/algebra/blas.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_BLAS_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_BLAS_H_\n\n// basic linear algebra subroutines\n#include \n\nnamespace proofs {\ntemplate \nclass Blas {\n public:\n using Elt = typename Field::Elt;\n\n // SUM_{i} x[i * incx].y[i * incy]\n static Elt dot(size_t n, const Elt x[/*n:incx*/], size_t incx,\n const Elt y[/*n:incy*/], size_t incy, const Field& F) {\n Elt r = F.zero();\n for (size_t i = 0; i < n; i++) {\n F.add(r, F.mulf(x[i * incx], y[i * incy]));\n }\n return r;\n }\n\n // SUM_{i} x[i * incx], or the dot product x^T * 1\n static Elt dot1(size_t n, const Elt x[/*n:incx*/], size_t incx,\n const Field& F) {\n Elt r = F.zero();\n for (size_t i = 0; i < n; ++i) {\n F.add(r, x[i * incx]);\n }\n return r;\n }\n\n // y = a*y\n static void scale(size_t n, Elt y[/*k:incy*/], size_t incy, const Elt a,\n const Field& F) {\n for (size_t i = 0; i < n; i++) {\n F.mul(y[i * incy], a);\n }\n }\n\n // y = a*x + y.\n static void axpy(size_t n, Elt y[/*k:incy*/], size_t incy, const Elt a,\n const Elt x[/*k:incx*/], size_t incx, const Field& F) {\n for (size_t i = 0; i < n; i++) {\n F.add(y[i * incy], F.mulf(x[i * incx], a));\n }\n }\n\n // nonstandard axpy() where A[] is itself an array\n static void vaxpy(size_t n, Elt y[/*k:incy*/], size_t incy,\n const Elt a[/*k:inca*/], size_t inca,\n const Elt x[/*k:incx*/], size_t incx, const Field& F) {\n for (size_t i = 0; i < n; i++) {\n F.add(y[i * incy], F.mulf(x[i * incx], a[i * inca]));\n }\n }\n\n // y[i] -= a[i] * x[i]\n static void vymax(size_t n, Elt y[/*k:incy*/], size_t incy,\n const Elt a[/*k:inca*/], size_t inca,\n const Elt x[/*k:incx*/], size_t incx, const Field& F) {\n for (size_t i = 0; i < n; i++) {\n F.sub(y[i * incy], F.mulf(x[i * incx], a[i * inca]));\n }\n }\n\n static bool equal(size_t n, const Elt x[/*n:incx*/], size_t incx,\n const Elt y[/*n:incy*/], size_t incy, const Field& F) {\n for (size_t i = 0; i < n; i++) {\n if (x[i * incx] != y[i * incy]) return false;\n }\n return true;\n }\n\n static bool equal0(size_t n, const Elt x[/*n:incx*/], size_t incx,\n const Field& F) {\n for (size_t i = 0; i < n; i++) {\n if (x[i * incx] != F.zero()) return false;\n }\n return true;\n }\n\n static void copy(size_t n, Elt dst[/*n:incx*/], size_t incd,\n const Elt src[/*n:incy*/], size_t incs) {\n for (size_t i = 0; i < n; i++) {\n dst[i * incd] = src[i * incs];\n }\n }\n\n // DST[i] = SRC[IDX[i]]. DST and SRC must not overlap.\n static void gather(size_t n, Elt dst[/*n*/], const Elt src[],\n const size_t idx[/*n*/]) {\n for (size_t i = 0; i < n; i++) {\n dst[i] = src[idx[i]];\n }\n }\n\n static void clear(size_t n, Elt dst[/*n:incx*/], size_t incd,\n const Field& F) {\n for (size_t i = 0; i < n; i++) {\n dst[i * incd] = F.zero();\n }\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_BLAS_H_\n"], ["/longfellow-zk/lib/circuits/compiler/circuit_id.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_CIRCUIT_ID_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_CIRCUIT_ID_H_\n\n#include \n\n#include \n\n#include \"circuits/compiler/circuit_id.h\"\n#include \"sumcheck/circuit.h\"\n#include \"util/crypto.h\"\n\nnamespace proofs {\n\n// This method produces a unique name for a circuit. It does not match\n// the serialization method for the circuit.\ntemplate \nvoid circuit_id(uint8_t id[/*32*/], const Circuit& c, const Field& F) {\n const uint64_t CHAR2 = 0x2;\n const uint64_t ODD = 0x1;\n SHA256 sha;\n uint8_t tmp[Field::kBytes];\n if (F.kCharacteristicTwo) {\n // Characteristic two fields are uniquely determined by their length\n // in our codebase.\n sha.Update8(CHAR2); // Indicates binary field.\n sha.Update8(F.kBits);\n } else {\n // Prime fields are determined by -1.\n sha.Update8(ODD); // Indicates odd prime field.\n F.to_bytes_field(tmp, F.mone());\n sha.Update(tmp, sizeof(tmp));\n }\n sha.Update8(c.nv);\n sha.Update8(c.logv);\n sha.Update8(c.nc);\n sha.Update8(c.logc);\n sha.Update8(c.nl);\n sha.Update8(c.ninputs);\n sha.Update8(c.npub_in);\n sha.Update8(c.subfield_boundary);\n for (const auto& layer : c.l) {\n sha.Update8(layer.nw);\n sha.Update8(layer.logw);\n sha.Update8(layer.quad->n_);\n for (size_t i = 0; i < layer.quad->n_; ++i) {\n sha.Update8(static_cast(layer.quad->c_[i].g));\n sha.Update8(static_cast(layer.quad->c_[i].h[0]));\n sha.Update8(static_cast(layer.quad->c_[i].h[1]));\n F.to_bytes_field(tmp, layer.quad->c_[i].v);\n sha.Update(tmp, sizeof(tmp));\n }\n }\n sha.DigestData(id);\n}\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_CIRCUIT_ID_H_\n"], ["/longfellow-zk/lib/merkle/merkle_tree.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_MERKLE_MERKLE_TREE_H_\n#define PRIVACY_PROOFS_ZK_LIB_MERKLE_MERKLE_TREE_H_\n\n#include \n#include \n\n#include \n#include \n\n#include \"util/crypto.h\"\n#include \"util/panic.h\"\n\nnamespace proofs {\n\n// This package computes and verifies Merkle Tree inclusion claims.\n// The standard Merkle tree algorithm has been implemented.\n\n// A digest of a Merkle tree.\nstruct Digest {\n static constexpr size_t kLength = kSHA256DigestSize;\n uint8_t data[kLength];\n\n bool operator==(const Digest& y) const {\n return memcmp(data, y.data, kLength) == 0;\n }\n\n static Digest hash2(const Digest& L, const Digest& R) {\n SHA256 sha;\n sha.Update(L.data, kLength);\n sha.Update(R.data, kLength);\n Digest output;\n sha.DigestData(output.data);\n return output;\n }\n};\n\n// Return the length of the proof for N leaves.\n// Mimic the code in generate_proof() without actually\n// computing the proof\ninline size_t merkle_tree_len(size_t n) {\n size_t r = 1;\n size_t pos = (n - 1); // maximum possible value\n for (pos += n; pos > 1; pos >>= 1) {\n ++r;\n }\n return r;\n}\n\n// compute the set of all nodes on the path from the\n// root to any leaf in POS.\ninline std::vector compressed_merkle_proof_tree(size_t n,\n const size_t pos[/*np*/],\n size_t np) {\n check(np > 0, \"A Merkle proof with 0 leaves is not defined.\");\n std::vector tree(2 * n, false);\n\n // leaves are in TREE\n for (size_t ip = 0; ip < np; ++ip) {\n check(pos[ip] < n, \"Invalid position for leaf in Merkle tree\");\n tree[pos[ip] + n] = true;\n }\n\n // If a child of an inner node is in TREE, then the parent is in TREE.\n for (size_t i = n; i-- > 1;) {\n tree[i] = (tree[2 * i] || tree[2 * i + 1]);\n }\n\n // Assert that the root is in TREE.\n check(tree[1], \"tree[1]\");\n\n return tree;\n}\n\nclass MerkleTree {\n public:\n explicit MerkleTree(size_t n) : n_(n), layers_(2 * n) {}\n\n void set_leaf(size_t pos, const Digest& leaf) {\n check(pos < n_, \"Invalid position for leaf in Merkle tree\");\n layers_[pos + n_] = leaf;\n }\n\n Digest build_tree() {\n for (size_t i = n_; i-- > 1;) {\n layers_[i] = Digest::hash2(layers_[2 * i], layers_[2 * i + 1]);\n }\n return layers_[1];\n }\n\n // The generate_proof method writes a Merkle tree proof for the leaf\n // at position pos into the proof array and returns the size of the proof\n // in number of Digests.\n size_t generate_proof(Digest proof[/*logn+1*/], size_t pos) const {\n Digest* begin = proof;\n *proof++ = layers_[pos + n_];\n for (pos += n_; pos > 1; pos >>= 1) {\n *proof++ = layers_[pos ^ 1];\n }\n return (proof - begin);\n }\n\n // Compressed Merkle proofs over a set POS[NP] of leaves.\n //\n // We first compute the set TREE of all nodes that are on the path\n // from the root to any leaf in POS. Then, for each inner node in\n // TREE, we include in the proof the child that is not in TREE, if\n // any.\n size_t generate_compressed_proof(std::vector& proof,\n const size_t pos[/*np*/], size_t np) {\n std::vector tree = compressed_merkle_proof_tree(n_, pos, np);\n\n // For each TREE node, include in the proof the\n // child that is not TREE, if any.\n size_t sz = 0;\n for (size_t i = n_; i-- > 1;) {\n if (tree[i]) {\n size_t child = 2 * i;\n if (tree[child]) {\n // try the other child\n child = 2 * i + 1;\n }\n if (!tree[child]) {\n proof.push_back(layers_[child]);\n ++sz;\n }\n }\n }\n return sz;\n }\n\n size_t n_;\n // layers_[n, 2 * n) stores the leaves (nodes at layer 0).\n // layers_[n/2, n) stores nodes at layer 1.\n // layers_[n/4, n/2) stores nodes at layer 2, etc.\n // The root is at layers_[1] where layers_[0] is not used.\n std::vector layers_;\n};\n\nclass MerkleTreeVerifier {\n public:\n explicit MerkleTreeVerifier(size_t n, const Digest& root)\n : n_(n), root_(root) {}\n\n bool verify_proof(const Digest* proof, size_t pos) const {\n Digest t = *proof++;\n for (pos += n_; pos > 1; pos >>= 1) {\n t = (pos & 1) ? Digest::hash2(*proof++, t) : Digest::hash2(t, *proof++);\n }\n return t == root_;\n }\n\n bool verify_compressed_proof(const Digest* proof, size_t proof_len,\n const Digest leaves[/*np*/],\n const size_t pos[/*np*/], size_t np) const {\n // Reconstructed layers_, where only the DEFINED subset is\n // defined.\n std::vector layers(2 * n_, Digest{});\n std::vector defined(2 * n_, false);\n\n /*scope for TREE */ {\n std::vector tree = compressed_merkle_proof_tree(n_, pos, np);\n\n // read the proof\n size_t sz = 0;\n for (size_t i = n_; i-- > 1;) {\n if (tree[i]) {\n size_t child = 2 * i;\n if (tree[child]) {\n // try the other child\n child = 2 * i + 1;\n }\n if (!tree[child]) {\n if (sz >= proof_len) {\n return false;\n }\n layers[child] = proof[sz++];\n defined[child] = true;\n }\n }\n }\n }\n\n // set LAYERS at all leaves in POS\n for (size_t ip = 0; ip < np; ++ip) {\n size_t l = pos[ip] + n_;\n layers[l] = leaves[ip];\n defined[l] = true;\n }\n\n // Recompute as many inner nodes as we can\n for (size_t i = n_; i-- > 1;) {\n if (defined[2 * i] && defined[2 * i + 1]) {\n layers[i] = Digest::hash2(layers[2 * i], layers[2 * i + 1]);\n defined[i] = true;\n }\n }\n\n return (defined[1] && (root_ == layers[1]));\n }\n\n private:\n size_t n_;\n Digest root_;\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_MERKLE_MERKLE_TREE_H_\n"], ["/longfellow-zk/lib/circuits/logic/evaluation_backend.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_EVALUATION_BACKEND_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_EVALUATION_BACKEND_H_\n\n#include \"util/panic.h\"\n\nnamespace proofs {\n// backend that evaluates values directly\ntemplate \nclass EvaluationBackend {\n using Elt = typename Field::Elt;\n\n public:\n explicit EvaluationBackend(const Field& F,\n bool panic_on_assertion_failure = true)\n : f_(F),\n panic_on_assertion_failure_(panic_on_assertion_failure),\n assertion_failed_(false) {}\n\n ~EvaluationBackend() {\n // Crash if assertion_failed_, which indicates that a test\n // has forgotten to read the value\n check(!assertion_failed_, \"assertion_failed_ true in ~EvaluationBackend()\");\n }\n\n // Reading ASSERTION_FAILED_ returns the current ASSERTION_FAILED_\n // state and resets the state.\n bool assertion_failed() const {\n bool b = assertion_failed_;\n assertion_failed_ = false;\n return b;\n }\n\n struct V {\n Elt e;\n V() = default;\n explicit V(const Elt& x) : e(x) {}\n Elt elt() const { return e; }\n\n bool operator==(const V& y) const { return e == y.e; }\n bool operator!=(const V& y) const { return e != y.e; }\n };\n\n V assert0(const V& a) const {\n if (a.e == f_.zero()) {\n return a;\n } else {\n if (panic_on_assertion_failure_) {\n check(false, \"a != F.zero()\");\n }\n assertion_failed_ = true;\n }\n return a;\n }\n\n V add(const V& a, const V& b) const { return V{f_.addf(a.e, b.e)}; }\n V sub(const V& a, const V& b) const { return V{f_.subf(a.e, b.e)}; }\n V mul(const V& a, const V& b) const { return V{f_.mulf(a.e, b.e)}; }\n V mul(const Elt& a, const V& b) const { return V{f_.mulf(a, b.e)}; }\n V mul(const Elt& a, const V& b, const V& c) const {\n return mul(a, mul(b, c));\n }\n V konst(const Elt& a) const { return V{a}; }\n\n V ax(const Elt& a, const V& x) const { return V{f_.mulf(a, x.e)}; }\n V axy(const Elt& a, const V& x, const V& y) const {\n return V{f_.mulf(a, f_.mulf(x.e, y.e))};\n }\n V axpy(const V& y, const Elt& a, const V& x) const {\n return V{f_.addf(y.e, f_.mulf(a, x.e))};\n }\n V apy(const V& y, const Elt& a) const { return V{f_.addf(y.e, a)}; }\n\n private:\n const Field& f_;\n bool panic_on_assertion_failure_;\n mutable bool assertion_failed_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_EVALUATION_BACKEND_H_\n"], ["/longfellow-zk/lib/algebra/fft.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FFT_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FFT_H_\n\n#include \n#include \n\n#include \"algebra/permutations.h\"\n#include \"algebra/twiddle.h\"\n\nnamespace proofs {\n/*\nFast Fourier Transform (FFT).\n\nWe use FFTPACK/FFTW/MATLAB conventions where the FFT\nhas a negative sign in the exponent. For root of unity\nW, input (\"time\") T and output (\"frequency\") F, the\n\"forward\" FFT computes\n\n F[k] = SUM_{j} T[j] W^{-jk}\n\nand the \"backward\" fft computes\n\n T[j] = SUM_{k} F[k] W^{jk}\n\nA forward transform followed by a backward transform\nmultiplies the array by N.\n\nMatlab and engineers call the forward transform the FFT.\nMathematicians tend to call the backward transform the FFT.\n*/\ntemplate \nclass FFT {\n using Elt = typename Field::Elt;\n\n static void butterfly(Elt* A, size_t s, const Field& F) {\n Elt t = A[s];\n A[s] = A[0];\n F.add(A[0], t);\n F.sub(A[s], t);\n }\n\n static void butterflytw(Elt* A, size_t s, const Elt& twiddle,\n const Field& F) {\n Elt t = A[s];\n F.mul(t, twiddle);\n A[s] = A[0];\n F.add(A[0], t);\n F.sub(A[s], t);\n }\n\n public:\n // Backward FFT.\n // N (the length of A) must be a power of 2\n static void fftb(Elt A[/*n*/], size_t n, const Elt& omega,\n uint64_t omega_order, const Field& F) {\n if (n <= 1) {\n return;\n }\n\n Elt omega_n = Twiddle::reroot(omega, omega_order, n, F);\n Twiddle roots(n, omega_n, F);\n\n Permutations::bitrev(A, n);\n\n // m=1 iteration\n for (size_t k = 0; k < n; k += 2) {\n butterfly(&A[k], 1, F);\n }\n\n // m>1 iterations\n for (size_t m = 2; m < n; m = 2 * m) {\n size_t ws = n / (2 * m);\n for (size_t k = 0; k < n; k += 2 * m) {\n butterfly(&A[k], m, F); // j==0\n for (size_t j = 1; j < m; ++j) {\n butterflytw(&A[k + j], m, roots.w_[j * ws], F);\n }\n }\n }\n }\n\n // forward transform\n static void fftf(Elt A[/*n*/], size_t n, const Elt& omega,\n uint64_t omega_order, const Field& F) {\n fftb(A, n, F.invertf(omega), omega_order, F);\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FFT_H_\n"], ["/longfellow-zk/lib/circuits/logic/compiler_backend.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_COMPILER_BACKEND_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_COMPILER_BACKEND_H_\n\n#include \n\n#include \n\n#include \"circuits/compiler/compiler.h\"\n\nnamespace proofs {\n// backend that compiles a circuit that, when evaluated, computes Elt's\ntemplate \nclass CompilerBackend {\n using QuadCircuitF = QuadCircuit;\n using Elt = typename Field::Elt;\n\n public:\n using V = size_t;\n\n explicit CompilerBackend(QuadCircuitF* q) : q_(q) {}\n\n V assert0(const V& a) const { return q_->assert0(a); }\n V add(const V& a, const V& b) const { return q_->add(a, b); }\n V sub(const V& a, const V& b) const {\n auto mb = mul(konst(q_->f_.mone()), b);\n return add(a, mb);\n }\n V mul(const V& a, const V& b) const { return q_->mul(a, b); }\n V mul(const Elt& a, const V& b) const { return q_->mul(a, b); }\n V mul(const Elt& a, const V& b, const V& c) const { return q_->mul(a, b, c); }\n V konst(const Elt& a) const { return q_->konst(a); }\n\n V ax(const Elt& a, const V& x) const { return q_->mul(a, x); }\n V axy(const Elt& a, const V& x, const V& y) const { return q_->mul(a, x, y); }\n V axpy(const V& y, const Elt& a, const V& x) const {\n return q_->axpy(y, a, x);\n }\n V apy(const V& y, const Elt& a) const { return q_->apy(y, a); }\n\n V input() const { return q_->input(); }\n void output(size_t n, V wire_id) const { q_->output(n, wire_id); }\n size_t wire_id(const V& a) const { return q_->wire_id(a); }\n\n private:\n QuadCircuitF* q_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_COMPILER_BACKEND_H_\n"], ["/longfellow-zk/lib/merkle/merkle_commitment.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_MERKLE_MERKLE_COMMITMENT_H_\n#define PRIVACY_PROOFS_ZK_LIB_MERKLE_MERKLE_COMMITMENT_H_\n\n#include \n#include \n\n#include \n#include \n#include \n\n#include \"merkle/merkle_tree.h\"\n#include \"random/random.h\"\n#include \"util/crypto.h\"\n\nnamespace proofs {\n\nstruct MerkleNonce {\n static constexpr size_t kLength = kSHA256DigestSize;\n uint8_t bytes[kLength];\n};\n\nstruct MerkleProof {\n explicit MerkleProof(size_t nreq) : nonce(nreq), path() {}\n\n std::vector nonce; // [nreq]\n std::vector path; // variable size, but < nreq * mt_pathlen\n};\n\ninline size_t merkle_commitment_len(size_t n) { return merkle_tree_len(n); }\n\n// prover-side\nclass MerkleCommitment {\n public:\n explicit MerkleCommitment(size_t n) : n_(n), mt_(n), nonce_(n) {}\n\n Digest commit(const std::function &updhash,\n RandomEngine &rng) {\n for (size_t i = 0; i < n_; ++i) {\n SHA256 sha;\n rng.bytes(nonce_[i].bytes, MerkleNonce::kLength);\n sha.Update(nonce_[i].bytes, MerkleNonce::kLength);\n updhash(i, sha);\n\n Digest dig;\n sha.DigestData(dig.data);\n mt_.set_leaf(i, dig);\n }\n\n return mt_.build_tree();\n }\n\n void open(MerkleProof &proof, const size_t pos[/*np*/], size_t np) {\n // fill in the nonces of the opening\n for (size_t i = 0; i < np; ++i) {\n proof.nonce[i] = nonce_[pos[i]];\n }\n\n (void)mt_.generate_compressed_proof(proof.path, pos, np);\n }\n\n private:\n size_t n_;\n MerkleTree mt_;\n std::vector nonce_;\n};\n\n// Declare a class for symmetry, but this class is never instantiated\nclass MerkleCommitmentVerifier {\n public:\n static bool verify(size_t n, const Digest &root, const MerkleProof &proof,\n const size_t pos[/*nreq*/], size_t nreq,\n const std::function &updhash) {\n // Assemble the expected leaf values\n std::vector leaves(nreq);\n for (size_t r = 0; r < nreq; ++r) {\n SHA256 sha;\n sha.Update(proof.nonce[r].bytes, MerkleNonce::kLength);\n updhash(r, sha);\n sha.DigestData(leaves[r].data);\n }\n\n MerkleTreeVerifier mtv(n, root);\n return mtv.verify_compressed_proof(proof.path.data(), proof.path.size(),\n &leaves[0], pos, nreq);\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_MERKLE_MERKLE_COMMITMENT_H_\n"], ["/longfellow-zk/lib/gf2k/gf2poly.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_GF2K_GF2POLY_H_\n#define PRIVACY_PROOFS_ZK_LIB_GF2K_GF2POLY_H_\n\n#include \n#include \n#include \n\n#include \"algebra/limb.h\"\n\nnamespace proofs {\n\n// Rough equivalent of Nat but representing polynomials\n// over GF2 instead of natural numbers.\ntemplate \nclass GF2Poly : public Limb {\n public:\n using Super = Limb;\n using T = GF2Poly;\n using Super::kLimbs;\n using Super::kU64;\n using Super::limb_;\n\n GF2Poly() = default; // uninitialized\n explicit GF2Poly(uint64_t x) : Super(x) {}\n\n explicit GF2Poly(const std::array& a) : Super(a) {}\n\n bool operator<(const T& other) const {\n for (size_t i = kLimbs; i-- > 0;) {\n if (limb_[i] < other.limb_[i]) {\n return true;\n }\n if (limb_[i] > other.limb_[i]) {\n return false;\n }\n }\n return false;\n }\n\n // Interpret A[] as a little-endian nat\n static T of_bytes(const uint8_t a[/* kBytes */]) {\n T r;\n for (size_t i = 0; i < kLimbs; ++i) {\n a = Super::of_bytes(&r.limb_[i], a);\n }\n return r;\n }\n\n T& add(const T& y) {\n for (size_t i = 0; i < kLimbs; ++i) {\n limb_[i] ^= y.limb_[i];\n }\n return *this;\n }\n T& sub(const T& y) { return add(y); }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_GF2K_GF2POLY_H_\n"], ["/longfellow-zk/lib/algebra/interpolation.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_INTERPOLATION_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_INTERPOLATION_H_\n\n#include \n\n#include \"algebra/poly.h\"\n\nnamespace proofs {\n// General-purpose polynomial interpolation routines,\n// which operate on arbitrary points at the cost of\n// computing inverses in the field.\n// These static functions are grouped into a class due\n// to the common template arguments.\ntemplate \nclass Interpolation {\n public:\n static const size_t kN = N;\n using Elt = typename Field::Elt;\n using PolyN = Poly;\n\n // Throughout, X are the evaluation points.\n\n // Lagrange basis to Newton\n static void newton_of_lagrange_inplace(PolyN &A, const PolyN &X,\n const Field &F) {\n // Cache one element E and its inverse. In the common\n // case where the points X are in an arithmetic sequence,\n // this cache avoids the computation of most inverses.\n Elt e = F.one(), inve = F.one();\n\n for (size_t i = 1; i < N; i++) {\n for (size_t k = N; k-- > i;) {\n Elt dx = F.subf(X[k], X[k - i]);\n if (dx != e) {\n e = dx;\n inve = F.invertf(dx);\n }\n A[k] = F.mulf(F.subf(A[k], A[k - 1]), inve);\n }\n }\n }\n\n static PolyN newton_of_lagrange(const PolyN &L, const PolyN &X,\n const Field &F) {\n PolyN A = L;\n newton_of_lagrange_inplace(A, X, F);\n return A;\n }\n\n // evaluation in Newton basis\n static Elt eval_newton(PolyN &Newton, const PolyN &X, const Elt &x,\n const Field &F) {\n Elt e{};\n\n for (size_t i = N; i-- > 0;) {\n e = F.addf(Newton[i], F.mulf(e, F.subf(x, X[i])));\n }\n return e;\n }\n\n // Newton basis to monomial basis (i.e., coefficients)\n static void monomial_of_newton_inplace(PolyN &A, const PolyN &X,\n const Field &F) {\n for (size_t i = N; i-- > 0;) {\n for (size_t k = i + 1; k < N; ++k) {\n A[k - 1] = F.subf(A[k - 1], F.mulf(A[k], X[i]));\n }\n }\n }\n\n static PolyN monomial_of_newton(const PolyN &Newton, const PolyN &X,\n const Field &F) {\n PolyN A = Newton;\n monomial_of_newton_inplace(A, X, F);\n return A;\n }\n\n // evaluation in the monomial basis\n static Elt eval_monomial(PolyN &M, const Elt &x, const Field &F) {\n Elt e{};\n\n for (size_t i = N; i-- > 0;) {\n e = F.addf(M[i], F.mulf(e, x));\n }\n return e;\n }\n\n static void monomial_of_lagrange_inplace(PolyN &A, const PolyN &X,\n const Field &F) {\n newton_of_lagrange_inplace(A, X, F);\n monomial_of_newton_inplace(A, X, F);\n }\n\n static PolyN monomial_of_lagrange(const PolyN &L, const PolyN &X,\n const Field &F) {\n PolyN A = L;\n monomial_of_lagrange_inplace(A, X, F);\n return A;\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_INTERPOLATION_H_\n"], ["/longfellow-zk/lib/sumcheck/testing.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_SUMCHECK_TESTING_H_\n#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_TESTING_H_\n\n#include \n\n#include \n#include \n\n#include \"arrays/dense.h\"\n#include \"random/transcript.h\"\n#include \"sumcheck/circuit.h\"\n#include \"sumcheck/prover.h\"\n#include \"sumcheck/verifier.h\"\n#include \"util/log.h\"\n#include \"util/panic.h\"\n\n/*\nThese are methods that help test modules\nby running the prover or the verifier.\n*/\nnamespace proofs {\ntemplate \nvoid run_prover(const Circuit *C, std::unique_ptr> W,\n Proof *proof, const Field& F) {\n typename Prover::inputs pin;\n\n Prover prover(F);\n auto V = prover.eval_circuit(&pin, C, W->clone(), F);\n\n check(V != nullptr, \"eval_circuit failed.\");\n\n // Ensure the witness satisfies the circuit before making a proof.\n for (size_t i = 0; i < V->n1_; ++i) {\n if (V->v_[i] != F.zero()) {\n log(INFO, \"witness failed: non-zero output at %zu\", i);\n }\n check(V->v_[i] == F.zero(), \"witness failed, non-zero output\");\n }\n\n Transcript tsp((uint8_t *)\"testing\", 7);\n prover.prove(proof, nullptr, C, pin, tsp);\n}\n\ntemplate \nvoid run_verifier(const Circuit *C, std::unique_ptr> W,\n Proof &proof, const Field& F) {\n const char *why = \"ok\";\n auto V = std::make_unique>(F);\n Transcript tsv((uint8_t *)\"testing\", 7);\n check(Verifier::verify(&why, C, &proof, std::move(V),\n W->clone(), tsv, F), why);\n}\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_TESTING_H_\n"], ["/longfellow-zk/lib/zk/zk_testing.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ZK_ZK_TESTING_H_\n#define PRIVACY_PROOFS_ZK_LIB_ZK_ZK_TESTING_H_\n\n#include \n#include \n#include \n\n#include \"algebra/convolution.h\"\n#include \"algebra/fp2.h\"\n#include \"algebra/reed_solomon.h\"\n#include \"arrays/dense.h\"\n#include \"random/secure_random_engine.h\"\n#include \"random/transcript.h\"\n#include \"sumcheck/circuit.h\"\n#include \"util/log.h\"\n#include \"util/readbuffer.h\"\n#include \"zk/zk_proof.h\"\n#include \"zk/zk_prover.h\"\n#include \"zk/zk_verifier.h\"\n#include \"gtest/gtest.h\"\n\nnamespace proofs {\n\nconstexpr size_t kLigeroRate = 4;\nconstexpr size_t kLigeroNreq = 189;\n\n// Runs a zk prover and verifier for a field that requires a field extension\n// to perform the commitment.\ntemplate \nvoid run2_test_zk(const Circuit& circuit, Dense& W,\n const Dense& pub, const Field& base,\n const typename Field::Elt& root_x,\n const typename Field::Elt& root_y, size_t root_order) {\n // Build the relevant algebra objects.\n using Field2 = Fp2;\n using Elt2 = typename Field2::Elt;\n using FftExtConvolutionFactory = FFTExtConvolutionFactory;\n using RSFactory = ReedSolomonFactory;\n\n const Field2 base_2(base);\n const Elt2 omega{root_x, root_y};\n const FftExtConvolutionFactory fft(base, base_2, omega, root_order);\n const RSFactory rsf(fft, base);\n\n ZkProof zkpr(circuit, kLigeroRate, kLigeroNreq);\n\n Transcript tp((uint8_t*)\"zk_test\", 7);\n SecureRandomEngine rng;\n ZkProver prover(circuit, base, rsf);\n prover.commit(zkpr, W, tp, rng);\n EXPECT_TRUE(prover.prove(zkpr, W, tp));\n log(INFO, \"ZK Prover done\");\n\n std::vector zbuf;\n zkpr.write(zbuf, base);\n log(INFO, \"zkp len: %zu bytes\", zbuf.size());\n\n // ======= run verifier =============\n // Re-parse the proof to simulate a different client.\n ZkProof zkpv(circuit, kLigeroRate, kLigeroNreq);\n ReadBuffer rb(zbuf);\n EXPECT_TRUE(zkpv.read(rb, base));\n\n ZkVerifier verifier(circuit, rsf, kLigeroRate, kLigeroNreq,\n base);\n Transcript tv((uint8_t*)\"zk_test\", 7);\n verifier.recv_commitment(zkpv, tv);\n EXPECT_TRUE(verifier.verify(zkpv, pub, tv));\n log(INFO, \"ZK Verify done\");\n}\n\ntemplate \nvoid run_failing_test_zk2(const Circuit& circuit, Dense& W,\n const Dense& pub, const Field& base,\n const typename Field::Elt& root_x,\n const typename Field::Elt& root_y,\n size_t root_order) {\n // Build the relevant algebra objects.\n using Field2 = Fp2;\n using Elt2 = typename Field2::Elt;\n using FftExtConvolutionFactory = FFTExtConvolutionFactory;\n using RSFactory = ReedSolomonFactory;\n\n const Field2 base_2(base);\n const Elt2 omega{root_x, root_y};\n const FftExtConvolutionFactory fft(base, base_2, omega, root_order);\n const RSFactory rsf(fft, base);\n\n ZkProof zkpr(circuit, kLigeroRate, kLigeroNreq);\n\n Transcript tp((uint8_t*)\"zk_test\", 7);\n SecureRandomEngine rng;\n ZkProver prover(circuit, base, rsf);\n prover.commit(zkpr, W, tp, rng);\n bool p_ok = prover.prove(zkpr, W, tp);\n EXPECT_FALSE(p_ok);\n}\n\n// Runs a zk prover and verifier for a field that has a suitable root of unity.\ntemplate \nvoid run_test_zk(const Circuit& circuit, Dense& W,\n const Dense& pub, const typename Field::Elt& omega,\n uint64_t omega_order, const Field& F) {\n using FftConvolutionFactory = FFTConvolutionFactory;\n\n FftConvolutionFactory fft(F, omega, omega_order);\n using RSFactory = ReedSolomonFactory;\n const RSFactory rsf(fft, F);\n\n ZkProof zkpr(circuit, kLigeroRate, kLigeroNreq);\n\n Transcript tp((uint8_t*)\"zk_test\", 7);\n SecureRandomEngine rng;\n ZkProver prover(circuit, F, rsf);\n prover.commit(zkpr, W, tp, rng);\n EXPECT_TRUE(prover.prove(zkpr, W, tp));\n\n log(INFO, \"ZK Prover done\");\n\n std::vector zbuf;\n zkpr.write(zbuf, F);\n log(INFO, \"zkp len: %zu bytes\", zbuf.size());\n\n // ======= zk verifier =============\n // Re-parse the proof to simulate a different client.\n ZkProof zkpv(circuit, kLigeroRate, kLigeroNreq);\n ReadBuffer rb(zbuf);\n EXPECT_TRUE(zkpv.read(rb, F));\n\n ZkVerifier verifier(circuit, rsf, kLigeroRate, kLigeroNreq,\n F);\n Transcript tv((uint8_t*)\"zk_test\", 7);\n verifier.recv_commitment(zkpv, tv);\n EXPECT_TRUE(verifier.verify(zkpv, pub, tv));\n}\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ZK_ZK_TESTING_H_\n"], ["/longfellow-zk/lib/zk/zk_verifier.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ZK_ZK_VERIFIER_H_\n#define PRIVACY_PROOFS_ZK_LIB_ZK_ZK_VERIFIER_H_\n\n#include \n\n#include \n\n#include \"arrays/dense.h\"\n#include \"ligero/ligero_param.h\"\n#include \"ligero/ligero_verifier.h\"\n#include \"random/transcript.h\"\n#include \"sumcheck/circuit.h\"\n#include \"util/log.h\"\n#include \"zk/zk_common.h\"\n#include \"zk/zk_proof.h\"\n\nnamespace proofs {\n// ZK Verifier\n//\n// Verifies a zk proof. See note in the prover for the design.\n// To verify a proof, instantiate the class, then call recv_commitment with\n// the commitment, and finally call verify. It is possible to receive several\n// commitments, or run other protocols between the recv_commitment and verify\n// calls. This allows composing two proofs in parallel.\n// To support this, the interface to both accepts a raw Transcript.\ntemplate \nclass ZkVerifier {\n using Elt = typename Field::Elt;\n\n public:\n explicit ZkVerifier(const Circuit& c, const RSFactory& rsf,\n size_t rate, size_t nreq, const Field& F)\n : circ_(c),\n n_witness_(c.ninputs - c.npub_in),\n param_(n_witness_ + ZkCommon::pad_size(c), c.nl, rate, nreq),\n lqc_(c.nl),\n rsf_(rsf),\n f_(F) {\n ZkCommon::setup_lqc(c, lqc_, n_witness_);\n }\n\n void recv_commitment(const ZkProof& zk, Transcript& t) const {\n log(INFO, \"verifier: recv commit\");\n LigeroVerifier::receive_commitment(zk.com, t);\n }\n\n // Verifies the proof.\n bool verify(const ZkProof& zk, const Dense& pub,\n Transcript& tv) const {\n log(INFO, \"verifier: verify\");\n\n ZkCommon::initialize_sumcheck_fiat_shamir(tv, circ_, pub, f_);\n\n // Derive constraints on the witness.\n using Llc = LigeroLinearConstraint;\n std::vector A;\n std::vector b;\n const LigeroHash hash_of_A{0xde, 0xad, 0xbe, 0xef};\n size_t cn = ZkCommon::verifier_constraints(circ_, pub, zk.proof,\n /*aux=*/nullptr, A, b, tv,\n n_witness_, f_);\n\n const char* why = \"\";\n bool ok = LigeroVerifier::verify(\n &why, param_, zk.com, zk.com_proof, tv, cn, A.size(), &A[0], hash_of_A,\n &b[0], &lqc_[0], rsf_, f_);\n\n log(INFO, \"verify done: %s\", why);\n return ok;\n }\n\n private:\n const Circuit& circ_;\n const size_t n_witness_;\n const LigeroParam param_;\n std::vector lqc_;\n const RSFactory& rsf_;\n const Field& f_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ZK_ZK_VERIFIER_H_\n"], ["/longfellow-zk/lib/algebra/fp_p128.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_P128_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_P128_H_\n\n#include \n#include \n\n#include \"algebra/fp_generic.h\"\n#include \"algebra/nat.h\"\n#include \"algebra/sysdep.h\"\n\nnamespace proofs {\n// Optimized implementation of Fp(2^128 - 2^108 + 1). We call this\n// prime P128 because of lack of imagination, but unlike P256,\n// this is not a NIST standard name. The field contains\n// roots of unity of order 2^108.\n\n// Root of unity from pari-gp:\n// ? p=2^128-2^108+1\n// %1 = 340282042402384805036647824275747635201\n// ? g=ffgen(x+Mod(1,p))\n// %2 = 340282042402384805036647824275747635200\n// ? w=sqrtn(g,2^107)\n// %3 = 17166008163159356379329005055841088858\n//\n// ? w=Mod(17166008163159356379329005055841088858, p)\n// %4 = Mod(17166008163159356379329005055841088858,\n// 340282042402384805036647824275747635201)\n// ? w^(2^107)\n// %5 = Mod(340282042402384805036647824275747635200,\n// 340282042402384805036647824275747635201)\n// ? w^(2^108)\n// %6 = Mod(1, 340282042402384805036647824275747635201)\n//\n// Root of unity of order 32:\n// ? w32=w^(2^(108-32))\n// %15 = Mod(164956748514267535023998284330560247862,\n// 340282042402384805036647824275747635201)\n// ? w32^(2^31)\n// %16 = Mod(340282042402384805036647824275747635200,\n// 340282042402384805036647824275747635201)\n// ? w32^(2^32)\n// %17 = Mod(1, 340282042402384805036647824275747635201)\n\n/*\nThis struct contains an optimized reduction step for the chosen field.\n*/\nstruct Fp128Reduce {\n // Harcoded base_64 modulus.\n static const constexpr std::array kModulus = {\n 0x0000000000000001u,\n 0xFFFFF00000000000u,\n };\n\n static inline void reduction_step(uint64_t a[], uint64_t mprime,\n const Nat<2>& m) {\n uint64_t r = -a[0];\n uint64_t sub[2] = {r << 44, r >> 20};\n uint64_t add[3] = {r, 0, r};\n accum(4, a, 3, add);\n negaccum(3, a + 1, 2, sub);\n }\n\n static inline void reduction_step(uint32_t a[], uint32_t mprime,\n const Nat<2>& m) {\n uint32_t r = -a[0];\n uint32_t sub[2] = {r << 12, r >> 20};\n uint32_t add[5] = {r, 0, 0, 0, r};\n accum(6, a, 5, add);\n negaccum(3, a + 3, 2, sub);\n }\n};\n\ntemplate \nusing Fp128 = FpGeneric<2, optimized_mul, Fp128Reduce>;\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_P128_H_\n"], ["/longfellow-zk/lib/util/ceildiv.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_UTIL_CEILDIV_H_\n#define PRIVACY_PROOFS_ZK_LIB_UTIL_CEILDIV_H_\n\n// This package holds basic math utility functions.\n\n#include \n#include \n\nnamespace proofs {\n\n// ceil(a/b)\ntemplate \nT ceildiv(T a, T b) {\n return (a + (b - 1)) / b;\n}\n\ninline size_t lg(size_t n) {\n size_t lgk = 0, k = 1;\n while (k < n) {\n k *= 2;\n lgk += 1;\n }\n return lgk;\n}\n\n// Morton-order operations\nnamespace morton {\n// extract even bits (pack)\ninline uint64_t even(uint64_t x) {\n x &= 0x5555555555555555ull;\n x |= (x >> 1);\n x &= 0x3333333333333333ull;\n x |= (x >> 2);\n x &= 0x0F0F0F0F0F0F0F0Full;\n x |= (x >> 4);\n x &= 0x00FF00FF00FF00FFull;\n x |= (x >> 8);\n x &= 0x0000FFFF0000FFFFull;\n x |= (x >> 16);\n x &= 0x00000000FFFFFFFFull;\n return x;\n}\n\n// inverse of even (unpack)\ninline uint64_t uneven(uint64_t x) {\n x &= 0x00000000FFFFFFFFull;\n x |= (x << 16);\n x &= 0x0000FFFF0000FFFFull;\n x |= (x << 8);\n x &= 0x00FF00FF00FF00FFull;\n x |= (x << 4);\n x &= 0x0F0F0F0F0F0F0F0Full;\n x |= (x << 2);\n x &= 0x3333333333333333ull;\n x |= (x << 1);\n x &= 0x5555555555555555ull;\n return x;\n}\n\n// Given two integers X and Y represented\n// as (even, odd) bits (X0, X1) and\n// (Y0, Y1), set (X0, X1) to the even/odd\n// representation of X+Y\ntemplate \nstatic void add(T *x0, T *x1, T y0, T y1) {\n // Given two arrays X[i] and Y[i] of bits, the goal\n // is to build an adder. One way to build an adder\n // is to switch to the generate/propagate representation\n // G[i] = X[i] & Y[i]\n // P[i] = X[i] ^ Y[i]\n // where G[i] means \"position i generates a carry\" and P[i] means\n // \"position i propagates the carry coming from position i-1\".\n //\n // Generate/propagate can be extended to pairs of positions\n // via the equations\n //\n // G = G[i+1] ^ (G[i] ^ P[i+1])\n // P = P[i+1] & P[i]. (1)\n //\n // (This is all well-known adder stuff that has been known since\n // at least the '50s).\n //\n // Our strategy is thus: convert the addends into G/P representation;\n // combine the [2i] and [2i+1] positions via Equation (1), and\n // use the C \"+\" operation to propagate the carry over one array.\n //\n // The fun part is, how do you use the C adder to propagate G.\n // The standard form of the adder is:\n //\n // (G, P) = (X & Y, X ^ Y)\n // G' = propagate G in any convenient way\n // (X + Y) = RESULT = P ^ G'\n //\n // and thus we can extract the propagated G' as G' = (X + Y) ^ X ^ Y.\n //\n // The other fun part is, given G and P, how do you go back to X and\n // Y that can be fed to the C adder? The transformation (X, Y) -> (G, P)\n // is not injective, but any inverse will work. We choose\n //\n // X = G\n // Y = P ^ G\n\n // Convert inputs into (G, P) form.\n T g0 = *x0 & y0, g1 = *x1 & y1;\n T p0 = *x0 ^ y0, p1 = *x1 ^ y1;\n\n // Combine the two (G, P) inputs.\n T g = g1 ^ (g0 & p1);\n T p = p0 & p1;\n\n // Convert back into (X, Y) = (G, P ^ G) and compute\n // GPRIME = (X + Y) ^ X ^ Y, which simplifies to (X + Y) ^ P\n // because X = G and Y = P ^ G.\n // Here we lose the carry of the addition, making it impossible\n // to output a global carry.\n T gprime = (g + (p ^ g)) ^ p;\n\n // XOR the propagated carries back into P\n *x0 = gprime ^ p0;\n *x1 = g0 ^ (gprime & p0) ^ p1;\n}\n\n// a-b via ~(~a + b)\ntemplate \nstatic void sub(T *x0, T *x1, T y0, T y1) {\n *x0 = ~*x0;\n *x1 = ~*x1;\n add(x0, x1, y0, y1);\n *x0 = ~*x0;\n *x1 = ~*x1;\n}\n\n// a < b via (a - b) < 0. Since we don't have\n// the output carry of the subtraction, we pretend that\n// the result is signed.\ntemplate \nstatic bool lt(T x0, T x1, T y0, T y1) {\n sub(&x0, &x1, y0, y1);\n return (x1 >> (8 * sizeof(T) - 1)) == 1;\n}\n\ntemplate \nstatic bool eq(T x0, T x1, T y0, T y1) {\n return x0 == y0 && x1 == y1;\n}\n\n} // namespace morton\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_UTIL_CEILDIV_H_\n"], ["/longfellow-zk/lib/arrays/eq.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ARRAYS_EQ_H_\n#define PRIVACY_PROOFS_ZK_LIB_ARRAYS_EQ_H_\n\n#include \n\n#include \"arrays/affine.h\"\n\nnamespace proofs {\ntemplate \n// EQ[i,j] is 2D sparse array EQ[i, j] = (i == j).\n// This class contains a state-free version of EQ, which\n// evaluates EQ[i, j] on the fly. See Eqs for a stateful\n// version that stores all the values of EQ[I, j] for fixed I\n// and variable j.\nclass Eq {\n using Elt = typename Field::Elt;\n\n public:\n /*\n Bind EQ{logn,n} at I, J.\n\n We consider the diagonal matrix EQ[i,j] to be composed of\n N-1 diagonal elements A and one last diagonal element B, i.e.,\n EQ=diag([A A A A ... B]). We bind one I variable and one J\n variable in one step, yielding a matrix of the same form\n with ceil(n/2) diagonal entries.\n\n Let I1J1=I[0]*J[0] and I0J0=(1-I[0])*(1-J[0]).\n\n Binding A is equivalent to binding the 2x2 block [A 0; 0 A],\n yielding A <- A*(I0J0+I1J1).\n\n If n is even, then the last 2x2 block is [A 0; 0 B], whose binding\n yields B <- A*I0J0 + B*I1J1.\n\n If n is odd, then the last 2x2 block is [B 0; 0 0], whose binding\n yields B <- B*I0J0.\n */\n static Elt eval(size_t logn, corner_t n, const Elt I[/*logn*/],\n const Elt J[/*logn*/], const Field& F) {\n Elt a = F.one(), b = F.one();\n for (size_t round = 0; round < logn; round++) {\n Elt i1 = I[round], j1 = J[round];\n Elt i0 = F.subf(F.one(), i1), j0 = F.subf(F.one(), j1);\n Elt i0j0 = F.mulf(i0, j0);\n Elt i1j1 = F.mulf(i1, j1);\n if ((n & 1) == 0) {\n F.mul(b, i1j1);\n F.add(b, F.mulf(a, i0j0));\n } else {\n F.mul(b, i0j0);\n }\n F.mul(a, F.addf(i0j0, i1j1));\n n = (n + 1) / 2;\n }\n return b;\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ARRAYS_EQ_H_\n"], ["/longfellow-zk/lib/algebra/bogorng.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_BOGORNG_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_BOGORNG_H_\n\nnamespace proofs {\n// Totally bogus \"random\" number generator, used only for testing.\n// There is no guarantee that it will cycle over all elements in the\n// field, but this keeps dependencies internal to this directory.\n// The public and internal functions of this class all take a const Field&\n// parameter to produce random elements in the Field. It is the caller's\n// responsibility to ensure the object remains valid during execution.\ntemplate \nclass Bogorng {\n using Elt = typename Field::Elt;\n\n public:\n explicit Bogorng(const Field* F)\n : f_(F), next_(F->of_scalar_field(123456789u)) {}\n\n Elt next() {\n // really old-school\n f_->mul(next_, f_->of_scalar_field(1103515245u));\n f_->add(next_, f_->of_scalar_field(12345u));\n return next_;\n }\n\n Elt nonzero() {\n Elt x;\n do {\n x = next();\n } while (x == f_->zero());\n return x;\n }\n\n private:\n const Field* f_;\n Elt next_;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_BOGORNG_H_\n"], ["/longfellow-zk/lib/util/readbuffer.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_UTIL_READBUFFER_H_\n#define PRIVACY_PROOFS_ZK_LIB_UTIL_READBUFFER_H_\n\n#include \n#include \n#include \n\n#include \"util/panic.h\"\n\nnamespace proofs {\n\nclass ReadBuffer {\n public:\n explicit ReadBuffer(const uint8_t *buf, size_t sz)\n : buf_(buf), size_(sz), next_(0) {}\n\n explicit ReadBuffer(const std::vector &v)\n : ReadBuffer(v.data(), v.size()) {}\n\n // no copies\n ReadBuffer(const ReadBuffer &) = delete;\n\n // TRUE if at least N bytes remain\n bool have(size_t n) const { return remaining() >= n; }\n\n size_t remaining() const {\n check(next_ <= size_, \"next_ <= size_\");\n return size_ - next_;\n }\n\n const uint8_t *next(size_t n) {\n check(have(n), \"have(n)\");\n const uint8_t *p = &buf_[next_];\n next_ += n;\n return p;\n }\n\n void next(size_t n, uint8_t dest[/*n*/]) {\n const uint8_t *p = next(n);\n for (size_t i = 0; i < n; ++i) {\n dest[i] = p[i];\n }\n }\n\n private:\n const uint8_t *buf_;\n size_t size_;\n size_t next_;\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_UTIL_READBUFFER_H_\n"], ["/longfellow-zk/lib/algebra/utility.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_UTILITY_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_UTILITY_H_\n\n#include \n\n#include \n\nnamespace proofs {\ntemplate \nclass AlgebraUtil {\n public:\n using Elt = typename Field::Elt;\n\n // a[i*da] = inverse(b[i*db]), via Montgomery batch inversion\n static void batch_invert(size_t n, Elt a[/*n with stride da*/], size_t da,\n const Elt b[/*n with stride db*/], size_t db,\n const Field& F) {\n Elt p = F.one();\n\n // a[i] \\gets \\prod_{j 0;) {\n F.mul(a[i * da], p);\n F.mul(p, b[i * db]);\n }\n }\n\n // a[i] = 1/i, with a[0]=0\n static void batch_inverse_arithmetic(size_t n, Elt a[/*n*/], const Field& F) {\n a[0] = F.zero();\n // this is essentially batch_inverse with b[i]=bi\n\n Elt p = F.one();\n Elt bi = F.zero();\n\n for (size_t i = 1; i < n; ++i) {\n F.add(bi, F.one());\n a[i] = p;\n F.mul(p, bi);\n }\n\n // now p = \\prod_{j 0;) {\n F.mul(a[i], p);\n F.mul(p, bi);\n F.sub(bi, F.one());\n }\n }\n\n static Elt factorial(uint64_t n, const Field& F) {\n auto p = F.one();\n auto fi = F.one();\n for (uint64_t i = 1; i <= n; ++i) {\n F.mul(p, fi);\n F.add(fi, F.one());\n }\n return p;\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_UTILITY_H_\n"], ["/longfellow-zk/lib/sumcheck/verifier.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_SUMCHECK_VERIFIER_H_\n#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_VERIFIER_H_\n\n#include \n\n#include \n\n#include \"arrays/dense.h\"\n#include \"random/transcript.h\"\n#include \"sumcheck/circuit.h\"\n#include \"sumcheck/transcript_sumcheck.h\"\n#include \"sumcheck/verifier_layers.h\"\n\nnamespace proofs {\n// Full sumcheck verifier that verifies the layers\n// via verifier_layers<> and then checks the input\n// binding directly.\ntemplate \nclass Verifier : public VerifierLayers {\n using super = VerifierLayers;\n using typename super::claims;\n using typename super::Elt;\n\n public:\n static bool verify(const char** why, const Circuit* circ,\n const Proof* proof,\n std::unique_ptr> V,\n std::unique_ptr> X, Transcript& ts,\n const Field& F) {\n if (why == nullptr || circ == nullptr || proof == nullptr ||\n V == nullptr || X == nullptr) {\n return false;\n }\n\n claims cl{};\n Challenge ch(circ->nl);\n TranscriptSumcheck tss(ts, F);\n tss.write_input(X.get());\n\n if (!(super::circuit(why, &cl, circ, proof, &ch, std::move(V), tss,\n F))) {\n return false;\n }\n\n // Final check on W, the input wires.\n // bind the copy variables:\n X->bind_all(circ->logc, cl.q, F);\n X->reshape(cl.nv);\n\n // bind the gate variables, for two hands:\n auto X1 = X->clone();\n Dense* VH[2] = {X.get(), X1.get()};\n\n for (size_t hand = 0; hand < 2; ++hand) {\n VH[hand]->bind_all(cl.logv, cl.g[hand], F);\n Elt got = VH[hand]->scalar();\n if (got != cl.claim[hand]) {\n *why = \"got != cl.claim[hand]\";\n return false;\n }\n }\n\n return true;\n }\n\n Verifier() = delete;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_VERIFIER_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_constants.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_CONSTANTS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_CONSTANTS_H_\n\n#include \n#include \n\nnamespace proofs {\n\n/* Max number of SHA blocks to process. */\nconstexpr static const size_t kMaxSHABlocks = 35;\n\n/* Number of bits in CBOR index. Must be large enough to index into MDOC.*/\nconstexpr static const size_t kCborIndexBits = 12;\n\n// This is the prefix added to the D8... mdoc encoding to produce\n// a COSE1 encoding that is ready to be hashed.\nstatic constexpr uint8_t kCose1Prefix[18] = {\n 0x84, 0x6A, 0x53, 0x69, 0x67, 0x6E, 0x61, 0x74, 0x75,\n 0x72, 0x65, 0x31, 0x43, 0xA1, 0x01, 0x26, 0x40, 0x59,\n};\nstatic constexpr size_t kCose1PrefixLen = 18;\n\n/* Max size of an MSO that hashes using < MAX SHA blocks. */\nconstexpr static const size_t kMaxMsoLen =\n kMaxSHABlocks * 64 - 9 - kCose1PrefixLen;\n\nstatic constexpr size_t kValidityInfoLen = 12;\nstatic constexpr size_t kValidFromLen = 9;\nstatic constexpr size_t kDeviceKeyLen = 9;\nstatic constexpr size_t kDeviceKeyInfoLen = 13;\nstatic constexpr size_t kValidUntilLen = 10;\nstatic constexpr size_t kValueDigestsLen = 12;\nstatic constexpr size_t kOrgLen = 17;\n\nstatic constexpr uint8_t kTag32[] = {0x58, 0x20};\nstatic constexpr size_t kIdLen = 32;\nstatic constexpr size_t kValueLen = 64;\n\nstatic constexpr uint8_t kValidityInfoID[kValidityInfoLen] = {\n 'v', 'a', 'l', 'i', 'd', 'i', 't', 'y', 'I', 'n', 'f', 'o'};\n\nstatic constexpr uint8_t kValidFromID[kValidFromLen] = {'v', 'a', 'l', 'i', 'd',\n 'F', 'r', 'o', 'm'};\n\nstatic constexpr uint8_t kValidUntilID[kValidUntilLen] = {\n 'v', 'a', 'l', 'i', 'd', 'U', 'n', 't', 'i', 'l'};\n\nstatic constexpr uint8_t kDeviceKeyID[kDeviceKeyLen] = {'d', 'e', 'v', 'i', 'c',\n 'e', 'K', 'e', 'y'};\n\nstatic constexpr uint8_t kDeviceKeyInfoID[kDeviceKeyInfoLen] = {\n 'd', 'e', 'v', 'i', 'c', 'e', 'K', 'e', 'y', 'I', 'n', 'f', 'o'};\n\nstatic constexpr uint8_t kValueDigestsID[kValueDigestsLen] = {\n 'v', 'a', 'l', 'u', 'e', 'D', 'i', 'g', 'e', 's', 't', 's'};\n\nstatic constexpr uint8_t kOrgID[kOrgLen] = {'o', 'r', 'g', '.', 'i', 's',\n 'o', '.', '1', '8', '0', '1',\n '3', '.', '5', '.', '1'};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_CONSTANTS_H_\n"], ["/longfellow-zk/lib/algebra/fp_p256.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_P256_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_P256_H_\n\n#include \n#include \n\n#include \"algebra/fp_generic.h\"\n#include \"algebra/nat.h\"\n#include \"algebra/sysdep.h\"\n\nnamespace proofs {\n// Optimized implementation of\n// Fp(115792089210356248762697446949407573530086143415290314195533631308867097853951)\n\n/*\nThis struct contains an optimized reduction step for the chosen field.\n*/\nstruct Fp256Reduce {\n // Harcoded base_64 modulus.\n static const constexpr std::array kModulus = {\n 0xFFFFFFFFFFFFFFFFu,\n 0xFFFFFFFFu,\n 0,\n 0xFFFFFFFF00000001u,\n };\n\n static inline void reduction_step(uint64_t a[], uint64_t mprime,\n const Nat<4>& m) {\n uint64_t r = a[0];\n uint64_t l[5] = {r, 0, 0, r << 32, r >> 32};\n negaccum(6, a, 5, l);\n uint64_t h[4] = {r << 32, r >> 32, r, r};\n accum(5, a + 1, 4, h);\n }\n\n static inline void reduction_step(uint32_t a[], uint32_t mprime,\n const Nat<4>& m) {\n uint32_t r = a[0];\n uint32_t l[8] = {r, 0, 0, 0, 0, 0, 0, r};\n negaccum(10, a, 8, l);\n uint32_t h[6] = {r, 0, 0, r, 0, r};\n accum(7, a + 3, 6, h);\n }\n};\n\ntemplate \nusing Fp256 = FpGeneric<4, optimized_mul, Fp256Reduce>;\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_P256_H_\n"], ["/longfellow-zk/lib/algebra/twiddle.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_TWIDDLE_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_TWIDDLE_H_\n\n#include \n#include \n\n#include \n\n// Twiddle factors for FFT\nnamespace proofs {\n\ntemplate \nclass Twiddle {\n using Elt = typename Field::Elt;\n\n public:\n size_t order_;\n // powers of omega_n\n std::vector w_;\n\n explicit Twiddle(size_t n, const Elt& omega_n, const Field& F)\n : order_(n), w_(n / 2) {\n auto w = F.one();\n for (size_t i = 0; 2 * i < n; ++i) {\n w_[i] = w;\n F.mul(w, omega_n);\n }\n }\n\n // given a n-th root of unity omega_n, return a r-th root of unity\n // for r <= n\n static Elt reroot(const Elt& omega_n, uint64_t n, uint64_t r,\n const Field& F) {\n Elt omega_r = omega_n;\n while (r < n) {\n F.mul(omega_r, omega_r);\n r += r;\n }\n return omega_r;\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_TWIDDLE_H_\n"], ["/longfellow-zk/lib/algebra/fp.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_H_\n\n#include \n\n#include \"algebra/fp_generic.h\"\n#include \"algebra/sysdep.h\"\n\nnamespace proofs {\n\n/*\nThe FpReduce structure factors out the main routine for performing modular\nreduction wrt to a Montgomery-represented field element in the FpGeneric\nclass. This struct contains a generic reduction step that always works,\nbut it can be specialized for certain primes to achieve better efficiency as\ndone with our 128- and 256- bit fields.\n*/\nstruct FpReduce {\n template \n static inline void reduction_step(limb_t a[], limb_t mprime, const N& m) {\n constexpr size_t kLimbs = N::kLimbs;\n if (kLimbs == 1) {\n // The general case (below) represents the (kLimbs+1)-word product as\n // L+(H<<64), where in general L and H overlap, requiring\n // two additions. For kLimbs==1, L and H do not overlap, and we can\n // interpret [L, H] as a single double-precision number.\n limb_t lh[2];\n limb_t r = mprime * a[0];\n mulhl(1, lh, lh + 1, r, m.limb_);\n accum(3, a, 2, lh);\n } else {\n limb_t l[kLimbs], h[kLimbs];\n limb_t r = mprime * a[0];\n mulhl(kLimbs, l, h, r, m.limb_);\n accum(kLimbs + 2, a, kLimbs, l);\n accum(kLimbs + 1, a + 1, kLimbs, h);\n }\n }\n};\n\ntemplate \nusing Fp = FpGeneric;\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_FP_H_\n"], ["/longfellow-zk/lib/circuits/sha/flatsha256_witness.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_FLATSHA256_WITNESS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_FLATSHA256_WITNESS_H_\n\n#include \n#include \n\nnamespace proofs {\n\nuint32_t SHA256_ru32be(const uint8_t *d);\n\nclass FlatSHA256Witness {\n public:\n struct BlockWitness {\n uint32_t outw[48];\n uint32_t oute[64];\n uint32_t outa[64];\n uint32_t h1[8];\n };\n\n static void transform_and_witness_block(const uint32_t in[16],\n const uint32_t H0[8],\n uint32_t outw[48], uint32_t oute[64],\n uint32_t outa[64], uint32_t H1[8]);\n\n static void transform_and_witness_message(size_t n, const uint8_t msg[/*n*/],\n size_t max, uint8_t &numb,\n uint8_t in[/* 64*max */],\n BlockWitness bw[/*max*/]);\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_FLATSHA256_WITNESS_H_\n"], ["/longfellow-zk/lib/ec/p256.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_EC_P256_H_\n#define PRIVACY_PROOFS_ZK_LIB_EC_P256_H_\n\n/*\nThis file declares the one instance of the P256 curve and its related fields.\nThere should be only one instance of this curve in any program due to the\ntyping conventions.\n\nThis curve is also known as secp256r1 and prime256v1.\n\nIt is defined over the base field F_p for\np = 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff\n= 115792089210356248762697446949407573530086143415290314195533631308867097853951\n\nand has an order of\n0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551\n115792089210356248762697446949407573529996955224135760342422259061068512044369\n\n\n*/\n\n#include \"algebra/fp.h\"\n#include \"algebra/fp_p256.h\"\n#include \"ec/elliptic_curve.h\"\n\nnamespace proofs {\n\nusing Fp256Base = Fp256;\nusing Fp256Scalar = Fp<4, true>;\nusing Fp256Nat = Fp256Base::N;\n\n// This is the base field of the curve.\nextern const Fp256Base p256_base;\n\n// Order of the curve.\nextern const Fp256Nat n256_order;\n\n// This field allows operations mod the order of the curve.\nextern const Fp256Scalar p256_scalar;\n\ntypedef EllipticCurve P256;\n\nextern const P256 p256;\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_EC_P256_H_\n"], ["/longfellow-zk/lib/sumcheck/prover.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_SUMCHECK_PROVER_H_\n#define PRIVACY_PROOFS_ZK_LIB_SUMCHECK_PROVER_H_\n\n#include \n\n#include \"random/transcript.h\"\n#include \"sumcheck/circuit.h\"\n#include \"sumcheck/prover_layers.h\"\n#include \"sumcheck/transcript_sumcheck.h\"\n\nnamespace proofs {\n\n// A high level idea is partially described in chapter 4.6.7 \"Leveraging Data\n// Parallelism for Further Speedups\" in the book \"Proofs, Arguments, and\n// Zero-Knowledge\" by Justin Thaler.\ntemplate \nclass Prover : public ProverLayers {\n using super = ProverLayers;\n using typename super::bindings;\n\n public:\n using typename super::inputs;\n\n explicit Prover(const Field& f) : ProverLayers(f) {}\n\n // Generate proof for circuit. pad can be nullptr if the caller does not\n // want to add any pad to the proof. Caller must ensure in, t, and F remain\n // valid during call duration.\n // This method always succeeds, but may not produce a verifying proof if\n // the inputs do not satisfy the circuit.\n void prove(Proof* proof, const Proof* pad,\n const Circuit* circ, const inputs& in, Transcript& t) {\n if (proof == nullptr || circ == nullptr) return;\n\n TranscriptSumcheck ts(t, super::f_);\n // The input X is stored at in's layer nl - 1.\n ts.write_input(in.at(circ->nl - 1).get());\n bindings bnd;\n super::prove(proof, pad, circ, in, /*aux=*/nullptr, bnd, ts, super::f_);\n }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_SUMCHECK_PROVER_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_test_attributes.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_TEST_ATTRIBUTES_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_TEST_ATTRIBUTES_H_\n\n#include \"circuits/mdoc/mdoc_zk.h\"\n\nnamespace proofs {\nnamespace test {\nstatic const RequestedAttribute age_over_18 = {\n {'a', 'g', 'e', '_', 'o', 'v', 'e', 'r', '_', '1', '8'},\n {0xf5},\n 11,\n 1,\n kPrimitive};\n\nstatic const RequestedAttribute not_over_18 = {\n .id = {'a', 'g', 'e', '_', 'o', 'v', 'e', 'r', '_', '1', '8'},\n .value = {0xf4},\n .id_len = 11,\n .value_len = 1,\n .type = kPrimitive};\n\nstatic const RequestedAttribute familyname_mustermann = {\n .id = {'f', 'a', 'm', 'i', 'l', 'y', '_', 'n', 'a', 'm', 'e'},\n .value = {'M', 'u', 's', 't', 'e', 'r', 'm', 'a', 'n', 'n'},\n .id_len = 11,\n .value_len = 10,\n .type = kString};\n\nstatic const RequestedAttribute birthdate_1971_09_01 = {\n .id = {'b', 'i', 'r', 't', 'h', '_', 'd', 'a', 't', 'e'},\n .value = {'1', '9', '7', '1', '-', '0', '9', '-', '0', '1'},\n .id_len = 10,\n .value_len = 10,\n .type = kDate};\n\nstatic const RequestedAttribute birthdate_1998_09_04 = {\n .id = {'b', 'i', 'r', 't', 'h', '_', 'd', 'a', 't', 'e'},\n .value = {'1', '9', '9', '8', '-', '0', '9', '-', '0', '4'},\n .id_len = 10,\n .value_len = 10,\n .type = kDate};\n\nstatic const RequestedAttribute height_175 = {\n {'h', 'e', 'i', 'g', 'h', 't'}, {0x18, 0xaf}, 6, 2, kInt};\n\nstatic const RequestedAttribute issue_date_2024_03_15 = {\n {'i', 's', 's', 'u', 'e', '_', 'd', 'a', 't', 'e'},\n {'2', '0', '2', '4', '-', '0', '3', '-', '1', '5'},\n 10,\n 10,\n kDate};\n\n} // namespace test\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_TEST_ATTRIBUTES_H_\n"], ["/longfellow-zk/lib/algebra/hash.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_HASH_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_HASH_H_\n\n#include \n#include \n\n#include \"util/crc64.h\"\n\nnamespace proofs {\n\n// canonical hash of an Elt\ntemplate \nuint64_t elt_hash(const typename Field::Elt& k, const Field& F) {\n uint64_t crc = 0x1;\n uint8_t buf[Field::kBytes];\n F.to_bytes_field(buf, k);\n for (size_t l = 0; l < Field::kBytes; ++l) {\n crc = crc64::update(crc, buf[l], 8);\n }\n return crc;\n}\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_HASH_H_\n"], ["/longfellow-zk/lib/circuits/logic/bit_plucker_constants.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_PLUCKER_CONSTANTS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_PLUCKER_CONSTANTS_H_\n\n#include \n#include \n\nnamespace proofs {\n// bit-plucker code common to both compiler-time and\n// wire-fill time\ntemplate \nstruct bit_plucker_point {\n using Elt = typename Field::Elt;\n\n // packing of bits compatible with even_lagrange_basis():\n Elt operator()(uint64_t bits, const Field& F) const {\n return F.subf(F.of_scalar(2 * bits), F.of_scalar(N - 1));\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_LOGIC_BIT_PLUCKER_CONSTANTS_H_\n"], ["/longfellow-zk/lib/algebra/permutations.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_PERMUTATIONS_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_PERMUTATIONS_H_\n\n#include \n\n#include \n\nnamespace proofs {\n\ntemplate \nclass Permutations {\n public:\n static void bitrev(Elt A[/*n*/], size_t n) {\n size_t revi = 0;\n for (size_t i = 0; i < n - 1; ++i) {\n if (i < revi) {\n std::swap(A[i], A[revi]);\n }\n\n bitrev_increment(&revi, n);\n }\n }\n\n private:\n static void bitrev_increment(size_t* j, size_t bit) {\n do {\n bit >>= 1;\n *j ^= bit;\n } while (!(*j & bit));\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_PERMUTATIONS_H_\n"], ["/longfellow-zk/lib/algebra/compare.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_COMPARE_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_COMPARE_H_\n\n#include \n#include \n\nnamespace proofs {\n\n// canonical a < b operation, defined as lexicographic comparison of\n// the Elt's serialization\ntemplate \nbool elt_less_than(const typename Field::Elt& a, const typename Field::Elt& b,\n const Field& F) {\n uint8_t ua[Field::kBytes], ub[Field::kBytes];\n F.to_bytes_field(ua, a);\n F.to_bytes_field(ub, b);\n for (size_t j = 0; j < Field::kBytes; ++j) {\n if (ua[j] < ub[j]) return true;\n if (ua[j] > ub[j]) return false;\n }\n return false; // equal\n}\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_COMPARE_H_\n"], ["/longfellow-zk/lib/circuits/sha3/sha3_reference.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA3_SHA3_REFERENCE_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA3_SHA3_REFERENCE_H_\n\n// !!!!! DO NOT USE IN PRODUCTION !!!!!\n\n/* This is a simple reference implementation of sha3\n to be used to design zero-knowledge circuits. DO NOT USE\n THIS CODE IN PRODUCTION. */\n#include \n#include \n\nnamespace proofs {\nclass Sha3Reference {\n size_t mdlen_;\n size_t rate_;\n size_t wrptr_;\n uint8_t buf_[200];\n uint64_t a_[5][5];\n\n static void keccak_f_1600(uint64_t A[5][5]);\n\n public:\n explicit Sha3Reference(size_t mdlen)\n : mdlen_(mdlen), rate_(200 - 2 * mdlen), wrptr_(0), buf_{}, a_{} {}\n\n void update(const char* data, size_t n);\n void final(uint8_t digest[/*mdlen*/]);\n\n static void keccak_f_1600_DEBUG_ONLY(uint64_t A[5][5]);\n};\n} // namespace proofs\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA3_SHA3_REFERENCE_H_\n"], ["/longfellow-zk/lib/circuits/compiler/circuit_dump.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_CIRCUIT_DUMP_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_CIRCUIT_DUMP_H_\n\n#include \n\n#include \"circuits/compiler/compiler.h\"\n#include \"util/log.h\"\n\n// Debug printing routines for circuit tests.\nnamespace proofs {\n\ntemplate \ninline void dump_info(const char* name, size_t size,\n const QuadCircuit& Q) {\n log(INFO, \"Compiled circuit: %s[%zu]\", name, size);\n dump_q(Q);\n}\n\ntemplate \ninline void dump_info(const char* name, size_t sz0, size_t sz1,\n const QuadCircuit& Q) {\n log(INFO, \"Compiled circuit: %s[%zu][%zu]\", name, sz0, sz1);\n dump_q(Q);\n}\n\ntemplate \ninline void dump_info(const char* name, size_t sz0, size_t sz1, size_t sz2,\n const QuadCircuit& Q) {\n log(INFO, \"Compiled circuit: %s[%zu][%zu][%zu]\", name, sz0, sz1, sz2);\n dump_q(Q);\n}\n\ntemplate \ninline void dump_info(const char* name, const QuadCircuit& Q) {\n log(INFO, \"Compiled circuit: %s\", name);\n dump_q(Q);\n}\n\ntemplate \ninline void dump_q(const QuadCircuit& Q) {\n log(INFO,\n \" depth: %zu wires: %zu in: %zu out:%zu use:%zu ovh:%zu t:%zu cse:%zu \"\n \"notn:%zu\",\n Q.depth_, Q.nwires_, Q.ninput_, Q.noutput_,\n Q.nwires_ - Q.nwires_overhead_, Q.nwires_overhead_, Q.nquad_terms_,\n Q.nwires_cse_eliminated_, Q.nwires_not_needed_);\n}\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_COMPILER_CIRCUIT_DUMP_H_\n"], ["/longfellow-zk/lib/circuits/anoncred/small_examples.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_EXAMPLES_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_EXAMPLES_H_\n\n#include \n#include \n\n#include \"algebra/static_string.h\"\n\nnamespace proofs {\n\nstruct SmallTest {\n StaticString pkx, pky; /* public key of the issuer */\n StaticString sigr, sigs, sigtr, sigts;\n uint8_t transcript[1024];\n size_t transcript_size;\n uint8_t *now;\n size_t mdoc_size;\n uint8_t mdoc[5000];\n};\n\nstatic const struct SmallTest mdoc_small_tests[] = {\n // Example that requires 3 SHA blocks for the credential.\n {StaticString(\n \"0x298aa30b14298b8bdb5b2b1cc0150e84a86a1469fa813f8df0f0bd09d8489661\"),\n StaticString(\n \"0x2f821d00395d0c63b222a8613c7af5f5cb2b655dda6c3926af7ea3acd6a05fba\"),\n StaticString(\n \"0xc96b7605f15536877592c24d4d65066a377c34e3e6a624ea52ce9d899207\"),\n StaticString(\n \"0xaca1128a3460368caefc5c24a27a7f9e8cc8d590b93485db2c408d1ac96d80ae\"),\n StaticString(\n \"0x08ca78156b6c60c711e501641d4b5000f1ff7715386f1186ce4aec1d6eb2ba92\"),\n StaticString(\n \"0xfdcb8d4da84f1dc03a7bd22909a6bcc103281310f9fe1fb97c13e5d2eb6934df\"),\n {0x60, 0x80, 0xf3, 0x09, 0x55, 0x56, 0xe5, 0x21, 0x4c, 0x5f, 0xff,\n 0x7c, 0x6d, 0x3d, 0xcb, 0x90, 0x3e, 0x2d, 0xcc, 0x45, 0x42, 0x9c,\n 0x4d, 0x81, 0xf9, 0x80, 0x8d, 0x5e, 0x7a, 0xd2, 0x14, 0x50},\n 32,\n (uint8_t *)\"20241005\",\n 183,\n {0x45, 0x72, 0x69, 0x6b, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4d, 0x75, 0x73, 0x74,\n 0x65, 0x72, 0x6d, 0x61, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x31, 0x39, 0x38, 0x30, 0x30, 0x31, 0x30, 0x31,\n 0x00, 0xf5, 0xf5, 0xf5, 0xf5, 0xf4, 0xf4, 0xf4, 0x00, 0x00, 0x00, 0x00,\n 0x32, 0x30, 0x32, 0x34, 0x31, 0x30, 0x30, 0x31, 0x32, 0x30, 0x32, 0x35,\n 0x31, 0x30, 0x30, 0x31, 0x3c, 0xeb, 0x4a, 0xec, 0x0d, 0x76, 0xbb, 0x50,\n 0x35, 0x09, 0xc6, 0x46, 0xad, 0xc6, 0x30, 0x3f, 0xb9, 0xea, 0xa5, 0x84,\n 0xb4, 0x8f, 0xa0, 0xbe, 0x07, 0x6f, 0x14, 0x28, 0xe4, 0xec, 0x3b, 0x37,\n 0x77, 0x91, 0x61, 0xbe, 0xb9, 0x86, 0x90, 0xfb, 0xc8, 0xe3, 0x57, 0x5a,\n 0x9d, 0xd9, 0x41, 0x91, 0xae, 0x8e, 0x4d, 0xbe, 0x2c, 0x44, 0x39, 0x07,\n 0x69, 0xea, 0x0c, 0x08, 0x80, 0x22, 0xf2, 0xc6, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00}},\n // The next examples requires 4 SHA blocks for the credential.\n {\n StaticString(\"0x08a25115e57d680260aafa44e674d45d43af885fffa6746b44ece71\"\n \"cd42febd2\"),\n StaticString(\"0x4a177f6c38543876c66573218db63de627d343f16a483a313069830\"\n \"37df79b2f\"),\n StaticString(\"0x95394343021474ed688e7e783063c768a3343def0f1245f1da09406\"\n \"34eb57410\"),\n StaticString(\"0x4953b2f11cd46c8e1673ac50ddc51665702a27e5788eca3a8bffa67\"\n \"fbdbf65ce\"),\n StaticString(\"0x1ca6eef3238ec5320429774f6b6b743cc868b3cfebff96c41112b36\"\n \"5638a9dc5\"),\n StaticString(\"0x7e303bd730d0e663621ddcaf52991ba9f744cabe161598a44b4508f\"\n \"de7bdaf2d\"),\n\n {0x60, 0x80, 0xf3, 0x09, 0x55, 0x56, 0xe5, 0x21, 0x4c, 0x5f, 0xff,\n 0x7c, 0x6d, 0x3d, 0xcb, 0x90, 0x3e, 0x2d, 0xcc, 0x45, 0x42, 0x9c,\n 0x4d, 0x81, 0xf9, 0x80, 0x8d, 0x5e, 0x7a, 0xd2, 0x14, 0x50},\n 32,\n (uint8_t *)\"20241005\",\n 247,\n {0x45, 0x72, 0x69, 0x6b, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4d, 0x75, 0x73, 0x74,\n 0x65, 0x72, 0x6d, 0x61, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x31, 0x39, 0x38, 0x30, 0x30, 0x31, 0x30, 0x31,\n 0x00, 0xf5, 0xf5, 0xf5, 0xf5, 0xf4, 0xf4, 0xf4, 0x00, 0x00, 0x00, 0x00,\n 0x32, 0x30, 0x32, 0x34, 0x31, 0x30, 0x30, 0x31, 0x32, 0x30, 0x32, 0x35,\n 0x31, 0x30, 0x30, 0x31, 0x3e, 0xf6, 0x39, 0x05, 0x33, 0xf8, 0xf3, 0x37,\n 0x7d, 0xe0, 0xb2, 0xb5, 0x65, 0x19, 0x93, 0x3f, 0x49, 0xe1, 0xa1, 0x41,\n 0x57, 0xa5, 0x22, 0x0e, 0xac, 0x79, 0x8a, 0xe2, 0xe2, 0xea, 0xd2, 0x0c,\n 0x9f, 0x23, 0x3d, 0x1b, 0xe2, 0x8e, 0x69, 0xc1, 0xda, 0x76, 0xec, 0xf9,\n 0xc3, 0x0c, 0xf9, 0x3b, 0xb5, 0xb6, 0x69, 0x6f, 0xc6, 0xc2, 0x8a, 0xa8,\n 0x98, 0x19, 0x7d, 0xbf, 0xea, 0x6d, 0xad, 0x40, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},\n },\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_EXAMPLES_H_\n"], ["/longfellow-zk/lib/ligero/ligero_transcript.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_TRANSCRIPT_H_\n#define PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_TRANSCRIPT_H_\n\n#include \n\n#include \n\n#include \"ligero/ligero_param.h\"\n#include \"random/transcript.h\"\n\nnamespace proofs {\ntemplate \nclass LigeroTranscript {\n public:\n using Elt = typename Field::Elt;\n\n static void write_commitment(const LigeroCommitment& commitment,\n Transcript& ts) {\n ts.write(commitment.root.data, commitment.root.kLength);\n }\n\n static void gen_uldt(Elt u[/*nwqrow*/], const LigeroParam& p,\n Transcript& ts, const Field& F) {\n ts.elt(u, p.nwqrow, F);\n }\n\n static void gen_alphal(size_t nl, Elt alpha[/*nl*/], Transcript& ts,\n const Field& F) {\n ts.elt(alpha, nl, F);\n }\n\n static void gen_alphaq(std::array alpha[/*nq*/],\n const LigeroParam& p, Transcript& ts,\n const Field& F) {\n ts.elt(&alpha[0][0], 3 * p.nq, F);\n }\n\n static void gen_uquad(Elt u[/*nqtriples*/], const LigeroParam& p,\n Transcript& ts, const Field& F) {\n ts.elt(u, p.nqtriples, F);\n }\n\n // Choose p.nreq distinct naturals in [0, p.block_enc - p.dblock)\n static void gen_idx(size_t idx[/*p.nreq*/], const LigeroParam& p,\n Transcript& ts, const Field& F) {\n check(p.block_enc >= p.dblock, \"p.block_enc >= p.dblock\");\n check(p.block_enc - p.dblock >= p.nreq, \"p.block_enc - p.dblock >= p.nreq\");\n ts.choose(idx, p.block_enc - p.dblock, p.nreq);\n }\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_LIGERO_LIGERO_TRANSCRIPT_H_\n"], ["/longfellow-zk/lib/circuits/sha/sha256_test_values.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_SHA256_TEST_VALUES_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_SHA256_TEST_VALUES_H_\n\n#include \n#include \n#include \n\nnamespace proofs {\n\nstruct sha256_testvec {\n const char* str;\n size_t len;\n uint8_t hash[32];\n};\n\n// A set of SHA256 test vectors used to verify the circuit implementation.\nstatic const struct sha256_testvec SHA256_TV[] = {\n {\"\", 0, {0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4,\n 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b,\n 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}},\n {\"abc\", 3, {0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,\n 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,\n 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,\n 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}},\n {\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\",\n 56,\n {0x24, 0x8d, 0x6a, 0x61, 0xd2, 0x06, 0x38, 0xb8, 0xe5, 0xc0, 0x26,\n 0x93, 0x0c, 0x3e, 0x60, 0x39, 0xa3, 0x3c, 0xe4, 0x59, 0x64, 0xff,\n 0x21, 0x67, 0xf6, 0xec, 0xed, 0xd4, 0x19, 0xdb, 0x06, 0xc1}},\n {\"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmno\"\n \"pjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu\",\n 112,\n {0xcf, 0x5b, 0x16, 0xa7, 0x78, 0xaf, 0x83, 0x80, 0x03, 0x6c, 0xe5,\n 0x9e, 0x7b, 0x04, 0x92, 0x37, 0x0b, 0x24, 0x9b, 0x11, 0xe8, 0xf0,\n 0x7a, 0x51, 0xaf, 0xac, 0x45, 0x03, 0x7a, 0xfe, 0xe9, 0xd1}},\n {\"D818590293A66776657273696F6E63312E306F646967657374416C676F726974686D67534\"\n \"8412D32353667646F6354797065756F72672E69736F2E31383031332E352E312E6D444C6C\"\n \"76616C756544696765737473A2716F72672E69736F2E31383031332E352E31A3005820CF9\"\n \"C1CB89584BF8C4176A37C2C954A8DC56077D3BA65EE44011E62AB7C63CE2D0158202F00C7\"\n \"0D5FA9867D7BD2207E0D0B87E35A9AC962A8DE36EE1BE3944B63B39141025820EA9C0339A\"\n \"AF9BAE8\",\n 372,\n {0xc7, 0xce, 0x90, 0x99, 0xbd, 0xb6, 0x41, 0x75, 0x02, 0xb7, 0x3e,\n 0x44, 0xc9, 0x82, 0x7c, 0xd2, 0x95, 0x6c, 0x54, 0x11, 0x0a, 0x39,\n 0xb2, 0x60, 0x67, 0xfb, 0xf7, 0x9f, 0xf8, 0x9b, 0x20, 0xee}},\n\n // test boundary conditions for padding\n // 55 a's\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\n 55,\n {0x9f, 0x43, 0x90, 0xf8, 0xd3, 0x0c, 0x2d, 0xd9, 0x2e, 0xc9, 0xf0,\n 0x95, 0xb6, 0x5e, 0x2b, 0x9a, 0xe9, 0xb0, 0xa9, 0x25, 0xa5, 0x25,\n 0x8e, 0x24, 0x1c, 0x9f, 0x1e, 0x91, 0x0f, 0x73, 0x43, 0x18}},\n // 56 a's\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\n 56,\n {0xb3, 0x54, 0x39, 0xa4, 0xac, 0x6f, 0x09, 0x48, 0xb6, 0xd6, 0xf9,\n 0xe3, 0xc6, 0xaf, 0x0f, 0x5f, 0x59, 0x0c, 0xe2, 0x0f, 0x1b, 0xde,\n 0x70, 0x90, 0xef, 0x79, 0x70, 0x68, 0x6e, 0xc6, 0x73, 0x8a}},\n // 57 a's\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\n 57,\n {0xf1, 0x3b, 0x2d, 0x72, 0x46, 0x59, 0xeb, 0x3b, 0xf4, 0x7f, 0x2d,\n 0xd6, 0xaf, 0x1a, 0xcc, 0xc8, 0x7b, 0x81, 0xf0, 0x9f, 0x59, 0xf2,\n 0xb7, 0x5e, 0x5c, 0x0b, 0xed, 0x65, 0x89, 0xdf, 0xe8, 0xc6}},\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\n 63,\n {0x7d, 0x3e, 0x74, 0xa0, 0x5d, 0x7d, 0xb1, 0x5b, 0xce, 0x4a, 0xd9,\n 0xec, 0x06, 0x58, 0xea, 0x98, 0xe3, 0xf0, 0x6e, 0xee, 0xcf, 0x16,\n 0xb4, 0xc6, 0xff, 0xf2, 0xda, 0x45, 0x7d, 0xdc, 0x2f, 0x34}},\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\n 64,\n {0xff, 0xe0, 0x54, 0xfe, 0x7a, 0xe0, 0xcb, 0x6d, 0xc6, 0x5c, 0x3a,\n 0xf9, 0xb6, 0x1d, 0x52, 0x09, 0xf4, 0x39, 0x85, 0x1d, 0xb4, 0x3d,\n 0x0b, 0xa5, 0x99, 0x73, 0x37, 0xdf, 0x15, 0x46, 0x68, 0xeb}},\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\n 65,\n {0x63, 0x53, 0x61, 0xc4, 0x8b, 0xb9, 0xea, 0xb1, 0x41, 0x98, 0xe7,\n 0x6e, 0xa8, 0xab, 0x7f, 0x1a, 0x41, 0x68, 0x5d, 0x6a, 0xd6, 0x2a,\n 0xa9, 0x14, 0x6d, 0x30, 0x1d, 0x4f, 0x17, 0xeb, 0x0a, 0xe0}},\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\n 66,\n {0xac, 0x13, 0x7f, 0xce, 0x49, 0x83, 0x7c, 0x7c, 0x29, 0x45, 0xf6,\n 0x16, 0x0d, 0x3c, 0x0e, 0x67, 0x9e, 0x6f, 0x40, 0x07, 0x08, 0x50,\n 0x42, 0x0a, 0x22, 0xbc, 0x10, 0xe0, 0x69, 0x2c, 0xbd, 0xc7}},\n // 2 block boundary conditions\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbb\"\n \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\n 118,\n {0x16, 0x1f, 0x88, 0x3d, 0xfb, 0x71, 0x6c, 0x8a, 0xcf, 0x49, 0x6c,\n 0x04, 0x78, 0x8d, 0x42, 0xf8, 0x0c, 0xe2, 0x21, 0x50, 0x4a, 0xfa,\n 0x81, 0x63, 0xc0, 0xe7, 0x3b, 0x11, 0xb5, 0xd2, 0x5f, 0xd0}},\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbb\"\n \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc\",\n 119,\n {0x6c, 0x17, 0x1b, 0xd6, 0x6a, 0x89, 0x03, 0x44, 0xee, 0x32, 0xde,\n 0x77, 0xe9, 0xdb, 0x13, 0xc0, 0x18, 0x23, 0xac, 0x16, 0xc6, 0xf4,\n 0x76, 0x67, 0x69, 0xd8, 0xa3, 0xf4, 0x91, 0x27, 0xda, 0x98}},\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbb\"\n \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccc\",\n 126,\n {0x8c, 0xfb, 0x31, 0xd1, 0x1d, 0xd7, 0x6e, 0xfb, 0x8c, 0x70, 0x38,\n 0xa5, 0x09, 0xb9, 0x80, 0x69, 0xbb, 0xb7, 0xa6, 0x04, 0x67, 0x55,\n 0xc5, 0x5b, 0x10, 0x83, 0x9e, 0xd8, 0x72, 0x39, 0x9b, 0x9c}},\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbb\"\n \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccd\",\n 127,\n {0xf4, 0xaf, 0x59, 0x2b, 0xd9, 0x85, 0xc2, 0x48, 0x66, 0x64, 0x61,\n 0x9a, 0xff, 0xd7, 0xf6, 0xe1, 0x97, 0x8d, 0x9b, 0x24, 0x01, 0x7c,\n 0xe8, 0x63, 0x82, 0x83, 0x62, 0xa1, 0xcd, 0xcd, 0x33, 0xfc}},\n {\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbb\"\n \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccdd\",\n 128,\n {0xdb, 0x2c, 0x2b, 0xe4, 0xf8, 0x50, 0xcf, 0xd4, 0x2d, 0xce, 0x67,\n 0x8b, 0xe2, 0x63, 0xa9, 0xbb, 0x74, 0x26, 0xf6, 0xbf, 0x39, 0x12,\n 0x8e, 0x9e, 0x75, 0xd3, 0xa3, 0xbd, 0x02, 0x31, 0x64, 0x9a}},\n {\"\\x00\", 1, {0x6e, 0x34, 0x0b, 0x9c, 0xff, 0xb3, 0x7a, 0x98,\n 0x9c, 0xa5, 0x44, 0xe6, 0xbb, 0x78, 0x0a, 0x2c,\n 0x78, 0x90, 0x1d, 0x3f, 0xb3, 0x37, 0x38, 0x76,\n 0x85, 0x11, 0xa3, 0x06, 0x17, 0xaf, 0xa0, 0x1d}},\n {\"\\x00\\x01\", 2, {0xb4, 0x13, 0xf4, 0x7d, 0x13, 0xee, 0x2f, 0xe6,\n 0xc8, 0x45, 0xb2, 0xee, 0x14, 0x1a, 0xf8, 0x1d,\n 0xe8, 0x58, 0xdf, 0x4e, 0xc5, 0x49, 0xa5, 0x8b,\n 0x79, 0x70, 0xbb, 0x96, 0x64, 0x5b, 0xc8, 0xd2}},\n {\"\\x00\\x01\\x02\", 3, {0xae, 0x4b, 0x32, 0x80, 0xe5, 0x6e, 0x2f, 0xaf,\n 0x83, 0xf4, 0x14, 0xa6, 0xe3, 0xda, 0xbe, 0x9d,\n 0x5f, 0xbe, 0x18, 0x97, 0x65, 0x44, 0xc0, 0x5f,\n 0xed, 0x12, 0x1a, 0xcc, 0xb8, 0x5b, 0x53, 0xfc}},\n {\"\\x00\\x01\\x02\\x03\", 4, {0x05, 0x4e, 0xde, 0xc1, 0xd0, 0x21, 0x1f, 0x62,\n 0x4f, 0xed, 0x0c, 0xbc, 0xa9, 0xd4, 0xf9, 0x40,\n 0x0b, 0x0e, 0x49, 0x1c, 0x43, 0x74, 0x2a, 0xf2,\n 0xc5, 0xb0, 0xab, 0xeb, 0xf0, 0xc9, 0x90, 0xd8}},\n};\n\n// Sample input-output pairs for the block transform.\nstruct SHA256BlockTests {\n uint32_t input[16];\n uint32_t h[8];\n uint32_t want[8];\n};\n\nstatic const struct SHA256BlockTests kSha_bt_[] = {\n {\n {\n 0,\n 0xdeadbeef,\n 0xbd5b7dde,\n 0x9c093ccd,\n 0x7ab6fbbc,\n 0x5964baab,\n 0x3812799a,\n 0x16c03889,\n 0xf56df778,\n 0xd41bb667,\n 0xb2c97556,\n 0x91773445,\n 0x7024f334,\n 0x4ed2b223,\n 0x2d807112,\n 0xc2e3001,\n },\n {0, 0xabadcafe, 0x575b95fc, 0x30960fa, 0xaeb72bf8, 0x5a64f6f6,\n 0x612c1f4, 0xb1c08cf2},\n {\n 0x656f967b,\n 0x508cb605,\n 0x109902c5,\n 0xbe9909c,\n 0x30ed1bc6,\n 0x8d3bb28c,\n 0x836c99a8,\n 0x30731a12,\n },\n },\n {\n {\n 0x7,\n 0xe,\n 0x15,\n 0x1c,\n 0x23,\n 0x2a,\n 0x31,\n 0x38,\n 0x3f,\n 0x46,\n 0x4d,\n 0x54,\n 0x5b,\n 0x62,\n 0x69,\n 0x70,\n },\n {0x0, 0x13, 0x26, 0x39, 0x4c, 0x5f, 0x72, 0x85},\n {\n 0x95ddd507,\n 0x1a7a4b1f,\n 0xf5951676,\n 0x105a25a3,\n 0x511cee03,\n 0xd0972a96,\n 0xb1cb76d7,\n 0xf9f46d72,\n },\n },\n {\n {\n 0xf0cee5d1,\n 0x615dfa6a,\n 0xbda82adf,\n 0xcb66fb25,\n 0x30d60637,\n 0xb1018af9,\n 0x2c5c0e06,\n 0xb0556e74,\n 0xf8e2da1f,\n 0xf05b699b,\n 0xabbf6d16,\n 0x3377e5ad,\n 0x46d8cd9e,\n 0xcc01d8dd,\n 0x5532a535,\n 0x34e928ea,\n },\n {\n 0x515f007c,\n 0x5bd062c2,\n 0x12200854,\n 0x4db127f8,\n 0x216231b,\n 0x1f16e9e8,\n 0x1190cde7,\n 0x66ef438d,\n },\n {\n 0x3a3995a,\n 0xb55e568e,\n 0x5fb4b933,\n 0x97c9e9c0,\n 0xaea7d67c,\n 0xaee17ae4,\n 0xcfffacb8,\n 0x91d6ab5e,\n },\n }};\n\n// Output values for SHA256(a^k) for various values of k used in the\n// benchmarking results.\nstruct sha256_bench {\n size_t len;\n uint8_t hash[32];\n};\n\nstatic const struct sha256_bench kSha_benchmark_[] = {\n {50, {0x16, 0x0b, 0x4e, 0x43, 0x3e, 0x38, 0x4e, 0x05, 0xe5, 0x37, 0xdc,\n 0x59, 0xb4, 0x67, 0xf7, 0xcb, 0x24, 0x03, 0xf0, 0x21, 0x4d, 0xb1,\n 0x5c, 0x5d, 0xb5, 0x88, 0x62, 0xa3, 0xf1, 0x15, 0x6d, 0x2e}},\n {114, {0x6c, 0xb7, 0x50, 0xb2, 0x18, 0x16, 0x06, 0x51, 0x1f, 0x4a, 0x7e,\n 0x47, 0x86, 0xb5, 0x36, 0x92, 0xf5, 0x1a, 0x9c, 0xdc, 0x4d, 0x31,\n 0x72, 0xfd, 0xcf, 0xb9, 0x26, 0x7a, 0xec, 0xa7, 0xe4, 0xe4}},\n {178, {0xca, 0xad, 0x4b, 0x2f, 0xbb, 0x83, 0x0f, 0xa5, 0x40, 0x02, 0xa1,\n 0x67, 0x5f, 0x15, 0x99, 0xd9, 0xb0, 0x92, 0xcd, 0x39, 0x8a, 0xd6,\n 0xfb, 0xb8, 0x16, 0xbf, 0xe8, 0xf9, 0x48, 0xcd, 0xd6, 0x20}},\n {242, {0x8f, 0xde, 0xd5, 0x9c, 0x42, 0x7b, 0x2e, 0x68, 0x09, 0xc8, 0x10,\n 0x91, 0x5a, 0xac, 0xa9, 0x63, 0x57, 0x32, 0xa1, 0xde, 0xcc, 0x4b,\n 0xa2, 0xac, 0x8e, 0x0a, 0x1d, 0x90, 0xfc, 0x10, 0x92, 0xc9}},\n {306, {0x4c, 0xef, 0xdb, 0xa1, 0xba, 0x8d, 0x39, 0x75, 0xf3, 0x2c, 0xba,\n 0xc9, 0xf2, 0x27, 0xc7, 0xe6, 0xb6, 0xe6, 0x63, 0x43, 0x9e, 0x79,\n 0x85, 0x61, 0x6b, 0xbb, 0x5c, 0x61, 0x82, 0x4d, 0xbb, 0x0c}},\n {370, {0x27, 0xdd, 0xc5, 0x8e, 0xcc, 0x58, 0xfd, 0x86, 0x93, 0x37, 0x48,\n 0x1a, 0xf7, 0x73, 0x02, 0xd5, 0x4d, 0xd5, 0xba, 0x91, 0x84, 0x21,\n 0x44, 0xf8, 0x7d, 0xeb, 0x83, 0x24, 0x09, 0x06, 0x9d, 0x0b}},\n {434, {0xd9, 0x67, 0xcc, 0x55, 0x05, 0x9d, 0x00, 0x82, 0xb6, 0xb2, 0x47,\n 0xd2, 0xa7, 0xd7, 0xfb, 0x79, 0xb7, 0xdd, 0xed, 0xa9, 0x7b, 0xe5,\n 0x92, 0x7d, 0xf4, 0x0c, 0xf9, 0x64, 0x2c, 0xee, 0xc6, 0xd3}},\n {498, {0x40, 0x47, 0x02, 0x9c, 0x99, 0xeb, 0x4e, 0xf6, 0x39, 0x25, 0x9b,\n 0x2e, 0xe3, 0xc8, 0xde, 0xb4, 0x40, 0x90, 0x86, 0xc8, 0x1d, 0xe1,\n 0xcd, 0xab, 0x00, 0x53, 0xbb, 0xcc, 0x08, 0x84, 0xe4, 0x1e}},\n {562, {0x3e, 0x47, 0xed, 0x99, 0x0d, 0x31, 0xf0, 0xfe, 0xb0, 0xa7, 0x77,\n 0x1c, 0x72, 0xd1, 0x32, 0x0f, 0xad, 0x55, 0x58, 0x14, 0xf7, 0x81,\n 0x95, 0x6e, 0xfc, 0x89, 0xda, 0x88, 0x4f, 0xf6, 0x3d, 0x40}},\n {626, {0xc6, 0x20, 0x91, 0x3d, 0xad, 0x86, 0x0a, 0x2a, 0x77, 0x3d, 0x9d,\n 0x56, 0x0c, 0x2c, 0xed, 0x25, 0x03, 0xf6, 0xf9, 0xe2, 0xc5, 0x5c,\n 0xcd, 0x65, 0x08, 0x3b, 0xf0, 0x53, 0x2d, 0x60, 0x62, 0x61}},\n {690, {0x21, 0x8d, 0xb2, 0x31, 0x17, 0xd4, 0x98, 0x63, 0x1b, 0xfc, 0x22,\n 0x96, 0x49, 0x9a, 0xb2, 0x7e, 0x07, 0x2c, 0xce, 0xf4, 0xfa, 0xea,\n 0xca, 0x63, 0xe5, 0xa2, 0xec, 0xcc, 0x7e, 0x22, 0xf4, 0xac}},\n {754, {0x29, 0x2c, 0x65, 0x83, 0xeb, 0xe8, 0x2f, 0xee, 0xec, 0xed, 0x13,\n 0xa8, 0x6b, 0xdb, 0x83, 0x8a, 0x15, 0xaf, 0xcc, 0x5b, 0xf4, 0x7f,\n 0x2a, 0xcf, 0x51, 0x51, 0x50, 0x7e, 0xae, 0x03, 0xd7, 0x7c}},\n {818, {0x5f, 0x99, 0x78, 0x83, 0x81, 0x11, 0x36, 0x98, 0x23, 0x16, 0x54,\n 0xd9, 0x80, 0xfc, 0x73, 0x8d, 0x8e, 0x19, 0x11, 0xc6, 0xa3, 0x0d,\n 0xe8, 0xcb, 0x33, 0xa2, 0x9e, 0xf7, 0xc1, 0xed, 0xc3, 0x19}},\n {882, {0x5f, 0x2e, 0xb1, 0xec, 0x0f, 0xd7, 0x93, 0x76, 0xc4, 0x8a, 0xfc,\n 0x9c, 0x15, 0xd1, 0x98, 0x64, 0x94, 0x20, 0x5f, 0x69, 0x08, 0x36,\n 0x43, 0xb9, 0xd6, 0x9a, 0x05, 0x85, 0xf4, 0xfb, 0xdc, 0x5f}},\n {946, {0xe8, 0x06, 0x78, 0xdf, 0xad, 0xb0, 0x70, 0x4e, 0x5e, 0x68, 0x4a,\n 0xda, 0x0b, 0x0b, 0xe7, 0xac, 0x2f, 0x22, 0x54, 0x7f, 0x13, 0x04,\n 0xfe, 0x9a, 0xb4, 0xaa, 0xa7, 0x30, 0xd9, 0x90, 0x9a, 0x3a}},\n {1010, {0x69, 0x4d, 0x24, 0xc6, 0x82, 0x83, 0xb9, 0x9a, 0xd5, 0xee, 0x5c,\n 0xea, 0xa3, 0x5d, 0x9d, 0xe4, 0xdd, 0x55, 0x45, 0xdd, 0x7a, 0x38,\n 0x5f, 0x4b, 0x18, 0xfa, 0x85, 0xb2, 0xdc, 0x6d, 0xe2, 0xba}},\n {1074, {0x55, 0xd2, 0xfe, 0x88, 0x80, 0x0f, 0x6b, 0xcb, 0xe7, 0xce, 0xa2,\n 0x98, 0xf4, 0x88, 0xa7, 0xc8, 0x41, 0xd4, 0x03, 0x9f, 0x3f, 0xf3,\n 0xf0, 0xc6, 0xea, 0x2f, 0xa5, 0x40, 0x84, 0xf4, 0xa0, 0xdf}},\n {1138, {0xa3, 0x38, 0x31, 0x67, 0x79, 0x4a, 0x75, 0x6d, 0x88, 0x9a, 0x7a,\n 0x99, 0xf4, 0x15, 0x79, 0x4d, 0xe9, 0xdf, 0xeb, 0x21, 0x67, 0x2c,\n 0xd1, 0x04, 0x41, 0xcf, 0xfd, 0x93, 0xdb, 0xd8, 0x20, 0x5a}},\n {1202, {0xdb, 0xb3, 0x3f, 0x50, 0xf1, 0xc7, 0xb1, 0xd9, 0x28, 0x63, 0x2f,\n 0x81, 0x35, 0x08, 0x6a, 0x58, 0xc2, 0x6a, 0x66, 0x55, 0x3b, 0xd2,\n 0x27, 0x7e, 0x4f, 0x9a, 0x5f, 0x00, 0x61, 0xc6, 0xcc, 0x25}},\n {1266, {0xeb, 0xdd, 0x77, 0xc4, 0x04, 0x96, 0xa9, 0xeb, 0x3f, 0xf9, 0x24,\n 0xf4, 0xcf, 0xb5, 0x4e, 0xee, 0xb2, 0xc6, 0xf5, 0x04, 0x26, 0xb1,\n 0xca, 0x2f, 0xd4, 0xd9, 0x72, 0x83, 0xd8, 0x49, 0x72, 0xce}},\n {1330, {0x05, 0x3b, 0xbf, 0x41, 0xf3, 0x3d, 0xad, 0x63, 0x5a, 0x69, 0x03,\n 0xca, 0x32, 0x8f, 0x2e, 0xfd, 0x98, 0x87, 0x70, 0x2a, 0x3e, 0x02,\n 0x1e, 0x6a, 0xac, 0x55, 0x9c, 0x53, 0x53, 0xec, 0x43, 0x41}},\n {1394, {0xf2, 0xda, 0xba, 0x28, 0x4a, 0x48, 0xf7, 0xc6, 0x8f, 0x72, 0x9a,\n 0x17, 0x2b, 0x26, 0x3a, 0xaf, 0x97, 0xd8, 0x0c, 0x57, 0xab, 0xba,\n 0x9b, 0xec, 0xa6, 0x75, 0xb9, 0x4c, 0xcb, 0x6e, 0x9d, 0xa7}},\n {1458, {0x20, 0x2f, 0x4f, 0x63, 0xe9, 0x31, 0x90, 0x1a, 0xe1, 0xcb, 0x8d,\n 0x42, 0x1d, 0x16, 0x9b, 0x12, 0x78, 0x2a, 0x58, 0x51, 0xca, 0x49,\n 0x73, 0x72, 0xf4, 0xf4, 0x7c, 0x6f, 0xea, 0xc7, 0x61, 0x1d}},\n {1522, {0xee, 0x97, 0x06, 0xa8, 0xbd, 0x8b, 0x8f, 0xbe, 0x96, 0xa9, 0xff,\n 0x52, 0xb7, 0xc6, 0x36, 0x02, 0x80, 0x70, 0x5f, 0x74, 0xbe, 0x73,\n 0xb8, 0x65, 0x5b, 0xdb, 0x8d, 0x56, 0x07, 0x61, 0xa7, 0xad}},\n {1586, {0x60, 0xd6, 0x6a, 0xa2, 0x83, 0xbf, 0x1c, 0xed, 0x60, 0x6f, 0xa6,\n 0x40, 0x73, 0xf4, 0x36, 0x3d, 0xed, 0x46, 0x92, 0x4e, 0x93, 0xbe,\n 0x67, 0xb8, 0x19, 0x0b, 0x04, 0xa5, 0x70, 0xab, 0x4a, 0xb5}},\n {1650, {0x93, 0x32, 0xff, 0xe0, 0x58, 0x84, 0xbf, 0x8f, 0xdd, 0x09, 0x2f,\n 0x94, 0x43, 0x22, 0x57, 0x28, 0x4f, 0x9c, 0x23, 0x2a, 0x72, 0xe5,\n 0xaa, 0x3b, 0x9b, 0x11, 0xda, 0xc4, 0x57, 0xe3, 0x46, 0x34}},\n {1714, {0xd3, 0x47, 0xa1, 0xbe, 0xf9, 0xea, 0x05, 0x0d, 0xe5, 0x06, 0x2e,\n 0x27, 0x86, 0x72, 0x7d, 0x2b, 0x4c, 0xcb, 0x60, 0x77, 0x7c, 0x82,\n 0xf9, 0x7c, 0xd7, 0x58, 0xfa, 0x44, 0x27, 0x35, 0x51, 0x42}},\n {1778, {0xdd, 0xf6, 0x34, 0x5e, 0x0e, 0xd2, 0x19, 0x75, 0x06, 0xac, 0x22,\n 0x9f, 0x3b, 0x5f, 0x53, 0xe8, 0xc0, 0x44, 0x24, 0x1d, 0xf6, 0x52,\n 0x72, 0x79, 0xdd, 0x08, 0xa1, 0x2c, 0xbf, 0x75, 0x9f, 0x5e}},\n {1842, {0xd3, 0xc1, 0x90, 0xe9, 0x4b, 0x65, 0xd4, 0xd6, 0x87, 0xf4, 0xa0,\n 0x14, 0xc6, 0x9a, 0x21, 0x93, 0x87, 0x64, 0x19, 0xcc, 0xa9, 0xa4,\n 0x11, 0xf5, 0xdb, 0x10, 0x03, 0x29, 0xb2, 0x44, 0xe7, 0x98}},\n {1906, {0x5a, 0x13, 0x1d, 0xa8, 0x27, 0xb8, 0x8a, 0x0e, 0x43, 0x40, 0x7b,\n 0x2b, 0x61, 0x5a, 0x9b, 0x39, 0x1f, 0x80, 0xee, 0x45, 0xab, 0x70,\n 0x55, 0x6c, 0x13, 0xa4, 0x72, 0xe2, 0xa6, 0xf5, 0x79, 0xb3}},\n {1970, {0x36, 0xaf, 0x67, 0x22, 0xf2, 0xf8, 0x6f, 0x99, 0x3d, 0x5f, 0x36,\n 0x02, 0xc3, 0x1f, 0x3d, 0xea, 0xbd, 0x34, 0xdc, 0xf1, 0xe4, 0xe4,\n 0x78, 0x73, 0x05, 0x20, 0xea, 0xec, 0xf8, 0x71, 0x76, 0xac}},\n {2034, {0xad, 0x21, 0x5f, 0x13, 0xa8, 0xf7, 0x7d, 0xa1, 0xd0, 0x15, 0xc3,\n 0x5a, 0xdd, 0xee, 0xf8, 0x08, 0x54, 0x79, 0x51, 0xa0, 0x1b, 0x06,\n 0x58, 0x0d, 0x06, 0x31, 0x29, 0x3a, 0xab, 0x6b, 0x24, 0x31}},\n {2098, {0x5b, 0xff, 0x21, 0x09, 0x0b, 0x8c, 0x80, 0xcf, 0xaf, 0x9c, 0xae,\n 0x93, 0x11, 0x75, 0x05, 0x3e, 0xb2, 0x37, 0x9b, 0xa4, 0xe5, 0xd5,\n 0xa1, 0x2a, 0x60, 0x7c, 0x55, 0x57, 0x72, 0x10, 0xf0, 0xb3}},\n {2162, {0xad, 0x56, 0x0c, 0xd1, 0x7d, 0x76, 0x14, 0x5f, 0x19, 0x34, 0x14,\n 0x78, 0x31, 0x88, 0x89, 0xdc, 0x35, 0x58, 0xb1, 0x83, 0xed, 0xd4,\n 0x6a, 0x80, 0x07, 0x82, 0x93, 0xdf, 0x94, 0xd9, 0x35, 0x43}},\n {2226, {0x49, 0x2d, 0x5a, 0x85, 0xfc, 0x33, 0x49, 0xc1, 0x01, 0x83, 0xb0,\n 0x54, 0x80, 0x3c, 0x6d, 0x97, 0x52, 0x8d, 0xcf, 0x61, 0x5b, 0x7a,\n 0x6f, 0xfa, 0x12, 0x97, 0xee, 0x46, 0x3b, 0x48, 0x0b, 0x08}},\n {2290, {0x9b, 0xfc, 0x47, 0x6b, 0xc9, 0x7e, 0x17, 0x78, 0xd9, 0x20, 0x9f,\n 0x8e, 0x1f, 0x5b, 0xa5, 0x79, 0x1d, 0xad, 0x62, 0xb0, 0x9d, 0xf2,\n 0x45, 0x33, 0x17, 0x4e, 0xf6, 0x8f, 0x3a, 0x04, 0xfb, 0x11}},\n {2354, {0x7a, 0xbb, 0x72, 0xe9, 0x1a, 0xb0, 0x42, 0x7d, 0xf0, 0x33, 0xaa,\n 0xb7, 0x21, 0xaa, 0x8c, 0x0a, 0xd0, 0x73, 0xe7, 0xd0, 0xea, 0x03,\n 0x40, 0x15, 0xda, 0x17, 0x9c, 0xe7, 0x85, 0xf1, 0x0e, 0x1e}},\n {2418, {0x21, 0xc6, 0xcc, 0xdb, 0x95, 0x84, 0x53, 0x12, 0xe3, 0xc9, 0x35,\n 0xff, 0xb8, 0xff, 0x69, 0xc2, 0x6e, 0x00, 0x4e, 0x9c, 0x10, 0x80,\n 0xb0, 0x0d, 0x82, 0xfb, 0x17, 0x77, 0x98, 0x23, 0x52, 0x66}},\n {2482, {0xda, 0x0f, 0x57, 0x79, 0x4d, 0x99, 0x1e, 0x88, 0xd7, 0x4e, 0x03,\n 0x86, 0x63, 0x2a, 0xeb, 0x24, 0xc8, 0x60, 0xe8, 0xc7, 0xff, 0x62,\n 0x5d, 0x5a, 0xd1, 0x20, 0x03, 0x0c, 0x78, 0xb5, 0xba, 0x62}}};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_SHA256_TEST_VALUES_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_attribute_ids.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_ATTRIBUTE_IDS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_ATTRIBUTE_IDS_H_\n\n#include \n\nnamespace proofs {\n\nstruct MdocAttribute {\n std::string_view identifier;\n std::string_view documentspec;\n};\n\n// Extracted from\n// https://github.com/ISOWG10/ISO-18013/blob/main/Working%20Documents/Working%20Draft%20WG%2010_N2549_ISO-IEC%2018013-5-%20Personal%20identification%20%E2%80%94%20ISO-compliant%20driving%20licence%20%E2%80%94%20Part%205-%20Mobile%20driving%20lic.pdf\n// https://www.aamva.org/getmedia/bb4fee66-592d-4d39-813a-8fdfd910268a/MobileDLGuidelines1-5.pdf\nconstexpr MdocAttribute kMdocAttributes[] = {\n {\"family_name\", \"org.iso.18013.5.1\"},\n {\"given_name\", \"org.iso.18013.5.1\"},\n {\"birth_date\", \"org.iso.18013.5.1\"},\n {\"issue_date\", \"org.iso.18013.5.1\"},\n {\"expiry_date\", \"org.iso.18013.5.1\"},\n {\"issuing_country\", \"org.iso.18013.5.1\"},\n {\"issuing_authority\", \"org.iso.18013.5.1\"},\n {\"document_number\", \"org.iso.18013.5.1\"},\n {\"portrait\", \"org.iso.18013.5.1\"},\n {\"driving_privileges\", \"org.iso.18013.5.1\"},\n {\"un_distinguishing_sign\", \"org.iso.18013.5.1\"},\n {\"administrative_number\", \"org.iso.18013.5.1\"},\n {\"sex\", \"org.iso.18013.5.1\"},\n {\"height\", \"org.iso.18013.5.1\"},\n {\"weight\", \"org.iso.18013.5.1\"},\n {\"eye_colour\", \"org.iso.18013.5.1\"},\n {\"hair_colour\", \"org.iso.18013.5.1\"},\n {\"birth_place\", \"org.iso.18013.5.1\"},\n {\"resident_address\", \"org.iso.18013.5.1\"},\n {\"portrait_capture_date\", \"org.iso.18013.5.1\"},\n {\"age_in_years\", \"org.iso.18013.5.1\"},\n {\"age_birth_year\", \"org.iso.18013.5.1\"},\n {\"age_over_10\", \"org.iso.18013.5.1\"},\n {\"age_over_11\", \"org.iso.18013.5.1\"},\n {\"age_over_12\", \"org.iso.18013.5.1\"},\n {\"age_over_13\", \"org.iso.18013.5.1\"},\n {\"age_over_14\", \"org.iso.18013.5.1\"},\n {\"age_over_15\", \"org.iso.18013.5.1\"},\n {\"age_over_16\", \"org.iso.18013.5.1\"},\n {\"age_over_17\", \"org.iso.18013.5.1\"},\n {\"age_over_18\", \"org.iso.18013.5.1\"},\n {\"age_over_19\", \"org.iso.18013.5.1\"},\n {\"age_over_20\", \"org.iso.18013.5.1\"},\n {\"age_over_21\", \"org.iso.18013.5.1\"},\n {\"age_over_23\", \"org.iso.18013.5.1\"},\n {\"age_over_25\", \"org.iso.18013.5.1\"},\n {\"age_over_50\", \"org.iso.18013.5.1\"},\n {\"age_over_55\", \"org.iso.18013.5.1\"},\n {\"age_over_60\", \"org.iso.18013.5.1\"},\n {\"age_over_65\", \"org.iso.18013.5.1\"},\n {\"age_over_70\", \"org.iso.18013.5.1\"},\n {\"age_over_75\", \"org.iso.18013.5.1\"},\n {\"issuing_jurisdiction\", \"org.iso.18013.5.1\"},\n {\"nationality\", \"org.iso.18013.5.1\"},\n {\"resident_city\", \"org.iso.18013.5.1\"},\n {\"resident_state\", \"org.iso.18013.5.1\"},\n {\"resident_postal_code\", \"org.iso.18013.5.1\"},\n {\"resident_country\", \"org.iso.18013.5.1\"},\n {\"biometric_template_face\", \"org.iso.18013.5.1\"},\n {\"biometric_template_voice\", \"org.iso.18013.5.1\"},\n {\"biometric_template_finger\", \"org.iso.18013.5.1\"},\n {\"biometric_template_iris\", \"org.iso.18013.5.1\"},\n {\"biometric_template_retina\", \"org.iso.18013.5.1\"},\n {\"biometric_template_hand_geometry\", \"org.iso.18013.5.1\"},\n {\"biometric_template_keystroke\", \"org.iso.18013.5.1\"},\n {\"biometric_template_signature_sign\", \"org.iso.18013.5.1\"},\n {\"biometric_template_lip_movement\", \"org.iso.18013.5.1\"},\n {\"biometric_template_thermal_face\", \"org.iso.18013.5.1\"},\n {\"biometric_template_thermal_hand\", \"org.iso.18013.5.1\"},\n {\"biometric_template_gait\", \"org.iso.18013.5.1\"},\n {\"biometric_template_body_odor\", \"org.iso.18013.5.1\"},\n {\"biometric_template_dna\", \"org.iso.18013.5.1\"},\n {\"biometric_template_ear\", \"org.iso.18013.5.1\"},\n {\"biometric_template_finger_geometry\", \"org.iso.18013.5.1\"},\n {\"biometric_template_palm_geometry\", \"org.iso.18013.5.1\"},\n {\"biometric_template_vein_pattern\", \"org.iso.18013.5.1\"},\n {\"biometric_template_foot_print\", \"org.iso.18013.5.1\"},\n {\"family_name_national_character\", \"org.iso.18013.5.1\"},\n {\"given_name_national_character\", \"org.iso.18013.5.1\"},\n {\"signature_usual_mark\", \"org.iso.18013.5.1\"},\n\n {\"name_suffix\", \"org.iso.18013.5.1.aamva\"},\n {\"organ_donor\", \"org.iso.18013.5.1.aamva\"},\n {\"veteran\", \"org.iso.18013.5.1.aamva\"},\n {\"family_name_truncation\", \"org.iso.18013.5.1.aamva\"},\n {\"given_name_truncation\", \"org.iso.18013.5.1.aamva\"},\n {\"aka_family_name.v2\", \"org.iso.18013.5.1.aamva\"},\n {\"aka_given_name.v2\", \"org.iso.18013.5.1.aamva\"},\n {\"aka_suffix\", \"org.iso.18013.5.1.aamva\"},\n {\"weight_range\", \"org.iso.18013.5.1.aamva\"},\n {\"race_ethnicity\", \"org.iso.18013.5.1.aamva\"},\n {\"sex\", \"org.iso.18013.5.1.aamva\"},\n {\"first_name\", \"org.iso.18013.5.1.aamva\"},\n {\"middle_names\", \"org.iso.18013.5.1.aamva\"},\n {\"first_name_truncation\", \"org.iso.18013.5.1.aamva\"},\n {\"middle_names_truncation\", \"org.iso.18013.5.1.aamva\"},\n {\"EDL_credential\", \"org.iso.18013.5.1.aamva\"},\n {\"EDL_credential.v2\", \"org.iso.18013.5.1.aamva\"},\n {\"DHS_compliance\", \"org.iso.18013.5.1.aamva\"},\n {\"resident_county\", \"org.iso.18013.5.1.aamva\"},\n {\"resident_county.v2\", \"org.iso.18013.5.1.aamva\"},\n {\"hazmat_endorsement_expiration_date\", \"org.iso.18013.5.1.aamva\"},\n {\"CDL_indicator\", \"org.iso.18013.5.1.aamva\"},\n {\"CDL_non_domiciled\", \"org.iso.18013.5.1.aamva\"},\n {\"CDL_non_domiciled.v2\", \"org.iso.18013.5.1.aamva\"},\n {\"DHS_compliance_text\", \"org.iso.18013.5.1.aamva\"},\n {\"DHS_temporary_lawful_status\", \"org.iso.18013.5.1.aamva\"},\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_ATTRIBUTE_IDS_H_\n"], ["/longfellow-zk/lib/util/serialization.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_UTIL_SERIALIZATION_H_\n#define PRIVACY_PROOFS_ZK_LIB_UTIL_SERIALIZATION_H_\n\n#include \n\nnamespace proofs {\n\nstatic inline void u64_to_le(uint8_t a[/*8*/], uint64_t x) {\n a[0] = x & 0xffu;\n a[1] = (x >> 8) & 0xffu;\n a[2] = (x >> 16) & 0xffu;\n a[3] = (x >> 24) & 0xffu;\n a[4] = (x >> 32) & 0xffu;\n a[5] = (x >> 40) & 0xffu;\n a[6] = (x >> 48) & 0xffu;\n a[7] = (x >> 56) & 0xffu;\n}\n\nstatic inline uint64_t u64_of_le(const uint8_t a[/*8*/]) {\n return ((uint64_t)a[7] << 56) | ((uint64_t)a[6] << 48) |\n ((uint64_t)a[5] << 40) | ((uint64_t)a[4] << 32) |\n ((uint64_t)a[3] << 24) | ((uint64_t)a[2] << 16) |\n ((uint64_t)a[1] << 8) | (uint64_t)a[0];\n}\n\nstatic inline void u32_to_le(uint8_t a[/*4*/], uint32_t x) {\n a[0] = x & 0xffu;\n a[1] = (x >> 8) & 0xffu;\n a[2] = (x >> 16) & 0xffu;\n a[3] = (x >> 24) & 0xffu;\n}\n\nstatic inline uint32_t u32_of_le(const uint8_t a[/*4*/]) {\n return ((uint32_t)a[3] << 24) | ((uint32_t)a[2] << 16) |\n ((uint32_t)a[1] << 8) | (uint32_t)a[0];\n}\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_UTIL_SERIALIZATION_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_1f_io.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_1F_IO_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_1F_IO_H_\n\n#include \n\n#include \"circuits/mdoc/mdoc_constants.h\"\n\nnamespace proofs {\n\nstatic constexpr size_t kMdoc1DateLen = 20; // Length of CBOR-formatted time.\nstatic constexpr size_t kMdoc1MaxSHABlocks = 7;\nstatic constexpr size_t kMdoc1CborIndexBits = 9;\nstatic constexpr size_t kMdoc1MaxMsoLen =\n kMdoc1MaxSHABlocks * 64 - 9 - kCose1PrefixLen;\nstatic constexpr size_t kMdoc1SHAPluckerBits = 3;\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_1F_IO_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_examples.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_EXAMPLES_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_EXAMPLES_H_\n\n#include \n#include \n\n#include \"algebra/static_string.h\"\n\nnamespace proofs {\n\nstatic const StaticString kIssuerPKX[] = {\n StaticString(\n \"0x2c80c10bf70f63bddcc41ea20d76a22ecba2a97fa8811bf19d572433b12c0c1f\"),\n StaticString(\n \"0xcc900843699408936c912474a27abb7b62d7c90e4f6d8557714825476eee2366\"),\n StaticString(\n \"0xdc1c1f55cff4cd5c76cf4169278f7217667f86ee81d8669b63f2e19bc12a0c9f\"),\n\n // AZ MVMProdCA\n StaticString(\n \"0xbace36c902b2bdfc41b4b36ae7e56b17d571424d8a04395cb2d9d42325436c5b\"),\n // AZ MVMProdCA\n StaticString(\n \"0x8b90d350003c890c55f8d5ec8c8d39a6eb3a7551a6fa5ca3c68cbeca32fe6666\"),\n // US-AZ MVMTestCA\n StaticString(\n \"0xf228c62ac2cbafff3fa728010b4a99c098e5d0ff27084155950c4e3fdabbff47\"),\n // California DMV IACA Root\n StaticString(\n \"0x60cca07942c457606c6621aa40de294ba17083c604cc236240ac0ef6550f602f\"),\n // Colorado Root Certificate\n StaticString(\n \"0xc3b5f6418a146d4f840ee9bf47d18eb1b27705abca2c423692721795fb8ff5cb\"),\n // CO DRIVES Root\n StaticString(\n \"0xe93b68b25e9a8c8a42b24e3595b83dbe2a2091d3e18cf0a735062abca578b4a4\"),\n // Georgia Root Certificate Authority\n StaticString(\n \"0xac469d749c214ab56eac24bd3130f30a0c291e28571c2dd4462a5da037db67cc\"),\n // Georgia Root Certificate Authority\n StaticString(\n \"0xbcc1c0025e04d985a34519e1ab3f721556aaa8ab658e591bb2bed40044782de0\"),\n // Maryland MVA, CN=Fast Enterprises Root\n StaticString(\n \"0x69670a22a94059ba15f774406b969dd0b2419fc5b4ff2630b4ec94971b93c68a\"),\n // Maryland MVA, CN=Fast Enterprises Root\n StaticString(\n \"0x530664d11e9e497f2d56ecb45ec876a543e5c153009f7b460514055883f9d0c6\"),\n // New Mexico Root Certificate Authority\n StaticString(\n \"0xe17985694bcec58d553e0f6d5179a53279264755c32d5d03148499b8eeeb7348\"),\n // Google UL TESTING Staging DS\n StaticString(\n \"0xcc900843699408936c912474a27abb7b62d7c90e4f6d8557714825476eee2366\"),\n // C=US\n StaticString(\n \"0xd2cfd2ab7d5b52d6ce2178bf94505d1435c87572a7874e6ad4acf18bd35c1be1\"),\n // State Of Utopia Issuing Authority Signing Key\n StaticString(\n \"0xac33541815b08cdd996aa325ba1a2b6f5c87a755c0c05956dca8b5dbdf73af69\"),\n};\n\nstatic const StaticString kIssuerPKY[] = {\n StaticString(\n \"0x3f994c043be7e17dd08387281bac0c37a529361b3cb36a0fac38d41ac066f903\"),\n StaticString(\n \"0xb19764d33b530e9bd6a87081f1d8e5cbc80db640ac962ee8a3e0393c14c6bfb4\"),\n StaticString(\n \"0x12355dd0385fed3bc33bedc9781b9aad47b33e4c24704b8d14288b1b3cb45c28\"),\n\n // AZ MVMProdCA\n StaticString(\n \"0xc2b612dd77e71e4a3a8642d4ef5a106b4e97618b194d2c1babdcae21f8304589\"),\n // AZ MVMProdCA\n StaticString(\n \"0x9a81b4198f1321f17f3caf33fac082f3dff6777185e8de2bb9cea8475b317fb7\"),\n // US-AZ MVMTestCA\n StaticString(\n \"0x1f79e1ecc5b9c6844bffa4c10b41cdbf4d514641a44eb6954913909db0964ed1\"),\n // California DMV IACA Root\n StaticString(\n \"0x60c82a4040725298b62c7bbd0c146e16c7efa9a799b3854b1625089b6295f975\"),\n // Colorado Root Certificate\n StaticString(\n \"0x22134720c33bbcddc1e237c24a27e535b9f33d4d60752b03be8231e8569bdc8c\"),\n // CO DRIVES Root\n StaticString(\n \"0x0f9ec3881c5ffbf7c360aaf4f591003f4b08aebe992cb7a8d5ccd8e77dbeacae\"),\n // Georgia Root Certificate Authority\n StaticString(\n \"0x68bd68479edf3f52faf387d84293c455668aa126092d6ee4b5c22a42c8abe0fe\"),\n // Georgia Root Certificate Authority\n StaticString(\n \"0x33630d016957de6e6a4b65b2827081886e520c84317af6af53846ceb2b1d7755\"),\n // Maryland MVA, CN=Fast Enterprises Root\n StaticString(\n \"0x3848f928aca98ecf71214e10be538591aedd776929c2b09b4afb0681160857bb\"),\n // Maryland MVA, CN=Fast Enterprises Root\n StaticString(\n \"0x79a63d1496b6ae12bf7946adeb5207b86a350927345248fcdcf3d781b24dc7c6\"),\n // New Mexico Root Certificate Authority\n StaticString(\n \"0x9b52d953a90b66dfcdf295663bc8304945915b751227516c0f5d1d563e914ab3\"),\n // Google UL TESTING Staging DS\n StaticString(\n \"0xb19764d33b530e9bd6a87081f1d8e5cbc80db640ac962ee8a3e0393c14c6bfb4\"),\n // C=US\n StaticString(\n \"0x8ab996be9c14dd5749bf9ad85d373f9bc4ee360428ef152823c6125b6c1fcb51\"),\n // State Of Utopia Issuing Authority Signing Key\n StaticString(\n \"0xb8555be0e8944c3f684b649cf2786a59fe7db6e73c27d4298fe903e3711a7017\"),\n};\n\nstatic const char *kIDPass = \"com.google.wallet.idcard.1\";\nstatic const char *kMDL = \"org.iso.18013.5.1.mDL\";\n\nstruct MdocTests {\n StaticString pkx, pky; /* public key of the issuer */\n uint8_t transcript[1024];\n size_t transcript_size;\n uint8_t *now;\n const char *doc_type;\n size_t mdoc_size;\n uint8_t mdoc[5000];\n};\n\n// These mdoc examples are used in several tests.\nstatic const struct MdocTests mdoc_tests[] = {\n // First example only has \"age_over_18\"\n {StaticString(\n \"0x2c80c10bf70f63bddcc41ea20d76a22ecba2a97fa8811bf19d572433b12c0c1f\"),\n StaticString(\n \"0x3f994c043be7e17dd08387281bac0c37a529361b3cb36a0fac38d41ac066f903\"),\n {0x83, 0xf6, 0xf6, 0x84, 0x71, 0x41, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64,\n 0x48, 0x61, 0x6e, 0x64, 0x6f, 0x76, 0x65, 0x72, 0x76, 0x31, 0x58, 0x20,\n 0x2e, 0x10, 0x05, 0xb3, 0xa9, 0xc8, 0xf0, 0xdf, 0x04, 0xdb, 0x42, 0x30,\n 0x01, 0xc8, 0xb5, 0x39, 0x03, 0xfe, 0xd0, 0x71, 0xba, 0x50, 0x24, 0xc3,\n 0xba, 0x69, 0x74, 0x0e, 0x62, 0xd4, 0x91, 0x7e, 0x58, 0x19, 0x63, 0x6f,\n 0x6d, 0x2e, 0x61, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x2e, 0x6d, 0x64,\n 0x6c, 0x2e, 0x61, 0x70, 0x70, 0x72, 0x65, 0x61, 0x64, 0x65, 0x72, 0x58,\n 0x20, 0xd8, 0xe7, 0x3c, 0x70, 0x60, 0xe3, 0xe8, 0x0d, 0x3d, 0xef, 0xc2,\n 0x63, 0x4e, 0xb0, 0x4d, 0x08, 0xc6, 0x56, 0xe2, 0x60, 0x68, 0xd8, 0xa5,\n 0x63, 0xf5, 0xb9, 0x45, 0x85, 0xda, 0xe1, 0x4f, 0xad},\n 117,\n (uint8_t *)\"2024-01-30T09:00:00Z\",\n kMDL,\n 1452,\n {0xa3, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e,\n 0x30, 0x69, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x81,\n 0xa3, 0x67, 0x64, 0x6f, 0x63, 0x54, 0x79, 0x70, 0x65, 0x75, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x2e, 0x6d, 0x44, 0x4c, 0x6c, 0x69, 0x73, 0x73, 0x75,\n 0x65, 0x72, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xa2, 0x6a, 0x6e, 0x61,\n 0x6d, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x73, 0xa1, 0x71, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x81, 0xd8, 0x18, 0x58, 0x4f, 0xa4, 0x68, 0x64, 0x69,\n 0x67, 0x65, 0x73, 0x74, 0x49, 0x44, 0x00, 0x66, 0x72, 0x61, 0x6e, 0x64,\n 0x6f, 0x6d, 0x50, 0xf1, 0x10, 0x59, 0xeb, 0x6f, 0xbc, 0xe6, 0x26, 0x55,\n 0xdf, 0xbd, 0x6f, 0x83, 0xb8, 0x96, 0x70, 0x71, 0x65, 0x6c, 0x65, 0x6d,\n 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65,\n 0x72, 0x6b, 0x61, 0x67, 0x65, 0x5f, 0x6f, 0x76, 0x65, 0x72, 0x5f, 0x31,\n 0x38, 0x6c, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x56, 0x61, 0x6c,\n 0x75, 0x65, 0xf5, 0x6a, 0x69, 0x73, 0x73, 0x75, 0x65, 0x72, 0x41, 0x75,\n 0x74, 0x68, 0x84, 0x43, 0xa1, 0x01, 0x26, 0xa1, 0x18, 0x21, 0x59, 0x02,\n 0x27, 0x30, 0x82, 0x02, 0x23, 0x30, 0x82, 0x01, 0xa9, 0xa0, 0x03, 0x02,\n 0x01, 0x02, 0x02, 0x10, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x5f, 0x54,\n 0x65, 0x73, 0x74, 0x5f, 0x44, 0x53, 0x5f, 0x31, 0x30, 0x0a, 0x06, 0x08,\n 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x03, 0x30, 0x3c, 0x31, 0x0b,\n 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31,\n 0x0e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x05, 0x55, 0x53,\n 0x2d, 0x4d, 0x41, 0x31, 0x1d, 0x30, 0x1b, 0x06, 0x03, 0x55, 0x04, 0x03,\n 0x0c, 0x14, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x20, 0x54, 0x45, 0x53,\n 0x54, 0x20, 0x49, 0x41, 0x43, 0x41, 0x20, 0x6d, 0x44, 0x4c, 0x30, 0x1e,\n 0x17, 0x0d, 0x32, 0x33, 0x30, 0x37, 0x32, 0x36, 0x30, 0x30, 0x30, 0x30,\n 0x30, 0x31, 0x5a, 0x17, 0x0d, 0x32, 0x34, 0x31, 0x30, 0x32, 0x35, 0x30,\n 0x30, 0x30, 0x30, 0x30, 0x31, 0x5a, 0x30, 0x3a, 0x31, 0x0b, 0x30, 0x09,\n 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x0e, 0x30,\n 0x0c, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x05, 0x55, 0x53, 0x2d, 0x4d,\n 0x41, 0x31, 0x1b, 0x30, 0x19, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x12,\n 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x20, 0x54, 0x45, 0x53, 0x54, 0x20,\n 0x44, 0x53, 0x20, 0x6d, 0x44, 0x4c, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07,\n 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48,\n 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x2c, 0x80, 0xc1,\n 0x0b, 0xf7, 0x0f, 0x63, 0xbd, 0xdc, 0xc4, 0x1e, 0xa2, 0x0d, 0x76, 0xa2,\n 0x2e, 0xcb, 0xa2, 0xa9, 0x7f, 0xa8, 0x81, 0x1b, 0xf1, 0x9d, 0x57, 0x24,\n 0x33, 0xb1, 0x2c, 0x0c, 0x1f, 0x3f, 0x99, 0x4c, 0x04, 0x3b, 0xe7, 0xe1,\n 0x7d, 0xd0, 0x83, 0x87, 0x28, 0x1b, 0xac, 0x0c, 0x37, 0xa5, 0x29, 0x36,\n 0x1b, 0x3c, 0xb3, 0x6a, 0x0f, 0xac, 0x38, 0xd4, 0x1a, 0xc0, 0x66, 0xf9,\n 0x03, 0xa3, 0x81, 0x8e, 0x30, 0x81, 0x8b, 0x30, 0x1f, 0x06, 0x03, 0x55,\n 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xde, 0xf3, 0xab, 0x6d,\n 0x37, 0xde, 0x9e, 0x3a, 0x81, 0x6e, 0x10, 0x32, 0xd0, 0x2b, 0x48, 0xaf,\n 0x35, 0x8a, 0x71, 0xab, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04,\n 0x16, 0x04, 0x14, 0x39, 0x7b, 0xe5, 0x3c, 0x50, 0xdf, 0xf0, 0xd7, 0xa2,\n 0xe4, 0xa9, 0xe4, 0x65, 0xea, 0x73, 0x7a, 0x9e, 0xd8, 0x92, 0xc8, 0x30,\n 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03,\n 0x02, 0x07, 0x80, 0x30, 0x22, 0x06, 0x03, 0x55, 0x1d, 0x12, 0x04, 0x1b,\n 0x30, 0x19, 0x86, 0x17, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f,\n 0x77, 0x77, 0x77, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63,\n 0x6f, 0x6d, 0x2f, 0x30, 0x15, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x01, 0x01,\n 0xff, 0x04, 0x0b, 0x30, 0x09, 0x06, 0x07, 0x28, 0x81, 0x8c, 0x5d, 0x05,\n 0x01, 0x02, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04,\n 0x03, 0x03, 0x03, 0x68, 0x00, 0x30, 0x65, 0x02, 0x31, 0x00, 0xa2, 0x5c,\n 0xdb, 0x8a, 0x6f, 0x0c, 0x23, 0x90, 0x5b, 0x9d, 0x3f, 0x58, 0x2a, 0x60,\n 0x8f, 0x0c, 0x16, 0xf4, 0x36, 0xb5, 0xee, 0xe3, 0x58, 0x7d, 0x2c, 0xa9,\n 0x77, 0x16, 0x7c, 0x6f, 0x16, 0xa2, 0xb9, 0xde, 0x10, 0xfe, 0x1d, 0xdd,\n 0x16, 0xde, 0x07, 0x2e, 0x4f, 0x86, 0x6f, 0x06, 0x05, 0xa7, 0x02, 0x30,\n 0x6a, 0x48, 0x89, 0x42, 0x1f, 0x9b, 0xb3, 0x74, 0xb8, 0xbd, 0xe1, 0x75,\n 0xb3, 0xd6, 0xab, 0x23, 0x21, 0x6b, 0xa9, 0x7e, 0x68, 0x95, 0x10, 0x97,\n 0x4a, 0xe0, 0xf6, 0x59, 0xa1, 0x0e, 0x95, 0x84, 0x69, 0xb5, 0xbd, 0x80,\n 0xdf, 0xc1, 0x05, 0x88, 0x83, 0x1d, 0x93, 0x19, 0x81, 0xa6, 0x39, 0x98,\n 0x59, 0x01, 0xe8, 0xd8, 0x18, 0x59, 0x01, 0xe3, 0xa6, 0x67, 0x76, 0x65,\n 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e, 0x30, 0x6f, 0x64, 0x69,\n 0x67, 0x65, 0x73, 0x74, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68,\n 0x6d, 0x67, 0x53, 0x48, 0x41, 0x2d, 0x32, 0x35, 0x36, 0x67, 0x64, 0x6f,\n 0x63, 0x54, 0x79, 0x70, 0x65, 0x75, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73,\n 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0x2e,\n 0x6d, 0x44, 0x4c, 0x6c, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x44, 0x69, 0x67,\n 0x65, 0x73, 0x74, 0x73, 0xa1, 0x71, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73,\n 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0xa5,\n 0x01, 0x58, 0x20, 0xad, 0xf6, 0xa3, 0x33, 0x03, 0x6a, 0xde, 0xfc, 0x48,\n 0x90, 0xdf, 0x38, 0xe0, 0xf7, 0x37, 0x22, 0x90, 0x85, 0xa9, 0xb0, 0xba,\n 0x7c, 0x07, 0x19, 0xd3, 0x92, 0x40, 0x5d, 0x74, 0x46, 0x23, 0x77, 0x02,\n 0x58, 0x20, 0xa0, 0xa1, 0x4a, 0x5a, 0xa1, 0xb3, 0x36, 0x84, 0x4d, 0x8f,\n 0x8d, 0x14, 0x8e, 0xd4, 0x4f, 0xd2, 0xcc, 0xc6, 0x6f, 0x54, 0xd8, 0x78,\n 0x2b, 0x70, 0xfb, 0x77, 0x13, 0xfb, 0x3c, 0x93, 0xf5, 0x56, 0x03, 0x58,\n 0x20, 0x97, 0xb0, 0x18, 0x4e, 0xdd, 0xe3, 0x99, 0xcb, 0x7d, 0xea, 0x2d,\n 0x7d, 0x27, 0x9a, 0x45, 0x69, 0x90, 0xd9, 0xf3, 0x12, 0x46, 0x71, 0x63,\n 0x78, 0x7e, 0x1b, 0xa7, 0x66, 0x0a, 0x5c, 0x08, 0x6f, 0x04, 0x58, 0x20,\n 0xaf, 0x0b, 0x9f, 0xe7, 0x24, 0x5c, 0xa9, 0xa5, 0x9f, 0x64, 0xb1, 0xaa,\n 0x82, 0xcc, 0x2c, 0x1a, 0xb1, 0x38, 0x6f, 0x77, 0x95, 0x64, 0x93, 0x83,\n 0x62, 0x97, 0xc8, 0xa8, 0x4d, 0x2a, 0xe0, 0xb4, 0x00, 0x58, 0x20, 0x0d,\n 0x98, 0x54, 0xdb, 0x51, 0x48, 0x6f, 0xf4, 0x49, 0x07, 0xbc, 0x61, 0x4f,\n 0xfa, 0xea, 0x93, 0xda, 0xe1, 0xa8, 0x9e, 0xad, 0x40, 0x26, 0x3f, 0x90,\n 0x1a, 0xe6, 0xce, 0x41, 0x26, 0x46, 0x21, 0x6d, 0x64, 0x65, 0x76, 0x69,\n 0x63, 0x65, 0x4b, 0x65, 0x79, 0x49, 0x6e, 0x66, 0x6f, 0xa1, 0x69, 0x64,\n 0x65, 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79, 0xa4, 0x01, 0x02, 0x20,\n 0x01, 0x21, 0x58, 0x20, 0xc3, 0x14, 0xa7, 0xab, 0xba, 0x07, 0xe4, 0x0e,\n 0x64, 0xae, 0x87, 0xdb, 0x4a, 0xd9, 0x71, 0x80, 0x13, 0xfd, 0x39, 0x8e,\n 0x6e, 0x23, 0x17, 0xb3, 0x04, 0xf5, 0x7f, 0xc9, 0xac, 0xca, 0xb9, 0xf5,\n 0x22, 0x58, 0x20, 0xed, 0xb8, 0xb0, 0x23, 0x0c, 0xcc, 0x98, 0xdd, 0x42,\n 0xcd, 0xff, 0x89, 0xa8, 0xd1, 0xe2, 0x5f, 0xf8, 0xd1, 0xa7, 0xfa, 0x38,\n 0x9e, 0x92, 0xdc, 0x8f, 0x01, 0xaf, 0x98, 0x5a, 0x79, 0xef, 0xcc, 0x6c,\n 0x76, 0x61, 0x6c, 0x69, 0x64, 0x69, 0x74, 0x79, 0x49, 0x6e, 0x66, 0x6f,\n 0xa3, 0x66, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xc0, 0x74, 0x32, 0x30,\n 0x32, 0x34, 0x2d, 0x30, 0x31, 0x2d, 0x32, 0x35, 0x54, 0x32, 0x31, 0x3a,\n 0x31, 0x32, 0x3a, 0x35, 0x39, 0x5a, 0x69, 0x76, 0x61, 0x6c, 0x69, 0x64,\n 0x46, 0x72, 0x6f, 0x6d, 0xc0, 0x74, 0x32, 0x30, 0x32, 0x34, 0x2d, 0x30,\n 0x31, 0x2d, 0x32, 0x35, 0x54, 0x32, 0x31, 0x3a, 0x31, 0x32, 0x3a, 0x35,\n 0x39, 0x5a, 0x6a, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x55, 0x6e, 0x74, 0x69,\n 0x6c, 0xc0, 0x74, 0x32, 0x30, 0x32, 0x34, 0x2d, 0x30, 0x32, 0x2d, 0x32,\n 0x34, 0x54, 0x32, 0x31, 0x3a, 0x31, 0x32, 0x3a, 0x35, 0x39, 0x5a, 0x58,\n 0x40, 0x67, 0x00, 0x7b, 0xe9, 0x95, 0xa3, 0xe7, 0x43, 0x94, 0x5c, 0x4f,\n 0xb1, 0xc5, 0x8a, 0xe8, 0x9d, 0x72, 0xd4, 0x97, 0x31, 0x82, 0x51, 0xd9,\n 0xf1, 0x97, 0x4f, 0x08, 0xe5, 0x13, 0x89, 0xc8, 0x6d, 0x40, 0x11, 0x01,\n 0x48, 0x8f, 0xc3, 0x7e, 0x66, 0x55, 0x46, 0x49, 0x53, 0xc5, 0x1c, 0x4f,\n 0x8c, 0x64, 0xb9, 0x60, 0x13, 0xa1, 0xab, 0x04, 0xa9, 0xa6, 0x5b, 0x80,\n 0xfd, 0x2f, 0x3b, 0x5c, 0xa3, 0x6c, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65,\n 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xa2, 0x6a, 0x6e, 0x61, 0x6d, 0x65,\n 0x53, 0x70, 0x61, 0x63, 0x65, 0x73, 0xd8, 0x18, 0x41, 0xa0, 0x6a, 0x64,\n 0x65, 0x76, 0x69, 0x63, 0x65, 0x41, 0x75, 0x74, 0x68, 0xa1, 0x6f, 0x64,\n 0x65, 0x76, 0x69, 0x63, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75,\n 0x72, 0x65, 0x84, 0x43, 0xa1, 0x01, 0x26, 0xa0, 0xf6, 0x58, 0x40, 0xcf,\n 0xb0, 0xac, 0x1a, 0x63, 0x1b, 0x06, 0xe1, 0xb5, 0xd5, 0x03, 0x16, 0xfa,\n 0x43, 0xda, 0xb2, 0x38, 0x86, 0xa2, 0x6b, 0x67, 0x6c, 0x33, 0xba, 0xb4,\n 0x52, 0x63, 0x4c, 0xba, 0xdf, 0xd1, 0xb3, 0xab, 0xd1, 0xbd, 0x7a, 0x5e,\n 0x3c, 0x36, 0x97, 0xde, 0x7c, 0xe1, 0xfc, 0x00, 0x4a, 0x90, 0xde, 0x84,\n 0xe0, 0x62, 0x64, 0xfe, 0x95, 0x78, 0x81, 0x98, 0xac, 0xdc, 0x3e, 0x4c,\n 0x57, 0x5d, 0x59, 0x66, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x00}},\n {\n StaticString(\"0x2c80c10bf70f63bddcc41ea20d76a22ecba2a97fa8811bf19d57243\"\n \"3b12c0c1f\"),\n StaticString(\"0x3f994c043be7e17dd08387281bac0c37a529361b3cb36a0fac38d41\"\n \"ac066f903\"),\n {0x83, 0xf6, 0xf6, 0x84, 0x71, 0x41, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64,\n 0x48, 0x61, 0x6e, 0x64, 0x6f, 0x76, 0x65, 0x72, 0x76, 0x31, 0x58, 0x20,\n 0x2e, 0x10, 0x05, 0xb3, 0xa9, 0xc8, 0xf0, 0xdf, 0x04, 0xdb, 0x42, 0x30,\n 0x01, 0xc8, 0xb5, 0x39, 0x03, 0xfe, 0xd0, 0x71, 0xba, 0x50, 0x24, 0xc3,\n 0xba, 0x69, 0x74, 0x0e, 0x62, 0xd4, 0x91, 0x7e, 0x58, 0x19, 0x63, 0x6f,\n 0x6d, 0x2e, 0x61, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x2e, 0x6d, 0x64,\n 0x6c, 0x2e, 0x61, 0x70, 0x70, 0x72, 0x65, 0x61, 0x64, 0x65, 0x72, 0x58,\n 0x20, 0xd8, 0xe7, 0x3c, 0x70, 0x60, 0xe3, 0xe8, 0x0d, 0x3d, 0xef, 0xc2,\n 0x63, 0x4e, 0xb0, 0x4d, 0x08, 0xc6, 0x56, 0xe2, 0x60, 0x68, 0xd8, 0xa5,\n 0x63, 0xf5, 0xb9, 0x45, 0x85, 0xda, 0xe1, 0x4f, 0xad},\n 117,\n (uint8_t *)\"2024-01-31T09:00:00Z\",\n kMDL,\n 1488,\n {0xa3, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e,\n 0x30, 0x69, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x81,\n 0xa3, 0x67, 0x64, 0x6f, 0x63, 0x54, 0x79, 0x70, 0x65, 0x75, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x2e, 0x6d, 0x44, 0x4c, 0x6c, 0x69, 0x73, 0x73, 0x75,\n 0x65, 0x72, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xa2, 0x6a, 0x6e, 0x61,\n 0x6d, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x73, 0xa1, 0x71, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x81, 0xd8, 0x18, 0x58, 0x4f, 0xa4, 0x68, 0x64, 0x69,\n 0x67, 0x65, 0x73, 0x74, 0x49, 0x44, 0x02, 0x66, 0x72, 0x61, 0x6e, 0x64,\n 0x6f, 0x6d, 0x50, 0x52, 0xd8, 0x3d, 0xee, 0xdc, 0x0b, 0xf6, 0x62, 0x05,\n 0x83, 0x5c, 0xcc, 0x16, 0xad, 0x68, 0x2d, 0x71, 0x65, 0x6c, 0x65, 0x6d,\n 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65,\n 0x72, 0x6b, 0x61, 0x67, 0x65, 0x5f, 0x6f, 0x76, 0x65, 0x72, 0x5f, 0x31,\n 0x38, 0x6c, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x56, 0x61, 0x6c,\n 0x75, 0x65, 0xf5, 0x6a, 0x69, 0x73, 0x73, 0x75, 0x65, 0x72, 0x41, 0x75,\n 0x74, 0x68, 0x84, 0x43, 0xa1, 0x01, 0x26, 0xa1, 0x18, 0x21, 0x59, 0x02,\n 0x27, 0x30, 0x82, 0x02, 0x23, 0x30, 0x82, 0x01, 0xa9, 0xa0, 0x03, 0x02,\n 0x01, 0x02, 0x02, 0x10, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x5f, 0x54,\n 0x65, 0x73, 0x74, 0x5f, 0x44, 0x53, 0x5f, 0x31, 0x30, 0x0a, 0x06, 0x08,\n 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x03, 0x30, 0x3c, 0x31, 0x0b,\n 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31,\n 0x0e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x05, 0x55, 0x53,\n 0x2d, 0x4d, 0x41, 0x31, 0x1d, 0x30, 0x1b, 0x06, 0x03, 0x55, 0x04, 0x03,\n 0x0c, 0x14, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x20, 0x54, 0x45, 0x53,\n 0x54, 0x20, 0x49, 0x41, 0x43, 0x41, 0x20, 0x6d, 0x44, 0x4c, 0x30, 0x1e,\n 0x17, 0x0d, 0x32, 0x33, 0x30, 0x37, 0x32, 0x36, 0x30, 0x30, 0x30, 0x30,\n 0x30, 0x31, 0x5a, 0x17, 0x0d, 0x32, 0x34, 0x31, 0x30, 0x32, 0x35, 0x30,\n 0x30, 0x30, 0x30, 0x30, 0x31, 0x5a, 0x30, 0x3a, 0x31, 0x0b, 0x30, 0x09,\n 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x0e, 0x30,\n 0x0c, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x05, 0x55, 0x53, 0x2d, 0x4d,\n 0x41, 0x31, 0x1b, 0x30, 0x19, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x12,\n 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x20, 0x54, 0x45, 0x53, 0x54, 0x20,\n 0x44, 0x53, 0x20, 0x6d, 0x44, 0x4c, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07,\n 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48,\n 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x2c, 0x80, 0xc1,\n 0x0b, 0xf7, 0x0f, 0x63, 0xbd, 0xdc, 0xc4, 0x1e, 0xa2, 0x0d, 0x76, 0xa2,\n 0x2e, 0xcb, 0xa2, 0xa9, 0x7f, 0xa8, 0x81, 0x1b, 0xf1, 0x9d, 0x57, 0x24,\n 0x33, 0xb1, 0x2c, 0x0c, 0x1f, 0x3f, 0x99, 0x4c, 0x04, 0x3b, 0xe7, 0xe1,\n 0x7d, 0xd0, 0x83, 0x87, 0x28, 0x1b, 0xac, 0x0c, 0x37, 0xa5, 0x29, 0x36,\n 0x1b, 0x3c, 0xb3, 0x6a, 0x0f, 0xac, 0x38, 0xd4, 0x1a, 0xc0, 0x66, 0xf9,\n 0x03, 0xa3, 0x81, 0x8e, 0x30, 0x81, 0x8b, 0x30, 0x1f, 0x06, 0x03, 0x55,\n 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xde, 0xf3, 0xab, 0x6d,\n 0x37, 0xde, 0x9e, 0x3a, 0x81, 0x6e, 0x10, 0x32, 0xd0, 0x2b, 0x48, 0xaf,\n 0x35, 0x8a, 0x71, 0xab, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04,\n 0x16, 0x04, 0x14, 0x39, 0x7b, 0xe5, 0x3c, 0x50, 0xdf, 0xf0, 0xd7, 0xa2,\n 0xe4, 0xa9, 0xe4, 0x65, 0xea, 0x73, 0x7a, 0x9e, 0xd8, 0x92, 0xc8, 0x30,\n 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03,\n 0x02, 0x07, 0x80, 0x30, 0x22, 0x06, 0x03, 0x55, 0x1d, 0x12, 0x04, 0x1b,\n 0x30, 0x19, 0x86, 0x17, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f,\n 0x77, 0x77, 0x77, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63,\n 0x6f, 0x6d, 0x2f, 0x30, 0x15, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x01, 0x01,\n 0xff, 0x04, 0x0b, 0x30, 0x09, 0x06, 0x07, 0x28, 0x81, 0x8c, 0x5d, 0x05,\n 0x01, 0x02, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04,\n 0x03, 0x03, 0x03, 0x68, 0x00, 0x30, 0x65, 0x02, 0x31, 0x00, 0xa2, 0x5c,\n 0xdb, 0x8a, 0x6f, 0x0c, 0x23, 0x90, 0x5b, 0x9d, 0x3f, 0x58, 0x2a, 0x60,\n 0x8f, 0x0c, 0x16, 0xf4, 0x36, 0xb5, 0xee, 0xe3, 0x58, 0x7d, 0x2c, 0xa9,\n 0x77, 0x16, 0x7c, 0x6f, 0x16, 0xa2, 0xb9, 0xde, 0x10, 0xfe, 0x1d, 0xdd,\n 0x16, 0xde, 0x07, 0x2e, 0x4f, 0x86, 0x6f, 0x06, 0x05, 0xa7, 0x02, 0x30,\n 0x6a, 0x48, 0x89, 0x42, 0x1f, 0x9b, 0xb3, 0x74, 0xb8, 0xbd, 0xe1, 0x75,\n 0xb3, 0xd6, 0xab, 0x23, 0x21, 0x6b, 0xa9, 0x7e, 0x68, 0x95, 0x10, 0x97,\n 0x4a, 0xe0, 0xf6, 0x59, 0xa1, 0x0e, 0x95, 0x84, 0x69, 0xb5, 0xbd, 0x80,\n 0xdf, 0xc1, 0x05, 0x88, 0x83, 0x1d, 0x93, 0x19, 0x81, 0xa6, 0x39, 0x98,\n 0x59, 0x02, 0x0b, 0xd8, 0x18, 0x59, 0x02, 0x06, 0xa6, 0x67, 0x76, 0x65,\n 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e, 0x30, 0x6f, 0x64, 0x69,\n 0x67, 0x65, 0x73, 0x74, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68,\n 0x6d, 0x67, 0x53, 0x48, 0x41, 0x2d, 0x32, 0x35, 0x36, 0x67, 0x64, 0x6f,\n 0x63, 0x54, 0x79, 0x70, 0x65, 0x75, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73,\n 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0x2e,\n 0x6d, 0x44, 0x4c, 0x6c, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x44, 0x69, 0x67,\n 0x65, 0x73, 0x74, 0x73, 0xa1, 0x71, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73,\n 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0xa6,\n 0x01, 0x58, 0x20, 0x6b, 0x6e, 0xe3, 0xd4, 0x97, 0x13, 0x66, 0xb2, 0xda,\n 0x89, 0x5f, 0x8b, 0x79, 0xb0, 0x08, 0x35, 0xd4, 0xeb, 0x9e, 0x36, 0x7b,\n 0xa2, 0x00, 0x21, 0x06, 0x39, 0xc9, 0xa2, 0x24, 0xd5, 0x61, 0x91, 0x00,\n 0x58, 0x20, 0x97, 0x1e, 0x94, 0xb3, 0x34, 0x56, 0xbb, 0x45, 0xd1, 0x7e,\n 0x9a, 0xe5, 0x58, 0xa3, 0x51, 0x5f, 0x68, 0xb4, 0x66, 0x27, 0x22, 0xb2,\n 0xee, 0x3c, 0x20, 0x98, 0x91, 0x52, 0xc2, 0xad, 0xc0, 0x71, 0x04, 0x58,\n 0x20, 0x64, 0x0a, 0x32, 0xae, 0x3e, 0xea, 0x27, 0x30, 0xe1, 0xdb, 0x11,\n 0x27, 0x56, 0xec, 0x65, 0x00, 0xa2, 0xab, 0xee, 0x2b, 0xe6, 0xe7, 0x50,\n 0xe2, 0x3c, 0x38, 0xb7, 0x55, 0x27, 0xf1, 0x8f, 0x37, 0x05, 0x58, 0x20,\n 0x28, 0x7e, 0x50, 0x4b, 0xd3, 0x5c, 0x0f, 0x8f, 0xa8, 0x23, 0x91, 0x66,\n 0x50, 0xd3, 0xc8, 0xa9, 0x8d, 0x38, 0x41, 0x50, 0xe7, 0x95, 0xf6, 0x2a,\n 0x11, 0x44, 0xda, 0x45, 0xc0, 0x91, 0x21, 0x3b, 0x03, 0x58, 0x20, 0xd1,\n 0x7f, 0x88, 0xf6, 0x17, 0x79, 0xaa, 0xc0, 0xa1, 0x00, 0xd0, 0xdd, 0xa0,\n 0xdd, 0x45, 0x85, 0xbd, 0x7b, 0x2c, 0xe5, 0x99, 0x22, 0x47, 0xf3, 0xed,\n 0x4f, 0xdc, 0xd7, 0x1d, 0x9c, 0xfa, 0xcc, 0x02, 0x58, 0x20, 0x96, 0x22,\n 0xa2, 0xd9, 0xfe, 0x02, 0xec, 0xbe, 0x3c, 0x63, 0x1d, 0x9a, 0xbb, 0x94,\n 0x05, 0xf5, 0x08, 0xed, 0xd0, 0xf4, 0x3e, 0x5f, 0x12, 0x51, 0xc9, 0xd7,\n 0xf8, 0x79, 0xe6, 0x96, 0xcb, 0x60, 0x6d, 0x64, 0x65, 0x76, 0x69, 0x63,\n 0x65, 0x4b, 0x65, 0x79, 0x49, 0x6e, 0x66, 0x6f, 0xa1, 0x69, 0x64, 0x65,\n 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79, 0xa4, 0x01, 0x02, 0x20, 0x01,\n 0x21, 0x58, 0x20, 0xc5, 0x4e, 0x80, 0xbd, 0xa8, 0xa1, 0xe1, 0xba, 0x92,\n 0x66, 0xcb, 0xe7, 0x4c, 0x7a, 0x73, 0xcf, 0x79, 0x08, 0xe2, 0x98, 0x58,\n 0x23, 0xc9, 0x1a, 0x9c, 0xb1, 0xfe, 0x57, 0x98, 0x52, 0x9d, 0xfb, 0x22,\n 0x58, 0x20, 0x1a, 0xc3, 0x2f, 0x5c, 0x02, 0x4d, 0xd7, 0xa7, 0x86, 0x1d,\n 0x2a, 0xb8, 0x97, 0x54, 0x3a, 0x1e, 0x17, 0x97, 0x04, 0x77, 0xab, 0xd3,\n 0x88, 0x63, 0xa5, 0xb8, 0xde, 0x22, 0x33, 0xd1, 0xdb, 0x95, 0x6c, 0x76,\n 0x61, 0x6c, 0x69, 0x64, 0x69, 0x74, 0x79, 0x49, 0x6e, 0x66, 0x6f, 0xa3,\n 0x66, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xc0, 0x74, 0x32, 0x30, 0x32,\n 0x34, 0x2d, 0x30, 0x31, 0x2d, 0x32, 0x36, 0x54, 0x31, 0x35, 0x3a, 0x33,\n 0x32, 0x3a, 0x35, 0x30, 0x5a, 0x69, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x46,\n 0x72, 0x6f, 0x6d, 0xc0, 0x74, 0x32, 0x30, 0x32, 0x34, 0x2d, 0x30, 0x31,\n 0x2d, 0x32, 0x36, 0x54, 0x31, 0x35, 0x3a, 0x33, 0x32, 0x3a, 0x35, 0x30,\n 0x5a, 0x6a, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x55, 0x6e, 0x74, 0x69, 0x6c,\n 0xc0, 0x74, 0x32, 0x30, 0x32, 0x34, 0x2d, 0x30, 0x32, 0x2d, 0x32, 0x35,\n 0x54, 0x31, 0x35, 0x3a, 0x33, 0x32, 0x3a, 0x35, 0x30, 0x5a, 0x58, 0x40,\n 0xac, 0x87, 0xaa, 0x02, 0x60, 0xb8, 0x36, 0x22, 0x9d, 0x1e, 0xa2, 0x85,\n 0x2f, 0x3c, 0xa3, 0x2a, 0xa3, 0x63, 0x9d, 0x26, 0x0c, 0x00, 0xda, 0x81,\n 0x24, 0x22, 0xbb, 0xd4, 0x5f, 0xc2, 0x05, 0x37, 0x08, 0xff, 0x70, 0x50,\n 0xde, 0xcc, 0x2d, 0xfc, 0xfd, 0x3a, 0xba, 0xfe, 0xea, 0x3d, 0x68, 0xe5,\n 0x14, 0xb5, 0x24, 0xe4, 0xc2, 0xee, 0xf8, 0xad, 0x28, 0xec, 0xd3, 0x14,\n 0x21, 0xfb, 0x9f, 0x8f, 0x6c, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x53,\n 0x69, 0x67, 0x6e, 0x65, 0x64, 0xa2, 0x6a, 0x6e, 0x61, 0x6d, 0x65, 0x53,\n 0x70, 0x61, 0x63, 0x65, 0x73, 0xd8, 0x18, 0x41, 0xa0, 0x6a, 0x64, 0x65,\n 0x76, 0x69, 0x63, 0x65, 0x41, 0x75, 0x74, 0x68, 0xa1, 0x6f, 0x64, 0x65,\n 0x76, 0x69, 0x63, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72,\n 0x65, 0x84, 0x43, 0xa1, 0x01, 0x26, 0xa0, 0xf6, 0x58, 0x40, 0xf2, 0xa2,\n 0x59, 0xcc, 0x16, 0xbf, 0x5c, 0x30, 0x52, 0x68, 0x4b, 0x1f, 0x16, 0x62,\n 0x07, 0xd5, 0x93, 0xff, 0x5b, 0x0e, 0x1d, 0xa8, 0xc1, 0x44, 0xc0, 0xb6,\n 0xe9, 0x0d, 0x53, 0x7b, 0xde, 0x49, 0x39, 0xe7, 0xe8, 0xa0, 0xfa, 0x24,\n 0x70, 0x8e, 0x5a, 0x59, 0x24, 0xb9, 0x53, 0x52, 0xd6, 0x4f, 0x02, 0x0b,\n 0x59, 0x89, 0x97, 0x1f, 0x09, 0x1c, 0xa1, 0xfe, 0x05, 0xe2, 0x5b, 0x45,\n 0x9d, 0x86, 0x66, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x00},\n },\n // Canonical payground example\n {StaticString(\n \"0xcc900843699408936c912474a27abb7b62d7c90e4f6d8557714825476eee2366\"),\n StaticString(\n \"0xb19764d33b530e9bd6a87081f1d8e5cbc80db640ac962ee8a3e0393c14c6bfb4\"),\n {0x83, 0xf6, 0xf6, 0x84, 0x76, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x57,\n 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x48, 0x61, 0x6e, 0x64, 0x6f, 0x76, 0x65,\n 0x72, 0x76, 0x31, 0x44, 0x01, 0x02, 0x03, 0x04, 0x78, 0x22, 0x63, 0x6f,\n 0x6d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x61, 0x6e, 0x64,\n 0x72, 0x6f, 0x69, 0x64, 0x2e, 0x67, 0x6d, 0x73, 0x2e, 0x74, 0x65, 0x73,\n 0x74, 0x2e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x58, 0x20, 0xb0, 0xd3,\n 0x81, 0x79, 0x7d, 0x0a, 0x06, 0x4b, 0x5e, 0xbe, 0xcf, 0xfd, 0x9c, 0x8b,\n 0x0f, 0x12, 0x88, 0xfc, 0x83, 0xb8, 0x59, 0xc7, 0x60, 0x8e, 0x91, 0x05,\n 0x14, 0x30, 0x25, 0x51, 0x2c, 0x54},\n 102,\n (uint8_t *)\"2024-05-05T09:00:00Z\",\n kMDL,\n 3272,\n {0xa3, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e,\n 0x30, 0x69, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x81,\n 0xa3, 0x67, 0x64, 0x6f, 0x63, 0x54, 0x79, 0x70, 0x65, 0x75, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x2e, 0x6d, 0x44, 0x4c, 0x6c, 0x69, 0x73, 0x73, 0x75,\n 0x65, 0x72, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xa2, 0x6a, 0x6e, 0x61,\n 0x6d, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x73, 0xa1, 0x71, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x81, 0xd8, 0x18, 0x58, 0x61, 0xa4, 0x68, 0x64, 0x69,\n 0x67, 0x65, 0x73, 0x74, 0x49, 0x44, 0x18, 0x1d, 0x66, 0x72, 0x61, 0x6e,\n 0x64, 0x6f, 0x6d, 0x58, 0x20, 0x3d, 0x02, 0x64, 0xc0, 0x07, 0x37, 0x5a,\n 0x43, 0x62, 0x0c, 0x37, 0xc0, 0xcc, 0x5c, 0x87, 0x3e, 0x15, 0x32, 0xa5,\n 0x2f, 0x5d, 0x32, 0x0e, 0x05, 0xc0, 0xfb, 0x17, 0x6c, 0x0c, 0xd9, 0xba,\n 0xb1, 0x71, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65,\n 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x6b, 0x61, 0x67, 0x65, 0x5f,\n 0x6f, 0x76, 0x65, 0x72, 0x5f, 0x31, 0x38, 0x6c, 0x65, 0x6c, 0x65, 0x6d,\n 0x65, 0x6e, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0xf5, 0x6a, 0x69, 0x73,\n 0x73, 0x75, 0x65, 0x72, 0x41, 0x75, 0x74, 0x68, 0x84, 0x43, 0xa1, 0x01,\n 0x26, 0xa1, 0x18, 0x21, 0x59, 0x02, 0xde, 0x30, 0x82, 0x02, 0xda, 0x30,\n 0x82, 0x02, 0x3b, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x14, 0x09, 0xbd,\n 0x7c, 0x4d, 0x2d, 0x53, 0x1a, 0x2c, 0x79, 0xbf, 0x50, 0x36, 0x29, 0x40,\n 0x8e, 0xe8, 0xfd, 0x40, 0xc8, 0x89, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86,\n 0x48, 0xce, 0x3d, 0x04, 0x03, 0x04, 0x30, 0x40, 0x31, 0x0f, 0x30, 0x0d,\n 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x06, 0x47, 0x6f, 0x6f, 0x67, 0x6c,\n 0x65, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,\n 0x5a, 0x5a, 0x31, 0x20, 0x30, 0x1e, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c,\n 0x17, 0x55, 0x4c, 0x20, 0x54, 0x45, 0x53, 0x54, 0x49, 0x4e, 0x47, 0x20,\n 0x53, 0x74, 0x61, 0x67, 0x69, 0x6e, 0x67, 0x20, 0x52, 0x6f, 0x6f, 0x74,\n 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34, 0x30, 0x34, 0x32, 0x36, 0x31, 0x35,\n 0x34, 0x39, 0x34, 0x35, 0x5a, 0x17, 0x0d, 0x32, 0x35, 0x30, 0x34, 0x32,\n 0x36, 0x31, 0x35, 0x34, 0x39, 0x34, 0x35, 0x5a, 0x30, 0x3e, 0x31, 0x0f,\n 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x06, 0x47, 0x6f, 0x6f,\n 0x67, 0x6c, 0x65, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06,\n 0x13, 0x02, 0x5a, 0x5a, 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x03, 0x55, 0x04,\n 0x03, 0x0c, 0x15, 0x55, 0x4c, 0x20, 0x54, 0x45, 0x53, 0x54, 0x49, 0x4e,\n 0x47, 0x20, 0x53, 0x74, 0x61, 0x67, 0x69, 0x6e, 0x67, 0x20, 0x44, 0x53,\n 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02,\n 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03,\n 0x42, 0x00, 0x04, 0xcc, 0x90, 0x08, 0x43, 0x69, 0x94, 0x08, 0x93, 0x6c,\n 0x91, 0x24, 0x74, 0xa2, 0x7a, 0xbb, 0x7b, 0x62, 0xd7, 0xc9, 0x0e, 0x4f,\n 0x6d, 0x85, 0x57, 0x71, 0x48, 0x25, 0x47, 0x6e, 0xee, 0x23, 0x66, 0xb1,\n 0x97, 0x64, 0xd3, 0x3b, 0x53, 0x0e, 0x9b, 0xd6, 0xa8, 0x70, 0x81, 0xf1,\n 0xd8, 0xe5, 0xcb, 0xc8, 0x0d, 0xb6, 0x40, 0xac, 0x96, 0x2e, 0xe8, 0xa3,\n 0xe0, 0x39, 0x3c, 0x14, 0xc6, 0xbf, 0xb4, 0xa3, 0x82, 0x01, 0x13, 0x30,\n 0x82, 0x01, 0x0f, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18,\n 0x30, 0x16, 0x80, 0x14, 0x73, 0xa7, 0x04, 0x1e, 0x50, 0x81, 0x93, 0x9e,\n 0xe0, 0xdb, 0xb7, 0x02, 0x8a, 0xe3, 0x71, 0x2f, 0xd0, 0xaa, 0x36, 0xc1,\n 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04,\n 0x03, 0x02, 0x07, 0x80, 0x30, 0x21, 0x06, 0x03, 0x55, 0x1d, 0x12, 0x04,\n 0x1a, 0x30, 0x18, 0x86, 0x16, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f,\n 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,\n 0x63, 0x6f, 0x6d, 0x30, 0x81, 0x82, 0x06, 0x03, 0x55, 0x1d, 0x1f, 0x04,\n 0x7b, 0x30, 0x79, 0x30, 0x77, 0xa0, 0x75, 0xa0, 0x73, 0x86, 0x71, 0x68,\n 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74,\n 0x65, 0x63, 0x61, 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d,\n 0x36, 0x36, 0x30, 0x33, 0x63, 0x36, 0x34, 0x37, 0x2d, 0x30, 0x30, 0x30,\n 0x30, 0x2d, 0x32, 0x39, 0x64, 0x34, 0x2d, 0x61, 0x65, 0x61, 0x36, 0x2d,\n 0x66, 0x34, 0x66, 0x35, 0x65, 0x38, 0x30, 0x64, 0x31, 0x62, 0x39, 0x30,\n 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x67, 0x6f, 0x6f,\n 0x67, 0x6c, 0x65, 0x61, 0x70, 0x69, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x2f,\n 0x34, 0x31, 0x64, 0x34, 0x33, 0x36, 0x38, 0x35, 0x39, 0x65, 0x34, 0x35,\n 0x64, 0x62, 0x66, 0x33, 0x65, 0x35, 0x61, 0x39, 0x2f, 0x63, 0x72, 0x6c,\n 0x2e, 0x63, 0x72, 0x6c, 0x30, 0x15, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x01,\n 0x01, 0xff, 0x04, 0x0b, 0x30, 0x09, 0x06, 0x07, 0x28, 0x81, 0x8c, 0x5d,\n 0x05, 0x01, 0x02, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16,\n 0x04, 0x14, 0x7c, 0xfd, 0x80, 0xe8, 0x38, 0x3f, 0x66, 0x5c, 0x9d, 0x6e,\n 0x2b, 0xa3, 0xbe, 0xf6, 0x78, 0x05, 0xf6, 0x16, 0x51, 0x13, 0x30, 0x0a,\n 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x04, 0x03, 0x81,\n 0x8c, 0x00, 0x30, 0x81, 0x88, 0x02, 0x42, 0x01, 0xfb, 0x90, 0x69, 0xf7,\n 0x3e, 0xc8, 0x67, 0x49, 0xfb, 0x2b, 0x12, 0x47, 0x2a, 0xbb, 0x43, 0x17,\n 0x44, 0xf0, 0x88, 0x85, 0x00, 0x1a, 0xcb, 0x1c, 0xea, 0xb4, 0xeb, 0x57,\n 0x5d, 0x34, 0xb1, 0x28, 0x44, 0x3d, 0xa5, 0x38, 0x11, 0x1b, 0x41, 0x0e,\n 0xfe, 0x65, 0xea, 0xfb, 0xc2, 0xb4, 0x2f, 0x5c, 0x60, 0x83, 0x7c, 0x38,\n 0xa0, 0x22, 0xe1, 0x98, 0x8c, 0x45, 0xe5, 0xf3, 0xb7, 0x87, 0x63, 0xa0,\n 0x55, 0x02, 0x42, 0x00, 0xd0, 0x15, 0x2a, 0x35, 0x94, 0x15, 0x5f, 0xc4,\n 0x59, 0x37, 0x90, 0x25, 0x07, 0x8d, 0x3a, 0xb1, 0x23, 0x2a, 0x13, 0x22,\n 0x7f, 0x13, 0xf7, 0x49, 0xe3, 0x93, 0xdd, 0x2b, 0xcd, 0xb6, 0xf7, 0xda,\n 0x00, 0xc4, 0xc2, 0xa5, 0x6e, 0x9c, 0x0c, 0x23, 0x9f, 0xa0, 0x74, 0x0b,\n 0x22, 0x2b, 0x71, 0xc2, 0x27, 0xf4, 0xa8, 0x94, 0x62, 0x43, 0x58, 0x07,\n 0x51, 0xa9, 0x3a, 0x8c, 0xbf, 0xed, 0xa1, 0x20, 0x88, 0x59, 0x08, 0x3c,\n 0xd8, 0x18, 0x59, 0x08, 0x37, 0xa6, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69,\n 0x6f, 0x6e, 0x63, 0x31, 0x2e, 0x30, 0x6f, 0x64, 0x69, 0x67, 0x65, 0x73,\n 0x74, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x67, 0x53,\n 0x48, 0x41, 0x2d, 0x32, 0x35, 0x36, 0x6c, 0x76, 0x61, 0x6c, 0x75, 0x65,\n 0x44, 0x69, 0x67, 0x65, 0x73, 0x74, 0x73, 0xa2, 0x71, 0x6f, 0x72, 0x67,\n 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35,\n 0x2e, 0x31, 0xb8, 0x2b, 0x00, 0x58, 0x20, 0x5b, 0xa2, 0x15, 0x53, 0xe6,\n 0x43, 0xe5, 0x20, 0xab, 0xde, 0x97, 0x81, 0x41, 0x9b, 0xa3, 0x30, 0x9e,\n 0x78, 0x69, 0x92, 0x25, 0xd5, 0x63, 0x5f, 0x4f, 0xe3, 0xa5, 0x01, 0xc7,\n 0x87, 0x0b, 0x9c, 0x01, 0x58, 0x20, 0x63, 0x42, 0x51, 0x8e, 0xb0, 0x68,\n 0x5a, 0x92, 0xe0, 0x4d, 0x2d, 0x8c, 0xf8, 0xfd, 0xa8, 0x8f, 0xad, 0x35,\n 0xe1, 0x8d, 0x77, 0x83, 0x48, 0xc2, 0x2d, 0xf9, 0x81, 0x09, 0x63, 0x29,\n 0x26, 0x40, 0x02, 0x58, 0x20, 0x49, 0xbe, 0x06, 0xcd, 0xf4, 0xb6, 0x1f,\n 0xe1, 0x6a, 0xb3, 0x4b, 0x3d, 0xf5, 0x30, 0x8d, 0xff, 0x42, 0x2a, 0xed,\n 0x4f, 0xd9, 0xdb, 0xdb, 0x0e, 0x82, 0x0d, 0xad, 0xf7, 0xae, 0x1d, 0xcf,\n 0x9e, 0x03, 0x58, 0x20, 0xc6, 0x4d, 0x57, 0x38, 0x99, 0x26, 0x59, 0xe5,\n 0xd2, 0x3c, 0x79, 0xaa, 0xfc, 0xde, 0x6a, 0xa8, 0x9f, 0xa7, 0x51, 0x7a,\n 0x6e, 0x63, 0xd4, 0x73, 0xe8, 0xa0, 0x1b, 0xd4, 0x5f, 0xa3, 0xba, 0xe3,\n 0x04, 0x58, 0x20, 0xa2, 0x5d, 0x81, 0xd8, 0x32, 0x72, 0xd3, 0x6d, 0x11,\n 0x76, 0x8c, 0x02, 0xab, 0x10, 0x3a, 0x8b, 0xdc, 0xd6, 0xae, 0x3b, 0x32,\n 0x5c, 0x51, 0x1a, 0xcd, 0x87, 0xdb, 0xe5, 0x64, 0xba, 0x61, 0x1a, 0x05,\n 0x58, 0x20, 0x46, 0x6c, 0x84, 0x0e, 0x42, 0x2b, 0x42, 0x43, 0x6a, 0x9e,\n 0xf6, 0x0a, 0xe8, 0xd5, 0x8b, 0x1c, 0x6e, 0x27, 0xab, 0xd3, 0xa8, 0x5e,\n 0xfa, 0x08, 0x2d, 0xbb, 0xb9, 0x91, 0xa7, 0x71, 0xec, 0x47, 0x06, 0x58,\n 0x20, 0x07, 0xb4, 0xcc, 0x54, 0xef, 0xd0, 0x1d, 0xb3, 0x22, 0x98, 0xe5,\n 0x77, 0x8b, 0x61, 0x43, 0xd1, 0x65, 0xeb, 0xe1, 0x11, 0x65, 0x19, 0x4c,\n 0x34, 0xed, 0x7b, 0x21, 0xe4, 0x51, 0x32, 0x53, 0x48, 0x07, 0x58, 0x20,\n 0x74, 0x2f, 0xc6, 0xb9, 0x4d, 0x42, 0xf4, 0xb5, 0x09, 0x3b, 0x2e, 0x09,\n 0xf0, 0xed, 0x05, 0x33, 0x70, 0x28, 0xc1, 0x02, 0xd8, 0x4b, 0x0b, 0x83,\n 0xd6, 0x17, 0xb3, 0x5e, 0xeb, 0xe4, 0x7d, 0x6b, 0x08, 0x58, 0x20, 0xc5,\n 0xc2, 0x6f, 0x0d, 0x3f, 0x59, 0x6f, 0x96, 0x16, 0x2e, 0xbe, 0xc7, 0xcc,\n 0xae, 0xfb, 0xf8, 0xa2, 0x9d, 0x77, 0x21, 0x9d, 0x21, 0xd6, 0xf9, 0xc2,\n 0xec, 0x62, 0xf4, 0x0f, 0x76, 0x32, 0x1e, 0x09, 0x58, 0x20, 0xec, 0xff,\n 0x29, 0x8b, 0xb3, 0x04, 0x89, 0x10, 0x7d, 0x67, 0x8a, 0x22, 0xd1, 0x0c,\n 0xc3, 0x00, 0x93, 0x96, 0xa0, 0xa4, 0xc8, 0x5b, 0x42, 0x03, 0x79, 0xc4,\n 0x99, 0x25, 0xcd, 0x84, 0xce, 0x99, 0x0a, 0x58, 0x20, 0x83, 0x98, 0x6e,\n 0x01, 0xd1, 0x26, 0xf0, 0x4d, 0x45, 0x1c, 0xf0, 0x83, 0xe7, 0x1e, 0x24,\n 0x0e, 0x3a, 0x9e, 0xe2, 0x24, 0x06, 0x86, 0xf1, 0xc9, 0xc7, 0x79, 0xe7,\n 0x09, 0x3e, 0x66, 0x30, 0x90, 0x0b, 0x58, 0x20, 0x5d, 0x9e, 0x05, 0x3d,\n 0x1a, 0xf1, 0x86, 0xad, 0x9d, 0xf4, 0xc1, 0xeb, 0x6b, 0xec, 0x06, 0xaa,\n 0xb5, 0xab, 0x1d, 0xf3, 0xfe, 0x43, 0x59, 0x7f, 0xe4, 0x92, 0x18, 0xcd,\n 0x05, 0x81, 0x98, 0x99, 0x0c, 0x58, 0x20, 0x3a, 0xda, 0x36, 0xa4, 0xa7,\n 0x34, 0xe3, 0xb8, 0x97, 0x3c, 0x17, 0x32, 0xdb, 0xcc, 0x71, 0x67, 0x88,\n 0x38, 0x3b, 0x11, 0x54, 0xea, 0xf4, 0x81, 0x8b, 0x58, 0xbf, 0xd9, 0xf8,\n 0x29, 0x83, 0x13, 0x0d, 0x58, 0x20, 0x29, 0x1b, 0x18, 0x71, 0xda, 0x79,\n 0x78, 0xb9, 0xc4, 0xe5, 0x2b, 0x1a, 0x6d, 0xfc, 0x14, 0x29, 0x74, 0x72,\n 0x9d, 0xe8, 0x2f, 0x14, 0x96, 0x44, 0x0a, 0x53, 0x72, 0xb7, 0x19, 0x4c,\n 0x8d, 0x4e, 0x0e, 0x58, 0x20, 0x47, 0x4b, 0x99, 0x28, 0x4b, 0xf4, 0xe7,\n 0x13, 0x1c, 0x74, 0x9d, 0x85, 0x2c, 0xcb, 0xdf, 0x29, 0xa7, 0x26, 0x45,\n 0x4b, 0x55, 0x96, 0x9e, 0x55, 0xfe, 0x0f, 0x47, 0xd4, 0x1a, 0xad, 0x5d,\n 0xfb, 0x0f, 0x58, 0x20, 0xe0, 0x98, 0xdb, 0x13, 0x84, 0x30, 0xb2, 0x6c,\n 0xc3, 0x3c, 0xb3, 0x15, 0xcc, 0x82, 0x0e, 0xc4, 0xea, 0x4b, 0x4b, 0x38,\n 0xf7, 0x5a, 0x54, 0xe6, 0xa6, 0x4c, 0x7c, 0xf0, 0x9b, 0x5f, 0xf2, 0xc5,\n 0x10, 0x58, 0x20, 0xfe, 0x68, 0xbd, 0x1d, 0xde, 0xf4, 0xc7, 0x60, 0xfd,\n 0xf9, 0x6b, 0x19, 0xaf, 0x5f, 0x5a, 0x7f, 0x82, 0xc5, 0x26, 0xb9, 0xcc,\n 0x66, 0xe4, 0xe3, 0x7a, 0x24, 0x3d, 0x33, 0x04, 0x91, 0x1f, 0x5c, 0x11,\n 0x58, 0x20, 0x91, 0x36, 0x4e, 0x16, 0x85, 0x3f, 0xfe, 0x4f, 0xa1, 0x50,\n 0x97, 0x87, 0xd8, 0x9d, 0xff, 0x12, 0x3b, 0x6b, 0x1f, 0xc4, 0x73, 0xe9,\n 0xe0, 0xaa, 0x07, 0x0a, 0xce, 0xfc, 0xbf, 0x25, 0xf6, 0x9a, 0x12, 0x58,\n 0x20, 0x89, 0xdb, 0x3e, 0x9b, 0xa2, 0x0e, 0xb0, 0x16, 0xd2, 0x80, 0xcd,\n 0x2b, 0xe2, 0xe5, 0x86, 0xdb, 0xac, 0xc5, 0xc8, 0x3b, 0xb5, 0x10, 0x9e,\n 0x8d, 0x01, 0xa3, 0xd2, 0x77, 0x1e, 0x6e, 0xa8, 0x1f, 0x13, 0x58, 0x20,\n 0x9b, 0xb5, 0x36, 0x08, 0x50, 0x6c, 0xe0, 0x03, 0x3b, 0x88, 0x49, 0xef,\n 0xd5, 0xeb, 0x15, 0x58, 0xe7, 0x14, 0xca, 0x05, 0x7a, 0x57, 0xa0, 0xcb,\n 0x00, 0x78, 0x67, 0xd4, 0x3c, 0x8f, 0x6f, 0x79, 0x14, 0x58, 0x20, 0x33,\n 0x3b, 0x9b, 0x28, 0x72, 0xbe, 0x3d, 0x76, 0xda, 0xeb, 0x79, 0x0e, 0x08,\n 0x86, 0x55, 0xcc, 0x63, 0x78, 0x52, 0x17, 0x11, 0x57, 0x71, 0x9f, 0xe3,\n 0x8d, 0x6c, 0xe9, 0xf7, 0xc3, 0x5e, 0x37, 0x15, 0x58, 0x20, 0xe9, 0xd4,\n 0x87, 0x4e, 0x06, 0x4c, 0x64, 0xf0, 0x95, 0xff, 0xaf, 0xd3, 0xce, 0x33,\n 0x2c, 0x6b, 0x5c, 0x31, 0xf1, 0x1e, 0xfe, 0x69, 0x6f, 0x3a, 0x9b, 0xbf,\n 0x6c, 0x2a, 0x37, 0x69, 0x9f, 0xf7, 0x16, 0x58, 0x20, 0x66, 0xf2, 0x53,\n 0xa4, 0xc5, 0xe0, 0xc9, 0x18, 0x5c, 0x29, 0x45, 0xee, 0x2d, 0x93, 0xc6,\n 0x40, 0xfd, 0x1c, 0x55, 0xcf, 0xac, 0xf6, 0x44, 0xd8, 0xa7, 0x9b, 0x26,\n 0xca, 0xc4, 0x32, 0xdf, 0x0c, 0x17, 0x58, 0x20, 0x79, 0xa3, 0x91, 0x0f,\n 0xba, 0x84, 0x41, 0x91, 0x27, 0xa3, 0xcb, 0x41, 0xfc, 0x75, 0x51, 0x67,\n 0xee, 0xf9, 0x9f, 0x6c, 0x32, 0x55, 0x9e, 0xbc, 0xe2, 0x5e, 0x81, 0x5d,\n 0x6e, 0x0e, 0x7d, 0x18, 0x18, 0x18, 0x58, 0x20, 0x00, 0x2b, 0x44, 0x81,\n 0x79, 0xd9, 0xde, 0xde, 0xb6, 0x72, 0xb1, 0x2a, 0xbd, 0xd1, 0xed, 0xfe,\n 0xcf, 0xf4, 0x3d, 0x30, 0x31, 0xa8, 0x93, 0x97, 0xd7, 0x6d, 0x26, 0x3e,\n 0x7f, 0x68, 0x8a, 0xad, 0x18, 0x19, 0x58, 0x20, 0x02, 0xf7, 0x7d, 0xac,\n 0x9f, 0x51, 0x08, 0x92, 0x01, 0xec, 0x78, 0x9a, 0x98, 0x3c, 0xa8, 0x0d,\n 0x60, 0x51, 0xcc, 0xa1, 0xda, 0x98, 0x3b, 0xb8, 0xcb, 0x8e, 0xb7, 0xe0,\n 0xc7, 0x02, 0xaf, 0x0a, 0x18, 0x1a, 0x58, 0x20, 0x0b, 0x0e, 0x24, 0xdb,\n 0xa7, 0x46, 0x48, 0xad, 0x2f, 0x1c, 0xbb, 0x66, 0x41, 0x46, 0xf7, 0x32,\n 0x9e, 0xa4, 0xfe, 0x57, 0xe2, 0xfa, 0x5b, 0x14, 0xb6, 0x9a, 0x7f, 0x3e,\n 0x3d, 0x98, 0xa0, 0x10, 0x18, 0x1b, 0x58, 0x20, 0x7f, 0x8c, 0x39, 0x1c,\n 0xe7, 0xcd, 0x6d, 0xaa, 0x75, 0xeb, 0xd7, 0xb5, 0xcd, 0x32, 0xf6, 0x1c,\n 0xd4, 0xf1, 0xdd, 0xe4, 0x5a, 0xba, 0xa1, 0xba, 0xdf, 0x35, 0x67, 0x1c,\n 0x94, 0xa8, 0x18, 0x40, 0x18, 0x1c, 0x58, 0x20, 0x45, 0x52, 0x2a, 0xab,\n 0xfe, 0x53, 0x5e, 0x05, 0x07, 0x16, 0x81, 0x0f, 0x0a, 0x72, 0x6b, 0x79,\n 0x00, 0xc5, 0xf7, 0xc2, 0x9d, 0xeb, 0x16, 0x0b, 0x7e, 0x1b, 0x38, 0xe4,\n 0x42, 0x7f, 0x10, 0x2c, 0x18, 0x1d, 0x58, 0x20, 0x96, 0x61, 0x0d, 0x45,\n 0x9e, 0x4b, 0xf5, 0x69, 0xb6, 0x73, 0x62, 0xcf, 0x08, 0x55, 0xff, 0xb3,\n 0xdd, 0x76, 0xc7, 0x0b, 0x62, 0x49, 0x48, 0xce, 0x63, 0xd5, 0x93, 0x90,\n 0xa2, 0x62, 0xba, 0x27, 0x18, 0x1e, 0x58, 0x20, 0xce, 0x79, 0xa1, 0xc5,\n 0x83, 0x75, 0x95, 0x5e, 0x00, 0x14, 0xdc, 0x4f, 0x2b, 0xdb, 0xc3, 0x3e,\n 0x26, 0x79, 0x6c, 0x0c, 0x5b, 0x32, 0xda, 0x23, 0x40, 0xa4, 0x3b, 0x2d,\n 0xc9, 0x81, 0x34, 0xf0, 0x18, 0x1f, 0x58, 0x20, 0x78, 0x71, 0x6e, 0x52,\n 0x0b, 0xcf, 0xc9, 0x77, 0x59, 0x74, 0x88, 0x7d, 0x41, 0x87, 0xe2, 0x0c,\n 0xef, 0xb9, 0x79, 0xe0, 0xa7, 0xf5, 0xd1, 0xc4, 0xdf, 0x11, 0xe7, 0xdd,\n 0x9c, 0x21, 0xed, 0x38, 0x18, 0x20, 0x58, 0x20, 0x5f, 0xc6, 0xed, 0x71,\n 0x46, 0xa0, 0xf4, 0xe3, 0x82, 0x97, 0x59, 0x1a, 0x58, 0x86, 0xba, 0x91,\n 0x62, 0xf8, 0x65, 0xcc, 0xf7, 0xa6, 0x0d, 0x7e, 0xb7, 0xdc, 0x0b, 0x97,\n 0xb3, 0xed, 0xa2, 0xdf, 0x18, 0x21, 0x58, 0x20, 0x22, 0x1d, 0xec, 0x99,\n 0xf8, 0xe5, 0x3a, 0xff, 0xc1, 0xac, 0x36, 0x98, 0x0e, 0xdd, 0x30, 0xd2,\n 0x45, 0xa0, 0x7d, 0x9e, 0x8a, 0x8f, 0xfe, 0xf8, 0x4e, 0xc4, 0x41, 0x53,\n 0x1d, 0x62, 0xed, 0x56, 0x18, 0x22, 0x58, 0x20, 0x2b, 0x1a, 0xcd, 0xda,\n 0xf5, 0xa5, 0x35, 0xc9, 0x43, 0xf9, 0x77, 0x0d, 0x18, 0x0e, 0x29, 0x6e,\n 0x1e, 0xa7, 0x48, 0xbd, 0xd3, 0x5c, 0xc8, 0xef, 0xfe, 0x6d, 0xa6, 0x69,\n 0x66, 0x9f, 0x01, 0x4d, 0x18, 0x23, 0x58, 0x20, 0x77, 0x6c, 0xc8, 0x79,\n 0x55, 0x8d, 0xf5, 0x5b, 0x38, 0xc7, 0x8e, 0xbe, 0xdf, 0xbf, 0x80, 0x8c,\n 0xfe, 0x42, 0x1f, 0x24, 0xeb, 0xd6, 0x16, 0x1a, 0x8b, 0xbf, 0xf4, 0xc9,\n 0x54, 0x70, 0x82, 0x9a, 0x18, 0x24, 0x58, 0x20, 0x4b, 0x7e, 0x0f, 0x51,\n 0x63, 0xbe, 0xa3, 0x76, 0xcf, 0x47, 0x76, 0xbd, 0x52, 0xa7, 0x76, 0x57,\n 0x28, 0xeb, 0xae, 0x1d, 0x17, 0x50, 0xc2, 0xc9, 0xc5, 0xb8, 0xa3, 0x08,\n 0xb3, 0x3a, 0x4f, 0xfd, 0x18, 0x25, 0x58, 0x20, 0x0d, 0x76, 0x9d, 0x48,\n 0x03, 0x55, 0x16, 0xca, 0x03, 0x59, 0x5c, 0x7f, 0xa6, 0x0d, 0xd4, 0x32,\n 0xfe, 0x75, 0xe0, 0x88, 0x11, 0x10, 0x15, 0x64, 0x89, 0x66, 0x8f, 0x92,\n 0xd1, 0xc0, 0x1b, 0xcb, 0x18, 0x26, 0x58, 0x20, 0x02, 0x70, 0x12, 0x7a,\n 0xb6, 0x66, 0x44, 0x57, 0x53, 0xd6, 0x12, 0x52, 0xca, 0xf0, 0x5d, 0x4a,\n 0x2f, 0x20, 0x77, 0x35, 0xca, 0xe9, 0x34, 0x9d, 0xdf, 0x35, 0x2c, 0x27,\n 0xea, 0xe7, 0x6e, 0xe8, 0x18, 0x27, 0x58, 0x20, 0x42, 0x9a, 0x96, 0xe3,\n 0x79, 0x51, 0xb1, 0xd8, 0x99, 0x98, 0x28, 0x81, 0x4a, 0xa2, 0x52, 0x68,\n 0xf8, 0xeb, 0x69, 0x53, 0xce, 0x41, 0x7f, 0xa9, 0x93, 0xf8, 0xd1, 0x47,\n 0xf2, 0xe0, 0xe7, 0x45, 0x18, 0x28, 0x58, 0x20, 0xf5, 0x03, 0xb9, 0x30,\n 0x8e, 0x63, 0x45, 0xb9, 0x9e, 0x0f, 0x01, 0xc6, 0x73, 0xc2, 0xcf, 0x0f,\n 0x84, 0x5e, 0x22, 0xfe, 0x1f, 0x77, 0x6a, 0xc8, 0xe4, 0x1e, 0xb1, 0x90,\n 0x58, 0x8d, 0xaf, 0x6a, 0x18, 0x29, 0x58, 0x20, 0xae, 0x02, 0x5f, 0x21,\n 0xb2, 0x08, 0x9d, 0xf9, 0x21, 0x6d, 0x6c, 0x7d, 0x65, 0x50, 0xf3, 0x36,\n 0x4b, 0x42, 0x19, 0x7b, 0x1f, 0x3f, 0xe2, 0x63, 0x72, 0xdc, 0x9c, 0x0c,\n 0xa7, 0xe3, 0x0c, 0x08, 0x18, 0x2a, 0x58, 0x20, 0x3e, 0xcd, 0x92, 0xc4,\n 0x9c, 0x3f, 0xee, 0x18, 0x41, 0xa9, 0xa5, 0xd7, 0x6e, 0x9e, 0xd5, 0xf0,\n 0xfd, 0x06, 0x22, 0x72, 0x98, 0xe7, 0x87, 0x6d, 0x25, 0xc1, 0xf6, 0x1f,\n 0x79, 0xb4, 0x37, 0xc0, 0x77, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73, 0x6f,\n 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0x2e, 0x61,\n 0x61, 0x6d, 0x76, 0x61, 0xa7, 0x00, 0x58, 0x20, 0xb9, 0x3d, 0x05, 0x94,\n 0xaf, 0x96, 0xfe, 0x77, 0x1a, 0xc8, 0x79, 0x7f, 0x9e, 0x75, 0x76, 0xf8,\n 0xd3, 0xa7, 0xd3, 0x14, 0x31, 0x7a, 0x7c, 0x6c, 0x29, 0x32, 0xbc, 0xe1,\n 0xf4, 0xde, 0x4f, 0x64, 0x01, 0x58, 0x20, 0xd8, 0x36, 0x54, 0x23, 0x07,\n 0x2f, 0x73, 0xbf, 0x62, 0x88, 0x46, 0x20, 0xd8, 0xb6, 0xdc, 0x27, 0xb2,\n 0x27, 0xe6, 0x56, 0xc7, 0xd6, 0xb2, 0x5e, 0xb0, 0xd6, 0xc8, 0xd5, 0xe2,\n 0x5c, 0x4a, 0x44, 0x02, 0x58, 0x20, 0xc1, 0xcb, 0x4f, 0x9a, 0xa4, 0x1b,\n 0x2f, 0x9b, 0xa1, 0x7a, 0x33, 0xaf, 0x86, 0xac, 0xbc, 0x47, 0x16, 0xf3,\n 0x8e, 0xf8, 0x91, 0x9f, 0x19, 0xd9, 0x8a, 0xfc, 0x33, 0x7c, 0x41, 0x5f,\n 0xe6, 0x1d, 0x03, 0x58, 0x20, 0x45, 0xdb, 0x9c, 0x8f, 0x0a, 0xe3, 0x43,\n 0x09, 0x0f, 0x2a, 0x39, 0x07, 0x9e, 0x89, 0xa4, 0x6a, 0xfb, 0xb4, 0x87,\n 0x1b, 0xc8, 0xc7, 0x70, 0x44, 0x62, 0xc0, 0xf4, 0x35, 0x48, 0x27, 0x74,\n 0x80, 0x04, 0x58, 0x20, 0x37, 0x0f, 0x26, 0x20, 0x67, 0x83, 0x1c, 0x85,\n 0x1d, 0x77, 0x84, 0xb1, 0x39, 0x5e, 0x73, 0x9e, 0x8f, 0xa0, 0x25, 0xe1,\n 0x8b, 0x92, 0x37, 0xdf, 0xa7, 0x10, 0x05, 0x87, 0x6e, 0xb4, 0x8b, 0x06,\n 0x05, 0x58, 0x20, 0x8c, 0xb6, 0xa4, 0x05, 0x06, 0xf7, 0xb1, 0x01, 0x20,\n 0x32, 0x46, 0x95, 0xef, 0x20, 0x15, 0xad, 0x45, 0xbe, 0x93, 0x33, 0x14,\n 0xb7, 0x5e, 0xa2, 0xb2, 0x50, 0xd6, 0x8b, 0xa9, 0x73, 0xd0, 0x09, 0x06,\n 0x58, 0x20, 0xe9, 0x00, 0x40, 0x02, 0xf9, 0x59, 0xc8, 0xe1, 0x80, 0x2d,\n 0x9b, 0xb2, 0x95, 0x6e, 0xc0, 0x07, 0x58, 0x18, 0x6e, 0xd1, 0x02, 0x61,\n 0x94, 0xa1, 0x3c, 0xc6, 0x79, 0x56, 0x34, 0x4a, 0x6c, 0xd5, 0x6d, 0x64,\n 0x65, 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79, 0x49, 0x6e, 0x66, 0x6f,\n 0xa1, 0x69, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79, 0xa4,\n 0x01, 0x02, 0x20, 0x01, 0x21, 0x58, 0x20, 0xd8, 0x03, 0x40, 0x9d, 0x10,\n 0x60, 0x75, 0xeb, 0x45, 0x83, 0xe1, 0xca, 0x94, 0xad, 0x54, 0x2b, 0x57,\n 0x79, 0xf1, 0xe8, 0x64, 0xa8, 0xd2, 0x46, 0x81, 0xa1, 0xa6, 0x2e, 0x3b,\n 0x50, 0xdb, 0xd3, 0x22, 0x58, 0x20, 0xd6, 0x66, 0x3f, 0x27, 0x76, 0x66,\n 0x68, 0x02, 0x6a, 0x25, 0x0c, 0x9e, 0xd2, 0xcb, 0xbb, 0xdd, 0xd7, 0x57,\n 0xe3, 0x03, 0x8a, 0xea, 0xf1, 0x07, 0x8f, 0xda, 0xb5, 0xd2, 0xb1, 0x82,\n 0x6b, 0xa0, 0x6c, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x69, 0x74, 0x79, 0x49,\n 0x6e, 0x66, 0x6f, 0xa3, 0x66, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xc0,\n 0x74, 0x32, 0x30, 0x32, 0x34, 0x2d, 0x30, 0x35, 0x2d, 0x30, 0x33, 0x54,\n 0x30, 0x37, 0x3a, 0x30, 0x30, 0x3a, 0x30, 0x30, 0x5a, 0x69, 0x76, 0x61,\n 0x6c, 0x69, 0x64, 0x46, 0x72, 0x6f, 0x6d, 0xc0, 0x74, 0x32, 0x30, 0x32,\n 0x34, 0x2d, 0x30, 0x35, 0x2d, 0x30, 0x33, 0x54, 0x30, 0x37, 0x3a, 0x30,\n 0x30, 0x3a, 0x30, 0x30, 0x5a, 0x6a, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x55,\n 0x6e, 0x74, 0x69, 0x6c, 0xc0, 0x74, 0x32, 0x30, 0x32, 0x35, 0x2d, 0x30,\n 0x35, 0x2d, 0x30, 0x33, 0x54, 0x30, 0x37, 0x3a, 0x30, 0x30, 0x3a, 0x30,\n 0x30, 0x5a, 0x67, 0x64, 0x6f, 0x63, 0x54, 0x79, 0x70, 0x65, 0x75, 0x6f,\n 0x72, 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33,\n 0x2e, 0x35, 0x2e, 0x31, 0x2e, 0x6d, 0x44, 0x4c, 0x58, 0x40, 0xfb, 0x37,\n 0x77, 0xd9, 0xbf, 0x2d, 0x25, 0x26, 0xe3, 0x0d, 0x8d, 0xf4, 0x59, 0xe0,\n 0x9e, 0x70, 0x48, 0x28, 0x40, 0x8d, 0x60, 0xa7, 0xc1, 0x3c, 0x14, 0xe9,\n 0x4f, 0xe4, 0x3d, 0xf3, 0x5e, 0xe2, 0xaf, 0x86, 0xe9, 0x60, 0x87, 0xf0,\n 0x40, 0x1b, 0xd0, 0xa7, 0x2f, 0x6e, 0x45, 0x16, 0xdf, 0xa9, 0x9d, 0xb1,\n 0xf1, 0xb7, 0x2d, 0xa5, 0xb7, 0x39, 0x4f, 0x86, 0x26, 0xe1, 0x98, 0x59,\n 0x27, 0xaf, 0x6c, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x53, 0x69, 0x67,\n 0x6e, 0x65, 0x64, 0xa2, 0x6a, 0x6e, 0x61, 0x6d, 0x65, 0x53, 0x70, 0x61,\n 0x63, 0x65, 0x73, 0xd8, 0x18, 0x41, 0xa0, 0x6a, 0x64, 0x65, 0x76, 0x69,\n 0x63, 0x65, 0x41, 0x75, 0x74, 0x68, 0xa1, 0x6f, 0x64, 0x65, 0x76, 0x69,\n 0x63, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x84,\n 0x43, 0xa1, 0x01, 0x26, 0xa0, 0xf6, 0x58, 0x40, 0xef, 0xde, 0xb6, 0xa0,\n 0x91, 0x85, 0x5f, 0x91, 0x1c, 0x5f, 0x94, 0x68, 0xd0, 0x4f, 0xe3, 0x9b,\n 0xee, 0xff, 0x3c, 0x9e, 0xb4, 0x32, 0x4a, 0xc4, 0x76, 0x9a, 0x5e, 0x81,\n 0x2d, 0x52, 0x45, 0x3b, 0xc6, 0x48, 0xf8, 0xc5, 0xe0, 0x3d, 0x12, 0x67,\n 0x7d, 0xf4, 0xf9, 0x6b, 0x9e, 0x56, 0xb0, 0xc5, 0x0f, 0x73, 0x7a, 0x02,\n 0xf7, 0x6b, 0x6f, 0x25, 0xe2, 0x50, 0x28, 0x34, 0xa5, 0x1d, 0x31, 0x47,\n 0x66, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x00}},\n\n // Sprind-Funke mdoc example that includes family_name,\n // birth_date, issue_date, height, and age_over_18.\n // To test these examples, change the kAgeShow[] data structure in\n // mdoc_zk.cc to include one of the following opened attributes:\n // {(uint8_t *)\"family_name\", 11, (uint8_t *)\"Mustermann\", 10},\n // {(uint8_t *)\"height\", 6, (uint8_t *)\"\\x18\\xaf\", 2},\n // {(uint8_t *)\"birth_date\", 10, (uint8_t *)\"\\xD9\\x03\\xEC\\x6A\"\n // \"1971-09-01\", 14},\n // {(uint8_t *)\"issue_date\", 10, (uint8_t *)\"\\xD9\\x03\\xEC\\x6A\"\n // \"2024-03-15\", 14},\n // Note that the D903EC6A prefix specifies the cbor full-date encoding for\n // the birth_date and issue_date. The spec suggests that the issue_date can\n // also be formatted as a tdate, which would have a different prefix.\n // The 0x18af formatting for the height attribute uses the uint formatting\n // and corresponds to the value 175.\n {\n StaticString(\"0xdc1c1f55cff4cd5c76cf4169278f7217667f86ee81d8669b63f2e19\"\n \"bc12a0c9f\"),\n StaticString(\"0x12355dd0385fed3bc33bedc9781b9aad47b33e4c24704b8d14288b1\"\n \"b3cb45c28\"),\n {0x83, 0xf6, 0xf6, 0x84, 0x71, 0x42, 0x72, 0x6f, 0x77, 0x73, 0x65, 0x72,\n 0x48, 0x61, 0x6e, 0x64, 0x6f, 0x76, 0x65, 0x72, 0x76, 0x31, 0x58, 0x20,\n 0xf9, 0x3e, 0xba, 0xc4, 0xce, 0x4d, 0x99, 0x01, 0xb9, 0xae, 0xa4, 0x72,\n 0x14, 0x5a, 0xe5, 0x42, 0x1f, 0x8f, 0xbe, 0xcb, 0xe5, 0xf0, 0x38, 0x96,\n 0x83, 0xf5, 0x9f, 0x08, 0xfc, 0xf9, 0x0e, 0x45, 0x58, 0x33, 0xa3, 0x63,\n 0x63, 0x61, 0x74, 0x01, 0x64, 0x74, 0x79, 0x70, 0x65, 0x01, 0x67, 0x64,\n 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0xa1, 0x67, 0x62, 0x61, 0x73, 0x65,\n 0x55, 0x72, 0x6c, 0x75, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x6c,\n 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x3a, 0x38, 0x30, 0x38,\n 0x30, 0x58, 0x20, 0x3c, 0x79, 0x91, 0x4b, 0x7f, 0x81, 0xa1, 0xc2, 0x55,\n 0x8f, 0xc8, 0x16, 0x19, 0xdd, 0x4a, 0x07, 0x4d, 0x32, 0x14, 0x3e, 0x6c,\n 0xf6, 0x89, 0x5f, 0xe4, 0x7d, 0xa1, 0x56, 0xd1, 0xc5, 0xb0, 0xae},\n 143,\n (uint8_t *)\"2024-10-01T09:00:00Z\",\n kMDL,\n 3173,\n {0xa3, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e,\n 0x30, 0x69, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x81,\n 0xa3, 0x67, 0x64, 0x6f, 0x63, 0x54, 0x79, 0x70, 0x65, 0x75, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x2e, 0x6d, 0x44, 0x4c, 0x6c, 0x69, 0x73, 0x73, 0x75,\n 0x65, 0x72, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xa2, 0x6a, 0x6e, 0x61,\n 0x6d, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x73, 0xa1, 0x71, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x85, 0xd8, 0x18, 0x58, 0x5a, 0xa4, 0x68, 0x64, 0x69,\n 0x67, 0x65, 0x73, 0x74, 0x49, 0x44, 0x18, 0x1a, 0x66, 0x72, 0x61, 0x6e,\n 0x64, 0x6f, 0x6d, 0x50, 0x72, 0xc7, 0xaf, 0x26, 0x49, 0xd0, 0x5a, 0x38,\n 0xb0, 0x2e, 0x7e, 0x1c, 0xc7, 0xf9, 0xd0, 0x46, 0x71, 0x65, 0x6c, 0x65,\n 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69,\n 0x65, 0x72, 0x6b, 0x66, 0x61, 0x6d, 0x69, 0x6c, 0x79, 0x5f, 0x6e, 0x61,\n 0x6d, 0x65, 0x6c, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x56, 0x61,\n 0x6c, 0x75, 0x65, 0x6a, 0x4d, 0x75, 0x73, 0x74, 0x65, 0x72, 0x6d, 0x61,\n 0x6e, 0x6e, 0xd8, 0x18, 0x58, 0x5b, 0xa4, 0x68, 0x64, 0x69, 0x67, 0x65,\n 0x73, 0x74, 0x49, 0x44, 0x0a, 0x66, 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d,\n 0x50, 0xfc, 0x8a, 0x8f, 0x5b, 0xaf, 0xb4, 0x0c, 0xb3, 0x21, 0x77, 0x6d,\n 0xbf, 0x5f, 0xbe, 0x18, 0x81, 0x71, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e,\n 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x6a,\n 0x62, 0x69, 0x72, 0x74, 0x68, 0x5f, 0x64, 0x61, 0x74, 0x65, 0x6c, 0x65,\n 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0xd9,\n 0x03, 0xec, 0x6a, 0x31, 0x39, 0x37, 0x31, 0x2d, 0x30, 0x39, 0x2d, 0x30,\n 0x31, 0xd8, 0x18, 0x58, 0x5b, 0xa4, 0x68, 0x64, 0x69, 0x67, 0x65, 0x73,\n 0x74, 0x49, 0x44, 0x14, 0x66, 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x50,\n 0x59, 0xcd, 0xdd, 0x91, 0xd7, 0x53, 0xed, 0x98, 0xff, 0x55, 0x5d, 0x2f,\n 0x97, 0x27, 0x45, 0x3b, 0x71, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74,\n 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x6a, 0x69,\n 0x73, 0x73, 0x75, 0x65, 0x5f, 0x64, 0x61, 0x74, 0x65, 0x6c, 0x65, 0x6c,\n 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0xd9, 0x03,\n 0xec, 0x6a, 0x32, 0x30, 0x32, 0x34, 0x2d, 0x30, 0x33, 0x2d, 0x31, 0x35,\n 0xd8, 0x18, 0x58, 0x4b, 0xa4, 0x68, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74,\n 0x49, 0x44, 0x0f, 0x66, 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x50, 0xcc,\n 0xdc, 0x59, 0x8c, 0xa9, 0xaf, 0xee, 0x95, 0xfd, 0x57, 0x68, 0x3e, 0xb1,\n 0x9a, 0xff, 0x33, 0x71, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x49,\n 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x66, 0x68, 0x65,\n 0x69, 0x67, 0x68, 0x74, 0x6c, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74,\n 0x56, 0x61, 0x6c, 0x75, 0x65, 0x18, 0xaf, 0xd8, 0x18, 0x58, 0x4f, 0xa4,\n 0x68, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74, 0x49, 0x44, 0x15, 0x66, 0x72,\n 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x50, 0xac, 0x50, 0xf6, 0x51, 0xbc, 0x04,\n 0xf0, 0x01, 0xd0, 0x21, 0x63, 0x84, 0x7c, 0x9f, 0x1c, 0xc9, 0x71, 0x65,\n 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69,\n 0x66, 0x69, 0x65, 0x72, 0x6b, 0x61, 0x67, 0x65, 0x5f, 0x6f, 0x76, 0x65,\n 0x72, 0x5f, 0x31, 0x38, 0x6c, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74,\n 0x56, 0x61, 0x6c, 0x75, 0x65, 0xf5, 0x6a, 0x69, 0x73, 0x73, 0x75, 0x65,\n 0x72, 0x41, 0x75, 0x74, 0x68, 0x84, 0x43, 0xa1, 0x01, 0x26, 0xa1, 0x18,\n 0x21, 0x59, 0x02, 0x83, 0x30, 0x82, 0x02, 0x7f, 0x30, 0x82, 0x02, 0x25,\n 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x10, 0x35, 0x00, 0xba, 0x9b, 0xef,\n 0xd9, 0x1c, 0xb9, 0xda, 0x79, 0x05, 0xff, 0xef, 0x18, 0xbe, 0x8a, 0x30,\n 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30,\n 0x39, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,\n 0x55, 0x54, 0x31, 0x2a, 0x30, 0x28, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c,\n 0x21, 0x4f, 0x57, 0x46, 0x20, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74,\n 0x79, 0x20, 0x43, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c,\n 0x20, 0x54, 0x45, 0x53, 0x54, 0x20, 0x49, 0x41, 0x43, 0x41, 0x30, 0x1e,\n 0x17, 0x0d, 0x32, 0x34, 0x30, 0x39, 0x30, 0x32, 0x31, 0x37, 0x32, 0x31,\n 0x31, 0x33, 0x5a, 0x17, 0x0d, 0x32, 0x35, 0x30, 0x39, 0x30, 0x32, 0x31,\n 0x37, 0x32, 0x31, 0x31, 0x33, 0x5a, 0x30, 0x37, 0x31, 0x28, 0x30, 0x26,\n 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x1f, 0x4f, 0x57, 0x46, 0x20, 0x49,\n 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x20, 0x43, 0x72, 0x65, 0x64,\n 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x20, 0x54, 0x45, 0x53, 0x54, 0x20,\n 0x44, 0x53, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,\n 0x02, 0x55, 0x54, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48,\n 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03,\n 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0xdc, 0x1c, 0x1f, 0x55, 0xcf, 0xf4,\n 0xcd, 0x5c, 0x76, 0xcf, 0x41, 0x69, 0x27, 0x8f, 0x72, 0x17, 0x66, 0x7f,\n 0x86, 0xee, 0x81, 0xd8, 0x66, 0x9b, 0x63, 0xf2, 0xe1, 0x9b, 0xc1, 0x2a,\n 0x0c, 0x9f, 0x12, 0x35, 0x5d, 0xd0, 0x38, 0x5f, 0xed, 0x3b, 0xc3, 0x3b,\n 0xed, 0xc9, 0x78, 0x1b, 0x9a, 0xad, 0x47, 0xb3, 0x3e, 0x4c, 0x24, 0x70,\n 0x4b, 0x8d, 0x14, 0x28, 0x8b, 0x1b, 0x3c, 0xb4, 0x5c, 0x28, 0xa3, 0x82,\n 0x01, 0x0f, 0x30, 0x82, 0x01, 0x0b, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d,\n 0x0e, 0x04, 0x16, 0x04, 0x14, 0x13, 0x09, 0xce, 0x86, 0x0b, 0x9d, 0xff,\n 0xbc, 0x85, 0x99, 0x28, 0x3a, 0x1d, 0xd9, 0xc1, 0xf3, 0x55, 0x6a, 0x63,\n 0xf1, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16,\n 0x80, 0x14, 0x3c, 0xc0, 0x46, 0x99, 0x0e, 0x93, 0x42, 0x85, 0x46, 0x6d,\n 0xf6, 0xc6, 0xe0, 0x9a, 0xe3, 0xe3, 0x68, 0xdf, 0x2b, 0x0e, 0x30, 0x0e,\n 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02,\n 0x07, 0x80, 0x30, 0x15, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x01, 0x01, 0xff,\n 0x04, 0x0b, 0x30, 0x09, 0x06, 0x07, 0x28, 0x81, 0x8c, 0x5d, 0x05, 0x01,\n 0x02, 0x30, 0x54, 0x06, 0x03, 0x55, 0x1d, 0x1f, 0x04, 0x4d, 0x04, 0x4b,\n 0x30, 0x49, 0x30, 0x47, 0xa0, 0x45, 0xa0, 0x43, 0x86, 0x41, 0x68, 0x74,\n 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62,\n 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6f, 0x70, 0x65, 0x6e, 0x77, 0x61, 0x6c,\n 0x6c, 0x65, 0x74, 0x2d, 0x66, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, 0x69,\n 0x6f, 0x6e, 0x2d, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x69, 0x64, 0x65, 0x6e,\n 0x74, 0x69, 0x74, 0x79, 0x2d, 0x63, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74,\n 0x69, 0x61, 0x6c, 0x30, 0x4c, 0x06, 0x03, 0x55, 0x1d, 0x12, 0x04, 0x45,\n 0x04, 0x43, 0x86, 0x41, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f,\n 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6f,\n 0x70, 0x65, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x2d, 0x66, 0x6f,\n 0x75, 0x6e, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2d, 0x6c, 0x61, 0x62,\n 0x73, 0x2f, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2d, 0x63,\n 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x30, 0x0a, 0x06,\n 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x48, 0x00,\n 0x30, 0x45, 0x02, 0x21, 0x00, 0xcc, 0x61, 0x2d, 0xb2, 0xda, 0x22, 0x60,\n 0x9b, 0xf0, 0xa9, 0xeb, 0xea, 0x39, 0xa9, 0x05, 0x74, 0xfa, 0xc6, 0xd1,\n 0xb0, 0xed, 0x8b, 0x8b, 0xe0, 0x45, 0x27, 0x3e, 0xc7, 0x27, 0x6f, 0x64,\n 0x0c, 0x02, 0x20, 0x7f, 0x21, 0x44, 0x30, 0x13, 0x45, 0x54, 0x40, 0x93,\n 0x53, 0xb4, 0xb7, 0x4c, 0x4b, 0x64, 0x52, 0x64, 0x15, 0x81, 0x6d, 0x2f,\n 0xcb, 0x43, 0x29, 0x57, 0x0c, 0x62, 0xd5, 0x56, 0x27, 0x2b, 0x54, 0x59,\n 0x06, 0xdb, 0xd8, 0x18, 0x59, 0x06, 0xd6, 0xa6, 0x67, 0x76, 0x65, 0x72,\n 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e, 0x30, 0x6f, 0x64, 0x69, 0x67,\n 0x65, 0x73, 0x74, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d,\n 0x67, 0x53, 0x48, 0x41, 0x2d, 0x32, 0x35, 0x36, 0x67, 0x64, 0x6f, 0x63,\n 0x54, 0x79, 0x70, 0x65, 0x75, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73, 0x6f,\n 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0x2e, 0x6d,\n 0x44, 0x4c, 0x6c, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x44, 0x69, 0x67, 0x65,\n 0x73, 0x74, 0x73, 0xa2, 0x71, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73, 0x6f,\n 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0xb8, 0x22,\n 0x18, 0x1a, 0x58, 0x20, 0x2c, 0xb7, 0x3e, 0x3e, 0xc2, 0x84, 0xc0, 0x76,\n 0x43, 0xcb, 0x0c, 0xf5, 0xdf, 0x2d, 0xc0, 0xac, 0x83, 0xf8, 0xb2, 0x36,\n 0xb3, 0xa9, 0xb7, 0x32, 0xb6, 0x8e, 0x4b, 0x3b, 0x64, 0x46, 0xf5, 0x79,\n 0x18, 0x1c, 0x58, 0x20, 0x9b, 0xbe, 0x80, 0x85, 0x23, 0x6e, 0xd0, 0x36,\n 0x89, 0x0f, 0x9b, 0x03, 0xf0, 0x18, 0x53, 0x1c, 0x33, 0xb2, 0x4b, 0x34,\n 0xb2, 0x95, 0x2d, 0xe6, 0xdb, 0x79, 0x1f, 0x39, 0x02, 0xc4, 0xa6, 0x6d,\n 0x0a, 0x58, 0x20, 0x5b, 0xde, 0xa4, 0x3a, 0x31, 0xd1, 0x78, 0xc3, 0xc7,\n 0x2f, 0xec, 0x44, 0xc7, 0x1b, 0xe5, 0x15, 0xa2, 0x68, 0x96, 0x27, 0xbe,\n 0x2d, 0x3e, 0x71, 0x5c, 0x3b, 0xba, 0x4e, 0x25, 0x78, 0x53, 0x34, 0x14,\n 0x58, 0x20, 0x55, 0xe0, 0xe0, 0x5e, 0xc0, 0xd6, 0xe2, 0x59, 0x20, 0xf4,\n 0x6e, 0x64, 0x28, 0x6c, 0xa9, 0x81, 0xf4, 0xfc, 0xba, 0xe9, 0xa0, 0xbc,\n 0xbd, 0x8b, 0x89, 0x3a, 0x22, 0x5d, 0x94, 0xa6, 0xc6, 0x94, 0x16, 0x58,\n 0x20, 0xc8, 0xf2, 0xef, 0x54, 0xbf, 0xa6, 0xb8, 0x19, 0x67, 0xf4, 0x78,\n 0xb5, 0xa7, 0xa9, 0xee, 0x36, 0x64, 0xf6, 0x00, 0xac, 0x8d, 0x28, 0x9f,\n 0xef, 0xd6, 0xa8, 0x03, 0xd1, 0x10, 0x7a, 0xa6, 0xb0, 0x18, 0x1f, 0x58,\n 0x20, 0x6a, 0x93, 0x6b, 0xd3, 0x48, 0x23, 0xee, 0x83, 0x20, 0x9d, 0x76,\n 0x4d, 0x1e, 0x5d, 0x38, 0xa7, 0x0c, 0x0d, 0xf2, 0x08, 0x93, 0x71, 0xcb,\n 0xb9, 0x84, 0x4c, 0xff, 0xf9, 0xb5, 0xc5, 0xc8, 0xef, 0x18, 0x27, 0x58,\n 0x20, 0x1a, 0x40, 0x41, 0x2d, 0xf1, 0x81, 0x55, 0x2d, 0xe9, 0xb5, 0x41,\n 0x74, 0x46, 0x66, 0x04, 0x9a, 0x86, 0x9f, 0xb2, 0x7e, 0x2d, 0x58, 0x86,\n 0xf7, 0xa9, 0x97, 0x28, 0xeb, 0xb8, 0xb9, 0x44, 0x30, 0x07, 0x58, 0x20,\n 0x38, 0xb1, 0x69, 0x90, 0xb9, 0xfc, 0x76, 0xf2, 0x3a, 0x85, 0x16, 0x69,\n 0x0a, 0x28, 0xa8, 0x22, 0x79, 0xd2, 0xcb, 0xd9, 0x6c, 0xdf, 0xd8, 0x89,\n 0xe4, 0x2b, 0xac, 0xbf, 0x06, 0xb9, 0xf0, 0x52, 0x18, 0x25, 0x58, 0x20,\n 0xe7, 0x8b, 0x03, 0x63, 0x13, 0x0b, 0x2c, 0x0c, 0xd8, 0x87, 0x03, 0x1d,\n 0x42, 0x0b, 0xc9, 0xd3, 0x86, 0x87, 0x05, 0x35, 0xfb, 0x16, 0x73, 0xcc,\n 0xd8, 0x6a, 0xcb, 0x83, 0xde, 0x2a, 0x10, 0x7c, 0x18, 0x21, 0x58, 0x20,\n 0x89, 0x90, 0xf0, 0xdc, 0x1a, 0xde, 0xd7, 0xa4, 0x61, 0x34, 0x81, 0x2c,\n 0x44, 0x0f, 0xc0, 0x8b, 0xeb, 0xaa, 0xfb, 0xf4, 0x72, 0xbd, 0x29, 0x8d,\n 0xf2, 0x8f, 0x1c, 0x65, 0xbd, 0xd0, 0x07, 0xdf, 0x08, 0x58, 0x20, 0x75,\n 0x1e, 0x3b, 0x24, 0xef, 0xb3, 0x2f, 0x74, 0x08, 0x11, 0x2b, 0x12, 0xe8,\n 0x86, 0xec, 0x4c, 0xf6, 0x17, 0x61, 0x56, 0x2f, 0x5a, 0xbd, 0x5a, 0xe5,\n 0x71, 0xc7, 0x30, 0x72, 0x30, 0x6c, 0xd9, 0x03, 0x58, 0x20, 0x52, 0x09,\n 0x57, 0x17, 0x6a, 0x82, 0x2a, 0x51, 0x94, 0x47, 0xd6, 0x15, 0x23, 0x4b,\n 0xcd, 0x6b, 0x97, 0x2a, 0x71, 0x54, 0xf2, 0xa4, 0x69, 0x99, 0x2b, 0x2e,\n 0xc1, 0x86, 0x29, 0x18, 0x19, 0x58, 0x0f, 0x58, 0x20, 0x7f, 0x49, 0x2e,\n 0xcd, 0xad, 0xe9, 0xb0, 0x15, 0xf1, 0x9e, 0x96, 0x56, 0xb7, 0xcb, 0x4f,\n 0x27, 0xd9, 0x68, 0x40, 0xee, 0xd5, 0x34, 0x26, 0x64, 0xdc, 0xd2, 0x23,\n 0xd1, 0x56, 0x41, 0xa8, 0x1b, 0x13, 0x58, 0x20, 0x9d, 0x2c, 0xf0, 0x53,\n 0x97, 0x9a, 0x21, 0x62, 0x2d, 0xb9, 0x13, 0x95, 0xf7, 0x8a, 0xaf, 0x5b,\n 0x9c, 0x92, 0x39, 0x16, 0x53, 0xd8, 0xc5, 0xbb, 0x42, 0x68, 0xa6, 0x40,\n 0x83, 0x96, 0xfe, 0x28, 0x04, 0x58, 0x20, 0xf7, 0x97, 0xdf, 0xe4, 0x0f,\n 0x5d, 0x9a, 0x61, 0x6c, 0x9d, 0x26, 0xf3, 0x74, 0x22, 0x51, 0x56, 0xa0,\n 0x9e, 0x61, 0xae, 0xa4, 0xa4, 0x38, 0x60, 0x68, 0x18, 0xd4, 0xbd, 0x2c,\n 0xe6, 0x18, 0xb0, 0x0c, 0x58, 0x20, 0xe5, 0x95, 0x37, 0xec, 0x38, 0xe7,\n 0xa7, 0x8f, 0xe9, 0xe8, 0xc0, 0xe8, 0xa8, 0x18, 0x81, 0xe7, 0xc1, 0xe9,\n 0x2f, 0x11, 0x17, 0xb6, 0x29, 0x7a, 0xcf, 0xf1, 0x7c, 0x8e, 0x74, 0xd0,\n 0xad, 0x12, 0x09, 0x58, 0x20, 0x6f, 0x7f, 0xb1, 0xdf, 0x35, 0x2f, 0x23,\n 0x2f, 0x25, 0x9a, 0xc0, 0xa4, 0xee, 0x39, 0x76, 0x09, 0x3a, 0x32, 0x4f,\n 0xd1, 0xb1, 0xa1, 0xf3, 0x15, 0xb2, 0x48, 0x1d, 0x40, 0xa0, 0x69, 0x7c,\n 0xc5, 0x18, 0x18, 0x58, 0x20, 0x70, 0x58, 0x58, 0x66, 0xab, 0xf1, 0xc5,\n 0xfb, 0x60, 0xd5, 0xf4, 0xb0, 0x9a, 0xa8, 0xab, 0xb9, 0xf9, 0x52, 0x2a,\n 0x14, 0x2d, 0xc3, 0x54, 0xa1, 0x1c, 0xbe, 0xb8, 0x58, 0xf6, 0x1c, 0xa1,\n 0x40, 0x06, 0x58, 0x20, 0xb7, 0x60, 0x27, 0x85, 0xef, 0x55, 0x31, 0x9c,\n 0x6e, 0xf1, 0xd3, 0xea, 0x6f, 0x36, 0x1d, 0xa9, 0xe1, 0xf0, 0x04, 0x50,\n 0x13, 0xcd, 0x2f, 0x74, 0xa1, 0xd8, 0x24, 0x7d, 0x1a, 0x75, 0x86, 0xbe,\n 0x12, 0x58, 0x20, 0xc1, 0x9a, 0xdf, 0x46, 0x4a, 0x9b, 0x22, 0xc5, 0x79,\n 0xc0, 0x56, 0xbb, 0x0e, 0x45, 0x98, 0xb8, 0x90, 0xa0, 0xbb, 0x16, 0x83,\n 0xb7, 0x29, 0x06, 0x7f, 0xa8, 0x2c, 0x5e, 0x6a, 0x10, 0x3d, 0x2d, 0x18,\n 0x1b, 0x58, 0x20, 0x94, 0x97, 0xfa, 0xb1, 0xcb, 0xa4, 0x6c, 0xe4, 0x10,\n 0x90, 0x9f, 0x5d, 0xb0, 0xea, 0xda, 0x49, 0xc5, 0xf0, 0x19, 0x5e, 0xcb,\n 0x03, 0x22, 0x0d, 0xe9, 0xba, 0x88, 0xc9, 0x61, 0xc4, 0xbb, 0xf8, 0x00,\n 0x58, 0x20, 0x5b, 0x22, 0x5a, 0xa1, 0xc6, 0x31, 0x6a, 0xcf, 0xed, 0x2b,\n 0xe6, 0x70, 0x15, 0xed, 0x71, 0xc2, 0xda, 0x4d, 0x87, 0x3f, 0x01, 0xa2,\n 0xfd, 0xd4, 0xd6, 0x2f, 0xb3, 0x01, 0x23, 0x38, 0x6d, 0xc8, 0x0e, 0x58,\n 0x20, 0xcf, 0x32, 0x74, 0x8e, 0x98, 0xfb, 0x6b, 0x9d, 0xee, 0x3d, 0x48,\n 0x42, 0x1f, 0xb5, 0xf6, 0xb4, 0x50, 0x24, 0xae, 0x46, 0x87, 0x89, 0x25,\n 0x79, 0xaa, 0x05, 0xe3, 0x10, 0x24, 0x60, 0x21, 0x80, 0x15, 0x58, 0x20,\n 0x71, 0xcd, 0x46, 0x7c, 0x9c, 0x1c, 0x7a, 0x0c, 0x88, 0x95, 0x06, 0xe9,\n 0x7e, 0x13, 0x35, 0xe0, 0xff, 0xb8, 0x1f, 0xd1, 0x9d, 0x8d, 0x5c, 0x84,\n 0x8d, 0x74, 0xd7, 0x02, 0x31, 0xab, 0xfa, 0x82, 0x18, 0x20, 0x58, 0x20,\n 0x88, 0x22, 0x51, 0x86, 0xc9, 0x41, 0xc8, 0x05, 0xea, 0xff, 0x63, 0x9d,\n 0xa5, 0xaf, 0x04, 0xaa, 0xf0, 0xe9, 0xad, 0x7c, 0xb4, 0x84, 0xb1, 0x66,\n 0x66, 0x94, 0x32, 0xed, 0x65, 0xf6, 0x3d, 0x52, 0x18, 0x26, 0x58, 0x20,\n 0xc6, 0xba, 0x1f, 0x99, 0x66, 0xd5, 0x25, 0x51, 0x5d, 0xc9, 0x0c, 0x48,\n 0x3f, 0x93, 0x25, 0xfe, 0x3d, 0x8d, 0x08, 0x3e, 0x2c, 0x58, 0xb6, 0x85,\n 0x97, 0x2b, 0x30, 0x8b, 0x4d, 0xa4, 0x3e, 0x31, 0x0d, 0x58, 0x20, 0x33,\n 0xb6, 0xfc, 0x44, 0xed, 0x68, 0x73, 0x54, 0x37, 0x11, 0xf5, 0xe7, 0x97,\n 0x9d, 0xef, 0xe9, 0xa7, 0x1a, 0x1b, 0x4a, 0x25, 0x4f, 0x91, 0x64, 0xf4,\n 0xfc, 0x37, 0xff, 0xb8, 0x00, 0x48, 0x50, 0x18, 0x1d, 0x58, 0x20, 0x3e,\n 0x1f, 0xfd, 0x36, 0x5a, 0x73, 0xb6, 0x9e, 0x8e, 0xe3, 0x7e, 0xd9, 0x1a,\n 0xc2, 0x7f, 0x79, 0xa1, 0x37, 0x00, 0xa7, 0xbc, 0x2e, 0xfe, 0xc0, 0xad,\n 0x0c, 0xce, 0xd1, 0xde, 0xb5, 0xbe, 0xbf, 0x18, 0x1e, 0x58, 0x20, 0x40,\n 0x89, 0xa1, 0x71, 0x6a, 0x4a, 0xd5, 0xb9, 0xd0, 0xf6, 0xd5, 0x18, 0xd3,\n 0x85, 0xd5, 0x2f, 0x77, 0xa2, 0x0d, 0x50, 0x46, 0x16, 0xf9, 0xc5, 0x88,\n 0xbd, 0x60, 0xc6, 0x14, 0xcd, 0x24, 0x8a, 0x11, 0x58, 0x20, 0x82, 0x1e,\n 0xa8, 0x0b, 0x1b, 0x53, 0x3b, 0xf3, 0x2c, 0x6c, 0x0f, 0xce, 0xdf, 0x78,\n 0x9d, 0x92, 0xac, 0xe2, 0x78, 0xc8, 0x68, 0x23, 0x06, 0x70, 0xe3, 0x41,\n 0xf9, 0x51, 0xfa, 0x15, 0x0b, 0xaa, 0x01, 0x58, 0x20, 0xa5, 0x8a, 0x7b,\n 0xe3, 0x89, 0x6c, 0x72, 0xb3, 0xce, 0x94, 0xe2, 0xc8, 0xf8, 0x23, 0x84,\n 0x0e, 0xc6, 0xe2, 0xd0, 0xe3, 0x2f, 0x9e, 0x27, 0xce, 0x4d, 0x51, 0xfb,\n 0x3e, 0xe1, 0x7c, 0x59, 0xd7, 0x02, 0x58, 0x20, 0xe4, 0xeb, 0x6b, 0x2d,\n 0x3c, 0x36, 0xd3, 0x54, 0xfe, 0x1e, 0xe2, 0x81, 0x89, 0x29, 0x49, 0x79,\n 0x82, 0x84, 0x82, 0xe3, 0x02, 0x64, 0x8b, 0x42, 0xd6, 0x4f, 0x89, 0xd8,\n 0x97, 0x02, 0x2e, 0x11, 0x17, 0x58, 0x20, 0xa3, 0x13, 0xf2, 0x6c, 0xb6,\n 0x25, 0xd2, 0x52, 0x20, 0x25, 0xf3, 0x33, 0x51, 0x17, 0x5c, 0xa0, 0x9a,\n 0xe5, 0x4d, 0xa5, 0xee, 0x6a, 0x75, 0x05, 0xa5, 0x40, 0xef, 0x55, 0x3c,\n 0xdd, 0x60, 0x29, 0x0b, 0x58, 0x20, 0x96, 0x47, 0xf0, 0xf8, 0xbc, 0x91,\n 0xd5, 0xc2, 0xb2, 0x48, 0x17, 0xb6, 0xe0, 0x0d, 0x7a, 0xfb, 0x2f, 0xa4,\n 0xe7, 0x8f, 0x4c, 0xce, 0xa3, 0x15, 0xeb, 0xfc, 0x01, 0xc4, 0x4a, 0xa0,\n 0x13, 0xd6, 0x77, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31,\n 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0x2e, 0x61, 0x61, 0x6d,\n 0x76, 0x61, 0xa6, 0x18, 0x19, 0x58, 0x20, 0xa6, 0xa9, 0x09, 0x5c, 0xa8,\n 0x57, 0xc0, 0x29, 0x4d, 0x81, 0x50, 0x8b, 0x26, 0xd6, 0x59, 0xa7, 0x73,\n 0xaf, 0x30, 0xfc, 0x24, 0x21, 0x5a, 0xb2, 0xdf, 0x92, 0xe2, 0x1e, 0x8f,\n 0xe7, 0xbf, 0xfb, 0x05, 0x58, 0x20, 0xfc, 0xba, 0xdd, 0x35, 0xf1, 0x3a,\n 0xf1, 0x53, 0xaa, 0xf1, 0x72, 0x7b, 0x3f, 0xd6, 0x86, 0x77, 0xfc, 0x5d,\n 0x52, 0xbb, 0xef, 0xc0, 0xd7, 0x9d, 0x1c, 0x35, 0xf3, 0x47, 0xd6, 0xd0,\n 0xce, 0x8c, 0x18, 0x23, 0x58, 0x20, 0x8b, 0x09, 0xae, 0xb3, 0xd6, 0x7d,\n 0x66, 0xb9, 0xe2, 0x65, 0x5a, 0x4f, 0x4f, 0xe9, 0x0e, 0x2b, 0x16, 0x42,\n 0x66, 0x81, 0x92, 0x7c, 0x05, 0xcb, 0x27, 0x8b, 0xe5, 0x4b, 0x6a, 0xca,\n 0x89, 0x3e, 0x10, 0x58, 0x20, 0x9b, 0xcd, 0x90, 0x2b, 0x6b, 0xcf, 0x9d,\n 0xa8, 0x70, 0xc1, 0x48, 0x4f, 0x14, 0x53, 0x23, 0xfc, 0x84, 0xa2, 0x64,\n 0xd4, 0x22, 0x41, 0x37, 0x52, 0x1c, 0x03, 0x53, 0xc4, 0x8c, 0x22, 0xc3,\n 0xab, 0x18, 0x24, 0x58, 0x20, 0x0f, 0xd3, 0xd9, 0x88, 0xef, 0x7c, 0x64,\n 0x0c, 0xc4, 0x83, 0xf1, 0x23, 0xcb, 0x0b, 0xeb, 0x0c, 0x49, 0xaa, 0x6e,\n 0xdd, 0xae, 0x96, 0xec, 0x17, 0xaf, 0x66, 0x58, 0x6b, 0x05, 0x16, 0x73,\n 0x55, 0x18, 0x22, 0x58, 0x20, 0x45, 0x87, 0xe3, 0x6a, 0x16, 0x9a, 0x71,\n 0xd6, 0xf2, 0x51, 0xfa, 0x39, 0x68, 0x69, 0x81, 0x22, 0x9e, 0x97, 0xe6,\n 0x46, 0xc9, 0x84, 0x3c, 0x1b, 0x5a, 0x13, 0x91, 0xdb, 0x03, 0x6b, 0xd2,\n 0xc0, 0x6d, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79, 0x49,\n 0x6e, 0x66, 0x6f, 0xa1, 0x69, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4b,\n 0x65, 0x79, 0xa4, 0x01, 0x02, 0x20, 0x01, 0x21, 0x58, 0x20, 0x53, 0x1a,\n 0x86, 0xbd, 0xc5, 0xae, 0xa7, 0xb4, 0xbf, 0xf1, 0x12, 0x08, 0xef, 0xb5,\n 0xc5, 0xa7, 0xdb, 0x1b, 0x00, 0x17, 0xc0, 0x20, 0xd7, 0xd9, 0xf6, 0xbf,\n 0x89, 0x2d, 0x47, 0xa6, 0x17, 0xd1, 0x22, 0x58, 0x20, 0x24, 0xac, 0x72,\n 0x74, 0xf7, 0xe6, 0xa1, 0x0a, 0x39, 0x56, 0xb9, 0x2e, 0x5a, 0xc2, 0xf8,\n 0xab, 0x53, 0xcd, 0x8a, 0xb3, 0xb4, 0x38, 0x22, 0xab, 0x1d, 0x05, 0x90,\n 0x4f, 0x3b, 0x50, 0xb2, 0xd6, 0x6c, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x69,\n 0x74, 0x79, 0x49, 0x6e, 0x66, 0x6f, 0xa3, 0x66, 0x73, 0x69, 0x67, 0x6e,\n 0x65, 0x64, 0xc0, 0x74, 0x32, 0x30, 0x32, 0x34, 0x2d, 0x30, 0x39, 0x2d,\n 0x33, 0x30, 0x54, 0x31, 0x33, 0x3a, 0x35, 0x30, 0x3a, 0x30, 0x30, 0x5a,\n 0x69, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x46, 0x72, 0x6f, 0x6d, 0xc0, 0x74,\n 0x32, 0x30, 0x32, 0x34, 0x2d, 0x30, 0x39, 0x2d, 0x33, 0x30, 0x54, 0x31,\n 0x33, 0x3a, 0x35, 0x30, 0x3a, 0x30, 0x30, 0x5a, 0x6a, 0x76, 0x61, 0x6c,\n 0x69, 0x64, 0x55, 0x6e, 0x74, 0x69, 0x6c, 0xc0, 0x74, 0x32, 0x30, 0x32,\n 0x34, 0x2d, 0x31, 0x30, 0x2d, 0x33, 0x30, 0x54, 0x31, 0x33, 0x3a, 0x35,\n 0x30, 0x3a, 0x30, 0x30, 0x5a, 0x58, 0x40, 0xc9, 0x9b, 0xd4, 0x13, 0xf8,\n 0x8d, 0xd3, 0xf1, 0x54, 0xe5, 0x82, 0x70, 0x10, 0xe3, 0x43, 0x14, 0xb4,\n 0x41, 0x2d, 0x4d, 0x25, 0x1a, 0xed, 0x28, 0xda, 0xae, 0xe2, 0x23, 0x36,\n 0x0a, 0x9d, 0xcc, 0x9f, 0xe9, 0x45, 0x08, 0x7e, 0x56, 0xc9, 0xa5, 0x4d,\n 0xb6, 0x7a, 0x0a, 0xe3, 0xd7, 0xe1, 0xa6, 0x2e, 0xfa, 0x63, 0xc3, 0x09,\n 0x74, 0x54, 0xa0, 0xe7, 0x82, 0xfa, 0x05, 0x77, 0xe5, 0xc4, 0xdc, 0x6c,\n 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64,\n 0xa2, 0x6a, 0x6e, 0x61, 0x6d, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x73,\n 0xd8, 0x18, 0x41, 0xa0, 0x6a, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x41,\n 0x75, 0x74, 0x68, 0xa1, 0x6f, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x53,\n 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x84, 0x43, 0xa1, 0x01,\n 0x26, 0xa0, 0xf6, 0x58, 0x40, 0x83, 0xef, 0x0e, 0x35, 0xd8, 0xc5, 0x36,\n 0x92, 0xb7, 0x1e, 0x9a, 0xea, 0x4c, 0x28, 0xab, 0xac, 0xd4, 0xf8, 0x50,\n 0x1d, 0x49, 0x21, 0x82, 0x2d, 0x24, 0xd1, 0xd4, 0x82, 0x6b, 0x2e, 0x4e,\n 0xe5, 0x0d, 0x2c, 0x3d, 0x35, 0xac, 0x4a, 0xf2, 0xdf, 0x95, 0x4e, 0x3a,\n 0x29, 0x72, 0x8a, 0xad, 0xb7, 0x9b, 0xdd, 0x86, 0xc6, 0x25, 0xe9, 0xd6,\n 0x7a, 0xb9, 0x0c, 0xbd, 0x7c, 0xd0, 0x7a, 0xe1, 0x3c, 0x66, 0x73, 0x74,\n 0x61, 0x74, 0x75, 0x73, 0x00},\n },\n // Google IACA identity-pass example\n {StaticString(\n \"0x5070e8199f3c5e1ecf6249662994997605b7205b039ff77fad4f9aceb3cadbcd\"),\n StaticString(\n \"0xc2f6fa056f2423ca57f828ded12656bdae863f23654561d494ae5efa9feb883f\"),\n {0x83, 0xf6, 0xf6, 0x84, 0x71, 0x42, 0x72, 0x6f, 0x77, 0x73, 0x65, 0x72,\n 0x48, 0x61, 0x6e, 0x64, 0x6f, 0x76, 0x65, 0x72, 0x76, 0x31, 0x58, 0x37,\n 0x01, 0x06, 0x78, 0x53, 0x3e, 0x47, 0xa7, 0xdb, 0x12, 0xde, 0x39, 0x1a,\n 0x58, 0xa0, 0x53, 0x1a, 0x13, 0x3e, 0x8f, 0x07, 0x14, 0xee, 0x07, 0x5f,\n 0xcb, 0x38, 0x4a, 0xf9, 0x0a, 0xb1, 0x71, 0x31, 0xce, 0x24, 0x1e, 0x7b,\n 0xf0, 0x71, 0x98, 0x32, 0xb5, 0xad, 0x02, 0xac, 0xee, 0x72, 0xfd, 0x69,\n 0x0e, 0xf3, 0x45, 0x28, 0x09, 0x71, 0xde, 0x58, 0x49, 0xa3, 0x63, 0x63,\n 0x61, 0x74, 0x01, 0x64, 0x74, 0x79, 0x70, 0x65, 0x01, 0x67, 0x64, 0x65,\n 0x74, 0x61, 0x69, 0x6c, 0x73, 0xa1, 0x67, 0x62, 0x61, 0x73, 0x65, 0x55,\n 0x72, 0x6c, 0x78, 0x2a, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f,\n 0x6f, 0x76, 0x32, 0x2d, 0x74, 0x64, 0x6d, 0x67, 0x70, 0x77, 0x61, 0x6d,\n 0x2e, 0x64, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x72, 0x70, 0x2e,\n 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x58, 0x20,\n 0xc5, 0x86, 0xef, 0x29, 0xc7, 0xf0, 0x76, 0xfc, 0x15, 0x2b, 0x93, 0x85,\n 0x94, 0x7e, 0x82, 0x58, 0x9d, 0x6d, 0xe2, 0x43, 0xae, 0x18, 0x90, 0xef,\n 0x08, 0x5f, 0xd1, 0x31, 0x2b, 0x1f, 0x25, 0xdd},\n 188,\n (uint8_t *)\"2025-01-29T18:00:00Z\",\n kIDPass,\n 2211,\n {0xa3, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e,\n 0x30, 0x69, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x81,\n 0xa3, 0x67, 0x64, 0x6f, 0x63, 0x54, 0x79, 0x70, 0x65, 0x78, 0x1a, 0x63,\n 0x6f, 0x6d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x77, 0x61,\n 0x6c, 0x6c, 0x65, 0x74, 0x2e, 0x69, 0x64, 0x63, 0x61, 0x72, 0x64, 0x2e,\n 0x31, 0x6c, 0x69, 0x73, 0x73, 0x75, 0x65, 0x72, 0x53, 0x69, 0x67, 0x6e,\n 0x65, 0x64, 0xa2, 0x6a, 0x6e, 0x61, 0x6d, 0x65, 0x53, 0x70, 0x61, 0x63,\n 0x65, 0x73, 0xa1, 0x71, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e,\n 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0x81, 0xd8, 0x18,\n 0x58, 0x5d, 0xa4, 0x68, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74, 0x49, 0x44,\n 0x19, 0xeb, 0xa5, 0x66, 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x50, 0xfa,\n 0xe2, 0x65, 0x0e, 0x5a, 0x8a, 0x33, 0x39, 0x2b, 0xc5, 0x74, 0x26, 0x6f,\n 0x4d, 0x19, 0xa7, 0x71, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x49,\n 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x6a, 0x62, 0x69,\n 0x72, 0x74, 0x68, 0x5f, 0x64, 0x61, 0x74, 0x65, 0x6c, 0x65, 0x6c, 0x65,\n 0x6d, 0x65, 0x6e, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0xd9, 0x03, 0xec,\n 0x6a, 0x31, 0x39, 0x39, 0x38, 0x2d, 0x30, 0x39, 0x2d, 0x30, 0x34, 0x6a,\n 0x69, 0x73, 0x73, 0x75, 0x65, 0x72, 0x41, 0x75, 0x74, 0x68, 0x84, 0x43,\n 0xa1, 0x01, 0x26, 0xa1, 0x18, 0x21, 0x59, 0x03, 0x91, 0x30, 0x82, 0x03,\n 0x8d, 0x30, 0x82, 0x03, 0x12, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x13,\n 0x35, 0xa5, 0x2a, 0x85, 0x87, 0x44, 0xb0, 0x01, 0x08, 0x5b, 0xe6, 0xaa,\n 0x4c, 0x72, 0xf8, 0xc8, 0x8f, 0x04, 0x97, 0x30, 0x0a, 0x06, 0x08, 0x2a,\n 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x03, 0x30, 0x5d, 0x31, 0x0b, 0x30,\n 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x54, 0x31, 0x13,\n 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0a, 0x47, 0x6f, 0x6f,\n 0x67, 0x6c, 0x65, 0x20, 0x4c, 0x4c, 0x43, 0x31, 0x0f, 0x30, 0x0d, 0x06,\n 0x03, 0x55, 0x04, 0x0b, 0x13, 0x06, 0x57, 0x61, 0x6c, 0x6c, 0x65, 0x74,\n 0x31, 0x28, 0x30, 0x26, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x1f, 0x54,\n 0x45, 0x53, 0x54, 0x20, 0x55, 0x53, 0x45, 0x20, 0x4f, 0x4e, 0x4c, 0x59,\n 0x20, 0x47, 0x49, 0x43, 0x49, 0x20, 0x53, 0x74, 0x61, 0x67, 0x69, 0x6e,\n 0x67, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34,\n 0x30, 0x33, 0x32, 0x38, 0x30, 0x31, 0x32, 0x32, 0x30, 0x30, 0x5a, 0x17,\n 0x0d, 0x32, 0x35, 0x30, 0x33, 0x32, 0x38, 0x30, 0x31, 0x32, 0x31, 0x35,\n 0x39, 0x5a, 0x30, 0x5b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,\n 0x06, 0x13, 0x02, 0x55, 0x54, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55,\n 0x04, 0x0a, 0x13, 0x0a, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x20, 0x4c,\n 0x4c, 0x43, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13,\n 0x06, 0x57, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x31, 0x26, 0x30, 0x24, 0x06,\n 0x03, 0x55, 0x04, 0x03, 0x13, 0x1d, 0x54, 0x45, 0x53, 0x54, 0x20, 0x55,\n 0x53, 0x45, 0x20, 0x4f, 0x4e, 0x4c, 0x59, 0x20, 0x47, 0x49, 0x43, 0x49,\n 0x20, 0x53, 0x74, 0x61, 0x67, 0x69, 0x6e, 0x67, 0x20, 0x44, 0x53, 0x30,\n 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01,\n 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42,\n 0x00, 0x04, 0x50, 0x70, 0xe8, 0x19, 0x9f, 0x3c, 0x5e, 0x1e, 0xcf, 0x62,\n 0x49, 0x66, 0x29, 0x94, 0x99, 0x76, 0x05, 0xb7, 0x20, 0x5b, 0x03, 0x9f,\n 0xf7, 0x7f, 0xad, 0x4f, 0x9a, 0xce, 0xb3, 0xca, 0xdb, 0xcd, 0xc2, 0xf6,\n 0xfa, 0x05, 0x6f, 0x24, 0x23, 0xca, 0x57, 0xf8, 0x28, 0xde, 0xd1, 0x26,\n 0x56, 0xbd, 0xae, 0x86, 0x3f, 0x23, 0x65, 0x45, 0x61, 0xd4, 0x94, 0xae,\n 0x5e, 0xfa, 0x9f, 0xeb, 0x88, 0x3f, 0xa3, 0x82, 0x01, 0xb1, 0x30, 0x82,\n 0x01, 0xad, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff,\n 0x04, 0x04, 0x03, 0x02, 0x07, 0x80, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d,\n 0x13, 0x01, 0x01, 0xff, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03,\n 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x62, 0x1b, 0xd1, 0x8c, 0xa5,\n 0x64, 0x49, 0x37, 0x2b, 0x6f, 0x0c, 0xf7, 0x82, 0x17, 0xac, 0x8a, 0x6d,\n 0xa3, 0xde, 0x67, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18,\n 0x30, 0x16, 0x80, 0x14, 0x9f, 0x5a, 0x68, 0xc3, 0xe9, 0x80, 0x19, 0xde,\n 0xe9, 0x98, 0x25, 0x64, 0xf6, 0xba, 0x23, 0x84, 0xff, 0x92, 0xed, 0xb4,\n 0x30, 0x81, 0x8d, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x01,\n 0x01, 0x04, 0x81, 0x80, 0x30, 0x7e, 0x30, 0x7c, 0x06, 0x08, 0x2b, 0x06,\n 0x01, 0x05, 0x05, 0x07, 0x30, 0x02, 0x86, 0x70, 0x68, 0x74, 0x74, 0x70,\n 0x3a, 0x2f, 0x2f, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x63, 0x61,\n 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x36, 0x36, 0x30,\n 0x33, 0x63, 0x36, 0x34, 0x37, 0x2d, 0x30, 0x30, 0x30, 0x30, 0x2d, 0x32,\n 0x39, 0x64, 0x34, 0x2d, 0x61, 0x65, 0x61, 0x36, 0x2d, 0x66, 0x34, 0x66,\n 0x35, 0x65, 0x38, 0x30, 0x64, 0x31, 0x62, 0x39, 0x30, 0x2e, 0x73, 0x74,\n 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65,\n 0x61, 0x70, 0x69, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x34, 0x31, 0x64,\n 0x34, 0x33, 0x36, 0x38, 0x35, 0x39, 0x65, 0x34, 0x35, 0x64, 0x62, 0x66,\n 0x33, 0x65, 0x35, 0x61, 0x39, 0x2f, 0x63, 0x61, 0x2e, 0x63, 0x72, 0x74,\n 0x30, 0x81, 0x82, 0x06, 0x03, 0x55, 0x1d, 0x1f, 0x04, 0x7b, 0x30, 0x79,\n 0x30, 0x77, 0xa0, 0x75, 0xa0, 0x73, 0x86, 0x71, 0x68, 0x74, 0x74, 0x70,\n 0x3a, 0x2f, 0x2f, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x63, 0x61,\n 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x36, 0x36, 0x30,\n 0x33, 0x63, 0x36, 0x34, 0x37, 0x2d, 0x30, 0x30, 0x30, 0x30, 0x2d, 0x32,\n 0x39, 0x64, 0x34, 0x2d, 0x61, 0x65, 0x61, 0x36, 0x2d, 0x66, 0x34, 0x66,\n 0x35, 0x65, 0x38, 0x30, 0x64, 0x31, 0x62, 0x39, 0x30, 0x2e, 0x73, 0x74,\n 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65,\n 0x61, 0x70, 0x69, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x34, 0x31, 0x64,\n 0x34, 0x33, 0x36, 0x38, 0x35, 0x39, 0x65, 0x34, 0x35, 0x64, 0x62, 0x66,\n 0x33, 0x65, 0x35, 0x61, 0x39, 0x2f, 0x63, 0x72, 0x6c, 0x2e, 0x63, 0x72,\n 0x6c, 0x30, 0x21, 0x06, 0x03, 0x55, 0x1d, 0x12, 0x04, 0x1a, 0x30, 0x18,\n 0x86, 0x16, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x77, 0x77,\n 0x77, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d,\n 0x30, 0x15, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x01, 0x01, 0xff, 0x04, 0x0b,\n 0x30, 0x09, 0x06, 0x07, 0x28, 0x81, 0x8c, 0x5d, 0x05, 0x01, 0x02, 0x30,\n 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x03, 0x03,\n 0x69, 0x00, 0x30, 0x66, 0x02, 0x31, 0x00, 0xfb, 0xa3, 0xb8, 0xf1, 0x2d,\n 0x58, 0xc6, 0xdf, 0x20, 0xbc, 0xa2, 0x6a, 0x6c, 0x2e, 0x9c, 0x30, 0x9e,\n 0x26, 0xf9, 0x75, 0x85, 0x16, 0x95, 0x71, 0xab, 0x11, 0xf1, 0x35, 0xb0,\n 0x4c, 0xd8, 0x19, 0x24, 0x6b, 0x24, 0x3f, 0xc0, 0xdc, 0x89, 0xab, 0x65,\n 0x4a, 0x4a, 0xe7, 0xc9, 0x25, 0xf5, 0x32, 0x02, 0x31, 0x00, 0xf9, 0xe0,\n 0xd4, 0x0a, 0xfc, 0x35, 0x6f, 0x74, 0x2d, 0xb0, 0x65, 0x7e, 0x64, 0xd7,\n 0xc8, 0x1f, 0x12, 0x64, 0x3c, 0x39, 0xc1, 0xeb, 0x3e, 0x6a, 0xf9, 0x0c,\n 0xd6, 0x24, 0x4e, 0xbf, 0x0d, 0x1a, 0xb7, 0x7a, 0x38, 0x01, 0x84, 0x5f,\n 0x0e, 0xcf, 0xc8, 0x69, 0x9c, 0x7c, 0xa0, 0xef, 0xf5, 0xde, 0x59, 0x03,\n 0x62, 0xd8, 0x18, 0x59, 0x03, 0x5d, 0xa6, 0x67, 0x76, 0x65, 0x72, 0x73,\n 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e, 0x30, 0x6f, 0x64, 0x69, 0x67, 0x65,\n 0x73, 0x74, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x67,\n 0x53, 0x48, 0x41, 0x2d, 0x32, 0x35, 0x36, 0x6c, 0x76, 0x61, 0x6c, 0x75,\n 0x65, 0x44, 0x69, 0x67, 0x65, 0x73, 0x74, 0x73, 0xa2, 0x71, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0xad, 0x19, 0x11, 0x9e, 0x58, 0x20, 0x0e, 0xc0, 0x48,\n 0x3e, 0x52, 0xb7, 0xe5, 0xb1, 0xa3, 0xba, 0xd7, 0x2d, 0xc3, 0x53, 0x13,\n 0x9b, 0x10, 0x83, 0xc0, 0x48, 0x37, 0xe0, 0xab, 0x2d, 0x62, 0x24, 0xb0,\n 0x31, 0xeb, 0xed, 0x79, 0x8f, 0x19, 0x29, 0xfa, 0x58, 0x20, 0x14, 0x6c,\n 0x91, 0x85, 0x3b, 0x61, 0xf0, 0xbd, 0x9d, 0x88, 0x93, 0x61, 0xfa, 0x40,\n 0x23, 0xe6, 0x22, 0xfe, 0x5b, 0x6a, 0x20, 0xaa, 0xd4, 0xa0, 0xad, 0x2a,\n 0x58, 0x48, 0x5e, 0xdf, 0xa3, 0x17, 0x19, 0x3f, 0x01, 0x58, 0x20, 0xfc,\n 0xb0, 0x96, 0xe0, 0x4d, 0xbe, 0x0e, 0xd5, 0x7a, 0xfe, 0x9a, 0x3c, 0x94,\n 0xd5, 0xca, 0x1f, 0x2e, 0x4f, 0x42, 0xf6, 0xa8, 0xae, 0xb6, 0x6a, 0x30,\n 0x5a, 0x73, 0xe8, 0x02, 0xf5, 0xd8, 0x0d, 0x19, 0x45, 0x0e, 0x58, 0x20,\n 0x4d, 0x55, 0x56, 0xdf, 0xe9, 0x6d, 0x0b, 0x4d, 0xd8, 0x3a, 0x03, 0xe5,\n 0x17, 0xe0, 0xa7, 0x85, 0xe5, 0xf6, 0x74, 0xb3, 0x87, 0xdc, 0xc8, 0xa6,\n 0x6c, 0x1b, 0x2f, 0x07, 0x87, 0x32, 0x44, 0x6c, 0x19, 0x4b, 0x15, 0x58,\n 0x20, 0x5a, 0x4e, 0xd4, 0xb6, 0x25, 0xa1, 0x67, 0x08, 0xa0, 0x02, 0xee,\n 0x8e, 0xfd, 0xfa, 0xa8, 0x34, 0x69, 0xe4, 0x28, 0xe2, 0x5e, 0x4b, 0xfe,\n 0xc2, 0xc3, 0xb6, 0xef, 0x7d, 0x5a, 0x98, 0xd3, 0xab, 0x19, 0x4b, 0xf9,\n 0x58, 0x20, 0x1f, 0xf4, 0x99, 0xcc, 0x18, 0x3a, 0xc8, 0xbb, 0x57, 0xce,\n 0x2d, 0xd6, 0x1d, 0xa2, 0x5e, 0x13, 0xe3, 0xc0, 0x71, 0xf1, 0xe9, 0x66,\n 0xbf, 0xf8, 0xc4, 0xa4, 0xab, 0x72, 0xa4, 0xc9, 0x31, 0x75, 0x19, 0x63,\n 0x99, 0x58, 0x20, 0xf9, 0x3d, 0xce, 0xdd, 0x21, 0x16, 0x53, 0xd9, 0x9c,\n 0x8a, 0x62, 0x70, 0x29, 0x10, 0xc5, 0x27, 0x57, 0x97, 0x24, 0x68, 0x57,\n 0xf8, 0x2a, 0xbe, 0x9c, 0xd5, 0xcd, 0xc0, 0x78, 0x36, 0x56, 0x74, 0x19,\n 0x65, 0x90, 0x58, 0x20, 0xa3, 0xf5, 0xc6, 0xc4, 0x74, 0x6a, 0xb5, 0x9d,\n 0xae, 0x8c, 0x43, 0x26, 0xf8, 0x00, 0xac, 0x25, 0xf3, 0xd8, 0x45, 0x3e,\n 0xf2, 0x14, 0x1e, 0x1c, 0x4f, 0x24, 0x46, 0x11, 0x8f, 0x7b, 0x59, 0xba,\n 0x19, 0x6e, 0xfb, 0x58, 0x20, 0xe1, 0x85, 0x25, 0xb6, 0x6f, 0xc9, 0x72,\n 0x86, 0x1d, 0x84, 0xc5, 0x7c, 0x60, 0x1e, 0x3b, 0xfb, 0x9f, 0x05, 0x4c,\n 0x8c, 0x1c, 0xb6, 0xb4, 0xb9, 0x50, 0xa1, 0x27, 0x7f, 0xb1, 0x13, 0xc7,\n 0x9a, 0x19, 0x94, 0xe0, 0x58, 0x20, 0xa5, 0x61, 0x36, 0x4f, 0x92, 0x27,\n 0xa5, 0x8c, 0xfb, 0xfd, 0xbf, 0x7c, 0xb2, 0x29, 0x17, 0x0c, 0xd0, 0x5c,\n 0x7b, 0x10, 0x9c, 0x7a, 0xa5, 0x1d, 0xa6, 0x76, 0x81, 0x72, 0xb9, 0x1f,\n 0x7f, 0x57, 0x19, 0x97, 0xbd, 0x58, 0x20, 0x04, 0xd5, 0xbe, 0xd8, 0x7e,\n 0x03, 0xb9, 0x08, 0xd2, 0x64, 0x76, 0x2d, 0x8f, 0x8d, 0xd6, 0x41, 0x2b,\n 0x61, 0xbb, 0xa4, 0x3d, 0xd7, 0x08, 0x70, 0x8b, 0xdd, 0x96, 0x94, 0x4d,\n 0xc4, 0xce, 0x5e, 0x19, 0xe1, 0x7b, 0x58, 0x20, 0x69, 0xcb, 0x57, 0x76,\n 0xe1, 0x2c, 0xe1, 0xe0, 0x06, 0x31, 0xbd, 0x8f, 0x76, 0x54, 0x99, 0x34,\n 0x4f, 0x27, 0x0f, 0x64, 0xd6, 0x45, 0xc6, 0x08, 0x88, 0x77, 0xa0, 0x3f,\n 0xa3, 0x90, 0x2e, 0x87, 0x19, 0xeb, 0xa5, 0x58, 0x20, 0x99, 0x03, 0xd0,\n 0x2a, 0xbd, 0xc6, 0x12, 0xc3, 0xde, 0xe7, 0x52, 0xbd, 0x88, 0x62, 0xed,\n 0xe0, 0xe3, 0x86, 0x8e, 0xe2, 0xa2, 0x0f, 0x5d, 0xc8, 0xdb, 0x03, 0x1a,\n 0x5f, 0x57, 0xd7, 0x5e, 0x4a, 0x78, 0x1a, 0x63, 0x6f, 0x6d, 0x2e, 0x67,\n 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74,\n 0x2e, 0x69, 0x64, 0x63, 0x61, 0x72, 0x64, 0x2e, 0x31, 0xa1, 0x19, 0x32,\n 0xab, 0x58, 0x20, 0xbb, 0x51, 0x2c, 0x61, 0x32, 0xd0, 0x3a, 0x2f, 0x13,\n 0xb7, 0x6a, 0x84, 0x37, 0x55, 0x82, 0xe7, 0x1d, 0xfa, 0x49, 0x76, 0x89,\n 0x81, 0xfa, 0xba, 0xf5, 0x3f, 0x84, 0x34, 0x01, 0x6b, 0x5e, 0x7b, 0x6d,\n 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79, 0x49, 0x6e, 0x66,\n 0x6f, 0xa1, 0x69, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79,\n 0xa4, 0x01, 0x02, 0x20, 0x01, 0x21, 0x58, 0x20, 0x84, 0x59, 0x27, 0x1c,\n 0xa2, 0x99, 0x4e, 0x77, 0x51, 0x7b, 0x74, 0x3f, 0x76, 0xfd, 0xbb, 0x81,\n 0x79, 0xad, 0xf1, 0x31, 0x31, 0xbb, 0x48, 0x7e, 0x93, 0x9b, 0xd1, 0x7b,\n 0xc7, 0xe8, 0xf5, 0x43, 0x22, 0x58, 0x20, 0x69, 0x0b, 0x7b, 0xf6, 0x3f,\n 0x8d, 0x14, 0x69, 0x5b, 0xc5, 0xd5, 0xcb, 0x4a, 0x82, 0x23, 0xfb, 0x7b,\n 0xee, 0x6d, 0xdd, 0x08, 0x7d, 0x9e, 0x3f, 0x06, 0xfc, 0x16, 0xff, 0xe8,\n 0x84, 0xce, 0x83, 0x67, 0x64, 0x6f, 0x63, 0x54, 0x79, 0x70, 0x65, 0x78,\n 0x1a, 0x63, 0x6f, 0x6d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,\n 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x2e, 0x69, 0x64, 0x63, 0x61, 0x72,\n 0x64, 0x2e, 0x31, 0x6c, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x69, 0x74, 0x79,\n 0x49, 0x6e, 0x66, 0x6f, 0xa3, 0x66, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64,\n 0xc0, 0x74, 0x32, 0x30, 0x32, 0x35, 0x2d, 0x30, 0x31, 0x2d, 0x32, 0x39,\n 0x54, 0x31, 0x34, 0x3a, 0x33, 0x39, 0x3a, 0x32, 0x38, 0x5a, 0x69, 0x76,\n 0x61, 0x6c, 0x69, 0x64, 0x46, 0x72, 0x6f, 0x6d, 0xc0, 0x74, 0x32, 0x30,\n 0x32, 0x35, 0x2d, 0x30, 0x31, 0x2d, 0x32, 0x39, 0x54, 0x31, 0x34, 0x3a,\n 0x33, 0x39, 0x3a, 0x32, 0x38, 0x5a, 0x6a, 0x76, 0x61, 0x6c, 0x69, 0x64,\n 0x55, 0x6e, 0x74, 0x69, 0x6c, 0xc0, 0x74, 0x32, 0x30, 0x32, 0x35, 0x2d,\n 0x30, 0x32, 0x2d, 0x31, 0x32, 0x54, 0x31, 0x34, 0x3a, 0x33, 0x39, 0x3a,\n 0x32, 0x38, 0x5a, 0x58, 0x40, 0x12, 0xb3, 0x7a, 0x55, 0xcb, 0xdc, 0xda,\n 0x03, 0xa0, 0x6e, 0xa0, 0x60, 0xd2, 0x44, 0xab, 0x5b, 0x1a, 0x10, 0xe4,\n 0x29, 0x50, 0xed, 0x84, 0xdf, 0x9e, 0xce, 0xf7, 0xbf, 0xb0, 0x0d, 0xb0,\n 0xfb, 0xa8, 0x4e, 0xa3, 0x86, 0x43, 0x22, 0x8c, 0xa2, 0x91, 0x4e, 0x25,\n 0x1f, 0x5d, 0x37, 0x65, 0xf2, 0x1e, 0x45, 0x33, 0x0e, 0xe7, 0x2b, 0xd8,\n 0x05, 0x28, 0x99, 0x76, 0xb7, 0xa6, 0x1b, 0x3f, 0x52, 0x6c, 0x64, 0x65,\n 0x76, 0x69, 0x63, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xa2, 0x6a,\n 0x6e, 0x61, 0x6d, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x73, 0xd8, 0x18,\n 0x41, 0xa0, 0x6a, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x41, 0x75, 0x74,\n 0x68, 0xa1, 0x6f, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x53, 0x69, 0x67,\n 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x84, 0x43, 0xa1, 0x01, 0x26, 0xa0,\n 0xf6, 0x58, 0x40, 0x3f, 0xae, 0x1b, 0xb1, 0x4c, 0x0f, 0x22, 0xb3, 0x73,\n 0x26, 0xf4, 0x4d, 0x61, 0x2f, 0x59, 0x94, 0x35, 0x39, 0xa6, 0x0b, 0xe8,\n 0xd4, 0xa6, 0x8f, 0x0b, 0x0a, 0x66, 0x19, 0xea, 0x3a, 0xbf, 0x56, 0xdb,\n 0xc3, 0xe2, 0xeb, 0x1e, 0xcd, 0xa8, 0x65, 0x2f, 0x62, 0xc5, 0xd4, 0x44,\n 0x3f, 0x2c, 0x1b, 0xde, 0x9a, 0xd5, 0xd9, 0x2c, 0xaf, 0x16, 0xbc, 0xdf,\n 0x0e, 0x7c, 0x40, 0xd8, 0x5b, 0xf5, 0xf3, 0x66, 0x73, 0x74, 0x61, 0x74,\n 0x75, 0x73, 0x00}},\n // Mdoc example from website explainer.\n {StaticString(\n \"0xb4682ec20e06e8df840b5dd32959798ab20c544d4da50109ff4684d06fd261fc\"),\n StaticString(\n \"0xf6f8e9a811911329a5f653fcec5990092c91a65bc1695d291cd51de9c94e7db7\"),\n {0x83, 0xF6, 0xF6, 0x84, 0x71, 0x42, 0x72, 0x6F, 0x77, 0x73, 0x65, 0x72,\n 0x48, 0x61, 0x6E, 0x64, 0x6F, 0x76, 0x65, 0x72, 0x76, 0x31, 0x58, 0x20,\n 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,\n 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,\n 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x58, 0x35, 0xA3, 0x63,\n 0x63, 0x61, 0x74, 0x01, 0x64, 0x74, 0x79, 0x70, 0x65, 0x01, 0x67, 0x64,\n 0x65, 0x74, 0x61, 0x69, 0x6C, 0x73, 0xA1, 0x67, 0x62, 0x61, 0x73, 0x65,\n 0x55, 0x72, 0x6C, 0x77, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x72,\n 0x65, 0x6C, 0x79, 0x69, 0x6E, 0x67, 0x70, 0x61, 0x72, 0x74, 0x79, 0x2E,\n 0x63, 0x6F, 0x6D, 0x58, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,\n 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33,\n 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,\n 0x40},\n 145,\n (uint8_t *)\"2025-04-30T00:00:00Z\",\n kMDL,\n 1298,\n {0xa3, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e,\n 0x30, 0x69, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x81,\n 0xa3, 0x67, 0x64, 0x6f, 0x63, 0x54, 0x79, 0x70, 0x65, 0x75, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x2e, 0x6d, 0x44, 0x4c, 0x6c, 0x69, 0x73, 0x73, 0x75,\n 0x65, 0x72, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xa2, 0x6a, 0x6e, 0x61,\n 0x6d, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x73, 0xa1, 0x71, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x82, 0xd8, 0x18, 0x58, 0x60, 0xa4, 0x68, 0x64, 0x69,\n 0x67, 0x65, 0x73, 0x74, 0x49, 0x44, 0x00, 0x66, 0x72, 0x61, 0x6e, 0x64,\n 0x6f, 0x6d, 0x58, 0x20, 0x22, 0x31, 0x18, 0x3c, 0x7d, 0x9f, 0x4d, 0x2e,\n 0x2e, 0x14, 0x6d, 0x24, 0x84, 0x58, 0xb4, 0xcc, 0xe9, 0x48, 0x79, 0x8f,\n 0xda, 0x82, 0x40, 0xd3, 0x60, 0xa8, 0xf4, 0x0f, 0x6d, 0x75, 0x48, 0xd3,\n 0x71, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e,\n 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x6b, 0x61, 0x67, 0x65, 0x5f, 0x6f,\n 0x76, 0x65, 0x72, 0x5f, 0x31, 0x38, 0x6c, 0x65, 0x6c, 0x65, 0x6d, 0x65,\n 0x6e, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0xf5, 0xd8, 0x18, 0x58, 0x5f,\n 0xa4, 0x68, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74, 0x49, 0x44, 0x01, 0x66,\n 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x58, 0x20, 0xcd, 0x6b, 0x77, 0x63,\n 0x8d, 0x8f, 0x26, 0x18, 0xb7, 0x2f, 0x90, 0x25, 0xb8, 0x8c, 0x3d, 0x63,\n 0x2a, 0xbb, 0xa8, 0xde, 0x96, 0xe3, 0x93, 0x2d, 0xa3, 0x56, 0x6e, 0x49,\n 0x1f, 0x19, 0xcb, 0x91, 0x71, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74,\n 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x63, 0x6e,\n 0x79, 0x6d, 0x6c, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x56, 0x61,\n 0x6c, 0x75, 0x65, 0x67, 0x31, 0x32, 0x33, 0x31, 0x32, 0x34, 0x34, 0x6a,\n 0x69, 0x73, 0x73, 0x75, 0x65, 0x72, 0x41, 0x75, 0x74, 0x68, 0x84, 0x43,\n 0xa1, 0x01, 0x26, 0xa1, 0x18, 0x21, 0x59, 0x01, 0x83, 0x30, 0x82, 0x01,\n 0x7f, 0x30, 0x82, 0x01, 0x26, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01,\n 0x01, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03,\n 0x02, 0x30, 0x29, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a,\n 0x13, 0x08, 0x61, 0x62, 0x68, 0x76, 0x69, 0x6f, 0x75, 0x73, 0x31, 0x14,\n 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x0b, 0x54, 0x65, 0x73,\n 0x74, 0x69, 0x6e, 0x67, 0x20, 0x6b, 0x65, 0x79, 0x30, 0x1e, 0x17, 0x0d,\n 0x32, 0x35, 0x30, 0x34, 0x32, 0x38, 0x32, 0x31, 0x31, 0x30, 0x31, 0x34,\n 0x5a, 0x17, 0x0d, 0x32, 0x35, 0x30, 0x35, 0x30, 0x35, 0x32, 0x31, 0x31,\n 0x30, 0x31, 0x34, 0x5a, 0x30, 0x29, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03,\n 0x55, 0x04, 0x0a, 0x13, 0x08, 0x61, 0x62, 0x68, 0x76, 0x69, 0x6f, 0x75,\n 0x73, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x0b,\n 0x54, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x6b, 0x65, 0x79, 0x30,\n 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01,\n 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42,\n 0x00, 0x04, 0xb4, 0x68, 0x2e, 0xc2, 0x0e, 0x06, 0xe8, 0xdf, 0x84, 0x0b,\n 0x5d, 0xd3, 0x29, 0x59, 0x79, 0x8a, 0xb2, 0x0c, 0x54, 0x4d, 0x4d, 0xa5,\n 0x01, 0x09, 0xff, 0x46, 0x84, 0xd0, 0x6f, 0xd2, 0x61, 0xfc, 0xf6, 0xf8,\n 0xe9, 0xa8, 0x11, 0x91, 0x13, 0x29, 0xa5, 0xf6, 0x53, 0xfc, 0xec, 0x59,\n 0x90, 0x09, 0x2c, 0x91, 0xa6, 0x5b, 0xc1, 0x69, 0x5d, 0x29, 0x1c, 0xd5,\n 0x1d, 0xe9, 0xc9, 0x4e, 0x7d, 0xb7, 0xa3, 0x3f, 0x30, 0x3d, 0x30, 0x0e,\n 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02,\n 0x05, 0xa0, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x16, 0x30,\n 0x14, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x06,\n 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02, 0x30, 0x0c, 0x06,\n 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x02, 0x30, 0x00, 0x30,\n 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03,\n 0x47, 0x00, 0x30, 0x44, 0x02, 0x20, 0x31, 0x0f, 0x9a, 0xc7, 0x56, 0xcf,\n 0xfa, 0x49, 0x3d, 0x2f, 0x75, 0x77, 0xab, 0x38, 0x0e, 0x9d, 0x4d, 0xa6,\n 0x91, 0xeb, 0x5a, 0x8f, 0x19, 0xeb, 0xb2, 0xd9, 0x39, 0xa1, 0x67, 0x49,\n 0x1f, 0xbe, 0x02, 0x20, 0x4c, 0x7d, 0xac, 0xde, 0x12, 0xf6, 0x98, 0xb1,\n 0xf9, 0x6e, 0xa1, 0xc9, 0xbc, 0xa1, 0x3e, 0xd7, 0x9c, 0xd5, 0x67, 0xf4,\n 0x04, 0x47, 0x3d, 0xa0, 0x66, 0x05, 0xa8, 0xf1, 0x49, 0xef, 0x67, 0x01,\n 0x59, 0x01, 0x7f, 0xd8, 0x18, 0x59, 0x01, 0x7a, 0xa6, 0x67, 0x76, 0x65,\n 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e, 0x30, 0x6f, 0x64, 0x69,\n 0x67, 0x65, 0x73, 0x74, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68,\n 0x6d, 0x67, 0x53, 0x48, 0x41, 0x2d, 0x32, 0x35, 0x36, 0x67, 0x64, 0x6f,\n 0x63, 0x54, 0x79, 0x70, 0x65, 0x75, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73,\n 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0x2e,\n 0x6d, 0x44, 0x4c, 0x6c, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x44, 0x69, 0x67,\n 0x65, 0x73, 0x74, 0x73, 0xa1, 0x71, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73,\n 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0xa2,\n 0x00, 0x58, 0x20, 0xff, 0x75, 0x3b, 0xf6, 0xc1, 0x19, 0x63, 0xfd, 0x64,\n 0x4c, 0xcc, 0xe4, 0x35, 0x56, 0xcd, 0xe1, 0x85, 0x7a, 0xcd, 0xfd, 0x8e,\n 0x7e, 0x60, 0x7c, 0x01, 0xdf, 0xf5, 0xdc, 0x3e, 0x1a, 0xfb, 0xfc, 0x01,\n 0x58, 0x20, 0xc5, 0x70, 0x2c, 0x25, 0x26, 0x38, 0xa4, 0xd0, 0xe9, 0x77,\n 0x44, 0xcd, 0x38, 0x4f, 0x0c, 0x04, 0x26, 0x07, 0x94, 0x84, 0xbe, 0xa1,\n 0xa2, 0xc9, 0x4b, 0xe5, 0x8f, 0xb5, 0xe8, 0xc2, 0x28, 0x61, 0x6d, 0x64,\n 0x65, 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79, 0x49, 0x6e, 0x66, 0x6f,\n 0xa1, 0x69, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79, 0xa4,\n 0x01, 0x02, 0x20, 0x01, 0x21, 0x58, 0x20, 0x02, 0x7a, 0x5a, 0x1f, 0xa9,\n 0x15, 0x1f, 0x67, 0xcd, 0xd2, 0xc5, 0x7f, 0xaf, 0x84, 0xcc, 0xfd, 0xb0,\n 0x5b, 0xcf, 0x59, 0x07, 0x87, 0x65, 0xfa, 0x0b, 0x7e, 0x1a, 0x82, 0x23,\n 0x79, 0x0d, 0xd2, 0x22, 0x58, 0x20, 0x3e, 0x17, 0x08, 0x11, 0xbe, 0xcf,\n 0x18, 0x4d, 0x36, 0xba, 0x38, 0xdb, 0xc2, 0x29, 0x21, 0x7d, 0x4f, 0xac,\n 0xa0, 0xf1, 0x62, 0xd5, 0x54, 0xe5, 0xf1, 0x40, 0x8d, 0x59, 0xc4, 0xba,\n 0xaa, 0x0b, 0x6c, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x69, 0x74, 0x79, 0x49,\n 0x6e, 0x66, 0x6f, 0xa3, 0x66, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xc0,\n 0x74, 0x32, 0x30, 0x32, 0x35, 0x2d, 0x30, 0x34, 0x2d, 0x32, 0x38, 0x54,\n 0x32, 0x31, 0x3a, 0x30, 0x30, 0x3a, 0x30, 0x30, 0x5a, 0x69, 0x76, 0x61,\n 0x6c, 0x69, 0x64, 0x46, 0x72, 0x6f, 0x6d, 0xc0, 0x74, 0x32, 0x30, 0x32,\n 0x35, 0x2d, 0x30, 0x34, 0x2d, 0x32, 0x38, 0x54, 0x32, 0x31, 0x3a, 0x30,\n 0x30, 0x3a, 0x30, 0x30, 0x5a, 0x6a, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x55,\n 0x6e, 0x74, 0x69, 0x6c, 0xc0, 0x74, 0x32, 0x30, 0x32, 0x36, 0x2d, 0x30,\n 0x34, 0x2d, 0x32, 0x38, 0x54, 0x32, 0x31, 0x3a, 0x30, 0x30, 0x3a, 0x30,\n 0x30, 0x5a, 0x58, 0x40, 0x29, 0x22, 0x9f, 0xa5, 0xda, 0x13, 0x7c, 0x73,\n 0xfa, 0xe1, 0xe5, 0xcb, 0x87, 0x5b, 0xa0, 0xd2, 0x21, 0x3d, 0x0d, 0xbe,\n 0xdc, 0x9d, 0x08, 0x96, 0xa7, 0x45, 0x99, 0x08, 0x83, 0x72, 0xd8, 0x98,\n 0x83, 0x45, 0x05, 0xb8, 0x6d, 0x3a, 0xde, 0x7e, 0xad, 0x4f, 0xc9, 0x3a,\n 0xa2, 0x8c, 0xd5, 0xc4, 0xf3, 0xff, 0x2d, 0xd4, 0x89, 0xfe, 0x89, 0x9a,\n 0x71, 0xe7, 0x21, 0x13, 0xae, 0x74, 0xfa, 0x8f, 0x6c, 0x64, 0x65, 0x76,\n 0x69, 0x63, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xa2, 0x6a, 0x6e,\n 0x61, 0x6d, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x73, 0xd8, 0x18, 0x41,\n 0xa0, 0x6a, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x41, 0x75, 0x74, 0x68,\n 0xa1, 0x6f, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x53, 0x69, 0x67, 0x6e,\n 0x61, 0x74, 0x75, 0x72, 0x65, 0x84, 0x43, 0xa1, 0x01, 0x26, 0xa0, 0xf6,\n 0x58, 0x40, 0x52, 0x0b, 0x17, 0xb8, 0xbd, 0x7e, 0xae, 0x5d, 0x4e, 0x7d,\n 0xcd, 0xb8, 0x8c, 0xdd, 0xb2, 0x4e, 0x7b, 0x2b, 0xf6, 0x5a, 0xfe, 0x42,\n 0x0a, 0x1c, 0x48, 0x81, 0x2d, 0x97, 0x65, 0x78, 0x42, 0xba, 0xb5, 0x05,\n 0x74, 0xf5, 0xc8, 0x29, 0xc3, 0x2f, 0xa6, 0xd7, 0xa2, 0x28, 0xdb, 0x96,\n 0x64, 0xdc, 0x75, 0x4e, 0x2f, 0x6c, 0x90, 0x1c, 0x7b, 0x9a, 0x97, 0x49,\n 0x59, 0xfc, 0x9b, 0x35, 0xcb, 0x4c, 0x66, 0x73, 0x74, 0x61, 0x74, 0x75,\n 0x73, 0x00}},\n // Large mDoc from Canonical Playground June 2025\n {StaticString(\n \"0xab4bb1a19d6bc9d61138cf43a004ba5156ae4f3080804c910cf638eacf3b4e00\"),\n StaticString(\n \"0x216a667060dae40ecca6fb4b39f1c93e1098ac64667b6e5bbf0140518672cb7b\"),\n {0x83, 0xf6, 0xf6, 0x82, 0x76, 0x4f, 0x70, 0x65, 0x6e,\n 0x49, 0x44, 0x34, 0x56, 0x50, 0x44, 0x43, 0x41, 0x50,\n 0x49, 0x48, 0x61, 0x6e, 0x64, 0x6f, 0x76, 0x65, 0x72,\n 0x58, 0x20, 0x6c, 0xd6, 0x05, 0x23, 0x72, 0x0c, 0x76,\n 0x4a, 0xda, 0x4b, 0xa1, 0x07, 0xe6, 0x4c, 0xcf, 0x2b,\n 0xb4, 0xc8, 0x1d, 0x21, 0xa9, 0xc3, 0x02, 0x0c, 0x52,\n 0xbf, 0x5c, 0x89, 0x40, 0x7d, 0x98, 0xee},\n 61,\n (uint8_t *)\"2025-06-10T23:59:59Z\",\n kMDL,\n 3321,\n { 0xa3, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e,\n 0x30, 0x69, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x81,\n 0xa3, 0x67, 0x64, 0x6f, 0x63, 0x54, 0x79, 0x70, 0x65, 0x75, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x2e, 0x6d, 0x44, 0x4c, 0x6c, 0x69, 0x73, 0x73, 0x75,\n 0x65, 0x72, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xa2, 0x6a, 0x6e, 0x61,\n 0x6d, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x73, 0xa1, 0x71, 0x6f, 0x72,\n 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,\n 0x35, 0x2e, 0x31, 0x81, 0xd8, 0x18, 0x58, 0x51, 0xa4, 0x68, 0x64, 0x69,\n 0x67, 0x65, 0x73, 0x74, 0x49, 0x44, 0x19, 0x36, 0xf7, 0x66, 0x72, 0x61,\n 0x6e, 0x64, 0x6f, 0x6d, 0x50, 0x84, 0x83, 0x3b, 0x67, 0x34, 0x97, 0x7a,\n 0x63, 0x0b, 0xd7, 0xf7, 0xd4, 0xd8, 0xca, 0xd3, 0xe9, 0x71, 0x65, 0x6c,\n 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66,\n 0x69, 0x65, 0x72, 0x6b, 0x61, 0x67, 0x65, 0x5f, 0x6f, 0x76, 0x65, 0x72,\n 0x5f, 0x31, 0x38, 0x6c, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x56,\n 0x61, 0x6c, 0x75, 0x65, 0xf4, 0x6a, 0x69, 0x73, 0x73, 0x75, 0x65, 0x72,\n 0x41, 0x75, 0x74, 0x68, 0x84, 0x43, 0xa1, 0x01, 0x26, 0xa1, 0x18, 0x21,\n 0x59, 0x02, 0xce, 0x30, 0x82, 0x02, 0xca, 0x30, 0x82, 0x02, 0x2b, 0xa0,\n 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00, 0xd7, 0x05, 0x20, 0x76, 0xb8,\n 0x88, 0xe1, 0x1a, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,\n 0x04, 0x03, 0x04, 0x30, 0x37, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,\n 0x04, 0x06, 0x13, 0x02, 0x5a, 0x5a, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03,\n 0x55, 0x04, 0x0a, 0x0c, 0x06, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x31,\n 0x17, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0e, 0x50, 0x61,\n 0x79, 0x67, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x20, 0x52, 0x6f, 0x6f, 0x74,\n 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x35, 0x30, 0x35, 0x30, 0x37, 0x30, 0x35,\n 0x33, 0x34, 0x31, 0x30, 0x5a, 0x17, 0x0d, 0x32, 0x36, 0x30, 0x35, 0x30,\n 0x37, 0x30, 0x35, 0x33, 0x34, 0x31, 0x30, 0x5a, 0x30, 0x42, 0x31, 0x0b,\n 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x5a, 0x5a, 0x31,\n 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x06, 0x47, 0x6f,\n 0x6f, 0x67, 0x6c, 0x65, 0x31, 0x22, 0x30, 0x20, 0x06, 0x03, 0x55, 0x04,\n 0x03, 0x0c, 0x19, 0x50, 0x61, 0x79, 0x67, 0x72, 0x6f, 0x75, 0x6e, 0x64,\n 0x20, 0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x53, 0x69,\n 0x67, 0x6e, 0x65, 0x72, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86,\n 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,\n 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0xab, 0x4b, 0xb1, 0xa1, 0x9d,\n 0x6b, 0xc9, 0xd6, 0x11, 0x38, 0xcf, 0x43, 0xa0, 0x04, 0xba, 0x51, 0x56,\n 0xae, 0x4f, 0x30, 0x80, 0x80, 0x4c, 0x91, 0x0c, 0xf6, 0x38, 0xea, 0xcf,\n 0x3b, 0x4e, 0x00, 0x21, 0x6a, 0x66, 0x70, 0x60, 0xda, 0xe4, 0x0e, 0xcc,\n 0xa6, 0xfb, 0x4b, 0x39, 0xf1, 0xc9, 0x3e, 0x10, 0x98, 0xac, 0x64, 0x66,\n 0x7b, 0x6e, 0x5b, 0xbf, 0x01, 0x40, 0x51, 0x86, 0x72, 0xcb, 0x7b, 0xa3,\n 0x82, 0x01, 0x13, 0x30, 0x82, 0x01, 0x0f, 0x30, 0x1d, 0x06, 0x03, 0x55,\n 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x36, 0x86, 0x68, 0x1a, 0x2b, 0x1a,\n 0x9c, 0xc3, 0xc5, 0x50, 0x2d, 0xe4, 0x60, 0x1d, 0x44, 0xab, 0x83, 0x81,\n 0x89, 0x27, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30,\n 0x16, 0x80, 0x14, 0x73, 0xa7, 0x04, 0x1e, 0x50, 0x81, 0x93, 0x9e, 0xe0,\n 0xdb, 0xb7, 0x02, 0x8a, 0xe3, 0x71, 0x2f, 0xd0, 0xaa, 0x36, 0xc1, 0x30,\n 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03,\n 0x02, 0x07, 0x80, 0x30, 0x21, 0x06, 0x03, 0x55, 0x1d, 0x12, 0x04, 0x1a,\n 0x30, 0x18, 0x86, 0x16, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f,\n 0x77, 0x77, 0x77, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63,\n 0x6f, 0x6d, 0x30, 0x15, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x01, 0x01, 0xff,\n 0x04, 0x0b, 0x30, 0x09, 0x06, 0x07, 0x28, 0x81, 0x8c, 0x5d, 0x05, 0x01,\n 0x02, 0x30, 0x81, 0x82, 0x06, 0x03, 0x55, 0x1d, 0x1f, 0x04, 0x7b, 0x30,\n 0x79, 0x30, 0x77, 0xa0, 0x75, 0xa0, 0x73, 0x86, 0x71, 0x68, 0x74, 0x74,\n 0x70, 0x3a, 0x2f, 0x2f, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x63,\n 0x61, 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x36, 0x36,\n 0x30, 0x33, 0x63, 0x36, 0x34, 0x37, 0x2d, 0x30, 0x30, 0x30, 0x30, 0x2d,\n 0x32, 0x39, 0x64, 0x34, 0x2d, 0x61, 0x65, 0x61, 0x36, 0x2d, 0x66, 0x34,\n 0x66, 0x35, 0x65, 0x38, 0x30, 0x64, 0x31, 0x62, 0x39, 0x30, 0x2e, 0x73,\n 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c,\n 0x65, 0x61, 0x70, 0x69, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x34, 0x31,\n 0x64, 0x34, 0x33, 0x36, 0x38, 0x35, 0x39, 0x65, 0x34, 0x35, 0x64, 0x62,\n 0x66, 0x33, 0x65, 0x35, 0x61, 0x39, 0x2f, 0x63, 0x72, 0x6c, 0x2e, 0x63,\n 0x72, 0x6c, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04,\n 0x03, 0x04, 0x03, 0x81, 0x8c, 0x00, 0x30, 0x81, 0x88, 0x02, 0x42, 0x00,\n 0xab, 0x5b, 0x98, 0x44, 0x72, 0xb7, 0x1a, 0x25, 0x5d, 0xe8, 0x60, 0xff,\n 0x9b, 0x99, 0x52, 0x8c, 0x73, 0xa9, 0xb1, 0x29, 0x7e, 0x87, 0x36, 0x57,\n 0x9c, 0xb8, 0x18, 0xf6, 0x6a, 0x82, 0x5a, 0xd7, 0x0f, 0x39, 0xdd, 0x3c,\n 0x18, 0x11, 0x3c, 0xf8, 0x04, 0x90, 0x5d, 0x9b, 0xa9, 0x4a, 0x03, 0xe3,\n 0xfe, 0x5a, 0x9e, 0x22, 0x8f, 0x1b, 0x10, 0x1d, 0xd0, 0x86, 0x55, 0x96,\n 0xe5, 0x81, 0x9c, 0xe7, 0x74, 0x02, 0x42, 0x01, 0xd0, 0x1e, 0x5d, 0x2f,\n 0xc1, 0x4d, 0xb2, 0x0e, 0x4b, 0xc2, 0x0e, 0x8b, 0xaf, 0xe6, 0x1e, 0xc2,\n 0x29, 0x64, 0x71, 0x31, 0xaf, 0xc1, 0xe3, 0xbb, 0xdb, 0x16, 0xd1, 0x8c,\n 0x43, 0x97, 0x72, 0x11, 0xbb, 0x8f, 0xda, 0xc6, 0x6c, 0x05, 0xd1, 0x3b,\n 0x76, 0xd4, 0x5b, 0x80, 0x7a, 0x20, 0x99, 0x07, 0x2b, 0x7d, 0x97, 0x86,\n 0xec, 0x19, 0xcd, 0x8f, 0x4e, 0xd4, 0x85, 0x16, 0x76, 0xcf, 0x99, 0xb9,\n 0xa3, 0x59, 0x08, 0x8d, 0xd8, 0x18, 0x59, 0x08, 0x88, 0xa6, 0x67, 0x76,\n 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e, 0x30, 0x6f, 0x64,\n 0x69, 0x67, 0x65, 0x73, 0x74, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74,\n 0x68, 0x6d, 0x67, 0x53, 0x48, 0x41, 0x2d, 0x32, 0x35, 0x36, 0x6c, 0x76,\n 0x61, 0x6c, 0x75, 0x65, 0x44, 0x69, 0x67, 0x65, 0x73, 0x74, 0x73, 0xa2,\n 0x71, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30,\n 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0xb8, 0x2b, 0x19, 0x03, 0x65, 0x58,\n 0x20, 0x54, 0xe2, 0xe0, 0x57, 0xf8, 0xd7, 0x41, 0x2f, 0xb9, 0x67, 0xe7,\n 0x38, 0x31, 0xb1, 0xbd, 0x43, 0x9b, 0xf7, 0x61, 0x4f, 0xe3, 0x0b, 0x13,\n 0xa5, 0xf5, 0xd5, 0x9d, 0x21, 0xfd, 0x8a, 0xfc, 0x0f, 0x19, 0x06, 0x4a,\n 0x58, 0x20, 0x77, 0x11, 0x08, 0x33, 0x52, 0xf0, 0x6a, 0x9e, 0x71, 0x87,\n 0x90, 0xb7, 0xa4, 0x2f, 0x2f, 0x88, 0xe2, 0xae, 0xee, 0xf5, 0x1e, 0x51,\n 0x4f, 0xe0, 0x27, 0xde, 0x73, 0xdc, 0x60, 0x80, 0x28, 0x13, 0x19, 0x07,\n 0x08, 0x58, 0x20, 0x30, 0x97, 0x45, 0x71, 0x69, 0x0f, 0x39, 0x25, 0xb5,\n 0x1f, 0xa4, 0xab, 0x60, 0x2b, 0xf3, 0xcc, 0xc4, 0x44, 0x0f, 0x21, 0xd3,\n 0x24, 0xe2, 0x08, 0x14, 0xea, 0xd5, 0x7a, 0xe5, 0xfb, 0x3e, 0x56, 0x19,\n 0x08, 0x01, 0x58, 0x20, 0x73, 0x6a, 0x04, 0xe2, 0x35, 0x20, 0x20, 0x17,\n 0xa0, 0xa1, 0x65, 0xd9, 0xd1, 0x1c, 0x0c, 0x5a, 0x74, 0xcf, 0xad, 0x39,\n 0xdf, 0x94, 0x08, 0x5a, 0xb0, 0x95, 0x55, 0xc3, 0xd3, 0xfe, 0xfc, 0x4f,\n 0x19, 0x13, 0x95, 0x58, 0x20, 0xe2, 0x36, 0x1c, 0x51, 0x0a, 0xd1, 0x29,\n 0x42, 0xab, 0x1e, 0x5e, 0x84, 0xc4, 0x06, 0xd2, 0x4c, 0xc1, 0x7c, 0x44,\n 0xaa, 0x6f, 0x79, 0x91, 0x85, 0x61, 0xf9, 0xda, 0x3e, 0xe5, 0x86, 0x80,\n 0xcb, 0x19, 0x19, 0x42, 0x58, 0x20, 0x2b, 0x86, 0xfb, 0x8a, 0xd1, 0x65,\n 0xce, 0x24, 0xf6, 0xb4, 0x28, 0x81, 0x91, 0x58, 0x76, 0x82, 0x19, 0x18,\n 0x7a, 0x1f, 0x2a, 0x92, 0xd6, 0x5f, 0xe9, 0x42, 0x54, 0x6c, 0xae, 0xf7,\n 0xe2, 0x90, 0x19, 0x24, 0x07, 0x58, 0x20, 0x97, 0x1a, 0xf5, 0x99, 0x97,\n 0x59, 0x0e, 0x21, 0x54, 0xcb, 0x12, 0x32, 0xf2, 0x6d, 0x25, 0x4d, 0xcb,\n 0xba, 0x57, 0x47, 0x2d, 0x17, 0x1d, 0xbb, 0x53, 0xa8, 0x24, 0x73, 0x69,\n 0x46, 0x11, 0xb2, 0x19, 0x25, 0x90, 0x58, 0x20, 0x74, 0x31, 0xb9, 0xa8,\n 0xe4, 0x9e, 0xa1, 0xf7, 0x7b, 0x6a, 0xf3, 0x6a, 0x2c, 0x5b, 0xe5, 0x31,\n 0x97, 0x1e, 0x50, 0xc3, 0xd6, 0x80, 0xfd, 0x08, 0x0c, 0x33, 0xc0, 0x19,\n 0xba, 0xfa, 0x48, 0xa9, 0x19, 0x2c, 0x0d, 0x58, 0x20, 0x7c, 0x66, 0x45,\n 0x45, 0x17, 0x5e, 0xf0, 0x03, 0x70, 0xca, 0x47, 0x50, 0x8f, 0x6e, 0x19,\n 0x95, 0x8f, 0x63, 0x0f, 0x2b, 0xc2, 0x92, 0xdb, 0xb4, 0x33, 0xbf, 0x73,\n 0xe9, 0xec, 0xe9, 0xbb, 0xcc, 0x19, 0x2d, 0x97, 0x58, 0x20, 0x05, 0x53,\n 0x0d, 0x90, 0x53, 0x30, 0xf4, 0x0b, 0x71, 0x79, 0xb6, 0x51, 0x53, 0x03,\n 0x1a, 0x83, 0x01, 0xbe, 0xdd, 0x8a, 0x88, 0xc9, 0x21, 0x26, 0x77, 0xe3,\n 0xd9, 0x72, 0xba, 0x05, 0x16, 0x17, 0x19, 0x2e, 0xbd, 0x58, 0x20, 0xe6,\n 0x7f, 0x26, 0xac, 0x90, 0x32, 0x0a, 0xff, 0xd5, 0x1b, 0x87, 0x40, 0x58,\n 0xb3, 0x55, 0xcd, 0x7c, 0x06, 0x69, 0x9c, 0x96, 0x3a, 0xb4, 0xd7, 0x2d,\n 0xd7, 0xe9, 0x3d, 0x77, 0xea, 0xff, 0x3c, 0x19, 0x36, 0xe7, 0x58, 0x20,\n 0x22, 0x2a, 0x50, 0xb5, 0x67, 0x8e, 0x4e, 0x06, 0x6b, 0xd4, 0x70, 0xbf,\n 0xe9, 0x79, 0x91, 0x2e, 0x8a, 0xab, 0xd3, 0x1a, 0xa0, 0xc3, 0x95, 0x6c,\n 0x1e, 0x41, 0xae, 0x1a, 0xe5, 0xf2, 0xe1, 0x3c, 0x19, 0x36, 0xf7, 0x58,\n 0x20, 0x43, 0x9f, 0xfb, 0x14, 0x4b, 0x03, 0x08, 0xc4, 0x27, 0x23, 0xdb,\n 0x01, 0xf5, 0x42, 0xff, 0x8a, 0x32, 0xd9, 0xf5, 0x49, 0x5a, 0xb2, 0xb0,\n 0x7c, 0x10, 0x49, 0x20, 0xb1, 0x2a, 0xea, 0x57, 0xba, 0x19, 0x53, 0x7b,\n 0x58, 0x20, 0x9c, 0xf8, 0x0d, 0xe4, 0x88, 0x8b, 0x76, 0x96, 0xfc, 0x35,\n 0x9c, 0xb6, 0xa9, 0xa8, 0xf7, 0xa2, 0xe4, 0x18, 0xdd, 0xe5, 0xc9, 0xeb,\n 0x4f, 0x1d, 0x56, 0x42, 0x2a, 0xa4, 0x3f, 0xc6, 0x91, 0x74, 0x19, 0x53,\n 0xa0, 0x58, 0x20, 0x37, 0x43, 0x2d, 0xa3, 0xcc, 0x4f, 0x7d, 0x25, 0x20,\n 0xd7, 0x57, 0x96, 0xb3, 0x54, 0x9f, 0xc0, 0x45, 0x54, 0x81, 0xaa, 0x58,\n 0x01, 0xb0, 0xed, 0xc9, 0x51, 0xd5, 0x1a, 0xd6, 0x56, 0x58, 0x46, 0x19,\n 0x5d, 0xf2, 0x58, 0x20, 0xd7, 0xd2, 0x86, 0xd6, 0x55, 0xf1, 0x6c, 0xef,\n 0x3b, 0x2e, 0x8c, 0x22, 0xd1, 0x4c, 0xd9, 0xa3, 0x41, 0x26, 0x06, 0x58,\n 0x66, 0xd9, 0x78, 0x6f, 0x4c, 0x97, 0xe5, 0x1c, 0x8c, 0xf1, 0x7d, 0x5a,\n 0x19, 0x5f, 0x12, 0x58, 0x20, 0xec, 0xbf, 0x9b, 0xf5, 0x18, 0xd0, 0xa8,\n 0xc1, 0x73, 0xc6, 0x5b, 0x7f, 0x6a, 0x14, 0xe5, 0x6f, 0x9e, 0x9e, 0x48,\n 0x3e, 0x6c, 0x1a, 0xaa, 0x60, 0xd9, 0x30, 0xde, 0x57, 0xae, 0x5d, 0x80,\n 0x66, 0x19, 0x66, 0xb4, 0x58, 0x20, 0xe1, 0xd7, 0x8f, 0xc9, 0xae, 0xae,\n 0x63, 0x48, 0x0c, 0xc0, 0xd8, 0x94, 0x00, 0xa4, 0xc6, 0xe0, 0xd8, 0xb7,\n 0xc5, 0xdf, 0x79, 0xcb, 0x4d, 0x67, 0x11, 0xfb, 0xb3, 0xbe, 0x7a, 0xef,\n 0xd8, 0x45, 0x19, 0x67, 0x4e, 0x58, 0x20, 0x9c, 0x66, 0xa2, 0x1f, 0xdc,\n 0x13, 0xfa, 0x40, 0xf6, 0xf3, 0x82, 0xc3, 0x7f, 0x53, 0x7f, 0x1c, 0x52,\n 0x0b, 0xca, 0x4b, 0x09, 0x25, 0xfa, 0xdd, 0xda, 0x7b, 0x50, 0xc5, 0xb0,\n 0xd9, 0x60, 0xfd, 0x19, 0x6f, 0x91, 0x58, 0x20, 0xa0, 0x91, 0x53, 0xe0,\n 0x04, 0x9d, 0x18, 0x47, 0x14, 0xf8, 0x43, 0x79, 0x8c, 0x90, 0xde, 0x41,\n 0xd1, 0x46, 0x5b, 0x77, 0x2f, 0x63, 0x87, 0xf3, 0xeb, 0x0e, 0x70, 0x63,\n 0x81, 0xe4, 0x0a, 0x1d, 0x19, 0x71, 0x34, 0x58, 0x20, 0x31, 0xaf, 0xc9,\n 0x92, 0xfe, 0xc3, 0x09, 0x98, 0xb3, 0xe8, 0x18, 0xf1, 0x45, 0xe9, 0xdd,\n 0xdb, 0xf3, 0x27, 0x44, 0x4b, 0xc9, 0xaa, 0x25, 0x08, 0x2a, 0xe1, 0x85,\n 0xc4, 0xfb, 0x6f, 0x18, 0xd4, 0x19, 0x72, 0x3f, 0x58, 0x20, 0xf2, 0xa3,\n 0x12, 0xca, 0xdd, 0x1f, 0xf2, 0x21, 0xce, 0xdb, 0x5d, 0x86, 0x1d, 0x79,\n 0xa7, 0x0c, 0x88, 0x7b, 0xdc, 0x8c, 0xd7, 0x7e, 0x3f, 0xf6, 0x36, 0xa0,\n 0x12, 0xa9, 0xc1, 0x76, 0x82, 0x59, 0x19, 0x73, 0x28, 0x58, 0x20, 0xca,\n 0xc8, 0x13, 0x4b, 0x17, 0x19, 0xa7, 0x4e, 0xb4, 0x8c, 0x36, 0x9a, 0x65,\n 0x4d, 0xfc, 0x3a, 0x72, 0xca, 0x17, 0x3a, 0x55, 0xe0, 0x20, 0x30, 0x77,\n 0xd5, 0x81, 0x21, 0xb6, 0x00, 0x30, 0x41, 0x19, 0x77, 0x39, 0x58, 0x20,\n 0x44, 0x95, 0xaf, 0xb6, 0x80, 0x07, 0xab, 0xc3, 0x21, 0x66, 0xe9, 0xf2,\n 0xc8, 0xfa, 0xfb, 0xd8, 0x18, 0x04, 0xac, 0x9d, 0x48, 0xb2, 0xc6, 0xe6,\n 0x19, 0x0b, 0xb5, 0x2d, 0x94, 0x23, 0x8b, 0x07, 0x19, 0x7c, 0x2b, 0x58,\n 0x20, 0x17, 0x1c, 0xa0, 0x43, 0x36, 0x04, 0x23, 0x86, 0x65, 0x71, 0x14,\n 0x7e, 0xa2, 0x99, 0x8b, 0xa9, 0xff, 0x40, 0xde, 0xb9, 0x84, 0x84, 0x53,\n 0x1c, 0xf8, 0x6f, 0xc9, 0x79, 0x1d, 0x84, 0xcb, 0x28, 0x19, 0x93, 0x07,\n 0x58, 0x20, 0x3b, 0xd0, 0x95, 0x2e, 0xd7, 0x7a, 0x7d, 0x87, 0xe0, 0x3d,\n 0x52, 0x0c, 0x9c, 0x5e, 0xb3, 0x27, 0x84, 0x55, 0x62, 0x48, 0xb2, 0x2a,\n 0x47, 0x9c, 0xd9, 0x44, 0xcb, 0xb1, 0x64, 0x92, 0x00, 0x76, 0x19, 0x98,\n 0xfa, 0x58, 0x20, 0x6e, 0x26, 0x5f, 0x85, 0x05, 0x25, 0x18, 0xb9, 0xeb,\n 0xb7, 0x99, 0x32, 0x8a, 0x34, 0xcc, 0x66, 0x4a, 0xdb, 0x57, 0xef, 0x03,\n 0xa2, 0x16, 0x56, 0x78, 0x0d, 0x48, 0xde, 0xc0, 0x27, 0xa5, 0x9c, 0x19,\n 0x99, 0x44, 0x58, 0x20, 0x6c, 0xdd, 0xac, 0x1d, 0xd1, 0xad, 0x04, 0xbf,\n 0xef, 0x67, 0x17, 0x3e, 0x88, 0x0f, 0x59, 0xb8, 0xbd, 0x2c, 0x0f, 0xb7,\n 0x5a, 0xd8, 0xc5, 0xb1, 0x5c, 0xa7, 0x13, 0xd8, 0x04, 0x54, 0x2a, 0xce,\n 0x19, 0xa5, 0x87, 0x58, 0x20, 0xf0, 0xf8, 0x36, 0x0f, 0xef, 0xc5, 0x73,\n 0x98, 0xfc, 0xde, 0x1d, 0xa3, 0x49, 0x93, 0xc4, 0x95, 0x48, 0x28, 0xa9,\n 0xda, 0x86, 0x2f, 0x4f, 0xf8, 0xe1, 0xc7, 0xee, 0x8a, 0xbc, 0x4a, 0x62,\n 0xbc, 0x19, 0xab, 0xab, 0x58, 0x20, 0x09, 0xc2, 0x04, 0xc8, 0x6f, 0x93,\n 0xd0, 0x11, 0xa6, 0x61, 0x8c, 0x17, 0xbc, 0xb2, 0x29, 0xf5, 0x7d, 0x93,\n 0x0f, 0x41, 0x21, 0x7f, 0x2e, 0x8c, 0x27, 0xc6, 0xcb, 0xb8, 0xc1, 0x1d,\n 0xd6, 0xc0, 0x19, 0xb5, 0x76, 0x58, 0x20, 0xd8, 0x5f, 0x64, 0x48, 0x3d,\n 0x68, 0xe7, 0xbb, 0xca, 0x46, 0xf3, 0x69, 0x2b, 0x91, 0xb8, 0x96, 0xff,\n 0x9a, 0xb1, 0xe2, 0x32, 0xf3, 0x6b, 0x4e, 0xb8, 0x65, 0x76, 0x7e, 0x31,\n 0x9b, 0x3c, 0x31, 0x19, 0xba, 0xd5, 0x58, 0x20, 0x67, 0x16, 0x9a, 0x66,\n 0x8c, 0x34, 0xfa, 0xec, 0x6e, 0xbc, 0x4a, 0xbd, 0xdc, 0xce, 0xc6, 0x31,\n 0x30, 0x9d, 0x59, 0x1d, 0x86, 0xaa, 0xc3, 0x69, 0x74, 0x43, 0x26, 0xa0,\n 0x37, 0x71, 0xae, 0xd1, 0x19, 0xbb, 0x63, 0x58, 0x20, 0xe6, 0xf9, 0xc6,\n 0x68, 0x49, 0xda, 0xc8, 0xd5, 0x79, 0x9f, 0x3d, 0x7c, 0x98, 0xaa, 0xc0,\n 0x8f, 0x28, 0xe6, 0x83, 0x6a, 0x47, 0x5b, 0x2e, 0xc0, 0x2a, 0x91, 0x2b,\n 0x0f, 0x1a, 0x4c, 0x04, 0x27, 0x19, 0xbc, 0xc5, 0x58, 0x20, 0xe2, 0xff,\n 0x42, 0x08, 0x69, 0xff, 0x52, 0x39, 0x19, 0x00, 0x4f, 0x95, 0x45, 0x0f,\n 0x80, 0x32, 0x0f, 0x1b, 0x11, 0xbd, 0x9e, 0x39, 0x80, 0xa3, 0x86, 0xbf,\n 0xd5, 0xc8, 0x5b, 0xc7, 0x86, 0x65, 0x19, 0xc0, 0x19, 0x58, 0x20, 0x5d,\n 0x77, 0x76, 0x84, 0x99, 0x59, 0x1b, 0x05, 0x9f, 0xad, 0x15, 0xc8, 0xb7,\n 0x3e, 0x77, 0x96, 0x98, 0x85, 0x4e, 0x7e, 0xe9, 0x02, 0x0c, 0x37, 0xa4,\n 0xd7, 0xee, 0x84, 0x9b, 0xb8, 0xca, 0x3b, 0x19, 0xc0, 0x8c, 0x58, 0x20,\n 0xf0, 0x5f, 0xd5, 0xc0, 0x4e, 0xfa, 0x49, 0x4c, 0x7d, 0xd1, 0xa9, 0xb5,\n 0x5b, 0x7e, 0xdc, 0xd8, 0xee, 0xd7, 0x7a, 0x22, 0x8f, 0x32, 0x17, 0x05,\n 0x41, 0xcf, 0x95, 0x82, 0x11, 0xb2, 0x36, 0x81, 0x19, 0xc5, 0xf1, 0x58,\n 0x20, 0x0b, 0x4b, 0x67, 0xdf, 0xf8, 0x16, 0xad, 0x56, 0x46, 0xab, 0xc3,\n 0x80, 0x74, 0x02, 0x20, 0x85, 0xd2, 0x1d, 0xde, 0xb3, 0x87, 0x95, 0xc2,\n 0xd6, 0x4c, 0xe3, 0x79, 0x29, 0xf0, 0x29, 0x96, 0x2b, 0x19, 0xd9, 0x71,\n 0x58, 0x20, 0x3c, 0x01, 0xc3, 0x49, 0xa4, 0x52, 0xb2, 0xb0, 0x07, 0x0f,\n 0xb5, 0xac, 0xe9, 0x91, 0xb8, 0x30, 0xc1, 0x06, 0xa2, 0xce, 0x7d, 0x90,\n 0xa1, 0x87, 0x56, 0x50, 0x4f, 0x46, 0x0c, 0xde, 0x29, 0x05, 0x19, 0xdd,\n 0x74, 0x58, 0x20, 0xea, 0xcd, 0x7e, 0x83, 0x23, 0xe5, 0x77, 0x5e, 0x65,\n 0xcf, 0x04, 0xa3, 0x2f, 0x15, 0xbf, 0xf3, 0x00, 0x74, 0x2f, 0xf4, 0xf9,\n 0x43, 0xb1, 0xdc, 0xe7, 0x9f, 0xe8, 0xc2, 0x18, 0xda, 0x66, 0x1e, 0x19,\n 0xe1, 0x50, 0x58, 0x20, 0x89, 0x8a, 0xfc, 0xc9, 0x16, 0xdb, 0x1f, 0x4f,\n 0x53, 0x72, 0x82, 0x2c, 0x8b, 0x73, 0x9f, 0x80, 0xcd, 0xa8, 0x6f, 0x34,\n 0xad, 0x89, 0xf4, 0xe0, 0x54, 0x9e, 0x0e, 0x97, 0x73, 0x9c, 0xc4, 0x01,\n 0x19, 0xe7, 0x28, 0x58, 0x20, 0x22, 0x9f, 0xbb, 0x28, 0x46, 0xef, 0xd4,\n 0x2a, 0x6d, 0xe3, 0x21, 0xda, 0x89, 0x53, 0x29, 0xee, 0x3f, 0x5f, 0x02,\n 0xd3, 0x9a, 0x60, 0x4c, 0x4c, 0x8d, 0x6f, 0xce, 0xd5, 0xef, 0xcc, 0x11,\n 0x86, 0x19, 0xf4, 0xbd, 0x58, 0x20, 0x10, 0xe4, 0x43, 0x85, 0x10, 0x27,\n 0x62, 0xef, 0x6b, 0xbf, 0x0d, 0x2c, 0xee, 0xfd, 0x37, 0xdf, 0xc0, 0xb1,\n 0xbe, 0x6d, 0x73, 0x07, 0xb5, 0x93, 0x0d, 0x08, 0x05, 0x61, 0xca, 0xf6,\n 0x1a, 0xdf, 0x19, 0xf8, 0x18, 0x58, 0x20, 0xd3, 0xf1, 0x37, 0x31, 0x07,\n 0x09, 0xe6, 0x94, 0xc6, 0x26, 0x0e, 0xd3, 0x7b, 0x90, 0x7b, 0x26, 0x96,\n 0xdd, 0x44, 0x9d, 0x88, 0xff, 0x8f, 0x05, 0xba, 0x0b, 0xed, 0x56, 0xc4,\n 0x3e, 0x30, 0xab, 0x77, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e,\n 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0x2e, 0x61, 0x61,\n 0x6d, 0x76, 0x61, 0xa7, 0x19, 0x33, 0xd9, 0x58, 0x20, 0x86, 0x34, 0xab,\n 0x2a, 0xce, 0xa2, 0x32, 0x3a, 0x4c, 0x7c, 0xce, 0x45, 0x33, 0x93, 0x9a,\n 0x3f, 0xb3, 0x4d, 0x41, 0xca, 0x68, 0x0e, 0x6b, 0x8e, 0x27, 0x16, 0x58,\n 0xf0, 0x9e, 0x31, 0x65, 0x77, 0x19, 0x35, 0xb6, 0x58, 0x20, 0xd8, 0xb8,\n 0x74, 0x4b, 0x9d, 0x7c, 0xa9, 0xc6, 0x89, 0x4f, 0x0d, 0x5d, 0x2f, 0x7d,\n 0x1e, 0x54, 0x97, 0x5f, 0x3b, 0xdc, 0x9b, 0xfb, 0x4b, 0xe1, 0xb5, 0x34,\n 0x8e, 0xc5, 0x38, 0xe3, 0xb7, 0x03, 0x19, 0x50, 0x2f, 0x58, 0x20, 0xd0,\n 0x1c, 0xe7, 0x38, 0xf7, 0x1c, 0x26, 0x0b, 0x33, 0x6a, 0x3c, 0x5d, 0x79,\n 0x77, 0xdf, 0x5d, 0x1b, 0x42, 0xad, 0x22, 0x54, 0xcc, 0x32, 0x11, 0xde,\n 0x92, 0x95, 0x0c, 0x35, 0x46, 0xee, 0x3d, 0x19, 0x92, 0x51, 0x58, 0x20,\n 0x88, 0x8f, 0xc9, 0x85, 0xcb, 0xee, 0x8e, 0xda, 0x02, 0x8e, 0x70, 0xb2,\n 0x3d, 0x2b, 0xfc, 0x6d, 0x99, 0x72, 0x3e, 0x4e, 0xa2, 0x77, 0xca, 0x3b,\n 0x91, 0xbc, 0x02, 0xec, 0x18, 0x20, 0x0a, 0x6f, 0x19, 0xa4, 0x7c, 0x58,\n 0x20, 0xb3, 0x75, 0x9c, 0xee, 0x1e, 0x90, 0xc0, 0x59, 0x09, 0xe3, 0x1f,\n 0x69, 0x53, 0xf2, 0x08, 0x5f, 0x3e, 0xa6, 0xa0, 0xf8, 0x4d, 0x36, 0x89,\n 0x6a, 0xd1, 0x56, 0xb4, 0x66, 0x24, 0x84, 0x49, 0x18, 0x19, 0xb6, 0x49,\n 0x58, 0x20, 0x1b, 0xdd, 0xe3, 0x1d, 0x45, 0x82, 0x65, 0xe6, 0x59, 0xa6,\n 0xf9, 0x7c, 0x34, 0xd2, 0x76, 0xa6, 0xff, 0x6a, 0x4f, 0x95, 0xdc, 0xbf,\n 0x8b, 0x31, 0xa5, 0x50, 0x2d, 0x5e, 0x09, 0x65, 0xac, 0x05, 0x19, 0xe4,\n 0xe4, 0x58, 0x20, 0x27, 0x9e, 0x2e, 0x80, 0x83, 0xf8, 0x7f, 0x13, 0x43,\n 0xae, 0x43, 0x98, 0x92, 0x26, 0x0a, 0xf6, 0xc7, 0x39, 0x28, 0x69, 0x66,\n 0xb8, 0xdb, 0x15, 0xbe, 0x75, 0x1d, 0xe2, 0x45, 0xe5, 0x42, 0x0c, 0x6d,\n 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79, 0x49, 0x6e, 0x66,\n 0x6f, 0xa1, 0x69, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79,\n 0xa4, 0x01, 0x02, 0x20, 0x01, 0x21, 0x58, 0x20, 0x0b, 0xaa, 0x22, 0x38,\n 0x68, 0x47, 0x64, 0x27, 0x74, 0x33, 0xe4, 0x35, 0x17, 0xd0, 0x8f, 0x35,\n 0xa4, 0xbd, 0x72, 0xb2, 0x3b, 0xce, 0xf0, 0x28, 0x75, 0xae, 0x51, 0x0b,\n 0x88, 0x85, 0x99, 0xca, 0x22, 0x58, 0x20, 0xa5, 0xf5, 0x7b, 0xc8, 0x56,\n 0xe3, 0x9e, 0xa3, 0x8f, 0x18, 0xc7, 0x91, 0xb8, 0xca, 0x7c, 0xc3, 0x9b,\n 0xaf, 0xec, 0x37, 0x1b, 0xe0, 0x29, 0xa0, 0x28, 0x49, 0xa9, 0xb7, 0xfb,\n 0x0c, 0x31, 0x04, 0x67, 0x64, 0x6f, 0x63, 0x54, 0x79, 0x70, 0x65, 0x75,\n 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31,\n 0x33, 0x2e, 0x35, 0x2e, 0x31, 0x2e, 0x6d, 0x44, 0x4c, 0x6c, 0x76, 0x61,\n 0x6c, 0x69, 0x64, 0x69, 0x74, 0x79, 0x49, 0x6e, 0x66, 0x6f, 0xa3, 0x66,\n 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xc0, 0x74, 0x32, 0x30, 0x32, 0x35,\n 0x2d, 0x30, 0x36, 0x2d, 0x30, 0x35, 0x54, 0x31, 0x36, 0x3a, 0x35, 0x35,\n 0x3a, 0x31, 0x31, 0x5a, 0x69, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x46, 0x72,\n 0x6f, 0x6d, 0xc0, 0x74, 0x32, 0x30, 0x32, 0x35, 0x2d, 0x30, 0x36, 0x2d,\n 0x30, 0x35, 0x54, 0x31, 0x36, 0x3a, 0x35, 0x35, 0x3a, 0x31, 0x31, 0x5a,\n 0x6a, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x55, 0x6e, 0x74, 0x69, 0x6c, 0xc0,\n 0x74, 0x32, 0x30, 0x32, 0x35, 0x2d, 0x30, 0x36, 0x2d, 0x31, 0x39, 0x54,\n 0x31, 0x36, 0x3a, 0x35, 0x35, 0x3a, 0x31, 0x31, 0x5a, 0x58, 0x40, 0x35,\n 0x49, 0x2b, 0x30, 0x4e, 0xe2, 0x80, 0x8e, 0xd6, 0x93, 0x9d, 0xf8, 0xe2,\n 0xb2, 0x65, 0x01, 0xee, 0xe2, 0x89, 0xd3, 0x2b, 0x0b, 0x25, 0x96, 0x46,\n 0xe4, 0x89, 0x9d, 0xbe, 0x87, 0xb2, 0xf4, 0xfc, 0xe6, 0x90, 0x9c, 0xeb,\n 0x2c, 0x1c, 0x5c, 0x8e, 0x81, 0x3d, 0x8d, 0x28, 0xd5, 0x02, 0x47, 0x99,\n 0x72, 0x6e, 0x3c, 0x8e, 0x50, 0x26, 0xeb, 0x67, 0xe5, 0xc3, 0xfe, 0xfe,\n 0x31, 0x92, 0x30, 0x6c, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x53, 0x69,\n 0x67, 0x6e, 0x65, 0x64, 0xa2, 0x6a, 0x6e, 0x61, 0x6d, 0x65, 0x53, 0x70,\n 0x61, 0x63, 0x65, 0x73, 0xd8, 0x18, 0x41, 0xa0, 0x6a, 0x64, 0x65, 0x76,\n 0x69, 0x63, 0x65, 0x41, 0x75, 0x74, 0x68, 0xa1, 0x6f, 0x64, 0x65, 0x76,\n 0x69, 0x63, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65,\n 0x84, 0x43, 0xa1, 0x01, 0x26, 0xa0, 0xf6, 0x58, 0x40, 0x92, 0x37, 0x26,\n 0x8c, 0xe3, 0x53, 0xc8, 0x55, 0x11, 0xe7, 0x50, 0x58, 0x75, 0x3d, 0xa2,\n 0x03, 0x8b, 0xca, 0x9d, 0x20, 0xf7, 0x59, 0x51, 0x96, 0x1f, 0x14, 0xf7,\n 0x16, 0xc5, 0x9f, 0xef, 0x24, 0xd2, 0x45, 0xdb, 0xef, 0x45, 0x87, 0x02,\n 0x9f, 0x88, 0x5a, 0xed, 0x8d, 0xce, 0xba, 0x1a, 0xf8, 0x30, 0xa4, 0x49,\n 0x3b, 0xbc, 0xfa, 0xe6, 0x0b, 0xc2, 0xa5, 0xff, 0x99, 0xa1, 0xc1, 0x85,\n 0x07, 0x66, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x00}},\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_EXAMPLES_H_\n"], ["/longfellow-zk/lib/arrays/affine.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ARRAYS_AFFINE_H_\n#define PRIVACY_PROOFS_ZK_LIB_ARRAYS_AFFINE_H_\n\n#include \n\nnamespace proofs {\n\nusing corner_t = size_t;\n\n// return r * f0 + (1-r) * f1 = f0 + r * (f1 - f0)\ntemplate \ntypename Field::Elt affine_interpolation(const typename Field::Elt& r,\n typename Field::Elt f0,\n typename Field::Elt f1,\n const Field& F) {\n F.sub(f1, f0);\n F.mul(f1, r);\n F.add(f0, f1);\n return f0;\n}\n\n// special case f0 = 0\ntemplate \ntypename Field::Elt affine_interpolation_z_nz(const typename Field::Elt& r,\n typename Field::Elt f1,\n const Field& F) {\n F.mul(f1, r);\n return f1;\n}\n\n// special case f1 = 0\ntemplate \ntypename Field::Elt affine_interpolation_nz_z(const typename Field::Elt& r,\n typename Field::Elt f0,\n const Field& F) {\n F.sub(f0, F.mulf(f0, r));\n return f0;\n}\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ARRAYS_AFFINE_H_\n"], ["/longfellow-zk/lib/util/crc64.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_UTIL_CRC64_H_\n#define PRIVACY_PROOFS_ZK_LIB_UTIL_CRC64_H_\n\n/*\nThis package defines 3 basic methods for computing a simple 64-bit CRC.\nIt is used for checksum and comparison of datastructures that are internal\nto this library.\n*/\n\n#include \n\n#include \n\nnamespace proofs {\nnamespace crc64 {\nstatic inline uint64_t shlu64(uint64_t x, size_t n) {\n return (n >= 64) ? 0u : (x << n);\n}\nstatic inline uint64_t shru64(uint64_t x, size_t n) {\n return (n >= 64) ? 0u : (x >> n);\n}\nstatic inline uint64_t update(uint64_t crc, uint64_t u, size_t n = 64) {\n crc ^= u;\n uint64_t l = shlu64(crc, 127u - n) ^ shlu64(crc, 125u - n) ^\n shlu64(crc, 124u - n) ^ shlu64(crc, 64u - n);\n return shru64(crc, n) ^ l ^ (l >> 1) ^ (l >> 3) ^ (l >> 4);\n}\n} // namespace crc64\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_UTIL_CRC64_H_\n"], ["/longfellow-zk/lib/circuits/sha/sha256_constants.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_SHA256_CONSTANTS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_SHA256_CONSTANTS_H_\n\n#include \n\nnamespace proofs {\n\n// Array of round constants used to define SHA256.\n// See FIPS 180-4, section 4.2.2.\nextern const uint32_t kSha256Round[64];\n\n} // namespace proofs\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_SHA256_CONSTANTS_H_\n"], ["/longfellow-zk/lib/circuits/jwt/jwt_constants.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_JWT_JWT_CONSTANTS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_JWT_JWT_CONSTANTS_H_\n\n#include \nnamespace proofs {\n\nstatic constexpr size_t kSHAJWTPluckerBits = 4u;\nstatic constexpr size_t kMaxJWTSHABlocks = 7;\nstatic constexpr size_t kJWTIndexBits = 10; /* #bits to index into payload */\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_JWT_JWT_CONSTANTS_H_\n"], ["/longfellow-zk/lib/circuits/base64/decode_util.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_BASE64_DECODE_UTIL_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_BASE64_DECODE_UTIL_H_\n\n#include \n\n#include \n#include \n\nnamespace proofs {\n\nbool base64_decode_url(std::string inp, std::vector& out);\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_BASE64_DECODE_UTIL_H_\n"], ["/longfellow-zk/lib/circuits/anoncred/small_io.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_IO_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_IO_H_\n\n#include \nnamespace proofs {\n\nstatic constexpr size_t kDateLen = 8;\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_ANONCRED_SMALL_IO_H_\n"], ["/longfellow-zk/lib/circuits/sha/flatsha256_io.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_FLATSHA256_IO_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_FLATSHA256_IO_H_\n\n#include \n\nnamespace proofs {\n\nconstexpr const size_t kShaPluckerSize = 2;\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA_FLATSHA256_IO_H_\n"], ["/longfellow-zk/lib/random/secure_random_engine.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_RANDOM_SECURE_RANDOM_ENGINE_H_\n#define PRIVACY_PROOFS_ZK_LIB_RANDOM_SECURE_RANDOM_ENGINE_H_\n\n#include \n\n#include \n#include \n\n#include \"random/random.h\"\n#include \"util/crypto.h\"\n\nnamespace proofs {\n\n// SecureRandomEngine is a RandomEngine that uses openssl.\nclass SecureRandomEngine : public RandomEngine {\n public:\n SecureRandomEngine() = default;\n void bytes(uint8_t* buf, size_t n) override { rand_bytes(buf, n); }\n};\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_RANDOM_SECURE_RANDOM_ENGINE_H_\n"], ["/longfellow-zk/lib/circuits/mdoc/mdoc_revocation_constants.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_REVOCATION_CONSTANTS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_REVOCATION_CONSTANTS_H_\n\n#include \nnamespace proofs {\n\nstatic constexpr size_t kSHARevocationPluckerBits = 4u;\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_MDOC_MDOC_REVOCATION_CONSTANTS_H_\n"], ["/longfellow-zk/lib/circuits/cbor_parser/cbor_constants.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_CONSTANTS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_CONSTANTS_H_\n\n#include \n\nnamespace proofs {\nstruct CborConstants {\n static constexpr size_t kNCounters = 4;\n static constexpr size_t kIndexBits = 12;\n};\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_CBOR_PARSER_CBOR_CONSTANTS_H_\n"], ["/longfellow-zk/lib/util/panic.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_UTIL_PANIC_H_\n#define PRIVACY_PROOFS_ZK_LIB_UTIL_PANIC_H_\n\n#if defined(__ABSL__)\n#include \"third_party/absl/log/check.h\"\n#else\n#include \n#include \n#endif\n\nnamespace proofs {\n\ninline void check(bool truth, const char* why) {\n#if defined(__ABSL__)\n CHECK(truth) << why;\n#else\n if (!truth) {\n fprintf(stderr, \"%s\", why);\n abort();\n }\n#endif\n}\n\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_UTIL_PANIC_H_\n"], ["/longfellow-zk/lib/circuits/sha3/sha3_round_constants.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA3_SHA3_ROUND_CONSTANTS_H_\n#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA3_SHA3_ROUND_CONSTANTS_H_\n\n#include \n#include \n\nnamespace proofs {\nextern const uint64_t sha3_rc[24];\nextern const size_t sha3_rotc[24];\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA3_SHA3_ROUND_CONSTANTS_H_\n"], ["/longfellow-zk/lib/algebra/static_string.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_ALGEBRA_STATIC_STRING_H_\n#define PRIVACY_PROOFS_ZK_LIB_ALGEBRA_STATIC_STRING_H_\n\n#include \n\n// utility class to wrap pointers to compile-time\n// constant strings\nstruct StaticString {\n template \n explicit StaticString(const char (&s)[N]) : as_pointer(s) {}\n\n const char* as_pointer;\n};\n\n#endif // PRIVACY_PROOFS_ZK_LIB_ALGEBRA_STATIC_STRING_H_\n"], ["/longfellow-zk/lib/util/log.h", "// Copyright 2025 Google LLC.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#ifndef PRIVACY_PROOFS_ZK_LIB_UTIL_LOG_H_\n#define PRIVACY_PROOFS_ZK_LIB_UTIL_LOG_H_\n\n// Simple, self-contained logger for this library.\n\nnamespace proofs {\n\nenum LogLevel {\n ERROR = 1,\n WARNING = 10,\n INFO = 100,\n};\n\nvoid set_log_level(enum LogLevel l);\n\nvoid log(enum LogLevel l, const char* format, ...);\n} // namespace proofs\n\n#endif // PRIVACY_PROOFS_ZK_LIB_UTIL_LOG_H_\n"]], "task_instance_info": {"created_time": "2025-08-20 19:59:49", "created_task_model": "DeepSeek-R1", "function_skeleton": "void unpack_msg(v128 msg[/*2*/], EltW msgw, Nat order,\n const Witness& vw) const {}", "code_description": "This code segment functions to: Validate the integrity of a bitwise message representation by reconstructing its packed form and enforcing constraints to prevent overflow within the cryptographic field's bounds."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```cpp\n[TASK_BEGIN]\n void unpack_msg(v128 msg[/*2*/], EltW msgw, Nat order,\n const Witness& vw) const {\n // Unpack committed message bits\n v256 xx_bits = bp_.template unpack(vw.xx_);\n \n // Split into two 128-bit message portions\n for (size_t i = 0; i < 128; ++i) {\n msg[0][i] = xx_bits[i];\n msg[1][i] = xx_bits[128 + i];\n }\n\n // Convert bits to native field elements for range check\n EltW hi = lc_.bits_to_nat(msg[0], 128);\n EltW lo = lc_.bits_to_nat(msg[1], 128);\n\n // Calculate 2^128 for proper bit alignment\n EltW shift = lc_.konst(lc_.f_.pow2(128));\n \n // Combine message parts with proper alignment and validate value\n EltW combined = lc_.add(lc_.mul(hi, shift), lo);\n lc_.assert_less_than(combined, order);\n lc_.assert_eq(combined, msgw);\n }\n[TASK_END]\n```", "inference_time": "2025-08-20 20-01-24"}, "editdistance_info": {"edit_distance": 37.5, "calculate_time": "2025-08-20 20:01:24", "true_code_clean": "void unpack_msg(v128 msg[], EltW msgw, Nat order,\n const Witness& vw) const {\n v256 x = bp_.template unpack(vw.xx_);\n std::copy(x.begin(), x.begin() + 128, msg[0].begin());\n std::copy(x.begin() + 128, x.end(), msg[1].begin());\n v256 bits_n;\n for (size_t i = 0; i < 256; ++i) {\n bits_n[i] = lc_.bit(order.bit(i));\n }\n lc_.assert1(lc_.vlt(&x, bits_n));\n EltW te = lc_.konst(lc_.zero());\n Elt twok = lc_.one();\n for (size_t i = 0; i < 256; ++i) {\n te = lc_.axpy(&te, twok, lc_.eval(x[i]));\n lc_.f_.add(twok, twok);\n }\n lc_.assert_eq(&te, msgw);\n }", "predict_code_clean": "void unpack_msg(v128 msg[], EltW msgw, Nat order,\n const Witness& vw) const {\n v256 xx_bits = bp_.template unpack(vw.xx_);\n for (size_t i = 0; i < 128; ++i) {\n msg[0][i] = xx_bits[i];\n msg[1][i] = xx_bits[128 + i];\n }\n EltW hi = lc_.bits_to_nat(msg[0], 128);\n EltW lo = lc_.bits_to_nat(msg[1], 128);\n EltW shift = lc_.konst(lc_.f_.pow2(128));\n EltW combined = lc_.add(lc_.mul(hi, shift), lo);\n lc_.assert_less_than(combined, order);\n lc_.assert_eq(combined, msgw);\n }"}}