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
9
14#include "utils/utils.hpp"
15
16#include <iostream>
17#include <sstream>
18
19using namespace bb;
21
22// Get rid of the inner typename
23template <typename Circuit, typename Flavor> void generate_proof(uint256_t inputs[])
24{
27 using VKAndHash = typename Flavor::VKAndHash;
28 using Prover = UltraProver_<Flavor>;
30 using Verifier = UltraVerifier_<Flavor, IO>;
31 using Proof = typename Flavor::Transcript::Proof;
33
34 CircuitBuilder builder = Circuit::generate(inputs);
35 // If this is not a recursive circuit, we need to add the default pairing points to the public inputs
37 if constexpr (HasIPAAccumulator<Flavor>) {
39 } else {
41 }
42 }
43
45 auto verification_key = std::make_shared<VerificationKey>(instance->get_precomputed());
46 auto vk_and_hash = std::make_shared<VKAndHash>(verification_key);
47 Prover prover(instance, verification_key);
48 Verifier verifier(vk_and_hash);
49
50 Proof proof = prover.construct_proof();
51 {
52 if (!verifier.verify_proof(proof).result) {
53 throw_or_abort("Verification failed");
54 }
55
56 std::vector<uint8_t> proof_bytes = to_buffer(proof);
57 std::string p = bytes_to_hex_string(proof_bytes);
58 std::cout << p;
59 }
60}
61
62std::string pad_left(std::string input, size_t length)
63{
64 return std::string(length - std::min(length, input.length()), '0') + input;
65}
66
75int main(int argc, char** argv)
76{
77 std::vector<std::string> args(argv, argv + argc);
78
79 if (args.size() < 5) {
80 info("usage: ", args[0], "[honk flavor] [circuit type] [srs path] [public inputs]");
81 return 1;
82 }
83
84 const std::string flavor = args[1];
85 const std::string circuit_type = args[2];
86 const std::string srs_path = args[3];
87 const std::string string_input = args[4];
88
90
91 // @todo dynamically allocate this
92 uint256_t inputs[] = { 0, 0, 0, 0, 0, 0 };
93
94 size_t count = 0;
95 std::stringstream s_stream(string_input);
96 while (s_stream.good()) {
97 std::string sub;
98 getline(s_stream, sub, ',');
99 if (sub.substr(0, 2) == "0x") {
100 sub = sub.substr(2);
101 }
102 std::string padded = pad_left(sub, 64);
103 inputs[count++] = uint256_t(padded);
104 }
105
106 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1227)
107 if (flavor == "honk") {
108 if (circuit_type == "blake") {
109 generate_proof<BlakeCircuit, UltraKeccakFlavor>(inputs);
110 } else if (circuit_type == "add2") {
111 generate_proof<Add2Circuit, UltraKeccakFlavor>(inputs);
112 } else if (circuit_type == "ecdsa") {
113 generate_proof<EcdsaCircuit, UltraKeccakFlavor>(inputs);
114 } else if (circuit_type == "recursive") {
115 generate_proof<RecursiveCircuit, UltraKeccakFlavor>(inputs);
116 } else {
117 info("Invalid circuit type: " + circuit_type);
118 return 1;
119 }
120
121 } else if (flavor == "honk_zk") {
122 if (circuit_type == "blake") {
123 generate_proof<BlakeCircuit, UltraKeccakZKFlavor>(inputs);
124 } else if (circuit_type == "add2") {
125 generate_proof<Add2Circuit, UltraKeccakZKFlavor>(inputs);
126 } else if (circuit_type == "ecdsa") {
127 generate_proof<EcdsaCircuit, UltraKeccakZKFlavor>(inputs);
128 } else if (circuit_type == "recursive") {
129 generate_proof<RecursiveCircuit, UltraKeccakZKFlavor>(inputs);
130 } else {
131 info("Invalid circuit type: " + circuit_type);
132 return 1;
133 }
134 } else {
135 info("Only honk flavor allowed");
136 return 1;
137 }
138}
std::shared_ptr< Napi::ThreadSafeFunction > instance
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...
ECCVMCircuitBuilder CircuitBuilder
Base Native verification key class.
Definition flavor.hpp:141
A ProverInstance is normally constructed from a finalized circuit and it contains all the information...
The data that is propagated on the public inputs of a rollup circuit.
TranslatorCircuitBuilder creates a circuit that evaluates the correctness of the evaluation of EccOpQ...
static void add_default(Builder &builder)
Add default public inputs when they are not present.
static void add_default(Builder &builder)
Add default public inputs when they are not present.
void info(Args... args)
Definition log.hpp:89
AluTraceBuilder builder
Definition alu.test.cpp:124
uint8_t const size_t length
Definition data_store.hpp:9
AvmProvingInputs inputs
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.
Definition api.hpp:5
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
void throw_or_abort(std::string const &err)