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
18
19namespace bb {
20
28template <typename Builder> void generate_sha256_test_circuit(Builder& builder, size_t num_iterations)
29{
32
33 // SHA-256 initial hash values (FIPS 180-4 section 5.3.3)
34 constexpr std::array<uint32_t, 8> H_INIT = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
35 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 };
36
37 // Initialize h_init as witnesses
39 for (size_t i = 0; i < 8; i++) {
40 h_init[i] = witness_ct(&builder, H_INIT[i]);
41 }
42
43 // Create a block of zeros as witnesses
45 for (size_t i = 0; i < 16; i++) {
46 block[i] = witness_ct(&builder, 0);
47 }
48
49 // Iterate: feed output of compression back as h_init for next round
50 for (size_t i = 0; i < num_iterations; i++) {
51 h_init = stdlib::SHA256<Builder>::sha256_block(h_init, block);
52 }
53}
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.
102 }
103
110 {
111 BB_BENCH();
112
113 // Add some arbitrary ecc op gates
114 for (size_t i = 0; i < 3; ++i) {
115 auto point = Point::random_element(&engine);
116 auto scalar = FF::random_element(&engine);
117 builder.queue_ecc_add_accum(point);
118 builder.queue_ecc_mul_accum(point, scalar);
119 }
120 // queues the result of the preceding ECC
121 builder.queue_ecc_eq(); // should be eq and reset
122 }
123
127 static void randomise_op_queue(MegaBuilder& builder, size_t num_ops)
128 {
129
130 for (size_t i = 0; i < num_ops; ++i) {
131 builder.queue_ecc_random_op();
132 }
133 }
134
148
149 static void construct_and_merge_mock_circuits(Goblin& goblin, const size_t num_circuits = 3)
150 {
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();
157 // Add random ops at START for Translator ZK (lands at beginning of op queue table)
159 // Add hiding op for ECCVM ZK (prepended to ECCVM ops at row 1)
160 builder.queue_ecc_hiding_op(Fq::random_element(), Fq::random_element());
161 }
163 goblin.prove_merge();
164 // Pop the merge proof from the queue, Goblin will be verified at the end
165 goblin.merge_verification_queue.pop_front();
166 }
169 // Add random ops at END for Translator ZK
171 }
172
183 {
184 BB_BENCH();
185
186 // Add operations representing general kernel logic e.g. state updates. Note: these are structured to make
187 // the kernel "full" within the dyadic size 2^17
188 const size_t NUM_ECDSA_VERIFICATIONS = 2;
189 const size_t NUM_SHA_HASHES = 10;
191 generate_sha256_test_circuit<MegaBuilder>(builder, NUM_SHA_HASHES);
192 }
193};
194} // namespace bb
#define BB_BENCH()
Definition bb_bench.hpp:223
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:29
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
static constexpr size_t NUM_WIRES
NativeVerificationKey_< PrecomputedEntities< Commitment >, Codec, HashFunction, CommitmentKey > VerificationKey
The verification key is responsible for storing the commitments to the precomputed (non-witness) poly...
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:141
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:379
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
bn254::witness_ct witness_ct
stdlib::field_t< Builder > field_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
curve::BN254::BaseField Fq