barretenberg
Loading...
Searching...
No Matches
packed_byte_array.hpp
1#pragma once
2#include "../bool/bool.hpp"
3#include "../byte_array/byte_array.hpp"
4#include "../circuit_builders/circuit_builders_fwd.hpp"
5#include "../field/field.hpp"
6
7namespace proof_system::plonk {
8namespace stdlib {
9
10template <typename Builder> class packed_byte_array {
11 private:
16
17 public:
18 packed_byte_array(Builder* parent_context, size_t const num_bytes = 0);
19
20 // THIS CTOR ASSUMES INPUT ELEMENTS HAVE ALREADY BEEN REDUCED TO <16 BYTES PER ELEMENT
21 // Use ::from_field_element_vector for raw vectors of unreduced prime field elements
22 packed_byte_array(const std::vector<field_pt>& input, const size_t bytes_per_input = BYTES_PER_ELEMENT);
23 packed_byte_array(Builder* parent_context, const std::vector<uint8_t>& input);
24 packed_byte_array(Builder* parent_context, const std::string& input);
25 packed_byte_array(const byte_array_pt& input);
26
29
30 packed_byte_array& operator=(const packed_byte_array& other);
31 packed_byte_array& operator=(packed_byte_array&& other);
32
33 operator byte_array_pt() const;
34
35 std::vector<field_pt> to_unverified_byte_slices(const size_t bytes_per_slice) const;
36 std::vector<field_pt> get_limbs() const { return limbs; }
37
38 static packed_byte_array from_field_element_vector(const std::vector<field_pt>& input);
39
40 void append(const field_pt& to_append, const size_t bytes_to_append);
41
42 size_t size() const { return num_bytes; }
43
44 Builder* get_context() const { return context; }
45
46 std::string get_value() const;
47
48 private:
49 static constexpr uint64_t BYTES_PER_ELEMENT = 16;
50 Builder* context;
51 size_t num_bytes;
52 std::vector<field_pt> limbs;
53};
54
55template <typename Builder> inline std::ostream& operator<<(std::ostream& os, packed_byte_array<Builder> const& arr)
56{
57 std::ios_base::fmtflags f(os.flags());
58 os << "[" << std::hex << std::setfill('0');
59 for (auto byte : arr.get_value()) {
60 os << ' ' << std::setw(2) << +(unsigned char)byte;
61 }
62 os << " ]";
63 os.flags(f);
64 return os;
65}
66
67EXTERN_STDLIB_TYPE(packed_byte_array);
68
69} // namespace stdlib
70} // namespace proof_system::plonk
Definition: standard_circuit_builder.hpp:12
Definition: byte_array.hpp:9
Definition: field.hpp:10
Definition: packed_byte_array.hpp:10
Definition: witness.hpp:10
Definition: widget.bench.cpp:13