Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
address.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
14
15// TODO(https://github.com/AztecProtocol/barretenberg/issues/376): Establish whether this type should be here at all.
16namespace bb::stdlib {
17
18// Native type
19class address {
20 public:
22
23 address() noexcept { address_ = fr(); }
24
25 address(address const& other)
26 : address_(other.address_) {};
27
29 : address_(address) {};
30
33
34 address(int const& address)
35 : address_(fr(address)) {};
36
37 operator fr() { return address_; }
38
39 operator fr() const { return address_; }
40
41 constexpr bool operator==(address const& other) const { return this->address_ == other.address_; }
42
43 friend std::ostream& operator<<(std::ostream& os, address const& v) { return os << v.address_; }
44
45 fr to_field() const { return address_; }
46
47 // delegate serialization to field
48 void msgpack_pack(auto& packer) const { address_.msgpack_pack(packer); }
49 void msgpack_unpack(auto const& o) { address_.msgpack_unpack(o); }
50 // help our msgpack schema compiler with this buffer alias (as far as wire representation is concerned) class
51 void msgpack_schema(auto& packer) const { packer.pack_alias("Address", "bin32"); }
52};
53
54template <typename B> void read(B& it, address& addr)
55{
56 using serialize::read;
57 fr address_field;
58 read(it, address_field);
59 addr = address(address_field);
60}
61
62template <typename B> void write(B& buf, address const& addr)
63{
64 using serialize::write;
65 write(buf, addr.address_);
66}
67
68// Circuit type
69template <typename Builder> class address_t {
70 public:
73
74 address_t() = default;
75
77 : address_(other.address_)
78 , context_(other.context_) {};
79
83
86 , context_(nullptr) {};
87
88 address_t(int const& address)
90 , context_(nullptr) {};
91
93 {
94 address_ = field_t(witness);
95 context_ = witness.context;
96 }
97
99 {
100 address_ = other.address_;
101 context_ = other.context_;
102 return *this;
103 }
104
105 bool_t<Builder> operator==(const address_t& other) const { return this->to_field() == other.to_field(); }
106
107 bool_t<Builder> operator!=(const address_t& other) const { return this->to_field() != other.to_field(); }
108
110
111 fr get_value() const { return address_.get_value(); };
112
113 void assert_equal(const address_t& rhs, std::string const& msg = "address_t::assert_equal") const
114 {
116 };
117
119 std::string const& msg = "address_t::assert_is_in_set") const
120 {
122 for (const auto& e : set) {
123 field_set.push_back(e.address_);
124 }
125 address_.assert_is_in_set(field_set, msg);
126 }
127
128 static address_t conditional_assign(const bool_t<Builder>& predicate, const address_t& lhs, const address_t& rhs)
129 {
130 return field_t<Builder>::conditional_assign(predicate, lhs.address_, rhs.address_);
131 };
132
134 {
135 // TODO: Dummy logic, for now. Proper derivation undecided.
138 return address_t<Builder>(public_key.x);
139 }
140
141 friend std::ostream& operator<<(std::ostream& os, address_t<Builder> const& v) { return os << v.address_; }
142};
143
144} // namespace bb::stdlib
static constexpr affine_element affine_one
Definition group.hpp:48
static address_t conditional_assign(const bool_t< Builder > &predicate, const address_t &lhs, const address_t &rhs)
Definition address.hpp:128
field_t< Builder > address_
Definition address.hpp:71
friend std::ostream & operator<<(std::ostream &os, address_t< Builder > const &v)
Definition address.hpp:141
field_t< Builder > to_field() const
Definition address.hpp:109
address_t< Builder > & operator=(const address_t< Builder > &other)
Definition address.hpp:98
address_t(field_t< Builder > const &address)
Definition address.hpp:80
void assert_equal(const address_t &rhs, std::string const &msg="address_t::assert_equal") const
Definition address.hpp:113
address_t(witness_t< Builder > const &witness)
Definition address.hpp:92
address_t(int const &address)
Definition address.hpp:88
address_t(uint256_t const &address)
Definition address.hpp:84
void assert_is_in_set(const std::vector< address_t > &set, std::string const &msg="address_t::assert_is_in_set") const
Definition address.hpp:118
address_t(address_t< Builder > const &other)
Definition address.hpp:76
bool_t< Builder > operator==(const address_t &other) const
Definition address.hpp:105
bool_t< Builder > operator!=(const address_t &other) const
Definition address.hpp:107
static address_t< Builder > derive_from_private_key(field_t< Builder > const &private_key)
Definition address.hpp:133
void msgpack_schema(auto &packer) const
Definition address.hpp:51
void msgpack_pack(auto &packer) const
Definition address.hpp:48
address(int const &address)
Definition address.hpp:34
address(uint256_t const &address)
Definition address.hpp:31
friend std::ostream & operator<<(std::ostream &os, address const &v)
Definition address.hpp:43
address(address const &other)
Definition address.hpp:25
fr to_field() const
Definition address.hpp:45
address() noexcept
Definition address.hpp:23
constexpr bool operator==(address const &other) const
Definition address.hpp:41
address(fr const &address)
Definition address.hpp:28
void msgpack_unpack(auto const &o)
Definition address.hpp:49
Implements boolean logic in-circuit.
Definition bool.hpp:59
cycle_group represents a group Element of the proving system's embedded curve i.e....
static cycle_scalar create_from_bn254_scalar(const field_t &_in, bool skip_primality_test=false)
Use when we want to multiply a group element by a string of bits of known size. N....
void assert_is_in_set(const std::vector< field_t > &set, std::string const &msg="field_t::assert_not_in_set") const
Constrain *this \in set by enforcing that P(X) = \prod_{s \in set} (X - s) is 0 at X = *this.
Definition field.cpp:974
void assert_equal(const field_t &rhs, std::string const &msg="field_t::assert_equal") const
Copy constraint: constrain that *this field is equal to rhs element.
Definition field.cpp:929
static field_t conditional_assign(const bool_t< Builder > &predicate, const field_t &lhs, const field_t &rhs)
If predicate == true then return lhs, else return rhs.
Definition field.cpp:884
bb::fr get_value() const
Given a := *this, compute its value given by a.v * a.mul + a.add.
Definition field.cpp:827
StrictMock< MockContext > context
uint8_t const * buf
Definition data_store.hpp:9
void read(B &it, field2< base_field, Params > &value)
field< Bn254FrParams > fr
Definition fr.hpp:174
void write(B &buf, field2< base_field, Params > const &value)
void read(auto &it, msgpack_concepts::HasMsgPack auto &obj)
Automatically derived read for any object that defines .msgpack() (implicitly defined by MSGPACK_FIEL...
void write(auto &buf, const msgpack_concepts::HasMsgPack auto &obj)
Automatically derived write for any object that defines .msgpack() (implicitly defined by MSGPACK_FIE...
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
void msgpack_pack(auto &packer) const
void msgpack_unpack(auto o)