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
101 {
102 BB_BENCH();
103
104 // Add some arbitrary ecc op gates
105 for (size_t i = 0; i < 3; ++i) {
106 auto point = Point::random_element(&engine);
107 auto scalar = FF::random_element(&engine);
108 builder.queue_ecc_add_accum(point);
109 builder.queue_ecc_mul_accum(point, scalar);
110 }
111 // queues the result of the preceding ECC
112 builder.queue_ecc_eq(); // should be eq and reset
113 }
114
118 static void randomise_op_queue(MegaBuilder& builder, size_t num_ops)
119 {
120
121 for (size_t i = 0; i < num_ops; ++i) {
122 builder.queue_ecc_random_op();
123 }
124 }
125
139
140 static void construct_and_merge_mock_circuits(Goblin& goblin, const size_t num_circuits = 3)
141 {
142 for (size_t idx = 0; idx < num_circuits - 1; ++idx) {
145 goblin.op_queue->merge();
146 }
149 // Add random ops at END for Translator ZK
151 }
152
163 {
164 BB_BENCH();
165
166 // Add operations representing general kernel logic e.g. state updates. Note: these are structured to make
167 // the kernel "full" within the dyadic size 2^17
168 const size_t NUM_ECDSA_VERIFICATIONS = 2;
169 const size_t NUM_SHA_HASHES = 10;
171 generate_sha256_test_circuit<MegaBuilder>(builder, NUM_SHA_HASHES);
172 }
173};
174} // namespace bb
#define BB_BENCH()
Definition bb_bench.hpp:268
CommitmentKey object over a pairing group 𝔾₁.
Manages ECC operations for the Goblin proving system.
std::shared_ptr< OpQueue > op_queue
Definition goblin.hpp:59
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.
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