Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
public_input_component.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Completed, auditors: [Sergei], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
8
13#include <cstdint>
14#include <span>
15namespace bb {
16
20template <typename ComponentType>
22 { ComponentType::PUBLIC_INPUTS_SIZE } -> std::convertible_to<size_t>;
23};
24
28template <typename T>
30 { T::reconstruct_from_public(limbs) } -> std::same_as<T>;
31};
32
38template <typename ComponentType>
41 using Codec = FrCodec;
42 static constexpr uint32_t COMPONENT_SIZE = ComponentType::PUBLIC_INPUTS_SIZE;
43
44 public:
46
47 // Reconstruct the component from the public inputs and the key indicating its location
48 static ComponentType reconstruct(const std::vector<bb::fr>& public_inputs, const Key& key)
49 {
50 // Ensure that the key has been set
51 if (!key.is_set()) {
52 throw_or_abort("ERROR: Trying to construct a PublicInputComponent from an invalid key!");
53 }
54
55 // Use the provided key to extract the limbs of the component from the public inputs then reconstruct it
57 public_inputs.size(),
58 "PublicInputComponent cannot be reconstructed - PublicInputComponentKey start_idx out of bounds");
59 std::span<const bb::fr, COMPONENT_SIZE> limbs{ public_inputs.data() + key.start_idx, COMPONENT_SIZE };
60
61 // Use reconstruct_from_public if available (for composite types like OpeningClaim),
62 // otherwise use Codec (for primitives and array-like types like PairingPoints)
64 return ComponentType::reconstruct_from_public(limbs);
65 } else {
66 return Codec::deserialize_from_fields<ComponentType>(limbs);
67 }
68 }
69};
70
71} // namespace bb
#define BB_ASSERT_LTE(left, right,...)
Definition assert.hpp:158
A wrapper class for deserializing objects from the public inputs of a circuit.
static constexpr uint32_t COMPONENT_SIZE
static ComponentType reconstruct(const std::vector< bb::fr > &public_inputs, const Key &key)
Check if a type has reconstruct_from_public method.
A concept for types that can be deserialized from public inputs.
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
void throw_or_abort(std::string const &err)