barretenberg
Loading...
Searching...
No Matches
aggregation_state.hpp
1#pragma once
2#include "../../primitives/field/field.hpp"
3
4namespace proof_system::plonk {
5namespace stdlib {
6namespace recursion {
7
15template <typename Curve> struct aggregation_state {
16 typename Curve::Group P0;
17 typename Curve::Group P1;
18
19 // The public inputs of the inner circuit are now private inputs of the outer circuit!
20 std::vector<typename Curve::ScalarField> public_inputs;
21 std::vector<uint32_t> proof_witness_indices;
22 bool has_data = false;
23
24 typename Curve::bool_ct operator==(aggregation_state const& other) const
25 {
26 return P0 == other.P0 && P1 == other.P1 && public_inputs == other.public_inputs &&
27 proof_witness_indices == other.proof_witness_indices;
28 // has_data == other.has_data; can't compare as native
29 };
30
37 {
38 auto* context = P0.get_context();
39 context->add_recursive_proof(proof_witness_indices);
40 }
41
42 void assign_object_to_proof_outputs()
43 {
44 if (proof_witness_indices.size() == 0) {
45 std::cerr << "warning. calling `assign_object_to_proof_outputs`, but aggregation object already has "
46 "assigned proof outputs to public inputs.";
47 return;
48 }
49
50 P0 = P0.reduce();
51 P1 = P1.reduce();
52 proof_witness_indices = {
53 P0.x.binary_basis_limbs[0].element.normalize().witness_index,
54 P0.x.binary_basis_limbs[1].element.normalize().witness_index,
55 P0.x.binary_basis_limbs[2].element.normalize().witness_index,
56 P0.x.binary_basis_limbs[3].element.normalize().witness_index,
57 P0.y.binary_basis_limbs[0].element.normalize().witness_index,
58 P0.y.binary_basis_limbs[1].element.normalize().witness_index,
59 P0.y.binary_basis_limbs[2].element.normalize().witness_index,
60 P0.y.binary_basis_limbs[3].element.normalize().witness_index,
61 P1.x.binary_basis_limbs[0].element.normalize().witness_index,
62 P1.x.binary_basis_limbs[1].element.normalize().witness_index,
63 P1.x.binary_basis_limbs[2].element.normalize().witness_index,
64 P1.x.binary_basis_limbs[3].element.normalize().witness_index,
65 P1.y.binary_basis_limbs[0].element.normalize().witness_index,
66 P1.y.binary_basis_limbs[1].element.normalize().witness_index,
67 P1.y.binary_basis_limbs[2].element.normalize().witness_index,
68 P1.y.binary_basis_limbs[3].element.normalize().witness_index,
69 };
70
71 auto* context = P0.get_context();
72
73 context->check_circuit();
74 info("checked circuit before add_recursive_proof");
75 context->add_recursive_proof(proof_witness_indices);
76 }
77};
78
79template <typename Curve> void read(uint8_t const*& it, aggregation_state<Curve>& as)
80{
81 using serialize::read;
82
83 read(it, as.P0);
84 read(it, as.P1);
85 read(it, as.public_inputs);
86 read(it, as.proof_witness_indices);
87 read(it, as.has_data);
88};
89
90template <typename Curve> void write(std::vector<uint8_t>& buf, aggregation_state<Curve> const& as)
91{
92 using serialize::write;
93
94 write(buf, as.P0);
95 write(buf, as.P1);
96 write(buf, as.public_inputs);
97 write(buf, as.proof_witness_indices);
98 write(buf, as.has_data);
99};
100
101template <typename NCT> std::ostream& operator<<(std::ostream& os, aggregation_state<NCT> const& as)
102{
103 return os << "P0: " << as.P0 << "\n"
104 << "P1: " << as.P1 << "\n"
105 << "public_inputs: " << as.public_inputs << "\n"
106 << "proof_witness_indices: " << as.proof_witness_indices << "\n"
107 << "has_data: " << as.has_data << "\n";
108}
109
110} // namespace recursion
111} // namespace stdlib
112} // namespace proof_system::plonk
Definition: widget.bench.cpp:13
void add_proof_outputs_as_public_inputs()
TODO(@dbanks12 please migrate A3 circuits to using assign_object_to_proof_outputs....
Definition: aggregation_state.hpp:36