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
24
25namespace bb {
26
27template <typename Builder> void generate_sha256_test_circuit(Builder& builder, size_t num_iterations)
28{
29 std::string in;
30 in.resize(32);
32 for (size_t i = 0; i < num_iterations; i++) {
33 input = stdlib::SHA256<Builder>::hash(input);
34 }
35}
36
41static constexpr TraceStructure SMALL_TEST_STRUCTURE_FOR_OVERFLOWS{ .ecc_op = 1 << 14,
42 .busread = 1 << 14,
43 .lookup = 1 << 14,
44 .pub_inputs = 1 << 14,
45 .arithmetic = 1 << 15,
46 .delta_range = 1 << 14,
47 .elliptic = 1 << 14,
48 .memory = 1 << 14,
49 .nnf = 1 << 7,
50 .poseidon2_external = 1 << 14,
51 .poseidon2_internal = 1 << 15,
52 .overflow = 0 };
53
55 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 {
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 // DeciderProvingKey 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 PROFILE_THIS();
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
129 {
130 builder.queue_ecc_random_op();
131 builder.queue_ecc_random_op();
132 }
133
139 static void construct_simple_circuit(MegaBuilder& builder, bool last_circuit = false)
140 {
141 PROFILE_THIS();
142 // The last circuit to be accumulated must contain a no-op
143 if (last_circuit) {
144 builder.queue_ecc_no_op();
145 }
146
150 }
151
162 {
163 PROFILE_THIS();
164
165 // Add operations representing general kernel logic e.g. state updates. Note: these are structured to make
166 // the kernel "full" within the dyadic size 2^17
167 const size_t NUM_ECDSA_VERIFICATIONS = 2;
168 const size_t NUM_SHA_HASHES = 10;
170 generate_sha256_test_circuit<MegaBuilder>(builder, NUM_SHA_HASHES);
171 }
172};
173} // namespace bb
CommitmentKey object over a pairing group 𝔾₁.
The DeciderVerificationKey encapsulates all the necessary information for a Mega Honk Verifier to ver...
Used to construct execution trace representations of elliptic curve operations.
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, bool last_circuit=false)
Generate a simple test circuit with some ECC op gates and conventional arithmetic gates.
RecursiveDeciderVerificationKey::VKAndHash RecursiveVKAndHash
static void construct_mock_folding_kernel(MegaBuilder &builder)
Construct a mock kernel circuit.
static constexpr size_t NUM_WIRES
static void randomise_op_queue(MegaBuilder &builder)
Add some randomness into the op queue.
std::shared_ptr< RecursiveDeciderVerificationKey > 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.
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 DeciderVerificationKey, used in recursive folding verification.
AluTraceBuilder builder
Definition alu.test.cpp:123
numeric::RNG & engine
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
#define PROFILE_THIS()
Definition op_count.hpp:15
static field random_element(numeric::RNG *engine=nullptr) noexcept