Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
mock_circuits.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#pragma once
8
25
26namespace bb {
27
28template <typename Builder> void generate_sha256_test_circuit(Builder& builder, size_t num_iterations)
29{
30 std::string in;
31 in.resize(32);
33 for (size_t i = 0; i < num_iterations; i++) {
34 input = stdlib::SHA256<Builder>::hash(input);
35 }
36}
37
42static constexpr TraceStructure SMALL_TEST_STRUCTURE_FOR_OVERFLOWS{ .ecc_op = 1 << 14,
43 .busread = 1 << 14,
44 .lookup = 1 << 14,
45 .pub_inputs = 1 << 14,
46 .arithmetic = 1 << 15,
47 .delta_range = 1 << 14,
48 .elliptic = 1 << 14,
49 .memory = 1 << 14,
50 .nnf = 1 << 7,
51 .poseidon2_external = 1 << 14,
52 .poseidon2_internal = 1 << 15,
53 .overflow = 0 };
54
56 public:
72
73 static constexpr size_t NUM_WIRES = Flavor::NUM_WIRES;
74
84 static void construct_mock_app_circuit(MegaBuilder& builder, bool large = false)
85 {
86 BB_BENCH();
87
88 if (large) { // Results in circuit size 2^19
89 generate_sha256_test_circuit<MegaBuilder>(builder, 9);
91 } else { // Results in circuit size 2^17
92 generate_sha256_test_circuit<MegaBuilder>(builder, 8);
94 }
95
96 // TODO(https://github.com/AztecProtocol/barretenberg/issues/911): We require goblin ops to be added to the
97 // function circuit because we cannot support zero commtiments. While the builder handles this at
98 // ProverInstance creation stage via the add_gates_to_ensure_all_polys_are_non_zero function for other
99 // MegaHonk circuits (where we don't explicitly need to add goblin ops), in IVC merge proving happens prior to
100 // folding where the absense of goblin ecc ops will result in zero commitments.
103 }
104
111 {
112 BB_BENCH();
113
114 // Add some arbitrary ecc op gates
115 for (size_t i = 0; i < 3; ++i) {
116 auto point = Point::random_element(&engine);
117 auto scalar = FF::random_element(&engine);
118 builder.queue_ecc_add_accum(point);
119 builder.queue_ecc_mul_accum(point, scalar);
120 }
121 // queues the result of the preceding ECC
122 builder.queue_ecc_eq(); // should be eq and reset
123 }
124
128 static void randomise_op_queue(MegaBuilder& builder, size_t num_ops)
129 {
130
131 for (size_t i = 0; i < num_ops; ++i) {
132 builder.queue_ecc_random_op();
133 }
134 }
135
149
150 static void construct_and_merge_mock_circuits(Goblin& goblin, const size_t num_circuits = 3)
151 {
152 for (size_t idx = 0; idx < num_circuits - 1; ++idx) {
154 if (idx == num_circuits - 2) {
155 // Last circuit appended needs to begin with a no-op for translator to be shiftable
156 builder.queue_ecc_no_op();
158 }
160 goblin.prove_merge();
161 // Pop the merge proof from the queue, Goblin will be verified at the end
162 goblin.merge_verification_queue.pop_front();
163 }
167 }
168
179 {
180 BB_BENCH();
181
182 // Add operations representing general kernel logic e.g. state updates. Note: these are structured to make
183 // the kernel "full" within the dyadic size 2^17
184 const size_t NUM_ECDSA_VERIFICATIONS = 2;
185 const size_t NUM_SHA_HASHES = 10;
187 generate_sha256_test_circuit<MegaBuilder>(builder, NUM_SHA_HASHES);
188 }
189};
190} // namespace bb
#define BB_BENCH()
Definition bb_bench.hpp:222
CommitmentKey object over a pairing group 𝔾₁.
Used to construct execution trace representations of elliptic curve operations.
void prove_merge(const std::shared_ptr< Transcript > &transcript=std::make_shared< Transcript >(), const MergeSettings merge_settings=MergeSettings::PREPEND)
Construct a merge proof for the goblin ECC ops in the provided circuit; append the proof to the merge...
Definition goblin.cpp:25
std::shared_ptr< OpQueue > op_queue
Definition goblin.hpp:48
std::deque< MergeProof > merge_verification_queue
Definition goblin.hpp:57
Curve::AffineElement Point
static void add_some_ecc_op_gates(MegaBuilder &builder)
Generate a simple test circuit with some ECC op gates and conventional arithmetic gates.
static void construct_mock_app_circuit(MegaBuilder &builder, bool large=false)
Populate a builder with some arbitrary but nontrivial constraints.
static void construct_simple_circuit(MegaBuilder &builder)
Generate a simple test circuit with some ECC op gates and conventional arithmetic gates.
static void construct_mock_folding_kernel(MegaBuilder &builder)
Construct a mock kernel circuit.
static void randomise_op_queue(MegaBuilder &builder, size_t num_ops)
Add some randomness into the op queue.
RecursiveVerifierInstance::VKAndHash RecursiveVKAndHash
static void construct_and_merge_mock_circuits(Goblin &goblin, const size_t num_circuits=3)
static constexpr size_t NUM_WIRES
std::shared_ptr< RecursiveVerifierInstance > RecursiveVerifierAccumulator
The verification key is responsible for storing the commitments to the precomputed (non-witness) poly...
static constexpr size_t NUM_WIRES
The recursive counterpart to the "native" Mega flavor.
static void construct_arithmetic_circuit(Builder &builder, const size_t target_log2_dyadic_size=4, bool include_public_inputs=true)
Populate a builder with a specified number of arithmetic gates; includes a PI.
static void construct_goblin_ecc_op_circuit(MegaCircuitBuilder &builder)
Populate a builder with some arbitrary goblinized ECC ops, one of each type.
The VerifierInstance encapsulates all the necessary information for a Mega Honk Verifier to verify a ...
bb::fq BaseField
Definition bn254.hpp:19
typename Group::affine_element AffineElement
Definition bn254.hpp:22
bb::fr ScalarField
Definition bn254.hpp:18
static byte_array< Builder > hash(const byte_array_ct &input)
Definition sha256.cpp:308
Represents a dynamic array of bytes in-circuit.
static void add_default(Builder &builder)
Add default public inputs when they are not present.
The stdlib counterpart of VerifierInstance, used in recursive folding verification.
AluTraceBuilder builder
Definition alu.test.cpp:123
void generate_ecdsa_verification_test_circuit(Builder &builder, size_t num_iterations)
Generate a simple ecdsa verification circuit for testing purposes.
Entry point for Barretenberg command-line interface.
void generate_sha256_test_circuit(Builder &builder, size_t num_iterations)
MegaCircuitBuilder_< field< Bn254FrParams > > MegaCircuitBuilder
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
static field random_element(numeric::RNG *engine=nullptr) noexcept