Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
special_public_inputs_test_serde.hpp
Go to the documentation of this file.
1#pragma once
2
9
11
18 public:
23 using NativeTableCommitments = std::array<NativeG1, MegaCircuitBuilder::NUM_WIRES>;
24
25 static constexpr size_t PUBLIC_INPUTS_SIZE = KERNEL_PUBLIC_INPUTS_SIZE;
26
32
40 static KernelIOSerde from_proof(const std::vector<NativeFF>& proof, size_t num_public_inputs)
41 {
42 KernelIOSerde result;
43 // KernelIO is at the end of public inputs, which are at the start of the proof
44 size_t idx = num_public_inputs - PUBLIC_INPUTS_SIZE;
45
46 // Each G1 point is 4 fr elements (2 limbs for x, 2 limbs for y) using 136-bit limb encoding
47 auto deserialize_point = [&]() {
49 NativeG1::PUBLIC_INPUTS_SIZE);
50 idx += NativeG1::PUBLIC_INPUTS_SIZE;
51 return FrCodec::deserialize_from_fields<NativeG1>(limbs);
52 };
53
54 result.pairing_inputs.P0() = deserialize_point();
55 result.pairing_inputs.P1() = deserialize_point();
56 result.kernel_return_data = deserialize_point();
57 result.app_return_data = deserialize_point();
58 for (auto& commitment : result.ecc_op_tables) {
59 commitment = deserialize_point();
60 }
61 result.output_hn_accum_hash = proof[idx];
62
63 return result;
64 }
65
71 void to_proof(std::vector<NativeFF>& proof, size_t num_public_inputs) const
72 {
73 // KernelIO is at the end of public inputs, which are at the start of the proof
74 size_t idx = num_public_inputs - PUBLIC_INPUTS_SIZE;
75
76 // Serialize fq to 2 fr limbs using 136-bit encoding (matching FrCodec)
77 auto serialize_fq = [&](const NativeFq& fq_val) {
78 constexpr uint64_t NUM_LIMB_BITS = 2 * NUM_LIMB_BITS_IN_FIELD_SIMULATION; // 136 bits
79 constexpr uint256_t LIMB_MASK = (uint256_t(1) << NUM_LIMB_BITS) - 1;
80 uint256_t val = static_cast<uint256_t>(fq_val);
81 proof[idx++] = NativeFF(val & LIMB_MASK);
82 proof[idx++] = NativeFF((val >> NUM_LIMB_BITS) & LIMB_MASK);
83 };
84
85 auto serialize_point = [&](const NativeG1& point) {
86 serialize_fq(point.x);
87 serialize_fq(point.y);
88 };
89
90 serialize_point(pairing_inputs.P0());
91 serialize_point(pairing_inputs.P1());
92 serialize_point(kernel_return_data);
93 serialize_point(app_return_data);
94 for (const auto& commitment : ecc_op_tables) {
95 serialize_point(commitment);
96 }
97 proof[idx] = output_hn_accum_hash;
98 }
99};
100
108 public:
113 using NativeTableCommitments = std::array<NativeG1, MegaCircuitBuilder::NUM_WIRES>;
114
115 static constexpr size_t PUBLIC_INPUTS_SIZE = HIDING_KERNEL_PUBLIC_INPUTS_SIZE;
116
120
126 static HidingKernelIOSerde from_proof(const std::vector<NativeFF>& proof, size_t num_public_inputs)
127 {
128 HidingKernelIOSerde result;
129 size_t idx = num_public_inputs - PUBLIC_INPUTS_SIZE;
130
131 auto deserialize_point = [&]() {
133 NativeG1::PUBLIC_INPUTS_SIZE);
134 idx += NativeG1::PUBLIC_INPUTS_SIZE;
135 return FrCodec::deserialize_from_fields<NativeG1>(limbs);
136 };
137
138 result.pairing_inputs.P0() = deserialize_point();
139 result.pairing_inputs.P1() = deserialize_point();
140 result.kernel_return_data = deserialize_point();
141 for (auto& commitment : result.ecc_op_tables) {
142 commitment = deserialize_point();
143 }
144
145 return result;
146 }
147
153 void to_proof(std::vector<NativeFF>& proof, size_t num_public_inputs) const
154 {
155 size_t idx = num_public_inputs - PUBLIC_INPUTS_SIZE;
156
157 auto serialize_fq = [&](const NativeFq& fq_val) {
158 constexpr uint64_t NUM_LIMB_BITS = 2 * NUM_LIMB_BITS_IN_FIELD_SIMULATION;
159 constexpr uint256_t LIMB_MASK = (uint256_t(1) << NUM_LIMB_BITS) - 1;
160 uint256_t val = static_cast<uint256_t>(fq_val);
161 proof[idx++] = NativeFF(val & LIMB_MASK);
162 proof[idx++] = NativeFF((val >> NUM_LIMB_BITS) & LIMB_MASK);
163 };
164
165 auto serialize_point = [&](const NativeG1& point) {
166 serialize_fq(point.x);
167 serialize_fq(point.y);
168 };
169
170 serialize_point(pairing_inputs.P0());
171 serialize_point(pairing_inputs.P1());
172 serialize_point(kernel_return_data);
173 for (const auto& commitment : ecc_op_tables) {
174 serialize_point(commitment);
175 }
176 }
177};
178
186 public:
191
192 static constexpr size_t PUBLIC_INPUTS_SIZE = DEFAULT_PUBLIC_INPUTS_SIZE; // 16 fr elements
193
195
203 static AppIOSerde from_proof(const std::vector<NativeFF>& proof, size_t num_public_inputs)
204 {
205 AppIOSerde result;
206 // AppIO is at the end of public inputs, which are at the start of the proof
207 size_t idx = num_public_inputs - PUBLIC_INPUTS_SIZE;
208
209 // Each G1 point is 4 fr elements (2 limbs for x, 2 limbs for y) using 136-bit limb encoding
210 auto deserialize_point = [&]() {
212 NativeG1::PUBLIC_INPUTS_SIZE);
213 idx += NativeG1::PUBLIC_INPUTS_SIZE;
214 return FrCodec::deserialize_from_fields<NativeG1>(limbs);
215 };
216
217 result.pairing_inputs.P0() = deserialize_point();
218 result.pairing_inputs.P1() = deserialize_point();
219
220 return result;
221 }
222
228 void to_proof(std::vector<NativeFF>& proof, size_t num_public_inputs) const
229 {
230 // AppIO is at the end of public inputs, which are at the start of the proof
231 size_t idx = num_public_inputs - PUBLIC_INPUTS_SIZE;
232
233 auto serialize_fq = [&](const NativeFq& fq_val) {
234 constexpr uint64_t NUM_LIMB_BITS = 2 * NUM_LIMB_BITS_IN_FIELD_SIMULATION;
235 constexpr uint256_t LIMB_MASK = (uint256_t(1) << NUM_LIMB_BITS) - 1;
236 uint256_t val = static_cast<uint256_t>(fq_val);
237 proof[idx++] = NativeFF(val & LIMB_MASK);
238 proof[idx++] = NativeFF((val >> NUM_LIMB_BITS) & LIMB_MASK);
239 };
240
241 auto serialize_point = [&](const NativeG1& point) {
242 serialize_fq(point.x);
243 serialize_fq(point.y);
244 };
245
246 serialize_point(pairing_inputs.P0());
247 serialize_point(pairing_inputs.P1());
248 }
249};
250
251} // namespace bb::stdlib::recursion::honk
bb::fq BaseField
Definition bn254.hpp:19
typename Group::affine_element AffineElement
Definition bn254.hpp:22
Native representation and serde for AppIO public inputs.
void to_proof(std::vector< NativeFF > &proof, size_t num_public_inputs) const
Serialize AppIO back to a proof vector.
static AppIOSerde from_proof(const std::vector< NativeFF > &proof, size_t num_public_inputs)
Deserialize AppIO from a proof vector.
Native representation and serde for HidingKernelIO public inputs.
void to_proof(std::vector< NativeFF > &proof, size_t num_public_inputs) const
Serialize HidingKernelIO back to a proof vector.
std::array< NativeG1, MegaCircuitBuilder::NUM_WIRES > NativeTableCommitments
static HidingKernelIOSerde from_proof(const std::vector< NativeFF > &proof, size_t num_public_inputs)
Deserialize HidingKernelIO from a proof vector.
For test purposes only: Native representation and serde for KernelIO public inputs
std::array< NativeG1, MegaCircuitBuilder::NUM_WIRES > NativeTableCommitments
void to_proof(std::vector< NativeFF > &proof, size_t num_public_inputs) const
Serialize KernelIO back to a proof vector.
static KernelIOSerde from_proof(const std::vector< NativeFF > &proof, size_t num_public_inputs)
Deserialize KernelIO from a proof vector.
field< Bn254FrParams > fr
Definition fr.hpp:155
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13