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
13namespace {
14
15std::vector<PublicDataWrite> get_public_data_writes(const PublicInputs& inputs)
16{
18 const auto* public_data_writes_start = inputs.accumulatedData.publicDataWrites.begin();
19 return std::vector<PublicDataWrite>(public_data_writes_start,
20 public_data_writes_start + inputs.accumulatedDataArrayLengths.publicDataWrites);
21}
22
23} // namespace
24
26{
27 // Simulate.
28 info("Simulating...");
29 AvmSimulationHelper simulation_helper;
30
31 auto events = AVM_TRACK_TIME_V(
32 "simulation/all",
33 simulation_helper.simulate_for_witgen(inputs.hints, get_public_data_writes(inputs.publicInputs)));
34
35 // Generate trace.
36 info("Generating trace...");
37 AvmTraceGenHelper tracegen_helper;
38 auto trace =
39 AVM_TRACK_TIME_V("tracegen/all", tracegen_helper.generate_trace(std::move(events), inputs.publicInputs));
40
41 // Prove.
42 info("Proving...");
43 AvmProvingHelper proving_helper;
44 auto [proof, vk] = AVM_TRACK_TIME_V("proving/all", proving_helper.prove(std::move(trace)));
45
46 info("Done!");
47 return { std::move(proof), std::move(vk) };
48}
49
51{
52 // Simulate.
53 info("Simulating...");
54 AvmSimulationHelper simulation_helper;
55
56 auto events = AVM_TRACK_TIME_V(
57 "simulation/all",
58 simulation_helper.simulate_for_witgen(inputs.hints, get_public_data_writes(inputs.publicInputs)));
59
60 // Generate trace.
61 // In contrast to proving, we do this step by step since it's usually more useful to debug
62 // before trying to run the interaction builders.
63 info("Generating trace...");
64 AvmTraceGenHelper tracegen_helper;
66 AVM_TRACK_TIME("tracegen/all", tracegen_helper.fill_trace_columns(trace, std::move(events), inputs.publicInputs));
67
68 // Go into interactive debug mode if requested.
69 if (getenv("AVM_DEBUG") != nullptr) {
70 InteractiveDebugger debugger(trace);
71 debugger.run();
72 }
73
74 AVM_TRACK_TIME("tracegen/all", tracegen_helper.fill_trace_interactions(trace));
75
76 // Check circuit.
77 info("Checking circuit...");
78 AvmProvingHelper proving_helper;
79 return proving_helper.check_circuit(std::move(trace));
80}
81
82bool AvmAPI::verify(const AvmProof& proof, const PublicInputs& pi, const AvmVerificationKey& vk_data)
83{
84 info("Verifying...");
85 AvmProvingHelper proving_helper;
86 return AVM_TRACK_TIME_V("verifing/all", proving_helper.verify(proof, pi, vk_data));
87}
88
90{
91 info("Simulating...");
92 AvmSimulationHelper simulation_helper;
93 AVM_TRACK_TIME("simulation/all", simulation_helper.simulate_fast(hints));
94}
95
96} // namespace bb::avm2
bool check_circuit(const ProvingInputs &inputs)
Definition avm_api.cpp:50
bool verify(const AvmProof &proof, const PublicInputs &pi, const AvmVerificationKey &vk_data)
Definition avm_api.cpp:82
std::vector< uint8_t > AvmVerificationKey
Definition avm_api.hpp:13
AvmProvingHelper::Proof AvmProof
Definition avm_api.hpp:12
void simulate(const ExecutionHints &hints)
Definition avm_api.cpp:89
std::pair< AvmProof, AvmVerificationKey > prove(const ProvingInputs &inputs)
Definition avm_api.cpp:25
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)
void simulate_fast(const ExecutionHints &hints)
simulation::EventsContainer simulate_for_witgen(const ExecutionHints &hints, std::vector< PublicDataWrite > public_data_writes)
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:74
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:18
#define AVM_TRACK_TIME(key, body)
Definition stats.hpp:16
std::array< PublicDataWrite, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX > publicDataWrites
AvmAccumulatedDataArrayLengths accumulatedDataArrayLengths
AvmAccumulatedData accumulatedData