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: Complete, 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
12#include <cstdint>
13namespace bb::stdlib {
14
18template <typename ComponentType>
19concept IsSerializableToPublicInputs = requires(ComponentType component) {
20 { component.set_public() } -> std::same_as<uint32_t>;
21 { ComponentType::PUBLIC_INPUTS_SIZE } -> std::convertible_to<size_t>;
22};
23
27template <typename T, typename Fr>
29 { T::reconstruct_from_public(limbs) } -> std::same_as<T>;
30};
31
37template <typename ComponentType>
40 using Builder = ComponentType::Builder;
43
44 static constexpr size_t COMPONENT_SIZE = ComponentType::PUBLIC_INPUTS_SIZE;
45
46 public:
48
49 // Set witness indices of the component to public; return key indicating location of the component in the pub inputs
50 static Key set(const ComponentType& component)
51 {
52 Key key;
53 key.start_idx = component.set_public();
54 return key;
55 }
56
57 // Reconstruct the component from the public inputs and the key indicating its location
58 static ComponentType reconstruct(const std::vector<Fr>& public_inputs, const Key& key)
59 {
60 // Ensure that the key has been set
61 if (!key.is_set()) {
62 throw_or_abort("ERROR: Trying to construct a PublicInputComponent from an invalid key!");
63 }
64
65 // Use the provided key to extract the limbs of the component from the public inputs then reconstruct it
66 if (key.start_idx + COMPONENT_SIZE > public_inputs.size()) {
67 throw_or_abort("PublicInputComponent::reconstruct: public_inputs vector too small");
68 }
69 std::span<const Fr, COMPONENT_SIZE> limbs{ public_inputs.data() + key.start_idx, COMPONENT_SIZE };
70
71 // Use reconstruct_from_public if available (for composite types like OpeningClaim),
72 // otherwise use Codec (for primitives and array-like types like PairingPoints)
74 return ComponentType::reconstruct_from_public(limbs);
75 } else {
76 return Codec::template deserialize_from_fields<ComponentType>(limbs);
77 }
78 }
79};
80
81} // namespace bb::stdlib
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< Fr > &public_inputs, const Key &key)
static Key set(const ComponentType &component)
Check if a type has reconstruct_from_public method.
A concept for types that can be serialized to public inputs.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
StdlibCodec for in-circuit (recursive) verification transcript handling.
void throw_or_abort(std::string const &err)