Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
honk_proof_gen.cpp
Go to the documentation of this file.
1
8
13#include "utils/utils.hpp"
14
15#include <iostream>
16#include <sstream>
17
18using namespace bb;
20
21// Get rid of the inner typename
22template <typename Circuit, typename Flavor> void generate_proof(uint256_t inputs[])
23{
26 using Prover = UltraProver_<Flavor>;
27 using Verifier = UltraVerifier_<Flavor>;
28 using Proof = typename Flavor::Transcript::Proof;
29 using CircuitBuilder = typename Flavor::CircuitBuilder;
31
32 CircuitBuilder builder = Circuit::generate(inputs);
33 // If this is not a recursive circuit, we need to add the default pairing points to the public inputs
36 }
37
39 auto verification_key = std::make_shared<VerificationKey>(instance->get_precomputed());
40 Prover prover(instance, verification_key);
41 Verifier verifier(verification_key);
42
43 Proof proof = prover.construct_proof();
44 {
45 if (!verifier.template verify_proof<IO>(proof)) {
46 throw_or_abort("Verification failed");
47 }
48
49 std::vector<uint8_t> proof_bytes = to_buffer(proof);
50 std::string p = bytes_to_hex_string(proof_bytes);
51 std::cout << p;
52 }
53}
54
55std::string pad_left(std::string input, size_t length)
56{
57 return std::string(length - std::min(length, input.length()), '0') + input;
58}
59
68int main(int argc, char** argv)
69{
70 std::vector<std::string> args(argv, argv + argc);
71
72 if (args.size() < 5) {
73 info("usage: ", args[0], "[honk flavor] [circuit type] [srs path] [public inputs]");
74 return 1;
75 }
76
77 const std::string flavor = args[1];
78 const std::string circuit_type = args[2];
79 const std::string srs_path = args[3];
80 const std::string string_input = args[4];
81
83
84 // @todo dynamically allocate this
85 uint256_t inputs[] = { 0, 0, 0, 0, 0, 0 };
86
87 size_t count = 0;
88 std::stringstream s_stream(string_input);
89 while (s_stream.good()) {
90 std::string sub;
91 getline(s_stream, sub, ',');
92 if (sub.substr(0, 2) == "0x") {
93 sub = sub.substr(2);
94 }
95 std::string padded = pad_left(sub, 64);
96 inputs[count++] = uint256_t(padded);
97 }
98
99 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1227)
100 if (flavor == "honk") {
101 if (circuit_type == "blake") {
102 generate_proof<BlakeCircuit, UltraKeccakFlavor>(inputs);
103 } else if (circuit_type == "add2") {
104 generate_proof<Add2Circuit, UltraKeccakFlavor>(inputs);
105 } else if (circuit_type == "ecdsa") {
106 generate_proof<EcdsaCircuit, UltraKeccakFlavor>(inputs);
107 } else if (circuit_type == "recursive") {
108 generate_proof<RecursiveCircuit, UltraKeccakFlavor>(inputs);
109 } else {
110 info("Invalid circuit type: " + circuit_type);
111 return 1;
112 }
113
114 } else if (flavor == "honk_zk") {
115 if (circuit_type == "blake") {
116 generate_proof<BlakeCircuit, UltraKeccakZKFlavor>(inputs);
117 } else if (circuit_type == "add2") {
118 generate_proof<Add2Circuit, UltraKeccakZKFlavor>(inputs);
119 } else if (circuit_type == "ecdsa") {
120 generate_proof<EcdsaCircuit, UltraKeccakZKFlavor>(inputs);
121 } else if (circuit_type == "recursive") {
122 generate_proof<RecursiveCircuit, UltraKeccakZKFlavor>(inputs);
123 } else {
124 info("Invalid circuit type: " + circuit_type);
125 return 1;
126 }
127 } else {
128 info("Only honk flavor allowed");
129 return 1;
130 }
131}
A DeciderProvingKey is normally constructed from a finalized circuit and it contains all the informat...
Manages the data that is propagated on the public inputs of an application/function circuit.
The verification key is responsible for storing the commitments to the precomputed (non-witnessk) pol...
MegaCircuitBuilder CircuitBuilder
The data that is propagated on the public inputs of a rollup circuit.
void info(Args... args)
Definition log.hpp:70
AluTraceBuilder builder
Definition alu.test.cpp:123
uint8_t const size_t length
Definition data_store.hpp:9
UltraKeccakFlavor::VerificationKey VerificationKey
void generate_proof(uint256_t inputs[])
int main(int argc, char **argv)
Main entry point for the proof generator. Expected inputs:
std::string pad_left(std::string input, size_t length)
void init_file_crs_factory(const std::filesystem::path &path)
Entry point for Barretenberg command-line interface.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::vector< uint8_t > to_buffer(T const &value)
std::string bytes_to_hex_string(const std::vector< uint8_t > &input)
Definition utils.hpp:5
static void add_default_to_public_inputs(Builder &builder)
Adds default public inputs to the builder.
void throw_or_abort(std::string const &err)