barretenberg
Loading...
Searching...
No Matches
mock_circuits.hpp
1#pragma once
2
3#include "barretenberg/commitment_schemes/commitment_key.hpp"
4#include "barretenberg/flavor/goblin_ultra.hpp"
5#include "barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.hpp"
6#include "barretenberg/srs/global_crs.hpp"
7
8namespace barretenberg {
10 public:
11 using Curve = curve::BN254;
12 using FF = Curve::ScalarField;
13 using Fbase = Curve::BaseField;
14 using Point = Curve::AffineElement;
19 static constexpr size_t NUM_OP_QUEUE_COLUMNS = Flavor::NUM_WIRES;
20
21 static void construct_arithmetic_circuit(GoblinUltraBuilder& builder)
22 {
23 // Add some arithmetic gates that utilize public inputs
24 for (size_t i = 0; i < 10; ++i) {
25 FF a = FF::random_element();
26 FF b = FF::random_element();
27 FF c = FF::random_element();
28 FF d = a + b + c;
29 uint32_t a_idx = builder.add_public_variable(a);
30 uint32_t b_idx = builder.add_variable(b);
31 uint32_t c_idx = builder.add_variable(c);
32 uint32_t d_idx = builder.add_variable(d);
33
34 builder.create_big_add_gate({ a_idx, b_idx, c_idx, d_idx, FF(1), FF(1), FF(1), FF(-1), FF(0) });
35 }
36 }
37
38 static void construct_goblin_ecc_op_circuit(GoblinUltraBuilder& builder)
39 {
40 // Add a mul accum op and an equality op
41 auto point = Point::one() * FF::random_element();
42 auto scalar = FF::random_element();
43 builder.queue_ecc_mul_accum(point, scalar);
44 builder.queue_ecc_eq();
45 }
46
60 std::shared_ptr<proof_system::ECCOpQueue>& op_queue)
61 {
63
64 // Add some goblinized ecc ops
65 construct_goblin_ecc_op_circuit(builder);
66
67 op_queue->set_size_data();
68
69 // Manually compute the op queue transcript commitments (which would normally be done by the merge prover)
70 auto crs_factory_ = barretenberg::srs::get_crs_factory();
71 auto commitment_key = CommitmentKey(op_queue->get_current_size(), crs_factory_);
72 std::array<Point, Flavor::NUM_WIRES> op_queue_commitments;
73 size_t idx = 0;
74 for (auto& entry : op_queue->get_aggregate_transcript()) {
75 op_queue_commitments[idx++] = commitment_key.commit(entry);
76 }
77 // Store the commitment data for use by the prover of the next circuit
78 op_queue->set_commitment_data(op_queue_commitments);
79 }
80
87 {
88 // TODO(https://github.com/AztecProtocol/barretenberg/issues/800) Testing cleanup
90
91 // Add some arbitrary ecc op gates
92 for (size_t i = 0; i < 3; ++i) {
93 auto point = Point::random_element();
94 auto scalar = FF::random_element();
95 builder.queue_ecc_add_accum(point);
96 builder.queue_ecc_mul_accum(point, scalar);
97 }
98 // queues the result of the preceding ECC
99 builder.queue_ecc_eq(); // should be eq and reset
100
101 construct_arithmetic_circuit(builder);
102 }
103};
104} // namespace barretenberg
Definition: mock_circuits.hpp:9
static void perform_op_queue_interactions_for_mock_first_circuit(std::shared_ptr< proof_system::ECCOpQueue > &op_queue)
Mock the interactions of a simple curcuit with the op_queue.
Definition: mock_circuits.hpp:59
static void construct_simple_initial_circuit(GoblinUltraBuilder &builder)
Generate a simple test circuit with some ECC op gates and conventional arithmetic gates.
Definition: mock_circuits.hpp:86
Definition: bn254.hpp:10
virtual uint32_t add_variable(const FF &in)
Definition: circuit_builder_base.hpp:163
virtual uint32_t add_public_variable(const FF &in)
Definition: circuit_builder_base.hpp:278
Used to construct execution trace representations of elliptic curve operations.
Definition: ecc_op_queue.hpp:18
Definition: goblin_ultra_circuit_builder.hpp:16
ecc_op_tuple queue_ecc_eq()
Add point equality gates based on the current value of the accumulator internal to the op queue and a...
Definition: goblin_ultra_circuit_builder.cpp:162
ecc_op_tuple queue_ecc_mul_accum(const g1::affine_element &point, const FF &scalar)
Add gates for point mul-then-accumulate and add the raw operation data to the op queue.
Definition: goblin_ultra_circuit_builder.cpp:143
ecc_op_tuple queue_ecc_add_accum(const g1::affine_element &point)
Add gates for simple point addition (no mul) and add the raw operation data to the op queue.
Definition: goblin_ultra_circuit_builder.cpp:122
void create_big_add_gate(const add_quad_< FF > &in, const bool use_next_gate_w_4=false)
Create a big addition gate, where in.a * in.a_scaling + in.b * in.b_scaling + in.c * in....
Definition: ultra_circuit_builder.cpp:157
Definition: goblin_ultra.hpp:24
CommitmentKey object over a pairing group 𝔾₁.
Definition: commitment_key.hpp:35
constexpr_utils defines some helper methods that perform some stl-equivalent operations but in a cons...
Definition: constexpr_utils.hpp:16