Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 9080d9a

Browse files
akokoshnakokoshn
andauthored
Find correct gate index for used gates (#301)
Co-authored-by: akokoshn <[email protected]>
1 parent 23c85b8 commit 9080d9a

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

include/nil/blueprint/blueprint/plonk/circuit_proxy.hpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ namespace nil {
5858
std::set<std::uint32_t> used_lookup_gates;
5959
std::set<std::uint32_t> used_lookup_tables;
6060

61+
std::uint32_t get_gate_index(std::size_t selector_index) const {
62+
const auto& gates = circuit_ptr->gates();
63+
auto it = std::find_if(gates.begin(), gates.end(), [selector_index](const typename ArithmetizationType::gates_container_type::value_type& gate) -> bool
64+
{ return selector_index == gate.selector_index; });
65+
return it - gates.begin();
66+
}
67+
68+
std::uint32_t get_lookup_gate_index(std::size_t selector_index) const {
69+
const auto& lookup_gates = circuit_ptr->lookup_gates();
70+
auto it = std::find_if(lookup_gates.begin(), lookup_gates.end(),
71+
[selector_index](const typename ArithmetizationType::lookup_gates_container_type::value_type& lookup_gate) -> bool
72+
{ return selector_index == lookup_gate.tag_index; });
73+
return it - lookup_gates.begin();
74+
}
75+
6176
public:
6277

6378
circuit_proxy(std::shared_ptr<circuit<ArithmetizationType>> circuit, std::uint32_t _id) :
@@ -120,37 +135,37 @@ namespace nil {
120135

121136
std::size_t add_gate(const std::vector<constraint_type> &args) override {
122137
const auto selector_index = circuit_ptr->add_gate(args);
123-
used_gates.insert(circuit_ptr->num_gates() - 1);
138+
used_gates.insert(get_gate_index(selector_index));
124139
return selector_index;
125140
}
126141

127142
std::size_t add_gate(const constraint_type &args) override {
128143
const auto selector_index = circuit_ptr->add_gate(args);
129-
used_gates.insert(circuit_ptr->num_gates() - 1);
144+
used_gates.insert(get_gate_index(selector_index));
130145
return selector_index;
131146
}
132147

133148
std::size_t add_gate(const std::initializer_list<constraint_type> &&args) override {
134149
const auto selector_index = circuit_ptr->add_gate(args);
135-
used_gates.insert(circuit_ptr->num_gates() - 1);
150+
used_gates.insert(get_gate_index(selector_index));
136151
return selector_index;
137152
}
138153

139154
std::size_t add_lookup_gate(const std::vector<lookup_constraint_type> &args) override {
140155
const auto selector_index = circuit_ptr->add_lookup_gate(args);
141-
used_lookup_gates.insert(circuit_ptr->num_lookup_gates() - 1);
156+
used_lookup_gates.insert(get_lookup_gate_index(selector_index));
142157
return selector_index;
143158
}
144159

145160
std::size_t add_lookup_gate(const lookup_constraint_type &args) override {
146161
const auto selector_index = circuit_ptr->add_lookup_gate(args);
147-
used_lookup_gates.insert(circuit_ptr->num_lookup_gates() - 1);
162+
used_lookup_gates.insert(get_lookup_gate_index(selector_index));
148163
return selector_index;
149164
}
150165

151166
std::size_t add_lookup_gate(const std::initializer_list<lookup_constraint_type> &&args) override {
152167
const auto selector_index = circuit_ptr->add_lookup_gate(args);
153-
used_lookup_gates.insert(circuit_ptr->num_lookup_gates() - 1);
168+
used_lookup_gates.insert(get_lookup_gate_index(selector_index));
154169
return selector_index;
155170
}
156171

0 commit comments

Comments
 (0)