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