Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
proving_helper.cpp
Go to the documentation of this file.
2
3#include <cstdint>
4#include <cstdlib>
5#include <memory>
6#include <stdexcept>
7
19
20namespace bb::avm2 {
21
23{
24 auto polynomials = AVM_TRACK_TIME_V("proving/prove:compute_polynomials", constraining::compute_polynomials(trace));
25 auto proving_key =
26 AVM_TRACK_TIME_V("proving/prove:proving_key", constraining::proving_key_from_polynomials(polynomials));
27
28 auto verification_key = std::make_shared<AvmVerifier::VerificationKey>();
29
30 auto prover = AVM_TRACK_TIME_V("proving/prove:construct_prover",
31 AvmProver(proving_key, verification_key, proving_key->commitment_key));
32
33 auto proof = AVM_TRACK_TIME_V("proving/construct_proof", prover.construct_proof());
34
35 return proof;
36}
37
39{
40 // The proof is done over the whole circuit (2^21 rows).
41 // However, for check-circuit purposes we run only over the witness rows
42 // PLUS one extra row to catch any possible errors in the empty remainder
43 // of the circuit.
44 const bool skippable_enabled = (getenv("AVM_DISABLE_SKIPPABLE") == nullptr);
45 const size_t num_rows = skippable_enabled ? trace.get_num_witness_rows() + 1 : trace.get_num_rows();
46 vinfo("Running check ",
47 skippable_enabled ? "(with skippable)" : "(without skippable)",
48 " circuit over ",
49 num_rows,
50 " rows.");
51
52 // Warning: this destroys the trace.
53 auto polynomials = AVM_TRACK_TIME_V("proving/prove:compute_polynomials", constraining::compute_polynomials(trace));
54 try {
55 AVM_TRACK_TIME("proving/check_circuit",
56 constraining::run_check_circuit(polynomials, num_rows, skippable_enabled));
57 } catch (std::runtime_error& e) {
58 // FIXME: This exception is never caught because it's thrown in a different thread.
59 // Execution never gets here!
60 vinfo("Circuit check failed: ", e.what());
61 }
62
63 return true;
64}
65
67{
68 auto vk =
69 AVM_TRACK_TIME_V("proving/verify:create_verification_key", std::make_shared<AvmFlavor::VerificationKey>());
70 auto verifier = AVM_TRACK_TIME_V("proving/verify:construct_verifier", AvmVerifier());
71 return AVM_TRACK_TIME_V("proving/verify_proof", verifier.verify_proof(proof, pi.to_columns()));
72}
73
74} // namespace bb::avm2
bool verify(const Proof &proof, const PublicInputs &pi)
Proof prove(tracegen::TraceContainer &&trace)
bool check_circuit(tracegen::TraceContainer &&trace)
#define vinfo(...)
Definition log.hpp:94
TestTraceContainer trace
AvmProver::ProverPolynomials compute_polynomials(tracegen::TraceContainer &trace)
std::shared_ptr< AvmProver::ProvingKey > proving_key_from_polynomials(AvmProver::ProverPolynomials &polynomials)
void run_check_circuit(AvmFlavor::ProverPolynomials &polys, size_t num_rows, bool skippable_enabled)
VerifierCommitmentKey< Curve > vk
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
#define AVM_TRACK_TIME_V(key, body)
Definition stats.hpp:18
#define AVM_TRACK_TIME(key, body)
Definition stats.hpp:16
std::vector< std::vector< FF > > to_columns() const
Serialization to columns.
Definition avm_io.cpp:142