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
8
10
17 public:
22 using NativeTableCommitments = std::array<NativeG1, MegaCircuitBuilder::NUM_WIRES>;
23
24 static constexpr size_t PUBLIC_INPUTS_SIZE = KERNEL_PUBLIC_INPUTS_SIZE;
25
31
39 static KernelIOSerde from_proof(const std::vector<NativeFF>& proof, size_t num_public_inputs)
40 {
41 KernelIOSerde result;
42 // KernelIO is at the end of public inputs, which are at the start of the proof
43 size_t idx = num_public_inputs - PUBLIC_INPUTS_SIZE;
44
45 // Each G1 point is 8 fr elements (4 limbs for x, 4 limbs for y) using 68-bit limb encoding
46 auto deserialize_point = [&]() {
48 NativeG1::PUBLIC_INPUTS_SIZE);
49 idx += NativeG1::PUBLIC_INPUTS_SIZE;
50 return NativeG1::reconstruct_from_public(limbs);
51 };
52
53 result.pairing_inputs.P0 = deserialize_point();
54 result.pairing_inputs.P1 = deserialize_point();
55 result.kernel_return_data = deserialize_point();
56 result.app_return_data = deserialize_point();
57 for (auto& commitment : result.ecc_op_tables) {
58 commitment = deserialize_point();
59 }
60 result.output_hn_accum_hash = proof[idx];
61
62 return result;
63 }
64
70 void to_proof(std::vector<NativeFF>& proof, size_t num_public_inputs) const
71 {
72 // KernelIO is at the end of public inputs, which are at the start of the proof
73 size_t idx = num_public_inputs - PUBLIC_INPUTS_SIZE;
74
75 // Serialize fq to 4 fr limbs using 68-bit encoding (matching reconstruct_from_public)
76 auto serialize_fq = [&](const NativeFq& fq_val) {
77 constexpr uint64_t NUM_LIMB_BITS = NUM_LIMB_BITS_IN_FIELD_SIMULATION; // 68 bits
78 constexpr uint256_t LIMB_MASK = (uint256_t(1) << NUM_LIMB_BITS) - 1;
79 uint256_t val = static_cast<uint256_t>(fq_val);
80 proof[idx++] = NativeFF(val & LIMB_MASK);
81 proof[idx++] = NativeFF((val >> NUM_LIMB_BITS) & LIMB_MASK);
82 proof[idx++] = NativeFF((val >> (NUM_LIMB_BITS * 2)) & LIMB_MASK);
83 proof[idx++] = NativeFF((val >> (NUM_LIMB_BITS * 3)) & LIMB_MASK);
84 };
85
86 auto serialize_point = [&](const NativeG1& point) {
87 serialize_fq(point.x);
88 serialize_fq(point.y);
89 };
90
91 serialize_point(pairing_inputs.P0);
92 serialize_point(pairing_inputs.P1);
93 serialize_point(kernel_return_data);
94 serialize_point(app_return_data);
95 for (const auto& commitment : ecc_op_tables) {
96 serialize_point(commitment);
97 }
98 proof[idx] = output_hn_accum_hash;
99 }
100};
101
109 public:
114 using NativeTableCommitments = std::array<NativeG1, MegaCircuitBuilder::NUM_WIRES>;
115
116 static constexpr size_t PUBLIC_INPUTS_SIZE = HIDING_KERNEL_PUBLIC_INPUTS_SIZE;
117
121
127 static HidingKernelIOSerde from_proof(const std::vector<NativeFF>& proof, size_t num_public_inputs)
128 {
129 HidingKernelIOSerde result;
130 size_t idx = num_public_inputs - PUBLIC_INPUTS_SIZE;
131
132 auto deserialize_point = [&]() {
134 NativeG1::PUBLIC_INPUTS_SIZE);
135 idx += NativeG1::PUBLIC_INPUTS_SIZE;
136 return NativeG1::reconstruct_from_public(limbs);
137 };
138
139 result.pairing_inputs.P0 = deserialize_point();
140 result.pairing_inputs.P1 = deserialize_point();
141 result.kernel_return_data = deserialize_point();
142 for (auto& commitment : result.ecc_op_tables) {
143 commitment = deserialize_point();
144 }
145
146 return result;
147 }
148
154 void to_proof(std::vector<NativeFF>& proof, size_t num_public_inputs) const
155 {
156 size_t idx = num_public_inputs - PUBLIC_INPUTS_SIZE;
157
158 auto serialize_fq = [&](const NativeFq& fq_val) {
159 constexpr uint64_t NUM_LIMB_BITS = NUM_LIMB_BITS_IN_FIELD_SIMULATION;
160 constexpr uint256_t LIMB_MASK = (uint256_t(1) << NUM_LIMB_BITS) - 1;
161 uint256_t val = static_cast<uint256_t>(fq_val);
162 proof[idx++] = NativeFF(val & LIMB_MASK);
163 proof[idx++] = NativeFF((val >> NUM_LIMB_BITS) & LIMB_MASK);
164 proof[idx++] = NativeFF((val >> (NUM_LIMB_BITS * 2)) & LIMB_MASK);
165 proof[idx++] = NativeFF((val >> (NUM_LIMB_BITS * 3)) & LIMB_MASK);
166 };
167
168 auto serialize_point = [&](const NativeG1& point) {
169 serialize_fq(point.x);
170 serialize_fq(point.y);
171 };
172
173 serialize_point(pairing_inputs.P0);
174 serialize_point(pairing_inputs.P1);
175 serialize_point(kernel_return_data);
176 for (const auto& commitment : ecc_op_tables) {
177 serialize_point(commitment);
178 }
179 }
180};
181
189 public:
194
195 static constexpr size_t PUBLIC_INPUTS_SIZE = DEFAULT_PUBLIC_INPUTS_SIZE; // 16 fr elements
196
198
206 static AppIOSerde from_proof(const std::vector<NativeFF>& proof, size_t num_public_inputs)
207 {
208 AppIOSerde result;
209 // AppIO is at the end of public inputs, which are at the start of the proof
210 size_t idx = num_public_inputs - PUBLIC_INPUTS_SIZE;
211
212 // Each G1 point is 8 fr elements (4 limbs for x, 4 limbs for y) using 68-bit limb encoding
213 auto deserialize_point = [&]() {
215 NativeG1::PUBLIC_INPUTS_SIZE);
216 idx += NativeG1::PUBLIC_INPUTS_SIZE;
217 return NativeG1::reconstruct_from_public(limbs);
218 };
219
220 result.pairing_inputs.P0 = deserialize_point();
221 result.pairing_inputs.P1 = deserialize_point();
222
223 return result;
224 }
225
231 void to_proof(std::vector<NativeFF>& proof, size_t num_public_inputs) const
232 {
233 // AppIO is at the end of public inputs, which are at the start of the proof
234 size_t idx = num_public_inputs - PUBLIC_INPUTS_SIZE;
235
236 auto serialize_fq = [&](const NativeFq& fq_val) {
237 constexpr uint64_t NUM_LIMB_BITS = NUM_LIMB_BITS_IN_FIELD_SIMULATION;
238 constexpr uint256_t LIMB_MASK = (uint256_t(1) << NUM_LIMB_BITS) - 1;
239 uint256_t val = static_cast<uint256_t>(fq_val);
240 proof[idx++] = NativeFF(val & LIMB_MASK);
241 proof[idx++] = NativeFF((val >> NUM_LIMB_BITS) & LIMB_MASK);
242 proof[idx++] = NativeFF((val >> (NUM_LIMB_BITS * 2)) & LIMB_MASK);
243 proof[idx++] = NativeFF((val >> (NUM_LIMB_BITS * 3)) & LIMB_MASK);
244 };
245
246 auto serialize_point = [&](const NativeG1& point) {
247 serialize_fq(point.x);
248 serialize_fq(point.y);
249 };
250
251 serialize_point(pairing_inputs.P0);
252 serialize_point(pairing_inputs.P1);
253 }
254};
255
256} // 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:174
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13