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, typename IO = DefaultIO> void generate_proof(uint256_t inputs[])
24{
27 using VKAndHash = typename Flavor::VKAndHash;
28 using Prover = UltraProver_<Flavor>;
29 using Verifier = UltraVerifier_<Flavor, IO>;
30 using Proof = typename Flavor::Transcript::Proof;
32
33 CircuitBuilder builder = Circuit::generate(inputs);
34
36 auto verification_key = std::make_shared<VerificationKey>(instance->get_precomputed());
37 auto vk_and_hash = std::make_shared<VKAndHash>(verification_key);
38 Prover prover(instance, verification_key);
39 Verifier verifier(vk_and_hash);
40
41 Proof proof = prover.construct_proof();
42 {
43 if (!verifier.verify_proof(proof).result) {
44 throw_or_abort("Verification failed");
45 }
46
47 std::vector<uint8_t> proof_bytes = to_buffer(proof);
48 std::string p = bytes_to_hex_string(proof_bytes);
49 std::cout << p;
50 }
51}
52
53std::string pad_left(std::string input, size_t length)
54{
55 return std::string(length - std::min(length, input.length()), '0') + input;
56}
57
66int main(int argc, char** argv)
67{
68 std::vector<std::string> args(argv, argv + argc);
69
70 if (args.size() < 5) {
71 info("usage: ", args[0], "[honk flavor] [circuit type] [srs path] [public inputs]");
72 return 1;
73 }
74
75 const std::string flavor = args[1];
76 const std::string circuit_type = args[2];
77 const std::string srs_path = args[3];
78 const std::string string_input = args[4];
79
81
82 // @todo dynamically allocate this
83 uint256_t inputs[] = { 0, 0, 0, 0, 0, 0 };
84
85 size_t count = 0;
86 std::stringstream s_stream(string_input);
87 while (s_stream.good()) {
88 std::string sub;
89 getline(s_stream, sub, ',');
90 if (sub.substr(0, 2) == "0x") {
91 sub = sub.substr(2);
92 }
93 std::string padded = pad_left(sub, 64);
94 inputs[count++] = uint256_t(padded);
95 }
96
97 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1227)
98 if (flavor == "honk") {
99 if (circuit_type == "blake") {
100 generate_proof<BlakeCircuit, UltraKeccakFlavor>(inputs);
101 } else if (circuit_type == "add2") {
102 generate_proof<Add2Circuit, UltraKeccakFlavor>(inputs);
103 } else if (circuit_type == "ecdsa") {
104 generate_proof<EcdsaCircuit, UltraKeccakFlavor>(inputs);
105 } else if (circuit_type == "recursive") {
106 generate_proof<RecursiveCircuit, UltraKeccakFlavor>(inputs);
107 } else {
108 info("Invalid circuit type: " + circuit_type);
109 return 1;
110 }
111
112 } else if (flavor == "honk_zk") {
113 if (circuit_type == "blake") {
114 generate_proof<BlakeCircuit, UltraKeccakZKFlavor>(inputs);
115 } else if (circuit_type == "add2") {
116 generate_proof<Add2Circuit, UltraKeccakZKFlavor>(inputs);
117 } else if (circuit_type == "ecdsa") {
118 generate_proof<EcdsaCircuit, UltraKeccakZKFlavor>(inputs);
119 } else if (circuit_type == "recursive") {
120 generate_proof<RecursiveCircuit, UltraKeccakZKFlavor>(inputs);
121 } else {
122 info("Invalid circuit type: " + circuit_type);
123 return 1;
124 }
125 } else {
126 info("Only honk flavor allowed");
127 return 1;
128 }
129}
std::shared_ptr< Napi::ThreadSafeFunction > instance
ECCVMCircuitBuilder CircuitBuilder
FixedVKAndHash_< PrecomputedEntities< Commitment >, BF, ECCVMHardcodedVKAndHash > VerificationKey
The verification key stores commitments to the precomputed polynomials used by the verifier.
Base Native verification key class.
Definition flavor.hpp:135
Contains all the information required by a Honk prover to create a proof, constructed from a finalize...
TranslatorCircuitBuilder creates a circuit that evaluates the correctness of the evaluation of EccOpQ...
#define info(...)
Definition log.hpp:93
AluTraceBuilder builder
Definition alu.test.cpp:124
uint8_t const size_t length
Definition data_store.hpp:9
AvmProvingInputs inputs
int main(int argc, char **argv)
Main entry point for the proof generator. Expected inputs:
void generate_proof(uint256_t 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
std::string bytes_to_hex_string(const std::vector< uint8_t > &bytes)
Convert bytes to a hex string with 0x prefix.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::vector< uint8_t > to_buffer(T const &value)
void throw_or_abort(std::string const &err)