Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
prove_tube.cpp
Go to the documentation of this file.
1#include "prove_tube.hpp"
7
8namespace bb {
15void prove_tube(const std::string& output_path, const std::string& vk_path)
16{
17 using namespace stdlib::recursion::honk;
18
20 using StdlibProof = ClientIVCRecursiveVerifier::StdlibProof;
23
24 std::string proof_path = output_path + "/proof";
25
26 // Read the proof and verification data from given files
27 auto proof = ClientIVC::Proof::from_file_msgpack(proof_path);
28 auto vk = from_buffer<ClientIVC::VerificationKey>(read_file(vk_path));
29
31 ClientIVCRecursiveVerifier verifier{ &builder, vk.mega };
32
33 StdlibProof stdlib_proof(builder, proof);
34 ClientIVCRecursiveVerifier::Output client_ivc_rec_verifier_output = verifier.verify(stdlib_proof);
35
36 // The public inputs in the proof are propagated to the base rollup by making them public inputs of this circuit.
37 // Exclude the public inputs of the Hiding Kernel: the pairing points are handled separately, the ecc op tables are
38 // not needed after this point
39 auto num_inner_public_inputs = vk.mega->num_public_inputs - HidingKernelIO::PUBLIC_INPUTS_SIZE;
40 for (size_t i = 0; i < num_inner_public_inputs; i++) {
41 stdlib_proof.mega_proof[i].set_public();
42 }
43
44 // IO
45 RollupIO inputs;
46 inputs.pairing_inputs = client_ivc_rec_verifier_output.points_accumulator;
47 inputs.ipa_claim = client_ivc_rec_verifier_output.opening_claim;
48 inputs.set_public();
49
50 // The tube only calls an IPA recursive verifier once, so we can just add this IPA proof
51 builder.ipa_proof = client_ivc_rec_verifier_output.ipa_proof.get_value();
52 BB_ASSERT_EQ(builder.ipa_proof.size(), IPA_PROOF_LENGTH, "IPA proof should be set.");
53
55 using Verifier = UltraVerifier_<UltraRollupFlavor>;
57 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1201): Precompute tube vk and pass it in.
58 info("WARNING: computing tube vk in prove_tube, but a precomputed vk should be passed in.");
59 auto tube_verification_key = std::make_shared<UltraRollupFlavor::VerificationKey>(proving_key->get_precomputed());
60
61 Prover tube_prover{ proving_key, tube_verification_key };
62 auto tube_proof = tube_prover.construct_proof();
63 std::string tubePublicInputsPath = output_path + "/public_inputs";
64 std::string tubeProofPath = output_path + "/proof";
65 PublicInputsAndProof<HonkProof> public_inputs_and_proof{
66 PublicInputsVector(tube_proof.begin(),
67 tube_proof.begin() + static_cast<std::ptrdiff_t>(num_inner_public_inputs)),
68 HonkProof(tube_proof.begin() + static_cast<std::ptrdiff_t>(num_inner_public_inputs), tube_proof.end())
69 };
70 write_file(tubePublicInputsPath, to_buffer(public_inputs_and_proof.public_inputs));
71 write_file(tubeProofPath, to_buffer(public_inputs_and_proof.proof));
72
73 std::string tubePublicInputsAsFieldsPath = output_path + "/public_inputs_fields.json";
74 std::string tubeProofAsFieldsPath = output_path + "/proof_fields.json";
75 const auto to_json = [](const std::vector<bb::fr>& data) {
76 if (data.empty()) {
77 return std::string("[]");
78 }
79 return format("[", join(transform::map(data, [](auto fr) { return format("\"", fr, "\""); })), "]");
80 };
81 auto public_inputs_data = to_json(public_inputs_and_proof.public_inputs);
82 auto proof_data = to_json(public_inputs_and_proof.proof);
83 write_file(tubePublicInputsAsFieldsPath, { public_inputs_data.begin(), public_inputs_data.end() });
84 write_file(tubeProofAsFieldsPath, { proof_data.begin(), proof_data.end() });
85
86 std::string tubeVkPath = output_path + "/vk";
87 write_file(tubeVkPath, to_buffer(tube_verification_key));
88
89 std::string tubeAsFieldsVkPath = output_path + "/vk_fields.json";
90 auto field_els = tube_verification_key->to_field_elements();
91 info("verificaton key length in fields:", field_els.size());
92 auto data = to_json(field_els);
93 write_file(tubeAsFieldsVkPath, { data.begin(), data.end() });
94
95 info("Native verification of the tube_proof");
96 VerifierCommitmentKey<curve::Grumpkin> ipa_verification_key(1 << CONST_ECCVM_LOG_N);
97 Verifier tube_verifier(tube_verification_key, ipa_verification_key);
98
99 // Break up the tube proof into the honk portion and the ipa portion
100 const size_t HONK_PROOF_LENGTH_WITHOUT_INNER_PUB_INPUTS =
102 // The extra calculation is for the IPA proof length.
103 BB_ASSERT_EQ(tube_proof.size(),
104 HONK_PROOF_LENGTH_WITHOUT_INNER_PUB_INPUTS + num_inner_public_inputs,
105 "In prove_tube, tube proof length is incorrect.");
106 // split out the ipa proof
107 const std::ptrdiff_t honk_proof_with_pub_inputs_length = static_cast<std::ptrdiff_t>(
108 HONK_PROOF_LENGTH_WITHOUT_INNER_PUB_INPUTS - IPA_PROOF_LENGTH + num_inner_public_inputs);
109 auto ipa_proof = HonkProof(tube_proof.begin() + honk_proof_with_pub_inputs_length, tube_proof.end());
110 auto tube_honk_proof = HonkProof(tube_proof.begin(), tube_proof.end() + honk_proof_with_pub_inputs_length);
111 bool verified = tube_verifier.template verify_proof<bb::RollupIO>(tube_honk_proof, ipa_proof).result;
112 info("Tube proof verification: ", verified);
113}
114
115} // namespace bb
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:59
Manages the data that is propagated on the public inputs of of a hiding kernel circuit.
static constexpr size_t PUBLIC_INPUTS_SIZE
The data that is propagated on the public inputs of a rollup circuit.
PairingPoints pairing_inputs
static constexpr size_t PUBLIC_INPUTS_SIZE
static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS(size_t virtual_log_n=VIRTUAL_LOG_N)
Representation of the Grumpkin Verifier Commitment Key inside a bn254 circuit.
Manages the data that is propagated on the public inputs of a hiding kernel circuit.
The data that is propagated on the public inputs of a rollup circuit.
std::string format(Args... args)
Definition log.hpp:20
void info(Args... args)
Definition log.hpp:70
AluTraceBuilder builder
Definition alu.test.cpp:123
const std::vector< FF > data
Cont< OutElem > map(Cont< InElem, Args... > const &in, F &&op)
Definition map.hpp:15
Entry point for Barretenberg command-line interface.
std::vector< fr > HonkProof
Definition proof.hpp:15
void prove_tube(const std::string &output_path, const std::string &vk_path)
Creates a Honk Proof for the Tube circuit responsible for recursively verifying a ClientIVC proof.
std::vector< fr > PublicInputsVector
Definition proof.hpp:14
UltraCircuitBuilder_< UltraExecutionTraceBlocks > UltraCircuitBuilder
std::vector< uint8_t > read_file(const std::string &filename, size_t bytes=0)
Definition file_io.hpp:29
C join(std::initializer_list< C > to_join)
Definition container.hpp:26
void write_file(const std::string &filename, std::vector< uint8_t > const &data)
Definition file_io.hpp:58
VerifierCommitmentKey< Curve > vk
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::vector< uint8_t > to_buffer(T const &value)
static Proof from_file_msgpack(const std::string &filename)