11#include <unordered_map>
12#include <unordered_set>
32 auto ultra_op = op_queue->add_accumulate(point);
55 auto ultra_op = op_queue->mul_accumulate(point, scalar);
58 ecc_op_tuple op_tuple = populate_ecc_op_wires(ultra_op, in_finalize);
72 auto ultra_op = op_queue->eq_and_reset();
75 ecc_op_tuple op_tuple = populate_ecc_op_wires(ultra_op, in_finalize);
89 auto ultra_op = op_queue->no_op_ultra_only();
108template <
typename FF>
112 op_tuple.
op = get_ecc_op_idx(ultra_op.
op_code);
113 op_tuple.
x_lo = this->add_variable(ultra_op.
x_lo);
114 op_tuple.
x_hi = this->add_variable(ultra_op.
x_hi);
115 op_tuple.
y_lo = this->add_variable(ultra_op.
y_lo);
116 op_tuple.
y_hi = this->add_variable(ultra_op.
y_hi);
117 op_tuple.
z_1 = this->add_variable(ultra_op.
z_1);
118 op_tuple.
z_2 = this->add_variable(ultra_op.
z_2);
121 uint32_t op_val_idx_1 = op_tuple.
op;
122 uint32_t op_val_idx_2 = this->zero_idx();
131 this->blocks.ecc_op.populate_wires(op_val_idx_1, op_tuple.
x_lo, op_tuple.
x_hi, op_tuple.
y_lo);
132 for (
auto& selector : this->blocks.ecc_op.get_selectors()) {
133 selector.emplace_back(0);
135 this->blocks.ecc_op.populate_wires(op_val_idx_2, op_tuple.
y_hi, op_tuple.
z_1, op_tuple.
z_2);
136 for (
auto& selector : this->blocks.ecc_op.get_selectors()) {
137 selector.emplace_back(0);
141 update_used_witnesses(
143 update_finalize_witnesses(
160 auto ultra_op = op_queue->random_op_ultra_only();
163 (void)populate_ecc_op_wires(ultra_op);
177template <
typename FF>
181 auto ultra_op = op_queue->append_hiding_op(Px, Py);
184 populate_ecc_op_wires(ultra_op);
189 null_op_idx = this->zero_idx();
190 add_accum_op_idx = this->put_constant_variable(
FF(
EccOpCode{ .
add =
true }.value()));
191 mul_accum_op_idx = this->put_constant_variable(
FF(
EccOpCode{ .
mul =
true }.value()));
192 equality_op_idx = this->put_constant_variable(
FF(
EccOpCode{ .
eq =
true, .reset =
true }.value()));
203template <
typename FF>
206 auto& bus_vector = databus[
static_cast<size_t>(bus_idx)];
208 const uint32_t read_idx =
static_cast<uint32_t
>(
uint256_t(this->get_variable(read_idx_witness_idx)));
214 FF value = this->get_variable(bus_vector[read_idx]);
215 uint32_t value_witness_idx = this->add_variable(
value);
217 create_databus_read_gate({ read_idx_witness_idx, value_witness_idx }, bus_idx);
218 bus_vector.increment_read_count(read_idx);
220 return value_witness_idx;
229template <
typename FF>
232 auto& block = this->blocks.busread;
233 block.populate_wires(in.
value, in.
index, this->zero_idx(), this->zero_idx());
234 apply_databus_selectors(bus_idx);
236 this->check_selector_length_consistency();
237 this->increment_num_gates();
242 auto& block = this->blocks.busread;
244 const size_t idx =
static_cast<size_t>(bus_idx);
245 block.q_1().emplace_back(idx == 0 ? 1 : 0);
246 block.q_2().emplace_back(idx == 1 ? 1 : 0);
247 block.q_3().emplace_back(idx == 2 ? 1 : 0);
248 block.q_4().emplace_back(idx == 3 ? 1 : 0);
249 block.q_5().emplace_back(0);
250 block.q_m().emplace_back(idx == 4 ? 1 : 0);
251 block.q_c().emplace_back(0);
252 block.set_gate_selector(1);
259template <
typename FF>
262 auto& block = this->blocks.poseidon2_external;
263 block.populate_wires(in.
a, in.
b, in.
c, in.
d);
264 block.q_m().emplace_back(0);
265 block.q_1().emplace_back(0);
266 block.q_2().emplace_back(0);
267 block.q_3().emplace_back(0);
268 block.q_c().emplace_back(0);
269 block.q_4().emplace_back(0);
270 block.q_5().emplace_back(0);
272 this->check_selector_length_consistency();
273 this->increment_num_gates();
285template <
typename FF>
288 auto& block = this->blocks.poseidon2_quad_internal;
289 block.populate_wires(in.
a, in.
b, in.
c, in.
d);
296 block.q_m().emplace_back(0);
297 block.q_c().emplace_back(0);
298 block.q_5().emplace_back(0);
306 this->check_selector_length_consistency();
307 this->increment_num_gates();
320template <
typename FF>
323 auto& block = this->blocks.poseidon2_quad_internal;
324 block.populate_wires(in.
a, in.
b, in.
c, in.
d);
326 block.q_m().emplace_back(0);
330 block.q_4().emplace_back(0);
331 block.q_5().emplace_back(0);
332 block.q_c().emplace_back(0);
334 this->check_selector_length_consistency();
335 this->increment_num_gates();
#define BB_ASSERT_LT(left, right,...)
void set_goblin_ecc_op_code_constant_variables()
void queue_ecc_random_op()
Mechanism for populating two rows with randomness. This "operation" doesn't return a tuple representi...
ecc_op_tuple queue_ecc_add_accum(const g1::affine_element &point)
Add simple point addition operation to the op queue and add corresponding gates.
ecc_op_tuple queue_ecc_mul_accum(const g1::affine_element &point, const FF &scalar, bool in_finalize=false)
Add point mul-then-accumulate operation to the op queue and add corresponding gates.
void create_poseidon2_quad_internal_gate(const poseidon2_quad_internal_gate_< FF > &in)
Poseidon2 K=4 compressed internal-round gate: processes FOUR consecutive internal rounds per row.
void apply_databus_selectors(BusId bus_idx)
ecc_op_tuple queue_ecc_eq(bool in_finalize=true)
Add point equality operation to the op queue based on the value of the internal accumulator and add c...
void create_databus_read_gate(const databus_lookup_gate_< FF > &in, BusId bus_idx)
Create a databus lookup/read gate.
ecc_op_tuple queue_ecc_no_op()
Add a no-op to the op queue and populate two zero rows in the ecc_op block.
void queue_ecc_hiding_op(const curve::BN254::BaseField &Px, const curve::BN254::BaseField &Py)
Add a hiding op with random (possibly non-curve) Px, Py values to the op queue and circuit.
void create_poseidon2_transition_entry_gate(const poseidon2_transition_entry_gate_< FF > &in)
Poseidon2 transition-entry gate: standard → K=4 compressed encoding boundary.
uint32_t read_bus_vector(BusId bus_idx, const uint32_t &read_idx_witness_idx)
Read from a databus column.
void create_poseidon2_initial_external_gate(const poseidon2_initial_external_gate_< FF > &in)
Poseidon2 initial linear layer gate, activates the q_poseidon2_external_initial selector and relation...
ecc_op_tuple populate_ecc_op_wires(const UltraOp &ultra_op, bool in_finalize=false)
Add goblin ecc op gates for a single operation.
typename ExecutionTrace::FF FF
Entry point for Barretenberg command-line interface.
@ Poseidon2QuadIntTerminal
@ Poseidon2TransitionEntry
Defines the opcodes for ECC operations used in both the Ultra and ECCVM formats. There are three opco...
static constexpr std::array< std::array< FF, t >, rounds_f+rounds_p > round_constants