11#include <unordered_map>
12#include <unordered_set>
21 if (ensure_nonzero && !this->circuit_finalized) {
24 add_mega_gates_to_ensure_all_polys_are_non_zero();
48 auto raw_read_idx =
static_cast<uint32_t
>(get_calldata().size()) - 1;
49 auto read_idx = this->add_variable(raw_read_idx);
50 read_calldata(read_idx);
54 raw_read_idx =
static_cast<uint32_t
>(get_secondary_calldata().size()) - 1;
55 read_idx = this->add_variable(raw_read_idx);
56 read_secondary_calldata(read_idx);
60 raw_read_idx =
static_cast<uint32_t
>(get_return_data().size()) - 1;
61 read_idx = this->add_variable(raw_read_idx);
62 read_return_data(read_idx);
83 add_mega_gates_to_ensure_all_polys_are_non_zero();
94 auto ultra_op = op_queue->add_accumulate(point);
109template <
typename FF>
113 auto ultra_op = op_queue->mul_accumulate(point, scalar);
116 ecc_op_tuple op_tuple = populate_ecc_op_wires(ultra_op);
129 auto ultra_op = op_queue->eq_and_reset();
132 ecc_op_tuple op_tuple = populate_ecc_op_wires(ultra_op);
145 auto ultra_op = op_queue->no_op_ultra_only();
148 ecc_op_tuple op_tuple = populate_ecc_op_wires(ultra_op);
161 op_tuple.
op = get_ecc_op_idx(ultra_op.
op_code);
162 op_tuple.
x_lo = this->add_variable(ultra_op.
x_lo);
163 op_tuple.
x_hi = this->add_variable(ultra_op.
x_hi);
164 op_tuple.
y_lo = this->add_variable(ultra_op.
y_lo);
165 op_tuple.
y_hi = this->add_variable(ultra_op.
y_hi);
166 op_tuple.
z_1 = this->add_variable(ultra_op.
z_1);
167 op_tuple.
z_2 = this->add_variable(ultra_op.
z_2);
170 uint32_t op_val_idx_1 = op_tuple.
op;
171 uint32_t op_val_idx_2 = this->zero_idx;
178 this->blocks.ecc_op.populate_wires(op_val_idx_1, op_tuple.
x_lo, op_tuple.
x_hi, op_tuple.
y_lo);
179 for (
auto& selector : this->blocks.ecc_op.get_selectors()) {
180 selector.emplace_back(0);
183 this->blocks.ecc_op.populate_wires(op_val_idx_2, op_tuple.
y_hi, op_tuple.
z_1, op_tuple.
z_2);
184 for (
auto& selector : this->blocks.ecc_op.get_selectors()) {
185 selector.emplace_back(0);
201 auto ultra_op = op_queue->random_op_ultra_only();
204 (void)populate_ecc_op_wires(ultra_op);
209 null_op_idx = this->zero_idx;
210 add_accum_op_idx = this->put_constant_variable(
FF(
EccOpCode{ .
add =
true }.value()));
211 mul_accum_op_idx = this->put_constant_variable(
FF(
EccOpCode{ .
mul =
true }.value()));
212 equality_op_idx = this->put_constant_variable(
FF(
EccOpCode{ .
eq =
true, .reset =
true }.value()));
223template <
typename FF>
226 auto& bus_vector = databus[
static_cast<size_t>(bus_idx)];
228 const uint32_t read_idx =
static_cast<uint32_t
>(
uint256_t(this->get_variable(read_idx_witness_idx)));
234 FF value = this->get_variable(bus_vector[read_idx]);
235 uint32_t value_witness_idx = this->add_variable(
value);
237 create_databus_read_gate({ read_idx_witness_idx, value_witness_idx }, bus_idx);
238 bus_vector.increment_read_count(read_idx);
240 return value_witness_idx;
249template <
typename FF>
252 auto& block = this->blocks.busread;
253 block.populate_wires(in.
value, in.
index, this->zero_idx, this->zero_idx);
254 apply_databus_selectors(bus_idx);
256 this->check_selector_length_consistency();
262 auto& block = this->blocks.busread;
265 block.q_1().emplace_back(1);
266 block.q_2().emplace_back(0);
267 block.q_3().emplace_back(0);
271 block.q_1().emplace_back(0);
272 block.q_2().emplace_back(1);
273 block.q_3().emplace_back(0);
277 block.q_1().emplace_back(0);
278 block.q_2().emplace_back(0);
279 block.q_3().emplace_back(1);
283 block.q_busread().emplace_back(1);
284 block.q_m().emplace_back(0);
285 block.q_c().emplace_back(0);
286 block.q_delta_range().emplace_back(0);
287 block.q_arith().emplace_back(0);
288 block.q_4().emplace_back(0);
289 block.q_lookup_type().emplace_back(0);
290 block.q_elliptic().emplace_back(0);
291 block.q_memory().emplace_back(0);
292 block.q_nnf().emplace_back(0);
293 block.q_poseidon2_external().emplace_back(0);
294 block.q_poseidon2_internal().emplace_back(0);
#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.
void apply_databus_selectors(BusId bus_idx)
void add_mega_gates_to_ensure_all_polys_are_non_zero()
Ensure all polynomials have at least one non-zero coefficient to avoid commiting to the zero-polynomi...
ecc_op_tuple queue_ecc_eq()
Add point equality operation to the op queue based on the value of the internal accumulator and add c...
ecc_op_tuple populate_ecc_op_wires(const UltraOp &ultra_op)
Add goblin ecc op gates for a single operation.
ecc_op_tuple queue_ecc_mul_accum(const g1::affine_element &point, const FF &scalar)
Add point mul-then-accumulate operation to the op queue and add corresponding gates.
void add_ultra_and_mega_gates_to_ensure_all_polys_are_non_zero()
Ensure all polynomials have at least one non-zero coefficient to avoid commiting to the zero-polynomi...
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()
Logic for a no-op operation.
void finalize_circuit(const bool ensure_nonzero)
uint32_t read_bus_vector(BusId bus_idx, const uint32_t &read_idx_witness_idx)
Read from a databus column.
void add_gates_to_ensure_all_polys_are_non_zero()
Ensure all polynomials have at least one non-zero coefficient to avoid commiting to the zero-polynomi...
void finalize_circuit(const bool ensure_nonzero)
static constexpr element one
Entry point for Barretenberg command-line interface.
static constexpr bb::fr DEFAULT_VALUE
Defines the opcodes for ECC operations used in both the Ultra and ECCVM formats. There are three opco...