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