Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
honk_key_gen.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#pragma once
8
19inline void output_vk_sol_ultra_honk(std::ostream& os,
20 auto const& key,
21 std::string const& class_name,
22 bool include_types_import = false)
23{
24
25 const auto print_u256_const = [&](const auto& element, const std::string& name) {
26 os << "uint256 constant " << name << " = " << element << ";" << std::endl;
27 };
28
29 const auto print_u256 = [&](const auto& element, const std::string& name) {
30 os << " " << name << ": uint256(" << element << ")," << std::endl;
31 };
32
33 const auto print_g1 = [&](const auto& element, const std::string& name, const bool last = false) {
34 os << " " << name << ": Honk.G1Point({ \n"
35 << " "
36 << "x: "
37 << "uint256(" << element.x << "),\n"
38 << " "
39 << "y: "
40 << "uint256(" << element.y << ")\n"
41 << " })";
42
43 // only include comma if we are not the last element
44 if (!last) {
45 os << ",\n";
46 } else {
47 os << "\n";
48 }
49 };
50
51 // Include the types import if working with the local test suite
52 const auto print_types_import = [&]() {
53 if (include_types_import) {
54 os << "import { Honk } from \"../HonkTypes.sol\";\n";
55 }
56 };
57
58 // clang-format off
59 os <<
60 // "// Verification Key Hash: " << key->sha256_hash() << "\n"
61 "// SPDX-License-Identifier: Apache-2.0\n"
62 "// Copyright 2022 Aztec\n"
63 "pragma solidity >=0.8.21;\n"
64 "\n"
65 "";
66 print_types_import();
67 print_u256_const(1 << key->log_circuit_size, "N");
68 print_u256_const(key->log_circuit_size, "LOG_N");
69 print_u256_const(key->num_public_inputs, "NUMBER_OF_PUBLIC_INPUTS");
70 print_u256_const(key->hash(), "VK_HASH");
71 os << ""
72 "library " << class_name << " {\n"
73 " function loadVerificationKey() internal pure returns (Honk.VerificationKey memory) {\n"
74 " Honk.VerificationKey memory vk = Honk.VerificationKey({\n";
75 print_u256(1 << key->log_circuit_size, "circuitSize");
76 print_u256(key->log_circuit_size, "logCircuitSize");
77 print_u256(key->num_public_inputs, "publicInputsSize");
78 print_g1(key->q_l, "ql");
79 print_g1(key->q_r, "qr");
80 print_g1(key->q_o, "qo");
81 print_g1(key->q_4, "q4");
82 print_g1(key->q_m, "qm");
83 print_g1(key->q_c, "qc");
84 print_g1(key->q_lookup, "qLookup");
85 print_g1(key->q_arith, "qArith");
86 print_g1(key->q_delta_range, "qDeltaRange");
87 print_g1(key->q_elliptic, "qElliptic");
88 print_g1(key->q_memory, "qMemory");
89 print_g1(key->q_nnf, "qNnf");
90 print_g1(key->q_poseidon2_external, "qPoseidon2External");
91 print_g1(key->q_poseidon2_internal, "qPoseidon2Internal");
92 print_g1(key->sigma_1, "s1");
93 print_g1(key->sigma_2, "s2");
94 print_g1(key->sigma_3, "s3");
95 print_g1(key->sigma_4, "s4");
96 print_g1(key->table_1, "t1");
97 print_g1(key->table_2, "t2");
98 print_g1(key->table_3, "t3");
99 print_g1(key->table_4, "t4");
100 print_g1(key->id_1, "id1");
101 print_g1(key->id_2, "id2");
102 print_g1(key->id_3, "id3");
103 print_g1(key->id_4, "id4");
104 print_g1(key->lagrange_first, "lagrangeFirst");
105 print_g1(key->lagrange_last, "lagrangeLast", /*last=*/ true);
106 os <<
107 " });\n"
108 " return vk;\n"
109 " }\n"
110 "}\n";
111
112 os << std::flush;
113}
void output_vk_sol_ultra_honk(std::ostream &os, auto const &key, std::string const &class_name, bool include_types_import=false)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13