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 info("Simulating...");
17 AvmSimulationHelper simulation_helper(inputs.hints);
18 auto events = AVM_TRACK_TIME_V("simulation/all", simulation_helper.simulate());
19
20 // Generate trace.
21 info("Generating trace...");
22 AvmTraceGenHelper tracegen_helper;
23 auto trace =
24 AVM_TRACK_TIME_V("tracegen/all", tracegen_helper.generate_trace(std::move(events), inputs.publicInputs));
25
26 // Prove.
27 info("Proving...");
28 AvmProvingHelper proving_helper;
29 auto [proof, vk] = AVM_TRACK_TIME_V("proving/all", proving_helper.prove(std::move(trace)));
30
31 info("Done!");
32 return { std::move(proof), std::move(vk) };
33}
34
36{
37 // Simulate.
38 info("Simulating...");
39 AvmSimulationHelper simulation_helper(inputs.hints);
40 auto events = AVM_TRACK_TIME_V("simulation/all", simulation_helper.simulate());
41
42 // Generate trace.
43 // In contrast to proving, we do this step by step since it's usually more useful to debug
44 // before trying to run the interaction builders.
45 info("Generating trace...");
46 AvmTraceGenHelper tracegen_helper;
48 AVM_TRACK_TIME("tracegen/all", tracegen_helper.fill_trace_columns(trace, std::move(events), inputs.publicInputs));
49
50 // Go into interactive debug mode if requested.
51 if (getenv("AVM_DEBUG") != nullptr) {
52 InteractiveDebugger debugger(trace);
53 debugger.run();
54 }
55
56 AVM_TRACK_TIME("tracegen/all", tracegen_helper.fill_trace_interactions(trace));
57
58 // Check circuit.
59 info("Checking circuit...");
60 AvmProvingHelper proving_helper;
61 return proving_helper.check_circuit(std::move(trace));
62}
63
64bool AvmAPI::verify(const AvmProof& proof, const PublicInputs& pi, const AvmVerificationKey& vk_data)
65{
66 info("Verifying...");
67 AvmProvingHelper proving_helper;
68 return AVM_TRACK_TIME_V("verifing/all", proving_helper.verify(proof, pi, vk_data));
69}
70
71} // namespace bb::avm2
bool check_circuit(const ProvingInputs &inputs)
Definition avm_api.cpp:35
bool verify(const AvmProof &proof, const PublicInputs &pi, const AvmVerificationKey &vk_data)
Definition avm_api.cpp:64
std::vector< uint8_t > AvmVerificationKey
Definition avm_api.hpp:13
AvmProvingHelper::Proof AvmProof
Definition avm_api.hpp:12
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)
bool check_circuit(tracegen::TraceContainer &&trace)
simulation::EventsContainer simulate()
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)
void run(uint32_t starting_row=0)
Definition debugger.cpp:76
void info(Args... args)
Definition log.hpp:70
TestTraceContainer trace
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:19
#define AVM_TRACK_TIME(key, body)
Definition stats.hpp:17