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: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#pragma once
8
11#include <cstdint>
12namespace bb::stdlib {
13
20template <typename ComponentType>
22 ComponentType component,
23 std::span<stdlib::field_t<typename ComponentType::Builder>, ComponentType::PUBLIC_INPUTS_SIZE> public_inputs) {
24 { // A method to set the limbs of the object to public and return the index of the first limb in public inputs
25 component.set_public()
27 { // A method to reconstruct the object from the limbs stored in public inputs
28 ComponentType::reconstruct_from_public(public_inputs)
30 { // A constant defining the number of limbs needed to represent the object in the public inputs
31 ComponentType::PUBLIC_INPUTS_SIZE
33};
34
40template <typename ComponentType>
43 using Builder = ComponentType::Builder;
44 using Fr = stdlib::field_t<Builder>; // type for native field elements in the circuit (i.e. the type for "limbs")
45
46 static constexpr uint32_t COMPONENT_SIZE = ComponentType::PUBLIC_INPUTS_SIZE;
47
48 public:
50
51 // Set witness indices of the component to public; return key indicating location of the component in the pub inputs
52 static Key set(const ComponentType& component)
53 {
54 Key key;
55 key.start_idx = component.set_public();
56 return key;
57 }
58
59 // Reconstruct the component from the public inputs and the key indicating its location
60 static ComponentType reconstruct(const std::vector<Fr>& public_inputs, const Key& key)
61 {
62 // Ensure that the key has been set
63 if (!key.is_set()) {
64 throw_or_abort("ERROR: Trying to construct a PublicInputComponent from an invalid key!");
65 }
66
67 // Use the provided key to extract the limbs of the component from the public inputs then reconstruct it
69 public_inputs.size(),
70 "PublicInputComponent cannot be reconstructed - PublicInputComponentKey start_idx out of bounds");
71 std::span<const Fr, COMPONENT_SIZE> limbs{ public_inputs.data() + key.start_idx, COMPONENT_SIZE };
72 return ComponentType::reconstruct_from_public(limbs);
73 }
74};
75
76} // namespace bb::stdlib
#define BB_ASSERT_LTE(left, right,...)
Definition assert.hpp:129
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)
A concept defining requirements for types that are to be serialized to and from the public inputs of ...
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
void throw_or_abort(std::string const &err)