|
| 1 | +#pragma once |
| 2 | +/** |
| 3 | + * @file bbapi_avm.hpp |
| 4 | + * @brief AVM-specific command definitions for the Barretenberg RPC API. |
| 5 | + * |
| 6 | + * This file contains command structures for AVM operations including proving, |
| 7 | + * verification, and circuit checking. When built with bb (non-AVM), these |
| 8 | + * commands return an error response. When built with bb-avm, they work normally. |
| 9 | + */ |
| 10 | +#include "barretenberg/bbapi/bbapi_shared.hpp" |
| 11 | +#include "barretenberg/common/named_union.hpp" |
| 12 | +#include "barretenberg/ecc/curves/bn254/fr.hpp" |
| 13 | +#include "barretenberg/serialize/msgpack.hpp" |
| 14 | +#include <cstdint> |
| 15 | +#include <string> |
| 16 | +#include <vector> |
| 17 | + |
| 18 | +namespace bb::bbapi { |
| 19 | + |
| 20 | +/** |
| 21 | + * @struct AvmStat |
| 22 | + * @brief A single AVM per-stage timing entry. `value_ms` is wall-clock milliseconds captured by |
| 23 | + * bb::avm2::Stats during a prove or check-circuit call. |
| 24 | + */ |
| 25 | +struct AvmStat { |
| 26 | + static constexpr const char MSGPACK_SCHEMA_NAME[] = "AvmStat"; |
| 27 | + |
| 28 | + std::string name; |
| 29 | + uint64_t value_ms; |
| 30 | + SERIALIZATION_FIELDS(name, value_ms); |
| 31 | + bool operator==(const AvmStat&) const = default; |
| 32 | +}; |
| 33 | + |
| 34 | +/** |
| 35 | + * @struct AvmProve |
| 36 | + * @brief Prove an AVM transaction from serialized inputs. |
| 37 | + * The inputs are opaque msgpack bytes of AvmProvingInputs. Callers should call AvmVerify |
| 38 | + * separately if they need to verify the resulting proof. |
| 39 | + */ |
| 40 | +struct AvmProve { |
| 41 | + static constexpr const char MSGPACK_SCHEMA_NAME[] = "AvmProve"; |
| 42 | + |
| 43 | + struct Response { |
| 44 | + static constexpr const char MSGPACK_SCHEMA_NAME[] = "AvmProveResponse"; |
| 45 | + |
| 46 | + std::vector<bb::fr> proof; |
| 47 | + std::vector<AvmStat> stats; |
| 48 | + SERIALIZATION_FIELDS(proof, stats); |
| 49 | + bool operator==(const Response&) const = default; |
| 50 | + }; |
| 51 | + |
| 52 | + std::vector<uint8_t> inputs; |
| 53 | + SERIALIZATION_FIELDS(inputs); |
| 54 | + Response execute(const BBApiRequest& request = {}) &&; |
| 55 | + bool operator==(const AvmProve&) const = default; |
| 56 | +}; |
| 57 | + |
| 58 | +/** |
| 59 | + * @struct AvmVerify |
| 60 | + * @brief Verify an AVM proof against serialized public inputs. |
| 61 | + */ |
| 62 | +struct AvmVerify { |
| 63 | + static constexpr const char MSGPACK_SCHEMA_NAME[] = "AvmVerify"; |
| 64 | + |
| 65 | + struct Response { |
| 66 | + static constexpr const char MSGPACK_SCHEMA_NAME[] = "AvmVerifyResponse"; |
| 67 | + |
| 68 | + bool verified; |
| 69 | + SERIALIZATION_FIELDS(verified); |
| 70 | + bool operator==(const Response&) const = default; |
| 71 | + }; |
| 72 | + |
| 73 | + std::vector<bb::fr> proof; |
| 74 | + std::vector<uint8_t> public_inputs; |
| 75 | + SERIALIZATION_FIELDS(proof, public_inputs); |
| 76 | + Response execute(const BBApiRequest& request = {}) &&; |
| 77 | + bool operator==(const AvmVerify&) const = default; |
| 78 | +}; |
| 79 | + |
| 80 | +/** |
| 81 | + * @struct AvmCheckCircuit |
| 82 | + * @brief Check the AVM circuit from serialized inputs. |
| 83 | + */ |
| 84 | +struct AvmCheckCircuit { |
| 85 | + static constexpr const char MSGPACK_SCHEMA_NAME[] = "AvmCheckCircuit"; |
| 86 | + |
| 87 | + struct Response { |
| 88 | + static constexpr const char MSGPACK_SCHEMA_NAME[] = "AvmCheckCircuitResponse"; |
| 89 | + |
| 90 | + bool passed; |
| 91 | + std::vector<AvmStat> stats; |
| 92 | + SERIALIZATION_FIELDS(passed, stats); |
| 93 | + bool operator==(const Response&) const = default; |
| 94 | + }; |
| 95 | + |
| 96 | + std::vector<uint8_t> inputs; |
| 97 | + SERIALIZATION_FIELDS(inputs); |
| 98 | + Response execute(const BBApiRequest& request = {}) &&; |
| 99 | + bool operator==(const AvmCheckCircuit&) const = default; |
| 100 | +}; |
| 101 | + |
| 102 | +} // namespace bb::bbapi |
0 commit comments