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#pragma once
2
16
17namespace bb {
18
26template <typename Builder> void generate_sha256_test_circuit(Builder& builder, size_t num_iterations)
27{
30
31 // SHA-256 initial hash values (FIPS 180-4 section 5.3.3)
32 constexpr std::array<uint32_t, 8> H_INIT = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
33 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 };
34
35 // Initialize h_init as witnesses
37 for (size_t i = 0; i < 8; i++) {
38 h_init[i] = witness_ct(&builder, H_INIT[i]);
39 }
40
41 // Create a block of zeros as witnesses
43 for (size_t i = 0; i < 16; i++) {
44 block[i] = witness_ct(&builder, 0);
45 }
46
47 // Iterate: feed output of compression back as h_init for next round
48 for (size_t i = 0; i < num_iterations; i++) {
49 h_init = stdlib::SHA256<Builder>::sha256_block(h_init, block);
50 }
51}
52
54 public:
70
71 static constexpr size_t NUM_WIRES = Flavor::NUM_WIRES;
72
82 static void construct_mock_app_circuit(MegaBuilder& builder, bool large = false)
83 {
84 BB_BENCH();
85
86 if (large) { // Results in circuit size 2^19
87 generate_sha256_test_circuit<MegaBuilder>(builder, 9);
89 } else { // Results in circuit size 2^17
90 generate_sha256_test_circuit<MegaBuilder>(builder, 8);
92 }
93
94 // TODO(https://github.com/AztecProtocol/barretenberg/issues/911): We require goblin ops to be added to the
95 // function circuit because we cannot support zero commtiments. While the builder handles this at
96 // ProverInstance creation stage via the add_gates_to_ensure_all_polys_are_non_zero function for other
97 // MegaHonk circuits (where we don't explicitly need to add goblin ops), in IVC merge proving happens prior to
98 // folding where the absense of goblin ecc ops will result in zero commitments.
100 }
101
108 {
109 BB_BENCH();
110
111 // Add some arbitrary ecc op gates
112 for (size_t i = 0; i < 3; ++i) {
113 auto point = Point::random_element(&engine);
114 auto scalar = FF::random_element(&engine);
115 builder.queue_ecc_add_accum(point);
116 builder.queue_ecc_mul_accum(point, scalar);
117 }
118 // queues the result of the preceding ECC
119 builder.queue_ecc_eq(); // should be eq and reset
120 }
121
125 static void randomise_op_queue(MegaBuilder& builder, size_t num_ops)
126 {
127
128 for (size_t i = 0; i < num_ops; ++i) {
129 builder.queue_ecc_random_op();
130 }
131 }
132
146
147 static void construct_and_merge_mock_circuits(Goblin& goblin, const size_t num_circuits = 3)
148 {
150 for (size_t idx = 0; idx < num_circuits - 1; ++idx) {
152 if (idx == num_circuits - 2) {
153 // Last circuit appended needs to begin with a no-op for translator to be shiftable
154 builder.queue_ecc_no_op();
155 // Add random ops at START for Translator ZK (lands at beginning of op queue table)
157 // Add hiding op for ECCVM ZK (prepended to ECCVM ops at row 1)
158 builder.queue_ecc_hiding_op(Fq::random_element(), Fq::random_element());
159 }
161 goblin.prove_merge();
162 // Pop the merge proof from the queue, Goblin will be verified at the end
163 goblin.merge_verification_queue.pop_front();
164 }
167 // Add random ops at END for Translator ZK
169 }
170
181 {
182 BB_BENCH();
183
184 // Add operations representing general kernel logic e.g. state updates. Note: these are structured to make
185 // the kernel "full" within the dyadic size 2^17
186 const size_t NUM_ECDSA_VERIFICATIONS = 2;
187 const size_t NUM_SHA_HASHES = 10;
189 generate_sha256_test_circuit<MegaBuilder>(builder, NUM_SHA_HASHES);
190 }
191};
192} // namespace bb
#define BB_BENCH()
Definition bb_bench.hpp:229
CommitmentKey object over a pairing group 𝔾₁.
Manages ECC operations for the Goblin proving system.
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:28
std::shared_ptr< OpQueue > op_queue
Definition goblin.hpp:54
std::deque< MergeProof > merge_verification_queue
Definition goblin.hpp:62
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
static constexpr size_t NUM_WIRES
NativeVerificationKey_< PrecomputedEntities< Commitment >, Codec, HashFunction, CommitmentKey > VerificationKey
The verification key stores commitments to the precomputed (non-witness) polynomials used by the veri...
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.
Base Native verification key class.
Definition flavor.hpp:135
The VerifierInstance encapsulates all the necessary information for a Honk Verifier to verify a proof...
typename Flavor::VKAndHash VKAndHash
bb::fq BaseField
Definition bn254.hpp:19
typename Group::affine_element AffineElement
Definition bn254.hpp:22
bb::fr ScalarField
Definition bn254.hpp:18
static std::array< field_ct, 8 > sha256_block(const std::array< field_ct, 8 > &h_init, const std::array< field_ct, 16 > &input)
Apply the SHA-256 compression function to a single 512-bit message block.
Definition sha256.cpp:333
static void add_default(Builder &builder)
Add default public inputs when they are not present.
AluTraceBuilder builder
Definition alu.test.cpp:124
numeric::RNG & engine
stdlib::witness_t< Builder > witness_ct
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.
Definition api.hpp:5
void generate_sha256_test_circuit(Builder &builder, size_t num_iterations)
Generate a test circuit using SHA256 compression (sha256_block)
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