Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
avm_api.cpp
Go to the documentation of this file.
2
8
9namespace bb::avm2 {
10
11using namespace bb::avm2::simulation;
12
14{
15 // Simulate.
16 vinfo("Simulating...");
17 AvmSimulationHelper simulation_helper;
18
19 auto events = AVM_TRACK_TIME_V("simulation/all", simulation_helper.simulate_for_witgen(inputs.hints));
20
21 // Generate trace.
22 vinfo("Generating trace...");
23 AvmTraceGenHelper tracegen_helper;
24 auto trace =
25 AVM_TRACK_TIME_V("tracegen/all", tracegen_helper.generate_trace(std::move(events), inputs.public_inputs));
26
27 // Prove.
28 vinfo("Proving...");
29 AvmProvingHelper proving_helper;
30 auto [proof, vk] = AVM_TRACK_TIME_V("proving/all", proving_helper.prove(std::move(trace)));
31
32 vinfo("Done!");
33 return { std::move(proof), std::move(vk) };
34}
35
37{
38 // Simulate.
39 vinfo("Simulating...");
40 AvmSimulationHelper simulation_helper;
41
42 auto events = AVM_TRACK_TIME_V("simulation/all", simulation_helper.simulate_for_witgen(inputs.hints));
43
44 // Generate trace.
45 // In contrast to proving, we do this step by step since it's usually more useful to debug
46 // before trying to run the interaction builders.
47 vinfo("Generating trace...");
48 AvmTraceGenHelper tracegen_helper;
50 AVM_TRACK_TIME("tracegen/all", tracegen_helper.fill_trace_columns(trace, std::move(events), inputs.public_inputs));
51
52 // Go into interactive debug mode if requested.
53 if (getenv("AVM_DEBUG") != nullptr) {
54 InteractiveDebugger debugger(trace);
55 debugger.run();
56 }
57
58 AVM_TRACK_TIME("tracegen/all", tracegen_helper.fill_trace_interactions(trace));
59
60 // Check circuit.
61 vinfo("Checking circuit...");
62 AvmProvingHelper proving_helper;
63 return proving_helper.check_circuit(std::move(trace));
64}
65
66bool AvmAPI::verify(const AvmProof& proof, const PublicInputs& pi, const AvmVerificationKey& vk_data)
67{
68 vinfo("Verifying...");
69 AvmProvingHelper proving_helper;
70 return AVM_TRACK_TIME_V("verifing/all", proving_helper.verify(proof, pi, vk_data));
71}
72
74{
75 vinfo("Generating trace...");
76 AvmTraceGenHelper tracegen_helper;
77 auto trace = tracegen_helper.generate_precomputed_columns();
78
79 vinfo("Computing verification key...");
80 AvmProvingHelper proving_helper;
81 return proving_helper.compute_verification_key(trace);
82}
83
84} // namespace bb::avm2
AvmVerificationKey get_verification_key()
Definition avm_api.cpp:73
bool check_circuit(const ProvingInputs &inputs)
Definition avm_api.cpp:36
bool verify(const AvmProof &proof, const PublicInputs &pi, const AvmVerificationKey &vk_data)
Definition avm_api.cpp:66
std::vector< uint8_t > AvmVerificationKey
Definition avm_api.hpp:12
AvmProvingHelper::Proof AvmProof
Definition avm_api.hpp:11
std::pair< AvmProof, AvmVerificationKey > prove(const ProvingInputs &inputs)
Definition avm_api.cpp:13
bool verify(const Proof &proof, const PublicInputs &pi, const VkData &vk_data)
std::pair< Proof, VkData > prove(tracegen::TraceContainer &&trace)
VkData compute_verification_key(tracegen::TraceContainer &trace)
bool check_circuit(tracegen::TraceContainer &&trace)
simulation::EventsContainer simulate_for_witgen(const ExecutionHints &hints)
void fill_trace_columns(tracegen::TraceContainer &trace, simulation::EventsContainer &&events, const PublicInputs &public_inputs)
tracegen::TraceContainer generate_trace(simulation::EventsContainer &&events, const PublicInputs &public_inputs)
void fill_trace_interactions(tracegen::TraceContainer &trace)
tracegen::TraceContainer generate_precomputed_columns()
void run(uint32_t starting_row=0)
Definition debugger.cpp:76
#define vinfo(...)
Definition log.hpp:80
TestTraceContainer trace
AvmProvingInputs inputs
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