Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
witness.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
10
11namespace bb::stdlib {
12
13// indicates whether a witness index actually contains a constant
14static constexpr uint32_t IS_CONSTANT = UINT32_MAX;
15
16template <typename Builder> class witness_t {
17 public:
18 witness_t() = default;
19
20 witness_t(Builder* parent_context, const bb::fr& in)
21 {
22 context = parent_context;
23 witness = in;
24 witness_index = context->add_variable(witness);
25 }
26
27 witness_t(Builder* parent_context, const bool in)
28 {
29 context = parent_context;
30 if (in) {
32 } else {
34 }
35 witness_index = context->add_variable(witness);
36 }
37
38 witness_t(Builder* parent_context, IntegralOrEnum auto const in)
39 {
40 context = parent_context;
41 witness = bb::fr{ static_cast<uint64_t>(in), 0, 0, 0 }.to_montgomery_form();
42 witness_index = context->add_variable(witness);
43 }
44
45 static witness_t create_constant_witness(Builder* parent_context, const bb::fr& in)
46 {
47 witness_t out(parent_context, in);
48 parent_context->assert_equal_constant(out.witness_index, in, "Failed to create constant witness.");
49 return out;
50 }
51
52 bool is_constant() const { return witness_index == IS_CONSTANT; }
53
55 uint32_t witness_index = IS_CONSTANT;
56 Builder* context = nullptr;
57};
58
59template <typename Builder> class public_witness_t : public witness_t<Builder> {
60 public:
64
65 public_witness_t() = default;
66 public_witness_t(Builder* parent_context, const bb::fr& in)
67 {
68 context = parent_context;
70 witness_index = context->add_public_variable(witness);
71 }
72
73 public_witness_t(Builder* parent_context, const bool in)
74 {
75 context = parent_context;
76 if (in) {
78 } else {
80 }
81 witness_index = context->add_public_variable(witness);
82 }
83
84 template <typename T> public_witness_t(Builder* parent_context, T const in)
85 {
86 context = parent_context;
87 witness = bb::fr{ static_cast<uint64_t>(in), 0, 0, 0 }.to_montgomery_form();
88 witness_index = context->add_public_variable(witness);
89 }
90};
91
92} // namespace bb::stdlib
public_witness_t(Builder *parent_context, T const in)
Definition witness.hpp:84
public_witness_t(Builder *parent_context, const bb::fr &in)
Definition witness.hpp:66
public_witness_t(Builder *parent_context, const bool in)
Definition witness.hpp:73
static witness_t create_constant_witness(Builder *parent_context, const bb::fr &in)
Definition witness.hpp:45
witness_t(Builder *parent_context, const bb::fr &in)
Definition witness.hpp:20
witness_t(Builder *parent_context, const bool in)
Definition witness.hpp:27
witness_t(Builder *parent_context, IntegralOrEnum auto const in)
Definition witness.hpp:38
bool is_constant() const
Definition witness.hpp:52
static constexpr field one()
BB_INLINE constexpr field to_montgomery_form() const noexcept
static BB_INLINE void __copy(const field &a, field &r) noexcept
static constexpr field zero()