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 Prover = UltraProver_<Flavor>;
28 using Verifier = UltraVerifier_<Flavor>;
29 using Proof = typename Flavor::Transcript::Proof;
32
33 CircuitBuilder builder = Circuit::generate(inputs);
34 // If this is not a recursive circuit, we need to add the default pairing points to the public inputs
36 if constexpr (HasIPAAccumulator<Flavor>) {
38 } else {
40 }
41 }
42
44 auto verification_key = std::make_shared<VerificationKey>(instance->get_precomputed());
45 Prover prover(instance, verification_key);
46 Verifier verifier(verification_key);
47
48 Proof proof = prover.construct_proof();
49 {
50 if (!verifier.template verify_proof<IO>(proof)) {
51 throw_or_abort("Verification failed");
52 }
53
54 std::vector<uint8_t> proof_bytes = to_buffer(proof);
55 std::string p = bytes_to_hex_string(proof_bytes);
56 std::cout << p;
57 }
58}
59
60std::string pad_left(std::string input, size_t length)
61{
62 return std::string(length - std::min(length, input.length()), '0') + input;
63}
64
73int main(int argc, char** argv)
74{
75 std::vector<std::string> args(argv, argv + argc);
76
77 if (args.size() < 5) {
78 info("usage: ", args[0], "[honk flavor] [circuit type] [srs path] [public inputs]");
79 return 1;
80 }
81
82 const std::string flavor = args[1];
83 const std::string circuit_type = args[2];
84 const std::string srs_path = args[3];
85 const std::string string_input = args[4];
86
88
89 // @todo dynamically allocate this
90 uint256_t inputs[] = { 0, 0, 0, 0, 0, 0 };
91
92 size_t count = 0;
93 std::stringstream s_stream(string_input);
94 while (s_stream.good()) {
95 std::string sub;
96 getline(s_stream, sub, ',');
97 if (sub.substr(0, 2) == "0x") {
98 sub = sub.substr(2);
99 }
100 std::string padded = pad_left(sub, 64);
101 inputs[count++] = uint256_t(padded);
102 }
103
104 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1227)
105 if (flavor == "honk") {
106 if (circuit_type == "blake") {
107 generate_proof<BlakeCircuit, UltraKeccakFlavor>(inputs);
108 } else if (circuit_type == "add2") {
109 generate_proof<Add2Circuit, UltraKeccakFlavor>(inputs);
110 } else if (circuit_type == "ecdsa") {
111 generate_proof<EcdsaCircuit, UltraKeccakFlavor>(inputs);
112 } else if (circuit_type == "recursive") {
113 generate_proof<RecursiveCircuit, UltraKeccakFlavor>(inputs);
114 } else {
115 info("Invalid circuit type: " + circuit_type);
116 return 1;
117 }
118
119 } else if (flavor == "honk_zk") {
120 if (circuit_type == "blake") {
121 generate_proof<BlakeCircuit, UltraKeccakZKFlavor>(inputs);
122 } else if (circuit_type == "add2") {
123 generate_proof<Add2Circuit, UltraKeccakZKFlavor>(inputs);
124 } else if (circuit_type == "ecdsa") {
125 generate_proof<EcdsaCircuit, UltraKeccakZKFlavor>(inputs);
126 } else if (circuit_type == "recursive") {
127 generate_proof<RecursiveCircuit, UltraKeccakZKFlavor>(inputs);
128 } else {
129 info("Invalid circuit type: " + circuit_type);
130 return 1;
131 }
132 } else {
133 info("Only honk flavor allowed");
134 return 1;
135 }
136}
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
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:75
AluTraceBuilder builder
Definition alu.test.cpp:124
uint8_t const size_t length
Definition data_store.hpp:9
AvmProvingInputs inputs
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.
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)